Jump to content
  • Advertisement
Sign in to follow this  
forsandifs

Clearing a ID311Buffer

This topic is 2836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to clear the information held in a structured ID3D11Buffer every time I render a frame. The buffer is bound to the device as a RWStructuredBuffer UAV. Currently I have tried:

[spoiler]
while( WM_QUIT != msg.message )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
pDeviceContext()->CopyResource( &MyBuffer, &EmptyVersionOfMyBuffer );

MyShader.Dispatch();

D3DSys.pGetSwapChain()->Present( 0, 0 );
}
}
[/spoiler]

and:

[spoiler]
while( WM_QUIT != msg.message )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
ZeroMemory( &MyBuffer, sizeof(MyBuffer) );

MyShader.Dispatch();

D3DSys.pGetSwapChain()->Present( 0, 0 );
}
}
[/spoiler]

Using the CopyResource method kills the performance (MyBuffer is large in size) and is therefore unacceptable.

Using the ZeroMemory method seems to work as intended without noticeably affecting performance, but when I exit the program I get the following debug output: First-chance exception at 0x6244fe9f in MyProgram.exe: 0xC0000005: Access violation reading location 0x00000004.
Unhandled exception at 0x6244fe9f in MyProgram.exe: 0xC0000005: Access violation reading location 0x00000004.


Questions:

Are there alternatives ways to clear the information in a structured ID3D11Buffer?

When using the ZeroMemory method what could be causing the exception error?

Share this post


Link to post
Share on other sites
Advertisement
Hmmm, given that the structure of the buffer is 3 UINT32s I could seperate it into 3 UINT buffers and thus be able to use[font="Arial"] the ID3D11DeviceContext::ClearUnorderedAccessViewUint method to clear it.

Still, it would be nice to not have to do that if possible.[/font]

Share this post


Link to post
Share on other sites

ZeroMemory( pMyBuffer, sizeof(MyBuffer) );


Is pMyBuffer a variable of type ID3D11Buffer*? If it is, then this most definitely does not do what you think it does...

Share this post


Link to post
Share on other sites


ZeroMemory( pMyBuffer, sizeof(MyBuffer) );


Is pMyBuffer a variable of type ID3D11Buffer*? If it is, then this most definitely does not do what you think it does...


Yes it is of that type.

Share this post


Link to post
Share on other sites
So a ID3D11Buffer* is not a pointer some area of memory that you can just access. It's a pointer to an interface, that is basically a proxy or wrapper for a GPU resource managed by the driver. The only way to have CPU code modify the actual contents of a buffer or any other resource is to call Map on it and access the pointer it gives you, and you can only do this if the resource was created with the appropriate usage and CPU access flags.

You could certainly try writing a compute shader that fills the buffer with 0's. You should be able to achieve good performance by maximizing the number of threads per group (1024 is your max) and by having a good amount of groups as well to keep all of the different multiprocessors on the GPU busy. Either way if you're concerned about performance, you should use a GPU profiling tool so that you can ensure that you're actually spending the time where you think you're spending it.

Share this post


Link to post
Share on other sites
as alternative to clearing the ID3D11Buffer with 400 elements with type R32_FLOAT
for example if it consists of floats and u need to clear them all to 1


std::vector<float> data;//make sure that this thing is aligned
data.resize(400);
devc11->UpdateSubResource(buffer,&data[0]);


as alternative u can map it with discard and clear there

Share this post


Link to post
Share on other sites
Having tested the methods suggested in the thread it seems the fastest method by far is to use a shader to clear the buffer. The second fastest is the CopyResource method.

If anyone has any suggestions that could be faster than the shader method please let me know.

Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!