Commit c349ec03 by Jamie Madill

Re-land "Move shader attributes into Program shared data."

Re-land with a fix for a warning in 32-bit Windows. Making the Program own the attribs, and the Impl only see a read-only copy cleans up the Impl object. It also allows us to more cleanly isolate certain coded into D3D. BUG=angleproject:1123 Change-Id: I73bda4b6d9e675d87d087d44757c598437d607f2 Reviewed-on: https://chromium-review.googlesource.com/295191Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 4e10722d
......@@ -180,6 +180,7 @@ class Program : angle::NonCopyable
ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS);
return mUniformBlockBindings[uniformBlockIndex];
}
const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; }
private:
friend class Program;
......@@ -193,6 +194,8 @@ class Program : angle::NonCopyable
GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
std::vector<sh::Attribute> mAttributes;
// TODO(jmadill): move more state into Data.
};
......@@ -228,7 +231,7 @@ class Program : angle::NonCopyable
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
GLint getActiveAttributeCount();
GLint getActiveAttributeMaxLength();
const std::vector<sh::Attribute> &getLinkedAttributes() const { return mLinkedAttributes; }
const std::vector<sh::Attribute> &getAttributes() const { return mData.mAttributes; }
GLint getFragDataLocation(const std::string &name) const;
......@@ -335,8 +338,6 @@ class Program : angle::NonCopyable
Data mData;
rx::ProgramImpl *mProgram;
std::vector<sh::Attribute> mLinkedAttributes;
std::map<int, VariableLocation> mOutputVariables;
bool mValidated;
......
......@@ -135,26 +135,4 @@ void ProgramImpl::reset()
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,7 +85,6 @@ class ProgramImpl : angle::NonCopyable
const std::vector<gl::LinkedUniform*> &getUniforms() const { return mUniforms; }
const std::map<GLuint, gl::VariableLocation> &getUniformIndices() const { return mUniformIndex; }
const std::vector<gl::UniformBlock*> &getUniformBlocks() const { return mUniformBlocks; }
const std::vector<sh::Attribute> getShaderAttributes() { return mShaderAttributes; }
const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndex; }
std::vector<gl::LinkedUniform*> &getUniforms() { return mUniforms; }
......@@ -101,9 +100,6 @@ class ProgramImpl : angle::NonCopyable
GLuint getUniformIndex(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();
protected:
......@@ -117,9 +113,6 @@ class ProgramImpl : angle::NonCopyable
std::vector<gl::UniformBlock*> mUniformBlocks;
SemanticIndexArray mSemanticIndex;
private:
std::vector<sh::Attribute> mShaderAttributes;
};
}
......
......@@ -1003,7 +1003,8 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::InputLayout &i
}
// Generate new dynamic layout with attribute conversions
std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, getShaderAttributes());
std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(
mVertexHLSL, inputLayout, mData.getAttributes());
// Generate new vertex executable
ShaderExecutableD3D *vertexExecutable = NULL;
......
......@@ -124,6 +124,7 @@ class ProgramD3D : public ProgramImpl
void sortAttributesByLayout(const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
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);
const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; }
......@@ -245,7 +246,7 @@ class ProgramD3D : public ProgramImpl
int mShaderVersion;
int mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS];
SemanticIndexArray mAttributesByLayout;
unsigned int mSerial;
......
......@@ -46,20 +46,20 @@ gl::InputLayout GetInputLayout(
return inputLayout;
}
GLenum GetNextGLSLAttributeType(const std::vector<sh::Attribute> &linkedAttributes, int index)
GLenum GetGLSLAttributeType(const std::vector<sh::Attribute> &shaderAttributes, int index)
{
// Count matrices differently
int subIndex = 0;
for (const sh::Attribute &attrib : linkedAttributes)
for (const sh::Attribute &attrib : shaderAttributes)
{
if (attrib.type == GL_NONE)
if (attrib.location == -1)
{
continue;
}
GLenum transposedType = gl::TransposeMatrixType(attrib.type);
subIndex += gl::VariableRowCount(transposedType);
if (subIndex > index)
int rows = gl::VariableRowCount(transposedType);
if (index >= attrib.location && index < attrib.location + rows)
{
return transposedType;
}
......@@ -185,6 +185,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
bool instancedPointSpritesActive = programUsesInstancedPointSprites && (mode == GL_POINTS);
bool indexedPointSpriteEmulationActive = instancedPointSpritesActive && (sourceInfo != nullptr);
const auto &semanticToLocation = programD3D->getAttributesByLayout();
if (!mDevice || !mDeviceContext)
{
return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized.");
......@@ -200,7 +202,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
unsigned int firstInstancedElement = gl::MAX_VERTEX_ATTRIBS;
unsigned int nextAvailableInputSlot = 0;
const std::vector<sh::Attribute> &linkedAttributes = program->getLinkedAttributes();
const std::vector<sh::Attribute> &shaderAttributes = program->getAttributes();
for (unsigned int i = 0; i < unsortedAttributes.size(); i++)
{
......@@ -232,7 +234,8 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
// Record the type of the associated vertex shader vector in our key
// This will prevent mismatched vertex shaders from using the same input layout
GLenum glslElementType = GetNextGLSLAttributeType(linkedAttributes, inputElementCount);
GLenum glslElementType = GetGLSLAttributeType(
shaderAttributes, semanticToLocation[sortedSemanticIndices[i]]);
layout.addAttributeData(glslElementType,
sortedSemanticIndices[i],
......
......@@ -169,34 +169,34 @@ LinkResult ProgramGL::link(const gl::Data &data,
}
}
// Query the attribute information
GLint activeAttributeMaxLength = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength);
for (const sh::Attribute &attribute : mData.getAttributes())
{
if (!attribute.staticUse)
continue;
std::vector<GLchar> attributeNameBuffer(activeAttributeMaxLength);
GLint realLocation = mFunctions->getAttribLocation(mProgramID, attribute.name.c_str());
GLint attributeCount = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTES, &attributeCount);
for (GLint i = 0; i < attributeCount; i++)
{
GLsizei attributeNameLength = 0;
GLint attributeSize = 0;
GLenum attributeType = GL_NONE;
mFunctions->getActiveAttrib(mProgramID, i, static_cast<GLsizei>(attributeNameBuffer.size()),
&attributeNameLength, &attributeSize, &attributeType,
&attributeNameBuffer[0]);
// Some drivers optimize attributes more aggressively.
if (realLocation == -1)
{
continue;
}
std::string attributeName(&attributeNameBuffer[0], attributeNameLength);
// TODO(jmadill): Fix this
ASSERT(attribute.location == realLocation);
GLint location = mFunctions->getAttribLocation(mProgramID, attributeName.c_str());
int registerCount = gl::VariableRegisterCount(attribute.type);
// TODO: determine attribute precision
setShaderAttribute(static_cast<size_t>(i), attributeType, GL_NONE, attributeName, attributeSize, location);
if (static_cast<GLint>(mAttributeRealLocations.size()) <
attribute.location + registerCount + 1)
{
mAttributeRealLocations.resize(attribute.location + registerCount + 1, -1);
}
int attributeRegisterCount = gl::VariableRegisterCount(attributeType);
for (int offset = 0; offset < attributeRegisterCount; offset++)
for (int offset = 0; offset < registerCount; ++offset)
{
mActiveAttributesMask.set(location + offset);
mActiveAttributesMask.set(attribute.location + offset);
mAttributeRealLocations[attribute.location + offset] = realLocation + offset;
}
}
......@@ -378,6 +378,7 @@ void ProgramGL::reset()
mSamplerUniformMap.clear();
mSamplerBindings.clear();
mActiveAttributesMask.reset();
mAttributeRealLocations.clear();
}
GLuint ProgramGL::getProgramID() const
......
......@@ -101,6 +101,9 @@ class ProgramGL : public ProgramImpl
// An array of the samplers that are used by the program
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
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