Repository navigation
Separate 2D depth comparisons from ordinary color sampling on MoltenVK - #4616
nschlaepfer wants to merge 5 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Built and ran the opt-in path at 17be8954 on Windows 11, RTX 5070 Ti (Vulkan 1.4.363), with LEONIDA_SEPARATE_DEPTH_2D=1 for the translator:
runtime/test/shaders/build.py out vs_ids ps_mixed_depth_2d-> 2 shaders translated, 2 passspirv-val.bindless_sizing_test-> exit 0,bindless sizing: synthetic limits gave the expected counts(the binding-29 array is budgeted in the 93,793 descriptors).vk_bindless_test vs_ids.spv ps_mixed_depth_2d.spv --separate-depth-2d-> 12 draws read back, 0 bad pixels, largest error 0 — including both depth-comparison outcomes, the erased/restored depth key and the depth-view-replaced-by-colour draw.pytest tests/test_spirv_metal_set0*.py -q-> 37 passed, 41 subtests passed.
The change keeps binding 29 opt-in (separate_depth_2d only when the flag is passed and the shader index names it), refuses a flagged PSO when the binding is disabled, and leaves unflagged shaders on their existing format. I could not re-run the Apple M3 MoltenVK side; the Windows/NVIDIA path is exact. git diff --check clean. No blocking issue.
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted Windows CPU review at 17be8954, uv CPython 3.12.13. Thirty hand-written shader builds validated for Vulkan 1.2 and 1.3, with maintenance8 enabled for the native offset case. Only supported 2D comparison samples moved to set 0 binding 29. Color remained at 0 and array comparison at 3. All five default controls were byte-identical to both d0835dd9 and the merge base 03b09a08.
A CPU harness loaded the actual generated index through ShaderLibrary. With opt-in enabled, a 1,212-descriptor synthetic budget allocated 256 entries each to bindings 0 and 29 and used 993 in total. The off layout had no binding 29. The offline Metal rewriter used argument-buffer ID 12545 for 29 and kept earlier IDs. Focused checks passed 137 Python tests, 110 subtests and five CPU CTests.
One existing translator contract carries over to the opt-in path: the fixture dynamically indexes binding 29 and its sampler array without SampledImageArrayDynamicIndexing. It passes offline validation, which does not settle VUID 10128. #3045 already tracks this capability and its current source includes both descriptor accesses. That composition was inspected at source level. No GPU dispatch was submitted in this review.
|
Tested
Not run: the full GPU suite on the PR head, and a negative control of the mixed fixture on |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted follow-up to my earlier review. I merged this exact head (17be8954) and #3045 (e34b0c7b) into a local scratch copy of upstream d0835dd9. Both merged without conflicts. Tested tree 778c321ba36e92037fba2327936463a692ef11a2.
With separate depth enabled, the mixed and compare-only fixtures used set 0 binding 29 and declared SampledImageArrayDynamicIndexing. Both carried shaderSampledImageArrayDynamicIndexing in required-feature metadata. Binding 29 was absent with the flag off and from the ordinary color and array-load controls. The texture-free control declared neither the capability nor the feature. All ten synthetic modules passed spirv-val for Vulkan 1.2 and 1.3.
The combined source routes both the image and sampler accesses through #3045’s tracker. The pipeline checker consults the required feature before module creation, and the D3D12 bindless device setup checks and enables that feature. On Windows with MSVC 19.38.33145 and Vulkan SDK 1.4.363.0, the checker and D3D12 COM shim built and the checker CLI, bindless sizing and shader library CTests passed (3/3). CPU and SPIR-V verification only. This shows that #3045 can supply the capability for the new path in this combination. Vulkan capability rule.
|
Tested head
AI-assisted (Devin). |
Scope
Claimed in coordination issue #4571. This AI-assisted opt-in change uses set 0 binding 29 for supported 2D depth-comparison samples. Bindings 26–28 remain available for the pending typed-resource proposals.
A synthetic shader samples RGBA from one array element and compares a separate D32 image at another. On Apple M3 Max the original module returned red in every color channel, even with constant, distinct indices. SPIRV-Cross at the revision pinned by MoltenVK 1.4.2 declared the shared array as Metal depth textures. Its ordinary sample returned a scalar and the generated Metal broadcast it to the output vector. Giving the depth view its own binding preserved color and both outcomes of the hardware depth comparison.
Build shaders with
--separate-depth-2dand run withLEONIDA_SEPARATE_DEPTH_2D=1. Unflagged shaders retain their existing format. The runtime budgets the new array, clears its D32 fallback to zero, updates depth and color views by the same lookup index, and rejects a flagged PSO when the binding is disabled.Verification
The public fixture uses an orange RGBA texture, a depth of 0.75 and a LESS sampler. The GPU test checks both comparison outcomes, erases and restores the depth key, and replaces a depth view with a color view. It compares 4,096 pixels on every draw.
spirv-val.Only the redistributable synthetic fixture and public sources are included.
The legacy Metal offline binding rewriter retains the earlier argument-buffer indices and rejects the three reserved slots. The new regression checks both color sampling and two genuinely different depth-comparison outcomes.
Dynamic-indexing capability. @whattheflop identified that the baseline translator can dynamically index a sampled texture or sampler array without declaring the corresponding SPIR-V capability. This also applies to the opt-in depth array when indexed dynamically. PR #3045 owns that general correction. Its author independently verified the capability and required device feature for binding 29 in the combined tree. I confirmed the two published heads merge cleanly. The pixel and validation-layer results above are observations for the tested drivers.
Upstream refresh. Merged main at
7b7d73f8in0512a0b3. The M3 opt-in path again matched all 49,152 pixels with validation enabled. Default shaders in four controls were byte-identical to the new base. Windows MSVC compiled the affected runtime object and linked the checker and bindless test tools. The general dynamic-indexing work in #3045 is still separate.