ValidationTest: Add helper to create a dummy renderpass

This commit is contained in:
Corentin Wallez 2017-07-20 10:59:24 -04:00 committed by Corentin Wallez
parent b343e8d920
commit 2dfea9961a
3 changed files with 50 additions and 8 deletions

View File

@ -23,12 +23,7 @@ static constexpr uint32_t kMaxVertexInputs = 16u;
class InputStateTest : public ValidationTest { class InputStateTest : public ValidationTest {
protected: protected:
nxt::RenderPipeline CreatePipeline(bool success, const nxt::InputState& inputState, std::string vertexSource) { nxt::RenderPipeline CreatePipeline(bool success, const nxt::InputState& inputState, std::string vertexSource) {
nxt::RenderPass renderPass = AssertWillBeSuccess(device.CreateRenderPassBuilder()) DummyRenderPass renderpassData = CreateDummyRenderPass();
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
nxt::ShaderModuleBuilder vsModuleBuilder = AssertWillBeSuccess(device.CreateShaderModuleBuilder()); nxt::ShaderModuleBuilder vsModuleBuilder = AssertWillBeSuccess(device.CreateShaderModuleBuilder());
utils::FillShaderModuleBuilder(vsModuleBuilder, nxt::ShaderStage::Vertex, vertexSource.c_str()); utils::FillShaderModuleBuilder(vsModuleBuilder, nxt::ShaderStage::Vertex, vertexSource.c_str());
@ -51,7 +46,7 @@ class InputStateTest : public ValidationTest {
builder = AssertWillBeError(device.CreateRenderPipelineBuilder()); builder = AssertWillBeError(device.CreateRenderPipelineBuilder());
} }
return builder.SetSubpass(renderPass, 0) return builder.SetSubpass(renderpassData.renderPass, 0)
.SetStage(nxt::ShaderStage::Vertex, vsModule, "main") .SetStage(nxt::ShaderStage::Vertex, vsModule, "main")
.SetStage(nxt::ShaderStage::Fragment, fsModule, "main") .SetStage(nxt::ShaderStage::Fragment, fsModule, "main")
.SetInputState(inputState) .SetInputState(inputState)

View File

@ -95,3 +95,36 @@ void ValidationTest::OnBuilderErrorStatus(nxtBuilderErrorStatus status, const ch
expectation.status = status; expectation.status = status;
expectation.statusMessage = message; expectation.statusMessage = message;
} }
ValidationTest::DummyRenderPass ValidationTest::CreateDummyRenderPass() {
DummyRenderPass dummy;
dummy.width = 400;
dummy.height = 400;
dummy.attachmentFormat = nxt::TextureFormat::R8G8B8A8Unorm;
dummy.renderPass = AssertWillBeSuccess(device.CreateRenderPassBuilder())
.SetAttachmentCount(1)
.AttachmentSetFormat(0, dummy.attachmentFormat)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
dummy.attachment = AssertWillBeSuccess(device.CreateTextureBuilder())
.SetDimension(nxt::TextureDimension::e2D)
.SetExtent(dummy.width, dummy.height, 1)
.SetFormat(dummy.attachmentFormat)
.SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult();
dummy.attachment.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
nxt::TextureView view = AssertWillBeSuccess(dummy.attachment.CreateTextureViewBuilder()).GetResult();
dummy.framebuffer = AssertWillBeSuccess(device.CreateFramebufferBuilder())
.SetRenderPass(dummy.renderPass)
.SetAttachment(0, view)
.SetDimensions(dummy.width, dummy.height)
.GetResult();
return dummy;
}

View File

@ -29,6 +29,8 @@ class ValidationTest : public testing::Test {
ValidationTest(); ValidationTest();
~ValidationTest(); ~ValidationTest();
void TearDown() override;
// Use these methods to add expectations on the validation of a builder. The expectations are // Use these methods to add expectations on the validation of a builder. The expectations are
// checked on test teardown. Adding an expectation is done like the following: // checked on test teardown. Adding an expectation is done like the following:
// //
@ -46,7 +48,17 @@ class ValidationTest : public testing::Test {
void StartExpectDeviceError(); void StartExpectDeviceError();
bool EndExpectDeviceError(); bool EndExpectDeviceError();
void TearDown() override; // Helper functions to create objects to test validation.
struct DummyRenderPass {
nxt::RenderPass renderPass;
nxt::Framebuffer framebuffer;
nxt::Texture attachment;
nxt::TextureFormat attachmentFormat;
uint32_t width;
uint32_t height;
};
DummyRenderPass CreateDummyRenderPass();
protected: protected:
nxt::Device device; nxt::Device device;
@ -72,6 +84,8 @@ class ValidationTest : public testing::Test {
static void OnBuilderErrorStatus(nxtBuilderErrorStatus status, const char* message, nxt::CallbackUserdata userdata1, nxt::CallbackUserdata userdata2); static void OnBuilderErrorStatus(nxtBuilderErrorStatus status, const char* message, nxt::CallbackUserdata userdata1, nxt::CallbackUserdata userdata2);
}; };
// Template implementation details
template<typename Builder> template<typename Builder>
Builder ValidationTest::AssertWillBeSuccess(Builder builder, std::string debugName) { Builder ValidationTest::AssertWillBeSuccess(Builder builder, std::string debugName) {
return AddExpectation(builder, debugName, true); return AddExpectation(builder, debugName, true);