Remove hacks for UShort2 texture coords
Plumb GPU type down for binding of vertex attributes in GL. Use that
to select between float and int versions of VertexAttribPointer.
For client code that was relying on the strange behavior of UShort2,
use shader caps to pick the appropriate GrSLType.
Bug: skia:
Change-Id: If52ea49e0a5667246687e90e088d0823dbedb921
Reviewed-on: https://skia-review.googlesource.com/155401
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index b5ee46e..f33fedc 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -1828,8 +1828,8 @@
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);
+ attribState->set(this, attrib.fLocation, vertexBuffer, attrib.fCPUType, attrib.fGPUType,
+ vertexStride, bufferOffset + attrib.fOffset, kDivisor);
}
}
if (int instanceStride = fHWProgram->instanceStride()) {
@@ -1839,8 +1839,9 @@
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);
+ attribState->set(this, attrib.fLocation, instanceBuffer, attrib.fCPUType,
+ attrib.fGPUType, instanceStride, bufferOffset + attrib.fOffset,
+ kDivisor);
}
}
}
@@ -3462,7 +3463,7 @@
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fStencilClipClearArrayBuffer.get(), kFloat2_GrVertexAttribType,
- 2 * sizeof(GrGLfloat), 0);
+ kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0);
GrXferProcessor::BlendInfo blendInfo;
blendInfo.reset();
@@ -3574,7 +3575,7 @@
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fClearProgramArrayBuffer.get(), kFloat2_GrVertexAttribType,
- 2 * sizeof(GrGLfloat), 0);
+ kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0);
GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(dst);
this->flushScissor(clip.scissorState(), glrt->getViewport(), origin);
@@ -3634,7 +3635,7 @@
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fCopyProgramArrayBuffer.get(), kFloat2_GrVertexAttribType,
- 2 * sizeof(GrGLfloat), 0);
+ kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0);
// dst rect edges in NDC (-1 to 1)
int dw = dst->width();
@@ -3833,7 +3834,7 @@
GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this);
attribs->enableVertexArrays(this, 1);
attribs->set(this, 0, fMipmapProgramArrayBuffer.get(), kFloat2_GrVertexAttribType,
- 2 * sizeof(GrGLfloat), 0);
+ kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0);
// Set "simple" state once:
GrXferProcessor::BlendInfo blendInfo;
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 1a2ef20..f0d0395 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -33,7 +33,8 @@
* Additionally, these store the attribute location.
*/
struct Attribute {
- GrVertexAttribType fType;
+ GrVertexAttribType fCPUType;
+ GrSLType fGPUType;
size_t fOffset;
GrGLint fLocation;
};
diff --git a/src/gpu/gl/GrGLVertexArray.cpp b/src/gpu/gl/GrGLVertexArray.cpp
index 2f65ed5..4646adc 100644
--- a/src/gpu/gl/GrGLVertexArray.cpp
+++ b/src/gpu/gl/GrGLVertexArray.cpp
@@ -76,70 +76,11 @@
return {false, 0, 0};
};
-static bool GrVertexAttribTypeIsIntType(const GrShaderCaps* shaderCaps,
- GrVertexAttribType type) {
- switch (type) {
- case kFloat_GrVertexAttribType:
- return false;
- case kFloat2_GrVertexAttribType:
- return false;
- case kFloat3_GrVertexAttribType:
- return false;
- case kFloat4_GrVertexAttribType:
- return false;
- case kHalf_GrVertexAttribType:
- return false;
- case kHalf2_GrVertexAttribType:
- return false;
- case kHalf3_GrVertexAttribType:
- return false;
- case kHalf4_GrVertexAttribType:
- return false;
- case kInt2_GrVertexAttribType:
- return true;
- case kInt3_GrVertexAttribType:
- return true;
- case kInt4_GrVertexAttribType:
- return true;
- case kByte_GrVertexAttribType:
- return true;
- case kByte2_GrVertexAttribType:
- return true;
- case kByte3_GrVertexAttribType:
- return true;
- case kByte4_GrVertexAttribType:
- return true;
- case kUByte_GrVertexAttribType:
- return true;
- case kUByte2_GrVertexAttribType:
- return true;
- case kUByte3_GrVertexAttribType:
- return true;
- case kUByte4_GrVertexAttribType:
- return true;
- case kUByte_norm_GrVertexAttribType:
- return false;
- case kUByte4_norm_GrVertexAttribType:
- return false;
- case kShort2_GrVertexAttribType:
- return true;
- case kUShort2_GrVertexAttribType:
- return shaderCaps->integerSupport(); // FIXME: caller should handle this.
- case kUShort2_norm_GrVertexAttribType:
- return false;
- case kInt_GrVertexAttribType:
- return true;
- case kUint_GrVertexAttribType:
- return true;
- }
- SK_ABORT("Unexpected attribute type");
- return false;
-}
-
void GrGLAttribArrayState::set(GrGLGpu* gpu,
int index,
const GrBuffer* vertexBuffer,
- GrVertexAttribType type,
+ GrVertexAttribType cpuType,
+ GrSLType gpuType,
GrGLsizei stride,
size_t offsetInBytes,
int divisor) {
@@ -147,13 +88,14 @@
SkASSERT(0 == divisor || gpu->caps()->instanceAttribSupport());
AttribArrayState* array = &fAttribArrayStates[index];
if (array->fVertexBufferUniqueID != vertexBuffer->uniqueID() ||
- array->fType != type ||
+ array->fCPUType != cpuType ||
+ array->fGPUType != gpuType ||
array->fStride != stride ||
array->fOffset != offsetInBytes) {
gpu->bindBuffer(kVertex_GrBufferType, vertexBuffer);
- const AttribLayout& layout = attrib_layout(type);
+ const AttribLayout& layout = attrib_layout(cpuType);
const GrGLvoid* offsetAsPtr = reinterpret_cast<const GrGLvoid*>(offsetInBytes);
- if (!GrVertexAttribTypeIsIntType(gpu->caps()->shaderCaps(), type)) {
+ if (GrSLTypeIsFloatType(gpuType)) {
GR_GL_CALL(gpu->glInterface(), VertexAttribPointer(index,
layout.fCount,
layout.fType,
@@ -170,7 +112,8 @@
offsetAsPtr));
}
array->fVertexBufferUniqueID = vertexBuffer->uniqueID();
- array->fType = type;
+ array->fCPUType = cpuType;
+ array->fGPUType = gpuType;
array->fStride = stride;
array->fOffset = offsetInBytes;
}
diff --git a/src/gpu/gl/GrGLVertexArray.h b/src/gpu/gl/GrGLVertexArray.h
index e460c04..93bd526 100644
--- a/src/gpu/gl/GrGLVertexArray.h
+++ b/src/gpu/gl/GrGLVertexArray.h
@@ -40,7 +40,8 @@
void set(GrGLGpu*,
int attribIndex,
const GrBuffer* vertexBuffer,
- GrVertexAttribType type,
+ GrVertexAttribType cpuType,
+ GrSLType gpuType,
GrGLsizei stride,
size_t offsetInBytes,
int divisor = 0);
@@ -77,7 +78,8 @@
}
GrGpuResource::UniqueID fVertexBufferUniqueID;
- GrVertexAttribType fType;
+ GrVertexAttribType fCPUType;
+ GrSLType fGPUType;
GrGLsizei fStride;
size_t fOffset;
int fDivisor;
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index be72881..3904265 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -136,7 +136,8 @@
fAttributes.reset(
new GrGLProgram::Attribute[fVertexAttributeCnt + fInstanceAttributeCnt]);
auto addAttr = [&](int i, const auto& a, size_t* stride) {
- fAttributes[i].fType = a.cpuType();
+ fAttributes[i].fCPUType = a.cpuType();
+ fAttributes[i].fGPUType = a.gpuType();
fAttributes[i].fOffset = *stride;
*stride += a.sizeAlign4();
fAttributes[i].fLocation = i;