Replace hardcode functions in templates

Make dawn_proc.c and dawn_thread_dispatch_proc.cpp flexible

BUG=dawn:1201

Change-Id: Ifca73b33d6aed70b2dda3cf181a4650380f0a2fb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/72065
Reviewed-by: Jiawei Shao <jiawei.shao@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:
fujunwei 2021-12-10 01:35:19 +00:00 committed by Dawn LUCI CQ
parent 0e922b5995
commit a840574db0
3 changed files with 37 additions and 21 deletions

View File

@ -757,8 +757,8 @@ class MultiGeneratorFromDawnJSON(Generator):
RENDER_PARAMS_BASE = make_base_render_params(metadata)
api = metadata.api.lower()
prefix = metadata.proc_table_prefix.lower()
if 'dawn_headers' in targets:
prefix = metadata.proc_table_prefix.lower()
renders.append(
FileRender('api.h', 'src/include/dawn/' + api + '.h',
[RENDER_PARAMS_BASE, params_dawn]))
@ -779,11 +779,11 @@ class MultiGeneratorFromDawnJSON(Generator):
if 'dawn_proc' in targets:
renders.append(
FileRender('dawn_proc.c', 'src/dawn/dawn_proc.c',
FileRender('dawn_proc.c', 'src/dawn/' + prefix + '_proc.c',
[RENDER_PARAMS_BASE, params_dawn]))
renders.append(
FileRender('dawn_thread_dispatch_proc.cpp',
'src/dawn/dawn_thread_dispatch_proc.cpp',
'src/dawn/' + prefix + '_thread_dispatch_proc.cpp',
[RENDER_PARAMS_BASE, params_dawn]))
if 'webgpu_dawn_native_proc' in targets:

View File

@ -12,13 +12,15 @@
//* See the License for the specific language governing permissions and
//* limitations under the License.
#include "dawn/dawn_proc.h"
{% set Prefix = metadata.proc_table_prefix %}
{% set prefix = Prefix.lower() %}
#include "dawn/{{prefix}}_proc.h"
static DawnProcTable procs;
static {{Prefix}}ProcTable procs;
static DawnProcTable nullProcs;
static {{Prefix}}ProcTable nullProcs;
void dawnProcSetProcs(const DawnProcTable* procs_) {
void {{prefix}}ProcSetProcs(const {{Prefix}}ProcTable* procs_) {
if (procs_) {
procs = *procs_;
} else {
@ -26,13 +28,20 @@ void dawnProcSetProcs(const DawnProcTable* procs_) {
}
}
WGPUInstance wgpuCreateInstance(WGPUInstanceDescriptor const * descriptor) {
return procs.createInstance(descriptor);
}
WGPUProc wgpuGetProcAddress(WGPUDevice device, const char* procName) {
return procs.getProcAddress(device, procName);
}
{% for function in by_category["function"] %}
{{as_cType(function.return_type.name)}} {{as_cMethod(None, function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
{%- endfor -%}
) {
{% if function.return_type.name.canonical_case() != "void" %}return {% endif %}
procs.{{as_varName(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_varName(arg.name)}}
{%- endfor -%}
);
}
{% endfor %}
{% for type in by_category["object"] %}
{% for method in c_methods(type) %}

View File

@ -15,13 +15,20 @@ void {{prefix}}ProcSetPerThreadProcs(const {{Prefix}}ProcTable* procs) {
}
}
static WGPUProc ThreadDispatchGetProcAddress(WGPUDevice device, const char* procName) {
return perThreadProcs.getProcAddress(device, procName);
}
static WGPUInstance ThreadDispatchCreateInstance(WGPUInstanceDescriptor const * descriptor) {
return perThreadProcs.createInstance(descriptor);
}
{% for function in by_category["function"] %}
static {{as_cType(function.return_type.name)}} ThreadDispatch{{as_cppType(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
{%- endfor -%}
) {
{% if function.return_type.name.canonical_case() != "void" %}return {% endif %}
perThreadProcs.{{as_varName(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_varName(arg.name)}}
{%- endfor -%}
);
}
{% endfor %}
{% for type in by_category["object"] %}
{% for method in c_methods(type) %}