Add Texture expectation macro and mip level parameter

This commit is contained in:
Austin Eng 2017-07-17 16:16:50 -04:00 committed by Austin Eng
parent 1b8c64d3e2
commit e5bd3e0ece
2 changed files with 8 additions and 4 deletions

View File

@ -180,7 +180,7 @@ std::ostringstream& NXTTest::AddBufferExpectation(const char* file, int line, co
return *(deferredExpectations.back().message.get()); return *(deferredExpectations.back().message.get());
} }
std::ostringstream& NXTTest::AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pixelSize, detail::Expectation* expectation) { std::ostringstream& NXTTest::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) {
nxt::Texture source = texture.Clone(); nxt::Texture source = texture.Clone();
uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment); uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment);
uint32_t size = rowPitch * (height - 1) + width * pixelSize; uint32_t size = rowPitch * (height - 1) + width * pixelSize;
@ -192,7 +192,7 @@ std::ostringstream& NXTTest::AddTextureExpectation(const char* file, int line, c
nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() nxt::CommandBuffer commands = device.CreateCommandBufferBuilder()
.TransitionTextureUsage(source, nxt::TextureUsageBit::TransferSrc) .TransitionTextureUsage(source, nxt::TextureUsageBit::TransferSrc)
.TransitionBufferUsage(readback.buffer, nxt::BufferUsageBit::TransferDst) .TransitionBufferUsage(readback.buffer, nxt::BufferUsageBit::TransferDst)
.CopyTextureToBuffer(source, x, y, 0, width, height, 1, 0, readback.buffer, readback.offset, rowPitch) .CopyTextureToBuffer(source, x, y, 0, width, height, 1, level, readback.buffer, readback.offset, rowPitch)
.GetResult(); .GetResult();
queue.Submit(1, &commands); queue.Submit(1, &commands);

View File

@ -28,9 +28,13 @@
// Test a pixel of the mip level 0 of a 2D texture. // Test a pixel of the mip level 0 of a 2D texture.
#define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \ #define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, sizeof(RGBA8), new detail::ExpectEq<RGBA8>(expected)) AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, 0, sizeof(RGBA8), new detail::ExpectEq<RGBA8>(expected))
#define EXPECT_TEXTURE_RGBA8_EQ(expected, texture, x, y, width, height, level) \
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, width, height, level, sizeof(RGBA8), new detail::ExpectEq<RGBA8>(expected, width * height))
struct RGBA8 { struct RGBA8 {
constexpr RGBA8() : RGBA8(0,0,0,0) {}
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) { constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {
} }
bool operator==(const RGBA8& other) const; bool operator==(const RGBA8& other) const;
@ -76,7 +80,7 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
// Helper methods to implement the EXPECT_ macros // 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& 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 pixelSize, 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 WaitABit();
void SwapBuffers(); void SwapBuffers();