Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SConstruct : Add Windows libraries for Cycles GPU rendering #5761

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main/installDependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Determine default archive URL.

defaultURL = "https://github.com/GafferHQ/dependencies/releases/download/8.0.0a9/gafferDependencies-8.0.0a9-{platform}{buildEnvironment}.{extension}"
defaultURL = "https://github.com/GafferHQ/dependencies/releases/download/8.0.0a10/gafferDependencies-8.0.0a10-{platform}{buildEnvironment}.{extension}"

# Parse command line arguments.

Expand Down
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
1.4.x.x (relative to 1.4.0.0b6)
=======

Features
--------

- Cycles : Added support for CUDA and Optix devices on Windows [^1].

Improvements
------------

Expand Down
9 changes: 7 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ libraries = {
"LIBS" : [
"Gaffer", "GafferScene", "GafferDispatch", "GafferBindings", "GafferCycles", "IECoreScene",
"cycles_session", "cycles_scene", "cycles_graph", "cycles_bvh", "cycles_device", "cycles_kernel", "cycles_kernel_osl",
"cycles_integrator", "cycles_util", "cycles_subd", "extern_sky",
"cycles_integrator", "cycles_util", "cycles_subd", "extern_sky", "extern_cuew",
"OpenImageIO$OIIO_LIB_SUFFIX", "OpenImageIO_Util$OIIO_LIB_SUFFIX", "oslexec$OSL_LIB_SUFFIX", "openvdb$VDB_LIB_SUFFIX",
"oslquery$OSL_LIB_SUFFIX", "Alembic", "osdCPU", "OpenColorIO$OCIO_LIB_SUFFIX", "embree4", "Iex", "openpgl",
],
Expand Down Expand Up @@ -1503,11 +1503,16 @@ for library in ( "GafferUI", ) :

if env["PLATFORM"] == "win32" :

for library in ( "Gaffer", ) :
for library in ( "Gaffer", "GafferCycles", ) :

libraries[library].setdefault( "envAppends", {} )
libraries[library]["envAppends"].setdefault( "LIBS", [] ).extend( [ "Advapi32" ] )

for library in ( "GafferCycles", ) :

libraries[library].setdefault( "pythonEnvAppends", {} )
libraries[library]["pythonEnvAppends"].setdefault( "LIBS", [] ).extend( [ "Advapi32" ] )

else :

libraries["GafferCycles"]["envAppends"]["LIBS"].extend( [ "dl" ] )
Expand Down
4 changes: 4 additions & 0 deletions include/GafferCycles/IECoreCyclesPreview/IECoreCycles.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ IECORE_POP_DEFAULT_VISIBILITY
namespace IECoreCycles
{

/// Returns the value of the `CYCLES_ROOT` environment variable, or
/// and empty string if the variable is not defined.
IECORECYCLES_API const char *cyclesRoot();

/// Initialises the library using the CYCLES_ROOT environment
/// variable, which should point to the root of a Cycles installation.
IECORECYCLES_API bool init();
Expand Down
13 changes: 9 additions & 4 deletions src/GafferCycles/IECoreCyclesPreview/IECoreCycles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,28 @@ std::string cyclesVersion = CYCLES_VERSION_STRING;
namespace IECoreCycles
{

bool init()
const char *cyclesRoot()
{
const char *cyclesRoot = getenv( "CYCLES_ROOT" );
if( !cyclesRoot )
{
IECore::msg( IECore::Msg::Error, "IECoreCycles::init", "CYCLES_ROOT environment variable not set" );
return false;
return "";
}
return cyclesRoot;
}

auto kernelFile = std::filesystem::path( cyclesRoot ) / "source" / "kernel" / "types.h";
bool init()
{
const char *cyclesRootValue = cyclesRoot();
auto kernelFile = std::filesystem::path( cyclesRootValue ) / "source" / "kernel" / "types.h";
if( !std::filesystem::is_regular_file( kernelFile ) )
{
IECore::msg( IECore::Msg::Error, "IECoreCycles::init", fmt::format( "File \"{}\" not found", kernelFile ) );
return false;
}

ccl::path_init( cyclesRoot );
ccl::path_init( cyclesRootValue );

// This is a global thing for logging
const char* argv[] = { "-", "v", "1" };
Expand Down
5 changes: 5 additions & 0 deletions src/GafferCyclesModule/GafferCyclesModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "device/device.h"
#include "graph/node.h"
#include "util/openimagedenoise.h"
#include "util/path.h"

namespace py = boost::python;
using namespace boost::python;
Expand Down Expand Up @@ -453,6 +454,10 @@ BOOST_PYTHON_MODULE( _GafferCycles )

IECoreCycles::init();

// Must be initialized to ensure the statically linked Cycles module
// we are linked to can find the binaries for GPU rendering.
ccl::path_init( IECoreCycles::cyclesRoot() );
Comment on lines +457 to +459
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, anything in IECoreCycles::init() could need this special duplicate treatment, right? And we're just lucky that at the moment there's just some additional logging bits and bobs in there?

This got me wondering - do we even need to link the GafferCycles module to Cycles at all? It already links to libGafferCycles, so can't it get the Cycles symbols from there? I gave that a go here and it seemed to compile and run on Linux at least. Might be worth giving that a shot on Windows too? It'd certainly be less fragile if it works....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this offline and tried a few things to remove the need for linking the library in both modules, but unfortunately none worked. Without the linking the Python module to the various Cycles libs, there are 11 unresolved symbols. We also tried linking GafferCycles with /WHOLEARCHIVE and variants on /WHOLEARCHIVE:cycles_util but none worked, instead generating different unresolved symbols within GafferCycles.

Leaving as-is for now, with the hope that some day there will be a dynamic Cycles library we can link to.


py::scope().attr( "devices" ) = getDevices();
py::scope().attr( "nodes" ) = getNodes();
py::scope().attr( "shaders" ) = getShaders();
Expand Down
Loading