From 72d9a325fe6c073cfb241c671ec15aff1d138c96 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 11 Jul 2022 08:59:11 -0700 Subject: [PATCH] gpu: add ShaderStage flagset Signed-off-by: Stephen Gutekanst --- gpu/TODO-webgpu.h | 9 --------- gpu/src/types.zig | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gpu/TODO-webgpu.h b/gpu/TODO-webgpu.h index 25ac186e..232b59bd 100644 --- a/gpu/TODO-webgpu.h +++ b/gpu/TODO-webgpu.h @@ -1,14 +1,5 @@ typedef uint32_t WGPUFlags; -typedef enum WGPUShaderStage { - WGPUShaderStage_None = 0x00000000, - WGPUShaderStage_Vertex = 0x00000001, - WGPUShaderStage_Fragment = 0x00000002, - WGPUShaderStage_Compute = 0x00000004, - WGPUShaderStage_Force32 = 0x7FFFFFFF -} WGPUShaderStage; -typedef WGPUFlags WGPUShaderStageFlags; - typedef enum WGPUTextureUsage { WGPUTextureUsage_None = 0x00000000, WGPUTextureUsage_CopySrc = 0x00000001, diff --git a/gpu/src/types.zig b/gpu/src/types.zig index 422f59f4..eb54119e 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -338,11 +338,32 @@ pub const MapMode = packed struct { pub const undef = MapMode{}; - pub fn equal(a: ColorWriteMask, b: ColorWriteMask) bool { + pub fn equal(a: MapMode, b: MapMode) bool { return @truncate(u2, @bitCast(u32, a)) == @truncate(u2, @bitCast(u32, b)); } }; +pub const ShaderStage = packed struct { + vertex: bool = false, + fragment: bool = false, + compute: bool = false, + + _padding: u29 = 0, + + comptime { + std.debug.assert( + @sizeOf(@This()) == @sizeOf(u32) and + @bitSizeOf(@This()) == @bitSizeOf(u32), + ); + } + + pub const none = ShaderStage{}; + + pub fn equal(a: ShaderStage, b: ShaderStage) bool { + return @truncate(u3, @bitCast(u32, a)) == @truncate(u3, @bitCast(u32, b)); + } +}; + test "BackendType name" { try testing.expectEqualStrings("Vulkan", BackendType.vulkan.name()); }