From de9cc72c47beea93a679379ca358b194481ec764 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Thu, 17 Mar 2022 11:39:59 -0700 Subject: [PATCH] gpu: implement CommandEncoder.copyTextureToBuffer Signed-off-by: Stephen Gutekanst --- gpu/src/CommandEncoder.zig | 13 +++++++++++-- gpu/src/NativeInstance.zig | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gpu/src/CommandEncoder.zig b/gpu/src/CommandEncoder.zig index 845c0233..6fa3b2b2 100644 --- a/gpu/src/CommandEncoder.zig +++ b/gpu/src/CommandEncoder.zig @@ -22,8 +22,7 @@ pub const VTable = struct { clearBuffer: fn (ptr: *anyopaque, buffer: Buffer, offset: u64, size: u64) void, copyBufferToBuffer: fn (ptr: *anyopaque, source: Buffer, source_offset: u64, destination: Buffer, destination_offset: u64, size: u64) void, copyBufferToTexture: fn (ptr: *anyopaque, source: *const ImageCopyBuffer, destination: *const ImageCopyTexture, copy_size: *const Extent3D) void, - // copyTextureToBuffer: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyBuffer, copy_size: *const Extent3D) void, - // WGPU_EXPORT void wgpuCommandEncoderCopyTextureToBuffer(WGPUCommandEncoder commandEncoder, WGPUImageCopyTexture const * source, WGPUImageCopyBuffer const * destination, WGPUExtent3D const * copySize); + copyTextureToBuffer: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyBuffer, copy_size: *const Extent3D) void, // copyTextureToTexture: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D) void, // WGPU_EXPORT void wgpuCommandEncoderCopyTextureToTexture(WGPUCommandEncoder commandEncoder, WGPUImageCopyTexture const * source, WGPUImageCopyTexture const * destination, WGPUExtent3D const * copySize); finish: fn (ptr: *anyopaque, descriptor: ?*const CommandBuffer.Descriptor) CommandBuffer, @@ -80,6 +79,15 @@ pub inline fn copyBufferToTexture( enc.vtable.copyBufferToTexture(enc.ptr, source, destination, copy_size); } +pub inline fn copyTextureToBuffer( + enc: CommandEncoder, + source: *const ImageCopyTexture, + destination: *const ImageCopyBuffer, + copy_size: *const Extent3D, +) void { + enc.vtable.copyTextureToBuffer(enc.ptr, source, destination, copy_size); +} + pub inline fn finish(enc: CommandEncoder, descriptor: ?*const CommandBuffer.Descriptor) CommandBuffer { return enc.vtable.finish(enc.ptr, descriptor); } @@ -117,6 +125,7 @@ test { _ = clearBuffer; _ = copyBufferToBuffer; _ = copyBufferToTexture; + _ = copyTextureToBuffer; _ = finish; _ = insertDebugMarker; _ = popDebugGroup; diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 4bd40346..33eb84ef 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -1654,6 +1654,21 @@ const command_encoder_vtable = CommandEncoder.VTable{ ); } }).copyBufferToTexture, + .copyTextureToBuffer = (struct { + pub fn copyTextureToBuffer( + ptr: *anyopaque, + source: *const ImageCopyTexture, + destination: *const ImageCopyBuffer, + copy_size: *const Extent3D, + ) void { + c.wgpuCommandEncoderCopyTextureToBuffer( + @ptrCast(c.WGPUCommandEncoder, ptr), + &convertImageCopyTexture(source), + &convertImageCopyBuffer(destination), + @ptrCast(*const c.WGPUExtent3D, copy_size), + ); + } + }).copyTextureToBuffer, .popDebugGroup = (struct { pub fn popDebugGroup(ptr: *anyopaque) void { c.wgpuCommandEncoderPopDebugGroup(@ptrCast(c.WGPUCommandEncoder, ptr));