Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spv-out: Decorate integer builtins as Flat in the spirv writer #2035

Merged
merged 1 commit into from
Sep 1, 2022

Conversation

nical
Copy link
Contributor

@nical nical commented Aug 31, 2022

Fixes #2032

Take what I write in this PR with a whole handful off salt, I'm new enough to naga and spirv that there's a decent chance I am jumping to conclusions.

See the investigation in #2032. My uneducated guess is that spirv wants the integer input builtins such as primitive_index to have the flat decoration. So I added that in fairly naive way.

This PR fixes the primitive_index.wgsl test case and doesn't appear to cause regressions as far as cargo test --all can tell.

@nical
Copy link
Contributor Author

nical commented Aug 31, 2022

It does not fix the water.wgsl test case, though.

Comment on lines 1175 to 1178
let is_flat = match built_in {
Bi::Position { .. } => false,
_ => true,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual rule from the Vulkan spec is:

  • VUID-StandaloneSpirv-Flat-04744
    Any variable with integer or double-precision floating-point type and with Input storage class in a fragment shader, must be decorated Flat

It's true that spirv-val doesn't complain about (say):

@fragment
fn fs_main(@location(0) index: u32) -> @location(0) vec4<f32> {
    return vec4<f32>(0.0, 0.0, 0.0, 0.0);
}

but since the background story is that these validations are just being implemented piecemeal as somebody's interest leads them, I think we should assume the above might well stop passing validation at some point in the future.

Anyway, that is too many words to say: Let's implement the rule as expressed in the Vulkan spec and attach Decoration::Flat to everything whose type is Sint, Uint, or 64-bit Float.

@nical nical force-pushed the spv-flat-builtins branch 2 times, most recently from 547c2cc to 6ab06fd Compare September 1, 2022 13:43
@nical nical changed the title Decorate most builtins as Flat in the spirv writer Decorate integer builtins as Flat in the spirv writer Sep 1, 2022
@nical nical changed the title Decorate integer builtins as Flat in the spirv writer spv-out: Decorate integer builtins as Flat in the spirv writer Sep 1, 2022
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic. Two small changes, but then this can land.

src/back/spv/writer.rs Outdated Show resolved Hide resolved
src/back/spv/writer.rs Outdated Show resolved Hide resolved
@jimblandy
Copy link
Member

(I made the minor changes I requested.)

@jimblandy jimblandy merged commit b63436a into gfx-rs:master Sep 1, 2022
jimblandy added a commit to jimblandy/naga that referenced this pull request Sep 1, 2022
The Vulkan decoration rules require us to distinguish vertex shader
inputs, fragment shader inputs, and everything else, so just pass the
stage to `Writer::write_varying`. Together with the SPIRV storage
class, this is sufficient to distinguish all the cases in a way that
closely follows the spec language.
jimblandy added a commit to jimblandy/naga that referenced this pull request Sep 1, 2022
The Vulkan decoration rules require us to distinguish vertex shader
inputs, fragment shader inputs, and everything else, so just pass the
stage to `Writer::write_varying`. Together with the SPIRV storage
class, this is sufficient to distinguish all the cases in a way that
closely follows the spec language.
jimblandy added a commit that referenced this pull request Sep 1, 2022
The Vulkan decoration rules require us to distinguish vertex shader
inputs, fragment shader inputs, and everything else, so just pass the
stage to `Writer::write_varying`. Together with the SPIRV storage
class, this is sufficient to distinguish all the cases in a way that
closely follows the spec language.
@nical nical deleted the spv-flat-builtins branch September 2, 2022 06:36
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.

SPIR-V output fails VUID-StandaloneSpirv-Flat-06202, VUID-StandaloneSpirv-Flat-04744
2 participants