From 3d5bdccc73aada01e04b32a160e653a06e0c3cff Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:46:21 -0800 Subject: [PATCH] Fix crash when shader validation is enabled. --- .../Commands/MVKCommandResourceFactory.mm | 7 ++++++- MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h | 8 -------- MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm | 17 ----------------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm index c8f346fb0..8a504d61f 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm @@ -666,9 +666,14 @@ static void getSwizzleString(char swizzleStr[4], VkComponentMapping vkMapping) { id MVKCommandResourceFactory::newMTLComputePipelineState(const char* funcName, MVKVulkanAPIDeviceObject* owner) { id mtlFunc = newFunctionNamed(funcName); // temp retain + // Providing a function directly may cause issues with Metal shader validation layer object + // management for some reason, so create a temporary pipeline descriptor to provide instead. + MTLComputePipelineDescriptor* plDesc = [MTLComputePipelineDescriptor new]; // temp retain + plDesc.computeFunction = mtlFunc; MVKComputePipelineCompiler* plc = new MVKComputePipelineCompiler(owner); - id cps = plc->newMTLComputePipelineState(mtlFunc); // retained + id cps = plc->newMTLComputePipelineState(plDesc); // retained plc->destroy(); + [plDesc release]; // temp release [mtlFunc release]; // temp release return cps; } diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h index 4f72ba2a9..284a7ddb8 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h @@ -594,14 +594,6 @@ class MVKComputePipelineCompiler : public MVKMetalCompiler { public: - /** - * Returns a new (retained) MTLComputePipelineState object compiled from the MTLFunction. - * - * If the Metal pipeline compiler does not return within MVKConfiguration::metalCompileTimeout - * nanoseconds, an error will be generated and logged, and nil will be returned. - */ - id newMTLComputePipelineState(id mtlFunction); - /** * Returns a new (retained) MTLComputePipelineState object compiled from the MTLComputePipelineDescriptor. * diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index 7a0942930..2440549df 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -2823,23 +2823,6 @@ void serialize(Archive & archive, MVKCompressor& comp) { #pragma mark - #pragma mark MVKComputePipelineCompiler -id MVKComputePipelineCompiler::newMTLComputePipelineState(id mtlFunction) { - unique_lock lock(_completionLock); - - compile(lock, ^{ - auto mtlDev = getMTLDevice(); - @synchronized (mtlDev) { - [mtlDev newComputePipelineStateWithFunction: mtlFunction - completionHandler: ^(id ps, NSError* error) { - bool isLate = compileComplete(ps, error); - if (isLate) { destroy(); } - }]; - } - }); - - return [_mtlComputePipelineState retain]; -} - id MVKComputePipelineCompiler::newMTLComputePipelineState(MTLComputePipelineDescriptor* plDesc) { unique_lock lock(_completionLock);