diff --git a/gpu/src/ExternalTexture.zig b/gpu/src/ExternalTexture.zig new file mode 100644 index 00000000..0b21dbc0 --- /dev/null +++ b/gpu/src/ExternalTexture.zig @@ -0,0 +1,28 @@ +const ExternalTexture = @This(); + +/// The type erased pointer to the ExternalTexture implementation +/// Equal to c.WGPUExternalTexture for NativeInstance. +ptr: *anyopaque, +vtable: *const VTable, + +pub const VTable = struct { + reference: fn (ptr: *anyopaque) void, + release: fn (ptr: *anyopaque) void, + // TODO: + // WGPU_EXPORT void wgpuExternalTextureDestroy(WGPUExternalTexture externalTexture); + // WGPU_EXPORT void wgpuExternalTextureSetLabel(WGPUExternalTexture externalTexture, char const * label); +}; + +pub inline fn reference(texture: ExternalTexture) void { + texture.vtable.reference(texture.ptr); +} + +pub inline fn release(texture: ExternalTexture) void { + texture.vtable.release(texture.ptr); +} + +test "syntax" { + _ = VTable; + _ = reference; + _ = release; +} diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 10405cd3..12d9ad54 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -29,6 +29,7 @@ const RenderBundleEncoder = @import("RenderBundleEncoder.zig"); const RenderBundle = @import("RenderBundle.zig"); const QuerySet = @import("QuerySet.zig"); const PipelineLayout = @import("PipelineLayout.zig"); +const ExternalTexture = @import("ExternalTexture.zig"); const TextureUsage = @import("enums.zig").TextureUsage; const TextureFormat = @import("enums.zig").TextureFormat; @@ -686,6 +687,26 @@ const pipeline_layout_vtable = PipelineLayout.VTable{ }).release, }; +fn wrapExternalTexture(texture: c.WGPUExternalTexture) ExternalTexture { + return .{ + .ptr = texture.?, + .vtable = &external_texture_vtable, + }; +} + +const external_texture_vtable = ExternalTexture.VTable{ + .reference = (struct { + pub fn reference(ptr: *anyopaque) void { + c.wgpuExternalTextureReference(@ptrCast(c.WGPUExternalTexture, ptr)); + } + }).reference, + .release = (struct { + pub fn release(ptr: *anyopaque) void { + c.wgpuExternalTextureRelease(@ptrCast(c.WGPUExternalTexture, ptr)); + } + }).release, +}; + test "syntax" { _ = wrap; _ = interface_vtable; @@ -708,4 +729,5 @@ test "syntax" { _ = wrapRenderBundle; _ = wrapQuerySet; _ = wrapPipelineLayout; + _ = wrapExternalTexture; } diff --git a/gpu/src/TODO b/gpu/src/TODO index cf8673b9..2d49a32a 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -593,17 +593,6 @@ WGPU_EXPORT void wgpuComputePipelineSetLabel(WGPUComputePipeline computePipeline WGPU_EXPORT void wgpuComputePipelineReference(WGPUComputePipeline computePipeline); WGPU_EXPORT void wgpuComputePipelineRelease(WGPUComputePipeline computePipeline); -// Methods of ExternalTexture -WGPU_EXPORT void wgpuExternalTextureDestroy(WGPUExternalTexture externalTexture); -WGPU_EXPORT void wgpuExternalTextureSetLabel(WGPUExternalTexture externalTexture, char const * label); -WGPU_EXPORT void wgpuExternalTextureReference(WGPUExternalTexture externalTexture); -WGPU_EXPORT void wgpuExternalTextureRelease(WGPUExternalTexture externalTexture); - -// Methods of PipelineLayout -WGPU_EXPORT void wgpuPipelineLayoutSetLabel(WGPUPipelineLayout pipelineLayout, char const * label); -WGPU_EXPORT void wgpuPipelineLayoutReference(WGPUPipelineLayout pipelineLayout); -WGPU_EXPORT void wgpuPipelineLayoutRelease(WGPUPipelineLayout pipelineLayout); - typedef enum WGPUSType { // webgpu.h upstream: WGPUSType_Invalid = 0x00000000, diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 15a6b1be..d5d94225 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -44,6 +44,7 @@ pub const RenderBundleEncoder = @import("RenderBundleEncoder.zig"); pub const RenderBundle = @import("RenderBundle.zig"); pub const QuerySet = @import("QuerySet.zig"); pub const PipelineLayout = @import("PipelineLayout.zig"); +pub const ExternalTexture = @import("ExternalTexture.zig"); pub const Feature = @import("enums.zig").Feature; pub const TextureUsage = @import("enums.zig").TextureUsage; @@ -112,6 +113,7 @@ test "syntax" { _ = RenderBundle; _ = QuerySet; _ = PipelineLayout; + _ = ExternalTexture; _ = Feature; }