Skip to content

GX: write constants as f32 literals instead of abstract floats - #319

Open
StilesCrisis wants to merge 1 commit into
encounter:mainfrom
StilesCrisis:typed-alpha-constants
Open

StilesCrisis wants to merge 1 commit into
encounter:mainfrom
StilesCrisis:typed-alpha-constants

Conversation

@StilesCrisis

Copy link
Copy Markdown

Previously, all of the alpha arguments were written without a f suffix, which in WGSL makes them "abstract floats."

This breaks Naga, the other major open-source WGSL implementation besides Dawn; it is not able to evaluate constant expressions with abstract values in them. (Known limitation: see gfx-rs/wgpu#4507)

This PR marks the floats with an f suffix, which gives them a concrete type and makes Naga happy.

The TEV alpha arguments used untyped float literals like "0.0" and
"(7.0/8.0)". When every argument of a combiner was a constant, the shader
contained mix(0.0, 0.0, 0.0), which wgpu's naga (Firefox) can't evaluate
as a constant expression yet, so it rejected the shader with "Abstract
types may only appear in constant expressions". Writing them as f32
literals (the color arguments already use vec3f) avoids this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SjpWodBBBeEnJWqBfHy3gy
@PJB3005

PJB3005 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

This breaks Naga, the other major open-source WGSL implementation besides Dawn; it is not able to evaluate constant expressions with abstract values in them. (Known limitation: see gfx-rs/wgpu#4507)

I see nothing in the linked issue about abstract floats.

@StilesCrisis

Copy link
Copy Markdown
Author

It's here: the "mix" intrinsic doesn't support compile-time folding/evaluation when used with abstract types in naga. They're chewing through a massive list of comp-time eval stuff and haven't reached "mix."
IMG_0182

@PJB3005

PJB3005 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

I'll defer to @encounter but personally I would say it's more productive to improve wgpu directly.

@StilesCrisis

Copy link
Copy Markdown
Author

It's fair to say that eventually naga will catch up and this will be moot. But this PR is pretty trivial, vs what I imagine would be a much more involved naga PR.

@PJB3005

PJB3005 commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

I believe that last time we checked, there were other, bigger issues blocking wgpu from running Aurora anyways.

@StilesCrisis

Copy link
Copy Markdown
Author

I've got one other fix and then I run in naga.

@Antidote

Copy link
Copy Markdown
Collaborator

It's better to fix the upstream issue than fix an otherwise compliant implementation.

@StilesCrisis

Copy link
Copy Markdown
Author

That's valid.
How do you feel about extensions? The other issue was that we rely on passing a pointer to a function, but that's not in the baseline WGSL spec. It's easy to fix on our end. I don't believe naga has any plans to start tackling extensions, given that they still haven't gotten constant folding to 100%.

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.

4 participants