Skip to content

[SPIR-V] get field index from SPIR-V type, not AST#4806

Merged
Keenuts merged 1 commit intomicrosoft:mainfrom
Keenuts:field-index
Nov 21, 2022
Merged

[SPIR-V] get field index from SPIR-V type, not AST#4806
Keenuts merged 1 commit intomicrosoft:mainfrom
Keenuts:field-index

Conversation

@Keenuts
Copy link
Copy Markdown
Collaborator

@Keenuts Keenuts commented Nov 21, 2022

Before this commit, struct field indices were computed from the AST type. This was correct as SPIR-V types and AST types had the same structure.

When adding bitfields, we started to squash some fields together, as long as some rules were respected (bitfield, same type, doesn't span over multiple type-sized words, etc).
This means indices now diverge between SPIR-V types and AST types.

This requires us to lower the AST type before the lowering pass, when generating instructions like OpAccessChain.
A cleaner alternative would be to lower all types before instruction generation, and only operate on SPIR-V type. But cost of making this refactoring is large, and we don't believe it is worth it since we plan to upstream to clang (hence rewrite this code).

note: this code prevents AST indices to diverge from SPIR-V indices when computed. This is just a safeguard until bitfields are in place in case I made a mistake with the layout rules, allowing us to catch those bugs faster.

Signed-off-by: Nathan Gauër brioche@google.com

@Keenuts Keenuts changed the title spirv: get field index from SPIR-V type, not AST [SPIR-V] get field index from SPIR-V type, not AST Nov 21, 2022
@Keenuts Keenuts marked this pull request as ready for review November 21, 2022 12:45
@AppVeyorBot
Copy link
Copy Markdown

@Keenuts Keenuts removed the request for review from cassiebeckley November 21, 2022 14:16
@Keenuts
Copy link
Copy Markdown
Collaborator Author

Keenuts commented Nov 21, 2022

found a bug when implementing bitfields. Removing reviewers

@Keenuts
Copy link
Copy Markdown
Collaborator Author

Keenuts commented Nov 21, 2022

The bug was related to inheritance, when the base class was empty. Because I only used the offset value to determine field merging, I was returning the wrong index for such cases.
It will be better to check for bitfield presence, and disallow any kind of field-merge is not a bitfield. Should be more robust. Will add that with the bitfield PRs

Before this commit, struct field indices were computed from the AST
type. This was correct as SPIR-V types and AST types had the same
structure.

When adding bitfields, we started to squash some fields together, as
long as some rules were respected (bitfield, same type, doesn't span
over multiple type-sized words, etc).
This means indices now diverge between SPIR-V types and AST types.

This requires us to lower the AST type before the lowering pass, when
generating instructions like OpAccessChain.
A cleaner alternative would be to lower all types before instruction
generation, and only operate on SPIR-V type. But cost of making this
refactoring is large, and we don't believe it is worth it since we plan
to upstream to clang (hence rewrite this code).

note: this code prevents AST indices to diverge from SPIR-V indices when
computed. This is just a safeguard until bitfields are in place in case
I made a mistake with the layout rules, allowing us to catch those bugs
faster.

Signed-off-by: Nathan Gauër <brioche@google.com>
@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

Copy link
Copy Markdown
Collaborator

@cassiebeckley cassiebeckley left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for figuring out a way to do this without it being too messy.

@AppVeyorBot
Copy link
Copy Markdown

@Keenuts Keenuts merged commit 8f279ba into microsoft:main Nov 21, 2022
@Keenuts Keenuts deleted the field-index branch November 21, 2022 18:31
cassiebeckley added a commit to cassiebeckley/DirectXShaderCompiler that referenced this pull request Dec 5, 2022
Revert "spirv: get field index from SPIR-V type, not AST (microsoft#4806)"

This reverts commit 8f279ba. This
commit isn't passing some of our internal tests and needs to be reverted
in preparation for the next Vulkan SDK release.
cassiebeckley added a commit that referenced this pull request Dec 6, 2022
Revert "spirv: get field index from SPIR-V type, not AST (#4806)"

This reverts commit 8f279ba. This
commit isn't passing some of our internal tests and needs to be reverted
in preparation for the next Vulkan SDK release.
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.

3 participants