2022-04-12 23:50:56 +00:00
|
|
|
//* Copyright 2022 The Dawn Authors
|
|
|
|
//*
|
|
|
|
//* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
//* you may not use this file except in compliance with the License.
|
|
|
|
//* You may obtain a copy of the License at
|
|
|
|
//*
|
|
|
|
//* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//*
|
|
|
|
//* Unless required by applicable law or agreed to in writing, software
|
|
|
|
//* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//* See the License for the specific language governing permissions and
|
|
|
|
//* limitations under the License.
|
|
|
|
|
|
|
|
{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %}
|
|
|
|
{% set namespace_name = Name(metadata.native_namespace) %}
|
|
|
|
{% set native_namespace = namespace_name.namespace_case() %}
|
|
|
|
{% set native_dir = impl_dir + namespace_name.Dirs() %}
|
|
|
|
{% set prefix = metadata.proc_table_prefix.lower() %}
|
|
|
|
#include "{{native_dir}}/CacheKey.h"
|
|
|
|
#include "{{native_dir}}/{{prefix}}_platform.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace {{native_namespace}} {
|
|
|
|
|
|
|
|
//
|
2022-09-07 20:09:54 +00:00
|
|
|
// Streaming readers for wgpu structures.
|
|
|
|
//
|
|
|
|
{% macro render_reader(member) %}
|
|
|
|
{%- set name = member.name.camelCase() -%}
|
|
|
|
DAWN_TRY(StreamOut(source, &t->{{name}}));
|
|
|
|
{% endmacro %}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Streaming writers for wgpu structures.
|
2022-04-12 23:50:56 +00:00
|
|
|
//
|
2022-07-28 23:04:31 +00:00
|
|
|
{% macro render_writer(member) %}
|
2022-04-12 23:50:56 +00:00
|
|
|
{%- set name = member.name.camelCase() -%}
|
|
|
|
{% if member.length == None %}
|
2022-07-28 23:04:31 +00:00
|
|
|
StreamIn(sink, t.{{name}});
|
2022-04-12 23:50:56 +00:00
|
|
|
{% elif member.length == "strlen" %}
|
2022-07-28 23:04:31 +00:00
|
|
|
StreamIn(sink, Iterable(t.{{name}}, strlen(t.{{name}})));
|
2022-04-12 23:50:56 +00:00
|
|
|
{% else %}
|
2022-07-28 23:04:31 +00:00
|
|
|
StreamIn(sink, Iterable(t.{{name}}, t.{{member.length.name.camelCase()}}));
|
2022-04-12 23:50:56 +00:00
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
|
|
|
|
2022-09-07 20:09:54 +00:00
|
|
|
{# Helper macro to render readers and writers. Should be used in a call block to provide additional custom
|
2022-04-12 23:50:56 +00:00
|
|
|
handling when necessary. The optional `omit` field can be used to omit fields that are either
|
|
|
|
handled in the custom code, or unnecessary in the serialized output.
|
|
|
|
Example:
|
2022-09-07 20:09:54 +00:00
|
|
|
{% call render_streaming_impl("struct name", writer=true, reader=false, omits=["omit field"]) %}
|
2022-04-12 23:50:56 +00:00
|
|
|
// Custom C++ code to handle special types/members that are hard to generate code for
|
|
|
|
{% endcall %}
|
2022-09-07 20:09:54 +00:00
|
|
|
One day we should probably make the generator smart enough to generate everything it can
|
|
|
|
instead of manually adding streaming implementations here.
|
2022-04-12 23:50:56 +00:00
|
|
|
#}
|
2022-09-07 20:09:54 +00:00
|
|
|
{% macro render_streaming_impl(json_type, writer, reader, omits=[]) %}
|
2022-04-12 23:50:56 +00:00
|
|
|
{%- set cpp_type = types[json_type].name.CamelCase() -%}
|
2022-09-07 20:09:54 +00:00
|
|
|
{% if reader %}
|
|
|
|
template <>
|
|
|
|
MaybeError stream::Stream<{{cpp_type}}>::Read(stream::Source* source, {{cpp_type}}* t) {
|
|
|
|
{{ caller() }}
|
|
|
|
{% for member in types[json_type].members %}
|
|
|
|
{% if not member.name.get() in omits %}
|
|
|
|
{{render_reader(member)}}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
{% if writer %}
|
|
|
|
template <>
|
|
|
|
void stream::Stream<{{cpp_type}}>::Write(stream::Sink* sink, const {{cpp_type}}& t) {
|
|
|
|
{{ caller() }}
|
|
|
|
{% for member in types[json_type].members %}
|
|
|
|
{% if not member.name.get() in omits %}
|
|
|
|
{{render_writer(member)}}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
{% endif %}
|
2022-04-12 23:50:56 +00:00
|
|
|
{% endmacro %}
|
|
|
|
|
2022-09-07 20:09:54 +00:00
|
|
|
{% call render_streaming_impl("adapter properties", true, false) %}
|
|
|
|
{% endcall %}
|
|
|
|
|
|
|
|
{% call render_streaming_impl("dawn cache device descriptor", true, false) %}
|
2022-04-12 23:50:56 +00:00
|
|
|
{% endcall %}
|
|
|
|
|
2022-09-07 20:09:54 +00:00
|
|
|
{% call render_streaming_impl("extent 3D", true, true) %}
|
2022-04-12 23:50:56 +00:00
|
|
|
{% endcall %}
|
|
|
|
|
|
|
|
} // namespace {{native_namespace}}
|