Simplify PersistentPipelineState and application of stencil states. Fix

stencil mask usage. D3D12 does not support separate front/back masks.
All APIs support separate read/write masks.
This commit is contained in:
Austin Eng
2017-06-02 14:31:53 -04:00
committed by Corentin Wallez
parent 5a67d196be
commit 58c76b3fe4
18 changed files with 318 additions and 374 deletions

View File

@@ -17,66 +17,79 @@
class DepthStencilStateValidationTest : public ValidationTest {
};
TEST_F(DepthStencilStateValidationTest, Creation) {
// Success
nxt::DepthStencilState buf0 = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.SetDepthCompareFunction(nxt::CompareFunction::Less)
.SetDepthWriteEnabled(true)
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Greater,
nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
.SetStencilMask(nxt::Face::Both, 0x1)
.GetResult();
TEST_F(DepthStencilStateValidationTest, CreationSuccess) {
// Success for setting all properties
{
nxt::DepthStencilState ds = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.SetDepthCompareFunction(nxt::CompareFunction::Less)
.SetDepthWriteEnabled(true)
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Greater,
nxt::StencilOperation::Keep, nxt::StencilOperation::Keep, nxt::StencilOperation::Replace)
.SetStencilMask(0x0, 0x1)
.GetResult();
}
// Success for empty builder
nxt::DepthStencilState buf1 = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.GetResult();
{
nxt::DepthStencilState ds = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.GetResult();
}
// Test failure when specifying properties multiple times
nxt::DepthStencilState buf2 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetDepthWriteEnabled(true)
.SetDepthWriteEnabled(false)
.GetResult();
nxt::DepthStencilState buf3 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetDepthCompareFunction(nxt::CompareFunction::Less)
.SetDepthCompareFunction(nxt::CompareFunction::Greater)
.GetResult();
// Test success when setting properties on separate faces
nxt::DepthStencilState buf4 = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.SetStencilMask(nxt::Face::Front, 0x00)
.SetStencilMask(nxt::Face::Back, 0xff)
.GetResult();
nxt::DepthStencilState buf5 = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Front, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
// Test failure when setting properties on a face multiple times
nxt::DepthStencilState buf6 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilMask(nxt::Face::Back, 0x00)
.SetStencilMask(nxt::Face::Back, 0xff)
.GetResult();
nxt::DepthStencilState buf7 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
nxt::DepthStencilState buf8 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilMask(nxt::Face::Both, 0x00)
.SetStencilMask(nxt::Face::Back, 0xff)
.GetResult();
nxt::DepthStencilState buf9 = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
// Test success when setting stencil function on separate faces
{
nxt::DepthStencilState ds = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Front, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
}
}
TEST_F(DepthStencilStateValidationTest, CreationDuplicates) {
// Test failure when specifying depth write enabled multiple times
{
nxt::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetDepthWriteEnabled(true)
.SetDepthWriteEnabled(false)
.GetResult();
}
// Test failure when specifying depth compare function multiple times
{
nxt::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetDepthCompareFunction(nxt::CompareFunction::Less)
.SetDepthCompareFunction(nxt::CompareFunction::Greater)
.GetResult();
}
// Test failure when setting stencil mask multiple times
{
nxt::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilMask(0x00, 0x00)
.SetStencilMask(0xff, 0xff)
.GetResult();
}
// Test failure when directly setting stencil function on a face multiple times
{
nxt::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
}
// Test failure when indirectly setting stencil function on a face multiple times
{
nxt::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
.SetStencilFunction(nxt::Face::Both, nxt::CompareFunction::Less,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.SetStencilFunction(nxt::Face::Back, nxt::CompareFunction::Greater,
nxt::StencilOperation::Replace, nxt::StencilOperation::Replace, nxt::StencilOperation::Replace)
.GetResult();
}
}
// TODO(enga@google.com) Test failure when set in a compute pipeline