Revert "Metal: First pass at async pipelineState creation."
This reverts commit adf36be2f9
.
Reason for revert: breaking Flutter roll
Original change's description:
> Metal: First pass at async pipelineState creation.
>
> Trying a basic approach to generating pipelineStates asynchronously.
> Rather than managing the caching ourselves, we depend on the Apple
> cache. When a pipelineState is created during the regular path, it
> should find it in the Apple cache and return immediately.
>
> To avoid too much duplication of the shader compilation step we cache
> the MTLLibrarys locally until the final PSO is cached.
>
> Bug: skia:12141
> Change-Id: Id8f6ba7caee33b4c7f6a5af0e8ad5b84993b1246
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/421321
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
TBR=jvanverth@google.com,brianosman@google.com,chinmaygarde@google.com
Change-Id: Iad7c4c87c22d0d002809c215878439fdb098f54a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:12141
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/422117
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
This commit is contained in:
parent
9204ca678b
commit
688d3180ab
@ -24,9 +24,8 @@ class GrMtlPipelineState;
|
|||||||
class SkReadBuffer;
|
class SkReadBuffer;
|
||||||
|
|
||||||
struct GrMtlPrecompiledLibraries {
|
struct GrMtlPrecompiledLibraries {
|
||||||
// TODO: wrap these in sk_cfp<> or unique_ptr<> when we remove ARC
|
// TODO: wrap this in sk_cfp<> or unique_ptr<> when we remove ARC
|
||||||
id<MTLLibrary> fVertexLibrary;
|
id<MTLRenderPipelineState> fPipelineState;
|
||||||
id<MTLLibrary> fFragmentLibrary;
|
|
||||||
bool fRTHeight = false;
|
bool fRTHeight = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -480,12 +480,31 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(
|
|||||||
// Geometry shaders are not supported
|
// Geometry shaders are not supported
|
||||||
SkASSERT(!this->geometryProcessor().willUseGeoShader());
|
SkASSERT(!this->geometryProcessor().willUseGeoShader());
|
||||||
|
|
||||||
// Set up for cache if needed
|
if (precompiledLibs) {
|
||||||
|
SkASSERT(precompiledLibs->fPipelineState);
|
||||||
|
if (precompiledLibs->fRTHeight) {
|
||||||
|
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
|
||||||
|
}
|
||||||
|
uint32_t bufferSize = buffer_size(fUniformHandler.fCurrentUBOOffset,
|
||||||
|
fUniformHandler.fCurrentUBOMaxAlignment);
|
||||||
|
return new GrMtlPipelineState(fGpu,
|
||||||
|
precompiledLibs->fPipelineState,
|
||||||
|
GrBackendFormatAsMTLPixelFormat(programInfo.backendFormat()),
|
||||||
|
fUniformHandles,
|
||||||
|
fUniformHandler.fUniforms,
|
||||||
|
bufferSize,
|
||||||
|
(uint32_t)fUniformHandler.numSamplers(),
|
||||||
|
std::move(fGeometryProcessor),
|
||||||
|
std::move(fXferProcessor),
|
||||||
|
std::move(fFPImpls));
|
||||||
|
}
|
||||||
|
|
||||||
|
// build from scratch
|
||||||
std::unique_ptr<SkBinaryWriteBuffer> writer;
|
std::unique_ptr<SkBinaryWriteBuffer> writer;
|
||||||
|
|
||||||
sk_sp<SkData> cached;
|
sk_sp<SkData> cached;
|
||||||
auto persistentCache = fGpu->getContext()->priv().getPersistentCache();
|
auto persistentCache = fGpu->getContext()->priv().getPersistentCache();
|
||||||
if (persistentCache && !precompiledLibs) {
|
if (persistentCache) {
|
||||||
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc.asKey(), desc.keyLength());
|
sk_sp<SkData> key = SkData::MakeWithoutCopy(desc.asKey(), desc.keyLength());
|
||||||
cached = persistentCache->load(*key);
|
cached = persistentCache->load(*key);
|
||||||
}
|
}
|
||||||
@ -515,19 +534,6 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(
|
|||||||
SkASSERT(pipelineDescriptor.vertexDescriptor);
|
SkASSERT(pipelineDescriptor.vertexDescriptor);
|
||||||
SkASSERT(pipelineDescriptor.colorAttachments[0]);
|
SkASSERT(pipelineDescriptor.colorAttachments[0]);
|
||||||
|
|
||||||
if (precompiledLibs) {
|
|
||||||
SkASSERT(precompiledLibs->fVertexLibrary);
|
|
||||||
SkASSERT(precompiledLibs->fFragmentLibrary);
|
|
||||||
pipelineDescriptor.vertexFunction =
|
|
||||||
[precompiledLibs->fVertexLibrary newFunctionWithName: @"vertexMain"];
|
|
||||||
pipelineDescriptor.fragmentFunction =
|
|
||||||
[precompiledLibs->fFragmentLibrary newFunctionWithName: @"fragmentMain"];
|
|
||||||
SkASSERT(pipelineDescriptor.vertexFunction);
|
|
||||||
SkASSERT(pipelineDescriptor.fragmentFunction);
|
|
||||||
if (precompiledLibs->fRTHeight) {
|
|
||||||
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
id<MTLLibrary> shaderLibraries[kGrShaderTypeCount];
|
id<MTLLibrary> shaderLibraries[kGrShaderTypeCount];
|
||||||
|
|
||||||
fVS.extensions().appendf("#extension GL_ARB_separate_shader_objects : enable\n");
|
fVS.extensions().appendf("#extension GL_ARB_separate_shader_objects : enable\n");
|
||||||
@ -652,7 +658,6 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(
|
|||||||
[shaderLibraries[kVertex_GrShaderType] newFunctionWithName: @"vertexMain"];
|
[shaderLibraries[kVertex_GrShaderType] newFunctionWithName: @"vertexMain"];
|
||||||
pipelineDescriptor.fragmentFunction =
|
pipelineDescriptor.fragmentFunction =
|
||||||
[shaderLibraries[kFragment_GrShaderType] newFunctionWithName: @"fragmentMain"];
|
[shaderLibraries[kFragment_GrShaderType] newFunctionWithName: @"fragmentMain"];
|
||||||
}
|
|
||||||
|
|
||||||
if (pipelineDescriptor.vertexFunction == nil) {
|
if (pipelineDescriptor.vertexFunction == nil) {
|
||||||
SkDebugf("Couldn't find vertexMain() in library\n");
|
SkDebugf("Couldn't find vertexMain() in library\n");
|
||||||
@ -750,11 +755,13 @@ bool GrMtlPipelineStateBuilder::PrecompileShaders(GrMtlGpu* gpu, const SkData& c
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id<MTLLibrary> vertexLibrary;
|
||||||
|
id<MTLLibrary> fragmentLibrary;
|
||||||
switch (shaderType) {
|
switch (shaderType) {
|
||||||
case kMSL_Tag: {
|
case kMSL_Tag: {
|
||||||
precompiledLibs->fVertexLibrary =
|
vertexLibrary =
|
||||||
GrCompileMtlShaderLibrary(gpu, shaders[kVertex_GrShaderType], errorHandler);
|
GrCompileMtlShaderLibrary(gpu, shaders[kVertex_GrShaderType], errorHandler);
|
||||||
precompiledLibs->fFragmentLibrary =
|
fragmentLibrary =
|
||||||
GrCompileMtlShaderLibrary(gpu, shaders[kFragment_GrShaderType], errorHandler);
|
GrCompileMtlShaderLibrary(gpu, shaders[kFragment_GrShaderType], errorHandler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -779,9 +786,9 @@ bool GrMtlPipelineStateBuilder::PrecompileShaders(GrMtlGpu* gpu, const SkData& c
|
|||||||
errorHandler)) {
|
errorHandler)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
precompiledLibs->fVertexLibrary =
|
vertexLibrary =
|
||||||
GrCompileMtlShaderLibrary(gpu, msl[kVertex_GrShaderType], errorHandler);
|
GrCompileMtlShaderLibrary(gpu, msl[kVertex_GrShaderType], errorHandler);
|
||||||
precompiledLibs->fFragmentLibrary =
|
fragmentLibrary =
|
||||||
GrCompileMtlShaderLibrary(gpu, msl[kFragment_GrShaderType], errorHandler);
|
GrCompileMtlShaderLibrary(gpu, msl[kFragment_GrShaderType], errorHandler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -792,9 +799,9 @@ bool GrMtlPipelineStateBuilder::PrecompileShaders(GrMtlGpu* gpu, const SkData& c
|
|||||||
}
|
}
|
||||||
|
|
||||||
pipelineDescriptor.vertexFunction =
|
pipelineDescriptor.vertexFunction =
|
||||||
[precompiledLibs->fVertexLibrary newFunctionWithName: @"vertexMain"];
|
[vertexLibrary newFunctionWithName: @"vertexMain"];
|
||||||
pipelineDescriptor.fragmentFunction =
|
pipelineDescriptor.fragmentFunction =
|
||||||
[precompiledLibs->fFragmentLibrary newFunctionWithName: @"fragmentMain"];
|
[fragmentLibrary newFunctionWithName: @"fragmentMain"];
|
||||||
|
|
||||||
NSError* error = nil;
|
NSError* error = nil;
|
||||||
#if GR_METAL_SDK_VERSION >= 230
|
#if GR_METAL_SDK_VERSION >= 230
|
||||||
@ -818,18 +825,19 @@ bool GrMtlPipelineStateBuilder::PrecompileShaders(GrMtlGpu* gpu, const SkData& c
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
TRACE_EVENT0("skia.shaders", "newRenderPipelineStateWithDescriptor");
|
TRACE_EVENT0("skia.shaders", "newRenderPipelineStateWithDescriptor");
|
||||||
MTLNewRenderPipelineStateCompletionHandler completionHandler =
|
#if defined(SK_BUILD_FOR_MAC)
|
||||||
^(id<MTLRenderPipelineState> state, NSError* error) {
|
precompiledLibs->fPipelineState =
|
||||||
|
GrMtlNewRenderPipelineStateWithDescriptor(gpu->device(), pipelineDescriptor, &error);
|
||||||
|
#else
|
||||||
|
precompiledLibs->fPipelineState =
|
||||||
|
[gpu->device() newRenderPipelineStateWithDescriptor: pipelineDescriptor
|
||||||
|
error: &error];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
if (error) {
|
if (error) {
|
||||||
SkDebugf("Error creating pipeline: %s\n",
|
SkDebugf("Error creating pipeline: %s\n",
|
||||||
[[error localizedDescription]
|
[[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]);
|
||||||
cStringUsingEncoding: NSASCIIStringEncoding]);
|
return false;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// kick off asynchronous pipeline build and depend on Apple's cache to manage it
|
|
||||||
[gpu->device() newRenderPipelineStateWithDescriptor: pipelineDescriptor
|
|
||||||
completionHandler: completionHandler];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
precompiledLibs->fRTHeight = inputs[kFragment_GrShaderType].fRTHeight;
|
precompiledLibs->fRTHeight = inputs[kFragment_GrShaderType].fRTHeight;
|
||||||
|
@ -131,10 +131,9 @@ GrMtlPipelineState* GrMtlResourceProvider::PipelineStateCache::onRefPipelineStat
|
|||||||
*stat = Stats::ProgramCacheResult::kHit;
|
*stat = Stats::ProgramCacheResult::kHit;
|
||||||
std::unique_ptr<Entry>* entry = fMap.find(desc);
|
std::unique_ptr<Entry>* entry = fMap.find(desc);
|
||||||
if (entry && !(*entry)->fPipelineState) {
|
if (entry && !(*entry)->fPipelineState) {
|
||||||
// We've pre-compiled the MSL shaders but don't yet have the pipelineState
|
// We've pre-compiled the MSL shaders but don't have the pipelineState
|
||||||
const GrMtlPrecompiledLibraries* precompiledLibs = &((*entry)->fPrecompiledLibraries);
|
const GrMtlPrecompiledLibraries* precompiledLibs = &((*entry)->fPrecompiledLibraries);
|
||||||
SkASSERT(precompiledLibs->fVertexLibrary);
|
SkASSERT(precompiledLibs->fPipelineState);
|
||||||
SkASSERT(precompiledLibs->fFragmentLibrary);
|
|
||||||
(*entry)->fPipelineState.reset(
|
(*entry)->fPipelineState.reset(
|
||||||
GrMtlPipelineStateBuilder::CreatePipelineState(fGpu, desc, programInfo,
|
GrMtlPipelineStateBuilder::CreatePipelineState(fGpu, desc, programInfo,
|
||||||
precompiledLibs));
|
precompiledLibs));
|
||||||
@ -144,9 +143,8 @@ GrMtlPipelineState* GrMtlResourceProvider::PipelineStateCache::onRefPipelineStat
|
|||||||
fStats.incNumCompilationFailures();
|
fStats.incNumCompilationFailures();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// release the libraries
|
// release the ref on the pipeline state
|
||||||
(*entry)->fPrecompiledLibraries.fVertexLibrary = nil;
|
(*entry)->fPrecompiledLibraries.fPipelineState = nil;
|
||||||
(*entry)->fPrecompiledLibraries.fFragmentLibrary = nil;
|
|
||||||
|
|
||||||
fStats.incNumPartialCompilationSuccesses();
|
fStats.incNumPartialCompilationSuccesses();
|
||||||
*stat = Stats::ProgramCacheResult::kPartial;
|
*stat = Stats::ProgramCacheResult::kPartial;
|
||||||
|
Loading…
Reference in New Issue
Block a user