microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.04k stars 678 forks source link

[SPIR-V] Invalid SPIR-V with function returning bigger size vector out variable than caller vector/sclar argument variable #6781

Closed shobomaru closed 1 week ago

shobomaru commented 1 month ago

Description DXC generates an invalid SPIR-V

Steps to Reproduce

dxc -T ps_6_0 -spirv path/to/file.hlsl

HLSL code:

void Get(out float2 foo)
{
    foo = (float2)0;
}

float main() : SV_Target
{
    float bar;
    Get(bar);
    return bar;
}

If change the code in one of the following ways, the issue is not occurred.

Actual Behavior

fatal error: generated SPIR-V is invalid: OpStore Pointer '2[%out_var_SV_Target]'s type does not match Object '6[%6]'s type. OpStore %out_var_SV_Target %6

Without validation:

               OpCapability Shader
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main" %out_var_SV_Target
               OpExecutionMode %main OriginUpperLeft
               OpSource HLSL 600
               OpName %out_var_SV_Target "out.var.SV_Target"
               OpName %main "main"
               OpDecorate %out_var_SV_Target Location 0
      %float = OpTypeFloat 32
    %float_0 = OpConstant %float 0
    %v2float = OpTypeVector %float 2
          %6 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Output_float = OpTypePointer Output %float
       %void = OpTypeVoid
          %9 = OpTypeFunction %void
%out_var_SV_Target = OpVariable %_ptr_Output_float Output
       %main = OpFunction %void None %9
         %10 = OpLabel
               OpStore %out_var_SV_Target %6
               OpReturn
               OpFunctionEnd

Environment

s-perron commented 1 month ago

This might be fixed by https://github.com/microsoft/DirectXShaderCompiler/pull/6747.

s-perron commented 1 week ago

This is now working: https://godbolt.org/z/G9eq5hTa8