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,13 +4,9 @@ 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);
pub const Aspect = enum(u32) {
all = 0x00000000, all = 0x00000000,
stencil_only = 0x00000001, stencil_only = 0x00000001,
depth_only = 0x00000002, depth_only = 0x00000002,
@ -18,20 +14,20 @@ pub const Texture = enum(usize) {
plane1_only = 0x00000004, plane1_only = 0x00000004,
}; };
pub const ComponentType = enum(u32) { pub const TextureComponentType = enum(u32) {
float = 0x00000000, float = 0x00000000,
sint = 0x00000001, sint = 0x00000001,
uint = 0x00000002, uint = 0x00000002,
depth_comparison = 0x00000003, depth_comparison = 0x00000003,
}; };
pub const Dimension = enum(u32) { pub const TextureDimension = enum(u32) {
dimension_1d = 0x00000000, dimension_1d = 0x00000000,
dimension_2d = 0x00000001, dimension_2d = 0x00000001,
dimension_3d = 0x00000002, dimension_3d = 0x00000002,
}; };
pub const Format = enum(u32) { pub const TextureFormat = enum(u32) {
undef = 0x00000000, undef = 0x00000000,
r8_unorm = 0x00000001, r8_unorm = 0x00000001,
r8_snorm = 0x00000002, r8_snorm = 0x00000002,
@ -130,7 +126,7 @@ pub const Texture = enum(usize) {
r8_bg8_biplanar420_unorm = 0x0000005f, r8_bg8_biplanar420_unorm = 0x0000005f,
}; };
pub const SampleType = enum(u32) { pub const TextureSampleType = enum(u32) {
undef = 0x00000000, undef = 0x00000000,
float = 0x00000001, float = 0x00000001,
unfilterable_float = 0x00000002, unfilterable_float = 0x00000002,
@ -139,7 +135,7 @@ pub const Texture = enum(usize) {
uint = 0x00000005, uint = 0x00000005,
}; };
pub const UsageFlags = packed struct { pub const TextureUsageFlags = packed struct {
copy_src: bool = false, copy_src: bool = false,
copy_dst: bool = false, copy_dst: bool = false,
texture_binding: bool = false, texture_binding: bool = false,
@ -156,37 +152,36 @@ pub const Texture = enum(usize) {
); );
} }
pub const none = UsageFlags{}; pub const none = TextureUsageFlags{};
pub fn equal(a: UsageFlags, b: UsageFlags) bool { pub fn equal(a: TextureUsageFlags, b: TextureUsageFlags) bool {
return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b)); return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b));
} }
}; };
pub const BindingLayout = extern struct { pub const TextureBindingLayout = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
sample_type: SampleType, sample_type: TextureSampleType,
view_dimension: TextureViewDimension, view_dimension: TextureViewDimension,
multisampled: bool, multisampled: bool,
}; };
pub const DataLayout = extern struct { pub const TextureDataLayout = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
offset: u64, offset: u64,
bytes_per_row: u32, bytes_per_row: u32,
rows_per_image: u32, rows_per_image: u32,
}; };
pub const Descriptor = extern struct { pub const TextureDescriptor = extern struct {
next_in_chain: *const ChainedStruct, next_in_chain: *const ChainedStruct,
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
usage: UsageFlags, usage: TextureUsageFlags,
dimension: Dimension, dimension: TextureDimension,
size: Extent3D, size: Extent3D,
format: Format, format: TextureFormat,
mip_level_count: u32, mip_level_count: u32,
sample_count: u32, sample_count: u32,
view_format_count: u32, view_format_count: u32,
view_formats: [*]const Format, view_formats: [*]const TextureFormat,
};
}; };

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,
}; };