mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-23 12:12:03 +00:00
This uses template and macro magic to reflect the fields of a class. Dawn: * Reflect the fields of the types that are used by Dawn's stream::Stream<T> specializations, and use tint::ForeachField() to call StreamIn(). Fuzzers: * Replace tint::fuzzers::DataBuilder::BuildImpl<T> specializations with the new reflection system. * static_assert that the type is either POD or reflected. Add a specialization for std::optional which was missing. Move tint::transform::BindingPoints into MultiplanarExternalTexture, as this is only used by MultiplanarExternalTexture. All this reduces fragility of the struct declarations slipping out of sync with the uses. Bug: tint:1640 Change-Id: I08729c1c356f1b427e85983efe3c2678fc2ce717 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101001 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
70 lines
2.2 KiB
C++
70 lines
2.2 KiB
C++
// Copyright 2021 The Tint 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.
|
|
|
|
#ifndef SRC_TINT_SEM_BINDING_POINT_H_
|
|
#define SRC_TINT_SEM_BINDING_POINT_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <functional>
|
|
|
|
#include "src/tint/reflection.h"
|
|
#include "src/tint/utils/hash.h"
|
|
|
|
namespace tint::sem {
|
|
|
|
/// BindingPoint holds a group and binding index.
|
|
struct BindingPoint {
|
|
/// The `@group` part of the binding point
|
|
uint32_t group = 0;
|
|
/// The `@binding` part of the binding point
|
|
uint32_t binding = 0;
|
|
|
|
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
|
|
TINT_REFLECT(group, binding);
|
|
|
|
/// Equality operator
|
|
/// @param rhs the BindingPoint to compare against
|
|
/// @returns true if this BindingPoint is equal to `rhs`
|
|
inline bool operator==(const BindingPoint& rhs) const {
|
|
return group == rhs.group && binding == rhs.binding;
|
|
}
|
|
|
|
/// Inequality operator
|
|
/// @param rhs the BindingPoint to compare against
|
|
/// @returns true if this BindingPoint is not equal to `rhs`
|
|
inline bool operator!=(const BindingPoint& rhs) const { return !(*this == rhs); }
|
|
};
|
|
|
|
} // namespace tint::sem
|
|
|
|
namespace std {
|
|
|
|
/// Custom std::hash specialization for tint::sem::BindingPoint so
|
|
/// BindingPoints can be used as keys for std::unordered_map and
|
|
/// std::unordered_set.
|
|
template <>
|
|
class hash<tint::sem::BindingPoint> {
|
|
public:
|
|
/// @param binding_point the binding point to create a hash for
|
|
/// @return the hash value
|
|
inline std::size_t operator()(const tint::sem::BindingPoint& binding_point) const {
|
|
return tint::utils::Hash(binding_point.group, binding_point.binding);
|
|
}
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
#endif // SRC_TINT_SEM_BINDING_POINT_H_
|