9#if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
10# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11# pragma GCC diagnostic ignored "-Wuninitialized"
57 memcpy((
void *)&m, &t,
sizeof(m));
63 memcpy((
void *)&m, &t,
sizeof(m));
128 : OSL::RendererServices(texture_system), device_type_(device_type)
135 VLOG_INFO <<
"OSL texture system stats:\n" << m_texturesys->getstats();
142 if (feature ==
"OptiX") {
152 OSL::TransformationPtr xform,
160 int object = sd->object;
163#ifdef __OBJECT_MOTION__
166 if (time == sd->time) {
192 OSL::TransformationPtr xform,
200 int object = sd->object;
203#ifdef __OBJECT_MOTION__
206 if (time == sd->time) {
296 OSL::TransformationPtr xform)
303 int object = sd->object;
324 OSL::TransformationPtr xform)
331 int object = sd->object;
418 float *fval = (
float *)val;
437 else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
438 float *fval = (
float *)val;
456 else if (type == TypeFloat) {
457 float *fval = (
float *)val;
487 float *fval = (
float *)val;
506 else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
507 float *fval = (
float *)val;
525 else if (type == TypeFloat) {
526 float *fval = (
float *)val;
561 float *fval = (
float *)val;
581 else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
597 else if (type == TypeFloat) {
625 float *fval = (
float *)val;
644 else if (type == TypePoint || type == TypeVector || type == TypeNormal || type == TypeColor) {
645 float *fval = (
float *)val;
662 else if (type == TypeFloat) {
663 float *fval = (
float *)val;
690 if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
691 int *ival = (
int *)val;
707 if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
710 ustring *sval = (ustring *)val;
726 if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
727 float *fval = (
float *)val;
741 if (type.arraylen > 3) {
742 memset(fval + 3 * 3, 0,
sizeof(
float) * 3 * (type.arraylen - 3));
745 memset(fval + type.arraylen * 3, 0,
sizeof(
float) * 2 * 3 * type.arraylen);
756 if (type == TypeMatrix) {
774 if (primitive_is_volume_attribute(sd, desc)) {
775 fval[0] = primitive_volume_attribute_float3(kg, sd, desc);
780 memset(fval, 0,
sizeof(fval));
782 kg, sd, desc, (derivatives) ? &fval[1] :
NULL, (derivatives) ? &fval[2] :
NULL);
788 if (primitive_is_volume_attribute(sd, desc)) {
789 assert(!
"Float2 attribute not support for volumes");
797 kg, sd, desc, (derivatives) ? &fval[1] :
NULL, (derivatives) ? &fval[2] :
NULL);
804 if (primitive_is_volume_attribute(sd, desc)) {
805 memset(fval, 0,
sizeof(fval));
806 fval[0] = primitive_volume_attribute_float(kg, sd, desc);
812 kg, sd, desc, (derivatives) ? &fval[1] :
NULL, (derivatives) ? &fval[2] :
NULL);
819 if (primitive_is_volume_attribute(sd, desc)) {
820 memset(fval, 0,
sizeof(fval));
821 fval[0] = primitive_volume_attribute_float4(kg, sd, desc);
827 kg, sd, desc, (derivatives) ? &fval[1] :
NULL, (derivatives) ? &fval[2] :
NULL);
962 ustring object_name = kg->osl->object_names[sd->object];
976 float f = curve_thickness(kg, sd);
980 float3 f = curve_tangent_normal(kg, sd);
984 float f = curve_random(kg, sd);
995 float f = point_radius(kg, sd);
999 float3 f = point_position(kg, sd);
1003 float f = point_random(kg, sd);
1030 float f = sd->ray_length;
1037 int f = (
state) ?
state->path.bounce : (shadow_state) ? shadow_state->shadow_path.bounce : 0;
1044 int f = (
state) ?
state->path.diffuse_bounce :
1045 (shadow_state) ? shadow_state->shadow_path.diffuse_bounce :
1053 int f = (
state) ?
state->path.glossy_bounce :
1054 (shadow_state) ? shadow_state->shadow_path.glossy_bounce :
1062 int f = (
state) ?
state->path.transmission_bounce :
1063 (shadow_state) ? shadow_state->shadow_path.transmission_bounce :
1071 int f = (
state) ?
state->path.transparent_bounce :
1072 (shadow_state) ? shadow_state->shadow_path.transparent_bounce :
1076 else if (name ==
u_ndc) {
1078 OSLThreadData *tdata = kg->osl_tdata;
1079 OSL::ShaderGlobals *globals = &tdata->globals;
1116 if (sg ==
NULL || sg->renderstate ==
NULL) {
1121 return get_attribute(sd, derivatives, object_name, type, name, val);
1136 OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name);
1138 if (it == kg->osl->object_name_map.end()) {
1142 object = it->second;
1145 object = sd->object;
1150 kg,
object, sd->prim,
object == sd->object ? sd->type :
PRIMITIVE_NONE, name.hash());
1166#if OSL_LIBRARY_VERSION_CODE >= 11304
1168 OSL::ShadingContext *context,
1169 const TextureOpt *opt)
1175 OSL::ShadingContext *,
1177#elif OSL_LIBRARY_VERSION_CODE >= 11100
1179 OSL::ShadingContext *)
1185 OSLTextureHandleMap::iterator it =
textures.find(filename);
1191 return reinterpret_cast<TextureSystem::TextureHandle *
>(it->second.get());
1196 OSL::TextureSystem *ts = m_texturesys;
1197 TextureSystem::TextureHandle *handle = ts->get_texture_handle(
to_ustring(filename));
1198 if (handle ==
NULL) {
1209 it->second->oiio_handle = handle;
1210 return reinterpret_cast<TextureSystem::TextureHandle *
>(it->second.get());
1215 switch (it->second->type) {
1219 if (!it->second->handle.empty() && it->second->handle.get_manager() !=
image_manager) {
1224 it->second->svm_slots[0].y);
1226 if (!it->second->handle.empty() && it->second->handle.get_manager() !=
image_manager) {
1231 it->second->svm_slots[0].y);
1233 return reinterpret_cast<TextureSystem::TextureHandle *
>(
1236 return reinterpret_cast<TextureSystem::TextureHandle *
>(
1247 if (handle.
empty()) {
1265 OSL::TextureSystem *ts = m_texturesys;
1274 TextureHandle *texture_handle,
1275 TexturePerthread *texture_thread_info,
1277 OSL::ShaderGlobals *sg,
1294 bool status =
false;
1296 switch (texture_type) {
1298#ifdef __SHADER_RAYTRACE__
1300 if (nchannels >= 3) {
1303 int num_samples = (
int)s;
1305 float3 N = svm_bevel(kernel_globals,
state, sd, radius, num_samples);
1316#ifdef __SHADER_RAYTRACE__
1320 int num_samples = (
int)s;
1333 result[0] = svm_ao(kernel_globals,
state, sd,
N, radius, num_samples, flags);
1349 int tile = 1001 + 10 * ty + tx;
1351 if (tile_node.
x ==
tile) {
1355 if (tile_node.
z ==
tile) {
1374 if (nchannels > 1) {
1377 if (nchannels > 2) {
1380 if (nchannels > 3) {
1394 OSL::TextureSystem *ts = m_texturesys;
1397 if (texture_thread_info ==
NULL) {
1398 OSLThreadData *tdata = kernel_globals->osl_tdata;
1399 texture_thread_info = tdata->oiio_thread_info;
1403 texture_thread_info,
1444 if (nchannels == 3 || nchannels == 4) {
1449 if (nchannels == 4) {
1459 TextureHandle *texture_handle,
1460 TexturePerthread *texture_thread_info,
1462 OSL::ShaderGlobals *sg,
1464 const OSL::Vec3 &dPdx,
1465 const OSL::Vec3 &dPdy,
1466 const OSL::Vec3 &dPdz,
1476 bool status =
false;
1478 switch (texture_type) {
1488 if (nchannels > 1) {
1491 if (nchannels > 2) {
1494 if (nchannels > 3) {
1502 OSL::TextureSystem *ts = m_texturesys;
1505 if (texture_thread_info ==
NULL) {
1508 OSLThreadData *tdata = kernel_globals->osl_tdata;
1509 texture_thread_info = tdata->oiio_thread_info;
1513 texture_thread_info,
1558 if (nchannels == 3 || nchannels == 4) {
1563 if (nchannels == 4) {
1573 TextureHandle *texture_handle,
1574 TexturePerthread *thread_info,
1576 OSL::ShaderGlobals *sg,
1578 const OSL::Vec3 &dRdx,
1579 const OSL::Vec3 &dRdy,
1587 OSL::TextureSystem *ts = m_texturesys;
1588 bool status =
false;
1591 if (thread_info ==
NULL) {
1594 OSLThreadData *tdata = kernel_globals->osl_tdata;
1595 thread_info = tdata->oiio_thread_info;
1610 status = ts->environment(
1615 if (nchannels == 3 || nchannels == 4) {
1620 if (nchannels == 4) {
1632#if OSL_LIBRARY_VERSION_CODE >= 11304
1634 TextureHandle *texture_handle,
1635 TexturePerthread *texture_thread_info,
1636 OSL::ShaderGlobals *,
1642#elif OSL_LIBRARY_VERSION_CODE >= 11100
1644 TextureHandle *texture_handle,
1645 TexturePerthread *texture_thread_info,
1646 OSL::ShadingContext *,
1655 TextureHandle *texture_handle,
1670 OSL::TextureSystem *ts = m_texturesys;
1671#if OSL_LIBRARY_VERSION_CODE >= 11100
1673 return ts->get_texture_info(
1679 return ts->get_texture_info(
1686 const OSL::Vec3 ¢er,
1690#
if OSL_LIBRARY_VERSION_CODE >= 11400
1693 size_t *out_indices,
1695 float *out_distances,
1703#
if OSL_LIBRARY_VERSION_CODE >= 11400
1718 const OSL::Vec3 &
pos,
1728 OSL::ShaderGlobals *sg,
1730 const OSL::Vec3 &dPdx,
1731 const OSL::Vec3 &dPdy,
1733 const OSL::Vec3 &dRdx,
1734 const OSL::Vec3 &dRdy)
1746 ray.
time = sd->time;
1753 if (
options.mindist == 0.0f) {
1755 if (ray.
P == sd->P) {
1776 OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
1777 tracedata->ray = ray;
1778 tracedata->setup =
false;
1779 tracedata->init =
true;
1780 tracedata->hit =
false;
1781 tracedata->sd.osl_globals = sd->osl_globals;
1792 tracedata->hit =
scene_intersect(kg, &ray, visibility, &tracedata->isect);
1793 return tracedata->hit;
1803 OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
1805 if (source ==
u_trace && tracedata->init) {
1806 if (name ==
u_hit) {
1809 else if (tracedata->hit) {
1811 float f[3] = {tracedata->isect.t, 0.0f, 0.0f};
1818 if (!tracedata->setup) {
1821 tracedata->setup =
true;
1827 else if (name ==
u_Ng) {
1830 else if (name ==
u_P) {
1835 else if (name ==
u_I) {
1840 else if (name ==
u_u) {
1841 float f[3] = {sd->u, sd->du.dx, sd->du.dy};
1844 else if (name ==
u_v) {
1845 float f[3] = {sd->v, sd->dv.dx, sd->dv.dy};
static DBVT_INLINE btDbvtNode * sort(btDbvtNode *n, btDbvtNode *&r)
static void to_scene_linear(ustring colorspace, T *pixels, size_t num_pixels, bool is_rgba, bool compress_as_srgb)
int svm_slot(const int tile_index=0) const
static ustring u_path_transmission_depth
static ustring u_particle_location
static ImageManager * image_manager
static ustring u_object_alpha
bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
static ustring u_curve_thickness
static ustring u_particle_index
bool get_array_attribute(OSL::ShaderGlobals *sg, bool derivatives, OSLUStringHash object, TypeDesc type, OSLUStringHash name, int index, void *val) override
static ustring u_point_position
static ustring u_point_radius
static ustring u_curve_tangent_normal
int supports(string_view feature) const override
static ustring u_path_diffuse_depth
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
bool get_userdata(bool derivatives, OSLUStringHash name, TypeDesc type, OSL::ShaderGlobals *sg, void *val) override
static ustring u_material_index
static ustring u_path_ray_depth
static ustring u_point_random
bool getmessage(OSL::ShaderGlobals *sg, OSLUStringHash source, OSLUStringHash name, TypeDesc type, void *val, bool derivatives) override
static bool get_object_standard_attribute(const KernelGlobalsCPU *kg, ShaderData *sd, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
static ustring u_is_smooth
static bool get_background_attribute(const KernelGlobalsCPU *kg, ShaderData *sd, OSLUStringHash name, TypeDesc type, bool derivatives, void *val)
static ustring u_object_location
static ustring u_curve_random
bool texture3d(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, const OSL::Vec3 &dPdz, int nchannels, float *result, float *dresultds, float *dresultdt, float *dresultdr, OSLUStringHash *errormessage) override
static ustring u_particle_rotation
OSLRenderServices(OSL::TextureSystem *texture_system, int device_type)
static ustring u_particle_velocity
static ustring u_particle_angular_velocity
static ustring u_path_glossy_depth
static ustring u_geom_dupli_uv
static ustring u_geom_undisplaced
OSLTextureHandleMap textures
static ustring u_geom_numpolyvertices
static ustring u_object_random
static ustring u_path_ray_length
bool get_texture_info(OSL::ShaderGlobals *sg, OSLUStringHash filename, TextureHandle *texture_handle, int subimage, OSLUStringHash dataname, TypeDesc datatype, void *data) override
static ustring u_object_is_light
int pointcloud_get(OSL::ShaderGlobals *sg, OSLUStringHash filename, size_t *indices, int count, OSLUStringHash attr_name, TypeDesc attr_type, void *out_data) override
bool texture(OSLUStringHash filename, TextureSystem::TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, float *result, float *dresultds, float *dresultdt, OSLUStringHash *errormessage) override
static ustring u_particle_random
static ustring u_particle_age
static ustring u_object_index
static ustring u_is_point
static ustring u_path_transparent_depth
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
bool environment(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, int nchannels, float *result, float *dresultds, float *dresultdt, OSLUStringHash *errormessage) override
static ustring u_is_curve
static ustring u_object_color
static ustring u_distance
static ustring u_geom_trianglevertices
int pointcloud_search(OSL::ShaderGlobals *sg, OSLUStringHash filename, const OSL::Vec3 ¢er, float radius, int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset) override
static ustring u_geom_polyvertices
TextureSystem::TextureHandle * get_texture_handle(OSLUStringHash filename) override
static ustring u_particle_size
bool pointcloud_write(OSL::ShaderGlobals *sg, OSLUStringHash filename, const OSL::Vec3 &pos, int nattribs, const OSLUStringRep *names, const TypeDesc *types, const void **data) override
static ustring u_geom_dupli_generated
bool good(TextureSystem::TextureHandle *texture_handle) override
bool get_attribute(OSL::ShaderGlobals *sg, bool derivatives, OSLUStringHash object, TypeDesc type, OSLUStringHash name, void *val) override
static ustring u_geom_name
ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals kg, int id, float3 P, InterpolationType interp)
ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, int id, float x, float y)
CCL_NAMESPACE_BEGIN struct ProjectionTransform ProjectionTransform
ccl_device_inline ProjectionTransform projection_transpose(const ProjectionTransform &a)
CCL_NAMESPACE_BEGIN struct Options options
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#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)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline void triangle_vertices(KernelGlobals kg, int prim, float3 P[3])
ccl_device_inline float3 triangle_smooth_normal_unnormalized(KernelGlobals kg, ccl_private const ShaderData *sd, float3 Ng, int prim, float u, float v)
ccl_device_inline float hash_uint2_to_float(uint kx, uint ky)
ccl_device_intersect bool scene_intersect(KernelGlobals kg, ccl_private const Ray *ray, const uint visibility, ccl_private Intersection *isect)
ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, ccl_private ShaderData *sd, float3 P)
ccl_global const KernelWorkTile * tile
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
ccl_device_inline float object_pass_id(KernelGlobals kg, int object)
ccl_device_inline float object_alpha(KernelGlobals kg, int object)
ccl_device float particle_age(KernelGlobals kg, int particle)
ccl_device float4 particle_rotation(KernelGlobals kg, int particle)
ccl_device_inline uint particle_index(KernelGlobals kg, int particle)
ccl_device_inline float3 object_location(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline float object_random_number(KernelGlobals kg, int object)
ccl_device float particle_lifetime(KernelGlobals kg, int particle)
ccl_device_inline void object_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device float3 particle_angular_velocity(KernelGlobals kg, int particle)
ccl_device_inline int object_particle_id(KernelGlobals kg, int object)
ccl_device_inline float3 object_color(KernelGlobals kg, int object)
ccl_device_inline Transform object_get_transform(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device int shader_pass_id(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float3 particle_velocity(KernelGlobals kg, int particle)
ccl_device float3 particle_location(KernelGlobals kg, int particle)
ccl_device float particle_size(KernelGlobals kg, int particle)
ccl_device_inline Transform lamp_fetch_transform(KernelGlobals kg, int lamp, bool inverse)
ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, int object)
ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, int object)
ccl_device_inline Transform object_get_inverse_transform(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline Transform object_fetch_transform_motion_test(KernelGlobals kg, int object, float time, ccl_private Transform *itfm)
#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, int slot, float h_angle, float v_angle)
ccl_device_inline float average(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, int object, uint3 tri_vindex, int numsteps, int numverts, int step, float t, float3 verts[3])
static OSL::ustring to_ustring(OSLUStringHash h)
CCL_NAMESPACE_BEGIN typedef OSL::ustringhash OSLUStringHash
OSL::ustringrep OSLUStringRep
static constexpr TypeDesc TypeFloatArray4(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 4)
ccl_device_forceinline float3 primitive_surface_attribute_float3(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float3 *dx, ccl_private float3 *dy)
ccl_device_forceinline float2 primitive_surface_attribute_float2(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float2 *dx, ccl_private float2 *dy)
ccl_device_forceinline float4 primitive_surface_attribute_float4(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float4 *dx, ccl_private float4 *dy)
CCL_NAMESPACE_BEGIN ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float *dx, ccl_private float *dy)
static bool set_attribute_string(ustring str, TypeDesc type, bool derivatives, void *val)
static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, void *val)
static bool set_attribute_float3_3(float3 P[3], TypeDesc type, bool derivatives, void *val)
static bool set_attribute_int(int i, TypeDesc type, bool derivatives, void *val)
static bool set_attribute_matrix(const Transform &tfm, TypeDesc type, void *val)
static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, void *val)
static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val)
static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val)
static CCL_NAMESPACE_BEGIN void copy_matrix(OSL::Matrix44 &m, const Transform &tfm)
static bool get_object_attribute(const KernelGlobalsCPU *kg, ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc &type, bool derivatives, void *val)
ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, ccl_private const Ray *ccl_restrict ray, ccl_private const Intersection *ccl_restrict isect)
static bool find_attribute(const std::string &attributes, const char *search_attribute)
ColorSpaceProcessor * processor
OSL::TextureSystem::TextureHandle * oiio_handle
VecBase< float, 4 > float4
ccl_device_inline float3 float4_to_float3(const float4 a)
#define TEX_IMAGE_MISSING_R
#define TEX_IMAGE_MISSING_B
#define TEX_IMAGE_MISSING_A
#define TEX_IMAGE_MISSING_G