-
Notifications
You must be signed in to change notification settings - Fork 222
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
WGSL: Fix issue where global calls are generated #5768
WGSL: Fix issue where global calls are generated #5768
Conversation
254d4da
to
9a44009
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
9a44009
to
a542a7b
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
f2f9e56
to
fc18647
Compare
Some tests were failing:
|
/format |
🌈 Formatted, please merge the changes from this PR |
d8abcde
to
e57ab0e
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
fce390b
to
7949b34
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
I got a test timeout...
|
// after inlining. | ||
for (auto& globalInst : globalInstsToConsiderDeleting) | ||
{ | ||
if (!hasDescendantSatisfyingPredicate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a band aid instead of an actual fix.
As we discussed in the meeting, the true problem is when we clone the global SpirvASM inst to a function, we didn't update the operand references to point to the cloned version of the local spirv operand insts, as a result, the inlined asm block is still referencing the child insts in the original global asm block.
The fix here just prevents removal of the global asm block, but the right fix is to make sure we dont have such inter block references back to the original global asm block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I must have misunderstood something.
Yesterday I stepped through the inlining code in the debugger and noticed that the SPIRVAsmOperandInst
s didn't get inlined (unlike all of the other operands) and so there was no clone to be found.
I figured this is something that can happen in general, and so we must check for uses recursively before deleting the global inst.
So you are saying that the existing inlining logic is broken?
I will take another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csyonghe Should the fix be that, when we decide to inline SPIRV ASM insts then we force-inline things it contains, like the SPIRVAsmOperandInst
s etc.. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we looked through the code together, it appears to me that the SPIRVAsm parent inst is being cloned, and its children are also being cloned. It is just the operands of the clone seems to be still referencing the original ones instead of the cloned ones.
e.g.
%b = SPIRV_Asm {
%x = SPIRVAsmOperandInst ...
%y = SPIRVAsmOperandInst ...
%z = SPIRVAsmInst %x %y
}
got cloned into main
as:
func %main {
%block = block {
%b' = SPIRV_Asm {
%x' = SPIRVAsmOperandInst ...
%y' = SPIRVAsmOperandInst ...
%z' = SPIRVAsmInst %x %y // !!! should be %x' here, instead of %x
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think I see now!
The SPIRVAsmOperand
s are special in that they are parented to the SPIRVAsm
which we would like to delete.
The inlineInst
function does indeed inline its children, but then later when we get to the last child which is a SPIRVAsmInst
taking SPIRVAsmOperand
s as operands, we decide not to inline them.
I see that there is a dictionary called m_mapGlobalInstToShouldInline
that is first consulted.
Perhaps whenever we inline some inst we should set it as true
in m_mapGlobalInstToShouldInline
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think I see now!
The
SPIRVAsmOperand
s are special in that they are parented to theSPIRVAsm
which we would like to delete.The
inlineInst
function does indeed inline its children, but then later when we get to the last child which is aSPIRVAsmInst
takingSPIRVAsmOperand
s as operands, we decide not to inline them.I see that there is a dictionary called
m_mapGlobalInstToShouldInline
that is first consulted. Perhaps whenever we inline some inst we should set it astrue
inm_mapGlobalInstToShouldInline
...
That works, but only because the SPIRVAsmInst taking these SPIRVAsmOperandInst's as operands happen to appear after the SPIRVAsmOperandInst's children of the SPIRVAsm...
If I instead mark m_mapGlobalInstToShouldInline
to true for any inlined insts first thing in inlineInst
, and then I can change shouldInlineInstImpl
to return true
in case any ancestors of the inst in question should be inlined according to m_mapGlobalInstToShouldInline
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did something similar to the above, and it seems to work.
9374e2f
to
92b0199
Compare
/format |
🌈 Formatted, please merge the changes from this PR |
4d95af8
to
215ddc4
Compare
This is a refactoring and should not affect generated code.
This is a refactoring and should not affect generated code.
This is a refactoring and should not affect generated code.
This is a refactoring and should not affect generated code.
This is a refactoring and should not affect generated code.
This is a refactoring and should not affect generated code.
This closes shader-slang#5607.
215ddc4
to
82e0928
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
The last step (also the last commit) gets rid of the global call and fixes the issue.
#5607