Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstantBuffer.Length gives shader compilation error #794

Open
BobSammers opened this issue May 8, 2024 · 0 comments
Open

ConstantBuffer.Length gives shader compilation error #794

BobSammers opened this issue May 8, 2024 · 0 comments
Labels
bug 🐛 Something isn't working untriaged 🧰 A new issue that needs initial triage

Comments

@BobSammers
Copy link

Description (optional)

ConstantBuffer<T> has a .Length property, but I get a shader compile error when I try to access it for a buffer of uints.

Reproduction Steps

Attempt to compile a shader with the following code

[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
[GeneratedComputeShaderDescriptor]
internal readonly partial struct Trial(
        ReadWriteTexture2D<uint> pixelBuffer,
        ConstantBuffer<uint> colourMap,
        int xMax
    ) : IComputeShader
{
    public void Execute()
    {
        var index = (int)(ThreadIds.X / (float)xMax * colourMap.Length);
        pixelBuffer[ThreadIds.XY] = colourMap[index];
    }
}

Expected Behavior

Shader is correctly compiled.

Actual Behavior

Compilation fails:

Message: "The DXC compiler encountered one or more errors while trying to compile the shader: "

error: invalid format for vector swizzle 'GetDimensions' resource.GetDimensions(_0, _1);

[error]: no matching function for call to '__get_Dimension0'

int index = (int)(ThreadIds.x / (float)xMax * __get_Dimension0(colourMap));
~~~~~~~~~~~~~~~ static int __get_Dimension0(uint resource) .

Using the current stable version (2.1.0), this occurs at run time; using 3.0.0-preview2 results in errors as soon as the code is typed.

System info

This section should contain useful info such as:

  • ComputeSharp
    • 2.1.0. / 3.0.0-preview2 (ComputerSharp.Dynamic @ 2.1.0 / 2.2.0-preview1)
  • Operating system version:
    • Win 11 Pro 22621.3447
  • CPU/GPU model (the latter is especially useful for shader issues)
    • Intel 8th Gen / Intel HD530
  • Visual Studio version, or .NET SDK/runtime version
    • VS2022 17.9.6 / .net8.0

Additional context (optional)

It may be that ConstantBuffer<T> is not the best type to use in this scenario (I have no experience in shader programming), but as the Length property is provided in a C# class specifically intended for creating shaders, I'm assuming it is a bug if it cannot be translated into valid HLSL. Using a ReadOnlyBuffer<T> instead in otherwise identical code works as expected, and the example compiles and runs with expected results.

@BobSammers BobSammers added bug 🐛 Something isn't working untriaged 🧰 A new issue that needs initial triage labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working untriaged 🧰 A new issue that needs initial triage
Projects
None yet
Development

No branches or pull requests

1 participant