-
Notifications
You must be signed in to change notification settings - Fork 255
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
Add WaveGetLane* support for Metal and WGSL #6371
Add WaveGetLane* support for Metal and WGSL #6371
Conversation
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!
source/slang/slang-emit.cpp
Outdated
@@ -100,7 +100,7 @@ | |||
#include "slang-ir-strip-default-construct.h" | |||
#include "slang-ir-strip-legalization-insts.h" | |||
#include "slang-ir-synthesize-active-mask.h" | |||
#include "slang-ir-translate-glsl-global-var.h" | |||
#include "slang-ir-translate-in-out-global-var.h" |
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.
Can name it translate-global-varying-var.
source/slang/slang-emit-c-like.cpp
Outdated
@@ -3055,6 +3055,11 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO | |||
emitOperand(as<IRGlobalValueRef>(inst)->getOperand(0), getInfo(EmitOp::General)); | |||
break; | |||
} | |||
case kIROp_RequireWGSLExtension: |
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.
Can we just use a single RequireTargetExtension for all targets?
Not sure why the Metal glsl variant test fails while the HLSL variant passes - the produced code is similar and they both compile fine using the Metal compiler. I do not have an Apple device to test, hopefully my most recent change fixes it. |
This reverts commit f2b97e9.
The glsl variant test still failed on Metal and I am not sure why. I loosened up the check requirements for the Metal case and added another test for the glsl syntax that is a copy of the hlsl syntax test(that passes just fine in Metal), so the new test should definitely pass. |
Hmm, if it is a hardware problem, then the HLSL syntax should also fail? Can you compare the metal shader output from both HLSL and GLSL syntax and see if there are any differences? |
Yea somehow the new GLSL syntax test(that is a 1-1 copy of the passing HLSL syntax test) is failing. Here is a diff of the outputs of the HLSL and GLSL syntax. They are very similar(the difference in output type is a test case typo). |
I noticed that the HLSL case, the compiler is able to fold the access to wave index directly as a use of Which should be fine, but I wonder if that's the reason that caused the wrong value. |
Another suspicious thing is:
note that |
We are currently generating:
and this is in reverse order of the fields, might worth clean this up and make the assignment in the consistent order of the fields. |
Thanks for the help. I have made changes so that the GLSL and HLSL outputs are exactly the same (diff). Can you run the test again? |
It is surprising that the GLSL syntax variant still fails. Here is a diff of the hlsl and glsl tests and diff of the Metal output. The produced Metal code is exactly the same. |
One test is using COMPARE_COMPUTE, and the other is using COMPARE_COMPUTE_EX, can we make both of them the same? |
This is needing more debug. Let's disable the glsl test and get this PR merged first. We can leave it as future work. |
|
||
|
||
// TODO: There are some issues with the Metal backend when using glsl-style syntax, test is disabled for now. | ||
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-metal -compute -entry computeMain -allow-glsl |
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.
Instead of disable test here, let’s run the test, but add the test name to expected-failure.txt so we can always use that file to track tests that we still need to work on.
Whoops I put the expected to fail tests in the wrong file, I have corrected them. |
There were some merge conflicts - I corrected them |
Closes #6208, related to #6210.
Adds support for
WaveGetLane*
intrinsics for Metal and WGSL through the use of GLSL flavored in/out global vars.These intrinsics require built-in values to be passed through the entry point parameters, but the intrinsics themselves are "global" functions. The implementation reuses the already existing code that handles glsl
gl_*
global builtin variables and adds them to the entry point parameter list.translateGLSLGlobalVar
is renamed because it also handles non-glsl code.