Hello,
I tried to copy the “Post-Process in OpenGL” example and everything went well, until I transfered it to a 3D texture probleme. I found out that cudaMemcpyToArray(…) is not a valid fuction for this situation. So I tried cudaMemcpy3D():
cudaArray *texture_ptr;
cutilSafeCall(cudaGraphicsMapResources(1, &cuda_tex, 0));
cutilSafeCall(cudaGraphicsSubResourceGetMappedArray(&texture_ptr, cuda_tex, 0, 0));
int num_texels = size.width * size.height * size.depth;
int num_values = num_texels;
int size_tex_data = sizeof(VolumeType) * num_values;cudaMemcpy3DParms copyParams = {0};
copyParams.srcPtr = make_cudaPitchedPtr((void*)cuda_dest_resource, size_tex_data, size.height, size.depth);
copyParams.dstArray = texture_ptr;
copyParams.extent = size;
copyParams.kind = cudaMemcpyDeviceToDevice;
cutilSafeCall(cudaMemcpy3D(©Params));
cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_tex, 0));
The old version was:
cutilSafeCall(cudaMemcpyToArray(texture_ptr, 0, 0, cuda_dest_resource, size_tex_data, cudaMemcpyDeviceToDevice));
I created the CUDA Buffer als follow:
// set up vertex data parameter
int num_texels = size.width * size.height * size.depth;
int num_values = num_texels;
int size_tex_data = sizeof(VolumeType) * num_values;
cutilSafeCall(cudaMalloc((void**)&cuda_dest_resource, size_tex_data));
And the OpenGl Texture:
glGenTextures(1, &opengl_tex);
glBindTexture(GL_TEXTURE_3D, opengl_tex);
// set basic parameters
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);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F_ARB, size.width, size.height, size.depth, 0, GL_RGBA, GL_FLOAT, pixels);
// register this texture with CUDA
cutilSafeCall(cudaGraphicsGLRegisterImage(&cuda_dest_resource, opengl_tex,
GL_TEXTURE_3D, cudaGraphicsMapFlagsReadOnly));
I got an “invalid argument” error at the position:
cutilSafeCall(cudaMemcpy3D(©Params));
Does anyone know what I have done wrong ?
Thanks
Many Regards,
Matthias