ID3D11DeviceContext::CopyResource with different D3D11_USAGE

1.4k views Asked by At

I am exporing Nvidia's Flex but I am very new to D3D. I am trying to copy between two ID3D11Buffer which are created using different D3D11_BUFFER_DESC. I wanted to use ID3D11DeviceContext::CopyResource() since it's GPU-GPU copy but the code is throwing exception.

Two buffers are created as below:

//First Buffer:
D3D11_BUFFER_DESC bufDesc;
bufDesc.ByteWidth = numParticles*sizeof(Vec4);
bufDesc.Usage = D3D11_USAGE_DYNAMIC;
bufDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bufDesc.MiscFlags = 0;
bufDesc.StructureByteStride = 0;
m_device->CreateBuffer(&bufDesc, NULL, buff0);

//Second Buffer
D3D11_BUFFER_DESC bufDescTemp;
bufDescTemp.ByteWidth = numParticles * sizeof(Vec4);
bufDescTemp.Usage =  D3D11_USAGE_DEFAULT;
bufDescTemp.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufDescTemp.CPUAccessFlags = 
D3D11_CPU_ACCESS_READ;//D3D11_CPU_ACCESS_READ;// 
bufDescTemp.MiscFlags = 0;
bufDescTemp.StructureByteStride = 0;
m_device->CreateBuffer(&bufDescTemp, NULL, buff1);

Then at each frame I get an updated buff0 from Flex's NvFlexGet. Then I try to copy buff0 to buff1:

context->CopyResource(buff1,buff0);

But this line throws exception. It works fine if both buffers are created using D3D11_USAGE_DYNAMIC. But not when buff1 is D3D11_USAGE_DEFAULT.

Does ID3D11DeviceContext::CopyResource supports copy between buffers with different D3D11_USAGE? Or did I miss something?

1

There are 1 answers

3
VuVirt On

D3D11_USAGE_DYNAMIC means a resource that is accessible by both the GPU (read only) and the CPU (write only). That's why it cannot be used in CopyResource.