mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-23 06:53:32 +00:00
Storing values into the cache will need to serialize and deserialize values in addition to keys. This patch factors the serialization utilities out of CacheKey into a more general "Stream" utility that supports both input and output for serialization and deserialization. Multiple files are not renamed to make parsing the diff easier. They will be renamed in Change If61f0466d79e7759ed32c4ddf541ad0c17247996. Bug: dawn:1480, dawn:1481 Change-Id: If7594c4ff7117454c1ab3d0afaeee5653120add8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96480 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Austin Eng <enga@chromium.org>
69 lines
2.6 KiB
C++
69 lines
2.6 KiB
C++
//* 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}} {
|
|
|
|
//
|
|
// Cache key writers for wgpu structures used in caching.
|
|
//
|
|
{% macro render_writer(member) %}
|
|
{%- set name = member.name.camelCase() -%}
|
|
{% if member.length == None %}
|
|
StreamIn(sink, t.{{name}});
|
|
{% elif member.length == "strlen" %}
|
|
StreamIn(sink, Iterable(t.{{name}}, strlen(t.{{name}})));
|
|
{% else %}
|
|
StreamIn(sink, Iterable(t.{{name}}, t.{{member.length.name.camelCase()}}));
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{# Helper macro to render writers. Should be used in a call block to provide additional custom
|
|
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:
|
|
{% call render_cache_key_writer("struct name", omits=["omit field"]) %}
|
|
// Custom C++ code to handle special types/members that are hard to generate code for
|
|
{% endcall %}
|
|
#}
|
|
{% macro render_cache_key_writer(json_type, omits=[]) %}
|
|
{%- set cpp_type = types[json_type].name.CamelCase() -%}
|
|
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 %}
|
|
}
|
|
{% endmacro %}
|
|
|
|
{% call render_cache_key_writer("adapter properties") %}
|
|
{% endcall %}
|
|
|
|
{% call render_cache_key_writer("dawn cache device descriptor") %}
|
|
{% endcall %}
|
|
|
|
} // namespace {{native_namespace}}
|