138 explicit ShaderNodeRhi(QQuickItem* item, std::unique_ptr<PhosphorShaders::IUboProfile> profile =
nullptr);
162 return m_itemValid.load(std::memory_order_acquire);
172 const std::shared_ptr<ShaderNodeLiveness>&
liveness()
const
179 QSGRenderNode::RenderingFlags
flags()
const override;
182 void render(
const RenderState* state)
override;
199 return m_uniformExtension;
304 return m_sourceTextureProvider.data();
357 void setEntryScaffold(
const QString& prologue,
const QList<PhosphorShaders::EntryCandidate>& candidates);
401 bool ensurePipeline();
402 bool ensureBufferPipeline();
403 bool ensureBufferTarget();
404 bool ensureDummyChannelResources(QRhi* rhi);
405 bool ensureBufferSampler(QRhi* rhi,
int index);
409 void resetBufferTargets();
413 void syncBaseUniforms(QRhi* rhi);
419 bool renderingIntoTexture() const;
420 void uploadDirtyTextures(QRhi* rhi, QRhiCommandBuffer* cb);
426 void uploadExtensionToUbo(QRhiResourceUpdateBatch* batch);
427 void releaseRhiResources();
428 void appendUserTextureBindings(QVector<QRhiShaderResourceBinding>& bindings) const;
442 bool wallpaperBindingLive()
const
444 return m_useWallpaper && m_wallpaperTexture && m_wallpaperSampler && !m_wallpaperImage.isNull();
446 void appendWallpaperBinding(QVector<QRhiShaderResourceBinding>& bindings)
const;
461 enum class DepthAccess {
465 void appendDepthBinding(QVector<QRhiShaderResourceBinding>& bindings, DepthAccess access)
const;
466 void appendExtraBindings(QVector<QRhiShaderResourceBinding>& bindings)
const;
467 void appendAudioBinding(QVector<QRhiShaderResourceBinding>& bindings)
const;
469 void appendUboAndExtraBindings(QVector<QRhiShaderResourceBinding>& bindings)
const;
473 void appendCommonTrailerBindings(QVector<QRhiShaderResourceBinding>& bindings, DepthAccess depthAccess)
const;
474 void resetAllBindingsAndPipelines();
475 void bakeBufferShaders();
476 QString loadAndExpandShader(
const QString& path, QString* outError);
482 QString loadAndExpandShaderTracked(
const QString& path, QStringList* outIncludedPaths, QString* outError);
484 QQuickItem* m_item =
nullptr;
485 std::atomic<bool> m_itemValid{
true};
498 mutable std::mutex m_itemMutex;
504 std::shared_ptr<ShaderNodeLiveness> m_liveness = std::make_shared<ShaderNodeLiveness>();
507 std::shared_ptr<PhosphorShaders::IUniformExtension> m_uniformExtension;
511 QByteArray m_extensionStaging;
514 QStringList m_shaderIncludePaths;
519 QString m_paramPreamble;
525 QString m_entryPrologue;
526 QList<PhosphorShaders::EntryCandidate> m_entryCandidates;
529 std::unique_ptr<QRhiBuffer> m_vbo;
530 std::unique_ptr<QRhiBuffer> m_ubo;
531 std::unique_ptr<QRhiShaderResourceBindings> m_srb;
532 std::unique_ptr<QRhiGraphicsPipeline> m_pipeline;
533 QShader m_vertexShader;
534 QShader m_fragmentShader;
535 QVector<quint32> m_renderPassFormat;
538 QString m_bufferPath;
539 QStringList m_bufferPaths;
540 bool m_bufferFeedback =
false;
541 qreal m_bufferScale = 1.0;
547 bool m_halfFloatBuffers =
true;
548 std::array<QString, kMaxBufferPasses> m_bufferWraps = {QStringLiteral(
"clamp"), QStringLiteral(
"clamp"),
549 QStringLiteral(
"clamp"), QStringLiteral(
"clamp")};
550 QString m_bufferWrapDefault = QStringLiteral(
"clamp");
551 std::array<QString, kMaxBufferPasses> m_bufferFilters = {QStringLiteral(
"linear"), QStringLiteral(
"linear"),
552 QStringLiteral(
"linear"), QStringLiteral(
"linear")};
553 QString m_bufferFilterDefault = QStringLiteral(
"linear");
554 QString m_bufferFragmentShaderSource;
555 QShader m_bufferFragmentShader;
556 bool m_bufferShaderReady =
false;
557 bool m_bufferShaderDirty =
true;
558 int m_bufferShaderRetries = 0;
559 std::unique_ptr<QRhiTexture> m_bufferTexture;
560 std::unique_ptr<QRhiRenderPassDescriptor> m_bufferRenderPassDescriptor;
561 std::unique_ptr<QRhiTextureRenderTarget> m_bufferRenderTarget;
562 std::array<std::unique_ptr<QRhiSampler>,
kMaxBufferPasses> m_bufferSamplers;
563 std::unique_ptr<QRhiShaderResourceBindings> m_bufferSrb;
564 std::unique_ptr<QRhiGraphicsPipeline> m_bufferPipeline;
565 QVector<quint32> m_bufferRenderPassFormat;
567 std::unique_ptr<QRhiTexture> m_bufferTextureB;
568 std::unique_ptr<QRhiRenderPassDescriptor> m_bufferRenderPassDescriptorB;
569 std::unique_ptr<QRhiTextureRenderTarget> m_bufferRenderTargetB;
570 std::unique_ptr<QRhiShaderResourceBindings> m_bufferSrbB;
571 std::unique_ptr<QRhiShaderResourceBindings> m_srbB;
572 bool m_bufferFeedbackCleared =
false;
575 std::array<std::unique_ptr<QRhiTexture>,
kMaxBufferPasses> m_multiBufferTextures = {};
576 std::array<std::unique_ptr<QRhiTextureRenderTarget>,
kMaxBufferPasses> m_multiBufferRenderTargets = {};
577 std::array<std::unique_ptr<QRhiRenderPassDescriptor>,
kMaxBufferPasses> m_multiBufferRenderPassDescriptors = {};
578 std::array<std::unique_ptr<QRhiGraphicsPipeline>,
kMaxBufferPasses> m_multiBufferPipelines = {};
579 std::array<std::unique_ptr<QRhiShaderResourceBindings>,
kMaxBufferPasses> m_multiBufferSrbs = {};
580 std::array<QShader, kMaxBufferPasses> m_multiBufferFragmentShaders = {};
581 std::array<QString, kMaxBufferPasses> m_multiBufferFragmentShaderSources = {};
582 bool m_multiBufferShadersReady =
false;
583 bool m_multiBufferShaderDirty =
true;
584 int m_multiBufferShaderRetries = 0;
591 std::unique_ptr<QRhiTexture> m_dummyChannelTexture;
592 std::unique_ptr<QRhiSampler> m_dummyChannelSampler;
593 bool m_dummyChannelTextureNeedsUpload =
false;
596 QString m_vertexShaderSource;
597 QString m_fragmentShaderSource;
598 QString m_vertexPath;
599 QString m_fragmentPath;
600 qint64 m_vertexMtime = 0;
601 qint64 m_fragmentMtime = 0;
610 QStringList m_vertexIncludedPaths;
611 QStringList m_fragmentIncludedPaths;
612 QString m_shaderError;
613 bool m_initialized =
false;
614 bool m_vboUploaded =
false;
615 bool m_shaderReady =
false;
616 bool m_shaderDirty =
true;
617 bool m_uniformsDirty =
true;
618 bool m_timeDirty =
true;
619 bool m_timeHiDirty =
true;
620 bool m_sceneDataDirty =
true;
621 bool m_appFieldsDirty =
false;
622 bool m_didFullUploadOnce =
false;
628 std::optional<bool> m_lastTargetWasTexture;
635 std::unique_ptr<PhosphorShaders::IUboProfile> m_uboProfile;
647 float m_timeDelta = 0.0f;
649 bool m_isReversed =
false;
650 float m_timeHi = 0.0f;
651 float m_width = 0.0f;
652 float m_height = 0.0f;
659 std::atomic<float> m_cachedWidth{0.0f};
660 std::atomic<float> m_cachedHeight{0.0f};
661 QPointF m_mousePosition;
666 float m_surfaceOpacity = 1.0f;
667 float m_surfaceScale = 1.0f;
668 bool m_surfaceFocused =
false;
669 float m_surfaceSize[2] = {0.0f, 0.0f};
670 float m_backdropRect[4] = {0.0f, 0.0f, 1.0f, 1.0f};
671 float m_surfaceFrameTopLeft[2] = {0.0f, 0.0f};
672 float m_surfaceFrameSize[2] = {0.0f, 0.0f};
675 std::array<QVector4D, kMaxCustomParams> m_customParams;
676 std::array<QColor, kMaxCustomColors> m_customColors;
681 QRhiTexture* texture =
nullptr;
682 QRhiSampler* sampler =
nullptr;
688 std::map<int, ExtraBinding> m_extraBindings;
689 bool m_extraBindingsDirty =
false;
692 QImage m_transparentFallbackImage;
695 QVector<float> m_audioSpectrum;
696 std::unique_ptr<QRhiTexture> m_audioSpectrumTexture;
697 std::unique_ptr<QRhiSampler> m_audioSpectrumSampler;
698 bool m_audioSpectrumDirty =
false;
701 std::array<QImage, kMaxUserTextures> m_userTextureImages;
703 std::array<std::unique_ptr<QRhiSampler>,
kMaxUserTextures> m_userTextureSamplers;
709 std::array<QString, kMaxUserTextures> m_userTextureWraps = {QStringLiteral(
"clamp"), QStringLiteral(
"clamp"),
710 QStringLiteral(
"clamp"), QStringLiteral(
"clamp")};
711 std::array<bool, kMaxUserTextures> m_userTextureDirty = {};
724 QPointer<QSGTextureProvider> m_sourceTextureProvider;
733 QMetaObject::Connection m_sourceTextureChangedConn;
734 std::unique_ptr<QRhiSampler> m_sourceSampler;
735 QRhiTexture* m_lastSourceRhiTexture =
nullptr;
740 bool m_sourceSamplerFailed =
false;
744 bool m_warnedForeignRhi =
false;
749 mutable bool m_warnedWallpaperBindingOmitted =
false;
754 bool m_warnedAudioTruncated =
false;
755 bool m_warnedAudioCreateFailed =
false;
763 std::unique_ptr<QRhiTexture> m_transparentFallbackTexture;
764 bool m_transparentFallbackTextureNeedsUpload =
false;
767 bool m_useDepthBuffer =
false;
768 bool m_depthMultiBufferWarned =
false;
769 std::unique_ptr<QRhiTexture> m_depthTexture;
770 std::unique_ptr<QRhiSampler> m_depthSampler;
773 bool m_useWallpaper =
false;
774 QImage m_wallpaperImage;
775 std::unique_ptr<QRhiTexture> m_wallpaperTexture;
776 std::unique_ptr<QRhiSampler> m_wallpaperSampler;
777 bool m_wallpaperDirty =
false;