Implement GrMtlGpu::compile().
Revises how we build/find GrMtlPipelineStates to no longer be dependent on GrRenderTarget. Change-Id: I54abcc3a28505ae4ef6e1944f839fbe78d28cf7e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379058 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
7e685f0377
commit
84ded4d46c
@ -58,6 +58,8 @@ public:
|
||||
|
||||
bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
|
||||
|
||||
bool precompileShader(const SkData& key, const SkData& data) override;
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
|
||||
|
||||
@ -112,8 +114,6 @@ public:
|
||||
this->didWriteToSurface(surface, origin, bounds);
|
||||
}
|
||||
|
||||
bool precompileShader(const SkData& key, const SkData& data) override;
|
||||
|
||||
private:
|
||||
GrMtlGpu(GrDirectContext*, const GrContextOptions&, id<MTLDevice>,
|
||||
id<MTLCommandQueue>, GrMTLHandle binaryArchive, MTLFeatureSet);
|
||||
|
@ -1083,8 +1083,14 @@ void GrMtlGpu::deleteBackendTexture(const GrBackendTexture& tex) {
|
||||
// Nothing to do here, will get cleaned up when the GrBackendTexture object goes away
|
||||
}
|
||||
|
||||
bool GrMtlGpu::compile(const GrProgramDesc&, const GrProgramInfo&) {
|
||||
return false;
|
||||
bool GrMtlGpu::compile(const GrProgramDesc& desc, const GrProgramInfo& programInfo) {
|
||||
auto pipelineState = this->resourceProvider().findOrCreateCompatiblePipelineState(
|
||||
desc, programInfo);
|
||||
return SkToBool(pipelineState);
|
||||
}
|
||||
|
||||
bool GrMtlGpu::precompileShader(const SkData& key, const SkData& data) {
|
||||
return GrMtlPipelineStateBuilder::PrecompileShaders(this, data);
|
||||
}
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
@ -1456,10 +1462,6 @@ void GrMtlGpu::resolveTexture(id<MTLTexture> resolveTexture, id<MTLTexture> colo
|
||||
cmdEncoder.label = @"resolveTexture";
|
||||
}
|
||||
|
||||
bool GrMtlGpu::precompileShader(const SkData& key, const SkData& data) {
|
||||
return GrMtlPipelineStateBuilder::PrecompileShaders(this, data);
|
||||
}
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
void GrMtlGpu::testingOnly_startCapture() {
|
||||
if (@available(macOS 10.13, iOS 11.0, *)) {
|
||||
|
@ -69,8 +69,15 @@ static MTLPrimitiveType gr_to_mtl_primitive(GrPrimitiveType primitiveType) {
|
||||
|
||||
bool GrMtlOpsRenderPass::onBindPipeline(const GrProgramInfo& programInfo,
|
||||
const SkRect& drawBounds) {
|
||||
const GrMtlCaps& caps = fGpu->mtlCaps();
|
||||
GrProgramDesc programDesc = caps.makeDesc(fRenderTarget, programInfo,
|
||||
GrCaps::ProgramDescOverrideFlags::kNone);
|
||||
if (!programDesc.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fActivePipelineState = fGpu->resourceProvider().findOrCreateCompatiblePipelineState(
|
||||
fRenderTarget, programInfo);
|
||||
programDesc, programInfo);
|
||||
if (!fActivePipelineState) {
|
||||
return false;
|
||||
}
|
||||
|
@ -33,17 +33,15 @@ public:
|
||||
* @return the created pipeline if generation was successful; nullptr otherwise
|
||||
*/
|
||||
static GrMtlPipelineState* CreatePipelineState(GrMtlGpu*,
|
||||
GrRenderTarget*,
|
||||
const GrProgramDesc&,
|
||||
const GrProgramInfo&);
|
||||
|
||||
static bool PrecompileShaders(GrMtlGpu*, const SkData&);
|
||||
|
||||
private:
|
||||
GrMtlPipelineStateBuilder(GrMtlGpu*, GrRenderTarget*,
|
||||
const GrProgramDesc&, const GrProgramInfo&);
|
||||
GrMtlPipelineStateBuilder(GrMtlGpu*, const GrProgramDesc&, const GrProgramInfo&);
|
||||
|
||||
GrMtlPipelineState* finalize(GrRenderTarget*, const GrProgramDesc&, const GrProgramInfo&);
|
||||
GrMtlPipelineState* finalize(const GrProgramDesc&, const GrProgramInfo&);
|
||||
|
||||
const GrCaps* caps() const override;
|
||||
|
||||
|
@ -28,23 +28,21 @@
|
||||
|
||||
GrMtlPipelineState* GrMtlPipelineStateBuilder::CreatePipelineState(
|
||||
GrMtlGpu* gpu,
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo) {
|
||||
GrAutoLocaleSetter als("C");
|
||||
GrMtlPipelineStateBuilder builder(gpu, renderTarget, desc, programInfo);
|
||||
GrMtlPipelineStateBuilder builder(gpu, desc, programInfo);
|
||||
|
||||
if (!builder.emitAndInstallProcs()) {
|
||||
return nullptr;
|
||||
}
|
||||
return builder.finalize(renderTarget, desc, programInfo);
|
||||
return builder.finalize(desc, programInfo);
|
||||
}
|
||||
|
||||
GrMtlPipelineStateBuilder::GrMtlPipelineStateBuilder(GrMtlGpu* gpu,
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo)
|
||||
: INHERITED(renderTarget, desc, programInfo)
|
||||
: INHERITED(nullptr, desc, programInfo)
|
||||
, fGpu(gpu)
|
||||
, fUniformHandler(this)
|
||||
, fVaryingHandler(this) {
|
||||
@ -357,8 +355,7 @@ uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment) {
|
||||
return offset + offsetDiff;
|
||||
}
|
||||
|
||||
GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo) {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
|
||||
@ -509,7 +506,7 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTa
|
||||
pipelineDescriptor.fragmentFunction = fragmentFunction;
|
||||
pipelineDescriptor.vertexDescriptor = create_vertex_descriptor(programInfo.primProc());
|
||||
|
||||
MTLPixelFormat pixelFormat = GrBackendFormatAsMTLPixelFormat(renderTarget->backendFormat());
|
||||
MTLPixelFormat pixelFormat = GrBackendFormatAsMTLPixelFormat(programInfo.backendFormat());
|
||||
if (pixelFormat == MTLPixelFormatInvalid) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -517,7 +514,7 @@ GrMtlPipelineState* GrMtlPipelineStateBuilder::finalize(GrRenderTarget* renderTa
|
||||
pipelineDescriptor.colorAttachments[0] = create_color_attachment(pixelFormat,
|
||||
programInfo.pipeline());
|
||||
pipelineDescriptor.sampleCount = programInfo.numRasterSamples();
|
||||
bool hasStencilAttachment = SkToBool(renderTarget->getStencilAttachment());
|
||||
bool hasStencilAttachment = programInfo.isStencilEnabled();
|
||||
GrMtlCaps* mtlCaps = (GrMtlCaps*)this->caps();
|
||||
pipelineDescriptor.stencilAttachmentPixelFormat =
|
||||
hasStencilAttachment ? mtlCaps->preferredStencilFormat() : MTLPixelFormatInvalid;
|
||||
|
@ -25,7 +25,7 @@ class GrMtlResourceProvider {
|
||||
public:
|
||||
GrMtlResourceProvider(GrMtlGpu* gpu);
|
||||
|
||||
GrMtlPipelineState* findOrCreateCompatiblePipelineState(GrRenderTarget*,
|
||||
GrMtlPipelineState* findOrCreateCompatiblePipelineState(const GrProgramDesc&,
|
||||
const GrProgramInfo&);
|
||||
|
||||
// Finds or creates a compatible MTLDepthStencilState based on the GrStencilSettings.
|
||||
@ -53,7 +53,7 @@ private:
|
||||
~PipelineStateCache();
|
||||
|
||||
void release();
|
||||
GrMtlPipelineState* refPipelineState(GrRenderTarget*, const GrProgramInfo&);
|
||||
GrMtlPipelineState* refPipelineState(const GrProgramDesc&, const GrProgramInfo&);
|
||||
|
||||
private:
|
||||
struct Entry;
|
||||
|
@ -27,9 +27,9 @@ GrMtlResourceProvider::GrMtlResourceProvider(GrMtlGpu* gpu)
|
||||
}
|
||||
|
||||
GrMtlPipelineState* GrMtlResourceProvider::findOrCreateCompatiblePipelineState(
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& programDesc,
|
||||
const GrProgramInfo& programInfo) {
|
||||
return fPipelineStateCache->refPipelineState(renderTarget, programInfo);
|
||||
return fPipelineStateCache->refPipelineState(programDesc, programInfo);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -114,28 +114,19 @@ void GrMtlResourceProvider::PipelineStateCache::release() {
|
||||
}
|
||||
|
||||
GrMtlPipelineState* GrMtlResourceProvider::PipelineStateCache::refPipelineState(
|
||||
GrRenderTarget* renderTarget,
|
||||
const GrProgramDesc& desc,
|
||||
const GrProgramInfo& programInfo) {
|
||||
#ifdef GR_PIPELINE_STATE_CACHE_STATS
|
||||
++fTotalRequests;
|
||||
#endif
|
||||
|
||||
const GrMtlCaps& caps = fGpu->mtlCaps();
|
||||
|
||||
GrProgramDesc desc = caps.makeDesc(renderTarget, programInfo,
|
||||
GrCaps::ProgramDescOverrideFlags::kNone);
|
||||
if (!desc.isValid()) {
|
||||
GrCapsDebugf(fGpu->caps(), "Failed to build mtl program descriptor!\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Entry>* entry = fMap.find(desc);
|
||||
if (!entry) {
|
||||
#ifdef GR_PIPELINE_STATE_CACHE_STATS
|
||||
++fCacheMisses;
|
||||
#endif
|
||||
GrMtlPipelineState* pipelineState(GrMtlPipelineStateBuilder::CreatePipelineState(
|
||||
fGpu, renderTarget, desc, programInfo));
|
||||
fGpu, desc, programInfo));
|
||||
if (!pipelineState) {
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user