NativeCapture: off-screen capture cannot describe NativeEngine render targets (unregistered, no sRGB flag)

Đang mở
#2,090 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend

Hướng nghiên cứu

Start with Plugins/NativeCapture/Source/NativeCapture.cpp and trace how OffScreenBufferFrameProvider creates and blits its readback target. Read Core/Graphics/InternalInclude/Babylon/Graphics/DeviceContext.h, Plugins/NativeXr/Source/NativeXrImpl.cpp, and the NativeEngine::InitializeTexture path to understand the missing texture description and sRGB flag. Done means NativeCapture can use the framebuffer attachment's size, format, and flags to create a compatible target; the issue reports no device reproduction or validation result.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

OffScreenBufferFrameProvider in Plugins/NativeCapture/Source/NativeCapture.cpp creates its readback blit target from DeviceContext::GetTextureInfo:

bgfx::createTexture2D(m_textureInfo.Width, m_textureInfo.Height, m_textureInfo.HasMips, m_textureInfo.NumLayers,
    m_textureInfo.Format, BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_READ_BACK)

and blits the framebuffer's colour texture into it every frame. That description is incomplete in two ways.

  1. NativeEngine textures are not registered. DeviceContext::AddTexture is only called by NativeXr (Plugins/NativeXr/Source/NativeXrImpl.cpp, BeginUpdate); NativeEngine stopped registering its textures in #1173. DeviceContext::GetTextureInfo returns m_textureHandleToInfo[handle.idx], so an unknown handle yields a default-constructed TextureInfo. Capturing a framebuffer created through NativeEngine therefore builds the blit target from width 0, height 0 and format value 0, and the blit's source and destination formats differ on every backend.
  2. No texture flags. Graphics::TextureInfo (Core/Graphics/InternalInclude/Babylon/Graphics/DeviceContext.h) carries width, height, mips, layers and format only. A source created with BGFX_TEXTURE_SRGB (NativeEngine::InitializeTexture sets it for sRGB render targets) would get a non-sRGB blit target. The bgfx Metal renderer (pinned 6d878f16) maps that flag to the _sRGB pixel format and blits with copyFromTexture, so the two pixel formats differ. This is the mismatch #2072 fixes for readTexture, where Metal API validation reports it.

Gap 1 hides gap 2 today: the only registered source is the NativeXr colour texture, which is linear on both sides (ARKit allocates MTLPixelFormatBGRA8Unorm, imported as bgfx::TextureFormat::BGRA8). Registering NativeEngine textures without carrying their flags would expose gap 2 for sRGB render targets.

Raised in https://github.com/BabylonJS/BabylonNative/pull/2072#discussion_r4529937549. Checked on master 020832ba; #2072 (head 86bfe570) does not change NativeCapture or TextureInfo.

Platform / backend

Gap 1: all backends. Gap 2: Metal; other backends not examined.

Reproduce

Create a RenderTargetTexture with useSRGBBuffer: true, add it to scene.customRenderTargets, and pass its native framebuffer to new NativeCapture(frameBuffer) with a callback that logs each frame's width, height and format.

Expected: frames with the render target's size in RGBA8. From the code, the blit target is created from the zero-initialised description instead. With the texture info supplied, running with Metal API validation enabled should report the sRGB / non-sRGB blit.

Not measured

Both gaps are established from the code path only. Neither the capture above nor the Metal validation failure has been run or captured on a device.

Suggested direction

Have the capture path get size, format and flags from the framebuffer it is given (for example by having Graphics::FrameBuffer expose its colour attachment's description) instead of the AddTexture registry, which DeviceContext.h already marks with a TODO, and keep BGFX_TEXTURE_SRGB on the blit target as #2072 does for readTexture.

Ngôn ngữ chính
C++
Star
931
Fork
169
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
66

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của BabylonJS/BabylonNative

Tất cả issue của BabylonJS/BabylonNative

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.