Loading...
Searching...
No Matches
score-plugin-gfx/Gfx/Graph/Utils.hpp
1#pragma once
2#include <Process/Dataflow/CableData.hpp>
3
4#include <Gfx/Graph/Mesh.hpp>
5#include <Gfx/Graph/RenderState.hpp>
6#include <Gfx/Graph/Scale.hpp>
7#include <Gfx/Graph/Uniforms.hpp>
8#include <Gfx/Graph/VertexFallbackPlan.hpp>
9
10#include <ossia/detail/hash_map.hpp>
11#include <ossia/detail/small_flat_map.hpp>
12
13#include <score_plugin_gfx_export.h>
14
15#include <QtCore/QDebug>
16
17#include <atomic>
18#include <span>
19
20namespace isf
21{
22struct descriptor;
23}
24
25namespace score::gfx
26{
27class Node;
28class NodeModel;
29struct Port;
30struct RenderTargetSpecs;
31class VertexFallbackPool;
32struct Edge;
33class RenderList;
34
49{
50 explicit OffscreenFrame(QRhi& rhi) noexcept
51 {
52 QRhiCommandBuffer* cb{};
53 m_beginResult = simulateDeviceLost.load(std::memory_order_relaxed)
54 ? QRhi::FrameOpDeviceLost
55 : rhi.beginOffscreenFrame(&cb);
56 if(m_beginResult == QRhi::FrameOpSuccess)
57 {
58 if(cb)
59 {
60 m_rhi = &rhi;
61 m_commands = cb;
62 }
63 else
64 {
65 thread_local int nested = 0;
66 if((nested++ % 600) == 0)
67 qWarning() << "score.gfx: beginOffscreenFrame entered while a frame is "
68 "already recording; skipping this render (occurrence"
69 << nested << ")";
70 }
71 }
72 }
73
74 ~OffscreenFrame() noexcept { end(); }
75
76 OffscreenFrame(const OffscreenFrame&) = delete;
78 OffscreenFrame& operator=(const OffscreenFrame&) = delete;
79 OffscreenFrame& operator=(OffscreenFrame&&) = delete;
80
81 explicit operator bool() const noexcept { return m_commands; }
82 QRhiCommandBuffer& commands() const noexcept { return *m_commands; }
83
84 QRhi::FrameOpResult beginResult() const noexcept { return m_beginResult; }
85 QRhi::FrameOpResult endResult() const noexcept { return m_endResult; }
86 bool deviceLost() const noexcept
87 {
88 return m_beginResult == QRhi::FrameOpDeviceLost
89 || m_endResult == QRhi::FrameOpDeviceLost;
90 }
91
92 QRhi::FrameOpResult end() noexcept
93 {
94 if(auto* rhi = m_rhi)
95 {
96 m_rhi = nullptr;
97 m_commands = nullptr;
98 m_endResult = rhi->endOffscreenFrame();
99 }
100 return m_endResult;
101 }
102
107 static inline std::atomic_bool simulateDeviceLost{false};
108
109private:
110 QRhi* m_rhi{};
111 QRhiCommandBuffer* m_commands{};
112 QRhi::FrameOpResult m_beginResult{QRhi::FrameOpSuccess};
113 QRhi::FrameOpResult m_endResult{QRhi::FrameOpSuccess};
114};
115
124{
125 SwapChainFrameGuard(QRhi& rhi, QRhiSwapChain& swapChain) noexcept
126 : rhi{&rhi}
127 , swapChain{&swapChain}
128 {
129 }
130
131 ~SwapChainFrameGuard() noexcept
132 {
133 if(rhi && rhi->isRecordingFrame())
134 rhi->endFrame(swapChain, QRhi::SkipPresent);
135 }
136
139 SwapChainFrameGuard& operator=(const SwapChainFrameGuard&) = delete;
140 SwapChainFrameGuard& operator=(SwapChainFrameGuard&&) = delete;
141
142 void release() noexcept { rhi = nullptr; }
143
144private:
145 QRhi* rhi{};
146 QRhiSwapChain* swapChain{};
147};
148
149
164{
165 QRhiSampler* sampler{};
166 QRhiTexture* texture{};
167 QRhiTexture* fallback{};
168};
169
174{
175 ossia::hash_map<RenderList*, Sampler> samplers;
176
177 std::vector<float> data;
178 int channels{};
179 int fixedSize{0};
180 enum Mode
181 {
182 Waveform,
183 FFT,
184 Histogram
185 } mode{};
186
187 // Optional sampler config. Empty strings keep legacy defaults
188 // (linear / clamp_to_edge). Populated by ISFNode from the parsed
189 // audio_input::sampler (FILTER / WRAP). Useful for FFT reads where
190 // NEAREST filtering avoids smearing adjacent bins.
191 std::string filter;
192 std::string wrap;
193};
194
198struct Port
199{
202
204 void* value{};
205
207 Types type{};
208
210 Flag flags{};
211
213 std::vector<Edge*> edges;
214};
215
219struct SCORE_PLUGIN_GFX_EXPORT Edge
220{
224 Edge(Port* source, Port* sink, Process::CableType t);
225
226 ~Edge()
227 {
228 generation.fetch_add(1, std::memory_order_relaxed);
229 if(auto it = std::find(source->edges.begin(), source->edges.end(), this);
230 it != source->edges.end())
231 source->edges.erase(it);
232 if(auto it = std::find(sink->edges.begin(), sink->edges.end(), this);
233 it != sink->edges.end())
234 sink->edges.erase(it);
235 }
236
237 Port* source{};
238 Port* sink{};
239 Process::CableType type{};
240
243 static inline std::atomic<uint64_t> generation{0};
244};
245
250inline bool outputGrabbedBySink(const Port& output) noexcept
251{
252 for(const Edge* e : output.edges)
253 if(e && e->sink && (e->sink->flags & Flag::GrabsFromSource) == Flag::GrabsFromSource)
254 return true;
255 return false;
256}
257
262{
263 QRhiGraphicsPipeline* pipeline{};
264 QRhiShaderResourceBindings* srb{};
265
272
273 void release()
274 {
275 if(pipeline)
276 pipeline->deleteLater();
277 pipeline = nullptr;
278
279 if(srb)
280 srb->deleteLater();
281 srb = nullptr;
282
283 plan.clear();
284 }
285};
286
291{
292 // The first five members must keep this order: out-of-tree addons
293 // aggregate-initialize {texture, colorRenderBuffer, depthRenderBuffer,
294 // renderPass, renderTarget}.
295 QRhiTexture* texture{}; // Primary color attachment (location 0)
296 QRhiRenderBuffer* colorRenderBuffer{};
297 QRhiRenderBuffer* depthRenderBuffer{};
298 QRhiRenderPassDescriptor* renderPass{};
299 QRhiRenderTarget* renderTarget{};
300
301 std::vector<QRhiTexture*> additionalColorTextures; // MRT: locations 1..N
302 std::vector<QRhiRenderBuffer*> additionalColorRenderBuffers; // MRT: MSAA attachments for locations 1..N
303 QRhiTexture* depthTexture{}; // Sampleable depth (alternative to depthRenderBuffer)
304 QRhiTexture* msDepthTexture{}; // MSAA depth attachment when depthTexture is the resolve target
305
306 // A 1×1 color texture allocated when the backend requires a color attachment
307 // but the user only wants depth-only rendering. Owned by this RT.
308 QRhiTexture* dummyColorTexture{};
309
310 // Number of array layers on `texture` (1 = non-layered, >1 = texture array).
311 int arrayLayers{1};
312
313 // Multiview view count (0/1 = disabled).
314 int multiViewCount{0};
315
316 // Which layer of `texture`/`additionalColorTextures` this RT renders to.
317 // -1 = not applicable (non-layered, or MultiView handles it automatically).
318 int renderLayer{-1};
319
320 operator bool() const noexcept { return texture != nullptr || dummyColorTexture != nullptr || depthTexture != nullptr; }
321
322 int colorAttachmentCount() const noexcept
323 {
324 if(texture)
325 return 1 + (int)additionalColorTextures.size();
326 if(dummyColorTexture)
327 return 1;
328 return 0;
329 }
330
331 // Returns the actual MSAA sample count of this render target, or -1 if it
332 // cannot be determined from the stored fields. Callers must treat -1 as
333 // "unknown — fall back to the renderlist's global sample count".
334 //
335 // Lookup priority:
336 // 1. colorRenderBuffer (owned MSAA attachment — always authoritative).
337 // 2. texture (single-sample resolve target OR non-MSAA render target).
338 // 3. depthTexture (depth-only RTs).
339 // 4. msDepthTexture (MSAA depth attachment when depth resolve is used).
340 // 5. renderTarget — BUT only when this RT genuinely owns its attachments
341 // (colorRenderBuffer/texture/depthTexture set). A "bare" RT that only
342 // carries renderTarget + renderPass (e.g. a swap-chain wrapper
343 // returned by QRhiSwapChain::currentFrameRenderTarget()) is NOT
344 // queried because swap-chain render-target objects lazily write
345 // their sampleCount only when createOrResize() runs — any read before
346 // that returns the default 1, which would silently mismatch a
347 // multi-sample renderPassDescriptor and produce
348 // VUID-VkGraphicsPipelineCreateInfo-multisampledRenderToSingleSampled-06853.
349 // 6. Otherwise return -1 so the caller uses RenderList::samples(), which
350 // IS authoritative for externally-managed swap-chain RTs (it drove
351 // the swap-chain sample count in the first place).
352 int sampleCount() const noexcept
353 {
354 if(colorRenderBuffer)
355 return colorRenderBuffer->sampleCount();
356 if(texture)
357 return texture->sampleCount();
358 if(msDepthTexture)
359 return msDepthTexture->sampleCount();
360 if(depthTexture)
361 return depthTexture->sampleCount();
362 // renderTarget alone without any owned attachment = swap-chain wrapper.
363 // Its sampleCount is unreliable pre-createOrResize; fall through.
364 return -1;
365 }
366
367 void release()
368 {
369 if(texture || dummyColorTexture || depthTexture)
370 {
371 // Use deleteLater() for all GPU resources: Qt RHI commands are async
372 // and resources may still be referenced by in-flight frames until
373 // endFrame() completes. deleteLater() defers actual destruction to
374 // the next beginFrame().
375 if(texture)
376 texture->deleteLater();
377 texture = nullptr;
378
379 if(dummyColorTexture)
380 dummyColorTexture->deleteLater();
381 dummyColorTexture = nullptr;
382
383 for(auto* t : additionalColorTextures)
384 t->deleteLater();
385 additionalColorTextures.clear();
386
387 if(colorRenderBuffer)
388 colorRenderBuffer->deleteLater();
389 colorRenderBuffer = nullptr;
390
391 for(auto* rb : additionalColorRenderBuffers)
392 rb->deleteLater();
393 additionalColorRenderBuffers.clear();
394
395 if(depthRenderBuffer)
396 depthRenderBuffer->deleteLater();
397 depthRenderBuffer = nullptr;
398
399 if(depthTexture)
400 depthTexture->deleteLater();
401 depthTexture = nullptr;
402
403 if(msDepthTexture)
404 msDepthTexture->deleteLater();
405 msDepthTexture = nullptr;
406
407 if(renderPass)
408 renderPass->deleteLater();
409 renderPass = nullptr;
410
411 if(renderTarget)
412 renderTarget->deleteLater();
413 renderTarget = nullptr;
414 }
415 }
416};
417
421struct Image
422{
423 QString path;
424 std::vector<QImage> frames;
425};
426
430SCORE_PLUGIN_GFX_EXPORT
432createRenderTarget(const RenderState& state, QRhiTexture* tex, int samples, bool depth, bool samplableDepth = false);
433
439SCORE_PLUGIN_GFX_EXPORT
441 const RenderState& state, QRhiTexture::Format fmt, QSize sz, int samples, bool depth,
442 bool samplableDepth = false, QRhiTexture::Flags flags = {});
443
450SCORE_PLUGIN_GFX_EXPORT
451TextureRenderTarget createRenderTarget(
452 const RenderState& state,
453 std::span<QRhiTexture* const> colorTextures,
454 QRhiTexture* depthTexture,
455 int samples);
456
470SCORE_PLUGIN_GFX_EXPORT
471TextureRenderTarget createDepthOnlyRenderTarget(
472 const RenderState& state, QSize sz, int samples, bool samplableDepth = true,
473 QRhiTexture::Format depthFmt = QRhiTexture::D32F);
474
486SCORE_PLUGIN_GFX_EXPORT
487TextureRenderTarget createDepthOnlyRenderTarget(
488 const RenderState& state, QRhiTexture* externalDepthTexture, int samples,
489 bool samplableDepth = true);
490
500SCORE_PLUGIN_GFX_EXPORT
501TextureRenderTarget createLayeredRenderTarget(
502 const RenderState& state, QRhiTexture* colorTextureArray, int renderLayer,
503 QRhiTexture* depthTexture, int samples);
504
513SCORE_PLUGIN_GFX_EXPORT
514TextureRenderTarget createLayeredRenderTarget(
515 const RenderState& state, std::span<QRhiTexture* const> colorTextures,
516 int renderLayer, QRhiTexture* depthTexture, int samples);
517
527SCORE_PLUGIN_GFX_EXPORT
528TextureRenderTarget createMultiViewRenderTarget(
529 const RenderState& state, QRhiTexture* colorTextureArray, int multiViewCount,
530 QRhiTexture* depthTextureArray, int samples);
531
539SCORE_PLUGIN_GFX_EXPORT
540TextureRenderTarget createMultiViewRenderTarget(
541 const RenderState& state, std::span<QRhiTexture* const> colorTextures,
542 int multiViewCount, QRhiTexture* depthTextureArray, int samples);
543
551SCORE_PLUGIN_GFX_EXPORT
552QRhiTexture::Format parseOutputFormat(
553 const std::string& fmt, QRhiTexture::Format fallback) noexcept;
554
555SCORE_PLUGIN_GFX_EXPORT
556void replaceBuffer(QRhiShaderResourceBindings&, int binding, QRhiBuffer* newBuffer);
557SCORE_PLUGIN_GFX_EXPORT
558void replaceSampler(QRhiShaderResourceBindings&, int binding, QRhiSampler* newSampler);
559SCORE_PLUGIN_GFX_EXPORT
560void replaceTexture(QRhiShaderResourceBindings&, int binding, QRhiTexture* newTexture);
561
562SCORE_PLUGIN_GFX_EXPORT
563void replaceBuffer(
564 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiBuffer* newBuffer);
565SCORE_PLUGIN_GFX_EXPORT
566void replaceSampler(
567 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiSampler* newSampler);
568SCORE_PLUGIN_GFX_EXPORT
569void replaceTexture(
570 std::vector<QRhiShaderResourceBinding>&, int binding, QRhiTexture* newTexture);
571
582SCORE_PLUGIN_GFX_EXPORT
584 std::vector<QRhiShaderResourceBinding>&, int binding, int element,
585 QRhiTexture* newTexture);
586SCORE_PLUGIN_GFX_EXPORT
588 QRhiShaderResourceBindings&, int binding, int element, QRhiTexture* newTexture);
589
593SCORE_PLUGIN_GFX_EXPORT
594void replaceSampler(
595 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler);
596
600SCORE_PLUGIN_GFX_EXPORT
601void replaceTexture(
602 QRhiShaderResourceBindings&, QRhiSampler* sampler, QRhiTexture* newTexture);
603
607SCORE_PLUGIN_GFX_EXPORT
609 QRhiShaderResourceBindings&, QRhiSampler* oldSampler, QRhiSampler* newSampler,
610 QRhiTexture* newTexture);
611
615SCORE_PLUGIN_GFX_EXPORT
616void replaceTexture(
617 QRhiShaderResourceBindings& srb, QRhiTexture* old_tex, QRhiTexture* new_tex);
621SCORE_PLUGIN_GFX_EXPORT
622QRhiShaderResourceBindings* createDefaultBindings(
623 const RenderList& renderer, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
624 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
625 std::span<QRhiShaderResourceBinding> additionalBindings = {},
626 int firstSamplerBinding = 3);
627
639SCORE_PLUGIN_GFX_EXPORT
640const ossia::geometry::attribute* findGeometryAttribute(
641 const ossia::geometry& geom, std::string_view name, std::string_view semantic_key);
642
657inline QRhiBuffer::Type bufferTypeFor(
658 QRhiBuffer::UsageFlags usage,
659 QRhiBuffer::Type nonDynamic = QRhiBuffer::Immutable) noexcept
660{
661 return usage.testFlag(QRhiBuffer::UniformBuffer) ? QRhiBuffer::Dynamic
662 : nonDynamic;
663}
664
677SCORE_PLUGIN_GFX_EXPORT
679 QRhiGraphicsPipeline& pip, const QShader& vertexShader,
680 const ossia::geometry& geom, FallbackBindingPlan* outPlan = nullptr,
681 QRhi* rhi = nullptr);
682
683// FallbackBindingPlan lives in its own header so both Utils.hpp and
684// CustomMesh.hpp can depend on it without creating an include cycle
685// (Utils.hpp depends on Mesh.hpp, which transitively reaches CustomMesh
686// consumers). See <Gfx/Graph/VertexFallbackPlan.hpp>.
687
708SCORE_PLUGIN_GFX_EXPORT
710 QRhiGraphicsPipeline& pip, const QShader& vertexShader,
711 const ossia::geometry& geom, const isf::descriptor& desc,
712 QRhi& rhi, VertexFallbackPool& pool, QRhiResourceUpdateBatch& batch,
713 FallbackBindingPlan& outPlan);
714
717SCORE_PLUGIN_GFX_EXPORT void dropTrailingOrphanVertexBindings(
718 QRhiVertexInputLayout& layout) noexcept;
719
720SCORE_PLUGIN_GFX_EXPORT void warnOrphanVertexBindings(
721 const QRhiVertexInputLayout& layout, const char* where) noexcept;
722
726SCORE_PLUGIN_GFX_EXPORT
727Pipeline buildPipeline(
728 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
729 const QShader& fragmentS, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
730 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
731 std::span<QRhiShaderResourceBinding> additionalBindings = {});
732
743SCORE_PLUGIN_GFX_EXPORT
744Pipeline buildPipeline(
745 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
746 const QShader& fragmentS, const TextureRenderTarget& rt,
747 QRhiShaderResourceBindings* srb);
748
749SCORE_PLUGIN_GFX_EXPORT
750Pipeline buildPipeline(
751 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
752 const QShader& fragmentS, const TextureRenderTarget& rt,
753 QRhiShaderResourceBindings* srb, const QRhiGraphicsPipeline::TargetBlend& blend);
754
762SCORE_PLUGIN_GFX_EXPORT
763Pipeline buildPipeline(
764 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
765 const QShader& fragmentS, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
766 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
767 const QRhiGraphicsPipeline::TargetBlend& blend,
768 std::span<QRhiShaderResourceBinding> additionalBindings = {});
769
770// Forward declarations — definitions in PipelineStateHelpers.hpp, IsfBindingsBuilder.hpp
771} // namespace score::gfx
772
773namespace isf
774{
775struct sampler_config;
776}
777
778namespace score::gfx
779{
792SCORE_PLUGIN_GFX_EXPORT
793QRhiSampler* makeSampler(QRhi& rhi, const isf::sampler_config& cfg);
794
798SCORE_PLUGIN_GFX_EXPORT
799bool declaresCompare(const isf::sampler_config& cfg) noexcept;
800
806SCORE_PLUGIN_GFX_EXPORT
807bool followTextureMips(QRhiSampler& sampler, const QRhiTexture& texture);
808} // namespace score::gfx
809
810namespace isf
811{
812struct pipeline_state;
813}
814
815namespace score::gfx
816{
817struct GraphicsStorageResources;
818
840SCORE_PLUGIN_GFX_EXPORT
842 const RenderList& renderer, const Mesh& mesh, const QShader& vertexS,
843 const QShader& fragmentS, const TextureRenderTarget& rt, QRhiBuffer* processUBO,
844 QRhiBuffer* materialUBO, std::span<const Sampler> samplers,
845 std::span<QRhiShaderResourceBinding> extraBindings,
846 const isf::pipeline_state& state,
847 int multiViewCount = 0,
848 bool useShadingRate = false,
849 int firstSamplerBinding = 3,
850 std::span<const QRhiGraphicsPipeline::TargetBlend> seedBlends = {});
851
857SCORE_PLUGIN_GFX_EXPORT
858std::pair<QShader, QShader> makeShaders(
859 const RenderState& v, QString vert, QString frag, int multiViewCount = 0);
860
866SCORE_PLUGIN_GFX_EXPORT
867QShader makeCompute(const RenderState& v, QString compt);
868
874struct SCORE_PLUGIN_GFX_EXPORT DefaultShaderMaterial
875{
876 void init(
877 RenderList& renderer, const std::vector<Port*>& input,
878 ossia::small_vector<Sampler, 8>& samplers);
879
880 QRhiBuffer* buffer{};
881 int size{};
882};
883
887SCORE_PLUGIN_GFX_EXPORT
888QSize resizeTextureSize(QSize img, int min, int max) noexcept;
889
893SCORE_PLUGIN_GFX_EXPORT
894QImage resizeTexture(const QImage& img, int min, int max) noexcept;
895
896inline void copyMatrix(const QMatrix4x4& mat, float* ptr) noexcept
897{
898 memcpy(ptr, mat.constData(), sizeof(float) * 16);
899}
900inline void copyMatrix(const QMatrix3x3& mat, float* ptr) noexcept
901{
902 memcpy(ptr, mat.constData(), sizeof(float) * 9);
903}
904
908SCORE_PLUGIN_GFX_EXPORT
909QSizeF computeScaleForMeshSizing(score::gfx::ScaleMode mode, QSizeF viewport, QSizeF texture);
910
914SCORE_PLUGIN_GFX_EXPORT
916 score::gfx::ScaleMode mode, QSizeF viewport, QSizeF texture);
917
922 QRhiResourceUpdateBatch* ub
923 , QRhiBuffer* buf
924 , int offset
925 , int64_t bytesize
926 , const char* data
927 )
928{
929#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
930 ub->updateDynamicBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
931#else
932 ub->updateDynamicBuffer(buf, offset, bytesize, data);
933#endif
934}
935
937 QRhiResourceUpdateBatch* ub
938 , QRhiBuffer* buf
939 , int offset
940 , QByteArray b
941 )
942{
943#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
944 ub->updateDynamicBuffer(buf, offset, std::move(b));
945#else
946 ub->updateDynamicBuffer(buf, offset, b.size(), b.data());
947#endif
948}
949
954 QRhiResourceUpdateBatch* ub
955 , QRhiBuffer* buf
956 , int offset
957 , int64_t bytesize
958 , const char* data
959 )
960{
961#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
962 ub->uploadStaticBuffer(buf, offset, QByteArray::fromRawData(data, bytesize));
963#else
964 ub->uploadStaticBuffer(buf, offset, bytesize, data);
965#endif
966}
967
969 QRhiResourceUpdateBatch* ub
970 , QRhiBuffer* buf
971 , int offset
972 , QByteArray b
973 )
974{
975#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
976 ub->uploadStaticBuffer(buf, offset, std::move(b));
977#else
978 ub->uploadStaticBuffer(buf, offset, b.size(), b.data());
979#endif
980}
981
986SCORE_PLUGIN_GFX_EXPORT
987QRhiTexture::Format imageFormatFromQualifier(std::string_view qualifier) noexcept;
988
994SCORE_PLUGIN_GFX_EXPORT
996 QRhi& rhi, QRhiResourceUpdateBatch& res, std::string_view qualifier, int dimensions,
997 bool array, bool cube);
998
1004SCORE_PLUGIN_GFX_EXPORT
1005int storageImageUnitLimit(QRhi& rhi);
1006
1008SCORE_PLUGIN_GFX_EXPORT
1009int maxStorageImageBinding(QStringView glsl);
1010
1016SCORE_PLUGIN_GFX_EXPORT
1018 QRhi& rhi, const char* kind, std::initializer_list<const QString*> sources);
1019
1020SCORE_PLUGIN_GFX_EXPORT
1021std::vector<Sampler> initInputSamplers(
1022 const score::gfx::Node& node, RenderList& renderer, const std::vector<Port*>& ports,
1023 const isf::descriptor* desc = nullptr);
1024
1029SCORE_PLUGIN_GFX_EXPORT
1031 std::span<const Sampler> samplers, const score::gfx::Node& node, const Port& input,
1032 const RenderTargetSpecs& spec);
1033}
Root data model for visual nodes.
Definition score-plugin-gfx/Gfx/Graph/Node.hpp:76
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
TreeNode< DeviceExplorerNode > Node
Definition DeviceNode.hpp:74
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
QSizeF computeScaleForTexcoordSizing(ScaleMode mode, QSizeF renderSize, QSizeF textureSize)
Compute the scale to apply to a texture rendered to a quad the size of viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1656
bool remapPipelineVertexInputs(QRhiGraphicsPipeline &pip, const QShader &vertexShader, const ossia::geometry &geom, FallbackBindingPlan *outPlan, QRhi *rhi)
Remap a pipeline's vertex input layout using semantic matching.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:909
void updateDynamicBufferWithStoredData(QRhiResourceUpdateBatch *ub, QRhiBuffer *buf, int offset, int64_t bytesize, const char *data)
Schedule a Dynamic buffer update when we can guarantee the buffer outlives the frame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:921
int maxStorageImageBinding(QStringView glsl)
Highest binding of a storage image declared in glsl, -1 if none.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2449
TextureRenderTarget createLayeredRenderTarget(const RenderState &state, QRhiTexture *colorTextureArray, int renderLayer, QRhiTexture *depthTex, int samples)
Create a render target that targets a single layer of a texture array.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2005
QRhiTexture * createStorageImagePlaceholder(QRhi &rhi, QRhiResourceUpdateBatch &res, std::string_view qualifier, int dimensions, bool array, bool cube)
A zero-filled 1x1 texture a storage image binding declared with qualifier can take when nothing is bo...
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2534
const ossia::geometry::attribute * findGeometryAttribute(const ossia::geometry &geom, std::string_view name, std::string_view semantic_key)
Match a (name, semantic) request to an upstream geometry attribute.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:607
QRhiBuffer::Type bufferTypeFor(QRhiBuffer::UsageFlags usage, QRhiBuffer::Type nonDynamic=QRhiBuffer::Immutable) noexcept
The QRhi buffer type a usage flag is allowed to be created with.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:657
void dropTrailingOrphanVertexBindings(QRhiVertexInputLayout &layout) noexcept
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:929
QRhiSampler * makeSampler(QRhi &rhi, const isf::sampler_config &cfg)
Build a QRhiSampler from an isf::sampler_config.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2394
QShader makeCompute(const RenderState &v, QString compute)
Compile a compute shader.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1466
bool outputGrabbedBySink(const Port &output) noexcept
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:250
bool followTextureMips(QRhiSampler &sampler, const QRhiTexture &texture)
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2414
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag, int multiViewCount)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1367
bool declaresCompare(const isf::sampler_config &cfg) noexcept
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2389
QRhiTexture::Format imageFormatFromQualifier(std::string_view qualifier) noexcept
QRhi format for a GLSL image format qualifier ("rgba8", "r32ui", ...); RGBA8 when unknown.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2508
TextureRenderTarget createRenderTarget(const RenderState &state, QRhiTexture *tex, int samples, bool depth, bool samplableDepth)
Create a render target from a texture.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:68
TextureRenderTarget createDepthOnlyRenderTarget(const RenderState &state, QSize sz, int samples, bool samplableDepth, QRhiTexture::Format depthFmt)
Create a depth-only render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1890
Pipeline buildPipeline(const RenderList &renderer, const Mesh &mesh, const QShader &vertexS, const QShader &fragmentS, const TextureRenderTarget &rt, QRhiShaderResourceBindings *srb)
Lower-level buildPipeline variant: bring your own SRB.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1170
int storageImageUnitLimit(QRhi &rhi)
Number of storage image units the backend binds by binding number: GL_MAX_IMAGE_UNITS on OpenGL (8 wh...
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2426
void uploadStaticBufferWithStoredData(QRhiResourceUpdateBatch *ub, QRhiBuffer *buf, int offset, int64_t bytesize, const char *data)
Schedule a Static buffer update when we can guarantee the buffer outlives the frame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:953
QRhiShaderResourceBindings * createDefaultBindings(const RenderList &renderer, const TextureRenderTarget &rt, QRhiBuffer *processUBO, QRhiBuffer *materialUBO, std::span< const Sampler > samplers, std::span< QRhiShaderResourceBinding > additionalBindings, int firstSamplerBinding)
Create bindings following the score conventions for shaders and materials.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1093
QRhiTexture::Format parseOutputFormat(const std::string &fmt, QRhiTexture::Format fallback) noexcept
Map an ISF/CSF FORMAT string to a QRhiTexture::Format.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2320
QImage resizeTexture(const QImage &img, int min, int max) noexcept
Resize a texture to fit within GPU limits.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1606
QSizeF computeScaleForMeshSizing(ScaleMode mode, QSizeF viewport, QSizeF texture)
Compute the scale to apply to a texture so that it fits in a GL viewport.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1616
TextureRenderTarget createMultiViewRenderTarget(const RenderState &state, QRhiTexture *colorTextureArray, int multiViewCount, QRhiTexture *depthTextureArray, int samples)
Create a multiview render target (single RT drawing N views at once).
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2052
Pipeline buildPipelineWithState(const RenderList &renderer, const Mesh &mesh, const QShader &vertexS, const QShader &fragmentS, const TextureRenderTarget &rt, QRhiBuffer *processUBO, QRhiBuffer *materialUBO, std::span< const Sampler > samplers, std::span< QRhiShaderResourceBinding > extraBindings, const isf::pipeline_state &state, int multiViewCount, bool useShadingRate, int firstSamplerBinding, std::span< const QRhiGraphicsPipeline::TargetBlend > seedBlends)
Create a render pipeline applying pipeline_state from an ISF descriptor.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1211
void replaceSamplerAndTexture(QRhiShaderResourceBindings &srb, QRhiSampler *oldSampler, QRhiSampler *newSampler, QRhiTexture *newTexture)
Replace both sampler and texture in a SRC.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:519
bool warnStorageImageUnits(QRhi &rhi, const char *kind, std::initializer_list< const QString * > sources)
Warn once per shader when a storage image in sources has a binding the OpenGL backend cannot bind (at...
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:2472
ScaleMode
How to resize a texture to adapt it to a viewport.
Definition Scale.hpp:10
void updateInputSamplerFilter(std::span< const Sampler > samplers, const score::gfx::Node &node, const Port &input, const RenderTargetSpecs &spec)
Give the sampler initInputSamplers() created for input, one of node's input ports,...
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1849
void replaceTextureElement(std::vector< QRhiShaderResourceBinding > &tmp, int binding, int element, QRhiTexture *newTexture)
Replace one element of a multi-element texture binding.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:419
QSize resizeTextureSize(QSize sz, int min, int max) noexcept
Resize the size of a texture to fit within GPU limits.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1555
Data model for audio data being sent to the GPU.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:174
Utility to represent a shader material following score conventions.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:875
Connection between two score::gfx::Port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:220
Definition VertexFallbackPlan.hpp:27
Image data and metadata.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:422
RAII bracket for QRhi::beginOffscreenFrame / endOffscreenFrame.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:49
static std::atomic_bool simulateDeviceLost
Test seam: while set, every new frame fails to begin with FrameOpDeviceLost without touching the QRhi...
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:107
Useful abstraction for storing a graphics pipeline and associated resource bindings.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:262
FallbackBindingPlan plan
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:271
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:199
void * value
Pointer to the corresponding data.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:204
score::gfx::Node * node
Parent node of the port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:201
Types type
Type of the value.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:207
std::vector< Edge * > edges
Edges connected to that port.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:213
Flag flags
Optional setting flags.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:210
Global state associated to a rendering context.
Definition RenderState.hpp:37
Stores a sampler and the texture currently associated with it.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:164
Closes a swapchain frame if the scope is left without presenting it.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:124
Useful abstraction for storing all the data related to a render target.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:291