mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Replace DepthStencilState builder via DepthStencilState descriptor.
This change also removes DepthStencilState object. Bug=dawn:31 Change-Id: I7bb54ef4da527184bb2726c77d93d411d44c3956 Reviewed-on: https://dawn-review.googlesource.com/c/3541 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
0b364067d0
commit
ea56333c1e
@@ -110,7 +110,7 @@ class DepthStencilStateTest : public DawnTest {
|
||||
}
|
||||
|
||||
struct TestSpec {
|
||||
const dawn::DepthStencilState& depthStencilState;
|
||||
const dawn::DepthStencilStateDescriptor& depthStencilState;
|
||||
RGBA8 color;
|
||||
float depth;
|
||||
uint32_t stencil;
|
||||
@@ -119,15 +119,27 @@ class DepthStencilStateTest : public DawnTest {
|
||||
// Check whether a depth comparison function works as expected
|
||||
// The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function
|
||||
void CheckDepthCompareFunction(dawn::CompareFunction compareFunction, bool less, bool equal, bool greater) {
|
||||
dawn::DepthStencilState baseState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Always)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
dawn::StencilStateFaceDescriptor stencilFace;
|
||||
stencilFace.compare = dawn::CompareFunction::Always;
|
||||
stencilFace.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.passOp = dawn::StencilOperation::Keep;
|
||||
|
||||
dawn::DepthStencilState state = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(compareFunction)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = true;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = stencilFace;
|
||||
baseState.front = stencilFace;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = true;
|
||||
state.depthCompare = compareFunction;
|
||||
state.back = stencilFace;
|
||||
state.front = stencilFace;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
|
||||
RGBA8 lessColor = RGBA8(255, 0, 0, 255);
|
||||
@@ -155,20 +167,26 @@ class DepthStencilStateTest : public DawnTest {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = false;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = compareFunction;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
|
||||
RGBA8 lessColor = RGBA8(255, 0, 0, 255);
|
||||
@@ -195,20 +213,26 @@ class DepthStencilStateTest : public DawnTest {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = false;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Always;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = stencilOperation;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
CheckStencil({
|
||||
// Wipe the stencil buffer with the initialStencil value
|
||||
@@ -226,10 +250,13 @@ class DepthStencilStateTest : public DawnTest {
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
testParams.push_back({ state, RGBA8(0, 255, 0, 255), 0, expectedStencil });
|
||||
DoTest(testParams, RGBA8(0, 255, 0, 255));
|
||||
@@ -268,7 +295,7 @@ class DepthStencilStateTest : public DawnTest {
|
||||
descriptor.cFragmentStage.module = fsModule;
|
||||
descriptor.cAttachmentsState.hasDepthStencilAttachment = true;
|
||||
descriptor.cDepthStencilAttachment.format = dawn::TextureFormat::D32FloatS8Uint;
|
||||
descriptor.depthStencilState = test.depthStencilState;
|
||||
descriptor.depthStencilState = &test.depthStencilState;
|
||||
|
||||
dawn::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
|
||||
|
||||
@@ -303,8 +330,19 @@ class DepthStencilStateTest : public DawnTest {
|
||||
|
||||
// Test compilation and usage of the fixture
|
||||
TEST_P(DepthStencilStateTest, Basic) {
|
||||
dawn::DepthStencilState state = device.CreateDepthStencilStateBuilder()
|
||||
.GetResult();
|
||||
dawn::StencilStateFaceDescriptor stencilFace;
|
||||
stencilFace.compare = dawn::CompareFunction::Always;
|
||||
stencilFace.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.passOp = dawn::StencilOperation::Keep;
|
||||
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFace;
|
||||
state.front = stencilFace;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
DoTest({
|
||||
{ state, RGBA8(0, 255, 0, 255), 0.5f, 0u },
|
||||
@@ -313,8 +351,19 @@ TEST_P(DepthStencilStateTest, Basic) {
|
||||
|
||||
// Test defaults: depth and stencil tests disabled
|
||||
TEST_P(DepthStencilStateTest, DepthStencilDisabled) {
|
||||
dawn::DepthStencilState state = device.CreateDepthStencilStateBuilder()
|
||||
.GetResult();
|
||||
dawn::StencilStateFaceDescriptor stencilFace;
|
||||
stencilFace.compare = dawn::CompareFunction::Always;
|
||||
stencilFace.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.passOp = dawn::StencilOperation::Keep;
|
||||
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFace;
|
||||
state.front = stencilFace;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
TestSpec specs[3] = {
|
||||
{ state, RGBA8(255, 0, 0, 255), 0.0f, 0u },
|
||||
@@ -367,19 +416,35 @@ TEST_P(DepthStencilStateTest, DepthNotEqual) {
|
||||
|
||||
// Test that disabling depth writes works and leaves the depth buffer unchanged
|
||||
TEST_P(DepthStencilStateTest, DepthWriteDisabled) {
|
||||
dawn::DepthStencilState baseState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Always)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
dawn::StencilStateFaceDescriptor stencilFace;
|
||||
stencilFace.compare = dawn::CompareFunction::Always;
|
||||
stencilFace.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFace.passOp = dawn::StencilOperation::Keep;
|
||||
|
||||
dawn::DepthStencilState noDepthWrite = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Always)
|
||||
.SetDepthWriteEnabled(false)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = true;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = stencilFace;
|
||||
baseState.front = stencilFace;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::DepthStencilState checkState = device.CreateDepthStencilStateBuilder()
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Equal)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor noDepthWrite;
|
||||
noDepthWrite.depthWriteEnabled = false;
|
||||
noDepthWrite.depthCompare = dawn::CompareFunction::Always;
|
||||
noDepthWrite.back = stencilFace;
|
||||
noDepthWrite.front = stencilFace;
|
||||
noDepthWrite.stencilReadMask = 0xff;
|
||||
noDepthWrite.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::DepthStencilStateDescriptor checkState;
|
||||
checkState.depthWriteEnabled = false;
|
||||
checkState.depthCompare = dawn::CompareFunction::Equal;
|
||||
checkState.back = stencilFace;
|
||||
checkState.front = stencilFace;
|
||||
checkState.stencilReadMask = 0xff;
|
||||
checkState.stencilWriteMask = 0xff;
|
||||
|
||||
DoTest({
|
||||
{ baseState, RGBA8(255, 255, 255, 255), 1.f, 0u }, // Draw a base triangle with depth enabled
|
||||
@@ -465,21 +530,26 @@ TEST_P(DepthStencilStateTest, StencilReadMask) {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = false;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Equal;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.SetStencilMask(0x2, 0xff)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0x2;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
|
||||
RGBA8 red = RGBA8(255, 0, 0, 255);
|
||||
@@ -497,21 +567,26 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.SetStencilMask(0xff, 0x1)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = false;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0x1;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Equal;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
|
||||
RGBA8 green = RGBA8(0, 255, 0, 255);
|
||||
@@ -528,20 +603,26 @@ TEST_P(DepthStencilStateTest, StencilFail) {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = false;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Less;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = false;
|
||||
state.depthCompare = dawn::CompareFunction::Always;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
CheckStencil({
|
||||
{ baseState, RGBA8(255, 255, 255, 255), 1.f, 1 }, // Triangle to set stencil value to 1
|
||||
@@ -556,23 +637,26 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = true;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Greater;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Keep;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = true;
|
||||
state.depthCompare = dawn::CompareFunction::Less;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
CheckStencil({
|
||||
{ baseState, RGBA8(255, 255, 255, 255), 0.f, 1 }, // Triangle to set stencil value to 1. Depth is 0
|
||||
@@ -587,23 +671,26 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) {
|
||||
baseStencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
baseStencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState baseState =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &baseStencilFaceDescriptor)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor baseState;
|
||||
baseState.depthWriteEnabled = true;
|
||||
baseState.depthCompare = dawn::CompareFunction::Always;
|
||||
baseState.back = baseStencilFaceDescriptor;
|
||||
baseState.front = baseStencilFaceDescriptor;
|
||||
baseState.stencilReadMask = 0xff;
|
||||
baseState.stencilWriteMask = 0xff;
|
||||
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Greater;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState state =
|
||||
device.CreateDepthStencilStateBuilder()
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.GetResult();
|
||||
dawn::DepthStencilStateDescriptor state;
|
||||
state.depthWriteEnabled = true;
|
||||
state.depthCompare = dawn::CompareFunction::Less;
|
||||
state.back = stencilFaceDescriptor;
|
||||
state.front = stencilFaceDescriptor;
|
||||
state.stencilReadMask = 0xff;
|
||||
state.stencilWriteMask = 0xff;
|
||||
|
||||
CheckStencil({
|
||||
{ baseState, RGBA8(255, 255, 255, 255), 1.f, 1 }, // Triangle to set stencil value to 1. Depth is 0
|
||||
|
||||
@@ -350,15 +350,20 @@ TEST_F(WireTests, CStringArgument) {
|
||||
.WillOnce(Return(apiInputState));
|
||||
|
||||
// Create the depth-stencil state
|
||||
dawnDepthStencilStateBuilder depthStencilStateBuilder = dawnDeviceCreateDepthStencilStateBuilder(device);
|
||||
dawnDepthStencilStateBuilder apiDepthStencilStateBuilder = api.GetNewDepthStencilStateBuilder();
|
||||
EXPECT_CALL(api, DeviceCreateDepthStencilStateBuilder(apiDevice))
|
||||
.WillOnce(Return(apiDepthStencilStateBuilder));
|
||||
dawnStencilStateFaceDescriptor stencilFace;
|
||||
stencilFace.compare = DAWN_COMPARE_FUNCTION_ALWAYS;
|
||||
stencilFace.stencilFailOp = DAWN_STENCIL_OPERATION_KEEP;
|
||||
stencilFace.depthFailOp = DAWN_STENCIL_OPERATION_KEEP;
|
||||
stencilFace.passOp = DAWN_STENCIL_OPERATION_KEEP;
|
||||
|
||||
dawnDepthStencilState depthStencilState = dawnDepthStencilStateBuilderGetResult(depthStencilStateBuilder);
|
||||
dawnDepthStencilState apiDepthStencilState = api.GetNewDepthStencilState();
|
||||
EXPECT_CALL(api, DepthStencilStateBuilderGetResult(apiDepthStencilStateBuilder))
|
||||
.WillOnce(Return(apiDepthStencilState));
|
||||
dawnDepthStencilStateDescriptor depthStencilState;
|
||||
depthStencilState.nextInChain = nullptr;
|
||||
depthStencilState.depthWriteEnabled = false;
|
||||
depthStencilState.depthCompare = DAWN_COMPARE_FUNCTION_ALWAYS;
|
||||
depthStencilState.back = stencilFace;
|
||||
depthStencilState.front = stencilFace;
|
||||
depthStencilState.stencilReadMask = 0xff;
|
||||
depthStencilState.stencilWriteMask = 0xff;
|
||||
|
||||
// Create the pipeline layout
|
||||
dawnPipelineLayoutDescriptor layoutDescriptor;
|
||||
@@ -405,7 +410,7 @@ TEST_F(WireTests, CStringArgument) {
|
||||
pipelineDescriptor.inputState = inputState;
|
||||
pipelineDescriptor.indexFormat = DAWN_INDEX_FORMAT_UINT32;
|
||||
pipelineDescriptor.primitiveTopology = DAWN_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||
pipelineDescriptor.depthStencilState = depthStencilState;
|
||||
pipelineDescriptor.depthStencilState = &depthStencilState;
|
||||
|
||||
dawnDeviceCreateRenderPipeline(device, &pipelineDescriptor);
|
||||
EXPECT_CALL(api, DeviceCreateRenderPipeline(apiDevice, MatchesLambda([](const dawnRenderPipelineDescriptor* desc) -> bool {
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
// Copyright 2017 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
class DepthStencilStateValidationTest : public ValidationTest {
|
||||
};
|
||||
|
||||
// Test cases where creation should succeed
|
||||
TEST_F(DepthStencilStateValidationTest, CreationSuccess) {
|
||||
// Success for setting all properties
|
||||
{
|
||||
dawn::StencilStateFaceDescriptor stencilFaceDescriptor;
|
||||
stencilFaceDescriptor.compare = dawn::CompareFunction::Greater;
|
||||
stencilFaceDescriptor.stencilFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.depthFailOp = dawn::StencilOperation::Keep;
|
||||
stencilFaceDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState ds =
|
||||
AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.SetDepthWriteEnabled(true)
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilFaceDescriptor)
|
||||
.SetStencilMask(0x0, 0x1)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Success for empty builder
|
||||
{
|
||||
dawn::DepthStencilState ds = AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test success when setting stencil function on separate faces
|
||||
{
|
||||
dawn::StencilStateFaceDescriptor stencilFrontDescriptor;
|
||||
stencilFrontDescriptor.compare = dawn::CompareFunction::Less;
|
||||
stencilFrontDescriptor.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilFrontDescriptor.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilFrontDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::StencilStateFaceDescriptor stencilBackDescriptor;
|
||||
stencilBackDescriptor.compare = dawn::CompareFunction::Greater;
|
||||
stencilBackDescriptor.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState ds =
|
||||
AssertWillBeSuccess(device.CreateDepthStencilStateBuilder())
|
||||
.SetStencilFunction(dawn::Face::Front, &stencilFrontDescriptor)
|
||||
.SetStencilFunction(dawn::Face::Back, &stencilBackDescriptor)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
// Test creation failure when specifying properties multiple times
|
||||
TEST_F(DepthStencilStateValidationTest, CreationDuplicates) {
|
||||
// Test failure when specifying depth write enabled multiple times
|
||||
{
|
||||
dawn::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
|
||||
.SetDepthWriteEnabled(true)
|
||||
.SetDepthWriteEnabled(false)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test failure when specifying depth compare function multiple times
|
||||
{
|
||||
dawn::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Less)
|
||||
.SetDepthCompareFunction(dawn::CompareFunction::Greater)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test failure when setting stencil mask multiple times
|
||||
{
|
||||
dawn::DepthStencilState ds = AssertWillBeError(device.CreateDepthStencilStateBuilder())
|
||||
.SetStencilMask(0x00, 0x00)
|
||||
.SetStencilMask(0xff, 0xff)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test failure when directly setting stencil function on a face multiple times
|
||||
{
|
||||
dawn::StencilStateFaceDescriptor stencilBackDescriptor1;
|
||||
stencilBackDescriptor1.compare = dawn::CompareFunction::Less;
|
||||
stencilBackDescriptor1.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor1.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor1.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::StencilStateFaceDescriptor stencilBackDescriptor2;
|
||||
stencilBackDescriptor2.compare = dawn::CompareFunction::Greater;
|
||||
stencilBackDescriptor2.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor2.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor2.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState ds =
|
||||
AssertWillBeError(device.CreateDepthStencilStateBuilder())
|
||||
.SetStencilFunction(dawn::Face::Back, &stencilBackDescriptor1)
|
||||
.SetStencilFunction(dawn::Face::Back, &stencilBackDescriptor2)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test failure when indirectly setting stencil function on a face multiple times
|
||||
{
|
||||
dawn::StencilStateFaceDescriptor stencilBothDescriptor;
|
||||
stencilBothDescriptor.compare = dawn::CompareFunction::Less;
|
||||
stencilBothDescriptor.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBothDescriptor.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBothDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::StencilStateFaceDescriptor stencilBackDescriptor;
|
||||
stencilBackDescriptor.compare = dawn::CompareFunction::Greater;
|
||||
stencilBackDescriptor.stencilFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor.depthFailOp = dawn::StencilOperation::Replace;
|
||||
stencilBackDescriptor.passOp = dawn::StencilOperation::Replace;
|
||||
dawn::DepthStencilState ds =
|
||||
AssertWillBeError(device.CreateDepthStencilStateBuilder())
|
||||
.SetStencilFunction(dawn::Face::Both, &stencilBothDescriptor)
|
||||
.SetStencilFunction(dawn::Face::Back, &stencilBackDescriptor)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user