-
Notifications
You must be signed in to change notification settings - Fork 151
Description
We are using Babylon Native with D3D12 in a workflow that requires us to copy the pixel data from the underlying texture of an external texture that we use with Babylon. When we try to execute a command list to copy data out of the texture we get the following warning related to concurrent access, which implies that GPU commands using that texture are still executing even though FinishRenderingCurrentFrame has completed.
D3D12 ERROR: ID3D12CommandQueue::ExecuteCommandLists: Non-simultaneous-access Texture Resource (0x000001898D538120:'RenderTarget') is still referenced by write|transition_barrier GPU operations in-flight on another Command Queue (0x00000189837EA1F0:'Unnamed ID3D12CommandQueue Object'). It is not safe to start read|write|transition_barrier GPU operations now on this Command Queue (0x00000189837A7CD0:'InteropCommandQueue'). This can result in race conditions and application instability. [ EXECUTION ERROR #1047: OBJECT_ACCESSED_WHILE_STILL_IN_USE]
A simplified snippet of the code is here:
this->BabylonGraphicsDeviceUpdate->Finish();
this->BabylonGraphicsDevice->FinishRenderingCurrentFrame();
// Inserting this sleep fixes the problem
// Sleep(100);
D3D12_TEXTURE_COPY_LOCATION dstLocation;
dstLocation.pResource = uploadBuffer.get();
dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
dstLocation.PlacedFootprint = placedTexture2D;
D3D12_TEXTURE_COPY_LOCATION srcLocation;
srcLocation.pResource = texture.get(); // <--- This is the 'RenderTarget' underlying the external texture
srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
srcLocation.PlacedFootprint = {};
D3DCommandList->CopyTextureRegion(
&dstLocation,
0, 0, 0,
&srcLocation,
nullptr);
check_hresult(D3DCommandList->Close()); // <-- The warning appears here
this->BabylonGraphicsDevice->StartRenderingCurrentFrame();
this->BabylonGraphicsDeviceUpdate->Start();
We need a safe way to access the pixel data of the external texture that is synchronized with Babylon's rendering.