From 5446777162d766cb81c52643e40fe044070561ce Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 12 Apr 2023 18:39:33 +0100 Subject: [PATCH] Added max texture unit getter Change-Id: Ia9e0389efe75fdbe74bd09e79bfa70df2a7abb17 --- .../test-graphics-application.h | 7 +++- .../adaptor-framework/graphics-capabilities.cpp | 35 +++++++++++++++++ .../adaptor-framework/graphics-capabilities.h | 38 ++++++++++++++++++ dali/devel-api/file.list | 2 + dali/internal/adaptor/common/adaptor-impl.h | 11 +++++- dali/internal/graphics/common/graphics-interface.h | 7 +++- dali/internal/graphics/gles-impl/gles-context.cpp | 4 ++ .../graphics/gles-impl/gles-graphics-shader.cpp | 6 +-- dali/internal/graphics/gles/egl-graphics.h | 5 +++ dali/internal/graphics/gles/gl-implementation.h | 13 +++++++ .../system/common/configuration-manager.cpp | 45 +++++++++++++++++++++- .../internal/system/common/configuration-manager.h | 10 ++++- .../internal/system/common/environment-variables.h | 4 +- 13 files changed, 178 insertions(+), 9 deletions(-) create mode 100644 dali/devel-api/adaptor-framework/graphics-capabilities.cpp create mode 100644 dali/devel-api/adaptor-framework/graphics-capabilities.h diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-application.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-application.h index 66c9f7a..fbeecdf 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-application.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-application.h @@ -2,7 +2,7 @@ #define DALI_TEST_GRAPHICS_APPLICATION_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -179,6 +179,11 @@ public: return 32768u; } + uint32_t GetMaxCombinedTextureUnits() override + { + return 96; + } + /** * @return the maximum texture samples when we use multisampled texture */ diff --git a/dali/devel-api/adaptor-framework/graphics-capabilities.cpp b/dali/devel-api/adaptor-framework/graphics-capabilities.cpp new file mode 100644 index 0000000..7f79a0f --- /dev/null +++ b/dali/devel-api/adaptor-framework/graphics-capabilities.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace Dali::GraphicsCapabilities +{ +uint32_t GetMaxCombinedTextureUnits() +{ + Dali::Adaptor& adaptor = Adaptor::Get(); + Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor); + const Dali::Internal::Adaptor::ConfigurationManager* configurationManager = adaptorImpl.GetConfigurationManager(); + if(configurationManager) + { + return const_cast(configurationManager)->GetMaxCombinedTextureUnits(); + } + return 8; // Gles2 max. +} + +} // namespace Dali::GraphicsCapabilities diff --git a/dali/devel-api/adaptor-framework/graphics-capabilities.h b/dali/devel-api/adaptor-framework/graphics-capabilities.h new file mode 100644 index 0000000..a989829 --- /dev/null +++ b/dali/devel-api/adaptor-framework/graphics-capabilities.h @@ -0,0 +1,38 @@ +#ifndef DALI_DEVEL_API_ADAPTOR_GRAPHICS_CAPABILITIES_H +#define DALI_DEVEL_API_ADAPTOR_GRAPHICS_CAPABILITIES_H + +/* + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// INTERNAL INCLUDES +#include + +// EXTERNAL INCLUDES +#include + +namespace Dali::GraphicsCapabilities +{ +/** + * @brief Get the total number of combined texture units that can be used by + * all the shaders in a given program. + * + * @return the maximum number of texture units + */ +DALI_ADAPTOR_API uint32_t GetMaxCombinedTextureUnits(); + +} // namespace Dali::GraphicsCapabilities + +#endif //DALI_DEVEL_API_ADAPTOR_GRAPHICS_CAPABILITIES_H diff --git a/dali/devel-api/file.list b/dali/devel-api/file.list index 9199da3..8cf5583 100755 --- a/dali/devel-api/file.list +++ b/dali/devel-api/file.list @@ -27,6 +27,7 @@ SET( devel_api_src_files ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.cpp ${adaptor_devel_api_dir}/adaptor-framework/file-loader.cpp ${adaptor_devel_api_dir}/adaptor-framework/file-stream.cpp + ${adaptor_devel_api_dir}/adaptor-framework/graphics-capabilities.cpp ${adaptor_devel_api_dir}/adaptor-framework/image-loading.cpp ${adaptor_devel_api_dir}/adaptor-framework/input-method-context.cpp ${adaptor_devel_api_dir}/adaptor-framework/input-method-options.cpp @@ -77,6 +78,7 @@ SET( devel_api_adaptor_framework_header_files ${adaptor_devel_api_dir}/adaptor-framework/feedback-player.h ${adaptor_devel_api_dir}/adaptor-framework/file-loader.h ${adaptor_devel_api_dir}/adaptor-framework/file-stream.h + ${adaptor_devel_api_dir}/adaptor-framework/graphics-capabilities.h ${adaptor_devel_api_dir}/adaptor-framework/image-loader-input.h ${adaptor_devel_api_dir}/adaptor-framework/image-loader-plugin.h ${adaptor_devel_api_dir}/adaptor-framework/image-loading.h diff --git a/dali/internal/adaptor/common/adaptor-impl.h b/dali/internal/adaptor/common/adaptor-impl.h index 07f5df4..814fa5a 100644 --- a/dali/internal/adaptor/common/adaptor-impl.h +++ b/dali/internal/adaptor/common/adaptor-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_ADAPTOR_IMPL_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -514,6 +514,15 @@ public: //AdaptorInternalServices */ void GetWindowContainerInterface(WindowContainer& windows) override; + /** + * @brief Get the configuration manager + * @return The configuration manager, or null if it hasn't been created yet + */ + const ConfigurationManager* GetConfigurationManager() const + { + return mConfigurationManager.get(); + } + public: // Signals /** * @copydoc Dali::Adaptor::SignalResized diff --git a/dali/internal/graphics/common/graphics-interface.h b/dali/internal/graphics/common/graphics-interface.h index 53fa462..af632ac 100644 --- a/dali/internal/graphics/common/graphics-interface.h +++ b/dali/internal/graphics/common/graphics-interface.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_BASE_GRAPHICS_INTERFACE_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -167,6 +167,11 @@ public: virtual uint32_t GetMaxTextureSize() = 0; /** + * @return the maximum number of combined texture units + */ + virtual uint32_t GetMaxCombinedTextureUnits() = 0; + + /** * @return the maximum texture samples when we use multisampled texture */ virtual uint8_t GetMaxTextureSamples() = 0; diff --git a/dali/internal/graphics/gles-impl/gles-context.cpp b/dali/internal/graphics/gles-impl/gles-context.cpp index c6f0728..8cc468e 100644 --- a/dali/internal/graphics/gles-impl/gles-context.cpp +++ b/dali/internal/graphics/gles-impl/gles-context.cpp @@ -139,6 +139,10 @@ struct Context::Impl memset(&mGlStateCache.mBoundTextureId, 0, sizeof(mGlStateCache.mBoundTextureId)); mGlStateCache.mFrameBufferStateCache.Reset(); + + GLint maxTextures; + gl.GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextures); + DALI_LOG_RELEASE_INFO("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: %d\n", maxTextures); } /** diff --git a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp index 60f9a34..e8eb2c8 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -116,8 +116,8 @@ bool Shader::Compile() const char output[4096]; GLsizei size{0u}; gl->GetShaderInfoLog(shader, 4096, &size, output); - DALI_LOG_RELEASE_INFO("Code: %s\n", reinterpret_cast(GetCreateInfo().sourceData)); - DALI_LOG_RELEASE_INFO("Log: %s\n", output); + DALI_LOG_RENDER_INFO("Code: %s\n", reinterpret_cast(GetCreateInfo().sourceData)); + DALI_LOG_RENDER_INFO("Log: %s\n", output); gl->DeleteShader(shader); return false; } diff --git a/dali/internal/graphics/gles/egl-graphics.h b/dali/internal/graphics/gles/egl-graphics.h index 5d04448..3969432 100644 --- a/dali/internal/graphics/gles/egl-graphics.h +++ b/dali/internal/graphics/gles/egl-graphics.h @@ -188,6 +188,11 @@ public: return mGLES->GetMaxTextureSize(); } + uint32_t GetMaxCombinedTextureUnits() override + { + return mGLES->GetMaxCombinedTextureUnits(); + } + uint8_t GetMaxTextureSamples() override { return mGLES->GetMaxTextureSamples(); diff --git a/dali/internal/graphics/gles/gl-implementation.h b/dali/internal/graphics/gles/gl-implementation.h index 191a294..5dac669 100644 --- a/dali/internal/graphics/gles/gl-implementation.h +++ b/dali/internal/graphics/gles/gl-implementation.h @@ -82,6 +82,7 @@ public: : mGlExtensionSupportedCacheList(), mContextCreatedWaitCondition(), mMaxTextureSize(0), + mMaxCombinedTextureUnits(0), mMaxTextureSamples(0), mVertexShaderPrefix(""), mGlesVersion(INITIAL_GLES_VERSION), @@ -110,6 +111,7 @@ public: void ContextCreated() { glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); + glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &mMaxCombinedTextureUnits); // Since gles 2.0 didn't return well for GL_MAJOR_VERSION and GL_MINOR_VERSION, // Only change gles version for the device that support above gles 3.0. @@ -365,6 +367,16 @@ public: return mMaxTextureSize; } + int GetMaxCombinedTextureUnits() + { + ConditionalWait::ScopedLock lock(mContextCreatedWaitCondition); + if(!mIsContextCreated) + { + mContextCreatedWaitCondition.Wait(lock); + } + return mMaxCombinedTextureUnits; + } + int GetMaxTextureSamples() { ConditionalWait::ScopedLock lock(mContextCreatedWaitCondition); @@ -1703,6 +1715,7 @@ private: ConditionalWait mContextCreatedWaitCondition; GLint mMaxTextureSize; + GLint mMaxCombinedTextureUnits; GLint mMaxTextureSamples; std::string mShaderVersionPrefix; std::string mVertexShaderPrefix; diff --git a/dali/internal/system/common/configuration-manager.cpp b/dali/internal/system/common/configuration-manager.cpp index ff77416..9f42c21 100644 --- a/dali/internal/system/common/configuration-manager.cpp +++ b/dali/internal/system/common/configuration-manager.cpp @@ -50,6 +50,7 @@ ConfigurationManager::ConfigurationManager(std::string systemCachePath, Graphics mGraphics(graphics), mThreadController(threadController), mMaxTextureSize(0u), + mMaxCombinedTextureUnits(0u), mShaderLanguageVersion(0u), mIsMultipleWindowSupported(true), mIsAdvancedBlendEquationSupported(true), @@ -58,7 +59,8 @@ ConfigurationManager::ConfigurationManager(std::string systemCachePath, Graphics mIsMultipleWindowSupportedCached(false), mIsAdvancedBlendEquationSupportedCached(false), mIsMultisampledRenderToTextureSupportedCached(false), - mShaderLanguageVersionCached(false) + mShaderLanguageVersionCached(false), + mMaxCombinedTextureUnitsCached(false) { } @@ -92,6 +94,12 @@ void ConfigurationManager::RetrieveKeysFromConfigFile(const std::string& configF mMaxTextureSize = std::atoi(value.c_str()); mMaxTextureSizeCached = true; } + if(!mMaxCombinedTextureUnitsCached && name == DALI_ENV_MAX_COMBINED_TEXTURE_UNITS) + { + std::getline(subStream, value); + mMaxCombinedTextureUnits = std::atoi(value.c_str()); + mMaxCombinedTextureUnitsCached = true; + } else if(!mIsAdvancedBlendEquationSupportedCached && name == DALI_BLEND_EQUATION_ADVANCED_SUPPORT) { std::getline(subStream, value); @@ -154,6 +162,41 @@ uint32_t ConfigurationManager::GetMaxTextureSize() return mMaxTextureSize; } +uint32_t ConfigurationManager::GetMaxCombinedTextureUnits() +{ + if(!mMaxCombinedTextureUnitsCached) + { + RetrieveKeysFromConfigFile(mSystemCacheFilePath); + + if(!mMaxCombinedTextureUnitsCached) + { + if(!mGraphics->IsInitialized()) + { + // Wait until Graphics Subsystem is initialised, but this will happen once. + // This method blocks until the render thread has initialised the graphics. + mThreadController->WaitForGraphicsInitialization(); + } + + mMaxCombinedTextureUnits = mGraphics->GetMaxCombinedTextureUnits(); + mMaxCombinedTextureUnitsCached = true; + DALI_LOG_RENDER_INFO("MaxCombinedTextureUnits = %d\n", mMaxCombinedTextureUnits); + + Dali::FileStream configFile(mSystemCacheFilePath, Dali::FileStream::READ | Dali::FileStream::APPEND | Dali::FileStream::TEXT); + std::fstream& stream = dynamic_cast(configFile.GetStream()); + if(stream.is_open()) + { + stream << DALI_ENV_MAX_COMBINED_TEXTURE_UNITS << " " << mMaxCombinedTextureUnits << std::endl; + } + else + { + DALI_LOG_ERROR("Fail to open file : %s\n", mSystemCacheFilePath.c_str()); + } + } + } + + return mMaxCombinedTextureUnits; +} + uint32_t ConfigurationManager::GetShadingLanguageVersion() { if(!mShaderLanguageVersionCached) diff --git a/dali/internal/system/common/configuration-manager.h b/dali/internal/system/common/configuration-manager.h index 7fc767e..930a38b 100644 --- a/dali/internal/system/common/configuration-manager.h +++ b/dali/internal/system/common/configuration-manager.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_ENVIRONMENT_CONFIGURATION_MANAGER_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -63,6 +63,12 @@ public: uint32_t GetMaxTextureSize(); /** + * @brief Get the maximum number of combined texture units (across all shaders in program) + * @return the number of combined texture units + */ + uint32_t GetMaxCombinedTextureUnits(); + + /** * @brief Get the shader language version that the system supports * @return the shader language version. */ @@ -102,6 +108,7 @@ private: // Data GraphicsInterface* mGraphics; ///< Graphics interface ThreadController* mThreadController; ///< The thread controller unsigned int mMaxTextureSize; ///< The largest texture that the GL can handle + unsigned int mMaxCombinedTextureUnits; ///< The maximum number of combined texture units unsigned int mShaderLanguageVersion; ///< The shader language version that the system supports. bool mIsMultipleWindowSupported : 1; ///< Whether multiple window is supported by the GLES bool mIsAdvancedBlendEquationSupported : 1; ///< Whether blend equation advanced (extension) is supported by the GLES @@ -111,6 +118,7 @@ private: // Data bool mIsAdvancedBlendEquationSupportedCached : 1; ///< Whether we have checked the support of blend equation advanced (extension) bool mIsMultisampledRenderToTextureSupportedCached : 1; ///< Whether we have checked the support of multisampled render to texture (extension) bool mShaderLanguageVersionCached : 1; ///< Whether we have checked the shader language version + bool mMaxCombinedTextureUnitsCached : 1; ///< Whether we have checked the maximum number of combined texture units }; } // namespace Adaptor diff --git a/dali/internal/system/common/environment-variables.h b/dali/internal/system/common/environment-variables.h index 59329f0..5ec4398 100644 --- a/dali/internal/system/common/environment-variables.h +++ b/dali/internal/system/common/environment-variables.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_ADAPTOR_ENVIRONMENT_VARIABLES_H /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -123,6 +123,8 @@ namespace Adaptor #define DALI_ENV_MAX_TEXTURE_SIZE "DALI_MAX_TEXTURE_SIZE" +#define DALI_ENV_MAX_COMBINED_TEXTURE_UNITS "DALI_MAX_COMBINED_TEXTURE_UNITS" + #define DALI_RENDER_TO_FBO "DALI_RENDER_TO_FBO" #define DALI_ENV_DISABLE_DEPTH_BUFFER "DALI_DISABLE_DEPTH_BUFFER" -- 2.7.4