Add ability to generate constants from dawn.json
The "constant" category has two keys: - `"type"`: a string, the name of the base data type - `"value"`: a string, the value is defined with preprocessor macro Remove deprecated constant InputStepMode. BUG=dawn:1201, dawn:1023 Change-Id: If4308bd5b25dddd9453514ce362bebe4fd771a57 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70704 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com> Commit-Queue: Junwei Fu <junwei.fu@intel.com>
This commit is contained in:
parent
a329997e27
commit
4e8769087a
42
dawn.json
42
dawn.json
|
@ -2581,6 +2581,48 @@
|
|||
{"value": 30, "name": "sint32x4"}
|
||||
]
|
||||
},
|
||||
"whole size" : {
|
||||
"category": "constant",
|
||||
"type": "uint64_t",
|
||||
"value": "(0xffffffffffffffffULL)"
|
||||
},
|
||||
"whole map size" : {
|
||||
"category": "constant",
|
||||
"type": "size_t",
|
||||
"value": "SIZE_MAX"
|
||||
},
|
||||
"stride undefined" : {
|
||||
"category": "constant",
|
||||
"tags": ["deprecated"],
|
||||
"_TODO": "crbug.com/dawn/520: Remove WGPU_STRIDE_UNDEFINED in favor of WGPU_COPY_STRIDE_UNDEFINED.",
|
||||
"type": "uint32_t",
|
||||
"value": "(0xffffffffUL)"
|
||||
},
|
||||
"copy stride undefined" : {
|
||||
"category": "constant",
|
||||
"type": "uint32_t",
|
||||
"value": "(0xffffffffUL)"
|
||||
},
|
||||
"limit u32 undefined" : {
|
||||
"category": "constant",
|
||||
"type": "uint32_t",
|
||||
"value": "(0xffffffffUL)"
|
||||
},
|
||||
"limit u64 undefined" : {
|
||||
"category": "constant",
|
||||
"type": "uint64_t",
|
||||
"value": "(0xffffffffffffffffULL)"
|
||||
},
|
||||
"array layer count undefined" : {
|
||||
"category": "constant",
|
||||
"type": "uint32_t",
|
||||
"value": "(0xffffffffUL)"
|
||||
},
|
||||
"mip level count undefined" : {
|
||||
"category": "constant",
|
||||
"type": "uint32_t",
|
||||
"value": "(0xffffffffUL)"
|
||||
},
|
||||
"ObjectType": {
|
||||
"_comment": "Only used for the wire",
|
||||
"category": "native"
|
||||
|
|
|
@ -71,6 +71,10 @@ A **record** is a list of **record members**, each of which is a dictionary with
|
|||
- `"return_type"` (default to no return type) a string that's the name of the return type.
|
||||
- `"arguments"` a **record**, so an array of **record members**
|
||||
|
||||
**`"constant"`**
|
||||
- `"type"`: a string, the name of the base data type
|
||||
- `"value"`: a string, the value is defined with preprocessor macro
|
||||
|
||||
## Dawn "wire" generators
|
||||
|
||||
The generator for the pieces of dawn_wire need additional data which is found in [`dawn_wire_json`](../dawn_wire.json). Examples of pieces that are generated are:
|
||||
|
|
|
@ -239,6 +239,14 @@ class StructureType(Record, Type):
|
|||
return self.chained == "out" or self.extensible == "out"
|
||||
|
||||
|
||||
class ConstantDefinition():
|
||||
def __init__(self, is_enabled, name, json_data):
|
||||
self.type = None
|
||||
self.value = json_data['value']
|
||||
self.json_data = json_data
|
||||
self.name = Name(name)
|
||||
|
||||
|
||||
class Command(Record):
|
||||
def __init__(self, name, members=None):
|
||||
Record.__init__(self, name)
|
||||
|
@ -310,6 +318,11 @@ def link_typedef(typedef, types):
|
|||
typedef.type = types[typedef.json_data['type']]
|
||||
|
||||
|
||||
def link_constant(constant, types):
|
||||
constant.type = types[constant.json_data['type']]
|
||||
assert constant.type.name.native
|
||||
|
||||
|
||||
# Sort structures so that if struct A has struct B as a member, then B is
|
||||
# listed before A.
|
||||
#
|
||||
|
@ -362,6 +375,7 @@ def parse_json(json, enabled_tags):
|
|||
'object': ObjectType,
|
||||
'structure': StructureType,
|
||||
'typedef': TypedefType,
|
||||
'constant': ConstantDefinition,
|
||||
}
|
||||
|
||||
types = {}
|
||||
|
@ -390,6 +404,9 @@ def parse_json(json, enabled_tags):
|
|||
for typedef in by_category['typedef']:
|
||||
link_typedef(typedef, types)
|
||||
|
||||
for constant in by_category['constant']:
|
||||
link_constant(constant, types)
|
||||
|
||||
for category in by_category.keys():
|
||||
by_category[category] = sorted(
|
||||
by_category[category], key=lambda typ: typ.name.canonical_case())
|
||||
|
|
|
@ -75,17 +75,9 @@
|
|||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define WGPU_WHOLE_SIZE (0xffffffffffffffffULL)
|
||||
#define WGPU_WHOLE_MAP_SIZE SIZE_MAX
|
||||
{% if 'deprecated' in enabled_tags %}
|
||||
// TODO(crbug.com/dawn/520): Remove WGPU_STRIDE_UNDEFINED in favor of WGPU_COPY_STRIDE_UNDEFINED.
|
||||
#define WGPU_STRIDE_UNDEFINED (0xffffffffUL)
|
||||
{% endif %}
|
||||
#define WGPU_COPY_STRIDE_UNDEFINED (0xffffffffUL)
|
||||
#define WGPU_LIMIT_U32_UNDEFINED (0xffffffffUL)
|
||||
#define WGPU_LIMIT_U64_UNDEFINED (0xffffffffffffffffULL)
|
||||
#define WGPU_ARRAY_LAYER_COUNT_UNDEFINED (0xffffffffUL)
|
||||
#define WGPU_MIP_LEVEL_COUNT_UNDEFINED (0xffffffffUL)
|
||||
{% for constant in by_category["constant"] %}
|
||||
#define {{c_prefix}}_{{constant.name.SNAKE_CASE()}} {{constant.value}}
|
||||
{% endfor %}
|
||||
|
||||
typedef uint32_t {{c_prefix}}Flags;
|
||||
|
||||
|
@ -138,13 +130,6 @@ typedef struct {{c_prefix}}ChainedStructOut {
|
|||
typedef {{as_cType(typeDef.type.name)}} {{as_cType(typeDef.name)}};
|
||||
|
||||
{% endfor %}
|
||||
{% if 'deprecated' in enabled_tags %}
|
||||
// TODO(crbug.com/dawn/1023): Remove after the deprecation period.
|
||||
#define WGPUInputStepMode_Vertex WGPUVertexStepMode_Vertex
|
||||
#define WGPUInputStepMode_Instance WGPUVertexStepMode_Instance
|
||||
#define WGPUInputStepMode_Force32 WGPUVertexStepMode_Force32
|
||||
|
||||
{% endif %}
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -19,17 +19,12 @@
|
|||
|
||||
namespace wgpu {
|
||||
|
||||
static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
|
||||
static constexpr size_t kWholeMapSize = WGPU_WHOLE_MAP_SIZE;
|
||||
{% if 'deprecated' in enabled_tags %}
|
||||
// TODO(crbug.com/520): Remove kStrideUndefined in favor of kCopyStrideUndefined.
|
||||
static constexpr uint32_t kStrideUndefined = WGPU_STRIDE_UNDEFINED;
|
||||
{% endif %}
|
||||
static constexpr uint32_t kCopyStrideUndefined = WGPU_COPY_STRIDE_UNDEFINED;
|
||||
static constexpr uint32_t kLimitU32Undefined = WGPU_LIMIT_U32_UNDEFINED;
|
||||
static constexpr uint64_t kLimitU64Undefined = WGPU_LIMIT_U64_UNDEFINED;
|
||||
static constexpr uint32_t kArrayLayerCountUndefined = WGPU_ARRAY_LAYER_COUNT_UNDEFINED;
|
||||
static constexpr uint32_t kMipLevelCountUndefined = WGPU_MIP_LEVEL_COUNT_UNDEFINED;
|
||||
{% set c_prefix = metadata.c_prefix %}
|
||||
{% for constant in by_category["constant"] %}
|
||||
{% set type = as_cppType(constant.type.name) %}
|
||||
{% set value = c_prefix + "_" + constant.name.SNAKE_CASE() %}
|
||||
static constexpr {{type}} k{{as_cppType(constant.name)}} = {{ value }};
|
||||
{% endfor %}
|
||||
|
||||
{% for type in by_category["enum"] %}
|
||||
enum class {{as_cppType(type.name)}} : uint32_t {
|
||||
|
|
Loading…
Reference in New Issue