Commit 7c8928d0 by Jiacheng Lu Committed by Commit Bot

Add more tests covering gl::vertexAttribPointer

1. Add tests ensuring VBO binding with format requiring conversion in vulkan backend is converted correctly after binding and offset changes. 2. Add tests ensuring VBO binding switching between CPU and GPU handles correctly in vulkan. As for vulkan, it transfers CPU side memory into tightly packed buffer and may causing a stride change. Bug: angleproject:3256 Change-Id: I5d9d78670b28bec286b96d3b6a9c6211da3f3d9b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1716614 Commit-Queue: Jiacheng Lu <lujc@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f3dbf0a7
......@@ -384,25 +384,37 @@ void AttributeLayoutTest::GetTestCases(void)
// 5. stride != size
mTestCases.push_back({Float(B0, 0, 16, mCoord), Float(B1, 0, 12, mColor)});
// 6-9. byte/short
// 6-7. same stride and format, switching data between memory and buffer
mTestCases.push_back({Float(M0, 0, 16, mCoord), Float(M1, 0, 12, mColor)});
mTestCases.push_back({Float(B0, 0, 16, mCoord), Float(B1, 0, 12, mColor)});
// 8-9. same stride and format, offset change
mTestCases.push_back({Float(B0, 0, 8, mCoord), Float(B1, 0, 12, mColor)});
mTestCases.push_back({Float(B0, 3, 8, mCoord), Float(B1, 4, 12, mColor)});
// 10-11. unaligned buffer data
mTestCases.push_back({Float(M0, 0, 8, mCoord), Float(B0, 1, 13, mColor)});
mTestCases.push_back({Float(M0, 0, 8, mCoord), Float(B1, 1, 13, mColor)});
// 12-15. byte/short
mTestCases.push_back({SByte(M0, 0, 20, mCoord), UByte(M0, 10, 20, mColor)});
mTestCases.push_back({SShort(M0, 0, 20, mCoord), UShort(M0, 8, 20, mColor)});
mTestCases.push_back({NormSByte(M0, 0, 8, mCoord), NormUByte(M0, 4, 8, mColor)});
mTestCases.push_back({NormSShort(M0, 0, 20, mCoord), NormUShort(M0, 8, 20, mColor)});
// 10. one buffer, sequential
// 16. one buffer, sequential
mTestCases.push_back({Fixed(B0, 0, 8, mCoord), Float(B0, 96, 12, mColor)});
// 11. one buffer, interleaved
// 17. one buffer, interleaved
mTestCases.push_back({Fixed(B0, 0, 20, mCoord), Float(B0, 8, 20, mColor)});
// 12. memory and buffer, float and integer
// 18. memory and buffer, float and integer
mTestCases.push_back({Float(M0, 0, 8, mCoord), SByte(B0, 0, 12, mColor)});
// 13. buffer and memory, unusual offset and stride
// 19. buffer and memory, unusual offset and stride
mTestCases.push_back({Float(B0, 11, 13, mCoord), Float(M0, 23, 17, mColor)});
// 14-15. remaining ES3 formats
// 20-21. remaining ES3 formats
if (es3)
{
mTestCases.push_back({SInt(M0, 0, 40, mCoord), UInt(M0, 16, 40, mColor)});
......
......@@ -1768,6 +1768,81 @@ TEST_P(SimpleStateChangeTest, DrawElementsUBYTEX2ThenDrawElementsUSHORT)
EXPECT_PIXEL_COLOR_EQ(quarterWidth, quarterHeight * 2, GLColor::blue);
}
// Draw a points use multiple unaligned vertex buffer with same data,
// verify all the rendering results are the same.
TEST_P(SimpleStateChangeTest, DrawRepeatUnalignedVboChange)
{
const int kRepeat = 2;
// set up VBO, colorVBO is unaligned
GLBuffer positionBuffer;
constexpr size_t posOffset = 0;
const GLfloat posData[] = {0.5f, 0.5f};
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(posData), posData, GL_STATIC_DRAW);
GLBuffer colorBuffers[kRepeat];
constexpr size_t colorOffset = 1;
const GLfloat colorData[] = {0.515f, 0.515f, 0.515f, 1.0f};
constexpr size_t colorBufferSize = colorOffset + sizeof(colorData);
uint8_t colorDataUnaligned[colorBufferSize] = {0};
memcpy(reinterpret_cast<void *>(colorDataUnaligned + colorOffset), colorData,
sizeof(colorData));
for (uint32_t i = 0; i < kRepeat; i++)
{
glBindBuffer(GL_ARRAY_BUFFER, colorBuffers[i]);
glBufferData(GL_ARRAY_BUFFER, colorBufferSize, colorDataUnaligned, GL_STATIC_DRAW);
}
// set up frame buffer
GLFramebuffer framebuffer;
GLTexture framebufferTexture;
bindTextureToFbo(framebuffer, framebufferTexture);
// set up program
ANGLE_GL_PROGRAM(program, kSimpleVertexShader, kSimpleFragmentShader);
glUseProgram(program);
GLuint colorAttrLocation = glGetAttribLocation(program, "color");
glEnableVertexAttribArray(colorAttrLocation);
GLuint posAttrLocation = glGetAttribLocation(program, "position");
glEnableVertexAttribArray(posAttrLocation);
EXPECT_GL_NO_ERROR();
// draw and get drawing results
constexpr size_t kRenderSize = kWindowSize * kWindowSize;
std::array<GLColor, kRenderSize> pixelBufs[kRepeat];
for (uint32_t i = 0; i < kRepeat; i++)
{
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, positionBuffer);
glVertexAttribPointer(posAttrLocation, 2, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<const void *>(posOffset));
glBindBuffer(GL_ARRAY_BUFFER, colorBuffers[i]);
glVertexAttribPointer(colorAttrLocation, 4, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<const void *>(colorOffset));
glDrawArrays(GL_POINTS, 0, 1);
// read drawing results
glReadPixels(0, 0, kWindowSize, kWindowSize, GL_RGBA, GL_UNSIGNED_BYTE,
pixelBufs[i].data());
EXPECT_GL_NO_ERROR();
}
// verify something is drawn
static_assert(kRepeat >= 2, "More than one repetition required");
std::array<GLColor, kRenderSize> pixelAllBlack{0};
EXPECT_NE(pixelBufs[0], pixelAllBlack);
// verify drawing results are all identical
for (uint32_t i = 1; i < kRepeat; i++)
{
EXPECT_EQ(pixelBufs[i - 1], pixelBufs[i]);
}
}
// Handles deleting a Buffer when it's being used.
TEST_P(SimpleStateChangeTest, DeleteBufferInUse)
{
......
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