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 BufferView createStorageBuffer(
42 RenderList& renderer, const QString& name, const QString& access, int size);
43 void updateStorageBuffers(RenderList& renderer, QRhiResourceUpdateBatch& res);
44 void recreateShaderResourceBindings(RenderList& renderer, QRhiResourceUpdateBatch& res);
45 int getArraySizeFromUI(const QString& bufferName) const;
46 QString updateShaderWithImageFormats(QString current);
47
48 BufferView bufferForOutput(const score::gfx::Port& output) override;
49
50 ossia::small_flat_map<const Port*, TextureRenderTarget, 2> m_rts;
51
52 struct ComputePass
53 {
54 QRhiComputePipeline* pipeline{};
55 QRhiShaderResourceBindings* srb{};
56 QRhiBuffer* processUBO{};
57 };
58
59 struct GraphicsPass
60 {
61 Pipeline pipeline;
62 QRhiSampler* outputSampler{};
63 MeshBuffers meshBuffers;
64 };
65
66 ossia::small_vector<std::pair<Edge*, ComputePass>, 2> m_computePasses;
67 ossia::small_vector<std::pair<Edge*, GraphicsPass>, 2> m_graphicsPasses;
68
69 ISFNode& n;
70
71 std::vector<Sampler> m_inputSamplers;
72
73 // Storage buffers for compute shaders
74 struct StorageBuffer
75 {
76 QRhiBuffer* buffer{};
77 int64_t size{};
78 int64_t lastKnownSize{}; // For dynamic resizing
79 QString name;
80 QString access; // "read_only", "write_only", "read_write"
81 std::vector<isf::storage_input::layout_field> layout; // For size calculation
82 };
83 std::vector<StorageBuffer> m_storageBuffers; // Contains both ins and outs
84
85 // Only outs, matched with index in m_storageBuffers
86 std::vector<std::pair<const score::gfx::Port*, int>> m_outStorageBuffers;
87
88 // Storage images for compute shaders
89 struct StorageImage
90 {
91 QRhiTexture* texture{};
92 QString name;
93 QString access; // "read_only", "write_only", "read_write"
94 QRhiTexture::Format format{QRhiTexture::RGBA8};
95 };
96 std::vector<StorageImage> m_storageImages;
97
98 QRhiBuffer* m_materialUBO{};
99 int m_materialSize{};
100
101 // Output texture for compute shader results
102 QRhiTexture* m_outputTexture{};
103 QRhiTexture::Format m_outputFormat{QRhiTexture::RGBA8};
104
105 // Compute shader specifics
106 QRhiComputePipeline* m_computePipeline{};
107 QShader m_computeShader;
108 bool m_pipelinesDirty{true};
109};
110
111}
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:71
Definition Mesh.hpp:23
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:98
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:53
Definition RenderedCSFNode.hpp:11
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:116