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