Skip to content

Commit

Permalink
Merge pull request #2421 from squidbus/fix-crash
Browse files Browse the repository at this point in the history
Fix crash when shader validation is enabled.
  • Loading branch information
cdavis5e authored Jan 14, 2025
2 parents 30ec0de + 3d5bdcc commit bd0a550
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
7 changes: 6 additions & 1 deletion MoltenVK/MoltenVK/Commands/MVKCommandResourceFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,14 @@ static void getSwizzleString(char swizzleStr[4], VkComponentMapping vkMapping) {
id<MTLComputePipelineState> MVKCommandResourceFactory::newMTLComputePipelineState(const char* funcName,
MVKVulkanAPIDeviceObject* owner) {
id<MTLFunction> 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<MTLComputePipelineState> cps = plc->newMTLComputePipelineState(mtlFunc); // retained
id<MTLComputePipelineState> cps = plc->newMTLComputePipelineState(plDesc); // retained
plc->destroy();
[plDesc release]; // temp release
[mtlFunc release]; // temp release
return cps;
}
Expand Down
8 changes: 0 additions & 8 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MTLComputePipelineState> newMTLComputePipelineState(id<MTLFunction> mtlFunction);

/**
* Returns a new (retained) MTLComputePipelineState object compiled from the MTLComputePipelineDescriptor.
*
Expand Down
17 changes: 0 additions & 17 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2823,23 +2823,6 @@ void serialize(Archive & archive, MVKCompressor<C>& comp) {
#pragma mark -
#pragma mark MVKComputePipelineCompiler

id<MTLComputePipelineState> MVKComputePipelineCompiler::newMTLComputePipelineState(id<MTLFunction> mtlFunction) {
unique_lock<mutex> lock(_completionLock);

compile(lock, ^{
auto mtlDev = getMTLDevice();
@synchronized (mtlDev) {
[mtlDev newComputePipelineStateWithFunction: mtlFunction
completionHandler: ^(id<MTLComputePipelineState> ps, NSError* error) {
bool isLate = compileComplete(ps, error);
if (isLate) { destroy(); }
}];
}
});

return [_mtlComputePipelineState retain];
}

id<MTLComputePipelineState> MVKComputePipelineCompiler::newMTLComputePipelineState(MTLComputePipelineDescriptor* plDesc) {
unique_lock<mutex> lock(_completionLock);

Expand Down

0 comments on commit bd0a550

Please sign in to comment.