You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] Invalid spir-v generated when using nointerpolation keyword #5270
Hello, when compiling the following drastically reduced HLSL example to spir-v with dxc.exe -spirv -fspv-target-env=vulkan1.1 -fvk-use-dx-layout -O3 -T ps_6_0 -E psMain nointerpolationbug.hlsl:
struct PSInput
{
nointerpolation int level : LEVEL;
};
int psMain(PSInput input) : SV_Target0
{
return input.level;
}
I get the following error:
fatal error: generated SPIR-V is invalid: Expected Result Type to be a composite type
%18 = OpCompositeConstruct %int %17 %12 %12
This occurs on the current latest nightly build against commit e0a2965, it does not occur using an earlier build against commit 740dd09.
Going through more of our shader builds and it definitely seems to affect everywhere we use nointerpolation, with results varying from something like the above to straight up crashing inside the optimizer in spvtools.
For pixel shaders to perform attribute interpolation using the system-generated barycentric weights, the attributes values at the vertices must be provided. These can be accessed by declaring the attribute as nointerpolation, and using new intrinsics to read the values at the 3 vertices.
So I think an inputs decorated with 'nointerpolation' should be treated as it has an extra dimension, indicating which vertices it mapped to. For the error reported here, its type is treated as an int[3] now.
Steven Perron (@s-perron)Nathan Gauër (@Keenuts)
I think this is the case we discussed before, like, whether 'nointerpolation' inputs could be used outside GetAttributeAtVertex() in a function body?
I'm not sure whether above case is legal in KHR extension, like the case in discussion before:
Yes, we did discuss this before. This case cannot be handled in Vulkan because the spir-v cannot correctly represent it. The spir-v validator message is not useful. If we can, we should try to add an error message before we generate the spir-v.
Also been getting issues due to inappropriate usage of nointerpolation but from an LLVM assert Error: assert(new_array_type != nullptr && "Can't copy an array to a non-array.") without it spitting out any errors about invalid spir-v, making it initially difficult to narrow down the troublesome code.
Matt Stevens (@handsomematt)Steven Perron (@s-perron) - I might not be fully understanding the discussion here, but can you confirm you will be fixing the regression with the case Matt Stevens (@handsomematt) mentions above. We have this in our shaders too, and this has worked for a very long time, so I presume this is just a regression due to your change?
I presume nointerpolation on a PS input should just map to the SPIR-V Flat decoration as it always has - should be fully represenable in SPIR-V?
I cannot find what HLSL is supposed to do if you access a nointerpolation input without using GetAttributeAtVertex. Is there anything that specifies what it does?
I cannot find what HLSL is supposed to do if you access a nointerpolation input without using GetAttributeAtVertex. Is there anything that specifies what it does?
The case that regressed is a PS input, not VS input. It should be a Flat interpolation modifier. I don’t think there is any ambiguity about that? It used to work.
Dan Ginsburg (@danginsburg) From the spec, GetAttributeAtVertex is used in PS. We now support this intrinsic so nointerpolation input will be treated as an array. Its index will represent VertexID, indicating where this value comes from / which vertex it is representing now. We are assuming it won't be used outside this intrinsics.
Just for further clarity here's the expected output of this code before cd3b40b and the error we're getting after, the assert I posted earlier is an additional error with the same root problem.
struct PS_INPUT
{
nointerpolationuint nView : TEXCOORD12;
};
uintMainPs( PS_INPUT i ) : SV_Target0
{
return i.nView;
}
// Before cd3b40b// dxc.exe -T ps_6_0 -E MainPs -spirv// ...// OpName %MainPs "MainPs"// OpDecorate %in_var_TEXCOORD12 Flat// OpDecorate %in_var_TEXCOORD12 Location 0// ...// After cd3b40b// dxc.exe -T ps_6_0 -E MainPs -spirv// fatal error: generated SPIR-V is invalid: Expected Result Type to be a composite type// %17 = OpCompositeConstruct %uint %16 %11 %11
Here are some observations I have from poking at it:
ps_6_0 in DXIL does not allow GetAttributeAtVertex, it gives this error:
error: Opcode AttributeAtVertex not valid in shader model ps_6_0.
note: at '%4 = call float @dx.op.attributeAtVertex.f32(i32 137, i32 0, i32 0, i8 3, i8 1)' in block '#0' of function 'PSMain'.
Validation failed.
ps_6_1 does allow both naked nointerpolation and GetAttributeAtVertex( ..., 0 ). naked nointerplation continues to generate the same code as it did with ps_6_0, GetAttributeAtVertex(..., 0 ) will add the Barycentric requirement to the shader: ; Note: shader requires additional functionality: ; Barycentrics
Chow (@ShchchowAMD) Sorry, but I will be on you a lot about this. People keep reporting new issues related to this. This is a serious regression. If we cannot get the fix soon, should we revert your change? Then you can put it back in when you have to fix ready.
Yeah, we are stuck not being able to take newer version of DXC until this gets fixed. I don't want to make extra work, but if it's not going to be addressed soon I agree it should be reverted. I wouldn't want this to go into an official release. It's broken for most of our pixel shaders, and I imagine many other people's as well.
Thanks everyone for your responses, I would also agree that this change should probably be reverted - even if a fix is forthcoming, it seems like it might be a better idea to instead have some test coverage (as suggested by Goshido Matazuki (@Goshido) above) alongside a fixed version of the original change instead?
Activity
jmccarthy634 commentedon Jun 7, 2023
Chow (@ShchchowAMD) this appears to have started happening with commit cd3b40b
Going through more of our shader builds and it definitely seems to affect everywhere we use nointerpolation, with results varying from something like the above to straight up crashing inside the optimizer in spvtools.
ShchchowAMD commentedon Jun 7, 2023
Thanks for reporting this issue.
Ref to comment in the commit: #4638 (comment)
For latest KHR extension, following SV_BaryCentrics description in wiki (https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_Barycentrics):
For pixel shaders to perform attribute interpolation using the system-generated barycentric weights, the attributes values at the vertices must be provided. These can be accessed by declaring the attribute as nointerpolation, and using new intrinsics to read the values at the 3 vertices.So I think an inputs decorated with 'nointerpolation' should be treated as it has an extra dimension, indicating which vertices it mapped to. For the error reported here, its type is treated as an int[3] now.
Steven Perron (@s-perron) Nathan Gauër (@Keenuts)
I think this is the case we discussed before, like, whether 'nointerpolation' inputs could be used outside GetAttributeAtVertex() in a function body?
I'm not sure whether above case is legal in KHR extension, like the case in discussion before:
If we could make sure it should only be used in such intrinsics, I'll add error message in compile result info.
s-perron commentedon Jun 12, 2023
Yes, we did discuss this before. This case cannot be handled in Vulkan because the spir-v cannot correctly represent it. The spir-v validator message is not useful. If we can, we should try to add an error message before we generate the spir-v.
Chow (@ShchchowAMD) Are you able to do that?
ShchchowAMD commentedon Jun 12, 2023
Yea. I'll make a new commit for this.
handsomematt commentedon Jun 12, 2023
Also been getting issues due to inappropriate usage of nointerpolation but from an LLVM assert
Error: assert(new_array_type != nullptr && "Can't copy an array to a non-array.")without it spitting out any errors about invalid spir-v, making it initially difficult to narrow down the troublesome code.danginsburg commentedon Jun 13, 2023
Matt Stevens (@handsomematt) Steven Perron (@s-perron) - I might not be fully understanding the discussion here, but can you confirm you will be fixing the regression with the case Matt Stevens (@handsomematt) mentions above. We have this in our shaders too, and this has worked for a very long time, so I presume this is just a regression due to your change?
I presume nointerpolation on a PS input should just map to the SPIR-V Flat decoration as it always has - should be fully represenable in SPIR-V?
s-perron commentedon Jun 13, 2023
I cannot find what HLSL is supposed to do if you access a nointerpolation input without using GetAttributeAtVertex. Is there anything that specifies what it does?
This is all that I could find.
https://github.com/microsoft/DirectXShaderCompiler/wiki/SV_Barycentrics#per-vertex-attributes
danginsburg commentedon Jun 13, 2023
The case that regressed is a PS input, not VS input. It should be a Flat interpolation modifier. I don’t think there is any ambiguity about that? It used to work.
ShchchowAMD commentedon Jun 13, 2023
Dan Ginsburg (@danginsburg) From the spec, GetAttributeAtVertex is used in PS. We now support this intrinsic so nointerpolation input will be treated as an array. Its index will represent VertexID, indicating where this value comes from / which vertex it is representing now. We are assuming it won't be used outside this intrinsics.
Matt Stevens (@handsomematt) I'll check this. Another question for this example is just as first comment to Dan Ginsburg (@danginsburg) here.
danginsburg commentedon Jun 13, 2023
Ok. I am confused. The SV_Barycentric proposal changes the meaning of nointerpolation PS inputs for all shader models? Shouldn’t it be opt in somehow? This has been supported since SM5 and has been in the spir-v backend for a long time https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#id66
handsomematt commentedon Jun 13, 2023
Just for further clarity here's the expected output of this code before cd3b40b and the error we're getting after, the assert I posted earlier is an additional error with the same root problem.
s-perron commentedon Jun 13, 2023
I'll review the specs, and get back to you.
danginsburg commentedon Jun 13, 2023
Here are some observations I have from poking at it:
; Note: shader requires additional functionality: ; BarycentricsI would propose, therefore, that for the purposes of SPIR-V:
That seems to be what DX12 is doing from what I can tell.
11 remaining items
s-perron commentedon Jun 30, 2023
Chow (@ShchchowAMD) Sorry, but I will be on you a lot about this. People keep reporting new issues related to this. This is a serious regression. If we cannot get the fix soon, should we revert your change? Then you can put it back in when you have to fix ready.
danginsburg commentedon Jun 30, 2023
Yeah, we are stuck not being able to take newer version of DXC until this gets fixed. I don't want to make extra work, but if it's not going to be addressed soon I agree it should be reverted. I wouldn't want this to go into an official release. It's broken for most of our pixel shaders, and I imagine many other people's as well.
ShchchowAMD commentedon Jul 1, 2023
Hi perron,
I'll update a fix today or tomorrow ASAP. I'm refining current new codes.
Apologize again for the regression.
Goshido commentedon Jul 1, 2023
Are there any autotests to prevent such breaking changes in the future?
jmccarthy634 commentedon Jul 2, 2023
Thanks everyone for your responses, I would also agree that this change should probably be reverted - even if a fix is forthcoming, it seems like it might be a better idea to instead have some test coverage (as suggested by Goshido Matazuki (@Goshido) above) alongside a fixed version of the original change instead?
ShchchowAMD commentedon Jul 3, 2023
Steven Perron (@s-perron) Please revert my previous commit. Current fix spent more time than expected.
I'll add more test coverages before making a new PR.
For some corner cases, I'll raise a new issue ticket for discussion.
Sorry for this regression again.
s-perron commentedon Jul 3, 2023
Nathan Gauër (@Keenuts) Cassandra Beckley (@cassiebeckley) I'm off today can one of you take care of the revert? If not I'll do it tomorrow.
Keenuts commentedon Jul 3, 2023
Sure, but everybody is OOO for the next 2 days (except me in Europe 🙃) so might not get the approvals for revert before Wednesday.
Revert "[SPIR-V] add support for extension KHR_fragment_shading_baryc…
Goshido commentedon Jul 4, 2023
DirectX Shader Compiler v1.7.2212.10216
2096d1b8054d1de864924ef0c5009f533597b9d4does not have the issue anymore.Thanks 👍
jmccarthy634 commentedon Jul 4, 2023
Thanks all