diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 3d351f23..89fd01f0 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -23,6 +23,7 @@ const SwapChain = @import("SwapChain.zig"); const TextureView = @import("TextureView.zig"); const Texture = @import("Texture.zig"); const Sampler = @import("Sampler.zig"); +const RenderPipeline = @import("RenderPipeline.zig"); const TextureUsage = @import("enums.zig").TextureUsage; const TextureFormat = @import("enums.zig").TextureFormat; @@ -560,6 +561,26 @@ const sampler_vtable = Sampler.VTable{ }).release, }; +fn wrapRenderPipeline(render_pipeline: c.WGPURenderPipeline) RenderPipeline { + return .{ + .ptr = render_pipeline.?, + .vtable = &render_pipeline_vtable, + }; +} + +const render_pipeline_vtable = RenderPipeline.VTable{ + .reference = (struct { + pub fn reference(ptr: *anyopaque) void { + c.wgpuRenderPipelineReference(@ptrCast(c.WGPURenderPipeline, ptr)); + } + }).reference, + .release = (struct { + pub fn release(ptr: *anyopaque) void { + c.wgpuRenderPipelineRelease(@ptrCast(c.WGPURenderPipeline, ptr)); + } + }).release, +}; + test "syntax" { _ = wrap; _ = interface_vtable; @@ -576,4 +597,5 @@ test "syntax" { _ = wrapTextureView; _ = wrapTexture; _ = wrapSampler; + _ = wrapRenderPipeline; } diff --git a/gpu/src/RenderPipeline.zig b/gpu/src/RenderPipeline.zig new file mode 100644 index 00000000..37d4ce34 --- /dev/null +++ b/gpu/src/RenderPipeline.zig @@ -0,0 +1,28 @@ +const RenderPipeline = @This(); + +/// The type erased pointer to the RenderPipeline implementation +/// Equal to c.WGPURenderPipeline for NativeInstance. +ptr: *anyopaque, +vtable: *const VTable, + +pub const VTable = struct { + reference: fn (ptr: *anyopaque) void, + release: fn (ptr: *anyopaque) void, + // TODO: + // WGPU_EXPORT WGPUBindGroupLayout wgpuRenderPipelineGetBindGroupLayout(WGPURenderPipeline renderPipeline, uint32_t groupIndex); + // WGPU_EXPORT void wgpuRenderPipelineSetLabel(WGPURenderPipeline renderPipeline, char const * label); +}; + +pub inline fn reference(pipeline: RenderPipeline) void { + pipeline.vtable.reference(pipeline.ptr); +} + +pub inline fn release(pipeline: RenderPipeline) void { + pipeline.vtable.release(pipeline.ptr); +} + +test "syntax" { + _ = VTable; + _ = reference; + _ = release; +} diff --git a/gpu/src/TODO b/gpu/src/TODO index 053509d9..ca5fbd25 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -657,17 +657,6 @@ WGPU_EXPORT void wgpuRenderPassEncoderWriteTimestamp(WGPURenderPassEncoder rende WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder); WGPU_EXPORT void wgpuRenderPassEncoderRelease(WGPURenderPassEncoder renderPassEncoder); -// Methods of RenderPipeline -WGPU_EXPORT WGPUBindGroupLayout wgpuRenderPipelineGetBindGroupLayout(WGPURenderPipeline renderPipeline, uint32_t groupIndex); -WGPU_EXPORT void wgpuRenderPipelineSetLabel(WGPURenderPipeline renderPipeline, char const * label); -WGPU_EXPORT void wgpuRenderPipelineReference(WGPURenderPipeline renderPipeline); -WGPU_EXPORT void wgpuRenderPipelineRelease(WGPURenderPipeline renderPipeline); - -// Methods of Sampler -WGPU_EXPORT void wgpuSamplerSetLabel(WGPUSampler sampler, char const * label); -WGPU_EXPORT void wgpuSamplerReference(WGPUSampler sampler); -WGPU_EXPORT void wgpuSamplerRelease(WGPUSampler sampler); - typedef enum WGPUSType { // webgpu.h upstream: WGPUSType_Invalid = 0x00000000, diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 3181d44f..af7dc832 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -38,6 +38,7 @@ pub const SwapChain = @import("SwapChain.zig"); pub const TextureView = @import("TextureView.zig"); pub const Texture = @import("Texture.zig"); pub const Sampler = @import("Sampler.zig"); +pub const RenderPipeline = @import("RenderPipeline.zig"); pub const Feature = @import("enums.zig").Feature; pub const TextureUsage = @import("enums.zig").TextureUsage; @@ -100,6 +101,7 @@ test "syntax" { _ = TextureView; _ = Texture; _ = Sampler; + _ = RenderPipeline; _ = Feature; }