Clean up BufferZeroInitTests

BUG=dawn:414
TEST=dawn_end2end_tests

Change-Id: I8a9a4d45fe93e1071b8508ba7ddd2bf9545a3c63
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26641
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Jiawei Shao 2020-08-13 12:03:28 +00:00 committed by Commit Bot service account
parent 4a486be696
commit 2b1c0b0e92
1 changed files with 19 additions and 30 deletions

View File

@ -207,6 +207,7 @@ class BufferZeroInitTest : public DawnTest {
fragColor = i_color; fragColor = i_color;
})"); })");
ASSERT(vertexBufferCount <= 1u);
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule; descriptor.vertexStage.module = vsModule;
descriptor.cFragmentStage.module = fsModule; descriptor.cFragmentStage.module = fsModule;
@ -220,18 +221,18 @@ class BufferZeroInitTest : public DawnTest {
return device.CreateRenderPipeline(&descriptor); return device.CreateRenderPipeline(&descriptor);
} }
void ValidateBufferAndOutputTexture(wgpu::CommandEncoder encoder, void ExpectLazyClearSubmitAndCheckOutputs(wgpu::CommandEncoder encoder,
wgpu::Buffer buffer, wgpu::Buffer buffer,
uint64_t bufferSize, uint64_t bufferSize,
wgpu::Texture colorAttachment) { wgpu::Texture colorAttachment) {
wgpu::CommandBuffer commandBuffer = encoder.Finish(); wgpu::CommandBuffer commandBuffer = encoder.Finish();
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commandBuffer)); EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commandBuffer));
// Although we just bind a part of the buffer, we still expect the whole buffer to be // Although we just bind a part of the buffer, we still expect the whole buffer to be
// lazily initialized to 0. // lazily initialized to 0.
const std::vector<float> expectedVertexBufferData(bufferSize / sizeof(float), 0.f); const std::vector<uint32_t> expectedBufferData(bufferSize / sizeof(uint32_t), 0);
EXPECT_LAZY_CLEAR(0u, EXPECT_BUFFER_FLOAT_RANGE_EQ(expectedVertexBufferData.data(), buffer, EXPECT_LAZY_CLEAR(0u, EXPECT_BUFFER_U32_RANGE_EQ(expectedBufferData.data(), buffer, 0,
0, expectedVertexBufferData.size())); expectedBufferData.size()));
const RGBA8 kExpectedPixelValue = {0, 255, 0, 255}; const RGBA8 kExpectedPixelValue = {0, 255, 0, 255};
EXPECT_PIXEL_RGBA8_EQ(kExpectedPixelValue, colorAttachment, 0, 0); EXPECT_PIXEL_RGBA8_EQ(kExpectedPixelValue, colorAttachment, 0, 0);
@ -274,7 +275,8 @@ class BufferZeroInitTest : public DawnTest {
renderPass.Draw(1); renderPass.Draw(1);
renderPass.EndPass(); renderPass.EndPass();
ValidateBufferAndOutputTexture(encoder, vertexBuffer, vertexBufferSize, colorAttachment); ExpectLazyClearSubmitAndCheckOutputs(encoder, vertexBuffer, vertexBufferSize,
colorAttachment);
} }
void TestBufferZeroInitAsIndexBuffer(uint64_t indexBufferOffset) { void TestBufferZeroInitAsIndexBuffer(uint64_t indexBufferOffset) {
@ -292,15 +294,7 @@ class BufferZeroInitTest : public DawnTest {
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); gl_Position = vec4(0.f, 0.f, 0.f, 1.f);
gl_PointSize = 1.0f; gl_PointSize = 1.0f;
})"; })";
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader); wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u);
// It is not allowed to use an index buffer without a vertex buffer although the vertex
// buffer is not used. So here we use an initialized dummy buffer as vertex buffer.
constexpr std::array<float, 4> kVertexBufferData = {0, 0, 0, 0};
constexpr uint64_t kVertexBufferSize = sizeof(kVertexBufferData);
wgpu::Buffer vertexBuffer =
utils::CreateBufferFromData(device, kVertexBufferData.data(), kVertexBufferSize,
wgpu::BufferUsage::Vertex | wgpu::BufferUsage::CopyDst);
// The buffer size cannot be less than 4 // The buffer size cannot be less than 4
const uint64_t indexBufferSize = sizeof(uint32_t) + indexBufferOffset; const uint64_t indexBufferSize = sizeof(uint32_t) + indexBufferOffset;
@ -314,7 +308,6 @@ class BufferZeroInitTest : public DawnTest {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetVertexBuffer(0, vertexBuffer, 0, kVertexBufferSize);
renderPass.SetPipeline(renderPipeline); renderPass.SetPipeline(renderPipeline);
// Bind the buffer with offset == indexBufferOffset and size sizeof(uint32_t) as the index // Bind the buffer with offset == indexBufferOffset and size sizeof(uint32_t) as the index
@ -323,7 +316,8 @@ class BufferZeroInitTest : public DawnTest {
renderPass.DrawIndexed(1); renderPass.DrawIndexed(1);
renderPass.EndPass(); renderPass.EndPass();
ValidateBufferAndOutputTexture(encoder, indexBuffer, indexBufferSize, colorAttachment); ExpectLazyClearSubmitAndCheckOutputs(encoder, indexBuffer, indexBufferSize,
colorAttachment);
} }
void TestBufferZeroInitAsIndirectBufferForDrawIndirect(uint64_t indirectBufferOffset) { void TestBufferZeroInitAsIndirectBufferForDrawIndirect(uint64_t indirectBufferOffset) {
@ -360,7 +354,7 @@ class BufferZeroInitTest : public DawnTest {
renderPass.DrawIndirect(indirectBuffer, indirectBufferOffset); renderPass.DrawIndirect(indirectBuffer, indirectBufferOffset);
renderPass.EndPass(); renderPass.EndPass();
ValidateBufferAndOutputTexture(encoder, indirectBuffer, bufferSize, colorAttachment); ExpectLazyClearSubmitAndCheckOutputs(encoder, indirectBuffer, bufferSize, colorAttachment);
} }
void TestBufferZeroInitAsIndirectBufferForDrawIndexedIndirect(uint64_t indirectBufferOffset) { void TestBufferZeroInitAsIndirectBufferForDrawIndexedIndirect(uint64_t indirectBufferOffset) {
@ -378,13 +372,9 @@ class BufferZeroInitTest : public DawnTest {
} }
)"; )";
// It is not allowed to use an index buffer without a vertex buffer although the vertex wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 0u);
// buffer is not used. So here we use an initialized dummy buffer as vertex buffer. wgpu::Buffer indexBuffer =
wgpu::RenderPipeline renderPipeline = CreateRenderPipelineForTest(vertexShader, 1u); utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Index, {0});
wgpu::Buffer vertexBuffer = utils::CreateBufferFromData<float>(
device, wgpu::BufferUsage::Vertex, {0.f, 0.f, 0.f, 0.f});
wgpu::Buffer indexBuffer = utils::CreateBufferFromData<float>(
device, wgpu::BufferUsage::Index, {0.f, 0.f, 0.f, 0.f});
// Clear the color attachment to green. // Clear the color attachment to green.
wgpu::Texture colorAttachment = wgpu::Texture colorAttachment =
@ -401,12 +391,11 @@ class BufferZeroInitTest : public DawnTest {
wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDescriptor); wgpu::RenderPassEncoder renderPass = encoder.BeginRenderPass(&renderPassDescriptor);
renderPass.SetPipeline(renderPipeline); renderPass.SetPipeline(renderPipeline);
renderPass.SetVertexBuffer(0, vertexBuffer);
renderPass.SetIndexBuffer(indexBuffer); renderPass.SetIndexBuffer(indexBuffer);
renderPass.DrawIndexedIndirect(indirectBuffer, indirectBufferOffset); renderPass.DrawIndexedIndirect(indirectBuffer, indirectBufferOffset);
renderPass.EndPass(); renderPass.EndPass();
ValidateBufferAndOutputTexture(encoder, indirectBuffer, bufferSize, colorAttachment); ExpectLazyClearSubmitAndCheckOutputs(encoder, indirectBuffer, bufferSize, colorAttachment);
} }
void TestBufferZeroInitAsIndirectBufferForDispatchIndirect(uint64_t indirectBufferOffset) { void TestBufferZeroInitAsIndirectBufferForDispatchIndirect(uint64_t indirectBufferOffset) {
@ -452,7 +441,7 @@ class BufferZeroInitTest : public DawnTest {
computePass.DispatchIndirect(indirectBuffer, indirectBufferOffset); computePass.DispatchIndirect(indirectBuffer, indirectBufferOffset);
computePass.EndPass(); computePass.EndPass();
ValidateBufferAndOutputTexture(encoder, indirectBuffer, bufferSize, outputTexture); ExpectLazyClearSubmitAndCheckOutputs(encoder, indirectBuffer, bufferSize, outputTexture);
} }
}; };