dawn_native: Move pass validation of buffer usages into the encoder.

In a future CL the PassResourceUsage structure will become a
SyncScopeResourceUsage and will be used to validate at each
synchronization scope. For separation of concerns, the validation that
resource have the correct usage shouldn't be done at the sync scope
level but at each entrypoint that uses the resource.

The validation tests had no coverage of usage validation for pass usage
so validation tests are added for Indirct/Index/Vertex usages. (Uniform
and Storage are validated at bindgroup creation and already had
validation tests)

Bug: dawn:635
Change-Id: I5058ad30eb041809f0f60d9403f3cc2d5d7e7c96
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38380
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2021-01-22 09:57:38 +00:00
committed by Commit Bot service account
parent db383498c5
commit 310d86f4a0
7 changed files with 123 additions and 11 deletions

View File

@@ -69,9 +69,10 @@ class DrawIndirectValidationTest : public ValidationTest {
void TestIndirectOffset(utils::Expectation expectation,
std::initializer_list<uint32_t> bufferList,
uint64_t indirectOffset,
bool indexed) {
bool indexed,
wgpu::BufferUsage usage = wgpu::BufferUsage::Indirect) {
wgpu::Buffer indirectBuffer =
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
utils::CreateBufferFromData<uint32_t>(device, usage, bufferList);
DummyRenderPass renderPass(device);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@@ -146,3 +147,18 @@ TEST_F(DrawIndirectValidationTest, DrawIndexedIndirectOffsetBounds) {
TestIndirectOffsetDrawIndexed(utils::Expectation::Failure, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
offset);
}
// Check that the buffer must have the indirect usage
TEST_F(DrawIndirectValidationTest, IndirectUsage) {
// Control cases: using a buffer with the indirect usage is valid.
TestIndirectOffset(utils::Expectation::Success, {1, 2, 3, 4}, 0, false,
wgpu::BufferUsage::Indirect);
TestIndirectOffset(utils::Expectation::Success, {1, 2, 3, 4, 5}, 0, true,
wgpu::BufferUsage::Indirect);
// Error cases: using a buffer with the vertex usage is an error.
TestIndirectOffset(utils::Expectation::Failure, {1, 2, 3, 4}, 0, false,
wgpu::BufferUsage::Vertex);
TestIndirectOffset(utils::Expectation::Failure, {1, 2, 3, 4, 5}, 0, true,
wgpu::BufferUsage::Vertex);
}