Skip to content

Commit e97bfdc

Browse files
committed
Add FrameCompletionScope to ReadTexture — called during init and from getFrameBufferData outside RAF.
1 parent 935bf4a commit e97bfdc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Plugins/NativeEngine/Source/NativeEngine.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,11 @@ namespace Babylon
16481648
}
16491649
else
16501650
{
1651+
// Acquire a FrameCompletionScope for the duration of the read operation.
1652+
// This ensures the encoder is available for the blit (if needed) and that
1653+
// bgfx::readTexture lands in the same frame as the blit.
1654+
Graphics::FrameCompletionScope scope{m_deviceContext.AcquireFrameCompletionScope()};
1655+
16511656
bgfx::TextureHandle sourceTextureHandle{texture->Handle()};
16521657
auto tempTexture = std::make_shared<bool>(false);
16531658

@@ -1656,10 +1661,7 @@ namespace Babylon
16561661
{
16571662
const bgfx::TextureHandle blitTextureHandle{bgfx::createTexture2D(width, height, /*hasMips*/ false, /*numLayers*/ 1, sourceTextureFormat, BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_READ_BACK)};
16581663

1659-
// Acquire a scope to ensure the encoder is available, then blit inline.
1660-
Graphics::FrameCompletionScope blitScope{m_deviceContext.AcquireFrameCompletionScope()};
1661-
bgfx::Encoder* encoder = m_deviceContext.GetActiveEncoder();
1662-
assert(encoder != nullptr);
1664+
bgfx::Encoder* encoder = GetEncoder();
16631665
encoder->blit(static_cast<uint16_t>(bgfx::getCaps()->limits.maxViews - 1), blitTextureHandle, /*dstMip*/ 0, /*dstX*/ 0, /*dstY*/ 0, /*dstZ*/ 0, sourceTextureHandle, mipLevel, x, y, /*srcZ*/ 0, width, height, /*depth*/ 0);
16641666

16651667
sourceTextureHandle = blitTextureHandle;

0 commit comments

Comments
 (0)