gpu: implement RenderPipeline

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-09 11:57:49 -07:00 committed by Stephen Gutekanst
parent b29fa9e13d
commit 8684195e19
4 changed files with 52 additions and 11 deletions

View file

@ -23,6 +23,7 @@ const SwapChain = @import("SwapChain.zig");
const TextureView = @import("TextureView.zig"); const TextureView = @import("TextureView.zig");
const Texture = @import("Texture.zig"); const Texture = @import("Texture.zig");
const Sampler = @import("Sampler.zig"); const Sampler = @import("Sampler.zig");
const RenderPipeline = @import("RenderPipeline.zig");
const TextureUsage = @import("enums.zig").TextureUsage; const TextureUsage = @import("enums.zig").TextureUsage;
const TextureFormat = @import("enums.zig").TextureFormat; const TextureFormat = @import("enums.zig").TextureFormat;
@ -560,6 +561,26 @@ const sampler_vtable = Sampler.VTable{
}).release, }).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" { test "syntax" {
_ = wrap; _ = wrap;
_ = interface_vtable; _ = interface_vtable;
@ -576,4 +597,5 @@ test "syntax" {
_ = wrapTextureView; _ = wrapTextureView;
_ = wrapTexture; _ = wrapTexture;
_ = wrapSampler; _ = wrapSampler;
_ = wrapRenderPipeline;
} }

View file

@ -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;
}

View file

@ -657,17 +657,6 @@ WGPU_EXPORT void wgpuRenderPassEncoderWriteTimestamp(WGPURenderPassEncoder rende
WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder); WGPU_EXPORT void wgpuRenderPassEncoderReference(WGPURenderPassEncoder renderPassEncoder);
WGPU_EXPORT void wgpuRenderPassEncoderRelease(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 { typedef enum WGPUSType {
// webgpu.h upstream: // webgpu.h upstream:
WGPUSType_Invalid = 0x00000000, WGPUSType_Invalid = 0x00000000,

View file

@ -38,6 +38,7 @@ pub const SwapChain = @import("SwapChain.zig");
pub const TextureView = @import("TextureView.zig"); pub const TextureView = @import("TextureView.zig");
pub const Texture = @import("Texture.zig"); pub const Texture = @import("Texture.zig");
pub const Sampler = @import("Sampler.zig"); pub const Sampler = @import("Sampler.zig");
pub const RenderPipeline = @import("RenderPipeline.zig");
pub const Feature = @import("enums.zig").Feature; pub const Feature = @import("enums.zig").Feature;
pub const TextureUsage = @import("enums.zig").TextureUsage; pub const TextureUsage = @import("enums.zig").TextureUsage;
@ -100,6 +101,7 @@ test "syntax" {
_ = TextureView; _ = TextureView;
_ = Texture; _ = Texture;
_ = Sampler; _ = Sampler;
_ = RenderPipeline;
_ = Feature; _ = Feature;
} }