#include_with_pragmas not working properly with compute

Hey!

I am currently reworking our shader library and would like to use DXC for some shaders to support various SM 6.x features (mostly wave intrinsics).

At the moment there is no way to force dxc for all shaders as far as I can tell so instead I would like to have a header file that is included everywhere where I define it.

Recently unity introduced #include_with_pragmas in combination with the custom shader preprocessor which should be what I want to use here. My test setup looks like this:

#pragma kernel CSBlit

Texture2D<float4> _Src;
RWTexture2D<float4> _Dst;

#include_with_pragmas "../Core/Compiler.hlsli"

[numthreads(8,8,1)]
void CSBlit (uint3 id : SV_DispatchThreadID)
{
    _Dst[id.xy] = _Src[id.xy];
}
#ifndef HEADER_COMPILER
#define HEADER_COMPILER

#pragma use_dxc

#endif //HEADER_COMPILER

I am getting errors like:

Shader warning in 'Blit': 'use_dxc' : unknown pragma ignored at kernel CSBlit at Assets/Rendering/Shaders/Core/Compiler.hlsli(4) (on d3d11)

I thought it might just be the dxc pragma but it seems to happen for every other one as well. In addition to that the preprocessor seems to be buggy since the error doesn’t change even if I change the pragma and reimport both shader files.

Is this a known issue? I appreciate any help, thanks in advance!

Hi!
It should work. Please report a bug :slight_smile:
Thanks!

I created a minimal repro for you and submitted it as CASE IN-4359.

If it is a bug and can be fixed would be great to have it backported to 2021.3. Also seems to possibly be related to Compute Shader 'undeclared identifier' for functions and variables defined in include files.

1 Like

Hi, has this been fixed? Or have you found any other solution to this? I still have the same problem in 2022.2.11