Repository navigation
Conversation
…compute Previously OpEmitVertex lowered directly to unconditional stores into %gsc_rec[(p * max_verts + n) * nout + i] and %gsc_meta[p * (max_verts + 1) + 1 + n] and incremented %gsc_n without checking n < max_verts. Any geometry shader emitting past OutputVertices silently overflowed into primitive p+1's vertex records and meta count slot, and left OpEndPrimitive/OpReturn indexing past max_verts. Emit a %gsc_emit helper function when OpEmitVertex is present and lower each OpEmitVertex to OpFunctionCall %gsc_emit %gsc_recbase %gsc_metabase. Inside %gsc_emit, skip stores and the %gsc_n increment when %gsc_n >= OutputVertices so %gsc_n stays bounded to [0, max_verts] for OpEndPrimitive and OpReturn too, without splitting structured loop headers or OpPhi blocks at call sites. Add synthetic regression tests with Vulkan 1.2 spirv-val checks (including emission directly inside a loop header and zero-output GS modules) in tests/test_spirv_gs_to_compute.py. AI-assisted.
Contributor
|
Tested f9986a0 on Windows, CPython 3.14.7, CPU only (no GPU, no game files): pass, with one gap: there is no SPIRV-Tools on this machine, so the
Someone with SPIRV-Tools should still run the validation half. No defect found. AI-assisted. |
Contributor
|
Tested f9986a0 on Windows 11 (Python 3.13.7, CPU only, no game files) with SPIRV-Tools v2026.4 and
Not run: |
This was referenced Nov 22, 2026
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.
Claimed in coordination issue #3232 as
EGEN-GSC-MAXVERTS-BOUNDS(finding: #3232 (comment)).What and why
In
tools/spirv_gs_to_compute.py,OpEmitVertexpreviously lowered inline to unconditional stores into%gsc_rec[(p * max_verts + n) * nout + i]and%gsc_meta[p * (max_verts + 1) + 1 + n]followed by%gsc_n = n + 1, with no check thatn < max_verts(OutputVertices).If a geometry shader emits more than
OutputVerticesvertices for primitivep, those excess emits silently overwrite primitivep + 1's vertex records andmetacount slot(p + 1) * (max_verts + 1)in the shared storage buffers, and leave%gsc_n > max_vertsforOpEndPrimitiveandOpReturn.Fix: When
OpEmitVertexis present, generate a%gsc_emithelper function taking(%gsc_recbase, %gsc_metabase)that checks%gsc_n < max_verts(OpULessThan) before writing%gsc_rec/%gsc_metaand incrementing%gsc_n. EachOpEmitVertexin%mainlowers to a singleOpFunctionCallto%gsc_emit. Keeping%gsc_nin[0, max_verts]keepsOpEndPrimitive(meta[metabase + n]) andOpReturn(meta[metabase] = n) within primitivep's allocation as well.Tested
upstream/mainf847748c):test_emit_vertex_is_bounded_by_output_vertices,test_emit_vertex_in_loop_header_stays_valid_spirv,test_zero_output_gs_emit_is_bounded) FAILED; 12 existing tests passed (3 failed, 12 passed in 1.26s).llvm-mconPATH/LLVM_MC, 0 skipped):pytest tests/test_spirv_gs_to_compute.py -v: 15 passed in 1.58s (every rewritten module validated withspirv-as+spirv-val --target-env vulkan1.2).pytest tests/test_gpu_unsupported_stage.py -v: 6 passed in 0.68s.spirv-valcheck on sample lowered module:vulkan1.2,vulkan1.3, andspv1.4all passed (OK).python -I tests/test_text_write_line_endings.py: 2 passed (OK).python -m compileall -q make_game.py tools testsandgit diff --check: clean (exit 0).spirv-val; synthetic GS inputs only, no game data).Notes
OpEmitVertexvia%gsc_emit(OpFunctionCall) instead of emittingOpSelectionMerge+OpBranchConditionalinline avoids splitting call-site basic blocks that may beOpLoopMergeloop headers, selection headers, orOpPhipredecessors, and handlesout_vars == {}cleanly as well.OpLoad/OpStorememory-operand handling (spirv_gs_to_compute: accept memory operands on built-in OpLoad and output OpStore #3062),--vs/--draw-vs(GPU tests: exact fallbacks on by themselves where the device lacks the feature; gs_tri as compute on MoltenVK (TEST-481) #3078), or CLI--layoutparsing (spirv_gs_to_compute: require a path after --layout #2393).(Antigravity)
AI-assisted.