Commit 7ae8531b by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Fix crash with 0-sized element buffer

VertexArray::syncState syncs all dirty bits, including DIRTY_BIT_ELEMENT_ARRAY_BUFFER even for draw calls that don't use this buffer, such as glDrawArrays. If the element buffer is given 0 size, this caused a crash in the Vulkan backend. Bug: chromium:1172577 Change-Id: I02d78c9660c07b896f7403867b648901478251fe Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2701831Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 436b43a6
...@@ -448,7 +448,7 @@ angle::Result VertexArrayVk::syncState(const gl::Context *context, ...@@ -448,7 +448,7 @@ angle::Result VertexArrayVk::syncState(const gl::Context *context,
case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA: case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA:
{ {
gl::Buffer *bufferGL = mState.getElementArrayBuffer(); gl::Buffer *bufferGL = mState.getElementArrayBuffer();
if (bufferGL) if (bufferGL && bufferGL->getSize() > 0)
{ {
// Note that just updating buffer data may still result in a new // Note that just updating buffer data may still result in a new
// vk::BufferHelper allocation. // vk::BufferHelper allocation.
......
...@@ -6075,6 +6075,21 @@ void main() ...@@ -6075,6 +6075,21 @@ void main()
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
} }
// Test that glDrawArrays when an empty-sized element array buffer is bound doesn't crash.
// Regression test for crbug.com/1172577.
TEST_P(SimpleStateChangeTest, DrawArraysWithZeroSizedElementArrayBuffer)
{
ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
GLBuffer indexBuffer;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);
drawQuad(greenProgram, essl1_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Validates GL_RASTERIZER_DISCARD state is tracked correctly // Validates GL_RASTERIZER_DISCARD state is tracked correctly
TEST_P(SimpleStateChangeTestES3, RasterizerDiscardState) TEST_P(SimpleStateChangeTestES3, RasterizerDiscardState)
{ {
......
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