18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#ifndef RENDER_RENDER__NODE__RENDER_BLOOM_H
178bf80f4bSopenharmony_ci#define RENDER_RENDER__NODE__RENDER_BLOOM_H
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include <array>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include <base/containers/string.h>
228bf80f4bSopenharmony_ci#include <base/containers/string_view.h>
238bf80f4bSopenharmony_ci#include <base/math/vector.h>
248bf80f4bSopenharmony_ci#include <render/datastore/render_data_store_render_pods.h>
258bf80f4bSopenharmony_ci#include <render/namespace.h>
268bf80f4bSopenharmony_ci#include <render/nodecontext/intf_pipeline_descriptor_set_binder.h>
278bf80f4bSopenharmony_ci#include <render/nodecontext/intf_render_node.h>
288bf80f4bSopenharmony_ci#include <render/render_data_structures.h>
298bf80f4bSopenharmony_ci#include <render/resource_handle.h>
308bf80f4bSopenharmony_ci
318bf80f4bSopenharmony_ciRENDER_BEGIN_NAMESPACE()
328bf80f4bSopenharmony_ciclass RenderBloom final {
338bf80f4bSopenharmony_cipublic:
348bf80f4bSopenharmony_ci    RenderBloom() = default;
358bf80f4bSopenharmony_ci    ~RenderBloom() = default;
368bf80f4bSopenharmony_ci
378bf80f4bSopenharmony_ci    struct BloomInfo {
388bf80f4bSopenharmony_ci        BindableImage input;
398bf80f4bSopenharmony_ci        BindableImage output;
408bf80f4bSopenharmony_ci        RenderHandle globalUbo;
418bf80f4bSopenharmony_ci        bool useCompute { false };
428bf80f4bSopenharmony_ci    };
438bf80f4bSopenharmony_ci
448bf80f4bSopenharmony_ci    void Init(IRenderNodeContextManager& renderNodeContextMgr, const BloomInfo& bloomInfo);
458bf80f4bSopenharmony_ci    void PreExecute(IRenderNodeContextManager& renderNodeContextMgr, const BloomInfo& bloomInfo,
468bf80f4bSopenharmony_ci        const PostProcessConfiguration& ppConfig);
478bf80f4bSopenharmony_ci    void Execute(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList,
488bf80f4bSopenharmony_ci        const PostProcessConfiguration& ppConfig);
498bf80f4bSopenharmony_ci
508bf80f4bSopenharmony_ci    DescriptorCounts GetDescriptorCounts() const;
518bf80f4bSopenharmony_ci    // call after PreExecute, to get the output
528bf80f4bSopenharmony_ci    RenderHandle GetFinalTarget() const;
538bf80f4bSopenharmony_ci
548bf80f4bSopenharmony_ciprivate:
558bf80f4bSopenharmony_ci    void ComputeBloom(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList);
568bf80f4bSopenharmony_ci    void ComputeDownscaleAndThreshold(const PushConstant& pc, IRenderCommandList& cmdList);
578bf80f4bSopenharmony_ci    void ComputeDownscale(const PushConstant& pc, IRenderCommandList& cmdList);
588bf80f4bSopenharmony_ci    void ComputeUpscale(const PushConstant& pc, IRenderCommandList& cmdList);
598bf80f4bSopenharmony_ci    void ComputeCombine(const PushConstant& pc, IRenderCommandList& cmdList);
608bf80f4bSopenharmony_ci
618bf80f4bSopenharmony_ci    void GraphicsBloom(IRenderNodeContextManager& renderNodeContextMgr, IRenderCommandList& cmdList);
628bf80f4bSopenharmony_ci
638bf80f4bSopenharmony_ci    void RenderDownscaleAndThreshold(RenderPass& renderPass, const PushConstant& pc, IRenderCommandList& cmdList);
648bf80f4bSopenharmony_ci    void RenderDownscale(RenderPass& renderPass, const PushConstant& pc, IRenderCommandList& cmdList);
658bf80f4bSopenharmony_ci    void RenderUpscale(RenderPass& renderPass, const PushConstant& pc, IRenderCommandList& cmdList);
668bf80f4bSopenharmony_ci    void RenderCombine(RenderPass& renderPass, const PushConstant& pc, IRenderCommandList& cmdList);
678bf80f4bSopenharmony_ci
688bf80f4bSopenharmony_ci    void CreateTargets(IRenderNodeContextManager& renderNodeContextMgr, const BASE_NS::Math::UVec2 baseSize);
698bf80f4bSopenharmony_ci    void CreatePsos(IRenderNodeContextManager& renderNodeContextMgr);
708bf80f4bSopenharmony_ci    void CreateComputePsos(IRenderNodeContextManager& renderNodeContextMgr);
718bf80f4bSopenharmony_ci    void CreateRenderPsos(IRenderNodeContextManager& renderNodeContextMgr);
728bf80f4bSopenharmony_ci    std::pair<RenderHandle, const PipelineLayout&> CreateAndReflectRenderPso(
738bf80f4bSopenharmony_ci        IRenderNodeContextManager& renderNodeContextMgr, const BASE_NS::string_view shader,
748bf80f4bSopenharmony_ci        const RenderPass& renderPass);
758bf80f4bSopenharmony_ci    void UpdateGlobalSet(IRenderCommandList& cmdList);
768bf80f4bSopenharmony_ci
778bf80f4bSopenharmony_ci    static constexpr uint32_t TARGET_COUNT { 7u };
788bf80f4bSopenharmony_ci    static constexpr uint32_t CORE_BLOOM_QUALITY_LOW { 1u };
798bf80f4bSopenharmony_ci    static constexpr uint32_t CORE_BLOOM_QUALITY_NORMAL { 2u };
808bf80f4bSopenharmony_ci    static constexpr uint32_t CORE_BLOOM_QUALITY_HIGH { 4u };
818bf80f4bSopenharmony_ci    static constexpr int CORE_BLOOM_QUALITY_COUNT { 3u };
828bf80f4bSopenharmony_ci
838bf80f4bSopenharmony_ci    struct Targets {
848bf80f4bSopenharmony_ci        std::array<RenderHandleReference, TARGET_COUNT> tex1;
858bf80f4bSopenharmony_ci        // separate target needed in graphics bloom upscale
868bf80f4bSopenharmony_ci        std::array<RenderHandleReference, TARGET_COUNT> tex2;
878bf80f4bSopenharmony_ci        std::array<BASE_NS::Math::UVec2, TARGET_COUNT> tex1Size;
888bf80f4bSopenharmony_ci    };
898bf80f4bSopenharmony_ci    Targets targets_;
908bf80f4bSopenharmony_ci
918bf80f4bSopenharmony_ci    struct PSOs {
928bf80f4bSopenharmony_ci        struct DownscaleHandles {
938bf80f4bSopenharmony_ci            RenderHandle regular;
948bf80f4bSopenharmony_ci            RenderHandle threshold;
958bf80f4bSopenharmony_ci        };
968bf80f4bSopenharmony_ci
978bf80f4bSopenharmony_ci        std::array<DownscaleHandles, CORE_BLOOM_QUALITY_COUNT> downscaleHandles;
988bf80f4bSopenharmony_ci        std::array<DownscaleHandles, CORE_BLOOM_QUALITY_COUNT> downscaleHandlesCompute;
998bf80f4bSopenharmony_ci
1008bf80f4bSopenharmony_ci        RenderHandle downscaleAndThreshold;
1018bf80f4bSopenharmony_ci        RenderHandle downscale;
1028bf80f4bSopenharmony_ci        RenderHandle upscale;
1038bf80f4bSopenharmony_ci        RenderHandle combine;
1048bf80f4bSopenharmony_ci
1058bf80f4bSopenharmony_ci        ShaderThreadGroup downscaleAndThresholdTGS { 1, 1, 1 };
1068bf80f4bSopenharmony_ci        ShaderThreadGroup downscaleTGS { 1, 1, 1 };
1078bf80f4bSopenharmony_ci        ShaderThreadGroup upscaleTGS { 1, 1, 1 };
1088bf80f4bSopenharmony_ci        ShaderThreadGroup combineTGS { 1, 1, 1 };
1098bf80f4bSopenharmony_ci    };
1108bf80f4bSopenharmony_ci    PSOs psos_;
1118bf80f4bSopenharmony_ci
1128bf80f4bSopenharmony_ci    struct Binders {
1138bf80f4bSopenharmony_ci        IDescriptorSetBinder::Ptr globalSet0;
1148bf80f4bSopenharmony_ci
1158bf80f4bSopenharmony_ci        IDescriptorSetBinder::Ptr downscaleAndThreshold;
1168bf80f4bSopenharmony_ci        std::array<IDescriptorSetBinder::Ptr, TARGET_COUNT> downscale;
1178bf80f4bSopenharmony_ci        std::array<IDescriptorSetBinder::Ptr, TARGET_COUNT> upscale;
1188bf80f4bSopenharmony_ci        IDescriptorSetBinder::Ptr combine;
1198bf80f4bSopenharmony_ci    };
1208bf80f4bSopenharmony_ci    Binders binders_;
1218bf80f4bSopenharmony_ci
1228bf80f4bSopenharmony_ci    BASE_NS::Math::UVec2 baseSize_ { 0u, 0u };
1238bf80f4bSopenharmony_ci    BASE_NS::Math::Vec4 bloomParameters_ { 0.0f, 0.0f, 0.0f, 0.0f };
1248bf80f4bSopenharmony_ci
1258bf80f4bSopenharmony_ci    RenderHandleReference samplerHandle_;
1268bf80f4bSopenharmony_ci    BASE_NS::Format format_ { BASE_NS::Format::BASE_FORMAT_UNDEFINED };
1278bf80f4bSopenharmony_ci
1288bf80f4bSopenharmony_ci    ViewportDesc baseViewportDesc_;
1298bf80f4bSopenharmony_ci    ScissorDesc baseScissorDesc_;
1308bf80f4bSopenharmony_ci
1318bf80f4bSopenharmony_ci    bool bloomEnabled_ { false };
1328bf80f4bSopenharmony_ci    BloomInfo bloomInfo_;
1338bf80f4bSopenharmony_ci};
1348bf80f4bSopenharmony_ciRENDER_END_NAMESPACE()
1358bf80f4bSopenharmony_ci
1368bf80f4bSopenharmony_ci#endif // CORE__RENDER__NODE__RENDER_BLOOM_H
137