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,