Use one context per OSL thread. Not sure if this actually works, but the simple rende...
authorLukas Toenne <lukas.toenne@googlemail.com>
Tue, 4 Sep 2012 08:53:47 +0000 (08:53 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Tue, 4 Sep 2012 08:53:47 +0000 (08:53 +0000)
intern/cycles/kernel/kernel_emission.h
intern/cycles/kernel/kernel_path.h
intern/cycles/kernel/kernel_shader.h
intern/cycles/kernel/osl/osl_globals.h
intern/cycles/kernel/osl/osl_shader.cpp
intern/cycles/kernel/osl/osl_shader.h

index 53d53b4bedd498b71aed4e21aaa56dec566fca45..9032d7d4a4109aedd15df0f41ed1ad121654079b 100644 (file)
@@ -54,8 +54,6 @@ __device float3 direct_emissive_eval(KernelGlobals *kg, float rando,
                        eval = make_float3(0.0f, 0.0f, 0.0f);
        }
 
-       shader_release(kg, &sd);
-
        return eval;
 }
 
@@ -164,7 +162,6 @@ __device float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag,
        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 */
index acf17e695e3e97712c47ed6d8a7355f3c40f92aa..fc67ca98039b33bdeabb68e21ae420df041e450e 100644 (file)
@@ -395,8 +395,6 @@ __device float4 kernel_path_progressive(KernelGlobals *kg, RNG *rng, int sample,
                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;
 
@@ -569,8 +567,6 @@ __device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, int sample, Ray
                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;
 
@@ -862,7 +858,6 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam
 
                /* continue in case of transparency */
                throughput *= shader_bsdf_transparency(kg, &sd);
-               shader_release(kg, &sd);
 
                if(is_zero(throughput))
                        break;
index 5ab3c2c25450718eab7835bedacca46efbe9d6a3..e3e45e62451dec8a3d5fc762fde905e7eae02db8 100644 (file)
@@ -773,15 +773,5 @@ __device void shader_merge_closures(KernelGlobals *kg, ShaderData *sd)
 }
 #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
 
index 075c68824e639ce581c650091ac3d2284d33617f..17cee67517793d8c2ede3507c95c6906802bc6b5 100644 (file)
@@ -64,6 +64,7 @@ struct OSLGlobals {
        struct ThreadData {
                OSL::ShaderGlobals globals;
                OSL::PerThreadInfo *thread_info;
+               OSL::ShadingContext *ctx;
        };
 
        static tls_ptr(ThreadData, thread_data);
index a7c21e7b595bcfbc3f0b001c2257258bb278c4be..7d6732b9e56b3ca762d51f9cda080d7abbac2e05 100644 (file)
@@ -42,6 +42,7 @@ void OSLShader::thread_init(KernelGlobals *kg)
 
        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);
 
@@ -54,6 +55,7 @@ void OSLShader::thread_free(KernelGlobals *kg)
 
        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;
@@ -204,7 +206,7 @@ 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 = tdata->ctx;
 
        /* setup shader globals from shader data */
        sd->osl_ctx = ctx;
@@ -262,7 +264,7 @@ 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 = tdata->ctx;
 
        /* setup shader globals from shader data */
        sd->osl_ctx = ctx;
@@ -339,7 +341,7 @@ 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 = tdata->ctx;
 
        /* setup shader globals from shader data */
        sd->osl_ctx = ctx;
@@ -363,7 +365,7 @@ 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 = tdata->ctx;
 
        /* setup shader globals from shader data */
        sd->osl_ctx = ctx;
@@ -379,13 +381,6 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
        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)
index 815557ed203a6d1d218b15547f18aca1334574c2..a888335aad6458a923c89d117715031ae6cccfd7 100644 (file)
@@ -77,9 +77,6 @@ public:
 
        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