aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLGpu.cpp99
-rw-r--r--src/gpu/gl/GrGLGpu.h19
-rw-r--r--src/gpu/gl/GrGLGpuProgramCache.cpp19
-rw-r--r--src/gpu/gl/GrGLPathRendering.cpp17
-rw-r--r--src/gpu/gl/GrGLPathRendering.h16
-rw-r--r--src/gpu/gl/GrGLVaryingHandler.cpp6
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp15
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h9
8 files changed, 119 insertions, 81 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index f742efe70d..76cb1a068a 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -10,13 +10,13 @@
#include "GrGLStencilAttachment.h"
#include "GrGLTextureRenderTarget.h"
#include "GrGpuResourcePriv.h"
+#include "GrMesh.h"
#include "GrPipeline.h"
#include "GrPLSGeometryProcessor.h"
#include "GrRenderTargetPriv.h"
#include "GrSurfacePriv.h"
#include "GrTexturePriv.h"
#include "GrTypes.h"
-#include "GrVertices.h"
#include "builders/GrGLShaderStringBuilder.h"
#include "glsl/GrGLSL.h"
#include "glsl/GrGLSLCaps.h"
@@ -2071,15 +2071,14 @@ void GrGLGpu::flushScissor(const GrScissorState& scissorState,
this->disableScissor();
}
-bool GrGLGpu::flushGLState(const DrawArgs& args) {
+bool GrGLGpu::flushGLState(const GrPipeline& pipeline, const GrPrimitiveProcessor& primProc) {
GrXferProcessor::BlendInfo blendInfo;
- const GrPipeline& pipeline = *args.fPipeline;
- args.fPipeline->getXferProcessor().getBlendInfo(&blendInfo);
+ pipeline.getXferProcessor().getBlendInfo(&blendInfo);
this->flushColorWrite(blendInfo.fWriteColor);
this->flushDrawFace(pipeline.getDrawFace());
- SkAutoTUnref<GrGLProgram> program(fProgramCache->refProgram(args));
+ SkAutoTUnref<GrGLProgram> program(fProgramCache->refProgram(this, pipeline, primProc));
if (!program) {
GrCapsDebugf(this->caps(), "Failed to create program!\n");
return false;
@@ -2094,12 +2093,12 @@ bool GrGLGpu::flushGLState(const DrawArgs& args) {
if (blendInfo.fWriteColor) {
// Swizzle the blend to match what the shader will output.
const GrSwizzle& swizzle = this->glCaps().glslCaps()->configOutputSwizzle(
- args.fPipeline->getRenderTarget()->config());
+ pipeline.getRenderTarget()->config());
this->flushBlend(blendInfo, swizzle);
}
SkSTArray<8, const GrTextureAccess*> textureAccesses;
- program->setData(*args.fPrimitiveProcessor, pipeline, &textureAccesses);
+ program->setData(primProc, pipeline, &textureAccesses);
int numTextureAccesses = textureAccesses.count();
for (int i = 0; i < numTextureAccesses; i++) {
@@ -2120,20 +2119,20 @@ bool GrGLGpu::flushGLState(const DrawArgs& args) {
}
void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
- const GrNonInstancedVertices& vertices,
+ const GrNonInstancedMesh& mesh,
size_t* indexOffsetInBytes) {
GrGLVertexBuffer* vbuf;
- vbuf = (GrGLVertexBuffer*) vertices.vertexBuffer();
+ vbuf = (GrGLVertexBuffer*) mesh.vertexBuffer();
SkASSERT(vbuf);
SkASSERT(!vbuf->isMapped());
GrGLIndexBuffer* ibuf = nullptr;
- if (vertices.isIndexed()) {
+ if (mesh.isIndexed()) {
SkASSERT(indexOffsetInBytes);
*indexOffsetInBytes = 0;
- ibuf = (GrGLIndexBuffer*)vertices.indexBuffer();
+ ibuf = (GrGLIndexBuffer*)mesh.indexBuffer();
SkASSERT(ibuf);
SkASSERT(!ibuf->isMapped());
@@ -2147,7 +2146,7 @@ void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride());
- size_t vertexOffsetInBytes = stride * vertices.startVertex();
+ size_t vertexOffsetInBytes = stride * mesh.startVertex();
vertexOffsetInBytes += vbuf->baseOffset();
@@ -2170,14 +2169,6 @@ void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
}
}
-void GrGLGpu::buildProgramDesc(GrProgramDesc* desc,
- const GrPrimitiveProcessor& primProc,
- const GrPipeline& pipeline) const {
- if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, *this->glCaps().glslCaps())) {
- SkDEBUGFAIL("Failed to generate GL program descriptor");
- }
-}
-
void GrGLGpu::bindBuffer(GrGLuint id, GrGLenum type) {
this->handleDirtyContext();
switch (type) {
@@ -2918,16 +2909,18 @@ GrGLenum gPrimitiveType2GLMode[] = {
#endif
#endif
-void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertices) {
- if (!this->flushGLState(args)) {
+void GrGLGpu::onDraw(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrMesh* meshes,
+ int meshCount) {
+ if (!this->flushGLState(pipeline, primProc)) {
return;
}
-
- GrPixelLocalStorageState plsState = args.fPrimitiveProcessor->getPixelLocalStorageState();
- if (!fHWPLSEnabled && plsState !=
+ GrPixelLocalStorageState plsState = primProc.getPixelLocalStorageState();
+ if (!fHWPLSEnabled && plsState !=
GrPixelLocalStorageState::kDisabled_GrPixelLocalStorageState) {
GL_CALL(Enable(GR_GL_SHADER_PIXEL_LOCAL_STORAGE));
- this->setupPixelLocalStorage(args);
+ this->setupPixelLocalStorage(pipeline, primProc);
fHWPLSEnabled = true;
}
if (plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState) {
@@ -2936,26 +2929,35 @@ void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertice
this->flushStencil(stencil);
}
- size_t indexOffsetInBytes = 0;
- this->setupGeometry(*args.fPrimitiveProcessor, vertices, &indexOffsetInBytes);
-
- SkASSERT((size_t)vertices.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GLMode));
+ for (int i = 0; i < meshCount; ++i) {
+ if (GrXferBarrierType barrierType = pipeline.xferBarrierType(*this->caps())) {
+ this->xferBarrier(pipeline.getRenderTarget(), barrierType);
+ }
- if (vertices.isIndexed()) {
- GrGLvoid* indices =
- reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
- vertices.startIndex());
- // info.startVertex() was accounted for by setupGeometry.
- GL_CALL(DrawElements(gPrimitiveType2GLMode[vertices.primitiveType()],
- vertices.indexCount(),
- GR_GL_UNSIGNED_SHORT,
- indices));
- } else {
- // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for
- // startVertex in the DrawElements case. So we always rely on setupGeometry to have
- // accounted for startVertex.
- GL_CALL(DrawArrays(gPrimitiveType2GLMode[vertices.primitiveType()], 0,
- vertices.vertexCount()));
+ const GrMesh& mesh = meshes[i];
+ GrMesh::Iterator iter;
+ const GrNonInstancedMesh* nonIdxMesh = iter.init(mesh);
+ do {
+ size_t indexOffsetInBytes = 0;
+ this->setupGeometry(primProc, *nonIdxMesh, &indexOffsetInBytes);
+ if (nonIdxMesh->isIndexed()) {
+ GrGLvoid* indices =
+ reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) *
+ nonIdxMesh->startIndex());
+ // info.startVertex() was accounted for by setupGeometry.
+ GL_CALL(DrawElements(gPrimitiveType2GLMode[nonIdxMesh->primitiveType()],
+ nonIdxMesh->indexCount(),
+ GR_GL_UNSIGNED_SHORT,
+ indices));
+ } else {
+ // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account
+ // for startVertex in the DrawElements case. So we always rely on setupGeometry to
+ // have accounted for startVertex.
+ GL_CALL(DrawArrays(gPrimitiveType2GLMode[nonIdxMesh->primitiveType()], 0,
+ nonIdxMesh->vertexCount()));
+ }
+ fStats.incNumDraws();
+ } while ((nonIdxMesh = iter.next()));
}
if (fHWPLSEnabled && plsState == GrPixelLocalStorageState::kFinish_GrPixelLocalStorageState) {
@@ -3009,13 +3011,14 @@ void GrGLGpu::stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGL
}
}
-void GrGLGpu::setupPixelLocalStorage(const DrawArgs& args) {
+void GrGLGpu::setupPixelLocalStorage(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc) {
fPLSHasBeenUsed = true;
const SkRect& bounds =
- static_cast<const GrPLSGeometryProcessor*>(args.fPrimitiveProcessor)->getBounds();
+ static_cast<const GrPLSGeometryProcessor&>(primProc).getBounds();
// setup pixel local storage -- this means capturing and storing the current framebuffer color
// and initializing the winding counts to zero
- GrRenderTarget* rt = args.fPipeline->getRenderTarget();
+ GrRenderTarget* rt = pipeline.getRenderTarget();
SkScalar width = SkIntToScalar(rt->width());
SkScalar height = SkIntToScalar(rt->height());
// dst rect edges in NDC (-1 to 1)
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 39d565987d..e365601e1f 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -27,7 +27,7 @@
#include "SkTypes.h"
class GrPipeline;
-class GrNonInstancedVertices;
+class GrNonInstancedMesh;
class GrSwizzle;
#ifdef SK_DEVELOPER
@@ -95,10 +95,6 @@ public:
fHWGeometryState.notifyIndexBufferDelete(id);
}
- void buildProgramDesc(GrProgramDesc*,
- const GrPrimitiveProcessor&,
- const GrPipeline&) const override;
-
// id and type (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, etc.) of buffer to bind
void bindBuffer(GrGLuint id, GrGLenum type);
@@ -216,7 +212,10 @@ private:
void onResolveRenderTarget(GrRenderTarget* target) override;
- void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override;
+ void onDraw(const GrPipeline&,
+ const GrPrimitiveProcessor&,
+ const GrMesh*,
+ int meshCount) override;
bool onCopySurface(GrSurface* dst,
GrSurface* src,
@@ -232,13 +231,13 @@ private:
void setTextureUnit(int unitIdx);
// Flushes state from GrPipeline to GL. Returns false if the state couldn't be set.
- bool flushGLState(const DrawArgs&);
+ bool flushGLState(const GrPipeline& pipeline, const GrPrimitiveProcessor& primProc);
// Sets up vertex attribute pointers and strides. On return indexOffsetInBytes gives the offset
// an into the index buffer. It does not account for vertices.startIndex() but rather the start
// index is relative to the returned offset.
void setupGeometry(const GrPrimitiveProcessor&,
- const GrNonInstancedVertices& vertices,
+ const GrNonInstancedMesh& mesh,
size_t* indexOffsetInBytes);
void flushBlend(const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle&);
@@ -261,7 +260,7 @@ private:
void stampRectUsingProgram(GrGLuint program, const SkRect& bounds, GrGLint posXformUniform,
GrGLuint arrayBuffer);
- void setupPixelLocalStorage(const DrawArgs& args);
+ void setupPixelLocalStorage(const GrPipeline&, const GrPrimitiveProcessor&);
static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
@@ -272,7 +271,7 @@ private:
void reset();
void abandon();
- GrGLProgram* refProgram(const DrawArgs&);
+ GrGLProgram* refProgram(const GrGLGpu* gpu, const GrPipeline&, const GrPrimitiveProcessor&);
private:
enum {
diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp
index df8cf60c7b..f37264aa1d 100644
--- a/src/gpu/gl/GrGLGpuProgramCache.cpp
+++ b/src/gpu/gl/GrGLGpuProgramCache.cpp
@@ -108,28 +108,37 @@ int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const {
return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
}
-GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) {
+GrGLProgram* GrGLGpu::ProgramCache::refProgram(const GrGLGpu* gpu,
+ const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc) {
#ifdef PROGRAM_CACHE_STATS
++fTotalRequests;
#endif
+ // Get GrGLProgramDesc
+ GrGLProgramDesc desc;
+ if (!GrGLProgramDescBuilder::Build(&desc, primProc, pipeline, *gpu->glCaps().glslCaps())) {
+ GrCapsDebugf(gpu->caps(), "Failed to gl program descriptor!\n");
+ return nullptr;
+ }
+
Entry* entry = nullptr;
- uint32_t hashIdx = args.fDesc->getChecksum();
+ uint32_t hashIdx = desc.getChecksum();
hashIdx ^= hashIdx >> 16;
if (kHashBits <= 8) {
hashIdx ^= hashIdx >> 8;
}
hashIdx &=((1 << kHashBits) - 1);
Entry* hashedEntry = fHashTable[hashIdx];
- if (hashedEntry && hashedEntry->fProgram->getDesc() == *args.fDesc) {
+ if (hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
SkASSERT(hashedEntry->fProgram);
entry = hashedEntry;
}
int entryIdx;
if (nullptr == entry) {
- entryIdx = this->search(*args.fDesc);
+ entryIdx = this->search(desc);
if (entryIdx >= 0) {
entry = fEntries[entryIdx];
#ifdef PROGRAM_CACHE_STATS
@@ -143,7 +152,7 @@ GrGLProgram* GrGLGpu::ProgramCache::refProgram(const DrawArgs& args) {
#ifdef PROGRAM_CACHE_STATS
++fCacheMisses;
#endif
- GrGLProgram* program = GrGLProgramBuilder::CreateProgram(args, fGpu);
+ GrGLProgram* program = GrGLProgramBuilder::CreateProgram(pipeline, primProc, desc, fGpu);
if (nullptr == program) {
return nullptr;
}
diff --git a/src/gpu/gl/GrGLPathRendering.cpp b/src/gpu/gl/GrGLPathRendering.cpp
index 723d73d535..47274f9d69 100644
--- a/src/gpu/gl/GrGLPathRendering.cpp
+++ b/src/gpu/gl/GrGLPathRendering.cpp
@@ -142,13 +142,16 @@ void GrGLPathRendering::onStencilPath(const StencilPathArgs& args, const GrPath*
}
}
-void GrGLPathRendering::onDrawPath(const DrawPathArgs& args, const GrPath* path) {
- if (!this->gpu()->flushGLState(args)) {
+void GrGLPathRendering::onDrawPath(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrStencilSettings& stencil,
+ const GrPath* path) {
+ if (!this->gpu()->flushGLState(pipeline, primProc)) {
return;
}
const GrGLPath* glPath = static_cast<const GrGLPath*>(path);
- this->flushPathStencilSettings(*args.fStencil);
+ this->flushPathStencilSettings(stencil);
SkASSERT(!fHWPathStencilSettings.isTwoSided());
GrGLenum fillMode = gr_stencil_op_to_gl_path_rendering_fill_mode(
@@ -167,16 +170,18 @@ void GrGLPathRendering::onDrawPath(const DrawPathArgs& args, const GrPath* path)
}
}
-void GrGLPathRendering::onDrawPaths(const DrawPathArgs& args, const GrPathRange* pathRange,
+void GrGLPathRendering::onDrawPaths(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrStencilSettings& stencil, const GrPathRange* pathRange,
const void* indices, PathIndexType indexType,
const float transformValues[], PathTransformType transformType,
int count) {
SkDEBUGCODE(verify_floats(transformValues, gXformType2ComponentCount[transformType] * count));
- if (!this->gpu()->flushGLState(args)) {
+ if (!this->gpu()->flushGLState(pipeline, primProc)) {
return;
}
- this->flushPathStencilSettings(*args.fStencil);
+ this->flushPathStencilSettings(stencil);
SkASSERT(!fHWPathStencilSettings.isTwoSided());
diff --git a/src/gpu/gl/GrGLPathRendering.h b/src/gpu/gl/GrGLPathRendering.h
index c3e5317808..cd4668fc88 100644
--- a/src/gpu/gl/GrGLPathRendering.h
+++ b/src/gpu/gl/GrGLPathRendering.h
@@ -65,9 +65,19 @@ public:
protected:
void onStencilPath(const StencilPathArgs&, const GrPath*) override;
- void onDrawPath(const DrawPathArgs&, const GrPath*) override;
- void onDrawPaths(const DrawPathArgs&, const GrPathRange*, const void* indices, PathIndexType,
- const float transformValues[], PathTransformType, int count) override;
+ void onDrawPath(const GrPipeline&,
+ const GrPrimitiveProcessor&,
+ const GrStencilSettings&,
+ const GrPath*) override;
+ void onDrawPaths(const GrPipeline&,
+ const GrPrimitiveProcessor&,
+ const GrStencilSettings&,
+ const GrPathRange*,
+ const void* indices,
+ PathIndexType,
+ const float transformValues[],
+ PathTransformType,
+ int count) override;
private:
/**
* Mark certain functionality as not supported.
diff --git a/src/gpu/gl/GrGLVaryingHandler.cpp b/src/gpu/gl/GrGLVaryingHandler.cpp
index a2d4e9d1b9..b7c8729305 100644
--- a/src/gpu/gl/GrGLVaryingHandler.cpp
+++ b/src/gpu/gl/GrGLVaryingHandler.cpp
@@ -19,9 +19,9 @@ GrGLSLVaryingHandler::VaryingHandle GrGLVaryingHandler::addPathProcessingVarying
GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder;
// This call is not used for non-NVPR backends.
SkASSERT(glPB->gpu()->glCaps().shaderCaps()->pathRenderingSupport() &&
- glPB->fArgs.fPrimitiveProcessor->isPathRendering() &&
- !glPB->fArgs.fPrimitiveProcessor->willUseGeoShader() &&
- glPB->fArgs.fPrimitiveProcessor->numAttribs() == 0);
+ glPB->fPrimProc.isPathRendering() &&
+ !glPB->fPrimProc.willUseGeoShader() &&
+ glPB->fPrimProc.numAttribs() == 0);
#endif
this->addVarying(name, v, fsPrecision);
auto varyingInfo = fPathProcVaryingInfos.push_back();
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 1c5cf25eb7..30df7a79af 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -16,6 +16,7 @@
#include "SkTraceEvent.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLProgram.h"
+#include "gl/GrGLProgramDesc.h"
#include "gl/GrGLSLPrettyPrint.h"
#include "gl/builders/GrGLShaderStringBuilder.h"
#include "glsl/GrGLSLCaps.h"
@@ -28,12 +29,15 @@
#define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X)
#define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X)
-GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gpu) {
+GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrGLProgramDesc& desc,
+ GrGLGpu* gpu) {
GrAutoLocaleSetter als("C");
// create a builder. This will be handed off to effects so they can use it to add
// uniforms, varyings, textures, etc
- GrGLProgramBuilder builder(gpu, args);
+ GrGLProgramBuilder builder(gpu, pipeline, primProc, desc);
// TODO: Once all stages can handle taking a float or vec4 and correctly handling them we can
// seed correctly here
@@ -50,8 +54,11 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp
/////////////////////////////////////////////////////////////////////////////
-GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
- : INHERITED(args)
+GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu,
+ const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ const GrGLProgramDesc& desc)
+ : INHERITED(pipeline, primProc, desc)
, fGpu(gpu)
, fVaryingHandler(this)
, fUniformHandler(this) {
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index a3a0fe762b..f2714f378a 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -17,6 +17,7 @@
class GrFragmentProcessor;
class GrGLContextInfo;
+class GrGLProgramDesc;
class GrGLSLShaderBuilder;
class GrGLSLCaps;
@@ -29,7 +30,10 @@ public:
* to be used.
* @return true if generation was successful.
*/
- static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*);
+ static GrGLProgram* CreateProgram(const GrPipeline&,
+ const GrPrimitiveProcessor&,
+ const GrGLProgramDesc&,
+ GrGLGpu*);
const GrCaps* caps() const override;
const GrGLSLCaps* glslCaps() const override;
@@ -37,7 +41,8 @@ public:
GrGLGpu* gpu() const { return fGpu; }
private:
- GrGLProgramBuilder(GrGLGpu*, const DrawArgs&);
+ GrGLProgramBuilder(GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&,
+ const GrGLProgramDesc&);
bool compileAndAttachShaders(GrGLSLShaderBuilder& shader,
GrGLuint programId,