From 2d600c4e6bbf1f6e03471ff601b04b0ef7e5db29 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 15 Nov 2026 00:21:57 -0600 Subject: [PATCH] Fix invalid attributes passed to CVMetalTextureCache --- .../video/ffmpeg-renderers/plvk_objc.mm | 18 +++++++++++++----- .../video/ffmpeg-renderers/vt_metal.mm | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/plvk_objc.mm b/app/streaming/video/ffmpeg-renderers/plvk_objc.mm index 22aee7c2..1e9969dc 100644 --- a/app/streaming/video/ffmpeg-renderers/plvk_objc.mm +++ b/app/streaming/video/ffmpeg-renderers/plvk_objc.mm @@ -38,11 +38,19 @@ MetalVulkanTextureFactory::MetalVulkanTextureFactory(pl_vulkan vulkan) : return; } - CFStringRef keys[1] = { kCVMetalTextureUsage }; - NSUInteger values[1] = { MTLTextureUsageShaderRead }; - auto cacheAttributes = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, 1, nullptr, nullptr); - int err = CVMetalTextureCacheCreate(kCFAllocatorDefault, cacheAttributes, device, nullptr, (CVMetalTextureCacheRef*)&m_TextureCache); - CFRelease(cacheAttributes); + // Create the Metal texture cache for our CVPixelBuffers + NSDictionary *textureAttributes = @{ + // NB: kCVMetalTextureUsage is documented as if it's a key used in the + // cacheAttributes dictionary, but it is actually for textureAttributes + // (as confirmed by Metal Validation failures for incorrect usages). + (__bridge NSString *)kCVMetalTextureUsage: @(MTLTextureUsageShaderRead) + }; + + int err = CVMetalTextureCacheCreate(kCFAllocatorDefault, + nullptr, + device, + (__bridge CFDictionaryRef)textureAttributes, + (CVMetalTextureCacheRef*)&m_TextureCache); if (err != kCVReturnSuccess) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, diff --git a/app/streaming/video/ffmpeg-renderers/vt_metal.mm b/app/streaming/video/ffmpeg-renderers/vt_metal.mm index 2852d437..bd559889 100644 --- a/app/streaming/video/ffmpeg-renderers/vt_metal.mm +++ b/app/streaming/video/ffmpeg-renderers/vt_metal.mm @@ -692,11 +692,18 @@ public: } // Create the Metal texture cache for our CVPixelBuffers - CFStringRef keys[1] = { kCVMetalTextureUsage }; - NSUInteger values[1] = { MTLTextureUsageShaderRead }; - auto cacheAttributes = CFDictionaryCreate(kCFAllocatorDefault, (const void**)keys, (const void**)values, 1, nullptr, nullptr); - err = CVMetalTextureCacheCreate(kCFAllocatorDefault, cacheAttributes, device, nullptr, &m_TextureCache); - CFRelease(cacheAttributes); + NSDictionary *textureAttributes = @{ + // NB: kCVMetalTextureUsage is documented as if it's a key used in the + // cacheAttributes dictionary, but it is actually for textureAttributes + // (as confirmed by Metal Validation failures for incorrect usages). + (__bridge NSString *)kCVMetalTextureUsage: @(MTLTextureUsageShaderRead) + }; + + err = CVMetalTextureCacheCreate(kCFAllocatorDefault, + nullptr, + device, + (__bridge CFDictionaryRef)textureAttributes, + &m_TextureCache); if (err != kCVReturnSuccess) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,