Added helper functions to BindGroupLayout.Entry (#213)
* gpu: Added helper functions to BindGroupLayout.Entry * gpu: Changed default values for *.BindingLayout structures. Added comments for helpers.
This commit is contained in:
parent
a943fbed3e
commit
9ed6f6ca8b
5 changed files with 91 additions and 13 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
const Buffer = @import("Buffer.zig");
|
const Buffer = @import("Buffer.zig");
|
||||||
const Sampler = @import("Sampler.zig");
|
const Sampler = @import("Sampler.zig");
|
||||||
const Texture = @import("Texture.zig");
|
const Texture = @import("Texture.zig");
|
||||||
|
const TextureView = @import("TextureView.zig");
|
||||||
const StorageTextureBindingLayout = @import("structs.zig").StorageTextureBindingLayout;
|
const StorageTextureBindingLayout = @import("structs.zig").StorageTextureBindingLayout;
|
||||||
|
const StorageTextureAccess = @import("enums.zig").StorageTextureAccess;
|
||||||
const ShaderStage = @import("enums.zig").ShaderStage;
|
const ShaderStage = @import("enums.zig").ShaderStage;
|
||||||
|
|
||||||
const BindGroupLayout = @This();
|
const BindGroupLayout = @This();
|
||||||
|
|
@ -38,10 +40,76 @@ pub const Entry = extern struct {
|
||||||
reserved: ?*anyopaque = null,
|
reserved: ?*anyopaque = null,
|
||||||
binding: u32,
|
binding: u32,
|
||||||
visibility: ShaderStage,
|
visibility: ShaderStage,
|
||||||
buffer: Buffer.BindingLayout,
|
buffer: Buffer.BindingLayout = .{ .type = .none },
|
||||||
sampler: Sampler.BindingLayout,
|
sampler: Sampler.BindingLayout = .{ .type = .none },
|
||||||
texture: Texture.BindingLayout,
|
texture: Texture.BindingLayout = .{ .sample_type = .none },
|
||||||
storage_texture: StorageTextureBindingLayout,
|
storage_texture: StorageTextureBindingLayout = .{ .access = .none, .format = .none },
|
||||||
|
|
||||||
|
/// Helper to create a buffer BindGroupLayout.Entry.
|
||||||
|
pub fn buffer(
|
||||||
|
binding: u32,
|
||||||
|
visibility: ShaderStage,
|
||||||
|
binding_type: Buffer.BindingType,
|
||||||
|
has_dynamic_offset: bool,
|
||||||
|
min_binding_size: u64,
|
||||||
|
) Entry {
|
||||||
|
return .{
|
||||||
|
.binding = binding,
|
||||||
|
.visibility = visibility,
|
||||||
|
.buffer = .{
|
||||||
|
.type = binding_type,
|
||||||
|
.has_dynamic_offset = has_dynamic_offset,
|
||||||
|
.min_binding_size = min_binding_size,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper to create a sampler BindGroupLayout.Entry.
|
||||||
|
pub fn sampler(binding: u32, visibility: ShaderStage, binding_type: Sampler.BindingType) Entry {
|
||||||
|
return .{
|
||||||
|
.binding = binding,
|
||||||
|
.visibility = visibility,
|
||||||
|
.sampler = .{ .type = binding_type },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper to create a texture BindGroupLayout.Entry.
|
||||||
|
pub fn texture(
|
||||||
|
binding: u32,
|
||||||
|
visibility: ShaderStage,
|
||||||
|
sample_type: Texture.SampleType,
|
||||||
|
view_dimension: TextureView.Dimension,
|
||||||
|
multisampled: bool,
|
||||||
|
) Entry {
|
||||||
|
return .{
|
||||||
|
.binding = binding,
|
||||||
|
.visibility = visibility,
|
||||||
|
.texture = .{
|
||||||
|
.sample_type = sample_type,
|
||||||
|
.view_dimension = view_dimension,
|
||||||
|
.multisampled = multisampled,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper to create a storage texture BindGroupLayout.Entry.
|
||||||
|
pub fn storageTexture(
|
||||||
|
binding: u32,
|
||||||
|
visibility: ShaderStage,
|
||||||
|
access: StorageTextureAccess,
|
||||||
|
format: Texture.Format,
|
||||||
|
view_dimension: TextureView.Dimension,
|
||||||
|
) Entry {
|
||||||
|
return .{
|
||||||
|
.binding = binding,
|
||||||
|
.visibility = visibility,
|
||||||
|
.storage_texture = .{
|
||||||
|
.access = access,
|
||||||
|
.format = format,
|
||||||
|
.view_dimension = view_dimension,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|
@ -51,4 +119,14 @@ test {
|
||||||
_ = setLabel;
|
_ = setLabel;
|
||||||
_ = Descriptor;
|
_ = Descriptor;
|
||||||
_ = Entry;
|
_ = Entry;
|
||||||
|
|
||||||
|
const desc = BindGroupLayout.Descriptor{
|
||||||
|
.entries = &.{
|
||||||
|
BindGroupLayout.Entry.buffer(0, .{ .vertex = true }, .uniform, true, 0),
|
||||||
|
BindGroupLayout.Entry.sampler(1, .{ .vertex = true }, .filtering),
|
||||||
|
BindGroupLayout.Entry.texture(2, .{ .fragment = true }, .float, .dimension_2d, false),
|
||||||
|
BindGroupLayout.Entry.storageTexture(3, .{ .fragment = true }, .none, .rgba32_float, .dimension_2d),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
_ = desc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ pub const BindingType = enum(u32) {
|
||||||
|
|
||||||
pub const BindingLayout = extern struct {
|
pub const BindingLayout = extern struct {
|
||||||
reserved: ?*anyopaque = null,
|
reserved: ?*anyopaque = null,
|
||||||
type: BindingType,
|
type: BindingType = .uniform,
|
||||||
has_dynamic_offset: bool,
|
has_dynamic_offset: bool = false,
|
||||||
min_binding_size: u64,
|
min_binding_size: u64 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const MapAsyncStatus = enum(u32) {
|
pub const MapAsyncStatus = enum(u32) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ pub const BindingType = enum(u32) {
|
||||||
|
|
||||||
pub const BindingLayout = extern struct {
|
pub const BindingLayout = extern struct {
|
||||||
reserved: ?*anyopaque = null,
|
reserved: ?*anyopaque = null,
|
||||||
type: BindingType,
|
type: BindingType = .filtering,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Descriptor = extern struct {
|
pub const Descriptor = extern struct {
|
||||||
|
|
|
||||||
|
|
@ -211,9 +211,9 @@ pub const SampleType = enum(u32) {
|
||||||
|
|
||||||
pub const BindingLayout = extern struct {
|
pub const BindingLayout = extern struct {
|
||||||
reserved: ?*anyopaque = null,
|
reserved: ?*anyopaque = null,
|
||||||
sample_type: SampleType,
|
sample_type: SampleType = .float,
|
||||||
view_dimension: TextureView.Dimension,
|
view_dimension: TextureView.Dimension = .dimension_2d,
|
||||||
multisampled: bool,
|
multisampled: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DataLayout = extern struct {
|
pub const DataLayout = extern struct {
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ pub const PrimitiveState = struct {
|
||||||
|
|
||||||
pub const StorageTextureBindingLayout = extern struct {
|
pub const StorageTextureBindingLayout = extern struct {
|
||||||
reserved: ?*anyopaque = null,
|
reserved: ?*anyopaque = null,
|
||||||
access: StorageTextureAccess,
|
access: StorageTextureAccess = .write_only,
|
||||||
format: Texture.Format,
|
format: Texture.Format,
|
||||||
view_dimension: TextureView.Dimension,
|
view_dimension: TextureView.Dimension = .dimension_2d,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DepthStencilState = struct {
|
pub const DepthStencilState = struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue