gpu: convert Texture from enum(usize) to *opaque

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-24 15:05:16 -07:00 committed by Stephen Gutekanst
parent 7f952545b9
commit c0ad349a12
7 changed files with 202 additions and 197 deletions

View file

@ -5,6 +5,7 @@ const BufferBindingLayout = @import("buffer.zig").BufferBindingLayout;
const Sampler = @import("sampler.zig").Sampler; const Sampler = @import("sampler.zig").Sampler;
const SamplerBindingLayout = @import("sampler.zig").SamplerBindingLayout; const SamplerBindingLayout = @import("sampler.zig").SamplerBindingLayout;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureBindingLayout = @import("texture.zig").TextureBindingLayout;
const StorageTextureBindingLayout = @import("types.zig").StorageTextureBindingLayout; const StorageTextureBindingLayout = @import("types.zig").StorageTextureBindingLayout;
pub const BindGroupLayout = *opaque {}; pub const BindGroupLayout = *opaque {};
@ -15,7 +16,7 @@ pub const BindGroupLayoutEntry = extern struct {
visibility: ShaderStageFlags, visibility: ShaderStageFlags,
buffer: BufferBindingLayout, buffer: BufferBindingLayout,
sampler: SamplerBindingLayout, sampler: SamplerBindingLayout,
texture: Texture.BindingLayout, texture: TextureBindingLayout,
storage_texture: StorageTextureBindingLayout, storage_texture: StorageTextureBindingLayout,
}; };

View file

@ -1,5 +1,6 @@
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureUsageFlags = @import("texture.zig").TextureUsageFlags;
pub const CacheDeviceDescriptor = extern struct { pub const CacheDeviceDescriptor = extern struct {
// TODO: file an issue on Dawn: why not named nextInChain? // TODO: file an issue on Dawn: why not named nextInChain?
@ -21,7 +22,7 @@ pub const InstanceDescriptor = extern struct {
pub const TextureInternalUsageDescriptor = extern struct { pub const TextureInternalUsageDescriptor = extern struct {
chain: ChainedStruct, chain: ChainedStruct,
internal_usage: Texture.UsageFlags, internal_usage: TextureUsageFlags,
}; };
pub const TogglesDeviceDescriptor = extern struct { pub const TogglesDeviceDescriptor = extern struct {

View file

@ -1,5 +1,6 @@
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureFormat = @import("texture.zig").TextureFormat;
pub const RenderBundleEncoder = *opaque {}; pub const RenderBundleEncoder = *opaque {};
@ -7,8 +8,8 @@ pub const RenderBundleEncoderDescriptor = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
color_formats_count: u32, color_formats_count: u32,
color_formats: [*]const Texture.Format, color_formats: [*]const TextureFormat,
depth_stencil_format: Texture.Format, depth_stencil_format: TextureFormat,
sample_count: u32, sample_count: u32,
depth_read_only: bool, depth_read_only: bool,
stencil_read_only: bool, stencil_read_only: bool,

View file

@ -1,14 +1,16 @@
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
const PresentMode = @import("types.zig").PresentMode; const PresentMode = @import("types.zig").PresentMode;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureUsageFlags = @import("texture.zig").TextureUsageFlags;
const TextureFormat = @import("texture.zig").TextureFormat;
pub const SwapChain = *opaque {}; pub const SwapChain = *opaque {};
pub const SwapChainDescriptor = extern struct { pub const SwapChainDescriptor = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
usage: Texture.UsageFlags, usage: TextureUsageFlags,
format: Texture.Format, format: TextureFormat,
width: u32, width: u32,
height: u32, height: u32,
present_mode: PresentMode, present_mode: PresentMode,

View file

@ -4,189 +4,184 @@ const TextureView = @import("texture_view.zig").TextureView;
const TextureViewDimension = @import("texture_view.zig").TextureViewDimension; const TextureViewDimension = @import("texture_view.zig").TextureViewDimension;
const Extent3D = @import("types.zig").Extent3D; const Extent3D = @import("types.zig").Extent3D;
pub const Texture = enum(usize) { pub const Texture = *opaque {};
_,
// TODO: verify there is a use case for nullable value of this type. pub const TextureAspect = enum(u32) {
pub const none: Texture = @intToEnum(Texture, 0); all = 0x00000000,
stencil_only = 0x00000001,
pub const Aspect = enum(u32) { depth_only = 0x00000002,
all = 0x00000000, plane0_only = 0x00000003,
stencil_only = 0x00000001, plane1_only = 0x00000004,
depth_only = 0x00000002, };
plane0_only = 0x00000003,
plane1_only = 0x00000004, pub const TextureComponentType = enum(u32) {
}; float = 0x00000000,
sint = 0x00000001,
pub const ComponentType = enum(u32) { uint = 0x00000002,
float = 0x00000000, depth_comparison = 0x00000003,
sint = 0x00000001, };
uint = 0x00000002,
depth_comparison = 0x00000003, pub const TextureDimension = enum(u32) {
}; dimension_1d = 0x00000000,
dimension_2d = 0x00000001,
pub const Dimension = enum(u32) { dimension_3d = 0x00000002,
dimension_1d = 0x00000000, };
dimension_2d = 0x00000001,
dimension_3d = 0x00000002, pub const TextureFormat = enum(u32) {
}; undef = 0x00000000,
r8_unorm = 0x00000001,
pub const Format = enum(u32) { r8_snorm = 0x00000002,
undef = 0x00000000, r8_uint = 0x00000003,
r8_unorm = 0x00000001, r8_sint = 0x00000004,
r8_snorm = 0x00000002, r16_uint = 0x00000005,
r8_uint = 0x00000003, r16_sint = 0x00000006,
r8_sint = 0x00000004, r16_float = 0x00000007,
r16_uint = 0x00000005, rg8_unorm = 0x00000008,
r16_sint = 0x00000006, rg8_snorm = 0x00000009,
r16_float = 0x00000007, rg8_uint = 0x0000000a,
rg8_unorm = 0x00000008, rg8_sint = 0x0000000b,
rg8_snorm = 0x00000009, r32_float = 0x0000000c,
rg8_uint = 0x0000000a, r32_uint = 0x0000000d,
rg8_sint = 0x0000000b, r32_sint = 0x0000000e,
r32_float = 0x0000000c, rg16_uint = 0x0000000f,
r32_uint = 0x0000000d, rg16_sint = 0x00000010,
r32_sint = 0x0000000e, rg16_float = 0x00000011,
rg16_uint = 0x0000000f, rgba8_unorm = 0x00000012,
rg16_sint = 0x00000010, rgba8_unorm_srgb = 0x00000013,
rg16_float = 0x00000011, rgba8_snorm = 0x00000014,
rgba8_unorm = 0x00000012, rgba8_uint = 0x00000015,
rgba8_unorm_srgb = 0x00000013, rgba8_sint = 0x00000016,
rgba8_snorm = 0x00000014, bgra8_unorm = 0x00000017,
rgba8_uint = 0x00000015, bgra8_unorm_srgb = 0x00000018,
rgba8_sint = 0x00000016, rgb10_a2_unorm = 0x00000019,
bgra8_unorm = 0x00000017, rg11_b10_ufloat = 0x0000001a,
bgra8_unorm_srgb = 0x00000018, rgb9_e5_ufloat = 0x0000001b,
rgb10_a2_unorm = 0x00000019, rg32_float = 0x0000001c,
rg11_b10_ufloat = 0x0000001a, rg32_uint = 0x0000001d,
rgb9_e5_ufloat = 0x0000001b, rg32_sint = 0x0000001e,
rg32_float = 0x0000001c, rgba16_uint = 0x0000001f,
rg32_uint = 0x0000001d, rgba16_sint = 0x00000020,
rg32_sint = 0x0000001e, rgba16_float = 0x00000021,
rgba16_uint = 0x0000001f, rgba32_float = 0x00000022,
rgba16_sint = 0x00000020, rgba32_uint = 0x00000023,
rgba16_float = 0x00000021, rgba32_sint = 0x00000024,
rgba32_float = 0x00000022, stencil8 = 0x00000025,
rgba32_uint = 0x00000023, depth16_unorm = 0x00000026,
rgba32_sint = 0x00000024, depth24_plus = 0x00000027,
stencil8 = 0x00000025, depth24_plus_stencil8 = 0x00000028,
depth16_unorm = 0x00000026, depth32_float = 0x00000029,
depth24_plus = 0x00000027, depth32_float_stencil8 = 0x0000002a,
depth24_plus_stencil8 = 0x00000028, bc1_rgba_unorm = 0x0000002b,
depth32_float = 0x00000029, bc1_rgba_unorm_srgb = 0x0000002c,
depth32_float_stencil8 = 0x0000002a, bc2_rgba_unorm = 0x0000002d,
bc1_rgba_unorm = 0x0000002b, bc2_rgba_unorm_srgb = 0x0000002e,
bc1_rgba_unorm_srgb = 0x0000002c, bc3_rgba_unorm = 0x0000002f,
bc2_rgba_unorm = 0x0000002d, bc3_rgba_unorm_srgb = 0x00000030,
bc2_rgba_unorm_srgb = 0x0000002e, bc4_runorm = 0x00000031,
bc3_rgba_unorm = 0x0000002f, bc4_rsnorm = 0x00000032,
bc3_rgba_unorm_srgb = 0x00000030, bc5_rg_unorm = 0x00000033,
bc4_runorm = 0x00000031, bc5_rg_snorm = 0x00000034,
bc4_rsnorm = 0x00000032, bc6_hrgb_ufloat = 0x00000035,
bc5_rg_unorm = 0x00000033, bc6_hrgb_float = 0x00000036,
bc5_rg_snorm = 0x00000034, bc7_rgba_unorm = 0x00000037,
bc6_hrgb_ufloat = 0x00000035, bc7_rgba_unorm_srgb = 0x00000038,
bc6_hrgb_float = 0x00000036, etc2_rgb8_unorm = 0x00000039,
bc7_rgba_unorm = 0x00000037, etc2_rgb8_unorm_srgb = 0x0000003a,
bc7_rgba_unorm_srgb = 0x00000038, etc2_rgb8_a1_unorm = 0x0000003b,
etc2_rgb8_unorm = 0x00000039, etc2_rgb8_a1_unorm_srgb = 0x0000003c,
etc2_rgb8_unorm_srgb = 0x0000003a, etc2_rgba8_unorm = 0x0000003d,
etc2_rgb8_a1_unorm = 0x0000003b, etc2_rgba8_unorm_srgb = 0x0000003e,
etc2_rgb8_a1_unorm_srgb = 0x0000003c, eacr11_unorm = 0x0000003f,
etc2_rgba8_unorm = 0x0000003d, eacr11_snorm = 0x00000040,
etc2_rgba8_unorm_srgb = 0x0000003e, eacrg11_unorm = 0x00000041,
eacr11_unorm = 0x0000003f, eacrg11_snorm = 0x00000042,
eacr11_snorm = 0x00000040, astc4x4_unorm = 0x00000043,
eacrg11_unorm = 0x00000041, astc4x4_unorm_srgb = 0x00000044,
eacrg11_snorm = 0x00000042, astc5x4_unorm = 0x00000045,
astc4x4_unorm = 0x00000043, astc5x4_unorm_srgb = 0x00000046,
astc4x4_unorm_srgb = 0x00000044, astc5x5_unorm = 0x00000047,
astc5x4_unorm = 0x00000045, astc5x5_unorm_srgb = 0x00000048,
astc5x4_unorm_srgb = 0x00000046, astc6x5_unorm = 0x00000049,
astc5x5_unorm = 0x00000047, astc6x5_unorm_srgb = 0x0000004a,
astc5x5_unorm_srgb = 0x00000048, astc6x6_unorm = 0x0000004b,
astc6x5_unorm = 0x00000049, astc6x6_unorm_srgb = 0x0000004c,
astc6x5_unorm_srgb = 0x0000004a, astc8x5_unorm = 0x0000004d,
astc6x6_unorm = 0x0000004b, astc8x5_unorm_srgb = 0x0000004e,
astc6x6_unorm_srgb = 0x0000004c, astc8x6_unorm = 0x0000004f,
astc8x5_unorm = 0x0000004d, astc8x6_unorm_srgb = 0x00000050,
astc8x5_unorm_srgb = 0x0000004e, astc8x8_unorm = 0x00000051,
astc8x6_unorm = 0x0000004f, astc8x8_unorm_srgb = 0x00000052,
astc8x6_unorm_srgb = 0x00000050, astc10x5_unorm = 0x00000053,
astc8x8_unorm = 0x00000051, astc10x5_unorm_srgb = 0x00000054,
astc8x8_unorm_srgb = 0x00000052, astc10x6_unorm = 0x00000055,
astc10x5_unorm = 0x00000053, astc10x6_unorm_srgb = 0x00000056,
astc10x5_unorm_srgb = 0x00000054, astc10x8_unorm = 0x00000057,
astc10x6_unorm = 0x00000055, astc10x8_unorm_srgb = 0x00000058,
astc10x6_unorm_srgb = 0x00000056, astc10x10_unorm = 0x00000059,
astc10x8_unorm = 0x00000057, astc10x10_unorm_srgb = 0x0000005a,
astc10x8_unorm_srgb = 0x00000058, astc12x10_unorm = 0x0000005b,
astc10x10_unorm = 0x00000059, astc12x10_unorm_srgb = 0x0000005c,
astc10x10_unorm_srgb = 0x0000005a, astc12x12_unorm = 0x0000005d,
astc12x10_unorm = 0x0000005b, astc12x12_unorm_srgb = 0x0000005e,
astc12x10_unorm_srgb = 0x0000005c, r8_bg8_biplanar420_unorm = 0x0000005f,
astc12x12_unorm = 0x0000005d, };
astc12x12_unorm_srgb = 0x0000005e,
r8_bg8_biplanar420_unorm = 0x0000005f, pub const TextureSampleType = enum(u32) {
}; undef = 0x00000000,
float = 0x00000001,
pub const SampleType = enum(u32) { unfilterable_float = 0x00000002,
undef = 0x00000000, depth = 0x00000003,
float = 0x00000001, sint = 0x00000004,
unfilterable_float = 0x00000002, uint = 0x00000005,
depth = 0x00000003, };
sint = 0x00000004,
uint = 0x00000005, pub const TextureUsageFlags = packed struct {
}; copy_src: bool = false,
copy_dst: bool = false,
pub const UsageFlags = packed struct { texture_binding: bool = false,
copy_src: bool = false, storage_binding: bool = false,
copy_dst: bool = false, render_attachment: bool = false,
texture_binding: bool = false, present: bool = false,
storage_binding: bool = false,
render_attachment: bool = false, _padding: u26 = 0,
present: bool = false,
comptime {
_padding: u26 = 0, std.debug.assert(
@sizeOf(@This()) == @sizeOf(u32) and
comptime { @bitSizeOf(@This()) == @bitSizeOf(u32),
std.debug.assert( );
@sizeOf(@This()) == @sizeOf(u32) and }
@bitSizeOf(@This()) == @bitSizeOf(u32),
); pub const none = TextureUsageFlags{};
}
pub fn equal(a: TextureUsageFlags, b: TextureUsageFlags) bool {
pub const none = UsageFlags{}; return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b));
}
pub fn equal(a: UsageFlags, b: UsageFlags) bool { };
return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b));
} pub const TextureBindingLayout = extern struct {
}; next_in_chain: *const ChainedStruct,
sample_type: TextureSampleType,
pub const BindingLayout = extern struct { view_dimension: TextureViewDimension,
next_in_chain: *const ChainedStruct, multisampled: bool,
sample_type: SampleType, };
view_dimension: TextureViewDimension,
multisampled: bool, pub const TextureDataLayout = extern struct {
}; next_in_chain: *const ChainedStruct,
offset: u64,
pub const DataLayout = extern struct { bytes_per_row: u32,
next_in_chain: *const ChainedStruct, rows_per_image: u32,
offset: u64, };
bytes_per_row: u32,
rows_per_image: u32, pub const TextureDescriptor = extern struct {
}; next_in_chain: *const ChainedStruct,
label: ?[*:0]const u8 = null,
pub const Descriptor = extern struct { usage: TextureUsageFlags,
next_in_chain: *const ChainedStruct, dimension: TextureDimension,
label: ?[*:0]const u8 = null, size: Extent3D,
usage: UsageFlags, format: TextureFormat,
dimension: Dimension, mip_level_count: u32,
size: Extent3D, sample_count: u32,
format: Format, view_format_count: u32,
mip_level_count: u32, view_formats: [*]const TextureFormat,
sample_count: u32,
view_format_count: u32,
view_formats: [*]const Format,
};
}; };

View file

@ -1,5 +1,7 @@
const ChainedStruct = @import("types.zig").ChainedStruct; const ChainedStruct = @import("types.zig").ChainedStruct;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureFormat = @import("texture.zig").TextureFormat;
const TextureAspect = @import("texture.zig").TextureAspect;
pub const TextureView = *opaque {}; pub const TextureView = *opaque {};
@ -16,11 +18,11 @@ pub const TextureViewDimension = enum(u32) {
pub const TextureViewDescriptor = extern struct { pub const TextureViewDescriptor = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
format: Texture.Format, format: TextureFormat,
dimension: TextureViewDimension, dimension: TextureViewDimension,
base_mip_level: u32, base_mip_level: u32,
mip_level_count: u32, mip_level_count: u32,
base_array_layer: u32, base_array_layer: u32,
array_layer_count: u32, array_layer_count: u32,
aspect: Texture.Aspect, aspect: TextureAspect,
}; };

View file

@ -1,6 +1,9 @@
const std = @import("std"); const std = @import("std");
const testing = std.testing; const testing = std.testing;
const Texture = @import("texture.zig").Texture; const Texture = @import("texture.zig").Texture;
const TextureFormat = @import("texture.zig").TextureFormat;
const TextureAspect = @import("texture.zig").TextureAspect;
const TextureDataLayout = @import("texture.zig").TextureDataLayout;
const TextureView = @import("texture_view.zig").TextureView; const TextureView = @import("texture_view.zig").TextureView;
const TextureViewDimension = @import("texture_view.zig").TextureViewDimension; const TextureViewDimension = @import("texture_view.zig").TextureViewDimension;
const Buffer = @import("buffer.zig").Buffer; const Buffer = @import("buffer.zig").Buffer;
@ -502,7 +505,7 @@ pub const StencilFaceState = extern struct {
pub const StorageTextureBindingLayout = extern struct { pub const StorageTextureBindingLayout = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
access: StorageTextureAccess, access: StorageTextureAccess,
format: Texture.Format, format: TextureFormat,
view_dimension: TextureViewDimension, view_dimension: TextureViewDimension,
}; };
@ -525,7 +528,7 @@ pub const CompilationInfo = extern struct {
pub const DepthStencilState = extern struct { pub const DepthStencilState = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
format: Texture.Format, format: TextureFormat,
depth_write_enabled: bool, depth_write_enabled: bool,
depth_compare: CompareFunction, depth_compare: CompareFunction,
stencil_front: StencilFaceState, stencil_front: StencilFaceState,
@ -539,7 +542,7 @@ pub const DepthStencilState = extern struct {
pub const ImageCopyBuffer = extern struct { pub const ImageCopyBuffer = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
layout: Texture.DataLayout, layout: TextureDataLayout,
buffer: Buffer, buffer: Buffer,
}; };
@ -548,7 +551,7 @@ pub const ImageCopyTexture = extern struct {
texture: Texture, texture: Texture,
mip_level: u32, mip_level: u32,
origin: Origin3D, origin: Origin3D,
aspect: Texture.Aspect, aspect: TextureAspect,
}; };
pub const ProgrammableStageDescriptor = extern struct { pub const ProgrammableStageDescriptor = extern struct {
@ -587,7 +590,7 @@ pub const VertexBufferLayout = extern struct {
pub const ColorTargetState = extern struct { pub const ColorTargetState = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
format: Texture.Format, format: TextureFormat,
blend: ?*const BlendState = null, blend: ?*const BlendState = null,
write_mask: ColorWriteMaskFlags, write_mask: ColorWriteMaskFlags,
}; };