FCT
载入中...
搜索中...
未找到
RenderGraph_RenderGraphBufferNode.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/8/10.
3//
4
5#ifndef RENDERGRAPHRENDERGRAPHBUFFERNODE_H
6#define RENDERGRAPHRENDERGRAPHBUFFERNODE_H
7namespace FCT
8{
10 {
11 private:
15 ImageUsages m_usage;
18 public:
24
30 void setAllocatedImage(Image* image) {
31 m_allocatedImage = image;
32 }
33 Image* getImage() const override
34 {
35 return m_allocatedImage;
36 }
37
38 RenderGraphBufferNode(const Texture& other) : RenderGraphImageNode(other.name), m_filled(true),
39 m_format(other.format), m_samples(other.samples),
40 m_usage(ImageUsage::Texture), m_size(other.size)
41 {
43 setFixedSize(other.size.width, other.size.height);
44 }
45 }
46
47 RenderGraphBufferNode(const Target& other) : RenderGraphImageNode(other.name), m_filled(true),
48 m_format(other.format), m_samples(other.samples),
50 {
51 if (other.hasFixedSize) {
52 setFixedSize(other.width, other.height);
53 }
54 }
55
57 m_format(other.format), m_samples(other.samples),
59 {
60 if (other.hasFixedSize) {
61 setFixedSize(other.width, other.height);
62 }
63 }
64 RenderGraphImageNode& operator|=(const Texture& other) override
65 {
66 if (m_filled) {
69 return *this;
70 }
71 *this = RenderGraphBufferNode(other);
72 return *this;
73 }
74
75 RenderGraphImageNode& operator|=(const Target& other) override
76 {
77 if (m_filled) {
80 other.width, other.height);
81 return *this;
82 }
83 *this = RenderGraphBufferNode(other);
84 return *this;
85 }
86
88 {
89 if (m_filled) {
92 other.width, other.height);
93 return *this;
94 }
95 *this = RenderGraphBufferNode(other);
96 return *this;
97 }
98 Format getFormat() const noexcept {
99 return m_format;
100 }
101
102 Samples getSamples() const noexcept {
103 return m_samples;
104 }
105
106 ImageUsages getUsage() const noexcept {
107 return m_usage;
108 }
109
110 bool isFilled() const noexcept {
111 return m_filled;
112 }
113 void fillDefaultData() override
114 {
116 {
118 }
120 {
122 }
123 }
124
125 private:
126 void checkCompatibilityAndMerge(const std::string& name, Format format, Samples samples,
127 ImageUsage usage, const TextureSize& size) {
128 checkCompatibilityAndMergeImpl(name, format, samples, usage, false, 0, 0, &size);
129 }
130
131 void checkCompatibilityAndMerge(const std::string& name, Format format, Samples samples,
132 ImageUsage usage, bool hasFixedSize, uint32_t width, uint32_t height) {
133 checkCompatibilityAndMergeImpl(name, format, samples, usage, hasFixedSize, width, height, nullptr);
134 }
135
136 void checkCompatibilityAndMergeImpl(const std::string& name, Format format, Samples samples,
137 ImageUsage usage, bool hasFixedSize, uint32_t width, uint32_t height,
138 const TextureSize* textureSize) {
139 //检查是否冲突
140 if (m_name != name) {
141 throw std::runtime_error("RenderGraph conflict: Different names for same resource - existing: '" +
142 m_name + "', new: '" + name + "'");
143 }
144 if (m_format != Format::UNDEFINED && format != Format::UNDEFINED && m_format != format) {
145 throw std::runtime_error("RenderGraph conflict: Incompatible formats for resource '" + name +
146 "' - existing format conflicts with new format");
147 }
148 if (m_samples != Samples::sample_undefined && samples != Samples::sample_undefined && m_samples != samples) {
149 throw std::runtime_error("RenderGraph conflict: Incompatible sample counts for resource '" + name +
150 "' - existing samples conflict with new samples");
151 }
152
153 m_usage |= usage;
154
155 // 更新未定义的属性
156 if (m_format == Format::UNDEFINED && format != Format::UNDEFINED) {
157 m_format = format;
158 }
160 m_samples = samples;
161 }
162
163 // 如果有固定大小,设置固定大小
164 if (hasFixedSize) {
165 if (!setFixedSize(width, height)) {
166 throw std::runtime_error("RenderGraph conflict: Incompatible sizes for resource '" + name + "'");
167 }
168 }
169 if (textureSize && usage == ImageUsage::Texture) {
170 if (textureSize->type == TextureSize::Type::Absolute) {
171 if (!setFixedSize(textureSize->width, textureSize->height)) {
172 throw std::runtime_error("RenderGraph conflict: Incompatible sizes for texture resource '" + name + "'");
173 }
174 }
175 }
176
177 }
178 };
180 {
181 private:
184
185 public:
186 void fillDefaultData() override
187 {
188
189 }
193
195 m_window(other.wnd)
196 {
197 if (!other.isWindow) {
198 throw std::runtime_error("RenderGraphWindowTargetNode can only be created from window Target");
199 }
200 setFixed();
201 }
202
203 RenderGraphImageNode& operator|=(const Target& other) override
204 {
205 if (!other.isWindow) {
206 throw std::runtime_error("RenderGraphWindowTargetNode can only merge with window Target");
207 }
208
209 if (m_filled) {
210 checkCompatibilityAndMerge(other.name, other.wnd);
211 return *this;
212 }
213 *this = RenderGraphWindowTargetNode(other);
214 return *this;
215 }
216
217 Window* getWindow() const noexcept {
218 return m_window;
219 }
220
221 bool isValidWindowTarget() const noexcept {
222 return m_filled && m_window != nullptr;
223 }
224 Image* getImage() const override;
225
226 private:
227 void checkCompatibilityAndMerge(const std::string& name, Window* window) {
228 // 检查是否冲突
229 if (m_name != name) {
230 throw std::runtime_error("RenderGraph conflict: Different names for same window target - existing: '" +
231 m_name + "', new: '" + name + "'");
232 }
233 if (m_window != window) {
234 throw std::runtime_error("RenderGraph conflict: Different windows for same target '" + name + "'");
235 }
236 }
237
238 public:
240 {
241 throw std::runtime_error("RenderGraphWindowTargetNode can't merge with texture");
242 }
244 {
245 throw std::runtime_error("RenderGraphWindowDepthStencilNode can't merge with depth stencil");
246 }
247 };
248
250 {
251 private:
254 public:
255 void fillDefaultData() override
256 {
257
258 }
262
264 m_window(other.wnd)
265 {
266 if (!other.isWindow) {
267 throw std::runtime_error("RenderGraphWindowDepthStencilNode can only be created from window DepthStencil");
268 }
269 setFixed();
270 }
271
273 {
274 if (!other.isWindow) {
275 throw std::runtime_error("RenderGraphWindowDepthStencilNode can only merge with window DepthStencil");
276 }
277
278 if (m_filled) {
279 checkCompatibilityAndMerge(other.name, other.wnd);
280 return *this;
281 }
283 return *this;
284 }
285
286 Window* getWindow() const noexcept {
287 return m_window;
288 }
289 Image* getImage() const override;
290
291 bool isValidWindowDepthStencil() const noexcept {
292 return m_filled && m_window != nullptr;
293 }
294
295 private:
296 void checkCompatibilityAndMerge(const std::string& name, Window* window) {
297 // 检查是否冲突
298 if (m_name != name) {
299 throw std::runtime_error("RenderGraph conflict: Different names for same window depth stencil - existing: '" +
300 m_name + "', new: '" + name + "'");
301 }
302 if (m_window != window) {
303 throw std::runtime_error("RenderGraph conflict: Different windows for same depth stencil '" + name + "'");
304 }
305 }
306
307 public:
309 {
310 throw std::runtime_error("RenderGraphWindowDepthStencilNode cannot merge with texture");
311 }
312 RenderGraphImageNode& operator|=(const Target& other) override
313 {
314 throw std::runtime_error("RenderGraphWindowDepthStencilNode cannot merge with window Target");
315 }
316 };
317
318}
319#endif //RENDERGRAPHRENDERGRAPHBUFFERNODE_H
RenderGraphImageNode & operator|=(const Target &other) override
void checkCompatibilityAndMerge(const std::string &name, Format format, Samples samples, ImageUsage usage, const TextureSize &size)
void checkCompatibilityAndMergeImpl(const std::string &name, Format format, Samples samples, ImageUsage usage, bool hasFixedSize, uint32_t width, uint32_t height, const TextureSize *textureSize)
void checkCompatibilityAndMerge(const std::string &name, Format format, Samples samples, ImageUsage usage, bool hasFixedSize, uint32_t width, uint32_t height)
RenderGraphImageNode & operator|=(const Texture &other) override
RenderGraphImageNode & operator|=(const DepthStencil &other) override
RenderGraphImageNode & operator|=(const Target &other) override
RenderGraphImageNode & operator|=(const DepthStencil &other) override
RenderGraphImageNode & operator|=(const Texture &other) override
void checkCompatibilityAndMerge(const std::string &name, Window *window)
RenderGraphImageNode & operator|=(const Target &other) override
void checkCompatibilityAndMerge(const std::string &name, Window *window)
RenderGraphImageNode & operator|=(const Texture &other) override
RenderGraphImageNode & operator|=(const DepthStencil &other) override
Image * getImage() const override
bool setFixed() const noexcept
bool setFixedSize(uint32_t w, uint32_t h) const noexcept