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));
130 : OSL::RendererServices(texture_system), device_type_(device_type)
137 VLOG_INFO <<
"OSL texture system stats:\n" << m_texturesys->getstats();
144 if (feature ==
"OptiX") {
154 OSL::TransformationPtr xform,
159 if (globals ==
nullptr || globals->
sd ==
nullptr) {
165 const ShaderData *sd = globals->
sd;
167 const int object = sd->object;
170#ifdef __OBJECT_MOTION__
173 if (time == sd->time) {
192 OSL::TransformationPtr xform,
197 if (globals ==
nullptr || globals->
sd ==
nullptr) {
203 const ShaderData *sd = globals->
sd;
205 const int object = sd->object;
208#ifdef __OBJECT_MOTION__
211 if (time == sd->time) {
294 OSL::TransformationPtr xform)
298 if (globals ==
nullptr || globals->
sd ==
nullptr) {
304 const ShaderData *sd = globals->
sd;
306 const int object = sd->object;
320 OSL::TransformationPtr xform)
324 if (globals ==
nullptr || globals->
sd ==
nullptr) {
330 const ShaderData *sd = globals->
sd;
332 const int object = sd->object;
411 const T v,
const T dx,
const T dy,
TypeDesc type,
bool derivatives,
void *val);
414 const float v,
const float dx,
const float dy,
bool derivatives,
void *val)
416 float *fval =
static_cast<float *
>(val);
427 float *fval =
static_cast<float *
>(val);
444 float *fval =
static_cast<float *
>(val);
462 const float v,
const float dx,
const float dy,
TypeDesc type,
bool derivatives,
void *val)
472 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
476 if (type == TypeFloat) {
495 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
499 if (type == TypeFloat) {
515 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
519 if (type == TypeFloat) {
542 if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
546 if (type == TypeFloat) {
568 if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
569 int *ival = (
int *)val;
588 if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
607 if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
608 float *fval = (
float *)val;
622 if (type.arraylen > 3) {
623 memset(fval + 3 * 3, 0,
sizeof(
float) * 3 * (type.arraylen - 3));
626 memset(fval + type.arraylen * 3, 0,
sizeof(
float) * 2 * 3 * type.arraylen);
637 if (type == TypeMatrix) {
657 if (primitive_is_volume_attribute(sd, desc)) {
658 v = primitive_volume_attribute<T>(kg, sd, desc);
664 kg, sd, desc, derivatives ? &dx :
nullptr, derivatives ? &dy :
nullptr);
698 ShaderData *sd = globals->
sd;
814 const ustring object_name = kg->osl.globals->object_names[sd->object];
828 const float f = curve_thickness(kg, sd);
832 const float3 f = curve_tangent_normal(kg, sd);
836 const float f = curve_random(kg, sd);
847 const float f = point_radius(kg, sd);
851 const float3 f = point_position(kg, sd);
855 const float f = point_random(kg, sd);
871 return set_attribute(f[0], f[1], f[2], type, derivatives, val);
879 ShaderData *sd = globals->
sd;
885 const float f = sd->ray_length;
889#define READ_PATH_STATE(elem) \
890 ((state != nullptr) ? state->path.elem : \
891 (shadow_state != nullptr) ? shadow_state->shadow_path.elem : \
927#undef READ_PATH_STATE
953 return set_attribute(ndc[0], ndc[1], ndc[2], type, derivatives, val);
997 if (globals ==
nullptr) {
1001 ShaderData *sd = globals->
sd;
1003 if (sd ==
nullptr) {
1011 const OSLGlobals::ObjectNameMap::iterator it = kg->osl.globals->object_name_map.find(
1014 if (it == kg->osl.globals->object_name_map.end()) {
1018 object = it->second;
1021 object = sd->object;
1041 OSLUStringHash filename, OSL::ShadingContext *context,
const OSL::TextureOpt *opt)
1047 OSL::ustring filename, OSL::ShadingContext * ,
const OSL::TextureOpt * )
1049 OSLTextureHandleMap::iterator it =
textures.find(filename);
1055 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1060 OSL::TextureSystem *ts = m_texturesys;
1061 OSL::TextureSystem::TextureHandle *handle = ts->get_texture_handle(
to_ustring(filename));
1062 if (handle ==
nullptr) {
1076 return (OSL::TextureSystem::TextureHandle *)(&it->second);
1081 switch (it->second.type) {
1085 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1090 it->second.svm_slots[0].y);
1092 if (!it->second.handle.empty() && it->second.handle.get_manager() !=
image_manager) {
1097 it->second.svm_slots[0].y);
1099 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1102 return reinterpret_cast<OSL::TextureSystem::TextureHandle *
>(
1113 if (handle.
empty()) {
1130 OSL::TextureSystem *ts = m_texturesys;
1137 TextureHandle *texture_handle,
1138 TexturePerthread *texture_thread_info,
1140 OSL::ShaderGlobals *sg,
1147 const int nchannels,
1156 ShaderData *sd = globals->
sd;
1159 bool status =
false;
1161 switch (texture_type) {
1163#ifdef __SHADER_RAYTRACE__
1165 if (nchannels >= 3 &&
state !=
nullptr) {
1166 const int num_samples = (int)s;
1167 const float radius = t;
1168 const float3 N = svm_bevel(kernel_globals,
state, sd, radius, num_samples);
1178#ifdef __SHADER_RAYTRACE__
1180 if (
state !=
nullptr) {
1181 const int num_samples = (int)s;
1182 const float radius = t;
1194 result[0] = svm_ao(kernel_globals,
state, sd,
N, radius, num_samples, flags);
1208 const int tx = (int)s;
1209 const int ty = (int)t;
1210 const int tile = 1001 + 10 * ty + tx;
1212 if (tile_node.
x ==
tile) {
1216 if (tile_node.
z ==
tile) {
1235 if (nchannels > 1) {
1238 if (nchannels > 2) {
1241 if (nchannels > 3) {
1255 OSL::TextureSystem *ts = m_texturesys;
1258 if (texture_thread_info ==
nullptr) {
1259 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1263 texture_thread_info,
1304 if (nchannels == 3 || nchannels == 4) {
1309 if (nchannels == 4) {
1319 TextureHandle *texture_handle,
1320 TexturePerthread *texture_thread_info,
1322 OSL::ShaderGlobals *sg,
1324 const OSL::Vec3 &dPdx,
1325 const OSL::Vec3 &dPdy,
1326 const OSL::Vec3 &dPdz,
1327 const int nchannels,
1338 bool status =
false;
1340 switch (texture_type) {
1343 const int slot = handle->
svm_slots[0].y;
1348 if (nchannels > 1) {
1351 if (nchannels > 2) {
1354 if (nchannels > 3) {
1362 OSL::TextureSystem *ts = m_texturesys;
1365 if (texture_thread_info ==
nullptr) {
1366 texture_thread_info = kernel_globals->osl.oiio_thread_info;
1370 texture_thread_info,
1415 if (nchannels == 3 || nchannels == 4) {
1420 if (nchannels == 4) {
1430 TextureHandle *texture_handle,
1431 TexturePerthread *thread_info,
1433 OSL::ShaderGlobals *sg,
1435 const OSL::Vec3 &dRdx,
1436 const OSL::Vec3 &dRdy,
1437 const int nchannels,
1444 OSL::TextureSystem *ts = m_texturesys;
1446 bool status =
false;
1449 if (thread_info ==
nullptr) {
1450 thread_info = globals->
kg->osl.oiio_thread_info;
1465 status = ts->environment(
1470 if (nchannels == 3 || nchannels == 4) {
1475 if (nchannels == 4) {
1488 TextureHandle *texture_handle,
1489 TexturePerthread *texture_thread_info,
1490 OSL::ShaderGlobals * ,
1498 OSL::TextureSystem *ts = m_texturesys;
1509 texture_thread_info,
1518 return ts->get_texture_info(
1524 const OSL::Vec3 ¢er,
1526 const int max_points,
1528#
if OSL_LIBRARY_VERSION_CODE >= 11400
1531 size_t *out_indices,
1533 float *out_distances,
1534 const int derivs_offset)
1541#
if OSL_LIBRARY_VERSION_CODE >= 11400
1556 const OSL::Vec3 &
pos,
1566 OSL::ShaderGlobals *sg,
1568 const OSL::Vec3 &dPdx,
1569 const OSL::Vec3 &dPdy,
1571 const OSL::Vec3 &dRdx,
1572 const OSL::Vec3 &dRdy)
1576 ShaderData *sd = globals->
sd;
1579 if (sd ==
nullptr) {
1590 ray.
time = sd->time;
1596 if (
options.mindist == 0.0f) {
1598 if (ray.
P == sd->P) {
1619 OSLTraceData *tracedata = globals->
tracedata;
1620 tracedata->ray = ray;
1621 tracedata->setup =
false;
1622 tracedata->init =
true;
1623 tracedata->hit =
false;
1632 tracedata->hit =
scene_intersect(kg, &ray, visibility, &tracedata->isect);
1633 return tracedata->hit;
1645 OSLTraceData *tracedata = globals->
tracedata;
1647 if (source ==
u_trace && tracedata->init) {
1648 if (name ==
u_hit) {
1651 if (tracedata->hit) {
1653 return set_attribute(tracedata->isect.t, type, derivatives, val);
1656 ShaderData *sd = &tracedata->sd;
1658 if (!tracedata->setup) {
1661 tracedata->setup =
true;
1679 return set_attribute(sd->u, sd->du.dx, sd->du.dy, type, derivatives, val);
1682 return set_attribute(sd->v, sd->dv.dx, sd->dv.dy, type, derivatives, val);
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btDbvtNode * sort(btDbvtNode *n, btDbvtNode *&r)
static void to_scene_linear(ustring colorspace, T *pixels, const size_t num_pixels, bool is_rgba, bool compress_as_srgb)
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_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_3d(KernelGlobals kg, const int id, float3 P, InterpolationType interp)
ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, const int id, const float x, float y)
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)
VecBase< float, 4 > float4
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_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *P)
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 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
@ 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 T make_zero()
ccl_device_inline float average(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
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 T primitive_surface_attribute(KernelGlobals kg, const ccl_private ShaderData *sd, const AttributeDescriptor desc, ccl_private T *dfdx, ccl_private T *dfdy)
bool get_object_attribute_impl(const ThreadKernelGlobalsCPU *kg, ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc &type, bool derivatives, void *val)
void set_data_float(const float v, const float dx, const float dy, bool derivatives, void *val)
bool set_attribute(const T v, const T dx, const T dy, 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)
void set_data_float4(const float4 v, const float4 dx, const float4 dy, bool derivatives, void *val)
static bool set_attribute_float3_3(const float3 P[3], TypeDesc type, bool derivatives, void *val)
void set_data_float3(const float3 v, const float3 dx, const float3 dy, 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_NAMESPACE_BEGIN ccl_device bool attribute_bump_map_normal(KernelGlobals kg, ccl_private const ShaderData *sd, float3 f[3])
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