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

bgfx:blit on texture arrays does not handle layers past the first one consistently #3301

Open
vbousquet opened this issue Jun 2, 2024 · 0 comments
Labels

Comments

@vbousquet
Copy link

vbousquet commented Jun 2, 2024

Describe the bug
Using bgfx::blit between two 2D texture arrays results in blitting only the first layer (using the blit overload that allows to set _depth to 2).

To Reproduce

  1. Create two 2D Texture Array with at least 2 layers
  2. Call bgfx::blit(viewId, destTex, 0, 0, 0, 0, srcTex, 0, 0, 0, 0, width, height, 2);
  3. Observe that second layer is not blitted (verified in RenderDoc for D3D11 and Vulkan)

Expected behavior
blit should honor the z and depth parameters or assert invalid parameter combinations.

Screenshots
NA

Additional context
I came up with a simple fix which works fine for my use case (porting Visual Pinball X, a large open source pinball simulator, to BGFX): master...vbousquet:bgfx:fix_texarray_blit
Note that this fix was only tested for D3D11 and Vulkan with limited test case (BGFX examples do not use this feature, Visual Pinball X has a single use case when rendering for VR or anaglyph stereo)

This fix was made after some search and diving into the bgfx D3D11, OpenGL and Vulkan renderer source. It is based on the understanding I got from this which is the following (and may be wrong):

  • The API intent is that _dstZ, _srcZ, _depth are used as z for 3D texture, side for cubemap, and as layer index for texture array. I may be completely wrong on that as this is not stated in the API doc (only cubemap and 3D) but the code seems to show this intent, at least it is what it does. For Vk:
    if (VK_IMAGE_VIEW_TYPE_3D == src.m_type)
    for OpenGl:
    GL_CHECK(glCopyImageSubData(src.m_id
    for D3D11:
    deviceCtx->CopySubresourceRegion(dst.m_ptr
  • blit calls are validated against 6 sides of cubemaps (no support for cubemap array) or 3D texture depth but not number of layers of texture array leading to always considering depth as 0. This is the reason only the first layer is blitted:

    bgfx/src/bgfx.cpp

    Line 4025 in 00fa5ad

    uint32_t srcDepth = src.isCubeMap() ? 6 : bx::max<uint32_t>(1, src.m_depth >> _srcMip);
  • D3D11 renderer rely on CopySubresourceRegion which allows to copy only one layer at a time. So either depth should be asserted for value above 1 or multiple calls should be performed.
@vbousquet vbousquet changed the title bgfxx:blit on texture arrays does not handle layers past the first one consistently bgfx:blit on texture arrays does not handle layers past the first one consistently Jun 2, 2024
@bkaradzic bkaradzic added the bug label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants