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

[hlsl-out] Fix accesses on zero value expressions #5587

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

Imberflur
Copy link
Contributor

@Imberflur Imberflur commented Apr 23, 2024

So that subsequent member access is resolved correctly.

Connections
https://matrix.to/#/!fjjkgHFcwtkREywzfk:matrix.org/$gMvEqmPg59z_xMR6WkUzik82z-UnGezovoXQ4ImVKmM

Description

I was getting HLSL output like:

float4 _expr2703 = float4(_expr2697.x, (float4)0.y, (float4)0.z, (float4)0.w);

Which produced this error:

error X3000: syntax error: unexpected token 'y'

This PR adjusts the output to:

float4 _expr2703 = float4(_expr2697.x, ((float4)0).y, ((float4)0).z, ((float4)0).w);

This is derived from some SPIRV input that I haven't looked through, I tried to reproduce the issue with some simple wgsl like vec2<f32>().x but naga outputs (float)0 for that.

Testing
I compiled my application with this change and stopped getting errors from the hlsl shader compiler.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@Imberflur Imberflur requested a review from a team as a code owner April 23, 2024 04:13
…ber access is resolved correctly.

e.g. `((float4)0).x` will be generated instead of `(float4)0.x` (which fails to compile)
@Imberflur
Copy link
Contributor Author

🙁

I'm getting this from the CI:

[ERROR xtask::validate] failed to validate entry point "foo_vert" with profile "vs_5_1": `dxc 'tests\out\hlsl\access.hlsl' -T vs_5_1 -E foo_vert -Wno-parentheses-equality -Zi -Qembed_debug -Od -HV 2018` failed to run; exit code: Some(-2147467259)
stdout:

stderr:
warning: Promoting older shader model profile to 6.0 version.
tests\out\hlsl\access.hlsl:183:41: error: cannot compile this l-value expression yet
    t_1.am = (__mat4x2[2])((float4x2[2])0);
                                        ^

@teoxoy
Copy link
Member

teoxoy commented Apr 23, 2024

That's unfortunate, we might need to generate helper functions for Expression::ZeroValue.

Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

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

Great stuff, thanks!

@teoxoy teoxoy changed the title [hlsl-out] Parenthesize zero value expressions [hlsl-out] Fix accesses on zero value expressions Apr 24, 2024
@teoxoy teoxoy merged commit 82fa580 into gfx-rs:trunk Apr 24, 2024
25 checks passed
@Imberflur Imberflur deleted the fix-hlsl-zero-value branch April 24, 2024 14:09
Imberflur added a commit to Imberflur/wgpu that referenced this pull request May 6, 2024
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.

2 participants