Skip to content

[SPIR-V] Fix crash with GetAttributeAtVertex#6018

Closed
Keenuts wants to merge 1 commit into
microsoft:mainfrom
Keenuts:fix-getattribute
Closed

[SPIR-V] Fix crash with GetAttributeAtVertex#6018
Keenuts wants to merge 1 commit into
microsoft:mainfrom
Keenuts:fix-getattribute

Conversation

@Keenuts
Copy link
Copy Markdown
Collaborator

@Keenuts Keenuts commented Nov 15, 2023

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.

@Keenuts Keenuts requested a review from s-perron November 15, 2023 16:50
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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 15, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Copy Markdown
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add checks to make sure the correct values are extracted from the input?

@ShchchowAMD
Copy link
Copy Markdown
Contributor

I'll help to take a look.

Copy link
Copy Markdown
Contributor

@cassiebeckley cassiebeckley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once Steven's comments are addressed

sudonatalie added a commit that referenced this pull request Mar 5, 2024
…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>
@Keenuts
Copy link
Copy Markdown
Collaborator Author

Keenuts commented Mar 14, 2024

@sudonatalie closing this PR: the bug this PR fixes is already fixed upstream thanks to the other PR.

@Keenuts Keenuts closed this Mar 14, 2024
@Keenuts Keenuts reopened this Mar 14, 2024
@Keenuts
Copy link
Copy Markdown
Collaborator Author

Keenuts commented Mar 14, 2024

Was wrong, the repro case I had is fixed, but not the issue case.
I need to look into this PR again to understand if the fix I suggested is really a fix, or just works because "luck".

@Keenuts
Copy link
Copy Markdown
Collaborator Author

Keenuts commented Mar 29, 2024

Replaced by #6459

@Keenuts Keenuts closed this Mar 29, 2024
@Keenuts Keenuts deleted the fix-getattribute branch March 29, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[SPIR-V] Silent compiler crash when using GetAttributeAtVertex

4 participants