Cycles: update OSL to work with version 1.13.5

This keeps compatibility with older stable versions, but not
older unreleased versions in the 1.13.x series.

Ref #113157

Pull Request: https://projects.blender.org/blender/blender/pulls/116004
This commit is contained in:
Brecht Van Lommel 2023-12-10 17:08:47 +01:00 committed by Brecht Van Lommel
parent 12c4d22e6d
commit 798a0b301e
11 changed files with 115 additions and 13 deletions

View File

@ -313,7 +313,7 @@ void CPUDevice::get_cpu_kernel_thread_globals(
kernel_thread_globals.clear();
void *osl_memory = get_cpu_osl_memory();
for (int i = 0; i < info.cpu_threads; i++) {
kernel_thread_globals.emplace_back(kernel_globals, osl_memory, profiler);
kernel_thread_globals.emplace_back(kernel_globals, osl_memory, profiler, i);
}
}

View File

@ -12,14 +12,16 @@ CCL_NAMESPACE_BEGIN
CPUKernelThreadGlobals::CPUKernelThreadGlobals(const KernelGlobalsCPU &kernel_globals,
void *osl_globals_memory,
Profiler &cpu_profiler)
Profiler &cpu_profiler,
const int thread_index)
: KernelGlobalsCPU(kernel_globals), cpu_profiler_(cpu_profiler)
{
clear_runtime_pointers();
#ifdef WITH_OSL
OSLGlobals::thread_init(this, static_cast<OSLGlobals *>(osl_globals_memory));
OSLGlobals::thread_init(this, static_cast<OSLGlobals *>(osl_globals_memory), thread_index);
#else
(void)thread_index;
(void)osl_globals_memory;
#endif

View File

@ -23,7 +23,8 @@ class CPUKernelThreadGlobals : public KernelGlobalsCPU {
* without OSL support. Will avoid need to those unnamed pointers and casts. */
CPUKernelThreadGlobals(const KernelGlobalsCPU &kernel_globals,
void *osl_globals_memory,
Profiler &cpu_profiler);
Profiler &cpu_profiler,
const int thread_index);
~CPUKernelThreadGlobals();

View File

@ -49,6 +49,7 @@ typedef struct KernelGlobalsCPU {
OSLGlobals *osl = nullptr;
OSLShadingSystem *osl_ss = nullptr;
OSLThreadData *osl_tdata = nullptr;
int osl_thread_index = 0;
#endif
#ifdef __PATH_GUIDING__

View File

@ -110,7 +110,17 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const KernelGlobalsCPU *kg,
if (sd->object == OBJECT_NONE && sd->lamp == LAMP_NONE) {
/* background */
if (kg->osl->background_state) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl->background_state),
kg->osl_thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl->background_state), *globals);
#endif
}
}
else {
@ -150,8 +160,18 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const KernelGlobalsCPU *kg,
globals->dPdy = TO_VEC3(tmp_dP.dy);
}
/* execute bump shader */
/* execute bump shader */
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl->bump_state[shader]),
kg->osl_thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl->bump_state[shader]), *globals);
#endif
/* reset state */
sd->P = P;
@ -164,7 +184,17 @@ void osl_eval_nodes<SHADER_TYPE_SURFACE>(const KernelGlobalsCPU *kg,
/* surface shader */
if (kg->osl->surface_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl->surface_state[shader]),
kg->osl_thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl->surface_state[shader]), *globals);
#endif
}
}
@ -208,7 +238,17 @@ void osl_eval_nodes<SHADER_TYPE_VOLUME>(const KernelGlobalsCPU *kg,
int shader = sd->shader & SHADER_MASK;
if (kg->osl->volume_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl->volume_state[shader]),
kg->osl_thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl->volume_state[shader]), *globals);
#endif
}
/* flatten closure tree */
@ -245,7 +285,17 @@ void osl_eval_nodes<SHADER_TYPE_DISPLACEMENT>(const KernelGlobalsCPU *kg,
int shader = sd->shader & SHADER_MASK;
if (kg->osl->displacement_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE >= 11304
ss->execute(*octx,
*(kg->osl->displacement_state[shader]),
kg->osl_thread_index,
0,
*globals,
nullptr,
nullptr);
#else
ss->execute(octx, *(kg->osl->displacement_state[shader]), *globals);
#endif
}
/* get back position */

View File

@ -14,7 +14,7 @@
CCL_NAMESPACE_BEGIN
void OSLGlobals::thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals)
void OSLGlobals::thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals, const int thread_index)
{
/* no osl used? */
if (!osl_globals->use) {
@ -37,6 +37,7 @@ void OSLGlobals::thread_init(KernelGlobalsCPU *kg, OSLGlobals *osl_globals)
kg->osl_ss = (OSLShadingSystem *)ss;
kg->osl_tdata = tdata;
kg->osl_thread_index = thread_index;
}
void OSLGlobals::thread_free(KernelGlobalsCPU *kg)

View File

@ -45,7 +45,9 @@ struct OSLGlobals {
}
/* per thread data */
static void thread_init(struct KernelGlobalsCPU *kg, OSLGlobals *osl_globals);
static void thread_init(struct KernelGlobalsCPU *kg,
OSLGlobals *osl_globals,
const int thread_init);
static void thread_free(struct KernelGlobalsCPU *kg);
bool use;

View File

@ -52,6 +52,11 @@ ccl_device_inline void shaderdata_to_shaderglobals(KernelGlobals kg,
/* shader data to be used in services callbacks */
globals->renderstate = 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;

View File

@ -1165,7 +1165,18 @@ bool OSLRenderServices::get_userdata(
return false; /* disabled by lockgeom */
}
#if OSL_LIBRARY_VERSION_CODE >= 11100
#if OSL_LIBRARY_VERSION_CODE >= 11304
TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename,
OSL::ShadingContext *context,
const TextureOpt *opt)
{
return get_texture_handle(to_ustring(filename), context, opt);
}
TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSL::ustring filename,
OSL::ShadingContext *,
const TextureOpt *)
#elif OSL_LIBRARY_VERSION_CODE >= 11100
TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename,
OSL::ShadingContext *)
#else
@ -1616,7 +1627,17 @@ bool OSLRenderServices::environment(OSLUStringHash filename,
return status;
}
#if OSL_LIBRARY_VERSION_CODE >= 11100
#if OSL_LIBRARY_VERSION_CODE >= 11304
bool OSLRenderServices::get_texture_info(OSLUStringHash filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
OSL::ShaderGlobals *,
int subimage,
OSLUStringHash dataname,
TypeDesc datatype,
void *data,
OSLUStringHash *)
#elif OSL_LIBRARY_VERSION_CODE >= 11100
bool OSLRenderServices::get_texture_info(OSLUStringHash filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
@ -1627,7 +1648,7 @@ bool OSLRenderServices::get_texture_info(OSLUStringHash filename,
void *data,
OSLUStringHash *)
#else
bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *sg,
bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *,
OSLUStringHash filename,
TextureHandle *texture_handle,
int subimage,

View File

@ -189,7 +189,14 @@ class OSLRenderServices : public OSL::RendererServices {
void *val,
bool derivatives) override;
#if OSL_LIBRARY_VERSION_CODE >= 11100
#if OSL_LIBRARY_VERSION_CODE >= 11304
TextureSystem::TextureHandle *get_texture_handle(OSL::ustring filename,
OSL::ShadingContext *context,
const TextureOpt *options) override;
TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename,
OSL::ShadingContext *context,
const TextureOpt *options) override;
#elif OSL_LIBRARY_VERSION_CODE >= 11100
TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename,
OSL::ShadingContext *context) override;
#else
@ -245,7 +252,17 @@ class OSLRenderServices : public OSL::RendererServices {
float *dresultdt,
OSLUStringHash *errormessage) override;
#if OSL_LIBRARY_VERSION_CODE >= 11100
#if OSL_LIBRARY_VERSION_CODE >= 11304
bool get_texture_info(OSLUStringHash filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
OSL::ShaderGlobals *sg,
int subimage,
OSLUStringHash dataname,
TypeDesc datatype,
void *data,
OSLUStringHash *errormessage) override;
#elif OSL_LIBRARY_VERSION_CODE >= 11100
bool get_texture_info(OSLUStringHash filename,
TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,

View File

@ -86,8 +86,10 @@ struct ShaderGlobals {
ccl_private void *tracedata;
ccl_private void *objdata;
void *context;
#if OSL_LIBRARY_VERSION_CODE >= 11302
#if OSL_LIBRARY_VERSION_CODE >= 11304
void *shadingStateUniform;
int thread_index;
int shade_index;
#endif
void *renderer;
ccl_private void *object2common;