Eliminate empty struct on metal target#6603
Conversation
518efe4 to
6ead786
Compare
|
|
||
| bool isSimpleType(IRType* type) override | ||
| { | ||
| if (isMetalTarget(targetProgram->getTargetReq())) |
There was a problem hiding this comment.
Why is this needed? Seems very hacky.
There was a problem hiding this comment.
Because all the following decor check are based on C/C++.
For shader target, we always want to handle the type recursively. Otherwise, it will just return a LegalType::simple(type);
There was a problem hiding this comment.
What really should be treated as non-simple type in this case is a type whose leaf type is a struct. However, we shouldn't repeat ourselves to do such check here, because there are already existing logic in legalizeTypeImpl() doing the same thing. We just want to make sure on Metal target, this will execute the logic in that function without early return.
There was a problem hiding this comment.
Instead of adding a check inside the type legalization context, is is possible to create a different TypeLegalizationContext for the metal target, or not run legalizeEmptyTypes if the target is metal in slang-emit.cpp:1286?
I think we should try to keep all target-specific conditions at the top-level in linkAndOptimize so it's clear what's getting run/not run on different backends..
There was a problem hiding this comment.
But I feel that the logic is almost 100% overlap with legalizeEmptyTypes. So there is no need to create different TypeLegalizationContext.
There was a problem hiding this comment.
And, we need to run legalizeEmptyTypes if the target is metal, that is the point of this change actually.
There was a problem hiding this comment.
Hmm..
I guess, since the legalization context does accept a TargetProgram, it's fine if target-specific stuff happens there.
Close 6573. We previously disabled the type legalization for ParameterBlock on Metal, but Metal doesn't allow empty struct in the argument buffer which is mapped from ParameterBlock, so we will need legalizeEmptyTypes on Metal target.
5c63582 to
55af06d
Compare
|
This PR seems to be causing CI failures. The new test fails with the following error, It looks like The following shader is the generated metal shader, I am wondering how this test passed CI, if it did. |
|
The incorrect Metal code is caused by having |
This reverts commit b3deec2.
* Reapply "Eliminate empty struct on metal target (#6603)" (#6711) This reverts commit bc9dc65. * Remove argument in make_struct call corresponding to void field This is a follow-up of #6543, where we leave the VoidType field as it in make_struct call during legalization pass. So during cleaning_void IR pass, when we remove "VoidType" from struct, we will have to also clean up the argument corresponding to the "VoidType" field.
* Eliminate empty struct on metal target Close 6573. We previously disabled the type legalization for ParameterBlock on Metal, but Metal doesn't allow empty struct in the argument buffer which is mapped from ParameterBlock, so we will need legalizeEmptyTypes on Metal target. * update test * update function name
* Reapply "Eliminate empty struct on metal target (shader-slang#6603)" (shader-slang#6711) This reverts commit bc9dc65. * Remove argument in make_struct call corresponding to void field This is a follow-up of shader-slang#6543, where we leave the VoidType field as it in make_struct call during legalization pass. So during cleaning_void IR pass, when we remove "VoidType" from struct, we will have to also clean up the argument corresponding to the "VoidType" field.
Close #6573.
We previously disabled the type legalization for ParameterBlock on Metal, but Metal doesn't allow empty struct in the argument buffer which is mapped from ParameterBlock, so we will need legalizeEmptyTypes on Metal target.