Skip to content

Commit

Permalink
Merge remote-tracking branch 'b/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Jan 30, 2025
2 parents 1616a50 + 8a2336b commit 0e82f56
Show file tree
Hide file tree
Showing 114 changed files with 2,609 additions and 1,534 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ Ensure string operations on fixed size buffers \
mark_as_advanced(WITH_STRSIZE_DEBUG)

# Compiler tool-chain.
if(UNIX)
if(UNIX AND NOT APPLE)
if(CMAKE_COMPILER_IS_GNUCC)
option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
mark_as_advanced(WITH_LINKER_GOLD)
Expand Down
20 changes: 14 additions & 6 deletions build_files/cmake/Modules/FindOSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ find_path(OSL_SHADER_DIR
shaders
)

# handle the QUIETLY and REQUIRED arguments and set OSL_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OSL DEFAULT_MSG _osl_LIBRARIES OSL_INCLUDE_DIR OSL_COMPILER)

if(OSL_FOUND)
if(OSL_INCLUDE_DIR)
set(OSL_LIBRARIES ${_osl_LIBRARIES})
set(OSL_INCLUDE_DIRS ${OSL_INCLUDE_DIR})

Expand All @@ -119,8 +114,21 @@ if(OSL_FOUND)
"\\1" OSL_LIBRARY_VERSION_MINOR ${OSL_LIBRARY_VERSION_MINOR})
string(REGEX REPLACE ".*#define[ \t]+OSL_LIBRARY_VERSION_PATCH[ \t]+([.0-9]+).*"
"\\1" OSL_LIBRARY_VERSION_PATCH ${OSL_LIBRARY_VERSION_PATCH})
set(OSL_VERSION "${OSL_LIBRARY_VERSION_MAJOR}.${OSL_LIBRARY_VERSION_MINOR}.${OSL_LIBRARY_VERSION_PATCH}")
endif()

# handle the QUIETLY and REQUIRED arguments and set OSL_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OSL
REQUIRED_VARS
OSL_LIBRARIES
OSL_INCLUDE_DIRS
OSL_COMPILER
VERSION_VAR
OSL_VERSION
)

mark_as_advanced(
OSL_INCLUDE_DIR
OSL_SHADER_DIR
Expand Down
27 changes: 1 addition & 26 deletions build_files/cmake/platform/platform_apple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ if(WITH_LLVM)
endif()

if(WITH_CYCLES AND WITH_CYCLES_OSL)
find_package(OSL REQUIRED)
find_package(OSL 1.13.4 REQUIRED)
endif()
add_bundled_libraries(osl/lib)

Expand Down Expand Up @@ -477,31 +477,6 @@ if(WITH_COMPILER_CCACHE)
endif()
endif()

unset(_custom_LINKER_FUSE_FLAG)
if(WITH_LINKER_LLD)
find_program(LLD_PROGRAM ld.lld)
if(LLD_PROGRAM)
set(_custom_LINKER_FUSE_FLAG "-fuse-ld=lld")
else()
message(WARNING "LLD linker NOT found, disabling WITH_LINKER_LLD")
set(WITH_LINKER_LLD OFF)
endif()
endif()
if(WITH_LINKER_MOLD)
find_program(MOLD_PROGRAM mold)
if(MOLD_PROGRAM)
set(_custom_LINKER_FUSE_FLAG "-fuse-ld=mold")
else()
message(WARNING "Mold linker NOT found, disabling WITH_LINKER_MOLD")
set(WITH_LINKER_MOLD OFF)
endif()
endif()

if(_custom_LINKER_FUSE_FLAG)
add_link_options(${_custom_LINKER_FUSE_FLAG})
endif()


if(WITH_COMPILER_ASAN)
list(APPEND PLATFORM_BUNDLED_LIBRARIES ${COMPILER_ASAN_LIBRARY})
endif()
Expand Down
2 changes: 1 addition & 1 deletion build_files/cmake/platform/platform_unix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ if(WITH_CYCLES AND WITH_CYCLES_OSL)
set(OSL_ROOT ${CYCLES_OSL})
endif()
endif()
find_package_wrapper(OSL)
find_package_wrapper(OSL 1.13.4)
set_and_warn_library_found("OSL" OSL_FOUND WITH_CYCLES_OSL)

if(OSL_FOUND)
Expand Down
4 changes: 2 additions & 2 deletions build_files/cmake/platform/platform_win32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ remove_cc_flag(
)

if(MSVC_CLANG) # Clangs version of cl doesn't support all flags
string(APPEND CMAKE_CXX_FLAGS " ${CXX_WARN_FLAGS} /MP /nologo /J /Gd /EHsc -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference /clang:-funsigned-char /clang:-fno-strict-aliasing /clang:-ffp-contract=off")
string(APPEND CMAKE_C_FLAGS " /MP /nologo /J /Gd -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference /clang:-funsigned-char /clang:-fno-strict-aliasing /clang:-ffp-contract=off")
string(APPEND CMAKE_CXX_FLAGS " ${CXX_WARN_FLAGS} /MP /nologo /J /Gd /showFilenames /EHsc -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference /clang:-funsigned-char /clang:-fno-strict-aliasing /clang:-ffp-contract=off")
string(APPEND CMAKE_C_FLAGS " /MP /nologo /J /Gd /showFilenames -Wno-unused-command-line-argument -Wno-microsoft-enum-forward-reference /clang:-funsigned-char /clang:-fno-strict-aliasing /clang:-ffp-contract=off")
else()
string(APPEND CMAKE_CXX_FLAGS " /nologo /J /Gd /MP /EHsc /bigobj")
string(APPEND CMAKE_C_FLAGS " /nologo /J /Gd /MP /bigobj")
Expand Down
14 changes: 6 additions & 8 deletions intern/cycles/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ set(SRC_KERNEL_DEVICE_OPTIX
if(WITH_CYCLES_OSL)
math(EXPR OSL_LIBRARY_VERSION_CODE "${OSL_LIBRARY_VERSION_MAJOR} * 10000 + ${OSL_LIBRARY_VERSION_MINOR} * 100 + ${OSL_LIBRARY_VERSION_PATCH}")

if(OSL_LIBRARY_VERSION_CODE GREATER_EQUAL 11300)
set(SRC_KERNEL_DEVICE_OPTIX
${SRC_KERNEL_DEVICE_OPTIX}
osl/services_optix.cu
device/optix/kernel_osl.cu
)
endif()
set(SRC_KERNEL_DEVICE_OPTIX
${SRC_KERNEL_DEVICE_OPTIX}
osl/services_optix.cu
device/optix/kernel_osl.cu
)
endif()

set(SRC_KERNEL_DEVICE_ONEAPI
Expand Down Expand Up @@ -1002,7 +1000,7 @@ if(WITH_CYCLES_DEVICE_OPTIX AND WITH_CYCLES_CUDA_BINARIES)
kernel_optix_shader_raytrace
"device/optix/kernel_shader_raytrace.cu"
"--keep-device-functions")
if(WITH_CYCLES_OSL AND OSL_LIBRARY_VERSION_CODE GREATER_EQUAL 11300)
if(WITH_CYCLES_OSL)
cycles_optix_kernel_add(
kernel_optix_osl
"device/optix/kernel_osl.cu"
Expand Down
22 changes: 1 addition & 21 deletions intern/cycles/kernel/osl/closures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,13 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const ThreadKernelGlobalsCPU *kg,
if (sd->object == OBJECT_NONE && sd->lamp == LAMP_NONE) {
/* background */
if (kg->osl.globals->background_state) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl.globals->background_state),
kg->osl.thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl.globals->background_state), *globals);
#endif
}
}
else {
Expand Down Expand Up @@ -158,18 +154,14 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const ThreadKernelGlobalsCPU *kg,
globals->dPdy = TO_VEC3(tmp_dP.dy);
}

/* execute bump shader */
#if OSL_LIBRARY_VERSION_CODE >= 11304
/* execute bump shader */
ss->execute(*octx,
*(kg->osl.globals->bump_state[shader]),
kg->osl.thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl.globals->bump_state[shader]), *globals);
#endif

/* reset state */
sd->P = P;
Expand All @@ -182,17 +174,13 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const ThreadKernelGlobalsCPU *kg,

/* surface shader */
if (kg->osl.globals->surface_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl.globals->surface_state[shader]),
kg->osl.thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl.globals->surface_state[shader]), *globals);
#endif
}
}

Expand Down Expand Up @@ -234,17 +222,13 @@ void osl_eval_nodes<SHADER_TYPE_VOLUME>(const ThreadKernelGlobalsCPU *kg,
const int shader = sd->shader & SHADER_MASK;

if (kg->osl.globals->volume_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl.globals->volume_state[shader]),
kg->osl.thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl.globals->volume_state[shader]), *globals);
#endif
}

/* flatten closure tree */
Expand Down Expand Up @@ -279,17 +263,13 @@ void osl_eval_nodes<SHADER_TYPE_DISPLACEMENT>(const ThreadKernelGlobalsCPU *kg,
const int shader = sd->shader & SHADER_MASK;

if (kg->osl.globals->displacement_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl.globals->displacement_state[shader]),
kg->osl.thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl.globals->displacement_state[shader]), *globals);
#endif
}

/* get back position */
Expand Down
65 changes: 64 additions & 1 deletion intern/cycles/kernel/osl/closures_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,40 @@ ccl_device void osl_closure_sheen_setup(KernelGlobals kg,
}
}

/* MaterialX compatibility */
ccl_device void osl_closure_sheen_bsdf_setup(KernelGlobals kg,
ccl_private ShaderData *sd,
const uint32_t path_flag,
const float3 weight,
const ccl_private SheenBSDFClosure *closure,
float3 *layer_albedo)
{
osl_zero_albedo(layer_albedo);

if (osl_closure_skip(kg, sd, path_flag, LABEL_DIFFUSE)) {
return;
}

ccl_private SheenBsdf *bsdf = (ccl_private SheenBsdf *)bsdf_alloc(
sd, sizeof(SheenBsdf), rgb_to_spectrum(weight * closure->albedo));
if (!bsdf) {
return;
}

bsdf->N = safe_normalize_fallback(closure->N, sd->N);
bsdf->roughness = closure->roughness;

const int sheen_flag = bsdf_sheen_setup(kg, sd, bsdf);

if (sheen_flag) {
sd->flag |= sheen_flag;

if (layer_albedo != nullptr) {
*layer_albedo = bsdf->weight * closure->albedo;
}
}
}

ccl_device void osl_closure_diffuse_toon_setup(KernelGlobals kg,
ccl_private ShaderData *sd,
const uint32_t path_flag,
Expand Down Expand Up @@ -920,7 +954,6 @@ ccl_device void osl_closure_bssrdf_setup(KernelGlobals kg,

bssrdf->radius = closure->radius;

/* create one closure per color channel */
bssrdf->albedo = closure->albedo;
bssrdf->N = maybe_ensure_valid_specular_reflection(sd,
safe_normalize_fallback(closure->N, sd->N));
Expand All @@ -931,6 +964,36 @@ ccl_device void osl_closure_bssrdf_setup(KernelGlobals kg,
sd->flag |= bssrdf_setup(sd, bssrdf, path_flag, type);
}

/* MaterialX-compatible subsurface_bssrdf */
ccl_device void osl_closure_subsurface_bssrdf_setup(
KernelGlobals kg,
ccl_private ShaderData *sd,
const uint32_t path_flag,
const float3 weight,
const ccl_private SubsurfaceBSSRDFClosure *closure,
float3 *layer_albedo)
{
ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, rgb_to_spectrum(weight));
if (!bssrdf) {
return;
}

#if OSL_LIBRARY_VERSION_CODE >= 11401
bssrdf->radius = closure->radius;
#else
bssrdf->radius = closure->transmission_depth * closure->transmission_color;
#endif

bssrdf->albedo = closure->albedo;
bssrdf->N = maybe_ensure_valid_specular_reflection(sd,
safe_normalize_fallback(closure->N, sd->N));
bssrdf->alpha = 1.0f;
bssrdf->ior = 1.4f;
bssrdf->anisotropy = closure->anisotropy;

sd->flag |= bssrdf_setup(sd, bssrdf, path_flag, CLOSURE_BSSRDF_RANDOM_WALK_ID);
}

/* Hair */

ccl_device void osl_closure_hair_reflection_setup(KernelGlobals kg,
Expand Down
18 changes: 18 additions & 0 deletions intern/cycles/kernel/osl/closures_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ OSL_CLOSURE_STRUCT_BEGIN(Sheen, sheen)
OSL_CLOSURE_STRUCT_MEMBER(Sheen, FLOAT, float, roughness, nullptr)
OSL_CLOSURE_STRUCT_END(Sheen, sheen)

OSL_CLOSURE_STRUCT_BEGIN(SheenBSDF, sheen_bsdf)
OSL_CLOSURE_STRUCT_MEMBER(SheenBSDF, VECTOR, packed_float3, N, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(SheenBSDF, VECTOR, packed_float3, albedo, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(SheenBSDF, FLOAT, float, roughness, nullptr)
OSL_CLOSURE_STRUCT_END(SheenBSDF, sheen_bsdf)

OSL_CLOSURE_STRUCT_BEGIN(DiffuseToon, diffuse_toon)
OSL_CLOSURE_STRUCT_MEMBER(DiffuseToon, VECTOR, packed_float3, N, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(DiffuseToon, FLOAT, float, size, nullptr)
Expand Down Expand Up @@ -184,6 +190,18 @@ OSL_CLOSURE_STRUCT_BEGIN(BSSRDF, bssrdf)
OSL_CLOSURE_STRUCT_MEMBER(BSSRDF, FLOAT, float, anisotropy, "anisotropy")
OSL_CLOSURE_STRUCT_END(BSSRDF, bssrdf)

OSL_CLOSURE_STRUCT_BEGIN(SubsurfaceBSSRDF, subsurface_bssrdf)
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, VECTOR, packed_float3, N, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, VECTOR, packed_float3, albedo, nullptr)
#if OSL_LIBRARY_VERSION_CODE >= 11401
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, VECTOR, packed_float3, radius, nullptr)
#else
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, FLOAT, float, transmission_depth, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, VECTOR, packed_float3, transmission_color, nullptr)
#endif
OSL_CLOSURE_STRUCT_MEMBER(SubsurfaceBSSRDF, FLOAT, float, anisotropy, nullptr)
OSL_CLOSURE_STRUCT_END(SubsurfaceBSSRDF, subsurface_bssrdf)

OSL_CLOSURE_STRUCT_BEGIN(HairReflection, hair_reflection)
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, VECTOR, packed_float3, N, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(HairReflection, FLOAT, float, roughness1, nullptr)
Expand Down
17 changes: 3 additions & 14 deletions intern/cycles/kernel/osl/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,16 @@

CCL_NAMESPACE_BEGIN

#if OSL_LIBRARY_VERSION_CODE >= 11302
using OSLUStringHash = OSL::ustringhash;
# if OSL_LIBRARY_VERSION_CODE >= 11400
#if OSL_LIBRARY_VERSION_CODE >= 11400
using OSLUStringRep = OSL::ustringhash;
# else
#else
using OSLUStringRep = OSL::ustringrep;
# endif
#endif

static inline OSL::ustring to_ustring(OSLUStringHash h)
{
return OSL::ustring::from_hash(h.hash());
}

#else
using OSLUStringHash = OSL::ustring;
using OSLUStringRep = OSL::ustring;

static inline OSL::ustring to_ustring(OSLUStringHash h)
{
return h;
}
#endif

CCL_NAMESPACE_END
2 changes: 0 additions & 2 deletions intern/cycles/kernel/osl/osl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ ccl_device_inline void shaderdata_to_shaderglobals(KernelGlobals kg,

/* shader data to be used in services callbacks */
globals->sd = sd;
#if OSL_LIBRARY_VERSION_CODE >= 11304
globals->shadingStateUniform = nullptr;
globals->thread_index = 0;
globals->shade_index = 0;
#endif

/* hacky, we leave it to services to fetch actual object matrix */
globals->shader2common = sd;
Expand Down
Loading

0 comments on commit 0e82f56

Please sign in to comment.