C#C
C#3y ago
Garf

❔ Using ComputeSharp with Veldrid?

Want to use ComputeSharp (turns C# into GPU shader code, basically) with Veldrid (a low level graphics API for C#) but I'm not sure how.

ComputeSharp can create precompiled shaders which I hope I can then use with Veldrid to simplify making shaders but I just have no idea how.


This is how you usually define shaders in Veldrid
ShaderDescription vertexShaderDesc = new ShaderDescription(
    ShaderStages.Vertex,
    Encoding.UTF8.GetBytes(VertexCode),
    "main");
ShaderDescription fragmentShaderDesc = new ShaderDescription(
    ShaderStages.Fragment,
    Encoding.UTF8.GetBytes(FragmentCode),
    "main");


and ComputeSharp 'shaders' look something like this

using ComputeSharp;
[AutoConstructor]
[EmbeddedBytecode(8, 8, 1)]
public readonly partial struct TestShader : IPixelShader<float4>
{
    public float4 Execute()
    {
        float2 uv = ThreadIds.Normalized.XY;
        float3 col = 0.5f + 0.5f * Hlsl.Cos(new float3(uv, uv.X) + new float3(0, 2, 4));

        return new(col, 1f);
    }
}


Does anyone know if this is possible?
Was this page helpful?