9#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
10# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11# pragma GCC diagnostic ignored "-Wuninitialized"
36 : OSL::RendererServices(reinterpret_cast<OSL::TextureSystem *>(1)), device_type_(device_type)
45 if (feature ==
"OptiX") {
56 OSL::Matrix44 &result,
57 OSL::TransformationPtr ,
61 if (globals ==
nullptr || globals->
sd ==
nullptr) {
65 globals->
kg, globals->
sd,
reinterpret_cast<float *
>(&result), time);
69 OSL::Matrix44 &result,
70 OSL::TransformationPtr ,
74 if (globals ==
nullptr || globals->
sd ==
nullptr) {
78 globals->
kg, globals->
sd,
reinterpret_cast<float *
>(&result), time);
82 OSL::Matrix44 &result,
91 OSL::Matrix44 &result,
100 OSL::Matrix44 &result,
101 OSL::TransformationPtr )
104 if (globals ==
nullptr || globals->
sd ==
nullptr) {
108 globals->
kg, globals->
sd,
reinterpret_cast<float *
>(&result));
112 OSL::Matrix44 &result,
113 OSL::TransformationPtr )
116 if (globals ==
nullptr || globals->
sd ==
nullptr) {
120 globals->
kg, globals->
sd,
reinterpret_cast<float *
>(&result));
124 OSL::Matrix44 &result,
132 OSL::Matrix44 &result,
158 globals->
kg, globals, sd, name, type, derivatives, val);
169 globals->
kg, globals, sd, name, type, derivatives, val);
186 if (globals ==
nullptr) {
190 return get_attribute(globals, globals->
sd, derivatives, object_name, type, name, val);
202 if (globals ==
nullptr) {
214 if (object_name != DeviceStrings::u_empty) {
215 const OSLGlobals::ObjectNameMap::iterator it = kg->osl.globals->object_name_map.find(
218 if (it == kg->osl.globals->object_name_map.end()) {
241 OSL::ShaderGlobals * ,
248 OSLUStringHash filename, OSL::ShadingContext *context,
const OSL::TextureOpt *opt)
257 image_managers_[context] = image_manager;
263 image_managers_.erase(context);
266ImageManager *OSLRenderServices::image_manager_find(
const OSL::ShadingContext *context)
269 auto it = image_managers_.find(context);
270 return (it != image_managers_.end()) ? it->second :
nullptr;
274 OSL::ustring filename, OSL::ShadingContext *context,
const OSL::TextureOpt * )
276 ImageManager *image_manager = image_manager_find(context);
277 if (image_manager ==
nullptr) {
278 LOG_WARNING <<
"Open Shading Language texture call can not resolve " << filename.c_str()
279 <<
", filename must be a compile-time constant";
286 auto [it, inserted] =
textures.find_or_insert({filename, image_manager},
301 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
318 TextureHandle *texture_handle,
321 OSL::ShaderGlobals *sg,
334 if (texture_handle ==
nullptr) {
335 if (texture_filenames_seen_.insert(filename).second) {
336 LOG_WARNING <<
"Open Shading Language texture call can not resolve " << filename.c_str()
337 <<
", filename must be a compile-time constant";
359 TextureHandle *texture_handle,
362 OSL::ShaderGlobals *sg,
364 const OSL::Vec3 &
dPdx,
365 const OSL::Vec3 &
dPdy,
366 const OSL::Vec3 &dPdz,
374 if (texture_handle ==
nullptr) {
375 if (texture_filenames_seen_.insert(filename).second) {
376 LOG_WARNING <<
"Open Shading Language texture3d call can not resolve " << filename.c_str()
377 <<
", filename must be a constant";
396 TextureHandle *texture_handle,
399 OSL::ShaderGlobals *sg,
401 const OSL::Vec3 &dRdx,
402 const OSL::Vec3 &dRdy,
409 if (texture_handle ==
nullptr) {
410 if (texture_filenames_seen_.insert(filename).second) {
411 LOG_WARNING <<
"Open Shading Language environment call can not resolve " << filename.c_str()
412 <<
", filename must be a constant string after optimization";
431 TextureHandle *texture_handle,
433 OSL::ShaderGlobals *sg,
436 const TypeDesc datatype,
440 if (texture_handle ==
nullptr) {
441 if (texture_filenames_seen_.insert(filename).second) {
442 LOG_WARNING <<
"Open Shading Language gettextureinfo call can not resolve "
443 << filename.c_str() <<
", filename must be a constant";
452 kg, texture_handle,
make_float2(0.0f, 0.0f),
false, dataname, datatype, data);
456 TextureHandle *texture_handle,
460 OSL::ShaderGlobals *sg,
463 const TypeDesc datatype,
467 if (texture_handle ==
nullptr) {
468 if (texture_filenames_seen_.insert(filename).second) {
469 LOG_WARNING <<
"Open Shading Language gettextureinfo call can not resolve "
470 << filename.c_str() <<
", filename must be a constant";
479 kg, texture_handle,
make_float2(s, t),
true, dataname, datatype, data);
488#
if OSL_LIBRARY_VERSION_CODE >= 11400
502#
if OSL_LIBRARY_VERSION_CODE >= 11400
527 OSL::ShaderGlobals *sg,
529 const OSL::Vec3 &
dPdx,
530 const OSL::Vec3 &
dPdy,
532 const OSL::Vec3 &dRdx,
533 const OSL::Vec3 &dRdy)
537 ShaderData *sd = globals->
sd;
557 if (ray.
tmin == 0.0f) {
559 if (ray.
P == sd->P) {
576 OSLTraceData *tracedata = globals->
tracedata;
577 tracedata->ray = ray;
578 tracedata->setup =
false;
579 tracedata->init =
true;
580 tracedata->hit =
false;
581 tracedata->self_hit =
false;
588 if (
options.traceset == DeviceStrings::u_traceset_only_local) {
590 scene_intersect_local(kg, &ray, &local_isect, sd->object,
nullptr, 1);
592 tracedata->isect = local_isect.
hits[0];
593 tracedata->hit =
true;
594 tracedata->self_hit =
true;
600 if (
options.traceset == DeviceStrings::u_traceset_raycast) {
603 tracedata->hit =
scene_intersect(kg, &ray, visibility, &tracedata->isect);
604 if (tracedata->hit) {
605 tracedata->self_hit = tracedata->isect.object == sd->object;
608 return tracedata->hit;
620 OSLTraceData *tracedata = globals->
tracedata;
622 if (source == DeviceStrings::u_trace && tracedata->init) {
623 if (name == DeviceStrings::u_hit) {
626 if (tracedata->hit) {
627 if (name == DeviceStrings::u_hitdist) {
628 return set_attribute(tracedata->isect.t, type, derivatives, val);
631 ShaderData *sd = &tracedata->sd;
633 if (!tracedata->setup) {
636 tracedata->setup =
true;
639 if (name == DeviceStrings::u_hitself) {
640 return set_attribute(
float(tracedata->self_hit), type, derivatives, val);
642 if (name == DeviceStrings::u_N) {
645 if (name == DeviceStrings::u_Ng) {
648 if (name == DeviceStrings::u_P) {
652 if (name == DeviceStrings::u_I) {
656 if (name == DeviceStrings::u_u) {
659 if (name == DeviceStrings::u_v) {
663 return get_attribute(globals, sd, derivatives, DeviceStrings::u_empty, type, name, val);
ImageHandle add_image(const string &filename, const ImageParams ¶ms)
static bool get_background_attribute(ShaderGlobals *globals, ShaderData *sd, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
bool get_texture_info(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, OSL::ShaderGlobals *sg, const int subimage, OSLUStringHash dataname, const TypeDesc datatype, void *data, OSLUStringHash *errormessage) override
bool is_udim(OSL::TextureSystem::TextureHandle *texture_handle) override
bool texture(OSLUStringHash filename, OSL::TextureSystem::TextureHandle *texture_handle, TexturePerthread *texture_thread_info, OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const float s, const float t, const float dsdx, const float dtdx, const float dsdy, const float dtdy, const int nchannels, float *result, float *dresultds, float *dresultdt, OSLUStringHash *errormessage) override
bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
int pointcloud_search(OSL::ShaderGlobals *sg, OSLUStringHash filename, const OSL::Vec3 ¢er, const float radius, const int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset) override
~OSLRenderServices() override
int supports(string_view feature) const override
static bool get_object_standard_attribute(ShaderGlobals *globals, ShaderData *sd, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
static bool get_camera_attribute(ShaderGlobals *globals, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
OSLRenderServices(const int device_type)
int pointcloud_get(OSL::ShaderGlobals *sg, OSLUStringHash filename, size_t *indices, const int count, OSLUStringHash attr_name, const TypeDesc attr_type, void *out_data) override
OSLTextureHandleMap textures
bool pointcloud_write(OSL::ShaderGlobals *sg, OSLUStringHash filename, const OSL::Vec3 &pos, const int nattribs, const OSLUStringRep *names, const TypeDesc *types, const void **data) override
bool environment(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, const int nchannels, float *result, float *dresultds, float *dresultdt, OSLUStringHash *errormessage) override
bool get_array_attribute(OSL::ShaderGlobals *sg, bool derivatives, OSLUStringHash object, const TypeDesc type, OSLUStringHash name, const int index, void *val) override
bool get_attribute(OSL::ShaderGlobals *sg, bool derivatives, OSLUStringHash object, const TypeDesc type, OSLUStringHash name, void *val) override
bool get_userdata(bool derivatives, OSLUStringHash name, const TypeDesc type, OSL::ShaderGlobals *sg, void *val) override
bool trace(TraceOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy) override
bool texture3d(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, const OSL::Vec3 &dPdz, const int nchannels, float *result, float *dresultds, float *dresultdt, float *dresultdr, OSLUStringHash *errormessage) override
void image_manager_remove(const OSL::ShadingContext *context)
bool getmessage(OSL::ShaderGlobals *sg, OSLUStringHash source, OSLUStringHash name, const TypeDesc type, void *val, bool derivatives) override
void image_manager_add(const OSL::ShadingContext *context, ImageManager *image_manager)
OSL::TextureSystem::TextureHandle * get_texture_handle(OSL::ustring filename, OSL::ShadingContext *context, const OSL::TextureOpt *options) override
bool good(OSL::TextureSystem::TextureHandle *texture_handle) override
ccl_device_forceinline float3 dPdx(const ccl_private ShaderData *sd)
ccl_device_forceinline float3 dPdy(const ccl_private ShaderData *sd)
CCL_NAMESPACE_BEGIN struct Options options
#define CCL_NAMESPACE_END
ccl_device_forceinline float differential_make_compact(const float dD)
ccl_device_forceinline differential3 differential_from_compact(const float3 D, const float dD)
ccl_device_intersect bool scene_intersect(KernelGlobals kg, const ccl_private Ray *ray, const uint visibility, ccl_private Intersection *isect)
CCL_NAMESPACE_BEGIN ccl_device_forceinline bool is_attribute_found(const ccl_private AttributeDescriptor &desc)
ccl_device_inline AttributeDescriptor find_attribute(const ccl_global AttributeMap *attributes_map, uint attr_offset, const int prim, const uint64_t id)
#define OSL_TEXTURE_HANDLE_ENCODE(type, id)
#define OSL_TEXTURE_HANDLE_TYPE(handle)
#define OSL_TEXTURE_HANDLE_ID(handle)
uint32_t PathRayVisibility
@ PATH_RAY_VISIBILITY_ALL
@ PATH_RAY_VISIBILITY_RAYCAST
@ PATH_RAY_VISIBILITY_SHADOW_OPAQUE
#define KERNEL_IMAGE_NONE
OSL::ustringhash OSLUStringHash
OSL::ustringrep OSLUStringRep
ccl_device_inline bool osl_shared_get_object_standard_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private ShaderData *sd, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool osl_shared_get_object_inverse_matrix_motion(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res, float time)
ccl_device_inline bool osl_shared_get_named_matrix(KernelGlobals kg, DeviceString from, ccl_private float *res)
ccl_device_inline bool osl_shared_get_object_matrix_motion(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res, float time)
ccl_device bool osl_shared_environment(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, float3 R, float3 dRdx, float3 dRdy, int nchannels, float *result)
ccl_device bool osl_shared_get_texture_info(KernelGlobals kg, ccl_private void *texture_handle, const float2 uv, const bool use_uv, DeviceString dataname, const TypeDesc datatype, void *data)
ccl_device_inline bool osl_shared_get_camera_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool set_attribute(const dual< T > v, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool osl_shared_get_background_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private ShaderData *sd, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool osl_shared_get_object_matrix(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res)
ccl_device bool osl_shared_texture3d(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, float3 P, float3, float3, float3, int nchannels, float *result)
ccl_device_inline bool osl_shared_get_object_attribute(KernelGlobals kg, ccl_private ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device bool osl_shared_texture(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, float *result)
ccl_device_inline bool osl_shared_get_named_inverse_matrix(KernelGlobals kg, DeviceString to, ccl_private float *res)
ccl_device_inline bool osl_shared_get_object_inverse_matrix(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res)
ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, const ccl_private Ray *ccl_restrict ray, const ccl_private Intersection *ccl_restrict isect)
Intersection hits[LOCAL_MAX_HITS]
OSLTextureHandle(const OSLTextureHandleType type, const int id=-1)
ccl_private ShaderData * sd
const ThreadKernelGlobalsCPU * kg
ccl_private OSLTraceData * tracedata
std::unique_lock< std::mutex > thread_scoped_lock