Commit 4e10722d by Jamie Madill

Revert "Move shader attributes into Program shared data."

Once again a signed/unsigned mismatch warning in 32-bit. src\libangle\renderer\gl\programgl.cpp(190) : warning C4018: '<' : signed/unsigned mismatch BUG=angleproject:1123 This reverts commit 2d773183. Change-Id: Icd26906ead1eaa06b4bd3ff7fc2b10bef4f46022 Reviewed-on: https://chromium-review.googlesource.com/295241Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 2d773183
...@@ -163,6 +163,7 @@ Program::Data::~Data() ...@@ -163,6 +163,7 @@ Program::Data::~Data()
Program::Program(rx::ImplFactory *factory, ResourceManager *manager, GLuint handle) Program::Program(rx::ImplFactory *factory, ResourceManager *manager, GLuint handle)
: mProgram(factory->createProgram(mData)), : mProgram(factory->createProgram(mData)),
mLinkedAttributes(gl::MAX_VERTEX_ATTRIBS),
mValidated(false), mValidated(false),
mLinked(false), mLinked(false),
mDeleteStatus(false), mDeleteStatus(false),
...@@ -355,7 +356,7 @@ void Program::unlink(bool destroy) ...@@ -355,7 +356,7 @@ void Program::unlink(bool destroy)
} }
} }
mData.mAttributes.clear(); mLinkedAttributes.assign(mLinkedAttributes.size(), sh::Attribute());
mData.mTransformFeedbackVaryingVars.clear(); mData.mTransformFeedbackVaryingVars.clear();
mProgram->reset(); mProgram->reset();
...@@ -407,21 +408,20 @@ Error Program::loadBinary(GLenum binaryFormat, const void *binary, GLsizei lengt ...@@ -407,21 +408,20 @@ Error Program::loadBinary(GLenum binaryFormat, const void *binary, GLsizei lengt
// TODO(jmadill): replace MAX_VERTEX_ATTRIBS // TODO(jmadill): replace MAX_VERTEX_ATTRIBS
for (int i = 0; i < MAX_VERTEX_ATTRIBS; ++i) for (int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
{ {
stream.readInt(&mLinkedAttributes[i].type);
stream.readString(&mLinkedAttributes[i].name);
stream.readInt(&mProgram->getSemanticIndexes()[i]); stream.readInt(&mProgram->getSemanticIndexes()[i]);
} }
unsigned int attribCount = stream.readInt<unsigned int>(); unsigned int attribCount = stream.readInt<unsigned int>();
ASSERT(mData.mAttributes.empty());
for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex) for (unsigned int attribIndex = 0; attribIndex < attribCount; ++attribIndex)
{ {
sh::Attribute attrib; GLenum type = stream.readInt<GLenum>();
attrib.type = stream.readInt<GLenum>(); GLenum precision = stream.readInt<GLenum>();
attrib.precision = stream.readInt<GLenum>(); std::string name = stream.readString();
attrib.name = stream.readString(); GLint arraySize = stream.readInt<GLint>();
attrib.arraySize = stream.readInt<GLint>(); int location = stream.readInt<int>();
attrib.location = stream.readInt<int>(); mProgram->setShaderAttribute(attribIndex, type, precision, name, arraySize, location);
attrib.staticUse = stream.readBool();
mData.mAttributes.push_back(attrib);
} }
stream.readInt(&mData.mTransformFeedbackBufferMode); stream.readInt(&mData.mTransformFeedbackBufferMode);
...@@ -454,18 +454,20 @@ Error Program::saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, G ...@@ -454,18 +454,20 @@ Error Program::saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, G
// TODO(jmadill): replace MAX_VERTEX_ATTRIBS // TODO(jmadill): replace MAX_VERTEX_ATTRIBS
for (unsigned int i = 0; i < MAX_VERTEX_ATTRIBS; ++i) for (unsigned int i = 0; i < MAX_VERTEX_ATTRIBS; ++i)
{ {
stream.writeInt(mLinkedAttributes[i].type);
stream.writeString(mLinkedAttributes[i].name);
stream.writeInt(mProgram->getSemanticIndexes()[i]); stream.writeInt(mProgram->getSemanticIndexes()[i]);
} }
stream.writeInt(mData.mAttributes.size()); const auto &shaderAttributes = mProgram->getShaderAttributes();
for (const sh::Attribute &attrib : mData.mAttributes) stream.writeInt(shaderAttributes.size());
for (const auto &attrib : shaderAttributes)
{ {
stream.writeInt(attrib.type); stream.writeInt(attrib.type);
stream.writeInt(attrib.precision); stream.writeInt(attrib.precision);
stream.writeString(attrib.name); stream.writeString(attrib.name);
stream.writeInt(attrib.arraySize); stream.writeInt(attrib.arraySize);
stream.writeInt(attrib.location); stream.writeInt(attrib.location);
stream.writeInt(attrib.staticUse);
} }
stream.writeInt(mData.mTransformFeedbackBufferMode); stream.writeInt(mData.mTransformFeedbackBufferMode);
...@@ -584,11 +586,11 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade ...@@ -584,11 +586,11 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade
GLuint Program::getAttributeLocation(const std::string &name) GLuint Program::getAttributeLocation(const std::string &name)
{ {
for (const sh::Attribute &attribute : mData.mAttributes) for (size_t index = 0; index < mLinkedAttributes.size(); index++)
{ {
if (attribute.name == name && attribute.staticUse) if (mLinkedAttributes[index].name == name)
{ {
return attribute.location; return static_cast<GLuint>(index);
} }
} }
...@@ -609,44 +611,30 @@ int Program::getSemanticIndex(int attributeIndex) const ...@@ -609,44 +611,30 @@ int Program::getSemanticIndex(int attributeIndex) const
void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name)
{ {
if (!mLinked) if (mLinked)
{ {
if (bufsize > 0) // Skip over inactive attributes
unsigned int activeAttribute = 0;
unsigned int attribute;
for (attribute = 0; attribute < static_cast<unsigned int>(mLinkedAttributes.size());
attribute++)
{ {
name[0] = '\0'; if (mLinkedAttributes[attribute].name.empty())
}
if (length)
{ {
*length = 0; continue;
}
*type = GL_NONE;
*size = 1;
return;
} }
size_t attributeIndex = 0; if (activeAttribute == index)
for (const sh::Attribute &attribute : mData.mAttributes)
{
// Skip over inactive attributes
if (attribute.staticUse)
{
if (static_cast<size_t>(index) == attributeIndex)
{ {
break; break;
} }
attributeIndex++;
}
}
ASSERT(index == attributeIndex && attributeIndex < mData.mAttributes.size()); activeAttribute++;
const sh::Attribute &attrib = mData.mAttributes[attributeIndex]; }
if (bufsize > 0) if (bufsize > 0)
{ {
const char *string = attrib.name.c_str(); const char *string = mLinkedAttributes[attribute].name.c_str();
strncpy(name, string, bufsize); strncpy(name, string, bufsize);
name[bufsize - 1] = '\0'; name[bufsize - 1] = '\0';
...@@ -657,23 +645,40 @@ void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, ...@@ -657,23 +645,40 @@ void Program::getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length,
} }
} }
// Always a single 'type' instance *size = 1; // Always a single 'type' instance
*type = mLinkedAttributes[attribute].type;
}
else
{
if (bufsize > 0)
{
name[0] = '\0';
}
if (length)
{
*length = 0;
}
*type = GL_NONE;
*size = 1; *size = 1;
*type = attrib.type; }
} }
GLint Program::getActiveAttributeCount() GLint Program::getActiveAttributeCount()
{ {
if (!mLinked) int count = 0;
{
return 0;
}
GLint count = 0;
for (const sh::Attribute &attrib : mData.mAttributes) if (mLinked)
{
for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{ {
count += (attrib.staticUse ? 1 : 0); if (!mLinkedAttributes[attributeIndex].name.empty())
{
count++;
}
}
} }
return count; return count;
...@@ -681,22 +686,22 @@ GLint Program::getActiveAttributeCount() ...@@ -681,22 +686,22 @@ GLint Program::getActiveAttributeCount()
GLint Program::getActiveAttributeMaxLength() GLint Program::getActiveAttributeMaxLength()
{ {
if (!mLinked) GLint maxLength = 0;
{
return 0;
}
size_t maxLength = 0; if (mLinked)
for (const sh::Attribute &attrib : mData.mAttributes)
{ {
if (attrib.staticUse) for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{ {
maxLength = std::max(attrib.name.length() + 1, maxLength); if (!mLinkedAttributes[attributeIndex].name.empty())
{
maxLength = std::max(
static_cast<GLint>(mLinkedAttributes[attributeIndex].name.length() + 1),
maxLength);
}
} }
} }
return static_cast<GLint>(maxLength); return maxLength;
} }
GLint Program::getFragDataLocation(const std::string &name) const GLint Program::getFragDataLocation(const std::string &name) const
...@@ -1287,77 +1292,73 @@ bool Program::linkAttributes(const gl::Data &data, ...@@ -1287,77 +1292,73 @@ bool Program::linkAttributes(const gl::Data &data,
const Shader *vertexShader) const Shader *vertexShader)
{ {
unsigned int usedLocations = 0; unsigned int usedLocations = 0;
mData.mAttributes = vertexShader->getActiveAttributes(); const std::vector<sh::Attribute> &shaderAttributes = vertexShader->getActiveAttributes();
GLuint maxAttribs = data.caps->maxVertexAttributes; GLuint maxAttribs = data.caps->maxVertexAttributes;
// TODO(jmadill): handle aliasing robustly // TODO(jmadill): handle aliasing robustly
if (mData.mAttributes.size() > maxAttribs) if (shaderAttributes.size() > maxAttribs)
{ {
infoLog << "Too many vertex attributes."; infoLog << "Too many vertex attributes.";
return false; return false;
} }
std::vector<sh::Attribute *> usedAttribMap(data.caps->maxVertexAttributes, nullptr);
// Link attributes that have a binding location // Link attributes that have a binding location
for (sh::Attribute &attribute : mData.mAttributes) for (unsigned int attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
{ {
// TODO(jmadill): do staticUse filtering step here, or not at all const sh::Attribute &attribute = shaderAttributes[attributeIndex];
ASSERT(attribute.staticUse); ASSERT(attribute.staticUse);
int bindingLocation = attributeBindings.getAttributeBinding(attribute.name); const int location = attribute.location == -1 ? attributeBindings.getAttributeBinding(attribute.name) : attribute.location;
if (attribute.location == -1 && bindingLocation != -1)
{
attribute.location = bindingLocation;
}
if (attribute.location != -1) mProgram->setShaderAttribute(attributeIndex, attribute);
if (location != -1) // Set by glBindAttribLocation or by location layout qualifier
{ {
// Location is set by glBindAttribLocation or by location layout qualifier
const int rows = VariableRegisterCount(attribute.type); const int rows = VariableRegisterCount(attribute.type);
if (static_cast<GLuint>(rows + attribute.location) > maxAttribs) if (static_cast<GLuint>(rows + location) > maxAttribs)
{ {
infoLog << "Active attribute (" << attribute.name << ") at location " infoLog << "Active attribute (" << attribute.name << ") at location "
<< attribute.location << " is too big to fit"; << location << " is too big to fit";
return false; return false;
} }
for (int row = 0; row < rows; row++) for (int row = 0; row < rows; row++)
{ {
const int rowLocation = attribute.location + row; const int rowLocation = location + row;
sh::ShaderVariable *linkedAttribute = usedAttribMap[rowLocation]; sh::ShaderVariable *linkedAttribute = &mLinkedAttributes[rowLocation];
// In GLSL 3.00, attribute aliasing produces a link error // In GLSL 3.00, attribute aliasing produces a link error
// In GLSL 1.00, attribute aliasing is allowed, but ANGLE currently has a bug // In GLSL 1.00, attribute aliasing is allowed, but ANGLE currently has a bug
if (linkedAttribute)
{
// TODO(jmadill): fix aliasing on ES2 // TODO(jmadill): fix aliasing on ES2
// if (mProgram->getShaderVersion() >= 300) // if (mProgram->getShaderVersion() >= 300)
{ {
if (!linkedAttribute->name.empty())
{
infoLog << "Attribute '" << attribute.name << "' aliases attribute '" infoLog << "Attribute '" << attribute.name << "' aliases attribute '"
<< linkedAttribute->name << "' at location " << rowLocation; << linkedAttribute->name << "' at location " << rowLocation;
return false; return false;
} }
} }
else
{
usedAttribMap[rowLocation] = &attribute;
}
*linkedAttribute = attribute;
usedLocations |= 1 << rowLocation; usedLocations |= 1 << rowLocation;
} }
} }
} }
// Link attributes that don't have a binding location // Link attributes that don't have a binding location
for (sh::Attribute &attribute : mData.mAttributes) for (unsigned int attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
{ {
const sh::Attribute &attribute = shaderAttributes[attributeIndex];
ASSERT(attribute.staticUse); ASSERT(attribute.staticUse);
// Not set by glBindAttribLocation or by location layout qualifier const int location = attribute.location == -1 ? attributeBindings.getAttributeBinding(attribute.name) : attribute.location;
if (attribute.location == -1)
if (location == -1) // Not set by glBindAttribLocation or by location layout qualifier
{ {
int rows = VariableRegisterCount(attribute.type); int rows = VariableRegisterCount(attribute.type);
int availableIndex = AllocateFirstFreeBits(&usedLocations, rows, maxAttribs); int availableIndex = AllocateFirstFreeBits(&usedLocations, rows, maxAttribs);
...@@ -1365,21 +1366,17 @@ bool Program::linkAttributes(const gl::Data &data, ...@@ -1365,21 +1366,17 @@ bool Program::linkAttributes(const gl::Data &data,
if (availableIndex == -1 || static_cast<GLuint>(availableIndex + rows) > maxAttribs) if (availableIndex == -1 || static_cast<GLuint>(availableIndex + rows) > maxAttribs)
{ {
infoLog << "Too many active attributes (" << attribute.name << ")"; infoLog << "Too many active attributes (" << attribute.name << ")";
return false; return false; // Fail to link
} }
attribute.location = availableIndex; mLinkedAttributes[availableIndex] = attribute;
} }
} }
// TODO(jmadill): make semantic index D3D-only for (GLuint attributeIndex = 0; attributeIndex < maxAttribs;)
for (const sh::Attribute &attribute : mData.mAttributes)
{ {
ASSERT(attribute.staticUse); int index = vertexShader->getSemanticIndex(mLinkedAttributes[attributeIndex].name);
int rows = VariableRegisterCount(mLinkedAttributes[attributeIndex].type);
unsigned int attributeIndex = attribute.location;
int index = vertexShader->getSemanticIndex(attribute.name);
int rows = VariableRegisterCount(attribute.type);
for (int r = 0; r < rows; r++) for (int r = 0; r < rows; r++)
{ {
......
...@@ -180,7 +180,6 @@ class Program : angle::NonCopyable ...@@ -180,7 +180,6 @@ class Program : angle::NonCopyable
ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS); ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS);
return mUniformBlockBindings[uniformBlockIndex]; return mUniformBlockBindings[uniformBlockIndex];
} }
const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; }
private: private:
friend class Program; friend class Program;
...@@ -194,8 +193,6 @@ class Program : angle::NonCopyable ...@@ -194,8 +193,6 @@ class Program : angle::NonCopyable
GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
std::vector<sh::Attribute> mAttributes;
// TODO(jmadill): move more state into Data. // TODO(jmadill): move more state into Data.
}; };
...@@ -231,7 +228,7 @@ class Program : angle::NonCopyable ...@@ -231,7 +228,7 @@ class Program : angle::NonCopyable
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
GLint getActiveAttributeCount(); GLint getActiveAttributeCount();
GLint getActiveAttributeMaxLength(); GLint getActiveAttributeMaxLength();
const std::vector<sh::Attribute> &getAttributes() const { return mData.mAttributes; } const std::vector<sh::Attribute> &getLinkedAttributes() const { return mLinkedAttributes; }
GLint getFragDataLocation(const std::string &name) const; GLint getFragDataLocation(const std::string &name) const;
...@@ -338,6 +335,8 @@ class Program : angle::NonCopyable ...@@ -338,6 +335,8 @@ class Program : angle::NonCopyable
Data mData; Data mData;
rx::ProgramImpl *mProgram; rx::ProgramImpl *mProgram;
std::vector<sh::Attribute> mLinkedAttributes;
std::map<int, VariableLocation> mOutputVariables; std::map<int, VariableLocation> mOutputVariables;
bool mValidated; bool mValidated;
......
...@@ -135,4 +135,26 @@ void ProgramImpl::reset() ...@@ -135,4 +135,26 @@ void ProgramImpl::reset()
SafeDeleteContainer(mUniformBlocks); SafeDeleteContainer(mUniformBlocks);
} }
void ProgramImpl::setShaderAttribute(size_t index, const sh::Attribute &attrib)
{
if (mShaderAttributes.size() <= index)
{
mShaderAttributes.resize(index + 1);
}
mShaderAttributes[index] = attrib;
}
void ProgramImpl::setShaderAttribute(size_t index, GLenum type, GLenum precision, const std::string &name, GLint size, int location)
{
if (mShaderAttributes.size() <= index)
{
mShaderAttributes.resize(index + 1);
}
mShaderAttributes[index].type = type;
mShaderAttributes[index].precision = precision;
mShaderAttributes[index].name = name;
mShaderAttributes[index].arraySize = size;
mShaderAttributes[index].location = location;
}
} }
...@@ -85,6 +85,7 @@ class ProgramImpl : angle::NonCopyable ...@@ -85,6 +85,7 @@ class ProgramImpl : angle::NonCopyable
const std::vector<gl::LinkedUniform*> &getUniforms() const { return mUniforms; } const std::vector<gl::LinkedUniform*> &getUniforms() const { return mUniforms; }
const std::map<GLuint, gl::VariableLocation> &getUniformIndices() const { return mUniformIndex; } const std::map<GLuint, gl::VariableLocation> &getUniformIndices() const { return mUniformIndex; }
const std::vector<gl::UniformBlock*> &getUniformBlocks() const { return mUniformBlocks; } const std::vector<gl::UniformBlock*> &getUniformBlocks() const { return mUniformBlocks; }
const std::vector<sh::Attribute> getShaderAttributes() { return mShaderAttributes; }
const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndex; } const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndex; }
std::vector<gl::LinkedUniform*> &getUniforms() { return mUniforms; } std::vector<gl::LinkedUniform*> &getUniforms() { return mUniforms; }
...@@ -100,6 +101,9 @@ class ProgramImpl : angle::NonCopyable ...@@ -100,6 +101,9 @@ class ProgramImpl : angle::NonCopyable
GLuint getUniformIndex(const std::string &name) const; GLuint getUniformIndex(const std::string &name) const;
GLuint getUniformBlockIndex(const std::string &name) const; GLuint getUniformBlockIndex(const std::string &name) const;
void setShaderAttribute(size_t index, const sh::Attribute &attrib);
void setShaderAttribute(size_t index, GLenum type, GLenum precision, const std::string &name, GLint size, int location);
virtual void reset(); virtual void reset();
protected: protected:
...@@ -113,6 +117,9 @@ class ProgramImpl : angle::NonCopyable ...@@ -113,6 +117,9 @@ class ProgramImpl : angle::NonCopyable
std::vector<gl::UniformBlock*> mUniformBlocks; std::vector<gl::UniformBlock*> mUniformBlocks;
SemanticIndexArray mSemanticIndex; SemanticIndexArray mSemanticIndex;
private:
std::vector<sh::Attribute> mShaderAttributes;
}; };
} }
......
...@@ -1003,8 +1003,7 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i ...@@ -1003,8 +1003,7 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
} }
// Generate new dynamic layout with attribute conversions // Generate new dynamic layout with attribute conversions
std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout( std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, getShaderAttributes());
mVertexHLSL, inputLayout, mData.getAttributes());
// Generate new vertex executable // Generate new vertex executable
ShaderExecutableD3D *vertexExecutable = NULL; ShaderExecutableD3D *vertexExecutable = NULL;
......
...@@ -124,7 +124,6 @@ class ProgramD3D : public ProgramImpl ...@@ -124,7 +124,6 @@ class ProgramD3D : public ProgramImpl
void sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes, void sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const; const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const;
const SemanticIndexArray &getAttributesByLayout() const { return mAttributesByLayout; }
void updateCachedInputLayout(const gl::Program *program, const gl::State &state); void updateCachedInputLayout(const gl::Program *program, const gl::State &state);
const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; } const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; }
...@@ -246,7 +245,7 @@ class ProgramD3D : public ProgramImpl ...@@ -246,7 +245,7 @@ class ProgramD3D : public ProgramImpl
int mShaderVersion; int mShaderVersion;
SemanticIndexArray mAttributesByLayout; int mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS];
unsigned int mSerial; unsigned int mSerial;
......
...@@ -46,20 +46,20 @@ gl::InputLayout GetInputLayout( ...@@ -46,20 +46,20 @@ gl::InputLayout GetInputLayout(
return inputLayout; return inputLayout;
} }
GLenum GetGLSLAttributeType(const std::vector<sh::Attribute> &shaderAttributes, int index) GLenum GetNextGLSLAttributeType(const std::vector<sh::Attribute> &linkedAttributes, int index)
{ {
// Count matrices differently // Count matrices differently
for (const sh::Attribute &attrib : shaderAttributes) int subIndex = 0;
for (const sh::Attribute &attrib : linkedAttributes)
{ {
if (attrib.location == -1) if (attrib.type == GL_NONE)
{ {
continue; continue;
} }
GLenum transposedType = gl::TransposeMatrixType(attrib.type); GLenum transposedType = gl::TransposeMatrixType(attrib.type);
int rows = gl::VariableRowCount(transposedType); subIndex += gl::VariableRowCount(transposedType);
if (subIndex > index)
if (index >= attrib.location && index < attrib.location + rows)
{ {
return transposedType; return transposedType;
} }
...@@ -185,8 +185,6 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -185,8 +185,6 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS); bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS);
bool indexedPointSpriteEmulationActive = instancedPointSpritesActive && (sourceInfo != nullptr); bool indexedPointSpriteEmulationActive = instancedPointSpritesActive && (sourceInfo != nullptr);
const auto &semanticToLocation = programD3D->getAttributesByLayout();
if (!mDevice || !mDeviceContext) if (!mDevice || !mDeviceContext)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized.");
...@@ -202,7 +200,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -202,7 +200,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
unsigned int firstInstancedElement = gl::MAX_VERTEX_ATTRIBS; unsigned int firstInstancedElement = gl::MAX_VERTEX_ATTRIBS;
unsigned int nextAvailableInputSlot = 0; unsigned int nextAvailableInputSlot = 0;
const std::vector<sh::Attribute> &shaderAttributes = program->getAttributes(); const std::vector<sh::Attribute> &linkedAttributes = program->getLinkedAttributes();
for (unsigned int i = 0; i < unsortedAttributes.size(); i++) for (unsigned int i = 0; i < unsortedAttributes.size(); i++)
{ {
...@@ -234,8 +232,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -234,8 +232,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
// Record the type of the associated vertex shader vector in our key // Record the type of the associated vertex shader vector in our key
// This will prevent mismatched vertex shaders from using the same input layout // This will prevent mismatched vertex shaders from using the same input layout
GLenum glslElementType = GetGLSLAttributeType( GLenum glslElementType = GetNextGLSLAttributeType(linkedAttributes, inputElementCount);
shaderAttributes, semanticToLocation[sortedSemanticIndices[i]]);
layout.addAttributeData(glslElementType, layout.addAttributeData(glslElementType,
sortedSemanticIndices[i], sortedSemanticIndices[i],
......
...@@ -169,33 +169,34 @@ LinkResult ProgramGL::link(const gl::Data &data, ...@@ -169,33 +169,34 @@ LinkResult ProgramGL::link(const gl::Data &data,
} }
} }
for (const sh::Attribute &attribute : mData.getAttributes()) // Query the attribute information
{ GLint activeAttributeMaxLength = 0;
if (!attribute.staticUse) mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength);
continue;
GLint realLocation = mFunctions->getAttribLocation(mProgramID, attribute.name.c_str()); std::vector<GLchar> attributeNameBuffer(activeAttributeMaxLength);
// Some drivers optimize attributes more aggressively. GLint attributeCount = 0;
if (realLocation == -1) mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTES, &attributeCount);
for (GLint i = 0; i < attributeCount; i++)
{ {
continue; GLsizei attributeNameLength = 0;
} GLint attributeSize = 0;
GLenum attributeType = GL_NONE;
mFunctions->getActiveAttrib(mProgramID, i, static_cast<GLsizei>(attributeNameBuffer.size()),
&attributeNameLength, &attributeSize, &attributeType,
&attributeNameBuffer[0]);
// TODO(jmadill): Fix this std::string attributeName(&attributeNameBuffer[0], attributeNameLength);
ASSERT(attribute.location == realLocation);
int registerCount = gl::VariableRegisterCount(attribute.type); GLint location = mFunctions->getAttribLocation(mProgramID, attributeName.c_str());
if (mAttributeRealLocations.size() < attribute.location + registerCount + 1) // TODO: determine attribute precision
{ setShaderAttribute(static_cast<size_t>(i), attributeType, GL_NONE, attributeName, attributeSize, location);
mAttributeRealLocations.resize(attribute.location + registerCount + 1, -1);
}
for (int offset = 0; offset < registerCount; ++offset) int attributeRegisterCount = gl::VariableRegisterCount(attributeType);
for (int offset = 0; offset < attributeRegisterCount; offset++)
{ {
mActiveAttributesMask.set(attribute.location + offset); mActiveAttributesMask.set(location + offset);
mAttributeRealLocations[attribute.location + offset] = realLocation + offset;
} }
} }
...@@ -377,7 +378,6 @@ void ProgramGL::reset() ...@@ -377,7 +378,6 @@ void ProgramGL::reset()
mSamplerUniformMap.clear(); mSamplerUniformMap.clear();
mSamplerBindings.clear(); mSamplerBindings.clear();
mActiveAttributesMask.reset(); mActiveAttributesMask.reset();
mAttributeRealLocations.clear();
} }
GLuint ProgramGL::getProgramID() const GLuint ProgramGL::getProgramID() const
......
...@@ -101,9 +101,6 @@ class ProgramGL : public ProgramImpl ...@@ -101,9 +101,6 @@ class ProgramGL : public ProgramImpl
// An array of the samplers that are used by the program // An array of the samplers that are used by the program
std::vector<SamplerBindingGL> mSamplerBindings; std::vector<SamplerBindingGL> mSamplerBindings;
// Map from GL-layer attribute location to native location.
std::vector<GLint> mAttributeRealLocations;
// Array of attribute locations used by this program // Array of attribute locations used by this program
gl::AttributesMask mActiveAttributesMask; gl::AttributesMask mActiveAttributesMask;
......
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