Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
BindGroupLayout.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "spdlog/fmt/fmt.h"
6#include <concepts>
7#include <vector>
8
9template <typename TBindGroupLayoutEntry>
10concept CBindGroupLayoutEntry = std::derived_from<TBindGroupLayoutEntry, Graphic::Utils::IBindGroupLayoutEntry>;
11
12namespace Graphic::Utils {
14 public:
15 explicit BindGroupLayout(const std::string &name) : name(name) {}
16 ~BindGroupLayout() override = default;
17
18 template <CBindGroupLayoutEntry TEntry> inline BindGroupLayout &addEntry(const TEntry &entry)
19 {
20 this->entries.push_back(std::make_shared<TEntry>(entry));
21 return *this;
22 }
23
24 const std::vector<std::shared_ptr<IBindGroupLayoutEntry>> &getEntries() const { return this->entries; }
25
26 const std::string &getName() const { return this->name; }
27
28 std::vector<ValidationError> validate(void) const override
29 {
30 std::vector<ValidationError> errors;
31 if (this->entries.empty())
32 {
33 errors.emplace_back("No entries in the bind group layout",
34 fmt::format("BindGroupLayout({})", this->getName()),
36 return errors;
37 }
38 for (const auto &entry : this->entries)
39 {
40 auto entryErrors = entry->validate();
41 for (const auto &error : entryErrors)
42 {
43 errors.emplace_back(error.message,
44 fmt::format("BindGroupLayout::{}::{}", error.location, entry->getName()),
45 error.severity);
46 }
47 }
48 for (uint32_t i = 0; i < this->entries.size(); i++)
49 {
50 const auto &entry = this->entries[i];
51 for (uint32_t j = i + 1; j < this->entries.size(); j++)
52 {
53 const auto &otherEntry = this->entries[j];
54 if (entry->getEntry().binding == otherEntry->getEntry().binding)
55 {
56 errors.emplace_back(fmt::format("Binding {} is duplicated between entries '{}' and '{}'",
57 entry->getEntry().binding, entry->getName(), otherEntry->getName()),
58 fmt::format("BindGroupLayout({})", this->getName()),
60 }
61 if (entry->getName() == otherEntry->getName())
62 {
63 errors.emplace_back(fmt::format("Entry name '{}' is duplicated between entries at index {} and {}",
64 entry->getName(), i, j),
65 fmt::format("BindGroupLayout({})", this->getName()),
67 }
68 }
69 }
70 return errors;
71 }
72
73 private:
74 std::vector<std::shared_ptr<IBindGroupLayoutEntry>> entries;
75 std::string name;
76};
77} // namespace Graphic::Utils
BindGroupLayout & addEntry(const TEntry &entry)
Definition BindGroupLayout.hpp:18
std::string name
Definition BindGroupLayout.hpp:75
std::vector< ValidationError > validate(void) const override
Definition BindGroupLayout.hpp:28
BindGroupLayout(const std::string &name)
Definition BindGroupLayout.hpp:15
const std::vector< std::shared_ptr< IBindGroupLayoutEntry > > & getEntries() const
Definition BindGroupLayout.hpp:24
const std::string & getName() const
Definition BindGroupLayout.hpp:26
std::vector< std::shared_ptr< IBindGroupLayoutEntry > > entries
Definition BindGroupLayout.hpp:74
~BindGroupLayout() override=default
Definition IValidable.hpp:26
Definition BindGroupLayout.hpp:10
Definition DefaultSampler.hpp:6
@ Warning
Definition IValidable.hpp:13
@ Error
Definition IValidable.hpp:14