tex2DGrad - exception when translating PTX to LLVM

I am always getting an exception when using tex2DGrad. Generating the ptx file works just fine but when I am trying to execute the program it tells me the following:

OptiX Error: 'Parse error (Details: Function “RTresult _rtProgramCreateFromPTXFile(RTcontext, const char*, const char*, RTprogram_api**)” caught exception: […].ptx: error: Failed to translate PTX input to LLVM
Unexpected cast from: <2 x float> to: float
Unexpected cast from: <2 x float> to: float

I tried using the optix sample optixTextureSample and just replaced the following call:

result_buffer[launch_index] = tex2D(input_texture, uv.x, uv.y);

with this one (just for testing purposes):

result_buffer[launch_index] = tex2DGrad(input_texture, uv.x, uv.y, make_float2(0.0, 0.0), make_float2(0.0, 0.0));

and it results in the same exception.

Does anyone know whats the problem here? I need tex2DGrad to prevent texture aliasing in our raytracer.

I am using Optix 4.1.0 and Cuda 8.0.61_375.26 in OpenSUSE 13.2

Only tex1D, tex2D, and tex3D are documented to be used on TextureSamplers directly in OptiX.
That’s the legacy way to access texture samplers and it’s not recommended in general because it will imply limits on the number of textures you can use in a scene.

Instead please convert the code to use bindless texture IDs and then you can use all template functions documented inside the OptiX API Reference document around page 70, or search headers inside the OptiX SDK include folder for “rtTex2DGrad” in your specific case. It’s defined in optix_device.h.

You can get the texture ID from an optix::TextureSampler with sampler->getId() on the host.
On the device side it’s just an int.
The special pre-defined texture ID RT_TEXTURE_ID_NULL allows to check on device side if a texture is present or not.
A call to lookup from a bindless texture via its texture ID can look like this:
const float4 result = optix::rtTex2D(textureID, uv.x, uv.y);

Thanks a lot, it works now!