Loading...
Searching...
No Matches
RenderedCSFNode.hpp
1#pragma once
2#include <Gfx/Graph/ISFNode.hpp>
3#include <Gfx/Graph/NodeRenderer.hpp>
4
5#include <ossia/detail/small_flat_map.hpp>
6
7namespace score::gfx
8{
9
11{
12 explicit RenderedCSFNode(const ISFNode& node) noexcept;
13
14 virtual ~RenderedCSFNode();
15
16 TextureRenderTarget renderTargetForInput(const Port& p) override;
17
18 void init(RenderList& renderer, QRhiResourceUpdateBatch& res) override;
19 void update(RenderList& renderer, QRhiResourceUpdateBatch& res, Edge* edge) override;
20 void release(RenderList& r) override;
21
22 void runInitialPasses(
23 RenderList&, QRhiCommandBuffer& commands, QRhiResourceUpdateBatch*& res,
24 Edge& edge) override;
25
26 void runRenderPass(RenderList&, QRhiCommandBuffer& commands, Edge& edge) override;
27
28private:
29 void initComputePass(const TextureRenderTarget& rt, RenderList& renderer, Edge& edge, QRhiResourceUpdateBatch& res);
30 void createComputePipeline(RenderList& renderer);
31 void createGraphicsPass(const TextureRenderTarget& rt, RenderList& renderer, Edge& edge, QRhiResourceUpdateBatch& res);
32 void updateDescriptorSet(RenderList& renderer, Edge& edge);
33 std::vector<Sampler> allSamplers() const noexcept;
34
35 // Image management
36 std::optional<QSize> getImageSize(const isf::csf_image_input&) const noexcept;
37 QSize computeTextureSize(const isf::csf_image_input& img) const noexcept;
38
39 // Buffer management methods
40 int calculateStorageBufferSize(std::span<const isf::storage_input::layout_field> layout, int arrayCount) const;
41 QRhiBuffer* createStorageBuffer(RenderList& renderer, const QString& name, const QString& access, int size);
42 void updateStorageBuffers(RenderList& renderer, QRhiResourceUpdateBatch& res);
43 void recreateShaderResourceBindings(RenderList& renderer, QRhiResourceUpdateBatch& res);
44 int getArraySizeFromUI(const QString& bufferName) const;
45 QString updateShaderWithImageFormats(QString current);
46
47 QRhiBuffer* bufferForOutput(const score::gfx::Port& output) override;
48
49 ossia::small_flat_map<const Port*, TextureRenderTarget, 2> m_rts;
50
51 struct ComputePass
52 {
53 QRhiComputePipeline* pipeline{};
54 QRhiShaderResourceBindings* srb{};
55 QRhiBuffer* processUBO{};
56 };
57
58 struct GraphicsPass
59 {
60 Pipeline pipeline;
61 QRhiSampler* outputSampler{};
62 MeshBuffers meshBuffers;
63 };
64
65 ossia::small_vector<std::pair<Edge*, ComputePass>, 2> m_computePasses;
66 ossia::small_vector<std::pair<Edge*, GraphicsPass>, 2> m_graphicsPasses;
67
68 ISFNode& n;
69
70 std::vector<Sampler> m_inputSamplers;
71
72 // Storage buffers for compute shaders
73 struct StorageBuffer
74 {
75 QRhiBuffer* buffer{};
76 int size{};
77 int lastKnownSize{}; // For dynamic resizing
78 QString name;
79 QString access; // "read_only", "write_only", "read_write"
80 std::vector<isf::storage_input::layout_field> layout; // For size calculation
81 };
82 std::vector<StorageBuffer> m_storageBuffers; // Contains both ins and outs
83
84 // Only outs, matched with index in m_storageBuffers
85 std::vector<std::pair<const score::gfx::Port*, int>> m_outStorageBuffers;
86
87 // Storage images for compute shaders
88 struct StorageImage
89 {
90 QRhiTexture* texture{};
91 QString name;
92 QString access; // "read_only", "write_only", "read_write"
93 QRhiTexture::Format format{QRhiTexture::RGBA8};
94 };
95 std::vector<StorageImage> m_storageImages;
96
97 QRhiBuffer* m_materialUBO{};
98 int m_materialSize{};
99
100 // Output texture for compute shader results
101 QRhiTexture* m_outputTexture{};
102 QRhiTexture::Format m_outputFormat{QRhiTexture::RGBA8};
103
104 // Compute shader specifics
105 QRhiComputePipeline* m_computePipeline{};
106 QShader m_computeShader;
107 bool m_pipelinesDirty{true};
108};
109
110}
Data model for Interactive Shader Format filters.
Definition ISFNode.hpp:20
Renderer for a given node.
Definition NodeRenderer.hpp:11
List of nodes to be rendered to an output.
Definition RenderList.hpp:19
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:70
Definition Mesh.hpp:15
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:97
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:52
Definition RenderedCSFNode.hpp:11
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:115