aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrCaps.cpp18
-rw-r--r--src/gpu/GrDrawContext.cpp18
-rw-r--r--src/gpu/GrDrawTarget.cpp7
-rw-r--r--src/gpu/GrDrawTarget.h8
-rw-r--r--src/gpu/GrDrawingManager.cpp6
-rw-r--r--src/gpu/GrGpu.cpp5
-rw-r--r--src/gpu/GrGpu.h6
-rw-r--r--src/gpu/gl/GrGLCaps.cpp22
-rw-r--r--src/gpu/gl/GrGLCaps.h4
-rw-r--r--src/gpu/gl/GrGLGpu.cpp8
-rw-r--r--src/gpu/gl/GrGLGpu.h5
-rw-r--r--src/gpu/instanced/GLInstancedRendering.cpp24
-rw-r--r--src/gpu/instanced/GLInstancedRendering.h12
-rw-r--r--src/gpu/instanced/InstanceProcessor.cpp40
-rw-r--r--src/gpu/instanced/InstanceProcessor.h11
-rw-r--r--src/gpu/instanced/InstancedRendering.cpp14
-rw-r--r--src/gpu/instanced/InstancedRendering.h4
-rw-r--r--src/gpu/vk/GrVkGpu.h2
18 files changed, 124 insertions, 90 deletions
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 36b7b17de2..fa4230f9fc 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -106,6 +106,8 @@ GrCaps::GrCaps(const GrContextOptions& options) {
fUseDrawInsteadOfClear = false;
+ fInstancedSupport = InstancedSupport::kNone;
+
fBlendEquationSupport = kBasic_BlendEquationSupport;
fAdvBlendEqBlacklist = 0;
@@ -123,6 +125,7 @@ GrCaps::GrCaps(const GrContextOptions& options) {
fBufferMapThreshold = options.fBufferMapThreshold;
fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite;
fUseDrawInsteadOfAllRenderTargetWrites = false;
+ fAvoidInstancedDrawsToFPTargets = false;
fPreferVRAMUseOverFlushes = true;
}
@@ -197,6 +200,21 @@ SkString GrCaps::dump() const {
r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount);
r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples);
+ static const char* kInstancedSupportNames[] = {
+ "None",
+ "Basic",
+ "Multisampled",
+ "Mixed Sampled",
+ };
+ GR_STATIC_ASSERT(0 == (int)InstancedSupport::kNone);
+ GR_STATIC_ASSERT(1 == (int)InstancedSupport::kBasic);
+ GR_STATIC_ASSERT(2 == (int)InstancedSupport::kMultisampled);
+ GR_STATIC_ASSERT(3 == (int)InstancedSupport::kMixedSampled);
+ GR_STATIC_ASSERT(4 == SK_ARRAY_COUNT(kInstancedSupportNames));
+
+ r.appendf("Instanced Support : %s\n",
+ kInstancedSupportNames[(int)fInstancedSupport]);
+
static const char* kBlendEquationSupportNames[] = {
"Basic",
"Advanced",
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index fedb397200..195cb7a911 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -368,7 +368,8 @@ bool GrDrawContext::drawFilledRect(const GrClip& clip,
SkAutoTUnref<GrDrawBatch> batch;
bool useHWAA;
- if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
paint.isAntiAlias(), fInstancedPipelineInfo,
&useHWAA));
@@ -618,7 +619,8 @@ void GrDrawContext::fillRectToRect(const GrClip& clip,
AutoCheckFlush acf(fDrawingManager);
bool useHWAA;
- if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
croppedLocalRect, paint.isAntiAlias(),
fInstancedPipelineInfo, &useHWAA));
@@ -676,7 +678,8 @@ void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip,
AutoCheckFlush acf(fDrawingManager);
bool useHWAA;
- if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix, paint.getColor(),
localMatrix, paint.isAntiAlias(),
fInstancedPipelineInfo, &useHWAA));
@@ -803,7 +806,8 @@ void GrDrawContext::drawRRect(const GrClip& clip,
const SkStrokeRec stroke = style.strokeRec();
bool useHWAA;
- if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() &&
+ stroke.isFillStyle()) {
InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
SkAutoTUnref<GrDrawBatch> batch(ir->recordRRect(rrect, viewMatrix, paint.getColor(),
paint.isAntiAlias(), fInstancedPipelineInfo,
@@ -843,8 +847,9 @@ bool GrDrawContext::drawFilledDRRect(const GrClip& clip,
SkASSERT(!origInner.isEmpty());
SkASSERT(!origOuter.isEmpty());
- if (InstancedRendering* ir = this->getDrawTarget()->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
bool useHWAA;
+ InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
SkAutoTUnref<GrDrawBatch> batch(ir->recordDRRect(origOuter, origInner, viewMatrix,
paintIn.getColor(), paintIn.isAntiAlias(),
fInstancedPipelineInfo, &useHWAA));
@@ -954,7 +959,8 @@ void GrDrawContext::drawOval(const GrClip& clip,
const SkStrokeRec& stroke = style.strokeRec();
bool useHWAA;
- if (this->getDrawTarget()->instancedRendering() && stroke.isFillStyle()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport() &&
+ stroke.isFillStyle()) {
InstancedRendering* ir = this->getDrawTarget()->instancedRendering();
SkAutoTUnref<GrDrawBatch> batch(ir->recordOval(oval, viewMatrix, paint.getColor(),
paint.isAntiAlias(), fInstancedPipelineInfo,
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 717cd5d1bb..bb473cafe4 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -48,8 +48,7 @@ GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
, fResourceProvider(resourceProvider)
, fAuditTrail(auditTrail)
, fFlags(0)
- , fRenderTarget(rt)
- , fInstancedRendering(fGpu->createInstancedRenderingIfSupported()) {
+ , fRenderTarget(rt) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager)
fContext = fGpu->getContext();
@@ -60,6 +59,10 @@ GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLookahead :
options.fMaxBatchLookahead;
+ if (GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport()) {
+ fInstancedRendering.reset(fGpu->createInstancedRendering());
+ }
+
rt->setLastDrawTarget(this);
#ifdef SK_DEBUG
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index 18ad1c8699..02a7770134 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -139,10 +139,10 @@ public:
const SkIRect& srcRect,
const SkIPoint& dstPoint);
- /**
- * Gets the shape rendering object if it is supported on this platform.
- */
- gr_instanced::InstancedRendering* instancedRendering() const { return fInstancedRendering; }
+ gr_instanced::InstancedRendering* instancedRendering() const {
+ SkASSERT(fInstancedRendering);
+ return fInstancedRendering;
+ }
private:
friend class GrDrawingManager; // for resetFlag & TopoSortTraits
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 5dc07dd960..840c50f5e0 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -45,7 +45,8 @@ GrDrawingManager::~GrDrawingManager() {
void GrDrawingManager::abandon() {
fAbandoned = true;
for (int i = 0; i < fDrawTargets.count(); ++i) {
- if (InstancedRendering* ir = fDrawTargets[i]->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
+ InstancedRendering* ir = fDrawTargets[i]->instancedRendering();
ir->resetGpuResources(InstancedRendering::ResetType::kAbandon);
}
}
@@ -58,7 +59,8 @@ void GrDrawingManager::freeGpuResources() {
fPathRendererChain = nullptr;
SkSafeSetNull(fSoftwarePathRenderer);
for (int i = 0; i < fDrawTargets.count(); ++i) {
- if (InstancedRendering* ir = fDrawTargets[i]->instancedRendering()) {
+ if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport()) {
+ InstancedRendering* ir = fDrawTargets[i]->instancedRendering();
ir->resetGpuResources(InstancedRendering::ResetType::kDestroy);
}
}
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 4cb96edd88..7199b4d976 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -251,6 +251,11 @@ GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType,
return buffer;
}
+gr_instanced::InstancedRendering* GrGpu::createInstancedRendering() {
+ SkASSERT(GrCaps::InstancedSupport::kNone != this->caps()->instancedSupport());
+ return this->onCreateInstancedRendering();
+}
+
bool GrGpu::copySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 37427b5739..393df1a9b6 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -152,9 +152,7 @@ public:
/**
* Creates an instanced rendering object if it is supported on this platform.
*/
- virtual gr_instanced::InstancedRendering* createInstancedRenderingIfSupported() {
- return nullptr;
- }
+ gr_instanced::InstancedRendering* createInstancedRendering();
/**
* Resolves MSAA.
@@ -537,6 +535,8 @@ private:
virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
const void* data) = 0;
+ virtual gr_instanced::InstancedRendering* onCreateInstancedRendering() = 0;
+
virtual bool onMakeCopyForTextureParams(GrTexture* texture, const GrTextureParams&,
GrTextureProducer::CopyParams*) const { return false; }
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index a484b05b95..653b5ca725 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -12,6 +12,7 @@
#include "GrGLContext.h"
#include "GrGLRenderTarget.h"
#include "glsl/GrGLSLCaps.h"
+#include "instanced/GLInstancedRendering.h"
#include "SkTSearch.h"
#include "SkTSort.h"
@@ -40,7 +41,6 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
fDrawIndirectSupport = false;
fMultiDrawIndirectSupport = false;
fBaseInstanceSupport = false;
- fCanDrawIndirectToFloat = false;
fIsCoreProfile = false;
fBindFragDataLocationSupport = false;
fRectangleTextureSupport = false;
@@ -526,14 +526,6 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
fBaseInstanceSupport = ctxInfo.hasExtension("GL_EXT_base_instance");
}
- // OS X doesn't seem to write correctly to floating point textures when using glDraw*Indirect,
- // regardless of the underlying GPU.
-#ifndef SK_BUILD_FOR_MAC
- if (fDrawIndirectSupport) {
- fCanDrawIndirectToFloat = true;
- }
-#endif
-
this->initShaderPrecisionTable(ctxInfo, gli, glslCaps);
if (contextOptions.fUseShaderSwizzling) {
@@ -1116,7 +1108,6 @@ SkString GrGLCaps::dump() const {
r.appendf("Draw indirect support: %s\n", (fDrawIndirectSupport ? "YES" : "NO"));
r.appendf("Multi draw indirect support: %s\n", (fMultiDrawIndirectSupport ? "YES" : "NO"));
r.appendf("Base instance support: %s\n", (fBaseInstanceSupport ? "YES" : "NO"));
- r.appendf("Can draw indirect to float: %s\n", (fCanDrawIndirectToFloat ? "YES" : "NO"));
r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO"));
r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO"));
r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO"));
@@ -1935,4 +1926,13 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
#endif
}
-void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {}
+void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
+ if (options.fEnableInstancedRendering) {
+ fInstancedSupport = gr_instanced::GLInstancedRendering::CheckSupport(*this);
+#ifndef SK_BUILD_FOR_MAC
+ // OS X doesn't seem to write correctly to floating point textures when using
+ // glDraw*Indirect, regardless of the underlying GPU.
+ fAvoidInstancedDrawsToFPTargets = true;
+#endif
+ }
+}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 1ccdf3e79c..0cb353aa9f 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -307,9 +307,6 @@ public:
/// Are the baseInstance fields supported in indirect draw commands?
bool baseInstanceSupport() const { return fBaseInstanceSupport; }
- /// Does the platform have known issuses rendering to floating point when using glDraw*Indirect?
- bool canDrawIndirectToFloat() const { return fCanDrawIndirectToFloat; }
-
/// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
@@ -401,7 +398,6 @@ private:
bool fDrawIndirectSupport : 1;
bool fMultiDrawIndirectSupport : 1;
bool fBaseInstanceSupport : 1;
- bool fCanDrawIndirectToFloat : 1;
bool fUseNonVBOVertexAndIndexDynamicData : 1;
bool fIsCoreProfile : 1;
bool fBindFragDataLocationSupport : 1;
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index ec38804da3..c91a0f46fa 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -479,10 +479,6 @@ void GrGLGpu::disconnect(DisconnectType type) {
///////////////////////////////////////////////////////////////////////////////
-InstancedRendering* GrGLGpu::createInstancedRenderingIfSupported() {
- return GLInstancedRendering::CreateIfSupported(this);
-}
-
void GrGLGpu::onResetContext(uint32_t resetBits) {
// we don't use the zb at all
if (resetBits & kMisc_GrGLBackendState) {
@@ -1965,6 +1961,10 @@ GrBuffer* GrGLGpu::onCreateBuffer(size_t size, GrBufferType intendedType,
return GrGLBuffer::Create(this, size, intendedType, accessPattern, data);
}
+InstancedRendering* GrGLGpu::onCreateInstancedRendering() {
+ return new GLInstancedRendering(this);
+}
+
void GrGLGpu::flushScissor(const GrScissorState& scissorState,
const GrGLIRect& rtViewport,
GrSurfaceOrigin rtOrigin) {
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index df88565100..0356352529 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -55,8 +55,6 @@ public:
return static_cast<GrGLPathRendering*>(pathRendering());
}
- gr_instanced::InstancedRendering* createInstancedRenderingIfSupported() override;
-
// Used by GrGLProgram to configure OpenGL state.
void bindTexture(int unitIdx, const GrTextureParams& params, bool allowSRGBInputs,
GrGLTexture* texture);
@@ -165,6 +163,9 @@ private:
GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
GrWrapOwnership) override;
GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
+
+ gr_instanced::InstancedRendering* onCreateInstancedRendering() override;
+
// Given a GrPixelConfig return the index into the stencil format array on GrGLCaps to a
// compatible stencil format, or negative if there is no compatible stencil format.
int getCompatibleStencilIndex(GrPixelConfig config);
diff --git a/src/gpu/instanced/GLInstancedRendering.cpp b/src/gpu/instanced/GLInstancedRendering.cpp
index 2962a86548..440796e19a 100644
--- a/src/gpu/instanced/GLInstancedRendering.cpp
+++ b/src/gpu/instanced/GLInstancedRendering.cpp
@@ -31,27 +31,21 @@ private:
typedef Batch INHERITED;
};
-GLInstancedRendering* GLInstancedRendering::CreateIfSupported(GrGLGpu* gpu) {
-#ifndef SK_BUILD_FOR_MAC
- // Only whitelisting on Mac for now. Once we've been able to work through the various issues on
- // other platforms we can enable more generally.
- return nullptr;
-#endif
- const GrGLCaps& glCaps = gpu->glCaps();
- AntialiasMode lastSupportedAAMode;
- if (!glCaps.vertexArrayObjectSupport() ||
- !glCaps.drawIndirectSupport() ||
- !InstanceProcessor::IsSupported(*glCaps.glslCaps(), glCaps, &lastSupportedAAMode)) {
- return nullptr;
+GrCaps::InstancedSupport GLInstancedRendering::CheckSupport(const GrGLCaps& glCaps) {
+ // This method is only intended to be used for initializing fInstancedSupport in the caps.
+ SkASSERT(GrCaps::InstancedSupport::kNone == glCaps.instancedSupport());
+ if (!glCaps.vertexArrayObjectSupport() || !glCaps.drawIndirectSupport()) {
+ return GrCaps::InstancedSupport::kNone;
}
- return new GLInstancedRendering(gpu, lastSupportedAAMode);
+ return InstanceProcessor::CheckSupport(*glCaps.glslCaps(), glCaps);
}
-GLInstancedRendering::GLInstancedRendering(GrGLGpu* gpu, AntialiasMode lastSupportedAAMode)
- : INHERITED(gpu, lastSupportedAAMode, gpu->glCaps().canDrawIndirectToFloat()),
+GLInstancedRendering::GLInstancedRendering(GrGLGpu* gpu)
+ : INHERITED(gpu),
fVertexArrayID(0),
fGLDrawCmdsInfo(0),
fInstanceAttribsBufferUniqueId(SK_InvalidUniqueID) {
+ SkASSERT(GrCaps::InstancedSupport::kNone != this->gpu()->caps()->instancedSupport());
}
GLInstancedRendering::~GLInstancedRendering() {
diff --git a/src/gpu/instanced/GLInstancedRendering.h b/src/gpu/instanced/GLInstancedRendering.h
index 3b87b0485a..4e17cb4535 100644
--- a/src/gpu/instanced/GLInstancedRendering.h
+++ b/src/gpu/instanced/GLInstancedRendering.h
@@ -8,9 +8,11 @@
#ifndef gr_instanced_GLInstancedRendering_DEFINED
#define gr_instanced_GLInstancedRendering_DEFINED
+#include "GrCaps.h"
#include "gl/GrGLBuffer.h"
#include "instanced/InstancedRendering.h"
+class GrGLCaps;
class GrGLGpu;
#define GR_GL_LOG_INSTANCED_BATCHES 0
@@ -19,11 +21,15 @@ namespace gr_instanced {
class GLInstancedRendering final : public InstancedRendering {
public:
- static GLInstancedRendering* CreateIfSupported(GrGLGpu*);
+ GLInstancedRendering(GrGLGpu*);
~GLInstancedRendering() override;
private:
- GLInstancedRendering(GrGLGpu*, AntialiasMode lastSupportedAAMode);
+ /**
+ * Called by GrGLCaps to determine the level of support this class can offer for instanced
+ * rendering on the current platform.
+ */
+ static GrCaps::InstancedSupport CheckSupport(const GrGLCaps&);
GrGLGpu* glGpu() const;
@@ -52,6 +58,8 @@ private:
class GLBatch;
+ friend class ::GrGLCaps; // For CheckSupport.
+
typedef InstancedRendering INHERITED;
};
diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp
index b6a3bb9a0f..50bc219087 100644
--- a/src/gpu/instanced/InstanceProcessor.cpp
+++ b/src/gpu/instanced/InstanceProcessor.cpp
@@ -18,29 +18,26 @@
namespace gr_instanced {
-bool InstanceProcessor::IsSupported(const GrGLSLCaps& glslCaps, const GrCaps& caps,
- AntialiasMode* lastSupportedAAMode) {
+GrCaps::InstancedSupport InstanceProcessor::CheckSupport(const GrGLSLCaps& glslCaps,
+ const GrCaps& caps) {
if (!glslCaps.canUseAnyFunctionInShader() ||
!glslCaps.flatInterpolationSupport() ||
!glslCaps.integerSupport() ||
0 == glslCaps.maxVertexSamplers() ||
!caps.shaderCaps()->texelBufferSupport() ||
caps.maxVertexAttributes() < kNumAttribs) {
- return false;
- }
- if (caps.sampleLocationsSupport() &&
- glslCaps.sampleVariablesSupport() &&
- glslCaps.shaderDerivativeSupport()) {
- if (0 != caps.maxRasterSamples() &&
- glslCaps.sampleMaskOverrideCoverageSupport()) {
- *lastSupportedAAMode = AntialiasMode::kMixedSamples;
- } else {
- *lastSupportedAAMode = AntialiasMode::kMSAA;
- }
- } else {
- *lastSupportedAAMode = AntialiasMode::kCoverage;
+ return GrCaps::InstancedSupport::kNone;
+ }
+ if (!caps.sampleLocationsSupport() ||
+ !glslCaps.sampleVariablesSupport() ||
+ !glslCaps.shaderDerivativeSupport()) {
+ return GrCaps::InstancedSupport::kBasic;
}
- return true;
+ if (0 == caps.maxRasterSamples() ||
+ !glslCaps.sampleMaskOverrideCoverageSupport()) {
+ return GrCaps::InstancedSupport::kMultisampled;
+ }
+ return GrCaps::InstancedSupport::kMixedSampled;
}
InstanceProcessor::InstanceProcessor(BatchInfo batchInfo, GrBuffer* paramsBuffer)
@@ -767,8 +764,8 @@ void GLSLInstanceProcessor::BackendCoverage::onInit(GrGLSLVaryingHandler* varyin
varyingHandler->addVarying("ellipseCoords", &fEllipseCoords, kMedium_GrSLPrecision);
varyingHandler->addFlatVarying("ellipseName", &fEllipseName, kHigh_GrSLPrecision);
} else {
- varyingHandler->addVarying("circleCoords", &fEllipseCoords, kMedium_GrSLPrecision);
- varyingHandler->addFlatVarying("bloatedRadius", &fBloatedRadius, kMedium_GrSLPrecision);
+ varyingHandler->addVarying("circleCoords", &fEllipseCoords, kHigh_GrSLPrecision);
+ varyingHandler->addFlatVarying("bloatedRadius", &fBloatedRadius, kHigh_GrSLPrecision);
}
}
}
@@ -1016,7 +1013,7 @@ void GLSLInstanceProcessor::BackendCoverage::emitCircle(GrGLSLPPFragmentBuilder*
const char* outCoverage) {
// TODO: circleCoords = max(circleCoords, 0) if we decide to do this optimization on rrects.
SkASSERT(!(kRRect_ShapesMask & fBatchInfo.fShapeTypes));
- f->appendPrecisionModifier(kLow_GrSLPrecision);
+ f->appendPrecisionModifier(kMedium_GrSLPrecision);
f->codeAppendf("float distanceToEdge = %s - length(%s);",
fBloatedRadius.fsIn(), fEllipseCoords.fsIn());
f->codeAppendf("%s = clamp(distanceToEdge, 0.0, 1.0);", outCoverage);
@@ -1407,9 +1404,8 @@ void GLSLInstanceProcessor::BackendMultisample::onEmitCode(GrGLSLVertexBuilder*,
}
} else {
const char* arcTest = fArcTest.fsIn();
- SkASSERT(arcTest);
- if (fBatchInfo.fHasPerspective) {
- // The non-perspective version accounts for fwith() in the vertex shader.
+ if (arcTest && fBatchInfo.fHasPerspective) {
+ // The non-perspective version accounts for fwidth() in the vertex shader.
// We make sure to take the derivative here, before a neighbor pixel may early accept.
f->enableFeature(GrGLSLPPFragmentBuilder::kStandardDerivatives_GLSLFeature);
f->appendPrecisionModifier(kHigh_GrSLPrecision);
diff --git a/src/gpu/instanced/InstanceProcessor.h b/src/gpu/instanced/InstanceProcessor.h
index b0edde95b8..0b3a16d5a4 100644
--- a/src/gpu/instanced/InstanceProcessor.h
+++ b/src/gpu/instanced/InstanceProcessor.h
@@ -8,6 +8,7 @@
#ifndef gr_instanced_InstanceProcessor_DEFINED
#define gr_instanced_InstanceProcessor_DEFINED
+#include "GrCaps.h"
#include "GrBufferAccess.h"
#include "GrGeometryProcessor.h"
#include "instanced/InstancedRenderingTypes.h"
@@ -22,8 +23,6 @@ namespace gr_instanced {
*/
class InstanceProcessor : public GrGeometryProcessor {
public:
- static bool IsSupported(const GrGLSLCaps&, const GrCaps&, AntialiasMode* lastSupportedAAMode);
-
InstanceProcessor(BatchInfo, GrBuffer* paramsBuffer);
const char* name() const override { return "Instance Processor"; }
@@ -52,9 +51,17 @@ public:
static const char* GetNameOfIndexRange(IndexRange);
private:
+ /**
+ * Called by the platform-specific instanced rendering implementation to determine the level of
+ * support this class can offer on the given GLSL platform.
+ */
+ static GrCaps::InstancedSupport CheckSupport(const GrGLSLCaps&, const GrCaps&);
+
const BatchInfo fBatchInfo;
GrBufferAccess fParamsAccess;
+ friend class GLInstancedRendering; // For CheckSupport.
+
typedef GrGeometryProcessor INHERITED;
};
diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp
index d763b73064..66e53dd5db 100644
--- a/src/gpu/instanced/InstancedRendering.cpp
+++ b/src/gpu/instanced/InstancedRendering.cpp
@@ -15,11 +15,8 @@
namespace gr_instanced {
-InstancedRendering::InstancedRendering(GrGpu* gpu, AntialiasMode lastSupportedAAMode,
- bool canRenderToFloat)
+InstancedRendering::InstancedRendering(GrGpu* gpu)
: fGpu(SkRef(gpu)),
- fLastSupportedAAMode(lastSupportedAAMode),
- fCanRenderToFloat(canRenderToFloat),
fState(State::kRecordingDraws),
fDrawPool(1024 * sizeof(Batch::Draw), 1024 * sizeof(Batch::Draw)) {
}
@@ -107,7 +104,7 @@ InstancedRendering::Batch* InstancedRendering::recordShape(ShapeType type, const
bool* useHWAA) {
SkASSERT(State::kRecordingDraws == fState);
- if (info.fIsRenderingToFloat && !fCanRenderToFloat) {
+ if (info.fIsRenderingToFloat && fGpu->caps()->avoidInstancedDrawsToFPTargets()) {
return nullptr;
}
@@ -201,9 +198,9 @@ inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix,
bool* useHWAA, AntialiasMode* antialiasMode) {
SkASSERT(!info.fColorDisabled || info.fDrawingShapeToStencil);
SkASSERT(!info.fIsMixedSampled || info.fIsMultisampled);
+ SkASSERT(GrCaps::InstancedSupport::kNone != fGpu->caps()->instancedSupport());
if (!info.fIsMultisampled || fGpu->caps()->multisampleDisableSupport()) {
- SkASSERT(fLastSupportedAAMode >= AntialiasMode::kCoverage);
if (!antialias) {
if (info.fDrawingShapeToStencil && !info.fCanDiscard) {
// We can't draw to the stencil buffer without discard (or sample mask if MSAA).
@@ -221,13 +218,14 @@ inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix,
}
}
- if (info.fIsMultisampled && fLastSupportedAAMode >= AntialiasMode::kMSAA) {
+ if (info.fIsMultisampled &&
+ fGpu->caps()->instancedSupport() >= GrCaps::InstancedSupport::kMultisampled) {
if (!info.fIsMixedSampled || info.fColorDisabled) {
*antialiasMode = AntialiasMode::kMSAA;
*useHWAA = true;
return true;
}
- if (fLastSupportedAAMode >= AntialiasMode::kMixedSamples) {
+ if (fGpu->caps()->instancedSupport() >= GrCaps::InstancedSupport::kMixedSampled) {
*antialiasMode = AntialiasMode::kMixedSamples;
*useHWAA = true;
return true;
diff --git a/src/gpu/instanced/InstancedRendering.h b/src/gpu/instanced/InstancedRendering.h
index d5289663e0..b2c360b252 100644
--- a/src/gpu/instanced/InstancedRendering.h
+++ b/src/gpu/instanced/InstancedRendering.h
@@ -143,7 +143,7 @@ protected:
typedef SkTInternalLList<Batch> BatchList;
- InstancedRendering(GrGpu* gpu, AntialiasMode lastSupportedAAMode, bool canRenderToFloat);
+ InstancedRendering(GrGpu* gpu);
const BatchList& trackedBatches() const { return fTrackedBatches; }
const GrBuffer* vertexBuffer() const { SkASSERT(fVertexBuffer); return fVertexBuffer; }
@@ -171,8 +171,6 @@ private:
virtual Batch* createBatch() = 0;
const SkAutoTUnref<GrGpu> fGpu;
- const AntialiasMode fLastSupportedAAMode;
- const bool fCanRenderToFloat;
State fState;
GrMemoryPool fDrawPool;
SkSTArray<1024, ParamsTexel, true> fParams;
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index a0bed3bcbe..1554115905 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -182,6 +182,8 @@ private:
GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern,
const void* data) override;
+ gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
+
bool onReadPixels(GrSurface* surface,
int left, int top, int width, int height,
GrPixelConfig,