Closed 3DartBlade closed 2 months ago
Project files: ComputeSharpTest3.zip (Ignore the typo, I've been trying to get this to work for a long time now)
You're missing AllowUnsafeBlocks
, the analyzers are telling you that as well 🙂
Just set that in your .csproj and it'll work as expected. The generators are disabled otherwise.
Thank you, that solved it!
For some reason it did not show me those errors, but that's probably my Visual Studio's fault. At least if someone has the same issue they'll find the answer here. I'm just glad it works now!
Description
I've been trying to get the sample 'MultiplyByTwo' code running from the wiki. I finally figured out after a lot of searching that I need the 3.0.0 preview version of the package, and my project is now using .NET 8.0 thanks to primary constructors.
However, calling
GraphicsDevice.Run
exactly as it is on the wiki, with a struck exactly as on the wiki (see code below), causes this compilation error:CS0315 The type 'MultiplyByTwo' cannot be used as type parameter 'T' in the generic type or method 'GraphicsDeviceExtensions.For<T>(GraphicsDevice, int, in T)'. There is no boxing conversion from 'MultiplyByTwo' to 'ComputeSharp.Descriptors.IComputeShaderDescriptor<MultiplyByTwo>'.
Through the internet and the description of the
GeneratedComputeShaderDescriptorAttribute
I found out that this is probably due to theGraphicsDevice.Run
method expecting a T where T has anIComputeShaderDescriptor
which apparently my struct doesn't have despite theGeneratedComputeShaderDescriptorAttribute
specified above it.Reproduction Steps
public class Program { public static void Main(string[] args) { int[] array = [.. Enumerable.Range(1, 100)];
}
[ThreadGroupSize(DefaultThreadGroupSizes.X)] [GeneratedComputeShaderDescriptor] public readonly partial struct MultiplyByTwo(ReadWriteBuffer buffer) : IComputeShader
{
public void Execute()
{
buffer[ThreadIds.X] *= 2;
}
}