mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 17:35:30 +00:00
Beautify visitable structs with more helpers
Bug: dawn:1480 Change-Id: I01450e1916766daba016f71c0ed825e6b6664541 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98840 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
@@ -31,7 +31,6 @@
|
||||
#include "tint/tint.h"
|
||||
|
||||
namespace dawn::native {
|
||||
|
||||
namespace {
|
||||
|
||||
GLenum GLShaderType(SingleShaderStage stage) {
|
||||
@@ -73,53 +72,11 @@ DAWN_MAKE_CACHE_REQUEST(GLSLCompilationRequest, GLSL_COMPILATION_REQUEST_MEMBERS
|
||||
X(std::string, glsl) \
|
||||
X(bool, needsPlaceholderSampler) \
|
||||
X(opengl::CombinedSamplerInfo, combinedSamplerInfo)
|
||||
struct GLSLCompilation {
|
||||
DAWN_VISITABLE_MEMBERS(GLSL_COMPILATION_MEMBERS)
|
||||
|
||||
DAWN_SERIALIZABLE(struct, GLSLCompilation, GLSL_COMPILATION_MEMBERS){};
|
||||
#undef GLSL_COMPILATION_MEMBERS
|
||||
|
||||
static ResultOrError<GLSLCompilation> FromBlob(Blob blob) {
|
||||
stream::BlobSource source(std::move(blob));
|
||||
GLSLCompilation out;
|
||||
DAWN_TRY(out.VisitAll([&](auto&... members) { return StreamOut(&source, &members...); }));
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
template <>
|
||||
void BlobCache::Store<GLSLCompilation>(const CacheKey& key, const GLSLCompilation& c) {
|
||||
stream::ByteVectorSink sink;
|
||||
c.VisitAll([&](const auto&... members) { StreamIn(&sink, members...); });
|
||||
Store(key, CreateBlob(std::move(sink)));
|
||||
}
|
||||
|
||||
template <>
|
||||
void stream::Stream<opengl::BindingLocation>::Write(
|
||||
stream::Sink* s,
|
||||
const opengl::BindingLocation& bindingLocation) {
|
||||
bindingLocation.VisitAll([&](auto&... members) { return StreamIn(s, members...); });
|
||||
}
|
||||
|
||||
template <>
|
||||
MaybeError stream::Stream<opengl::BindingLocation>::Read(stream::Source* s,
|
||||
opengl::BindingLocation* bindingLocation) {
|
||||
return bindingLocation->VisitAll([&](auto&... members) { return StreamOut(s, &members...); });
|
||||
}
|
||||
|
||||
template <>
|
||||
void stream::Stream<opengl::CombinedSampler>::Write(
|
||||
stream::Sink* s,
|
||||
const opengl::CombinedSampler& combinedSampler) {
|
||||
combinedSampler.VisitAll([&](auto&... members) { return StreamIn(s, members...); });
|
||||
}
|
||||
|
||||
template <>
|
||||
MaybeError stream::Stream<opengl::CombinedSampler>::Read(stream::Source* s,
|
||||
opengl::CombinedSampler* combinedSampler) {
|
||||
return combinedSampler->VisitAll([&](auto&... members) { return StreamOut(s, &members...); });
|
||||
}
|
||||
|
||||
} // namespace dawn::native
|
||||
|
||||
namespace dawn::native::opengl {
|
||||
@@ -280,8 +237,8 @@ ResultOrError<GLuint> ShaderModule::CompileShader(const OpenGLFunctions& gl,
|
||||
DAWN_INVALID_IF(!result.success, "An error occured while generating GLSL: %s.",
|
||||
result.error);
|
||||
|
||||
return GLSLCompilation{std::move(result.glsl), needsPlaceholderSampler,
|
||||
std::move(combinedSamplerInfo)};
|
||||
return GLSLCompilation{
|
||||
{std::move(result.glsl), needsPlaceholderSampler, std::move(combinedSamplerInfo)}};
|
||||
});
|
||||
|
||||
if (GetDevice()->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "dawn/native/Serializable.h"
|
||||
#include "dawn/native/ShaderModule.h"
|
||||
#include "dawn/native/VisitableMembers.h"
|
||||
#include "dawn/native/opengl/opengl_platform.h"
|
||||
|
||||
namespace dawn::native {
|
||||
@@ -44,10 +44,9 @@ std::string GetBindingName(BindGroupIndex group, BindingNumber bindingNumber);
|
||||
#define BINDING_LOCATION_MEMBERS(X) \
|
||||
X(BindGroupIndex, group) \
|
||||
X(BindingNumber, binding)
|
||||
struct BindingLocation {
|
||||
DAWN_VISITABLE_MEMBERS(BINDING_LOCATION_MEMBERS)
|
||||
DAWN_SERIALIZABLE(struct, BindingLocation, BINDING_LOCATION_MEMBERS){};
|
||||
#undef BINDING_LOCATION_MEMBERS
|
||||
};
|
||||
|
||||
bool operator<(const BindingLocation& a, const BindingLocation& b);
|
||||
|
||||
#define COMBINED_SAMPLER_MEMBERS(X) \
|
||||
@@ -58,12 +57,11 @@ bool operator<(const BindingLocation& a, const BindingLocation& b);
|
||||
/* |samplerLocation| is unused. */ \
|
||||
X(bool, usePlaceholderSampler)
|
||||
|
||||
struct CombinedSampler {
|
||||
DAWN_VISITABLE_MEMBERS(COMBINED_SAMPLER_MEMBERS)
|
||||
#undef COMBINED_SAMPLER_MEMBERS
|
||||
|
||||
DAWN_SERIALIZABLE(struct, CombinedSampler, COMBINED_SAMPLER_MEMBERS) {
|
||||
std::string GetName() const;
|
||||
};
|
||||
#undef COMBINED_SAMPLER_MEMBERS
|
||||
|
||||
bool operator<(const CombinedSampler& a, const CombinedSampler& b);
|
||||
|
||||
using CombinedSamplerInfo = std::vector<CombinedSampler>;
|
||||
|
||||
Reference in New Issue
Block a user