Created a GpuTextureDef
This commit is contained in:
parent
fc57bee3af
commit
45c0f3180e
@ -10,7 +10,7 @@ pub const Binding = struct {
|
||||
element_size: u32 = 0,
|
||||
};
|
||||
|
||||
pub const RenderDef = struct {
|
||||
pub const GpuRenderDef = struct {
|
||||
bindings: []const Binding = &.{},
|
||||
/// The surface texture format we are rendering to (e.g., BGRA8Unorm)
|
||||
texture_format: GpuTextureFormat,
|
||||
@ -32,9 +32,9 @@ const GpuPrimitiveTopology = enum(c_uint) {
|
||||
};
|
||||
|
||||
pip: c.WGPURenderPipeline,
|
||||
def: RenderDef,
|
||||
def: GpuRenderDef,
|
||||
|
||||
pub fn init(device: GpuDevice, wgsl: []const u8, def: RenderDef) !@This() {
|
||||
pub fn init(device: GpuDevice, wgsl: []const u8, def: GpuRenderDef) !@This() {
|
||||
var wgsl_src = c.WGPUShaderSourceWGSL{
|
||||
.chain = .{ .sType = c.WGPUSType_ShaderSourceWGSL },
|
||||
.code = sv(wgsl),
|
||||
|
||||
@ -3,7 +3,7 @@ const c = @import("utils.zig").c;
|
||||
const GpuAllocator = @import("GpuAllocator.zig");
|
||||
const GpuTextureFormat = @import("lib.zig").GpuTextureFormat;
|
||||
|
||||
const TextureUsage = enum(u64) {
|
||||
const GpuTextureUsage = enum(u64) {
|
||||
None = 0x0000000000000000,
|
||||
CopySrc = 0x0000000000000001,
|
||||
CopyDst = 0x0000000000000002,
|
||||
@ -13,29 +13,33 @@ const TextureUsage = enum(u64) {
|
||||
TransientAttachment = 0x0000000000000020,
|
||||
};
|
||||
|
||||
raw: c.WGPUTexture,
|
||||
pub const GpuTextureDef = struct {
|
||||
size: c.WGPUExtent3D,
|
||||
usage: c.WGPUTextureUsage,
|
||||
usage: std.EnumSet(GpuTextureUsage),
|
||||
format: GpuTextureFormat,
|
||||
};
|
||||
|
||||
raw: c.WGPUTexture,
|
||||
gloc: GpuAllocator,
|
||||
def: GpuTextureDef,
|
||||
|
||||
/// Allocates the underlying WebGPU handle and registers it to the parent GpuAllocator
|
||||
pub fn init(gloc: GpuAllocator, format: GpuTextureFormat, size: c.WGPUExtent3D, usage: std.EnumSet(TextureUsage)) !@This() {
|
||||
pub fn init(gloc: GpuAllocator, def: GpuTextureDef) !@This() {
|
||||
var use: u64 = 0;
|
||||
var iter = usage.iterator();
|
||||
var iter = def.usage.iterator();
|
||||
while (iter.next()) |flag| use |= @intFromEnum(flag);
|
||||
|
||||
const desc = c.WGPUTextureDescriptor{
|
||||
.usage = use,
|
||||
.dimension = c.WGPUTextureDimension_2D,
|
||||
.size = size,
|
||||
.format = @intFromEnum(format),
|
||||
.size = def.size,
|
||||
.format = @intFromEnum(def.format),
|
||||
.mipLevelCount = 1,
|
||||
.sampleCount = 1,
|
||||
};
|
||||
const raw = try gloc.allocTexture(desc);
|
||||
|
||||
return .{ .gloc = gloc, .raw = raw, .size = size, .format = format, .usage = use };
|
||||
return .{ .gloc = gloc, .raw = raw, .def = def };
|
||||
}
|
||||
|
||||
/// Unregisters from the parent GpuAllocator and cleanly destroys GPU resources
|
||||
|
||||
@ -35,12 +35,11 @@ pub fn main(init: std.process.Init) !void {
|
||||
defer circle_rp.deinit();
|
||||
|
||||
// 3. Create the offscreen VRAM texture to render into
|
||||
const texture = try GpuTexture.init(
|
||||
gloc,
|
||||
.RGBA8Unorm,
|
||||
.{ .width = width, .height = height, .depthOrArrayLayers = 1 },
|
||||
.initMany(&.{ .RenderAttachment, .CopySrc }),
|
||||
);
|
||||
const texture = try GpuTexture.init(gloc, .{
|
||||
.format = .RGBA8Unorm,
|
||||
.size = .{ .width = width, .height = height, .depthOrArrayLayers = 1 },
|
||||
.usage = .initMany(&.{ .RenderAttachment, .CopySrc }),
|
||||
});
|
||||
defer texture.deinit();
|
||||
|
||||
const target_view = c.wgpuTextureCreateView(texture.raw, null) orelse return error.View;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user