Define kQueryResolveAlignment
This patch defines kQueryResolveAlignment in Constants.h as the
minimum alignment of destination buffer offset in ResolveQuerySet()
for internal use.
Bug: dawn:940
Change-Id: I248de39dbc37d3d7dc50754efc161c4a7b8e0ce4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/140080
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/dawn/common/Constants.h b/src/dawn/common/Constants.h
index 4a46586..d95c8cf 100644
--- a/src/dawn/common/Constants.h
+++ b/src/dawn/common/Constants.h
@@ -29,6 +29,7 @@
static constexpr uint32_t kNumStages = 3;
static constexpr uint8_t kMaxColorAttachments = 8u;
static constexpr uint32_t kTextureBytesPerRowAlignment = 256u;
+static constexpr uint32_t kQueryResolveAlignment = 256u;
static constexpr uint32_t kMaxInterStageShaderComponents = 60u;
static constexpr uint32_t kMaxInterStageShaderVariables = 16u;
static constexpr uint64_t kAssumedMaxBufferSize =
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index 28811e0..6ccbd5d 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -654,9 +654,9 @@
"(%u) in %s.",
firstQuery, queryCount, querySet->GetQueryCount(), querySet);
- DAWN_INVALID_IF(destinationOffset % 256 != 0,
- "The destination buffer %s offset (%u) is not a multiple of 256.", destination,
- destinationOffset);
+ DAWN_INVALID_IF(destinationOffset % kQueryResolveAlignment != 0,
+ "The destination buffer %s offset (%u) is not a multiple of %u.", destination,
+ destinationOffset, kQueryResolveAlignment);
uint64_t bufferSize = destination->GetSize();
// The destination buffer must have enough storage, from destination offset, to contain
diff --git a/src/dawn/tests/end2end/BufferZeroInitTests.cpp b/src/dawn/tests/end2end/BufferZeroInitTests.cpp
index 973223a..4e7155c 100644
--- a/src/dawn/tests/end2end/BufferZeroInitTests.cpp
+++ b/src/dawn/tests/end2end/BufferZeroInitTests.cpp
@@ -1368,7 +1368,7 @@
// destinationOffset > 0 and destinationOffset + 8 * queryCount <= kBufferSize
{
constexpr uint32_t kQueryCount = 1;
- constexpr uint64_t kDestinationOffset = 256u;
+ constexpr uint64_t kDestinationOffset = kQueryResolveAlignment;
wgpu::Buffer destination = CreateBuffer(kBufferSize + kDestinationOffset, kBufferUsage);
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
diff --git a/src/dawn/tests/end2end/QueryTests.cpp b/src/dawn/tests/end2end/QueryTests.cpp
index b74aa8e..a52ca2b 100644
--- a/src/dawn/tests/end2end/QueryTests.cpp
+++ b/src/dawn/tests/end2end/QueryTests.cpp
@@ -25,7 +25,7 @@
constexpr static uint64_t kSentinelValue = ~uint64_t(0u);
constexpr static uint64_t kZero = 0u;
constexpr static unsigned int kRTSize = 4;
-constexpr uint64_t kMinDestinationOffset = 256;
+constexpr uint64_t kMinDestinationOffset = kQueryResolveAlignment;
constexpr uint64_t kMinCount = kMinDestinationOffset / sizeof(uint64_t);
constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
constexpr wgpu::TextureFormat kDepthStencilFormat = wgpu::TextureFormat::Depth24PlusStencil8;
diff --git a/src/dawn/tests/unittests/validation/QueryValidationTests.cpp b/src/dawn/tests/unittests/validation/QueryValidationTests.cpp
index ca59f0a..dcb830e 100644
--- a/src/dawn/tests/unittests/validation/QueryValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/QueryValidationTests.cpp
@@ -843,7 +843,7 @@
TEST_F(ResolveQuerySetValidationTest, ResolveToInvalidBufferAndOffset) {
constexpr uint32_t kQueryCount = 4;
constexpr uint64_t kBufferSize =
- (kQueryCount - 1) * sizeof(uint64_t) + 256 /*destinationOffset*/;
+ (kQueryCount - 1) * sizeof(uint64_t) + kQueryResolveAlignment /*destinationOffset*/;
wgpu::QuerySet querySet = CreateQuerySet(device, wgpu::QueryType::Occlusion, kQueryCount);
wgpu::Buffer destination = CreateBuffer(device, kBufferSize, wgpu::BufferUsage::QueryResolve);
@@ -851,7 +851,7 @@
// Success
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- encoder.ResolveQuerySet(querySet, 1, kQueryCount - 1, destination, 256);
+ encoder.ResolveQuerySet(querySet, 1, kQueryCount - 1, destination, kQueryResolveAlignment);
wgpu::CommandBuffer commands = encoder.Finish();
wgpu::Queue queue = device.GetQueue();
@@ -871,14 +871,14 @@
// Fail to resolve query set to a buffer if offset is not a multiple of 256 bytes
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- encoder.ResolveQuerySet(querySet, 0, kQueryCount, destination, 128);
+ encoder.ResolveQuerySet(querySet, 0, kQueryCount, destination, kQueryResolveAlignment / 2);
ASSERT_DEVICE_ERROR(encoder.Finish());
}
// Fail to resolve query set to a buffer if the data size overflow the buffer
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- encoder.ResolveQuerySet(querySet, 0, kQueryCount, destination, 256);
+ encoder.ResolveQuerySet(querySet, 0, kQueryCount, destination, kQueryResolveAlignment);
ASSERT_DEVICE_ERROR(encoder.Finish());
}
diff --git a/src/dawn/tests/white_box/QueryInternalShaderTests.cpp b/src/dawn/tests/white_box/QueryInternalShaderTests.cpp
index 410fd0c..3113dcd 100644
--- a/src/dawn/tests/white_box/QueryInternalShaderTests.cpp
+++ b/src/dawn/tests/white_box/QueryInternalShaderTests.cpp
@@ -139,7 +139,7 @@
uint32_t queryCount,
uint32_t destinationOffset,
float period) {
- ASSERT(destinationOffset % 256 == 0);
+ ASSERT(destinationOffset % kQueryResolveAlignment == 0);
uint64_t size = queryCount * sizeof(uint64_t) + destinationOffset;
@@ -221,11 +221,11 @@
// Convert timestamps in timestamps buffer with offset 256
// Test for ResolveQuerySet(querySet, 1, kQueryCount - 1, timestampsBuffer, 256)
- RunTest(1, kQueryCount - 1, 256, period);
+ RunTest(1, kQueryCount - 1, kQueryResolveAlignment, period);
// Convert partial timestamps in timestamps buffer with offset 256
// Test for ResolveQuerySet(querySet, 1, 4, timestampsBuffer, 256)
- RunTest(1, 4, 256, period);
+ RunTest(1, 4, kQueryResolveAlignment, period);
}
}