174 explicit ShaderNodeRhi(QQuickItem* item, std::unique_ptr<PhosphorShaders::IUboProfile> profile =
nullptr);
198 return m_itemValid.load(std::memory_order_acquire);
208 const std::shared_ptr<ShaderNodeLiveness>&
liveness()
const
215 QSGRenderNode::RenderingFlags
flags()
const override;
218 void render(
const RenderState* state)
override;
235 return m_uniformExtension;
378 return m_sourceTextureProvider.data();
486 void setEntryScaffold(
const QString& prologue,
const QList<PhosphorShaders::EntryCandidate>& candidates);
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
597 return m_useWallpaper && m_wallpaperTexture && m_wallpaperSampler && !m_wallpaperImage.isNull();
599 void appendWallpaperBinding(QVector<QRhiShaderResourceBinding>& bindings)
const;
614 enum class DepthAccess {
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);
637 QQuickItem* m_item =
nullptr;
638 std::atomic<bool> m_itemValid{
true};
651 mutable std::mutex m_itemMutex;
657 std::shared_ptr<ShaderNodeLiveness> m_liveness = std::make_shared<ShaderNodeLiveness>();
660 std::shared_ptr<PhosphorShaders::IUniformExtension> m_uniformExtension;
664 QByteArray m_extensionStaging;
667 QStringList m_shaderIncludePaths;
672 QString m_paramPreamble;
678 QString m_entryPrologue;
679 QList<PhosphorShaders::EntryCandidate> m_entryCandidates;
684 bool gridActive()
const
686 return m_gridSubdivisions > 0 && !m_gridBuffersFailed;
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;
714 QString m_bufferPath;
715 QStringList m_bufferPaths;
716 bool m_bufferFeedback =
false;
717 qreal m_bufferScale = 1.0;
730 std::array<qreal, kMaxBufferPasses> m_bufferScales = []() {
731 std::array<qreal, kMaxBufferPasses> a;
740 bool m_halfFloatBuffers =
true;
741 std::array<QString, kMaxBufferPasses> m_bufferWraps = []() {
742 std::array<QString, kMaxBufferPasses> a;
743 a.fill(QStringLiteral(
"clamp"));
746 QString m_bufferWrapDefault = QStringLiteral(
"clamp");
747 std::array<QString, kMaxBufferPasses> m_bufferFilters = []() {
748 std::array<QString, kMaxBufferPasses> a;
749 a.fill(QStringLiteral(
"linear"));
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;
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;
771 bool m_bufferFeedbackCleared =
false;
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;
789 std::unique_ptr<QRhiTexture> m_dummyChannelTexture;
790 std::unique_ptr<QRhiSampler> m_dummyChannelSampler;
791 bool m_dummyChannelTextureNeedsUpload =
false;
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;
831 std::unique_ptr<PhosphorShaders::IUboProfile> m_uboProfile;
843 float m_timeDelta = 0.0f;
845 bool m_isReversed =
false;
846 float m_timeHi = 0.0f;
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;
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};
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));
894 std::array<QColor, kMaxCustomColors> m_customColors = []() {
895 std::array<QColor, kMaxCustomColors> a;
896 a.fill(QColor(Qt::white));
903 QRhiTexture* texture =
nullptr;
904 QRhiSampler* sampler =
nullptr;
910 std::map<int, ExtraBinding> m_extraBindings;
913 QImage m_transparentFallbackImage;
916 QVector<float> m_audioSpectrum;
917 std::unique_ptr<QRhiTexture> m_audioSpectrumTexture;
918 std::unique_ptr<QRhiSampler> m_audioSpectrumSampler;
919 bool m_audioSpectrumDirty =
false;
922 std::array<QImage, kMaxUserTextures> m_userTextureImages;
924 std::array<std::unique_ptr<QRhiSampler>,
kMaxUserTextures> m_userTextureSamplers;
932 std::array<QString, kMaxUserTextures> m_userTextureWraps = []() {
933 std::array<QString, kMaxUserTextures> a;
934 a.fill(QStringLiteral(
"clamp"));
937 std::array<bool, kMaxUserTextures> m_userTextureDirty = {};
941 std::array<bool, kMaxUserTextures> m_userTextureSamplerWarned = {};
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;
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;
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;
1043 bool m_bufferSamplerCreateWarned =
false;
1060 int m_depthCreateRetries = 0;
1070 bool m_depthCreateWarned =
false;
1075 void requestDepthCreateRetry();
1080 void clearDepthCreateFailure();
1095 QSize m_depthCreateFailedSize;
1113 bool m_warnedWallpaperCreateFailed =
false;
1114 std::array<bool, kMaxUserTextures> m_userTextureCreateWarned = {};
1122 bool m_mipmapFallbackWarned =
false;
1132 int m_dummyCreateRetries = 0;
1136 void requestDummyCreateRetry();
1144 std::array<bool, kMaxUserTextures> m_userTextureClampWarned = {};