9#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
10# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11# pragma GCC diagnostic ignored "-Wuninitialized"
52 memcpy((
float *)&m, (
const float *)&t,
sizeof(m));
58 memcpy((
float *)&m, (
const float *)&t,
sizeof(m));
132 : OSL::RendererServices(texture_system), device_type_(device_type)
139 LOG_INFO <<
"OSL texture system stats:\n" << m_texturesys->getstats();
146 if (feature ==
"OptiX") {
158 OSL::TransformationPtr ,
163 if (globals ==
nullptr || globals->
sd ==
nullptr) {
169 const ShaderData *sd = globals->
sd;
171 const int object = sd->object;
174#ifdef __OBJECT_MOTION__
177 if (time == sd->time) {
196 OSL::TransformationPtr ,
201 if (globals ==
nullptr || globals->
sd ==
nullptr) {
207 const ShaderData *sd = globals->
sd;
209 const int object = sd->object;
212#ifdef __OBJECT_MOTION__
215 if (time == sd->time) {
298 OSL::TransformationPtr )
302 if (globals ==
nullptr || globals->
sd ==
nullptr) {
308 const ShaderData *sd = globals->
sd;
310 const int object = sd->object;
324 OSL::TransformationPtr )
328 if (globals ==
nullptr || globals->
sd ==
nullptr) {
334 const ShaderData *sd = globals->
sd;
336 const int object = sd->object;
422 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
426 if (type == TypeFloat) {
443 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
447 if (type == TypeFloat) {
464 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
468 if (type == TypeFloat) {
493 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
497 if (type == TypeFloat) {
515 if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
516 int *ival = (
int *)val;
535 if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
554 if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
555 float *fval = (
float *)val;
561 if (type.arraylen > 3) {
562 memset(fval + 3 * 3, 0,
sizeof(
float) * 3 * (type.arraylen - 3));
565 memset(fval + type.arraylen * 3, 0,
sizeof(
float) * 2 * 3 * type.arraylen);
576 if (type == TypeMatrix) {
588 const TypeDesc &type,
594 if (primitive_is_volume_attribute(sd)) {
595 data.val = primitive_volume_attribute<T>(kg, sd, desc,
true);
608 const TypeDesc &type,
634 ShaderData *sd = globals->
sd;
750 const ustring object_name = kg->osl.globals->object_names[sd->object];
764 const float f = curve_thickness(kg, sd);
768 const float3 f = curve_tangent_normal(sd);
772 const float f = curve_random(kg, sd);
783 const float f = point_radius(kg, sd);
787 const float3 f = point_position(kg, sd);
791 const float f = point_random(kg, sd);
820 ShaderData *sd = globals->
sd;
826 const float f = sd->ray_length;
830#define READ_PATH_STATE(elem) \
831 ((state != nullptr) ? state->path.elem : \
832 (shadow_state != nullptr) ? shadow_state->shadow_path.elem : \
873#undef READ_PATH_STATE
938 if (globals ==
nullptr) {
942 ShaderData *sd = globals->
sd;
952 const OSLGlobals::ObjectNameMap::iterator it = kg->osl.globals->object_name_map.find(
955 if (it == kg->osl.globals->object_name_map.end()) {
978 OSL::ShaderGlobals * ,
985 OSLUStringHash filename, OSL::ShadingContext *context,
const OSL::TextureOpt *opt)
991 OSL::ustring filename, OSL::ShadingContext * ,
const OSL::TextureOpt * )
993 OSLTextureHandleMap::iterator it =
textures.find(filename);
999 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1004 OSL::TextureSystem *ts = m_texturesys;
1005 OSL::TextureSystem::TextureHandle *handle = ts->get_texture_handle(
to_ustring(filename));
1006 if (handle ==
nullptr) {
1020 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1025 switch (it->second.type) {
1029 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1034 it->second.svm_slots[0].y);
1036 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1041 it->second.svm_slots[0].y);
1043 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1046 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1057 if (handle.
empty()) {
1074 OSL::TextureSystem *ts = m_texturesys;
1081 TextureHandle *texture_handle,
1082 TexturePerthread *texture_thread_info,
1084 OSL::ShaderGlobals *sg,
1091 const int nchannels,
1100 ShaderData *sd = globals->
sd;
1105 switch (texture_type) {
1107#ifdef __SHADER_RAYTRACE__
1109 if (nchannels >= 3 &&
state !=
nullptr) {
1110 const int num_samples = (int)s;
1111 const float radius = t;
1112 const float3 N = svm_bevel(kernel_globals,
state, sd, radius, num_samples);
1122#ifdef __SHADER_RAYTRACE__
1124 if (
state !=
nullptr) {
1125 const int num_samples = (int)s;
1126 const float radius = t;
1138 result[0] = svm_ao(kernel_globals,
state, sd,
N, radius, num_samples, flags);
1152 const int tx = (int)s;
1153 const int ty = (int)t;
1154 const int tile = 1001 + 10 * ty + tx;
1156 if (tile_node.
x ==
tile) {
1160 if (tile_node.
z ==
tile) {
1179 if (nchannels > 1) {
1182 if (nchannels > 2) {
1185 if (nchannels > 3) {
1199 OSL::TextureSystem *ts = m_texturesys;
1202 if (texture_thread_info ==
nullptr) {
1203 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1207 texture_thread_info,
1248 if (nchannels == 3 || nchannels == 4) {
1253 if (nchannels == 4) {
1263 TextureHandle *texture_handle,
1264 TexturePerthread *texture_thread_info,
1266 OSL::ShaderGlobals *sg,
1268 const OSL::Vec3 &
dPdx,
1269 const OSL::Vec3 &
dPdy,
1270 const OSL::Vec3 &dPdz,
1271 const int nchannels,
1284 switch (texture_type) {
1287 const int slot = handle->
svm_slots[0].y;
1289 float4 rgba = kernel_tex_image_interp_3d(
1293 if (nchannels > 1) {
1296 if (nchannels > 2) {
1299 if (nchannels > 3) {
1307 OSL::TextureSystem *ts = m_texturesys;
1310 if (texture_thread_info ==
nullptr) {
1311 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1315 texture_thread_info,
1360 if (nchannels == 3 || nchannels == 4) {
1365 if (nchannels == 4) {
1375 TextureHandle *texture_handle,
1376 TexturePerthread *thread_info,
1378 OSL::ShaderGlobals *sg,
1380 const OSL::Vec3 &dRdx,
1381 const OSL::Vec3 &dRdy,
1382 const int nchannels,
1389 OSL::TextureSystem *ts = m_texturesys;
1394 if (thread_info ==
nullptr) {
1395 thread_info = globals->
kg->osl.oiio_thread_info;
1410 status = ts->environment(
1415 if (nchannels == 3 || nchannels == 4) {
1420 if (nchannels == 4) {
1433 TextureHandle *texture_handle,
1434 TexturePerthread *texture_thread_info,
1435 OSL::ShaderGlobals * ,
1438 const TypeDesc datatype,
1443 OSL::TextureSystem *ts = m_texturesys;
1454 texture_thread_info,
1463 return ts->get_texture_info(
1473#
if OSL_LIBRARY_VERSION_CODE >= 11400
1487#
if OSL_LIBRARY_VERSION_CODE >= 11400
1512 OSL::ShaderGlobals *sg,
1514 const OSL::Vec3 &
dPdx,
1515 const OSL::Vec3 &
dPdy,
1517 const OSL::Vec3 &dRdx,
1518 const OSL::Vec3 &dRdy)
1522 ShaderData *sd = globals->
sd;
1525 if (sd ==
nullptr) {
1536 ray.
time = sd->time;
1542 if (
options.mindist == 0.0f) {
1544 if (ray.
P == sd->P) {
1565 OSLTraceData *tracedata = globals->
tracedata;
1566 tracedata->ray = ray;
1567 tracedata->setup =
false;
1568 tracedata->init =
true;
1569 tracedata->hit =
false;
1578 tracedata->hit =
scene_intersect(kg, &ray, visibility, &tracedata->isect);
1579 return tracedata->hit;
1585 const TypeDesc type,
1591 OSLTraceData *tracedata = globals->
tracedata;
1593 if (source ==
u_trace && tracedata->init) {
1597 if (tracedata->hit) {
1599 return set_attribute(tracedata->isect.t, type, derivatives, val);
1602 ShaderData *sd = &tracedata->sd;
1604 if (!tracedata->setup) {
1607 tracedata->setup =
true;
MINLINE void copy_v3_v3(float r[3], const float a[3])
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void to_scene_linear(ustring colorspace, T *pixels, const size_t num_pixels, bool is_rgba, bool compress_as_srgb, bool ignore_alpha)
int svm_slot(const int slot_index=0) const
static ustring u_bump_map_normal
static ustring u_path_transmission_depth
static bool get_background_attribute(ShaderGlobals *globals, OSLUStringHash name, const TypeDesc type, bool derivatives, void *val)
static ustring u_particle_location
static ImageManager * image_manager
static ustring u_object_alpha
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
static ustring u_sensor_size
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
static ustring u_curve_thickness
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
static ustring u_particle_index
static ustring u_point_position
static ustring u_point_radius
static ustring u_curve_tangent_normal
~OSLRenderServices() override
int supports(string_view feature) const override
static ustring u_image_resolution
static ustring u_path_diffuse_depth
static bool get_camera_attribute(ShaderGlobals *globals, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
static ustring u_normal_map_normal
bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
static ustring u_curve_length
static ustring u_aperture_aspect_ratio
static ustring u_material_index
static ustring u_path_ray_depth
static ustring u_point_random
static ustring u_is_smooth
static ustring u_object_location
static ustring u_curve_random
static ustring u_particle_rotation
static ustring u_focal_distance
static ustring u_particle_velocity
static ustring u_particle_angular_velocity
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
static ustring u_path_glossy_depth
static bool get_object_standard_attribute(ShaderGlobals *globals, OSLUStringHash name, const TypeDesc type, bool derivatives, void *val)
static ustring u_geom_dupli_uv
static ustring u_aperture_size
static ustring u_geom_undisplaced
OSLTextureHandleMap textures
static ustring u_geom_numpolyvertices
static ustring u_object_random
static ustring u_path_ray_length
static ustring u_path_portal_depth
static ustring u_object_is_light
static ustring u_particle_random
static ustring u_particle_age
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
static ustring u_object_index
bool get_attribute(OSL::ShaderGlobals *sg, bool derivatives, OSLUStringHash object, const TypeDesc type, OSLUStringHash name, void *val) override
static ustring u_is_point
static ustring u_path_transparent_depth
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
static ustring u_particle_lifetime
static ustring u_is_curve
static ustring u_object_color
static ustring u_distance
static ustring u_aperture_position
static ustring u_geom_trianglevertices
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
static ustring u_geom_polyvertices
bool getmessage(OSL::ShaderGlobals *sg, OSLUStringHash source, OSLUStringHash name, const TypeDesc type, void *val, bool derivatives) override
static ustring u_particle_size
OSL::TextureSystem::TextureHandle * get_texture_handle(OSL::ustring filename, OSL::ShadingContext *context, const OSL::TextureOpt *options) override
static ustring u_geom_dupli_generated
OSLRenderServices(OSL::TextureSystem *texture_system, const int device_type)
bool good(OSL::TextureSystem::TextureHandle *texture_handle) override
static ustring u_geom_name
ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, const int id, const float x, float y)
ccl_device_forceinline float3 dPdx(const ccl_private ShaderData *sd)
ccl_device_forceinline float3 dPdy(const ccl_private ShaderData *sd)
ccl_device_inline ProjectionTransform projection_transpose(const ProjectionTransform a)
CCL_NAMESPACE_BEGIN struct Options options
#define ccl_device_inline
#define ccl_device_template_spec
#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_inline void triangle_vertices(KernelGlobals kg, const int prim, float3 P[3])
ccl_device_inline float3 triangle_smooth_normal_unnormalized(KernelGlobals kg, const ccl_private ShaderData *sd, const float3 Ng, const int prim, const float u, float v)
ccl_device_inline float hash_uint2_to_float(const uint kx, const uint ky)
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 float2 camera_sample_aperture(ccl_constant KernelCamera *cam, const float2 rand)
ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, ccl_private ShaderData *sd, float3 P)
const ccl_global KernelWorkTile * tile
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, const int object)
ccl_device_inline int object_particle_id(KernelGlobals kg, const int object)
ccl_device int shader_pass_id(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_inline Transform object_get_inverse_transform(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device float4 particle_rotation(KernelGlobals kg, const int particle)
ccl_device float3 particle_location(KernelGlobals kg, const int particle)
ccl_device float particle_lifetime(KernelGlobals kg, const int particle)
ccl_device float particle_age(KernelGlobals kg, const int particle)
ccl_device_inline uint particle_index(KernelGlobals kg, const int particle)
ccl_device_inline float3 object_color(KernelGlobals kg, const int object)
ccl_device_inline Transform object_get_transform(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device float3 particle_velocity(KernelGlobals kg, const int particle)
ccl_device_inline float object_alpha(KernelGlobals kg, const int object)
ccl_device float3 particle_angular_velocity(KernelGlobals kg, const int particle)
ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, const int object)
ccl_device_inline float object_pass_id(KernelGlobals kg, const int object)
ccl_device float particle_size(KernelGlobals kg, const int particle)
ccl_device_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
ccl_device_inline float3 object_location(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_inline Transform object_fetch_transform_motion_test(KernelGlobals kg, const int object, const float time, ccl_private Transform *itfm)
ccl_device_inline float object_random_number(KernelGlobals kg, const int object)
#define OSL_TEXTURE_HANDLE_TYPE_SVM
#define OSL_TEXTURE_HANDLE_TYPE_IES
#define OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL
@ ATTR_STD_NORMAL_UNDISPLACED
@ PATH_RAY_ALL_VISIBILITY
@ SD_OBJECT_TRANSFORM_APPLIED
ccl_device_inline float kernel_ies_interp(KernelGlobals kg, const int slot, const float h_angle, const float v_angle)
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, const int object, const uint3 tri_vindex, const int numsteps, const int numverts, const int step, const float t, float3 verts[3])
OSL::ustringhash OSLUStringHash
OSL::ustringrep OSLUStringRep
static OSL::ustring to_ustring(OSLUStringHash h)
static constexpr TypeDesc TypeFloatArray4(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 4)
CCL_NAMESPACE_BEGIN ccl_device_forceinline dual< T > primitive_surface_attribute(KernelGlobals kg, const ccl_private ShaderData *sd, const AttributeDescriptor desc, const bool dx=false, const bool dy=false)
ccl_device_template_spec bool set_attribute(const dual1 v, TypeDesc type, bool derivatives, void *val)
bool get_object_attribute_impl(const ThreadKernelGlobalsCPU *kg, ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc &type, bool derivatives, void *val)
static bool get_object_attribute(const ThreadKernelGlobalsCPU *kg, ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc &type, bool derivatives, void *val)
static bool set_attribute_float3_3(const float3 P[3], TypeDesc type, bool derivatives, void *val)
#define READ_PATH_STATE(elem)
static bool set_attribute_matrix(const Transform &tfm, const TypeDesc type, void *val)
static CCL_NAMESPACE_BEGIN void copy_matrix(OSL::Matrix44 &m, const Transform &tfm)
ccl_device_inline void set_data_float3(const dual3 data, bool derivatives, ccl_private void *val)
ccl_device bool attribute_bump_map_normal(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private dual3 &f)
ccl_device_inline void set_data_float4(const dual4 data, bool derivatives, ccl_private void *val)
ccl_device_inline void set_data_float(const dual1 data, bool derivatives, ccl_private void *val)
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)
static bool find_attribute(const std::string &attributes, const char *search_attribute)
ColorSpaceProcessor * processor
OSL::TextureSystem::TextureHandle * oiio_handle
ccl_private ShaderData * sd
const ThreadKernelGlobalsCPU * kg
ccl_private OSLTraceData * tracedata
const struct IntegratorStateCPU * path_state
const struct IntegratorShadowStateCPU * shadow_path_state