MoonWorks/src/Graphics/Resources/ComputePipeline.cs

41 lines
971 B
C#
Raw Normal View History

2024-06-05 00:24:25 +00:00
using SDL2_gpuCS;
using System;
namespace MoonWorks.Graphics
{
2023-09-19 20:19:41 +00:00
/// <summary>
/// Compute pipelines perform arbitrary parallel processing on input data.
/// </summary>
2024-06-04 19:19:41 +00:00
public class ComputePipeline : SDL_GpuResource
2022-02-23 05:14:32 +00:00
{
2024-06-05 00:24:25 +00:00
protected override Action<IntPtr, IntPtr> ReleaseFunction => SDL_Gpu.SDL_GpuReleaseComputePipeline;
2024-06-05 00:24:25 +00:00
public ComputePipelineResourceInfo ResourceInfo { get; }
2022-02-23 05:14:32 +00:00
public unsafe ComputePipeline(
GraphicsDevice device,
2024-06-05 00:24:25 +00:00
Shader computeShader,
ComputePipelineResourceInfo resourceInfo
2022-02-23 05:14:32 +00:00
) : base(device)
{
2024-06-05 00:24:25 +00:00
var sdlComputePipelineCreateInfo = new SDL_Gpu.ComputePipelineCreateInfo
2022-02-23 05:14:32 +00:00
{
2024-06-05 00:24:25 +00:00
ComputeShader = computeShader.Handle,
PipelineResourceInfo = resourceInfo.ToSDL()
2022-02-23 05:14:32 +00:00
};
2024-06-05 00:24:25 +00:00
Handle = SDL_Gpu.SDL_GpuCreateComputePipeline(
2022-02-23 05:14:32 +00:00
device.Handle,
2024-06-05 00:24:25 +00:00
sdlComputePipelineCreateInfo
2022-02-23 05:14:32 +00:00
);
2024-06-05 00:24:25 +00:00
if (Handle == IntPtr.Zero)
{
throw new Exception("Could not create compute pipeline!");
}
2024-06-05 00:24:25 +00:00
ResourceInfo = resourceInfo;
2022-02-23 05:14:32 +00:00
}
}
}