[SPIR-V] Fix crash with GetAttributeAtVertex#6018
Conversation
The code assumed all the types we handled had an AST type. But when the struct is created in the SPIR-V backend, there are no AST type left to represent it. In such case, the lowering step should handle the interpolation attributes, so I think we shouldn't have to do anything. Signed-off-by: Nathan Gauër <brioche@google.com>
54dc4e3 to
df553c6
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
s-perron
left a comment
There was a problem hiding this comment.
It is hard for me to know if it is correct. I want to see that the expansion of GetAttributeAtVertex is still correct. I also do not understand why the type does not have to be expanded. Please update the comment with more details. Where does it get expanded?
| bool PervertexInputVisitor::expandNointerpVarAndParam( | ||
| SpirvInstruction *spvInst) { | ||
| // If the spirv type has no AST type (hybrid struct for ex), no need to expand | ||
| // it. |
There was a problem hiding this comment.
Can you explain why there is no need to expand it?
|
|
||
| float colorAtV0 = GetAttributeAtVertex(input.color, 0)[cmp]; | ||
| float colorAtV1 = GetAttributeAtVertex(input.color, 1)[cmp]; | ||
| float colorAtV2 = GetAttributeAtVertex(input.color, 2)[cmp]; |
There was a problem hiding this comment.
Could you add checks to make sure the correct values are extracted from the input?
|
I'll help to take a look. |
cassiebeckley
left a comment
There was a problem hiding this comment.
LGTM once Steven's comments are addressed
…ture inputs. (#6041) **Fix for** Fix issue under: #2955 For structure type, when `nointerpolation` is 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 `compute` should 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. ``` struct S { float4 a : COLOR; }; float compute(float4 a) { return GetAttributeAtVertex(a, 2)[0]; } float4 main(nointerpolation S s, float4 b : COLOR2) : SV_TARGET //float4 main(nointerpolation S s) : SV_TARGET { return float4(0, 0, compute(b), compute(s.a)); //return float4(0, 0, 0, compute(s.a)); } ``` I added an error report point in this commit and gets following reports: ``` 1.hlsl:12:31: error: Current function could only use noninterpolated variable as input. return float4(0, 0, compute(b), compute(s.a)); ^ fatal error: generated SPIR-V is invalid: OpFunctionCall Argument <id> '37[%param_var_a_0]'s type does not match Function <id> '24[%_ptr_Function_v4float]'s parameter type. %45 = OpFunctionCall %float %compute %param_var_a_0 note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible ``` Any idea to let the error only reported before spirv validator? **Ref**: #2955 #6018 --------- Co-authored-by: Zhou, Shaochi(AMD) <shaozhou@amd.com> Co-authored-by: Natalie Chouinard <sudonatalie@google.com>
|
@sudonatalie closing this PR: the bug this PR fixes is already fixed upstream thanks to the other PR. |
|
Was wrong, the repro case I had is fixed, but not the issue case. |
|
Replaced by #6459 |
The code assumed all the types we handled had an AST type. But when the struct is created in the SPIR-V backend, there are no AST type left to represent it.
In such case, the lowering step should handle the interpolation attributes, so I think we shouldn't have to do anything.
Fixes #2955 again.