mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
tint: Add TINT_REFLECT() & ForeachField()
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>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
bd6bcf1e0c
commit
648bd7b4be
@@ -28,30 +28,33 @@ namespace tint::transform {
|
||||
/// BindingPoint is an alias to sem::BindingPoint
|
||||
using BindingPoint = sem::BindingPoint;
|
||||
|
||||
/// This struct identifies the binding groups and locations for new bindings to
|
||||
/// use when transforming a texture_external instance.
|
||||
struct BindingPoints {
|
||||
/// The desired binding location of the texture_2d representing plane #1 when
|
||||
/// a texture_external binding is expanded.
|
||||
BindingPoint plane_1;
|
||||
/// The desired binding location of the ExternalTextureParams uniform when a
|
||||
/// texture_external binding is expanded.
|
||||
BindingPoint params;
|
||||
};
|
||||
|
||||
/// Within the MultiplanarExternalTexture transform, each instance of a
|
||||
/// texture_external binding is unpacked into two texture_2d<f32> bindings
|
||||
/// representing two possible planes of a texture and a uniform buffer binding
|
||||
/// representing a struct of parameters. Calls to textureLoad or
|
||||
/// textureSampleLevel that contain a texture_external parameter will be
|
||||
/// transformed into a newly generated version of the function, which can
|
||||
/// perform the desired operation on a single RGBA plane or on seperate Y and UV
|
||||
/// perform the desired operation on a single RGBA plane or on separate Y and UV
|
||||
/// planes, and do colorspace conversions including yuv->rgb conversion, gamma
|
||||
/// decoding, gamut conversion, and gamma encoding steps. Specifically
|
||||
// for BT.709 to SRGB conversion, it takes the fast path only doing the yuv->rgb
|
||||
// step and skipping all other steps.
|
||||
class MultiplanarExternalTexture final : public Castable<MultiplanarExternalTexture, Transform> {
|
||||
public:
|
||||
/// This struct identifies the binding groups and locations for new bindings to
|
||||
/// use when transforming a texture_external instance.
|
||||
struct BindingPoints {
|
||||
/// The desired binding location of the texture_2d representing plane #1 when
|
||||
/// a texture_external binding is expanded.
|
||||
BindingPoint plane_1;
|
||||
/// The desired binding location of the ExternalTextureParams uniform when a
|
||||
/// texture_external binding is expanded.
|
||||
BindingPoint params;
|
||||
|
||||
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
|
||||
TINT_REFLECT(plane_1, params);
|
||||
};
|
||||
|
||||
/// BindingsMap is a map where the key is the binding location of a
|
||||
/// texture_external and the value is a struct containing the desired
|
||||
/// locations for new bindings expanded from the texture_external instance.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/reflection.h"
|
||||
#include "src/tint/transform/transform.h"
|
||||
|
||||
namespace tint::transform {
|
||||
@@ -72,6 +73,9 @@ struct VertexAttributeDescriptor {
|
||||
uint32_t offset;
|
||||
/// The shader location used for the attribute
|
||||
uint32_t shader_location;
|
||||
|
||||
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
|
||||
TINT_REFLECT(format, offset, shader_location);
|
||||
};
|
||||
|
||||
/// Describes a buffer containing multiple vertex attributes
|
||||
@@ -102,6 +106,9 @@ struct VertexBufferLayoutDescriptor {
|
||||
VertexStepMode step_mode = VertexStepMode::kVertex;
|
||||
/// The vertex attributes
|
||||
std::vector<VertexAttributeDescriptor> attributes;
|
||||
|
||||
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
|
||||
TINT_REFLECT(array_stride, step_mode, attributes);
|
||||
};
|
||||
|
||||
/// Describes vertex state, which consists of many buffers containing vertex
|
||||
@@ -154,6 +161,9 @@ class VertexPulling final : public Castable<VertexPulling, Transform> {
|
||||
/// The "group" we will put all our vertex buffers into (as storage buffers)
|
||||
/// Default to 4 as it is past the limits of user-accessible groups
|
||||
uint32_t pulling_group = 4u;
|
||||
|
||||
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
|
||||
TINT_REFLECT(entry_point_name, vertex_state, pulling_group);
|
||||
};
|
||||
|
||||
/// Constructor
|
||||
|
||||
Reference in New Issue
Block a user