Loading...
Searching...
No Matches
IsfBindingsBuilder.hpp
1#pragma once
2#include <QString>
3#include <functional>
4
5// Shared infrastructure for binding `storage_input` and `csf_image_input`
6// declarations into a graphics pipeline's shader resource bindings.
7//
8// Mirrors the pattern established by RenderedCSFNode (for compute) but wired
9// to Vertex|Fragment stages for ISF / Raw Raster Pipeline / Scene Pass nodes.
10
11#include <Gfx/Graph/Utils.hpp>
12#include <isf.hpp>
13
14#include <QtGui/private/qrhi_p.h>
15
16#include <score_plugin_gfx_export.h>
17
18#include <cstdint>
19#include <string>
20#include <string_view>
21#include <vector>
22
23namespace score::gfx
24{
25
36{
37 std::string name;
38 std::string access;
39 std::string buffer_usage;
40 bool persistent{false};
41 bool owned{true};
42 bool adopted{false};
43 bool from_port{false};
44 int64_t size{0};
47 int64_t offset{0};
50 QString refused;
51
52 // Layout fields (for size computation + validation). May be empty for auxiliaries.
53 std::vector<isf::storage_input::layout_field> layout;
54
55 // Buffer handles. `buffer` is the currently-written slot (R/W for persistent).
56 // `prev` is only set when persistent — holds the previous frame's data (R/O).
57 QRhiBuffer* buffer{};
58 QRhiBuffer* prev{};
59
60 // Resolved SRB binding slots.
61 int binding{-1};
62 int prev_binding{-1};
63
64 // Stages that see this binding (fragment / vertex / both).
65 QRhiShaderResourceBinding::StageFlags stages{};
66
67 // Optional: indices into the Node's input/output port vectors. -1 = not
68 // connected to a port (e.g. private aux buffer or persistent-only).
69 int input_port_index{-1};
70 int output_port_index{-1};
71
76 int count{0};
77};
78
83{
84 std::string name;
85 std::string access;
86 std::string format;
87 bool is3D{false};
88 bool cubemap{false};
89 bool is_array{false};
90 bool persistent{false};
92 std::string width_expression;
93 std::string height_expression;
94 int depth{0};
95 int layers{0};
96
97 QRhiTexture* texture{};
98 QRhiTexture* prev{};
99 bool owned{true};
100
101 int binding{-1};
102 int prev_binding{-1};
103 QRhiShaderResourceBinding::StageFlags stages{};
104
105 int input_port_index{-1};
106 int output_port_index{-1};
107};
108
116{
117 std::string name;
118 QRhiBuffer* buffer{};
119 bool owned{false};
120 bool adopted{false};
121 bool from_port{false};
122 int binding{-1};
123 QRhiShaderResourceBinding::StageFlags stages{};
124 int input_port_index{-1};
127 int64_t offset{0};
128 int64_t size{0};
129 QString refused;
130
134 int64_t declared_size{};
136 int64_t min_size{};
137};
138
143{
144 std::vector<GraphicsSSBO> ssbos;
145 std::vector<GraphicsStorageImage> images;
146 std::vector<GraphicsUBO> ubos;
147
148 // Quick aliases: first SSBO with BUFFER_USAGE="indirect_draw*". Populated
149 // by collectGraphicsStorageResources. Updated by callers when the underlying
150 // SSBO's buffer pointer changes (e.g. when an upstream CSF rebuilds it).
151 QRhiBuffer* indirectDrawBuffer{};
152 bool indirectDrawIndexed{false};
153 int indirectDrawSsboIndex{-1};
154
155 // Next free binding index after all graphics-visible storage resources
156 // (SSBOs + images + UBOs) have been assigned by
157 // collectGraphicsStorageResources. This is exactly the value libisf's
158 // isf_emit_graphics_storage() returns (isf.cpp:3406-3449) and the binding
159 // at which the codegen places the multiview UBO (isf.cpp:3773-3783). Callers
160 // that append a multiview UBO MUST use this rather than re-deriving a max
161 // over ssbos/images alone: that omits uniform_input UBOs and collides the
162 // multiview binding with the last UBO's slot. -1 until the first
163 // collectGraphicsStorageResources() call.
164 int nextBinding{-1};
165
166 // Sentinel zero-buffer bound when an SSBO/UBO upstream port disconnects
167 // mid-session. QRhi (especially Vulkan) requires every SRB binding to
168 // point at a valid resource — without a sentinel, a disconnect leaves
169 // the binding pointing at a dangling QRhiBuffer* (the prior upstream's
170 // buffer, which was deleteLater'd when the upstream node was destroyed).
171 // Lazily allocated on first disconnect, sized to the largest binding
172 // observed (sentinelSize). Single buffer reused for both SSBO and UBO
173 // disconnects since the descriptor type is set on the SRB binding side,
174 // not the buffer side; QRhi accepts a buffer with both StorageBuffer and
175 // UniformBuffer usage flags. owned=true; freed in release().
176 QRhiBuffer* sentinelBuffer{};
177 QRhiBuffer* sentinelUniformBuffer{};
178 uint32_t sentinelSize{0};
179
182 SCORE_PLUGIN_GFX_EXPORT void release(RenderList& renderer);
183};
184
185// --- API ------------------------------------------------------------------
186
199SCORE_PLUGIN_GFX_EXPORT
201 const isf::descriptor& desc, int firstBinding, GraphicsStorageResources& out,
202 int firstInlet = 0, int firstImageBinding = -1);
203
208SCORE_PLUGIN_GFX_EXPORT
209int graphicsStorageImageBindingCount(const isf::descriptor& desc) noexcept;
210
218SCORE_PLUGIN_GFX_EXPORT
219std::vector<int> storageImageInputSamplers(
220 const isf::descriptor& desc, const std::vector<Port*>& ports, int firstInlet = 0);
221
229SCORE_PLUGIN_GFX_EXPORT
231 QRhi& rhi, QRhiResourceUpdateBatch& res, const RenderList& renderer,
232 const isf::descriptor& desc, GraphicsStorageResources& store,
233 QSize renderSize,
236 const std::function<QSize(const GraphicsStorageImage&, QSize)>& imageSize = {});
237
247SCORE_PLUGIN_GFX_EXPORT
249 QRhi& rhi, QRhiResourceUpdateBatch& res, const std::vector<Port*>& inputPorts,
250 const isf::descriptor& desc, GraphicsStorageResources& store);
251
259SCORE_PLUGIN_GFX_EXPORT
260QVarLengthArray<QRhiShaderResourceBinding, 8> buildExtraBindings(
261 const GraphicsStorageResources& store);
262
271SCORE_PLUGIN_GFX_EXPORT
273 RenderList& renderer, const std::vector<Port*>& inputPorts,
274 GraphicsStorageResources& store,
275 QRhiShaderResourceBindings* srb = nullptr);
276
285SCORE_PLUGIN_GFX_EXPORT
287 GraphicsStorageResources& store, QRhiShaderResourceBindings& srb);
288
297SCORE_PLUGIN_GFX_EXPORT
298void swapPersistentSSBOsState(GraphicsStorageResources& store);
299
309SCORE_PLUGIN_GFX_EXPORT
311 const GraphicsStorageResources& store, QRhiShaderResourceBindings& srb);
312
333SCORE_PLUGIN_GFX_EXPORT
335 GraphicsStorageResources& store, const ossia::geometry& geometry,
336 QRhiShaderResourceBindings* srb = nullptr);
337
364SCORE_PLUGIN_GFX_EXPORT
366 QRhi& rhi, QRhiResourceUpdateBatch& res,
367 GraphicsStorageResources& store, const ossia::geometry& geometry,
368 QRhiShaderResourceBindings* srb = nullptr);
369
379SCORE_PLUGIN_GFX_EXPORT
380QRhiShaderResourceBinding::StageFlags visibilityToStages(std::string_view visibility) noexcept;
381
411SCORE_PLUGIN_GFX_EXPORT
412int64_t glslTypeSizeBytes(std::string_view type) noexcept;
413
423SCORE_PLUGIN_GFX_EXPORT
424int64_t glslTypeSizeBytes(std::string_view type, const isf::descriptor& d) noexcept;
425
432SCORE_PLUGIN_GFX_EXPORT
433int64_t std430LayoutSize(
434 const std::vector<isf::storage_input::layout_field>& layout) noexcept;
435
452SCORE_PLUGIN_GFX_EXPORT
453int64_t std430ArrayStride(std::string_view type) noexcept;
454
460SCORE_PLUGIN_GFX_EXPORT
461int64_t std430ArrayStride(std::string_view type, const isf::descriptor& d) noexcept;
462
463}
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
void bindUpstreamImagesFromGeometry(GraphicsStorageResources &store, const ossia::geometry &geometry, QRhiShaderResourceBindings *srb)
Wire read-only csf_image_input storage images to an upstream geometry's published auxiliary_textures.
Definition IsfBindingsBuilder.cpp:1140
int graphicsStorageImageBindingCount(const isf::descriptor &desc) noexcept
Number of bindings the graphics-visible csf_image_input's of desc take, _prev slots included.
Definition IsfBindingsBuilder.cpp:167
int64_t glslTypeSizeBytes(std::string_view type) noexcept
Byte size of a single GLSL primitive type as used for SSBO element strides in this codebase.
Definition IsfBindingsBuilder.cpp:22
void collectGraphicsStorageResources(const isf::descriptor &desc, int firstBinding, GraphicsStorageResources &out, int firstInlet, int firstImageBinding)
Walk desc.inputs once and populate out with the storage buffers and images declared by the shader.
Definition IsfBindingsBuilder.cpp:207
int64_t std430ArrayStride(std::string_view type) noexcept
std430 array stride for a GLSL primitive type when laid out as T array[] inside a shader storage bloc...
Definition IsfBindingsBuilder.cpp:41
QVarLengthArray< QRhiShaderResourceBinding, 8 > buildExtraBindings(const GraphicsStorageResources &store)
Produce the QRhiShaderResourceBinding list for the graphics pipeline.
Definition IsfBindingsBuilder.cpp:682
bool resizeCountedStorage(QRhi &rhi, QRhiResourceUpdateBatch &res, const std::vector< Port * > &inputPorts, const isf::descriptor &desc, GraphicsStorageResources &store)
Resize the owned flexible-array SSBOs whose size control changed.
Definition IsfBindingsBuilder.cpp:909
void ensureStorageResources(QRhi &rhi, QRhiResourceUpdateBatch &res, const RenderList &renderer, const isf::descriptor &, GraphicsStorageResources &store, QSize renderSize, const std::function< QSize(const GraphicsStorageImage &, QSize)> &imageSize)
Create missing buffers and textures.
Definition IsfBindingsBuilder.cpp:513
std::vector< int > storageImageInputSamplers(const isf::descriptor &desc, const std::vector< Port * > &ports, int firstInlet)
Indices, in the list initInputSamplers() returns for ports, of the samplers it creates for the input ...
Definition IsfBindingsBuilder.cpp:177
void swapPersistentSSBOs(GraphicsStorageResources &store, QRhiShaderResourceBindings &srb)
Swap current/prev for all persistent SSBOs and storage images, then update the SRB.
Definition IsfBindingsBuilder.cpp:1361
void bindUpstreamBuffers(RenderList &renderer, const std::vector< Port * > &inputPorts, GraphicsStorageResources &store, QRhiShaderResourceBindings *srb)
Wire read-only SSBOs to upstream geometry buffers.
Definition IsfBindingsBuilder.cpp:952
void reapplyStorageBindings(const GraphicsStorageResources &store, QRhiShaderResourceBindings &srb)
Re-apply the current persistent-storage state to a single SRB.
Definition IsfBindingsBuilder.cpp:1338
QRhiShaderResourceBinding::StageFlags visibilityToStages(std::string_view v) noexcept
Decode an isf::storage_input::visibility string to Qt RHI stage flags.
Definition IsfBindingsBuilder.cpp:136
void bindUpstreamBuffersFromGeometry(QRhi &rhi, QRhiResourceUpdateBatch &res, GraphicsStorageResources &store, const ossia::geometry &geometry, QRhiShaderResourceBindings *srb)
Wire INPUTS storage_input / uniform_input bindings to upstream geometry's published auxiliary_buffers...
Definition IsfBindingsBuilder.cpp:1191
void swapPersistentSSBOsState(GraphicsStorageResources &store)
Swap current/prev pointers in store without touching any SRB.
Definition IsfBindingsBuilder.cpp:1328
int64_t std430LayoutSize(const std::vector< isf::storage_input::layout_field > &layout) noexcept
Compute the std430 element size of a layout (vector of {name,type} field entries),...
Definition IsfBindingsBuilder.cpp:56
One SSBO attached to a graphics pipeline.
Definition IsfBindingsBuilder.hpp:36
std::string access
"read_only" / "write_only" / "read_write"
Definition IsfBindingsBuilder.hpp:38
bool from_port
buffer was borrowed through the Buffer input port
Definition IsfBindingsBuilder.hpp:43
std::string buffer_usage
"", "indirect_draw", "indirect_draw_indexed"
Definition IsfBindingsBuilder.hpp:39
bool persistent
Ping-pong swapped every frame.
Definition IsfBindingsBuilder.hpp:40
std::string name
Base GLSL identifier (e.g.
Definition IsfBindingsBuilder.hpp:37
QString refused
Definition IsfBindingsBuilder.hpp:50
int prev_binding
Binding of prev (only set when persistent)
Definition IsfBindingsBuilder.hpp:62
int size_port_index
Definition IsfBindingsBuilder.hpp:75
int64_t size
Definition IsfBindingsBuilder.hpp:44
bool adopted
Holds a RenderList::adoptBuffer reference on buffer
Definition IsfBindingsBuilder.hpp:42
bool owned
This SSBO owns buffer and prev (releases them)
Definition IsfBindingsBuilder.hpp:41
int binding
Binding of buffer
Definition IsfBindingsBuilder.hpp:61
int64_t offset
Definition IsfBindingsBuilder.hpp:47
One storage image attached to a graphics pipeline.
Definition IsfBindingsBuilder.hpp:83
bool is_array
image2DArray — N-layer array texture
Definition IsfBindingsBuilder.hpp:89
int depth
Explicit Z dimension for 3D textures; 0 = use default (16)
Definition IsfBindingsBuilder.hpp:94
bool persistent
Definition IsfBindingsBuilder.hpp:90
std::string format
e.g.
Definition IsfBindingsBuilder.hpp:86
QRhiTexture * texture
Current (write / read_write) slot.
Definition IsfBindingsBuilder.hpp:97
int layers
Layer count for is_array (0 = use parser-supplied default)
Definition IsfBindingsBuilder.hpp:95
std::string width_expression
WIDTH / HEIGHT, literal or $ expression; empty = the render size.
Definition IsfBindingsBuilder.hpp:92
int prev_binding
Binding of prev (only set when persistent)
Definition IsfBindingsBuilder.hpp:102
bool cubemap
imageCube — 6-layer cubemap storage image
Definition IsfBindingsBuilder.hpp:88
std::string access
"read_only" / "write_only" / "read_write"
Definition IsfBindingsBuilder.hpp:85
QRhiTexture * prev
Previous frame (read-only); only set when persistent.
Definition IsfBindingsBuilder.hpp:98
Aggregate of all graphics-visible storage resources for a node.
Definition IsfBindingsBuilder.hpp:143
QRhiBuffer * sentinelBuffer
StorageBuffer usage only.
Definition IsfBindingsBuilder.hpp:176
QRhiBuffer * sentinelUniformBuffer
UniformBuffer usage only (GL rejects combined usages)
Definition IsfBindingsBuilder.hpp:177
void release(RenderList &renderer)
Definition IsfBindingsBuilder.cpp:852
One UBO sourced from an upstream Buffer port (uniform_input).
Definition IsfBindingsBuilder.hpp:116
bool owned
Always false for now: borrowed from upstream.
Definition IsfBindingsBuilder.hpp:119
int64_t min_size
The smallest buffer that can back it: minimumUniformBlockSize (U42).
Definition IsfBindingsBuilder.hpp:136
bool from_port
buffer was borrowed through the Buffer input port
Definition IsfBindingsBuilder.hpp:121
int64_t offset
Definition IsfBindingsBuilder.hpp:127
bool adopted
Holds a RenderList::adoptBuffer reference on buffer
Definition IsfBindingsBuilder.hpp:120
QString refused
See GraphicsSSBO::refused.
Definition IsfBindingsBuilder.hpp:129
int64_t declared_size
Definition IsfBindingsBuilder.hpp:134