2026-07-28 22:37:53 +01:00
|
|
|
//! ----------------------------------------------------
|
|
|
|
|
//! ----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
|
const gtl = @import("gtl");
|
|
|
|
|
const App = @import("app");
|
|
|
|
|
const WGPUDevice = @import("../../device/resource/wgpu_device.zig");
|
2026-07-29 01:15:31 +01:00
|
|
|
|
2026-07-28 22:37:53 +01:00
|
|
|
const ShaderCache = @import("../resource/shader_cache.zig");
|
|
|
|
|
const PipelineCache = @import("../resource/pipeline_cache.zig");
|
2026-07-29 01:15:31 +01:00
|
|
|
const MeshCache = @import("../resource/mesh_cache.zig");
|
2026-07-28 22:37:53 +01:00
|
|
|
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
pub fn init(app: *App) !void {
|
|
|
|
|
// --- # ---
|
|
|
|
|
const res = try app.resources.getMany(struct {
|
|
|
|
|
device: *const WGPUDevice,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- SHADER CACHE ---
|
|
|
|
|
const shaders = try app.resources.getOrSet(ShaderCache.init(
|
|
|
|
|
res.device.raw,
|
|
|
|
|
app.alloc,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// --- PIPELINE CACHE ---
|
|
|
|
|
const pipelines = try app.resources.getOrSet(PipelineCache.init(
|
|
|
|
|
shaders,
|
|
|
|
|
res.device.queue,
|
|
|
|
|
res.device.raw,
|
|
|
|
|
app.alloc,
|
|
|
|
|
));
|
|
|
|
|
|
2026-07-29 01:15:31 +01:00
|
|
|
// --- MESH CACHE ---
|
|
|
|
|
const meshes = try app.resources.getOrSet(MeshCache.init(
|
|
|
|
|
res.device.raw,
|
|
|
|
|
res.device.queue,
|
|
|
|
|
app.alloc,
|
|
|
|
|
));
|
2026-07-29 02:06:24 +01:00
|
|
|
_ = meshes;
|
2026-07-29 01:15:31 +01:00
|
|
|
|
2026-07-28 22:37:53 +01:00
|
|
|
// TODO: Remove or place it somewhere else, idk
|
|
|
|
|
|
|
|
|
|
// --- TEST ---
|
|
|
|
|
_ = try pipelines.getOrCreate(.{});
|
|
|
|
|
_ = try pipelines.getOrCreate(.{});
|
|
|
|
|
|
2026-07-29 21:36:00 +01:00
|
|
|
_ = try pipelines.getOrCreate(.{ .unique = .{ .shader = .unlit } });
|
|
|
|
|
_ = try pipelines.getOrCreate(.{ .unique = .{ .shader = .unlit } });
|
2026-07-28 22:37:53 +01:00
|
|
|
|
|
|
|
|
{ // DEBUG
|
|
|
|
|
std.debug.print("{s}┏━{s} PIPELINES\n", .{ gtl.ansi.blue, gtl.ansi.reset });
|
|
|
|
|
for (pipelines.pipelines.items(), 0..) |entry, i| {
|
|
|
|
|
// std.debug.print("\x1b[33m\x1b[0m {s:<12} {s}\n", .{ plugin.name, plugin.description });
|
|
|
|
|
std.debug.print(
|
|
|
|
|
\\{s}┃ ┏━{s} {}
|
|
|
|
|
\\{s}┃ ┃ {s}Shader: {s}
|
|
|
|
|
\\{s}┃ ┃ {s}Cull Mode: {s}
|
|
|
|
|
\\{s}┃ ┃ {s}Blend Mode: {s}
|
|
|
|
|
\\{s}┃ ┃ {s}Front Face: {s}
|
|
|
|
|
\\{s}┃ ┃ {s}Topology: {s}
|
|
|
|
|
\\
|
|
|
|
|
, .{
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
i,
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
@tagName(entry.key.shader),
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
@tagName(entry.key.cull_mode),
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
@tagName(entry.key.blend_mode),
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
@tagName(entry.key.front_face),
|
|
|
|
|
gtl.ansi.blue,
|
|
|
|
|
gtl.ansi.reset,
|
|
|
|
|
@tagName(entry.key.topology),
|
|
|
|
|
});
|
|
|
|
|
std.debug.print("{s}┃ ┗━{s}\n", .{ gtl.ansi.blue, gtl.ansi.reset });
|
|
|
|
|
}
|
|
|
|
|
std.debug.print("{s}┗━{s}\n", .{ gtl.ansi.blue, gtl.ansi.reset });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
/// ----------------------------------------------------
|
|
|
|
|
pub fn deinit(app: *App) !void {
|
|
|
|
|
// --- # ---
|
|
|
|
|
const res = try app.resources.getMany(struct {
|
|
|
|
|
shaders: *ShaderCache,
|
|
|
|
|
pipelines: *PipelineCache,
|
2026-07-29 01:15:31 +01:00
|
|
|
meshes: *MeshCache,
|
2026-07-28 22:37:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// --- # ---
|
|
|
|
|
res.shaders.deinit();
|
|
|
|
|
res.pipelines.deinit();
|
2026-07-29 01:15:31 +01:00
|
|
|
res.meshes.deinit();
|
2026-07-28 22:37:53 +01:00
|
|
|
}
|