dasSpirv: integer vector*scalar (splat + IMul) + bool constants (OpConstantTrue/False)#3244
Merged
Merged
Conversation
…nstantTrue/False)
Two emitter gaps surfaced by the GLSL.std.450 / arithmetic dispatch audit.
1. Integer `ivecN * int` was rejected ("integer vector/scalar mixes need
a splat"): a missing feature, since SPIR-V has no OpVectorTimesScalar
for integers (that op is float-only). emit_mul now splats the scalar to
the vector width via OpCompositeConstruct (new splat_to_vec helper) and
does a component-wise OpIMul, for both operand orders (vec*scalar and
scalar*vec) and both int + uint.
2. Bool literals (`false` / `true`, ExprConstBool) had no rvalue path and
failed the annotation patch with "no rvalue available for ExprConstBool".
They now lower to OpConstantFalse / OpConstantTrue (new const_bool
builder helper) via a visitExprConstBool override + an emit_const case.
Bool locals, comparisons, &&/||/!, and bool `if` conditions already
worked -- only the literal constants were missing.
Tests: tests/spirv/test_int_vec_scalar.das (loads ivec from SSBO so the
splats are the only OpCompositeConstruct -> exact counts) and
test_bool_const.das (OpTypeBool + both bool constants). Both assert
spirv-val clean. 160 tests/spirv pass; lint-clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR closes two missing lowering cases in the dasSpirv emitter that were previously fail-closed: (1) integer vecN * scalar multiplication and (2) boolean literal constants. These gaps surfaced during an audit of arithmetic/ext-inst dispatch and are exercised via new SPIR-V tests.
Changes:
- Add
const_boolsupport and emitter rvalue handling forExprConstBoolviaOpConstantTrue/OpConstantFalse. - Add integer vector*scalar multiplication lowering by splatting the scalar with
OpCompositeConstructand using component-wiseOpIMul. - Add two new
tests/spirvgates validating opcode shapes and spirv-val cleanliness for both cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/spirv/test_int_vec_scalar.das | New gate test asserting integer vec*scalar lowers to scalar splat (OpCompositeConstruct) + OpIMul (and not OpVectorTimesScalar). |
| tests/spirv/test_bool_const.das | New gate test asserting bool literals emit OpTypeBool plus OpConstantTrue/OpConstantFalse. |
| modules/dasSpirv/spirv/spirv_emit.das | Implement integer vec*scalar multiply via splat helper + OpIMul; add ExprConstBool constant emission/visitor support. |
| modules/dasSpirv/spirv/spirv_builder.das | Add const_bool constant pooling + emission using OpConstantTrue / OpConstantFalse. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Two dasSpirv emitter gaps surfaced by the GLSL.std.450 / arithmetic dispatch audit (the dasVulkan tutorial ladder is the forcing function). Both were fail-closed/missing, not silent-invalid.
1. Integer
ivecN * int→ splat +OpIMulivecN * intwas rejected with "integer vector/scalar mixes need a splat" — a missing feature, since SPIR-V has noOpVectorTimesScalarfor integers (that op is float-only).emit_mulnow splats the scalar to the vector width viaOpCompositeConstruct(newsplat_to_vechelper) and does a component-wiseOpIMul, for both operand orders (vec*scalarandscalar*vec) and bothint+uint. Mirrors the existing floatOpVectorTimesScalarpath and the FMix scalar-broadcast.2. Bool constants →
OpConstantFalse/OpConstantTruefalse/trueliterals (ExprConstBool) had no rvalue path and failed the annotation patch with "no rvalue available for ExprConstBool". They now lower toOpConstantFalse/OpConstantTrue(newconst_boolbuilder helper — these carry no literal word, the opcode is the value) via avisitExprConstBooloverride + anemit_constcase. Bool locals, comparisons,&&/||/!, and boolifconditions already worked — only the literal constants were missing.Tests
tests/spirv/test_int_vec_scalar.das— loads the vectors from SSBOarray<ivec>elements (not constructed), so the onlyOpCompositeConstructare the three splats: asserts exactly 3OpIMul+ 3OpCompositeConstruct, noOpVectorTimesScalar(ints don't use it), and spirv-val clean.tests/spirv/test_bool_const.das— assertsOpTypeBool+ both bool constants, spirv-val clean.160
tests/spirvpass; lint-clean. Self-contained inline-shader fixtures (the establishedtest_math_*/test_ext_broadcastpattern); auto-discovered by thetests/spirv/*.dasAOT glob, sotest_aot_spirvexercises both through the AOT path too.🤖 Generated with Claude Code