[dawn] Make ComboLimits chain only standard limits extensions by default
Some experimental limit extensions are currently output-only
(DawnTexelCopyBufferRowAlignmentLimits and DawnHostMappedPointerLimits
are ignored in requiredLimits, and operations are not validated against
them). Remove these experimental extensions from ComboLimits to stop
warning span about that problem. This also obsoletes the #ifdef
__EMSCRIPTEN__ that I used previously to make this work on Wasm.
Instead, callers can pass any additional extensions to GetLinked() as
variadic type-inferred arguments. Two tests are updated to use this.
Also revert 2987f3c04d9b4f401dbe4fac6a52832ff90f17aa
"[dawn][wasm] Fixes WASM builds by excluding native utils."
since that should no longer be necessary.
Fixed: 416304914
Change-Id: I268a48180f30bddfbcc42955fc8682263fdaba7f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/249114
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index b3fee3d..48e2ef3 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -317,8 +317,6 @@
assert name.startswith('emscripten'), name
else:
assert not name.startswith('emscripten'), name
- self.ifndef_emscripten = len(
- tags) and 'emscripten' not in tags and 'compat' not in tags
Record.__init__(self, name)
json_data_override = {}
@@ -1409,14 +1407,18 @@
frontend_params))
if 'dawn_utils' in targets:
+ # Generate ComboLimits without any extensions so it works on
+ # all targets (and doesn't chain any experimental stuff like
+ # extensions that are output only and produce warnings on input).
+ params = parse_json(loaded_json, enabled_tags=['compat'])
renders.append(
FileRender('dawn/utils/ComboLimits.h',
'src/dawn/utils/ComboLimits.h',
- [RENDER_PARAMS_BASE, params_all]))
+ [RENDER_PARAMS_BASE, params]))
renders.append(
FileRender('dawn/utils/ComboLimits.cpp',
'src/dawn/utils/ComboLimits.cpp',
- [RENDER_PARAMS_BASE, params_all]))
+ [RENDER_PARAMS_BASE, params]))
if 'wire' in targets:
params_dawn_wire = parse_json(
diff --git a/generator/templates/dawn/utils/ComboLimits.cpp b/generator/templates/dawn/utils/ComboLimits.cpp
index d69e147..b6939bf 100644
--- a/generator/templates/dawn/utils/ComboLimits.cpp
+++ b/generator/templates/dawn/utils/ComboLimits.cpp
@@ -32,32 +32,10 @@
{% set limits_and_extensions = [types['limits']] + types['limits'].extensions %}
void ComboLimits::UnlinkedCopyTo(ComboLimits* dst) const {
- {% for type in limits_and_extensions if not type.ifndef_emscripten %}
+ {% for type in limits_and_extensions %}
*static_cast<wgpu::{{as_cppType(type.name)}}*>(dst) = *this;
dst->wgpu::{{as_cppType(type.name)}}::nextInChain = nullptr;
{% endfor %}
-#ifndef __EMSCRIPTEN__
- {% for type in limits_and_extensions if type.ifndef_emscripten %}
- *static_cast<wgpu::{{as_cppType(type.name)}}*>(dst) = *this;
- dst->wgpu::{{as_cppType(type.name)}}::nextInChain = nullptr;
- {% endfor %}
-#endif
-}
-
-wgpu::Limits* ComboLimits::GetLinked() {
- this->wgpu::Limits::nextInChain =
- {% for type in types['limits'].extensions if not type.ifndef_emscripten%}
- static_cast<wgpu::{{as_cppType(type.name)}}*>(this);
- this->wgpu::{{as_cppType(type.name)}}::nextInChain =
- {% endfor %}
-#ifndef __EMSCRIPTEN__
- {% for type in types['limits'].extensions if type.ifndef_emscripten %}
- static_cast<wgpu::{{as_cppType(type.name)}}*>(this);
- this->wgpu::{{as_cppType(type.name)}}::nextInChain =
- {% endfor %}
-#endif
- nullptr;
- return this;
}
} // namespace dawn::utils
diff --git a/generator/templates/dawn/utils/ComboLimits.h b/generator/templates/dawn/utils/ComboLimits.h
index cfa16db..88b99d6 100644
--- a/generator/templates/dawn/utils/ComboLimits.h
+++ b/generator/templates/dawn/utils/ComboLimits.h
@@ -35,14 +35,9 @@
{% set limits_and_extensions = [types['limits']] + types['limits'].extensions %}
class ComboLimits : public NonMovable
- {% for type in limits_and_extensions if not type.ifndef_emscripten %}
+ {% for type in limits_and_extensions %}
, private wgpu::{{as_cppType(type.name)}}
{% endfor %}
-#ifndef __EMSCRIPTEN__
- {% for type in limits_and_extensions if type.ifndef_emscripten %}
- , private wgpu::{{as_cppType(type.name)}}
- {% endfor %}
-#endif
{
public:
ComboLimits();
@@ -52,21 +47,33 @@
void UnlinkedCopyTo(ComboLimits*) const;
// Modify the ComboLimits in-place to link the extension structs correctly, and return the base
- // struct. Use this (rather than &comboLimits) whenever passing a ComboLimits to the API.
- wgpu::Limits* GetLinked();
+ // struct. Optionally accepts any number of additional structs to add to the
+ // end of the chain, e.g.: `comboLimits.GetLinked(&extension1, &extension2)`.
+ // Always use GetLinked (rather than `&comboLimits`) whenever passing a ComboLimits to the API.
+ template <typename... Extension>
+ requires (std::convertible_to<Extension, wgpu::ChainedStructOut*> && ...)
+ wgpu::Limits* GetLinked(Extension... extension) {
+ wgpu::ChainedStructOut* lastExtension = nullptr;
+ // Link all of the standard extensions.
+ {% for type in types['limits'].extensions %}
+ {% if loop.first %}
+ lastExtension = this->wgpu::Limits::nextInChain =
+ {% else %}
+ lastExtension = lastExtension->nextInChain =
+ {% endif %}
+ static_cast<wgpu::{{as_cppType(type.name)}}*>(this);
+ {% endfor %}
+ // Link any extensions passed by the caller.
+ ((lastExtension = lastExtension->nextInChain = extension), ...);
+ lastExtension->nextInChain = nullptr;
+ return this;
+ }
- {% for type in limits_and_extensions if not type.ifndef_emscripten %}
+ {% for type in limits_and_extensions %}
{% for member in type.members %}
using wgpu::{{as_cppType(type.name)}}::{{as_varName(member.name)}};
{% endfor %}
{% endfor %}
-#ifndef __EMSCRIPTEN__
- {% for type in limits_and_extensions if type.ifndef_emscripten %}
- {% for member in type.members %}
- using wgpu::{{as_cppType(type.name)}}::{{as_varName(member.name)}};
- {% endfor %}
- {% endfor %}
-#endif
};
} // namespace dawn::utils
diff --git a/src/dawn/native/Limits.cpp b/src/dawn/native/Limits.cpp
index 450f155..4d5bf9e 100644
--- a/src/dawn/native/Limits.cpp
+++ b/src/dawn/native/Limits.cpp
@@ -282,7 +282,7 @@
}
if (unpacked.Get<DawnHostMappedPointerLimits>()) {
- dawn::WarningLog() << "hostMappedPointerLimits is not supported in required limits";
+ dawn::WarningLog() << "DawnHostMappedPointerLimits is not supported in required limits";
}
return {};
diff --git a/src/dawn/tests/end2end/BufferHostMappedPointerTests.cpp b/src/dawn/tests/end2end/BufferHostMappedPointerTests.cpp
index f2eb109..edbf9f1 100644
--- a/src/dawn/tests/end2end/BufferHostMappedPointerTests.cpp
+++ b/src/dawn/tests/end2end/BufferHostMappedPointerTests.cpp
@@ -51,10 +51,9 @@
DawnTestWithParams<BufferHostMappedPointerTestParams>::SetUp();
DAWN_TEST_UNSUPPORTED_IF(!SupportsFeatures({wgpu::FeatureName::HostMappedPointer}));
- wgpu::Limits limits;
+ dawn::utils::ComboLimits limits;
wgpu::DawnHostMappedPointerLimits hostAlignmentLimits;
- limits.nextInChain = &hostAlignmentLimits;
- device.GetLimits(&limits);
+ device.GetLimits(limits.GetLinked(&hostAlignmentLimits));
ASSERT_TRUE(dawn::IsPowerOfTwo(hostAlignmentLimits.hostMappedPointerAlignment));
mRequiredAlignment = hostAlignmentLimits.hostMappedPointerAlignment;
diff --git a/src/dawn/tests/end2end/CopyTests.cpp b/src/dawn/tests/end2end/CopyTests.cpp
index 6aa55b5..182b0c4 100644
--- a/src/dawn/tests/end2end/CopyTests.cpp
+++ b/src/dawn/tests/end2end/CopyTests.cpp
@@ -420,10 +420,9 @@
if (!device.HasFeature(wgpu::FeatureName::DawnTexelCopyBufferRowAlignment)) {
return kTextureBytesPerRowAlignment;
}
- wgpu::Limits limits{};
+ dawn::utils::ComboLimits limits;
wgpu::DawnTexelCopyBufferRowAlignmentLimits alignmentLimits{};
- limits.nextInChain = &alignmentLimits;
- device.GetLimits(&limits);
+ device.GetLimits(limits.GetLinked(&alignmentLimits));
return alignmentLimits.minTexelCopyBufferRowAlignment;
}
BufferSpec MinimumBufferSpec(uint32_t width, uint32_t height, uint32_t depth = 1) {
diff --git a/src/dawn/utils/BUILD.gn b/src/dawn/utils/BUILD.gn
index de214b6..7641e14 100644
--- a/src/dawn/utils/BUILD.gn
+++ b/src/dawn/utils/BUILD.gn
@@ -50,7 +50,8 @@
"${dawn_root}/src/tint:tint_public_config",
]
- sources = [
+ sources = get_target_outputs(":dawn_utils_gen")
+ sources += [
"ComboRenderBundleEncoderDescriptor.cpp",
"ComboRenderBundleEncoderDescriptor.h",
"ComboRenderPipelineDescriptor.cpp",
@@ -61,20 +62,11 @@
"WGPUHelpers.h",
]
- if (!is_wasm) {
- # TODO(crbug.com/422530025): Currently the generated files cannot be used with WASM.
- sources += get_target_outputs(":dawn_utils_gen")
- }
-
public_deps = [
"${dawn_root}/include/dawn:cpp_headers",
"${dawn_root}/src/dawn/common",
]
- deps = []
- if (!is_wasm) {
- # TODO(crbug.com/422530025): Currently the generated files cannot be used with WASM.
- deps += [ ":dawn_utils_gen" ]
- }
+ deps = [ ":dawn_utils_gen" ]
if (tint_build_spv_reader) {
deps += [ "${dawn_spirv_tools_dir}:spvtools_opt" ]
}
diff --git a/src/dawn/utils/CMakeLists.txt b/src/dawn/utils/CMakeLists.txt
index 929f0e9..7523bb5 100644
--- a/src/dawn/utils/CMakeLists.txt
+++ b/src/dawn/utils/CMakeLists.txt
@@ -34,15 +34,12 @@
list(APPEND private_wgpu_depends SPIRV-Tools-opt)
endif()
-# TODO(crbug.com/422530025): Currently the generated files cannot be used with WASM.
-if (NOT EMSCRIPTEN)
- DawnJSONGenerator(
- TARGET "dawn_utils"
- PRINT_NAME "Dawn native utilities"
- OUTPUT_HEADERS DAWN_UTILS_GEN_HEADERS
- OUTPUT_SOURCES DAWN_UTILS_GEN_SOURCES
- )
-endif()
+DawnJSONGenerator(
+ TARGET "dawn_utils"
+ PRINT_NAME "Dawn native utilities"
+ OUTPUT_HEADERS DAWN_UTILS_GEN_HEADERS
+ OUTPUT_SOURCES DAWN_UTILS_GEN_SOURCES
+)
dawn_add_library(
dawn_wgpu_utils
ENABLE_EMSCRIPTEN