From c352033d48204b354f419a8ad716f0196e5a8470 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Fri, 11 Nov 2022 22:39:21 +0900 Subject: [PATCH] Add MultiSampling FrameBuffer implement. Let we allow to call FramebufferTexture2DMultisample if possible. Change-Id: I4874ad78dfe1e468b5571ba4bc0112e7f710f492 Signed-off-by: Eunki, Hong --- .../dali-test-suite-utils/test-gl-abstraction.cpp | 5 ++++ .../dali-test-suite-utils/test-gl-abstraction.h | 8 +++++++ automated-tests/src/dali/utc-Dali-FrameBuffer.cpp | 27 +++++++++++++++++++++- dali/devel-api/rendering/frame-buffer-devel.cpp | 7 +++++- dali/devel-api/rendering/frame-buffer-devel.h | 12 +++++++++- .../graphics-framebuffer-create-info.h | 15 +++++++++++- dali/integration-api/gl-abstraction.h | 7 ++++++ dali/internal/common/type-abstraction.h | 17 +++++++++++++- .../internal/event/rendering/frame-buffer-impl.cpp | 7 +++++- dali/internal/event/rendering/frame-buffer-impl.h | 7 +++++- dali/internal/render/common/render-manager.cpp | 5 ++++ dali/internal/render/common/render-manager.h | 9 +++++++- .../render/renderers/render-frame-buffer.cpp | 7 +++++- .../render/renderers/render-frame-buffer.h | 12 +++++++--- dali/internal/update/manager/update-manager.cpp | 11 +++++++++ dali/internal/update/manager/update-manager.h | 18 +++++++++++++++ 16 files changed, 162 insertions(+), 12 deletions(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.cpp index 7a31046..6021026 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.cpp @@ -166,6 +166,11 @@ bool TestGlAbstraction::IsAdvancedBlendEquationSupported() return true; } +bool TestGlAbstraction::IsMultisampledRenderToTextureSupported() +{ + return true; +} + bool TestGlAbstraction::IsBlendEquationSupported(DevelBlendEquation::Type blendEquation) { return true; diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index f6878ae..5e5fde3 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -72,6 +72,8 @@ public: bool IsAdvancedBlendEquationSupported() override; + bool IsMultisampledRenderToTextureSupported() override; + bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation) override; std::string GetShaderVersionPrefix(); @@ -1702,6 +1704,12 @@ public: { } + inline void FramebufferTexture2DMultisample(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) override + { + // TODO : Check it if need + FramebufferTexture2D(target, attachment, textarget, texture, level); + } + inline void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) override { } diff --git a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp index 95cf119..dfb0db1 100644 --- a/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp +++ b/automated-tests/src/dali/utc-Dali-FrameBuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -551,6 +551,31 @@ int UtcDaliFrameBufferAttachDepthStencilTexture01(void) END_TEST; } +int UtcDaliFrameBufferSetMultiSampingLevel(void) +{ + TestApplication application; + + unsigned int width(64); + unsigned int height(64); + FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL); + Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height); + frameBuffer.AttachColorTexture(texture); + + DevelFrameBuffer::SetMultiSamplingLevel(frameBuffer, 4u); + + CreateRenderTask(application, frameBuffer); + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); + DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); + + // We don't have getter API for multisampling level. No testing. + + END_TEST; +} + int UtcDaliFrameBufferGetColorTexture01(void) { TestApplication application; diff --git a/dali/devel-api/rendering/frame-buffer-devel.cpp b/dali/devel-api/rendering/frame-buffer-devel.cpp index fe0d072..2ae365b 100644 --- a/dali/devel-api/rendering/frame-buffer-devel.cpp +++ b/dali/devel-api/rendering/frame-buffer-devel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -53,6 +53,11 @@ void AttachDepthStencilTexture(FrameBuffer frameBuffer, Texture& texture, uint32 } } +void SetMultiSamplingLevel(FrameBuffer frameBuffer, uint8_t multiSamplingLevel) +{ + GetImplementation(frameBuffer).SetMultiSamplingLevel(multiSamplingLevel); +} + Texture GetColorTexture(const FrameBuffer frameBuffer, uint8_t index) { Internal::Texture* texturePtr = GetImplementation(frameBuffer).GetColorTexture(index); diff --git a/dali/devel-api/rendering/frame-buffer-devel.h b/dali/devel-api/rendering/frame-buffer-devel.h index 2799887..99c5b34 100644 --- a/dali/devel-api/rendering/frame-buffer-devel.h +++ b/dali/devel-api/rendering/frame-buffer-devel.h @@ -2,7 +2,7 @@ #define DALI_FRAME_BUFFER_DEVEL_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -77,6 +77,16 @@ DALI_CORE_API void AttachDepthStencilTexture(FrameBuffer frameBuffer, Texture& t DALI_CORE_API void AttachDepthStencilTexture(FrameBuffer frameBuffer, Texture& texture, uint32_t mipmapLevel); /** + * @brief Sets the level of multisampling in the frame buffer. + * @note This API must be called before the frame buffer is attached to render task. (Since multi sample level is immutable) + * Otherwise, no effects. + * + * @param[in] frameBuffer The FrameBuffer handle + * @param[in] multiSamplingLevel The level of samples + */ +DALI_CORE_API void SetMultiSamplingLevel(FrameBuffer frameBuffer, uint8_t multiSamplingLevel); + +/** * @brief Gets the color texture at the given @a index used as output in the frame buffer. * * @param[in] frameBuffer A handle to the FrameBuffer diff --git a/dali/graphics-api/graphics-framebuffer-create-info.h b/dali/graphics-api/graphics-framebuffer-create-info.h index c4c1c59..a09bbd5 100644 --- a/dali/graphics-api/graphics-framebuffer-create-info.h +++ b/dali/graphics-api/graphics-framebuffer-create-info.h @@ -2,7 +2,7 @@ #define DALI_GRAPHICS_FRAMEBUFFER_CREATE_INFO_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -97,6 +97,18 @@ struct FramebufferCreateInfo } /** + * @brief Sets multisampling level of framebuffer + * + * @param[in] value multisampling level of framebuffer + * @return reference to this structure + */ + auto& SetMultiSamplingLevel(uint8_t value) + { + multiSamplingLevel = value; + return *this; + } + + /** * @brief Sets allocation callbacks which will be used when object is created * and destroyed. * @@ -114,6 +126,7 @@ struct FramebufferCreateInfo std::vector colorAttachments{}; DepthStencilAttachment depthStencilAttachment{}; Extent2D size{}; + uint8_t multiSamplingLevel{0u}; const AllocationCallbacks* allocationCallbacks{nullptr}; }; diff --git a/dali/integration-api/gl-abstraction.h b/dali/integration-api/gl-abstraction.h index df82db9..2b06e3a 100644 --- a/dali/integration-api/gl-abstraction.h +++ b/dali/integration-api/gl-abstraction.h @@ -130,6 +130,12 @@ public: virtual bool IsAdvancedBlendEquationSupported() = 0; /** + * Returns current gles can support multisampled render to texture + * @Return true current gles support multisampled render to texture + */ + virtual bool IsMultisampledRenderToTextureSupported() = 0; + + /** * Returns current gles can support the blend equation * @Return true current gles support the blend equation */ @@ -339,6 +345,7 @@ public: virtual void UniformMatrix4x3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = 0; virtual void BlitFramebuffer (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) = 0; virtual void RenderbufferStorageMultisample (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) = 0; + virtual void FramebufferTexture2DMultisample(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) = 0; virtual void FramebufferTextureLayer (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer) = 0; virtual GLvoid* MapBufferRange (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) = 0; virtual void FlushMappedBufferRange (GLenum target, GLintptr offset, GLsizeiptr length) = 0; diff --git a/dali/internal/common/type-abstraction.h b/dali/internal/common/type-abstraction.h index 135afdc..2c2768b 100644 --- a/dali/internal/common/type-abstraction.h +++ b/dali/internal/common/type-abstraction.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_TYPE_ABSTRACTION_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -101,6 +101,21 @@ template<> struct ParameterType : public BasicType { }; +template<> +struct ParameterType : public BasicType +{ +}; + +#if SCHAR_MAX != SHRT_MAX +template<> +struct ParameterType : public BasicType +{ +}; +template<> +struct ParameterType : public BasicType +{ +}; +#endif #if INT_MAX != LONG_MAX template<> diff --git a/dali/internal/event/rendering/frame-buffer-impl.cpp b/dali/internal/event/rendering/frame-buffer-impl.cpp index 9114269..bd6b118 100644 --- a/dali/internal/event/rendering/frame-buffer-impl.cpp +++ b/dali/internal/event/rendering/frame-buffer-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -107,6 +107,11 @@ void FrameBuffer::AttachDepthStencilTexture(TexturePtr texture, unsigned int mip } } +void FrameBuffer::SetMultiSamplingLevel(uint8_t multiSamplingLevel) +{ + SetMultiSamplingLevelToFrameBuffer(mEventThreadServices.GetUpdateManager(), *mRenderObject, multiSamplingLevel); +} + Texture* FrameBuffer::GetColorTexture(uint8_t index) const { return (index >= mColorAttachmentCount) ? nullptr : mColor[index].Get(); diff --git a/dali/internal/event/rendering/frame-buffer-impl.h b/dali/internal/event/rendering/frame-buffer-impl.h index 399436b..9066334 100644 --- a/dali/internal/event/rendering/frame-buffer-impl.h +++ b/dali/internal/event/rendering/frame-buffer-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_FRAME_BUFFER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -84,6 +84,11 @@ public: void AttachDepthStencilTexture(TexturePtr texture, uint32_t mipmapLevel); /** + * @copydoc Dali::DevelFrameBuffer::SetMultiSamplingLevel() + */ + void SetMultiSamplingLevel(uint8_t multiSamplingLevel); + + /** * @copydoc Dali::FrameBuffer::GetColorTexture() */ Texture* GetColorTexture(uint8_t index) const; diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index fc2ceb7..6c1b4de 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -348,6 +348,11 @@ void RenderManager::AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer->AttachDepthStencilTexture(texture, mipmapLevel); } +void RenderManager::SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel) +{ + frameBuffer->SetMultiSamplingLevel(multiSamplingLevel); +} + void RenderManager::AddVertexBuffer(OwnerPointer& vertexBuffer) { mImpl->vertexBufferContainer.PushBack(vertexBuffer.Release()); diff --git a/dali/internal/render/common/render-manager.h b/dali/internal/render/common/render-manager.h index 7ba572b..3a5c231 100644 --- a/dali/internal/render/common/render-manager.h +++ b/dali/internal/render/common/render-manager.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -283,6 +283,13 @@ public: void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel); /** + * Set a multisampling level value as texture output to the existing frame buffer + * @param[in] frameBuffer The FrameBuffer + * @param[in] multiSamplingLevel The level of multisampling + */ + void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel); + + /** * Initializes a Scene to the render manager * @param[in] scene The Scene to initialize */ diff --git a/dali/internal/render/renderers/render-frame-buffer.cpp b/dali/internal/render/renderers/render-frame-buffer.cpp index 73101e1..25209a9 100644 --- a/dali/internal/render/renderers/render-frame-buffer.cpp +++ b/dali/internal/render/renderers/render-frame-buffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -101,6 +101,11 @@ void FrameBuffer::AttachDepthStencilTexture(Render::Texture* texture, uint32_t m } } +void FrameBuffer::SetMultiSamplingLevel(uint8_t multiSamplingLevel) +{ + mCreateInfo.multiSamplingLevel = multiSamplingLevel; +} + bool FrameBuffer::CreateGraphicsObjects() { bool created = false; diff --git a/dali/internal/render/renderers/render-frame-buffer.h b/dali/internal/render/renderers/render-frame-buffer.h index 01ce5c2..097e703 100644 --- a/dali/internal/render/renderers/render-frame-buffer.h +++ b/dali/internal/render/renderers/render-frame-buffer.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_RENDER_FRAME_BUFFER_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -62,8 +62,8 @@ public: * Doesn't re-create them if they are already generated, also doesn't * check for new attachments. * - * Creates the framebuffer, attaches color and depth textures, generates - * render target and render passes. + * Creates the framebuffer, attaches color and depth textures, set multi sampling level, + * generates render target and render passes. * * @return true if there are attachments and the graphics objects have been created. */ @@ -105,6 +105,12 @@ public: void AttachDepthStencilTexture(Render::Texture* texture, uint32_t mipmapLevel); /** + * @brief Sets the level of multisampling in the frame buffer. This API is valid only GL_EXT_multisampled_render_to_texture supported. + * @param[in] multiSamplingLevel The level of multisampling + */ + void SetMultiSamplingLevel(uint8_t multiSamplingLevel); + + /** * @brief Get the number of textures bound to this frame buffer as color attachments. * @return The number of color attachments. */ diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index cffa575..1574b5d 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -1503,6 +1503,17 @@ void UpdateManager::AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* new(slot) DerivedType(&mImpl->renderManager, &RenderManager::AttachDepthStencilTextureToFrameBuffer, frameBuffer, texture, mipmapLevel); } +void UpdateManager::SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel) +{ + using DerivedType = MessageValue2; + + // Reserve some memory inside the render queue + uint32_t* slot = mImpl->renderQueue.ReserveMessageSlot(mSceneGraphBuffers.GetUpdateBufferIndex(), sizeof(DerivedType)); + + // Construct message in the render queue memory; note that delete should not be called on the return value + new(slot) DerivedType(&mImpl->renderManager, &RenderManager::SetMultiSamplingLevelToFrameBuffer, frameBuffer, multiSamplingLevel); +} + } // namespace SceneGraph } // namespace Internal diff --git a/dali/internal/update/manager/update-manager.h b/dali/internal/update/manager/update-manager.h index 99d7e72..d1f82be 100644 --- a/dali/internal/update/manager/update-manager.h +++ b/dali/internal/update/manager/update-manager.h @@ -581,6 +581,13 @@ public: void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel); /** + * Set a multisampling level value as texture output to the existing FrameBuffer + * @param[in] frameBuffer The FrameBuffer + * @param[in] multiSamplingLevel The level of multisampling + */ + void SetMultiSamplingLevelToFrameBuffer(Render::FrameBuffer* frameBuffer, uint8_t multiSamplingLevel); + + /** * This is called when the surface of the scene has been replaced. * @param[in] scene The scene. */ @@ -1426,6 +1433,17 @@ inline void AttachDepthStencilTextureToFrameBuffer(UpdateManager& manager, Rende new(slot) LocalType(&manager, &UpdateManager::AttachDepthStencilTextureToFrameBuffer, &frameBuffer, texture, mipmapLevel); } +inline void SetMultiSamplingLevelToFrameBuffer(UpdateManager& manager, Render::FrameBuffer& frameBuffer, uint8_t multiSamplingLevel) +{ + using LocalType = MessageValue2; + + // Reserve some memory inside the message queue + uint32_t* slot = manager.ReserveMessageSlot(sizeof(LocalType)); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new(slot) LocalType(&manager, &UpdateManager::SetMultiSamplingLevelToFrameBuffer, &frameBuffer, multiSamplingLevel); +} + inline void SetDepthIndicesMessage(UpdateManager& manager, OwnerPointer& nodeDepths) { using LocalType = MessageValue1>; -- 2.7.4