end2end: Add BufferSetSubData tests
The test doing many small SetSubData freezes the Metal driver on a MTLBuffer allocation. This is because we don't use a ringbuffer for SetSubData and instead create one small upload buffer per call. The same test is skipped on D3D12 as it is bound to have the same issue. Also adds comments that were forgotten before every MapReadAsync test.
This commit is contained in:
parent
e1f16a25bf
commit
1e66ab93fe
|
@ -41,6 +41,7 @@ class BufferMapReadTests : public NXTTest {
|
||||||
const void* mappedData = nullptr;
|
const void* mappedData = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Test that the simplest map read (one u32 at offset 0) works.
|
||||||
TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
||||||
nxt::Buffer buffer = device.CreateBufferBuilder()
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
.SetSize(4)
|
.SetSize(4)
|
||||||
|
@ -58,6 +59,7 @@ TEST_P(BufferMapReadTests, SmallReadAtZero) {
|
||||||
buffer.Unmap();
|
buffer.Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test mapping a buffer at an offset.
|
||||||
TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
||||||
nxt::Buffer buffer = device.CreateBufferBuilder()
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
.SetSize(4000)
|
.SetSize(4000)
|
||||||
|
@ -75,6 +77,7 @@ TEST_P(BufferMapReadTests, SmallReadAtOffset) {
|
||||||
buffer.Unmap();
|
buffer.Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test mapping large ranges of a buffer.
|
||||||
TEST_P(BufferMapReadTests, LargeRead) {
|
TEST_P(BufferMapReadTests, LargeRead) {
|
||||||
constexpr uint32_t kDataSize = 1000 * 1000;
|
constexpr uint32_t kDataSize = 1000 * 1000;
|
||||||
std::vector<uint32_t> myData;
|
std::vector<uint32_t> myData;
|
||||||
|
@ -98,3 +101,83 @@ TEST_P(BufferMapReadTests, LargeRead) {
|
||||||
}
|
}
|
||||||
|
|
||||||
NXT_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend, MetalBackend, OpenGLBackend)
|
NXT_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend, MetalBackend, OpenGLBackend)
|
||||||
|
|
||||||
|
class BufferSetSubDataTests : public NXTTest {
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test the simplest set sub data: setting one u32 at offset 0.
|
||||||
|
TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
|
||||||
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
|
.SetSize(4)
|
||||||
|
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
|
||||||
|
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
uint32_t value = 298371;
|
||||||
|
buffer.SetSubData(0, 1, &value);
|
||||||
|
|
||||||
|
EXPECT_BUFFER_U32_EQ(value, buffer, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that SetSubData offset works.
|
||||||
|
TEST_P(BufferSetSubDataTests, SmallDataAtOffset) {
|
||||||
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
|
.SetSize(4000)
|
||||||
|
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
|
||||||
|
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
constexpr uint32_t kOffset = 2000;
|
||||||
|
uint32_t value = 298371;
|
||||||
|
buffer.SetSubData(kOffset / 4, 1, &value);
|
||||||
|
|
||||||
|
EXPECT_BUFFER_U32_EQ(value, buffer, kOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stress test for many calls to SetSubData
|
||||||
|
TEST_P(BufferSetSubDataTests, ManySetSubData) {
|
||||||
|
if (IsD3D12() || IsMetal()) {
|
||||||
|
// TODO(cwallez@chromium.org): Use ringbuffers for SetSubData on explicit APIs.
|
||||||
|
// otherwise this creates too many resources and can take freeze the driver(?)
|
||||||
|
std::cout << "Test skipped on D3D12 and Metal" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint32_t kSize = 4000 * 1000;
|
||||||
|
constexpr uint32_t kElements = 1000 * 1000;
|
||||||
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
|
.SetSize(kSize)
|
||||||
|
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
|
||||||
|
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData;
|
||||||
|
for (uint32_t i = 0; i < kElements; ++i) {
|
||||||
|
buffer.SetSubData(i, 1, &i);
|
||||||
|
expectedData.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test using SetSubData for lots of data
|
||||||
|
TEST_P(BufferSetSubDataTests, LargeSetSubData) {
|
||||||
|
constexpr uint32_t kSize = 4000 * 1000;
|
||||||
|
constexpr uint32_t kElements = 1000 * 1000;
|
||||||
|
nxt::Buffer buffer = device.CreateBufferBuilder()
|
||||||
|
.SetSize(kSize)
|
||||||
|
.SetAllowedUsage(nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)
|
||||||
|
.SetInitialUsage(nxt::BufferUsageBit::TransferDst)
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
std::vector<uint32_t> expectedData;
|
||||||
|
for (uint32_t i = 0; i < kElements; ++i) {
|
||||||
|
expectedData.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.SetSubData(0, kElements, expectedData.data());
|
||||||
|
|
||||||
|
EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
NXT_INSTANTIATE_TEST(BufferSetSubDataTests, D3D12Backend, MetalBackend, OpenGLBackend)
|
||||||
|
|
Loading…
Reference in New Issue