From 3020a30fb244cbdef43644923be1ae286c3e341c Mon Sep 17 00:00:00 2001 From: Rohit-Bevinahally Date: Sun, 23 Feb 2025 15:24:03 +0530 Subject: [PATCH] Do not set layer as opaque --- src/renderer/Metal.zig | 17 ++++++++++++----- src/renderer/shaders/cell.metal | 12 ++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 363f1b55a..21cd621d2 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -623,7 +623,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal { else => @compileError("unsupported target for Metal"), }; layer.setProperty("device", gpu_state.device.value); - layer.setProperty("opaque", options.config.background_opacity >= 1); + layer.setProperty("opaque", options.config.background_opacity >= 1 and options.config.background_image.value == null); layer.setProperty("displaySyncEnabled", options.config.vsync); // Set our layer's pixel format appropriately. @@ -1272,7 +1272,6 @@ pub fn updateFrame( // TODO: Is this expensive? Should we be checking if our // bg color has changed first before doing this work? { - std.log.info("Updating background color to {}", .{critical.bg}); const color = graphics.c.CGColorCreate( @ptrCast(self.terminal_colorspace), &[4]f64{ @@ -1339,7 +1338,11 @@ pub fn updateFrame( .replace_gray_alpha, .replace_rgb, .replace_rgba, - => try self.current_background_image.?.upload(self.alloc, self.gpu_state.device), + => try self.current_background_image.?.upload( + self.alloc, + self.gpu_state.device, + self.gpu_state.default_storage_mode, + ), .unload_pending, .unload_replace, @@ -1720,7 +1723,11 @@ fn drawBackgroundImage( @as(f32, @floatFromInt(self.size.terminal().height)), }, .mode = self.background_image_mode, - }}); + }}, .{ + // Indicate that the CPU writes to this resource but never reads it. + .cpu_cache_mode = .write_combined, + .storage_mode = self.gpu_state.default_storage_mode, + }); defer buf.deinit(); // Set our buffer @@ -2401,7 +2408,7 @@ pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void { CATransaction.msgSend(void, "begin", .{}); defer CATransaction.msgSend(void, "commit", .{}); - self.layer.setProperty("opaque", config.background_opacity >= 1); + self.layer.setProperty("opaque", config.background_opacity >= 1 and config.background_image.value == null); self.layer.setProperty("displaySyncEnabled", config.vsync); } diff --git a/src/renderer/shaders/cell.metal b/src/renderer/shaders/cell.metal index 8a20f731e..9cef3397c 100644 --- a/src/renderer/shaders/cell.metal +++ b/src/renderer/shaders/cell.metal @@ -262,12 +262,12 @@ fragment float4 cell_bg_fragment( int2 grid_pos = int2(floor((in.position.xy - uniforms.grid_padding.wx) / uniforms.cell_size)); float4 bg = float4(0.0); - // If we have any background transparency then we render bg-colored cells as - // fully transparent, since the background is handled by the layer bg color - // and we don't want to double up our bg color, but if our bg color is fully - // opaque then our layer is opaque and can't handle transparency, so we need - // to return the bg color directly instead. - if (uniforms.bg_color.a == 255) { + // If we have any background transparency or a background image, then we + // render bg-colored cells as fully transparent, since the background is + // handled by the layer bg color and we don't want to double up our bg color. + // But if our bg color is fully opaque, then our layer is opaque and can't + // handle transparency, so we need to return the bg color directly instead. + if (uniforms.bg_color.a == 255 && !uniforms.has_bg_image) { bg = in.bg_color; }