bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.59k stars 1.92k forks source link

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

Open vbousquet opened 4 weeks ago

vbousquet commented 4 weeks ago

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): https://github.com/bkaradzic/bgfx/compare/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):