CUdeviceptr to ID3D11Texture2D
I need a cuda device pointer (CUdeviceptr) to a ID3D11Texture2D. My first try:

[code]
D3D11_TEXTURE2D_DESC desc;
desc.Width = width;
desc.Height = height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;

ID3D11Texture2D *pTextureBuffer;
if( FAILED( m_pd3dDevice->CreateTexture2D( &desc, nullptr, &pTextureBuffer ) ) )
std::cout<<"CreateTexture2D failed"<<std::endl;

CUgraphicsResource cudaResource;

CUresult result = cuGraphicsD3D11RegisterResource( &cudaResource,
pTextureBuffer,
CU_GRAPHICS_REGISTER_FLAGS_NONE);
if (result != CUDA_SUCCESS)
std::cout<<"cuGraphicsD3D11RegisterResource failed"<<std::endl;

result = cuGraphicsResourceSetMapFlags(cuResource, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (result != CUDA_SUCCESS)
std::cout<<"cuGraphicsResourceSetMapFlags failed"<<std::endl;

result = cuGraphicsMapResources(1, &cudaResource, 0);
if (result != CUDA_SUCCESS)
std::cout<<"cuGraphicsMapResources failed"<<std::endl;

size_t num_bytes;
CUdeviceptr pDevPtr;
result = cuGraphicsResourceGetMappedPointer(&pDevPtr, &num_bytes, cudaResource);
if (result != CUDA_SUCCESS)
std::cout<<"cuGraphicsResourceGetMappedPointer failed"<<std::endl;
[/code]

It doesn’t work - I always get "cuGraphicsResourceGetMappedPointer failed" message. What am I doing wrong?
I need a cuda device pointer (CUdeviceptr) to a ID3D11Texture2D. My first try:





D3D11_TEXTURE2D_DESC desc;

desc.Width = width;

desc.Height = height;

desc.MipLevels = 1;

desc.ArraySize = 1;

desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;

desc.SampleDesc.Count = 1;

desc.SampleDesc.Quality = 0;

desc.Usage = D3D11_USAGE_DEFAULT;

desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

desc.CPUAccessFlags = 0;

desc.MiscFlags = 0;



ID3D11Texture2D *pTextureBuffer;

if( FAILED( m_pd3dDevice->CreateTexture2D( &desc, nullptr, &pTextureBuffer ) ) )

std::cout<<"CreateTexture2D failed"<<std::endl;



CUgraphicsResource cudaResource;



CUresult result = cuGraphicsD3D11RegisterResource( &cudaResource,

pTextureBuffer,

CU_GRAPHICS_REGISTER_FLAGS_NONE);

if (result != CUDA_SUCCESS)

std::cout<<"cuGraphicsD3D11RegisterResource failed"<<std::endl;



result = cuGraphicsResourceSetMapFlags(cuResource, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);

if (result != CUDA_SUCCESS)

std::cout<<"cuGraphicsResourceSetMapFlags failed"<<std::endl;



result = cuGraphicsMapResources(1, &cudaResource, 0);

if (result != CUDA_SUCCESS)

std::cout<<"cuGraphicsMapResources failed"<<std::endl;



size_t num_bytes;

CUdeviceptr pDevPtr;

result = cuGraphicsResourceGetMappedPointer(&pDevPtr, &num_bytes, cudaResource);

if (result != CUDA_SUCCESS)

std::cout<<"cuGraphicsResourceGetMappedPointer failed"<<std::endl;




It doesn’t work - I always get "cuGraphicsResourceGetMappedPointer failed" message. What am I doing wrong?

#1
Posted 07/06/2011 03:22 PM   
You need to use cuGraphicsSubResourceGetMappedArray (for textures) instead of cuGraphicsResourceGetMappedPointer (for buffers).
You need to use cuGraphicsSubResourceGetMappedArray (for textures) instead of cuGraphicsResourceGetMappedPointer (for buffers).

#2
Posted 02/02/2012 03:34 PM   
Scroll To Top