Commit 337bd698 by Shahbaz Youssefi Committed by Commit Bot

Disable vertex attributes if not active in program

Even if explicitly enabled. Bug: angleproject:2138 Change-Id: I598d21296bb6843e05cdeab146c1ff3da3a1174b Reviewed-on: https://chromium-review.googlesource.com/1185743Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent dc248f71
......@@ -310,8 +310,12 @@ void VertexArray::enableAttribute(size_t attribIndex, bool enabledState)
VertexAttribute &attrib = mState.mVertexAttributes[attribIndex];
if (mState.mEnabledAttributesMask.test(attribIndex) == enabledState)
{
return;
}
attrib.enabled = enabledState;
mState.mVertexAttributesTypeMask.setIndex(GetVertexAttributeBaseType(attrib), attribIndex);
setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_ENABLED);
......
......@@ -1945,8 +1945,8 @@ void StateManagerGL::syncState(const gl::Context *context, const gl::State::Dirt
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(state.getVertexArray());
bindVertexArray(vaoGL->getVertexArrayID(), vaoGL->getAppliedElementArrayBufferID());
propagateNumViewsToVAO(state.getProgram(),
GetImplAs<VertexArrayGL>(state.getVertexArray()));
propagateProgramToVAO(state.getProgram(),
GetImplAs<VertexArrayGL>(state.getVertexArray()));
break;
}
case gl::State::DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING:
......@@ -1978,8 +1978,8 @@ void StateManagerGL::syncState(const gl::Context *context, const gl::State::Dirt
case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE:
mProgramTexturesAndSamplersDirty = true;
mProgramStorageBuffersDirty = true;
propagateNumViewsToVAO(state.getProgram(),
GetImplAs<VertexArrayGL>(state.getVertexArray()));
propagateProgramToVAO(state.getProgram(),
GetImplAs<VertexArrayGL>(state.getVertexArray()));
updateMultiviewBaseViewLayerIndexUniform(
state.getProgram(),
state.getDrawFramebuffer()->getImplementation()->getState());
......@@ -2238,9 +2238,15 @@ void StateManagerGL::applyViewportOffsetsAndSetViewports(const gl::Rectangle &vi
setViewportArrayv(0u, viewportArray);
}
void StateManagerGL::propagateNumViewsToVAO(const gl::Program *program, VertexArrayGL *vao)
void StateManagerGL::propagateProgramToVAO(const gl::Program *program, VertexArrayGL *vao)
{
if (mIsMultiviewEnabled && vao != nullptr)
if (vao == nullptr)
{
return;
}
// Number of views:
if (mIsMultiviewEnabled)
{
int programNumViews = 1;
if (program && program->usesMultiview())
......@@ -2249,6 +2255,12 @@ void StateManagerGL::propagateNumViewsToVAO(const gl::Program *program, VertexAr
}
vao->applyNumViewsToDivisor(programNumViews);
}
// Attribute enabled mask:
if (program)
{
vao->applyActiveAttribLocationsMask(program->getActiveAttribLocationsMask());
}
}
void StateManagerGL::updateMultiviewBaseViewLayerIndexUniform(
......
......@@ -193,7 +193,7 @@ class StateManagerGL final : angle::NonCopyable
const gl::Framebuffer &drawFramebuffer);
void applyViewportOffsetsAndSetViewports(const gl::Rectangle &viewport,
const gl::Framebuffer &drawFramebuffer);
void propagateNumViewsToVAO(const gl::Program *program, VertexArrayGL *vao);
void propagateProgramToVAO(const gl::Program *program, VertexArrayGL *vao);
void updateProgramTextureAndSamplerBindings(const gl::Context *context);
void updateProgramStorageBufferBindings(const gl::Context *context);
......
......@@ -417,7 +417,8 @@ GLuint VertexArrayGL::getAppliedElementArrayBufferID() const
void VertexArrayGL::updateAttribEnabled(size_t attribIndex)
{
const bool enabled = mState.getVertexAttribute(attribIndex).enabled;
const bool enabled = mState.getVertexAttribute(attribIndex).enabled &
mProgramActiveAttribLocationsMask.test(attribIndex);
if (mAppliedAttributes[attribIndex].enabled == enabled)
{
return;
......@@ -731,4 +732,15 @@ void VertexArrayGL::applyNumViewsToDivisor(int numViews)
}
}
void VertexArrayGL::applyActiveAttribLocationsMask(const gl::AttributesMask &activeMask)
{
gl::AttributesMask updateMask = mProgramActiveAttribLocationsMask ^ activeMask;
mProgramActiveAttribLocationsMask = activeMask;
for (size_t attribIndex : updateMask)
{
updateAttribEnabled(attribIndex);
}
}
} // namespace rx
......@@ -50,6 +50,7 @@ class VertexArrayGL : public VertexArrayImpl
const gl::VertexArray::DirtyBindingBitsArray &bindingBits) override;
void applyNumViewsToDivisor(int numViews);
void applyActiveAttribLocationsMask(const gl::AttributesMask &activeMask);
private:
gl::Error syncDrawState(const gl::Context *context,
......@@ -115,6 +116,10 @@ class VertexArrayGL : public VertexArrayImpl
GLuint mVertexArrayID;
int mAppliedNumViews;
// Remember the program's active attrib location mask so that attributes can be enabled/disabled
// based on whether they are active in the program
gl::AttributesMask mProgramActiveAttribLocationsMask;
mutable gl::BindingPointer<gl::Buffer> mAppliedElementArrayBuffer;
mutable std::vector<gl::VertexAttribute> mAppliedAttributes;
......
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