Commit 1c7f0284 by Alexey Knyazev Committed by Commit Bot

Vulkan: Fix invalid clamping of ES3 clear stencil values

Added 3 new end2end tests Bug: angleproject:5202 Change-Id: I95f9ffd989105f5bd3283676d6fa46e904503369 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2488481Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
parent d7475437
...@@ -637,9 +637,8 @@ angle::Result FramebufferVk::clearBufferiv(const gl::Context *context, ...@@ -637,9 +637,8 @@ angle::Result FramebufferVk::clearBufferiv(const gl::Context *context,
if (buffer == GL_STENCIL) if (buffer == GL_STENCIL)
{ {
clearStencil = true; clearStencil = true;
clearValue.depthStencil.stencil = clearValue.depthStencil.stencil = static_cast<uint8_t>(values[0]);
gl::clamp(values[0], 0, std::numeric_limits<uint8_t>::max());
} }
else else
{ {
...@@ -663,7 +662,7 @@ angle::Result FramebufferVk::clearBufferfi(const gl::Context *context, ...@@ -663,7 +662,7 @@ angle::Result FramebufferVk::clearBufferfi(const gl::Context *context,
VkClearValue clearValue = {}; VkClearValue clearValue = {};
clearValue.depthStencil.depth = depth; clearValue.depthStencil.depth = depth;
clearValue.depthStencil.stencil = gl::clamp(stencil, 0, std::numeric_limits<uint8_t>::max()); clearValue.depthStencil.stencil = static_cast<uint8_t>(stencil);
return clearImpl(context, gl::DrawBufferMask(), true, true, clearValue.color, return clearImpl(context, gl::DrawBufferMask(), true, true, clearValue.color,
clearValue.depthStencil); clearValue.depthStencil);
......
...@@ -1972,6 +1972,107 @@ TEST_P(ClearTestES3, ClearThenMixedMaskedClear) ...@@ -1972,6 +1972,107 @@ TEST_P(ClearTestES3, ClearThenMixedMaskedClear)
EXPECT_PIXEL_COLOR_NEAR(kSize - 1, kSize - 1, kExpected, 1); EXPECT_PIXEL_COLOR_NEAR(kSize - 1, kSize - 1, kExpected, 1);
} }
// Test that clear stencil value is correctly masked to 8 bits.
TEST_P(ClearTest, ClearStencilMask)
{
GLint stencilBits = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
EXPECT_EQ(stencilBits, 8);
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
glUseProgram(drawColor);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Clear stencil value must be masked to 0x42
glClearStencil(0x142);
glClear(GL_STENCIL_BUFFER_BIT);
// Check that the stencil test works as expected
glEnable(GL_STENCIL_TEST);
// Negative case
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Positive case
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
}
// Test that glClearBufferiv correctly masks the clear stencil value.
TEST_P(ClearTestES3, ClearBufferivStencilMask)
{
GLint stencilBits = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
EXPECT_EQ(stencilBits, 8);
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
glUseProgram(drawColor);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Clear stencil value must be masked to 0x42
const GLint kStencilClearValue = 0x142;
glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
// Check that the stencil test works as expected
glEnable(GL_STENCIL_TEST);
// Negative case
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Positive case
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
}
// Test that glClearBufferfi correctly masks the clear stencil value.
TEST_P(ClearTestES3, ClearBufferfiStencilMask)
{
GLint stencilBits = 0;
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
EXPECT_EQ(stencilBits, 8);
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
glUseProgram(drawColor);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Clear stencil value must be masked to 0x42
glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x142);
// Check that the stencil test works as expected
glEnable(GL_STENCIL_TEST);
// Negative case
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
// Positive case
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
}
#ifdef Bool #ifdef Bool
// X11 craziness. // X11 craziness.
# undef Bool # undef Bool
......
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