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>
This commit is contained in:
Loko Kung 2023-03-02 21:51:03 +00:00 committed by Dawn LUCI CQ
parent 6cc183c85a
commit 861dfd89e8
5 changed files with 37 additions and 8 deletions

View File

@ -71,6 +71,12 @@ MaybeError AdapterBase::Initialize() {
mLimits.v1.maxUniformBuffersPerShaderStage = mLimits.v1.maxUniformBuffersPerShaderStage =
std::min(mLimits.v1.maxUniformBuffersPerShaderStage, kMaxUniformBuffersPerShaderStage); 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 {}; return {};
} }

View File

@ -68,7 +68,6 @@
X(Alignment, minUniformBufferOffsetAlignment, 256, 256) \ X(Alignment, minUniformBufferOffsetAlignment, 256, 256) \
X(Alignment, minStorageBufferOffsetAlignment, 256, 256) \ X(Alignment, minStorageBufferOffsetAlignment, 256, 256) \
X(Maximum, maxVertexBuffers, 8, 8) \ X(Maximum, maxVertexBuffers, 8, 8) \
X(Maximum, maxBufferSize, 268435456, 268435456) \
X(Maximum, maxVertexAttributes, 16, 16) \ X(Maximum, maxVertexAttributes, 16, 16) \
X(Maximum, maxVertexBufferArrayStride, 2048, 2048) \ X(Maximum, maxVertexBufferArrayStride, 2048, 2048) \
X(Maximum, maxInterStageShaderComponents, 60, 60) \ X(Maximum, maxInterStageShaderComponents, 60, 60) \

View File

@ -815,6 +815,12 @@ const wgpu::AdapterProperties& DawnTestBase::GetAdapterProperties() const {
return mParam.adapterProperties; return mParam.adapterProperties;
} }
wgpu::SupportedLimits DawnTestBase::GetAdapterLimits() {
wgpu::SupportedLimits supportedLimits = {};
mAdapter.GetLimits(&supportedLimits);
return supportedLimits;
}
wgpu::SupportedLimits DawnTestBase::GetSupportedLimits() { wgpu::SupportedLimits DawnTestBase::GetSupportedLimits() {
wgpu::SupportedLimits supportedLimits = {}; wgpu::SupportedLimits supportedLimits = {};
device.GetLimits(&supportedLimits); device.GetLimits(&supportedLimits);

View File

@ -564,6 +564,7 @@ class DawnTestBase {
const wgpu::AdapterProperties& GetAdapterProperties() const; const wgpu::AdapterProperties& GetAdapterProperties() const;
wgpu::SupportedLimits GetAdapterLimits();
wgpu::SupportedLimits GetSupportedLimits(); wgpu::SupportedLimits GetSupportedLimits();
private: private:

View File

@ -113,8 +113,6 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
// TODO(dawn:1549) Fails on Qualcomm-based Android devices. // TODO(dawn:1549) Fails on Qualcomm-based Android devices.
DAWN_SUPPRESS_TEST_IF(IsAndroid() && IsQualcomm()); 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}) { for (wgpu::BufferUsage usage : {wgpu::BufferUsage::Storage, wgpu::BufferUsage::Uniform}) {
uint64_t maxBufferBindingSize; uint64_t maxBufferBindingSize;
@ -136,6 +134,7 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
maxBufferBindingSize = maxBufferBindingSize =
std::min(maxBufferBindingSize, uint64_t(512) * 1024 * 1024); std::min(maxBufferBindingSize, uint64_t(512) * 1024 * 1024);
} }
maxBufferBindingSize = Align(maxBufferBindingSize - 3u, 4);
shader = R"( shader = R"(
struct Buf { struct Buf {
values : array<u32> values : array<u32>
@ -162,6 +161,7 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
// Clamp to not exceed the maximum i32 value for the WGSL @size(x) annotation. // Clamp to not exceed the maximum i32 value for the WGSL @size(x) annotation.
maxBufferBindingSize = std::min(maxBufferBindingSize, maxBufferBindingSize = std::min(maxBufferBindingSize,
uint64_t(std::numeric_limits<int32_t>::max()) + 8); uint64_t(std::numeric_limits<int32_t>::max()) + 8);
maxBufferBindingSize = Align(maxBufferBindingSize - 3u, 4);
shader = R"( shader = R"(
struct Buf { struct Buf {
@ -194,8 +194,7 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory); device.PushErrorScope(wgpu::ErrorFilter::OutOfMemory);
wgpu::BufferDescriptor bufDesc; wgpu::BufferDescriptor bufDesc;
uint64_t bufferSize = Align(maxBufferBindingSize - 3u, 4); bufDesc.size = maxBufferBindingSize;
bufDesc.size = bufferSize;
bufDesc.usage = usage | wgpu::BufferUsage::CopyDst; bufDesc.usage = usage | wgpu::BufferUsage::CopyDst;
wgpu::Buffer buffer = device.CreateBuffer(&bufDesc); wgpu::Buffer buffer = device.CreateBuffer(&bufDesc);
@ -216,7 +215,7 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
queue.WriteBuffer(buffer, 0, &value0, sizeof(value0)); queue.WriteBuffer(buffer, 0, &value0, sizeof(value0));
uint32_t value1 = 234; 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)); queue.WriteBuffer(buffer, value1Offset, &value1, sizeof(value1));
wgpu::ComputePipelineDescriptor csDesc; wgpu::ComputePipelineDescriptor csDesc;
@ -237,9 +236,10 @@ TEST_P(MaxLimitTests, MaxBufferBindingSize) {
queue.Submit(1, &commands); queue.Submit(1, &commands);
EXPECT_BUFFER_U32_EQ(value0, resultBuffer, 0) 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) EXPECT_BUFFER_U32_EQ(value1, resultBuffer, 4)
<< "maxBufferBindingSize=" << bufferSize << "; offset=" << value1Offset << "maxBufferBindingSize=" << maxBufferBindingSize << "; offset=" << value1Offset
<< "; usage=" << usage; << "; usage=" << usage;
} }
} }
@ -540,6 +540,23 @@ TEST_P(MaxLimitTests, ReallyLargeBindGroup) {
EXPECT_BUFFER_U32_EQ(1, result, 0); 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, DAWN_INSTANTIATE_TEST(MaxLimitTests,
D3D12Backend(), D3D12Backend(),
MetalBackend(), MetalBackend(),