Sergio0694/ComputeSharp

Can't use a struct within a CS.D2D1 shader

rickbrew opened this issue · 0 comments

Consider this code:

internal sealed partial class ClassWithShader
{
    [D2DInputCount(0)]
    [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
    [D2DGeneratedPixelShaderDescriptor]
    internal readonly partial struct ShaderWithStruct
        : ID2D1PixelShader
    {
        private struct Data
        {
            public int value;
        }

        public float4 Execute()
        {
            Data data = default;
            UseData(ref data);
            return new float4(data.value, data.value, data.value, data.value);
        }

        private void UseData(ref Data data)
        {
            ++data.value;
        }        
    }
}

This should work fine but generates the following error:

error CMPSD2D0034: The shader of type PaintDotNet.Direct2D1.Effects.ClassWithShader.ShaderWithStruct failed to compile due to an HLSL compiler error (Message: "The FXC compiler encountered one or more errors while trying to compile the shader: "error X3000: unrecognized identifier 'PaintDotNet_Direct2D1_Effects_ClassWithShader_ShaderWithStruct_Data'.". Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp. If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.") (https://github.com/Sergio0694/ComputeSharp)

The error happens no matter where I put the struct, (inside shader, outside shader) X (before methods using it, after methods using it). Even inside/outside of the containing class makes no difference.

This did work in CS.D2D1 v2.1.