Expose more functions#10
Merged
CedricGuillemet merged 4 commits intoMay 12, 2026
Merged
Conversation
…exposeMissingFunctions # Conflicts: # spirv_hlsl.cpp
There was a problem hiding this comment.
Pull request overview
This PR adjusts SPIRV-Cross’ WEBMIN build configuration to expose additional MSL and HLSL codegen helpers that were previously excluded (or stubbed as invalid), enabling more shaders/opcodes to be validated under WEBMIN (as needed by the referenced BabylonNative unittest).
Changes:
- MSL: Move several helper implementations out of
SPIRV_CROSS_WEBMIN-guarded regions and remove corresponding WEBMIN stubs. - HLSL: Remove
SPIRV_CROSS_WEBMINguards that previously rejected certain opcodes (e.g.,OpFMod,OpFwidth*,OpIsNan/OpIsInf, logical ops) and expose required helper implementations. - General: Refactor/reorder function definitions to make the newly exposed functionality available in WEBMIN builds.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spirv_msl.cpp | Exposes additional MSL helper implementations to WEBMIN and removes now-unneeded WEBMIN stubs. |
| spirv_hlsl.cpp | Enables more instruction emission paths under WEBMIN and moves helper implementations to be available in WEBMIN builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+24456
to
+24463
| // Pass internal array of spvUnsafeArray<> into wrapper functions | ||
| if (lhs_is_array_template && rhs_is_array_template && !msl_options.force_native_arrays) | ||
| statement("spvArrayCopy", tag, type.array.size(), "(", lhs, ".elements, ", to_expression(rhs_id), ".elements);"); | ||
| if (lhs_is_array_template && !msl_options.force_native_arrays) | ||
| statement("spvArrayCopy", tag, type.array.size(), "(", lhs, ".elements, ", to_expression(rhs_id), ");"); | ||
| else if (rhs_is_array_template && !msl_options.force_native_arrays) | ||
| statement("spvArrayCopy", tag, type.array.size(), "(", lhs, ", ", to_expression(rhs_id), ".elements);"); | ||
| else |
bkaradzic-microsoft
approved these changes
May 12, 2026
This was referenced May 14, 2026
bkaradzic-microsoft
added a commit
that referenced
this pull request
May 15, 2026
Continues the work in #6-#10. Removes WEBMIN guards around four opcodes/helpers that Babylon Native's shader compiler trips on: - OpSNegate (case in CompilerGLSL_emit_instruction) - OpVectorTimesMatrix (cases in emit_instruction and CompilerGLSL_emit_instruction) - OpVectorExtractDynamic (case in CompilerGLSL_emit_instruction) - to_extract_constant_composite_expression() helper (replaces INVALID_CALL stub with the real implementation already present in the same file) These were the only remaining SPIRV-Cross stubs reachable by Babylon Native's HLSL transpile path on D3D11. Net change: +35 / -20 lines.
bkaradzic-microsoft
added a commit
to bkaradzic-microsoft/BabylonNative
that referenced
this pull request
May 15, 2026
Picks up BabylonJS/SPIRV-Cross#10 which removes the SPIRV_CROSS_WEBMIN stubs (SPIRV_CROSS_INVALID_CALL -> assert(false)) around OpFMod, OpLogicalOr, and other opcodes commonly emitted by Babylon.js shaders. Re-tested 46 previously-excluded validation_native.js tests on the bumped SPIRV-Cross. Net change: 0 -> 9 PASS, 1 -> 5 FAIL_PIXEL_DIFF, 45 -> 31 still failing with shader-compile errors. The bump revealed that several of the 31 remaining failures had distinct root causes that the SPIRV-Cross assert was masking: PrePassRenderer WebGL2 capability check, GPU-particle ARRAY_BUFFER bug, area-lights LTC asset load failures, and a different remaining stub site for OpenPBR. Follow-up issues are being filed to track those. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bkaradzic-microsoft
added a commit
to BabylonJS/BabylonNative
that referenced
this pull request
May 15, 2026
## Summary Bumps `BabylonJS/SPIRV-Cross` to [`866e5ed`](BabylonJS/SPIRV-Cross@866e5ed), the merge of [BabylonJS/SPIRV-Cross#11](BabylonJS/SPIRV-Cross#11) on top of [BabylonJS/SPIRV-Cross#10](BabylonJS/SPIRV-Cross#10) ("Expose more functions"). Together these remove `#ifndef SPIRV_CROSS_WEBMIN` guards and their `SPIRV_CROSS_INVALID_CALL()` (= `assert(false)`) stub bodies for the HLSL opcodes / helpers reachable from the BN test catalog: `OpFMod`, `OpLogicalOr`, `OpLogicalAnd`, `OpFwidthFine`, `OpVectorTimesMatrix` (×2 sites), `OpVectorExtractDynamic`, `OpSNegate`, plus `to_extract_constant_composite_expression`. Previously-stubbed opcodes now emit the actual HLSL instead of crashing or returning invalid shader code. Also re-enables 17 `validation_native.js` tests in `Apps/Playground/Scripts/config.json` that were previously excluded with `"reason": "Test crashes or hangs on Babylon Native"` and now pass on Win32 D3D11: idx 138, 241, 254, 293, 296, 309, 321, 322, 323, 332, 333, 373, 376, 391, 558, 559, 574. ## Note on remaining failures unmasked by the bump In Release builds `SPIRV_CROSS_INVALID_CALL()` is a no-op, so SPIRV-Cross was silently emitting invalid shader code and the test pipeline appeared to hang waiting for a render. After this bump, the underlying JS-side errors are now visible. Several still-failing tests turn out to have causes unrelated to SPIRV-Cross: 1. The 26 Prepass SSAO + motion blur tests fail at the JS layer with `PrePassRenderer needs WebGL 2 support` **before** any shader compile — `NativeEngine` does not advertise the WebGL2 capability that `PrePassRenderer` requires. 2. One GPU-particles test (`GPU Particles - Animations`) now fails with `TypeError: Unable to get property 'ARRAY_BUFFER' of undefined` — same root cause as the GPU-particle `ARRAY_BUFFER` bug previously identified. 3. Two tests (`GreasedLine`, `Area Lights Standard Material`) fail to load LTC LUT textures: `Error: Unknown error opening URL` — UrlLib / asset resolution issue. 4. Three OpenPBR variants (Fuzz Weight, Transmission Dispersion — the `Realtime IBL` / `Prefiltered IBL` paths) still hit shader-compile errors — likely additional `SPIRV_CROSS_INVALID_CALL()` stub sites not yet reached by this bump. These will be tracked as separate follow-up work (renderer-side WebGL2 capability, GPU-particle gl-constants binding, UrlLib LTC asset path, and a further SPIRV-Cross pass once a `Debug` build pinpoints the remaining stub sites). ## OpenGL backend coverage A local `OpenGLWindowsDevOnly` build (Windows + ANGLE, same `STRINGIZE(GRAPHICS_API) == "OpenGL"` as Linux native OpenGL) was used to validate the re-enabled tests against the OpenGL backend. Four entries diverge on OpenGL only and have been marked `"excludedGraphicsApis": ["OpenGL"]` with a documented reason: - idx 293, 296: `BGFX FATAL` `mediump float`→`int` shader-compile error in the `PrePassRenderer` fragment shader (OpenGL/ANGLE GLSL only). - idx 391: 90 900-px diff in `sphere-with-custom-shader-to-display-wireframe-using-glow-layer` (glow-layer + custom-shader divergence). idx 299 (`Prepass SSAO + GUI`) is held out of the re-enable batch entirely (kept `excludeFromAutomaticTesting: true`): it passes in isolation but produces a ~6000-px diff right at the 2.5 % `errorRatio` threshold when run after sibling Prepass-SSAO tests in the full sweep — flaky on Win32 D3D11 in CI. ## Build hygiene fix The pre-existing `OpenGLWindowsDevOnly` build was broken under MSVC `/WX` because `ExternalTexture_Shared.h` lines 25/28 trip C4702 (unreachable code) — the OpenGL impl's `GetInfo` / `Set` / `Get` always throw, so the dispatch's no-throw fall-through is statically unreachable. Added `target_compile_options(ExternalTexture PRIVATE /wd4702)` gated on `GRAPHICS_API STREQUAL "OpenGL" AND MSVC` in `Plugins/ExternalTexture/CMakeLists.txt`. No other build is affected. The right long-term fix is to make the throws conditional in the OpenGL impl. ## Verification - Win32 D3D11 (Release x64, Chakra), Windows ANGLE OpenGL (`OpenGLWindowsDevOnly`), and Linux native OpenGL all run the full sweep cleanly with the bump applied. - Re-fetched `_deps/spirv-cross-src` matches the merged `866e5ed` byte-for-byte. ## Notes - This only bumps the standalone SPIRV-Cross used by `Plugins/ShaderCompiler/Source/ShaderCompilerDXBC.cpp` (the one declared in `CMakeLists.txt`). The bgfx-bundled SPIRV-Cross under `_deps/bgfx.cmake-src/3rdparty/spirv-cross/` is unaffected. - Upstream `BabylonJS/SPIRV-Cross` is now 2 commits ahead of the previous pin (PR #10 + PR #11). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
CedricGuillemet
added a commit
to BabylonJS/BabylonNative
that referenced
this pull request
May 18, 2026
Use a generated shader to check no mandatory glsl function missing in spirv-cross when using WEBMIN flag. BabylonJS/SPIRV-Cross#10 ## Fix `UniformTypeChangeTraverser` and `MoveNonSamplerUniformsIntoStruct` were also visiting whole `layout(std140) uniform` blocks (`EbtBlock`) and `uniform Foo foo;` struct instances (`EbtStruct`) and rewriting them to `vec4`, producing unnamed placeholder uniforms in the spirv-cross output and a `Identifier can't be empty.` assert in bgfx. Both traversers are now restricted to scalar/vector basic types (Float/Int/Uint/Bool). `CollectNonSamplerUniforms` also throws early if a uniform name is empty so future regressions surface in the compiler instead of deep in bgfx.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use this unittest to check all mandatory glsl construction are valid with webmin flag on.
BabylonJS/BabylonNative#1638
Some functions were missing and are added in this PR.
Windows BN PG build:
before : 3.27 Mb (3,429,888 bytes)
after : 3.28Mb 3,446,272 bytes
+15Kb