Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read external texture pixel data on D3D12 without concurrent access warning #1452

Open
jawhiteh opened this issue Jan 8, 2025 · 2 comments

Comments

@jawhiteh
Copy link

jawhiteh commented Jan 8, 2025

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.

@bghgary
Copy link
Contributor

bghgary commented Jan 10, 2025

Related issue for Metal: #1385

@SergioRZMasson
Copy link
Contributor

@jawhiteh , It is possible to ensure proper concurrent access to the ID3D12Resource object by using the same CommandQueue to submit the CommandList that Babylon Native is using internally as well as using proper resource Resource Barriers.

I have a PR to update the documentation for External Texture with examples on how to properly access the Resource.

#1453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants