9#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
10# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11# pragma GCC diagnostic ignored "-Wuninitialized"
51 memcpy((
float *)&m, (
const float *)&t,
sizeof(m));
57 memcpy((
float *)&m, (
const float *)&t,
sizeof(m));
131 : OSL::RendererServices(texture_system), device_type_(device_type)
138 LOG_INFO <<
"OSL texture system stats:\n" << m_texturesys->getstats();
145 if (feature ==
"OptiX") {
157 OSL::TransformationPtr ,
162 if (globals ==
nullptr || globals->
sd ==
nullptr) {
168 const ShaderData *sd = globals->
sd;
170 const int object = sd->object;
173#ifdef __OBJECT_MOTION__
176 if (time == sd->time) {
195 OSL::TransformationPtr ,
200 if (globals ==
nullptr || globals->
sd ==
nullptr) {
206 const ShaderData *sd = globals->
sd;
208 const int object = sd->object;
211#ifdef __OBJECT_MOTION__
214 if (time == sd->time) {
297 OSL::TransformationPtr )
301 if (globals ==
nullptr || globals->
sd ==
nullptr) {
307 const ShaderData *sd = globals->
sd;
309 const int object = sd->object;
323 OSL::TransformationPtr )
327 if (globals ==
nullptr || globals->
sd ==
nullptr) {
333 const ShaderData *sd = globals->
sd;
335 const int object = sd->object;
421 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
425 if (type == TypeFloat) {
442 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
446 if (type == TypeFloat) {
463 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
467 if (type == TypeFloat) {
492 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
496 if (type == TypeFloat) {
514 if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
515 int *ival = (
int *)val;
534 if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
553 if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
554 float *fval = (
float *)val;
560 if (type.arraylen > 3) {
561 memset(fval + 3 * 3, 0,
sizeof(
float) * 3 * (type.arraylen - 3));
564 memset(fval + type.arraylen * 3, 0,
sizeof(
float) * 2 * 3 * type.arraylen);
575 if (type == TypeMatrix) {
587 const TypeDesc &type,
593 if (primitive_is_volume_attribute(sd)) {
594 data.val = primitive_volume_attribute<T>(kg, sd, desc,
true);
607 const TypeDesc &type,
633 ShaderData *sd = globals->
sd;
749 const ustring object_name = kg->osl.globals->object_names[sd->object];
763 const float f = curve_thickness(kg, sd);
767 const float3 f = curve_tangent_normal(sd);
771 const float f = curve_random(kg, sd);
782 const float f = point_radius(kg, sd);
786 const float3 f = point_position(kg, sd);
790 const float f = point_random(kg, sd);
819 ShaderData *sd = globals->
sd;
825 const float f = sd->ray_length;
829#define READ_PATH_STATE(elem) \
830 ((state != nullptr) ? state->path.elem : \
831 (shadow_state != nullptr) ? shadow_state->shadow_path.elem : \
872#undef READ_PATH_STATE
937 if (globals ==
nullptr) {
941 ShaderData *sd = globals->
sd;
951 const OSLGlobals::ObjectNameMap::iterator it = kg->osl.globals->object_name_map.find(
954 if (it == kg->osl.globals->object_name_map.end()) {
977 OSL::ShaderGlobals * ,
984 OSLUStringHash filename, OSL::ShadingContext *context,
const OSL::TextureOpt *opt)
990 OSL::ustring filename, OSL::ShadingContext * ,
const OSL::TextureOpt * )
992 OSLTextureHandleMap::iterator it =
textures.find(filename);
998 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1003 OSL::TextureSystem *ts = m_texturesys;
1004 OSL::TextureSystem::TextureHandle *handle = ts->get_texture_handle(
to_ustring(filename));
1005 if (handle ==
nullptr) {
1019 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1024 switch (it->second.type) {
1028 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1033 it->second.svm_slots[0].y);
1035 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1040 it->second.svm_slots[0].y);
1042 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1045 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1056 if (handle.
empty()) {
1073 OSL::TextureSystem *ts = m_texturesys;
1080 TextureHandle *texture_handle,
1081 TexturePerthread *texture_thread_info,
1083 OSL::ShaderGlobals *sg,
1090 const int nchannels,
1099 ShaderData *sd = globals->
sd;
1104 switch (texture_type) {
1106#ifdef __SHADER_RAYTRACE__
1108 if (nchannels >= 3 &&
state !=
nullptr) {
1109 const int num_samples = (int)s;
1110 const float radius = t;
1111 const float3 N = svm_bevel(kernel_globals,
state, sd, radius, num_samples);
1121#ifdef __SHADER_RAYTRACE__
1123 if (
state !=
nullptr) {
1124 const int num_samples = (int)s;
1125 const float radius = t;
1137 result[0] = svm_ao(kernel_globals,
state, sd,
N, radius, num_samples, flags);
1151 const int tx = (int)s;
1152 const int ty = (int)t;
1153 const int tile = 1001 + 10 * ty + tx;
1155 if (tile_node.
x ==
tile) {
1159 if (tile_node.
z ==
tile) {
1178 if (nchannels > 1) {
1181 if (nchannels > 2) {
1184 if (nchannels > 3) {
1198 OSL::TextureSystem *ts = m_texturesys;
1201 if (texture_thread_info ==
nullptr) {
1202 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1206 texture_thread_info,
1247 if (nchannels == 3 || nchannels == 4) {
1252 if (nchannels == 4) {
1262 TextureHandle *texture_handle,
1263 TexturePerthread *texture_thread_info,
1265 OSL::ShaderGlobals *sg,
1267 const OSL::Vec3 &
dPdx,
1268 const OSL::Vec3 &
dPdy,
1269 const OSL::Vec3 &dPdz,
1270 const int nchannels,
1283 switch (texture_type) {
1286 const int slot = handle->
svm_slots[0].y;
1288 float4 rgba = kernel_tex_image_interp_3d(
1292 if (nchannels > 1) {
1295 if (nchannels > 2) {
1298 if (nchannels > 3) {
1306 OSL::TextureSystem *ts = m_texturesys;
1309 if (texture_thread_info ==
nullptr) {
1310 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1314 texture_thread_info,
1359 if (nchannels == 3 || nchannels == 4) {
1364 if (nchannels == 4) {
1374 TextureHandle *texture_handle,
1375 TexturePerthread *thread_info,
1377 OSL::ShaderGlobals *sg,
1379 const OSL::Vec3 &dRdx,
1380 const OSL::Vec3 &dRdy,
1381 const int nchannels,
1388 OSL::TextureSystem *ts = m_texturesys;
1393 if (thread_info ==
nullptr) {
1394 thread_info = globals->
kg->osl.oiio_thread_info;
1409 status = ts->environment(
1414 if (nchannels == 3 || nchannels == 4) {
1419 if (nchannels == 4) {
1432 TextureHandle *texture_handle,
1433 TexturePerthread *texture_thread_info,
1434 OSL::ShaderGlobals * ,
1437 const TypeDesc datatype,
1442 OSL::TextureSystem *ts = m_texturesys;
1453 texture_thread_info,
1462 return ts->get_texture_info(
1472#
if OSL_LIBRARY_VERSION_CODE >= 11400
1486#
if OSL_LIBRARY_VERSION_CODE >= 11400
1511 OSL::ShaderGlobals *sg,
1513 const OSL::Vec3 &
dPdx,
1514 const OSL::Vec3 &
dPdy,
1516 const OSL::Vec3 &dRdx,
1517 const OSL::Vec3 &dRdy)
1521 ShaderData *sd = globals->
sd;
1524 if (sd ==
nullptr) {
1535 ray.
time = sd->time;
1541 if (
options.mindist == 0.0f) {
1543 if (ray.
P == sd->P) {
1564 OSLTraceData *tracedata = globals->
tracedata;
1565 tracedata->ray = ray;
1566 tracedata->setup =
false;
1567 tracedata->init =
true;
1568 tracedata->hit =
false;
1577 tracedata->hit =
scene_intersect(kg, &ray, visibility, &tracedata->isect);
1578 return tracedata->hit;
1584 const TypeDesc type,
1590 OSLTraceData *tracedata = globals->
tracedata;
1592 if (source ==
u_trace && tracedata->init) {
1596 if (tracedata->hit) {
1598 return set_attribute(tracedata->isect.t, type, derivatives, val);
1601 ShaderData *sd = &tracedata->sd;
1603 if (!tracedata->setup) {
1606 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