Fix a memory leak in metal ShaderModule.

Make the MetalFunctionData object returned by GetFunction() own a
reference to the MTLFunction and release it on destruction.
This commit is contained in:
Stephen White 2018-04-26 15:16:16 -04:00 committed by Corentin Wallez
parent 1ec5782bff
commit 8f2050540d
2 changed files with 6 additions and 2 deletions

View File

@ -76,8 +76,9 @@ namespace backend { namespace metal {
const auto& module = ToBackend(builder->GetStageInfo(stage).module); const auto& module = ToBackend(builder->GetStageInfo(stage).module);
const auto& entryPoint = builder->GetStageInfo(stage).entryPoint; const auto& entryPoint = builder->GetStageInfo(stage).entryPoint;
id<MTLFunction> function = ShaderModule::MetalFunctionData data =
module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout())).function; module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout()));
id<MTLFunction> function = data.function;
switch (stage) { switch (stage) {
case nxt::ShaderStage::Vertex: case nxt::ShaderStage::Vertex:

View File

@ -34,6 +34,9 @@ namespace backend { namespace metal {
struct MetalFunctionData { struct MetalFunctionData {
id<MTLFunction> function; id<MTLFunction> function;
MTLSize localWorkgroupSize; MTLSize localWorkgroupSize;
~MetalFunctionData() {
[function release];
}
}; };
MetalFunctionData GetFunction(const char* functionName, const PipelineLayout* layout) const; MetalFunctionData GetFunction(const char* functionName, const PipelineLayout* layout) const;