Skip to content

Shaders: arithmetic on a vector constant is evaluated - #3454

Merged
xen2 merged 1 commit into
stride3d:masterfrom
xen2:feature/vector-constant-math
Sep 20, 2026
Merged

xen2 merged 1 commit into
stride3d:masterfrom
xen2:feature/vector-constant-math

Conversation

@xen2

@xen2 xen2 commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

PR details

Stacked on the shader constants PR #3453 : only the last commit is new.

static const float3 X = float3(1, 2, 3) * 0.5; and -float2(...) did not compile. They use OpFMul/OpFNegate, which SPIR-V does not allow in a shader constant, so the compiler has to compute the value, and ConstantEvaluator only knew scalars.

It now applies an operation per component of a vector. The result is written as an OpConstantComposite, when the shader is compiled, or when mixing if it depends on a generic.

Tests: a render test (ConstVectorMath) and evaluator unit tests. Stride.Shaders.Tests passes (929 tests).

`static const float3 X = float3(1, 2, 3) * 0.5;` or `-float2(...)` use OpFMul/OpFNegate, which SPIR-V
does not allow in a constant of a shader module, and ConstantEvaluator only knew scalars: the constant
could not be resolved. It now applies an operation per component of a vector. The value becomes an
OpConstantComposite preceded by the constants of its components, when the shader is compiled, or
when mixing if it depends on a generic.
@xen2
xen2 force-pushed the feature/vector-constant-math branch from 1580e9c to 1c3cedf Compare September 20, 2026 13:26
@xen2
xen2 merged commit 1ed4ee0 into stride3d:master Sep 20, 2026
31 checks passed
@xen2
xen2 deleted the feature/vector-constant-math branch September 20, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant