const std = @import("std");
const GpuDevice = @import("GpuDevice.zig");
const c = @import("utils.zig").c;
const sv = @import("utils.zig").sv;

raw: c.WGPUComputePipeline,

pub fn init(device: GpuDevice, wgsl: []const u8) !@This() {
    var wgsl_src = c.WGPUShaderSourceWGSL{
        .chain = .{ .sType = c.WGPUSType_ShaderSourceWGSL },
        .code = sv(wgsl),
    };
    const shader = c.wgpuDeviceCreateShaderModule(device.device, &.{
        .nextInChain = @ptrCast(&wgsl_src),
    }) orelse return error.Shader;
    defer c.wgpuShaderModuleRelease(shader);

    return .{ .raw = c.wgpuDeviceCreateComputePipeline(device.device, &.{
        .compute = .{ .module = shader, .entryPoint = sv("main") },
    }) orelse return error.Pipeline };
}

pub fn deinit(self: @This()) void {
    c.wgpuComputePipelineRelease(self.raw);
}
