Dawn: Cache limits in AdapterBase

This CL make AdapterBase cache its CombinedLimits, so that getting
adapter's limits would be simplified and allow using internal non-API
method AdapterBase::GetLimits simply returning a const reference.
This CL will make generating increase limit message more directly,
helping the refactor of shader compilation.

Bug: 396323236
Change-Id: Ia8b35d483ab19a598d244cf7e66012e8436740fd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/226495
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@microsoft.com>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 985ecca..db5eed5 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -62,12 +62,16 @@
     // Cache the supported features of this adapter. Note that with device toggles overriding, a
     // device created by this adapter may support features not in this set and vice versa.
     mSupportedFeatures = mPhysicalDevice->GetSupportedFeatures(mTogglesState);
+    // Cache the limits of this adapter. UpdateLimits should be called when the adapter's
+    // limits-related status changes, e.g. SetUseTieredLimits.
+    UpdateLimits();
 }
 
 AdapterBase::~AdapterBase() = default;
 
 void AdapterBase::SetUseTieredLimits(bool useTieredLimits) {
     mUseTieredLimits = useTieredLimits;
+    UpdateLimits();
 }
 
 PhysicalDeviceBase* AdapterBase::GetPhysicalDevice() {
@@ -89,6 +93,27 @@
     return instance;
 }
 
+void AdapterBase::UpdateLimits() {
+    mLimits = mPhysicalDevice->GetLimits();
+
+    // Apply the tiered limits if needed.
+    if (mUseTieredLimits) {
+        mLimits.v1 = ApplyLimitTiers(mLimits.v1);
+    }
+
+    // TODO(crbug.com/382520104): Remove DawnExperimentalSubgroupLimits.
+    // Apply the D3D12RelaxMinSubgroupSizeTo8 toggle if enabled.
+    if (mPhysicalDevice->GetBackendType() == wgpu::BackendType::D3D12 &&
+        mTogglesState.IsEnabled(Toggle::D3D12RelaxMinSubgroupSizeTo8)) {
+        mLimits.experimentalSubgroupLimits.minSubgroupSize =
+            std::max(8u, mLimits.experimentalSubgroupLimits.minSubgroupSize);
+    }
+}
+
+const CombinedLimits& AdapterBase::GetLimits() const {
+    return mLimits;
+}
+
 wgpu::Status AdapterBase::APIGetLimits(Limits* limits) const {
     DAWN_ASSERT(limits != nullptr);
     UnpackedPtr<Limits> unpacked;
@@ -98,11 +123,7 @@
 
     {
         wgpu::ChainedStructOut* originalChain = unpacked->nextInChain;
-        if (mUseTieredLimits) {
-            **unpacked = ApplyLimitTiers(mPhysicalDevice->GetLimits().v1);
-        } else {
-            **unpacked = mPhysicalDevice->GetLimits().v1;
-        }
+        **unpacked = mLimits.v1;
         // Recover origin chain.
         unpacked->nextInChain = originalChain;
     }
@@ -120,12 +141,7 @@
             *subgroupLimits = DawnExperimentalSubgroupLimits{};
         } else {
             // If adapter supports subgroups features, always return the valid subgroup limits.
-            *subgroupLimits = mPhysicalDevice->GetLimits().experimentalSubgroupLimits;
-            if (mPhysicalDevice->GetBackendType() == wgpu::BackendType::D3D12 &&
-                mTogglesState.IsEnabled(Toggle::D3D12RelaxMinSubgroupSizeTo8)) {
-                subgroupLimits->minSubgroupSize =
-                    subgroupLimits->minSubgroupSize > 8 ? 8 : subgroupLimits->minSubgroupSize;
-            }
+            *subgroupLimits = mLimits.experimentalSubgroupLimits;
         }
 
         // Recover origin chain.
@@ -142,7 +158,7 @@
         } else {
             // If adapter supports immediate data features, always return the valid immediate data
             // limits.
-            *immediateDataLimits = mPhysicalDevice->GetLimits().experimentalImmediateDataLimits;
+            *immediateDataLimits = mLimits.experimentalImmediateDataLimits;
         }
 
         // Recover origin chain.
@@ -157,8 +173,7 @@
             // to WGPU_LIMIT_U32_UNDEFINED.
             *texelCopyBufferRowAlignmentLimits = DawnTexelCopyBufferRowAlignmentLimits{};
         } else {
-            *texelCopyBufferRowAlignmentLimits =
-                mPhysicalDevice->GetLimits().texelCopyBufferRowAlignmentLimits;
+            *texelCopyBufferRowAlignmentLimits = mLimits.texelCopyBufferRowAlignmentLimits;
         }
 
         // Recover origin chain.
diff --git a/src/dawn/native/Adapter.h b/src/dawn/native/Adapter.h
index e7a13cc..2674e67 100644
--- a/src/dawn/native/Adapter.h
+++ b/src/dawn/native/Adapter.h
@@ -71,6 +71,9 @@
     wgpu::Status APIGetFormatCapabilities(wgpu::TextureFormat format,
                                           DawnFormatCapabilities* capabilities);
 
+    // Return the limits for the adapter.
+    const CombinedLimits& GetLimits() const;
+    // Set if the adapter uses tiered limits, may result in a change in the adapter's limits.
     void SetUseTieredLimits(bool useTieredLimits);
 
     // Return the underlying PhysicalDevice.
@@ -92,10 +95,17 @@
     ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(const DeviceDescriptor* rawDescriptor,
                                                         Ref<DeviceBase::DeviceLostEvent> lostEvent);
 
+    // Generate the adapter's limits based on current adapter status. Should be called during
+    // AdapterBase creation and when the adapter's limits-related status changes, e.g.
+    // SetUseTieredLimits.
+    void UpdateLimits();
+
     Ref<InstanceBase> mInstance;
     Ref<PhysicalDeviceBase> mPhysicalDevice;
     wgpu::FeatureLevel mFeatureLevel;
     bool mUseTieredLimits = false;
+    // Limits for the adapter, tiered if mUseTieredLimits is set.
+    CombinedLimits mLimits;
 
     // Supported features under adapter toggles.
     FeaturesSet mSupportedFeatures;
diff --git a/src/dawn/native/BindGroup.cpp b/src/dawn/native/BindGroup.cpp
index 147a4b5..4303149 100644
--- a/src/dawn/native/BindGroup.cpp
+++ b/src/dawn/native/BindGroup.cpp
@@ -135,7 +135,7 @@
                             "Binding size (%u) of %s is larger than the maximum uniform buffer "
                             "binding size (%u).%s",
                             bindingSize, entry.buffer, maxUniformBufferBindingSize,
-                            DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(),
+                            DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
                                                         maxUniformBufferBindingSize, bindingSize));
             break;
         case wgpu::BufferBindingType::Storage:
@@ -146,7 +146,7 @@
                             "Binding size (%u) of %s is larger than the maximum storage buffer "
                             "binding size (%u).%s",
                             bindingSize, entry.buffer, maxStorageBufferBindingSize,
-                            DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(),
+                            DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
                                                         maxStorageBufferBindingSize, bindingSize));
             break;
         case wgpu::BufferBindingType::BindingNotUsed:
diff --git a/src/dawn/native/BindingInfo.cpp b/src/dawn/native/BindingInfo.cpp
index c014c7a..777313b 100644
--- a/src/dawn/native/BindingInfo.cpp
+++ b/src/dawn/native/BindingInfo.cpp
@@ -144,7 +144,8 @@
         "The number of dynamic uniform buffers (%u) exceeds the maximum per-pipeline-layout "
         "limit (%u).%s",
         bindingCounts.dynamicUniformBufferCount, maxDynamicUniformBuffersPerPipelineLayout,
-        DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxDynamicUniformBuffersPerPipelineLayout,
+        DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                    maxDynamicUniformBuffersPerPipelineLayout,
                                     bindingCounts.dynamicUniformBufferCount));
 
     uint32_t maxDynamicStorageBuffersPerPipelineLayout =
@@ -154,7 +155,8 @@
         "The number of dynamic storage buffers (%u) exceeds the maximum per-pipeline-layout "
         "limit (%u).%s",
         bindingCounts.dynamicStorageBufferCount, maxDynamicStorageBuffersPerPipelineLayout,
-        DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxDynamicStorageBuffersPerPipelineLayout,
+        DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                    maxDynamicStorageBuffersPerPipelineLayout,
                                     bindingCounts.dynamicStorageBufferCount));
 
     uint32_t maxSampledTexturesPerShaderStage = limits.v1.maxSampledTexturesPerShaderStage;
@@ -168,12 +170,13 @@
     uint32_t maxStorageTexturesPerShaderStage = limits.v1.maxStorageTexturesPerShaderStage;
     for (SingleShaderStage stage : IterateStages(kAllStages)) {
         uint32_t sampledTextureCount = bindingCounts.perStage[stage].sampledTextureCount;
-        DAWN_INVALID_IF(sampledTextureCount > maxSampledTexturesPerShaderStage,
-                        "The number of sampled textures (%u) in the %s stage exceeds the maximum "
-                        "per-stage limit (%u).%s",
-                        sampledTextureCount, stage, maxSampledTexturesPerShaderStage,
-                        DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxSampledTexturesPerShaderStage,
-                                                    sampledTextureCount));
+        DAWN_INVALID_IF(
+            sampledTextureCount > maxSampledTexturesPerShaderStage,
+            "The number of sampled textures (%u) in the %s stage exceeds the maximum "
+            "per-stage limit (%u).%s",
+            sampledTextureCount, stage, maxSampledTexturesPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxSampledTexturesPerShaderStage,
+                                        sampledTextureCount));
 
         uint32_t externalTextureCount = bindingCounts.perStage[stage].externalTextureCount;
         uint32_t sampledTextureAndExternalTextureCount =
@@ -184,7 +187,7 @@
             "stage exceeds the maximum per-stage limit (%u).%s",
             sampledTextureCount, externalTextureCount, kSampledTexturesPerExternalTexture, stage,
             maxSampledTexturesPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxSampledTexturesPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxSampledTexturesPerShaderStage,
                                         sampledTextureCount));
 
         uint32_t samplerCount = bindingCounts.perStage[stage].samplerCount;
@@ -194,7 +197,8 @@
             "The number of samplers (%u) in the %s stage exceeds the maximum per-stage limit "
             "(%u).%s",
             samplerCount, stage, maxSamplersPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxSamplersPerShaderStage, samplerCount));
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxSamplersPerShaderStage,
+                                        samplerCount));
 
         uint32_t samplerAndExternalTextureCount =
             samplerCount + (externalTextureCount * kSamplersPerExternalTexture);
@@ -205,7 +209,7 @@
             "exceeds the maximum per-stage limit (%u).%s",
             samplerCount, externalTextureCount, kSamplersPerExternalTexture, stage,
             maxSamplersPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxSamplersPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxSamplersPerShaderStage,
                                         samplerAndExternalTextureCount));
 
         uint32_t storageBufferCount = bindingCounts.perStage[stage].storageBufferCount;
@@ -214,7 +218,7 @@
             "The number of storage buffers (%u) in the %s stage exceeds the maximum per-stage "
             "limit (%u).%s",
             storageBufferCount, stage, maxStorageBuffersPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxStorageBuffersPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxStorageBuffersPerShaderStage,
                                         storageBufferCount));
 
         uint32_t storageTextureCount = bindingCounts.perStage[stage].storageTextureCount;
@@ -223,7 +227,7 @@
             "The number of storage textures (%u) in the %s stage exceeds the maximum per-stage "
             "limit (%u).%s",
             storageTextureCount, stage, maxStorageTexturesPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxStorageTexturesPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxStorageTexturesPerShaderStage,
                                         storageTextureCount));
 
         uint32_t uniformBufferCount = bindingCounts.perStage[stage].uniformBufferCount;
@@ -232,7 +236,7 @@
             "The number of uniform buffers (%u) in the %s stage exceeds the maximum per-stage "
             "limit (%u).%s",
             uniformBufferCount, stage, maxUniformBuffersPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxUniformBuffersPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxUniformBuffersPerShaderStage,
                                         uniformBufferCount));
 
         uint32_t uniformBuffersAndExternalTextureCount =
@@ -243,7 +247,7 @@
             "stage exceeds the maximum per-stage limit (%u).%s",
             uniformBufferCount, externalTextureCount, kUniformsPerExternalTexture, stage,
             maxUniformBuffersPerShaderStage,
-            DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxUniformBuffersPerShaderStage,
+            DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxUniformBuffersPerShaderStage,
                                         uniformBuffersAndExternalTextureCount));
 
         switch (stage) {
@@ -252,29 +256,32 @@
                                 "number of storage buffers used in fragment stage (%u) exceeds "
                                 "maxStorageBuffersInFragmentStage (%u).%s",
                                 storageBufferCount, maxStorageBuffersInFragmentStage,
-                                DAWN_INCREASE_LIMIT_MESSAGE(
-                                    adapter, maxStorageBuffersInFragmentStage, storageBufferCount));
-                DAWN_INVALID_IF(
-                    storageTextureCount > maxStorageTexturesInFragmentStage,
-                    "number of storage textures used in fragment stage (%u) exceeds "
-                    "maxStorageTexturesInFragmentStage (%u).%s",
-                    storageTextureCount, maxStorageTexturesInFragmentStage,
-                    DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxStorageTexturesInFragmentStage,
-                                                storageTextureCount));
+                                DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                                            maxStorageBuffersInFragmentStage,
+                                                            storageBufferCount));
+                DAWN_INVALID_IF(storageTextureCount > maxStorageTexturesInFragmentStage,
+                                "number of storage textures used in fragment stage (%u) exceeds "
+                                "maxStorageTexturesInFragmentStage (%u).%s",
+                                storageTextureCount, maxStorageTexturesInFragmentStage,
+                                DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                                            maxStorageTexturesInFragmentStage,
+                                                            storageTextureCount));
                 break;
             case SingleShaderStage::Vertex:
                 DAWN_INVALID_IF(storageBufferCount > maxStorageBuffersInVertexStage,
                                 "number of storage buffers used in vertex stage (%u) exceeds "
                                 "maxStorageBuffersInVertexStage (%u).%s",
                                 storageBufferCount, maxStorageBuffersInVertexStage,
-                                DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxStorageBuffersInVertexStage,
+                                DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                                            maxStorageBuffersInVertexStage,
                                                             storageBufferCount));
                 DAWN_INVALID_IF(storageTextureCount > maxStorageTexturesInVertexStage,
                                 "number of storage textures used in vertex stage (%u) exceeds "
                                 "maxStorageTexturesInVertexStage (%u).%s",
                                 storageTextureCount, maxStorageTexturesInVertexStage,
-                                DAWN_INCREASE_LIMIT_MESSAGE(
-                                    adapter, maxStorageTexturesInVertexStage, storageTextureCount));
+                                DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                                            maxStorageTexturesInVertexStage,
+                                                            storageTextureCount));
                 break;
             default:
                 break;
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index e3b4b6d..77b5d39 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -324,11 +324,11 @@
                     descriptor->size);
 
     uint64_t maxBufferSize = device->GetLimits().v1.maxBufferSize;
-    DAWN_INVALID_IF(
-        descriptor->size > maxBufferSize,
-        "Buffer size (%u) exceeds the max buffer size limit (%u).%s", descriptor->size,
-        maxBufferSize,
-        DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxBufferSize, descriptor->size));
+    DAWN_INVALID_IF(descriptor->size > maxBufferSize,
+                    "Buffer size (%u) exceeds the max buffer size limit (%u).%s", descriptor->size,
+                    maxBufferSize,
+                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1, maxBufferSize,
+                                                descriptor->size));
 
     return unpacked;
 }
diff --git a/src/dawn/native/CommandEncoder.cpp b/src/dawn/native/CommandEncoder.cpp
index 601f965..3cc9455 100644
--- a/src/dawn/native/CommandEncoder.cpp
+++ b/src/dawn/native/CommandEncoder.cpp
@@ -754,7 +754,7 @@
         descriptor->colorAttachmentCount > maxColorAttachments,
         "Color attachment count (%u) exceeds the maximum number of color attachments (%u).%s",
         descriptor->colorAttachmentCount, maxColorAttachments,
-        DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxColorAttachments,
+        DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1, maxColorAttachments,
                                     descriptor->colorAttachmentCount));
 
     auto colorAttachments = ityp::SpanFromUntyped<ColorAttachmentIndex>(
diff --git a/src/dawn/native/CommandValidation.cpp b/src/dawn/native/CommandValidation.cpp
index 863d535..7fa92a3 100644
--- a/src/dawn/native/CommandValidation.cpp
+++ b/src/dawn/native/CommandValidation.cpp
@@ -715,8 +715,8 @@
         "Total color attachment bytes per sample (%u) exceeds maximum (%u) with formats "
         "(%s).%s",
         totalByteSize, maxColorAttachmentBytesPerSample, TextureFormatsToString(formats),
-        DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxColorAttachmentBytesPerSample,
-                                    totalByteSize));
+        DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
+                                    maxColorAttachmentBytesPerSample, totalByteSize));
 
     return {};
 }
diff --git a/src/dawn/native/ComputePassEncoder.cpp b/src/dawn/native/ComputePassEncoder.cpp
index 1e023fc..8851838 100644
--- a/src/dawn/native/ComputePassEncoder.cpp
+++ b/src/dawn/native/ComputePassEncoder.cpp
@@ -221,7 +221,7 @@
                     "Dispatch workgroup count X (%u) exceeds max compute "
                     "workgroups per dimension (%u).%s",
                     workgroupCountX, maxComputeWorkgroupsPerDimension,
-                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter(),
+                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter()->GetLimits().v1,
                                                 maxComputeWorkgroupsPerDimension, workgroupCountX));
 
                 DAWN_INVALID_IF(
@@ -229,7 +229,7 @@
                     "Dispatch workgroup count Y (%u) exceeds max compute "
                     "workgroups per dimension (%u).%s",
                     workgroupCountY, maxComputeWorkgroupsPerDimension,
-                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter(),
+                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter()->GetLimits().v1,
                                                 maxComputeWorkgroupsPerDimension, workgroupCountY));
 
                 DAWN_INVALID_IF(
@@ -237,7 +237,7 @@
                     "Dispatch workgroup count Z (%u) exceeds max compute "
                     "workgroups per dimension (%u).%s",
                     workgroupCountZ, maxComputeWorkgroupsPerDimension,
-                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter(),
+                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter()->GetLimits().v1,
                                                 maxComputeWorkgroupsPerDimension, workgroupCountZ));
 
                 if (!GetDevice()->HasFlexibleTextureViews()) {
diff --git a/src/dawn/native/Error.h b/src/dawn/native/Error.h
index c5dd0fd..45a5ddc 100644
--- a/src/dawn/native/Error.h
+++ b/src/dawn/native/Error.h
@@ -159,15 +159,11 @@
         limitName, adapterLimitValue);
 }
 
-#define DAWN_INCREASE_LIMIT_MESSAGE(adapter, limitName, limitValue)                           \
-    [&]() -> std::string {                                                                    \
-        ::dawn::native::Limits adapterLimits;                                                 \
-        wgpu::Status status = adapter->APIGetLimits(&adapterLimits);                          \
-        DAWN_ASSERT(status == wgpu::Status::Success);                                         \
-        if (limitValue > adapterLimits.limitName) {                                           \
-            return "";                                                                        \
-        }                                                                                     \
-        return ::dawn::native::MakeIncreaseLimitMessage(#limitName, adapterLimits.limitName); \
+#define DAWN_INCREASE_LIMIT_MESSAGE(adapterLimits, limitName, limitValue)                         \
+    [&]() -> std::string {                                                                        \
+        return (limitValue > adapterLimits.limitName) ? ""                                        \
+                                                      : ::dawn::native::MakeIncreaseLimitMessage( \
+                                                            #limitName, adapterLimits.limitName); \
     }()
 
 #define DAWN_CONCAT1(x, y) x##y
diff --git a/src/dawn/native/RenderBundleEncoder.cpp b/src/dawn/native/RenderBundleEncoder.cpp
index 7108664..5beaa06 100644
--- a/src/dawn/native/RenderBundleEncoder.cpp
+++ b/src/dawn/native/RenderBundleEncoder.cpp
@@ -74,8 +74,8 @@
     DAWN_INVALID_IF(descriptor->colorFormatCount > maxColorAttachments,
                     "Color formats count (%u) exceeds maximum number of color attachments (%u).%s",
                     descriptor->colorFormatCount, maxColorAttachments,
-                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxColorAttachments,
-                                                descriptor->colorFormatCount));
+                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
+                                                maxColorAttachments, descriptor->colorFormatCount));
 
     bool allColorFormatsUndefined = true;
     ColorAttachmentFormats colorAttachmentFormats;
diff --git a/src/dawn/native/RenderPassEncoder.cpp b/src/dawn/native/RenderPassEncoder.cpp
index 725c9e3..72c53fc 100644
--- a/src/dawn/native/RenderPassEncoder.cpp
+++ b/src/dawn/native/RenderPassEncoder.cpp
@@ -255,17 +255,18 @@
                     "Viewport bounds (width: %f, height: %f) contains a negative value.", width,
                     height);
 
-                DAWN_INVALID_IF(width > maxViewportSize,
-                                "Viewport width (%f) exceeds the maximum (%u).%s", width,
-                                maxViewportSize,
-                                DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter(),
-                                                            maxTextureDimension2D, width));
+                DAWN_INVALID_IF(
+                    width > maxViewportSize, "Viewport width (%f) exceeds the maximum (%u).%s",
+                    width, maxViewportSize,
+                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter()->GetLimits().v1,
+                                                maxTextureDimension2D, width));
 
-                DAWN_INVALID_IF(height > maxViewportSize,
-                                "Viewport size height (%f) exceeds the maximum (%u).%s", height,
-                                maxViewportSize,
-                                DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter(),
-                                                            maxTextureDimension2D, height));
+                DAWN_INVALID_IF(
+                    height > maxViewportSize,
+                    "Viewport size height (%f) exceeds the maximum (%u).%s", height,
+                    maxViewportSize,
+                    DAWN_INCREASE_LIMIT_MESSAGE(GetDevice()->GetAdapter()->GetLimits().v1,
+                                                maxTextureDimension2D, height));
 
                 DAWN_INVALID_IF(x < -maxViewportBounds || y < -maxViewportBounds,
                                 "Viewport offset (x: %f, y: %f) is less than the minimum "
diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp
index bbc9716..d4a854b 100644
--- a/src/dawn/native/RenderPipeline.cpp
+++ b/src/dawn/native/RenderPipeline.cpp
@@ -199,8 +199,8 @@
     DAWN_INVALID_IF(descriptor->bufferCount > maxVertexBuffers,
                     "Vertex buffer count (%u) exceeds the maximum number of vertex buffers (%u).%s",
                     descriptor->bufferCount, maxVertexBuffers,
-                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxVertexBuffers,
-                                                descriptor->bufferCount));
+                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
+                                                maxVertexBuffers, descriptor->bufferCount));
 
     ShaderModuleEntryPoint entryPoint;
     DAWN_TRY_ASSIGN_CONTEXT(
@@ -661,8 +661,8 @@
     DAWN_INVALID_IF(descriptor->targetCount > maxColorAttachments,
                     "Number of targets (%u) exceeds the maximum (%u).%s", descriptor->targetCount,
                     maxColorAttachments,
-                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter(), maxColorAttachments,
-                                                descriptor->targetCount));
+                    DAWN_INCREASE_LIMIT_MESSAGE(device->GetAdapter()->GetLimits().v1,
+                                                maxColorAttachments, descriptor->targetCount));
 
     auto targets =
         ityp::SpanFromUntyped<ColorAttachmentIndex>(descriptor->targets, descriptor->targetCount);
diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp
index da85c5f..57cd65c 100644
--- a/src/dawn/native/ShaderModule.cpp
+++ b/src/dawn/native/ShaderModule.cpp
@@ -1180,12 +1180,12 @@
 
     uint64_t numInvocations = static_cast<uint64_t>(x) * y * z;
     uint32_t maxComputeInvocationsPerWorkgroup = limits.maxComputeInvocationsPerWorkgroup;
-    DAWN_INVALID_IF(
-        numInvocations > maxComputeInvocationsPerWorkgroup,
-        "The total number of workgroup invocations (%u) exceeds the "
-        "maximum allowed (%u).%s",
-        numInvocations, maxComputeInvocationsPerWorkgroup,
-        DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxComputeInvocationsPerWorkgroup, numInvocations));
+    DAWN_INVALID_IF(numInvocations > maxComputeInvocationsPerWorkgroup,
+                    "The total number of workgroup invocations (%u) exceeds the "
+                    "maximum allowed (%u).%s",
+                    numInvocations, maxComputeInvocationsPerWorkgroup,
+                    DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1,
+                                                maxComputeInvocationsPerWorkgroup, numInvocations));
 
     uint32_t maxComputeWorkgroupStorageSize = limits.maxComputeWorkgroupStorageSize;
     DAWN_INVALID_IF(
@@ -1193,7 +1193,8 @@
         "The total use of workgroup storage (%u bytes) is larger than "
         "the maximum allowed (%u bytes).%s",
         workgroupStorageSize, maxComputeWorkgroupStorageSize,
-        DAWN_INCREASE_LIMIT_MESSAGE(adapter, maxComputeWorkgroupStorageSize, workgroupStorageSize));
+        DAWN_INCREASE_LIMIT_MESSAGE(adapter->GetLimits().v1, maxComputeWorkgroupStorageSize,
+                                    workgroupStorageSize));
 
     if (usesSubgroupMatrix) {
         uint32_t maxSubgroupSize = adapter->GetPhysicalDevice()->GetSubgroupMaxSize();