diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 6a89240467..35638ccb20 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -901,11 +901,11 @@ class MultiGeneratorFromDawnJSON(Generator): 'src/dawn_native/ProcTable.cpp', frontend_params)) renders.append( FileRender('dawn_native/ChainUtils.h', - 'src/dawn_native/ChainUtils_autogen.h', + 'src/' + native_dir + '/ChainUtils_autogen.h', frontend_params)) renders.append( FileRender('dawn_native/ChainUtils.cpp', - 'src/dawn_native/ChainUtils_autogen.cpp', + 'src/' + native_dir + '/ChainUtils_autogen.cpp', frontend_params)) renders.append( FileRender('dawn_native/webgpu_absl_format.h', @@ -917,11 +917,11 @@ class MultiGeneratorFromDawnJSON(Generator): frontend_params)) renders.append( FileRender('dawn_native/ObjectType.h', - 'src/dawn_native/ObjectType_autogen.h', + 'src/' + native_dir + '/ObjectType_autogen.h', frontend_params)) renders.append( FileRender('dawn_native/ObjectType.cpp', - 'src/dawn_native/ObjectType_autogen.cpp', + 'src/' + native_dir + '/ObjectType_autogen.cpp', frontend_params)) if 'dawn_wire' in targets: diff --git a/generator/templates/dawn_native/ChainUtils.cpp b/generator/templates/dawn_native/ChainUtils.cpp index 2a42db2a32..11d150b39b 100644 --- a/generator/templates/dawn_native/ChainUtils.cpp +++ b/generator/templates/dawn_native/ChainUtils.cpp @@ -12,17 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "dawn_native/ChainUtils_autogen.h" +{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %} +{% set native_namespace = Name(metadata.native_namespace).snake_case() %} +{% set native_dir = impl_dir + native_namespace %} +#include "{{native_dir}}/ChainUtils_autogen.h" #include -namespace dawn_native { +namespace {{native_namespace}} { +{% set namespace = metadata.namespace %} {% for value in types["s type"].values %} {% if value.valid %} void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out) { for (; chain; chain = chain->nextInChain) { - if (chain->sType == wgpu::SType::{{as_cppEnum(value.name)}}) { + if (chain->sType == {{namespace}}::SType::{{as_cppEnum(value.name)}}) { *out = static_cast(chain); break; } @@ -32,8 +36,8 @@ namespace dawn_native { {% endfor %} MaybeError ValidateSTypes(const ChainedStruct* chain, - std::vector> oneOfConstraints) { - std::unordered_set allSTypes; + std::vector> oneOfConstraints) { + std::unordered_set<{{namespace}}::SType> allSTypes; for (; chain; chain = chain->nextInChain) { if (allSTypes.find(chain->sType) != allSTypes.end()) { return DAWN_VALIDATION_ERROR("Chain cannot have duplicate sTypes"); @@ -42,7 +46,7 @@ MaybeError ValidateSTypes(const ChainedStruct* chain, } for (const auto& oneOfConstraint : oneOfConstraints) { bool satisfied = false; - for (wgpu::SType oneOfSType : oneOfConstraint) { + for ({{namespace}}::SType oneOfSType : oneOfConstraint) { if (allSTypes.find(oneOfSType) != allSTypes.end()) { if (satisfied) { return DAWN_VALIDATION_ERROR("Unsupported sType combination"); @@ -58,4 +62,4 @@ MaybeError ValidateSTypes(const ChainedStruct* chain, return {}; } -} // namespace dawn_native +} // namespace {{native_namespace}} diff --git a/generator/templates/dawn_native/ChainUtils.h b/generator/templates/dawn_native/ChainUtils.h index 7bc1dae91b..37cf5efd5b 100644 --- a/generator/templates/dawn_native/ChainUtils.h +++ b/generator/templates/dawn_native/ChainUtils.h @@ -12,13 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef DAWNNATIVE_CHAIN_UTILS_H_ -#define DAWNNATIVE_CHAIN_UTILS_H_ +{% set namespace_name = Name(metadata.native_namespace) %} +{% set DIR = namespace_name.concatcase().upper() %} +#ifndef {{DIR}}_CHAIN_UTILS_H_ +#define {{DIR}}_CHAIN_UTILS_H_ -#include "dawn_native/dawn_platform.h" -#include "dawn_native/Error.h" +{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %} +{% set native_namespace = namespace_name.snake_case() %} +{% set native_dir = impl_dir + native_namespace %} +{% set prefix = metadata.proc_table_prefix.lower() %} +#include "{{native_dir}}/{{prefix}}_platform.h" +#include "{{native_dir}}/Error.h" -namespace dawn_native { +namespace {{native_namespace}} { {% for value in types["s type"].values %} {% if value.valid %} void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out); @@ -31,8 +37,9 @@ namespace dawn_native { // For example: // ValidateSTypes(chain, { { ShaderModuleSPIRVDescriptor, ShaderModuleWGSLDescriptor } })) // ValidateSTypes(chain, { { Extension1 }, { Extension2 } }) + {% set namespace = metadata.namespace %} MaybeError ValidateSTypes(const ChainedStruct* chain, - std::vector> oneOfConstraints); + std::vector> oneOfConstraints); template MaybeError ValidateSingleSTypeInner(const ChainedStruct* chain, T sType) { @@ -73,6 +80,6 @@ namespace dawn_native { return ValidateSingleSTypeInner(chain, sType, sTypes...); } -} // namespace dawn_native +} // namespace {{native_namespace}} -#endif // DAWNNATIVE_CHAIN_UTILS_H_ +#endif // {{DIR}}_CHAIN_UTILS_H_ diff --git a/generator/templates/dawn_native/ObjectType.cpp b/generator/templates/dawn_native/ObjectType.cpp index df3e0fce8a..0f79327649 100644 --- a/generator/templates/dawn_native/ObjectType.cpp +++ b/generator/templates/dawn_native/ObjectType.cpp @@ -12,9 +12,12 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#include "dawn_native/ObjectType_autogen.h" +{% set native_namespace = Name(metadata.native_namespace).snake_case() %} +{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %} +{% set native_dir = impl_dir + native_namespace %} +#include "{{native_dir}}/ObjectType_autogen.h" -namespace dawn_native { +namespace {{native_namespace}} { const char* ObjectTypeAsString(ObjectType type) { switch (type) { @@ -27,4 +30,4 @@ namespace dawn_native { } } -} // namespace dawn_native +} // namespace {{native_namespace}} diff --git a/generator/templates/dawn_native/ObjectType.h b/generator/templates/dawn_native/ObjectType.h index cde4b07b1f..6430e6fa86 100644 --- a/generator/templates/dawn_native/ObjectType.h +++ b/generator/templates/dawn_native/ObjectType.h @@ -12,14 +12,17 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#ifndef DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ -#define DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ +{% set namespace_name = Name(metadata.native_namespace) %} +{% set DIR = namespace_name.concatcase().upper() %} +#ifndef {{DIR}}_OBJECTTPYE_AUTOGEN_H_ +#define {{DIR}}_OBJECTTPYE_AUTOGEN_H_ #include "common/ityp_array.h" #include -namespace dawn_native { +{% set native_namespace = namespace_name.snake_case() %} +namespace {{native_namespace}} { enum class ObjectType : uint32_t { {% for type in by_category["object"] %} @@ -32,7 +35,7 @@ namespace dawn_native { const char* ObjectTypeAsString(ObjectType type); -} // namespace dawn_native +} // namespace {{native_namespace}} -#endif // DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ +#endif // {{DIR}}_OBJECTTPYE_AUTOGEN_H_