gpu: convert Texture.Usage to packed struct
This commit is contained in:
parent
adf5332969
commit
614322edc7
4 changed files with 35 additions and 14 deletions
|
|
@ -504,7 +504,7 @@ const device_vtable = Device.VTable{
|
||||||
const desc = c.WGPUSwapChainDescriptor{
|
const desc = c.WGPUSwapChainDescriptor{
|
||||||
.nextInChain = null,
|
.nextInChain = null,
|
||||||
.label = if (descriptor.label) |l| l else null,
|
.label = if (descriptor.label) |l| l else null,
|
||||||
.usage = @enumToInt(descriptor.usage),
|
.usage = @bitCast(u32, descriptor.usage),
|
||||||
.format = @enumToInt(descriptor.format),
|
.format = @enumToInt(descriptor.format),
|
||||||
.width = descriptor.width,
|
.width = descriptor.width,
|
||||||
.height = descriptor.height,
|
.height = descriptor.height,
|
||||||
|
|
@ -1017,7 +1017,7 @@ const swap_chain_vtable = SwapChain.VTable{
|
||||||
c.wgpuSwapChainConfigure(
|
c.wgpuSwapChainConfigure(
|
||||||
@ptrCast(c.WGPUSwapChain, ptr),
|
@ptrCast(c.WGPUSwapChain, ptr),
|
||||||
@enumToInt(format),
|
@enumToInt(format),
|
||||||
@enumToInt(allowed_usage),
|
@bitCast(u32, allowed_usage),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ pub const Descriptor = struct {
|
||||||
pub fn equal(a: *const Descriptor, b: *const Descriptor) bool {
|
pub fn equal(a: *const Descriptor, b: *const Descriptor) bool {
|
||||||
if ((a.label == null) != (b.label == null)) return false;
|
if ((a.label == null) != (b.label == null)) return false;
|
||||||
if (a.label != null and !std.mem.eql(u8, a.label.?, b.label.?)) return false;
|
if (a.label != null and !std.mem.eql(u8, a.label.?, b.label.?)) return false;
|
||||||
if (a.usage != b.usage) return false;
|
if (!a.usage.equal(b.usage)) return false;
|
||||||
if (a.format != b.format) return false;
|
if (a.format != b.format) return false;
|
||||||
if (a.width != b.width) return false;
|
if (a.width != b.width) return false;
|
||||||
if (a.height != b.height) return false;
|
if (a.height != b.height) return false;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
const Extent3D = @import("data.zig").Extent3D;
|
const Extent3D = @import("data.zig").Extent3D;
|
||||||
|
|
||||||
const TextureView = @import("TextureView.zig");
|
const TextureView = @import("TextureView.zig");
|
||||||
|
|
@ -48,14 +50,33 @@ pub const Descriptor = struct {
|
||||||
sample_count: u32,
|
sample_count: u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Usage = enum(u32) {
|
pub const Usage = packed struct {
|
||||||
none = 0x00000000,
|
copy_src: bool = false,
|
||||||
copy_src = 0x00000001,
|
copy_dst: bool = false,
|
||||||
copy_dst = 0x00000002,
|
texture_binding: bool = false,
|
||||||
texture_binding = 0x00000004,
|
storage_binding: bool = false,
|
||||||
storage_binding = 0x00000008,
|
render_attachment: bool = false,
|
||||||
render_attachment = 0x00000010,
|
present: bool = false,
|
||||||
present = 0x00000020,
|
|
||||||
|
_pad0: u2 = 0,
|
||||||
|
_pad1: u8 = 0,
|
||||||
|
_pad2: u16 = 0,
|
||||||
|
|
||||||
|
comptime {
|
||||||
|
std.debug.assert(
|
||||||
|
@sizeOf(@This()) == @sizeOf(u32) and
|
||||||
|
@bitSizeOf(@This()) == @bitSizeOf(u32),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn equal(a: Usage, b: Usage) bool {
|
||||||
|
return a.copy_src == b.copy_src and
|
||||||
|
a.copy_dst == b.copy_dst and
|
||||||
|
a.texture_binding == b.texture_binding and
|
||||||
|
a.storage_binding == b.storage_binding and
|
||||||
|
a.render_attachment == b.render_attachment and
|
||||||
|
a.present == b.present;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Format = enum(u32) {
|
pub const Format = enum(u32) {
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ pub fn App(comptime Context: type, comptime config: AppConfig) type {
|
||||||
swap_chain_format = .bgra8_unorm;
|
swap_chain_format = .bgra8_unorm;
|
||||||
descriptor = .{
|
descriptor = .{
|
||||||
.label = "basic swap chain",
|
.label = "basic swap chain",
|
||||||
.usage = .render_attachment,
|
.usage = .{ .render_attachment = true },
|
||||||
.format = swap_chain_format,
|
.format = swap_chain_format,
|
||||||
.width = framebuffer_size.width,
|
.width = framebuffer_size.width,
|
||||||
.height = framebuffer_size.height,
|
.height = framebuffer_size.height,
|
||||||
|
|
@ -174,7 +174,7 @@ pub fn App(comptime Context: type, comptime config: AppConfig) type {
|
||||||
swap_chain_format = @intToEnum(gpu.Texture.Format, @intCast(u32, c.machUtilsBackendBinding_getPreferredSwapChainTextureFormat(binding)));
|
swap_chain_format = @intToEnum(gpu.Texture.Format, @intCast(u32, c.machUtilsBackendBinding_getPreferredSwapChainTextureFormat(binding)));
|
||||||
swap_chain.?.configure(
|
swap_chain.?.configure(
|
||||||
swap_chain_format,
|
swap_chain_format,
|
||||||
.render_attachment,
|
.{ .render_attachment = true },
|
||||||
framebuffer_size.width,
|
framebuffer_size.width,
|
||||||
framebuffer_size.height,
|
framebuffer_size.height,
|
||||||
);
|
);
|
||||||
|
|
@ -221,7 +221,7 @@ pub fn App(comptime Context: type, comptime config: AppConfig) type {
|
||||||
app.swap_chain = app.device.nativeCreateSwapChain(app.surface, &app.target_desc);
|
app.swap_chain = app.device.nativeCreateSwapChain(app.surface, &app.target_desc);
|
||||||
} else app.swap_chain.?.configure(
|
} else app.swap_chain.?.configure(
|
||||||
app.swap_chain_format,
|
app.swap_chain_format,
|
||||||
.render_attachment,
|
.{ .render_attachment = true },
|
||||||
app.target_desc.width,
|
app.target_desc.width,
|
||||||
app.target_desc.height,
|
app.target_desc.height,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue