[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50394] trunk/blender/intern/cycles/kernel : Revert "Use one context per OSL thread.

Lukas Tönne lukas.toenne at gmail.com
Wed Sep 5 12:27:26 CEST 2012


I don't think this will be necessary. The problem here was that
contexts are created all the time, because the old ones were not
released properly in all cases. OSL has a simple pooling mechanism
that allows the reuse of contexts, so now that this is fixed (r50410)
the overhead should be minimal. We can still consider this of course,
but i guess it's not worth the effort.

On Wed, Sep 5, 2012 at 12:15 PM, Brecht Van Lommel
<brechtvanlommel at pandora.be> wrote:
> If it helps performance, there can only be 3 shaders active at any
> given time (one for path, another for light sampling, and third for
> indirect path with non-progressive sampling). So you could create 3
> contexts in advance.
>
> Brecht.
>
> On Tue, Sep 4, 2012 at 7:28 PM, Lukas Toenne
> <lukas.toenne at googlemail.com> wrote:
>> Revision: 50394
>>           http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50394
>> Author:   lukastoenne
>> Date:     2012-09-04 17:28:36 +0000 (Tue, 04 Sep 2012)
>> Log Message:
>> -----------
>> Revert "Use one context per OSL thread. Not sure if this actually works, but the simple renderer example in OSL does it this way."
>>
>> This does not actually work: The context must not be shared between threads, but using the same context between different samples actually seems to prevent OSL from switching between shaders. The proper solution would be to ensure memory pooling works correctly.
>>
>> This reverts commit 69f87e69258d6266dcb20f09f7e3d4021e663432.
>>
>> Modified Paths:
>> --------------
>>     trunk/blender/intern/cycles/kernel/kernel_emission.h
>>     trunk/blender/intern/cycles/kernel/kernel_path.h
>>     trunk/blender/intern/cycles/kernel/kernel_shader.h
>>     trunk/blender/intern/cycles/kernel/osl/osl_globals.h
>>     trunk/blender/intern/cycles/kernel/osl/osl_shader.cpp
>>     trunk/blender/intern/cycles/kernel/osl/osl_shader.h
>>
>> Modified: trunk/blender/intern/cycles/kernel/kernel_emission.h
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/kernel_emission.h        2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/kernel_emission.h        2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -54,6 +54,8 @@
>>                         eval = make_float3(0.0f, 0.0f, 0.0f);
>>         }
>>
>> +       shader_release(kg, &sd);
>> +
>>         return eval;
>>  }
>>
>> @@ -162,6 +164,7 @@
>>         ShaderData sd;
>>         shader_setup_from_background(kg, &sd, ray);
>>         float3 L = shader_eval_background(kg, &sd, path_flag);
>> +       shader_release(kg, &sd);
>>
>>  #ifdef __BACKGROUND_MIS__
>>         /* check if background light exists or if we should skip pdf */
>>
>> Modified: trunk/blender/intern/cycles/kernel/kernel_path.h
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/kernel_path.h    2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/kernel_path.h    2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -395,6 +395,8 @@
>>                 label = shader_bsdf_sample(kg, &sd, bsdf_u, bsdf_v, &bsdf_eval,
>>                         &bsdf_omega_in, &bsdf_domega_in, &bsdf_pdf);
>>
>> +               shader_release(kg, &sd);
>> +
>>                 if(bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval))
>>                         break;
>>
>> @@ -567,6 +569,8 @@
>>                 label = shader_bsdf_sample(kg, &sd, bsdf_u, bsdf_v, &bsdf_eval,
>>                         &bsdf_omega_in, &bsdf_domega_in, &bsdf_pdf);
>>
>> +               shader_release(kg, &sd);
>> +
>>                 if(bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval))
>>                         break;
>>
>> @@ -858,6 +862,7 @@
>>
>>                 /* continue in case of transparency */
>>                 throughput *= shader_bsdf_transparency(kg, &sd);
>> +               shader_release(kg, &sd);
>>
>>                 if(is_zero(throughput))
>>                         break;
>>
>> Modified: trunk/blender/intern/cycles/kernel/kernel_shader.h
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/kernel_shader.h  2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/kernel_shader.h  2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -773,5 +773,15 @@
>>  }
>>  #endif
>>
>> +/* Free ShaderData */
>> +
>> +__device void shader_release(KernelGlobals *kg, ShaderData *sd)
>> +{
>> +#ifdef __OSL__
>> +       if (kernel_osl_use(kg))
>> +               OSLShader::release(kg, sd);
>> +#endif
>> +}
>> +
>>  CCL_NAMESPACE_END
>>
>>
>> Modified: trunk/blender/intern/cycles/kernel/osl/osl_globals.h
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/osl/osl_globals.h        2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/osl/osl_globals.h        2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -64,7 +64,6 @@
>>         struct ThreadData {
>>                 OSL::ShaderGlobals globals;
>>                 OSL::PerThreadInfo *thread_info;
>> -               OSL::ShadingContext *ctx;
>>         };
>>
>>         static tls_ptr(ThreadData, thread_data);
>>
>> Modified: trunk/blender/intern/cycles/kernel/osl/osl_shader.cpp
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/osl/osl_shader.cpp       2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/osl/osl_shader.cpp       2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -42,7 +42,6 @@
>>
>>         memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals));
>>         tdata->thread_info = ss->create_thread_info();
>> -       tdata->ctx = ss->get_context(tdata->thread_info);
>>
>>         tls_set(kg->osl.thread_data, tdata);
>>
>> @@ -55,7 +54,6 @@
>>
>>         OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
>>
>> -       ss->release_context(tdata->ctx);
>>         ss->destroy_thread_info(tdata->thread_info);
>>
>>         delete tdata;
>> @@ -206,7 +204,7 @@
>>         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 = tdata->ctx;
>> +       OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
>>
>>         /* setup shader globals from shader data */
>>         sd->osl_ctx = ctx;
>> @@ -264,7 +262,7 @@
>>         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 = tdata->ctx;
>> +       OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
>>
>>         /* setup shader globals from shader data */
>>         sd->osl_ctx = ctx;
>> @@ -341,7 +339,7 @@
>>         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 = tdata->ctx;
>> +       OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
>>
>>         /* setup shader globals from shader data */
>>         sd->osl_ctx = ctx;
>> @@ -365,7 +363,7 @@
>>         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 = tdata->ctx;
>> +       OSL::ShadingContext *ctx = ss->get_context(tdata->thread_info);
>>
>>         /* setup shader globals from shader data */
>>         sd->osl_ctx = ctx;
>> @@ -381,6 +379,13 @@
>>         sd->P = TO_FLOAT3(globals->P);
>>  }
>>
>> +void OSLShader::release(KernelGlobals *kg, const ShaderData *sd)
>> +{
>> +       OSL::ShadingSystem *ss = kg->osl.ss;
>> +
>> +       ss->release_context((OSL::ShadingContext *)sd->osl_ctx);
>> +}
>> +
>>  /* BSDF Closure */
>>
>>  int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float randu, float randv, float3& eval, float3& omega_in, differential3& domega_in, float& pdf)
>>
>> Modified: trunk/blender/intern/cycles/kernel/osl/osl_shader.h
>> ===================================================================
>> --- trunk/blender/intern/cycles/kernel/osl/osl_shader.h 2012-09-04 17:09:40 UTC (rev 50393)
>> +++ trunk/blender/intern/cycles/kernel/osl/osl_shader.h 2012-09-04 17:28:36 UTC (rev 50394)
>> @@ -77,6 +77,9 @@
>>
>>         static float3 volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc,
>>                                         const float3 omega_in, const float3 omega_out);
>> +
>> +       /* release */
>> +       static void release(KernelGlobals *kg, const ShaderData *sd);
>>  };
>>
>>  CCL_NAMESPACE_END
>>
>> _______________________________________________
>> Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers


More information about the Bf-committers mailing list