[spirv] decouple argument scope from call-by-value decision#1991
[spirv] decouple argument scope from call-by-value decision#1991jaebaek merged 9 commits intomicrosoft:masterfrom
Conversation
|
✅ Build DirectXShaderCompiler 1.0.1446 completed (commit e098adcb17 by @jaebaek) |
There was a problem hiding this comment.
You also need to add a test for the case where we are calling a structure member function.
For example:
struct testStruct {
int foo() {
// ...
}
};
groupshared testStruct sharedStruct;
void main() {
int result = sharedStruct.foo();
}I believe you haven't handled this case.
There was a problem hiding this comment.
please run clang-format on this file.
f214c31 to
a49bf6e
Compare
|
✅ Build DirectXShaderCompiler 1.0.1463 completed (commit 158c41535a by @jaebaek) |
d6bbccb to
541c834
Compare
|
✅ Build DirectXShaderCompiler 1.0.1722 completed (commit db750c0b3f by @jaebaek) |
There was a problem hiding this comment.
What about variables in the Private storage class? (e.g. static variable)
I believe with the new behavior of SPIRV-Tools, we should never create a temporary variable because of storage class mismatch. (we still do need to create a temporary variable if the param is an rvalue).
If you're not sure, you can check with @s-perron about what the unoptimized output of DXC should look like.
There was a problem hiding this comment.
What about variables in the Private storage class? (e.g. static variable)
again, I think with the new SPIRV-Tools behavior, we shouldn't create temporary variables unless we have an rvalue? Also think about the cases where the function parameter is out or inout.
There was a problem hiding this comment.
Also add tests for cases where the param is out or inout. e.g.
int bar(out int x) {
...
}int bar(inout int x) {
...
}There was a problem hiding this comment.
should also add tests for static cases (to get Private storage class).
541c834 to
1ba5a80
Compare
|
❌ Build DirectXShaderCompiler 1.0.1767 failed (commit 8b59984b7f by @jaebaek) |
|
❌ Build DirectXShaderCompiler 1.0.1777 failed (commit bd797ab890 by @jaebaek) |
626526f to
8aa3f16
Compare
|
❌ Build DirectXShaderCompiler 1.0.1862 failed (commit 2a879cfc34 by @jaebaek) |
There was a problem hiding this comment.
This is removed because it is not generated with the newer SPIRV-Header/Tools
There was a problem hiding this comment.
I just realized this is wrong. Let me update it.
8aa3f16 to
5dc3b6a
Compare
|
✅ Build DirectXShaderCompiler 1.0.1873 completed (commit ee0c23173b by @jaebaek) |
5dc3b6a to
4abcbcb
Compare
|
✅ Build DirectXShaderCompiler 1.0.1902 completed (commit 0ec256cdcd by @jaebaek) |
There was a problem hiding this comment.
s/must be always Function scope/must always be in Function scope
There was a problem hiding this comment.
Better comment:
If it calls a non-static member function, the object itself is argument 0, and therefore all other argument positions are shifted by 1.
There was a problem hiding this comment.
oops! Thanks for fixing this! :)
There was a problem hiding this comment.
maybe you need to add a beforeHlslLegalization parameter to spirvToolsValidate
There was a problem hiding this comment.
this one is using setRelaxLogicalPointer instead of setBeforeHLSLLegalization. why?
There was a problem hiding this comment.
This test does not contain implicit type conversion between isomorphic types. It only uses a illegal storage class i.e., GroupShared instead of function. In this case, enabling only --relax-logical-pointer is fine.
There was a problem hiding this comment.
I think it would be best to use before-hlsl-legalization.
There was a problem hiding this comment.
these ones can maybe still keep using setRelaxLogicalPointer ?
There was a problem hiding this comment.
All of them must be setRelaxLogicalPointer because they have isomorphic function arguments that are actually different from function parameters.
|
✅ Build DirectXShaderCompiler 1.0.1907 completed (commit 9ff3c76a1f by @jaebaek) |
ehsannas
left a comment
There was a problem hiding this comment.
As discussed offline, we should remove relaxLogicalPointer from the backend, and only use beforeHlslLegalization. You can do it in a follow-up CL. Thanks
This issue is related to HLSL to SPIR-V compile. Previously, when passing a variable with Workgroup scope, DXC creates a temporal variable with Function scope and copies the Workgroup variable to the temporal one. This prevents Workgroup variables from being a function parameter. However, it causes unnecessary loads / stores if the function is inlined by spirv-opt. If a function param is a Workgroup variable, this commit does not create a temporal one. This is illegal but spirv-opt legalization will handle it. Related to microsoft#1977
ee96997 to
518a346
Compare
|
✅ Build DirectXShaderCompiler 1.0.1912 completed (commit d924eb080a by @jaebaek) |
Previously, when passing a variable whose scope is not Function,
DXC creates a temporal variable with Function scope and copies
the value of the variable to the temporal one. It produces legal
SPIR-V code but it causes unnecessary loads / stores if the
function is inlined by spirv-opt.
This commit decouples argument scope from call-by-value
decision to avoid creation/load/store of temporal variables.
This generates illegal SPIR-V code but spirv-opt HLSL
legalization handles it.
Related to #1977