aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/builders
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-06-18 12:52:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-18 17:13:58 +0000
commit19c1233c447f625c2522e7ecd0a0adecc629bb2f (patch)
tree891e06143986ade3aae8d4176ec8b426f70b896f /src/gpu/gl/builders
parent146cf3ce7935019ecc63ce9e93450a8c122880d8 (diff)
Change how vertex/instance attributes are handled in geometry processors.
* No longer register vertex/instance attributes on base class, just counts * Separate instance and vertex attributes and remove InputRate and offset * Make attributes constexpr where possible Change-Id: I1f1d5e772fa177a96d2aeb805aab7b69f35bfae6 Reviewed-on: https://skia-review.googlesource.com/132405 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/gl/builders')
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp38
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h7
2 files changed, 30 insertions, 15 deletions
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 0cdc3b5b21..79e13d3555 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -70,7 +70,8 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu,
, fGpu(gpu)
, fVaryingHandler(this)
, fUniformHandler(this)
- , fAttributeCnt(0)
+ , fVertexAttributeCnt(0)
+ , fInstanceAttributeCnt(0)
, fVertexStride(0)
, fInstanceStride(0) {}
@@ -227,18 +228,30 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
// NVPR actually requires a vertex shader to compile
bool useNvpr = primProc.isPathRendering();
if (!useNvpr) {
- fAttributeCnt = primProc.numAttribs();
- fAttributes.reset(new GrGLProgram::Attribute[fAttributeCnt]);
- fVertexStride = primProc.getVertexStride();
- fInstanceStride = primProc.getInstanceStride();
- for (int i = 0; i < fAttributeCnt; i++) {
- const auto& attr = primProc.getAttrib(i);
- fAttributes[i].fInputRate = attr.inputRate();
- fAttributes[i].fType = attr.type();
- fAttributes[i].fOffset = attr.offsetInRecord();
+ fVertexAttributeCnt = primProc.numVertexAttributes();
+ fInstanceAttributeCnt = primProc.numInstanceAttributes();
+ fAttributes.reset(
+ new GrGLProgram::Attribute[fVertexAttributeCnt + fInstanceAttributeCnt]);
+ auto addAttr = [&](int i, const auto& a, size_t* stride) {
+ fAttributes[i].fType = a.type();
+ fAttributes[i].fOffset = *stride;
+ *stride += a.sizeAlign4();
fAttributes[i].fLocation = i;
- GL_CALL(BindAttribLocation(programID, i, attr.name()));
+ GL_CALL(BindAttribLocation(programID, i, a.name()));
+ };
+ fVertexStride = 0;
+ int i = 0;
+ for (; i < fVertexAttributeCnt; i++) {
+ addAttr(i, primProc.vertexAttribute(i), &fVertexStride);
+ SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_vertexAttributeOffset(i));
}
+ SkASSERT(fVertexStride == primProc.debugOnly_vertexStride());
+ fInstanceStride = 0;
+ for (int j = 0; j < fInstanceAttributeCnt; j++, ++i) {
+ addAttr(i, primProc.instanceAttribute(j), &fInstanceStride);
+ SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_instanceAttributeOffset(j));
+ }
+ SkASSERT(fInstanceStride == primProc.debugOnly_instanceStride());
}
if (primProc.willUseGeoShader()) {
@@ -406,7 +419,8 @@ GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
std::move(fFragmentProcessors),
fFragmentProcessorCnt,
std::move(fAttributes),
- fAttributeCnt,
+ fVertexAttributeCnt,
+ fInstanceAttributeCnt,
fVertexStride,
fInstanceStride);
}
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index ea3432bd04..30d5179325 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -81,9 +81,10 @@ private:
GrGLUniformHandler fUniformHandler;
std::unique_ptr<GrGLProgram::Attribute[]> fAttributes;
- int fAttributeCnt;
- int fVertexStride;
- int fInstanceStride;
+ int fVertexAttributeCnt;
+ int fInstanceAttributeCnt;
+ size_t fVertexStride;
+ size_t fInstanceStride;
// shader pulled from cache. Data is organized as:
// SkSL::Program::Inputs inputs