diff --git a/gpu/src/CommandEncoder.zig b/gpu/src/CommandEncoder.zig index 26205bd7..845c0233 100644 --- a/gpu/src/CommandEncoder.zig +++ b/gpu/src/CommandEncoder.zig @@ -3,6 +3,9 @@ const RenderPassEncoder = @import("RenderPassEncoder.zig"); const CommandBuffer = @import("CommandBuffer.zig"); const QuerySet = @import("QuerySet.zig"); const Buffer = @import("Buffer.zig"); +const ImageCopyBuffer = @import("structs.zig").ImageCopyBuffer; +const ImageCopyTexture = @import("structs.zig").ImageCopyTexture; +const Extent3D = @import("data.zig").Extent3D; const CommandEncoder = @This(); @@ -18,11 +21,10 @@ pub const VTable = struct { beginRenderPass: fn (ptr: *anyopaque, descriptor: *const RenderPassEncoder.Descriptor) RenderPassEncoder, 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: Extent3D) void, - // WGPU_EXPORT void wgpuCommandEncoderCopyBufferToTexture(WGPUCommandEncoder commandEncoder, WGPUImageCopyBuffer const * source, WGPUImageCopyTexture const * destination, WGPUExtent3D const * copySize); - // copyTextureToBuffer: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyBuffer, copy_size: Extent3D) 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); - // copyTextureToTexture: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: 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, // injectValidationError: fn (ptr: *anyopaque, message: [*:0]const u8) void, @@ -69,6 +71,15 @@ pub inline fn copyBufferToBuffer( enc.vtable.copyBufferToBuffer(enc.ptr, source, source_offset, destination, destination_offset, size); } +pub inline fn copyBufferToTexture( + enc: CommandEncoder, + source: *const ImageCopyBuffer, + destination: *const ImageCopyTexture, + copy_size: *const Extent3D, +) void { + enc.vtable.copyBufferToTexture(enc.ptr, source, destination, copy_size); +} + pub inline fn finish(enc: CommandEncoder, descriptor: ?*const CommandBuffer.Descriptor) CommandBuffer { return enc.vtable.finish(enc.ptr, descriptor); } @@ -105,6 +116,7 @@ test { _ = beginRenderPass; _ = clearBuffer; _ = copyBufferToBuffer; + _ = copyBufferToTexture; _ = finish; _ = insertDebugMarker; _ = popDebugGroup; diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index ed61535e..4bd40346 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -15,10 +15,12 @@ const RequestDeviceError = Adapter.RequestDeviceError; const RequestDeviceCallback = Adapter.RequestDeviceCallback; const RequestDeviceResponse = Adapter.RequestDeviceResponse; -const Device = @import("Device.zig"); -const Surface = @import("Surface.zig"); const Limits = @import("data.zig").Limits; const Color = @import("data.zig").Color; +const Extent3D = @import("data.zig").Extent3D; + +const Device = @import("Device.zig"); +const Surface = @import("Surface.zig"); const Queue = @import("Queue.zig"); const CommandBuffer = @import("CommandBuffer.zig"); const ShaderModule = @import("ShaderModule.zig"); @@ -43,6 +45,9 @@ const ComputePipeline = @import("ComputePipeline.zig"); const PresentMode = @import("enums.zig").PresentMode; const IndexFormat = @import("enums.zig").IndexFormat; +const ImageCopyBuffer = @import("structs.zig").ImageCopyBuffer; +const ImageCopyTexture = @import("structs.zig").ImageCopyTexture; + const NativeInstance = @This(); /// The WGPUInstance that is wrapped by this native instance. @@ -1634,6 +1639,21 @@ const command_encoder_vtable = CommandEncoder.VTable{ ); } }).copyBufferToBuffer, + .copyBufferToTexture = (struct { + pub fn copyBufferToTexture( + ptr: *anyopaque, + source: *const ImageCopyBuffer, + destination: *const ImageCopyTexture, + copy_size: *const Extent3D, + ) void { + c.wgpuCommandEncoderCopyBufferToTexture( + @ptrCast(c.WGPUCommandEncoder, ptr), + &convertImageCopyBuffer(source), + &convertImageCopyTexture(destination), + @ptrCast(*const c.WGPUExtent3D, copy_size), + ); + } + }).copyBufferToTexture, .popDebugGroup = (struct { pub fn popDebugGroup(ptr: *anyopaque) void { c.wgpuCommandEncoderPopDebugGroup(@ptrCast(c.WGPUCommandEncoder, ptr)); @@ -1655,6 +1675,33 @@ const command_encoder_vtable = CommandEncoder.VTable{ }).writeTimestamp, }; +inline fn convertImageCopyBuffer(v: *const ImageCopyBuffer) c.WGPUImageCopyBuffer { + return .{ + .nextInChain = null, + .layout = convertTextureDataLayout(v.layout), + .buffer = @ptrCast(c.WGPUBuffer, v.buffer.ptr), + }; +} + +inline fn convertImageCopyTexture(v: *const ImageCopyTexture) c.WGPUImageCopyTexture { + return .{ + .nextInChain = null, + .texture = @ptrCast(c.WGPUTexture, v.texture.ptr), + .mipLevel = v.mip_level, + .origin = @bitCast(c.WGPUOrigin3D, v.origin), + .aspect = @enumToInt(v.aspect), + }; +} + +inline fn convertTextureDataLayout(v: Texture.DataLayout) c.WGPUTextureDataLayout { + return .{ + .nextInChain = null, + .offset = v.offset, + .bytesPerRow = v.bytes_per_row, + .rowsPerImage = v.rows_per_image, + }; +} + fn wrapComputePassEncoder(enc: c.WGPUComputePassEncoder) ComputePassEncoder { return .{ .ptr = enc.?,