Hi !
I did not find anything about “tex2D” in the OptiX7 API Reference nor in the Programming Guide.
So obivously tex2D is used from CUDA
But also at https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html I did not find the answer to my question:
When I use tex2D in an OptiX7-kernel:
tex2D<<b>float4</b>>( id, UV.x , UV.y ).w;
for a 2D image texture created with:
...
channel_desc = cudaCreateChannelDesc<<b>float4</b>>(); // < is it mandatory that these types must match
// with the type specifed at tex2D() ?
cudaMallocArray(&cuda_array, &channel_desc, width, height ));
...
cudaTextureDesc tex_desc = {};
if float type
{
tex_desc.readMode = cudaReadModeElementType;
}
else
{
tex_desc.readMode = cudaReadModeNormalizedFloat;
}
...
cudaCreateTextureObject(&cuda_tex, &res_desc, &tex_desc, nullptr) // init cudaTextureObject_t object
...
cudaMallocArray(&cuda_array,
&channel_desc,
width,
height
)
...
obviously it is not always required for an OptiX7 kernel to initialize the cudaTextureObject_t object with the type used at tex2D<TYPE>
So its also possible to use a smaller texture, right?
For example 8bit (as most image files use) for init of the cudaTextureObject_t object:
channel_desc = cudaCreateChannelDesc<<b>uchar4</b>>();
and then access it the same way as if its a float4
tex2D<float4>( id, UV.x , UV.y ).w;
Due to memory saving optimizations in my app I tried out to use it that other way (and now it works), and also saw this handling in Ingo Walds example code.
https://github.com/ingowald/optix7course/blob/master/example08_addingTextures/SampleRenderer.cpp#L108
https://github.com/ingowald/optix7course/blob/master/example08_addingTextures/devicePrograms.cu#L109
Before I always used float4 (although the source images are mostly 8bit per component).
Is there a speed advantage when using float4 over uchar4 in cudaTextureObject_t ?
Thank you!
My System: OptiX 7.0.0 SDK CUDA 10.1.243 GTX 1050 2GB Win10PRO 64bit (version 1809; build 17763.107) device driver: 442.50 VS2019 v16.4.5 (toolkit v140 of VS2015) MDL SDK 2019.2