gpu: implement Queue.writeTexture
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
67a0f60a68
commit
991c88d851
3 changed files with 63 additions and 4 deletions
|
|
@ -920,6 +920,31 @@ const queue_vtable = Queue.VTable{
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}).writeBuffer,
|
}).writeBuffer,
|
||||||
|
.writeTexture = (struct {
|
||||||
|
pub fn writeTexture(
|
||||||
|
ptr: *anyopaque,
|
||||||
|
destination: *const ImageCopyTexture,
|
||||||
|
data: *const anyopaque,
|
||||||
|
data_size: usize,
|
||||||
|
data_layout: *const Texture.DataLayout,
|
||||||
|
write_size: *const Extent3D,
|
||||||
|
) void {
|
||||||
|
c.wgpuQueueWriteTexture(
|
||||||
|
@ptrCast(c.WGPUQueue, ptr),
|
||||||
|
&c.WGPUImageCopyTexture{
|
||||||
|
.nextInChain = null,
|
||||||
|
.texture = @ptrCast(c.WGPUTexture, destination.texture.ptr),
|
||||||
|
.mipLevel = destination.mip_level,
|
||||||
|
.origin = @bitCast(c.WGPUOrigin3D, destination.origin),
|
||||||
|
.aspect = @bitCast(c.WGPUTextureAspect, destination.aspect),
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
data_size,
|
||||||
|
@ptrCast(*const c.WGPUTextureDataLayout, data_layout),
|
||||||
|
@ptrCast(*const c.WGPUExtent3D, write_size),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}).writeTexture,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn wrapShaderModule(shader_module: c.WGPUShaderModule) ShaderModule {
|
fn wrapShaderModule(shader_module: c.WGPUShaderModule) ShaderModule {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
const ImageCopyTexture = @import("structs.zig").ImageCopyTexture;
|
||||||
|
const Extent3D = @import("data.zig").Extent3D;
|
||||||
const CommandBuffer = @import("CommandBuffer.zig");
|
const CommandBuffer = @import("CommandBuffer.zig");
|
||||||
const Buffer = @import("Buffer.zig");
|
const Buffer = @import("Buffer.zig");
|
||||||
|
const Texture = @import("Texture.zig");
|
||||||
|
|
||||||
const Queue = @This();
|
const Queue = @This();
|
||||||
|
|
||||||
|
|
@ -18,9 +21,21 @@ pub const VTable = struct {
|
||||||
// TODO: dawn specific?
|
// TODO: dawn specific?
|
||||||
// copyTextureForBrowser: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D, options: *const CopyTextureForBrowserOptions) void,
|
// copyTextureForBrowser: fn (ptr: *anyopaque, source: *const ImageCopyTexture, destination: *const ImageCopyTexture, copy_size: *const Extent3D, options: *const CopyTextureForBrowserOptions) void,
|
||||||
submit: fn (queue: Queue, commands: []const CommandBuffer) void,
|
submit: fn (queue: Queue, commands: []const CommandBuffer) void,
|
||||||
writeBuffer: fn (ptr: *anyopaque, buffer: Buffer, buffer_offset: u64, data: *const anyopaque, size: u64) void,
|
writeBuffer: fn (
|
||||||
// TODO(implement):
|
ptr: *anyopaque,
|
||||||
// writeTexture: fn (ptr: *anyopaque, destination: *const ImageCopyTexture, data: *const anyopaque, data_size: usize, data_layout: *const TextureDataLayout, write_size: *const Extent3D);
|
buffer: Buffer,
|
||||||
|
buffer_offset: u64,
|
||||||
|
data: *const anyopaque,
|
||||||
|
size: u64,
|
||||||
|
) void,
|
||||||
|
writeTexture: fn (
|
||||||
|
ptr: *anyopaque,
|
||||||
|
destination: *const ImageCopyTexture,
|
||||||
|
data: *const anyopaque,
|
||||||
|
data_size: usize,
|
||||||
|
data_layout: *const Texture.DataLayout,
|
||||||
|
write_size: *const Extent3D,
|
||||||
|
) void,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub inline fn reference(queue: Queue) void {
|
pub inline fn reference(queue: Queue) void {
|
||||||
|
|
@ -45,6 +60,23 @@ pub inline fn writeBuffer(queue: Queue, buffer: Buffer, buffer_offset: u64, data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub inline fn writeTexture(
|
||||||
|
queue: Queue,
|
||||||
|
destination: *const ImageCopyTexture,
|
||||||
|
data: anytype,
|
||||||
|
data_layout: *const Texture.DataLayout,
|
||||||
|
write_size: *const Extent3D,
|
||||||
|
) void {
|
||||||
|
queue.vtable.writeTexture(
|
||||||
|
queue.ptr,
|
||||||
|
destination,
|
||||||
|
@ptrCast(*const anyopaque, &data[0]),
|
||||||
|
@intCast(u64, data.len) * @sizeOf(@TypeOf(std.meta.Elem(data))),
|
||||||
|
data_layout,
|
||||||
|
write_size,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub const WorkDoneCallback = struct {
|
pub const WorkDoneCallback = struct {
|
||||||
type_erased_ctx: *anyopaque,
|
type_erased_ctx: *anyopaque,
|
||||||
type_erased_callback: fn (ctx: *anyopaque, status: WorkDoneStatus) callconv(.Inline) void,
|
type_erased_callback: fn (ctx: *anyopaque, status: WorkDoneStatus) callconv(.Inline) void,
|
||||||
|
|
@ -81,6 +113,7 @@ test {
|
||||||
_ = release;
|
_ = release;
|
||||||
_ = submit;
|
_ = submit;
|
||||||
_ = writeBuffer;
|
_ = writeBuffer;
|
||||||
|
_ = writeTexture;
|
||||||
_ = WorkDoneCallback;
|
_ = WorkDoneCallback;
|
||||||
_ = WorkDoneStatus;
|
_ = WorkDoneStatus;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,8 @@ pub const BindingLayout = extern struct {
|
||||||
multisampled: bool,
|
multisampled: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DataLayout = struct {
|
pub const DataLayout = extern struct {
|
||||||
|
reserved: ?*anyopaque = null,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
bytes_per_row: u32,
|
bytes_per_row: u32,
|
||||||
rows_per_image: u32,
|
rows_per_image: u32,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue