Sergio0694 / ComputeSharp

A .NET library to run C# code in parallel on the GPU through DX12, D2D1, and dynamically generated HLSL compute and pixel shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
MIT License
2.7k stars 121 forks source link

Example code doesnt compile with just computesharp, needs compute sharp dynamic #765

Closed IR0NSIGHT closed 6 months ago

IR0NSIGHT commented 6 months ago

I feel like im missing something here but:

nuget.org example code

Error list shows:

Severity    Code    Description Project File    Line    Suppression State   Details
Error   CMPS0047    The shader of type application.Maps.heightMap.MultiplyByTwo needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported  cFlowAPI    C:\Users\?????\Documents\Repos\cFlow\cFlowAPI\Maps\heightMap\ShadedHeightmapComputer.cs 26  Active  
[EmbeddedBytecode(DispatchAxis.X)]

fixes that

i mean thats not a major problem, but it was confusing to me since the code from the docu didnt mention the need for dynamic addon

github docu example code

this one i couldnt get to compile.

[ThreadGroupSize(DefaultThreadGroupSizes.X)]
[GeneratedComputeShaderDescriptor]
public readonly partial struct MultiplyByTwo(ReadWriteBuffer<int> buffer) : IComputeShader
{
    public void Execute()
    {
        buffer[ThreadIds.X] *= 2;
    }
Severity    Code    Description Project File    Line    Suppression State   Details
Error   CS0246  The type or namespace name 'ThreadGroupSizeAttribute' could not be found (are you missing a using directive or an assembly reference?)  cFlowAPI    C:\Users\Max1M\Documents\Repos\cFlow\cFlowAPI\Maps\heightMap\ShadedHeightmapComputer.cs 25  Active  
Error   CS0103  The name 'DefaultThreadGroupSizes' does not exist in the current context    cFlowAPI    C:\Users\Max1M\Documents\Repos\cFlow\cFlowAPI\Maps\heightMap\ShadedHeightmapComputer.cs 25  Active  
Error   CS0246  The type or namespace name 'GeneratedComputeShaderDescriptorAttribute' could not be found (are you missing a using directive or an assembly reference?) cFlowAPI    C:\Users\Max1M\Documents\Repos\cFlow\cFlowAPI\Maps\heightMap\ShadedHeightmapComputer.cs 26  Active  
Error   CMPS0047    The shader of type application.Maps.heightMap.MultiplyByTwo needs to be annotated as having embedded bytecode (using the [EmbeddedBytecode] attribute), as dynamic shader compilation is not supported  cFlowAPI    C:\Users\Max1M\Documents\Repos\cFlow\cFlowAPI\Maps\heightMap\ShadedHeightmapComputer.cs 27  Active  

i checked the github if ThreadGroupSizeAttribute even exists (maybe the docu is just outdated) and it does exist. But it doesnt exist in my ComputeSharp installation/namespace, checked in my ide. 🤷

Anyways, just wanted to let you know that the docu getting-started part doesnt run right out of the box :)

Sergio0694 commented 6 months ago

"it was confusing to me since the code from the docu didnt mention the need for dynamic addon"

The documentation has a disclaimer at the bottom saying that sample assumed the Dynamic package was installed 🙂

"But it doesnt exist in my ComputeSharp installation/namespace, checked in my ide."

That's expected, that attribute is only introduced in ComputeSharp 3.0, which is only available in preview for the moment. If you want to try it out (I do recommend it, it has a ton of improvements over 2.x), you can get the latest preview version for it 😄

Thank you!