aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-07 22:06:08 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-07 22:06:08 +0000
commitd3baf20dd1de9940717dd50b5c9ff6061561342e (patch)
treeae0f7b376e67362e4e20cf3a6edc5309dc48b9b5 /src/gpu/gl
parent5e4d9819dbcbfbbdbd2ad2840b9c1b2b01c98db1 (diff)
Added support for Chrome's gpu command buffer extension BindUniformLocation.
R=bsalomon@google.com, bsalomon Author: skaslev@chromium.org Review URL: https://codereview.chromium.org/62163004 git-svn-id: http://skia.googlecode.com/svn/trunk@12178 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLProgram.cpp4
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp7
-rw-r--r--src/gpu/gl/GrGLUniformManager.cpp59
-rw-r--r--src/gpu/gl/GrGLUniformManager.h24
4 files changed, 56 insertions, 38 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index f80bc2e550..accaf884d1 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -272,7 +272,7 @@ void GrGLProgram::setColor(const GrDrawState& drawState,
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(color, c);
- fUniformManager.set4fv(fUniformHandles.fColorUni, 0, 1, c);
+ fUniformManager.set4fv(fUniformHandles.fColorUni, 1, c);
fColor = color;
}
sharedState->fConstAttribColorIndex = -1;
@@ -311,7 +311,7 @@ void GrGLProgram::setCoverage(const GrDrawState& drawState,
// OpenGL ES doesn't support unsigned byte varieties of glUniform
GrGLfloat c[4];
GrColorToRGBAFloat(coverage, c);
- fUniformManager.set4fv(fUniformHandles.fCoverageUni, 0, 1, c);
+ fUniformManager.set4fv(fUniformHandles.fCoverageUni, 1, c);
fCoverage = coverage;
}
sharedState->fConstAttribCoverageIndex = -1;
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 348ee2622f..961cad798f 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -588,6 +588,9 @@ bool GrGLShaderBuilder::finish(GrGLuint* outProgramId) {
}
this->bindProgramLocations(programId);
+ if (fUniformManager.isUsingBindUniform()) {
+ fUniformManager.getUniformLocations(programId, fUniforms);
+ }
GL_CALL(LinkProgram(programId));
@@ -619,7 +622,9 @@ bool GrGLShaderBuilder::finish(GrGLuint* outProgramId) {
}
}
- fUniformManager.getUniformLocations(programId, fUniforms);
+ if (!fUniformManager.isUsingBindUniform()) {
+ fUniformManager.getUniformLocations(programId, fUniforms);
+ }
*outProgramId = programId;
return true;
}
diff --git a/src/gpu/gl/GrGLUniformManager.cpp b/src/gpu/gl/GrGLUniformManager.cpp
index 74bb651fa4..2d0b48a2be 100644
--- a/src/gpu/gl/GrGLUniformManager.cpp
+++ b/src/gpu/gl/GrGLUniformManager.cpp
@@ -11,9 +11,13 @@
#include "gl/GrGpuGL.h"
#include "SkMatrix.h"
-#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \
- SkASSERT(offset + arrayCount <= uni.fArrayCount || \
- (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
+#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
+ SkASSERT(arrayCount <= uni.fArrayCount || \
+ (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
+
+GrGLUniformManager::GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {
+ fUsingBindUniform = fGpu->glInterface()->fBindUniformLocation != NULL;
+}
GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType type, int arrayCount) {
int idx = fUniforms.count();
@@ -56,22 +60,21 @@ void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const {
}
void GrGLUniformManager::set1fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kFloat_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
// This assert fires in some instances of the two-pt gradient for its VSParams.
// Once the uniform manager is responsible for inserting the duplicate uniform
// arrays in VS and FS driver bug workaround, this can be enabled.
//SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v));
}
}
@@ -89,19 +92,18 @@ void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) cons
}
void GrGLUniformManager::set2fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec2f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v));
}
}
@@ -119,19 +121,18 @@ void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGL
}
void GrGLUniformManager::set3fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec3f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v));
}
}
@@ -153,18 +154,18 @@ void GrGLUniformManager::set4f(UniformHandle u,
}
void GrGLUniformManager::set4fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat v[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kVec4f_GrSLType);
SkASSERT(arrayCount > 0);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
- GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation + offset, arrayCount, v));
+ GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v));
}
}
@@ -196,40 +197,38 @@ void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[])
}
void GrGLUniformManager::setMatrix3fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kMat33f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices));
}
}
void GrGLUniformManager::setMatrix4fv(UniformHandle u,
- int offset,
int arrayCount,
const GrGLfloat matrices[]) const {
const Uniform& uni = fUniforms[u.toUniformIndex()];
SkASSERT(uni.fType == kMat44f_GrSLType);
SkASSERT(arrayCount > 0);
- ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
+ ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
if (kUnusedUniform != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices));
}
if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
GR_GL_CALL(fGpu->glInterface(),
- UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices));
+ UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices));
}
}
@@ -258,8 +257,14 @@ void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn
SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount);
GrGLint location;
// TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
- GR_GL_CALL_RET(fGpu->glInterface(), location,
+ if (fUsingBindUniform) {
+ location = i;
+ GR_GL_CALL(fGpu->glInterface(),
+ BindUniformLocation(programID, location, uniforms[i].fVariable.c_str()));
+ } else {
+ GR_GL_CALL_RET(fGpu->glInterface(), location,
GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
+ }
if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
fUniforms[i].fVSLocation = location;
}
diff --git a/src/gpu/gl/GrGLUniformManager.h b/src/gpu/gl/GrGLUniformManager.h
index eefab04986..d7438f9ed7 100644
--- a/src/gpu/gl/GrGLUniformManager.h
+++ b/src/gpu/gl/GrGLUniformManager.h
@@ -46,28 +46,28 @@ public:
friend class GrGLUniformManager; // For accessing toUniformIndex().
};
- GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {}
+ GrGLUniformManager(GrGpuGL* gpu);
UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray);
/** Functions for uploading uniform values. The varities ending in v can be used to upload to an
- * array of uniforms. offset + arrayCount must be <= the array count of the uniform.
+ * array of uniforms. arrayCount must be <= the array count of the uniform.
*/
void setSampler(UniformHandle, GrGLint texUnit) const;
void set1f(UniformHandle, GrGLfloat v0) const;
- void set1fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set2f(UniformHandle, GrGLfloat, GrGLfloat) const;
- void set2fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const;
- void set3fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const;
- void set4fv(UniformHandle, int offset, int arrayCount, const GrGLfloat v[]) const;
+ void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
// matrices are column-major, the first three upload a single matrix, the latter three upload
// arrayCount matrices into a uniform array.
void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const;
void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const;
- void setMatrix3fv(UniformHandle, int offset, int arrayCount, const GrGLfloat matrices[]) const;
- void setMatrix4fv(UniformHandle, int offset, int arrayCount, const GrGLfloat matrices[]) const;
+ void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
+ void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
// convenience method for uploading a SkMatrix to a 3x3 matrix uniform
void setSkMatrix(UniformHandle, const SkMatrix&) const;
@@ -82,6 +82,13 @@ public:
typedef GrTAllocator<BuilderUniform> BuilderUniformArray;
/**
+ * Called by the GrGLShaderBuilder to know if the manager is using
+ * BindUniformLocation. In that case getUniformLocations must be called
+ * before the program is linked.
+ */
+ bool isUsingBindUniform() const { return fUsingBindUniform; }
+
+ /**
* Called by the GrGLShaderBuilder to get GL locations for all uniforms.
*/
void getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms);
@@ -103,6 +110,7 @@ private:
int fArrayCount;
};
+ bool fUsingBindUniform;
SkTArray<Uniform, true> fUniforms;
GrGpuGL* fGpu;
};