diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 70be1a96b..b42b83276 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -273,6 +273,15 @@ pub inline fn textureOptions(self: Metal) Texture.Options { .cpu_cache_mode = .write_combined, .storage_mode = self.default_storage_mode, }, + .usage = .{ + // textureOptions is currently only used for custom shaders, + // which require both the shader read (for when multiple shaders + // are chained) and render target (for the final output) usage. + // Disabling either of these will lead to metal validation + // errors in Xcode. + .shader_read = true, + .render_target = true, + }, }; } @@ -311,6 +320,10 @@ pub inline fn imageTextureOptions( .cpu_cache_mode = .write_combined, .storage_mode = self.default_storage_mode, }, + .usage = .{ + // We only need to read from this texture from a shader. + .shader_read = true, + }, }; } @@ -334,6 +347,10 @@ pub fn initAtlasTexture( .cpu_cache_mode = .write_combined, .storage_mode = self.default_storage_mode, }, + .usage = .{ + // We only need to read from this texture from a shader. + .shader_read = true, + }, }, atlas.size, atlas.size, diff --git a/src/renderer/metal/Texture.zig b/src/renderer/metal/Texture.zig index 5e6ef78d0..cde50e8de 100644 --- a/src/renderer/metal/Texture.zig +++ b/src/renderer/metal/Texture.zig @@ -18,6 +18,7 @@ pub const Options = struct { device: objc.Object, pixel_format: mtl.MTLPixelFormat, resource_options: mtl.MTLResourceOptions, + usage: mtl.MTLTextureUsage, }; /// The underlying MTLTexture Object. @@ -57,6 +58,7 @@ pub fn init( desc.setProperty("width", @as(c_ulong, width)); desc.setProperty("height", @as(c_ulong, height)); desc.setProperty("resourceOptions", opts.resource_options); + desc.setProperty("usage", opts.usage); // Initialize const id = opts.device.msgSend(