From 06f95df9d216cd6b88bcd9faec964c832dd3fa3b Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 05:27:35 -0800 Subject: [PATCH] :racehorse: Make the hardware decode's plane textures read-only The Metal bundle's textures over a decode's output planes declared ShaderRead and ShaderWrite. No host arm needs the write: VA-API and NVDEC land a picture in the plane's buffer (the surface's device cache or its pages), by the CPU or a GPU copy into that buffer, never through a texture or a shader, and no host path checks the texture's usage. The decode op already names both planes written whatever their usage (rgfxEncodeVideoSession). The usage only made the device take a plane as written wherever a shader with no interface at hand bound it, on the guest (RgfxSurfaceBindings) and on the host (usage_writes, a laid-out cache's use), each a download or a dirty shape of a surface no shader wrote. The textures now declare ShaderRead alone. --- guest/bundle/src/RgfxMetalDevice+Video.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guest/bundle/src/RgfxMetalDevice+Video.mm b/guest/bundle/src/RgfxMetalDevice+Video.mm index 3dbf1b81d..c3c85939c 100644 --- a/guest/bundle/src/RgfxMetalDevice+Video.mm +++ b/guest/bundle/src/RgfxMetalDevice+Video.mm @@ -281,7 +281,11 @@ id planeTexture(RgfxMetalDevice *device, IOSurfaceRef surface, size_ width:w height:h mipmapped:NO]; - desc.usage = MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite; + // Read alone: the host's decode writes the plane's bytes in the surface's device cache or its + // pages, not a shader, and the decode op names the texture written whatever its usage + // (rgfxEncodeVideoSession). A usage with ShaderWrite would have the device take the plane as + // written wherever a shader with no interface at hand binds it. + desc.usage = MTLTextureUsageShaderRead; auto make = [&]() -> id { if (width == 0) return [device newTextureWithDescriptor:desc iosurface:surface plane:plane];