DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

dxc silently passes uninitialized value as undef

Open vcsharma opened this issue 5 years ago • 3 comments

Compiling the below hlsl generates dxil with undef passed to @dx.op.tertiary.i32 without generating any warnings/errors.

// dxc /E main /T vs_6_2

HLSL

int2x2 m;

int2 main (int a : IN) : OUT
{
 int2 b;
 b.x = a;
 return mul( b, m );
}

DXIL

define void @main() {
..
  %10 = call i32 @dx.op.tertiary.i32(i32 48, i32 undef, i32 %5, i32 %9)  ; IMad(a,b,c)
..
}

vcsharma avatar Jun 30 '20 02:06 vcsharma

I'm going to tweak the example given a bit because arbitrary outs are allowed to be partially undefined for some reason that I have no reason to doubt is valid. This shader exhibits the same problem:

int4x4 m;

float4 main (int a : IN) : SV_Position
{
 float2 b;
 b.x = a;
 return mul( b.xyxy, m );
}

pow2clk avatar Sep 03 '20 22:09 pow2clk

I encountered this issue via mistakenly using out for a function parameter instead of inout. It took me quite awhile to track this issue down :(

Here's a representative example:

struct PSInput
{
	float4 color : COLOR;
};

void GetMaxChannel( float4 color, out float maxChannel )
{
    maxChannel = max( maxChannel, max( max( color.x, color.y), max( color.z, color.w ) ) );
}

float4 PSMain(PSInput input) : SV_TARGET
{
    
    float maxChannel = 0;
    GetMaxChannel(input.color, maxChannel);
	return maxChannel.xxxx;
}

jshopf avatar Dec 15 '21 16:12 jshopf

This is unlikely to be something we could catch before codegen, but the validator should be able to detect this.

@jshopf - I don't think that this is the same issue. If the issue you reported here is still important to you, can you please open a new one with an up-to-date repro? Thanks!

damyanp avatar Jul 01 '24 17:07 damyanp