Add tests for clears, render passes, framebuffers (#107)

* Add tests for clears, render passes, framebuffers

* Test load with a draw in it
This commit is contained in:
Kai Ninomiya
2017-08-14 16:32:26 -07:00
committed by GitHub
parent 37d11539a4
commit afa45a9176
9 changed files with 437 additions and 13 deletions

View File

@@ -29,6 +29,21 @@ class FramebufferValidationTest : public ValidationTest {
return attachment.CreateTextureViewBuilder()
.GetResult();
}
nxt::Framebuffer CreateFramebufferWithAttachment(uint32_t width, uint32_t height, nxt::TextureFormat format) {
auto renderpass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetAttachmentCount(1)
.AttachmentSetFormat(0, format)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
nxt::TextureView attachment = Create2DAttachment(width, height, format);
return AssertWillBeSuccess(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetAttachment(0, attachment)
.SetDimensions(100, 100)
.GetResult();
}
};
// Test for an empty framebuffer builder
@@ -73,12 +88,29 @@ TEST_F(FramebufferValidationTest, BasicWithEmptyAttachment) {
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
auto framebuffer = AssertWillBeSuccess(device.CreateFramebufferBuilder())
AssertWillBeError(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetDimensions(100, 100)
.GetResult();
}
// Test for a basic framebuffer with one attachment
TEST_F(FramebufferValidationTest, BasicWithOneAttachment) {
CreateFramebufferWithAttachment(100, 100, nxt::TextureFormat::R8G8B8A8Unorm);
}
// Tests for setting clear values
TEST_F(FramebufferValidationTest, ClearValues) {
auto framebuffer = CreateFramebufferWithAttachment(100, 100, nxt::TextureFormat::R8G8B8A8Unorm);
// Set clear color value for attachment 0
framebuffer.AttachmentSetClearColor(0, 0.0f, 0.0f, 0.0f, 0.0f);
// Set clear depth/stencil values for attachment 0 - ok, but ignored, since it's a color attachment
framebuffer.AttachmentSetClearDepthStencil(0, 0.0f, 0);
// Set clear color value for attachment 1 - should fail
ASSERT_DEVICE_ERROR(framebuffer.AttachmentSetClearColor(1, 0.0f, 0.0f, 0.0f, 0.0f));
}
// Check validation that the attachment size must be the same as the framebuffer size.
// TODO(cwallez@chromium.org): Investigate this constraint more, for example Vulkan requires
// that the attachment sizes are *at least* the framebuffer size.
@@ -121,3 +153,75 @@ TEST_F(FramebufferValidationTest, AttachmentSizeMatchFramebufferSize) {
// TODO(cwallez@chromium.org): also test with a mismatches depth / stencil
}
TEST_F(FramebufferValidationTest, AttachmentFormatMatchTextureFormat) {
// Control case: attach color attachment to color slot
{
auto renderpass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
nxt::TextureView attachment = Create2DAttachment(100, 100, nxt::TextureFormat::R8G8B8A8Unorm);
auto framebuffer = AssertWillBeSuccess(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetAttachment(0, attachment)
.SetDimensions(100, 100)
.GetResult();
}
// Error: attach color attachment to depth slot, setting the attachment format first
{
auto renderpass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetAttachmentCount(1)
.SetSubpassCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::D32FloatS8Uint)
.SubpassSetDepthStencilAttachment(0, 0)
.GetResult();
nxt::TextureView attachment = Create2DAttachment(100, 100, nxt::TextureFormat::R8G8B8A8Unorm);
auto framebuffer = AssertWillBeError(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetAttachment(0, attachment)
.SetDimensions(100, 100)
.GetResult();
}
// Error: attach color attachment to depth slot, but setting the attachment format last
{
auto renderpass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.SubpassSetDepthStencilAttachment(0, 0)
.AttachmentSetFormat(0, nxt::TextureFormat::D32FloatS8Uint)
.GetResult();
nxt::TextureView attachment = Create2DAttachment(100, 100, nxt::TextureFormat::R8G8B8A8Unorm);
auto framebuffer = AssertWillBeError(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetAttachment(0, attachment)
.SetDimensions(100, 100)
.GetResult();
}
// Error: attach depth texture to color slot
{
auto renderpass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
nxt::TextureView attachment = Create2DAttachment(100, 100, nxt::TextureFormat::D32FloatS8Uint);
auto framebuffer = AssertWillBeError(device.CreateFramebufferBuilder())
.SetRenderPass(renderpass)
.SetAttachment(0, attachment)
.SetDimensions(100, 100)
.GetResult();
}
// TODO(kainino@chromium.org): also check attachment samples, etc.
}

View File

@@ -37,6 +37,123 @@ TEST_F(RenderPassValidationTest, OneSubpassOneAttachment) {
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// without a load op
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
}
// Tests for setting attachment load ops
TEST_F(RenderPassValidationTest, AttachmentLoadOps) {
AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// with a load op
.AttachmentSetColorLoadOp(0, nxt::LoadOp::Clear)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// with a load op of the wrong type - this is okay, just ignored
.AttachmentSetDepthStencilLoadOps(0, nxt::LoadOp::Clear, nxt::LoadOp::Clear)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
}
// Test for attachment slot arguments out of bounds
TEST_F(RenderPassValidationTest, AttachmentOutOfBounds) {
// Control case
AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// Test AttachmentSetFormat slot out of bounds
.AttachmentSetFormat(1, nxt::TextureFormat::R8G8B8A8Unorm)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// Test AttachmentSetColorLoadOp slot out of bounds
.AttachmentSetColorLoadOp(1, nxt::LoadOp::Clear)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// Test AttachmentSetDepthStencilLoadOps slot out of bounds
.AttachmentSetDepthStencilLoadOps(1, nxt::LoadOp::Clear, nxt::LoadOp::Clear)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// Test SubpassSetColorAttachment attachment slot out of bounds
.SubpassSetColorAttachment(0, 0, 1)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
// Test SubpassSetDepthStencilAttachment attachment slot out of bounds
.SubpassSetDepthStencilAttachment(0, 1)
.GetResult();
}
// Test for subpass arguments out of bounds
TEST_F(RenderPassValidationTest, SubpassOutOfBounds) {
// Control case
AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SubpassSetColorAttachment(0, 0, 0)
// Test SubpassSetColorAttachment subpass out of bounds
.SubpassSetColorAttachment(1, 0, 0)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::D32FloatS8Uint)
// Test SubpassSetDepthStencilAttachment subpass out of bounds
.SubpassSetDepthStencilAttachment(1, 0)
.GetResult();
}
// Test attaching depth/stencil textures to color attachments and vice versa
TEST_F(RenderPassValidationTest, SubpassAttachmentWrongAspect) {
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SubpassSetDepthStencilAttachment(0, 0)
.GetResult();
AssertWillBeError(device.CreateRenderPassBuilder())
.SetSubpassCount(1)
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::D32FloatS8Uint)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
}