Repository navigation
Fix for an issue when noninterpolation is decorated on structure inputs. - #6041
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
emitFatal should be enough. Looks like we don't check for error in the SpirvEmitter once we got the module. I'll add a check to early return in such cases. |
|
Sent #6044 to solve this. |
|
Sorry, I'm confused. Is there a test that this PR is fixing which we can add as a test case? Does it add to #6018 or does it replace it? |
I think I make a mistake. For this fix, test case should be a little different from Keenuts' test case (as showed in PR message). I'll add another one for this fix. Thanks for reminding. |
…hould be recreated. Add more error info.
|
Nathan Gauër (@Keenuts) Please help to review, thanks! |
Steven Perron (s-perron)
left a comment
There was a problem hiding this comment.
Generally looks good. I just have a couple minor suggestions. Also, the one test still confuses me. I don't know where the second store it coming from.
The first access chain is created in PerVertex Visitor, as you commented above, to help get a pointer to the entire array and pass it to function call as its argument. The second one is created in original SPIRV generation step, which has been changed to access to first vertex value, which will be used to let all the 's.a' equal to 's.a[0]' within current function. To make it simple, here's the conclusion of what I made for noninterpolated inputs:
An example could be as following: 1. interpolated inputs: SPIRV: 2. non-interpolated inputs: SPIRV: You can see, Hence, following codes are added in the front of current block to make sure 'param_var_a' could be passed as an array to function call to 'compute': If there's any usage to s.a in main, |
|
Hello! Thanks for putting this together! From https://microsoft.github.io/DirectX-Specs/d3d/MeshShader.html, it says if I use GetAttributeAtVertex, I should mark it as nointerpolation. struct S {
float4 a : COLOR;
};
float compute(float4 a) {
return GetAttributeAtVertex(a, 0)[0];
}
float4 main(nointerpolation S s) : SV_TARGET
{
return float4(0, 0, 0, compute(s.a));
}Here, the main param |
It works for DXIL (https://godbolt.org/z/n443jj4E9). That is usually how we determine what is "legal". The documentation for GetAttributeAtVertex does not say too much about the function parameters. |
Yes, I know, but should we this time? If at least DXC had one HLSL->DXIL test covering this case, I'd say "sure, that's the design", but the only tests I see that aren't SPIR-V are calling GetAttributeAtVertex directly in the main, where the params are directly decorated with |
|
Hi Nathan, as detailed spec for pervertex inputs doesn't say too much about compile check or error rules, I'll share my personal thinking here:
From my personal understanding, the main idea is: In pixel shader stage, the most important thing is we should make sure the first argument is an input attribute decorated with noninterpolation qualifier. For example, a temp local variable, marked as noninterpolation will be meaningless when it is used as the first argument in a GetAttributeAtVertex function call like (maybe this needs an error check later if we all agree?):
I'm afraid this is not a good way for developers, including following concerns:
Like above explanation, even if we may need more works in HLSL-SPIRV compiler module, if it is not definitely abandoned from spec, users should be allowed to use GetAttributeAtVertex in a stage local function call. What we need to do is to report errors when compiler find the first argument is interpolated or not an input from final function call chain.
Yes, that's true. The key problem for per-vertex inputs and noninterpolation qualifier now, is that we need to keep legacy usage still legal. So we can't directly require all the noninterpolation inputs to be an array now, that's the key question. We now need to implicitly expand them to an three-element array in new feature. The first draft of implementation tried to let all the noninterpolated inputs be an array and received many errors reported here. |
Hi, Thanks for the input!
To be clear, my case was not to restrict void foo(float4 a) {
GetAttributeAtVertex(a, 0);
}
int main(nointerpolation float4 a : COLOR) {
foo(a);
}But I do see this as valid: void foo(nointerpolation float4 a) {
GetAttributeAtVertex(a, 0);
}
int main(nointerpolation float4 a : COLOR) {
foo(a);
}
Yes, I do think this should trigger an error. Or if we stay coherent with the float compute(nointerpolation float4 a) {
return a.r;
}
float4 main(float4 a : COLOR) : SV_TARGET
{
return float4(0, 0, 0, compute(s.a));
}Same as this, which returns a validation error right now: float compute(nointerpolation float4 a) {
return GetAttributeAtVertex(a, 0)[0];
}
float4 main(float4 a : COLOR) : SV_TARGET
{
return float4(0, 0, 0, compute(a));
}
Yes, that's the sad reality. The only reason I'm pushing against is the DXC backend didn't test those cases. They only test |
|
Nathan Gauër (@Keenuts) The defacto standard is what is implemented in DXC for dxil. This means that there is probably lots of code that assumes the current behaviour. We should do what happens in DXIL. If you want to make changes to the spec the explicitly allow or disallow something, that is a dicussion for HLSL specs. You can bring it up there, but I'm sure your TL will tell you it is not worth it. 😉 |
|
Should I wait for feedback from Nathan related to current discussion or should I merge this PR? I think current fix won't against additional detailed usage description of |
I think we can move forward, and follow blindly what the DXIL backend allows. |
|
A few other examples: float foo(int c, float v) {
if (c == 0)
return GetAttributeAtVertex(v, 1);
else
return v;
}
float4 main(nointerpolation float a : A) : SV_Target
{
float tmp1 = GetAttributeAtVertex(a, 2);
float tmp2 = foo(0, a);
float tmp3 = foo(1, a);
return float4(0, 0, 0, tmp1 + tmp2 + tmp3);
}DXIL seems to only call the intrinsic for Also, noticed we crash for this usage of float foo(float v, uint index) {
return GetAttributeAtVertex(v, index);
}
float4 main(nointerpolation float a : A) : SV_Target
{
float tmp = foo(a, 1);
return float4(0, 0, 0, tmp);
}Another example float foo(float a, float b, uint index) {
if (index == 0)
return GetAttributeAtVertex(a, 0);
else
return GetAttributeAtVertex(b, 0);
}
float4 main(nointerpolation float a : A) : SV_Target
{
float b = 0;
float tmp = foo(a, b, 0);
return float4(0, 0, 0, tmp);
}Depending if foo is called with |
|
Just discusses with Steven Perron (@s-perron), and we might want to force legalization if |
|
Nathan Gauër (@Keenuts) I've resolved the merge conflicts on this change and retested all (I think) of the cases mentioned in the comments here. Most are orthogonal to this change, and I don't think there are any cases which this PR makes worse, so what do you think about merging it as-is, and leaving follow-up issues for error message improvements? I've created: |
Nathan Gauër (Keenuts)
left a comment
There was a problem hiding this comment.
Agree, let's move this forward.
Changes addressed, s-perron OOO
Fix for
Fix issue under:
#2955
For structure type, when
nointerpolationis decorated on a structure input, this flag should be broadcast to its members.PR (#6018) also helps to resolve an issue when SPIRV backend generated variable has no AST type.
Test
Please see same case under:
#6018
Besides, example as below should be invalid as the first parameter of function
computeshould has only one spirv-type.If its parameter type declaration has been expanded to an array implicitly, it should not accept other interpolated inputs as its input parameter.
I added an error report point in this commit and gets following reports:
Any idea to let the error only reported before spirv validator?
Ref:
#2955
#6018