Removes duplicated maxBufferSize in limit macros.
- Note the duplication (in LIMITS_MAX_BUFFER_SIZE and LIMITS_OTHER)
caused tiering to be overridden.
- Also updated binding size test to align buffer sizes properly since
the test was failing locally for me.
Fixes: dawn:1683
Change-Id: I8d05f863ea9bf4dc8e620b7803bedb913af9f67b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122260
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 2fbdf18..a23b6e1 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -71,6 +71,12 @@
mLimits.v1.maxUniformBuffersPerShaderStage =
std::min(mLimits.v1.maxUniformBuffersPerShaderStage, kMaxUniformBuffersPerShaderStage);
+ // Additional enforcement for dependent limits.
+ mLimits.v1.maxStorageBufferBindingSize =
+ std::min(mLimits.v1.maxStorageBufferBindingSize, mLimits.v1.maxBufferSize);
+ mLimits.v1.maxUniformBufferBindingSize =
+ std::min(mLimits.v1.maxUniformBufferBindingSize, mLimits.v1.maxBufferSize);
+
return {};
}
diff --git a/src/dawn/native/Limits.cpp b/src/dawn/native/Limits.cpp
index 98fb4c6..3e593ae 100644
--- a/src/dawn/native/Limits.cpp
+++ b/src/dawn/native/Limits.cpp
@@ -68,7 +68,6 @@
X(Alignment, minUniformBufferOffsetAlignment, 256, 256) \
X(Alignment, minStorageBufferOffsetAlignment, 256, 256) \
X(Maximum, maxVertexBuffers, 8, 8) \
- X(Maximum, maxBufferSize, 268435456, 268435456) \
X(Maximum, maxVertexAttributes, 16, 16) \
X(Maximum, maxVertexBufferArrayStride, 2048, 2048) \
X(Maximum, maxInterStageShaderComponents, 60, 60) \
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 8c2777f..7b118e8 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -815,6 +815,12 @@
return mParam.adapterProperties;
}
+wgpu::SupportedLimits DawnTestBase::GetAdapterLimits() {
+ wgpu::SupportedLimits supportedLimits = {};
+ mAdapter.GetLimits(&supportedLimits);
+ return supportedLimits;
+}
+
wgpu::SupportedLimits DawnTestBase::GetSupportedLimits() {
wgpu::SupportedLimits supportedLimits = {};
device.GetLimits(&supportedLimits);
diff --git a/src/dawn/tests/DawnTest.h b/src/dawn/tests/DawnTest.h
index 47046fe..a254710 100644
--- a/src/dawn/tests/DawnTest.h
+++ b/src/dawn/tests/DawnTest.h
@@ -564,6 +564,7 @@
const wgpu::AdapterProperties& GetAdapterProperties() const;
+ wgpu::SupportedLimits GetAdapterLimits();
wgpu::SupportedLimits GetSupportedLimits();
private:
diff --git a/src/dawn/tests/end2end/MaxLimitTests.cpp b/src/dawn/tests/end2end/MaxLimitTests.cpp
index a603db8..696f0a1 100644
--- a/src/dawn/tests/end2end/MaxLimitTests.cpp
+++ b/src/dawn/tests/end2end/MaxLimitTests.cpp
@@ -113,8 +113,6 @@
// TODO(dawn:1549) Fails on Qualcomm-based Android devices.
DAWN_SUPPRESS_TEST_IF(IsAndroid() && IsQualcomm());
- // TODO(crbug.com/dawn/1683) Fails on MacBook Pro 2019
- DAWN_SUPPRESS_TEST_IF(IsMacOS() && IsMetal() && IsAMD());
for (wgpu::BufferUsage usage : {wgpu::BufferUsage::Storage, wgpu::BufferUsage::Uniform}) {
uint64_t maxBufferBindingSize;
@@ -136,6 +134,7 @@
maxBufferBindingSize =
std::min(maxBufferBindingSize, uint64_t(512) * 1024 * 1024);
}
+ maxBufferBindingSize = Align(maxBufferBindingSize - 3u, 4);
shader = R"(
struct Buf {
values : array<u32>
@@ -162,6 +161,7 @@
// Clamp to not exceed the maximum i32 value for the WGSL @size(x) annotation.
maxBufferBindingSize = std::min(maxBufferBindingSize,
uint64_t(std::numeric_limits<int32_t>::max()) + 8);
+ maxBufferBindingSize = Align(maxBufferBindingSize - 3u, 4);
shader = R"(
struct Buf {
@@ -194,8 +194,7 @@
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
wgpu::BufferDescriptor bufDesc;
- uint64_t bufferSize = Align(maxBufferBindingSize - 3u, 4);
- bufDesc.size = bufferSize;
+ bufDesc.size = maxBufferBindingSize;
bufDesc.usage = usage | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&bufDesc);
@@ -216,7 +215,7 @@
queue.WriteBuffer(buffer, 0, &value0, sizeof(value0));
uint32_t value1 = 234;
- uint64_t value1Offset = Align(bufferSize - sizeof(value1), 4);
+ uint64_t value1Offset = Align(maxBufferBindingSize - sizeof(value1), 4);
queue.WriteBuffer(buffer, value1Offset, &value1, sizeof(value1));
wgpu::ComputePipelineDescriptor csDesc;
@@ -237,9 +236,10 @@
queue.Submit(1, &commands);
EXPECT_BUFFER_U32_EQ(value0, resultBuffer, 0)
- << "maxBufferBindingSize=" << bufferSize << "; offset=" << 0 << "; usage=" << usage;
+ << "maxBufferBindingSize=" << maxBufferBindingSize << "; offset=" << 0
+ << "; usage=" << usage;
EXPECT_BUFFER_U32_EQ(value1, resultBuffer, 4)
- << "maxBufferBindingSize=" << bufferSize << "; offset=" << value1Offset
+ << "maxBufferBindingSize=" << maxBufferBindingSize << "; offset=" << value1Offset
<< "; usage=" << usage;
}
}
@@ -540,6 +540,23 @@
EXPECT_BUFFER_U32_EQ(1, result, 0);
}
+// Verifies that supported buffer limits do not exceed maxBufferSize.
+TEST_P(MaxLimitTests, MaxBufferSizes) {
+ // Base limits without tiering.
+ wgpu::Limits baseLimits = GetAdapterLimits().limits;
+ EXPECT_LE(baseLimits.maxStorageBufferBindingSize, baseLimits.maxBufferSize);
+ EXPECT_LE(baseLimits.maxUniformBufferBindingSize, baseLimits.maxBufferSize);
+
+ // Base limits eith tiering.
+ GetAdapter().SetUseTieredLimits(true);
+ wgpu::Limits tieredLimits = GetAdapterLimits().limits;
+ EXPECT_LE(tieredLimits.maxStorageBufferBindingSize, tieredLimits.maxBufferSize);
+ EXPECT_LE(tieredLimits.maxUniformBufferBindingSize, tieredLimits.maxBufferSize);
+
+ // Unset tiered limit usage to avoid affecting other tests.
+ GetAdapter().SetUseTieredLimits(false);
+}
+
DAWN_INSTANTIATE_TEST(MaxLimitTests,
D3D12Backend(),
MetalBackend(),