[dawn][emscripten] Fix ComboLimits compilation on Emscripten
A single copy of ComboLimits is used for both Dawn and Emscripten
targets, but it's generated with Dawn tags. Rather than try to generate
multiple copies of it (and move it to some other path), generate ifdefs
to make it work correctly on both (and switch it to params_all since
it's actually for all targets, not Dawn).
Bug: none
Change-Id: I7344c792a11117a715a5b9941ec8dbb27c726077
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/245240
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Auto-Submit: Kai Ninomiya <kainino@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 9ef1f92..04be3149 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -311,6 +311,8 @@
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 = {}
@@ -1401,11 +1403,11 @@
renders.append(
FileRender('dawn/utils/ComboLimits.h',
'src/dawn/utils/ComboLimits.h',
- [RENDER_PARAMS_BASE, params_dawn]))
+ [RENDER_PARAMS_BASE, params_all]))
renders.append(
FileRender('dawn/utils/ComboLimits.cpp',
'src/dawn/utils/ComboLimits.cpp',
- [RENDER_PARAMS_BASE, params_dawn]))
+ [RENDER_PARAMS_BASE, params_all]))
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 91581b5..d69e147 100644
--- a/generator/templates/dawn/utils/ComboLimits.cpp
+++ b/generator/templates/dawn/utils/ComboLimits.cpp
@@ -32,23 +32,31 @@
{% set limits_and_extensions = [types['limits']] + types['limits'].extensions %}
void ComboLimits::UnlinkedCopyTo(ComboLimits* dst) const {
- {% for type in limits_and_extensions %}
+ {% for type in limits_and_extensions if not type.ifndef_emscripten %}
*static_cast<wgpu::{{as_cppType(type.name)}}*>(dst) = *this;
- {% endfor %}
- {% for type in limits_and_extensions %}
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() {
- {% for type in limits_and_extensions %}
+ 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 =
- {% if loop.nextitem %}
- static_cast<wgpu::{{as_cppType(loop.nextitem.name)}}*>(this);
- {% else %}
- nullptr;
- {% endif %}
{% 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;
}
diff --git a/generator/templates/dawn/utils/ComboLimits.h b/generator/templates/dawn/utils/ComboLimits.h
index df3a352..cfa16db 100644
--- a/generator/templates/dawn/utils/ComboLimits.h
+++ b/generator/templates/dawn/utils/ComboLimits.h
@@ -35,9 +35,14 @@
{% set limits_and_extensions = [types['limits']] + types['limits'].extensions %}
class ComboLimits : public NonMovable
- {% for type in limits_and_extensions %}
- , private wgpu::{{as_cppType(type.name)}}
+ {% for type in limits_and_extensions if not type.ifndef_emscripten %}
+ , 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();
@@ -49,12 +54,19 @@
// 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();
- {% for type in limits_and_extensions %}
+ {% for type in limits_and_extensions if not type.ifndef_emscripten %}
{% 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