bugfix(bgfx): Sample the scene composite the right way up on GLES - #3
bugfix(bgfx): Sample the scene composite the right way up on GLES#3githubawn wants to merge 523 commits into
Conversation
… on Windows (cherry picked from commit 3704ae283516a47b27d4a5511566d4f8f6169a7c) (cherry picked from commit c2e4ebd508ef4ebdaa1bdc1ac513632dce0bf5a6)
…n-Windows builds (cherry picked from commit bc2a0e474438860d80addcbf6e1795624624ecd9) (cherry picked from commit 79c1e3c42fb96fa060f78720ed80ab3f424162a4)
…destroyed (cherry picked from commit 757b56e262097d43b3dbba912e1026fef11a6efe) (cherry picked from commit 5e6c40439b05766d872e32e4a3f5b780bd92f7ab)
…pling can't read out of bounds and crash (cherry picked from commit bcf96610c984fde5d1bd614cb94569c06ba13db6) (cherry picked from commit d3f978645a3a89cb747220d6aa9f58631b0e87e6)
…ady on construction complete (non-retail CRC) (cherry picked from commit 323a3c220da03d8e7b7c636a5fc049d6f9715f9b) (cherry picked from commit dbee96e4b2aeb170ff4f89a9d64af98881ecae7a)
…erals Challenge so the next general isn't instantly defeated (cherry picked from commit 255fc6bacfa2db0a346b87f550f0dffff8889237) (cherry picked from commit 053938d17936b1cba41436c658a0bf38f5467ba5)
…e Continue starts the next battle instead of an instant defeat (cherry picked from commit ba12ef4621e95d7719c542f17388802532f40ba1) (cherry picked from commit 09110dd45e6b4dcfcac75b5334de6d7fe9a6866d)
…int so debug builds link (cherry picked from commit a3d78a591598b5abadd60470de79d4077e42e252) (cherry picked from commit 60e92e4fa5dc9559f87ecdb9a5b4c6bada19ae42)
…_ZOOM hack, deferring camera height limits to GameData.ini (cherry picked from commit a2625f8ee57fb8c9955a8f5a52444f7f1d4dd1b2) (cherry picked from commit 79fe3af9c0bfe5e6bf8d0302678b414251b05333)
(cherry picked from commit 6aca92fca0d16b65a30b76ced3d0cc40e2d528ee) (cherry picked from commit 8b5dceefe4b42fc9c7c1420565efaa5d1170337c)
…ur, composite add)
…lowout on bright surfaces
…eState use-after-free
…tch CI on Ubuntu 24.04
…d Linux setup to release notes
… WINE import helper
…to avoid ABI mixing
The composite pass reads the scene render target back to the swapchain with a fullscreen triangle. Render targets are bottom-left origin on GLES and WebGL but top-left on DX11 and Metal, and nothing accounted for that: the vertex shader built one fixed set of texture coordinates and the backend passed a hardcoded 0 where the flip flag belongs. So everything that goes through the composite - the whole 3D scene - came out vertically mirrored on those renderers, while the UI, which draws straight to the swapchain, stayed upright. That reads as "the game is upside down but the menus are not". Carry the flag in u_postTexelSize.z again, from bgfx's originBottomLeft cap, and flip V in the vertex shader when it is set. DX11 and Metal report false and pass 0.0, so they are byte-for-byte unaffected. (cherry picked from commit 755d205)
| v_texcoord0 = vec2(a_position.x * 0.5 + 0.5, 0.5 - a_position.y * 0.5); | ||
| float u = a_position.x * 0.5 + 0.5; | ||
| float v = 0.5 - a_position.y * 0.5; | ||
| if (u_postTexelSize.z > 0.5) |
There was a problem hiding this comment.
vs_scene_composite is also linked into the bloom-bright, bloom-blur, SSAO and copy programs (BgfxBackend.cpp:4471-4485), but .z is assigned only in SubmitSceneComposite. SubmitSSAO explicitly writes 0.0f (:3869), and the bloom, blur and copy submits never set this uniform at all — with submit order Bloom → SSAO → Composite (:6070-6072), the bloom passes inherit whatever the previous frame's composite left behind, which is undefined on the first frame. copyProgram feeds both kBgfxSmudgeCopyView (:11925) and kBgfxPointShadowVizView (:3339), whose consumers handle UVs differently.
Let's set the intended value explicitly at every submit that uses this VS, or split out purpose-specific fullscreen vertex shaders, and verify each producer/consumer pair.
66cf60b to
0f1e948
Compare
The scene composite pass reads the scene render target back to the swapchain with a fullscreen triangle. Render targets are bottom-left origin on GLES and WebGL but top-left on DX11 and Metal, and nothing accounted for that: the vertex shader built one fixed set of texture coordinates, and the backend passed a hardcoded
0where the flip flag belongs.So everything that goes through the composite — the whole 3D scene — came out vertically mirrored on those renderers, while the UI, which draws straight to the swapchain, stayed upright. That reads as "the game is upside down but the menus are not".
Fix
Carry the flag in
u_postTexelSize.z, sourced from bgfx'soriginBottomLeftcap, and flip V in the vertex shader when it is set.Platform impact
DX11 and Metal report
originBottomLeft == falseand pass0.0, so the sampled coordinates are identical to before — those backends are byte-for-byte unaffected. The behaviour change is confined to bottom-left-origin renderers, which are the ones that were wrong.On trunk the composite is gated only on the scene framebuffer being valid, not on render-resolution scaling, so this affects any GLES/WebGL target that has the scene framebuffer active.
Testing
Verified on the Emscripten/WebGL build, where the 3D scene rendered mirrored before the change and correct after. Not runtime-verified on Android GLES or desktop GL — those go through the same cap and should be fixed identically, but a second pair of eyes there would be welcome.