Fix wgpu::WholeSize to count until the end of the buffer.

Bug: dawn:377
Change-Id: Ia829ec05e5dd6a218b7f1c1bb7bdaf39088bdf70
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18960
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Corentin Wallez 2020-04-08 12:09:25 +00:00 committed by Commit Bot service account
parent 36cd17488a
commit ff77ffee1a
2 changed files with 11 additions and 2 deletions

View File

@ -38,7 +38,14 @@ namespace dawn_native {
DAWN_TRY(device->ValidateObject(binding.buffer)); DAWN_TRY(device->ValidateObject(binding.buffer));
uint64_t bufferSize = binding.buffer->GetSize(); uint64_t bufferSize = binding.buffer->GetSize();
uint64_t bindingSize = (binding.size == wgpu::kWholeSize) ? bufferSize : binding.size;
// Handle wgpu::WholeSize, avoiding overflows.
if (binding.offset > bufferSize) {
return DAWN_VALIDATION_ERROR("Buffer binding doesn't fit in the buffer");
}
uint64_t bindingSize =
(binding.size == wgpu::kWholeSize) ? bufferSize - binding.offset : binding.size;
if (bindingSize > bufferSize) { if (bindingSize > bufferSize) {
return DAWN_VALIDATION_ERROR("Buffer binding size larger than the buffer"); return DAWN_VALIDATION_ERROR("Buffer binding size larger than the buffer");
} }

View File

@ -429,6 +429,9 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) {
utils::MakeBindGroup(device, layout, {{0, buffer, 0, 1024}}); utils::MakeBindGroup(device, layout, {{0, buffer, 0, 1024}});
utils::MakeBindGroup(device, layout, {{0, buffer, 0, wgpu::kWholeSize}}); utils::MakeBindGroup(device, layout, {{0, buffer, 0, wgpu::kWholeSize}});
// Success case, whole size causes the rest of the buffer to be used but not beyond.
utils::MakeBindGroup(device, layout, {{0, buffer, 256, wgpu::kWholeSize}});
// Error case, offset is OOB // Error case, offset is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256*5, 0}})); ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256*5, 0}}));
@ -437,7 +440,6 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) {
// Error case, offset+size is OOB // Error case, offset+size is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 256}})); ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 256}}));
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, wgpu::kWholeSize}}));
// Error case, offset+size overflows to be 0 // Error case, offset+size overflows to be 0
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}})); ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));