mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Add BlendState validation tests
This commit is contained in:
@@ -27,6 +27,8 @@ class RenderPipelineValidationTest : public ValidationTest {
|
||||
|
||||
inputState = device.CreateInputStateBuilder().GetResult();
|
||||
|
||||
blendState = device.CreateBlendStateBuilder().GetResult();
|
||||
|
||||
vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
@@ -57,6 +59,7 @@ class RenderPipelineValidationTest : public ValidationTest {
|
||||
nxt::ShaderModule vsModule;
|
||||
nxt::ShaderModule fsModule;
|
||||
nxt::InputState inputState;
|
||||
nxt::BlendState blendState;
|
||||
nxt::PipelineLayout pipelineLayout;
|
||||
};
|
||||
|
||||
@@ -64,6 +67,14 @@ class RenderPipelineValidationTest : public ValidationTest {
|
||||
TEST_F(RenderPipelineValidationTest, CreationSuccess) {
|
||||
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
|
||||
.GetResult();
|
||||
|
||||
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
|
||||
.SetInputState(inputState)
|
||||
.GetResult();
|
||||
|
||||
AddDefaultStates(AssertWillBeSuccess(device.CreateRenderPipelineBuilder()))
|
||||
.SetColorAttachmentBlendState(0, blendState)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Test creation failure when properties are missing
|
||||
@@ -99,6 +110,84 @@ TEST_F(RenderPipelineValidationTest, CreationMissingProperty) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(RenderPipelineValidationTest, BlendState) {
|
||||
// Fails because blend state is set on a nonexistent color attachment
|
||||
{
|
||||
auto texture1 = device.CreateTextureBuilder()
|
||||
.SetDimension(nxt::TextureDimension::e2D)
|
||||
.SetExtent(640, 480, 1)
|
||||
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
texture1.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
|
||||
auto textureView1 = texture1.CreateTextureViewBuilder()
|
||||
.GetResult();
|
||||
|
||||
auto texture2 = device.CreateTextureBuilder()
|
||||
.SetDimension(nxt::TextureDimension::e2D)
|
||||
.SetExtent(640, 480, 1)
|
||||
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetMipLevels(1)
|
||||
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
|
||||
.GetResult();
|
||||
texture2.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
|
||||
auto textureView2 = texture2.CreateTextureViewBuilder()
|
||||
.GetResult();
|
||||
|
||||
auto renderpass = device.CreateRenderPassBuilder()
|
||||
.SetAttachmentCount(2)
|
||||
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
|
||||
.AttachmentSetFormat(1, nxt::TextureFormat::R8G8B8A8Unorm)
|
||||
.SetSubpassCount(1)
|
||||
.SubpassSetColorAttachment(0, 0, 0)
|
||||
.GetResult();
|
||||
|
||||
auto framebuffer = device.CreateFramebufferBuilder()
|
||||
.SetRenderPass(renderpass)
|
||||
.SetDimensions(640, 480)
|
||||
.SetAttachment(0, textureView1)
|
||||
.SetAttachment(1, textureView2)
|
||||
.GetResult();
|
||||
|
||||
|
||||
// This one succeeds because attachment 0 is the subpass's color attachment
|
||||
AssertWillBeSuccess(device.CreateRenderPipelineBuilder())
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pipelineLayout)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetPrimitiveTopology(nxt::PrimitiveTopology::TriangleList)
|
||||
.SetColorAttachmentBlendState(0, blendState)
|
||||
.GetResult();
|
||||
|
||||
// This fails because attachment 1 is not one of the subpass's color attachments
|
||||
AssertWillBeError(device.CreateRenderPipelineBuilder())
|
||||
.SetSubpass(renderpass, 0)
|
||||
.SetLayout(pipelineLayout)
|
||||
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
|
||||
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
|
||||
.SetPrimitiveTopology(nxt::PrimitiveTopology::TriangleList)
|
||||
.SetColorAttachmentBlendState(1, blendState)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Fails because color attachment is out of bounds
|
||||
{
|
||||
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
|
||||
.SetColorAttachmentBlendState(1, blendState)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Fails because color attachment blend state is set twice
|
||||
{
|
||||
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
|
||||
.SetColorAttachmentBlendState(0, blendState)
|
||||
.SetColorAttachmentBlendState(0, blendState)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(enga@google.com): These should be added to the test above when validation is implemented
|
||||
TEST_F(RenderPipelineValidationTest, DISABLED_TodoCreationMissingProperty) {
|
||||
// Fails because pipeline layout is not set
|
||||
@@ -158,4 +247,11 @@ TEST_F(RenderPipelineValidationTest, DISABLED_CreationDuplicates) {
|
||||
.SetSubpass(renderpass, 0)
|
||||
.GetResult();
|
||||
}
|
||||
|
||||
// Fails because the layout is set twice
|
||||
{
|
||||
AddDefaultStates(AssertWillBeError(device.CreateRenderPipelineBuilder()))
|
||||
.SetLayout(pipelineLayout)
|
||||
.GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user