summaryrefslogtreecommitdiffstats
path: root/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp')
-rw-r--r--Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp184
1 files changed, 104 insertions, 80 deletions
diff --git a/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp b/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp
index a32bc9f..780c3e3 100644
--- a/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp
+++ b/Source/ThirdParty/ANGLE/src/libGLESv2/Program.cpp
@@ -45,7 +45,7 @@ UniformLocation::UniformLocation(const std::string &name, unsigned int element,
{
}
-Program::Program(ResourceManager *manager, GLuint handle) : mResourceManager(manager), mHandle(handle)
+Program::Program(ResourceManager *manager, GLuint handle) : mResourceManager(manager), mHandle(handle), mSerial(issueSerial())
{
mFragmentShader = NULL;
mVertexShader = NULL;
@@ -63,8 +63,6 @@ Program::Program(ResourceManager *manager, GLuint handle) : mResourceManager(man
mDeleteStatus = false;
mRefCount = 0;
-
- mSerial = issueSerial();
}
Program::~Program()
@@ -205,7 +203,7 @@ GLint Program::getSamplerMapping(unsigned int samplerIndex)
logicalTextureUnit = mSamplers[samplerIndex].logicalTextureUnit;
}
- if (logicalTextureUnit < MAX_TEXTURE_IMAGE_UNITS)
+ if (logicalTextureUnit >= 0 && logicalTextureUnit < MAX_TEXTURE_IMAGE_UNITS)
{
return logicalTextureUnit;
}
@@ -243,26 +241,22 @@ void Program::setSamplerDirty(unsigned int samplerIndex, bool dirty)
GLint Program::getUniformLocation(const char *name, bool decorated)
{
- std::string nameStr(name);
+ std::string _name = decorated ? name : decorate(name);
int subscript = 0;
- size_t beginB = nameStr.find('[');
- size_t endB = nameStr.find(']');
- if (beginB != std::string::npos && endB != std::string::npos)
- {
- std::string subscrStr = nameStr.substr(beginB + 1, beginB - endB - 1);
- nameStr.erase(beginB);
- subscript = atoi(subscrStr.c_str());
- }
- if (!decorated)
+ // Strip any trailing array operator and retrieve the subscript
+ size_t open = _name.find_last_of('[');
+ size_t close = _name.find_last_of(']');
+ if (open != std::string::npos && close == _name.length() - 1)
{
- nameStr = decorate(nameStr);
+ subscript = atoi(_name.substr(open + 1).c_str());
+ _name.erase(open);
}
unsigned int numUniforms = mUniformIndex.size();
for (unsigned int location = 0; location < numUniforms; location++)
{
- if (mUniformIndex[location].name == nameStr &&
+ if (mUniformIndex[location].name == _name &&
mUniformIndex[location].element == subscript)
{
return location;
@@ -595,7 +589,9 @@ bool Program::setUniform1iv(GLint location, GLsizei count, const GLint *v)
Uniform *targetUniform = mUniforms[mUniformIndex[location].index];
targetUniform->dirty = true;
- if (targetUniform->type == GL_INT)
+ if (targetUniform->type == GL_INT ||
+ targetUniform->type == GL_SAMPLER_2D ||
+ targetUniform->type == GL_SAMPLER_CUBE)
{
int arraySize = targetUniform->arraySize;
@@ -949,6 +945,8 @@ void Program::applyUniforms()
case GL_FLOAT_MAT2: applyUniformMatrix2fv(location, arraySize, f); break;
case GL_FLOAT_MAT3: applyUniformMatrix3fv(location, arraySize, f); break;
case GL_FLOAT_MAT4: applyUniformMatrix4fv(location, arraySize, f); break;
+ case GL_SAMPLER_2D:
+ case GL_SAMPLER_CUBE:
case GL_INT: applyUniform1iv(location, arraySize, i); break;
case GL_INT_VEC2: applyUniform2iv(location, arraySize, i); break;
case GL_INT_VEC3: applyUniform3iv(location, arraySize, i); break;
@@ -1001,6 +999,9 @@ ID3DXBuffer *Program::compileToBinary(const char *hlsl, const char *profile, ID3
// Returns the number of used varying registers, or -1 if unsuccesful
int Program::packVaryings(const Varying *packing[][4])
{
+ Context *context = getContext();
+ const int maxVaryingVectors = context->getMaximumVaryingVectors();
+
for (VaryingList::iterator varying = mFragmentShader->varyings.begin(); varying != mFragmentShader->varyings.end(); varying++)
{
int n = VariableRowCount(varying->type) * varying->size;
@@ -1009,7 +1010,7 @@ int Program::packVaryings(const Varying *packing[][4])
if (m == 2 || m == 3 || m == 4)
{
- for (int r = 0; r <= MAX_VARYING_VECTORS - n && !success; r++)
+ for (int r = 0; r <= maxVaryingVectors - n && !success; r++)
{
bool available = true;
@@ -1043,7 +1044,7 @@ int Program::packVaryings(const Varying *packing[][4])
if (!success && m == 2)
{
- for (int r = MAX_VARYING_VECTORS - n; r >= 0 && !success; r--)
+ for (int r = maxVaryingVectors - n; r >= 0 && !success; r--)
{
bool available = true;
@@ -1080,7 +1081,7 @@ int Program::packVaryings(const Varying *packing[][4])
{
int space[4] = {0};
- for (int y = 0; y < MAX_VARYING_VECTORS; y++)
+ for (int y = 0; y < maxVaryingVectors; y++)
{
for (int x = 0; x < 4; x++)
{
@@ -1100,7 +1101,7 @@ int Program::packVaryings(const Varying *packing[][4])
if (space[column] > n)
{
- for (int r = 0; r < MAX_VARYING_VECTORS; r++)
+ for (int r = 0; r < maxVaryingVectors; r++)
{
if (!packing[r][column])
{
@@ -1133,7 +1134,7 @@ int Program::packVaryings(const Varying *packing[][4])
// Return the number of used registers
int registers = 0;
- for (int r = 0; r < MAX_VARYING_VECTORS; r++)
+ for (int r = 0; r < maxVaryingVectors; r++)
{
if (packing[r][0] || packing[r][1] || packing[r][2] || packing[r][3])
{
@@ -1151,7 +1152,7 @@ bool Program::linkVaryings()
return false;
}
- const Varying *packing[MAX_VARYING_VECTORS][4] = {NULL};
+ const Varying *packing[MAX_VARYING_VECTORS_SM3][4] = {NULL};
int registers = packVaryings(packing);
if (registers < 0)
@@ -1159,7 +1160,11 @@ bool Program::linkVaryings()
return false;
}
- if (registers == MAX_VARYING_VECTORS && mFragmentShader->mUsesFragCoord)
+ Context *context = getContext();
+ const bool sm3 = context->supportsShaderModel3();
+ const int maxVaryingVectors = context->getMaximumVaryingVectors();
+
+ if (registers == maxVaryingVectors && mFragmentShader->mUsesFragCoord)
{
appendToInfoLog("No varying registers left to support gl_FragCoord");
@@ -1197,8 +1202,6 @@ bool Program::linkVaryings()
}
}
- Context *context = getContext();
- bool sm3 = context->supportsShaderModel3();
std::string varyingSemantic = (sm3 ? "COLOR" : "TEXCOORD");
mVertexHLSL += "struct VS_INPUT\n"
@@ -1371,6 +1374,9 @@ bool Program::linkVaryings()
if (mFragmentShader->mUsesFragCoord)
{
mPixelHLSL += " float4 gl_FragCoord : " + varyingSemantic + str(registers) + ";\n";
+ if (sm3) {
+ mPixelHLSL += " float2 dx_VPos : VPOS;\n";
+ }
}
if (mFragmentShader->mUsesPointCoord && sm3)
@@ -1395,10 +1401,15 @@ bool Program::linkVaryings()
if (mFragmentShader->mUsesFragCoord)
{
- mPixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n"
- " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Viewport.x + dx_Viewport.z;\n"
- " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_Viewport.y + dx_Viewport.w;\n"
- " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n"
+ mPixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
+ if (sm3) {
+ mPixelHLSL += " gl_FragCoord.x = input.dx_VPos.x;\n"
+ " gl_FragCoord.y = input.dx_VPos.y;\n";
+ } else {
+ mPixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Viewport.x + dx_Viewport.z;\n"
+ " gl_FragCoord.y = (input.gl_FragCoord.y * rhw) * dx_Viewport.y + dx_Viewport.w;\n";
+ }
+ mPixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n"
" gl_FragCoord.w = rhw;\n";
}
@@ -1525,9 +1536,7 @@ void Program::link()
// these uniforms are searched as already-decorated because gl_ and dx_
// are reserved prefixes, and do not receive additional decoration
- mDepthRangeNearLocation = getUniformLocation("gl_DepthRange.near", true);
- mDepthRangeFarLocation = getUniformLocation("gl_DepthRange.far", true);
- mDepthRangeDiffLocation = getUniformLocation("gl_DepthRange.diff", true);
+ mDxDepthRangeLocation = getUniformLocation("dx_DepthRange", true);
mDxDepthLocation = getUniformLocation("dx_Depth", true);
mDxViewportLocation = getUniformLocation("dx_Viewport", true);
mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize", true);
@@ -1650,32 +1659,38 @@ bool Program::defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT
{
if (constantDescription.RegisterSet == D3DXRS_SAMPLER)
{
- unsigned int samplerIndex = constantDescription.RegisterIndex;
-
- assert(samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]));
+ for (unsigned int samplerIndex = constantDescription.RegisterIndex; samplerIndex < constantDescription.RegisterIndex + constantDescription.RegisterCount; samplerIndex++)
+ {
+ ASSERT(samplerIndex < sizeof(mSamplers)/sizeof(mSamplers[0]));
- mSamplers[samplerIndex].active = true;
- mSamplers[samplerIndex].type = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? SAMPLER_CUBE : SAMPLER_2D;
- mSamplers[samplerIndex].logicalTextureUnit = 0;
- mSamplers[samplerIndex].dirty = true;
+ mSamplers[samplerIndex].active = true;
+ mSamplers[samplerIndex].type = (constantDescription.Type == D3DXPT_SAMPLERCUBE) ? SAMPLER_CUBE : SAMPLER_2D;
+ mSamplers[samplerIndex].logicalTextureUnit = 0;
+ mSamplers[samplerIndex].dirty = true;
+ }
}
switch(constantDescription.Class)
{
case D3DXPC_STRUCT:
{
- for (unsigned int field = 0; field < constantDescription.StructMembers; field++)
+ for (unsigned int arrayIndex = 0; arrayIndex < constantDescription.Elements; arrayIndex++)
{
- D3DXHANDLE fieldHandle = mConstantTablePS->GetConstant(constantHandle, field);
+ for (unsigned int field = 0; field < constantDescription.StructMembers; field++)
+ {
+ D3DXHANDLE fieldHandle = mConstantTablePS->GetConstant(constantHandle, field);
- D3DXCONSTANT_DESC fieldDescription;
- UINT descriptionCount = 1;
+ D3DXCONSTANT_DESC fieldDescription;
+ UINT descriptionCount = 1;
- mConstantTablePS->GetConstantDesc(fieldHandle, &fieldDescription, &descriptionCount);
+ mConstantTablePS->GetConstantDesc(fieldHandle, &fieldDescription, &descriptionCount);
- if (!defineUniform(fieldHandle, fieldDescription, name + constantDescription.Name + "."))
- {
- return false;
+ std::string structIndex = (constantDescription.Elements > 1) ? ("[" + str(arrayIndex) + "]") : "";
+
+ if (!defineUniform(fieldHandle, fieldDescription, name + constantDescription.Name + structIndex + "."))
+ {
+ return false;
+ }
}
}
@@ -1737,10 +1752,16 @@ Uniform *Program::createUniform(const D3DXCONSTANT_DESC &constantDescription, st
switch (constantDescription.Type)
{
case D3DXPT_SAMPLER2D:
+ switch (constantDescription.Columns)
+ {
+ case 1: return new Uniform(GL_SAMPLER_2D, name, constantDescription.Elements);
+ default: UNREACHABLE();
+ }
+ break;
case D3DXPT_SAMPLERCUBE:
switch (constantDescription.Columns)
{
- case 1: return new Uniform(GL_INT, name, constantDescription.Elements);
+ case 1: return new Uniform(GL_SAMPLER_CUBE, name, constantDescription.Elements);
default: UNREACHABLE();
}
break;
@@ -2205,14 +2226,14 @@ bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v)
{
unsigned int firstIndex = mConstantTablePS->GetSamplerIndex(constantPS);
- for (unsigned int samplerIndex = firstIndex; samplerIndex < firstIndex + count; samplerIndex++)
+ for (int i = 0; i < count; i++)
{
- GLint mappedSampler = v[0];
+ unsigned int samplerIndex = firstIndex + i;
- if (samplerIndex >= 0 && samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
+ if (samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
{
ASSERT(mSamplers[samplerIndex].active);
- mSamplers[samplerIndex].logicalTextureUnit = mappedSampler;
+ mSamplers[samplerIndex].logicalTextureUnit = v[i];
mSamplers[samplerIndex].dirty = true;
}
}
@@ -2371,6 +2392,7 @@ void Program::resetInfoLog()
if (mInfoLog)
{
delete [] mInfoLog;
+ mInfoLog = NULL;
}
}
@@ -2434,9 +2456,7 @@ void Program::unlink(bool destroy)
mUniforms.pop_back();
}
- mDepthRangeDiffLocation = -1;
- mDepthRangeNearLocation = -1;
- mDepthRangeFarLocation = -1;
+ mDxDepthRangeLocation = -1;
mDxDepthLocation = -1;
mDxViewportLocation = -1;
mDxHalfPixelSizeLocation = -1;
@@ -2562,16 +2582,22 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade
void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{
- unsigned int attribute = 0;
- for (unsigned int i = 0; i < index; i++)
+ // Skip over inactive attributes
+ unsigned int activeAttribute = 0;
+ unsigned int attribute;
+ for (attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
{
- do
+ if (mLinkedAttribute[attribute].name.empty())
{
- attribute++;
+ continue;
+ }
- ASSERT(attribute < MAX_VERTEX_ATTRIBS); // index must be smaller than getActiveAttributeCount()
+ if (activeAttribute == index)
+ {
+ break;
}
- while (mLinkedAttribute[attribute].name.empty());
+
+ activeAttribute++;
}
if (bufsize > 0)
@@ -2624,18 +2650,26 @@ GLint Program::getActiveAttributeMaxLength()
void Program::getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{
- unsigned int uniform = 0;
- for (unsigned int i = 0; i < index; i++)
+ // Skip over internal uniforms
+ unsigned int activeUniform = 0;
+ unsigned int uniform;
+ for (uniform = 0; uniform < mUniforms.size(); uniform++)
{
- do
+ if (mUniforms[uniform]->name.substr(0, 3) == "dx_")
{
- uniform++;
+ continue;
+ }
- ASSERT(uniform < mUniforms.size()); // index must be smaller than getActiveUniformCount()
+ if (activeUniform == index)
+ {
+ break;
}
- while (mUniforms[uniform]->name.substr(0, 3) == "dx_");
+
+ activeUniform++;
}
+ ASSERT(uniform < mUniforms.size()); // index must be smaller than getActiveUniformCount()
+
if (bufsize > 0)
{
std::string string = undecorate(mUniforms[uniform]->name);
@@ -2763,19 +2797,9 @@ void Program::getConstantHandles(Uniform *targetUniform, D3DXHANDLE *constantPS,
*constantVS = targetUniform->vsHandle;
}
-GLint Program::getDepthRangeDiffLocation() const
-{
- return mDepthRangeDiffLocation;
-}
-
-GLint Program::getDepthRangeNearLocation() const
-{
- return mDepthRangeNearLocation;
-}
-
-GLint Program::getDepthRangeFarLocation() const
+GLint Program::getDxDepthRangeLocation() const
{
- return mDepthRangeFarLocation;
+ return mDxDepthRangeLocation;
}
GLint Program::getDxDepthLocation() const