Texture data types Can uchar data put into a float texture?

Hi!

I tried to put unsigned char data into a float texture, to get a linearly filtered image at subpixel locations:

texture<float, 2, cudaReadModeElementType > tex1; 

void bindTexture( unsigned char* dPtrImg, int size1, int size2, int pitch )

{

  cudaChannelFormatDesc oUCharDesc = cudaCreateChannelDesc<unsigned char>();

  cudaBindTexture2D(0, &tex1, static_cast< void* >( dPtrImg), &oUCharDesc, size1, size2, pitch); 

  tex1.filterMode = cudaFilterModeLinear;

}

However, a call to tex2D always returns a normalised float value (so 0…255 is mapped to 0…1), despite the given cudaReadModeElementType in the texture definition.

The mapping of integer to float is always in the range [-1.0,] 0.0, 1.0 as in 0% - 100%, so what you are getting back is what is expected.

The linear aspect of the filtering refers to that sampling in between points returns the linear interpolation of the two points ie; for ushort, two adjacent points with the values 0, 65535 returns 0.5 if sampled excactly in the middle. There are 255 “virtual samples” - each differing from the previous and/or next by 0.4% of the whole difference between the two real samples - that the interpolator can return.

Note that it is the selection and not the return value that is quantized. Two adjacent integer values like 101, 102 will still have 255 evenly distributed float values in between them.

Thanks for the explanation, especially for pointing out the quantization step for the selection.