Skip to content

Commit 3d5bdcc

Browse files
committed
Fix crash when shader validation is enabled.
1 parent 9f0b616 commit 3d5bdcc

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,14 @@ static void getSwizzleString(char swizzleStr[4], VkComponentMapping vkMapping) {
666666
id<MTLComputePipelineState> MVKCommandResourceFactory::newMTLComputePipelineState(const char* funcName,
667667
MVKVulkanAPIDeviceObject* owner) {
668668
id<MTLFunction> mtlFunc = newFunctionNamed(funcName); // temp retain
669+
// Providing a function directly may cause issues with Metal shader validation layer object
670+
// management for some reason, so create a temporary pipeline descriptor to provide instead.
671+
MTLComputePipelineDescriptor* plDesc = [MTLComputePipelineDescriptor new]; // temp retain
672+
plDesc.computeFunction = mtlFunc;
669673
MVKComputePipelineCompiler* plc = new MVKComputePipelineCompiler(owner);
670-
id<MTLComputePipelineState> cps = plc->newMTLComputePipelineState(mtlFunc); // retained
674+
id<MTLComputePipelineState> cps = plc->newMTLComputePipelineState(plDesc); // retained
671675
plc->destroy();
676+
[plDesc release]; // temp release
672677
[mtlFunc release]; // temp release
673678
return cps;
674679
}

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,6 @@ class MVKComputePipelineCompiler : public MVKMetalCompiler {
594594

595595
public:
596596

597-
/**
598-
* Returns a new (retained) MTLComputePipelineState object compiled from the MTLFunction.
599-
*
600-
* If the Metal pipeline compiler does not return within MVKConfiguration::metalCompileTimeout
601-
* nanoseconds, an error will be generated and logged, and nil will be returned.
602-
*/
603-
id<MTLComputePipelineState> newMTLComputePipelineState(id<MTLFunction> mtlFunction);
604-
605597
/**
606598
* Returns a new (retained) MTLComputePipelineState object compiled from the MTLComputePipelineDescriptor.
607599
*

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,23 +2823,6 @@ void serialize(Archive & archive, MVKCompressor<C>& comp) {
28232823
#pragma mark -
28242824
#pragma mark MVKComputePipelineCompiler
28252825

2826-
id<MTLComputePipelineState> MVKComputePipelineCompiler::newMTLComputePipelineState(id<MTLFunction> mtlFunction) {
2827-
unique_lock<mutex> lock(_completionLock);
2828-
2829-
compile(lock, ^{
2830-
auto mtlDev = getMTLDevice();
2831-
@synchronized (mtlDev) {
2832-
[mtlDev newComputePipelineStateWithFunction: mtlFunction
2833-
completionHandler: ^(id<MTLComputePipelineState> ps, NSError* error) {
2834-
bool isLate = compileComplete(ps, error);
2835-
if (isLate) { destroy(); }
2836-
}];
2837-
}
2838-
});
2839-
2840-
return [_mtlComputePipelineState retain];
2841-
}
2842-
28432826
id<MTLComputePipelineState> MVKComputePipelineCompiler::newMTLComputePipelineState(MTLComputePipelineDescriptor* plDesc) {
28442827
unique_lock<mutex> lock(_completionLock);
28452828

0 commit comments

Comments
 (0)