Resource Management 4: Stress test buffer writes

Add test for many buffer writes.

BUG=dawn:27

Change-Id: I026c3b9a6d30c7c6634b89db9798902b036150c3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9280
Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Bryan Bernhart 2019-07-24 20:09:44 +00:00 committed by Commit Bot service account
parent fde94905fe
commit 2718177841
1 changed files with 34 additions and 1 deletions

View File

@ -100,7 +100,11 @@ class BufferMapWriteTests : public DawnTest {
WaitABit();
}
return mappedData;
// Ensure the prior write's status is updated.
void* resultPointer = mappedData;
mappedData = nullptr;
return resultPointer;
}
private:
@ -142,6 +146,35 @@ TEST_P(BufferMapWriteTests, LargeWrite) {
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), buffer, 0, kDataSize);
}
// Stress test mapping many buffers.
TEST_P(BufferMapWriteTests, ManyWrites) {
constexpr uint32_t kDataSize = 1000;
std::vector<uint32_t> myData;
for (uint32_t i = 0; i < kDataSize; ++i) {
myData.push_back(i);
}
std::vector<dawn::Buffer> buffers;
constexpr uint32_t kBuffers = 100;
for (uint32_t i = 0; i < kBuffers; ++i) {
dawn::BufferDescriptor descriptor;
descriptor.size = static_cast<uint32_t>(kDataSize * sizeof(uint32_t));
descriptor.usage = dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::CopySrc;
dawn::Buffer buffer = device.CreateBuffer(&descriptor);
void* mappedData = MapWriteAsyncAndWait(buffer);
memcpy(mappedData, myData.data(), kDataSize * sizeof(uint32_t));
buffer.Unmap();
buffers.push_back(buffer); // Destroy buffers upon return.
}
for (uint32_t i = 0; i < kBuffers; ++i) {
EXPECT_BUFFER_U32_RANGE_EQ(myData.data(), buffers[i], 0, kDataSize);
}
}
DAWN_INSTANTIATE_TEST(BufferMapWriteTests, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);
class BufferSetSubDataTests : public DawnTest {