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

Remove 'raw' default construct insts for SPIRV emit #5556

Merged

Conversation

saipraveenb25
Copy link
Collaborator

@saipraveenb25 saipraveenb25 commented Nov 13, 2024

Our auto-diff step currently emits a few 'raw' OpDefaultConstruct insts for intermediate data types, mostly to silence HLSL errors about uninitialized variables. This is a redundant inst, because our auto-diff pass will always make sure all generated fields are individually set.

Usually, these intermediate types are made up of zero-initializable types so they get lowered to OpMakeStruct, so targets like SPIRV where OpDefaultConstruct does not exist don't run into issues.

For some special types, it is not easy (or safe) to emit such zero initializers, so we will instead run a pass to remove OpDefaultConstruct for backends where it is not available (thankfully, these backends do not complain about uninitialized variables, so the code correctness is unaffected)

@saipraveenb25 saipraveenb25 requested a review from a team as a code owner November 13, 2024 21:55
@saipraveenb25 saipraveenb25 added the pr: non-breaking PRs without breaking changes label Nov 13, 2024
// On targets that don't support default initialization, remove 'raw' default construct
// insts because our code-gen will not have any way to emit them.
//
case CodeGenTarget::SPIRV:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the raw default constructor has uses? If we just remove them the rest of the IR will be ill-formed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see the code is detecting store(var, defaultConstruct()) and remove the store along with the defaultConstruct.

@saipraveenb25 saipraveenb25 merged commit 147ceb1 into shader-slang:master Nov 14, 2024
14 checks passed
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.

2 participants