Commit d078c681 by Jamie Madill Committed by Commit Bot

VertexArray: Add enabled attribs bitmask.

This replaces the "max enabled attrib" integer with a bitmask of enabled attribs. Should have better worst-case performance (only attribute 15 is enabled) and similar best-case performance (when only attribute 0 is enabled). This might also help implementing validation optimizations. Bug: angleproject:2202 Change-Id: I5cbb533c3af23851a42c80a6dc409a0da84e87c3 Reviewed-on: https://chromium-review.googlesource.com/847284Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent ffa2cd04
...@@ -2205,8 +2205,7 @@ bool State::hasMappedBuffer(BufferBinding target) const ...@@ -2205,8 +2205,7 @@ bool State::hasMappedBuffer(BufferBinding target) const
const VertexArray *vao = getVertexArray(); const VertexArray *vao = getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
const auto &vertexBindings = vao->getVertexBindings(); const auto &vertexBindings = vao->getVertexBindings();
size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); for (size_t attribIndex : vao->getEnabledAttributesMask())
for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
{ {
const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; const VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get(); auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get();
......
...@@ -16,7 +16,7 @@ namespace gl ...@@ -16,7 +16,7 @@ namespace gl
{ {
VertexArrayState::VertexArrayState(size_t maxAttribs, size_t maxAttribBindings) VertexArrayState::VertexArrayState(size_t maxAttribs, size_t maxAttribBindings)
: mLabel(), mVertexBindings(maxAttribBindings), mMaxEnabledAttribute(0) : mLabel(), mVertexBindings(maxAttribBindings)
{ {
ASSERT(maxAttribs <= maxAttribBindings); ASSERT(maxAttribs <= maxAttribBindings);
...@@ -206,18 +206,7 @@ void VertexArray::enableAttribute(size_t attribIndex, bool enabledState) ...@@ -206,18 +206,7 @@ void VertexArray::enableAttribute(size_t attribIndex, bool enabledState)
mDirtyBits.set(DIRTY_BIT_ATTRIB_0_ENABLED + attribIndex); mDirtyBits.set(DIRTY_BIT_ATTRIB_0_ENABLED + attribIndex);
// Update state cache // Update state cache
if (enabledState) mState.mEnabledAttributesMask.set(attribIndex, enabledState);
{
mState.mMaxEnabledAttribute = std::max(attribIndex + 1, mState.mMaxEnabledAttribute);
}
else if (mState.mMaxEnabledAttribute == attribIndex + 1)
{
while (mState.mMaxEnabledAttribute > 0 &&
!mState.mVertexAttributes[mState.mMaxEnabledAttribute - 1].enabled)
{
--mState.mMaxEnabledAttribute;
}
}
} }
void VertexArray::setVertexAttribPointer(const Context *context, void VertexArray::setVertexAttribPointer(const Context *context,
......
...@@ -42,7 +42,7 @@ class VertexArrayState final : angle::NonCopyable ...@@ -42,7 +42,7 @@ class VertexArrayState final : angle::NonCopyable
const BindingPointer<Buffer> &getElementArrayBuffer() const { return mElementArrayBuffer; } const BindingPointer<Buffer> &getElementArrayBuffer() const { return mElementArrayBuffer; }
size_t getMaxAttribs() const { return mVertexAttributes.size(); } size_t getMaxAttribs() const { return mVertexAttributes.size(); }
size_t getMaxBindings() const { return mVertexBindings.size(); } size_t getMaxBindings() const { return mVertexBindings.size(); }
size_t getMaxEnabledAttribute() const { return mMaxEnabledAttribute; } const AttributesMask &getEnabledAttributesMask() const { return mEnabledAttributesMask; }
const std::vector<VertexAttribute> &getVertexAttributes() const { return mVertexAttributes; } const std::vector<VertexAttribute> &getVertexAttributes() const { return mVertexAttributes; }
const VertexAttribute &getVertexAttribute(size_t attribIndex) const const VertexAttribute &getVertexAttribute(size_t attribIndex) const
{ {
...@@ -68,7 +68,7 @@ class VertexArrayState final : angle::NonCopyable ...@@ -68,7 +68,7 @@ class VertexArrayState final : angle::NonCopyable
std::vector<VertexAttribute> mVertexAttributes; std::vector<VertexAttribute> mVertexAttributes;
BindingPointer<Buffer> mElementArrayBuffer; BindingPointer<Buffer> mElementArrayBuffer;
std::vector<VertexBinding> mVertexBindings; std::vector<VertexBinding> mVertexBindings;
size_t mMaxEnabledAttribute; AttributesMask mEnabledAttributesMask;
}; };
class VertexArray final : public LabeledObject class VertexArray final : public LabeledObject
...@@ -147,7 +147,10 @@ class VertexArray final : public LabeledObject ...@@ -147,7 +147,10 @@ class VertexArray final : public LabeledObject
rx::VertexArrayImpl *getImplementation() const { return mVertexArray; } rx::VertexArrayImpl *getImplementation() const { return mVertexArray; }
size_t getMaxEnabledAttribute() const { return mState.getMaxEnabledAttribute(); } const AttributesMask &getEnabledAttributesMask() const
{
return mState.getEnabledAttributesMask();
}
enum DirtyBitType enum DirtyBitType
{ {
......
...@@ -47,8 +47,7 @@ bool ValidateDrawAttribs(ValidationContext *context, ...@@ -47,8 +47,7 @@ bool ValidateDrawAttribs(ValidationContext *context,
const VertexArray *vao = state.getVertexArray(); const VertexArray *vao = state.getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
const auto &vertexBindings = vao->getVertexBindings(); const auto &vertexBindings = vao->getVertexBindings();
size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); for (size_t attributeIndex : vao->getEnabledAttributesMask())
for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
{ {
const VertexAttribute &attrib = vertexAttribs[attributeIndex]; const VertexAttribute &attrib = vertexAttribs[attributeIndex];
......
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