X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.h;h=5583fe0667704d7a472581d31091b7a5bffa3975;hb=eb07b0dfcfa3c654cb7e200e259571c4f8b6e50e;hp=d6668a13247707af8583bb4dcc28c415ea17d77a;hpb=da4ad1b400618f4663547453326cffa8a6c789cc;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h index d6668a1..5583fe0 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -19,44 +19,51 @@ */ // INTERNAL INCLUDES +#include +#include +#include + +#include #include #include +#include #include #include #include #include -#include #include +#include +#include #include -#include -#include -#include namespace Dali { namespace Internal { -class Context; class Texture; -class Program; +class ProgramCache; namespace SceneGraph { class SceneController; class Shader; class NodeDataProvider; - -class RenderInstruction; //for relfection effect +class RenderInstruction; //for reflection effect } // namespace SceneGraph namespace Render { +struct ShaderCache; +class PipelineCache; +class UniformBufferManager; +class PipelineCache; + /** * Renderers are used to render meshes * These objects are used during RenderManager::Render(), so properties modified during * the Update must either be double-buffered, or set via a message added to the RenderQueue. */ -class Renderer : public GlResourceOwner +class Renderer { public: /** @@ -87,21 +94,11 @@ public: }; /** - * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed() - */ - void GlContextDestroyed() override; - - /** - * @copydoc Dali::Internal::GlResourceOwner::GlCleanup() - */ - void GlCleanup() override; - - /** * Create a new renderer instance * @param[in] dataProviders The data providers for the renderer * @param[in] geometry The geometry for the renderer * @param[in] blendingBitmask A bitmask of blending options. - * @param[in] blendColor The blend color to pass to GL + * @param[in] blendColor The blend color * @param[in] faceCullingMode The face-culling mode. * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied. * @param[in] depthWriteMode Depth buffer write mode @@ -125,7 +122,7 @@ public: * @param[in] dataProviders The data providers for the renderer * @param[in] geometry The geometry for the renderer * @param[in] blendingBitmask A bitmask of blending options. - * @param[in] blendColor The blend color to pass to GL + * @param[in] blendColor The blend color * @param[in] faceCullingMode The face-culling mode. * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied. * @param[in] depthWriteMode Depth buffer write mode @@ -156,7 +153,7 @@ public: * @brief Returns a reference to an array of draw commands * @return Valid array of draw commands (may be empty) */ - const std::vector& GetDrawCommands() const + [[nodiscard]] const std::vector& GetDrawCommands() const { return mDrawCommands; } @@ -164,14 +161,22 @@ public: /** * Second-phase construction. * This is called when the renderer is inside render thread - * @param[in] context Context used by the renderer + * @param[in] graphicsController The graphics controller to use + * @param[in] programCache Cache of program objects + * @param[in] shaderCache Cache of shaders + * @param[in] uniformBufferManager Uniform buffer manager + * @param[in] pipelineCache Cache of pipelines */ - void Initialize(Context& context); + void Initialize(Graphics::Controller& graphicsController, + ProgramCache& programCache, + Render::ShaderCache& shaderCache, + Render::UniformBufferManager& uniformBufferManager, + Render::PipelineCache& pipelineCache); /** * Destructor */ - ~Renderer() override; + ~Renderer(); /** * Set the face-culling mode. @@ -187,7 +192,7 @@ public: /** * Set the blend color for blending options - * @param[in] blendColor The blend color to pass to GL + * @param[in] blendColor The blend color */ void SetBlendColor(const Vector4& color); @@ -220,7 +225,7 @@ public: * Query the Renderer's depth write mode * @return The renderer depth write mode */ - DepthWriteMode::Type GetDepthWriteMode() const; + [[nodiscard]] DepthWriteMode::Type GetDepthWriteMode() const; /** * Sets the depth test mode @@ -232,7 +237,7 @@ public: * Query the Renderer's depth test mode * @return The renderer depth test mode */ - DepthTestMode::Type GetDepthTestMode() const; + [[nodiscard]] DepthTestMode::Type GetDepthTestMode() const; /** * Sets the depth function @@ -244,7 +249,7 @@ public: * Query the Renderer's depth function * @return The renderer depth function */ - DepthFunction::Type GetDepthFunction() const; + [[nodiscard]] DepthFunction::Type GetDepthFunction() const; /** * Sets the render mode @@ -256,7 +261,7 @@ public: * Gets the render mode * @return The render mode */ - RenderMode::Type GetRenderMode() const; + [[nodiscard]] RenderMode::Type GetRenderMode() const; /** * Sets the stencil function @@ -268,7 +273,7 @@ public: * Gets the stencil function * @return The stencil function */ - StencilFunction::Type GetStencilFunction() const; + [[nodiscard]] StencilFunction::Type GetStencilFunction() const; /** * Sets the stencil function mask @@ -280,7 +285,7 @@ public: * Gets the stencil function mask * @return The stencil function mask */ - int GetStencilFunctionMask() const; + [[nodiscard]] int GetStencilFunctionMask() const; /** * Sets the stencil function reference @@ -292,7 +297,7 @@ public: * Gets the stencil function reference * @return The stencil function reference */ - int GetStencilFunctionReference() const; + [[nodiscard]] int GetStencilFunctionReference() const; /** * Sets the stencil mask @@ -304,7 +309,7 @@ public: * Gets the stencil mask * @return The stencil mask */ - int GetStencilMask() const; + [[nodiscard]] int GetStencilMask() const; /** * Sets the stencil operation for when the stencil test fails @@ -316,7 +321,7 @@ public: * Gets the stencil operation for when the stencil test fails * @return The stencil operation */ - StencilOperation::Type GetStencilOperationOnFail() const; + [[nodiscard]] StencilOperation::Type GetStencilOperationOnFail() const; /** * Sets the stencil operation for when the depth test fails @@ -328,7 +333,7 @@ public: * Gets the stencil operation for when the depth test fails * @return The stencil operation */ - StencilOperation::Type GetStencilOperationOnZFail() const; + [[nodiscard]] StencilOperation::Type GetStencilOperationOnZFail() const; /** * Sets the stencil operation for when the depth test passes @@ -340,17 +345,16 @@ public: * Gets the stencil operation for when the depth test passes * @return The stencil operation */ - StencilOperation::Type GetStencilOperationOnZPass() const; + [[nodiscard]] StencilOperation::Type GetStencilOperationOnZPass() const; /** * Called to upload during RenderManager::Render(). - * @param[in] context The context used for uploading */ - void Upload(Context& context); + void Upload(); /** * Called to render during RenderManager::Render(). - * @param[in] context The context used for rendering + * @param[in,out] commandBuffer The command buffer to write into * @param[in] bufferIndex The index of the previous update buffer. * @param[in] node The node using this renderer * @param[in] modelViewMatrix The model-view matrix. @@ -360,9 +364,10 @@ public: * @param[in] blend If true, blending is enabled * @param[in] boundTextures The textures bound for rendering * @param[in] instruction. for use case like reflection where CullFace needs to be adjusted - + * + * @return True if commands have been added to the command buffer */ - void Render(Context& context, + bool Render(Graphics::CommandBuffer& commandBuffer, BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Matrix& modelMatrix, @@ -371,17 +376,16 @@ public: const Matrix& projectionMatrix, const Vector3& size, bool blend, - Vector& boundTextures, + Vector& boundTextures, const Dali::Internal::SceneGraph::RenderInstruction& instruction, uint32_t queueIndex); /** * Write the renderer's sort attributes to the passed in reference * - * @param[in] bufferIndex The current update buffer index. * @param[out] sortAttributes */ - void SetSortAttributes(BufferIndex bufferIndex, SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const; + void SetSortAttributes(SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes) const; /** * Sets the flag indicating whether shader changed. @@ -398,6 +402,26 @@ public: */ bool Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node); + template + bool WriteDefaultUniform(const Graphics::UniformInfo* uniformInfo, + Render::UniformBufferView& ubo, + const T& data); + + template + void WriteUniform(Render::UniformBufferView& ubo, + const Graphics::UniformInfo& uniformInfo, + const T& data); + + void WriteUniform(Render::UniformBufferView& ubo, + const Graphics::UniformInfo& uniformInfo, + const void* data, + uint32_t size); + + [[nodiscard]] FaceCullingMode::Type GetFaceCullMode() const + { + return mFaceCullingMode; + } + private: struct UniformIndexMap; @@ -408,56 +432,121 @@ private: Renderer& operator=(const Renderer& rhs); /** - * Sets blending options - * @param context to use - * @param blend Wheter blending should be enabled or not - */ - void SetBlending(Context& context, bool blend); - - /** - * Set the uniforms from properties according to the uniform map + * Builds a uniform map based on the index of the cached location in the Program. * @param[in] bufferIndex The index of the previous update buffer. * @param[in] node The node using the renderer * @param[in] size The size of the renderer * @param[in] program The shader program on which to set the uniforms. */ - void SetUniforms(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program); + void BuildUniformIndexMap(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program); /** - * Set the program uniform in the map from the mapped property - * @param[in] bufferIndex The index of the previous update buffer. - * @param[in] program The shader program - * @param[in] map The uniform + * Bind the textures and setup the samplers + * @param[in] commandBuffer The command buffer to record binding into + * @param[in] boundTextures The textures bound for rendering */ - void SetUniformFromProperty(BufferIndex bufferIndex, Program& program, UniformIndexMap& map); + void BindTextures(Graphics::CommandBuffer& commandBuffer, Vector& boundTextures); /** - * Bind the textures and setup the samplers - * @param[in] context The GL context - * @param[in] program The shader program - * @param[in] boundTextures The textures bound for rendering - * @return False if create or bind failed, true if success. + * Prepare a pipeline for this renderer. + * + * As a renderer can be re-used in a single frame (e.g. being used by multiple nodes, or + * by non-exclusive render tasks), we store a pipeline per node/instruction. + * In practice, the implementation will cached pipelines, so we normally only have + * multiple handles. */ - bool BindTextures(Context& context, Program& program, Vector& boundTextures); + Graphics::Pipeline& PrepareGraphicsPipeline( + Program& program, + const Dali::Internal::SceneGraph::RenderInstruction& instruction, + const SceneGraph::NodeDataProvider& node, + bool blend); + + /** + * Setup and write data to the uniform buffer + * + * @param[in] bufferIndex The current buffer index + * @param[in] commandBuffer The command buffer to bind the uniform buffer to + * @param[in] node The node using this renderer + * @param[in] modelViewMatrix The model-view matrix. + * @param[in] viewMatrix The view matrix. + * @param[in] projectionMatrix The projection matrix. + * @param[in] size Size of the render item + * @param[in] blend If true, blending is enabled + * @param[in] instruction The render instruction + */ + void WriteUniformBuffer(BufferIndex bufferIndex, + Graphics::CommandBuffer& commandBuffer, + Program* program, + const SceneGraph::RenderInstruction& instruction, + const SceneGraph::NodeDataProvider& node, + const Matrix& modelMatrix, + const Matrix& modelViewMatrix, + const Matrix& viewMatrix, + const Matrix& projectionMatrix, + const Vector3& size); + + /** + * @brief Fill uniform buffer at index. Writes uniforms into given memory address + * + * @param[in] instruction The render instruction + * @param[in,out] ubo Target uniform buffer object + * @param[out] outBindings output bindings vector + * @param[out] offset output offset of the next uniform buffer memory address + * @param[in] updateBufferIndex update buffer index + */ + void FillUniformBuffer(Program& program, + const SceneGraph::RenderInstruction& instruction, + Render::UniformBufferView& ubo, + std::vector*& outBindings, + uint32_t& offset, + BufferIndex updateBufferIndex); private: + Graphics::Controller* mGraphicsController; OwnerPointer mRenderDataProvider; - Context* mContext; Render::Geometry* mGeometry; + ProgramCache* mProgramCache{nullptr}; + Render::ShaderCache* mShaderCache{nullptr}; + + Render::UniformBufferManager* mUniformBufferManager{}; + std::vector mUniformBufferBindings{}; + + Render::PipelineCache* mPipelineCache{nullptr}; + + using Hash = unsigned long; + + typedef const float&(PropertyInputImpl::*FuncGetter )(BufferIndex) const; + struct UniformIndexMap { - uint32_t uniformIndex; ///< The index of the cached location in the Program - const PropertyInputImpl* propertyValue; + ConstString uniformName; ///< The uniform name + const PropertyInputImpl* propertyValue{nullptr}; ///< The property value + Hash uniformNameHash{0u}; + Hash uniformNameHashNoArray{0u}; + int32_t arrayIndex{-1}; ///< The array index + + int16_t uniformLocation{0u}; + uint16_t uniformOffset{0u}; + uint16_t uniformSize{0u}; + FuncGetter uniformFunc{0}; }; using UniformIndexMappings = Dali::Vector; UniformIndexMappings mUniformIndexMap; - Vector mAttributesLocation; + uint64_t mUniformsHash; - uint64_t mUniformsHash; + struct HashedPipeline + { + uint64_t mHash{0u}; + Graphics::UniquePtr mGraphicsPipeline{nullptr}; + inline static uint64_t GetHash(const void* node, const void* instruction, bool blend) + { + return (reinterpret_cast(node) << 32) | ((reinterpret_cast(instruction) & 0xFFFFFFF) << 1) | blend; + } + }; StencilParameters mStencilParameters; ///< Struct containing all stencil related options BlendingOptions mBlendingOptions; ///< Blending options including blend color, blend func and blend equation @@ -465,13 +554,12 @@ private: uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw uint32_t mIndexedDrawElementsCount; ///< Number of elements to draw - DepthFunction::Type mDepthFunction : 4; ///< The depth function - FaceCullingMode::Type mFaceCullingMode : 3; ///< The mode of face culling - DepthWriteMode::Type mDepthWriteMode : 3; ///< The depth write mode - DepthTestMode::Type mDepthTestMode : 3; ///< The depth test mode - bool mUpdateAttributesLocation : 1; ///< Indicates attribute locations have changed - bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required - bool mShaderChanged : 1; ///< Flag indicating the shader changed and uniform maps have to be updated + DepthFunction::Type mDepthFunction : 4; ///< The depth function + FaceCullingMode::Type mFaceCullingMode : 3; ///< The mode of face culling + DepthWriteMode::Type mDepthWriteMode : 3; ///< The depth write mode + DepthTestMode::Type mDepthTestMode : 3; ///< The depth test mode + bool mPremultipliedAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required + bool mShaderChanged : 1; ///< Flag indicating the shader changed and uniform maps have to be updated bool mUpdated : 1; std::vector mDrawCommands; // Devel stuff