diff options
author | 2018-06-19 01:40:57 +0000 | |
---|---|---|
committer | 2018-06-19 01:41:10 +0000 | |
commit | 5045e501d2aec23e5f1e4b46346033ac3202c6b0 (patch) | |
tree | b0179c300d6bc1822b0d945be812fff267bb414a /src/gpu/gl | |
parent | 63b3bfb711d7e3d4f9ad75681d77a69a3c454ab0 (diff) |
Revert "Change how vertex/instance attributes are handled in geometry processors."
This reverts commit 19c1233c447f625c2522e7ecd0a0adecc629bb2f.
Reason for revert: want to make sure Google3 can roll
Original change's description:
> 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>
TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com
Change-Id: I4800632515e14fbf54af52826928ac915657b59f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/135661
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/gpu/gl')
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 40 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 27 | ||||
-rw-r--r-- | src/gpu/gl/GrGLVaryingHandler.cpp | 3 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 38 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.h | 7 |
6 files changed, 48 insertions, 73 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index be53222ee8..88f5abecb4 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -1775,29 +1775,35 @@ void GrGLGpu::setupGeometry(const GrBuffer* indexBuffer, attribState = fHWVertexArrayState.bindInternalVertexArray(this); } - int numAttribs = fHWProgram->numVertexAttributes() + fHWProgram->numInstanceAttributes(); - attribState->enableVertexArrays(this, numAttribs, enablePrimitiveRestart); + struct { + const GrBuffer* fBuffer; + int fStride; + size_t fBufferOffset; + } bindings[2]; if (int vertexStride = fHWProgram->vertexStride()) { SkASSERT(vertexBuffer && !vertexBuffer->isMapped()); - size_t bufferOffset = vertexBuffer->baseOffset() + baseVertex * vertexStride; - for (int i = 0; i < fHWProgram->numVertexAttributes(); ++i) { - const auto& attrib = fHWProgram->vertexAttribute(i); - static constexpr int kDivisor = 0; - attribState->set(this, attrib.fLocation, vertexBuffer, attrib.fType, vertexStride, - bufferOffset + attrib.fOffset, kDivisor); - } + bindings[0].fBuffer = vertexBuffer; + bindings[0].fStride = vertexStride; + bindings[0].fBufferOffset = vertexBuffer->baseOffset() + baseVertex * vertexStride; } if (int instanceStride = fHWProgram->instanceStride()) { SkASSERT(instanceBuffer && !instanceBuffer->isMapped()); - size_t bufferOffset = instanceBuffer->baseOffset() + baseInstance * instanceStride; - int attribIdx = fHWProgram->numVertexAttributes(); - for (int i = 0; i < fHWProgram->numInstanceAttributes(); ++i, ++attribIdx) { - const auto& attrib = fHWProgram->instanceAttribute(i); - static constexpr int kDivisor = 1; - attribState->set(this, attrib.fLocation, instanceBuffer, attrib.fType, instanceStride, - bufferOffset + attrib.fOffset, kDivisor); - } + bindings[1].fBuffer = instanceBuffer; + bindings[1].fStride = instanceStride; + bindings[1].fBufferOffset = instanceBuffer->baseOffset() + baseInstance * instanceStride; + } + + auto numAttributes = fHWProgram->numAttributes(); + attribState->enableVertexArrays(this, numAttributes, enablePrimitiveRestart); + + for (int i = 0; i < numAttributes; ++i) { + using InputRate = GrPrimitiveProcessor::Attribute::InputRate; + const GrGLProgram::Attribute& attribute = fHWProgram->attribute(i); + const int divisor = InputRate::kPerInstance == attribute.fInputRate ? 1 : 0; + const auto& binding = bindings[divisor]; + attribState->set(this, attribute.fLocation, binding.fBuffer, attribute.fType, + binding.fStride, binding.fBufferOffset + attribute.fOffset, divisor); } } diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 3d4bd380fa..262f0b21c4 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -38,8 +38,7 @@ GrGLProgram::GrGLProgram( std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors, int fragmentProcessorCnt, std::unique_ptr<Attribute[]> attributes, - int vertexAttributeCnt, - int instanceAttributeCnt, + int attributeCnt, int vertexStride, int instanceStride) : fBuiltinUniformHandles(builtinUniforms) @@ -49,8 +48,7 @@ GrGLProgram::GrGLProgram( , fFragmentProcessors(std::move(fragmentProcessors)) , fFragmentProcessorCnt(fragmentProcessorCnt) , fAttributes(std::move(attributes)) - , fVertexAttributeCnt(vertexAttributeCnt) - , fInstanceAttributeCnt(instanceAttributeCnt) + , fAttributeCnt(attributeCnt) , fVertexStride(vertexStride) , fInstanceStride(instanceStride) , fGpu(gpu) diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index ca4eddce4b..6ea1f2cbf9 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -10,6 +10,7 @@ #define GrGLProgram_DEFINED #include "GrGLProgramDataManager.h" +#include "GrPrimitiveProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" @@ -34,18 +35,15 @@ public: */ struct Attribute { GrVertexAttribType fType; - size_t fOffset; + int fOffset; GrGLint fLocation; + GrPrimitiveProcessor::Attribute::InputRate fInputRate; }; using UniformHandle = GrGLSLProgramDataManager::UniformHandle; using UniformInfoArray = GrGLProgramDataManager::UniformInfoArray; using VaryingInfoArray = GrGLProgramDataManager::VaryingInfoArray; - /** - * The attribute array consists of vertexAttributeCnt + instanceAttributeCnt elements with - * the vertex attributes preceding the instance attributes. - */ GrGLProgram(GrGLGpu*, const GrGLSLBuiltinUniformHandles&, GrGLuint programID, @@ -58,8 +56,7 @@ public: std::unique_ptr<std::unique_ptr<GrGLSLFragmentProcessor>[]> fragmentProcessors, int fragmentProcessorCnt, std::unique_ptr<Attribute[]>, - int vertexAttributeCnt, - int instanceAttributeCnt, + int attributeCnt, int vertexStride, int instanceStride); @@ -127,17 +124,8 @@ public: int vertexStride() const { return fVertexStride; } int instanceStride() const { return fInstanceStride; } - int numVertexAttributes() const { return fVertexAttributeCnt; } - const Attribute& vertexAttribute(int i) const { - SkASSERT(i >= 0 && i < fVertexAttributeCnt); - return fAttributes[i]; - } - - int numInstanceAttributes() const { return fInstanceAttributeCnt; } - const Attribute& instanceAttribute(int i) const { - SkASSERT(i >= 0 && i < fInstanceAttributeCnt); - return fAttributes[i + fVertexAttributeCnt]; - } + int numAttributes() const { return fAttributeCnt; } + const Attribute& attribute(int i) const { return fAttributes[i]; } private: // A helper to loop over effects, set the transforms (via subclass) and bind textures @@ -165,8 +153,7 @@ private: int fFragmentProcessorCnt; std::unique_ptr<Attribute[]> fAttributes; - int fVertexAttributeCnt; - int fInstanceAttributeCnt; + int fAttributeCnt; int fVertexStride; int fInstanceStride; diff --git a/src/gpu/gl/GrGLVaryingHandler.cpp b/src/gpu/gl/GrGLVaryingHandler.cpp index e426d46e14..eecc63e617 100644 --- a/src/gpu/gl/GrGLVaryingHandler.cpp +++ b/src/gpu/gl/GrGLVaryingHandler.cpp @@ -20,8 +20,7 @@ GrGLSLVaryingHandler::VaryingHandle GrGLVaryingHandler::addPathProcessingVarying SkASSERT(glPB->gpu()->glCaps().shaderCaps()->pathRenderingSupport() && glPB->fPrimProc.isPathRendering() && !glPB->fPrimProc.willUseGeoShader() && - !glPB->fPrimProc.numVertexAttributes() && - !glPB->fPrimProc.numInstanceAttributes()); + glPB->fPrimProc.numAttribs() == 0); #endif this->addVarying(name, v); auto varyingInfo = fPathProcVaryingInfos.push_back(); diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 79e13d3555..0cdc3b5b21 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -70,8 +70,7 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, , fGpu(gpu) , fVaryingHandler(this) , fUniformHandler(this) - , fVertexAttributeCnt(0) - , fInstanceAttributeCnt(0) + , fAttributeCnt(0) , fVertexStride(0) , fInstanceStride(0) {} @@ -228,30 +227,18 @@ GrGLProgram* GrGLProgramBuilder::finalize() { // NVPR actually requires a vertex shader to compile bool useNvpr = primProc.isPathRendering(); if (!useNvpr) { - 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(); + 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(); fAttributes[i].fLocation = i; - 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)); + GL_CALL(BindAttribLocation(programID, i, attr.name())); } - 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()) { @@ -419,8 +406,7 @@ GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { std::move(fFragmentProcessors), fFragmentProcessorCnt, std::move(fAttributes), - fVertexAttributeCnt, - fInstanceAttributeCnt, + fAttributeCnt, fVertexStride, fInstanceStride); } diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 30d5179325..ea3432bd04 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -81,10 +81,9 @@ private: GrGLUniformHandler fUniformHandler; std::unique_ptr<GrGLProgram::Attribute[]> fAttributes; - int fVertexAttributeCnt; - int fInstanceAttributeCnt; - size_t fVertexStride; - size_t fInstanceStride; + int fAttributeCnt; + int fVertexStride; + int fInstanceStride; // shader pulled from cache. Data is organized as: // SkSL::Program::Inputs inputs |