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.65k stars 122 forks source link

From AnimatedComputeShaderPanel to ComputeShaderPanel in WinUI 3 #782

Open diluculo opened 3 months ago

diluculo commented 3 months ago

I'm currently working on visualizing voltage distribution in a WinUI 3 app. Currently, I'm using AnimatedComputeShaderPanel of ComputeSharp v2.0.3, but I'd like to migrate to ComputeShaderPanel since the calculation at each pixel coordinate isn't actually time-dependent.

My first question is whether ComputeShaderPanel is suitable for static visualization tasks. If so, I would like to know whether it can help reduce the GPU load.

Here's the code snippet using AnimatedComputeShaderPanel:

<computesharp:AnimatedComputeShaderPanel x:Name="ShaderLayer"/>

And in the code-behind, I'm setting up AnimatedComputeShaderPanel like this:

ShaderLayer.ShaderRunner = new ShaderRunner<Heatmap>(t => new Heatmap(settings, ... ));

The shader Heatmap is

    [EmbeddedBytecode(DispatchAxis.XY)]
    [AutoConstructor]
    public readonly partial struct Heatmap : IPixelShader<float4>
    {
        [AutoConstructor]
        public readonly partial struct Settings
        {
            public readonly Bool isDarkTheme;
            public readonly Bool renderingAxisLines;
            // other properties...
        }       

        // other settings and private methods...

        public float4 Execute()
        { 
            // Shader execution logic...
        }
    ));

When attempting to switch to ComputeShaderPanel in XAML, however, I encountered no rendering result.

Could you guide me on how to accomplish this task? Thank you.