Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when shader validation is enabled. #2421

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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