Skip to content

Conversation

@jhelferty-nv
Copy link
Contributor

Fixes #8443

In order to support some legacy shaders, we will allow zero-initialization of structs that contain resource types as fields. The resource variables get initialized to a Poison value. We also issue a diagnostic warning.

The expectation here is that (a) the correct value will be assigned in SSA, or (b) if there's a branch scope where it remains initialized to Poison, the value will subsequently not be used. (The latter case is the one that we needed to implement this change for.)

Fixes shader-slang#8443

In order to support some legacy shaders, we will allow
zero-initialization of structs that contain resource types as fields.
The resource variables get initialized to a Poison value. We also
issue a diagnostic warning.

The expectation here is that (a) the correct value will be assigned in
SSA, or (b) if there's a branch scope where it remains initialized to
Poison, the value will subsequently not be used. (The latter case is
the one that we needed to implement this change for.)
@jhelferty-nv jhelferty-nv self-assigned this Nov 27, 2025
@jhelferty-nv jhelferty-nv added the pr: non-breaking PRs without breaking changes label Nov 27, 2025
getSink()->diagnose(
fromInitializerListExpr->loc,
Diagnostics::cannotUseInitializerListForResourceType,
toType);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the one downside here is that instead of the one warning, we end up with two warnings, because a later chunk of code notices that the source is uninitialized:

tests/spirv/zero-init-tex2d-field.slang(27): warning 30506: cannot use initializer list for resource type 'Texture2D<vector<float,4>>'
    S s = (S)0;
          ^
tests/spirv/zero-init-tex2d-field.slang(27): warning 41016: use of uninitialized variable ''
    S s = (S)0;
          ^

@jhelferty-nv jhelferty-nv marked this pull request as ready for review November 27, 2025 04:09
@jhelferty-nv jhelferty-nv requested a review from a team as a code owner November 27, 2025 04:09
@jhelferty-nv jhelferty-nv marked this pull request as draft November 27, 2025 04:47
The variant of tests/diagnostics/uninitialized-resource-type.slang
that uses arrays was generating duplicate diagnostics without tracking
back the source location. This change fixes that.

Also cleans up the diagnostic message content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SPIRV] Slang producing invalid spir-v for Texture2D in struct conditionally initialized and used

1 participant