diff options
author | 2017-02-13 15:45:35 -0700 | |
---|---|---|
committer | 2017-02-13 23:21:35 +0000 | |
commit | 936f81b95882be2e171a623b3116cc2ff408c813 (patch) | |
tree | 339761c23c6bbed0d495212a5854c2c22ab374d2 /src | |
parent | ed4984bf53b90e50acad606aeb4b35340db802a3 (diff) |
Move the rt adjust uniform into GP EmitArgs
The GP will likely require this value when dealing with a geometry
shader. In the future we may wish to either switch to device-space
geometry shaders, or else put this value in an "sk_" builtin.
BUG=skia:
Change-Id: I8dff88fc219feef84d39fb7bbd08f3b5686f53d2
Reviewed-on: https://skia-review.googlesource.com/8362
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/glsl/GrGLSLGeometryProcessor.cpp | 2 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLPrimitiveProcessor.h | 3 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.cpp | 25 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLProgramBuilder.h | 4 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp | 21 | ||||
-rw-r--r-- | src/gpu/glsl/GrGLSLVertexShaderBuilder.h | 4 |
6 files changed, 26 insertions, 33 deletions
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp index 87df89641d..f13024878f 100644 --- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp +++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp @@ -17,7 +17,7 @@ void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) { GrGLSLVertexBuilder* vBuilder = args.fVertBuilder; GrGPArgs gpArgs; this->onEmitCode(args, &gpArgs); - vBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar); + vBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar, args.fRTAdjustName); if (kVec2f_GrSLType == gpArgs.fPositionVar.getType()) { args.fVaryingHandler->setNoPerspective(); } diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h index c6480ae086..5fbf9bd42f 100644 --- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h +++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h @@ -75,6 +75,7 @@ public: const char* outputColor, const char* outputCoverage, const char* distanceVectorName, + const char* rtAdjustName, const SamplerHandle* texSamplers, const SamplerHandle* bufferSamplers, const ImageStorageHandle* imageStorages, @@ -89,6 +90,7 @@ public: , fOutputColor(outputColor) , fOutputCoverage(outputCoverage) , fDistanceVectorName(distanceVectorName) + , fRTAdjustName(rtAdjustName) , fTexSamplers(texSamplers) , fBufferSamplers(bufferSamplers) , fImageStorages(imageStorages) @@ -103,6 +105,7 @@ public: const char* fOutputColor; const char* fOutputCoverage; const char* fDistanceVectorName; + const char* fRTAdjustName; const SamplerHandle* fTexSamplers; const SamplerHandle* fBufferSamplers; const ImageStorageHandle* fImageStorages; diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp index 2b8a3a7264..385026a52d 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp +++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp @@ -91,6 +91,18 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr fFS.codeAppendf("vec4 %s;", distanceVectorName); } + SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); + GrShaderFlags rtAdjustVisibility = kVertex_GrShaderFlag; + if (proc.willUseGeoShader()) { + rtAdjustVisibility |= kGeometry_GrShaderFlag; + } + fUniformHandles.fRTAdjustmentUni = this->uniformHandler()->addUniform(rtAdjustVisibility, + kVec4f_GrSLType, + kHigh_GrSLPrecision, + "rtAdjustment"); + const char* rtAdjustName = + this->uniformHandler()->getUniformCStr(fUniformHandles.fRTAdjustmentUni); + // Enclose custom code in a block to avoid namespace conflicts SkString openBrace; openBrace.printf("{ // Stage %d, %s\n", fStageIndex, proc.name()); @@ -117,6 +129,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr outputColor->c_str(), outputCoverage->c_str(), distanceVectorName, + rtAdjustName, texSamplers.begin(), bufferSamplers.begin(), imageStorages.begin(), @@ -456,18 +469,6 @@ void GrGLSLProgramBuilder::appendUniformDecls(GrShaderFlags visibility, SkString this->uniformHandler()->appendUniformDecls(visibility, out); } -void GrGLSLProgramBuilder::addRTAdjustmentUniform(GrSLPrecision precision, - const char* name, - const char** outName) { - SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid()); - fUniformHandles.fRTAdjustmentUni = - this->uniformHandler()->addUniform(kVertex_GrShaderFlag, - kVec4f_GrSLType, - precision, - name, - outName); -} - void GrGLSLProgramBuilder::addRTHeightUniform(const char* name) { SkASSERT(!fUniformHandles.fRTHeightUni.isValid()); GrGLSLUniformHandler* uniformHandler = this->uniformHandler(); diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h index 3074110f60..321d81cad2 100644 --- a/src/gpu/glsl/GrGLSLProgramBuilder.h +++ b/src/gpu/glsl/GrGLSLProgramBuilder.h @@ -66,10 +66,6 @@ public: UniformHandle fRTHeightUni; }; - // Used to add a uniform in the vertex shader for transforming into normalized device space. - void addRTAdjustmentUniform(GrSLPrecision precision, const char* name, const char** outName); - const char* rtAdjustment() const { return "rtAdjustment"; } - // Used to add a uniform for the RenderTarget height (used for frag position) without mangling // the name of the uniform inside of a stage. void addRTHeightUniform(const char* name); diff --git a/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp b/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp index 2aded892d4..627b11d685 100644 --- a/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp @@ -11,17 +11,12 @@ #include "glsl/GrGLSLVarying.h" GrGLSLVertexBuilder::GrGLSLVertexBuilder(GrGLSLProgramBuilder* program) - : INHERITED(program) - , fRtAdjustName(nullptr) { + : INHERITED(program) { } -void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar) { - SkASSERT(!fRtAdjustName); - +void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar, + const char* rtAdjustName) { // setup RT Uniform - fProgramBuilder->addRTAdjustmentUniform(kHigh_GrSLPrecision, - fProgramBuilder->rtAdjustment(), - &fRtAdjustName); if (this->getProgramBuilder()->desc()->header().fSnapVerticesToPixelCenters) { if (kVec3f_GrSLType == posVar.getType()) { const char* p = posVar.c_str(); @@ -33,17 +28,17 @@ void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& po this->codeAppendf("_posTmp = floor(_posTmp) + vec2(0.5, 0.5);" "gl_Position = vec4(_posTmp.x * %s.x + %s.y," "_posTmp.y * %s.z + %s.w, 0, 1);}", - fRtAdjustName, fRtAdjustName, fRtAdjustName, fRtAdjustName); + rtAdjustName, rtAdjustName, rtAdjustName, rtAdjustName); } else if (kVec3f_GrSLType == posVar.getType()) { this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);", - posVar.c_str(), fRtAdjustName, - posVar.c_str(), fRtAdjustName, + posVar.c_str(), rtAdjustName, + posVar.c_str(), rtAdjustName, posVar.c_str()); } else { SkASSERT(kVec2f_GrSLType == posVar.getType()); this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);", - posVar.c_str(), fRtAdjustName, fRtAdjustName, - posVar.c_str(), fRtAdjustName, fRtAdjustName); + posVar.c_str(), rtAdjustName, rtAdjustName, + posVar.c_str(), rtAdjustName, rtAdjustName); } // We could have the GrGeometryProcessor do this, but its just easier to have it performed // here. If we ever need to set variable pointsize, then we can reinvestigate. diff --git a/src/gpu/glsl/GrGLSLVertexShaderBuilder.h b/src/gpu/glsl/GrGLSLVertexShaderBuilder.h index af8d10c2cb..5d71565056 100644 --- a/src/gpu/glsl/GrGLSLVertexShaderBuilder.h +++ b/src/gpu/glsl/GrGLSLVertexShaderBuilder.h @@ -20,12 +20,10 @@ class GrGLSLVertexBuilder : public GrGLSLShaderBuilder { public: GrGLSLVertexBuilder(GrGLSLProgramBuilder* program); - void transformToNormalizedDeviceSpace(const GrShaderVar& posVar); + void transformToNormalizedDeviceSpace(const GrShaderVar& posVar, const char* rtAdjustName); private: void onFinalize() override; - const char* fRtAdjustName; - friend class GrGLProgramBuilder; typedef GrGLSLShaderBuilder INHERITED; |