Skip to content

Commit 2a4c401

Browse files
authored
Fix the OptiX path in testrender and testshade (#1896)
The recent free function change (#1852) put the OptiX paths in testrender and testshade in a non-working state (issue #1894). The bitcode for the free functions wasn't plumbed through for OptiX. This PR rolls the free function definitions into the existing "rendlib" bitcode and PTX. This is somewhat of a stopgap fix; eventually we'll want to handle the free function more explicitly. Fixes #1894 Signed-off-by: Tim Grant <[email protected]>
1 parent 96745ed commit 2a4c401

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

src/include/OSL/oslconfig.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static_assert(sizeof(TypeDesc_pod) == sizeof(TypeDesc),
210210
"TypeDesc size differs from its POD counterpart");
211211

212212
/// Convenience function to convert to a TypeDesc.
213-
inline TypeDesc
213+
OSL_HOSTDEVICE inline TypeDesc
214214
TypeDesc_from(TypeDesc_pod type)
215215
{
216216
return OSL::bitcast<OSL::TypeDesc>(type);

src/testrender/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if (OSL_USE_OPTIX)
2121

2222
set (testrender_rend_lib_srcs
2323
cuda/rend_lib.cu
24+
../testshade/rs_simplerend.cpp
2425
)
2526

2627
# We need to make sure that the PTX files are regenerated whenever these

src/testrender/cuda/rend_lib.cu

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -364,35 +364,6 @@ make_float3(const float4& a)
364364

365365

366366

367-
// FIXME:
368-
// clang++ 9.0 seems to have trouble with tex2d<float4>() look-ups,
369-
// so we'll declare this external and implement texture lookups in
370-
// CUDA files compiled by nvcc (optix_grid_renderer.cu and
371-
// optix_raytrace.cu).
372-
// (clang++ 9.0 error 'undefined __nv_tex_surf_handler')
373-
extern __device__ float4
374-
osl_tex2DLookup(void* handle, float s, float t);
375-
376-
__device__ int
377-
osl_texture(void* sg_, OSL::ustringhash_pod name, void* handle, void* opt_,
378-
float s, float t, float dsdx, float dtdx, float dsdy, float dtdy,
379-
int chans, void* result, void* dresultdx, void* dresultdy,
380-
void* alpha, void* dalphadx, void* dalphady,
381-
void* ustringhash_errormessage)
382-
{
383-
if (!handle)
384-
return 0;
385-
// cudaTextureObject_t texID = cudaTextureObject_t(handle);
386-
float4 fromTexture = osl_tex2DLookup(handle, s, t);
387-
// see note above
388-
// float4 fromTexture = tex2D<float4>(texID, s, t);
389-
*((float3*)result) = make_float3(fromTexture.x, fromTexture.y,
390-
fromTexture.z);
391-
return 1;
392-
}
393-
394-
395-
396367
__device__ int
397368
osl_range_check_err(int indexvalue, int length, OSL::ustringhash_pod symname,
398369
void* sg, OSL::ustringhash_pod sourcefile, int sourceline,

src/testshade/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if (OSL_USE_OPTIX)
2121

2222
set (testshade_rend_lib_srcs
2323
../testrender/cuda/rend_lib.cu
24+
rs_simplerend.cpp
2425
)
2526

2627
set ( testshade_cuda_headers

src/testshade/cuda/optix_grid_renderer.cu

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ __raygen__()
168168
output_buffer[pixel] = { f_output[1], f_output[2], f_output[3] };
169169
}
170170

171-
172-
173171
// Because clang++ 9.0 seems to have trouble with some of the texturing "intrinsics"
174172
// let's do the texture look-ups in this file.
175173
extern "C" __device__ float4

src/testshade/rs_simplerend.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
// SPDX-License-Identifier: BSD-3-Clause
33
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
44

5-
#ifndef OSL_HOST_RS_BITCODE
5+
#if !defined(__CUDACC__) && !defined(OSL_HOST_RS_BITCODE)
66
# error OSL_HOST_RS_BITCODE must be defined by your build system.
77
#endif
88

99
#include <OpenImageIO/fmath.h>
1010

11-
#include <OSL/fmt_util.h>
12-
#include <OSL/journal.h>
11+
#ifndef __CUDACC__
12+
# include <OSL/fmt_util.h>
13+
# include <OSL/journal.h>
14+
#endif
1315
#include <OSL/rendererservices.h>
1416
#include <OSL/rs_free_function.h>
1517

@@ -181,6 +183,14 @@ rs_transform_points(OSL::OpaqueExecContextPtr /*ec*/, OSL::ustringhash /*from*/,
181183
return false;
182184
}
183185

186+
#ifdef __CUDACC__
187+
// This texture lookup function needs to be compiled by NVCC because clang
188+
// doesn't know how to handle CUDA texture intrinsics. This function must be
189+
// defined in the CUDA source for testshade and testrender.
190+
extern "C" __device__ float4
191+
osl_tex2DLookup(void* handle, float s, float t);
192+
#endif
193+
184194
OSL_RSOP OSL_HOSTDEVICE bool
185195
rs_texture(OSL::OpaqueExecContextPtr ec, OSL::ustringhash filename,
186196
OSL::TextureSystem::TextureHandle* texture_handle,
@@ -196,7 +206,12 @@ rs_texture(OSL::OpaqueExecContextPtr ec, OSL::ustringhash filename,
196206
nchannels, result, dresultds, dresultdt,
197207
errormessage);
198208
#else
199-
return false;
209+
if (!texture_handle)
210+
return false;
211+
const float4 fromTexture = osl_tex2DLookup((void*)texture_handle, s, t);
212+
*((float3*)result) = make_float3(fromTexture.x, fromTexture.y,
213+
fromTexture.z);
214+
return true;
200215
#endif
201216
}
202217

@@ -613,6 +628,7 @@ rs_get_interpolated_test(void* val)
613628
return true;
614629
}
615630

631+
#ifndef __CUDACC__
616632
OSL_RSOP OSL_HOSTDEVICE void
617633
rs_errorfmt(OSL::OpaqueExecContextPtr ec, OSL::ustringhash fmt_specification,
618634
int32_t arg_count, const OSL::EncodedType* argTypes,
@@ -668,3 +684,4 @@ rs_filefmt(OSL::OpaqueExecContextPtr ec, OSL::ustringhash filename_hash,
668684
filename_hash, fmt_specification, arg_count, argTypes,
669685
argValuesSize, argValues);
670686
}
687+
#endif // #ifndef __CUDACC__

0 commit comments

Comments
 (0)