DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Verify behavior of GetAttributeAtVertex

Open sudonatalie opened this issue 11 months ago • 2 comments

Description Follow-up from https://github.com/microsoft/DirectXShaderCompiler/pull/6041#issuecomment-1829775849

Steps to Reproduce

dxc -T ps_6_6 -spirv
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);
}

Actual Behavior Once #6041 is merged, the above sample will successfully compile for both DXIL and SPIR-V, however, as @Keenuts mentioned:

DXIL seems to only call the intrinsic for tmp1 and tmp2, but tmp3 gets loaded as usual, but with an undefined vertex index. While for SPIR-V, we default to the index 0.

Expected Behavior We should determine whether this behavior is well-defined for DXIL then verify that that SPIR-V backend implementation is matches.

sudonatalie avatar Mar 04 '24 21:03 sudonatalie

I'm surprised we don't see errors for this since it's calling GetAttributeAtVertex from a subfunction.

pow2clk avatar Mar 05 '24 16:03 pow2clk

@pow2clk If calling GetAttributeAtVertex outside the main entrypoint function is illegal, adding a check and error messaging for that would resolve a lot of our issues, but we didn't find any docs explicitly stating that. It looks like the compiler allows it (with various degrees of functionality) for both DXIL and SPIR-V right now.

sudonatalie avatar Mar 05 '24 16:03 sudonatalie

Related: https://github.com/microsoft/hlsl-specs/issues/181

sudonatalie avatar Mar 26 '24 18:03 sudonatalie

This is now fixed (https://github.com/microsoft/DirectXShaderCompiler/commit/27b87b75937f4d3fff0c486bc9bba6540c3bddb7)

Keenuts avatar Apr 03 '24 16:04 Keenuts