skia2/include/gpu/GrRecordingContext.h

286 lines
9.3 KiB
C
Raw Normal View History

/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrRecordingContext_DEFINED
#define GrRecordingContext_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/private/SkTArray.h"
#include "include/private/gpu/ganesh/GrImageContext.h"
#if GR_GPU_STATS && GR_TEST_UTILS
#include <map>
#include <string>
#endif
class GrAuditTrail;
class GrBackendFormat;
class GrDrawingManager;
class GrOnFlushCallbackObject;
class GrMemoryPool;
class GrProgramDesc;
class GrProgramInfo;
class GrProxyProvider;
class GrRecordingContextPriv;
class GrSurfaceProxy;
class GrTextBlobRedrawCoordinator;
class GrThreadSafeCache;
class SkArenaAlloc;
class SkCapabilities;
class SkJSONWriter;
namespace sktext::gpu {
class SubRunAllocator;
}
#if GR_TEST_UTILS
class SkString;
#endif
class GrRecordingContext : public GrImageContext {
public:
~GrRecordingContext() override;
SK_API GrBackendFormat defaultBackendFormat(SkColorType ct, GrRenderable renderable) const {
return INHERITED::defaultBackendFormat(ct, renderable);
}
/**
* Reports whether the GrDirectContext associated with this GrRecordingContext is abandoned.
* When called on a GrDirectContext it may actively check whether the underlying 3D API
* device/context has been disconnected before reporting the status. If so, calling this
* method will transition the GrDirectContext to the abandoned state.
*/
bool abandoned() override { return INHERITED::abandoned(); }
/*
* Can a SkSurface be created with the given color type. To check whether MSAA is supported
* use maxSurfaceSampleCountForColorType().
*/
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const {
if (kR16G16_unorm_SkColorType == colorType ||
kA16_unorm_SkColorType == colorType ||
kA16_float_SkColorType == colorType ||
kR16G16_float_SkColorType == colorType ||
kR16G16B16A16_unorm_SkColorType == colorType ||
kGray_8_SkColorType == colorType) {
return false;
}
return this->maxSurfaceSampleCountForColorType(colorType) > 0;
}
/**
* Gets the maximum supported texture size.
*/
SK_API int maxTextureSize() const;
/**
* Gets the maximum supported render target size.
*/
SK_API int maxRenderTargetSize() const;
/**
* Can a SkImage be created with the given color type.
*/
SK_API bool colorTypeSupportedAsImage(SkColorType) const;
/**
* Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA
* rendering is supported for the color type. 0 is returned if rendering to this color type
* is not supported at all.
*/
SK_API int maxSurfaceSampleCountForColorType(SkColorType colorType) const {
return INHERITED::maxSurfaceSampleCountForColorType(colorType);
}
SK_API sk_sp<const SkCapabilities> skCapabilities() const;
// Provides access to functions that aren't part of the public API.
GrRecordingContextPriv priv();
const GrRecordingContextPriv priv() const; // NOLINT(readability-const-return-type)
// The collection of specialized memory arenas for different types of data recorded by a
// GrRecordingContext. Arenas does not maintain ownership of the pools it groups together.
class Arenas {
public:
Arenas(SkArenaAlloc*, sktext::gpu::SubRunAllocator*);
// For storing pipelines and other complex data as-needed by ops
SkArenaAlloc* recordTimeAllocator() { return fRecordTimeAllocator; }
// For storing GrTextBlob SubRuns
sktext::gpu::SubRunAllocator* recordTimeSubRunAllocator() {
return fRecordTimeSubRunAllocator;
}
private:
SkArenaAlloc* fRecordTimeAllocator;
sktext::gpu::SubRunAllocator* fRecordTimeSubRunAllocator;
};
protected:
friend class GrRecordingContextPriv; // for hidden functions
friend class SkDeferredDisplayList; // for OwnedArenas
friend class SkDeferredDisplayListPriv; // for ProgramData
// Like Arenas, but preserves ownership of the underlying pools.
class OwnedArenas {
public:
OwnedArenas(bool ddlRecording);
~OwnedArenas();
Arenas get();
OwnedArenas& operator=(OwnedArenas&&);
private:
bool fDDLRecording;
std::unique_ptr<SkArenaAlloc> fRecordTimeAllocator;
std::unique_ptr<sktext::gpu::SubRunAllocator> fRecordTimeSubRunAllocator;
};
GrRecordingContext(sk_sp<GrContextThreadSafeProxy>, bool ddlRecording);
Reland "Have DDLs honor the reduceOpsTaskSplittingFlag" This reverts commit 6e9bf51dd88001380fa41d7c6daa52f9d864ec90. Reason for revert: We're sticking with this despite regression Original change's description: > Revert "Have DDLs honor the reduceOpsTaskSplittingFlag" > > This reverts commit d7b59c091d33ef30e352135abaff8e59da5ad9fe. > > Reason for revert: Regression in chrome:1146701 > > Original change's description: > > Have DDLs honor the reduceOpsTaskSplittingFlag > > > > Especially while I'm fiddling with the implementation, we don't > > want the user to be surprised when using DDLs also triggers > > this other codepath. > > > > Bug: skia:10877 > > Change-Id: I660ea08189fff45acd7a45df12e15c45f607758a > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332720 > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Bug: skia:10877 chromium:1146701 > Change-Id: Ieab2853b54663e7633bec6d71929db9885251ed2 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/346659 > Commit-Queue: Adlai Holler <adlai@google.com> > Reviewed-by: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because this is a reland. Bug: skia:10877 chromium:1146701 Change-Id: I754436755829d25da3fdb37f634669ae33419eb4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348882 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2020-12-30 16:20:25 +00:00
bool init() override;
void abandonContext() override;
GrDrawingManager* drawingManager();
Reland "Consolidate GrDrawingManager <-> GrRenderTask lifecycle" This reverts commit 65888b81cf35503b148f7866224a74d1fef1508a. Reason for revert: Fixed underlying issue http://crbug.com/1097620 Original change's description: > Revert "Consolidate GrDrawingManager <-> GrRenderTask lifecycle" > > This reverts commit 6f1487fe80c19c7a18a41d5a738d7ba2301929a9. > > Reason for revert: http://crbug.com/1097620 > > Original change's description: > > Consolidate GrDrawingManager <-> GrRenderTask lifecycle > > > > This creates a funnel in the drawing manager (removeRenderTasks) that > > opens the door for tighter integration between the two classes. Also we > > add some assertions about the relationship and cut out duplicated code. > > > > Bug: skia:10372 > > Change-Id: I0781ba7d45ac090cf7f6d430f0d56afe0f98b7e0 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297195 > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Commit-Queue: Adlai Holler <adlai@google.com> > > TBR=robertphillips@google.com,adlai@google.com > > Change-Id: I5d34ada1838d206d8a33294427d459c36ad6b740 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10372 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298137 > Auto-Submit: Adlai Holler <adlai@google.com> > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> TBR=bsalomon@google.com,adlai@google.com Bug: skia:10372 Change-Id: I9c83d4b2dc10b9db576d506b461b596b94afbc8d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298339 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
2020-06-26 12:50:14 +00:00
// There is no going back from this method. It should only be called to control the timing
// during abandon or destruction of the context.
void destroyDrawingManager();
Arenas arenas() { return fArenas.get(); }
Reland "Detach op memory pool from recording context" This reverts commit ed58654e39df63bd8d58944bea9f65a8ca206986. Reason for revert: Fix field order in SkDeferredDisplayList to deconstruct dependent types in the proper order. Original change's description: > Revert "Detach op memory pool from recording context" > > This reverts commit 6b955167286de1cc0cf215e460389614221903fe. > > Reason for revert: breaking some Win10 bots > > Original change's description: > > Detach op memory pool from recording context > > > > This changes GrOpMemoryPool to no longer extend SkRefCnt, and all usages > > either are std::unique_ptr for owners, or GrOpMemoryPool* when ownership > > is held somewhere else. The culmination of this is that DDLs explicitly > > detach the memory pool from the recording context instead of the GrOpsTask > > maintaining a strong ref that preserved the memory somewhat sneakily. > > > > Change-Id: I33e2caebea70cebe8fd7681207c631feeaf2c703 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259424 > > Commit-Queue: Michael Ludwig <michaelludwig@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,michaelludwig@google.com > > Change-Id: I942ae1e07fdc63d9311f6ee482bd71beca090502 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259696 > Reviewed-by: Derek Sollenberger <djsollen@google.com> > Commit-Queue: Derek Sollenberger <djsollen@google.com> Change-Id: Ia82fa6e42fc8d75b8aa57e5172894e8dfc7e83d1 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259816 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2019-12-12 18:59:20 +00:00
// This entry point should only be used for DDL creation where we want the ops' lifetime to
// match that of the DDL.
OwnedArenas&& detachArenas();
GrProxyProvider* proxyProvider() { return fProxyProvider.get(); }
const GrProxyProvider* proxyProvider() const { return fProxyProvider.get(); }
struct ProgramData {
ProgramData(std::unique_ptr<const GrProgramDesc>, const GrProgramInfo*);
ProgramData(ProgramData&&); // for SkTArray
ProgramData(const ProgramData&) = delete;
~ProgramData();
const GrProgramDesc& desc() const { return *fDesc; }
const GrProgramInfo& info() const { return *fInfo; }
private:
// TODO: store the GrProgramDescs in the 'fRecordTimeData' arena
std::unique_ptr<const GrProgramDesc> fDesc;
// The program infos should be stored in 'fRecordTimeData' so do not need to be ref
// counted or deleted in the destructor.
const GrProgramInfo* fInfo = nullptr;
};
// This entry point gives the recording context a chance to cache the provided
// programInfo. The DDL context takes this opportunity to store programInfos as a sidecar
// to the DDL.
virtual void recordProgramInfo(const GrProgramInfo*) {}
// This asks the recording context to return any programInfos it may have collected
// via the 'recordProgramInfo' call. It is up to the caller to ensure that the lifetime
// of the programInfos matches the intended use. For example, in DDL-record mode it
// is known that all the programInfos will have been allocated in an arena with the
// same lifetime at the DDL itself.
virtual void detachProgramData(SkTArray<ProgramData>*) {}
GrTextBlobRedrawCoordinator* getTextBlobRedrawCoordinator();
const GrTextBlobRedrawCoordinator* getTextBlobRedrawCoordinator() const;
GrThreadSafeCache* threadSafeCache();
const GrThreadSafeCache* threadSafeCache() const;
/**
* Registers an object for flush-related callbacks. (See GrOnFlushCallbackObject.)
*
* NOTE: the drawing manager tracks this object as a raw pointer; it is up to the caller to
* ensure its lifetime is tied to that of the context.
*/
void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
GrRecordingContext* asRecordingContext() override { return this; }
class Stats {
public:
Stats() = default;
#if GR_GPU_STATS
void reset() { *this = {}; }
int numPathMasksGenerated() const { return fNumPathMasksGenerated; }
void incNumPathMasksGenerated() { fNumPathMasksGenerated++; }
int numPathMaskCacheHits() const { return fNumPathMaskCacheHits; }
void incNumPathMasksCacheHits() { fNumPathMaskCacheHits++; }
#if GR_TEST_UTILS
void dump(SkString* out) const;
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
#endif
private:
int fNumPathMasksGenerated{0};
int fNumPathMaskCacheHits{0};
#else // GR_GPU_STATS
void incNumPathMasksGenerated() {}
void incNumPathMasksCacheHits() {}
#if GR_TEST_UTILS
void dump(SkString*) const {}
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const {}
#endif
#endif // GR_GPU_STATS
} fStats;
#if GR_GPU_STATS && GR_TEST_UTILS
struct DMSAAStats {
void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
void dump() const;
void merge(const DMSAAStats&);
int fNumRenderPasses = 0;
int fNumMultisampleRenderPasses = 0;
std::map<std::string, int> fTriggerCounts;
};
DMSAAStats fDMSAAStats;
#endif
Stats* stats() { return &fStats; }
const Stats* stats() const { return &fStats; }
void dumpJSON(SkJSONWriter*) const;
protected:
// Delete last in case other objects call it during destruction.
std::unique_ptr<GrAuditTrail> fAuditTrail;
private:
OwnedArenas fArenas;
std::unique_ptr<GrDrawingManager> fDrawingManager;
std::unique_ptr<GrProxyProvider> fProxyProvider;
#if GR_TEST_UTILS
int fSuppressWarningMessages = 0;
#endif
using INHERITED = GrImageContext;
};
/**
* Safely cast a possibly-null base context to direct context.
*/
static inline GrDirectContext* GrAsDirectContext(GrContext_Base* base) {
return base ? base->asDirectContext() : nullptr;
}
#endif