Make the templates of ChainUtils and ObjectType flexible
Replace hardcode contents with metadata. BUG=dawn:1201 Change-Id: I5e000edfeae3cc597127e487da29455c99fa8de2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/73920 Reviewed-by: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
parent
7cc1c0b7ea
commit
2b1dcd92b1
|
@ -901,11 +901,11 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||||
'src/dawn_native/ProcTable.cpp', frontend_params))
|
'src/dawn_native/ProcTable.cpp', frontend_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_native/ChainUtils.h',
|
FileRender('dawn_native/ChainUtils.h',
|
||||||
'src/dawn_native/ChainUtils_autogen.h',
|
'src/' + native_dir + '/ChainUtils_autogen.h',
|
||||||
frontend_params))
|
frontend_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_native/ChainUtils.cpp',
|
FileRender('dawn_native/ChainUtils.cpp',
|
||||||
'src/dawn_native/ChainUtils_autogen.cpp',
|
'src/' + native_dir + '/ChainUtils_autogen.cpp',
|
||||||
frontend_params))
|
frontend_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_native/webgpu_absl_format.h',
|
FileRender('dawn_native/webgpu_absl_format.h',
|
||||||
|
@ -917,11 +917,11 @@ class MultiGeneratorFromDawnJSON(Generator):
|
||||||
frontend_params))
|
frontend_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_native/ObjectType.h',
|
FileRender('dawn_native/ObjectType.h',
|
||||||
'src/dawn_native/ObjectType_autogen.h',
|
'src/' + native_dir + '/ObjectType_autogen.h',
|
||||||
frontend_params))
|
frontend_params))
|
||||||
renders.append(
|
renders.append(
|
||||||
FileRender('dawn_native/ObjectType.cpp',
|
FileRender('dawn_native/ObjectType.cpp',
|
||||||
'src/dawn_native/ObjectType_autogen.cpp',
|
'src/' + native_dir + '/ObjectType_autogen.cpp',
|
||||||
frontend_params))
|
frontend_params))
|
||||||
|
|
||||||
if 'dawn_wire' in targets:
|
if 'dawn_wire' in targets:
|
||||||
|
|
|
@ -12,17 +12,21 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace dawn_native {
|
namespace {{native_namespace}} {
|
||||||
|
|
||||||
|
{% set namespace = metadata.namespace %}
|
||||||
{% for value in types["s type"].values %}
|
{% for value in types["s type"].values %}
|
||||||
{% if value.valid %}
|
{% if value.valid %}
|
||||||
void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out) {
|
void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out) {
|
||||||
for (; chain; chain = chain->nextInChain) {
|
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<const {{as_cppEnum(value.name)}}*>(chain);
|
*out = static_cast<const {{as_cppEnum(value.name)}}*>(chain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -32,8 +36,8 @@ namespace dawn_native {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
MaybeError ValidateSTypes(const ChainedStruct* chain,
|
MaybeError ValidateSTypes(const ChainedStruct* chain,
|
||||||
std::vector<std::vector<wgpu::SType>> oneOfConstraints) {
|
std::vector<std::vector<{{namespace}}::SType>> oneOfConstraints) {
|
||||||
std::unordered_set<wgpu::SType> allSTypes;
|
std::unordered_set<{{namespace}}::SType> allSTypes;
|
||||||
for (; chain; chain = chain->nextInChain) {
|
for (; chain; chain = chain->nextInChain) {
|
||||||
if (allSTypes.find(chain->sType) != allSTypes.end()) {
|
if (allSTypes.find(chain->sType) != allSTypes.end()) {
|
||||||
return DAWN_VALIDATION_ERROR("Chain cannot have duplicate sTypes");
|
return DAWN_VALIDATION_ERROR("Chain cannot have duplicate sTypes");
|
||||||
|
@ -42,7 +46,7 @@ MaybeError ValidateSTypes(const ChainedStruct* chain,
|
||||||
}
|
}
|
||||||
for (const auto& oneOfConstraint : oneOfConstraints) {
|
for (const auto& oneOfConstraint : oneOfConstraints) {
|
||||||
bool satisfied = false;
|
bool satisfied = false;
|
||||||
for (wgpu::SType oneOfSType : oneOfConstraint) {
|
for ({{namespace}}::SType oneOfSType : oneOfConstraint) {
|
||||||
if (allSTypes.find(oneOfSType) != allSTypes.end()) {
|
if (allSTypes.find(oneOfSType) != allSTypes.end()) {
|
||||||
if (satisfied) {
|
if (satisfied) {
|
||||||
return DAWN_VALIDATION_ERROR("Unsupported sType combination");
|
return DAWN_VALIDATION_ERROR("Unsupported sType combination");
|
||||||
|
@ -58,4 +62,4 @@ MaybeError ValidateSTypes(const ChainedStruct* chain,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace {{native_namespace}}
|
||||||
|
|
|
@ -12,13 +12,19 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef DAWNNATIVE_CHAIN_UTILS_H_
|
{% set namespace_name = Name(metadata.native_namespace) %}
|
||||||
#define DAWNNATIVE_CHAIN_UTILS_H_
|
{% set DIR = namespace_name.concatcase().upper() %}
|
||||||
|
#ifndef {{DIR}}_CHAIN_UTILS_H_
|
||||||
|
#define {{DIR}}_CHAIN_UTILS_H_
|
||||||
|
|
||||||
#include "dawn_native/dawn_platform.h"
|
{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %}
|
||||||
#include "dawn_native/Error.h"
|
{% 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 %}
|
{% for value in types["s type"].values %}
|
||||||
{% if value.valid %}
|
{% if value.valid %}
|
||||||
void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out);
|
void FindInChain(const ChainedStruct* chain, const {{as_cppEnum(value.name)}}** out);
|
||||||
|
@ -31,8 +37,9 @@ namespace dawn_native {
|
||||||
// For example:
|
// For example:
|
||||||
// ValidateSTypes(chain, { { ShaderModuleSPIRVDescriptor, ShaderModuleWGSLDescriptor } }))
|
// ValidateSTypes(chain, { { ShaderModuleSPIRVDescriptor, ShaderModuleWGSLDescriptor } }))
|
||||||
// ValidateSTypes(chain, { { Extension1 }, { Extension2 } })
|
// ValidateSTypes(chain, { { Extension1 }, { Extension2 } })
|
||||||
|
{% set namespace = metadata.namespace %}
|
||||||
MaybeError ValidateSTypes(const ChainedStruct* chain,
|
MaybeError ValidateSTypes(const ChainedStruct* chain,
|
||||||
std::vector<std::vector<wgpu::SType>> oneOfConstraints);
|
std::vector<std::vector<{{namespace}}::SType>> oneOfConstraints);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
MaybeError ValidateSingleSTypeInner(const ChainedStruct* chain, T sType) {
|
MaybeError ValidateSingleSTypeInner(const ChainedStruct* chain, T sType) {
|
||||||
|
@ -73,6 +80,6 @@ namespace dawn_native {
|
||||||
return ValidateSingleSTypeInner(chain, sType, sTypes...);
|
return ValidateSingleSTypeInner(chain, sType, sTypes...);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace {{native_namespace}}
|
||||||
|
|
||||||
#endif // DAWNNATIVE_CHAIN_UTILS_H_
|
#endif // {{DIR}}_CHAIN_UTILS_H_
|
||||||
|
|
|
@ -12,9 +12,12 @@
|
||||||
//* See the License for the specific language governing permissions and
|
//* See the License for the specific language governing permissions and
|
||||||
//* limitations under the License.
|
//* 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) {
|
const char* ObjectTypeAsString(ObjectType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -27,4 +30,4 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace {{native_namespace}}
|
||||||
|
|
|
@ -12,14 +12,17 @@
|
||||||
//* See the License for the specific language governing permissions and
|
//* See the License for the specific language governing permissions and
|
||||||
//* limitations under the License.
|
//* limitations under the License.
|
||||||
|
|
||||||
#ifndef DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_
|
{% set namespace_name = Name(metadata.native_namespace) %}
|
||||||
#define DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_
|
{% set DIR = namespace_name.concatcase().upper() %}
|
||||||
|
#ifndef {{DIR}}_OBJECTTPYE_AUTOGEN_H_
|
||||||
|
#define {{DIR}}_OBJECTTPYE_AUTOGEN_H_
|
||||||
|
|
||||||
#include "common/ityp_array.h"
|
#include "common/ityp_array.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace dawn_native {
|
{% set native_namespace = namespace_name.snake_case() %}
|
||||||
|
namespace {{native_namespace}} {
|
||||||
|
|
||||||
enum class ObjectType : uint32_t {
|
enum class ObjectType : uint32_t {
|
||||||
{% for type in by_category["object"] %}
|
{% for type in by_category["object"] %}
|
||||||
|
@ -32,7 +35,7 @@ namespace dawn_native {
|
||||||
|
|
||||||
const char* ObjectTypeAsString(ObjectType type);
|
const char* ObjectTypeAsString(ObjectType type);
|
||||||
|
|
||||||
} // namespace dawn_native
|
} // namespace {{native_namespace}}
|
||||||
|
|
||||||
|
|
||||||
#endif // DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_
|
#endif // {{DIR}}_OBJECTTPYE_AUTOGEN_H_
|
||||||
|
|
Loading…
Reference in New Issue