summaryrefslogtreecommitdiff
path: root/src/gui/Post.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/Post.zig')
-rw-r--r--src/gui/Post.zig27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/gui/Post.zig b/src/gui/Post.zig
index a79d9f0c..c0b71d97 100644
--- a/src/gui/Post.zig
+++ b/src/gui/Post.zig
@@ -37,6 +37,8 @@ const bloom_up_spv = @embedFile("bloom-up.frag.spv");
/// Bloom's steps below the frame, at levels 1 to 3: a half, a quarter, ...
const bloom_steps = [_]u8{ 3, 4, 5 };
const bloom_format = c.SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT;
+/// Every pass writes its target whole: no blending.
+const no_blend = std.mem.zeroes(c.SDL_GPUColorTargetBlendState);
/// pardes's own block (shaders/post/prefix.glsl PardesPost), std140.
pub const Own = extern struct {
@@ -137,10 +139,10 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, forma
var next: [max]Pass = @splat(.{});
for (chain, 0..) |entry, i| {
if (entry.scene) |scene| {
- if (post.bundled.get(scene) == null) post.bundled.set(scene, makePipeline(device, format, bundled_spv.get(scene), if (scene == .bloom) 2 else 1, 4) catch null);
+ if (post.bundled.get(scene) == null) post.bundled.set(scene, gui.makePipeline(device, format, vert_spv, bundled_spv.get(scene), if (scene == .bloom) 2 else 1, 4, null, no_blend) catch null);
if (scene == .bloom and post.bloom_down == null) {
- post.bloom_down = makePipeline(device, bloom_format, bloom_down_spv, 1, 1) catch null;
- post.bloom_up = makePipeline(device, bloom_format, bloom_up_spv, 1, 1) catch null;
+ post.bloom_down = gui.makePipeline(device, bloom_format, vert_spv, bloom_down_spv, 1, 1, null, no_blend) catch null;
+ post.bloom_up = gui.makePipeline(device, bloom_format, vert_spv, bloom_up_spv, 1, 1, null, no_blend) catch null;
}
next[i] = .{ .scene = scene, .level = entry.level, .pipeline = post.bundled.get(scene), .animated = entry.animated };
continue;
@@ -156,7 +158,7 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, forma
pass.animated = entry.animated;
if (pass.revision == entry.revision or entry.spirv.len == 0) continue;
pass.revision = entry.revision;
- const made = makePipeline(device, format, entry.spirv, 1, 4) catch {
+ const made = gui.makePipeline(device, format, vert_spv, entry.spirv, 1, 4, null, no_blend) catch {
var buf: [512]u8 = undefined;
const text = std.fmt.bufPrint(&buf, "Shader {s}: the GPU refused it", .{entry.path}) catch "Shader: the GPU refused it";
if (core) |p| p.setMessage(p.active, text) else std.log.err("{s}", .{text});
@@ -179,23 +181,6 @@ pub fn sync(post: *Post, gpa: std.mem.Allocator, device: *c.SDL_GPUDevice, forma
}
}
-fn makePipeline(device: *c.SDL_GPUDevice, format: c.SDL_GPUTextureFormat, frag: []const u8, samplers: u32, uniform_buffers: u32) !*Pipeline {
- const vs = try gui.makeShader(device, vert_spv, c.SDL_GPU_SHADERSTAGE_VERTEX, 0, 0);
- defer c.SDL_ReleaseGPUShader(device, vs);
- const fs = try gui.makeShader(device, frag, c.SDL_GPU_SHADERSTAGE_FRAGMENT, samplers, uniform_buffers);
- defer c.SDL_ReleaseGPUShader(device, fs);
- var target = c.SDL_GPUColorTargetDescription{ .format = format, .blend_state = std.mem.zeroes(c.SDL_GPUColorTargetBlendState) };
- var info = std.mem.zeroes(c.SDL_GPUGraphicsPipelineCreateInfo);
- info.vertex_shader = vs;
- info.fragment_shader = fs;
- info.primitive_type = c.SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
- info.rasterizer_state.fill_mode = c.SDL_GPU_FILLMODE_FILL;
- info.rasterizer_state.cull_mode = c.SDL_GPU_CULLMODE_NONE;
- info.multisample_state.sample_count = c.SDL_GPU_SAMPLECOUNT_1;
- info.target_info = .{ .color_target_descriptions = &target, .num_color_targets = 1 };
- return c.SDL_CreateGPUGraphicsPipeline(device, &info) orelse error.GpuCreate;
-}
-
/// A pass is ready to draw.
pub fn ready(post: *const Post) bool {
for (post.passes[0..post.len]) |pass| if (pass.pipeline != null) return true;