Commit d9268889 by shrekshao Committed by Commit Bot

Take into account baseVertex for drawElementsImpl D3D11

Also add test for GL_DYNAMIC_DRAW and GL_STREAM_DRAW with vertex color data updating before each draw call to make sure index range is retrieved correctly. Bug: angleproject:3402, angleproject:3911 Change-Id: I5f209292b6e316e4b50505a98b361eb8761a7d6b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2162132Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShrek Shao <shrekshao@google.com> Commit-Queue: Shrek Shao <shrekshao@google.com>
parent 1398080c
...@@ -309,12 +309,13 @@ ANGLE_INLINE angle::Result Context11::drawElementsImpl(const gl::Context *contex ...@@ -309,12 +309,13 @@ ANGLE_INLINE angle::Result Context11::drawElementsImpl(const gl::Context *contex
gl::IndexRange indexRange; gl::IndexRange indexRange;
ANGLE_TRY(context->getState().getVertexArray()->getIndexRange( ANGLE_TRY(context->getState().getVertexArray()->getIndexRange(
context, indexType, indexCount, indices, &indexRange)); context, indexType, indexCount, indices, &indexRange));
GLint startVertex;
ANGLE_TRY(ComputeStartVertex(GetImplAs<Context11>(context), indexRange, baseVertex,
&startVertex));
ANGLE_TRY(mRenderer->getStateManager()->updateState( ANGLE_TRY(mRenderer->getStateManager()->updateState(
context, mode, static_cast<GLint>(indexRange.start), indexCount, indexType, indices, context, mode, startVertex, indexCount, indexType, indices, instanceCount, baseVertex));
instanceCount, baseVertex)); return mRenderer->drawElements(context, mode, startVertex, indexCount, indexType, indices,
return mRenderer->drawElements(context, mode, static_cast<GLint>(indexRange.start), instanceCount, baseVertex, baseInstance);
indexCount, indexType, indices, instanceCount, baseVertex,
baseInstance);
} }
else else
{ {
......
...@@ -35,6 +35,7 @@ constexpr std::array<GLfloat, 2> kQuadRadius = {0.25f * kTileSize[0], 0.25f ...@@ -35,6 +35,7 @@ constexpr std::array<GLfloat, 2> kQuadRadius = {0.25f * kTileSize[0], 0.25f
constexpr std::array<uint32_t, 2> kPixelCheckSize = { constexpr std::array<uint32_t, 2> kPixelCheckSize = {
static_cast<uint32_t>(kQuadRadius[0] * kWidth), static_cast<uint32_t>(kQuadRadius[0] * kWidth),
static_cast<uint32_t>(kQuadRadius[1] * kHeight)}; static_cast<uint32_t>(kQuadRadius[1] * kHeight)};
constexpr GLenum kBufferDataUsage[] = {GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_DRAW};
constexpr std::array<GLfloat, 2> GetTileCenter(uint32_t x, uint32_t y) constexpr std::array<GLfloat, 2> GetTileCenter(uint32_t x, uint32_t y)
{ {
...@@ -62,9 +63,38 @@ enum class DrawCallVariants ...@@ -62,9 +63,38 @@ enum class DrawCallVariants
DrawElementsInstancedBaseVertexBaseInstance DrawElementsInstancedBaseVertexBaseInstance
}; };
using DrawBaseVertexVariantsTestParams = std::tuple<angle::PlatformParameters, GLenum>;
std::string DrawBaseVertexVariantsTestPrint(
const ::testing::TestParamInfo<DrawBaseVertexVariantsTestParams> &paramsInfo)
{
const DrawBaseVertexVariantsTestParams &params = paramsInfo.param;
std::ostringstream out;
out << std::get<0>(params) << '_';
switch (std::get<1>(params))
{
case GL_STATIC_DRAW:
out << "STATIC_DRAW";
break;
case GL_DYNAMIC_DRAW:
out << "DYNAMIC_DRAW";
break;
case GL_STREAM_DRAW:
out << "STREAM_DRAW";
break;
default:
out << "UPDATE_THIS_SWITCH";
break;
}
return out.str();
}
// These tests check correctness of variants of baseVertex draw calls from different extensions // These tests check correctness of variants of baseVertex draw calls from different extensions
class DrawBaseVertexVariantsTest : public ANGLETest class DrawBaseVertexVariantsTest : public ANGLETestWithParam<DrawBaseVertexVariantsTestParams>
{ {
protected: protected:
DrawBaseVertexVariantsTest() DrawBaseVertexVariantsTest()
...@@ -173,23 +203,24 @@ void main() ...@@ -173,23 +203,24 @@ void main()
GLBuffer &vertexColorBuffer, GLBuffer &vertexColorBuffer,
GLBuffer &indexBuffer) GLBuffer &indexBuffer)
{ {
GLenum usage = std::get<1>(GetParam());
glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLubyte) * mVertexColors.size(), mVertexColors.data(), glBufferData(GL_ARRAY_BUFFER, sizeof(GLubyte) * mVertexColors.size(), mVertexColors.data(),
GL_STATIC_DRAW); usage);
glEnableVertexAttribArray(mColorLoc); glEnableVertexAttribArray(mColorLoc);
glVertexAttribPointer(mColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0); glVertexAttribPointer(mColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * mVertices.size(), mVertices.data(), glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * mVertices.size(), mVertices.data(), usage);
GL_STATIC_DRAW);
glEnableVertexAttribArray(mPositionLoc); glEnableVertexAttribArray(mPositionLoc);
glVertexAttribPointer(mPositionLoc, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(mPositionLoc, 2, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * mIndices.size(), mIndices.data(), glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * mIndices.size(), mIndices.data(),
GL_STATIC_DRAW); usage);
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
...@@ -210,6 +241,8 @@ void main() ...@@ -210,6 +241,8 @@ void main()
{ {
int repetitionCount = std::min(3 - baseRepetition, kBoxCount - i); int repetitionCount = std::min(3 - baseRepetition, kBoxCount - i);
updateVertexColorData(i, repetitionCount);
switch (drawCallType) switch (drawCallType)
{ {
case DrawCallVariants::DrawElementsInstancedBaseVertexBaseInstance: case DrawCallVariants::DrawElementsInstancedBaseVertexBaseInstance:
...@@ -255,8 +288,31 @@ void main() ...@@ -255,8 +288,31 @@ void main()
checkDrawResult(); checkDrawResult();
} }
void updateVertexColorData(GLint drawnQuadCount, GLint toDrawQuadCount)
{
// update the vertex color of the next [count] of quads to draw
if (std::get<1>(GetParam()) == GL_STATIC_DRAW)
{
return;
}
GLint offset = sizeof(GLubyte) * drawnQuadCount * 4 * sizeof(GLColor);
for (GLint i = 0; i < toDrawQuadCount; i++)
{
const GLColor &color = mColorPalette[(drawnQuadCount + i) % mColorPalette.size()];
for (GLint j = 0; j < 4; j++)
{
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(GLColor), color.data());
offset += sizeof(GLColor);
}
}
}
void checkDrawResult() void checkDrawResult()
{ {
bool dynamicLayout = std::get<1>(GetParam()) == GL_STATIC_DRAW ? false : true;
for (uint32_t y = 0; y < kCountY; ++y) for (uint32_t y = 0; y < kCountY; ++y)
{ {
for (uint32_t x = 0; x < kCountX; ++x) for (uint32_t x = 0; x < kCountX; ++x)
...@@ -264,7 +320,8 @@ void main() ...@@ -264,7 +320,8 @@ void main()
uint32_t center_x = x * kTilePixelSize[0] + kTilePixelSize[0] / 2; uint32_t center_x = x * kTilePixelSize[0] + kTilePixelSize[0] / 2;
uint32_t center_y = y * kTilePixelSize[1] + kTilePixelSize[1] / 2; uint32_t center_y = y * kTilePixelSize[1] + kTilePixelSize[1] / 2;
const auto &color = mColorPalette[(x + y) % mColorPalette.size()]; const auto &color =
mColorPalette[(dynamicLayout ? x : x + y) % mColorPalette.size()];
EXPECT_PIXEL_NEAR(center_x - kPixelCheckSize[0] / 2, EXPECT_PIXEL_NEAR(center_x - kPixelCheckSize[0] / 2,
center_y - kPixelCheckSize[1] / 2, color[0], color[1], color[2], center_y - kPixelCheckSize[1] / 2, color[0], color[1], color[2],
...@@ -314,6 +371,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsBaseVertex) ...@@ -314,6 +371,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsBaseVertex)
GLBuffer vertexColorBuffer; GLBuffer vertexColorBuffer;
setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer); setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer);
// for potential update vertex color later
glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer);
doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsBaseVertex); doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsBaseVertex);
} }
...@@ -330,6 +390,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsInstancedBaseVertex) ...@@ -330,6 +390,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsInstancedBaseVertex)
GLBuffer vertexColorBuffer; GLBuffer vertexColorBuffer;
setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer); setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer);
// for potential update vertex color later
glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer);
doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsInstancedBaseVertex); doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsInstancedBaseVertex);
} }
...@@ -346,6 +409,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawRangeElementsBaseVertex) ...@@ -346,6 +409,9 @@ TEST_P(DrawBaseVertexVariantsTest, DrawRangeElementsBaseVertex)
GLBuffer vertexColorBuffer; GLBuffer vertexColorBuffer;
setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer); setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer);
// for potential update vertex color later
glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer);
doDrawElementsBaseVertexVariants(DrawCallVariants::DrawRangeElementsBaseVertex); doDrawElementsBaseVertexVariants(DrawCallVariants::DrawRangeElementsBaseVertex);
} }
...@@ -362,9 +428,18 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsInstancedBaseVertexBaseInstance) ...@@ -362,9 +428,18 @@ TEST_P(DrawBaseVertexVariantsTest, DrawElementsInstancedBaseVertexBaseInstance)
GLBuffer vertexColorBuffer; GLBuffer vertexColorBuffer;
setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer); setupIndexedBuffers(vertexPositionBuffer, vertexColorBuffer, indexBuffer);
// for potential update vertex color later
glBindBuffer(GL_ARRAY_BUFFER, vertexColorBuffer);
doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsInstancedBaseVertexBaseInstance); doDrawElementsBaseVertexVariants(DrawCallVariants::DrawElementsInstancedBaseVertexBaseInstance);
} }
ANGLE_INSTANTIATE_TEST_ES3(DrawBaseVertexVariantsTest); ANGLE_INSTANTIATE_TEST_COMBINE_1(DrawBaseVertexVariantsTest,
DrawBaseVertexVariantsTestPrint,
testing::ValuesIn(kBufferDataUsage),
ES3_D3D11(),
ES3_OPENGL(),
ES3_OPENGLES(),
ES3_VULKAN());
} // namespace } // namespace
...@@ -203,6 +203,10 @@ struct CombinedPrintToStringParamName ...@@ -203,6 +203,10 @@ struct CombinedPrintToStringParamName
// enumeration of platforms in the extra args, similar to // enumeration of platforms in the extra args, similar to
// ANGLE_INSTANTIATE_TEST. The macros are defined only for the Ns // ANGLE_INSTANTIATE_TEST. The macros are defined only for the Ns
// currently in use, and can be expanded as necessary. // currently in use, and can be expanded as necessary.
#define ANGLE_INSTANTIATE_TEST_COMBINE_1(testName, print, combine1, first, ...) \
const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
INSTANTIATE_TEST_SUITE_P( \
, testName, testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), combine1), print)
#define ANGLE_INSTANTIATE_TEST_COMBINE_4(testName, print, combine1, combine2, combine3, combine4, \ #define ANGLE_INSTANTIATE_TEST_COMBINE_4(testName, print, combine1, combine2, combine3, combine4, \
first, ...) \ first, ...) \
const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \ const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
......
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