Fix for OSL memory leak. The context creation for OSL is now done in the shader_setup_* functions, since it should specific to the sample being worked on. The the context release then happens in the kernel_shader functions after shader evaluation is done. Care has to be taken to ensure the shader_release function is also called in cases where the path integration is cancelled early, this was the main cause for unreleased contexts and subsequent new allocations.
This commit is contained in:
@@ -204,10 +204,9 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
|
||||
OSL::ShaderGlobals *globals = &tdata->globals;
|
||||
OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
|
||||
OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx;
|
||||
|
||||
/* setup shader globals from shader data */
|
||||
sd->osl_ctx = ctx;
|
||||
shaderdata_to_shaderglobals(kg, sd, path_flag, globals);
|
||||
|
||||
/* execute shader for this point */
|
||||
@@ -262,10 +261,9 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
|
||||
OSL::ShaderGlobals *globals = &tdata->globals;
|
||||
OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
|
||||
OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx;
|
||||
|
||||
/* setup shader globals from shader data */
|
||||
sd->osl_ctx = ctx;
|
||||
shaderdata_to_shaderglobals(kg, sd, path_flag, globals);
|
||||
|
||||
/* execute shader for this point */
|
||||
@@ -339,10 +337,9 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
|
||||
OSL::ShaderGlobals *globals = &tdata->globals;
|
||||
OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
|
||||
OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx;
|
||||
|
||||
/* setup shader globals from shader data */
|
||||
sd->osl_ctx = ctx;
|
||||
shaderdata_to_shaderglobals(kg, sd, path_flag, globals);
|
||||
|
||||
/* execute shader */
|
||||
@@ -363,10 +360,9 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
|
||||
OSL::ShaderGlobals *globals = &tdata->globals;
|
||||
OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
|
||||
OSL::ShadingContext *ctx = (OSL::ShadingContext *)sd->osl_ctx;
|
||||
|
||||
/* setup shader globals from shader data */
|
||||
sd->osl_ctx = ctx;
|
||||
shaderdata_to_shaderglobals(kg, sd, 0, globals);
|
||||
|
||||
/* execute shader */
|
||||
@@ -379,7 +375,15 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
|
||||
sd->P = TO_FLOAT3(globals->P);
|
||||
}
|
||||
|
||||
void OSLShader::release(KernelGlobals *kg, const ShaderData *sd)
|
||||
void OSLShader::init(KernelGlobals *kg, ShaderData *sd)
|
||||
{
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
|
||||
|
||||
sd->osl_ctx = ss->get_context(tdata->thread_info);
|
||||
}
|
||||
|
||||
void OSLShader::release(KernelGlobals *kg, ShaderData *sd)
|
||||
{
|
||||
OSL::ShadingSystem *ss = kg->osl.ss;
|
||||
|
||||
|
Reference in New Issue
Block a user