Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
ShaderNodeRhi.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorRendering/phosphorrendering_export.h>
8
14
15#include <QColor>
16#include <QImage>
17#include <QPointF>
18#include <QPointer>
19#include <QQuickItem>
20#include <QSGRenderNode>
21#include <QSGTextureProvider>
22#include <QSize>
23#include <QString>
24#include <QStringList>
25#include <QVector>
26#include <QVector4D>
27
28#include <array>
29#include <atomic>
30#include <map>
31#include <memory>
32#include <mutex>
33#include <optional>
34
35#include <rhi/qrhi.h>
36
37namespace PhosphorRendering {
38
39// Forward declare constants used in member declarations.
40// A namespace-scope `constexpr int` in a header is NOT implicitly inline: it is
41// const and therefore has internal linkage, so each translation unit gets its
42// own copy. That is harmless for an integral constant used only in constant
43// expressions and array bounds, which is every use here, and it matches the
44// existing style of kFirstFreeConsumerBinding / kMaxConsumerBinding below. Only
45// a constexpr STATIC DATA MEMBER became implicitly inline in C++17, which is the
46// rule this comment used to cite.
49constexpr int kMaxCustomParams = 8;
50constexpr int kMaxCustomColors = 16;
51
52// ── Consumer binding range (for setExtraBinding) ────────────────────────
53// The binding table is PhosphorShaders::Bindings (ShaderBindings.h), the one
54// layout every shader family's shared GLSL header declares and the validator
55// reflects baked stages against. Library-managed bindings: 0 (UBO), 2..9
56// (multipass buffers), 10 (audio), 11..14 (user textures), 15 (wallpaper /
57// backdrop), 16 (depth). Assigning any of those via setExtraBinding() would
58// duplicate SRB entries and is rejected at runtime. Binding 1 is the one
59// "free-in-the-gap" slot; 17..31 are free as well.
60//
61// Phosphor uses binding 1 for its zone-labels texture by convention.
62// Other consumers that interoperate with Phosphor should pick from
63// (kReservedBindingRangeEnd + 1)..kMaxConsumerBinding to avoid a per-instance
64// overwrite. (The binding table spells that lower bound kExtraBase, but that
65// name lives in PhosphorShaders::Bindings and is not declared in this
66// namespace, so the local spelling is the one to use here.)
75// An exported MIRROR of Bindings::kChannelBase, not a value this library tests
76// against: the consumer-binding predicate forwards to
77// PhosphorShaders::isConsumerBinding, and the setExtraBinding rejection reads
78// kFirstFreeConsumerBinding, kReservedBindingRangeEnd and kMaxConsumerBinding.
79// Kept for an out-of-tree consumer describing the same range.
83
88
90constexpr bool isConsumerBinding(int binding) noexcept
91{
93}
94
157class PHOSPHORRENDERING_EXPORT ShaderNodeRhi : public QSGRenderNode
158{
159public:
174 explicit ShaderNodeRhi(QQuickItem* item, std::unique_ptr<PhosphorShaders::IUboProfile> profile = nullptr);
175 ~ShaderNodeRhi() override;
176
185
196 bool hasValidItem() const
197 {
198 return m_itemValid.load(std::memory_order_acquire);
199 }
200
208 const std::shared_ptr<ShaderNodeLiveness>& liveness() const
209 {
210 return m_liveness;
211 }
212
213 // QSGRenderNode
214 QSGRenderNode::StateFlags changedStates() const override;
215 QSGRenderNode::RenderingFlags flags() const override;
216 QRectF rect() const override;
217 void prepare() override;
218 void render(const RenderState* state) override;
219 void releaseResources() override;
228 void preprocess() override;
229
230 // ── Uniform Extension ──────────────────────────────────────────────
231 void setUniformExtension(std::shared_ptr<PhosphorShaders::IUniformExtension> extension);
233 std::shared_ptr<PhosphorShaders::IUniformExtension> uniformExtension() const
234 {
235 return m_uniformExtension;
236 }
237
238 // ── Timing ─────────────────────────────────────────────────────────
239 void setTime(double time);
240 void setTimeDelta(float delta);
241 void setFrame(int frame);
242 void setResolution(float width, float height);
243 void setMousePosition(const QPointF& pos);
249 void setIsReversed(bool reverse);
250
251 // ── Custom Parameters (indexed API) ────────────────────────────────
252 void setCustomParams(int index, const QVector4D& params);
253 void setCustomColor(int index, const QColor& color);
254
255 // ── Surface-only state ─────────────────────────────────────────────
280 void setSurfaceOpacity(float opacity);
281 void setSurfaceScale(float scale);
282 void setSurfaceFocused(bool focused);
283 void setSurfaceSize(float width, float height);
291 void setBackdropRect(float x, float y, float w, float h);
292 void setSurfaceFrameTopLeft(float x, float y);
293 void setSurfaceFrameSize(float width, float height);
294
295 // ── App Fields (consumer escape hatch in BaseUniforms) ─────────────
303 void setAppField0(int value);
304 void setAppField1(int value);
305
306 // ── Extra Bindings (consumer-managed texture bindings) ─────────────
322 bool setExtraBinding(int binding, QRhiTexture* texture, QRhiSampler* sampler);
324 bool removeExtraBinding(int binding);
325
326 // ── Geometry ───────────────────────────────────────────────────────
342 void setGridSubdivisions(int subdivisions);
343
348 static constexpr int kMaxGridSubdivisions = 255;
349
350 // ── Textures ───────────────────────────────────────────────────────
351 void setAudioSpectrum(const QVector<float>& spectrum);
352 void setUserTexture(int slot, const QImage& image);
356 void setUserTextureWrap(int slot, const QString& wrap);
357 void setWallpaperTexture(const QImage& image);
358 void setUseWallpaper(bool use);
359 void setUseDepthBuffer(bool use);
360
375 void setSourceTextureProvider(QSGTextureProvider* provider);
376 QSGTextureProvider* sourceTextureProvider() const
377 {
378 return m_sourceTextureProvider.data();
379 }
380
381 // ── Multi-pass Buffers ─────────────────────────────────────────────
382 void setBufferShaderPath(const QString& path);
383 void setBufferShaderPaths(const QStringList& paths);
384
400 void setBufferFeedback(bool enable);
409 void setBufferScale(qreal scale);
415 void setBufferScales(const QList<qreal>& scales);
419 void setBufferScales(const QVariantList& scales);
423 void setHalfFloatBuffers(bool enable);
424 void setBufferWrap(const QString& wrap);
425 void setBufferWraps(const QStringList& wraps);
426 void setBufferFilter(const QString& filter);
427 void setBufferFilters(const QStringList& filters);
428
429 // ── Shader Loading ─────────────────────────────────────────────────
430 //
431 // BOTH stages are mandatory and the bake FAILS CLOSED without them: with an
432 // empty vertex or fragment source the bake aborts with "Vertex or fragment
433 // shader source is empty", leaves isShaderReady() false, and render() draws
434 // nothing. A consumer that sets only a fragment stage gets a silent blank,
435 // not a default vertex stage, so it must supply one of these two.
436 //
437 // The file form returns false and leaves the previously installed source
438 // standing; the inline form replaces it and clears the file-derived
439 // bake-cache key (path, mtime and include fingerprint), since inline source
440 // has no file behind it.
441 bool loadVertexShader(const QString& path);
442 bool loadFragmentShader(const QString& path);
443 void setVertexShaderSource(const QString& source);
444 void setFragmentShaderSource(const QString& source);
445 bool isShaderReady() const;
446 QString shaderError() const;
459
460 // ── Include Paths ──────────────────────────────────────────────────
461 void setShaderIncludePaths(const QStringList& paths);
462
463 // ── Parameter preamble (T1.1: generated `#define p_<id> ...`) ─────
473 void setParamPreamble(const QString& preamble);
474
475 // ── Entry-point scaffold (T1.4: harness-generated `main()`) ────────
486 void setEntryScaffold(const QString& prologue, const QList<PhosphorShaders::EntryCandidate>& candidates);
487
493 static QString normalizeWrapMode(const QString& wrap);
495 static QString normalizeFilterMode(const QString& filter);
496
500 static QRhiSampler::AddressMode wrapModeToRhiAddress(const QString& wrap);
501
502protected:
510 QRhi* safeRhi() const;
511
527 void retractLiveness() noexcept;
528
542
543private:
544 bool ensurePipeline();
545 bool ensureBufferPipeline();
546 bool ensureBufferTarget();
547 bool ensureDummyChannelResources(QRhi* rhi);
551 void uploadDummyChannelTexture(QRhi* rhi, QRhiCommandBuffer* cb);
552 bool ensureBufferSampler(QRhi* rhi, int index);
562 void resetBufferTargets();
566 void syncBaseUniforms(QRhi* rhi);
572 bool renderingIntoTexture() const;
573 void uploadDirtyTextures(QRhi* rhi, QRhiCommandBuffer* cb);
579 void uploadExtensionToUbo(QRhiResourceUpdateBatch* batch);
580 void releaseRhiResources();
581 void appendUserTextureBindings(QVector<QRhiShaderResourceBinding>& bindings) const;
595 bool wallpaperBindingLive() const
596 {
597 return m_useWallpaper && m_wallpaperTexture && m_wallpaperSampler && !m_wallpaperImage.isNull();
598 }
599 void appendWallpaperBinding(QVector<QRhiShaderResourceBinding>& bindings) const;
614 enum class DepthAccess {
615 Sampled,
616 WrittenThisPass
617 };
618 void appendDepthBinding(QVector<QRhiShaderResourceBinding>& bindings, DepthAccess access) const;
619 void appendExtraBindings(QVector<QRhiShaderResourceBinding>& bindings) const;
620 void appendAudioBinding(QVector<QRhiShaderResourceBinding>& bindings) const;
622 void appendUboAndExtraBindings(QVector<QRhiShaderResourceBinding>& bindings) const;
626 void appendCommonTrailerBindings(QVector<QRhiShaderResourceBinding>& bindings, DepthAccess depthAccess) const;
627 void resetAllBindingsAndPipelines();
628 void bakeBufferShaders();
629 QString loadAndExpandShader(const QString& path, QString* outError);
635 QString loadAndExpandShaderTracked(const QString& path, QStringList* outIncludedPaths, QString* outError);
636
637 QQuickItem* m_item = nullptr;
638 std::atomic<bool> m_itemValid{true};
639
649 // Lock-ordering invariant: MUST NOT block on the GUI thread while holding
650 // m_itemMutex (avoids deadlock during ~ShaderEffect → invalidateItem path).
651 mutable std::mutex m_itemMutex;
652
657 std::shared_ptr<ShaderNodeLiveness> m_liveness = std::make_shared<ShaderNodeLiveness>();
658
659 // ── Uniform Extension ──────────────────────────────────────────────
660 std::shared_ptr<PhosphorShaders::IUniformExtension> m_uniformExtension;
664 QByteArray m_extensionStaging;
665
666 // ── Shader Include Paths ───────────────────────────────────────────
667 QStringList m_shaderIncludePaths;
668
669 // ── Parameter preamble (generated `#define p_<id> ...`) ───────────
672 QString m_paramPreamble;
673
674 // ── Entry-point scaffold (T1.4) ────────────────────────────────────
678 QString m_entryPrologue;
679 QList<PhosphorShaders::EntryCandidate> m_entryCandidates;
680
684 bool gridActive() const
685 {
686 return m_gridSubdivisions > 0 && !m_gridBuffersFailed;
687 }
688
689 // ── RHI Core Resources ─────────────────────────────────────────────
690 std::unique_ptr<QRhiBuffer> m_vbo;
692 std::unique_ptr<QRhiBuffer> m_gridVbo;
693 std::unique_ptr<QRhiBuffer> m_gridIbo;
694 int m_gridSubdivisions = 0;
695 int m_gridIndexCount = 0;
696 bool m_gridUploaded = false;
705 bool m_gridBuffersFailed = false;
706 std::unique_ptr<QRhiBuffer> m_ubo;
707 std::unique_ptr<QRhiShaderResourceBindings> m_srb;
708 std::unique_ptr<QRhiGraphicsPipeline> m_pipeline;
709 QShader m_vertexShader;
710 QShader m_fragmentShader;
711 QVector<quint32> m_renderPassFormat;
712
713 // ── Multi-pass: buffer pass(es) (optional). Up to kMaxBufferPasses paths. ──
714 QString m_bufferPath;
715 QStringList m_bufferPaths;
716 bool m_bufferFeedback = false;
717 qreal m_bufferScale = 1.0;
718 // Per-pass render-target scales (a pack's `bufferScales`), positionally
719 // aligned with m_bufferPaths. A slot without its own entry follows
720 // m_bufferScale, which setBufferScale writes into every slot; only
721 // setBufferScales diverges them. This is what lets a pyramid (dual Kawase)
722 // render each level at its own resolution inside one pack.
723 //
724 // Because setBufferScale SEEDS all of these, it must not compare against
725 // them to decide whether anything changed: the sync pushes it first and
726 // setBufferScales re-diverges the slots immediately after, so a comparison
727 // here would see its own seed undone every frame and rebuild every buffer
728 // target twice per frame. It compares the single value alone. See its own
729 // body for the matching note.
730 std::array<qreal, kMaxBufferPasses> m_bufferScales = []() {
731 std::array<qreal, kMaxBufferPasses> a;
732 a.fill(1.0);
733 return a;
734 }();
735 // Buffer-pass texel format. Half-float by default so packs that store HDR
736 // radiance, signed data, or feedback accumulators keep full precision; a
737 // pack whose buffers hold plain clamped [0,1] colour opts down to RGBA8
738 // via metadata to halve buffer bandwidth (which is what integrated GPUs
739 // are starved of).
740 bool m_halfFloatBuffers = true;
741 std::array<QString, kMaxBufferPasses> m_bufferWraps = []() {
742 std::array<QString, kMaxBufferPasses> a;
743 a.fill(QStringLiteral("clamp"));
744 return a;
745 }();
746 QString m_bufferWrapDefault = QStringLiteral("clamp");
747 std::array<QString, kMaxBufferPasses> m_bufferFilters = []() {
748 std::array<QString, kMaxBufferPasses> a;
749 a.fill(QStringLiteral("linear"));
750 return a;
751 }();
752 QString m_bufferFilterDefault = QStringLiteral("linear");
753 QString m_bufferFragmentShaderSource;
754 QShader m_bufferFragmentShader;
755 bool m_bufferShaderReady = false;
756 bool m_bufferShaderDirty = true;
757 int m_bufferShaderRetries = 0;
758 std::unique_ptr<QRhiTexture> m_bufferTexture;
759 std::unique_ptr<QRhiRenderPassDescriptor> m_bufferRenderPassDescriptor;
760 std::unique_ptr<QRhiTextureRenderTarget> m_bufferRenderTarget;
761 std::array<std::unique_ptr<QRhiSampler>, kMaxBufferPasses> m_bufferSamplers;
762 std::unique_ptr<QRhiShaderResourceBindings> m_bufferSrb;
763 std::unique_ptr<QRhiGraphicsPipeline> m_bufferPipeline;
764 QVector<quint32> m_bufferRenderPassFormat;
765 // Ping-pong (bufferFeedback): second texture/RT/SRB for buffer pass; image pass has two SRBs
766 std::unique_ptr<QRhiTexture> m_bufferTextureB;
767 std::unique_ptr<QRhiRenderPassDescriptor> m_bufferRenderPassDescriptorB;
768 std::unique_ptr<QRhiTextureRenderTarget> m_bufferRenderTargetB;
769 std::unique_ptr<QRhiShaderResourceBindings> m_bufferSrbB;
770 std::unique_ptr<QRhiShaderResourceBindings> m_srbB; // image pass SRB with binding 2 = texture B
771 bool m_bufferFeedbackCleared = false;
772
773 // Multi-buffer mode (2-8 passes): per-pass resources
774 std::array<std::unique_ptr<QRhiTexture>, kMaxBufferPasses> m_multiBufferTextures = {};
775 std::array<std::unique_ptr<QRhiTextureRenderTarget>, kMaxBufferPasses> m_multiBufferRenderTargets = {};
776 std::array<std::unique_ptr<QRhiRenderPassDescriptor>, kMaxBufferPasses> m_multiBufferRenderPassDescriptors = {};
777 std::array<std::unique_ptr<QRhiGraphicsPipeline>, kMaxBufferPasses> m_multiBufferPipelines = {};
778 std::array<std::unique_ptr<QRhiShaderResourceBindings>, kMaxBufferPasses> m_multiBufferSrbs = {};
779 std::array<QShader, kMaxBufferPasses> m_multiBufferFragmentShaders = {};
780 bool m_multiBufferShadersReady = false;
781 bool m_multiBufferShaderDirty = true;
782 int m_multiBufferShaderRetries = 0;
783 // Dummy 1x1 texture for the multipass channel-0 buffer slot (SRB
784 // binding 2, GLSL `iChannel0`) when multipass is configured but the
785 // backing buffer hasn't been created yet. Distinct from the user-
786 // texture slot 0 (SRB binding 11, GLSL `uTexture0`) — the iChannel0
787 // name here refers to the buffer-channel binding, not the renamed
788 // user-texture.
789 std::unique_ptr<QRhiTexture> m_dummyChannelTexture;
790 std::unique_ptr<QRhiSampler> m_dummyChannelSampler;
791 bool m_dummyChannelTextureNeedsUpload = false;
792
793 // ── Shader Sources ─────────────────────────────────────────────────
794 QString m_vertexShaderSource;
795 QString m_fragmentShaderSource;
796 QString m_vertexPath;
797 QString m_fragmentPath;
798 qint64 m_vertexMtime = 0;
799 qint64 m_fragmentMtime = 0;
806 QByteArray m_vertexIncludeFp;
807 QByteArray m_fragmentIncludeFp;
808 QString m_shaderError;
809 bool m_initialized = false;
810 bool m_vboUploaded = false;
811 bool m_shaderReady = false;
812 bool m_shaderDirty = true;
813 bool m_uniformsDirty = true;
814 bool m_timeDirty = true;
815 bool m_timeHiDirty = true;
816 bool m_sceneDataDirty = true;
817 bool m_appFieldsDirty = false;
818 bool m_didFullUploadOnce = false;
824 std::optional<bool> m_lastTargetWasTexture;
825
826 // ── UBO Profile (pluggable uniform buffer concern) ─────────────────
831 std::unique_ptr<PhosphorShaders::IUboProfile> m_uboProfile;
832
837 int m_appField0 = 0;
838 int m_appField1 = 0;
839
840 // Full-precision elapsed seconds (double). Split into iTime (wrapped lo) +
841 // iTimeHi (wrap offset) at upload.
842 double m_time = 0.0;
843 float m_timeDelta = 0.0f;
844 int m_frame = 0;
845 bool m_isReversed = false;
846 float m_timeHi = 0.0f; // Cached iTimeHi for wrap-offset change detection
847 float m_width = 0.0f;
848 float m_height = 0.0f;
861 std::atomic<float> m_cachedWidth{0.0f};
862 std::atomic<float> m_cachedHeight{0.0f};
863 QPointF m_mousePosition;
864
865 // ── Surface-only state (consumed by a SurfaceUniformProfile; ignored by
866 // the BaseUniformProfile). Defaults mirror UboFrameState so the overlay
867 // path is byte-identical whether or not these are ever touched. ──
868 float m_surfaceOpacity = 1.0f;
872 float m_inheritedOpacity = 1.0f;
873 float m_surfaceScale = 1.0f;
874 bool m_surfaceFocused = false;
875 float m_surfaceSize[2] = {0.0f, 0.0f};
876 float m_backdropRect[4] = {0.0f, 0.0f, 1.0f, 1.0f};
877 float m_surfaceFrameTopLeft[2] = {0.0f, 0.0f};
878 float m_surfaceFrameSize[2] = {0.0f, 0.0f};
879
880 // ── Custom Parameters (indexed) ────────────────────────────────────
884 std::array<QVector4D, kMaxCustomParams> m_customParams = []() {
885 std::array<QVector4D, kMaxCustomParams> a;
886 a.fill(QVector4D(-1.0f, -1.0f, -1.0f, -1.0f));
887 return a;
888 }();
894 std::array<QColor, kMaxCustomColors> m_customColors = []() {
895 std::array<QColor, kMaxCustomColors> a;
896 a.fill(QColor(Qt::white));
897 return a;
898 }();
899
900 // ── Extra Bindings (consumer-managed) ──────────────────────────────
901 struct ExtraBinding
902 {
903 QRhiTexture* texture = nullptr;
904 QRhiSampler* sampler = nullptr;
905 };
906 // std::map (ordered) so SRB construction produces a deterministic binding
907 // order regardless of insertion/erasure history. An unordered_map can
908 // produce different iteration orders after erasures, which Qt RHI
909 // backends may hash into different pipeline layout signatures.
910 std::map<int, ExtraBinding> m_extraBindings;
911
912 // ── 1x1 Transparent Fallback ───────────────────────────────────────
913 QImage m_transparentFallbackImage;
914
915 // ── Audio spectrum texture (binding 10) ─────────────────────────────
916 QVector<float> m_audioSpectrum;
917 std::unique_ptr<QRhiTexture> m_audioSpectrumTexture;
918 std::unique_ptr<QRhiSampler> m_audioSpectrumSampler;
919 bool m_audioSpectrumDirty = false;
920
921 // ── User texture slots (bindings 11-14) ─────────────────────────────
922 std::array<QImage, kMaxUserTextures> m_userTextureImages;
923 std::array<std::unique_ptr<QRhiTexture>, kMaxUserTextures> m_userTextures;
924 std::array<std::unique_ptr<QRhiSampler>, kMaxUserTextures> m_userTextureSamplers;
925 // Seeded with the explicit "clamp" token rather than default-constructed,
926 // matching m_bufferWraps above, so the two arrays answer the same string to
927 // anything that compares tokens rather than normalising them.
928 //
929 // Filled from kMaxUserTextures rather than written out as four literals: the
930 // count comes from the binding table, so a literal list silently stops
931 // covering the array the moment the table grows a slot.
932 std::array<QString, kMaxUserTextures> m_userTextureWraps = []() {
933 std::array<QString, kMaxUserTextures> a;
934 a.fill(QStringLiteral("clamp"));
935 return a;
936 }();
937 std::array<bool, kMaxUserTextures> m_userTextureDirty = {};
941 std::array<bool, kMaxUserTextures> m_userTextureSamplerWarned = {};
942
943 // ── Source texture override (slot 0 / binding 11) ───────────────────
944 // Texture-provider source — typically a `QQuickItem::textureProvider()`
945 // for a layer-enabled item. When non-null this supersedes
946 // m_userTextures[0] in the SRB build, so the shader's uTexture0
947 // samples a live QML render instead of a static QImage upload.
948 // m_sourceSampler is owned here (not a user-texture sampler) so we
949 // can keep slot 0's user-texture sampler available for callers that
950 // mix the two paths. m_lastSourceRhiTexture caches the QRhiTexture*
951 // we last bound; when the provider's underlying texture changes
952 // (FBO recreation on resize / device-loss) we drop the SRB so the
953 // next rebuild picks up the new pointer.
954 QPointer<QSGTextureProvider> m_sourceTextureProvider;
963 QMetaObject::Connection m_sourceTextureChangedConn;
964 std::unique_ptr<QRhiSampler> m_sourceSampler;
965 QRhiTexture* m_lastSourceRhiTexture = nullptr;
970 bool m_sourceSamplerFailed = false;
974 bool m_warnedForeignRhi = false;
979 mutable bool m_warnedWallpaperBindingOmitted = false;
982 mutable bool m_warnedDepthBindingOmitted = false;
991 bool m_warnedAudioTruncated = false;
992 bool m_warnedAudioCreateFailed = false;
996 bool m_dummyChannelWarned = false;
999 bool m_halfFloatUnsupportedWarned = false;
1003 bool m_bufferTargetCreateWarned = false;
1011 std::unique_ptr<QRhiTexture> m_transparentFallbackTexture;
1015 bool m_transparentFallbackWarned = false;
1016 bool m_transparentFallbackTextureNeedsUpload = false;
1017
1018 // ── Depth buffer (binding 16) ──────────────────────────────────────
1019 bool m_useDepthBuffer = false;
1020 bool m_depthMultiBufferWarned = false;
1023 bool m_depthScalesWarned = false;
1024 std::unique_ptr<QRhiTexture> m_depthTexture;
1025 std::unique_ptr<QRhiSampler> m_depthSampler;
1026
1027 // ── Desktop wallpaper texture (binding 15) ─────────────────────────
1028 bool m_useWallpaper = false;
1029 QImage m_wallpaperImage;
1030 std::unique_ptr<QRhiTexture> m_wallpaperTexture;
1031 std::unique_ptr<QRhiSampler> m_wallpaperSampler;
1032 bool m_wallpaperDirty = false;
1033
1034 // ── Appended members ───────────────────────────────────────────────
1035 // New members go HERE, at the end, even at SOVERSION 0: this is an installed
1036 // header, and inserting one mid-class shifts every later member's offset for
1037 // anything already compiled against it. Grouped by concern above only for the
1038 // members that shipped together.
1039
1043 bool m_bufferSamplerCreateWarned = false;
1044
1060 int m_depthCreateRetries = 0;
1061
1070 bool m_depthCreateWarned = false;
1071
1075 void requestDepthCreateRetry();
1076
1080 void clearDepthCreateFailure();
1081
1095 QSize m_depthCreateFailedSize;
1096
1113 bool m_warnedWallpaperCreateFailed = false;
1114 std::array<bool, kMaxUserTextures> m_userTextureCreateWarned = {};
1115
1122 bool m_mipmapFallbackWarned = false;
1123
1132 int m_dummyCreateRetries = 0;
1133
1136 void requestDummyCreateRetry();
1137
1144 std::array<bool, kMaxUserTextures> m_userTextureClampWarned = {};
1145};
1146
1149{
1150 bool success = false;
1152};
1153
1177 const QString& vertexPath, const QString& fragmentPath, const QStringList& includePaths = {},
1178 const QString& paramPreamble = {}, const QString& entryPrologue = {},
1179 const QList<PhosphorShaders::EntryCandidate>& entryCandidates = {});
1180
1181} // namespace PhosphorRendering
bool removeExtraBinding(int binding)
void invalidateBufferShaders()
Force every buffer pass to re-read its source and re-bake, with the path list unchanged.
void setBufferScale(qreal scale)
The single-value scale, and the seed for every per-pass slot: this writes scale into ALL of them.
void setUniformExtension(std::shared_ptr< PhosphorShaders::IUniformExtension > extension)
void clearBakedShader()
Drop the resident bake, its error, and any pending rebake together.
void setIsReversed(bool reverse)
Direction signal for asymmetric leg rendering.
void setVertexShaderSource(const QString &source)
void setShaderIncludePaths(const QStringList &paths)
QRectF rect() const override
QSGRenderNode::RenderingFlags flags() const override
void setBufferWrap(const QString &wrap)
void setCustomParams(int index, const QVector4D &params)
void setSurfaceOpacity(float opacity)
Per-surface inputs consumed by a SurfaceUniformProfile.
void setUserTexture(int slot, const QImage &image)
void invalidateItem()
Notify the render node that its owning item is being destroyed.
void setBufferFilter(const QString &filter)
void setAppField0(int value)
Write the consumer's two int slots inside BaseUniforms (offsets 88, 92).
void setBufferShaderPaths(const QStringList &paths)
void setAudioSpectrum(const QVector< float > &spectrum)
void setSurfaceSize(float width, float height)
void setGridSubdivisions(int subdivisions)
Tessellate the IMAGE pass into an n×n cell grid (0 = the default two-triangle fullscreen quad).
void setBufferWraps(const QStringList &wraps)
void setHalfFloatBuffers(bool enable)
Buffer-pass texel format: RGBA16F when true (the default — safe for HDR, signed-data,...
bool loadFragmentShader(const QString &path)
void setUserTextureWrap(int slot, const QString &wrap)
Set per-slot sampler address mode.
void setWallpaperTexture(const QImage &image)
bool hasValidItem() const
Whether this node still holds a usable back-pointer to its item.
Definition ShaderNodeRhi.h:196
QRhi * safeRhi() const
Thread-safe QRhi accessor.
void setMousePosition(const QPointF &pos)
void setResolution(float width, float height)
void retractLiveness() noexcept
Retract this node from its liveness block.
void requestAnotherFrame() const
Schedule another frame from the render thread (QQuickWindow::update() is documented thread-safe),...
std::shared_ptr< PhosphorShaders::IUniformExtension > uniformExtension() const
Access the currently-installed uniform extension (may be nullptr).
Definition ShaderNodeRhi.h:233
void setFragmentShaderSource(const QString &source)
void setBufferScales(const QVariantList &scales)
Overload for the QVariantList the item already holds, so a per-frame sync does not materialise a QLis...
void setSourceTextureProvider(QSGTextureProvider *provider)
Live texture-provider override for user-texture slot 0 (SRB binding 11 / uTexture0).
void preprocess() override
Stock-parity dependency pull (mirrors QSGRhiShaderEffectNode): bring the source provider's layer text...
const std::shared_ptr< ShaderNodeLiveness > & liveness() const
The liveness block to hand to ShaderEffect::registerRenderNode.
Definition ShaderNodeRhi.h:208
void setBufferShaderPath(const QString &path)
QSGTextureProvider * sourceTextureProvider() const
Definition ShaderNodeRhi.h:376
void setSurfaceFocused(bool focused)
void setBufferScales(const QList< qreal > &scales)
Per-pass scales aligned with the buffer paths; a slot past the list's end follows the single-value sc...
ShaderNodeRhi(QQuickItem *item, std::unique_ptr< PhosphorShaders::IUboProfile > profile=nullptr)
void setSurfaceFrameSize(float width, float height)
void setSurfaceFrameTopLeft(float x, float y)
void render(const RenderState *state) override
static QString normalizeFilterMode(const QString &filter)
Normalize filter mode string to "nearest", "linear", or "mipmap".
void setEntryScaffold(const QString &prologue, const QList< PhosphorShaders::EntryCandidate > &candidates)
Install the entry-point scaffold for the fragment stage.
void setCustomColor(int index, const QColor &color)
void setSurfaceScale(float scale)
QSGRenderNode::StateFlags changedStates() const override
static QString normalizeWrapMode(const QString &wrap)
Normalize wrap mode string to "clamp", "repeat", or "mirror" (static helper, safe to call from any th...
bool loadVertexShader(const QString &path)
void setParamPreamble(const QString &preamble)
Set the generated named-parameter preamble that is spliced after the fragment shader's #version line ...
static constexpr int kMaxGridSubdivisions
Grid-density ceiling: (255+1)² vertices is the most a quint16 index buffer can address.
Definition ShaderNodeRhi.h:348
void setBackdropRect(float x, float y, float w, float h)
The slice of the bound backdrop this surface samples, normalized texture coords (xy = min,...
bool setExtraBinding(int binding, QRhiTexture *texture, QRhiSampler *sampler)
Bind a consumer-owned texture/sampler at the given binding number.
void setBufferFeedback(bool enable)
void setBufferFilters(const QStringList &filters)
static QRhiSampler::AddressMode wrapModeToRhiAddress(const QString &wrap)
Map a normalized wrap-mode string to QRhiSampler::AddressMode.
constexpr int kMaxBufferPasses
Multipass buffer-pass budget.
Definition AnimationShaderContract.h:576
Definition AnimationShaderItemConfig.h:10
constexpr int kMaxBufferPasses
Definition ShaderNodeRhi.h:47
constexpr int kReservedBindingRangeEnd
Last library-managed binding.
Definition ShaderNodeRhi.h:82
constexpr int kMaxCustomColors
Definition ShaderNodeRhi.h:50
PHOSPHORRENDERING_EXPORT WarmShaderBakeResult warmShaderBakeCacheForPaths(const QString &vertexPath, const QString &fragmentPath, const QStringList &includePaths={}, const QString &paramPreamble={}, const QString &entryPrologue={}, const QList< PhosphorShaders::EntryCandidate > &entryCandidates={})
Pre-load cache warming: load, bake, and insert shaders for the given paths into the shared bake cache...
constexpr int kFirstFreeConsumerBinding
First slot usable via setExtraBinding().
Definition ShaderNodeRhi.h:67
constexpr int kReservedBindingRangeStart
First library-managed binding above 0.
Definition ShaderNodeRhi.h:80
constexpr bool isConsumerBinding(int binding) noexcept
Definition ShaderNodeRhi.h:90
constexpr int kMaxConsumerBinding
Highest binding this library will hand out.
Definition ShaderNodeRhi.h:74
constexpr int kMaxUserTextures
Definition ShaderNodeRhi.h:48
constexpr int kUserTextureBaseBinding
First SRB binding for the user-texture slots (slot 0 → binding 11).
Definition ShaderNodeRhi.h:87
constexpr int kMaxCustomParams
Definition ShaderNodeRhi.h:49
constexpr int kMaxBinding
Highest binding a consumer may claim.
Definition ShaderBindings.h:74
constexpr bool isConsumerBinding(int binding) noexcept
Whether binding is one a consumer may claim through setExtraBinding: the single gap slot,...
Definition ShaderBindings.h:129
constexpr int kUserTextureCount
Definition ShaderBindings.h:43
constexpr int kReservedEnd
Last binding the library manages; everything above is a consumer slot.
Definition ShaderBindings.h:47
constexpr int kUserTextureBase
Definition ShaderBindings.h:42
constexpr int kConsumer
Definition ShaderBindings.h:38
constexpr int kChannelBase
Definition ShaderBindings.h:39
constexpr int kMaxBufferPasses
Maximum number of multipass buffer passes a pack may declare.
Definition CustomParamsKey.h:68
Result of warmShaderBakeCacheForPaths for reporting to UI.
Definition ShaderNodeRhi.h:1149
QString errorMessage
Definition ShaderNodeRhi.h:1151
bool success
Definition ShaderNodeRhi.h:1150