Swap chains, part 2 (#94)

This commit is contained in:
Kai Ninomiya
2017-07-27 18:30:57 -07:00
committed by GitHub
parent 3818e18c5c
commit c16a67ae52
49 changed files with 771 additions and 435 deletions

View File

@@ -137,6 +137,10 @@ void NXTTest::SetUp() {
device = nxt::Device::Acquire(backendDevice);
queue = device.CreateQueueBuilder().GetResult();
swapchain = device.CreateSwapChainBuilder()
.SetImplementation(binding->GetSwapChainImplementation())
.GetResult();
device.SetErrorCallback(DeviceErrorCauseTestFailure, 0);
}
@@ -217,8 +221,11 @@ void NXTTest::WaitABit() {
utils::USleep(100);
}
void NXTTest::SwapBuffers() {
binding->SwapBuffers();
void NXTTest::SwapBuffersForCapture() {
// Insert a frame boundary for API capture tools.
nxt::Texture backBuffer = swapchain.GetNextTexture();
backBuffer.TransitionUsage(nxt::TextureUsageBit::Present);
swapchain.Present(backBuffer);
}
NXTTest::ReadbackReservation NXTTest::ReserveReadback(uint32_t readbackSize) {

View File

@@ -77,13 +77,15 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
protected:
nxt::Device device;
nxt::Queue queue;
nxt::SwapChain swapchain;
// Helper methods to implement the EXPECT_ macros
std::ostringstream& AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, detail::Expectation* expectation);
std::ostringstream& AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t level, uint32_t pixelSize, detail::Expectation* expectation);
void WaitABit();
void SwapBuffers();
void SwapBuffersForCapture();
private:
// MapRead buffers used to get data for the expectations

View File

@@ -21,7 +21,7 @@ class RenderPipelineValidationTest : public ValidationTest {
void SetUp() override {
ValidationTest::SetUp();
utils::CreateDefaultRenderPass(device, &renderpass, &framebuffer);
CreateSimpleRenderPassAndFramebuffer(device, &renderpass, &framebuffer);
pipelineLayout = device.CreatePipelineLayoutBuilder().GetResult();

View File

@@ -69,6 +69,32 @@ bool ValidationTest::EndExpectDeviceError() {
return error;
}
void ValidationTest::CreateSimpleRenderPassAndFramebuffer(const nxt::Device& device, nxt::RenderPass* renderpass, nxt::Framebuffer* framebuffer) {
auto colorBuffer = device.CreateTextureBuilder()
.SetDimension(nxt::TextureDimension::e2D)
.SetExtent(640, 480, 1)
.SetFormat(nxt::TextureFormat::R8G8B8A8Unorm)
.SetMipLevels(1)
.SetAllowedUsage(nxt::TextureUsageBit::OutputAttachment)
.GetResult();
colorBuffer.FreezeUsage(nxt::TextureUsageBit::OutputAttachment);
auto colorView = colorBuffer.CreateTextureViewBuilder()
.GetResult();
*renderpass = device.CreateRenderPassBuilder()
.SetAttachmentCount(1)
.AttachmentSetFormat(0, nxt::TextureFormat::R8G8B8A8Unorm)
.SetSubpassCount(1)
.SubpassSetColorAttachment(0, 0, 0)
.GetResult();
*framebuffer = device.CreateFramebufferBuilder()
.SetRenderPass(*renderpass)
.SetDimensions(640, 480)
.SetAttachment(0, colorView)
.GetResult();
}
void ValidationTest::OnDeviceError(const char* message, nxtCallbackUserdata userdata) {
// Skip this one specific error that is raised when a builder is used after it got an error
// this is important because we don't want to wrap all creation tests in ASSERT_DEVICE_ERROR.

View File

@@ -48,6 +48,8 @@ class ValidationTest : public testing::Test {
void StartExpectDeviceError();
bool EndExpectDeviceError();
void CreateSimpleRenderPassAndFramebuffer(const nxt::Device& device, nxt::RenderPass* renderpass, nxt::Framebuffer* framebuffer);
// Helper functions to create objects to test validation.
struct DummyRenderPass {