microsoft / DirectX-Graphics-Samples

This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.
MIT License
6k stars 2.02k forks source link

Instructions should not read uninitialized value #873

Closed wagshiwei closed 3 months ago

wagshiwei commented 3 months ago

Project D3D12RaytracingRealTimeDenoisedAmbientOcclusion

FXC : warning : no output provided for debug - embedding PDB in shader container.  Use -Qembed_debug to silence this warning.
1>FXC : error : validation errors
1>
1>RTAO\Shaders\Denoising\FillInCheckerboard_CrossBox4TapFilterCS.hlsl(50,29): error GE58B881B: Instructions should not read uninitialized value.
1>note: at 'store float undef, float* %36' in block '#2' of function 'main'.
1>Validation failed.
stanard commented 3 months ago

Hello,

I just updated several aspects of the raytracing sample infrastructure. I did not reproduce your issue, which implies to me that it may be coming from your GPU vendor's backend shader compiler. I don't think the error is valid. Please try pulling latest and see how it goes. This will require Visual Studio 2022. Please also have the newest Windows SDK installed. If the compiler error persists, could I please have you identify the GPU you are using? You might need to submit a bug to our HLSL team.

Thank You, James Stanard

wagshiwei commented 3 months ago

Compile successfully if I add select

1>In file included from RTAO\Shaders\Denoising\CalculateMeanVarianceCS.hlsl:27:
1>./RTAO/shaders\RaytracingShaderHelper.hlsli(287,9): error G13DA7946: use of undeclared identifier 'select'
1>        return select(x < 0.04045, x / 12.92, pow((x + 0.055) / 1.055, 2.4));
1>               ^
1>./RTAO/shaders\RaytracingShaderHelper.hlsli(292,9): error G13DA7946: use of undeclared identifier 'select'
1>        return select(x < 0.0031308, 12.92 * x, 1.055 * pow(abs(x), 1.0 / 2.4) - 0.055);
1>               ^
1>./RTAO/shaders\RaytracingShaderHelper.hlsli(346,32): error G13DA7946: use of undeclared identifier 'select'
1>    return (1.0 - abs(v.yx)) * select(v.xy >= 0.0, 1.0, -1.0);
1>                               ^
1>./RTAO/shaders\RaytracingShaderHelper.hlsli(365,13): error G13DA7946: use of undeclared identifier 'select'
1>    n.xy += select(n.xy >= 0.0, -t, t);
stanard commented 3 months ago

I think this means you didn't install the latest Windows 11 SDK. With the latest shader compiler, HLSL 2021 is enabled by default. In HLSL 2021, vector conditional operators (?:) aren't allowed. The select() intrinsic was introduced to replace it.

You can install the latest SDK with Visual Studio Installer. Click on 'Modify'. Then under 'Individual Components', search for "Windows 11 SDK" and check 10.0.26100.0. Then click on the 'Modify' button in the lower right.

walbourn commented 3 months ago

@stanard It might be more robust to add to the sample's code for invoking DXC -HV 2021 to make sure it is using the expected language version.

Easiest way to do that is in each ItemDefinitionGroup in the vcxproj, add:

    <FXCompile>
      <AdditionalOptions>-HV 2021 %(AdditionalOptions)</AdditionalOptions>
    </FXCompile>