Clamp viewport dimensions on store

Bug: angleproject:7486
Bug: chromium:1130759
Change-Id: I6131baacc940b5df7e33ba10fca8e6e148cb8670
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3751056
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
This commit is contained in:
Alexey Knyazev 2022-07-07 00:00:00 +00:00 коммит произвёл Angle LUCI CQ
Родитель fb3e2def8e
Коммит 925ec6b5ac
2 изменённых файлов: 57 добавлений и 0 удалений

Просмотреть файл

@ -1608,6 +1608,11 @@ void State::setFragmentShaderDerivativeHint(GLenum hint)
void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
{
// [OpenGL ES 2.0.25] section 2.12.1 page 45:
// Viewport width and height are clamped to implementation-dependent maximums when specified.
width = std::min(width, mCaps.maxViewportWidth);
height = std::min(height, mCaps.maxViewportHeight);
// Skip if same viewport info
if (mViewport.x != x || mViewport.y != y || mViewport.width != width ||
mViewport.height != height)

Просмотреть файл

@ -382,6 +382,56 @@ TEST_P(ViewportTest, Overflow)
}
}
// Test that viewport dimensions are clamped to implementation-defined maximums
TEST_P(ViewportTest, ClampOnStore)
{
GLint maxDims[2];
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, maxDims);
ASSERT_GT(maxDims[0], 0);
ASSERT_GT(maxDims[1], 0);
GLint viewport[4];
glViewport(0, 0, 1, 1);
ASSERT_GL_NO_ERROR();
glGetIntegerv(GL_VIEWPORT, viewport);
ASSERT_EQ(viewport[0], 0);
ASSERT_EQ(viewport[1], 0);
ASSERT_EQ(viewport[2], 1);
ASSERT_EQ(viewport[3], 1);
glViewport(0, 0, -2, 2);
ASSERT_GL_ERROR(GL_INVALID_VALUE);
glGetIntegerv(GL_VIEWPORT, viewport);
ASSERT_EQ(viewport[0], 0);
ASSERT_EQ(viewport[1], 0);
ASSERT_EQ(viewport[2], 1);
ASSERT_EQ(viewport[3], 1);
glViewport(0, 0, 3, -3);
ASSERT_GL_ERROR(GL_INVALID_VALUE);
glGetIntegerv(GL_VIEWPORT, viewport);
ASSERT_EQ(viewport[0], 0);
ASSERT_EQ(viewport[1], 0);
ASSERT_EQ(viewport[2], 1);
ASSERT_EQ(viewport[3], 1);
glViewport(0, 0, maxDims[0], maxDims[1]);
ASSERT_GL_NO_ERROR();
glGetIntegerv(GL_VIEWPORT, viewport);
ASSERT_EQ(viewport[0], 0);
ASSERT_EQ(viewport[1], 0);
ASSERT_EQ(viewport[2], maxDims[0]);
ASSERT_EQ(viewport[3], maxDims[1]);
glViewport(0, 0, maxDims[0] + 1, maxDims[1] + 1);
ASSERT_GL_NO_ERROR();
glGetIntegerv(GL_VIEWPORT, viewport);
ASSERT_EQ(viewport[0], 0);
ASSERT_EQ(viewport[1], 0);
ASSERT_EQ(viewport[2], maxDims[0]);
ASSERT_EQ(viewport[3], maxDims[1]);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against. D3D11 Feature Level 9 and D3D9 emulate large and negative viewports
// in the vertex shader. We should test both of these as well as D3D11 Feature Level 10_0+.
@ -391,6 +441,8 @@ ANGLE_INSTANTIATE_TEST(ViewportTest,
ES2_D3D11_PRESENT_PATH_FAST(),
ES2_OPENGLES(),
ES3_OPENGLES(),
ES2_METAL(),
ES2_OPENGL(),
ES2_VULKAN());
// This test suite is not instantiated on some OSes.