Commit 00155d58 by Luc Ferron Committed by Commit Bot

Vulkan: Implement scissor test and add a simple test for it

Bug: angleproject:2338 Change-Id: I699189fcd41feca1656c8553fdf4c1078421524d Reviewed-on: https://chromium-review.googlesource.com/904861 Commit-Queue: Luc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b9d1daa0
...@@ -416,14 +416,34 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits ...@@ -416,14 +416,34 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits
switch (dirtyBit) switch (dirtyBit)
{ {
case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED:
WARN() << "DIRTY_BIT_SCISSOR_TEST_ENABLED unimplemented"; if (glState.isScissorTestEnabled())
{
mPipelineDesc->updateScissor(glState.getScissor());
}
else
{
mPipelineDesc->updateScissor(glState.getViewport());
}
break; break;
case gl::State::DIRTY_BIT_SCISSOR: case gl::State::DIRTY_BIT_SCISSOR:
WARN() << "DIRTY_BIT_SCISSOR unimplemented"; // Only modify the scissor region if the test is enabled, otherwise we want to keep
// the viewport size as the scissor region.
if (glState.isScissorTestEnabled())
{
mPipelineDesc->updateScissor(glState.getScissor());
}
break; break;
case gl::State::DIRTY_BIT_VIEWPORT: case gl::State::DIRTY_BIT_VIEWPORT:
mPipelineDesc->updateViewport(glState.getViewport(), glState.getNearPlane(), mPipelineDesc->updateViewport(glState.getViewport(), glState.getNearPlane(),
glState.getFarPlane()); glState.getFarPlane());
// If the scissor test isn't enabled, we have to also update the scissor to
// be equal to the viewport to make sure we keep rendering everything in the
// viewport.
if (!glState.isScissorTestEnabled())
{
mPipelineDesc->updateScissor(glState.getViewport());
}
break; break;
case gl::State::DIRTY_BIT_DEPTH_RANGE: case gl::State::DIRTY_BIT_DEPTH_RANGE:
WARN() << "DIRTY_BIT_DEPTH_RANGE unimplemented"; WARN() << "DIRTY_BIT_DEPTH_RANGE unimplemented";
......
...@@ -607,6 +607,12 @@ void PipelineDesc::updateRenderPassDesc(const RenderPassDesc &renderPassDesc) ...@@ -607,6 +607,12 @@ void PipelineDesc::updateRenderPassDesc(const RenderPassDesc &renderPassDesc)
mRenderPassDesc = renderPassDesc; mRenderPassDesc = renderPassDesc;
} }
void PipelineDesc::updateScissor(const gl::Rectangle &rect)
{
mScissor = {{rect.x, rect.y},
{static_cast<uint32_t>(rect.width), static_cast<uint32_t>(rect.height)}};
}
// AttachmentOpsArray implementation. // AttachmentOpsArray implementation.
AttachmentOpsArray::AttachmentOpsArray() AttachmentOpsArray::AttachmentOpsArray()
{ {
......
...@@ -287,6 +287,9 @@ class PipelineDesc final ...@@ -287,6 +287,9 @@ class PipelineDesc final
const RenderPassDesc &getRenderPassDesc() const; const RenderPassDesc &getRenderPassDesc() const;
void updateRenderPassDesc(const RenderPassDesc &renderPassDesc); void updateRenderPassDesc(const RenderPassDesc &renderPassDesc);
// Scissor support
void updateScissor(const gl::Rectangle &rect);
private: private:
// TODO(jmadill): Handle Geometry/Compute shaders when necessary. // TODO(jmadill): Handle Geometry/Compute shaders when necessary.
ShaderStageInfo mShaderStageInfo; ShaderStageInfo mShaderStageInfo;
......
...@@ -104,6 +104,28 @@ TEST_P(SimpleOperationTest, ClearAndSwap) ...@@ -104,6 +104,28 @@ TEST_P(SimpleOperationTest, ClearAndSwap)
EXPECT_EGL_SUCCESS(); EXPECT_EGL_SUCCESS();
} }
// Simple case of setting a scissor, enabled or disabled.
TEST_P(SimpleOperationTest, ScissorTest)
{
ANGLE_GL_PROGRAM(program, kBasicVertexShader, kGreenFragmentShader);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(getWindowWidth() / 4, getWindowHeight() / 4, getWindowWidth() / 2,
getWindowHeight() / 2);
// Fill the whole screen with a quad.
drawQuad(program.get(), "position", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
// Test outside the scissor test, pitch black.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack);
// Test inside, green of the fragment shader.
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::green);
}
TEST_P(SimpleOperationTest, LinkProgramShadersNoInputs) TEST_P(SimpleOperationTest, LinkProgramShadersNoInputs)
{ {
const std::string vsSource = const std::string vsSource =
......
...@@ -1067,6 +1067,64 @@ TEST_P(SimpleStateChangeTest, RedefineFramebufferInUse) ...@@ -1067,6 +1067,64 @@ TEST_P(SimpleStateChangeTest, RedefineFramebufferInUse)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
TEST_P(SimpleStateChangeTest, ScissorTest)
{
// This test validates this order of state changes:
// 1- Set scissor but don't enable it, validate its not used.
// 2- Enable it and validate its working.
// 3- Disable the scissor validate its not used anymore.
ANGLE_GL_PROGRAM(program, kSolidColorVertexShader, kSolidColorFragmentShader);
glClear(GL_COLOR_BUFFER_BIT);
// Set the scissor region, but don't enable it yet.
glScissor(getWindowWidth() / 4, getWindowHeight() / 4, getWindowWidth() / 2,
getWindowHeight() / 2);
// Fill the whole screen with a quad.
drawQuad(program.get(), "position", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
// Test outside, scissor isnt enabled so its red.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Test inside, red of the fragment shader.
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
// Clear everything and start over with the test enabled.
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
drawQuad(program.get(), "position", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
// Test outside the scissor test, pitch black.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::transparentBlack);
// Test inside, red of the fragment shader.
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
// Now disable the scissor test, do it again, and verify the region isn't used
// for the scissor test.
glDisable(GL_SCISSOR_TEST);
// Clear everything and start over with the test enabled.
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(program.get(), "position", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
// Test outside, scissor isnt enabled so its red.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
// Test inside, red of the fragment shader.
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::red);
}
} // anonymous namespace } // anonymous namespace
ANGLE_INSTANTIATE_TEST(StateChangeTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL()); ANGLE_INSTANTIATE_TEST(StateChangeTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL());
......
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