Hello,
I have some problem with textures… namely, I cannot understand how do they work.
I’m loading some image from host to the texture like this:
/ allocate CUDA array in the device and copy image data
cudaChannelFormatDesc channelDesc;
channelDesc = cudaCreateChannelDesc(32, 32,32, 32,cudaChannelFormatKindUnsigned );
cudaArray *cuArray;
cutilSafeCall( cudaMallocArray( &cuArray, &channelDesc, imgW, imgH ) );
cutilSafeCall( cudaMemcpyToArray( cuArray, 0, 0, img->getImgArray(), mem_size, cudaMemcpyHostToDevice ));
// set texture parameters
texRef.addressMode[0] = cudaAddressModeClamp;
texRef.addressMode[1] = cudaAddressModeClamp;
texRef.filterMode = cudaFilterModePoint;
texRef.normalized = false;
Then I wrote simple copy kernel, that copies pixels to some output array. The point is, I don’t know how can I access pixels in the texture . I used examples from NVIDIA but I still cannot understand how do the use it (everything through bit operations …and this doesn’t work, in my case, at all — why ?! and why do the shift it by 16, 24 … !!! - could somebody explain me how does texture and those bit operations work ? - I would be glad for every answer
This is my kernel :
texture<uchar4, 2, cudaReadModeElementType> texRef;
__global__
void copy_kernel ( IType *dst, int imgW, int imgH ) {
const int idx = blockIdx.x*blockDim.x + threadIdx.x;
const int idy = blockIdx.y*blockDim.y + threadIdx.y;
const float x = ( float )idx + 0.5f;
const float y = ( float )idy + 0.5f;
if( idx < imgW && idy < imgH ) {
uchar4 rgba = tex2D( texRef, y, x );
dst[ (imgW*idx + idy) + 0 ] = ((uchar)(rgba.w ) << 24) | ((uchar)(rgba.z) << 16) | ((uchar)(rgba.y) << 8) | ((uchar)(rgba.x) << 0);
/* dst[ (imgW*idx + idy) + 1 ] = rgba.y;
dst[ (imgW*idx + idy) + 2 ] = rgba.z;
dst[ (imgW*idx + idy) + 3 ] = rgba.w;
*/
}
}
This is what I’m getting … (see attch)