Commit bcb6a1e0 by Jamie Madill

Simplify the varying priority sorting logic, and add more verbose comments.

TRAC #23746 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods
parent 921968ca
...@@ -525,54 +525,70 @@ GLenum Shader::parseType(const std::string &type) ...@@ -525,54 +525,70 @@ GLenum Shader::parseType(const std::string &type)
return GL_NONE; return GL_NONE;
} }
typedef std::map<GLenum, int> VaryingPriorityMap; // [OpenGL ES SL 3.00.4] Section 11 p. 120
static VaryingPriorityMap varyingPriorities; // Vertex Outs/Fragment Ins packing priorities
static const GLenum varyingPriorityList[] =
static void makeVaryingPriorityMap() {
{ // 1. Arrays of mat4 and mat4
varyingPriorities[GL_FLOAT_MAT4] = 0; GL_FLOAT_MAT4,
varyingPriorities[GL_FLOAT_MAT3x4] = 10;
varyingPriorities[GL_FLOAT_MAT4x3] = 20; // Non-square matrices of type matCxR consume the same space as a square
varyingPriorities[GL_FLOAT_MAT2x4] = 30; // matrix of type matN where N is the greater of C and R
varyingPriorities[GL_FLOAT_MAT4x2] = 40; GL_FLOAT_MAT3x4,
varyingPriorities[GL_FLOAT_MAT2] = 50; GL_FLOAT_MAT4x3,
varyingPriorities[GL_FLOAT_VEC4] = 60; GL_FLOAT_MAT2x4,
varyingPriorities[GL_INT_VEC4] = 61; GL_FLOAT_MAT4x2,
varyingPriorities[GL_UNSIGNED_INT_VEC4] = 62;
varyingPriorities[GL_FLOAT_MAT3] = 70; // 2. Arrays of mat2 and mat2 (since they occupy full rows)
varyingPriorities[GL_FLOAT_MAT2x3] = 80; GL_FLOAT_MAT2,
varyingPriorities[GL_FLOAT_MAT3x2] = 90;
varyingPriorities[GL_FLOAT_VEC3] = 100; // 3. Arrays of vec4 and vec4
varyingPriorities[GL_INT_VEC3] = 101; GL_FLOAT_VEC4,
varyingPriorities[GL_UNSIGNED_INT_VEC3] = 102; GL_INT_VEC4,
varyingPriorities[GL_FLOAT_VEC2] = 110; GL_UNSIGNED_INT_VEC4,
varyingPriorities[GL_INT_VEC2] = 111;
varyingPriorities[GL_UNSIGNED_INT_VEC2] = 112; // 4. Arrays of mat3 and mat3
varyingPriorities[GL_FLOAT] = 120; GL_FLOAT_MAT3,
varyingPriorities[GL_INT] = 125; GL_FLOAT_MAT2x3,
varyingPriorities[GL_UNSIGNED_INT] = 130; GL_FLOAT_MAT3x2,
}
// 5. Arrays of vec3 and vec3
GL_FLOAT_VEC3,
GL_INT_VEC3,
GL_UNSIGNED_INT_VEC3,
// 6. Arrays of vec2 and vec2
GL_FLOAT_VEC2,
GL_INT_VEC2,
GL_UNSIGNED_INT_VEC2,
// 7. Arrays of float and float
GL_FLOAT,
GL_INT,
GL_UNSIGNED_INT,
};
// true if varying x has a higher priority in packing than y // true if varying x has a higher priority in packing than y
bool Shader::compareVarying(const Varying &x, const Varying &y) bool Shader::compareVarying(const Varying &x, const Varying &y)
{ {
if (varyingPriorities.empty()) if (x.type == y.type)
{ {
makeVaryingPriorityMap(); return x.size > y.size;
} }
if(x.type == y.type) unsigned int xPriority = GL_INVALID_INDEX;
unsigned int yPriority = GL_INVALID_INDEX;
for (unsigned int priorityIndex = 0; priorityIndex < ArraySize(varyingPriorityList); priorityIndex++)
{ {
return x.size > y.size; if (varyingPriorityList[priorityIndex] == x.type) xPriority = priorityIndex;
if (varyingPriorityList[priorityIndex] == y.type) yPriority = priorityIndex;
if (xPriority != GL_INVALID_INDEX && yPriority != GL_INVALID_INDEX) break;
} }
VaryingPriorityMap::iterator xPriority = varyingPriorities.find(x.type); ASSERT(xPriority != GL_INVALID_INDEX && yPriority != GL_INVALID_INDEX);
VaryingPriorityMap::iterator yPriority = varyingPriorities.find(y.type);
ASSERT(xPriority != varyingPriorities.end());
ASSERT(yPriority != varyingPriorities.end());
return xPriority->second <= yPriority->second; return xPriority <= yPriority;
} }
int Shader::getShaderVersion() const int Shader::getShaderVersion() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment