This is what I do:
// init GL texture
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32UI, width, height, depth, 0, format, type, NULL);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// upload data to texture ...
// ...
err = cuGraphicsGLRegisterImage(&m_cuGpuMocTree, (GLuint)(*m_gpuMocTree.get()), GL_TEXTURE_3D, CU_GRAPHICS_REGISTER_FLAGS_NONE);
assert(err == CUDA_SUCCESS);
// ...
CUarray gpuMoctree;
err = cuGraphicsSubResourceGetMappedArray(&gpuMoctree, m_cuGpuMocTree, 0, 0);
assert(err == CUDA_SUCCESS);
CUtexref texrefMoctree;
err = cuModuleGetTexRef(&texrefMoctree, m_raycastProgram, "moctree");
assert(err == CUDA_SUCCESS);
err = cuTexRefSetArray(texrefMoctree, gpuMoctree, CU_TRSA_OVERRIDE_FORMAT);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetAddressMode(texrefMoctree, 0, CU_TR_ADDRESS_MODE_CLAMP);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetAddressMode(texrefMoctree, 1, CU_TR_ADDRESS_MODE_CLAMP);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetAddressMode(texrefMoctree, 2, CU_TR_ADDRESS_MODE_CLAMP);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetFilterMode(texrefMoctree, CU_TR_FILTER_MODE_POINT);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetFlags(texrefMoctree, CU_TRSF_READ_AS_INTEGER);
assert(err == CUDA_SUCCESS);
err = cuTexRefSetFormat(texrefMoctree, CU_AD_FORMAT_UNSIGNED_INT32, 4);
assert(err == CUDA_SUCCESS);
// ...
cuLaunchKernel(m_raycastIntersect,....);
// ...
// tear down stuff
And the CUDA C program:
// ...
texture<uint4, cudaTextureType3D, cudaReadModeElementType> moctree;
// ...
extern "C" __global__ void raycastIntersect(...)
{
// ...
uint4 at = tex3D(moctree, x, y, z);
// ...
}
All of the components are always zero and the “moctree” texref shows “???” when putting a breakpoint with CUDA Debugger. All the asserts do pass. This is on a GTX Titan on Win8 x64.
Anything clearly wrong here?
Cheers!