77
88#include " oslexec_pvt.h"
99#include < OSL/genclosure.h>
10+ #include < OSL/rs_free_function.h>
1011
1112
1213OSL_NAMESPACE_BEGIN
1314namespace pvt {
1415
1516
1617
17- OSL_SHADEOP const ClosureColor *
18- osl_add_closure_closure (ShaderGlobals* sg , const ClosureColor* a ,
19- const ClosureColor* b )
18+ OSL_SHADEOP OSL_HOSTDEVICE const void *
19+ osl_add_closure_closure (OpaqueExecContextPtr oec , const void * a_ ,
20+ const void * b_ )
2021{
22+ const ClosureColor* a = (const ClosureColor*)a_;
23+ const ClosureColor* b = (const ClosureColor*)b_;
2124 if (a == NULL )
2225 return b;
2326 if (b == NULL )
2427 return a;
25- return sg->context ->closure_add_allot (a, b);
28+ ClosureAdd* add = (ClosureAdd*)rs_allocate_closure (oec, sizeof (ClosureAdd),
29+ alignof (ClosureAdd));
30+ if (add) {
31+ add->id = ClosureColor::ADD;
32+ add->closureA = a;
33+ add->closureB = b;
34+ }
35+ return add;
2636}
2737
2838
29- OSL_SHADEOP const ClosureColor *
30- osl_mul_closure_color (ShaderGlobals* sg, ClosureColor* a , const Color3* w )
39+ OSL_SHADEOP OSL_HOSTDEVICE const void *
40+ osl_mul_closure_color (OpaqueExecContextPtr oec, const void * a_ , const void * w_ )
3141{
42+ const ClosureColor* a = (const ClosureColor*)a_;
43+ const Color3* w = (const Color3*)w_;
3244 if (a == NULL )
3345 return NULL ;
3446 if (w->x == 0 .0f && w->y == 0 .0f && w->z == 0 .0f )
3547 return NULL ;
3648 if (w->x == 1 .0f && w->y == 1 .0f && w->z == 1 .0f )
3749 return a;
38- return sg->context ->closure_mul_allot (*w, a);
50+ ClosureMul* mul = (ClosureMul*)rs_allocate_closure (oec, sizeof (ClosureMul),
51+ alignof (ClosureMul));
52+ if (mul) {
53+ mul->id = ClosureColor::MUL;
54+ mul->weight = *w;
55+ mul->closure = a;
56+ }
57+ return mul;
3958}
4059
4160
42- OSL_SHADEOP const ClosureColor *
43- osl_mul_closure_float (ShaderGlobals* sg, ClosureColor* a , float w)
61+ OSL_SHADEOP OSL_HOSTDEVICE const void *
62+ osl_mul_closure_float (OpaqueExecContextPtr oec, const void * a_ , float w)
4463{
64+ const ClosureColor* a = (const ClosureColor*)a_;
4565 if (a == NULL )
4666 return NULL ;
4767 if (w == 0 .0f )
4868 return NULL ;
4969 if (w == 1 .0f )
5070 return a;
51- return sg->context ->closure_mul_allot (w, a);
71+ ClosureMul* mul = (ClosureMul*)rs_allocate_closure (oec, sizeof (ClosureMul),
72+ alignof (ClosureMul));
73+ if (mul) {
74+ mul->id = ClosureColor::MUL;
75+ mul->weight = Color3 (w);
76+ mul->closure = a;
77+ }
78+ return mul;
5279}
5380
5481
55- OSL_SHADEOP ClosureComponent *
56- osl_allocate_closure_component (ShaderGlobals* sg , int id, int size)
82+ OSL_SHADEOP OSL_HOSTDEVICE void *
83+ osl_allocate_closure_component (OpaqueExecContextPtr oec , int id, int size)
5784{
58- return sg->context ->closure_component_allot (id, size, Color3 (1 .0f ));
85+ // Allocate the component and the mul back to back
86+ const size_t needed = sizeof (ClosureComponent) + size;
87+ ClosureComponent* comp
88+ = (ClosureComponent*)rs_allocate_closure (oec, needed,
89+ alignof (ClosureComponent));
90+ if (comp) {
91+ comp->id = id;
92+ comp->w = Color3 (1 .0f );
93+ }
94+ return comp;
5995}
6096
6197
6298
63- OSL_SHADEOP ClosureColor *
64- osl_allocate_weighted_closure_component (ShaderGlobals* sg , int id, int size ,
65- const Color3* w )
99+ OSL_SHADEOP OSL_HOSTDEVICE void *
100+ osl_allocate_weighted_closure_component (OpaqueExecContextPtr oec , int id,
101+ int size, const void * w_ )
66102{
103+ const Color3* w = (const Color3*)w_;
67104 if (w->x == 0 .0f && w->y == 0 .0f && w->z == 0 .0f )
68105 return NULL ;
69- return sg->context ->closure_component_allot (id, size, *w);
106+ // Allocate the component and the mul back to back
107+ const size_t needed = sizeof (ClosureComponent) + size;
108+ ClosureComponent* comp
109+ = (ClosureComponent*)rs_allocate_closure (oec, needed,
110+ alignof (ClosureComponent));
111+ if (comp) {
112+ comp->id = id;
113+ comp->w = *w;
114+ }
115+ return comp;
70116}
71117
72118// Deprecated, remove when conversion from ustring to ustringhash is finished
73119OSL_SHADEOP const char *
74- osl_closure_to_string (ShaderGlobals* sg, ClosureColor* c )
120+ osl_closure_to_string (OpaqueExecContextPtr oec, const void * c_ )
75121{
122+ ShaderGlobals* sg = (ShaderGlobals*)oec;
123+ const ClosureColor* c = (const ClosureColor*)c_;
76124 // Special case for printing closures
77125 std::ostringstream stream;
78126 stream.imbue (std::locale::classic ()); // force C locale
@@ -82,8 +130,10 @@ osl_closure_to_string(ShaderGlobals* sg, ClosureColor* c)
82130}
83131
84132OSL_SHADEOP ustringhash_pod
85- osl_closure_to_ustringhash (ShaderGlobals* sg, ClosureColor* c )
133+ osl_closure_to_ustringhash (OpaqueExecContextPtr oec, const void * c_ )
86134{
135+ ShaderGlobals* sg = (ShaderGlobals*)oec;
136+ const ClosureColor* c = (const ClosureColor*)c_;
87137 // Special case for printing closures
88138 std::ostringstream stream;
89139 stream.imbue (std::locale::classic ()); // force C locale
0 commit comments