From 467b0360b96ea6cfce4ae1bb530d12f56b382946 Mon Sep 17 00:00:00 2001 From: Adam Bialogonski Date: Thu, 5 Sep 2024 16:35:32 +0100 Subject: [PATCH] Passing down render target to compile the pipeline Change-Id: Ia544d2661ffbef7c6392e550ee8119e9dc993818 --- .../graphics-pipeline-create-info.h | 24 ++++++++++++++++++- .../render/common/render-algorithms.cpp | 11 +++++---- .../render/common/render-algorithms.h | 19 ++++++--------- .../internal/render/common/render-manager.cpp | 3 ++- .../render/renderers/pipeline-cache.cpp | 3 ++- .../render/renderers/pipeline-cache.h | 2 ++ .../render/renderers/render-renderer.cpp | 5 +++- .../render/renderers/render-renderer.h | 4 ++++ 8 files changed, 51 insertions(+), 20 deletions(-) diff --git a/dali/graphics-api/graphics-pipeline-create-info.h b/dali/graphics-api/graphics-pipeline-create-info.h index 0ddcbd7de..b44f0027b 100644 --- a/dali/graphics-api/graphics-pipeline-create-info.h +++ b/dali/graphics-api/graphics-pipeline-create-info.h @@ -2,7 +2,7 @@ #define DALI_GRAPHICS_PIPELINE_CREATE_INFO_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ namespace Dali { namespace Graphics { +class RenderTarget; /** * @brief Interface class for generating Pipeline types in the graphics API. * @@ -190,6 +191,25 @@ struct PipelineCreateInfo return *this; } + /** + * @brief Sets render target that pipeline will be used with + * + * The pipeline must know which render target (this or compatible) + * it will be used with. + * + * It is valid not to set render target but only if device supports + * 'dynamic rendering'. Our current implementation doesn't support it + * but it may in the future. + * + * @param[in] value Pointer to valid RenderTarget objet + * @return reference to this structure + */ + auto& SetRenderTarget(RenderTarget* value) + { + renderTarget = value; + return *this; + } + GraphicsStructureType type{GraphicsStructureType::PIPELINE_CREATE_INFO_STRUCT}; ExtensionCreateInfo* nextExtension{nullptr}; @@ -203,6 +223,8 @@ struct PipelineCreateInfo InputAssemblyState* inputAssemblyState{nullptr}; PipelineDynamicStateMask dynamicStateMask{0u}; + RenderTarget* renderTarget{nullptr}; + const AllocationCallbacks* allocationCallbacks{nullptr}; }; diff --git a/dali/internal/render/common/render-algorithms.cpp b/dali/internal/render/common/render-algorithms.cpp index 3dd8b4f98..ced4aebe3 100644 --- a/dali/internal/render/common/render-algorithms.cpp +++ b/dali/internal/render/common/render-algorithms.cpp @@ -592,7 +592,8 @@ inline void RenderAlgorithms::ProcessRenderList(const RenderList& const Rect& viewport, const Rect& rootClippingRect, int orientation, - const Uint16Pair& sceneSize) + const Uint16Pair& sceneSize, + Graphics::RenderTarget* renderTarget) { DALI_PRINT_RENDER_LIST(renderList); @@ -704,7 +705,7 @@ inline void RenderAlgorithms::ProcessRenderList(const RenderList& for(auto queue = 0u; queue < MAX_QUEUE; ++queue) { // Render the item. It will write into the command buffer everything it has to render - item.mRenderer->Render(secondaryCommandBuffer, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mScale, item.mSize, !item.mIsOpaque, instruction, queue); + item.mRenderer->Render(secondaryCommandBuffer, bufferIndex, *item.mNode, item.mModelMatrix, item.mModelViewMatrix, viewMatrix, projectionMatrix, item.mScale, item.mSize, !item.mIsOpaque, instruction, renderTarget, queue); } } } @@ -757,7 +758,8 @@ void RenderAlgorithms::ProcessRenderInstruction(const RenderInstruction& const Rect& viewport, const Rect& rootClippingRect, int orientation, - const Uint16Pair& sceneSize) + const Uint16Pair& sceneSize, + Graphics::RenderTarget* renderTarget) { DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_RENDER_INSTRUCTION_PROCESS", [&](std::ostringstream& oss) { oss << "[" << instruction.RenderListCount() << "]"; }); @@ -792,7 +794,8 @@ void RenderAlgorithms::ProcessRenderInstruction(const RenderInstruction& viewport, rootClippingRect, orientation, - sceneSize); + sceneSize, + renderTarget); // Execute command buffer auto* commandBuffer = renderList->GetCommandBuffer(); diff --git a/dali/internal/render/common/render-algorithms.h b/dali/internal/render/common/render-algorithms.h index 04b2fe6ba..38b4d6d67 100644 --- a/dali/internal/render/common/render-algorithms.h +++ b/dali/internal/render/common/render-algorithms.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_RENDER_ALGORITHMS_H /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,7 @@ class RenderAlgorithms * @param[in] rootClippingRect The clipping rectangle * @param[in] orientation The Scene's surface orientation. * @param[in] sceneSize The Scene's surface size. + * @param[in] renderTarget The RenderTarget associated with instruction */ void ProcessRenderInstruction(const SceneGraph::RenderInstruction& instruction, BufferIndex bufferIndex, @@ -69,7 +70,8 @@ class RenderAlgorithms const Rect& viewport, const Rect& rootClippingRect, int orientation, - const Uint16Pair& sceneSize); + const Uint16Pair& sceneSize, + Graphics::RenderTarget* renderTarget); /** * Resets main command buffer (per scene) @@ -95,15 +97,6 @@ class RenderAlgorithms } private: - /** - * @brief Calculate a 2D AABB (axis aligned bounding box) in screen space. - * The RenderItems dimensions are translated and a Z value of 0 is assumed for this purpose. - * No projection is performed, but rotation on Z is supported. - * @param[in] item The RenderItem to generate an AABB for - * @return The generated AABB in screen space - */ - inline Dali::ClippingBox CalculateScreenSpaceAABB(const Dali::Internal::SceneGraph::RenderItem& item); - /** * @brief Perform any scissor clipping related operations based on the current RenderItem. * This includes: @@ -155,6 +148,7 @@ class RenderAlgorithms * @param[in] rootClippingRect The root clipping rectangle * @param[in] orientation The Scene's surface orientation * @param[in] sceneSize The Scene's surface size. + * @param[in] renderTarget The render target associated with render instruction */ inline void ProcessRenderList(const Dali::Internal::SceneGraph::RenderList& renderList, BufferIndex bufferIndex, @@ -166,7 +160,8 @@ class RenderAlgorithms const Rect& viewport, const Rect& rootClippingRect, int orientation, - const Uint16Pair& sceneSize); + const Uint16Pair& sceneSize, + Graphics::RenderTarget* renderTarget); // Member variables: diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index 784ad8543..aca9fece7 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -1194,7 +1194,8 @@ void RenderManager::RenderScene(Integration::RenderStatus& status, Integration:: viewportRect, clippingRect, surfaceOrientation, - Uint16Pair(surfaceRect.width, surfaceRect.height)); + Uint16Pair(surfaceRect.width, surfaceRect.height), + currentRenderTarget); Graphics::SyncObject* syncObject{nullptr}; // If the render instruction has an associated render tracker (owned separately) diff --git a/dali/internal/render/renderers/pipeline-cache.cpp b/dali/internal/render/renderers/pipeline-cache.cpp index c73ab4e79..dfbd1ab3b 100644 --- a/dali/internal/render/renderers/pipeline-cache.cpp +++ b/dali/internal/render/renderers/pipeline-cache.cpp @@ -543,7 +543,8 @@ PipelineResult PipelineCache::GetPipeline(const PipelineCacheQueryInfo& queryInf .SetVertexInputState(&level0->inputState) .SetRasterizationState(&level1->rs) .SetColorBlendState(&level2->colorBlendState) - .SetProgramState(&programState); + .SetProgramState(&programState) + .SetRenderTarget(queryInfo.renderTarget); // Store a pipeline per renderer per render (renderer can be owned by multiple nodes, // and re-drawn in multiple instructions). diff --git a/dali/internal/render/renderers/pipeline-cache.h b/dali/internal/render/renderers/pipeline-cache.h index 17bc6a030..0f2f5ad86 100644 --- a/dali/internal/render/renderers/pipeline-cache.h +++ b/dali/internal/render/renderers/pipeline-cache.h @@ -102,6 +102,8 @@ struct PipelineCacheQueryInfo Program* program; Geometry* geometry; + Graphics::RenderTarget* renderTarget; + bool cameraUsingReflection; // Blending diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 231af2a2c..d7c5c4eda 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -492,6 +492,7 @@ bool Renderer::Render(Graphics::CommandBuffer& comma const Vector3& size, bool blend, const Dali::Internal::SceneGraph::RenderInstruction& instruction, + Graphics::RenderTarget* renderTarget, uint32_t queueIndex) { // Before doing anything test if the call happens in the right queue @@ -591,7 +592,7 @@ bool Renderer::Render(Graphics::CommandBuffer& comma if(program) { // Prepare the graphics pipeline. This may either re-use an existing pipeline or create a new one. - auto& pipeline = PrepareGraphicsPipeline(*program, instruction, node, blend); + auto& pipeline = PrepareGraphicsPipeline(*program, instruction, renderTarget, node, blend); commandBuffer.BindPipeline(pipeline); @@ -1062,6 +1063,7 @@ Vector4 Renderer::GetTextureUpdateArea() const noexcept Graphics::Pipeline& Renderer::PrepareGraphicsPipeline( Program& program, const Dali::Internal::SceneGraph::RenderInstruction& instruction, + Graphics::RenderTarget* renderTarget, const SceneGraph::NodeDataProvider& node, bool blend) { @@ -1074,6 +1076,7 @@ Graphics::Pipeline& Renderer::PrepareGraphicsPipeline( queryInfo.blendingOptions = &mBlendingOptions; queryInfo.alphaPremultiplied = mPremultipliedAlphaEnabled; queryInfo.cameraUsingReflection = instruction.GetCamera()->GetReflectionUsed(); + queryInfo.renderTarget = renderTarget; queryInfo.GenerateHash(); diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index 1726d518e..6ab32254a 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -412,6 +412,8 @@ class Renderer : public Program::LifecycleObserver * @param[in] size Size of the render item * @param[in] blend If true, blending is enabled * @param[in] instruction. for use case like reflection where CullFace needs to be adjusted + * @param[in] renderTarget render target associated with instruction + * @param[in] queueIndex Index of the render queue * * @return True if commands have been added to the command buffer */ @@ -426,6 +428,7 @@ class Renderer : public Program::LifecycleObserver const Vector3& size, bool blend, const Dali::Internal::SceneGraph::RenderInstruction& instruction, + Graphics::RenderTarget* renderTarget, uint32_t queueIndex); /** @@ -583,6 +586,7 @@ class Renderer : public Program::LifecycleObserver Graphics::Pipeline& PrepareGraphicsPipeline( Program& program, const Dali::Internal::SceneGraph::RenderInstruction& instruction, + Graphics::RenderTarget* renderTarget, const SceneGraph::NodeDataProvider& node, bool blend);