Commit 0ba963ef by Shao Committed by Commit Bot

ES31: Add test on large strides

ES3.1 requires the implementation should define MAX_VERTEX_ATTRIB_STRIDE, which should be emulated when we use D3D11 backends. This patch adds tests to verify this value required in ES3.1 are supported to be used directly in glVertexAttribPointer for rendering. BUG=angleproject:1593 TEST=angle_end2end_tests Change-Id: I1ac206e4f6c972b5748552177c787c0adcb66786 Reviewed-on: https://chromium-review.googlesource.com/441308 Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent fe9306a8
......@@ -443,7 +443,7 @@ struct Caps
GLuint64 maxServerWaitTimeout;
// ES 3.1 (April 29, 2015) Table 20.41: Implementation dependent values (cont.)
GLuint maxVertexAttribRelativeOffset;
GLint maxVertexAttribRelativeOffset;
GLuint maxVertexAttribBindings;
GLint maxVertexAttribStride;
GLuint maxElementsIndices;
......
......@@ -1224,8 +1224,12 @@ void GenerateCaps(ID3D11Device *device, ID3D11DeviceContext *deviceContext, cons
static_cast<GLuint>(GetMaximumVertexOutputVectors(featureLevel)) * 4;
caps->maxVertexTextureImageUnits =
static_cast<GLuint>(GetMaximumVertexTextureUnits(featureLevel));
// Vertex Attrib Bindings not supported.
// Vertex Attribute Bindings are emulated on D3D11.
caps->maxVertexAttribBindings = caps->maxVertexAttributes;
// Experimental testing confirmed 2048 is the maximum stride that D3D11 can support on all
// platforms.
caps->maxVertexAttribStride = 2048;
// Fragment shader limits
caps->maxFragmentUniformComponents =
......
......@@ -612,6 +612,90 @@ TEST_P(VertexAttributeTest, DrawArraysWithBufferOffset)
EXPECT_GL_NO_ERROR();
}
class VertexAttributeTestES31 : public VertexAttributeTestES3
{
protected:
VertexAttributeTestES31() {}
void drawArraysWithStrideAndOffset(GLint stride, GLsizeiptr offset)
{
GLint floatStride = stride ? (stride / TypeStride(GL_FLOAT)) : 1;
GLsizeiptr floatOffset = offset / TypeStride(GL_FLOAT);
size_t floatCount = static_cast<size_t>(floatOffset) + mVertexCount * floatStride;
GLsizeiptr inputSize = static_cast<GLsizeiptr>(floatCount) * TypeStride(GL_FLOAT);
initBasicProgram();
glUseProgram(mProgram);
std::vector<GLfloat> inputData(floatCount);
GLfloat expectedData[mVertexCount];
for (size_t count = 0; count < mVertexCount; ++count)
{
inputData[floatOffset + count * floatStride] = static_cast<GLfloat>(count);
expectedData[count] = static_cast<GLfloat>(count);
}
auto quadVertices = GetQuadVertices();
GLsizeiptr quadVerticesSize =
static_cast<GLsizeiptr>(quadVertices.size() * sizeof(quadVertices[0]));
glGenBuffers(1, &mQuadBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mQuadBuffer);
glBufferData(GL_ARRAY_BUFFER, quadVerticesSize, nullptr, GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, quadVerticesSize, quadVertices.data());
GLint positionLocation = glGetAttribLocation(mProgram, "position");
ASSERT_NE(-1, positionLocation);
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(positionLocation);
// Ensure inputSize, inputStride and inputOffset are multiples of TypeStride(GL_FLOAT).
GLsizei inputStride = stride ? floatStride * TypeStride(GL_FLOAT) : 0;
GLsizeiptr inputOffset = floatOffset * TypeStride(GL_FLOAT);
glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
glBufferData(GL_ARRAY_BUFFER, inputSize, nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, inputSize, &inputData[0]);
glVertexAttribPointer(mTestAttrib, 1, GL_FLOAT, GL_FALSE, inputStride,
reinterpret_cast<const GLvoid *>(inputOffset));
glEnableVertexAttribArray(mTestAttrib);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(mExpectedAttrib, 1, GL_FLOAT, GL_FALSE, 0, expectedData);
glEnableVertexAttribArray(mExpectedAttrib);
glDrawArrays(GL_TRIANGLES, 0, 6);
checkPixels();
EXPECT_GL_NO_ERROR();
}
// Set the maximum value for stride if the stride is too large.
const GLint MAX_STRIDE_FOR_TEST = 4095;
};
// Verify that MAX_VERTEX_ATTRIB_STRIDE is no less than the minimum required value (2048) in ES3.1.
TEST_P(VertexAttributeTestES31, MaxVertexAttribStride)
{
GLint maxStride;
glGetIntegerv(GL_MAX_VERTEX_ATTRIB_STRIDE, &maxStride);
ASSERT_GL_NO_ERROR();
EXPECT_GE(maxStride, 2048);
}
// Verify using MAX_VERTEX_ATTRIB_STRIDE as stride doesn't mess up the draw.
// Use default value if the value of MAX_VERTEX_ATTRIB_STRIDE is too large for this test.
TEST_P(VertexAttributeTestES31, DrawArraysWithLargeStride)
{
GLint maxStride;
glGetIntegerv(GL_MAX_VERTEX_ATTRIB_STRIDE, &maxStride);
ASSERT_GL_NO_ERROR();
GLint largeStride = (maxStride < MAX_STRIDE_FOR_TEST) ? maxStride : MAX_STRIDE_FOR_TEST;
drawArraysWithStrideAndOffset(largeStride, 0);
}
class VertexAttributeCachingTest : public VertexAttributeTest
{
protected:
......@@ -885,6 +969,8 @@ ANGLE_INSTANTIATE_TEST(VertexAttributeTest,
ANGLE_INSTANTIATE_TEST(VertexAttributeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
ANGLE_INSTANTIATE_TEST(VertexAttributeTestES31, ES31_D3D11(), ES31_OPENGL(), ES31_OPENGLES());
ANGLE_INSTANTIATE_TEST(VertexAttributeCachingTest,
ES2_D3D9(),
ES2_D3D11(),
......
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