Commit 8047c0d2 by Jamie Madill Committed by Commit Bot

D3D11: Clean up InputLayoutCache.

This change does a couple things. First, it uses the 'active attribs' mask in the gl::Program to sort the translated attributes, instead of checking the translated attribute themselves. This means we don't have to consult the 'active' field of the translated attributes, which in turns means we don't have to update the active field in the attributes, which breaks the dependency of the attributes on the gl::Program. Second, use a dynamically sized array for storing the cached vertex attributes in the InputLayoutCache. This is nice because it means we don't have to store the size of the array separately. Also some other refactoring cleanups. Refactoring change only. BUG=angleproject:1327 Change-Id: Iab22de92840b30674b92eca72e450673ed9f6d6d Reviewed-on: https://chromium-review.googlesource.com/330172Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e9e15349
...@@ -79,28 +79,6 @@ bool IsRowMajorLayout(const sh::ShaderVariable &var) ...@@ -79,28 +79,6 @@ bool IsRowMajorLayout(const sh::ShaderVariable &var)
return false; return false;
} }
struct AttributeSorter
{
AttributeSorter(const ProgramD3D::SemanticIndexArray &semanticIndices)
: originalIndices(&semanticIndices)
{
}
bool operator()(int a, int b)
{
int indexA = (*originalIndices)[a];
int indexB = (*originalIndices)[b];
if (indexA == -1)
return false;
if (indexB == -1)
return true;
return (indexA < indexB);
}
const ProgramD3D::SemanticIndexArray *originalIndices;
};
// 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 ComparePackedVarying(const PackedVarying &x, const PackedVarying &y) bool ComparePackedVarying(const PackedVarying &x, const PackedVarying &y)
{ {
...@@ -772,10 +750,9 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -772,10 +750,9 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
return LinkResult(false, gl::Error(GL_NO_ERROR)); return LinkResult(false, gl::Error(GL_NO_ERROR));
} }
// TODO(jmadill): replace MAX_VERTEX_ATTRIBS for (int &index : mAttribLocationToD3DSemantic)
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; ++i)
{ {
stream->readInt(&mSemanticIndexes[i]); stream->readInt(&index);
} }
const unsigned int psSamplerCount = stream->readInt<unsigned int>(); const unsigned int psSamplerCount = stream->readInt<unsigned int>();
...@@ -983,7 +960,6 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) ...@@ -983,7 +960,6 @@ LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
} }
initializeUniformStorage(); initializeUniformStorage();
initAttributesByLayout();
return LinkResult(true, gl::Error(GL_NO_ERROR)); return LinkResult(true, gl::Error(GL_NO_ERROR));
} }
...@@ -999,10 +975,9 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -999,10 +975,9 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL); stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
// TODO(jmadill): replace MAX_VERTEX_ATTRIBS for (int d3dSemantic : mAttribLocationToD3DSemantic)
for (unsigned int i = 0; i < gl::MAX_VERTEX_ATTRIBS; ++i)
{ {
stream->writeInt(mSemanticIndexes[i]); stream->writeInt(d3dSemantic);
} }
stream->writeInt(mSamplersPS.size()); stream->writeInt(mSamplersPS.size());
...@@ -1465,7 +1440,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1465,7 +1440,7 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
mGeometryShaderPreamble = mDynamicHLSL->generateGeometryShaderPreamble(varyingPacking); mGeometryShaderPreamble = mDynamicHLSL->generateGeometryShaderPreamble(varyingPacking);
} }
initSemanticIndex(); initAttribLocationsToD3DSemantic();
defineUniformsAndAssignRegisters(); defineUniformsAndAssignRegisters();
...@@ -2173,8 +2148,7 @@ void ProgramD3D::reset() ...@@ -2173,8 +2148,7 @@ void ProgramD3D::reset()
mUsedPixelSamplerRange = 0; mUsedPixelSamplerRange = 0;
mDirtySamplerMapping = true; mDirtySamplerMapping = true;
std::fill(mSemanticIndexes, mSemanticIndexes + ArraySize(mSemanticIndexes), -1); mAttribLocationToD3DSemantic.fill(-1);
std::fill(mAttributesByLayout, mAttributesByLayout + ArraySize(mAttributesByLayout), -1);
mStreamOutVaryings.clear(); mStreamOutVaryings.clear();
...@@ -2191,7 +2165,7 @@ unsigned int ProgramD3D::issueSerial() ...@@ -2191,7 +2165,7 @@ unsigned int ProgramD3D::issueSerial()
return mCurrentSerial++; return mCurrentSerial++;
} }
void ProgramD3D::initSemanticIndex() void ProgramD3D::initAttribLocationsToD3DSemantic()
{ {
const gl::Shader *vertexShader = mData.getAttachedVertexShader(); const gl::Shader *vertexShader = mData.getAttachedVertexShader();
ASSERT(vertexShader != nullptr); ASSERT(vertexShader != nullptr);
...@@ -2199,41 +2173,14 @@ void ProgramD3D::initSemanticIndex() ...@@ -2199,41 +2173,14 @@ void ProgramD3D::initSemanticIndex()
// Init semantic index // Init semantic index
for (const sh::Attribute &attribute : mData.getAttributes()) for (const sh::Attribute &attribute : mData.getAttributes())
{ {
int attributeIndex = attribute.location; int d3dSemantic = vertexShader->getSemanticIndex(attribute.name);
int index = vertexShader->getSemanticIndex(attribute.name); int regCount = gl::VariableRegisterCount(attribute.type);
int regs = gl::VariableRegisterCount(attribute.type);
for (int reg = 0; reg < regs; ++reg) for (int reg = 0; reg < regCount; ++reg)
{ {
mSemanticIndexes[attributeIndex + reg] = index + reg; mAttribLocationToD3DSemantic[attribute.location + reg] = d3dSemantic + reg;
} }
} }
initAttributesByLayout();
}
void ProgramD3D::initAttributesByLayout()
{
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
mAttributesByLayout[i] = i;
}
std::sort(&mAttributesByLayout[0], &mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS],
AttributeSorter(mSemanticIndexes));
}
void ProgramD3D::sortAttributesByLayout(
const std::vector<TranslatedAttribute> &unsortedAttributes,
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS],
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const
{
for (size_t attribIndex = 0; attribIndex < unsortedAttributes.size(); ++attribIndex)
{
int oldIndex = mAttributesByLayout[attribIndex];
sortedSemanticIndicesOut[attribIndex] = mSemanticIndexes[oldIndex];
sortedAttributesOut[attribIndex] = &unsortedAttributes[oldIndex];
}
} }
void ProgramD3D::updateCachedInputLayout(const gl::State &state) void ProgramD3D::updateCachedInputLayout(const gl::State &state)
...@@ -2241,19 +2188,19 @@ void ProgramD3D::updateCachedInputLayout(const gl::State &state) ...@@ -2241,19 +2188,19 @@ void ProgramD3D::updateCachedInputLayout(const gl::State &state)
mCachedInputLayout.clear(); mCachedInputLayout.clear();
const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes(); const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes();
for (unsigned int attributeIndex : angle::IterateBitSet(mData.getActiveAttribLocationsMask())) for (unsigned int locationIndex : angle::IterateBitSet(mData.getActiveAttribLocationsMask()))
{ {
int semanticIndex = mSemanticIndexes[attributeIndex]; int d3dSemantic = mAttribLocationToD3DSemantic[locationIndex];
if (semanticIndex != -1) if (d3dSemantic != -1)
{ {
if (mCachedInputLayout.size() < static_cast<size_t>(semanticIndex + 1)) if (mCachedInputLayout.size() < static_cast<size_t>(d3dSemantic + 1))
{ {
mCachedInputLayout.resize(semanticIndex + 1, gl::VERTEX_FORMAT_INVALID); mCachedInputLayout.resize(d3dSemantic + 1, gl::VERTEX_FORMAT_INVALID);
} }
mCachedInputLayout[semanticIndex] = mCachedInputLayout[d3dSemantic] =
GetVertexFormatType(vertexAttributes[attributeIndex], GetVertexFormatType(vertexAttributes[locationIndex],
state.getVertexAttribCurrentValue(attributeIndex).Type); state.getVertexAttribCurrentValue(locationIndex).Type);
} }
} }
} }
...@@ -2357,4 +2304,4 @@ bool ProgramD3D::getUniformBlockMemberInfo(const std::string &memberUniformName, ...@@ -2357,4 +2304,4 @@ bool ProgramD3D::getUniformBlockMemberInfo(const std::string &memberUniformName,
*memberInfoOut = infoIter->second; *memberInfoOut = infoIter->second;
return true; return true;
} }
} } // namespace rx
...@@ -134,8 +134,6 @@ class ProgramD3DMetadata : angle::NonCopyable ...@@ -134,8 +134,6 @@ class ProgramD3DMetadata : angle::NonCopyable
class ProgramD3D : public ProgramImpl class ProgramD3D : public ProgramImpl
{ {
public: public:
typedef int SemanticIndexArray[gl::MAX_VERTEX_ATTRIBS];
ProgramD3D(const gl::Program::Data &data, RendererD3D *renderer); ProgramD3D(const gl::Program::Data &data, RendererD3D *renderer);
virtual ~ProgramD3D(); virtual ~ProgramD3D();
...@@ -238,12 +236,10 @@ class ProgramD3D : public ProgramImpl ...@@ -238,12 +236,10 @@ class ProgramD3D : public ProgramImpl
unsigned int getSerial() const; unsigned int getSerial() const;
void sortAttributesByLayout( const AttribIndexArray &getAttribLocationToD3DSemantics() const
const std::vector<TranslatedAttribute> &unsortedAttributes, {
int sortedSemanticIndicesOut[gl::MAX_VERTEX_ATTRIBS], return mAttribLocationToD3DSemantic;
const rx::TranslatedAttribute *sortedAttributesOut[gl::MAX_VERTEX_ATTRIBS]) const; }
const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndexes; }
const SemanticIndexArray &getAttributesByLayout() const { return mAttributesByLayout; }
void updateCachedInputLayout(const gl::State &state); void updateCachedInputLayout(const gl::State &state);
const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; } const gl::InputLayout &getCachedInputLayout() const { return mCachedInputLayout; }
...@@ -350,8 +346,7 @@ class ProgramD3D : public ProgramImpl ...@@ -350,8 +346,7 @@ class ProgramD3D : public ProgramImpl
D3DUniform *getD3DUniformByName(const std::string &name); D3DUniform *getD3DUniformByName(const std::string &name);
D3DUniform *getD3DUniformFromLocation(GLint location); D3DUniform *getD3DUniformFromLocation(GLint location);
void initSemanticIndex(); void initAttribLocationsToD3DSemantic();
void initAttributesByLayout();
void reset(); void reset();
void assignUniformBlockRegisters(); void assignUniformBlockRegisters();
...@@ -394,8 +389,7 @@ class ProgramD3D : public ProgramImpl ...@@ -394,8 +389,7 @@ class ProgramD3D : public ProgramImpl
// Cache for getPixelExecutableForFramebuffer // Cache for getPixelExecutableForFramebuffer
std::vector<GLenum> mPixelShaderOutputFormatCache; std::vector<GLenum> mPixelShaderOutputFormatCache;
SemanticIndexArray mSemanticIndexes; AttribIndexArray mAttribLocationToD3DSemantic;
SemanticIndexArray mAttributesByLayout;
unsigned int mSerial; unsigned int mSerial;
......
...@@ -94,6 +94,8 @@ class BufferFactoryD3D ...@@ -94,6 +94,8 @@ class BufferFactoryD3D
GLsizei instances) const = 0; GLsizei instances) const = 0;
}; };
using AttribIndexArray = std::array<int, gl::MAX_VERTEX_ATTRIBS>;
class RendererD3D : public Renderer, public BufferFactoryD3D class RendererD3D : public Renderer, public BufferFactoryD3D
{ {
public: public:
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "libANGLE/Constants.h" #include "libANGLE/Constants.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
namespace gl namespace gl
{ {
...@@ -34,9 +35,6 @@ struct TranslatedIndexData; ...@@ -34,9 +35,6 @@ struct TranslatedIndexData;
struct SourceIndexData; struct SourceIndexData;
class ProgramD3D; class ProgramD3D;
using SortedAttribArray = std::array<const TranslatedAttribute *, gl::MAX_VERTEX_ATTRIBS>;
using SortedIndexArray = std::array<int, gl::MAX_VERTEX_ATTRIBS>;
class InputLayoutCache : angle::NonCopyable class InputLayoutCache : angle::NonCopyable
{ {
public: public:
...@@ -47,9 +45,9 @@ class InputLayoutCache : angle::NonCopyable ...@@ -47,9 +45,9 @@ class InputLayoutCache : angle::NonCopyable
void clear(); void clear();
void markDirty(); void markDirty();
gl::Error applyVertexBuffers(const std::vector<TranslatedAttribute> &attributes, gl::Error applyVertexBuffers(const gl::State &state,
const std::vector<TranslatedAttribute> &attributes,
GLenum mode, GLenum mode,
gl::Program *program,
TranslatedIndexData *indexInfo, TranslatedIndexData *indexInfo,
GLsizei numIndicesPerInstance); GLsizei numIndicesPerInstance);
...@@ -86,15 +84,11 @@ class InputLayoutCache : angle::NonCopyable ...@@ -86,15 +84,11 @@ class InputLayoutCache : angle::NonCopyable
uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS]; uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS];
}; };
gl::Error updateInputLayout(gl::Program *program, gl::Error updateInputLayout(const gl::State &state,
GLenum mode, GLenum mode,
const SortedAttribArray &sortedAttributes, const AttribIndexArray &sortedSemanticIndices,
const SortedIndexArray &sortedSemanticIndices,
size_t attribCount,
GLsizei numIndicesPerInstance); GLsizei numIndicesPerInstance);
gl::Error createInputLayout(const SortedAttribArray &sortedAttributes, gl::Error createInputLayout(const AttribIndexArray &sortedSemanticIndices,
const SortedIndexArray &sortedSemanticIndices,
size_t attribCount,
GLenum mode, GLenum mode,
gl::Program *program, gl::Program *program,
GLsizei numIndicesPerInstance, GLsizei numIndicesPerInstance,
...@@ -103,11 +97,10 @@ class InputLayoutCache : angle::NonCopyable ...@@ -103,11 +97,10 @@ class InputLayoutCache : angle::NonCopyable
std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap; std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap;
ID3D11InputLayout *mCurrentIL; ID3D11InputLayout *mCurrentIL;
ID3D11Buffer *mCurrentBuffers[gl::MAX_VERTEX_ATTRIBS]; std::array<ID3D11Buffer *, gl::MAX_VERTEX_ATTRIBS> mCurrentBuffers;
UINT mCurrentVertexStrides[gl::MAX_VERTEX_ATTRIBS]; std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexStrides;
UINT mCurrentVertexOffsets[gl::MAX_VERTEX_ATTRIBS]; std::array<UINT, gl::MAX_VERTEX_ATTRIBS> mCurrentVertexOffsets;
SortedAttribArray mSortedAttributes; std::vector<const TranslatedAttribute *> mCurrentAttributes;
size_t mUnsortedAttributesCount;
ID3D11Buffer *mPointSpriteVertexBuffer; ID3D11Buffer *mPointSpriteVertexBuffer;
ID3D11Buffer *mPointSpriteIndexBuffer; ID3D11Buffer *mPointSpriteIndexBuffer;
......
...@@ -1515,8 +1515,8 @@ gl::Error Renderer11::applyVertexBuffer(const gl::State &state, ...@@ -1515,8 +1515,8 @@ gl::Error Renderer11::applyVertexBuffer(const gl::State &state,
{ {
numIndicesPerInstance = count; numIndicesPerInstance = count;
} }
return mInputLayoutCache.applyVertexBuffers(mTranslatedAttribCache, mode, state.getProgram(), return mInputLayoutCache.applyVertexBuffers(state, mTranslatedAttribCache, mode, indexInfo,
indexInfo, numIndicesPerInstance); numIndicesPerInstance);
} }
gl::Error Renderer11::applyIndexBuffer(const gl::Data &data, gl::Error Renderer11::applyIndexBuffer(const gl::Data &data,
......
...@@ -102,7 +102,7 @@ gl::Error VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, ...@@ -102,7 +102,7 @@ gl::Error VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device,
D3DVERTEXELEMENT9 *element = &elements[0]; D3DVERTEXELEMENT9 *element = &elements[0];
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
const auto &semanticIndexes = programD3D->getSemanticIndexes(); const auto &semanticIndexes = programD3D->getAttribLocationToD3DSemantics();
for (size_t i = 0; i < attributes.size(); i++) for (size_t i = 0; i < attributes.size(); i++)
{ {
......
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