I believe I am doing something fundamentally wrong when binding pitched memory to 2D textures. I have a kernel that works fine, when the pitch equals the width. Somehow the texture seems to deliver wrong values when the pitch is not equal to the width.
//Texture reference to work represent image data texture<unsigned char, 2, cudaReadModeElementType> bayTex;
//Bind Texture to reference const textureReference* bayTexPtr; cudaGetTextureReference(&bayTexPtr, "bayTex"); cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<unsigned char>(); //Set acces parameters bayTex.addressMode = cudaAddressModeClamp; bayTex.addressMode = cudaAddressModeClamp; //Bind pitched data to texture unsigned int width_px = source->d_width / (source->d_padding * source->element_size); cudaBindTexture2D(NULL, bayTexPtr, source->d_pointer, &channelDesc, width_px, source->d_height, source->d_pitch);
I am fetching my values with tex2D(bayTex, x, y). When I put in the same image with different crop (resulting in different pitch), the same texture position returns different results.
P.S.: What about that offset parameter? Do I need to use it?