diff --git a/native/.clang-format b/native/.clang-format index 78f3c14637..9f238f2ae8 100644 --- a/native/.clang-format +++ b/native/.clang-format @@ -1,33 +1,18 @@ -BasedOnStyle: LLVM +--- -IndentWidth: 4 +BasedOnStyle: Google -BreakBeforeBraces: Attach +AccessModifierOffset: -4 +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: true +AlignConsecutiveDeclarations: true +AllowShortCaseLabelsOnASingleLine: true +ColumnLimit: 0 +ConstructorInitializerIndentWidth: 0 +IncludeBlocks: Preserve +IndentPPDirectives: BeforeHash +IndentWidth: 4 +SpacesBeforeTrailingComments: 1 -AllowShortIfStatementsOnASingleLine: true - -AllowShortLoopsOnASingleLine: true - -IndentCaseLabels: true - -ObjCBlockIndentWidth: 4 - -ObjCSpaceAfterProperty: true - -ColumnLimit: 0 - -AlignTrailingComments: true - -AllowShortCaseLabelsOnASingleLine: true -AllowAllConstructorInitializersOnNextLine: false - -AccessModifierOffset: -4 - -ConstructorInitializerIndentWidth: 0 -ConstructorInitializerAllOnOneLineOrOnePerLine: true - -AlignConsecutiveMacros: true -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true - -IndentPPDirectives: BeforeHash +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true diff --git a/native/.clang-tidy b/native/.clang-tidy index 53425b4002..8376196f46 100644 --- a/native/.clang-tidy +++ b/native/.clang-tidy @@ -1,81 +1,60 @@ -# Here is an explanation for why some of the checks are disabled: +--- +# Here are the reasons for disabled checks: # -# -modernize-use-trailing-return-type, -fuchsia-trailing-return: return a function call -# at the end of a function is normal usage. -# -# -readability-implicit-bool-conversion, -readability-implicit-bool-cast: if (_usage & BufferUsageBit::VERTEX) -# is normal usage -# -# -cppcoreguidelines-pro-type-vararg: use it in macro define, such as Log functions. May use -# template instead in future. -# -# -cppcoreguidelines-pro-type-static-cast-downcast: sub class of gfx device should use static_cast() to -# cast to derived class. -# -# -readability-function-cognitive-complexity: it will limit function size. -# -# -cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-bounds-array-to-pointer-decay: -# JS pass data by pointer, so it is common to use pointer arithmetic. +# -misc-non-private-member-variables-in-classes +# -modernize-avoid-c-arrays +# Legacy reasons # +# -modernize-concat-nested-namespaces: More flexible not concated +# -modernize-use-nodiscard: No C++17 specific rules for now +# -modernize-use-trailing-return-type: It is acceptable to return a function call at the end of a function +# -readability-braces-around-statements: Simple single statement can be without braces +# -readability-function-cognitive-complexity: This will limit function size +# -readability-implicit-bool-conversion: We omit explicit bool conversion for brevity +# -readability-implicit-bool-cast: We omit explicit bool conversion for brevity +# -readability-magic-numbers: There will be lots of constants + Checks: > - -*, - readability-identifier-*, - modernize-use-override, - modernize-use-auto, - modernize-use-emplace, - modernize-use-equals-delete, - modernize-use-equals-default, - modernize-use-noexcept, - modernize-use-nullptr, - modernize-redundant-void-arg, - modernize-raw-string-literal, - modernize-pass-by-value, - modernize-loop-convert, - modernize-avoid-c-arrays, - modernize-use-using, - google-explicit-constructor + -*, + bugprone-*, + google-*, + misc-*, + modernize-*, + performance-*, + portability-*, + readability-*, + + -misc-non-private-member-variables-in-classes, + -modernize-avoid-c-arrays, + + -modernize-concat-nested-namespaces, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -readability-braces-around-statements, + -readability-function-cognitive-complexity, + -readability-implicit-bool-conversion, + -readability-implicit-bool-cast, + -readability-magic-numbers, CheckOptions: -################## readability identifier naming ################################ -# class - - key: readability-identifier-naming.ClassCase - value: CamelCase - - key: readability-identifier-naming.ClassMemberCase - value: camelBack - - key: readability-identifier-naming.ClassMemberPrefix - value: _ - - key: readability-identifier-naming.ClassMethodCase - value: camelBack - - key: readability-identifier-naming.ClassConstantCase - value: UPPER_CASE - - key: readability-identifier-naming.ClassConstantCasePrefix - value: _ -# enum - - key: readability-identifier-naming.EnumCase - value: CamelCase - - key: readability-identifier-naming.ScopedEnumConstantCase - value: UPPER_CASE - - key: readability-identifier-naming.EnumConstantCase - value: UPPER_CASE -# others - - key: readability-identifier-naming.FunctionCase - value: camelBack - - key: readability-identifier-naming.ConstantCase - value: UPPER_CASE - - key: readability-identifier-naming.GlobalConstantCase - value: UPPER_CASE - - key: readability-identifier-naming.LocalConstantCase - value: camelBack - - key: readability-identifier-naming.LocalVariableCase - value: camelBack - - key: readability-identifier-naming.MacroDefinitionCase - value: UPPER_CASE - - key: readability-identifier-naming.ParameterCase - value: camelBack - - key: readability-identifier-naming.StaticConstantCase - value: UPPER_CASE - - key: readability-identifier-naming.VariableCase - value: camelBack - - key: readability-identifier-naming.StructCase - value: CamelBack + - { key: readability-identifier-naming.NamespaceCase, value: lower_case } + - { key: readability-identifier-naming.StructCase, value: CamelCase } + - { key: readability-identifier-naming.ClassCase, value: CamelCase } + - { key: readability-identifier-naming.ClassMethodCase, value: camelBack } + - { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.ClassMemberCase, value: camelBack } + - { key: readability-identifier-naming.ProtectedMemberPrefix, value: _ } + - { key: readability-identifier-naming.PrivateMemberPrefix, value: _ } + - { key: readability-identifier-naming.EnumCase, value: CamelCase } + - { key: readability-identifier-naming.ScopedEnumConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } + + - { key: readability-identifier-naming.FunctionCase, value: camelBack } + - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.LocalConstantCase, value: camelBack } + - { key: readability-identifier-naming.LocalVariableCase, value: camelBack } + - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } + - { key: readability-identifier-naming.ParameterCase, value: camelBack } + - { key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE } + - { key: readability-identifier-naming.VariableCase, value: camelBack } diff --git a/native/.github/workflows/clangtidy-android.yml b/native/.github/workflows/clangtidy-android.yml index 1dd1790263..e79b877892 100644 --- a/native/.github/workflows/clangtidy-android.yml +++ b/native/.github/workflows/clangtidy-android.yml @@ -46,9 +46,7 @@ jobs: EXT_VERSION=`grep version external/config.json |awk -F'"' '{print $4}'` rm external/config.json git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external external - echo -e "cmake_minimum_required(VERSION 3.8)\nproject(engine_native CXX)\nenable_language(C ASM)" | cat - CMakeLists.txt > tmp.txt - mv tmp.txt CMakeLists.txt - cmake -Bbuild -DCC_USE_GLES2=ON -DCC_USE_VULKAN=ON -DCC_USE_GLES3=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" -DANDROID_PLATFORM=android-21 -G"Unix Makefiles" + utils/generate_compile_commands_android.sh - name: Generate clang-fix.yaml shell: bash @@ -59,7 +57,7 @@ jobs: if [[ "$FILTERED-xxx" == "-xxx" ]]; then echo "no source files match" else - clang-tidy-11 --format-style=file -p ./build --export-fixes=clang-fixes.yaml $FILTERED + clang-tidy-11 --format-style=file --export-fixes=clang-fixes.yaml $FILTERED fi - name: clang-tidy-action uses: PatriceJiang/clang-tidy-action@master diff --git a/native/.github/workflows/filter_by_cdb.js b/native/.github/workflows/filter_by_cdb.js index 87962c7df9..2e8e358847 100644 --- a/native/.github/workflows/filter_by_cdb.js +++ b/native/.github/workflows/filter_by_cdb.js @@ -11,13 +11,12 @@ const cdbFile = path.join(__dirname, '../../build/compile_commands.json'); if (fs.existsSync(cdbFile)) { const db = JSON.parse(fs.readFileSync(cdbFile, { encoding: 'utf8' })); for (let f of ARGS) { - for (let t of db) { - if (t.file.endsWith(f)) { - result.push(f); - } + const name = f.endsWith('.h') ? f.slice(0, -2) : f; // ignore .h extension name + if (db.some((info) => info.file.includes(name))) { + result.push(f); } } - console.log(result.join(" ")); + console.log(result.join(' ')); } else { - console.log(ARGS.join(" ")); -} \ No newline at end of file + console.log(ARGS.join(' ')); +} diff --git a/native/.gitignore b/native/.gitignore index 98a616f708..e10d3055a6 100644 --- a/native/.gitignore +++ b/native/.gitignore @@ -77,9 +77,6 @@ xcschememanagement.plist xcuserdata/ DerivedData/ -# Ignore files built by AppCode -.idea/ - # Ignore files built by bada .Simulator-Debug/ .Target-Debug/ @@ -159,6 +156,10 @@ tests/cpp-tests/Resources/audio # generated by vscode .vscode/ +# generated by Clion +.idea/ +cmake-build* +compile_commands.json # generated by "gulp gen-simulator" /tools/simulator/runtime/win32 diff --git a/native/.vscode/c_cpp_properties.json b/native/.vscode/c_cpp_properties.json new file mode 100644 index 0000000000..13969a5434 --- /dev/null +++ b/native/.vscode/c_cpp_properties.json @@ -0,0 +1,23 @@ +{ + "configurations": [ + { + "name": "Clang-Android", + "includePath": [ + ".", + "cocos", + "cocos/renderer", + "cocos/platform", + "cocos/platform/ios", + "cocos/editor-support", + "cocos/bindings/jswrapper", + "external/sources", + "external/sources/khronos", + "external/win32/include", + "external/win32/include/glslang", + "external/win32/include/v8" + ], + "compileCommands": "compile_commands.json" + } + ], + "version": 4 +} diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 0009393649..a30c5e7b97 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1021,9 +1021,10 @@ if(CC_USE_VULKAN) cocos/renderer/gfx-vulkan/VKTexture.h NO_WERROR cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp cocos/renderer/gfx-vulkan/VKTextureBarrier.h + NO_WERROR cocos/renderer/gfx-vulkan/VKUtils.cpp cocos/renderer/gfx-vulkan/VKUtils.h - cocos/renderer/gfx-vulkan/volk.h NO_WERROR cocos/renderer/gfx-vulkan/volk.c + cocos/renderer/gfx-vulkan/volk.h ) endif() diff --git a/native/README.md b/native/README.md index eb7a6cf499..426f901cad 100644 --- a/native/README.md +++ b/native/README.md @@ -8,7 +8,7 @@ It is the native backend of [Cocos Creator](https://www.cocos.com/en/creator). I Coding format and coding style --------------------------------- -The coding format file is `.clang-format`, and the coding style fomat file is `.clang-tidy`. Please use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format the codes and use [clang-tidy](http://clang.llvm.org/extra/index.html) to fix the coding style before commiting codes. +The coding format file is `.clang-format`, and the coding style fomat file is `.clang-tidy`. Please use [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format the codes and use [clang-tidy](http://clang.llvm.org/extra/index.html) to fix the coding style before commiting codes. See the [linter auto-fix guide](docs/LINTER_AUTOFIX_GUIDE.md) for more information. Documentations -------------------------------- diff --git a/native/cocos/base/Agent.h b/native/cocos/base/Agent.h index 6382837d93..f7d7f2eb40 100644 --- a/native/cocos/base/Agent.h +++ b/native/cocos/base/Agent.h @@ -25,6 +25,7 @@ #pragma once +#include "Macros.h" #include namespace cc { @@ -34,7 +35,7 @@ class CC_DLL Agent : public Actor { public: Agent() noexcept = delete; - Agent(Actor *const actor) noexcept + explicit Agent(Actor *const actor) noexcept : Actor(), _actor(actor) {} ~Agent() override {} diff --git a/native/cocos/base/CachedArray.h b/native/cocos/base/CachedArray.h index 0c4833efb7..6d2448b377 100755 --- a/native/cocos/base/CachedArray.h +++ b/native/cocos/base/CachedArray.h @@ -23,22 +23,24 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_KERNEL_CACHED_ARRAY_H_ -#define CC_CORE_KERNEL_CACHED_ARRAY_H_ +#pragma once + +#include "base/Object.h" +#include "base/TypeDef.h" namespace cc { template class CachedArray : public Object { public: - CachedArray(uint size = 1u) { + explicit CachedArray(uint size = 1U) { _size = 0; _capacity = std::max(size, 1u); _array = CC_NEW_ARRAY(T, _capacity); } // The rule of five applies here - ~CachedArray() { + ~CachedArray() override { CC_SAFE_DELETE_ARRAY(_array); } @@ -47,6 +49,7 @@ public: memcpy(_array, other._array, _size * sizeof(T)); } + // NOLINTNEXTLINE(bugprone-unhandled-self-assignment) false positive CachedArray &operator=(const CachedArray &other) noexcept { if (this != &other) { CC_DELETE_ARRAY(_array); @@ -59,7 +62,7 @@ public: } CachedArray(CachedArray &&other) - : _size(other._size), _capacity(other._capacity), _array(other._array) { + noexcept : _size(other._size), _capacity(other._capacity), _array(other._array) { other._size = 0; other._capacity = 0; other._array = nullptr; @@ -161,5 +164,3 @@ private: }; } // namespace cc - -#endif // CC_CORE_KERNEL_CACHED_ARRAY_H_ diff --git a/native/cocos/base/Object.h b/native/cocos/base/Object.h index 22edd1ba1e..bef6411e1e 100755 --- a/native/cocos/base/Object.h +++ b/native/cocos/base/Object.h @@ -25,8 +25,7 @@ #pragma once -#include "memory/AllocatedObj.h" -#include "memory/MemDef.h" +#include "memory/Memory.h" namespace cc { diff --git a/native/cocos/base/Utils.h b/native/cocos/base/Utils.h index acec4f86e1..1f1c68e724 100644 --- a/native/cocos/base/Utils.h +++ b/native/cocos/base/Utils.h @@ -32,40 +32,46 @@ #include #include -/** @file ccUtils.h -Misc free functions -*/ - namespace cc { - -/* -utils::nextPOT function is licensed under the same license that is used in Texture2D.m. -*/ - -/** Returns the Next Power of Two value. - -Examples: -- If "value" is 15, it will return 16. -- If "value" is 16, it will return 16. -- If "value" is 17, it will return 32. -@param value The value to get next power of two. -@return Returns the next power of two value. -@since v0.99.5 -*/ - namespace utils { CC_DLL std::string getStacktrace(uint skip = 0, uint maxDepth = UINT_MAX); -CC_DLL int nextPOT(int x); -/** Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof. - * Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal part and contain - * several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. This function is used to fix this bug. - * @param str The string be to converted to double. - * @return Returns converted value of a string. - */ +/** + * Returns the Next Power of Two value. + * Examples: + * - If "value" is 15, it will return 16. + * - If "value" is 16, it will return 16. + * - If "value" is 17, it will return 32. + * @param value The value to get next power of two. + * @return Returns the next power of two value. + * @since v0.99.5 +*/ +CC_DLL uint nextPOT(uint x); + +/** + * Same to ::atof, but strip the string, remain 7 numbers after '.' before call atof. + * Why we need this? Because in android c++_static, atof ( and std::atof ) is unsupported for numbers have long decimal part and contain + * several numbers can approximate to 1 ( like 90.099998474121094 ), it will return inf. This function is used to fix this bug. + * @param str The string be to converted to double. + * @return Returns converted value of a string. + */ CC_DLL double atof(const char *str); -} // namespace utils +template +char (*countOfHelper(T (&array)[Size]))[Size]; +#define COUNTOF(array) (sizeof(*countOfHelper(array)) + 0) + +template +uint toUint(T value) { + static_assert(std::is_arithmetic::value, "T must be numeric"); + + CCASSERT(static_cast(value) <= static_cast(std::numeric_limits::max()), + "value is too big to be converted to uint"); + + return static_cast(value); +} + +} // namespace utils } // namespace cc diff --git a/native/cocos/base/memory/AllocatedObj.h b/native/cocos/base/memory/AllocatedObj.h index 2b1b3eec8b..e56f5e7887 100755 --- a/native/cocos/base/memory/AllocatedObj.h +++ b/native/cocos/base/memory/AllocatedObj.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_ALLOCATED_OBJ_H_ -#define CC_CORE_ALLOCATED_OBJ_H_ +#pragma once #include "../Macros.h" @@ -47,8 +46,8 @@ namespace cc { template class CC_DLL AllocatedObject { public: - explicit AllocatedObject() {} - ~AllocatedObject() {} + explicit AllocatedObject() = default; + virtual ~AllocatedObject() = default; // operator new, with debug line info void *operator new(size_t sz, const char *file, int line, const char *func) { @@ -81,12 +80,12 @@ public: } // Corresponding operator for placement delete (second param same as the first) - void operator delete(void *ptr, void *) { + void operator delete(void *ptr, void * /*unused*/) { Alloc::DeallocateBytes(ptr); } // only called if there is an exception in corresponding 'new' - void operator delete(void *ptr, const char *, int, const char *) { + void operator delete(void *ptr, const char * /*unused*/, int /*unused*/, const char * /*unused*/) { Alloc::DeallocateBytes(ptr); } @@ -94,11 +93,9 @@ public: Alloc::DeallocateBytes(ptr); } - void operator delete[](void *ptr, const char *, int, const char *) { + void operator delete[](void *ptr, const char * /*unused*/, int /*unused*/, const char * /*unused*/) { Alloc::DeallocateBytes(ptr); } }; } // namespace cc - -#endif // CC_CORE_ALLOCATED_OBJ_H_ diff --git a/native/cocos/base/threading/ThreadSafeLinearAllocator.cpp b/native/cocos/base/threading/ThreadSafeLinearAllocator.cpp index f2a61a383e..a367d771b9 100644 --- a/native/cocos/base/threading/ThreadSafeLinearAllocator.cpp +++ b/native/cocos/base/threading/ThreadSafeLinearAllocator.cpp @@ -28,7 +28,7 @@ namespace cc { -ThreadSafeLinearAllocator::ThreadSafeLinearAllocator(uint32_t const size) noexcept +ThreadSafeLinearAllocator::ThreadSafeLinearAllocator(uint32_t size) noexcept : _capacity(size) { _buffer = malloc(size); } @@ -37,7 +37,7 @@ ThreadSafeLinearAllocator::~ThreadSafeLinearAllocator() { free(_buffer); } -void *ThreadSafeLinearAllocator::allocate(size_t const size, size_t const alignment) noexcept { +void *ThreadSafeLinearAllocator::allocate(size_t size, size_t alignment) noexcept { if (size == 0) { return nullptr; } @@ -51,11 +51,10 @@ void *ThreadSafeLinearAllocator::allocate(size_t const size, size_t const alignm allocatedMemory = acl::align_to(acl::add_offset_to_ptr(_buffer, oldUsedSize), alignment); newUsedSize = reinterpret_cast(allocatedMemory) - reinterpret_cast(_buffer) + size; - if (newUsedSize > _capacity) // overflows - { - return nullptr; + if (newUsedSize > _capacity) { + return nullptr; // overflows } - } while (!_usedSize.compare_exchange_weak(oldUsedSize, static_cast(newUsedSize), std::memory_order_relaxed, std::memory_order_relaxed)); // 不可能存在ABA 不处理 + } while (!_usedSize.compare_exchange_weak(oldUsedSize, static_cast(newUsedSize), std::memory_order_relaxed, std::memory_order_relaxed)); // no ABA possible return allocatedMemory; } diff --git a/native/cocos/base/threading/ThreadSafeLinearAllocator.h b/native/cocos/base/threading/ThreadSafeLinearAllocator.h index 42a6ef5b02..ac89bbfb7f 100644 --- a/native/cocos/base/threading/ThreadSafeLinearAllocator.h +++ b/native/cocos/base/threading/ThreadSafeLinearAllocator.h @@ -33,14 +33,14 @@ namespace cc { class alignas(16) ThreadSafeLinearAllocator final { public: - explicit ThreadSafeLinearAllocator(uint32_t const size) noexcept; + explicit ThreadSafeLinearAllocator(uint32_t size) noexcept; ~ThreadSafeLinearAllocator(); ThreadSafeLinearAllocator(ThreadSafeLinearAllocator const &) = delete; ThreadSafeLinearAllocator(ThreadSafeLinearAllocator &&) = delete; ThreadSafeLinearAllocator &operator=(ThreadSafeLinearAllocator const &) = delete; ThreadSafeLinearAllocator &operator=(ThreadSafeLinearAllocator &&) = delete; - void *allocate(size_t const size, size_t const alignment) noexcept; + void *allocate(size_t size, size_t alignment) noexcept; inline void * getBuffer() const noexcept { return _buffer; } inline uint32_t getCapacity() const noexcept { return _capacity; } diff --git a/native/cocos/bindings/dop/BufferPool.cpp b/native/cocos/bindings/dop/BufferPool.cpp index 3e9b4ee553..78057be3c9 100644 --- a/native/cocos/bindings/dop/BufferPool.cpp +++ b/native/cocos/bindings/dop/BufferPool.cpp @@ -27,7 +27,7 @@ #include "base/Macros.h" #include "base/memory/Memory.h" -using namespace se; +namespace se { cc::map BufferPool::_poolMap; @@ -52,7 +52,7 @@ BufferPool::~BufferPool() { } Object *BufferPool::allocateNewChunk() { - Object *jsObj = _allocator.alloc((uint)_chunks.size(), _bytesPerChunk); + Object *jsObj = _allocator.alloc(static_cast(_chunks.size()), _bytesPerChunk); uint8_t *realPtr = nullptr; size_t len = 0; @@ -61,3 +61,5 @@ Object *BufferPool::allocateNewChunk() { return jsObj; } + +} // namespace se diff --git a/native/cocos/platform/Image.cpp b/native/cocos/platform/Image.cpp index a486c98741..a66e52a6f2 100644 --- a/native/cocos/platform/Image.cpp +++ b/native/cocos/platform/Image.cpp @@ -26,17 +26,17 @@ ****************************************************************************/ #include "Image.h" -#include -#include -#include #include "base/Config.h" // CC_USE_JPEG, CC_USE_WEBP +#include +#include +#include #if CC_USE_JPEG #include "jpeg/jpeglib.h" #endif // CC_USE_JPEG +#include "base/CoreStd.h" #include "base/Data.h" #include "base/Utils.h" -#include "base/CoreStd.h" #include "gfx-base/GFXDef.h" extern "C" { @@ -54,8 +54,8 @@ extern "C" { #include "webp/decode.h" #endif // CC_USE_WEBP -#include "platform/FileUtils.h" #include "base/ZipUtils.h" +#include "platform/FileUtils.h" #if (CC_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/FileUtils-android.h" #endif @@ -68,22 +68,22 @@ namespace cc { //struct and data for pvr structure namespace { -static const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff; +const int PVR_TEXTURE_FLAG_TYPE_MASK = 0xff; // Values taken from PVRTexture.h from http://www.imgtec.com enum class PVR2TextureFlag { - Mipmap = (1 << 8), // has mip map levels - Twiddle = (1 << 9), // is twiddled - Bumpmap = (1 << 10), // has normals encoded for a bump map - Tiling = (1 << 11), // is bordered for tiled pvr - Cubemap = (1 << 12), // is a cubemap/skybox - FalseMipCol = (1 << 13), // are there false colored MIP levels - Volume = (1 << 14), // is this a volume texture - Alpha = (1 << 15), // v2.1 is there transparency info in the texture - VerticalFlip = (1 << 16), // v2.1 is the texture vertically flipped + MIPMAP = (1 << 8), // has mip map levels + TWIDDLE = (1 << 9), // is twiddled + BUMPMAP = (1 << 10), // has normals encoded for a bump map + TILING = (1 << 11), // is bordered for tiled pvr + CUBEMAP = (1 << 12), // is a cubemap/skybox + FALSE_MIP_COL = (1 << 13), // are there false colored MIP levels + VOLUME = (1 << 14), // is this a volume texture + ALPHA = (1 << 15), // v2.1 is there transparency info in the texture + VERTICAL_FLIP = (1 << 16), // v2.1 is the texture vertically flipped }; -static const char gPVRTexIdentifier[5] = "PVR!"; +const char G_PVR_TEX_IDENTIFIER[5] = "PVR!"; // v2 enum class PVR2TexturePixelFormat : unsigned char { @@ -103,99 +103,97 @@ enum class PVR2TexturePixelFormat : unsigned char { // v3 enum class PVR3TexturePixelFormat : uint64_t { - PVRTC2BPP_RGB = 0ULL, - PVRTC2BPP_RGBA = 1ULL, - PVRTC4BPP_RGB = 2ULL, - PVRTC4BPP_RGBA = 3ULL, - PVRTC2_2BPP_RGBA = 4ULL, - PVRTC2_4BPP_RGBA = 5ULL, - ETC1 = 6ULL, - DXT1 = 7ULL, - DXT2 = 8ULL, - DXT3 = 9ULL, - DXT4 = 10ULL, - DXT5 = 11ULL, - BC1 = 7ULL, - BC2 = 9ULL, - BC3 = 11ULL, - BC4 = 12ULL, - BC5 = 13ULL, - BC6 = 14ULL, - BC7 = 15ULL, - UYVY = 16ULL, - YUY2 = 17ULL, - BW1bpp = 18ULL, - R9G9B9E5 = 19ULL, - RGBG8888 = 20ULL, - GRGB8888 = 21ULL, - ETC2_RGB = 22ULL, - ETC2_RGBA = 23ULL, - ETC2_RGBA1 = 24ULL, - EAC_R11_Unsigned = 25ULL, - EAC_R11_Signed = 26ULL, - EAC_RG11_Unsigned = 27ULL, - EAC_RG11_Signed = 28ULL, + PVRTC2BPP_RGB = 0ULL, + PVRTC2BPP_RGBA = 1ULL, + PVRTC4BPP_RGB = 2ULL, + PVRTC4BPP_RGBA = 3ULL, + PVRTC2_2BPP_RGBA = 4ULL, + PVRTC2_4BPP_RGBA = 5ULL, + ETC1 = 6ULL, + DXT1 = 7ULL, + DXT2 = 8ULL, + DXT3 = 9ULL, + DXT4 = 10ULL, + DXT5 = 11ULL, + BC1 = 7ULL, + BC2 = 9ULL, + BC3 = 11ULL, + BC4 = 12ULL, + BC5 = 13ULL, + BC6 = 14ULL, + BC7 = 15ULL, + UYVY = 16ULL, + YUY2 = 17ULL, + B_W1BPP = 18ULL, + R9G9B9E5 = 19ULL, + RGBG8888 = 20ULL, + GRGB8888 = 21ULL, + ETC2_RGB = 22ULL, + ETC2_RGBA = 23ULL, + ETC2_RGBA1 = 24ULL, + EAC_R11_UNSIGNED = 25ULL, + EAC_R11_SIGNED = 26ULL, + EAC_R_G11_UNSIGNED = 27ULL, + EAC_R_G11_SIGNED = 28ULL, BGRA8888 = 0x0808080861726762ULL, RGBA8888 = 0x0808080861626772ULL, RGBA4444 = 0x0404040461626772ULL, RGBA5551 = 0x0105050561626772ULL, - RGB565 = 0x0005060500626772ULL, - RGB888 = 0x0008080800626772ULL, - A8 = 0x0000000800000061ULL, - L8 = 0x000000080000006cULL, - LA88 = 0x000008080000616cULL, + RGB565 = 0x0005060500626772ULL, + RGB888 = 0x0008080800626772ULL, + A8 = 0x0000000800000061ULL, + L8 = 0x000000080000006cULL, + LA88 = 0x000008080000616cULL, }; // v2 -typedef const std::map _pixel2_formathash; +using _pixel2_formathash = const std::map; -static const _pixel2_formathash::value_type v2_pixel_formathash_value[] = - { - _pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, gfx::Format::BGRA8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, gfx::Format::RGBA8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, gfx::Format::RGBA4), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, gfx::Format::RGB5A1), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, gfx::Format::R5G6B5), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, gfx::Format::RGB8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, gfx::Format::A8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, gfx::Format::L8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, gfx::Format::LA8), +const _pixel2_formathash::value_type V2_PIXEL_FORMATHASH_VALUE[] = { + _pixel2_formathash::value_type(PVR2TexturePixelFormat::BGRA8888, gfx::Format::BGRA8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA8888, gfx::Format::RGBA8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA4444, gfx::Format::RGBA4), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGBA5551, gfx::Format::RGB5A1), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB565, gfx::Format::R5G6B5), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::RGB888, gfx::Format::RGB8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::A8, gfx::Format::A8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::I8, gfx::Format::L8), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::AI88, gfx::Format::LA8), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, gfx::Format::PVRTC_RGBA2), - _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, gfx::Format::PVRTC_RGBA4), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC2BPP_RGBA, gfx::Format::PVRTC_RGBA2), + _pixel2_formathash::value_type(PVR2TexturePixelFormat::PVRTC4BPP_RGBA, gfx::Format::PVRTC_RGBA4), }; -static const int PVR2_MAX_TABLE_ELEMENTS = sizeof(v2_pixel_formathash_value) / sizeof(v2_pixel_formathash_value[0]); -static const _pixel2_formathash v2_pixel_formathash(v2_pixel_formathash_value, v2_pixel_formathash_value + PVR2_MAX_TABLE_ELEMENTS); +const int PVR2_MAX_TABLE_ELEMENTS = sizeof(V2_PIXEL_FORMATHASH_VALUE) / sizeof(V2_PIXEL_FORMATHASH_VALUE[0]); +const _pixel2_formathash V2_PIXEL_FORMATHASH(V2_PIXEL_FORMATHASH_VALUE, V2_PIXEL_FORMATHASH_VALUE + PVR2_MAX_TABLE_ELEMENTS); // v3 -typedef const std::map _pixel3_formathash; -static _pixel3_formathash::value_type v3_pixel_formathash_value[] = - { - _pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, gfx::Format::BGRA8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, gfx::Format::RGBA8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, gfx::Format::RGBA4), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, gfx::Format::RGB5A1), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, gfx::Format::R5G6B5), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, gfx::Format::RGB8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, gfx::Format::A8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, gfx::Format::L8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, gfx::Format::LA8), +using _pixel3_formathash = const std::map; +_pixel3_formathash::value_type v3PixelFormathashValue[] = { + _pixel3_formathash::value_type(PVR3TexturePixelFormat::BGRA8888, gfx::Format::BGRA8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA8888, gfx::Format::RGBA8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA4444, gfx::Format::RGBA4), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGBA5551, gfx::Format::RGB5A1), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB565, gfx::Format::R5G6B5), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::RGB888, gfx::Format::RGB8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::A8, gfx::Format::A8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::L8, gfx::Format::L8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::LA88, gfx::Format::LA8), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, gfx::Format::PVRTC_RGB2), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, gfx::Format::PVRTC_RGBA2), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, gfx::Format::PVRTC_RGB4), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, gfx::Format::PVRTC_RGBA4), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGB, gfx::Format::PVRTC_RGB2), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC2BPP_RGBA, gfx::Format::PVRTC_RGBA2), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGB, gfx::Format::PVRTC_RGB4), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::PVRTC4BPP_RGBA, gfx::Format::PVRTC_RGBA4), - _pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, gfx::Format::ETC_RGB8), + _pixel3_formathash::value_type(PVR3TexturePixelFormat::ETC1, gfx::Format::ETC_RGB8), }; -static const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3_pixel_formathash_value) / sizeof(v3_pixel_formathash_value[0]); +const int PVR3_MAX_TABLE_ELEMENTS = sizeof(v3PixelFormathashValue) / sizeof(v3PixelFormathashValue[0]); -static const _pixel3_formathash v3_pixel_formathash(v3_pixel_formathash_value, v3_pixel_formathash_value + PVR3_MAX_TABLE_ELEMENTS); +const _pixel3_formathash V3_PIXEL_FORMATHASH(v3PixelFormathashValue, v3PixelFormathashValue + PVR3_MAX_TABLE_ELEMENTS); -typedef struct _PVRTexHeader { +using PVRv2TexHeader = struct PvrTexHeader { unsigned int headerLength; unsigned int height; unsigned int width; @@ -209,13 +207,12 @@ typedef struct _PVRTexHeader { unsigned int bitmaskAlpha; unsigned int pvrTag; unsigned int numSurfs; -} PVRv2TexHeader; +}; #ifdef _MSC_VER #pragma pack(push, 1) #endif -typedef struct -{ +using PVRv3TexHeader = struct { uint32_t version; uint32_t flags; uint64_t pixelFormat; @@ -229,31 +226,30 @@ typedef struct uint32_t numberOfMipmaps; uint32_t metadataLength; #ifdef _MSC_VER -} PVRv3TexHeader; +}; #pragma pack(pop) #else -} __attribute__((packed)) PVRv3TexHeader; +} __attribute__((packed)); #endif } // namespace //pvr structure end namespace { -typedef struct -{ +using tImageSource = struct { const unsigned char *data; - ssize_t size; - int offset; -} tImageSource; + ssize_t size; + int offset; +}; #ifdef CC_USE_PNG -static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t length) { - tImageSource *isource = (tImageSource *)png_get_io_ptr(png_ptr); +void pngReadCallback(png_structp pngPtr, png_bytep data, png_size_t length) { + auto *isource = static_cast(png_get_io_ptr(pngPtr)); - if ((int)(isource->offset + length) <= isource->size) { + if (static_cast(isource->offset + length) <= isource->size) { memcpy(data, isource->data + isource->offset, length); isource->offset += length; } else { - png_error(png_ptr, "pngReaderCallback failed"); + png_error(pngPtr, "pngReaderCallback failed"); } } #endif //CC_USE_PNG @@ -292,7 +288,7 @@ bool Image::initWithImageData(const unsigned char *data, ssize_t dataLen) { CC_BREAK_IF(!data || dataLen <= 0); unsigned char *unpackedData = nullptr; - ssize_t unpackedLen = 0; + ssize_t unpackedLen = 0; //detect and unzip the compress file if (ZipUtils::isCCZBuffer(data, dataLen)) { @@ -301,7 +297,7 @@ bool Image::initWithImageData(const unsigned char *data, ssize_t dataLen) { unpackedLen = ZipUtils::inflateMemory(const_cast(data), dataLen, &unpackedData); } else { unpackedData = const_cast(data); - unpackedLen = dataLen; + unpackedLen = dataLen; } _fileType = detectFormat(unpackedData, unpackedLen); @@ -335,7 +331,7 @@ bool Image::initWithImageData(const unsigned char *data, ssize_t dataLen) { if (unpackedData != data) { free(unpackedData); } - } while (0); + } while (false); return ret; } @@ -350,16 +346,16 @@ bool Image::isPng(const unsigned char *data, ssize_t dataLen) { return memcmp(PNG_SIGNATURE, data, sizeof(PNG_SIGNATURE)) == 0; } -bool Image::isEtc(const unsigned char *data, ssize_t dataLen) { - return etc1_pkm_is_valid((etc1_byte *)data) ? true : false; +bool Image::isEtc(const unsigned char *data, ssize_t /*dataLen*/) { + return etc1_pkm_is_valid(const_cast(data)) != 0; } -bool Image::isEtc2(const unsigned char *data, ssize_t dataLen) { - return etc2_pkm_is_valid((etc2_byte *)data) ? true : false; +bool Image::isEtc2(const unsigned char *data, ssize_t /*dataLen*/) { + return etc2_pkm_is_valid(const_cast(data)) != 0; } -bool Image::isASTC(const unsigned char *data, ssize_t dataLen) { - return astcIsValid((astc_byte *)data) ? true : false; +bool Image::isASTC(const unsigned char *data, ssize_t /*dataLen*/) { + return astcIsValid(const_cast(data)); } bool Image::isJpg(const unsigned char *data, ssize_t dataLen) { @@ -377,10 +373,10 @@ bool Image::isWebp(const unsigned char *data, ssize_t dataLen) { return false; } - static const char *WEBP_RIFF = "RIFF"; - static const char *WEBP_WEBP = "WEBP"; + static const char *webpRiff = "RIFF"; + static const char *webpWebp = "WEBP"; - return memcmp(data, WEBP_RIFF, 4) == 0 && memcmp(static_cast(data) + 8, WEBP_WEBP, 4) == 0; + return memcmp(data, webpRiff, 4) == 0 && memcmp(static_cast(data) + 8, webpWebp, 4) == 0; } bool Image::isPvr(const unsigned char *data, ssize_t dataLen) { @@ -388,122 +384,109 @@ bool Image::isPvr(const unsigned char *data, ssize_t dataLen) { return false; } - const PVRv2TexHeader *headerv2 = static_cast(static_cast(data)); - const PVRv3TexHeader *headerv3 = static_cast(static_cast(data)); + const auto *headerv2 = static_cast(static_cast(data)); + const auto *headerv3 = static_cast(static_cast(data)); - return memcmp(&headerv2->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203; + return memcmp(&headerv2->pvrTag, G_PVR_TEX_IDENTIFIER, strlen(G_PVR_TEX_IDENTIFIER)) == 0 || CC_SWAP_INT32_BIG_TO_HOST(headerv3->version) == 0x50565203; } Image::Format Image::detectFormat(const unsigned char *data, ssize_t dataLen) { if (isPng(data, dataLen)) { return Format::PNG; - } else if (isJpg(data, dataLen)) { - return Format::JPG; - } else if (isWebp(data, dataLen)) { - return Format::WEBP; - } else if (isPvr(data, dataLen)) { - return Format::PVR; - } else if (isEtc(data, dataLen)) { - return Format::ETC; - } else if (isEtc2(data, dataLen)) { - return Format::ETC2; - } else if (isASTC(data, dataLen)) { - return Format::ASTC; - } else { - return Format::UNKNOWN; } + if (isJpg(data, dataLen)) { + return Format::JPG; + } + if (isWebp(data, dataLen)) { + return Format::WEBP; + } + if (isPvr(data, dataLen)) { + return Format::PVR; + } + if (isEtc(data, dataLen)) { + return Format::ETC; + } + if (isEtc2(data, dataLen)) { + return Format::ETC2; + } + if (isASTC(data, dataLen)) { + return Format::ASTC; + } + return Format::UNKNOWN; } -gfx::Format Image::getASTCFormat(const unsigned char *pHeader) const { +gfx::Format Image::getASTCFormat(const unsigned char *pHeader) { int xdim = pHeader[ASTC_HEADER_MAGIC]; int ydim = pHeader[ASTC_HEADER_MAGIC + 1]; - if (xdim == 4) { - return gfx::Format::ASTC_RGBA_4x4; - } else if (xdim == 5) { - if (ydim == 4) { - return gfx::Format::ASTC_RGBA_5x4; - } else { - return gfx::Format::ASTC_RGBA_5x5; - } - } else if (xdim == 6) { - if (ydim == 5) { - return gfx::Format::ASTC_RGBA_6x5; - } else { - return gfx::Format::ASTC_RGBA_6x6; - } - } else if (xdim == 8) { - if (ydim == 5) { - return gfx::Format::ASTC_RGBA_8x5; - } else if (ydim == 6) { - return gfx::Format::ASTC_RGBA_8x6; - } else { - return gfx::Format::ASTC_RGBA_8x8; - } - } else if (xdim == 10) { - if (ydim == 5) { - return gfx::Format::ASTC_RGBA_10x5; - } else if (ydim == 6) { - return gfx::Format::ASTC_RGBA_10x6; - } else if (ydim == 8) { - return gfx::Format::ASTC_RGBA_10x8; - } else { - return gfx::Format::ASTC_RGBA_10x10; - } - } else { - if (ydim == 10) { - return gfx::Format::ASTC_RGBA_12x10; - } else { - return gfx::Format::ASTC_RGBA_12x12; - } + if (xdim == 4) return gfx::Format::ASTC_RGBA_4X4; + if (xdim == 5) { + if (ydim == 4) return gfx::Format::ASTC_RGBA_5X4; + return gfx::Format::ASTC_RGBA_5X5; } + if (xdim == 6) { + if (ydim == 5) return gfx::Format::ASTC_RGBA_6X5; + return gfx::Format::ASTC_RGBA_6X6; + } + if (xdim == 8) { + if (ydim == 5) return gfx::Format::ASTC_RGBA_8X5; + if (ydim == 6) return gfx::Format::ASTC_RGBA_8X6; + return gfx::Format::ASTC_RGBA_8X8; + } + if (xdim == 10) { + if (ydim == 5) return gfx::Format::ASTC_RGBA_10X5; + if (ydim == 6) return gfx::Format::ASTC_RGBA_10X6; + if (ydim == 8) return gfx::Format::ASTC_RGBA_10X8; + return gfx::Format::ASTC_RGBA_10X10; + } + if (ydim == 10) return gfx::Format::ASTC_RGBA_12X10; + return gfx::Format::ASTC_RGBA_12X12; } namespace { /* - * ERROR HANDLING: - * - * The JPEG library's standard error handler (jerror.c) is divided into - * several "methods" which you can override individually. This lets you - * adjust the behavior without duplicating a lot of code, which you might - * have to update with each future release. - * - * We override the "error_exit" method so that control is returned to the - * library's caller when a fatal error occurs, rather than calling exit() - * as the standard error_exit method does. - * - * We use C's setjmp/longjmp facility to return control. This means that the - * routine which calls the JPEG library must first execute a setjmp() call to - * establish the return point. We want the replacement error_exit to do a - * longjmp(). But we need to make the setjmp buffer accessible to the - * error_exit routine. To do this, we make a private extension of the - * standard JPEG error handler object. (If we were using C++, we'd say we - * were making a subclass of the regular error handler.) - * - * Here's the extended error handler struct: - */ + * ERROR HANDLING: + * + * The JPEG library's standard error handler (jerror.c) is divided into + * several "methods" which you can override individually. This lets you + * adjust the behavior without duplicating a lot of code, which you might + * have to update with each future release. + * + * We override the "error_exit" method so that control is returned to the + * library's caller when a fatal error occurs, rather than calling exit() + * as the standard error_exit method does. + * + * We use C's setjmp/longjmp facility to return control. This means that the + * routine which calls the JPEG library must first execute a setjmp() call to + * establish the return point. We want the replacement error_exit to do a + * longjmp(). But we need to make the setjmp buffer accessible to the + * error_exit routine. To do this, we make a private extension of the + * standard JPEG error handler object. (If we were using C++, we'd say we + * were making a subclass of the regular error handler.) + * + * Here's the extended error handler struct: + */ #if CC_USE_JPEG struct MyErrorMgr { - struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ + struct jpeg_error_mgr pub; /* "public" fields */ + jmp_buf setjmp_buffer; /* for return to caller */ }; -typedef struct MyErrorMgr *MyErrorPtr; +using MyErrorPtr = struct MyErrorMgr *; /* - * Here's the routine that will replace the standard error_exit method: - */ + * Here's the routine that will replace the standard error_exit method: + */ -METHODDEF(void) -myErrorExit(j_common_ptr cinfo) { +void myErrorExit(j_common_ptr cinfo) { /* cinfo->err really points to a MyErrorMgr struct, so coerce pointer */ - MyErrorPtr myerr = (MyErrorPtr)cinfo->err; + auto *myerr = reinterpret_cast(cinfo->err); /* Always display the message. */ /* We could postpone this until after returning, if we chose. */ /* internal message function can't show error message in some platforms, so we rewrite it here. - * edit it if has version conflict. - */ + * edit it if has version conflict. + */ //(*cinfo->err->output_message) (cinfo); char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message)(cinfo, buffer); @@ -525,13 +508,13 @@ bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) { */ struct MyErrorMgr jerr; /* libjpeg data structure for storing one row, that is, scanline of an image */ - JSAMPROW row_pointer[1] = {0}; - unsigned long location = 0; + JSAMPROW rowPointer[1] = {nullptr}; + uint32_t location = 0; bool ret = false; do { /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo.err = jpeg_std_error(&jerr.pub); + cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = myErrorExit; /* Establish the setjmp return context for MyErrorExit to use. */ if (setjmp(jerr.setjmp_buffer)) { @@ -556,11 +539,11 @@ bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) { #endif // we only support RGB or grayscale - if (cinfo.jpeg_color_space == JCS_GRAYSCALE) + if (cinfo.jpeg_color_space == JCS_GRAYSCALE) { _renderFormat = gfx::Format::L8; - else { + } else { cinfo.out_color_space = JCS_RGB; - _renderFormat = gfx::Format::RGB8; + _renderFormat = gfx::Format::RGB8; } /* Start decompression jpeg here */ @@ -568,18 +551,18 @@ bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) { /* init image info */ _isCompressed = false; - _width = cinfo.output_width; - _height = cinfo.output_height; - _dataLen = cinfo.output_width * cinfo.output_height * cinfo.output_components; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _width = cinfo.output_width; + _height = cinfo.output_height; + _dataLen = cinfo.output_width * cinfo.output_height * cinfo.output_components; + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); CC_BREAK_IF(!_data); /* now actually read the jpeg into the raw buffer */ /* read one scan line at a time */ while (cinfo.output_scanline < cinfo.output_height) { - row_pointer[0] = _data + location; + rowPointer[0] = _data + location; location += cinfo.output_width * cinfo.output_components; - jpeg_read_scanlines(&cinfo, row_pointer, 1); + jpeg_read_scanlines(&cinfo, rowPointer, 1); } /* When read image file with broken data, jpeg_finish_decompress() may cause error. @@ -591,7 +574,7 @@ bool Image::initWithJpgData(const unsigned char *data, ssize_t dataLen) { jpeg_destroy_decompress(&cinfo); /* wrap up decompression, destroy objects, free pointers and close open files */ ret = true; - } while (0); + } while (false); return ret; #endif // CC_USE_JPEG @@ -601,10 +584,10 @@ bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) { #if CC_USE_PNG // length of bytes to check if it is a valid png file #define PNGSIGSIZE 8 - bool ret = false; - png_byte header[PNGSIGSIZE] = {0}; - png_structp png_ptr = 0; - png_infop info_ptr = 0; + bool ret = false; + png_byte header[PNGSIGSIZE] = {0}; + png_structp pngPtr = nullptr; + png_infop infoPtr = nullptr; do { // png header len is 8 bytes @@ -615,64 +598,64 @@ bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) { CC_BREAK_IF(png_sig_cmp(header, 0, PNGSIGSIZE)); // init png_struct - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - CC_BREAK_IF(!png_ptr); + pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); + CC_BREAK_IF(!pngPtr); // init png_info - info_ptr = png_create_info_struct(png_ptr); - CC_BREAK_IF(!info_ptr); + infoPtr = png_create_info_struct(pngPtr); + CC_BREAK_IF(!infoPtr); - CC_BREAK_IF(setjmp(png_jmpbuf(png_ptr))); + CC_BREAK_IF(setjmp(png_jmpbuf(pngPtr))); // set the read call back function tImageSource imageSource; - imageSource.data = (unsigned char *)data; - imageSource.size = dataLen; + imageSource.data = const_cast(data); + imageSource.size = dataLen; imageSource.offset = 0; - png_set_read_fn(png_ptr, &imageSource, pngReadCallback); + png_set_read_fn(pngPtr, &imageSource, pngReadCallback); // read png header info // read png file info - png_read_info(png_ptr, info_ptr); + png_read_info(pngPtr, infoPtr); - _isCompressed = false; - _width = png_get_image_width(png_ptr, info_ptr); - _height = png_get_image_height(png_ptr, info_ptr); - png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr); - png_uint_32 color_type = png_get_color_type(png_ptr, info_ptr); + _isCompressed = false; + _width = png_get_image_width(pngPtr, infoPtr); + _height = png_get_image_height(pngPtr, infoPtr); + png_byte bitDepth = png_get_bit_depth(pngPtr, infoPtr); + png_uint_32 colorType = png_get_color_type(pngPtr, infoPtr); //CC_LOG_DEBUG("color type %u", color_type); // force palette images to be expanded to 24-bit RGB // it may include alpha channel - if (color_type == PNG_COLOR_TYPE_PALETTE) { - png_set_palette_to_rgb(png_ptr); + if (colorType == PNG_COLOR_TYPE_PALETTE) { + png_set_palette_to_rgb(pngPtr); } // low-bit-depth grayscale images are to be expanded to 8 bits - if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { - bit_depth = 8; - png_set_expand_gray_1_2_4_to_8(png_ptr); + if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) { + bitDepth = 8; + png_set_expand_gray_1_2_4_to_8(pngPtr); } // expand any tRNS chunk data into a full alpha channel - if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) { - png_set_tRNS_to_alpha(png_ptr); + if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS)) { + png_set_tRNS_to_alpha(pngPtr); } // reduce images with 16-bit samples to 8 bits - if (bit_depth == 16) { - png_set_strip_16(png_ptr); + if (bitDepth == 16) { + png_set_strip_16(pngPtr); } // Expanded earlier for grayscale, now take care of palette and rgb - if (bit_depth < 8) { - png_set_packing(png_ptr); + if (bitDepth < 8) { + png_set_packing(pngPtr); } // update info - png_read_update_info(png_ptr, info_ptr); - bit_depth = png_get_bit_depth(png_ptr, info_ptr); - color_type = png_get_color_type(png_ptr, info_ptr); + png_read_update_info(pngPtr, infoPtr); + bitDepth = png_get_bit_depth(pngPtr, infoPtr); + colorType = png_get_color_type(pngPtr, infoPtr); - switch (color_type) { + switch (colorType) { case PNG_COLOR_TYPE_GRAY: _renderFormat = gfx::Format::L8; break; @@ -691,64 +674,65 @@ bool Image::initWithPngData(const unsigned char *data, ssize_t dataLen) { // read png data png_size_t rowbytes; - png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * _height); + auto * rowPointers = static_cast(malloc(sizeof(png_bytep) * _height)); - rowbytes = png_get_rowbytes(png_ptr, info_ptr); + rowbytes = png_get_rowbytes(pngPtr, infoPtr); _dataLen = rowbytes * _height; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); if (!_data) { - if (row_pointers != nullptr) { - free(row_pointers); + if (rowPointers != nullptr) { + free(rowPointers); } break; } - for (unsigned short i = 0; i < _height; ++i) { - row_pointers[i] = _data + i * rowbytes; + for (int i = 0; i < _height; ++i) { + rowPointers[i] = _data + i * rowbytes; } - png_read_image(png_ptr, row_pointers); - png_read_end(png_ptr, nullptr); + png_read_image(pngPtr, rowPointers); + png_read_end(pngPtr, nullptr); - if (row_pointers != nullptr) { - free(row_pointers); + if (rowPointers != nullptr) { + free(rowPointers); } ret = true; - } while (0); + } while (false); - if (png_ptr) { - png_destroy_read_struct(&png_ptr, (info_ptr) ? &info_ptr : 0, 0); + if (pngPtr) { + png_destroy_read_struct(&pngPtr, (infoPtr) ? &infoPtr : nullptr, nullptr); } return ret; #endif //CC_USE_PNG } bool Image::initWithPVRv2Data(const unsigned char *data, ssize_t dataLen) { - int width = 0, height = 0; + int width = 0; + int height = 0; //Cast first sizeof(PVRTexHeader) bytes of data stream as PVRTexHeader - const PVRv2TexHeader *header = static_cast(static_cast(data)); + const auto *header = static_cast(static_cast(data)); //Make sure that tag is in correct formatting - if (memcmp(&header->pvrTag, gPVRTexIdentifier, strlen(gPVRTexIdentifier)) != 0) { + if (memcmp(&header->pvrTag, G_PVR_TEX_IDENTIFIER, strlen(G_PVR_TEX_IDENTIFIER)) != 0) { return false; } - unsigned int flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags); - PVR2TexturePixelFormat formatFlags = static_cast(flags & PVR_TEXTURE_FLAG_TYPE_MASK); - bool flipped = (flags & (unsigned int)PVR2TextureFlag::VerticalFlip) ? true : false; + unsigned int flags = CC_SWAP_INT32_LITTLE_TO_HOST(header->flags); + auto formatFlags = static_cast(flags & PVR_TEXTURE_FLAG_TYPE_MASK); + bool flipped = (flags & static_cast(PVR2TextureFlag::VERTICAL_FLIP)) != 0; if (flipped) { CC_LOG_DEBUG("initWithPVRv2Data: WARNING: Image is flipped. Regenerate it using PVRTexTool"); } - if (v2_pixel_formathash.find(formatFlags) == v2_pixel_formathash.end()) { + if (V2_PIXEL_FORMATHASH.find(formatFlags) == V2_PIXEL_FORMATHASH.end()) { CC_LOG_DEBUG("initWithPVRv2Data: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags); return false; } - auto it = v2_pixel_formathash.find(formatFlags); - if (it == v2_pixel_formathash.end()) { + auto it = V2_PIXEL_FORMATHASH.find(formatFlags); + if (it == V2_PIXEL_FORMATHASH.end()) { CC_LOG_DEBUG("initWithPVRv2Data: WARNING: Unsupported PVR Pixel Format: 0x%02X. Re-encode it with a OpenGL pixel format variant", (int)formatFlags); return false; } @@ -758,12 +742,12 @@ bool Image::initWithPVRv2Data(const unsigned char *data, ssize_t dataLen) { //Get size of mipmap _width = width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); _height = height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height); - _isCompressed = true; + _isCompressed = true; //Move by size of header _dataLen = dataLen - sizeof(PVRv2TexHeader); - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - memcpy(_data, (unsigned char *)data + sizeof(PVRv2TexHeader), _dataLen); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + memcpy(_data, const_cast(data) + sizeof(PVRv2TexHeader), _dataLen); return true; } @@ -773,7 +757,7 @@ bool Image::initWithPVRv3Data(const unsigned char *data, ssize_t dataLen) { return false; } - const PVRv3TexHeader *header = static_cast(static_cast(data)); + const auto *header = static_cast(static_cast(data)); // validate version if (CC_SWAP_INT32_BIG_TO_HOST(header->version) != 0x50565203) { @@ -782,16 +766,16 @@ bool Image::initWithPVRv3Data(const unsigned char *data, ssize_t dataLen) { } // parse pixel format - PVR3TexturePixelFormat pixelFormat = static_cast(header->pixelFormat); + auto pixelFormat = static_cast(header->pixelFormat); - if (v3_pixel_formathash.find(pixelFormat) == v3_pixel_formathash.end()) { + if (V3_PIXEL_FORMATHASH.find(pixelFormat) == V3_PIXEL_FORMATHASH.end()) { CC_LOG_DEBUG("initWithPVRv3Data: WARNING: Unsupported PVR Pixel Format: 0x%016llX. Re-encode it with a OpenGL pixel format variant", static_cast(pixelFormat)); return false; } - auto it = v3_pixel_formathash.find(pixelFormat); - if (it == v3_pixel_formathash.end()) { + auto it = V3_PIXEL_FORMATHASH.find(pixelFormat); + if (it == V3_PIXEL_FORMATHASH.end()) { CC_LOG_DEBUG("initWithPVRv3Data: WARNING: Unsupported PVR Pixel Format: 0x%016llX. Re-encode it with a OpenGL pixel format variant", static_cast(pixelFormat)); return false; @@ -800,27 +784,27 @@ bool Image::initWithPVRv3Data(const unsigned char *data, ssize_t dataLen) { _renderFormat = it->second; // sizing - _width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); - _height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height); + _width = CC_SWAP_INT32_LITTLE_TO_HOST(header->width); + _height = CC_SWAP_INT32_LITTLE_TO_HOST(header->height); _isCompressed = true; _dataLen = dataLen - (sizeof(PVRv3TexHeader) + header->metadataLength); - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); memcpy(_data, static_cast(data) + sizeof(PVRv3TexHeader) + header->metadataLength, _dataLen); return true; } bool Image::initWithETCData(const unsigned char *data, ssize_t dataLen) { - const etc1_byte *header = static_cast(data); + const auto *header = static_cast(data); //check the data if (!etc1_pkm_is_valid(header)) { return false; } - _width = etc1_pkm_get_width(header); - _height = etc1_pkm_get_height(header); + _width = etc1_pkm_get_width(header); + _height = etc1_pkm_get_height(header); _isCompressed = true; if (0 == _width || 0 == _height) { @@ -828,22 +812,22 @@ bool Image::initWithETCData(const unsigned char *data, ssize_t dataLen) { } _renderFormat = gfx::Format::ETC_RGB8; - _dataLen = dataLen - ETC_PKM_HEADER_SIZE; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _dataLen = dataLen - ETC_PKM_HEADER_SIZE; + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); memcpy(_data, static_cast(data) + ETC_PKM_HEADER_SIZE, _dataLen); return true; } bool Image::initWithETC2Data(const unsigned char *data, ssize_t dataLen) { - const etc2_byte *header = static_cast(data); + const auto *header = static_cast(data); //check the data if (!etc2_pkm_is_valid(header)) { return false; } - _width = etc2_pkm_get_width(header); - _height = etc2_pkm_get_height(header); + _width = etc2_pkm_get_width(header); + _height = etc2_pkm_get_height(header); _isCompressed = true; if (0 == _width || 0 == _height) { @@ -851,27 +835,28 @@ bool Image::initWithETC2Data(const unsigned char *data, ssize_t dataLen) { } etc2_uint32 format = etc2_pkm_get_format(header); - if (format == ETC2_RGB_NO_MIPMAPS) + if (format == ETC2_RGB_NO_MIPMAPS) { _renderFormat = gfx::Format::ETC2_RGB8; - else + } else { _renderFormat = gfx::Format::ETC2_RGBA8; + } _dataLen = dataLen - ETC2_PKM_HEADER_SIZE; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); memcpy(_data, static_cast(data) + ETC2_PKM_HEADER_SIZE, _dataLen); return true; } bool Image::initWithASTCData(const unsigned char *data, ssize_t dataLen) { - const astc_byte *header = static_cast(data); + const auto *header = static_cast(data); //check the data if (!astcIsValid(header)) { return false; } - _width = astcGetWidth(header); - _height = astcGetHeight(header); + _width = astcGetWidth(header); + _height = astcGetHeight(header); _isCompressed = true; if (0 == _width || 0 == _height) { @@ -881,7 +866,7 @@ bool Image::initWithASTCData(const unsigned char *data, ssize_t dataLen) { _renderFormat = getASTCFormat(header); _dataLen = dataLen - ASTC_HEADER_SIZE; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); memcpy(_data, static_cast(data) + ASTC_HEADER_SIZE, _dataLen); // if (_data == nullptr) { // CCLOG("initWithASTCData: ERROR: Image _data is null!"); @@ -906,17 +891,17 @@ bool Image::initWithWebpData(const unsigned char *data, ssize_t dataLen) { if (config.input.width == 0 || config.input.height == 0) break; config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB; - _renderFormat = config.input.has_alpha ? gfx::Format::RGBA8 : gfx::Format::RGB8; - _width = config.input.width; - _height = config.input.height; - _isCompressed = false; + _renderFormat = config.input.has_alpha ? gfx::Format::RGBA8 : gfx::Format::RGB8; + _width = config.input.width; + _height = config.input.height; + _isCompressed = false; _dataLen = _width * _height * (config.input.has_alpha ? 4 : 3); - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); - config.output.u.RGBA.rgba = static_cast(_data); - config.output.u.RGBA.stride = _width * (config.input.has_alpha ? 4 : 3); - config.output.u.RGBA.size = _dataLen; + config.output.u.RGBA.rgba = static_cast(_data); + config.output.u.RGBA.stride = _width * (config.input.has_alpha ? 4 : 3); + config.output.u.RGBA.size = _dataLen; config.output.is_external_memory = 1; if (WebPDecode(static_cast(data), dataLen, &config) != VP8_STATUS_OK) { @@ -926,30 +911,30 @@ bool Image::initWithWebpData(const unsigned char *data, ssize_t dataLen) { } ret = true; - } while (0); + } while (false); return ret; #endif // CC_USE_WEBP } -bool Image::initWithRawData(const unsigned char *data, ssize_t dataLen, int width, int height, int bitsPerComponent, bool preMulti) { +bool Image::initWithRawData(const unsigned char *data, ssize_t /*dataLen*/, int width, int height, int /*bitsPerComponent*/, bool /*preMulti*/) { bool ret = false; do { CC_BREAK_IF(0 == width || 0 == height); - _height = height; - _width = width; + _height = height; + _width = width; _renderFormat = gfx::Format::RGBA8; _isCompressed = false; // only RGBA8888 supported int bytesPerComponent = 4; - _dataLen = height * width * bytesPerComponent; - _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); + _dataLen = height * width * bytesPerComponent; + _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); CC_BREAK_IF(!_data); memcpy(_data, data, _dataLen); ret = true; - } while (0); + } while (false); return ret; } diff --git a/native/cocos/platform/Image.h b/native/cocos/platform/Image.h index 7c93ebbc99..ce534e8772 100644 --- a/native/cocos/platform/Image.h +++ b/native/cocos/platform/Image.h @@ -97,7 +97,6 @@ protected: bool initWithETC2Data(const unsigned char *data, ssize_t dataLen); bool initWithASTCData(const unsigned char *data, ssize_t dataLen); -protected: unsigned char *_data = nullptr; ssize_t _dataLen = 0; int _width = 0; @@ -107,27 +106,18 @@ protected: std::string _filePath; bool _isCompressed = false; -protected: - // noncopyable - Image(const Image &) = delete; - Image &operator=(const Image &) = delete; + ~Image() override; - // nonmoveable - Image(Image &&) = delete; - Image &operator=(Image &&) = delete; + static Format detectFormat(const unsigned char *data, ssize_t dataLen); + static bool isPng(const unsigned char *data, ssize_t dataLen); + static bool isJpg(const unsigned char *data, ssize_t dataLen); + static bool isWebp(const unsigned char *data, ssize_t dataLen); + static bool isPvr(const unsigned char *data, ssize_t dataLen); + static bool isEtc(const unsigned char *data, ssize_t dataLen); + static bool isEtc2(const unsigned char *data, ssize_t dataLen); + static bool isASTC(const unsigned char *data, ssize_t detaLen); - virtual ~Image(); - - Format detectFormat(const unsigned char *data, ssize_t dataLen); - bool isPng(const unsigned char *data, ssize_t dataLen); - bool isJpg(const unsigned char *data, ssize_t dataLen); - bool isWebp(const unsigned char *data, ssize_t dataLen); - bool isPvr(const unsigned char *data, ssize_t dataLen); - bool isEtc(const unsigned char *data, ssize_t dataLen); - bool isEtc2(const unsigned char *data, ssize_t dataLen); - bool isASTC(const unsigned char *data, ssize_t detaLen); - - gfx::Format getASTCFormat(const unsigned char *pHeader) const; + static gfx::Format getASTCFormat(const unsigned char *pHeader); }; } //namespace cc diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index fdbf9f7a62..8a3dc353b0 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -81,23 +81,17 @@ public: } static void destroy() { - CC_SAFE_DESTROY(Device::_instance); + CC_SAFE_DESTROY(Device::instance); } - static constexpr bool useAgent() { return true; } - - static constexpr bool useValidator() { return CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION; } - private: template ::value>> static bool tryCreate(const DeviceInfo &info, Device *&device) { device = CC_NEW(DeviceCtor); - if (useAgent()) { - device = CC_NEW(gfx::DeviceAgent(device)); - } + device = CC_NEW(gfx::DeviceAgent(device)); - if (useValidator()) { + if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) { device = CC_NEW(gfx::DeviceValidator(device)); //((gfx::DeviceValidator *)device)->enableRecording(true); } diff --git a/native/cocos/renderer/frame-graph/Resource.h b/native/cocos/renderer/frame-graph/Resource.h index f4d85e565e..5afd90fc72 100644 --- a/native/cocos/renderer/frame-graph/Resource.h +++ b/native/cocos/renderer/frame-graph/Resource.h @@ -41,14 +41,14 @@ namespace framegraph { template struct ResourceDescriptorHasher final { - CC_INLINE uint32_t operator()(const DescriptorType &desc) const noexcept { + CC_INLINE uint32_t operator()(const DescriptorType &desc) const { return 1; } }; template struct DeviceResourceCreator final { - CC_INLINE DeviceResourceType *operator()(const DescriptorType &desc) const noexcept { + CC_INLINE DeviceResourceType *operator()(const DescriptorType &desc) const { return nullptr; } }; @@ -64,13 +64,13 @@ public: using Descriptor = DescriptorType; using DescriptorHasher = DescriptorHasherType; - Resource() noexcept = default; + Resource() = default; explicit Resource(const Descriptor &desc) noexcept; - ~Resource() = default; - Resource(const Resource &) = default; - Resource(Resource &&) = default; + ~Resource() = default; + Resource(const Resource &) = default; + Resource(Resource &&) noexcept = default; Resource &operator=(const Resource &) = default; - Resource &operator=(Resource &&) = default; + Resource &operator=(Resource &&) noexcept = default; void createTransient() noexcept; void createPersistent() noexcept; @@ -145,22 +145,22 @@ void Resource \ - struct ResourceDescriptorHasher final { \ - CC_INLINE uint32_t operator()(const gfx::Type##Info &desc) const noexcept { \ - return gfx::Type::computeHash(desc); \ - } \ - }; \ - \ - template <> \ - struct DeviceResourceCreator final { \ - CC_INLINE gfx::Type *operator()(const gfx::Type##Info &desc) const noexcept { \ - return gfx::Device::getInstance()->create##Type(desc); \ - } \ - }; \ - \ - using Type = Resource; \ +#define DEFINE_GFX_RESOURCE(Type) \ + template <> \ + struct ResourceDescriptorHasher final { \ + CC_INLINE uint32_t operator()(const gfx::Type##Info &desc) const { \ + return gfx::Type::computeHash(desc); \ + } \ + }; \ + \ + template <> \ + struct DeviceResourceCreator final { \ + CC_INLINE gfx::Type *operator()(const gfx::Type##Info &desc) const { \ + return gfx::Device::getInstance()->create##Type(desc); \ + } \ + }; \ + \ + using Type = Resource; /* NOLINT(bugprone-macro-parentheses) N/A */ \ using Type##Handle = TypedHandle; DEFINE_GFX_RESOURCE(Buffer) diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp index a6d2cf973d..e67b5dc891 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp @@ -24,8 +24,8 @@ ****************************************************************************/ #include "base/CoreStd.h" -#include "base/threading/MessageQueue.h" #include "base/job-system/JobSystem.h" +#include "base/threading/MessageQueue.h" #include "BufferAgent.h" #include "CommandBufferAgent.h" @@ -48,17 +48,17 @@ void CommandBufferAgent::flushCommands(uint count, CommandBufferAgent *const *cm if (count > workForThisThread + 1 && multiThreaded) { // more than one job to dispatch JobGraph g(JobSystem::getInstance()); - g.createForEachIndexJob(workForThisThread, count, 1u, [cmdBuffs](uint i) { + g.createForEachIndexJob(workForThisThread, count, 1U, [cmdBuffs](uint i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); }); g.run(); - for (uint i = 0u; i < workForThisThread; ++i) { + for (uint i = 0U; i < workForThisThread; ++i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); } g.waitForAll(); } else { - for (uint i = 0u; i < count; ++i) { + for (uint i = 0U; i < count; ++i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); } } @@ -78,7 +78,7 @@ CommandBufferAgent::~CommandBufferAgent() { void CommandBufferAgent::initMessageQueue() { _allocatorPools.resize(MAX_CPU_FRAME_AHEAD + 1); - for (uint i = 0u; i < MAX_CPU_FRAME_AHEAD + 1; ++i) { + for (uint i = 0U; i < MAX_CPU_FRAME_AHEAD + 1; ++i) { _allocatorPools[i] = CC_NEW(LinearAllocatorPool); } DeviceAgent *device = DeviceAgent::getInstance(); @@ -195,7 +195,7 @@ void CommandBufferAgent::endRenderPass() { void CommandBufferAgent::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { if (!count) return; - CommandBuffer **actorCmdBuffs = getAllocator()->allocate(count); + auto **actorCmdBuffs = getAllocator()->allocate(count); for (uint i = 0; i < count; ++i) { actorCmdBuffs[i] = static_cast(cmdBuffs[i])->getActor(); } @@ -335,20 +335,20 @@ void CommandBufferAgent::setStencilCompareMask(StencilFace face, int ref, uint m }); } -void CommandBufferAgent::draw(InputAssembler *ia) { +void CommandBufferAgent::draw(const DrawInfo &info) { ENQUEUE_MESSAGE_2( _messageQueue, CommandBufferDraw, actor, getActor(), - ia, static_cast(ia)->getActor(), + info, info, { - actor->draw(ia); + actor->draw(info); }); } void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint size) { MessageQueue *queue = _messageQueue; - uint8_t *actorData = getAllocator()->allocate(size); + auto *actorData = getAllocator()->allocate(size); memcpy(actorData, data, size); ENQUEUE_MESSAGE_4( @@ -365,19 +365,19 @@ void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint size) void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { LinearAllocatorPool *allocator = getAllocator(); - BufferTextureCopy *actorRegions = allocator->allocate(count); + auto *actorRegions = allocator->allocate(count); memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy)); - uint bufferCount = 0u; - for (uint i = 0u; i < count; i++) { + uint bufferCount = 0U; + for (uint i = 0U; i < count; i++) { bufferCount += regions[i].texSubres.layerCount; } - const uint8_t **actorBuffers = allocator->allocate(bufferCount); - for (uint i = 0u, n = 0u; i < count; i++) { + const auto **actorBuffers = allocator->allocate(bufferCount); + for (uint i = 0U, n = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = FormatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); + uint size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); for (uint l = 0; l < region.texSubres.layerCount; l++) { - uint8_t *buffer = allocator->allocate(size); + auto *buffer = allocator->allocate(size); memcpy(buffer, buffers[n], size); actorBuffers[n++] = buffer; } @@ -401,7 +401,7 @@ void CommandBufferAgent::blitTexture(Texture *srcTexture, Texture *dstTexture, c if (srcTexture) actorSrcTexture = static_cast(srcTexture)->getActor(); if (dstTexture) actorDstTexture = static_cast(dstTexture)->getActor(); - TextureBlit *actorRegions = getAllocator()->allocate(count); + auto *actorRegions = getAllocator()->allocate(count); memcpy(actorRegions, regions, count * sizeof(TextureBlit)); ENQUEUE_MESSAGE_6( @@ -436,10 +436,10 @@ void CommandBufferAgent::pipelineBarrier(const GlobalBarrier *barrier, const Tex if (textureBarrierCount) { actorTextureBarriers = getAllocator()->allocate(textureBarrierCount); - memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(TextureBarrier *)); + memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(uintptr_t)); actorTextures = getAllocator()->allocate(textureBarrierCount); - for (uint i = 0u; i < textureBarrierCount; ++i) { + for (uint i = 0U; i < textureBarrierCount; ++i) { actorTextures[i] = textures[i] ? static_cast(textures[i])->getActor() : nullptr; } } diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h index 1613a14c6e..6a36fee654 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h @@ -58,7 +58,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 764658e4b0..851aa965ee 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -45,19 +45,19 @@ namespace cc { namespace gfx { -DeviceAgent *DeviceAgent::_instance = nullptr; +DeviceAgent *DeviceAgent::instance = nullptr; DeviceAgent *DeviceAgent::getInstance() { - return DeviceAgent::_instance; + return DeviceAgent::instance; } DeviceAgent::DeviceAgent(Device *device) : Agent(device) { - DeviceAgent::_instance = this; + DeviceAgent::instance = this; } DeviceAgent::~DeviceAgent() { CC_SAFE_DELETE(_actor); - DeviceAgent::_instance = nullptr; + DeviceAgent::instance = nullptr; } bool DeviceAgent::doInit(const DeviceInfo &info) { @@ -66,7 +66,7 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { } _context = _actor->getContext(); - _API = _actor->getGfxAPI(); + _api = _actor->getGfxAPI(); _deviceName = _actor->getDeviceName(); _queue = CC_NEW(QueueAgent(_actor->getQueue())); _cmdBuff = CC_NEW(CommandBufferAgent(_actor->getCommandBuffer())); @@ -79,7 +79,7 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { _mainEncoder = CC_NEW(MessageQueue); _allocatorPools.resize(MAX_CPU_FRAME_AHEAD + 1); - for (uint i = 0u; i < MAX_CPU_FRAME_AHEAD + 1; ++i) { + for (uint i = 0U; i < MAX_CPU_FRAME_AHEAD + 1; ++i) { _allocatorPools[i] = CC_NEW(LinearAllocatorPool); } static_cast(_cmdBuff)->initMessageQueue(); @@ -194,7 +194,7 @@ void DeviceAgent::setMultithreaded(bool multithreaded) { } } -CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { +CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) { CommandBuffer *actor = _actor->createCommandBuffer(info, true); return CC_NEW(CommandBufferAgent(actor)); } @@ -270,19 +270,19 @@ TextureBarrier *DeviceAgent::createTextureBarrier() { void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { LinearAllocatorPool *allocator = getMainAllocator(); - BufferTextureCopy *actorRegions = allocator->allocate(count); + auto *actorRegions = allocator->allocate(count); memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy)); - uint bufferCount = 0u; - for (uint i = 0u; i < count; i++) { + uint bufferCount = 0U; + for (uint i = 0U; i < count; i++) { bufferCount += regions[i].texSubres.layerCount; } - const uint8_t **actorBuffers = allocator->allocate(bufferCount); - for (uint i = 0u, n = 0u; i < count; i++) { + const auto **actorBuffers = allocator->allocate(bufferCount); + for (uint i = 0U, n = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = FormatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); + uint size = formatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); for (uint l = 0; l < region.texSubres.layerCount; l++) { - uint8_t *buffer = allocator->allocate(size); + auto *buffer = allocator->allocate(size); memcpy(buffer, buffers[n], size); actorBuffers[n++] = buffer; } @@ -305,7 +305,7 @@ void DeviceAgent::flushCommands(CommandBuffer *const *cmdBuffs, uint count) { bool multiThreaded = hasFeature(Feature::MULTITHREADED_SUBMISSION); - CommandBufferAgent **agentCmdBuffs = getMainAllocator()->allocate(count); + auto **agentCmdBuffs = getMainAllocator()->allocate(count); for (uint i = 0; i < count; ++i) { agentCmdBuffs[i] = static_cast(cmdBuffs[i]); MessageQueue::freeChunksInFreeQueue(agentCmdBuffs[i]->_messageQueue); diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.h b/native/cocos/renderer/gfx-agent/DeviceAgent.h index 79f4dfc03d..7911eed9ba 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.h +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.h @@ -38,7 +38,7 @@ namespace gfx { class LinearAllocatorPool; class CommandBuffer; class CommandBufferAgent; -constexpr uint MAX_CPU_FRAME_AHEAD = 1u; +constexpr uint MAX_CPU_FRAME_AHEAD = 1U; class CC_DLL DeviceAgent final : public Agent { public: @@ -100,12 +100,12 @@ public: LinearAllocatorPool *getMainAllocator() const { return _allocatorPools[_currentIndex]; } protected: - static DeviceAgent *_instance; + static DeviceAgent *instance; friend class DeviceManager; friend class CommandBufferAgent; - DeviceAgent(Device *device); + explicit DeviceAgent(Device *device); bool doInit(const DeviceInfo &info) override; void doDestroy() override; @@ -119,7 +119,7 @@ protected: bool _multithreaded{false}; MessageQueue *_mainEncoder{nullptr}; - uint _currentIndex = 0u; + uint _currentIndex = 0U; vector _allocatorPools; Semaphore _frameBoundarySemaphore{MAX_CPU_FRAME_AHEAD}; diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.cpp b/native/cocos/renderer/gfx-base/GFXBuffer.cpp index af6c7165a9..1cb73e1e19 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXBuffer.cpp @@ -36,15 +36,14 @@ Buffer::Buffer() : GFXObject(ObjectType::BUFFER) { } -Buffer::~Buffer() { -} +Buffer::~Buffer() = default; uint Buffer::computeHash(const BufferInfo &info) { uint seed = 4; - seed ^= (uint)(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.size) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.size) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } @@ -53,7 +52,7 @@ void Buffer::initialize(const BufferInfo &info) { _memUsage = info.memUsage; _size = info.size; _flags = info.flags; - _stride = std::max(info.stride, 1u); + _stride = std::max(info.stride, 1U); _count = _size / _stride; Device::getInstance()->getMemoryStatus().bufferSize += _size; @@ -67,7 +66,7 @@ void Buffer::initialize(const BufferViewInfo &info) { _flags = info.buffer->getFlags(); _offset = info.offset; _size = _stride = info.range; - _count = 1u; + _count = 1U; _isBufferView = true; doInit(info); @@ -78,7 +77,7 @@ void Buffer::destroy() { Device::getInstance()->getMemoryStatus().bufferSize -= _size; - _offset = _size = _stride = _count = 0u; + _offset = _size = _stride = _count = 0U; } void Buffer::resize(uint size) { diff --git a/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp b/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp index 50aebcb63b..5a1dfe42a6 100644 --- a/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp @@ -35,8 +35,7 @@ CommandBuffer::CommandBuffer() : GFXObject(ObjectType::COMMAND_BUFFER) { } -CommandBuffer::~CommandBuffer() { -} +CommandBuffer::~CommandBuffer() = default; void CommandBuffer::initialize(const CommandBufferInfo& info) { _type = info.type; diff --git a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h index 15399a707c..194ccc775f 100644 --- a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h @@ -26,7 +26,9 @@ #pragma once #include "GFXBuffer.h" +#include "GFXInputAssembler.h" #include "GFXObject.h" +#include "base/Utils.h" namespace cc { namespace gfx { @@ -34,9 +36,8 @@ namespace gfx { class CC_DLL CommandBuffer : public GFXObject { public: CommandBuffer(); - virtual ~CommandBuffer(); + ~CommandBuffer() override; -public: void initialize(const CommandBufferInfo &info); void destroy(); @@ -55,7 +56,7 @@ public: virtual void setDepthBound(float minBounds, float maxBounds) = 0; virtual void setStencilWriteMask(StencilFace face, uint mask) = 0; virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) = 0; - virtual void draw(InputAssembler *ia) = 0; + virtual void draw(const DrawInfo &info) = 0; virtual void updateBuffer(Buffer *buff, const void *data, uint size) = 0; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) = 0; virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) = 0; @@ -69,7 +70,7 @@ public: inline void updateBuffer(Buffer *buff, const void *data); - inline void execute(CommandBufferList &cmdBuffs, uint32_t count); + inline void execute(const CommandBufferList &cmdBuffs, uint32_t count); inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet); inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets); @@ -78,6 +79,7 @@ public: inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil); inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil); + inline void draw(InputAssembler *ia); inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions); inline void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlitList ®ions, Filter filter); @@ -127,7 +129,7 @@ void CommandBuffer::updateBuffer(Buffer *buff, const void *data) { updateBuffer(buff, data, buff->getSize()); } -void CommandBuffer::execute(CommandBufferList &cmdBuffs, uint32_t count) { +void CommandBuffer::execute(const CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); } @@ -136,11 +138,11 @@ void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { } void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { - bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); + bindDescriptorSet(set, descriptorSet, utils::toUint(dynamicOffsets.size()), dynamicOffsets.data()); } void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), utils::toUint(secondaryCBs.size())); } void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) { @@ -151,20 +153,26 @@ void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, co beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, nullptr, 0); } +void CommandBuffer::draw(InputAssembler *ia) { + DrawInfo info; + ia->extractDrawInfo(info); + draw(info); +} + void CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { - copyBuffersToTexture(buffers.data(), texture, regions.data(), static_cast(regions.size())); + copyBuffersToTexture(buffers.data(), texture, regions.data(), utils::toUint(regions.size())); } void CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlitList ®ions, Filter filter) { - blitTexture(srcTexture, dstTexture, regions.data(), static_cast(regions.size()), filter); + blitTexture(srcTexture, dstTexture, regions.data(), utils::toUint(regions.size()), filter); } void CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier) { - pipelineBarrier(barrier, nullptr, nullptr, 0u); + pipelineBarrier(barrier, nullptr, nullptr, 0U); } void CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrierList &textureBarriers, const TextureList &textures) { - pipelineBarrier(barrier, textureBarriers.data(), textures.data(), static_cast(textureBarriers.size())); + pipelineBarrier(barrier, textureBarriers.data(), textures.data(), utils::toUint(textureBarriers.size())); } void CommandBuffer::bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet) { @@ -172,11 +180,11 @@ void CommandBuffer::bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSe } void CommandBuffer::bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { - bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); + bindDescriptorSet(set, descriptorSet, utils::toUint(dynamicOffsets.size()), dynamicOffsets.data()); } void CommandBuffer::beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), utils::toUint(secondaryCBs.size())); } void CommandBuffer::beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) { diff --git a/native/cocos/renderer/gfx-base/GFXContext.cpp b/native/cocos/renderer/gfx-base/GFXContext.cpp index 77d2c7aaf1..5d25122134 100644 --- a/native/cocos/renderer/gfx-base/GFXContext.cpp +++ b/native/cocos/renderer/gfx-base/GFXContext.cpp @@ -30,11 +30,9 @@ namespace cc { namespace gfx { -Context::Context() { -} +Context::Context() = default; -Context::~Context() { -} +Context::~Context() = default; bool Context::initialize(const ContextInfo& info) { _vsyncMode = info.vsyncMode; diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index 348fd28209..6c0c54f8a9 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -283,36 +283,36 @@ enum class Format { PVRTC2_4BPP, // ASTC (Adaptive Scalable Texture Compression) - ASTC_RGBA_4x4, - ASTC_RGBA_5x4, - ASTC_RGBA_5x5, - ASTC_RGBA_6x5, - ASTC_RGBA_6x6, - ASTC_RGBA_8x5, - ASTC_RGBA_8x6, - ASTC_RGBA_8x8, - ASTC_RGBA_10x5, - ASTC_RGBA_10x6, - ASTC_RGBA_10x8, - ASTC_RGBA_10x10, - ASTC_RGBA_12x10, - ASTC_RGBA_12x12, + ASTC_RGBA_4X4, + ASTC_RGBA_5X4, + ASTC_RGBA_5X5, + ASTC_RGBA_6X5, + ASTC_RGBA_6X6, + ASTC_RGBA_8X5, + ASTC_RGBA_8X6, + ASTC_RGBA_8X8, + ASTC_RGBA_10X5, + ASTC_RGBA_10X6, + ASTC_RGBA_10X8, + ASTC_RGBA_10X10, + ASTC_RGBA_12X10, + ASTC_RGBA_12X12, // ASTC (Adaptive Scalable Texture Compression) SRGB - ASTC_SRGBA_4x4, - ASTC_SRGBA_5x4, - ASTC_SRGBA_5x5, - ASTC_SRGBA_6x5, - ASTC_SRGBA_6x6, - ASTC_SRGBA_8x5, - ASTC_SRGBA_8x6, - ASTC_SRGBA_8x8, - ASTC_SRGBA_10x5, - ASTC_SRGBA_10x6, - ASTC_SRGBA_10x8, - ASTC_SRGBA_10x10, - ASTC_SRGBA_12x10, - ASTC_SRGBA_12x12, + ASTC_SRGBA_4X4, + ASTC_SRGBA_5X4, + ASTC_SRGBA_5X5, + ASTC_SRGBA_6X5, + ASTC_SRGBA_6X6, + ASTC_SRGBA_8X5, + ASTC_SRGBA_8X6, + ASTC_SRGBA_8X8, + ASTC_SRGBA_10X5, + ASTC_SRGBA_10X6, + ASTC_SRGBA_10X8, + ASTC_SRGBA_10X10, + ASTC_SRGBA_12X10, + ASTC_SRGBA_12X12, // Total count COUNT, @@ -695,37 +695,37 @@ using ClearFlags = ClearFlagBit; CC_ENUM_OPERATORS(ClearFlagBit); struct Size { - uint x = 0u; - uint y = 0u; - uint z = 0u; + uint x = 0U; + uint y = 0U; + uint z = 0U; }; struct DeviceCaps { - uint maxVertexAttributes = 0u; - uint maxVertexUniformVectors = 0u; - uint maxFragmentUniformVectors = 0u; - uint maxTextureUnits = 0u; - uint maxImageUnits = 0u; - uint maxVertexTextureUnits = 0u; - uint maxColorRenderTargets = 0u; - uint maxShaderStorageBufferBindings = 0u; - uint maxShaderStorageBlockSize = 0u; - uint maxUniformBufferBindings = 0u; - uint maxUniformBlockSize = 0u; - uint maxTextureSize = 0u; - uint maxCubeMapTextureSize = 0u; - uint depthBits = 0u; - uint stencilBits = 0u; - uint uboOffsetAlignment = 1u; + uint maxVertexAttributes = 0U; + uint maxVertexUniformVectors = 0U; + uint maxFragmentUniformVectors = 0U; + uint maxTextureUnits = 0U; + uint maxImageUnits = 0U; + uint maxVertexTextureUnits = 0U; + uint maxColorRenderTargets = 0U; + uint maxShaderStorageBufferBindings = 0U; + uint maxShaderStorageBlockSize = 0U; + uint maxUniformBufferBindings = 0U; + uint maxUniformBlockSize = 0U; + uint maxTextureSize = 0U; + uint maxCubeMapTextureSize = 0U; + uint depthBits = 0U; + uint stencilBits = 0U; + uint uboOffsetAlignment = 1U; - uint maxComputeSharedMemorySize = 0u; - uint maxComputeWorkGroupInvocations = 0u; + uint maxComputeSharedMemorySize = 0U; + uint maxComputeWorkGroupInvocations = 0U; Size maxComputeWorkGroupSize; Size maxComputeWorkGroupCount; - float clipSpaceMinZ = -1.0f; - float screenSpaceSignY = 1.0f; - float UVSpaceSignY = -1.0f; + float clipSpaceMinZ = -1.0F; + float screenSpaceSignY = 1.0F; + float UVSpaceSignY = -1.0F; }; struct Offset { @@ -737,41 +737,38 @@ struct Offset { struct Rect { int x = 0; int y = 0; - uint width = 0u; - uint height = 0u; + uint width = 0U; + uint height = 0U; - bool operator==(const Rect &rs) { - if (x == rs.x && - y == rs.y && - width == rs.width && - height == rs.height) { - return true; - } else - return false; + bool operator==(const Rect &rs) const { + return x == rs.x && + y == rs.y && + width == rs.width && + height == rs.height; } - bool operator!=(const Rect &rs) { + bool operator!=(const Rect &rs) const { return !(*this == rs); } }; struct Extent { - uint width = 0u; - uint height = 0u; - uint depth = 1u; + uint width = 0U; + uint height = 0U; + uint depth = 1U; }; struct TextureSubresLayers { - uint mipLevel = 0u; - uint baseArrayLayer = 0u; - uint layerCount = 1u; + uint mipLevel = 0U; + uint baseArrayLayer = 0U; + uint layerCount = 1U; }; struct TextureSubresRange { - uint baseMipLevel = 0u; - uint levelCount = 1u; - uint baseArrayLayer = 0u; - uint layerCount = 1u; + uint baseMipLevel = 0U; + uint levelCount = 1U; + uint baseArrayLayer = 0U; + uint layerCount = 1U; }; struct TextureCopy { @@ -806,10 +803,10 @@ struct Viewport { int top = 0; uint width = 0; uint height = 0; - float minDepth = 0.0f; - float maxDepth = 1.0f; + float minDepth = 0.0F; + float maxDepth = 1.0F; - bool operator==(const Viewport &rs) { + bool operator==(const Viewport &rs) const { return (left == rs.left && top == rs.top && width == rs.width && @@ -818,18 +815,18 @@ struct Viewport { math::IsEqualF(maxDepth, maxDepth)); } - bool operator!=(const Viewport &rs) { + bool operator!=(const Viewport &rs) const { return !(*this == rs); } }; struct Color { - float x = 0.0f; - float y = 0.0f; - float z = 0.0f; - float w = 0.0f; + float x = 0.0F; + float y = 0.0F; + float z = 0.0F; + float w = 0.0F; - bool operator==(const Color &rhs) { + bool operator==(const Color &rhs) const { return (math::IsEqualF(x, rhs.x) && math::IsEqualF(y, rhs.y) && math::IsEqualF(z, rhs.z) && @@ -852,42 +849,42 @@ using ColorList = vector; struct BindingMappingInfo { std::vector bufferOffsets; std::vector samplerOffsets; - uint flexibleSet = 0u; + uint flexibleSet = 0U; }; struct BufferInfo { BufferUsage usage = BufferUsageBit::NONE; MemoryUsage memUsage = MemoryUsageBit::NONE; - uint size = 0u; - uint stride = 0u; // in bytes + uint size = 0U; + uint stride = 0U; // in bytes BufferFlags flags = BufferFlagBit::NONE; }; struct BufferViewInfo { Buffer *buffer = nullptr; - uint offset = 0u; - uint range = 0u; + uint offset = 0U; + uint range = 0U; }; struct DrawInfo { - uint vertexCount = 0u; - uint firstVertex = 0u; - uint indexCount = 0u; - uint firstIndex = 0u; - uint vertexOffset = 0u; - uint instanceCount = 0u; - uint firstInstance = 0u; + uint vertexCount = 0U; + uint firstVertex = 0U; + uint indexCount = 0U; + uint firstIndex = 0U; + uint vertexOffset = 0U; + uint instanceCount = 0U; + uint firstInstance = 0U; }; using DrawInfoList = vector; struct DispatchInfo { - uint groupCountX = 0u; - uint groupCountY = 0u; - uint groupCountZ = 0u; + uint groupCountX = 0U; + uint groupCountY = 0U; + uint groupCountZ = 0U; Buffer *indirectBuffer = nullptr; // @ts-nullable - uint indirectOffset = 0u; + uint indirectOffset = 0U; }; using DispatchInfoList = vector; @@ -900,23 +897,23 @@ struct TextureInfo { TextureType type = TextureType::TEX2D; TextureUsage usage = TextureUsageBit::NONE; Format format = Format::UNKNOWN; - uint width = 0u; - uint height = 0u; + uint width = 0U; + uint height = 0U; TextureFlags flags = TextureFlagBit::NONE; - uint layerCount = 1u; - uint levelCount = 1u; + uint layerCount = 1U; + uint levelCount = 1U; SampleCount samples = SampleCount::X1; - uint depth = 1u; + uint depth = 1U; }; struct TextureViewInfo { Texture * texture = nullptr; TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; - uint baseLevel = 0u; - uint levelCount = 1u; - uint baseLayer = 0u; - uint layerCount = 1u; + uint baseLevel = 0U; + uint levelCount = 1U; + uint baseLayer = 0U; + uint layerCount = 1U; }; struct SamplerInfo { @@ -926,85 +923,85 @@ struct SamplerInfo { Address addressU = Address::WRAP; Address addressV = Address::WRAP; Address addressW = Address::WRAP; - uint maxAnisotropy = 0u; + uint maxAnisotropy = 0U; ComparisonFunc cmpFunc = ComparisonFunc::ALWAYS; Color borderColor; - float mipLODBias = 0.0f; + float mipLODBias = 0.0F; }; struct Uniform { String name; Type type = Type::UNKNOWN; - uint count = 0u; + uint count = 0U; }; using UniformList = vector; struct UniformBlock { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; UniformList members; - uint count = 0u; + uint count = 0U; }; using UniformBlockList = vector; struct UniformSamplerTexture { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; Type type = Type::UNKNOWN; - uint count = 0u; + uint count = 0U; }; using UniformSamplerTextureList = vector; struct UniformSampler { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; - uint count = 0u; + uint count = 0U; }; using UniformSamplerList = vector; struct UniformTexture { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; Type type = Type::UNKNOWN; - uint count = 0u; + uint count = 0U; }; using UniformTextureList = vector; struct UniformStorageImage { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; Type type = Type::UNKNOWN; - uint count = 0u; + uint count = 0U; MemoryAccess memoryAccess = MemoryAccessBit::READ_WRITE; }; using UniformStorageImageList = vector; struct UniformStorageBuffer { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; - uint count = 0u; + uint count = 0U; MemoryAccess memoryAccess = MemoryAccessBit::READ_WRITE; }; using UniformStorageBufferList = vector; struct UniformInputAttachment { - uint set = 0u; - uint binding = 0u; + uint set = 0U; + uint binding = 0U; String name; - uint count = 0u; + uint count = 0U; }; using UniformInputAttachmentList = vector; @@ -1054,23 +1051,6 @@ struct ColorAttachment { StoreOp storeOp = StoreOp::STORE; std::vector beginAccesses; std::vector endAccesses{AccessType::PRESENT}; - - // vector constructor with initializer list is not noexcept - //ColorAttachment() noexcept = default; // this does not work for MSVC intellisense - ColorAttachment( - Format format_ = Format::UNKNOWN, - SampleCount sampleCount_ = SampleCount::X1, - LoadOp loadOp_ = LoadOp::CLEAR, - StoreOp storeOp_ = StoreOp::STORE, - std::vector beginAccesses_ = {}, - std::vector endAccesses_ = {AccessType::PRESENT}) noexcept { - format = format_; - sampleCount = sampleCount_; - loadOp = loadOp_; - storeOp = storeOp_; - beginAccesses = beginAccesses_; - endAccesses = endAccesses_; - } }; using ColorAttachmentList = vector; @@ -1084,27 +1064,6 @@ struct DepthStencilAttachment { StoreOp stencilStoreOp = StoreOp::STORE; std::vector beginAccesses; std::vector endAccesses{AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}; - - // vector constructor with initializer list is not noexcept - //DepthStencilAttachment() noexcept = default; // this does not work for MSVC intellisense - DepthStencilAttachment( - Format format_ = Format::UNKNOWN, - SampleCount sampleCount_ = SampleCount::X1, - LoadOp depthLoadOp_ = LoadOp::CLEAR, - StoreOp depthStoreOp_ = StoreOp::STORE, - LoadOp stencilLoadOp_ = LoadOp::CLEAR, - StoreOp stencilStoreOp_ = StoreOp::STORE, - std::vector beginAccesses_ = {}, - std::vector endAccesses_ = {AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}) noexcept { - format = format_; - sampleCount = sampleCount_; - depthLoadOp = depthLoadOp_; - depthStoreOp = depthStoreOp_; - stencilLoadOp = stencilLoadOp_; - stencilStoreOp = stencilStoreOp_; - beginAccesses = beginAccesses_; - endAccesses = endAccesses_; - } }; struct SubpassInfo { @@ -1181,12 +1140,12 @@ struct RasterizerState { CullMode cullMode = CullMode::BACK; uint isFrontFaceCCW = 1; uint depthBiasEnabled = 0; - float depthBias = 0.0f; - float depthBiasClamp = 0.0f; - float depthBiasSlop = 0.0f; + float depthBias = 0.0F; + float depthBiasClamp = 0.0F; + float depthBiasSlop = 0.0F; uint isDepthClip = 1; uint isMultisample = 0; - float lineWidth = 1.0f; + float lineWidth = 1.0F; }; // Use uint for all boolean values to convert memory to DepthStencilState* in shared memory. diff --git a/native/cocos/renderer/gfx-base/GFXDef.cpp b/native/cocos/renderer/gfx-base/GFXDef.cpp index 674b171416..7354862a68 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.cpp +++ b/native/cocos/renderer/gfx-base/GFXDef.cpp @@ -44,7 +44,7 @@ const DescriptorType DESCRIPTOR_TEXTURE_TYPE = DescriptorType::SAMPLER_TEXTURE | const DescriptorType DESCRIPTOR_DYNAMIC_TYPE = DescriptorType::DYNAMIC_STORAGE_BUFFER | DescriptorType::DYNAMIC_UNIFORM_BUFFER; -const uint DRAW_INFO_SIZE = 28u; +const uint DRAW_INFO_SIZE = 28U; const FormatInfo GFX_FORMAT_INFOS[] = { {"UNKNOWN", 0, 0, FormatType::NONE, false, false, false, false}, @@ -148,136 +148,134 @@ const FormatInfo GFX_FORMAT_INFOS[] = { {"PVRTC2_2BPP", 2, 4, FormatType::UNORM, true, false, false, true}, {"PVRTC2_4BPP", 2, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_4x4", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_5x4", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_5x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_6x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_6x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_8x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_8x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_8x8", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_10x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_10x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_10x8", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_10x10", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_12x10", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_RGBA_12x12", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_4X4", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_5X4", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_5X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_6X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_6X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_8X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_8X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_8X8", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_10X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_10X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_10X8", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_10X10", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_12X10", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_RGBA_12X12", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_4x4", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_5x4", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_5x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_6x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_6x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_8x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_8x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_8x8", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_10x5", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_10x6", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_10x8", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_10x10", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_12x10", 1, 4, FormatType::UNORM, true, false, false, true}, - {"ASTC_SRGBA_12x12", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_4X4", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_5X4", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_5X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_6X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_6X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_8X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_8X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_8X8", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_10X5", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_10X6", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_10X8", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_10X10", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_12X10", 1, 4, FormatType::UNORM, true, false, false, true}, + {"ASTC_SRGBA_12X12", 1, 4, FormatType::UNORM, true, false, false, true}, }; bool isCombinedImageSampler(Type type) { return type >= Type::SAMPLER1D && type <= Type::SAMPLER_CUBE; } bool isSampledImage(Type type) { return type >= Type::TEXTURE1D && type <= Type::TEXTURE_CUBE; } bool isStorageImage(Type type) { return type >= Type::IMAGE1D && type <= Type::IMAGE_CUBE; } -uint FormatSize(Format format, uint width, uint height, uint depth) { +uint ceilDiv(uint x, uint y) { return (x - 1) / y + 1; } - if (!GFX_FORMAT_INFOS[(uint)format].isCompressed) { - return (width * height * depth * GFX_FORMAT_INFOS[(uint)format].size); - } else { - switch (format) { - case Format::BC1: - case Format::BC1_ALPHA: - case Format::BC1_SRGB: - case Format::BC1_SRGB_ALPHA: - return (uint)std::ceil(width / 4) * (uint)std::ceil(height / 4) * 8 * depth; - case Format::BC2: - case Format::BC2_SRGB: - case Format::BC3: - case Format::BC3_SRGB: - case Format::BC4: - case Format::BC4_SNORM: - case Format::BC6H_SF16: - case Format::BC6H_UF16: - case Format::BC7: - case Format::BC7_SRGB: - return (uint)std::ceil(width / 4) * (uint)std::ceil(height / 4) * 16 * depth; - case Format::BC5: - case Format::BC5_SNORM: - return (uint)std::ceil(width / 4) * (uint)std::ceil(height / 4) * 32 * depth; +uint formatSize(Format format, uint width, uint height, uint depth) { + if (!GFX_FORMAT_INFOS[static_cast(format)].isCompressed) { + return (width * height * depth * GFX_FORMAT_INFOS[static_cast(format)].size); + } + switch (format) { + case Format::BC1: + case Format::BC1_ALPHA: + case Format::BC1_SRGB: + case Format::BC1_SRGB_ALPHA: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 8 * depth; + case Format::BC2: + case Format::BC2_SRGB: + case Format::BC3: + case Format::BC3_SRGB: + case Format::BC4: + case Format::BC4_SNORM: + case Format::BC6H_SF16: + case Format::BC6H_UF16: + case Format::BC7: + case Format::BC7_SRGB: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 16 * depth; + case Format::BC5: + case Format::BC5_SNORM: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 32 * depth; - case Format::ETC_RGB8: - case Format::ETC2_RGB8: - case Format::ETC2_SRGB8: - case Format::ETC2_RGB8_A1: - case Format::EAC_R11: - case Format::EAC_R11SN: - return (uint)std::ceil((float)width / 4) * (uint)std::ceil((float)height / 4) * 8 * depth; - case Format::ETC2_RGBA8: - case Format::ETC2_SRGB8_A1: - case Format::EAC_RG11: - case Format::EAC_RG11SN: - return (uint)std::ceil((float)width / 4) * (uint)std::ceil((float)height / 4) * 16 * depth; + case Format::ETC_RGB8: + case Format::ETC2_RGB8: + case Format::ETC2_SRGB8: + case Format::ETC2_RGB8_A1: + case Format::EAC_R11: + case Format::EAC_R11SN: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 8 * depth; + case Format::ETC2_RGBA8: + case Format::ETC2_SRGB8_A1: + case Format::EAC_RG11: + case Format::EAC_RG11SN: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 16 * depth; - case Format::PVRTC_RGB2: - case Format::PVRTC_RGBA2: - case Format::PVRTC2_2BPP: - return (uint)std::ceil(std::max(width, 16U) * std::max(height, 8U) / 4) * depth; - case Format::PVRTC_RGB4: - case Format::PVRTC_RGBA4: - case Format::PVRTC2_4BPP: - return (uint)std::ceil(std::max(width, 16U) * std::max(height, 8U) / 2) * depth; + case Format::PVRTC_RGB2: + case Format::PVRTC_RGBA2: + case Format::PVRTC2_2BPP: + return ceilDiv(std::max(width, 16U) * std::max(height, 8U), 4) * depth; + case Format::PVRTC_RGB4: + case Format::PVRTC_RGBA4: + case Format::PVRTC2_4BPP: + return ceilDiv(std::max(width, 16U) * std::max(height, 8U), 2) * depth; - case Format::ASTC_RGBA_4x4: - case Format::ASTC_SRGBA_4x4: - return (uint)std::ceil((float)width / 4) * (uint)std::ceil((float)height / 4) * 16 * depth; - case Format::ASTC_RGBA_5x4: - case Format::ASTC_SRGBA_5x4: - return (uint)std::ceil((float)width / 5) * (uint)std::ceil((float)height / 4) * 16 * depth; - case Format::ASTC_RGBA_5x5: - case Format::ASTC_SRGBA_5x5: - return (uint)std::ceil((float)width / 5) * (uint)std::ceil((float)height / 5) * 16 * depth; - case Format::ASTC_RGBA_6x5: - case Format::ASTC_SRGBA_6x5: - return (uint)std::ceil((float)width / 6) * (uint)std::ceil((float)height / 5) * 16 * depth; - case Format::ASTC_RGBA_6x6: - case Format::ASTC_SRGBA_6x6: - return (uint)std::ceil((float)width / 6) * (uint)std::ceil((float)height / 6) * 16 * depth; - case Format::ASTC_RGBA_8x5: - case Format::ASTC_SRGBA_8x5: - return (uint)std::ceil((float)width / 8) * (uint)std::ceil((float)height / 5) * 16 * depth; - case Format::ASTC_RGBA_8x6: - case Format::ASTC_SRGBA_8x6: - return (uint)std::ceil((float)width / 8) * (uint)std::ceil((float)height / 6) * 16 * depth; - case Format::ASTC_RGBA_8x8: - case Format::ASTC_SRGBA_8x8: - return (uint)std::ceil((float)width / 8) * (uint)std::ceil((float)height / 8) * 16 * depth; - case Format::ASTC_RGBA_10x5: - case Format::ASTC_SRGBA_10x5: - return (uint)std::ceil((float)width / 10) * (uint)std::ceil((float)height / 5) * 16 * depth; - case Format::ASTC_RGBA_10x6: - case Format::ASTC_SRGBA_10x6: - return (uint)std::ceil((float)width / 10) * (uint)std::ceil((float)height / 6) * 16 * depth; - case Format::ASTC_RGBA_10x8: - case Format::ASTC_SRGBA_10x8: - return (uint)std::ceil((float)width / 10) * (uint)std::ceil((float)height / 8) * 16 * depth; - case Format::ASTC_RGBA_10x10: - case Format::ASTC_SRGBA_10x10: - return (uint)std::ceil((float)width / 10) * (uint)std::ceil((float)height / 10) * 16 * depth; - case Format::ASTC_RGBA_12x10: - case Format::ASTC_SRGBA_12x10: - return (uint)std::ceil((float)width / 12) * (uint)std::ceil((float)height / 10) * 16 * depth; - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_12x12: - return (uint)std::ceil((float)width / 12) * (uint)std::ceil((float)height / 12) * 16 * depth; - - default: { - return 0; - } - } + case Format::ASTC_RGBA_4X4: + case Format::ASTC_SRGBA_4X4: + return ceilDiv(width, 4) * ceilDiv(height, 4) * 16 * depth; + case Format::ASTC_RGBA_5X4: + case Format::ASTC_SRGBA_5X4: + return ceilDiv(width, 5) * ceilDiv(height, 4) * 16 * depth; + case Format::ASTC_RGBA_5X5: + case Format::ASTC_SRGBA_5X5: + return ceilDiv(width, 5) * ceilDiv(height, 5) * 16 * depth; + case Format::ASTC_RGBA_6X5: + case Format::ASTC_SRGBA_6X5: + return ceilDiv(width, 6) * ceilDiv(height, 5) * 16 * depth; + case Format::ASTC_RGBA_6X6: + case Format::ASTC_SRGBA_6X6: + return ceilDiv(width, 6) * ceilDiv(height, 6) * 16 * depth; + case Format::ASTC_RGBA_8X5: + case Format::ASTC_SRGBA_8X5: + return ceilDiv(width, 8) * ceilDiv(height, 5) * 16 * depth; + case Format::ASTC_RGBA_8X6: + case Format::ASTC_SRGBA_8X6: + return ceilDiv(width, 8) * ceilDiv(height, 6) * 16 * depth; + case Format::ASTC_RGBA_8X8: + case Format::ASTC_SRGBA_8X8: + return ceilDiv(width, 8) * ceilDiv(height, 8) * 16 * depth; + case Format::ASTC_RGBA_10X5: + case Format::ASTC_SRGBA_10X5: + return ceilDiv(width, 10) * ceilDiv(height, 5) * 16 * depth; + case Format::ASTC_RGBA_10X6: + case Format::ASTC_SRGBA_10X6: + return ceilDiv(width, 10) * ceilDiv(height, 6) * 16 * depth; + case Format::ASTC_RGBA_10X8: + case Format::ASTC_SRGBA_10X8: + return ceilDiv(width, 10) * ceilDiv(height, 8) * 16 * depth; + case Format::ASTC_RGBA_10X10: + case Format::ASTC_SRGBA_10X10: + return ceilDiv(width, 10) * ceilDiv(height, 10) * 16 * depth; + case Format::ASTC_RGBA_12X10: + case Format::ASTC_SRGBA_12X10: + return ceilDiv(width, 12) * ceilDiv(height, 10) * 16 * depth; + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_12X12: + return ceilDiv(width, 12) * ceilDiv(height, 12) * 16 * depth; + default: + return 0; } } @@ -316,12 +314,11 @@ const uint GFX_TYPE_SIZES[] = { 4, // SAMPLER_CUBE }; -uint FormatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips) { - +uint formatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips) { uint size = 0; for (uint i = 0; i < mips; ++i) { - size += FormatSize(format, width, height, depth); + size += formatSize(format, width, height, depth); width = std::max(width >> 1, 1U); height = std::max(height >> 1, 1U); } diff --git a/native/cocos/renderer/gfx-base/GFXDef.h b/native/cocos/renderer/gfx-base/GFXDef.h index 0f21f44c2a..c121c00fff 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.h +++ b/native/cocos/renderer/gfx-base/GFXDef.h @@ -55,11 +55,11 @@ enum class VsyncMode { }; struct DeviceInfo { - uintptr_t windowHandle = 0; - uint width = 0; - uint height = 0; - uint nativeWidth = 0; - uint nativeHeight = 0; + uintptr_t windowHandle = 0U; + uint width = 0U; + uint height = 0U; + uint nativeWidth = 0U; + uint nativeHeight = 0U; BindingMappingInfo bindingMappingInfo; }; @@ -72,14 +72,14 @@ struct ContextInfo { extern const DescriptorType DESCRIPTOR_BUFFER_TYPE; extern const DescriptorType DESCRIPTOR_TEXTURE_TYPE; extern const DescriptorType DESCRIPTOR_DYNAMIC_TYPE; -extern const uint DRAW_INFO_SIZE; +extern const uint DRAW_INFO_SIZE; extern const FormatInfo GFX_FORMAT_INFOS[]; extern const uint GFX_TYPE_SIZES[]; -extern uint FormatSize(Format format, uint width, uint height, uint depth); +extern uint formatSize(Format format, uint width, uint height, uint depth); -extern uint FormatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips); +extern uint formatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp index 5f4b40f383..217182c51d 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp @@ -36,10 +36,9 @@ DescriptorSet::DescriptorSet() : GFXObject(ObjectType::DESCRIPTOR_SET) { } -DescriptorSet::~DescriptorSet() { -} +DescriptorSet::~DescriptorSet() = default; -void DescriptorSet::initialize(const DescriptorSetInfo& info) { +void DescriptorSet::initialize(const DescriptorSetInfo &info) { CCASSERT(info.layout, "Invalid set layout"); _layout = info.layout; diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp index 0c77c63db7..0980da0787 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp @@ -35,18 +35,17 @@ DescriptorSetLayout::DescriptorSetLayout() : GFXObject(ObjectType::DESCRIPTOR_SET_LAYOUT) { } -DescriptorSetLayout::~DescriptorSetLayout() { -} +DescriptorSetLayout::~DescriptorSetLayout() = default; void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { _bindings = info.bindings; uint bindingCount = _bindings.size(); - _descriptorCount = 0u; + _descriptorCount = 0U; if (bindingCount) { - uint maxBinding = 0u; + uint maxBinding = 0U; vector flattenedIndices(bindingCount); - for (uint i = 0u; i < bindingCount; i++) { + for (uint i = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; flattenedIndices[i] = _descriptorCount; _descriptorCount += binding.count; @@ -55,7 +54,7 @@ void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { + for (uint i = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; _bindingIndices[binding.binding] = i; _descriptorIndices[binding.binding] = flattenedIndices[i]; @@ -69,7 +68,7 @@ void DescriptorSetLayout::destroy() { doDestroy(); _bindings.clear(); - _descriptorCount = 0u; + _descriptorCount = 0U; _bindingIndices.clear(); _descriptorIndices.clear(); } diff --git a/native/cocos/renderer/gfx-base/GFXDevice.cpp b/native/cocos/renderer/gfx-base/GFXDevice.cpp index 58e52a6c4b..b2323d5866 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.cpp +++ b/native/cocos/renderer/gfx-base/GFXDevice.cpp @@ -32,19 +32,19 @@ namespace cc { namespace gfx { -Device *Device::_instance = nullptr; +Device *Device::instance = nullptr; Device *Device::getInstance() { - return Device::_instance; + return Device::instance; } Device::Device() { - Device::_instance = this; + Device::instance = this; memset(_features, 0, sizeof(_features)); } Device::~Device() { - Device::_instance = nullptr; + Device::instance = nullptr; } Format Device::getColorFormat() const { @@ -78,7 +78,7 @@ void Device::destroy() { _bindingMappingInfo.bufferOffsets.clear(); _bindingMappingInfo.samplerOffsets.clear(); - _width = _height = _nativeWidth = _nativeHeight = _windowHandle = 0u; + _width = _height = _nativeWidth = _nativeHeight = _windowHandle = 0U; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index b9399e5b0a..013fdf6254 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -49,7 +49,7 @@ class CC_DLL Device : public Object { public: static Device *getInstance(); - virtual ~Device(); + ~Device() override; bool initialize(const DeviceInfo &info); void destroy(); @@ -96,7 +96,7 @@ public: inline Queue * getQueue() const { return _queue; } inline CommandBuffer * getCommandBuffer() const { return _cmdBuff; } inline const DeviceCaps &getCapabilities() const { return _caps; } - inline API getGfxAPI() const { return _API; } + inline API getGfxAPI() const { return _api; } inline const String & getDeviceName() const { return _deviceName; } inline const String & getRenderer() const { return _renderer; } inline const String & getVendor() const { return _vendor; } @@ -108,7 +108,7 @@ public: Format getDepthStencilFormat() const; protected: - static Device *_instance; + static Device *instance; friend class DeviceAgent; friend class DeviceValidator; @@ -146,7 +146,7 @@ protected: inline Context *getContext() const { return _context; } - API _API = API::UNKNOWN; + API _api = API::UNKNOWN; SurfaceTransform _transform = SurfaceTransform::IDENTITY; String _deviceName; String _renderer; @@ -162,9 +162,9 @@ protected: Context * _context = nullptr; Queue * _queue = nullptr; CommandBuffer * _cmdBuff = nullptr; - uint _numDrawCalls = 0u; - uint _numInstances = 0u; - uint _numTriangles = 0u; + uint _numDrawCalls = 0U; + uint _numInstances = 0U; + uint _numTriangles = 0U; BindingMappingInfo _bindingMappingInfo; DeviceCaps _caps; }; @@ -274,15 +274,15 @@ TextureBarrier *Device::createTextureBarrier(const TextureBarrierInfo &info) { } void Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - copyBuffersToTexture(buffers.data(), dst, regions.data(), static_cast(regions.size())); + copyBuffersToTexture(buffers.data(), dst, regions.data(), utils::toUint(regions.size())); } void Device::flushCommands(const vector &cmdBuffs) { - flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); + flushCommands(cmdBuffs.data(), utils::toUint(cmdBuffs.size())); } void Device::flushCommandsForJS(const vector &cmdBuffs) { - flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); + flushCommands(cmdBuffs.data(), utils::toUint(cmdBuffs.size())); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp index 749e611cd5..4fe15d6d61 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp @@ -35,19 +35,18 @@ Framebuffer::Framebuffer() : GFXObject(ObjectType::FRAMEBUFFER) { } -Framebuffer::~Framebuffer() { -} +Framebuffer::~Framebuffer() = default; uint Framebuffer::computeHash(const FramebufferInfo &info) { uint seed = info.colorTextures.size() + info.colorMipmapLevels.size() + 2; for (const Texture *attachment : info.colorTextures) { - seed ^= (uint)attachment->getTextureID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= attachment->getTextureID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (uint level : info.colorMipmapLevels) { - seed ^= (uint)level + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= level + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - seed ^= (uint)info.depthStencilTexture->getTextureID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilMipmapLevel + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= info.depthStencilTexture->getTextureID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilMipmapLevel) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } diff --git a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp index 0ef1059f11..26655ce343 100644 --- a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp @@ -35,17 +35,16 @@ GlobalBarrier::GlobalBarrier() : GFXObject(ObjectType::GLOBAL_BARRIER) { } -GlobalBarrier::~GlobalBarrier() { -} +GlobalBarrier::~GlobalBarrier() = default; uint GlobalBarrier::computeHash(const GlobalBarrierInfo &info) { uint seed = info.prevAccesses.size() + info.nextAccesses.size(); for (const AccessType type : info.prevAccesses) { - seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const AccessType type : info.nextAccesses) { - seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; diff --git a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h index 655500b354..594f38d73f 100644 --- a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h +++ b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h @@ -33,7 +33,7 @@ namespace gfx { class CC_DLL GlobalBarrier : public GFXObject { public: GlobalBarrier(); - virtual ~GlobalBarrier(); + ~GlobalBarrier() override; static uint computeHash(const GlobalBarrierInfo &info); @@ -44,7 +44,9 @@ protected: virtual void doInit(const GlobalBarrierInfo &info) {} - void initialize(const GlobalBarrierInfo &info) { _info = info; doInit(info); } + void initialize(const GlobalBarrierInfo &info) { + _info = info; doInit(info); + } GlobalBarrierInfo _info; }; diff --git a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp index f78a4ee58a..830ecf15f4 100644 --- a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp +++ b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp @@ -36,8 +36,7 @@ InputAssembler::InputAssembler() : GFXObject(ObjectType::INPUT_ASSEMBLER) { } -InputAssembler::~InputAssembler() { -} +InputAssembler::~InputAssembler() = default; void InputAssembler::extractDrawInfo(DrawInfo &drawInfo) const { drawInfo.vertexCount = _vertexCount; @@ -55,13 +54,13 @@ uint InputAssembler::computeAttributesHash() const { std::size_t seed = _attributes.size() * 6; for (const auto &attribute : _attributes) { seed ^= std::hash{}(attribute.name) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.isNormalized + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.stream + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.isInstanced + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.location + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - return static_cast(seed); + return seed; } void InputAssembler::initialize(const InputAssemblerInfo &info) { @@ -73,7 +72,7 @@ void InputAssembler::initialize(const InputAssemblerInfo &info) { if (_indexBuffer) { _indexCount = _indexBuffer->getCount(); _firstIndex = 0; - } else if (_vertexBuffers.size()) { + } else if (!_vertexBuffers.empty()) { _vertexCount = _vertexBuffers[0]->getCount(); _firstVertex = 0; _vertexOffset = 0; @@ -88,7 +87,7 @@ void InputAssembler::destroy() { _vertexBuffers.clear(); _indexBuffer = nullptr; _indirectBuffer = nullptr; - _indexCount = _firstIndex = _vertexCount = _firstVertex = _vertexOffset = _attributesHash = 0u; + _indexCount = _firstIndex = _vertexCount = _firstVertex = _vertexOffset = _attributesHash = 0U; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp b/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp index fd077ecccb..c16fd5545f 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp @@ -35,8 +35,7 @@ PipelineLayout::PipelineLayout() : GFXObject(ObjectType::PIPELINE_LAYOUT) { } -PipelineLayout::~PipelineLayout() { -} +PipelineLayout::~PipelineLayout() = default; void PipelineLayout::initialize(const PipelineLayoutInfo& info) { _setLayouts = info.setLayouts; diff --git a/native/cocos/renderer/gfx-base/GFXPipelineState.cpp b/native/cocos/renderer/gfx-base/GFXPipelineState.cpp index d751e6ebb9..a369efae27 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineState.cpp +++ b/native/cocos/renderer/gfx-base/GFXPipelineState.cpp @@ -35,8 +35,7 @@ PipelineState::PipelineState() : GFXObject(ObjectType::PIPELINE_STATE) { } -PipelineState::~PipelineState() { -} +PipelineState::~PipelineState() = default; void PipelineState::initialize(const PipelineStateInfo &info) { _primitive = info.primitive; diff --git a/native/cocos/renderer/gfx-base/GFXQueue.cpp b/native/cocos/renderer/gfx-base/GFXQueue.cpp index fb5f36e403..c3d402f79e 100644 --- a/native/cocos/renderer/gfx-base/GFXQueue.cpp +++ b/native/cocos/renderer/gfx-base/GFXQueue.cpp @@ -35,8 +35,7 @@ Queue::Queue() : GFXObject(ObjectType::QUEUE) { } -Queue::~Queue() { -} +Queue::~Queue() = default; void Queue::initialize(const QueueInfo& info) { _type = info.type; diff --git a/native/cocos/renderer/gfx-base/GFXQueue.h b/native/cocos/renderer/gfx-base/GFXQueue.h index da8eb1c164..49d3945503 100644 --- a/native/cocos/renderer/gfx-base/GFXQueue.h +++ b/native/cocos/renderer/gfx-base/GFXQueue.h @@ -26,6 +26,7 @@ #pragma once #include "GFXObject.h" +#include "base/Utils.h" namespace cc { namespace gfx { @@ -33,16 +34,16 @@ namespace gfx { class CC_DLL Queue : public GFXObject { public: Queue(); - virtual ~Queue(); + ~Queue() override; void initialize(const QueueInfo &info); void destroy(); virtual void submit(CommandBuffer *const *cmdBuffs, uint count) = 0; - CC_INLINE void submit(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), static_cast(cmdBuffs.size())); } + CC_INLINE void submit(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), utils::toUint(cmdBuffs.size())); } - CC_INLINE void submitForJS(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), static_cast(cmdBuffs.size())); } + CC_INLINE void submitForJS(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), utils::toUint(cmdBuffs.size())); } CC_INLINE QueueType getType() const { return _type; } @@ -50,7 +51,7 @@ protected: virtual void doInit(const QueueInfo &info) = 0; virtual void doDestroy() = 0; - QueueType _type = QueueType::GRAPHICS; + QueueType _type = QueueType::GRAPHICS; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp index 035a5f0b09..d408d32a41 100644 --- a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp +++ b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp @@ -35,14 +35,13 @@ RenderPass::RenderPass() : GFXObject(ObjectType::RENDER_PASS) { } -RenderPass::~RenderPass() { -} +RenderPass::~RenderPass() = default; // Based on render pass compatibility uint RenderPass::computeHash() { // https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector uint seed = 0; - if (_subpasses.size()) { + if (!_subpasses.empty()) { for (const SubpassInfo &subPass : _subpasses) { for (const uint iaIndex : subPass.inputs) { if (iaIndex >= _colorAttachments.size()) break; @@ -68,41 +67,41 @@ uint RenderPass::computeHash() { for (const uint iaIndex : subPass.inputs) { if (iaIndex >= _colorAttachments.size()) break; const ColorAttachment &ia = _colorAttachments[iaIndex]; - seed ^= (uint)(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)ia.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ia.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const uint caIndex : subPass.colors) { if (caIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[caIndex]; - seed ^= (uint)(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)ca.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const uint raIndex : subPass.resolves) { if (raIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[raIndex]; - seed ^= (uint)(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)ca.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const uint paIndex : subPass.preserves) { if (paIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[paIndex]; - seed ^= (uint)(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)ca.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } if (subPass.depthStencil < _colorAttachments.size()) { const ColorAttachment &ds = _colorAttachments[subPass.depthStencil]; - seed ^= (uint)(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)ds.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } } } else { seed = _colorAttachments.size() * 2 + 2; for (const ColorAttachment &colorAttachment : _colorAttachments) { - seed ^= (uint)(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)colorAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(colorAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - seed ^= (uint)(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)_depthStencilAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(_depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; @@ -110,19 +109,19 @@ uint RenderPass::computeHash() { uint RenderPass::computeHash(const RenderPassInfo &info) { static auto computeAttachmentHash = [](const ColorAttachment &attachment, uint &seed) { - seed ^= (uint)attachment.format + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)attachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)attachment.loadOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)attachment.storeOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.loadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.storeOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); for (AccessType type : attachment.beginAccesses) { - seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (AccessType type : attachment.endAccesses) { - seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; uint seed = 0; - if (info.subpasses.size()) { + if (!info.subpasses.empty()) { for (const SubpassInfo &subPass : info.subpasses) { for (const uint iaIndex : subPass.inputs) { if (iaIndex >= info.colorAttachments.size()) break; @@ -179,17 +178,17 @@ uint RenderPass::computeHash(const RenderPassInfo &info) { for (const ColorAttachment &ca : info.colorAttachments) { computeAttachmentHash(ca, seed); } - seed ^= (uint)info.depthStencilAttachment.format + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilAttachment.sampleCount + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilAttachment.depthLoadOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilAttachment.depthStoreOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilAttachment.stencilLoadOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)info.depthStencilAttachment.stencilStoreOp + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.depthLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.depthStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.stencilLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.depthStencilAttachment.stencilStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); for (AccessType type : info.depthStencilAttachment.beginAccesses) { - seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (AccessType type : info.depthStencilAttachment.endAccesses) { - seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } } @@ -210,7 +209,7 @@ void RenderPass::destroy() { _colorAttachments.clear(); _subpasses.clear(); - _hash = 0u; + _hash = 0U; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXSampler.cpp b/native/cocos/renderer/gfx-base/GFXSampler.cpp index 3de43697a9..87567f715b 100644 --- a/native/cocos/renderer/gfx-base/GFXSampler.cpp +++ b/native/cocos/renderer/gfx-base/GFXSampler.cpp @@ -33,14 +33,13 @@ namespace gfx { Sampler::Sampler() : GFXObject(ObjectType::SAMPLER) { - _borderColor.x = 0.0f; - _borderColor.y = 0.0f; - _borderColor.z = 0.0f; - _borderColor.w = 0.0f; + _borderColor.x = 0.0F; + _borderColor.y = 0.0F; + _borderColor.z = 0.0F; + _borderColor.w = 0.0F; } -Sampler::~Sampler() { -} +Sampler::~Sampler() = default; void Sampler::initialize(const SamplerInfo &info) { _minFilter = info.minFilter; diff --git a/native/cocos/renderer/gfx-base/GFXShader.cpp b/native/cocos/renderer/gfx-base/GFXShader.cpp index dd6f90e161..c83ec04f2c 100644 --- a/native/cocos/renderer/gfx-base/GFXShader.cpp +++ b/native/cocos/renderer/gfx-base/GFXShader.cpp @@ -37,8 +37,7 @@ Shader::Shader() _shaderID = generateShaderID(); } -Shader::~Shader() { -} +Shader::~Shader() = default; void Shader::initialize(const ShaderInfo &info) { _name = info.name; diff --git a/native/cocos/renderer/gfx-base/GFXTexture.cpp b/native/cocos/renderer/gfx-base/GFXTexture.cpp index 0593f6376f..0c79f66260 100644 --- a/native/cocos/renderer/gfx-base/GFXTexture.cpp +++ b/native/cocos/renderer/gfx-base/GFXTexture.cpp @@ -37,21 +37,20 @@ Texture::Texture() _textureID = generateTextureID(); } -Texture::~Texture() { -} +Texture::~Texture() = default; uint Texture::computeHash(const TextureInfo &info) { uint seed = 10; - seed ^= (uint)(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.width) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.height) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.layerCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.levelCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.samples) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (uint)(info.depth) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.width) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.height) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.layerCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.levelCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.samples) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.depth) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } @@ -66,7 +65,7 @@ void Texture::initialize(const TextureInfo &info) { _levelCount = info.levelCount; _samples = info.samples; _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); + _size = formatSize(_format, _width, _height, _depth); Device::getInstance()->getMemoryStatus().textureSize += _size; @@ -88,7 +87,7 @@ void Texture::initialize(const TextureViewInfo &info) { _depth = info.texture->getDepth(); _samples = info.texture->getSamples(); _flags = info.texture->getFlags(); - _size = FormatSize(_format, _width, _height, _depth); + _size = formatSize(_format, _width, _height, _depth); _isTextureView = true; doInit(info); @@ -105,7 +104,7 @@ void Texture::destroy() { void Texture::resize(uint width, uint height) { if (_width != width || _height != height) { - uint size = FormatSize(_format, width, height, _depth); + uint size = formatSize(_format, width, height, _depth); doResize(width, height, size); Device::getInstance()->getMemoryStatus().textureSize -= _size; diff --git a/native/cocos/renderer/gfx-base/GFXTexture.h b/native/cocos/renderer/gfx-base/GFXTexture.h index fdcfd96f3b..c6b12c2832 100644 --- a/native/cocos/renderer/gfx-base/GFXTexture.h +++ b/native/cocos/renderer/gfx-base/GFXTexture.h @@ -33,7 +33,7 @@ namespace gfx { class CC_DLL Texture : public GFXObject { public: Texture(); - virtual ~Texture(); + ~Texture() override; static uint computeHash(const TextureInfo &info); @@ -58,8 +58,8 @@ public: protected: static uint generateTextureID() noexcept { - static uint _idGen = 0; - return _idGen++; + static uint idGen = 0; + return idGen++; } virtual void doInit(const TextureInfo &info) = 0; @@ -71,14 +71,14 @@ protected: TextureType _type = TextureType::TEX2D; TextureUsage _usage = TextureUsageBit::NONE; Format _format = Format::UNKNOWN; - uint _width = 0u; - uint _height = 0u; - uint _depth = 1u; - uint _baseLevel = 0u; - uint _levelCount = 1u; - uint _baseLayer = 0u; - uint _layerCount = 1u; - uint _size = 0u; + uint _width = 0U; + uint _height = 0U; + uint _depth = 1U; + uint _baseLevel = 0U; + uint _levelCount = 1U; + uint _baseLayer = 0U; + uint _layerCount = 1U; + uint _size = 0U; SampleCount _samples = SampleCount::X1; TextureFlags _flags = TextureFlagBit::NONE; bool _isTextureView = false; diff --git a/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp b/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp index 0030e333f9..ea9e9c9970 100644 --- a/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp @@ -36,22 +36,21 @@ TextureBarrier::TextureBarrier() : GFXObject(ObjectType::TEXTURE_BARRIER) { } -TextureBarrier::~TextureBarrier() { -} +TextureBarrier::~TextureBarrier() = default; uint TextureBarrier::computeHash(const TextureBarrierInfo &info) { uint seed = info.prevAccesses.size() + info.nextAccesses.size() + 3; for (const AccessType type : info.prevAccesses) { - seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const AccessType type : info.nextAccesses) { - seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } seed ^= info.discardContents + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (info.srcQueue ? (uint)info.srcQueue->getType() : 0u) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (info.dstQueue ? (uint)info.dstQueue->getType() : 0u) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.srcQueue ? static_cast(info.srcQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.dstQueue ? static_cast(info.dstQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp index f77a64fd8e..02ef8de080 100644 --- a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp @@ -82,7 +82,7 @@ void EmptyCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { void EmptyCommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) { } -void EmptyCommandBuffer::draw(InputAssembler *ia) { +void EmptyCommandBuffer::draw(const DrawInfo &info) { } void EmptyCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h index 86ece9d477..d62b5a270c 100644 --- a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h @@ -47,7 +47,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; diff --git a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h index a05ff4562d..79c886ef60 100644 --- a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h +++ b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h @@ -25,6 +25,8 @@ #pragma once +#include +#include #include "base/CachedArray.h" namespace cc { @@ -48,8 +50,8 @@ public: GLESCmdType type; uint refCount = 0; - GLESCmd(GLESCmdType _type) : type(_type) {} - virtual ~GLESCmd() {} + explicit GLESCmd(GLESCmdType type) : type(type) {} + ~GLESCmd() override = default; virtual void clear() = 0; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp index 70e5bb7a82..2b8d4a4602 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES2Buffer::GLES2Buffer() -: Buffer() { -} +GLES2Buffer::GLES2Buffer() = default; GLES2Buffer::~GLES2Buffer() { destroy(); } -void GLES2Buffer::doInit(const BufferInfo &info) { +void GLES2Buffer::doInit(const BufferInfo & /*info*/) { _gpuBuffer = CC_NEW(GLES2GPUBuffer); _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; @@ -52,11 +50,11 @@ void GLES2Buffer::doInit(const BufferInfo &info) { _gpuBuffer->indirects.resize(_count); } - GLES2CmdFuncCreateBuffer(GLES2Device::getInstance(), _gpuBuffer); + cmdFuncGLES2CreateBuffer(GLES2Device::getInstance(), _gpuBuffer); } void GLES2Buffer::doInit(const BufferViewInfo &info) { - GLES2Buffer *buffer = (GLES2Buffer *)info.buffer; + auto *buffer = static_cast(info.buffer); _gpuBufferView = CC_NEW(GLES2GPUBufferView); _gpuBufferView->gpuBuffer = buffer->gpuBuffer(); _gpuBufferView->range = _size; @@ -65,7 +63,7 @@ void GLES2Buffer::doInit(const BufferViewInfo &info) { void GLES2Buffer::doDestroy() { if (_gpuBuffer) { - GLES2CmdFuncDestroyBuffer(GLES2Device::getInstance(), _gpuBuffer); + cmdFuncGLES2DestroyBuffer(GLES2Device::getInstance(), _gpuBuffer); CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; } @@ -76,11 +74,11 @@ void GLES2Buffer::doDestroy() { void GLES2Buffer::doResize(uint size, uint count) { _gpuBuffer->size = size; _gpuBuffer->count = count; - GLES2CmdFuncResizeBuffer(GLES2Device::getInstance(), _gpuBuffer); + cmdFuncGLES2ResizeBuffer(GLES2Device::getInstance(), _gpuBuffer); } void GLES2Buffer::update(void *buffer, uint size) { - GLES2CmdFuncUpdateBuffer(GLES2Device::getInstance(), _gpuBuffer, buffer, 0u, size); + cmdFuncGLES2UpdateBuffer(GLES2Device::getInstance(), _gpuBuffer, buffer, 0U, size); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp index 3e2aa6f8a3..ac755a1047 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -38,19 +38,15 @@ namespace cc { namespace gfx { -GLES2CommandBuffer::GLES2CommandBuffer() -: CommandBuffer() { -} - GLES2CommandBuffer::~GLES2CommandBuffer() { destroy(); } void GLES2CommandBuffer::doInit(const CommandBufferInfo &info) { - _type = info.type; + _type = info.type; _queue = info.queue; - _cmdAllocator = CC_NEW(GLES2GPUCommandAllocator); + _cmdAllocator = CC_NEW(GLES2GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES2CmdPackage); size_t setCount = GLES2Device::getInstance()->bindingMappingInfo().bufferOffsets.size(); @@ -59,6 +55,8 @@ void GLES2CommandBuffer::doInit(const CommandBufferInfo &info) { } void GLES2CommandBuffer::doDestroy() { + if (!_cmdAllocator) return; + _cmdAllocator->clearCmds(_curCmdPackage); CC_SAFE_DELETE(_curCmdPackage); @@ -77,10 +75,10 @@ void GLES2CommandBuffer::doDestroy() { } _cmdAllocator->reset(); - CC_DELETE(_cmdAllocator); + CC_SAFE_DELETE(_cmdAllocator); } -void GLES2CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void GLES2CommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { _cmdAllocator->clearCmds(_curCmdPackage); _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; @@ -93,7 +91,7 @@ void GLES2CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer void GLES2CommandBuffer::end() { if (_isStateInvalid) { - BindStates(); + bindStates(); } _isInRenderPass = false; @@ -106,18 +104,18 @@ void GLES2CommandBuffer::end() { } } -void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { +void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { _isInRenderPass = true; GLES2CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc(); - cmd->gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); - cmd->gpuFBO = static_cast(fbo)->gpuFBO(); - cmd->renderArea = renderArea; - cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size(); + cmd->gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); + cmd->gpuFBO = static_cast(fbo)->gpuFBO(); + cmd->renderArea = renderArea; + cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size(); for (size_t i = 0; i < cmd->numClearColors; ++i) { cmd->clearColors[i] = colors[i]; } - cmd->clearDepth = depth; + cmd->clearDepth = depth; cmd->clearStencil = stencil; _curCmdPackage->beginRenderPassCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::BEGIN_RENDER_PASS); @@ -132,7 +130,7 @@ void GLES2CommandBuffer::bindPipelineState(PipelineState *pso) { GLES2GPUPipelineState *gpuPipelineState = static_cast(pso)->gpuPipelineState(); if (_curGPUPipelineState != gpuPipelineState) { _curGPUPipelineState = gpuPipelineState; - _isStateInvalid = true; + _isStateInvalid = true; } } @@ -142,7 +140,7 @@ void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSe GLES2GPUDescriptorSet *gpuDescriptorSet = static_cast(descriptorSet)->gpuDescriptorSet(); if (_curGPUDescriptorSets[set] != gpuDescriptorSet) { _curGPUDescriptorSets[set] = gpuDescriptorSet; - _isStateInvalid = true; + _isStateInvalid = true; } if (dynamicOffsetCount) { _curDynamicOffsets[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); @@ -152,7 +150,7 @@ void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSe void GLES2CommandBuffer::bindInputAssembler(InputAssembler *ia) { _curGPUInputAssember = static_cast(ia)->gpuInputAssembler(); - _isStateInvalid = true; + _isStateInvalid = true; } void GLES2CommandBuffer::setViewport(const Viewport &vp) { @@ -163,7 +161,7 @@ void GLES2CommandBuffer::setViewport(const Viewport &vp) { (_curViewport.height != vp.height) || math::IsNotEqualF(_curViewport.minDepth, vp.minDepth) || math::IsNotEqualF(_curViewport.maxDepth, vp.maxDepth)) { - _curViewport = vp; + _curViewport = vp; _isStateInvalid = true; } } @@ -173,14 +171,14 @@ void GLES2CommandBuffer::setScissor(const Rect &rect) { (_curScissor.y != rect.y) || (_curScissor.width != rect.width) || (_curScissor.height != rect.height)) { - _curScissor = rect; + _curScissor = rect; _isStateInvalid = true; } } void GLES2CommandBuffer::setLineWidth(float width) { if (math::IsNotEqualF(_curLineWidth, width)) { - _curLineWidth = width; + _curLineWidth = width; _isStateInvalid = true; } } @@ -190,9 +188,9 @@ void GLES2CommandBuffer::setDepthBias(float constant, float clamp, float slope) math::IsNotEqualF(_curDepthBias.clamp, clamp) || math::IsNotEqualF(_curDepthBias.slope, slope)) { _curDepthBias.constant = constant; - _curDepthBias.clamp = clamp; - _curDepthBias.slope = slope; - _isStateInvalid = true; + _curDepthBias.clamp = clamp; + _curDepthBias.slope = slope; + _isStateInvalid = true; } } @@ -205,7 +203,7 @@ void GLES2CommandBuffer::setBlendConstants(const Color &constants) { _curBlendConstants.y = constants.y; _curBlendConstants.z = constants.z; _curBlendConstants.w = constants.w; - _isStateInvalid = true; + _isStateInvalid = true; } } @@ -214,16 +212,16 @@ void GLES2CommandBuffer::setDepthBound(float minBounds, float maxBounds) { math::IsNotEqualF(_curDepthBounds.maxBounds, maxBounds)) { _curDepthBounds.minBounds = minBounds; _curDepthBounds.maxBounds = maxBounds; - _isStateInvalid = true; + _isStateInvalid = true; } } void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { if ((_curStencilWriteMask.face != face) || (_curStencilWriteMask.writeMask != mask)) { - _curStencilWriteMask.face = face; + _curStencilWriteMask.face = face; _curStencilWriteMask.writeMask = mask; - _isStateInvalid = true; + _isStateInvalid = true; } } @@ -231,38 +229,35 @@ void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint m if ((_curStencilCompareMask.face != face) || (_curStencilCompareMask.refrence != ref) || (_curStencilCompareMask.compareMask != mask)) { - _curStencilCompareMask.face = face; - _curStencilCompareMask.refrence = ref; + _curStencilCompareMask.face = face; + _curStencilCompareMask.refrence = ref; _curStencilCompareMask.compareMask = mask; - _isStateInvalid = true; + _isStateInvalid = true; } } -void GLES2CommandBuffer::draw(InputAssembler *ia) { +void GLES2CommandBuffer::draw(const DrawInfo &info) { if (_isStateInvalid) { - BindStates(); + bindStates(); } GLES2CmdDraw *cmd = _cmdAllocator->drawCmdPool.alloc(); - static_cast(ia)->ExtractCmdDraw(cmd); + cmd->drawInfo = info; _curCmdPackage->drawCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::DRAW); ++_numDrawCalls; - _numInstances += ia->getInstanceCount(); + _numInstances += info.instanceCount; + uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; if (_curGPUPipelineState) { switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { - if (ia->getIndexBuffer() == nullptr) { - _numTriangles += ia->getVertexCount() / 3 * std::max(ia->getInstanceCount(), 1U); - } else { - _numTriangles += ia->getIndexCount() / 3 * std::max(ia->getInstanceCount(), 1U); - } + _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); break; } case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: { - _numTriangles += (ia->getVertexCount() - 2) * std::max(ia->getInstanceCount(), 1U); + _numTriangles += (indexCount - 2) * std::max(info.instanceCount, 1U); break; } default: @@ -275,9 +270,9 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) GLES2GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { GLES2CmdUpdateBuffer *cmd = _cmdAllocator->updateBufferCmdPool.alloc(); - cmd->gpuBuffer = gpuBuffer; - cmd->size = size; - cmd->buffer = (uint8_t *)data; + cmd->gpuBuffer = gpuBuffer; + cmd->size = size; + cmd->buffer = static_cast(data); _curCmdPackage->updateBufferCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::UPDATE_BUFFER); @@ -288,10 +283,10 @@ void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex GLES2GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { GLES2CmdCopyBufferToTexture *cmd = _cmdAllocator->copyBufferToTextureCmdPool.alloc(); - cmd->gpuTexture = gpuTexture; - cmd->regions = regions; - cmd->count = count; - cmd->buffers = buffers; + cmd->gpuTexture = gpuTexture; + cmd->regions = regions; + cmd->count = count; + cmd->buffers = buffers; _curCmdPackage->copyBufferToTextureCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::COPY_BUFFER_TO_TEXTURE); @@ -305,7 +300,7 @@ void GLES2CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) CCASSERT(false, "Command 'execute' must be recorded in primary command buffers."); for (uint i = 0; i < count; ++i) { - GLES2CommandBuffer *cmdBuff = (GLES2CommandBuffer *)cmdBuffs[i]; + auto * cmdBuff = static_cast(cmdBuffs[i]); GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); for (uint j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { @@ -349,17 +344,17 @@ void GLES2CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) } } -void GLES2CommandBuffer::BindStates() { +void GLES2CommandBuffer::bindStates() { GLES2CmdBindStates *cmd = _cmdAllocator->bindStatesCmdPool.alloc(); - cmd->gpuPipelineState = _curGPUPipelineState; + cmd->gpuPipelineState = _curGPUPipelineState; cmd->gpuInputAssembler = _curGPUInputAssember; cmd->gpuDescriptorSets = _curGPUDescriptorSets; if (_curGPUPipelineState) { vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; cmd->dynamicOffsets.resize(_curGPUPipelineState->gpuPipelineLayout->dynamicOffsetCount); - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); @@ -367,16 +362,16 @@ void GLES2CommandBuffer::BindStates() { } } - cmd->viewport = _curViewport; - cmd->scissor = _curScissor; - cmd->lineWidth = _curLineWidth; - cmd->depthBias = _curDepthBias; - cmd->blendConstants.x = _curBlendConstants.x; - cmd->blendConstants.y = _curBlendConstants.y; - cmd->blendConstants.z = _curBlendConstants.z; - cmd->blendConstants.w = _curBlendConstants.w; - cmd->depthBounds = _curDepthBounds; - cmd->stencilWriteMask = _curStencilWriteMask; + cmd->viewport = _curViewport; + cmd->scissor = _curScissor; + cmd->lineWidth = _curLineWidth; + cmd->depthBias = _curDepthBias; + cmd->blendConstants.x = _curBlendConstants.x; + cmd->blendConstants.y = _curBlendConstants.y; + cmd->blendConstants.z = _curBlendConstants.z; + cmd->blendConstants.w = _curBlendConstants.w; + cmd->depthBounds = _curDepthBounds; + cmd->stencilWriteMask = _curStencilWriteMask; cmd->stencilCompareMask = _curStencilCompareMask; _curCmdPackage->bindStatesCmds.push(cmd); diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h index ca0a7ec31d..ba26cba0b3 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h @@ -25,8 +25,8 @@ #pragma once -#include "gfx-base/GFXCommandBuffer.h" #include "GLES2Commands.h" +#include "gfx-base/GFXCommandBuffer.h" namespace cc { namespace gfx { @@ -35,8 +35,8 @@ class GLES2GPUCommandAllocator; class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer { public: - GLES2CommandBuffer(); - ~GLES2CommandBuffer(); + GLES2CommandBuffer() = default; + ~GLES2CommandBuffer() override; friend class GLES2Queue; @@ -55,7 +55,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; @@ -67,26 +67,26 @@ protected: void doInit(const CommandBufferInfo &info) override; void doDestroy() override; - void BindStates(); + virtual void bindStates(); - GLES2GPUCommandAllocator *_cmdAllocator = nullptr; - GLES2CmdPackage *_curCmdPackage = nullptr; - queue _pendingPackages, _freePackages; + GLES2GPUCommandAllocator *_cmdAllocator = nullptr; + GLES2CmdPackage * _curCmdPackage = nullptr; + queue _pendingPackages, _freePackages; - bool _isInRenderPass = false; - GLES2GPUPipelineState *_curGPUPipelineState = nullptr; + bool _isInRenderPass = false; + GLES2GPUPipelineState * _curGPUPipelineState = nullptr; vector _curGPUDescriptorSets; - vector> _curDynamicOffsets; - GLES2GPUInputAssembler *_curGPUInputAssember = nullptr; - Viewport _curViewport; - Rect _curScissor; - float _curLineWidth = 1.0f; - GLES2DepthBias _curDepthBias; - Color _curBlendConstants; - GLES2DepthBounds _curDepthBounds; - GLES2StencilWriteMask _curStencilWriteMask; - GLES2StencilCompareMask _curStencilCompareMask; - bool _isStateInvalid = false; + vector> _curDynamicOffsets; + GLES2GPUInputAssembler * _curGPUInputAssember = nullptr; + Viewport _curViewport; + Rect _curScissor; + float _curLineWidth = 1.0F; + GLES2DepthBias _curDepthBias; + Color _curBlendConstants; + GLES2DepthBounds _curDepthBounds; + GLES2StencilWriteMask _curStencilWriteMask; + GLES2StencilCompareMask _curStencilCompareMask; + bool _isStateInvalid = false; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp index 0f4096a380..af0d71bc66 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp @@ -35,60 +35,60 @@ namespace cc { namespace gfx { namespace { -GLenum MapGLInternalFormat(Format format) { +GLenum mapGLInternalFormat(Format format) { switch (format) { case Format::A8: return GL_ALPHA; case Format::L8: return GL_LUMINANCE; case Format::LA8: return GL_LUMINANCE_ALPHA; - case Format::R8: return GL_LUMINANCE; - case Format::R8SN: return GL_LUMINANCE; - case Format::R8UI: return GL_LUMINANCE; + case Format::R8: + case Format::R8SN: + case Format::R8UI: case Format::R8I: return GL_LUMINANCE; - case Format::RG8: return GL_LUMINANCE_ALPHA; - case Format::RG8SN: return GL_LUMINANCE_ALPHA; - case Format::RG8UI: return GL_LUMINANCE_ALPHA; + case Format::RG8: + case Format::RG8SN: + case Format::RG8UI: case Format::RG8I: return GL_LUMINANCE_ALPHA; - case Format::RGB8: return GL_RGB; - case Format::RGB8SN: return GL_RGB; - case Format::RGB8UI: return GL_RGB; + case Format::RGB8: + case Format::RGB8SN: + case Format::RGB8UI: case Format::RGB8I: return GL_RGB; - case Format::RGBA8: return GL_RGBA; - case Format::RGBA8SN: return GL_RGBA; - case Format::RGBA8UI: return GL_RGBA; + case Format::RGBA8: + case Format::RGBA8SN: + case Format::RGBA8UI: case Format::RGBA8I: return GL_RGBA; - case Format::R16I: return GL_LUMINANCE; - case Format::R16UI: return GL_LUMINANCE; + case Format::R16I: + case Format::R16UI: case Format::R16F: return GL_LUMINANCE; - case Format::RG16I: return GL_LUMINANCE_ALPHA; - case Format::RG16UI: return GL_LUMINANCE_ALPHA; + case Format::RG16I: + case Format::RG16UI: case Format::RG16F: return GL_LUMINANCE_ALPHA; - case Format::RGB16I: return GL_RGB; - case Format::RGB16UI: return GL_RGB; + case Format::RGB16I: + case Format::RGB16UI: case Format::RGB16F: return GL_RGB; - case Format::RGBA16I: return GL_RGBA; - case Format::RGBA16UI: return GL_RGBA; + case Format::RGBA16I: + case Format::RGBA16UI: case Format::RGBA16F: return GL_RGBA; - case Format::R32I: return GL_LUMINANCE; - case Format::R32UI: return GL_LUMINANCE; + case Format::R32I: + case Format::R32UI: case Format::R32F: return GL_LUMINANCE; - case Format::RG32I: return GL_LUMINANCE_ALPHA; - case Format::RG32UI: return GL_LUMINANCE_ALPHA; + case Format::RG32I: + case Format::RG32UI: case Format::RG32F: return GL_LUMINANCE_ALPHA; - case Format::RGB32I: return GL_RGB; - case Format::RGB32UI: return GL_RGB; + case Format::RGB32I: + case Format::RGB32UI: case Format::RGB32F: return GL_RGB; - case Format::RGBA32I: return GL_RGBA; - case Format::RGBA32UI: return GL_RGBA; #if CC_PLATFORM == CC_PLATFORM_WINDOWS case Format::RGBA32F: return GL_RGBA32F_EXT; // driver issue #else - case Format::RGBA32F: return GL_RGBA; + case Format::RGBA32F: #endif + case Format::RGBA32I: + case Format::RGBA32UI: return GL_RGBA; case Format::R5G6B5: return GL_RGB565; case Format::RGB5A1: return GL_RGB5_A1; case Format::RGBA4: return GL_RGBA4; - case Format::RGB10A2: return GL_RGB; - case Format::RGB10A2UI: return GL_RGB; + case Format::RGB10A2: + case Format::RGB10A2UI: case Format::R11G11B10F: return GL_RGB; case Format::D16: return GL_DEPTH_COMPONENT; case Format::D16S8: return GL_DEPTH_STENCIL_OES; @@ -115,35 +115,35 @@ GLenum MapGLInternalFormat(Format format) { case Format::PVRTC_RGB4: return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; case Format::PVRTC_RGBA4: return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - case Format::ASTC_RGBA_4x4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - case Format::ASTC_RGBA_5x4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - case Format::ASTC_RGBA_5x5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - case Format::ASTC_RGBA_6x5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - case Format::ASTC_RGBA_6x6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - case Format::ASTC_RGBA_8x5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - case Format::ASTC_RGBA_8x6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - case Format::ASTC_RGBA_8x8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - case Format::ASTC_RGBA_10x5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - case Format::ASTC_RGBA_10x6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - case Format::ASTC_RGBA_10x8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - case Format::ASTC_RGBA_10x10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - case Format::ASTC_RGBA_12x10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - case Format::ASTC_RGBA_12x12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + case Format::ASTC_RGBA_4X4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case Format::ASTC_RGBA_5X4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + case Format::ASTC_RGBA_5X5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + case Format::ASTC_RGBA_6X5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + case Format::ASTC_RGBA_6X6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + case Format::ASTC_RGBA_8X5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + case Format::ASTC_RGBA_8X6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + case Format::ASTC_RGBA_8X8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + case Format::ASTC_RGBA_10X5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + case Format::ASTC_RGBA_10X6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + case Format::ASTC_RGBA_10X8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + case Format::ASTC_RGBA_10X10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + case Format::ASTC_RGBA_12X10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + case Format::ASTC_RGBA_12X12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - case Format::ASTC_SRGBA_4x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - case Format::ASTC_SRGBA_5x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - case Format::ASTC_SRGBA_5x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - case Format::ASTC_SRGBA_6x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - case Format::ASTC_SRGBA_6x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - case Format::ASTC_SRGBA_8x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - case Format::ASTC_SRGBA_8x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - case Format::ASTC_SRGBA_8x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - case Format::ASTC_SRGBA_10x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - case Format::ASTC_SRGBA_10x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - case Format::ASTC_SRGBA_10x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - case Format::ASTC_SRGBA_10x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - case Format::ASTC_SRGBA_12x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - case Format::ASTC_SRGBA_12x12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; + case Format::ASTC_SRGBA_4X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + case Format::ASTC_SRGBA_5X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + case Format::ASTC_SRGBA_5X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + case Format::ASTC_SRGBA_6X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + case Format::ASTC_SRGBA_6X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + case Format::ASTC_SRGBA_8X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + case Format::ASTC_SRGBA_8X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + case Format::ASTC_SRGBA_8X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + case Format::ASTC_SRGBA_10X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + case Format::ASTC_SRGBA_10X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + case Format::ASTC_SRGBA_10X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + case Format::ASTC_SRGBA_10X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + case Format::ASTC_SRGBA_12X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + case Format::ASTC_SRGBA_12X12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; default: { CCASSERT(false, "Unsupported Format, convert to GL internal format failed."); @@ -152,7 +152,7 @@ GLenum MapGLInternalFormat(Format format) { } } -GLenum MapGLFormat(Format format) { +GLenum mapGLFormat(Format format) { switch (format) { case Format::A8: return GL_ALPHA; case Format::L8: return GL_LUMINANCE; @@ -196,11 +196,11 @@ GLenum MapGLFormat(Format format) { case Format::RGB32F: return GL_RGB; case Format::RGBA32UI: case Format::RGBA32I: - case Format::RGBA32F: return GL_RGBA; + case Format::RGBA32F: case Format::RGB10A2: return GL_RGBA; - case Format::R11G11B10F: return GL_RGB; + case Format::R11G11B10F: case Format::R5G6B5: return GL_RGB; - case Format::RGB5A1: return GL_RGBA; + case Format::RGB5A1: case Format::RGBA4: return GL_RGBA; case Format::D16: return GL_DEPTH_COMPONENT; case Format::D16S8: return GL_DEPTH_STENCIL_OES; @@ -227,35 +227,35 @@ GLenum MapGLFormat(Format format) { case Format::PVRTC_RGB4: return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; case Format::PVRTC_RGBA4: return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - case Format::ASTC_RGBA_4x4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - case Format::ASTC_RGBA_5x4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - case Format::ASTC_RGBA_5x5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - case Format::ASTC_RGBA_6x5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - case Format::ASTC_RGBA_6x6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - case Format::ASTC_RGBA_8x5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - case Format::ASTC_RGBA_8x6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - case Format::ASTC_RGBA_8x8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - case Format::ASTC_RGBA_10x5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - case Format::ASTC_RGBA_10x6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - case Format::ASTC_RGBA_10x8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - case Format::ASTC_RGBA_10x10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - case Format::ASTC_RGBA_12x10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - case Format::ASTC_RGBA_12x12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + case Format::ASTC_RGBA_4X4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case Format::ASTC_RGBA_5X4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + case Format::ASTC_RGBA_5X5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + case Format::ASTC_RGBA_6X5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + case Format::ASTC_RGBA_6X6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + case Format::ASTC_RGBA_8X5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + case Format::ASTC_RGBA_8X6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + case Format::ASTC_RGBA_8X8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + case Format::ASTC_RGBA_10X5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + case Format::ASTC_RGBA_10X6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + case Format::ASTC_RGBA_10X8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + case Format::ASTC_RGBA_10X10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + case Format::ASTC_RGBA_12X10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + case Format::ASTC_RGBA_12X12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - case Format::ASTC_SRGBA_4x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - case Format::ASTC_SRGBA_5x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - case Format::ASTC_SRGBA_5x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - case Format::ASTC_SRGBA_6x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - case Format::ASTC_SRGBA_6x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - case Format::ASTC_SRGBA_8x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - case Format::ASTC_SRGBA_8x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - case Format::ASTC_SRGBA_8x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - case Format::ASTC_SRGBA_10x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - case Format::ASTC_SRGBA_10x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - case Format::ASTC_SRGBA_10x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - case Format::ASTC_SRGBA_10x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - case Format::ASTC_SRGBA_12x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - case Format::ASTC_SRGBA_12x12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; + case Format::ASTC_SRGBA_4X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + case Format::ASTC_SRGBA_5X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + case Format::ASTC_SRGBA_5X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + case Format::ASTC_SRGBA_6X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + case Format::ASTC_SRGBA_6X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + case Format::ASTC_SRGBA_8X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + case Format::ASTC_SRGBA_8X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + case Format::ASTC_SRGBA_8X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + case Format::ASTC_SRGBA_10X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + case Format::ASTC_SRGBA_10X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + case Format::ASTC_SRGBA_10X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + case Format::ASTC_SRGBA_10X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + case Format::ASTC_SRGBA_12X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + case Format::ASTC_SRGBA_12X12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; default: { CCASSERT(false, "Unsupported Format, convert to WebGL format failed."); @@ -264,7 +264,7 @@ GLenum MapGLFormat(Format format) { } } -GLenum MapGLType(Type type) { +GLenum mapGLType(Type type) { switch (type) { case Type::BOOL: return GL_BOOL; case Type::BOOL2: return GL_BOOL_VEC2; @@ -292,7 +292,7 @@ GLenum MapGLType(Type type) { } } -Type MapType(GLenum glType) { +Type mapType(GLenum glType) { switch (glType) { case GL_BOOL: return Type::BOOL; case GL_BOOL_VEC2: return Type::BOOL2; @@ -320,7 +320,7 @@ Type MapType(GLenum glType) { } } -GLenum FormatToGLType(Format format) { +GLenum formatToGLType(Format format) { switch (format) { case Format::R8: return GL_UNSIGNED_BYTE; case Format::R8SN: return GL_BYTE; @@ -342,7 +342,7 @@ GLenum FormatToGLType(Format format) { case Format::RG32UI: return GL_UNSIGNED_INT; case Format::RG32I: return GL_INT; - case Format::RGB8: return GL_UNSIGNED_BYTE; + case Format::RGB8: case Format::SRGB8: return GL_UNSIGNED_BYTE; case Format::RGB8SN: return GL_BYTE; case Format::RGB8UI: return GL_UNSIGNED_BYTE; @@ -354,7 +354,7 @@ GLenum FormatToGLType(Format format) { case Format::RGB32UI: return GL_UNSIGNED_INT; case Format::RGB32I: return GL_INT; - case Format::RGBA8: return GL_UNSIGNED_BYTE; + case Format::RGBA8: case Format::SRGB8_A8: return GL_UNSIGNED_BYTE; case Format::RGBA8SN: return GL_BYTE; case Format::RGBA8UI: return GL_UNSIGNED_BYTE; @@ -381,66 +381,66 @@ GLenum FormatToGLType(Format format) { case Format::D32F: return GL_UNSIGNED_INT; case Format::D32F_S8: return GL_UNSIGNED_INT_24_8_OES; - case Format::BC1: return GL_UNSIGNED_BYTE; - case Format::BC1_SRGB: return GL_UNSIGNED_BYTE; - case Format::BC2: return GL_UNSIGNED_BYTE; - case Format::BC2_SRGB: return GL_UNSIGNED_BYTE; - case Format::BC3: return GL_UNSIGNED_BYTE; - case Format::BC3_SRGB: return GL_UNSIGNED_BYTE; + case Format::BC1: + case Format::BC1_SRGB: + case Format::BC2: + case Format::BC2_SRGB: + case Format::BC3: + case Format::BC3_SRGB: case Format::BC4: return GL_UNSIGNED_BYTE; case Format::BC4_SNORM: return GL_BYTE; case Format::BC5: return GL_UNSIGNED_BYTE; case Format::BC5_SNORM: return GL_BYTE; - case Format::BC6H_SF16: return GL_FLOAT; + case Format::BC6H_SF16: case Format::BC6H_UF16: return GL_FLOAT; - case Format::BC7: return GL_UNSIGNED_BYTE; - case Format::BC7_SRGB: return GL_UNSIGNED_BYTE; + case Format::BC7: + case Format::BC7_SRGB: - case Format::ETC_RGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_RGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_SRGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_RGB8_A1: return GL_UNSIGNED_BYTE; - case Format::ETC2_SRGB8_A1: return GL_UNSIGNED_BYTE; + case Format::ETC_RGB8: + case Format::ETC2_RGB8: + case Format::ETC2_SRGB8: + case Format::ETC2_RGB8_A1: + case Format::ETC2_SRGB8_A1: case Format::EAC_R11: return GL_UNSIGNED_BYTE; case Format::EAC_R11SN: return GL_BYTE; case Format::EAC_RG11: return GL_UNSIGNED_BYTE; case Format::EAC_RG11SN: return GL_BYTE; - case Format::PVRTC_RGB2: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGBA2: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGB4: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGBA4: return GL_UNSIGNED_BYTE; - case Format::PVRTC2_2BPP: return GL_UNSIGNED_BYTE; - case Format::PVRTC2_4BPP: return GL_UNSIGNED_BYTE; + case Format::PVRTC_RGB2: + case Format::PVRTC_RGBA2: + case Format::PVRTC_RGB4: + case Format::PVRTC_RGBA4: + case Format::PVRTC2_2BPP: + case Format::PVRTC2_4BPP: - case Format::ASTC_RGBA_4x4: - case Format::ASTC_RGBA_5x4: - case Format::ASTC_RGBA_5x5: - case Format::ASTC_RGBA_6x5: - case Format::ASTC_RGBA_6x6: - case Format::ASTC_RGBA_8x5: - case Format::ASTC_RGBA_8x6: - case Format::ASTC_RGBA_8x8: - case Format::ASTC_RGBA_10x5: - case Format::ASTC_RGBA_10x6: - case Format::ASTC_RGBA_10x8: - case Format::ASTC_RGBA_10x10: - case Format::ASTC_RGBA_12x10: - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_4x4: - case Format::ASTC_SRGBA_5x4: - case Format::ASTC_SRGBA_5x5: - case Format::ASTC_SRGBA_6x5: - case Format::ASTC_SRGBA_6x6: - case Format::ASTC_SRGBA_8x5: - case Format::ASTC_SRGBA_8x6: - case Format::ASTC_SRGBA_8x8: - case Format::ASTC_SRGBA_10x5: - case Format::ASTC_SRGBA_10x6: - case Format::ASTC_SRGBA_10x8: - case Format::ASTC_SRGBA_10x10: - case Format::ASTC_SRGBA_12x10: - case Format::ASTC_SRGBA_12x12: + case Format::ASTC_RGBA_4X4: + case Format::ASTC_RGBA_5X4: + case Format::ASTC_RGBA_5X5: + case Format::ASTC_RGBA_6X5: + case Format::ASTC_RGBA_6X6: + case Format::ASTC_RGBA_8X5: + case Format::ASTC_RGBA_8X6: + case Format::ASTC_RGBA_8X8: + case Format::ASTC_RGBA_10X5: + case Format::ASTC_RGBA_10X6: + case Format::ASTC_RGBA_10X8: + case Format::ASTC_RGBA_10X10: + case Format::ASTC_RGBA_12X10: + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_4X4: + case Format::ASTC_SRGBA_5X4: + case Format::ASTC_SRGBA_5X5: + case Format::ASTC_SRGBA_6X5: + case Format::ASTC_SRGBA_6X6: + case Format::ASTC_SRGBA_8X5: + case Format::ASTC_SRGBA_8X6: + case Format::ASTC_SRGBA_8X8: + case Format::ASTC_SRGBA_10X5: + case Format::ASTC_SRGBA_10X6: + case Format::ASTC_SRGBA_10X8: + case Format::ASTC_SRGBA_10X10: + case Format::ASTC_SRGBA_12X10: + case Format::ASTC_SRGBA_12X12: return GL_UNSIGNED_BYTE; default: { @@ -449,7 +449,7 @@ GLenum FormatToGLType(Format format) { } } -uint GLTypeSize(GLenum glType) { +uint glTypeSize(GLenum glType) { switch (glType) { case GL_BOOL: return 4; case GL_BOOL_VEC2: return 8; @@ -459,20 +459,20 @@ uint GLTypeSize(GLenum glType) { case GL_INT_VEC2: return 8; case GL_INT_VEC3: return 12; case GL_INT_VEC4: return 16; - case GL_UNSIGNED_INT: return 4; + case GL_UNSIGNED_INT: case GL_FLOAT: return 4; case GL_FLOAT_VEC2: return 8; case GL_FLOAT_VEC3: return 12; - case GL_FLOAT_VEC4: return 16; + case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: return 16; case GL_FLOAT_MAT3: return 36; case GL_FLOAT_MAT4: return 64; - case GL_SAMPLER_2D: return 4; - case GL_SAMPLER_3D_OES: return 4; - case GL_SAMPLER_CUBE: return 4; - case GL_SAMPLER_CUBE_MAP_ARRAY_OES: return 4; - case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_OES: return 4; - case GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES: return 4; + case GL_SAMPLER_2D: + case GL_SAMPLER_3D_OES: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_CUBE_MAP_ARRAY_OES: + case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_OES: + case GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES: case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES: return 4; default: { CCASSERT(false, "Unsupported GLType, get type failed."); @@ -481,7 +481,7 @@ uint GLTypeSize(GLenum glType) { } } -uint GLComponentCount(GLenum glType) { +uint glComponentCount(GLenum glType) { switch (glType) { case GL_FLOAT_MAT2: return 2; case GL_FLOAT_MAT3: return 3; @@ -548,7 +548,7 @@ const GLenum GLES2_BLEND_FACTORS[] = { }; } // namespace -void GLES2CmdFuncCreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { +void cmdFuncGLES2CreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLenum glUsage = (gpuBuffer->memUsage & MemoryUsageBit::HOST ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); @@ -592,14 +592,12 @@ void GLES2CmdFuncCreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); device->stateCache()->glElementArrayBuffer = 0; } - } else if (gpuBuffer->usage & BufferUsageBit::UNIFORM) { - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); - gpuBuffer->glTarget = GL_NONE; } else if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { gpuBuffer->glTarget = GL_NONE; - } else if ((gpuBuffer->usage & BufferUsageBit::TRANSFER_DST) || + } else if ((gpuBuffer->usage & BufferUsageBit::UNIFORM) || + (gpuBuffer->usage & BufferUsageBit::TRANSFER_DST) || (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC)) { - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); + gpuBuffer->buffer = static_cast(CC_MALLOC(gpuBuffer->size)); gpuBuffer->glTarget = GL_NONE; } else { CCASSERT(false, "Unsupported BufferType, create buffer failed."); @@ -607,7 +605,7 @@ void GLES2CmdFuncCreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { } } -void GLES2CmdFuncDestroyBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { +void cmdFuncGLES2DestroyBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuBuffer->glBuffer) { if (gpuBuffer->usage & BufferUsageBit::VERTEX) { @@ -641,7 +639,7 @@ void GLES2CmdFuncDestroyBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { CC_SAFE_FREE(gpuBuffer->buffer); } -void GLES2CmdFuncResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { +void cmdFuncGLES2ResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLenum glUsage = (gpuBuffer->memUsage & MemoryUsageBit::HOST ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); @@ -683,21 +681,16 @@ void GLES2CmdFuncResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); device->stateCache()->glElementArrayBuffer = 0; } - } else if (gpuBuffer->usage & BufferUsageBit::UNIFORM) { - if (gpuBuffer->buffer) { - CC_FREE(gpuBuffer->buffer); - } - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); - gpuBuffer->glTarget = GL_NONE; } else if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { gpuBuffer->indirects.resize(gpuBuffer->count); gpuBuffer->glTarget = GL_NONE; - } else if ((gpuBuffer->usage & BufferUsageBit::TRANSFER_DST) || + } else if ((gpuBuffer->usage & BufferUsageBit::UNIFORM) || + (gpuBuffer->usage & BufferUsageBit::TRANSFER_DST) || (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC)) { if (gpuBuffer->buffer) { CC_FREE(gpuBuffer->buffer); } - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); + gpuBuffer->buffer = static_cast(CC_MALLOC(gpuBuffer->size)); gpuBuffer->glTarget = GL_NONE; } else { CCASSERT(false, "Unsupported BufferType, resize buffer failed."); @@ -705,10 +698,10 @@ void GLES2CmdFuncResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer) { } } -void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { - gpuTexture->glInternelFmt = MapGLInternalFormat(gpuTexture->format); - gpuTexture->glFormat = MapGLFormat(gpuTexture->format); - gpuTexture->glType = FormatToGLType(gpuTexture->format); +void cmdFuncGLES2CreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { + gpuTexture->glInternelFmt = mapGLInternalFormat(gpuTexture->format); + gpuTexture->glFormat = mapGLFormat(gpuTexture->format); + gpuTexture->glType = formatToGLType(gpuTexture->format); switch (gpuTexture->type) { case TextureType::TEX2D: { @@ -722,7 +715,7 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } uint w = gpuTexture->width; uint h = gpuTexture->height; - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); @@ -730,7 +723,7 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -748,7 +741,7 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_CUBE_MAP, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint f = 0; f < 6; ++f) { uint w = gpuTexture->width; uint h = gpuTexture->height; @@ -763,7 +756,7 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -779,7 +772,7 @@ void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } -void GLES2CmdFuncDestroyTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { +void cmdFuncGLES2DestroyTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { if (gpuTexture->glTexture) { for (GLuint &glTexture : device->stateCache()->glTextures) { if (glTexture == gpuTexture->glTexture) { @@ -791,10 +784,10 @@ void GLES2CmdFuncDestroyTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture } } -void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { - gpuTexture->glInternelFmt = MapGLInternalFormat(gpuTexture->format); - gpuTexture->glFormat = MapGLFormat(gpuTexture->format); - gpuTexture->glType = FormatToGLType(gpuTexture->format); +void cmdFuncGLES2ResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) { + gpuTexture->glInternelFmt = mapGLInternalFormat(gpuTexture->format); + gpuTexture->glFormat = mapGLFormat(gpuTexture->format); + gpuTexture->glType = formatToGLType(gpuTexture->format); switch (gpuTexture->type) { case TextureType::TEX2D: { @@ -807,7 +800,7 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } uint w = gpuTexture->width; uint h = gpuTexture->height; - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); @@ -815,7 +808,7 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -832,7 +825,7 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_CUBE_MAP, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint f = 0; f < 6; ++f) { uint w = gpuTexture->width; uint h = gpuTexture->height; @@ -847,7 +840,7 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -863,7 +856,7 @@ void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) } } -void GLES2CmdFuncCreateSampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) { +void cmdFuncGLES2CreateSampler(GLES2Device * /*device*/, GLES2GPUSampler *gpuSampler) { if (gpuSampler->minFilter == Filter::LINEAR || gpuSampler->minFilter == Filter::ANISOTROPIC) { if (gpuSampler->mipFilter == Filter::LINEAR || gpuSampler->mipFilter == Filter::ANISOTROPIC) { gpuSampler->glMinFilter = GL_LINEAR_MIPMAP_LINEAR; @@ -888,15 +881,15 @@ void GLES2CmdFuncCreateSampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) gpuSampler->glMagFilter = GL_NEAREST; } - gpuSampler->glWrapS = GLES2_WRAPS[(int)gpuSampler->addressU]; - gpuSampler->glWrapT = GLES2_WRAPS[(int)gpuSampler->addressV]; - gpuSampler->glWrapR = GLES2_WRAPS[(int)gpuSampler->addressW]; + gpuSampler->glWrapS = GLES2_WRAPS[static_cast(gpuSampler->addressU)]; + gpuSampler->glWrapT = GLES2_WRAPS[static_cast(gpuSampler->addressV)]; + gpuSampler->glWrapR = GLES2_WRAPS[static_cast(gpuSampler->addressW)]; } -void GLES2CmdFuncDestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) { +void cmdFuncGLES2DestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler) { } -void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { +void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GLenum glShaderType = 0; String shaderTypeStr; GLint status; @@ -932,7 +925,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GL_CHECK(glGetShaderiv(gpuStage.glShader, GL_INFO_LOG_LENGTH, &logSize)); ++logSize; - GLchar *logs = (GLchar *)CC_MALLOC(logSize); + auto *logs = static_cast(CC_MALLOC(logSize)); GL_CHECK(glGetShaderInfoLog(gpuStage.glShader, logSize, nullptr, logs)); CC_LOG_ERROR("%s in %s compilation failed.", shaderTypeStr.c_str(), gpuShader->name.c_str()); @@ -972,7 +965,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &logSize)); if (logSize) { ++logSize; - GLchar *logs = (GLchar *)CC_MALLOC(logSize); + auto *logs = static_cast(CC_MALLOC(logSize)); GL_CHECK(glGetProgramInfoLog(gpuShader->glProgram, logSize, nullptr, logs)); CC_LOG_ERROR(logs); @@ -1007,15 +1000,15 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, glName); gpuInput.binding = gpuInput.glLoc; gpuInput.name = glName; - gpuInput.type = MapType(glType); - gpuInput.stride = GLTypeSize(glType); + gpuInput.type = mapType(glType); + gpuInput.stride = glTypeSize(glType); gpuInput.count = glSize; gpuInput.size = gpuInput.stride * gpuInput.count; gpuInput.glType = glType; } // create uniform blocks - if (gpuShader->blocks.size()) { + if (!gpuShader->blocks.empty()) { gpuShader->glBlocks.resize(gpuShader->blocks.size()); @@ -1035,11 +1028,11 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuUniform.binding = GFX_INVALID_BINDING; gpuUniform.name = uniform.name; gpuUniform.type = uniform.type; - gpuUniform.stride = GFX_TYPE_SIZES[(int)uniform.type]; + gpuUniform.stride = GFX_TYPE_SIZES[static_cast(uniform.type)]; gpuUniform.count = uniform.count; gpuUniform.size = gpuUniform.stride * gpuUniform.count; gpuUniform.offset = gpuBlock.size; - gpuUniform.glType = MapGLType(gpuUniform.type); + gpuUniform.glType = mapGLType(gpuUniform.type); gpuUniform.glLoc = -1; gpuUniform.buff = nullptr; @@ -1049,7 +1042,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } // if // create uniform samplers - if (gpuShader->samplers.size()) { + if (!gpuShader->samplers.empty()) { gpuShader->glSamplers.resize(gpuShader->samplers.size()); for (size_t i = 0; i < gpuShader->glSamplers.size(); ++i) { @@ -1059,7 +1052,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuSampler.binding = sampler.binding; gpuSampler.name = sampler.name; gpuSampler.count = sampler.count; - gpuSampler.glType = MapGLType(gpuSampler.type); + gpuSampler.glType = mapGLType(gpuSampler.type); gpuSampler.glLoc = -1; } } @@ -1091,7 +1084,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { if (gpuBlock.glUniforms[u].name == name) { GLES2GPUUniform &gpuUniform = gpuBlock.glUniforms[u]; gpuUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); - gpuUniform.buff = (uint8_t *)CC_MALLOC(gpuUniform.size); + gpuUniform.buff = static_cast(CC_MALLOC(gpuUniform.size)); gpuBlock.glActiveUniforms.emplace_back(gpuUniform); break; @@ -1109,16 +1102,16 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers - uint flexibleSetBaseOffset = 0u; - for (uint i = 0u; i < gpuShader->blocks.size(); i++) { - if (gpuShader->blocks[i].set == bindingMappingInfo.flexibleSet) { + uint flexibleSetBaseOffset = 0U; + for (auto &block : gpuShader->blocks) { + if (block.set == bindingMappingInfo.flexibleSet) { flexibleSetBaseOffset++; } } - uint arrayOffset = 0u; + uint arrayOffset = 0U; - for (uint i = 0u; i < gpuShader->samplers.size(); i++) { + for (uint i = 0U; i < gpuShader->samplers.size(); i++) { const UniformSampler &sampler = gpuShader->samplers[i]; GLint glLoc = glGetUniformLocation(gpuShader->glProgram, sampler.name.c_str()); if (glLoc >= 0) { @@ -1133,16 +1126,16 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } - if (glActiveSamplers.size()) { + if (!glActiveSamplers.empty()) { vector usedTexUnits(device->getCapabilities().maxTextureUnits, false); // try to reuse existing mappings first - for (uint i = 0u; i < glActiveSamplers.size(); i++) { + for (uint i = 0U; i < glActiveSamplers.size(); i++) { GLES2GPUUniformSampler &glSampler = glActiveSamplers[i]; if (texUnitCacheMap.count(glSampler.name)) { uint cachedUnit = texUnitCacheMap[glSampler.name]; glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0u, offset = 0u; t < glSampler.count; t++) { + for (uint t = 0U, offset = 0U; t < glSampler.count; t++) { while (usedTexUnits[cachedUnit + t + offset]) offset++; glSampler.units.push_back(cachedUnit + t + offset); usedTexUnits[cachedUnit + t + offset] = true; @@ -1150,13 +1143,13 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } // fill in the rest sequencially - uint unitIdx = 0u; - for (uint i = 0u; i < glActiveSamplers.size(); i++) { + uint unitIdx = 0U; + for (uint i = 0U; i < glActiveSamplers.size(); i++) { GLES2GPUUniformSampler &glSampler = glActiveSamplers[i]; if (glSampler.glLoc < 0) { glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0u; t < glSampler.count; t++) { + for (uint t = 0U; t < glSampler.count; t++) { while (usedTexUnits[unitIdx + t]) unitIdx++; glSampler.units.push_back(unitIdx + t); usedTexUnits[unitIdx + t] = true; @@ -1171,8 +1164,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GL_CHECK(glUseProgram(gpuShader->glProgram)); } - for (size_t i = 0; i < glActiveSamplers.size(); ++i) { - GLES2GPUUniformSampler &gpuSampler = glActiveSamplers[i]; + for (auto &gpuSampler : glActiveSamplers) { GL_CHECK(glUniform1iv(gpuSampler.glLoc, (GLsizei)gpuSampler.units.size(), gpuSampler.units.data())); } @@ -1182,8 +1174,8 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } // strip out the inactive ones - for (uint i = 0u; i < gpuShader->glBlocks.size();) { - if (gpuShader->glBlocks[i].glActiveUniforms.size()) { + for (uint i = 0U; i < gpuShader->glBlocks.size();) { + if (!gpuShader->glBlocks[i].glActiveUniforms.empty()) { i++; } else { gpuShader->glBlocks[i] = gpuShader->glBlocks.back(); @@ -1193,7 +1185,7 @@ void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuShader->glSamplers = glActiveSamplers; } -void GLES2CmdFuncDestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader) { +void cmdFuncGLES2DestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuShader->glProgram) { if (device->stateCache()->glProgram == gpuShader->glProgram) { @@ -1206,7 +1198,7 @@ void GLES2CmdFuncDestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } -void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler) { +void cmdFuncGLES2CreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler) { if (gpuInputAssembler->gpuIndexBuffer) { switch (gpuInputAssembler->gpuIndexBuffer->stride) { @@ -1219,20 +1211,20 @@ void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble } } - vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0u); + vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { GLES2GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[i]; const Attribute & attrib = gpuInputAssembler->attributes[i]; - GLES2GPUBuffer *gpuVB = (GLES2GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; + auto *gpuVB = static_cast(gpuInputAssembler->gpuVertexBuffers[attrib.stream]); gpuAttribute.name = attrib.name; - gpuAttribute.glType = FormatToGLType(attrib.format); - gpuAttribute.size = GFX_FORMAT_INFOS[(int)attrib.format].size; - gpuAttribute.count = GFX_FORMAT_INFOS[(int)attrib.format].count; - gpuAttribute.componentCount = GLComponentCount(gpuAttribute.glType); + gpuAttribute.glType = formatToGLType(attrib.format); + gpuAttribute.size = GFX_FORMAT_INFOS[static_cast(attrib.format)].size; + gpuAttribute.count = GFX_FORMAT_INFOS[static_cast(attrib.format)].count; + gpuAttribute.componentCount = glComponentCount(gpuAttribute.glType); gpuAttribute.isNormalized = attrib.isNormalized; gpuAttribute.isInstanced = attrib.isInstanced; gpuAttribute.offset = streamOffsets[attrib.stream]; @@ -1245,7 +1237,7 @@ void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble } } -void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler) { +void cmdFuncGLES2DestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; for (auto it = gpuInputAssembler->glVAOs.begin(); it != gpuInputAssembler->glVAOs.end(); ++it) { if (device->stateCache()->glVAO == it->second) { @@ -1258,7 +1250,7 @@ void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembl gpuInputAssembler->glVAOs.clear(); } -void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO) { +void cmdFuncGLES2CreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO) { uint colorViewCount = gpuFBO->gpuColorTextures.size(); uint swapchainImageIndices = 0; for (size_t i = 0; i < colorViewCount; ++i) { @@ -1288,7 +1280,7 @@ void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu // Mipmap level in GLES2 should be 0. GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, (GLenum)(GL_COLOR_ATTACHMENT0 + i), gpuColorTexture->glTarget, gpuColorTexture->glTexture, 0)); - attachments[attachmentCount++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + attachments[attachmentCount++] = static_cast(GL_COLOR_ATTACHMENT0 + i); } } @@ -1297,7 +1289,7 @@ void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu // Mipmap level in GLES2 should be 0. GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gpuDepthStencilTexture->glTarget, gpuDepthStencilTexture->glTexture, 0)); - if (GFX_FORMAT_INFOS[(int)gpuDepthStencilTexture->format].hasStencil) { + if (GFX_FORMAT_INFOS[static_cast(gpuDepthStencilTexture->format)].hasStencil) { // Mipmap level in GLES2 should be 0. GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, gpuDepthStencilTexture->glTarget, gpuDepthStencilTexture->glTexture, 0)); } @@ -1332,7 +1324,7 @@ void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu } } -void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO) { +void cmdFuncGLES2DestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO) { if (gpuFBO->isOffscreen) { if (gpuFBO->glFramebuffer) { if (device->stateCache()->glFramebuffer == gpuFBO->glFramebuffer) { @@ -1345,7 +1337,7 @@ void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gp } } -void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, +void cmdFuncGLES2BeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; gfxStateCache.gpuRenderPass = gpuRenderPass; @@ -1420,7 +1412,7 @@ void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRen } // for if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) { - bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth; + bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; if (hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour @@ -1440,7 +1432,7 @@ void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRen default:; } } // if (hasDepth) - bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour @@ -1499,7 +1491,7 @@ void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRen } } -void GLES2CmdFuncEndRenderPass(GLES2Device *device) { +void cmdFuncGLES2EndRenderPass(GLES2Device *device) { GLES2ObjectCache & gfxStateCache = device->stateCache()->gfxStateCache; size_t numClearColors = gfxStateCache.numClearColors; GLES2GPURenderPass * gpuRenderPass = gfxStateCache.gpuRenderPass; @@ -1527,7 +1519,7 @@ void GLES2CmdFuncEndRenderPass(GLES2Device *device) { } // for if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) { - bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth; + bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; if (hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthStoreOp) { case StoreOp::STORE: break; @@ -1539,7 +1531,7 @@ void GLES2CmdFuncEndRenderPass(GLES2Device *device) { default:; } } // if (hasDepth) - bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { case StoreOp::STORE: break; @@ -1558,17 +1550,17 @@ void GLES2CmdFuncEndRenderPass(GLES2Device *device) { } } -void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipelineState, GLES2GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, - Viewport &viewport, Rect &scissor, float lineWidth, bool depthBiasEnabled, GLES2DepthBias &depthBias, Color &blendConstants, - GLES2DepthBounds &depthBounds, GLES2StencilWriteMask &stencilWriteMask, GLES2StencilCompareMask &stencilCompareMask) { +void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipelineState, GLES2GPUInputAssembler *gpuInputAssembler, + const vector &gpuDescriptorSets, const vector &dynamicOffsets, + const Viewport &viewport, const Rect &scissor, float lineWidth, bool depthBiasEnabled, const GLES2DepthBias &depthBias, const Color & /*blendConstants*/, + const GLES2DepthBounds & /*depthBounds*/, const GLES2StencilWriteMask &stencilWriteMask, const GLES2StencilCompareMask &stencilCompareMask) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLES2GPUStateCache *cache = device->stateCache(); bool isShaderChanged = false; - GLenum glWrapS = 0u; - GLenum glWrapT = 0u; - GLenum glMinFilter = 0u; + GLenum glWrapS = 0U; + GLenum glWrapT = 0U; + GLenum glMinFilter = 0U; if (gpuPipelineState && gpuPipelineState != gfxStateCache.gpuPipelineState) { gfxStateCache.gpuPipelineState = gpuPipelineState; @@ -1610,8 +1602,8 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } cache->rs.cullMode = gpuPipelineState->rs.cullMode; } - bool isFrontFaceCCW = (bool)gpuPipelineState->rs.isFrontFaceCCW != gfxStateCache.reverseCW; - if ((bool)cache->rs.isFrontFaceCCW != isFrontFaceCCW) { + bool isFrontFaceCCW = static_cast(gpuPipelineState->rs.isFrontFaceCCW) != gfxStateCache.reverseCW; + if (static_cast(cache->rs.isFrontFaceCCW) != isFrontFaceCCW) { GL_CHECK(glFrontFace(isFrontFaceCCW ? GL_CCW : GL_CW)); cache->rs.isFrontFaceCCW = isFrontFaceCCW; } @@ -1775,7 +1767,8 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli size_t blockLen = gpuPipelineState->gpuShader->glBlocks.size(); const vector> &dynamicOffsetIndices = gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices; - uint8_t * uniformBuffBase = nullptr, *uniformBuff; + uint8_t * uniformBuffBase = nullptr; + uint8_t * uniformBuff; for (size_t j = 0; j < blockLen; j++) { const GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; @@ -1791,7 +1784,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli continue; } - uint offset = 0u; + uint offset = 0U; const vector &dynamicOffsetIndexSet = dynamicOffsetIndices[glBlock.set]; if (dynamicOffsetIndexSet.size() > glBlock.binding) { int dynamicOffsetIndex = dynamicOffsetIndexSet[glBlock.binding]; @@ -1805,9 +1798,8 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli uniformBuffBase = gpuDescriptor.gpuBuffer->buffer + offset; } - for (size_t u = 0; u < glBlock.glActiveUniforms.size(); ++u) { - const GLES2GPUUniform &gpuUniform = glBlock.glActiveUniforms[u]; - uniformBuff = uniformBuffBase + gpuUniform.offset; + for (const auto &gpuUniform : glBlock.glActiveUniforms) { + uniformBuff = uniformBuffBase + gpuUniform.offset; switch (gpuUniform.glType) { case GL_BOOL: case GL_INT: { @@ -1917,7 +1909,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli const GLES2GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glSampler.units.size(); u++, gpuDescriptor++) { - uint unit = (uint)glSampler.units[u]; + uint unit = static_cast(glSampler.units[u]); if (!gpuDescriptor->gpuTexture || !gpuDescriptor->gpuSampler) { CC_LOG_ERROR( @@ -2020,8 +2012,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0)); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - for (size_t j = 0; j < gpuPipelineState->gpuShader->glInputs.size(); ++j) { - const GLES2GPUInput &gpuInput = gpuPipelineState->gpuShader->glInputs[j]; + for (auto &gpuInput : gpuPipelineState->gpuShader->glInputs) { for (size_t a = 0; a < gpuInputAssembler->attributes.size(); ++a) { const GLES2GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { @@ -2071,12 +2062,11 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli cache->glVAO = glVAO; } } else { - for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { - cache->glCurrentAttribLocs[a] = false; + for (auto &&glCurrentAttribLoc : cache->glCurrentAttribLocs) { + glCurrentAttribLoc = false; } - for (size_t j = 0; j < gpuPipelineState->gpuShader->glInputs.size(); ++j) { - const GLES2GPUInput &gpuInput = gpuPipelineState->gpuShader->glInputs[j]; + for (auto &gpuInput : gpuPipelineState->gpuShader->glInputs) { for (size_t a = 0; a < gpuInputAssembler->attributes.size(); ++a) { const GLES2GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { @@ -2151,11 +2141,12 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } break; case DynamicStateFlagBit::DEPTH_BIAS: - if ((bool)cache->rs.depthBiasEnabled != depthBiasEnabled) { - if (depthBiasEnabled) + if (static_cast(cache->rs.depthBiasEnabled) != depthBiasEnabled) { + if (depthBiasEnabled) { GL_CHECK(glEnable(GL_POLYGON_OFFSET_FILL)); - else + } else { GL_CHECK(glDisable(GL_POLYGON_OFFSET_FILL)); + } cache->rs.depthBiasEnabled = depthBiasEnabled; } @@ -2212,7 +2203,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli switch (stencilCompareMask.face) { case StencilFace::FRONT: if ((cache->dss.stencilRefFront != - (uint)stencilCompareMask.refrence) || + static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, @@ -2225,7 +2216,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli break; case StencilFace::BACK: if ((cache->dss.stencilRefBack != - (uint)stencilCompareMask.refrence) || + static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_BACK, @@ -2238,11 +2229,11 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli break; case StencilFace::ALL: if ((cache->dss.stencilRefFront != - (uint)stencilCompareMask.refrence) || + static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask) || (cache->dss.stencilRefBack != - (uint)stencilCompareMask.refrence) || + static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, @@ -2269,7 +2260,7 @@ void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } // if } -void GLES2CmdFuncDraw(GLES2Device *device, DrawInfo &drawInfo) { +void cmdFuncGLES2Draw(GLES2Device *device, const DrawInfo &drawInfo) { GLES2ObjectCache & gfxStateCache = device->stateCache()->gfxStateCache; GLES2GPUPipelineState * gpuPipelineState = gfxStateCache.gpuPipelineState; GLES2GPUInputAssembler *gpuInputAssembler = gfxStateCache.gpuInputAssembler; @@ -2280,7 +2271,7 @@ void GLES2CmdFuncDraw(GLES2Device *device, DrawInfo &drawInfo) { if (gpuInputAssembler->gpuIndexBuffer) { if (drawInfo.indexCount > 0) { - uint8_t *offset = 0; + uint8_t *offset = nullptr; offset += drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (drawInfo.instanceCount == 0) { GL_CHECK(glDrawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset)); @@ -2304,7 +2295,7 @@ void GLES2CmdFuncDraw(GLES2Device *device, DrawInfo &drawInfo) { const DrawInfo &draw = gpuInputAssembler->gpuIndirectBuffer->indirects[j]; if (gpuInputAssembler->gpuIndexBuffer) { if (draw.indexCount > 0) { - uint8_t *offset = 0; + uint8_t *offset = nullptr; offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (drawInfo.instanceCount == 0) { GL_CHECK(glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset)); @@ -2328,15 +2319,14 @@ void GLES2CmdFuncDraw(GLES2Device *device, DrawInfo &drawInfo) { } } -void GLES2CmdFuncUpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { +void cmdFuncGLES2UpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; CCASSERT(buffer, "Buffer should not be nullptr"); - if (gpuBuffer->usage & BufferUsageBit::UNIFORM) { + if ((gpuBuffer->usage & BufferUsageBit::UNIFORM) || + (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC)) { memcpy(gpuBuffer->buffer + offset, buffer, size); } else if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { - memcpy((uint8_t *)gpuBuffer->indirects.data() + offset, buffer, size); - } else if (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC) { - memcpy(gpuBuffer->buffer + offset, buffer, size); + memcpy(reinterpret_cast(gpuBuffer->indirects.data()) + offset, buffer, size); } else { switch (gpuBuffer->glTarget) { case GL_ARRAY_BUFFER: { @@ -2376,7 +2366,7 @@ void GLES2CmdFuncUpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, co } } -void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, +void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { GLuint &glTexture = device->stateCache()->glTextures[device->stateCache()->texUint]; if (glTexture != gpuTexture->glTexture) { @@ -2384,7 +2374,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const glTexture = gpuTexture->glTexture; } - bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed; + bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; uint n = 0; switch (gpuTexture->glTarget) { @@ -2397,7 +2387,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage2D(GL_TEXTURE_2D, region.texSubres.mipLevel, region.texOffset.x, @@ -2432,7 +2422,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage3DOES(GL_TEXTURE_2D_ARRAY, region.texSubres.mipLevel, region.texOffset.x, @@ -2467,7 +2457,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const d = region.texExtent.depth; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage3DOES(GL_TEXTURE_3D, region.texSubres.mipLevel, region.texOffset.x, @@ -2503,7 +2493,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel, region.texOffset.x, @@ -2536,44 +2526,44 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const } } -void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { +void cmdFuncGLES2ExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { if (!cmdPackage->cmds.size()) return; - static uint cmdIndices[(int)GLESCmdType::COUNT] = {0}; + static uint cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; memset(cmdIndices, 0, sizeof(cmdIndices)); for (uint i = 0; i < cmdPackage->cmds.size(); ++i) { GLESCmdType cmdType = cmdPackage->cmds[i]; - uint & cmdIdx = cmdIndices[(int)cmdType]; + uint & cmdIdx = cmdIndices[static_cast(cmdType)]; switch (cmdType) { case GLESCmdType::BEGIN_RENDER_PASS: { GLES2CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[cmdIdx]; - GLES2CmdFuncBeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, cmd->renderArea, cmd->numClearColors, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); + cmdFuncGLES2BeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, cmd->renderArea, cmd->numClearColors, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); break; } case GLESCmdType::END_RENDER_PASS: { - GLES2CmdFuncEndRenderPass(device); + cmdFuncGLES2EndRenderPass(device); break; } case GLESCmdType::BIND_STATES: { GLES2CmdBindStates *cmd = cmdPackage->bindStatesCmds[cmdIdx]; - GLES2CmdFuncBindState(device, cmd->gpuPipelineState, cmd->gpuInputAssembler, cmd->gpuDescriptorSets, cmd->dynamicOffsets, cmd->viewport, cmd->scissor, cmd->lineWidth, cmd->depthBiasEnabled, cmd->depthBias, cmd->blendConstants, cmd->depthBounds, cmd->stencilWriteMask, cmd->stencilCompareMask); + cmdFuncGLES2BindState(device, cmd->gpuPipelineState, cmd->gpuInputAssembler, cmd->gpuDescriptorSets, cmd->dynamicOffsets, cmd->viewport, cmd->scissor, cmd->lineWidth, cmd->depthBiasEnabled, cmd->depthBias, cmd->blendConstants, cmd->depthBounds, cmd->stencilWriteMask, cmd->stencilCompareMask); break; } case GLESCmdType::DRAW: { GLES2CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx]; - GLES2CmdFuncDraw(device, cmd->drawInfo); + cmdFuncGLES2Draw(device, cmd->drawInfo); break; } case GLESCmdType::UPDATE_BUFFER: { GLES2CmdUpdateBuffer *cmd = cmdPackage->updateBufferCmds[cmdIdx]; - GLES2CmdFuncUpdateBuffer(device, cmd->gpuBuffer, cmd->buffer, cmd->offset, cmd->size); + cmdFuncGLES2UpdateBuffer(device, cmd->gpuBuffer, cmd->buffer, cmd->offset, cmd->size); break; } case GLESCmdType::COPY_BUFFER_TO_TEXTURE: { GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); + cmdFuncGLES2CopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); break; } default: diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.h b/native/cocos/renderer/gfx-gles2/GLES2Commands.h index 5a92b02340..b3531e35ca 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -25,8 +25,10 @@ #pragma once -#include "../gfx-gles-common/GLESCommandPool.h" +#include "gfx-gles-common/GLESCommandPool.h" + #include "GLES2GPUObjects.h" +#include "GLES2Std.h" namespace cc { namespace gfx { @@ -34,57 +36,57 @@ namespace gfx { class GLES2Device; struct GLES2DepthBias final { - float constant = 0.0f; - float clamp = 0.0f; - float slope = 0.0f; + float constant = 0.0F; + float clamp = 0.0F; + float slope = 0.0F; }; struct GLES2DepthBounds final { - float minBounds = 0.0f; - float maxBounds = 0.0f; + float minBounds = 0.0F; + float maxBounds = 0.0F; }; struct GLES2StencilWriteMask final { - StencilFace face = StencilFace::FRONT; - uint writeMask = 0; + StencilFace face = StencilFace::FRONT; + uint writeMask = 0; }; struct GLES2StencilCompareMask final { - StencilFace face = StencilFace::FRONT; - int refrence = 0; - uint compareMask = 0; + StencilFace face = StencilFace::FRONT; + int refrence = 0; + uint compareMask = 0; }; struct GLES2TextureSubres final { - uint baseMipLevel = 0; - uint levelCount = 1; + uint baseMipLevel = 0; + uint levelCount = 1; uint baseArrayLayer = 0; - uint layerCount = 1; + uint layerCount = 1; }; struct GLES2BufferTextureCopy final { - uint buffOffset = 0; - uint buffStride = 0; - uint buffTexHeight = 0; - uint texOffset[3] = {0}; - uint texExtent[3] = {0}; + uint buffOffset = 0; + uint buffStride = 0; + uint buffTexHeight = 0; + uint texOffset[3] = {0}; + uint texExtent[3] = {0}; GLES2TextureSubres texSubres; }; class GLES2CmdBeginRenderPass final : public GLESCmd { public: - GLES2GPURenderPass *gpuRenderPass = nullptr; - GLES2GPUFramebuffer *gpuFBO = nullptr; - Rect renderArea; - size_t numClearColors = 0; - Color clearColors[GFX_MAX_ATTACHMENTS]; - float clearDepth = 1.0f; - int clearStencil = 0; + GLES2GPURenderPass * gpuRenderPass = nullptr; + GLES2GPUFramebuffer *gpuFBO = nullptr; + Rect renderArea; + size_t numClearColors = 0; + Color clearColors[GFX_MAX_ATTACHMENTS]; + float clearDepth = 1.0F; + int clearStencil = 0; GLES2CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} void clear() override { - gpuFBO = nullptr; + gpuFBO = nullptr; numClearColors = 0; } }; @@ -103,24 +105,24 @@ enum class GLES2State { class GLES2CmdBindStates final : public GLESCmd { public: - GLES2GPUPipelineState *gpuPipelineState = nullptr; - GLES2GPUInputAssembler *gpuInputAssembler = nullptr; + GLES2GPUPipelineState * gpuPipelineState = nullptr; + GLES2GPUInputAssembler * gpuInputAssembler = nullptr; vector gpuDescriptorSets; - vector dynamicOffsets; - Viewport viewport; - Rect scissor; - float lineWidth = 1.0f; - bool depthBiasEnabled = false; - GLES2DepthBias depthBias; - Color blendConstants; - GLES2DepthBounds depthBounds; - GLES2StencilWriteMask stencilWriteMask; - GLES2StencilCompareMask stencilCompareMask; + vector dynamicOffsets; + Viewport viewport; + Rect scissor; + float lineWidth = 1.0F; + bool depthBiasEnabled = false; + GLES2DepthBias depthBias; + Color blendConstants; + GLES2DepthBounds depthBounds; + GLES2StencilWriteMask stencilWriteMask; + GLES2StencilCompareMask stencilCompareMask; GLES2CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} void clear() override { - gpuPipelineState = nullptr; + gpuPipelineState = nullptr; gpuInputAssembler = nullptr; gpuDescriptorSets.clear(); dynamicOffsets.clear(); @@ -138,71 +140,71 @@ public: class GLES2CmdUpdateBuffer final : public GLESCmd { public: GLES2GPUBuffer *gpuBuffer = nullptr; - uint8_t *buffer = nullptr; - uint size = 0; - uint offset = 0; + const uint8_t * buffer = nullptr; + uint size = 0; + uint offset = 0; GLES2CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} void clear() override { gpuBuffer = nullptr; - buffer = nullptr; + buffer = nullptr; } }; class GLES2CmdCopyBufferToTexture final : public GLESCmd { public: - GLES2GPUTexture *gpuTexture = nullptr; - const BufferTextureCopy *regions = nullptr; - uint count = 0u; - const uint8_t *const *buffers; + GLES2GPUTexture * gpuTexture = nullptr; + const BufferTextureCopy *regions = nullptr; + uint count = 0U; + const uint8_t *const * buffers; GLES2CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} void clear() override { gpuTexture = nullptr; - regions = nullptr; - count = 0u; - buffers = nullptr; + regions = nullptr; + count = 0U; + buffers = nullptr; } }; class GLES2CmdPackage final : public Object { public: - CachedArray cmds; - CachedArray beginRenderPassCmds; - CachedArray bindStatesCmds; - CachedArray drawCmds; - CachedArray updateBufferCmds; + CachedArray cmds; + CachedArray beginRenderPassCmds; + CachedArray bindStatesCmds; + CachedArray drawCmds; + CachedArray updateBufferCmds; CachedArray copyBufferToTextureCmds; }; class GLES2GPUCommandAllocator final : public Object { public: - CommandPool beginRenderPassCmdPool; - CommandPool bindStatesCmdPool; - CommandPool drawCmdPool; - CommandPool updateBufferCmdPool; + CommandPool beginRenderPassCmdPool; + CommandPool bindStatesCmdPool; + CommandPool drawCmdPool; + CommandPool updateBufferCmdPool; CommandPool copyBufferToTextureCmdPool; - void clearCmds(GLES2CmdPackage *cmd_package) { - if (cmd_package->beginRenderPassCmds.size()) { - beginRenderPassCmdPool.freeCmds(cmd_package->beginRenderPassCmds); + void clearCmds(GLES2CmdPackage *cmdPackage) { + if (cmdPackage->beginRenderPassCmds.size()) { + beginRenderPassCmdPool.freeCmds(cmdPackage->beginRenderPassCmds); } - if (cmd_package->bindStatesCmds.size()) { - bindStatesCmdPool.freeCmds(cmd_package->bindStatesCmds); + if (cmdPackage->bindStatesCmds.size()) { + bindStatesCmdPool.freeCmds(cmdPackage->bindStatesCmds); } - if (cmd_package->drawCmds.size()) { - drawCmdPool.freeCmds(cmd_package->drawCmds); + if (cmdPackage->drawCmds.size()) { + drawCmdPool.freeCmds(cmdPackage->drawCmds); } - if (cmd_package->updateBufferCmds.size()) { - updateBufferCmdPool.freeCmds(cmd_package->updateBufferCmds); + if (cmdPackage->updateBufferCmds.size()) { + updateBufferCmdPool.freeCmds(cmdPackage->updateBufferCmds); } - if (cmd_package->copyBufferToTextureCmds.size()) { - copyBufferToTextureCmdPool.freeCmds(cmd_package->copyBufferToTextureCmds); + if (cmdPackage->copyBufferToTextureCmds.size()) { + copyBufferToTextureCmdPool.freeCmds(cmdPackage->copyBufferToTextureCmds); } - cmd_package->cmds.clear(); + cmdPackage->cmds.clear(); } CC_INLINE void reset() { @@ -214,33 +216,33 @@ public: } }; -CC_GLES2_API void GLES2CmdFuncCreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); -CC_GLES2_API void GLES2CmdFuncDestroyBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); -CC_GLES2_API void GLES2CmdFuncResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); -CC_GLES2_API void GLES2CmdFuncCreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); -CC_GLES2_API void GLES2CmdFuncDestroyTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); -CC_GLES2_API void GLES2CmdFuncResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); -CC_GLES2_API void GLES2CmdFuncCreateSampler(GLES2Device *device, GLES2GPUSampler *gpuSampler); -CC_GLES2_API void GLES2CmdFuncDestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler); -CC_GLES2_API void GLES2CmdFuncCreateShader(GLES2Device *device, GLES2GPUShader *gpuShader); -CC_GLES2_API void GLES2CmdFuncDestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader); -CC_GLES2_API void GLES2CmdFuncCreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); -CC_GLES2_API void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); -CC_GLES2_API void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); -CC_GLES2_API void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); +CC_GLES2_API void cmdFuncGLES2CreateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); +CC_GLES2_API void cmdFuncGLES2DestroyBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); +CC_GLES2_API void cmdFuncGLES2ResizeBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer); +CC_GLES2_API void cmdFuncGLES2CreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); +CC_GLES2_API void cmdFuncGLES2DestroyTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); +CC_GLES2_API void cmdFuncGLES2ResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture); +CC_GLES2_API void cmdFuncGLES2CreateSampler(GLES2Device *device, GLES2GPUSampler *gpuSampler); +CC_GLES2_API void cmdFuncGLES2DestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler); +CC_GLES2_API void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader); +CC_GLES2_API void cmdFuncGLES2DestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader); +CC_GLES2_API void cmdFuncGLES2CreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); +CC_GLES2_API void cmdFuncGLES2DestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); +CC_GLES2_API void cmdFuncGLES2CreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); +CC_GLES2_API void cmdFuncGLES2DestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); -CC_GLES2_API void GLES2CmdFuncBeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFBO, +CC_GLES2_API void cmdFuncGLES2BeginRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil); -CC_GLES2_API void GLES2CmdFuncEndRenderPass(GLES2Device *device); -CC_GLES2_API void GLES2CmdFuncBindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipelineState, GLES2GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, - Viewport &viewport, Rect &scissor, float lineWidth, bool depthBiasEnabled, GLES2DepthBias &depthBias, Color &blendConstants, - GLES2DepthBounds &depthBounds, GLES2StencilWriteMask &stencilWriteMask, GLES2StencilCompareMask &stencilCompareMask); -CC_GLES2_API void GLES2CmdFuncDraw(GLES2Device *device, DrawInfo &drawInfo); -CC_GLES2_API void GLES2CmdFuncUpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size); -CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, +CC_GLES2_API void cmdFuncGLES2EndRenderPass(GLES2Device *device); +CC_GLES2_API void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipelineState, GLES2GPUInputAssembler *gpuInputAssembler, + const vector &gpuDescriptorSets, const vector &dynamicOffsets, + const Viewport &viewport, const Rect &scissor, float lineWidth, bool depthBiasEnabled, const GLES2DepthBias &depthBias, const Color &blendConstants, + const GLES2DepthBounds &depthBounds, const GLES2StencilWriteMask &stencilWriteMask, const GLES2StencilCompareMask &stencilCompareMask); +CC_GLES2_API void cmdFuncGLES2Draw(GLES2Device *device, const DrawInfo &drawInfo); +CC_GLES2_API void cmdFuncGLES2UpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size); +CC_GLES2_API void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count); -CC_GLES2_API void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage); +CC_GLES2_API void cmdFuncGLES2ExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp index 0c8eeea2e5..73c641e990 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp @@ -91,12 +91,9 @@ void GL_APIENTRY GLES2EGLDebugProc(GLenum source, #endif -GLES2Context::GLES2Context() -: Context() { -} +GLES2Context::GLES2Context() = default; -GLES2Context::~GLES2Context() { -} +GLES2Context::~GLES2Context() = default; #if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX) @@ -219,10 +216,10 @@ bool GLES2Context::doInit(const ContextInfo &info) { uint width = GLES2Device::getInstance()->getWidth(); uint height = GLES2Device::getInstance()->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); + ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); #endif - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), NULL)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("Window surface created failed."); return false; @@ -255,7 +252,7 @@ bool GLES2Context::doInit(const ContextInfo &info) { ctxAttribs[n] = EGL_NONE; } - EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs)); + EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, nullptr, ctxAttribs)); if (!_eglContext) { CC_LOG_ERROR("Create EGL context failed."); return false; @@ -271,7 +268,7 @@ bool GLES2Context::doInit(const ContextInfo &info) { // guaranteed to be invoked in the order they were added EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void { - _windowHandle = (uintptr_t)event.args->ptrVal; + _windowHandle = reinterpret_cast(event.args->ptrVal); EGLint nFmt = 0; if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { @@ -280,15 +277,15 @@ bool GLES2Context::doInit(const ContextInfo &info) { } uint width = GLES2Device::getInstance()->getWidth(); uint height = GLES2Device::getInstance()->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); + ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, nullptr)); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("Recreate window surface failed."); return; } - ((GLES2Context *)GLES2Device::getInstance()->getContext())->MakeCurrent(); + static_cast(GLES2Device::getInstance()->getContext())->MakeCurrent(); GLES2Device::getInstance()->stateCache()->reset(); }); #endif @@ -296,7 +293,7 @@ bool GLES2Context::doInit(const ContextInfo &info) { _eglSharedContext = _eglContext; } else { - GLES2Context *sharedCtx = static_cast(info.sharedCtx); + auto *sharedCtx = static_cast(info.sharedCtx); _majorVersion = sharedCtx->major_ver(); _minorVersion = sharedCtx->minor_ver(); @@ -377,7 +374,7 @@ void GLES2Context::doDestroy() { _isPrimaryContex = false; _windowHandle = 0; - _nativeDisplay = 0; + _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues _vsyncMode = VsyncMode::OFF; _isInitialized = false; } @@ -411,7 +408,7 @@ bool GLES2Context::MakeCurrent(bool bound) { int interval = 1; switch (_vsyncMode) { case VsyncMode::OFF: interval = 0; break; - case VsyncMode::ON: interval = 1; break; + case VsyncMode::ON: case VsyncMode::RELAXED: interval = 1; break; case VsyncMode::MAILBOX: interval = 0; break; case VsyncMode::HALF: interval = 2; break; @@ -471,14 +468,13 @@ bool GLES2Context::MakeCurrent(bool bound) { GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD)); GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO)); GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)); - GL_CHECK(glBlendColor(0.0f, 0.0f, 0.0f, 0.0f)); + GL_CHECK(glBlendColor(0.0F, 0.0F, 0.0F, 0.0F)); CC_LOG_DEBUG("eglMakeCurrent() - SUCCEEDED, Context: 0x%p", this); return true; - } else { - CC_LOG_ERROR("MakeCurrent() - FAILED, Context: 0x%p", this); - return false; } + CC_LOG_ERROR("MakeCurrent() - FAILED, Context: 0x%p", this); + return false; } bool GLES2Context::CheckExtension(const String &extension) const { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 4818166365..d1af48c6ae 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -45,24 +45,24 @@ namespace cc { namespace gfx { -GLES2Device *GLES2Device::_instance = nullptr; +GLES2Device *GLES2Device::instance = nullptr; GLES2Device *GLES2Device::getInstance() { - return GLES2Device::_instance; + return GLES2Device::instance; } GLES2Device::GLES2Device() { - _API = API::GLES2; + _api = API::GLES2; _deviceName = "GLES2"; - GLES2Device::_instance = this; + GLES2Device::instance = this; } GLES2Device::~GLES2Device() { - GLES2Device::_instance = nullptr; + GLES2Device::instance = nullptr; } -bool GLES2Device::doInit(const DeviceInfo &info) { +bool GLES2Device::doInit(const DeviceInfo & /*info*/) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; @@ -86,7 +86,7 @@ bool GLES2Device::doInit(const DeviceInfo &info) { bindRenderContext(true); - String extStr = (const char *)glGetString(GL_EXTENSIONS); + String extStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); _extensions = StringUtil::split(extStr, " "); if (checkExtension("GL_OES_texture_float")) { @@ -105,28 +105,34 @@ bool GLES2Device::doInit(const DeviceInfo &info) { _features[static_cast(Feature::ELEMENT_INDEX_UINT)] = true; } - if (checkExtension("color_buffer_float")) + if (checkExtension("color_buffer_float")) { _features[static_cast(Feature::COLOR_FLOAT)] = true; + } - if (checkExtension("color_buffer_half_float")) + if (checkExtension("color_buffer_half_float")) { _features[static_cast(Feature::COLOR_HALF_FLOAT)] = true; + } - if (checkExtension("texture_float_linear")) + if (checkExtension("texture_float_linear")) { _features[static_cast(Feature::TEXTURE_FLOAT_LINEAR)] = true; + } - if (checkExtension("texture_half_float_linear")) + if (checkExtension("texture_half_float_linear")) { _features[static_cast(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = true; + } - if (checkExtension("draw_buffers")) + if (checkExtension("draw_buffers")) { _features[static_cast(Feature::MULTIPLE_RENDER_TARGETS)] = true; + } - if (checkExtension("blend_minmax")) + if (checkExtension("blend_minmax")) { _features[static_cast(Feature::BLEND_MINMAX)] = true; + } _useVAO = checkExtension("vertex_array_object"); _useDrawInstanced = checkExtension("draw_instanced"); _useInstancedArrays = _features[static_cast(Feature::INSTANCED_ARRAYS)] = checkExtension("instanced_arrays"); - _useDiscardFramebuffer = checkExtension("discard_framebuffer"); + _useDiscardFramebuffer = checkExtension("discard_framebuffer"); String compressedFmts; @@ -161,9 +167,9 @@ bool GLES2Device::doInit(const DeviceInfo &info) { _features[static_cast(Feature::FORMAT_D24S8)] = checkExtension("packed_depth_stencil"); } - _renderer = (const char *)glGetString(GL_RENDERER); - _vendor = (const char *)glGetString(GL_VENDOR); - _version = (const char *)glGetString(GL_VERSION); + _renderer = reinterpret_cast(glGetString(GL_RENDERER)); + _vendor = reinterpret_cast(glGetString(GL_VENDOR)); + _version = reinterpret_cast(glGetString(GL_VERSION)); CC_LOG_INFO("GLES2 device initialized."); CC_LOG_INFO("RENDERER: %s", _renderer.c_str()); @@ -174,15 +180,15 @@ bool GLES2Device::doInit(const DeviceInfo &info) { CC_LOG_INFO("USE_VAO: %s", _useVAO ? "true" : "false"); CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str()); - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)&_caps.maxVertexAttributes); - glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, (GLint *)&_caps.maxVertexUniformVectors); - glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, (GLint *)&_caps.maxFragmentUniformVectors); - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint *)&_caps.maxTextureUnits); - glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, (GLint *)&_caps.maxVertexTextureUnits); - glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&_caps.maxTextureSize); - glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint *)&_caps.maxCubeMapTextureSize); - glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_caps.depthBits); - glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_caps.stencilBits); + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast(&_caps.maxVertexAttributes)); + glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, reinterpret_cast(&_caps.maxVertexUniformVectors)); + glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, reinterpret_cast(&_caps.maxFragmentUniformVectors)); + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, reinterpret_cast(&_caps.maxTextureUnits)); + glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, reinterpret_cast(&_caps.maxVertexTextureUnits)); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast(&_caps.maxTextureSize)); + glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, reinterpret_cast(&_caps.maxCubeMapTextureSize)); + glGetIntegerv(GL_DEPTH_BITS, reinterpret_cast(&_caps.depthBits)); + glGetIntegerv(GL_STENCIL_BITS, reinterpret_cast(&_caps.stencilBits)); _gpuStateCache->initialize(_caps.maxTextureUnits, _caps.maxVertexAttributes); @@ -209,10 +215,10 @@ void GLES2Device::acquire() { } void GLES2Device::present() { - GLES2Queue *queue = (GLES2Queue *)_queue; - _numDrawCalls = queue->_numDrawCalls; - _numInstances = queue->_numInstances; - _numTriangles = queue->_numTriangles; + auto *queue = static_cast(_queue); + _numDrawCalls = queue->_numDrawCalls; + _numInstances = queue->_numInstances; + _numTriangles = queue->_numTriangles; _context->present(); @@ -312,19 +318,20 @@ TextureBarrier *GLES2Device::createTextureBarrier() { } void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { - GLES2CmdFuncCopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); + cmdFuncGLES2CopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); } -bool GLES2Device::checkForETC2() const { +bool GLES2Device::checkForETC2() { GLint numFormats = 0; glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &numFormats); - GLint *formats = new GLint[numFormats]; + auto *formats = new GLint[numFormats]; glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats); int supportNum = 0; for (GLint i = 0; i < numFormats; ++i) { - if (formats[i] == GL_COMPRESSED_RGB8_ETC2 || formats[i] == GL_COMPRESSED_RGBA8_ETC2_EAC) + if (formats[i] == GL_COMPRESSED_RGB8_ETC2 || formats[i] == GL_COMPRESSED_RGBA8_ETC2_EAC) { supportNum++; + } } delete[] formats; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index 302599cd28..842e98dbe0 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -25,6 +25,8 @@ #pragma once +#include "GLES2Std.h" + #include "gfx-base/GFXDevice.h" #ifndef GL_COMPRESSED_RGB8_ETC2 @@ -69,27 +71,24 @@ public: void acquire() override; void present() override; - CC_INLINE bool useVAO() const { return _useVAO; } - CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; } - CC_INLINE bool useInstancedArrays() const { return _useInstancedArrays; } - CC_INLINE bool useDiscardFramebuffer() const { return _useDiscardFramebuffer; } + inline bool useVAO() const { return _useVAO; } + inline bool useDrawInstanced() const { return _useDrawInstanced; } + inline bool useInstancedArrays() const { return _useInstancedArrays; } + inline bool useDiscardFramebuffer() const { return _useDiscardFramebuffer; } - CC_INLINE GLES2GPUStateCache *stateCache() const { return _gpuStateCache; } - CC_INLINE GLES2GPUStagingBufferPool *stagingBufferPool() const { return _gpuStagingBufferPool; } + inline GLES2GPUStateCache * stateCache() const { return _gpuStateCache; } + inline GLES2GPUStagingBufferPool *stagingBufferPool() const { return _gpuStagingBufferPool; } - CC_INLINE bool checkExtension(const String &extension) const { - for (size_t i = 0; i < _extensions.size(); ++i) { - if (_extensions[i].find(extension) != String::npos) { - return true; - } - } - return false; + inline bool checkExtension(const String &extension) const { + return std::any_of(_extensions.begin(), _extensions.end(), [&extension](auto &ext) { + return ext.find(extension) != String::npos; + }); } - CC_INLINE uint getThreadID() const { return _threadID; } + inline uint getThreadID() const { return _threadID; } protected: - static GLES2Device * _instance; + static GLES2Device *instance; friend class DeviceManager; friend class GLES2Context; @@ -118,7 +117,7 @@ protected: void bindRenderContext(bool bound) override; void bindDeviceContext(bool bound) override; - bool checkForETC2() const; + static bool checkForETC2(); GLES2Context * _renderContext = nullptr; GLES2Context * _deviceContext = nullptr; @@ -132,7 +131,7 @@ protected: bool _useInstancedArrays = false; bool _useDiscardFramebuffer = false; - uint _threadID = 0u; + uint _threadID = 0U; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp index 1912e782cf..037eedb457 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp @@ -34,9 +34,7 @@ namespace cc { namespace gfx { -GLES2Framebuffer::GLES2Framebuffer() -: Framebuffer() { -} +GLES2Framebuffer::GLES2Framebuffer() = default; GLES2Framebuffer::~GLES2Framebuffer() { destroy(); @@ -46,7 +44,7 @@ void GLES2Framebuffer::doInit(const FramebufferInfo &info) { if (info.depthStencilMipmapLevel != 0) { CC_LOG_WARNING("Mipmap level of depth stencil attachment should be 0 in GLES2. Convert to 0."); } - if (info.colorMipmapLevels.size() > 0) { + if (!info.colorMipmapLevels.empty()) { int i = 0; for (const auto mipmapLevel : info.colorMipmapLevels) { if (mipmapLevel != 0) { @@ -61,7 +59,7 @@ void GLES2Framebuffer::doInit(const FramebufferInfo &info) { _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - GLES2Texture *colorTexture = (GLES2Texture *)_colorTextures[i]; + auto *colorTexture = static_cast(_colorTextures[i]); if (colorTexture) { _gpuFBO->gpuColorTextures[i] = colorTexture->gpuTexture(); } @@ -71,12 +69,12 @@ void GLES2Framebuffer::doInit(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilTexture = static_cast(_depthStencilTexture)->gpuTexture(); } - GLES2CmdFuncCreateFramebuffer(GLES2Device::getInstance(), _gpuFBO); + cmdFuncGLES2CreateFramebuffer(GLES2Device::getInstance(), _gpuFBO); } void GLES2Framebuffer::doDestroy() { if (_gpuFBO) { - GLES2CmdFuncDestroyFramebuffer(GLES2Device::getInstance(), _gpuFBO); + cmdFuncGLES2DestroyFramebuffer(GLES2Device::getInstance(), _gpuFBO); CC_DELETE(_gpuFBO); _gpuFBO = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index b9d38987de..35b733f728 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -25,6 +25,9 @@ #pragma once +#include + +#include "base/Object.h" #include "gfx-base/GFXDef.h" #include "GLES2Wrangler.h" @@ -43,13 +46,13 @@ public: uint8_t *buffer = nullptr; DrawInfoList indirects; }; -typedef vector GLES2GPUBufferList; +using GLES2GPUBufferList = vector; class GLES2GPUBufferView final : public Object { public: GLES2GPUBuffer *gpuBuffer = nullptr; - uint offset = 0u; - uint range = 0u; + uint offset = 0U; + uint range = 0U; }; class GLES2GPUTexture final : public Object { @@ -78,7 +81,7 @@ public: GLenum glMagFilter = 0; }; -typedef vector GLES2GPUTextureList; +using GLES2GPUTextureList = vector; class GLES2GPUSampler final : public Object { public: @@ -105,7 +108,7 @@ struct GLES2GPUInput final { GLenum glType = 0; GLint glLoc = -1; }; -typedef vector GLES2GPUInputList; +using GLES2GPUInputList = vector; struct GLES2GPUUniform final { uint binding = GFX_INVALID_BINDING; @@ -119,7 +122,7 @@ struct GLES2GPUUniform final { GLint glLoc = -1; uint8_t *buff = nullptr; - GLES2GPUUniform() {} + GLES2GPUUniform() = default; GLES2GPUUniform(const GLES2GPUUniform &rhs) { *this = rhs; } @@ -137,10 +140,11 @@ struct GLES2GPUUniform final { if (size != rhs.size) { size = rhs.size; CC_SAFE_FREE(buff); - buff = (uint8_t *)CC_MALLOC(size); + buff = static_cast(CC_MALLOC(size)); } - if (buff && rhs.buff) + if (buff && rhs.buff) { memcpy(buff, rhs.buff, size); +} } return *this; } @@ -149,7 +153,7 @@ struct GLES2GPUUniform final { CC_SAFE_FREE(buff); } }; -typedef vector GLES2GPUUniformList; +using GLES2GPUUniformList = vector; struct GLES2GPUUniformBlock final { uint set = 0; @@ -160,29 +164,29 @@ struct GLES2GPUUniformBlock final { GLES2GPUUniformList glUniforms; GLES2GPUUniformList glActiveUniforms; }; -typedef vector GLES2GPUUniformBlockList; +using GLES2GPUUniformBlockList = vector; struct GLES2GPUUniformSampler final { uint set = 0; uint binding = 0; String name; Type type = Type::UNKNOWN; - uint count = 0u; + uint count = 0U; vector units; GLenum glType = 0; GLint glLoc = -1; }; -typedef vector GLES2GPUUniformSamplerList; +using GLES2GPUUniformSamplerList = vector; struct GLES2GPUShaderStage final { GLES2GPUShaderStage(ShaderStageFlagBit t, String s, GLuint shader = 0) - : type(t), source(s), glShader(shader) {} + : type(t), source(std::move(std::move(s))), glShader(shader) {} ShaderStageFlagBit type; String source; GLuint glShader = 0; }; -typedef vector GLES2GPUShaderStageList; +using GLES2GPUShaderStageList = vector; class GLES2GPUShader final : public Object { public: @@ -208,7 +212,7 @@ struct GLES2GPUAttribute final { bool isInstanced = false; uint offset = 0; }; -typedef vector GLES2GPUAttributeList; +using GLES2GPUAttributeList = vector; class GLES2GPUInputAssembler final : public Object { public: @@ -243,9 +247,9 @@ public: vector bindingIndices; vector descriptorIndices; - uint descriptorCount = 0u; + uint descriptorCount = 0U; }; -typedef vector GLES2GPUDescriptorSetLayoutList; +using GLES2GPUDescriptorSetLayoutList = vector; class GLES2GPUPipelineLayout final : public Object { public: @@ -278,7 +282,7 @@ struct GLES2GPUDescriptor final { GLES2GPUTexture *gpuTexture = nullptr; GLES2GPUSampler *gpuSampler = nullptr; }; -typedef vector GLES2GPUDescriptorList; +using GLES2GPUDescriptorList = vector; class GLES2GPUDescriptorSet final : public Object { public: @@ -291,7 +295,7 @@ public: }; struct GLES2ObjectCache final { - size_t numClearColors = 0u; + size_t numClearColors = 0U; GLES2GPURenderPass *gpuRenderPass = nullptr; GLES2GPUFramebuffer *gpuFramebuffer = nullptr; GLES2GPUPipelineState *gpuPipelineState = nullptr; @@ -325,7 +329,7 @@ public: GLES2ObjectCache gfxStateCache; void initialize(size_t texUnits, size_t vertexAttributes) { - glTextures.resize(texUnits, 0u); + glTextures.resize(texUnits, 0U); glEnabledAttribLocs.resize(vertexAttributes, false); glCurrentAttribLocs.resize(vertexAttributes, false); } @@ -336,10 +340,10 @@ public: glUniformBuffer = 0; glVAO = 0; texUint = 0; - glTextures.assign(glTextures.size(), 0u); + glTextures.assign(glTextures.size(), 0U); glProgram = 0; - glEnabledAttribLocs.assign(glEnabledAttribLocs.size(), 0u); - glCurrentAttribLocs.assign(glCurrentAttribLocs.size(), 0u); + glEnabledAttribLocs.assign(glEnabledAttribLocs.size(), false); + glCurrentAttribLocs.assign(glCurrentAttribLocs.size(), false); glFramebuffer = 0; glReadFBO = 0; isCullFaceEnabled = true; @@ -352,19 +356,19 @@ public: bs = BlendState(); gfxStateCache.gpuPipelineState = nullptr; - gfxStateCache.numClearColors = 0u; + gfxStateCache.numClearColors = 0U; gfxStateCache.gpuRenderPass = nullptr; gfxStateCache.gpuFramebuffer = nullptr; gfxStateCache.gpuInputAssembler = nullptr; - gfxStateCache.glPrimitive = 0u; + gfxStateCache.glPrimitive = 0U; gfxStateCache.reverseCW = false; } }; -constexpr size_t chunkSize = 16 * 1024 * 1024; // 16M per block by default +constexpr size_t CHUNK_SIZE = 16 * 1024 * 1024; // 16M per block by default class GLES2GPUStagingBufferPool final : public Object { public: - ~GLES2GPUStagingBufferPool() { + ~GLES2GPUStagingBufferPool() override { for (Buffer &buffer : _pool) { CC_FREE(buffer.mappedData); } @@ -374,9 +378,9 @@ public: uint8_t *alloc(size_t size) { size_t bufferCount = _pool.size(); Buffer *buffer = nullptr; - for (size_t idx = 0u; idx < bufferCount; idx++) { + for (size_t idx = 0U; idx < bufferCount; idx++) { Buffer *cur = &_pool[idx]; - if (chunkSize - cur->curOffset >= size) { + if (CHUNK_SIZE - cur->curOffset >= size) { buffer = cur; break; } @@ -384,7 +388,7 @@ public: if (!buffer) { _pool.resize(bufferCount + 1); buffer = &_pool.back(); - buffer->mappedData = (uint8_t *)CC_MALLOC(chunkSize); + buffer->mappedData = static_cast(CC_MALLOC(CHUNK_SIZE)); } uint8_t *data = buffer->mappedData + buffer->curOffset; buffer->curOffset += size; @@ -393,14 +397,14 @@ public: void reset() { for (Buffer &buffer : _pool) { - buffer.curOffset = 0u; + buffer.curOffset = 0U; } } private: struct Buffer { uint8_t *mappedData = nullptr; - size_t curOffset = 0u; + size_t curOffset = 0U; }; vector _pool; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp index 7ba146f931..7aeca7b555 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp @@ -33,9 +33,7 @@ namespace cc { namespace gfx { -GLES2InputAssembler::GLES2InputAssembler() -: InputAssembler() { -} +GLES2InputAssembler::GLES2InputAssembler() = default; GLES2InputAssembler::~GLES2InputAssembler() { destroy(); @@ -46,21 +44,23 @@ void GLES2InputAssembler::doInit(const InputAssemblerInfo &info) { _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { - GLES2Buffer *vb = (GLES2Buffer *)_vertexBuffers[i]; + auto *vb = static_cast(_vertexBuffers[i]); _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } - if (info.indexBuffer) + if (info.indexBuffer) { _gpuInputAssembler->gpuIndexBuffer = static_cast(info.indexBuffer)->gpuBuffer(); + } - if (info.indirectBuffer) + if (info.indirectBuffer) { _gpuInputAssembler->gpuIndirectBuffer = static_cast(info.indirectBuffer)->gpuBuffer(); + } - GLES2CmdFuncCreateInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); + cmdFuncGLES2CreateInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); } void GLES2InputAssembler::doDestroy() { if (_gpuInputAssembler) { - GLES2CmdFuncDestroyInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); + cmdFuncGLES2DestroyInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); CC_DELETE(_gpuInputAssembler); _gpuInputAssembler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp index 9a3fafc8e4..c010ebef29 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp @@ -38,15 +38,11 @@ namespace cc { namespace gfx { -GLES2PrimaryCommandBuffer::GLES2PrimaryCommandBuffer() -: GLES2CommandBuffer() { -} - GLES2PrimaryCommandBuffer::~GLES2PrimaryCommandBuffer() { destroy(); } -void GLES2PrimaryCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void GLES2PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -58,56 +54,55 @@ void GLES2PrimaryCommandBuffer::begin(RenderPass *renderPass, uint subpass, Fram void GLES2PrimaryCommandBuffer::end() { if (_isStateInvalid) { - BindStates(); + bindStates(); } _isInRenderPass = false; } -void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { - _isInRenderPass = true; - GLES2GPURenderPass *gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); +void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { + _isInRenderPass = true; + GLES2GPURenderPass * gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); GLES2GPUFramebuffer *gpuFramebuffer = static_cast(fbo)->gpuFBO(); - GLES2CmdFuncBeginRenderPass(GLES2Device::getInstance(), gpuRenderPass, gpuFramebuffer, + cmdFuncGLES2BeginRenderPass(GLES2Device::getInstance(), gpuRenderPass, gpuFramebuffer, renderArea, gpuRenderPass->colorAttachments.size(), colors, depth, stencil); } void GLES2PrimaryCommandBuffer::endRenderPass() { - GLES2CmdFuncEndRenderPass(GLES2Device::getInstance()); + cmdFuncGLES2EndRenderPass(GLES2Device::getInstance()); _isInRenderPass = false; } -void GLES2PrimaryCommandBuffer::draw(InputAssembler *ia) { +void GLES2PrimaryCommandBuffer::draw(const DrawInfo &info) { if (_isStateInvalid) { vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; - vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; + for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); } - GLES2CmdFuncBindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, - _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); + cmdFuncGLES2BindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, + _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); _isStateInvalid = false; } - DrawInfo drawInfo; - ia->extractDrawInfo(drawInfo); - GLES2CmdFuncDraw(GLES2Device::getInstance(), drawInfo); + cmdFuncGLES2Draw(GLES2Device::getInstance(), info); ++_numDrawCalls; - _numInstances += ia->getInstanceCount(); + _numInstances += info.instanceCount; + uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; if (_curGPUPipelineState) { switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { - _numTriangles += ia->getIndexCount() / 3 * std::max(ia->getInstanceCount(), 1U); + _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); break; } case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: { - _numTriangles += (ia->getIndexCount() - 2) * std::max(ia->getInstanceCount(), 1U); + _numTriangles += (indexCount - 2) * std::max(info.instanceCount, 1U); break; } default: @@ -119,25 +114,25 @@ void GLES2PrimaryCommandBuffer::draw(InputAssembler *ia) { void GLES2PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { GLES2GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { - GLES2CmdFuncUpdateBuffer(GLES2Device::getInstance(), gpuBuffer, data, 0u, size); + cmdFuncGLES2UpdateBuffer(GLES2Device::getInstance(), gpuBuffer, data, 0U, size); } } void GLES2PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { GLES2GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { - GLES2CmdFuncCopyBuffersToTexture(GLES2Device::getInstance(), buffers, gpuTexture, regions, count); + cmdFuncGLES2CopyBuffersToTexture(GLES2Device::getInstance(), buffers, gpuTexture, regions, count); } } void GLES2PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { - GLES2PrimaryCommandBuffer *cmdBuff = (GLES2PrimaryCommandBuffer *)cmdBuffs[i]; + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES2CmdFuncExecuteCmds(GLES2Device::getInstance(), cmdPackage); + cmdFuncGLES2ExecuteCmds(GLES2Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); @@ -151,5 +146,20 @@ void GLES2PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t } } +void GLES2PrimaryCommandBuffer::bindStates() { + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; + for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { + size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; + //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); + count = std::min(count, _curDynamicOffsets[i].size()); + if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + } + cmdFuncGLES2BindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, + _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); + + _isStateInvalid = false; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h index e38010049d..144f8cb865 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h @@ -26,26 +26,29 @@ #pragma once #include "GLES2CommandBuffer.h" +#include "GLES2Std.h" namespace cc { namespace gfx { class CC_GLES2_API GLES2PrimaryCommandBuffer final : public GLES2CommandBuffer { public: - GLES2PrimaryCommandBuffer(); - ~GLES2PrimaryCommandBuffer(); + GLES2PrimaryCommandBuffer() = default; + ~GLES2PrimaryCommandBuffer() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; void endRenderPass() override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: friend class GLES2Queue; + + void bindStates() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp index ffac5995b3..a5b5244a3b 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp @@ -27,15 +27,13 @@ #include "GLES2CommandBuffer.h" #include "GLES2Commands.h" -#include "GLES2Queue.h" #include "GLES2Device.h" +#include "GLES2Queue.h" namespace cc { namespace gfx { -GLES2Queue::GLES2Queue() -: Queue() { -} +GLES2Queue::GLES2Queue() = default; GLES2Queue::~GLES2Queue() { destroy(); @@ -49,12 +47,12 @@ void GLES2Queue::doDestroy() { void GLES2Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { for (uint i = 0; i < count; ++i) { - GLES2CommandBuffer *cmdBuff = (GLES2CommandBuffer *)cmdBuffs[i]; + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES2CmdFuncExecuteCmds(GLES2Device::getInstance(), cmdPackage); + cmdFuncGLES2ExecuteCmds(GLES2Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp b/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp index e18f10b2ea..c2d219ad99 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES2Sampler::GLES2Sampler() -: Sampler() { -} +GLES2Sampler::GLES2Sampler() = default; GLES2Sampler::~GLES2Sampler() { destroy(); } -void GLES2Sampler::doInit(const SamplerInfo &info) { +void GLES2Sampler::doInit(const SamplerInfo & /*info*/) { _gpuSampler = CC_NEW(GLES2GPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; @@ -49,12 +47,12 @@ void GLES2Sampler::doInit(const SamplerInfo &info) { _gpuSampler->addressV = _addressV; _gpuSampler->addressW = _addressW; - GLES2CmdFuncCreateSampler(GLES2Device::getInstance(), _gpuSampler); + cmdFuncGLES2CreateSampler(GLES2Device::getInstance(), _gpuSampler); } void GLES2Sampler::doDestroy() { if (_gpuSampler) { - GLES2CmdFuncDestroySampler(GLES2Device::getInstance(), _gpuSampler); + cmdFuncGLES2DestroySampler(GLES2Device::getInstance(), _gpuSampler); CC_DELETE(_gpuSampler); _gpuSampler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp index 6e8ff19fa0..e299442f2d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES2Shader::GLES2Shader() -: Shader() { -} +GLES2Shader::GLES2Shader() = default; GLES2Shader::~GLES2Shader() { destroy(); } -void GLES2Shader::doInit(const ShaderInfo &info) { +void GLES2Shader::doInit(const ShaderInfo & /*info*/) { _gpuShader = CC_NEW(GLES2GPUShader); _gpuShader->name = _name; _gpuShader->blocks = _blocks; @@ -50,12 +48,12 @@ void GLES2Shader::doInit(const ShaderInfo &info) { _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } - GLES2CmdFuncCreateShader(GLES2Device::getInstance(), _gpuShader); + cmdFuncGLES2CreateShader(GLES2Device::getInstance(), _gpuShader); } void GLES2Shader::doDestroy() { if (_gpuShader) { - GLES2CmdFuncDestroyShader(GLES2Device::getInstance(), _gpuShader); + cmdFuncGLES2DestroyShader(GLES2Device::getInstance(), _gpuShader); CC_DELETE(_gpuShader); _gpuShader = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp index 5592aabda5..505a05c2fd 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp @@ -25,56 +25,54 @@ #include "GLES2Std.h" +#include "GLES2Commands.h" #include "GLES2Device.h" #include "GLES2Texture.h" -#include "GLES2Commands.h" namespace cc { namespace gfx { -GLES2Texture::GLES2Texture() -: Texture() { -} +GLES2Texture::GLES2Texture() = default; GLES2Texture::~GLES2Texture() { destroy(); } -void GLES2Texture::doInit(const TextureInfo &info) { - _gpuTexture = CC_NEW(GLES2GPUTexture); - _gpuTexture->type = _type; - _gpuTexture->format = _format; - _gpuTexture->usage = _usage; - _gpuTexture->width = _width; - _gpuTexture->height = _height; - _gpuTexture->depth = _depth; - _gpuTexture->size = _size; +void GLES2Texture::doInit(const TextureInfo & /*info*/) { + _gpuTexture = CC_NEW(GLES2GPUTexture); + _gpuTexture->type = _type; + _gpuTexture->format = _format; + _gpuTexture->usage = _usage; + _gpuTexture->width = _width; + _gpuTexture->height = _height; + _gpuTexture->depth = _depth; + _gpuTexture->size = _size; _gpuTexture->arrayLayer = _layerCount; - _gpuTexture->mipLevel = _levelCount; - _gpuTexture->samples = _samples; - _gpuTexture->flags = _flags; + _gpuTexture->mipLevel = _levelCount; + _gpuTexture->samples = _samples; + _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); - GLES2CmdFuncCreateTexture(GLES2Device::getInstance(), _gpuTexture); + cmdFuncGLES2CreateTexture(GLES2Device::getInstance(), _gpuTexture); } -void GLES2Texture::doInit(const TextureViewInfo &info) { +void GLES2Texture::doInit(const TextureViewInfo & /*info*/) { CC_LOG_ERROR("GLES2 doesn't support texture view"); } void GLES2Texture::doDestroy() { if (_gpuTexture) { - GLES2CmdFuncDestroyTexture(GLES2Device::getInstance(), _gpuTexture); + cmdFuncGLES2DestroyTexture(GLES2Device::getInstance(), _gpuTexture); CC_DELETE(_gpuTexture); _gpuTexture = nullptr; } } void GLES2Texture::doResize(uint width, uint height, uint size) { - _gpuTexture->width = width; + _gpuTexture->width = width; _gpuTexture->height = height; - _gpuTexture->size = size; - GLES2CmdFuncResizeTexture(GLES2Device::getInstance(), _gpuTexture); + _gpuTexture->size = size; + cmdFuncGLES2ResizeTexture(GLES2Device::getInstance(), _gpuTexture); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp index 27623d06f4..9ee6203cc2 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp @@ -25,55 +25,53 @@ #include "GLES3Std.h" -#include "GLES3Device.h" #include "GLES3Buffer.h" #include "GLES3Commands.h" +#include "GLES3Device.h" namespace cc { namespace gfx { -GLES3Buffer::GLES3Buffer() -: Buffer() { -} +GLES3Buffer::GLES3Buffer() = default; GLES3Buffer::~GLES3Buffer() { destroy(); } -void GLES3Buffer::doInit(const BufferInfo &info) { - _gpuBuffer = CC_NEW(GLES3GPUBuffer); - _gpuBuffer->usage = _usage; +void GLES3Buffer::doInit(const BufferInfo & /*info*/) { + _gpuBuffer = CC_NEW(GLES3GPUBuffer); + _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; - _gpuBuffer->size = _size; - _gpuBuffer->stride = _stride; - _gpuBuffer->count = _count; + _gpuBuffer->size = _size; + _gpuBuffer->stride = _stride; + _gpuBuffer->count = _count; if (_usage & BufferUsageBit::INDIRECT) { _gpuBuffer->indirects.resize(_count); } - GLES3CmdFuncCreateBuffer(GLES3Device::getInstance(), _gpuBuffer); + cmdFuncGLES3CreateBuffer(GLES3Device::getInstance(), _gpuBuffer); } void GLES3Buffer::doInit(const BufferViewInfo &info) { - GLES3Buffer *buffer = (GLES3Buffer *)info.buffer; - _gpuBuffer = CC_NEW(GLES3GPUBuffer); - _gpuBuffer->usage = _usage; - _gpuBuffer->memUsage = _memUsage; - _gpuBuffer->size = _size; - _gpuBuffer->stride = _stride; - _gpuBuffer->count = _count; - _gpuBuffer->glTarget = buffer->_gpuBuffer->glTarget; - _gpuBuffer->glBuffer = buffer->_gpuBuffer->glBuffer; - _gpuBuffer->glOffset = info.offset; - _gpuBuffer->buffer = buffer->_gpuBuffer->buffer; + auto *buffer = static_cast(info.buffer); + _gpuBuffer = CC_NEW(GLES3GPUBuffer); + _gpuBuffer->usage = _usage; + _gpuBuffer->memUsage = _memUsage; + _gpuBuffer->size = _size; + _gpuBuffer->stride = _stride; + _gpuBuffer->count = _count; + _gpuBuffer->glTarget = buffer->_gpuBuffer->glTarget; + _gpuBuffer->glBuffer = buffer->_gpuBuffer->glBuffer; + _gpuBuffer->glOffset = info.offset; + _gpuBuffer->buffer = buffer->_gpuBuffer->buffer; _gpuBuffer->indirects = buffer->_gpuBuffer->indirects; } void GLES3Buffer::doDestroy() { if (_gpuBuffer) { if (!_isBufferView) { - GLES3CmdFuncDestroyBuffer(GLES3Device::getInstance(), _gpuBuffer); + cmdFuncGLES3DestroyBuffer(GLES3Device::getInstance(), _gpuBuffer); } CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; @@ -83,11 +81,11 @@ void GLES3Buffer::doDestroy() { void GLES3Buffer::doResize(uint size, uint count) { _gpuBuffer->size = size; _gpuBuffer->count = count; - GLES3CmdFuncResizeBuffer(GLES3Device::getInstance(), _gpuBuffer); + cmdFuncGLES3ResizeBuffer(GLES3Device::getInstance(), _gpuBuffer); } void GLES3Buffer::update(void *buffer, uint size) { - GLES3CmdFuncUpdateBuffer(GLES3Device::getInstance(), _gpuBuffer, buffer, 0u, size); + cmdFuncGLES3UpdateBuffer(GLES3Device::getInstance(), _gpuBuffer, buffer, 0U, size); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index c5f4c6e4e6..32e0c9dcaa 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -39,15 +39,11 @@ namespace cc { namespace gfx { -GLES3CommandBuffer::GLES3CommandBuffer() -: CommandBuffer() { -} - GLES3CommandBuffer::~GLES3CommandBuffer() { destroy(); } -void GLES3CommandBuffer::doInit(const CommandBufferInfo &info) { +void GLES3CommandBuffer::doInit(const CommandBufferInfo & /*info*/) { _cmdAllocator = CC_NEW(GLES3GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES3CmdPackage); @@ -57,6 +53,8 @@ void GLES3CommandBuffer::doInit(const CommandBufferInfo &info) { } void GLES3CommandBuffer::doDestroy() { + if (!_cmdAllocator) return; + _cmdAllocator->clearCmds(_curCmdPackage); CC_SAFE_DELETE(_curCmdPackage); @@ -75,10 +73,10 @@ void GLES3CommandBuffer::doDestroy() { } _cmdAllocator->reset(); - CC_DELETE(_cmdAllocator); + CC_SAFE_DELETE(_cmdAllocator); } -void GLES3CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void GLES3CommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -92,7 +90,7 @@ void GLES3CommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer void GLES3CommandBuffer::end() { if (_isStateInvalid) { - BindStates(); + bindStates(); } _isInRenderPass = false; @@ -105,7 +103,7 @@ void GLES3CommandBuffer::end() { } } -void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { +void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { _isInRenderPass = true; GLES3CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc(); @@ -244,27 +242,28 @@ void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint m } } -void GLES3CommandBuffer::draw(InputAssembler *ia) { +void GLES3CommandBuffer::draw(const DrawInfo &info) { if (_isStateInvalid) { - BindStates(); + bindStates(); } GLES3CmdDraw *cmd = _cmdAllocator->drawCmdPool.alloc(); - static_cast(ia)->ExtractCmdDraw(cmd); + cmd->drawInfo = info; _curCmdPackage->drawCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::DRAW); ++_numDrawCalls; - _numInstances += ia->getInstanceCount(); + _numInstances += info.instanceCount; if (_curGPUPipelineState) { + uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { - _numTriangles += ia->getIndexCount() / 3 * std::max(ia->getInstanceCount(), 1U); + _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); break; } case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: { - _numTriangles += (ia->getIndexCount() - 2) * std::max(ia->getInstanceCount(), 1U); + _numTriangles += (indexCount - 2) * std::max(info.instanceCount, 1U); break; } default: @@ -279,7 +278,7 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) GLES3CmdUpdateBuffer *cmd = _cmdAllocator->updateBufferCmdPool.alloc(); cmd->gpuBuffer = gpuBuffer; cmd->size = size; - cmd->buffer = (uint8_t *)data; + cmd->buffer = static_cast(data); _curCmdPackage->updateBufferCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::UPDATE_BUFFER); @@ -317,8 +316,8 @@ void GLES3CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) CCASSERT(false, "Command 'execute' must be recorded in primary command buffers."); for (uint i = 0; i < count; ++i) { - GLES3CommandBuffer *cmdBuff = (GLES3CommandBuffer *)cmdBuffs[i]; - GLES3CmdPackage * cmdPackage = cmdBuff->_pendingPackages.front(); + auto * cmdBuff = static_cast(cmdBuffs[i]); + GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); for (uint j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { GLES3CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[j]; @@ -376,7 +375,7 @@ void GLES3CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) } } -void GLES3CommandBuffer::BindStates() { +void GLES3CommandBuffer::bindStates() { GLES3CmdBindStates *cmd = _cmdAllocator->bindStatesCmdPool.alloc(); cmd->gpuPipelineState = _curGPUPipelineState; cmd->gpuInputAssembler = _curGPUInputAssember; @@ -385,7 +384,7 @@ void GLES3CommandBuffer::BindStates() { if (_curGPUPipelineState) { vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; cmd->dynamicOffsets.resize(_curGPUPipelineState->gpuPipelineLayout->dynamicOffsetCount); - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); @@ -412,7 +411,7 @@ void GLES3CommandBuffer::BindStates() { void GLES3CommandBuffer::dispatch(const DispatchInfo &info) { if (_isStateInvalid) { - BindStates(); + bindStates(); } GLES3CmdDispatch *cmd = _cmdAllocator->dispatchCmdPool.alloc(); @@ -428,10 +427,10 @@ void GLES3CommandBuffer::dispatch(const DispatchInfo &info) { _curCmdPackage->cmds.push(GLESCmdType::DISPATCH); } -void GLES3CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void GLES3CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint /*textureBarrierCount*/) { if (!barrier) return; - auto gpuBarrier = static_cast(barrier)->gpuBarrier(); + const auto *gpuBarrier = static_cast(barrier)->gpuBarrier(); GLES3CmdBarrier *cmd = _cmdAllocator->barrierCmdPool.alloc(); cmd->barriers = gpuBarrier->glBarriers; diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index f82c86bac1..b1d3fb2cb8 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -36,8 +36,8 @@ class GLES3GPUCommandAllocator; class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer { public: - GLES3CommandBuffer(); - ~GLES3CommandBuffer(); + GLES3CommandBuffer() = default; + ~GLES3CommandBuffer() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; @@ -54,7 +54,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; @@ -68,7 +68,7 @@ protected: void doInit(const CommandBufferInfo &info) override; void doDestroy() override; - virtual void BindStates(); + virtual void bindStates(); GLES3GPUCommandAllocator *_cmdAllocator = nullptr; GLES3CmdPackage *_curCmdPackage = nullptr; @@ -81,7 +81,7 @@ protected: vector> _curDynamicOffsets; Viewport _curViewport; Rect _curScissor; - float _curLineWidth = 1.0f; + float _curLineWidth = 1.0F; GLES3DepthBias _curDepthBias; Color _curBlendConstants; GLES3DepthBounds _curDepthBounds; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index e7222779e9..0689b21f15 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -37,7 +37,7 @@ namespace cc { namespace gfx { namespace { -GLenum MapGLInternalFormat(Format format) { +GLenum mapGLInternalFormat(Format format) { switch (format) { case Format::A8: return GL_ALPHA; case Format::L8: return GL_LUMINANCE; @@ -121,35 +121,35 @@ GLenum MapGLInternalFormat(Format format) { case Format::PVRTC_RGB4: return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; case Format::PVRTC_RGBA4: return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - case Format::ASTC_RGBA_4x4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - case Format::ASTC_RGBA_5x4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - case Format::ASTC_RGBA_5x5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - case Format::ASTC_RGBA_6x5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - case Format::ASTC_RGBA_6x6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - case Format::ASTC_RGBA_8x5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - case Format::ASTC_RGBA_8x6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - case Format::ASTC_RGBA_8x8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - case Format::ASTC_RGBA_10x5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - case Format::ASTC_RGBA_10x6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - case Format::ASTC_RGBA_10x8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - case Format::ASTC_RGBA_10x10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - case Format::ASTC_RGBA_12x10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - case Format::ASTC_RGBA_12x12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + case Format::ASTC_RGBA_4X4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case Format::ASTC_RGBA_5X4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + case Format::ASTC_RGBA_5X5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + case Format::ASTC_RGBA_6X5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + case Format::ASTC_RGBA_6X6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + case Format::ASTC_RGBA_8X5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + case Format::ASTC_RGBA_8X6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + case Format::ASTC_RGBA_8X8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + case Format::ASTC_RGBA_10X5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + case Format::ASTC_RGBA_10X6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + case Format::ASTC_RGBA_10X8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + case Format::ASTC_RGBA_10X10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + case Format::ASTC_RGBA_12X10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + case Format::ASTC_RGBA_12X12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - case Format::ASTC_SRGBA_4x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - case Format::ASTC_SRGBA_5x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - case Format::ASTC_SRGBA_5x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - case Format::ASTC_SRGBA_6x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - case Format::ASTC_SRGBA_6x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - case Format::ASTC_SRGBA_8x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - case Format::ASTC_SRGBA_8x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - case Format::ASTC_SRGBA_8x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - case Format::ASTC_SRGBA_10x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - case Format::ASTC_SRGBA_10x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - case Format::ASTC_SRGBA_10x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - case Format::ASTC_SRGBA_10x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - case Format::ASTC_SRGBA_12x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - case Format::ASTC_SRGBA_12x12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; + case Format::ASTC_SRGBA_4X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + case Format::ASTC_SRGBA_5X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + case Format::ASTC_SRGBA_5X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + case Format::ASTC_SRGBA_6X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + case Format::ASTC_SRGBA_6X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + case Format::ASTC_SRGBA_8X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + case Format::ASTC_SRGBA_8X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + case Format::ASTC_SRGBA_8X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + case Format::ASTC_SRGBA_10X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + case Format::ASTC_SRGBA_10X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + case Format::ASTC_SRGBA_10X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + case Format::ASTC_SRGBA_10X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + case Format::ASTC_SRGBA_12X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + case Format::ASTC_SRGBA_12X12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; default: { CCASSERT(false, "Unsupported Format, convert to GL internal format failed."); @@ -158,7 +158,7 @@ GLenum MapGLInternalFormat(Format format) { } } -GLenum MapGLFormat(Format format) { +GLenum mapGLFormat(Format format) { switch (format) { case Format::A8: return GL_ALPHA; case Format::L8: return GL_LUMINANCE; @@ -202,11 +202,11 @@ GLenum MapGLFormat(Format format) { case Format::RGB32F: return GL_RGB; case Format::RGBA32UI: case Format::RGBA32I: - case Format::RGBA32F: return GL_RGBA; + case Format::RGBA32F: case Format::RGB10A2: return GL_RGBA; - case Format::R11G11B10F: return GL_RGB; + case Format::R11G11B10F: case Format::R5G6B5: return GL_RGB; - case Format::RGB5A1: return GL_RGBA; + case Format::RGB5A1: case Format::RGBA4: return GL_RGBA; case Format::D16: return GL_DEPTH_COMPONENT; case Format::D16S8: return GL_DEPTH_STENCIL; @@ -241,35 +241,35 @@ GLenum MapGLFormat(Format format) { case Format::PVRTC_RGB4: return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; case Format::PVRTC_RGBA4: return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - case Format::ASTC_RGBA_4x4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; - case Format::ASTC_RGBA_5x4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; - case Format::ASTC_RGBA_5x5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; - case Format::ASTC_RGBA_6x5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; - case Format::ASTC_RGBA_6x6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; - case Format::ASTC_RGBA_8x5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; - case Format::ASTC_RGBA_8x6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; - case Format::ASTC_RGBA_8x8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; - case Format::ASTC_RGBA_10x5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; - case Format::ASTC_RGBA_10x6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; - case Format::ASTC_RGBA_10x8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; - case Format::ASTC_RGBA_10x10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; - case Format::ASTC_RGBA_12x10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; - case Format::ASTC_RGBA_12x12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; + case Format::ASTC_RGBA_4X4: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR; + case Format::ASTC_RGBA_5X4: return GL_COMPRESSED_RGBA_ASTC_5x4_KHR; + case Format::ASTC_RGBA_5X5: return GL_COMPRESSED_RGBA_ASTC_5x5_KHR; + case Format::ASTC_RGBA_6X5: return GL_COMPRESSED_RGBA_ASTC_6x5_KHR; + case Format::ASTC_RGBA_6X6: return GL_COMPRESSED_RGBA_ASTC_6x6_KHR; + case Format::ASTC_RGBA_8X5: return GL_COMPRESSED_RGBA_ASTC_8x5_KHR; + case Format::ASTC_RGBA_8X6: return GL_COMPRESSED_RGBA_ASTC_8x6_KHR; + case Format::ASTC_RGBA_8X8: return GL_COMPRESSED_RGBA_ASTC_8x8_KHR; + case Format::ASTC_RGBA_10X5: return GL_COMPRESSED_RGBA_ASTC_10x5_KHR; + case Format::ASTC_RGBA_10X6: return GL_COMPRESSED_RGBA_ASTC_10x6_KHR; + case Format::ASTC_RGBA_10X8: return GL_COMPRESSED_RGBA_ASTC_10x8_KHR; + case Format::ASTC_RGBA_10X10: return GL_COMPRESSED_RGBA_ASTC_10x10_KHR; + case Format::ASTC_RGBA_12X10: return GL_COMPRESSED_RGBA_ASTC_12x10_KHR; + case Format::ASTC_RGBA_12X12: return GL_COMPRESSED_RGBA_ASTC_12x12_KHR; - case Format::ASTC_SRGBA_4x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; - case Format::ASTC_SRGBA_5x4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; - case Format::ASTC_SRGBA_5x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; - case Format::ASTC_SRGBA_6x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; - case Format::ASTC_SRGBA_6x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; - case Format::ASTC_SRGBA_8x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; - case Format::ASTC_SRGBA_8x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; - case Format::ASTC_SRGBA_8x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; - case Format::ASTC_SRGBA_10x5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; - case Format::ASTC_SRGBA_10x6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; - case Format::ASTC_SRGBA_10x8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; - case Format::ASTC_SRGBA_10x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; - case Format::ASTC_SRGBA_12x10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; - case Format::ASTC_SRGBA_12x12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; + case Format::ASTC_SRGBA_4X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR; + case Format::ASTC_SRGBA_5X4: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR; + case Format::ASTC_SRGBA_5X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR; + case Format::ASTC_SRGBA_6X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR; + case Format::ASTC_SRGBA_6X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR; + case Format::ASTC_SRGBA_8X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR; + case Format::ASTC_SRGBA_8X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR; + case Format::ASTC_SRGBA_8X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR; + case Format::ASTC_SRGBA_10X5: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR; + case Format::ASTC_SRGBA_10X6: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR; + case Format::ASTC_SRGBA_10X8: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR; + case Format::ASTC_SRGBA_10X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR; + case Format::ASTC_SRGBA_12X10: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR; + case Format::ASTC_SRGBA_12X12: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR; default: { CCASSERT(false, "Unsupported Format, convert to WebGL format failed."); @@ -278,7 +278,7 @@ GLenum MapGLFormat(Format format) { } } -GLenum MapGLType(Type type) { +GLenum mapGLType(Type type) { switch (type) { case Type::BOOL: return GL_BOOL; case Type::BOOL2: return GL_BOOL_VEC2; @@ -313,7 +313,7 @@ GLenum MapGLType(Type type) { } } -Type MapType(GLenum glType) { +Type mapType(GLenum glType) { switch (glType) { case GL_BOOL: return Type::BOOL; case GL_BOOL_VEC2: return Type::BOOL2; @@ -351,7 +351,7 @@ Type MapType(GLenum glType) { } } -GLenum FormatToGLType(Format format) { +GLenum formatToGLType(Format format) { switch (format) { case Format::R8: return GL_UNSIGNED_BYTE; case Format::R8SN: return GL_BYTE; @@ -375,7 +375,7 @@ GLenum FormatToGLType(Format format) { case Format::RG32UI: return GL_UNSIGNED_INT; case Format::RG32I: return GL_INT; - case Format::RGB8: return GL_UNSIGNED_BYTE; + case Format::RGB8: case Format::SRGB8: return GL_UNSIGNED_BYTE; case Format::RGB8SN: return GL_BYTE; case Format::RGB8UI: return GL_UNSIGNED_BYTE; @@ -387,7 +387,7 @@ GLenum FormatToGLType(Format format) { case Format::RGB32UI: return GL_UNSIGNED_INT; case Format::RGB32I: return GL_INT; - case Format::RGBA8: return GL_UNSIGNED_BYTE; + case Format::RGBA8: case Format::SRGB8_A8: return GL_UNSIGNED_BYTE; case Format::RGBA8SN: return GL_BYTE; case Format::RGBA8UI: return GL_UNSIGNED_BYTE; @@ -403,7 +403,7 @@ GLenum FormatToGLType(Format format) { case Format::R11G11B10F: return GL_UNSIGNED_INT_10F_11F_11F_REV; case Format::RGB5A1: return GL_UNSIGNED_SHORT_5_5_5_1; case Format::RGBA4: return GL_UNSIGNED_SHORT_4_4_4_4; - case Format::RGB10A2: return GL_UNSIGNED_INT_2_10_10_10_REV; + case Format::RGB10A2: case Format::RGB10A2UI: return GL_UNSIGNED_INT_2_10_10_10_REV; case Format::RGB9E5: return GL_FLOAT; @@ -414,66 +414,66 @@ GLenum FormatToGLType(Format format) { case Format::D32F: return GL_FLOAT; case Format::D32F_S8: return GL_FLOAT_32_UNSIGNED_INT_24_8_REV; - case Format::BC1: return GL_UNSIGNED_BYTE; - case Format::BC1_SRGB: return GL_UNSIGNED_BYTE; - case Format::BC2: return GL_UNSIGNED_BYTE; - case Format::BC2_SRGB: return GL_UNSIGNED_BYTE; - case Format::BC3: return GL_UNSIGNED_BYTE; - case Format::BC3_SRGB: return GL_UNSIGNED_BYTE; + case Format::BC1: + case Format::BC1_SRGB: + case Format::BC2: + case Format::BC2_SRGB: + case Format::BC3: + case Format::BC3_SRGB: case Format::BC4: return GL_UNSIGNED_BYTE; case Format::BC4_SNORM: return GL_BYTE; case Format::BC5: return GL_UNSIGNED_BYTE; case Format::BC5_SNORM: return GL_BYTE; - case Format::BC6H_SF16: return GL_FLOAT; + case Format::BC6H_SF16: case Format::BC6H_UF16: return GL_FLOAT; - case Format::BC7: return GL_UNSIGNED_BYTE; - case Format::BC7_SRGB: return GL_UNSIGNED_BYTE; + case Format::BC7: + case Format::BC7_SRGB: - case Format::ETC_RGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_RGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_SRGB8: return GL_UNSIGNED_BYTE; - case Format::ETC2_RGB8_A1: return GL_UNSIGNED_BYTE; - case Format::ETC2_SRGB8_A1: return GL_UNSIGNED_BYTE; + case Format::ETC_RGB8: + case Format::ETC2_RGB8: + case Format::ETC2_SRGB8: + case Format::ETC2_RGB8_A1: + case Format::ETC2_SRGB8_A1: case Format::EAC_R11: return GL_UNSIGNED_BYTE; case Format::EAC_R11SN: return GL_BYTE; case Format::EAC_RG11: return GL_UNSIGNED_BYTE; case Format::EAC_RG11SN: return GL_BYTE; - case Format::PVRTC_RGB2: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGBA2: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGB4: return GL_UNSIGNED_BYTE; - case Format::PVRTC_RGBA4: return GL_UNSIGNED_BYTE; - case Format::PVRTC2_2BPP: return GL_UNSIGNED_BYTE; - case Format::PVRTC2_4BPP: return GL_UNSIGNED_BYTE; + case Format::PVRTC_RGB2: + case Format::PVRTC_RGBA2: + case Format::PVRTC_RGB4: + case Format::PVRTC_RGBA4: + case Format::PVRTC2_2BPP: + case Format::PVRTC2_4BPP: - case Format::ASTC_RGBA_4x4: - case Format::ASTC_RGBA_5x4: - case Format::ASTC_RGBA_5x5: - case Format::ASTC_RGBA_6x5: - case Format::ASTC_RGBA_6x6: - case Format::ASTC_RGBA_8x5: - case Format::ASTC_RGBA_8x6: - case Format::ASTC_RGBA_8x8: - case Format::ASTC_RGBA_10x5: - case Format::ASTC_RGBA_10x6: - case Format::ASTC_RGBA_10x8: - case Format::ASTC_RGBA_10x10: - case Format::ASTC_RGBA_12x10: - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_4x4: - case Format::ASTC_SRGBA_5x4: - case Format::ASTC_SRGBA_5x5: - case Format::ASTC_SRGBA_6x5: - case Format::ASTC_SRGBA_6x6: - case Format::ASTC_SRGBA_8x5: - case Format::ASTC_SRGBA_8x6: - case Format::ASTC_SRGBA_8x8: - case Format::ASTC_SRGBA_10x5: - case Format::ASTC_SRGBA_10x6: - case Format::ASTC_SRGBA_10x8: - case Format::ASTC_SRGBA_10x10: - case Format::ASTC_SRGBA_12x10: - case Format::ASTC_SRGBA_12x12: + case Format::ASTC_RGBA_4X4: + case Format::ASTC_RGBA_5X4: + case Format::ASTC_RGBA_5X5: + case Format::ASTC_RGBA_6X5: + case Format::ASTC_RGBA_6X6: + case Format::ASTC_RGBA_8X5: + case Format::ASTC_RGBA_8X6: + case Format::ASTC_RGBA_8X8: + case Format::ASTC_RGBA_10X5: + case Format::ASTC_RGBA_10X6: + case Format::ASTC_RGBA_10X8: + case Format::ASTC_RGBA_10X10: + case Format::ASTC_RGBA_12X10: + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_4X4: + case Format::ASTC_SRGBA_5X4: + case Format::ASTC_SRGBA_5X5: + case Format::ASTC_SRGBA_6X5: + case Format::ASTC_SRGBA_6X6: + case Format::ASTC_SRGBA_8X5: + case Format::ASTC_SRGBA_8X6: + case Format::ASTC_SRGBA_8X8: + case Format::ASTC_SRGBA_10X5: + case Format::ASTC_SRGBA_10X6: + case Format::ASTC_SRGBA_10X8: + case Format::ASTC_SRGBA_10X10: + case Format::ASTC_SRGBA_12X10: + case Format::ASTC_SRGBA_12X12: return GL_UNSIGNED_BYTE; default: { @@ -482,7 +482,7 @@ GLenum FormatToGLType(Format format) { } } -uint GLTypeSize(GLenum glType) { +uint glTypeSize(GLenum glType) { switch (glType) { case GL_BOOL: return 4; case GL_BOOL_VEC2: return 8; @@ -499,7 +499,7 @@ uint GLTypeSize(GLenum glType) { case GL_FLOAT: return 4; case GL_FLOAT_VEC2: return 8; case GL_FLOAT_VEC3: return 12; - case GL_FLOAT_VEC4: return 16; + case GL_FLOAT_VEC4: case GL_FLOAT_MAT2: return 16; case GL_FLOAT_MAT2x3: return 24; case GL_FLOAT_MAT2x4: return 32; @@ -509,18 +509,18 @@ uint GLTypeSize(GLenum glType) { case GL_FLOAT_MAT4x2: return 32; case GL_FLOAT_MAT4x3: return 48; case GL_FLOAT_MAT4: return 64; - case GL_SAMPLER_2D: return 4; - case GL_SAMPLER_2D_ARRAY: return 4; - case GL_SAMPLER_2D_ARRAY_SHADOW: return 4; - case GL_SAMPLER_3D: return 4; - case GL_SAMPLER_CUBE: return 4; - case GL_INT_SAMPLER_2D: return 4; - case GL_INT_SAMPLER_2D_ARRAY: return 4; - case GL_INT_SAMPLER_3D: return 4; - case GL_INT_SAMPLER_CUBE: return 4; - case GL_UNSIGNED_INT_SAMPLER_2D: return 4; - case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: return 4; - case GL_UNSIGNED_INT_SAMPLER_3D: return 4; + case GL_SAMPLER_2D: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_ARRAY_SHADOW: + case GL_SAMPLER_3D: + case GL_SAMPLER_CUBE: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_3D: + case GL_INT_SAMPLER_CUBE: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_3D: case GL_UNSIGNED_INT_SAMPLER_CUBE: return 4; default: { CCASSERT(false, "Unsupported GLType, get type failed."); @@ -529,16 +529,16 @@ uint GLTypeSize(GLenum glType) { } } -uint GLComponentCount(GLenum glType) { +uint glComponentCount(GLenum glType) { switch (glType) { - case GL_FLOAT_MAT2: return 2; - case GL_FLOAT_MAT2x3: return 2; + case GL_FLOAT_MAT2: + case GL_FLOAT_MAT2x3: case GL_FLOAT_MAT2x4: return 2; - case GL_FLOAT_MAT3x2: return 3; - case GL_FLOAT_MAT3: return 3; + case GL_FLOAT_MAT3x2: + case GL_FLOAT_MAT3: case GL_FLOAT_MAT3x4: return 3; - case GL_FLOAT_MAT4x2: return 4; - case GL_FLOAT_MAT4x3: return 4; + case GL_FLOAT_MAT4x2: + case GL_FLOAT_MAT4x3: case GL_FLOAT_MAT4: return 4; default: { return 1; @@ -615,7 +615,7 @@ const GLenum GL_MEMORY_ACCESS[] = { }; } // namespace -void GLES3CmdFuncCreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { +void cmdFuncGLES3CreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { GLenum glUsage = (gpuBuffer->memUsage & MemoryUsageBit::HOST ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; @@ -687,7 +687,7 @@ void GLES3CmdFuncCreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { gpuBuffer->glTarget = GL_NONE; } else if ((gpuBuffer->usage & BufferUsageBit::TRANSFER_DST) || (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC)) { - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); + gpuBuffer->buffer = static_cast(CC_MALLOC(gpuBuffer->size)); gpuBuffer->glTarget = GL_NONE; } else { CCASSERT(false, "Unsupported BufferType, create buffer failed."); @@ -695,7 +695,7 @@ void GLES3CmdFuncCreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { } } -void GLES3CmdFuncDestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { +void cmdFuncGLES3DestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuBuffer->glBuffer) { @@ -754,10 +754,10 @@ void GLES3CmdFuncDestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { GL_CHECK(glDeleteBuffers(1, &gpuBuffer->glBuffer)); gpuBuffer->glBuffer = 0; } - CC_SAFE_FREE(gpuBuffer->buffer); + CC_SAFE_FREE(gpuBuffer->buffer) } -void GLES3CmdFuncResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { +void cmdFuncGLES3ResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLenum glUsage = (gpuBuffer->memUsage & MemoryUsageBit::HOST ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW); @@ -819,7 +819,7 @@ void GLES3CmdFuncResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { if (gpuBuffer->buffer) { CC_FREE(gpuBuffer->buffer); } - gpuBuffer->buffer = (uint8_t *)CC_MALLOC(gpuBuffer->size); + gpuBuffer->buffer = static_cast(CC_MALLOC(gpuBuffer->size)); gpuBuffer->glTarget = GL_NONE; } else { CCASSERT(false, "Unsupported BufferType, resize buffer failed."); @@ -827,10 +827,10 @@ void GLES3CmdFuncResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer) { } } -void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { - gpuTexture->glInternelFmt = MapGLInternalFormat(gpuTexture->format); - gpuTexture->glFormat = MapGLFormat(gpuTexture->format); - gpuTexture->glType = FormatToGLType(gpuTexture->format); +void cmdFuncGLES3CreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { + gpuTexture->glInternelFmt = mapGLInternalFormat(gpuTexture->format); + gpuTexture->glFormat = mapGLFormat(gpuTexture->format); + gpuTexture->glType = formatToGLType(gpuTexture->format); switch (gpuTexture->type) { case TextureType::TEX2D: { @@ -847,7 +847,7 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) if (gpuTexture->flags & TextureFlagBit::IMMUTABLE) { GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, gpuTexture->mipLevel, gpuTexture->glInternelFmt, w, h)); } else { - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); @@ -855,7 +855,7 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -879,7 +879,7 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) if (gpuTexture->flags & TextureFlagBit::IMMUTABLE) { GL_CHECK(glTexStorage2D(GL_TEXTURE_CUBE_MAP, gpuTexture->mipLevel, gpuTexture->glInternelFmt, w, h)); } else { - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { for (uint f = 0; f < 6; ++f) { GL_CHECK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); @@ -889,7 +889,7 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); for (uint f = 0; f < 6; ++f) { GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); } @@ -907,7 +907,7 @@ void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } -void GLES3CmdFuncDestroyTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { +void cmdFuncGLES3DestroyTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { if (gpuTexture->glTexture) { for (GLuint &glTexture : device->stateCache()->glTextures) { if (glTexture == gpuTexture->glTexture) { @@ -921,10 +921,10 @@ void GLES3CmdFuncDestroyTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture } } -void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { - gpuTexture->glInternelFmt = MapGLInternalFormat(gpuTexture->format); - gpuTexture->glFormat = MapGLFormat(gpuTexture->format); - gpuTexture->glType = FormatToGLType(gpuTexture->format); +void cmdFuncGLES3ResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) { + gpuTexture->glInternelFmt = mapGLInternalFormat(gpuTexture->format); + gpuTexture->glFormat = mapGLFormat(gpuTexture->format); + gpuTexture->glType = formatToGLType(gpuTexture->format); switch (gpuTexture->type) { case TextureType::TEX2D: { @@ -937,7 +937,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } uint w = gpuTexture->width; uint h = gpuTexture->height; - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); @@ -945,7 +945,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } else { for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -962,7 +962,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_CUBE_MAP, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - if (!GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed) { + if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { for (uint f = 0; f < 6; ++f) { uint w = gpuTexture->width; uint h = gpuTexture->height; @@ -977,7 +977,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) uint w = gpuTexture->width; uint h = gpuTexture->height; for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = FormatSize(gpuTexture->format, w, h, 1); + uint imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternelFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -993,7 +993,7 @@ void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } -void GLES3CmdFuncCreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) { +void cmdFuncGLES3CreateSampler(GLES3Device * /*device*/, GLES3GPUSampler *gpuSampler) { GL_CHECK(glGenSamplers(1, &gpuSampler->glSampler)); if (gpuSampler->minFilter == Filter::LINEAR || gpuSampler->minFilter == Filter::ANISOTROPIC) { if (gpuSampler->mipFilter == Filter::LINEAR || gpuSampler->mipFilter == Filter::ANISOTROPIC) { @@ -1019,19 +1019,19 @@ void GLES3CmdFuncCreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) gpuSampler->glMagFilter = GL_NEAREST; } - gpuSampler->glWrapS = GLES3_WRAPS[(int)gpuSampler->addressU]; - gpuSampler->glWrapT = GLES3_WRAPS[(int)gpuSampler->addressV]; - gpuSampler->glWrapR = GLES3_WRAPS[(int)gpuSampler->addressW]; + gpuSampler->glWrapS = GLES3_WRAPS[static_cast(gpuSampler->addressU)]; + gpuSampler->glWrapT = GLES3_WRAPS[static_cast(gpuSampler->addressV)]; + gpuSampler->glWrapR = GLES3_WRAPS[static_cast(gpuSampler->addressW)]; GL_CHECK(glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MIN_FILTER, gpuSampler->glMinFilter)); GL_CHECK(glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_MAG_FILTER, gpuSampler->glMagFilter)); GL_CHECK(glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_S, gpuSampler->glWrapS)); GL_CHECK(glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_T, gpuSampler->glWrapT)); GL_CHECK(glSamplerParameteri(gpuSampler->glSampler, GL_TEXTURE_WRAP_R, gpuSampler->glWrapR)); - GL_CHECK(glSamplerParameterf(gpuSampler->glSampler, GL_TEXTURE_MIN_LOD, 0.f)); - GL_CHECK(glSamplerParameterf(gpuSampler->glSampler, GL_TEXTURE_MAX_LOD, 1000.f)); + GL_CHECK(glSamplerParameterf(gpuSampler->glSampler, GL_TEXTURE_MIN_LOD, 0.F)); + GL_CHECK(glSamplerParameterf(gpuSampler->glSampler, GL_TEXTURE_MAX_LOD, 1000.F)); } -void GLES3CmdFuncDestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) { +void cmdFuncGLES3DestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler) { if (gpuSampler->glSampler) { for (GLuint &glSampler : device->stateCache()->glSamplers) { if (glSampler == gpuSampler->glSampler) { @@ -1043,7 +1043,7 @@ void GLES3CmdFuncDestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler } } -void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { +void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GLenum glShaderStage = 0; String shaderStageStr; GLint status; @@ -1087,7 +1087,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GL_CHECK(glGetShaderiv(gpuStage.glShader, GL_INFO_LOG_LENGTH, &logSize)); ++logSize; - GLchar *logs = (GLchar *)CC_MALLOC(logSize); + auto *logs = static_cast(CC_MALLOC(logSize)); GL_CHECK(glGetShaderInfoLog(gpuStage.glShader, logSize, nullptr, logs)); CC_LOG_ERROR("%s in %s compilation failed.", shaderStageStr.c_str(), gpuShader->name.c_str()); @@ -1127,7 +1127,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_INFO_LOG_LENGTH, &logSize)); if (logSize) { ++logSize; - GLchar *logs = (GLchar *)CC_MALLOC(logSize); + auto *logs = static_cast(CC_MALLOC(logSize)); GL_CHECK(glGetProgramInfoLog(gpuShader->glProgram, logSize, nullptr, logs)); CC_LOG_ERROR(logs); @@ -1162,7 +1162,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GL_CHECK(gpuInput.glLoc = glGetAttribLocation(gpuShader->glProgram, glName)); gpuInput.binding = gpuInput.glLoc; gpuInput.name = glName; - gpuInput.type = MapType(glType); + gpuInput.type = mapType(glType); gpuInput.count = glSize; gpuInput.size = gpuInput.stride * gpuInput.count; gpuInput.glType = glType; @@ -1233,7 +1233,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } // create uniform sampler textures - if (gpuShader->samplerTextures.size()) { + if (!gpuShader->samplerTextures.empty()) { gpuShader->glSamplerTextures.resize(gpuShader->samplerTextures.size()); for (size_t i = 0; i < gpuShader->glSamplerTextures.size(); ++i) { @@ -1244,7 +1244,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { gpuSamplerTexture.name = samplerTexture.name; gpuSamplerTexture.type = samplerTexture.type; gpuSamplerTexture.count = samplerTexture.count; - gpuSamplerTexture.glType = MapGLType(gpuSamplerTexture.type); + gpuSamplerTexture.glType = mapGLType(gpuSamplerTexture.type); gpuSamplerTexture.glLoc = -1; } } @@ -1257,16 +1257,16 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers - uint flexibleSetBaseOffset = 0u; + uint flexibleSetBaseOffset = 0U; for (GLES3GPUUniformBuffer &buffer : gpuShader->glBuffers) { if (buffer.set == bindingMappingInfo.flexibleSet) { flexibleSetBaseOffset++; } } - uint arrayOffset = 0u; + uint arrayOffset = 0U; - for (uint i = 0u; i < gpuShader->samplerTextures.size(); i++) { + for (uint i = 0U; i < gpuShader->samplerTextures.size(); i++) { const UniformSamplerTexture &samplerTexture = gpuShader->samplerTextures[i]; GLint glLoc = -1; GL_CHECK(glLoc = glGetUniformLocation(gpuShader->glProgram, samplerTexture.name.c_str())); @@ -1274,7 +1274,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { glActiveSamplerTextures.push_back(gpuShader->glSamplerTextures[i]); glActiveSamplerLocations.push_back(glLoc); } - if (texUnitCacheMap.count(samplerTexture.name) == 0u) { + if (texUnitCacheMap.count(samplerTexture.name) == 0U) { uint binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; if (samplerTexture.set == bindingMappingInfo.flexibleSet) binding -= flexibleSetBaseOffset; texUnitCacheMap[samplerTexture.name] = binding % device->getCapabilities().maxTextureUnits; @@ -1285,13 +1285,13 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { if (!glActiveSamplerTextures.empty()) { vector usedTexUnits(device->getCapabilities().maxTextureUnits, false); // try to reuse existing mappings first - for (uint i = 0u; i < glActiveSamplerTextures.size(); i++) { + for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES3GPUUniformSamplerTexture &glSampler = glActiveSamplerTextures[i]; - if (texUnitCacheMap.count(glSampler.name) != 0u) { + if (texUnitCacheMap.count(glSampler.name) != 0U) { uint cachedUnit = texUnitCacheMap[glSampler.name]; glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0u; t < glSampler.count; t++) { + for (uint t = 0U; t < glSampler.count; t++) { while (usedTexUnits[cachedUnit]) { // the shader already compiles so we should be safe to do this here cachedUnit = (cachedUnit + 1) % device->getCapabilities().maxTextureUnits; } @@ -1301,17 +1301,17 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } // fill in the rest sequencially - uint unitIdx = 0u; - for (uint i = 0u; i < glActiveSamplerTextures.size(); i++) { + uint unitIdx = 0U; + for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES3GPUUniformSamplerTexture &glSampler = glActiveSamplerTextures[i]; if (glSampler.glLoc < 0) { glSampler.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0u; t < glSampler.count; t++) { + for (uint t = 0U; t < glSampler.count; t++) { while (usedTexUnits[unitIdx]) { unitIdx = (unitIdx + 1) % device->getCapabilities().maxTextureUnits; } - if (texUnitCacheMap.count(glSampler.name) == 0u) { + if (texUnitCacheMap.count(glSampler.name) == 0U) { texUnitCacheMap[glSampler.name] = unitIdx; } glSampler.units.push_back(unitIdx); @@ -1335,7 +1335,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { gpuShader->glSamplerTextures = glActiveSamplerTextures; // create uniform storage images - if (gpuShader->images.size()) { + if (!gpuShader->images.empty()) { for (size_t i = 0; i < gpuShader->images.size(); ++i) { UniformStorageImage &image = gpuShader->images[i]; GLint glLoc = -1; @@ -1347,7 +1347,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { gpuImage.name = image.name; gpuImage.type = image.type; gpuImage.count = image.count; - gpuImage.glMemoryAccess = GL_MEMORY_ACCESS[(uint)image.memoryAccess]; + gpuImage.glMemoryAccess = GL_MEMORY_ACCESS[static_cast(image.memoryAccess)]; gpuImage.units.resize(gpuImage.count); gpuImage.glLoc = glLoc; // storage image units are immutable @@ -1358,7 +1358,7 @@ void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } -void GLES3CmdFuncDestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { +void cmdFuncGLES3DestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuShader->glProgram) { if (device->stateCache()->glProgram == gpuShader->glProgram) { @@ -1371,7 +1371,7 @@ void GLES3CmdFuncDestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } -void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { +void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { if (gpuInputAssembler->gpuIndexBuffer) { switch (gpuInputAssembler->gpuIndexBuffer->stride) { @@ -1384,19 +1384,19 @@ void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble } } - vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0u); + vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[i]; const Attribute & attrib = gpuInputAssembler->attributes[i]; - GLES3GPUBuffer * gpuVB = (GLES3GPUBuffer *)gpuInputAssembler->gpuVertexBuffers[attrib.stream]; + auto * gpuVB = static_cast(gpuInputAssembler->gpuVertexBuffers[attrib.stream]); gpuAttribute.name = attrib.name; - gpuAttribute.glType = FormatToGLType(attrib.format); - gpuAttribute.size = GFX_FORMAT_INFOS[(int)attrib.format].size; - gpuAttribute.count = GFX_FORMAT_INFOS[(int)attrib.format].count; - gpuAttribute.componentCount = GLComponentCount(gpuAttribute.glType); + gpuAttribute.glType = formatToGLType(attrib.format); + gpuAttribute.size = GFX_FORMAT_INFOS[static_cast(attrib.format)].size; + gpuAttribute.count = GFX_FORMAT_INFOS[static_cast(attrib.format)].count; + gpuAttribute.componentCount = glComponentCount(gpuAttribute.glType); gpuAttribute.isNormalized = attrib.isNormalized; gpuAttribute.isInstanced = attrib.isInstanced; gpuAttribute.offset = streamOffsets[attrib.stream]; @@ -1409,7 +1409,7 @@ void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble } } -void GLES3CmdFuncDestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { +void cmdFuncGLES3DestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; for (auto it = gpuInputAssembler->glVAOs.begin(); it != gpuInputAssembler->glVAOs.end(); ++it) { if (device->stateCache()->glVAO == it->second) { @@ -1422,7 +1422,7 @@ void GLES3CmdFuncDestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembl gpuInputAssembler->glVAOs.clear(); } -void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { +void cmdFuncGLES3CreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { size_t colorViewCount = gpuFBO->gpuColorTextures.size(); uint swapchainImageIndices = 0; for (size_t i = 0; i < colorViewCount; ++i) { @@ -1456,13 +1456,13 @@ void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpu } GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, (GLenum)(GL_COLOR_ATTACHMENT0 + i), gpuColorTexture->glTarget, gpuColorTexture->glTexture, mipmapLevel)); - attachments[attachmentCount++] = (GLenum)(GL_COLOR_ATTACHMENT0 + i); + attachments[attachmentCount++] = static_cast(GL_COLOR_ATTACHMENT0 + i); } } if (gpuFBO->gpuDepthStencilTexture) { GLES3GPUTexture *gpuDepthStencilTexture = gpuFBO->gpuDepthStencilTexture; - const GLenum glAttachment = GFX_FORMAT_INFOS[(int)gpuDepthStencilTexture->format].hasStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT; + const GLenum glAttachment = GFX_FORMAT_INFOS[static_cast(gpuDepthStencilTexture->format)].hasStencil ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT; GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, gpuDepthStencilTexture->glTarget, gpuDepthStencilTexture->glTexture, gpuFBO->depthStencilMipmapLevel)); } @@ -1498,7 +1498,7 @@ void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpu } } -void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { +void cmdFuncGLES3DestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { if (gpuFBO->isOffscreen) { if (gpuFBO->glFramebuffer) { if (device->stateCache()->glDrawFramebuffer == gpuFBO->glFramebuffer) { @@ -1511,7 +1511,7 @@ void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gp } } -void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil) { +void cmdFuncGLES3BeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; gfxStateCache.gpuRenderPass = gpuRenderPass; gfxStateCache.gpuFramebuffer = gpuFramebuffer; @@ -1593,7 +1593,7 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen } // for if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) { - bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth; + bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; if (hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour @@ -1613,7 +1613,7 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen default:; } } // if (hasDepth) - bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour @@ -1672,7 +1672,7 @@ void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRen } } -void GLES3CmdFuncEndRenderPass(GLES3Device *device) { +void cmdFuncGLES3EndRenderPass(GLES3Device *device) { GLES3ObjectCache & gfxStateCache = device->stateCache()->gfxStateCache; size_t numClearColors = gfxStateCache.numClearColors; GLES3GPURenderPass * gpuRenderPass = gfxStateCache.gpuRenderPass; @@ -1700,7 +1700,7 @@ void GLES3CmdFuncEndRenderPass(GLES3Device *device) { } // for if (gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN) { - bool hasDepth = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasDepth; + bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; if (hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthStoreOp) { case StoreOp::STORE: break; @@ -1712,7 +1712,7 @@ void GLES3CmdFuncEndRenderPass(GLES3Device *device) { default:; } } // if (hasDepth) - bool hasStencils = GFX_FORMAT_INFOS[(int)gpuRenderPass->depthStencilAttachment.format].hasStencil; + bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; if (hasStencils) { switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { case StoreOp::STORE: break; @@ -1731,10 +1731,10 @@ void GLES3CmdFuncEndRenderPass(GLES3Device *device) { } } -void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, Viewport &viewport, Rect &scissor, - float lineWidth, bool depthBiasEnabled, GLES3DepthBias &depthBias, Color &blendConstants, GLES3DepthBounds &depthBounds, - GLES3StencilWriteMask &stencilWriteMask, GLES3StencilCompareMask &stencilCompareMask) { +void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, + const vector &gpuDescriptorSets, const vector &dynamicOffsets, + const Viewport &viewport, const Rect &scissor, float lineWidth, bool depthBiasEnabled, const GLES3DepthBias &depthBias, const Color & /*blendConstants*/, + const GLES3DepthBounds & /*depthBounds*/, const GLES3StencilWriteMask &stencilWriteMask, const GLES3StencilCompareMask &stencilCompareMask) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLES3GPUStateCache *cache = device->stateCache(); @@ -2003,7 +2003,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glSamplerTexture.units.size(); u++, gpuDescriptor++) { - uint unit = (uint)glSamplerTexture.units[u]; + uint unit = static_cast(glSamplerTexture.units[u]); if (!gpuDescriptor->gpuTexture || !gpuDescriptor->gpuSampler) { CC_LOG_ERROR("Sampler texture '%s' at binding %d set %d index %d is not bounded", @@ -2041,7 +2041,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glImage.units.size(); u++, gpuDescriptor++) { - uint unit = (uint)glImage.units[u]; + uint unit = static_cast(glImage.units[u]); if (!gpuDescriptor->gpuTexture) { CC_LOG_ERROR("Storage image '%s' at binding %d set %d index %d is not bounded", @@ -2074,8 +2074,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0)); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - for (size_t j = 0; j < gpuPipelineState->gpuShader->glInputs.size(); ++j) { - const GLES3GPUInput &gpuInput = gpuPipelineState->gpuShader->glInputs[j]; + for (auto &gpuInput : gpuPipelineState->gpuShader->glInputs) { for (size_t a = 0; a < gpuInputAssembler->attributes.size(); ++a) { const GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { @@ -2112,12 +2111,11 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli cache->glVAO = glVAO; } } else { - for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { - cache->glCurrentAttribLocs[a] = false; + for (auto &&glCurrentAttribLoc : cache->glCurrentAttribLocs) { + glCurrentAttribLoc = false; } - for (size_t j = 0; j < gpuPipelineState->gpuShader->glInputs.size(); ++j) { - const GLES3GPUInput &gpuInput = gpuPipelineState->gpuShader->glInputs[j]; + for (auto &gpuInput : gpuPipelineState->gpuShader->glInputs) { for (size_t a = 0; a < gpuInputAssembler->attributes.size(); ++a) { const GLES3GPUAttribute &gpuAttribute = gpuInputAssembler->glAttribs[a]; if (gpuAttribute.name == gpuInput.name) { @@ -2179,10 +2177,11 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli break; case DynamicStateFlagBit::DEPTH_BIAS: if (cache->rs.depthBiasEnabled != depthBiasEnabled) { - if (depthBiasEnabled) + if (depthBiasEnabled) { GL_CHECK(glEnable(GL_POLYGON_OFFSET_FILL)); - else + } else { GL_CHECK(glDisable(GL_POLYGON_OFFSET_FILL)); + } cache->rs.depthBiasEnabled = depthBiasEnabled; } @@ -2232,7 +2231,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli case DynamicStateFlagBit::STENCIL_COMPARE_MASK: switch (stencilCompareMask.face) { case StencilFace::FRONT: - if ((cache->dss.stencilRefFront != (uint)stencilCompareMask.refrence) || + if ((cache->dss.stencilRefFront != static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], @@ -2243,7 +2242,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } break; case StencilFace::BACK: - if ((cache->dss.stencilRefBack != (uint)stencilCompareMask.refrence) || + if ((cache->dss.stencilRefBack != static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_BACK, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], @@ -2254,9 +2253,9 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } break; case StencilFace::ALL: - if ((cache->dss.stencilRefFront != (uint)stencilCompareMask.refrence) || + if ((cache->dss.stencilRefFront != static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskFront != stencilCompareMask.compareMask) || - (cache->dss.stencilRefBack != (uint)stencilCompareMask.refrence) || + (cache->dss.stencilRefBack != static_cast(stencilCompareMask.refrence)) || (cache->dss.stencilReadMaskBack != stencilCompareMask.compareMask)) { GL_CHECK(glStencilFuncSeparate(GL_FRONT, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], @@ -2282,7 +2281,7 @@ void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } } -void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { +void cmdFuncGLES3Draw(GLES3Device *device, const DrawInfo &drawInfo) { GLES3ObjectCache & gfxStateCache = device->stateCache()->gfxStateCache; GLES3GPUPipelineState * gpuPipelineState = gfxStateCache.gpuPipelineState; GLES3GPUInputAssembler *gpuInputAssembler = gfxStateCache.gpuInputAssembler; @@ -2292,7 +2291,7 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { if (!gpuInputAssembler->gpuIndirectBuffer) { if (gpuInputAssembler->gpuIndexBuffer) { if (drawInfo.indexCount > 0) { - uint8_t *offset = 0; + uint8_t *offset = nullptr; offset += drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (drawInfo.instanceCount == 0) { GL_CHECK(glDrawElements(glPrimitive, drawInfo.indexCount, gpuInputAssembler->glIndexType, offset)); @@ -2312,7 +2311,7 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { const DrawInfo &draw = gpuInputAssembler->gpuIndirectBuffer->indirects[j]; if (gpuInputAssembler->gpuIndexBuffer) { if (draw.indexCount > 0) { - uint8_t *offset = 0; + uint8_t *offset = nullptr; offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; if (draw.instanceCount == 0) { GL_CHECK(glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset)); @@ -2332,7 +2331,7 @@ void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo) { } } -void GLES3CmdFuncDispatch(GLES3Device *device, const GLES3GPUDispatchInfo &info) { +void cmdFuncGLES3Dispatch(GLES3Device *device, const GLES3GPUDispatchInfo &info) { GLES3GPUStateCache *cache = device->stateCache(); if (info.indirectBuffer) { if (cache->glDispatchIndirectBuffer != info.indirectBuffer->glBuffer) { @@ -2345,17 +2344,17 @@ void GLES3CmdFuncDispatch(GLES3Device *device, const GLES3GPUDispatchInfo &info) } } -void GLES3CmdFuncMemoryBarrier(GLES3Device *device, GLbitfield barriers, GLbitfield barriersByRegion) { +void cmdFuncGLES3MemoryBarrier(GLES3Device * /*device*/, GLbitfield barriers, GLbitfield barriersByRegion) { if (barriers) glMemoryBarrier(barriers); if (barriersByRegion) glMemoryBarrierByRegion(barriersByRegion); } -void GLES3CmdFuncUpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { +void cmdFuncGLES3UpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { - memcpy((uint8_t *)gpuBuffer->indirects.data() + offset, buffer, size); + memcpy(reinterpret_cast(gpuBuffer->indirects.data()) + offset, buffer, size); } else if (gpuBuffer->usage & BufferUsageBit::TRANSFER_SRC) { - memcpy((uint8_t *)gpuBuffer->buffer + offset, buffer, size); + memcpy(gpuBuffer->buffer + offset, buffer, size); } else { switch (gpuBuffer->glTarget) { case GL_ARRAY_BUFFER: { @@ -2407,14 +2406,14 @@ void GLES3CmdFuncUpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, co } } -void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { +void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { GLuint &glTexture = device->stateCache()->glTextures[device->stateCache()->texUint]; if (glTexture != gpuTexture->glTexture) { GL_CHECK(glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed; + bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; uint n = 0; switch (gpuTexture->glTarget) { @@ -2427,7 +2426,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage2D(GL_TEXTURE_2D, region.texSubres.mipLevel, region.texOffset.x, @@ -2462,7 +2461,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, region.texSubres.mipLevel, region.texOffset.x, @@ -2498,7 +2497,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const d = region.texExtent.depth; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage3D(GL_TEXTURE_3D, region.texSubres.mipLevel, region.texOffset.x, @@ -2534,7 +2533,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const h = region.texExtent.height; const uint8_t *buff = buffers[n++]; if (isCompressed) { - GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); + auto memSize = static_cast(formatSize(gpuTexture->format, w, h, 1)); GL_CHECK(glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, region.texSubres.mipLevel, region.texOffset.x, @@ -2569,11 +2568,11 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const } } -void GLES3CmdFuncBlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc, GLES3GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter) { +void cmdFuncGLES3BlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc, GLES3GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter) { GLES3GPUStateCache *cache = device->stateCache(); - GLbitfield mask = 0u; - const FormatInfo &info = GFX_FORMAT_INFOS[(uint)gpuTextureSrc->format]; + GLbitfield mask = 0U; + const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTextureSrc->format)]; if (info.hasDepth || info.hasStencil) { if (info.hasDepth) mask |= GL_DEPTH_BUFFER_BIT; if (info.hasStencil) mask |= GL_STENCIL_BUFFER_BIT; @@ -2581,10 +2580,10 @@ void GLES3CmdFuncBlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc mask = GL_COLOR_BUFFER_BIT; } - for (uint i = 0u; i < count; ++i) { + for (uint i = 0U; i < count; ++i) { const TextureBlit ®ion = regions[i]; - GLuint srcFramebuffer = 0u; + GLuint srcFramebuffer = 0U; if (gpuTextureSrc) srcFramebuffer = device->framebufferCacheMap()->getFramebufferFromTexture(gpuTextureSrc, region.srcSubres); #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) else @@ -2595,7 +2594,7 @@ void GLES3CmdFuncBlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc cache->glReadFramebuffer = srcFramebuffer; } - GLuint dstFramebuffer = 0u; + GLuint dstFramebuffer = 0U; if (gpuTextureDst) dstFramebuffer = device->framebufferCacheMap()->getFramebufferFromTexture(gpuTextureDst, region.srcSubres); #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) else @@ -2613,59 +2612,59 @@ void GLES3CmdFuncBlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc } } -void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { +void cmdFuncGLES3ExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { if (!cmdPackage->cmds.size()) return; - static uint cmdIndices[(int)GLESCmdType::COUNT] = {0}; + static uint cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; memset(cmdIndices, 0, sizeof(cmdIndices)); for (uint i = 0; i < cmdPackage->cmds.size(); ++i) { GLESCmdType cmdType = cmdPackage->cmds[i]; - uint & cmdIdx = cmdIndices[(int)cmdType]; + uint & cmdIdx = cmdIndices[static_cast(cmdType)]; switch (cmdType) { case GLESCmdType::BEGIN_RENDER_PASS: { GLES3CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[cmdIdx]; - GLES3CmdFuncBeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, cmd->renderArea, cmd->numClearColors, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); + cmdFuncGLES3BeginRenderPass(device, cmd->gpuRenderPass, cmd->gpuFBO, cmd->renderArea, cmd->numClearColors, cmd->clearColors, cmd->clearDepth, cmd->clearStencil); break; } case GLESCmdType::END_RENDER_PASS: { - GLES3CmdFuncEndRenderPass(device); + cmdFuncGLES3EndRenderPass(device); break; } case GLESCmdType::BIND_STATES: { GLES3CmdBindStates *cmd = cmdPackage->bindStatesCmds[cmdIdx]; - GLES3CmdFuncBindState(device, cmd->gpuPipelineState, cmd->gpuInputAssembler, cmd->gpuDescriptorSets, cmd->dynamicOffsets, cmd->viewport, cmd->scissor, cmd->lineWidth, cmd->depthBiasEnabled, cmd->depthBias, cmd->blendConstants, cmd->depthBounds, cmd->stencilWriteMask, cmd->stencilCompareMask); + cmdFuncGLES3BindState(device, cmd->gpuPipelineState, cmd->gpuInputAssembler, cmd->gpuDescriptorSets, cmd->dynamicOffsets, cmd->viewport, cmd->scissor, cmd->lineWidth, cmd->depthBiasEnabled, cmd->depthBias, cmd->blendConstants, cmd->depthBounds, cmd->stencilWriteMask, cmd->stencilCompareMask); break; } case GLESCmdType::DRAW: { GLES3CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx]; - GLES3CmdFuncDraw(device, cmd->drawInfo); + cmdFuncGLES3Draw(device, cmd->drawInfo); break; } case GLESCmdType::DISPATCH: { GLES3CmdDispatch *cmd = cmdPackage->dispatchCmds[cmdIdx]; - GLES3CmdFuncDispatch(device, cmd->dispatchInfo); + cmdFuncGLES3Dispatch(device, cmd->dispatchInfo); break; } case GLESCmdType::BARRIER: { GLES3CmdBarrier *cmd = cmdPackage->barrierCmds[cmdIdx]; - GLES3CmdFuncMemoryBarrier(device, cmd->barriers, cmd->barriersByRegion); + cmdFuncGLES3MemoryBarrier(device, cmd->barriers, cmd->barriersByRegion); break; } case GLESCmdType::UPDATE_BUFFER: { GLES3CmdUpdateBuffer *cmd = cmdPackage->updateBufferCmds[cmdIdx]; - GLES3CmdFuncUpdateBuffer(device, cmd->gpuBuffer, cmd->buffer, cmd->offset, cmd->size); + cmdFuncGLES3UpdateBuffer(device, cmd->gpuBuffer, cmd->buffer, cmd->offset, cmd->size); break; } case GLESCmdType::COPY_BUFFER_TO_TEXTURE: { GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); + cmdFuncGLES3CopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count); break; } case GLESCmdType::BLIT_TEXTURE: { GLES3CmdBlitTexture *cmd = cmdPackage->blitTextureCmds[cmdIdx]; - GLES3CmdFuncBlitTexture(device, cmd->gpuTextureSrc, cmd->gpuTextureDst, cmd->regions, cmd->count, cmd->filter); + cmdFuncGLES3BlitTexture(device, cmd->gpuTextureSrc, cmd->gpuTextureDst, cmd->regions, cmd->count, cmd->filter); break; } default: diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 6de1737a7c..1013a6fb45 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -25,8 +25,8 @@ #pragma once -#include "../gfx-gles-common/GLESCommandPool.h" #include "GLES3GPUObjects.h" +#include "gfx-gles-common/GLESCommandPool.h" namespace cc { namespace gfx { @@ -34,57 +34,57 @@ namespace gfx { class GLES3Device; struct GLES3DepthBias final { - float constant = 0.0f; - float clamp = 0.0f; - float slope = 0.0f; + float constant = 0.0F; + float clamp = 0.0F; + float slope = 0.0F; }; struct GLES3DepthBounds final { - float minBounds = 0.0f; - float maxBounds = 0.0f; + float minBounds = 0.0F; + float maxBounds = 0.0F; }; struct GLES3StencilWriteMask final { - StencilFace face = StencilFace::FRONT; - uint writeMask = 0; + StencilFace face = StencilFace::FRONT; + uint writeMask = 0; }; struct GLES3StencilCompareMask final { - StencilFace face = StencilFace::FRONT; - int refrence = 0; - uint compareMask = 0; + StencilFace face = StencilFace::FRONT; + int refrence = 0; + uint compareMask = 0; }; struct GLES3TextureSubres final { - uint baseMipLevel = 0; - uint levelCount = 1; + uint baseMipLevel = 0; + uint levelCount = 1; uint baseArrayLayer = 0; - uint layerCount = 1; + uint layerCount = 1; }; struct GLES3BufferTextureCopy final { - uint buffOffset = 0; - uint buffStride = 0; - uint buffTexHeight = 0; - uint texOffset[3] = {0}; - uint texExtent[3] = {0}; + uint buffOffset = 0; + uint buffStride = 0; + uint buffTexHeight = 0; + uint texOffset[3] = {0}; + uint texExtent[3] = {0}; GLES3TextureSubres texSubres; }; class GLES3CmdBeginRenderPass final : public GLESCmd { public: - GLES3GPURenderPass *gpuRenderPass = nullptr; - GLES3GPUFramebuffer *gpuFBO = nullptr; - Rect renderArea; - size_t numClearColors = 0; - Color clearColors[GFX_MAX_ATTACHMENTS]; - float clearDepth = 1.0f; - int clearStencil = 0; + GLES3GPURenderPass * gpuRenderPass = nullptr; + GLES3GPUFramebuffer *gpuFBO = nullptr; + Rect renderArea; + size_t numClearColors = 0; + Color clearColors[GFX_MAX_ATTACHMENTS]; + float clearDepth = 1.0F; + int clearStencil = 0; GLES3CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} void clear() override { - gpuFBO = nullptr; + gpuFBO = nullptr; numClearColors = 0; } }; @@ -103,24 +103,24 @@ enum class GLES3State { class GLES3CmdBindStates final : public GLESCmd { public: - GLES3GPUPipelineState *gpuPipelineState = nullptr; - GLES3GPUInputAssembler *gpuInputAssembler = nullptr; + GLES3GPUPipelineState * gpuPipelineState = nullptr; + GLES3GPUInputAssembler * gpuInputAssembler = nullptr; vector gpuDescriptorSets; - vector dynamicOffsets; - Viewport viewport; - Rect scissor; - float lineWidth = 1.0f; - bool depthBiasEnabled = false; - GLES3DepthBias depthBias; - Color blendConstants; - GLES3DepthBounds depthBounds; - GLES3StencilWriteMask stencilWriteMask; - GLES3StencilCompareMask stencilCompareMask; + vector dynamicOffsets; + Viewport viewport; + Rect scissor; + float lineWidth = 1.0F; + bool depthBiasEnabled = false; + GLES3DepthBias depthBias; + Color blendConstants; + GLES3DepthBounds depthBounds; + GLES3StencilWriteMask stencilWriteMask; + GLES3StencilCompareMask stencilCompareMask; GLES3CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} void clear() override { - gpuPipelineState = nullptr; + gpuPipelineState = nullptr; gpuInputAssembler = nullptr; gpuDescriptorSets.clear(); dynamicOffsets.clear(); @@ -148,117 +148,117 @@ public: class GLES3CmdBarrier final : public GLESCmd { public: - GLbitfield barriers = 0u; - GLbitfield barriersByRegion = 0u; + GLbitfield barriers = 0U; + GLbitfield barriersByRegion = 0U; GLES3CmdBarrier() : GLESCmd(GLESCmdType::BARRIER) {} void clear() override { - barriers = 0u; - barriersByRegion = 0u; + barriers = 0U; + barriersByRegion = 0U; } }; class GLES3CmdUpdateBuffer final : public GLESCmd { public: GLES3GPUBuffer *gpuBuffer = nullptr; - uint8_t *buffer = nullptr; - uint size = 0; - uint offset = 0; + const uint8_t * buffer = nullptr; + uint size = 0; + uint offset = 0; GLES3CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} void clear() override { gpuBuffer = nullptr; - buffer = nullptr; + buffer = nullptr; } }; class GLES3CmdCopyBufferToTexture final : public GLESCmd { public: - GLES3GPUTexture *gpuTexture = nullptr; - const BufferTextureCopy *regions = nullptr; - uint count = 0u; - const uint8_t *const *buffers; + GLES3GPUTexture * gpuTexture = nullptr; + const BufferTextureCopy *regions = nullptr; + uint count = 0U; + const uint8_t *const * buffers; GLES3CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} void clear() override { gpuTexture = nullptr; - regions = nullptr; - count = 0u; - buffers = nullptr; + regions = nullptr; + count = 0U; + buffers = nullptr; } }; class GLES3CmdBlitTexture final : public GLESCmd { public: - GLES3GPUTexture *gpuTextureSrc = nullptr; - GLES3GPUTexture *gpuTextureDst = nullptr; - const TextureBlit *regions = nullptr; - uint count = 0u; - Filter filter = Filter::POINT; + GLES3GPUTexture * gpuTextureSrc = nullptr; + GLES3GPUTexture * gpuTextureDst = nullptr; + const TextureBlit *regions = nullptr; + uint count = 0U; + Filter filter = Filter::POINT; GLES3CmdBlitTexture() : GLESCmd(GLESCmdType::BLIT_TEXTURE) {} void clear() override { gpuTextureSrc = nullptr; gpuTextureDst = nullptr; - regions = nullptr; - count = 0u; + regions = nullptr; + count = 0U; } }; class GLES3CmdPackage final : public Object { public: - CachedArray cmds; - CachedArray beginRenderPassCmds; - CachedArray bindStatesCmds; - CachedArray drawCmds; - CachedArray dispatchCmds; - CachedArray barrierCmds; - CachedArray updateBufferCmds; + CachedArray cmds; + CachedArray beginRenderPassCmds; + CachedArray bindStatesCmds; + CachedArray drawCmds; + CachedArray dispatchCmds; + CachedArray barrierCmds; + CachedArray updateBufferCmds; CachedArray copyBufferToTextureCmds; - CachedArray blitTextureCmds; + CachedArray blitTextureCmds; }; class GLES3GPUCommandAllocator final : public Object { public: - CommandPool beginRenderPassCmdPool; - CommandPool bindStatesCmdPool; - CommandPool drawCmdPool; - CommandPool dispatchCmdPool; - CommandPool barrierCmdPool; - CommandPool updateBufferCmdPool; + CommandPool beginRenderPassCmdPool; + CommandPool bindStatesCmdPool; + CommandPool drawCmdPool; + CommandPool dispatchCmdPool; + CommandPool barrierCmdPool; + CommandPool updateBufferCmdPool; CommandPool copyBufferToTextureCmdPool; - CommandPool blitTextureCmdPool; + CommandPool blitTextureCmdPool; - void clearCmds(GLES3CmdPackage *cmd_package) { - if (cmd_package->beginRenderPassCmds.size()) { - beginRenderPassCmdPool.freeCmds(cmd_package->beginRenderPassCmds); + void clearCmds(GLES3CmdPackage *cmdPackage) { + if (cmdPackage->beginRenderPassCmds.size()) { + beginRenderPassCmdPool.freeCmds(cmdPackage->beginRenderPassCmds); } - if (cmd_package->bindStatesCmds.size()) { - bindStatesCmdPool.freeCmds(cmd_package->bindStatesCmds); + if (cmdPackage->bindStatesCmds.size()) { + bindStatesCmdPool.freeCmds(cmdPackage->bindStatesCmds); } - if (cmd_package->drawCmds.size()) { - drawCmdPool.freeCmds(cmd_package->drawCmds); + if (cmdPackage->drawCmds.size()) { + drawCmdPool.freeCmds(cmdPackage->drawCmds); } - if (cmd_package->dispatchCmds.size()) { - dispatchCmdPool.freeCmds(cmd_package->dispatchCmds); + if (cmdPackage->dispatchCmds.size()) { + dispatchCmdPool.freeCmds(cmdPackage->dispatchCmds); } - if (cmd_package->barrierCmds.size()) { - barrierCmdPool.freeCmds(cmd_package->barrierCmds); + if (cmdPackage->barrierCmds.size()) { + barrierCmdPool.freeCmds(cmdPackage->barrierCmds); } - if (cmd_package->updateBufferCmds.size()) { - updateBufferCmdPool.freeCmds(cmd_package->updateBufferCmds); + if (cmdPackage->updateBufferCmds.size()) { + updateBufferCmdPool.freeCmds(cmdPackage->updateBufferCmds); } - if (cmd_package->copyBufferToTextureCmds.size()) { - copyBufferToTextureCmdPool.freeCmds(cmd_package->copyBufferToTextureCmds); + if (cmdPackage->copyBufferToTextureCmds.size()) { + copyBufferToTextureCmdPool.freeCmds(cmdPackage->copyBufferToTextureCmds); } - if (cmd_package->blitTextureCmds.size()) { - blitTextureCmdPool.freeCmds(cmd_package->blitTextureCmds); + if (cmdPackage->blitTextureCmds.size()) { + blitTextureCmdPool.freeCmds(cmdPackage->blitTextureCmds); } - cmd_package->cmds.clear(); + cmdPackage->cmds.clear(); } CC_INLINE void reset() { @@ -273,36 +273,36 @@ public: } }; -CC_GLES3_API void GLES3CmdFuncCreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); -CC_GLES3_API void GLES3CmdFuncDestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); -CC_GLES3_API void GLES3CmdFuncResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); -CC_GLES3_API void GLES3CmdFuncCreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); -CC_GLES3_API void GLES3CmdFuncDestroyTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); -CC_GLES3_API void GLES3CmdFuncResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); -CC_GLES3_API void GLES3CmdFuncCreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler); -CC_GLES3_API void GLES3CmdFuncDestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler); -CC_GLES3_API void GLES3CmdFuncCreateShader(GLES3Device *device, GLES3GPUShader *gpuShader); -CC_GLES3_API void GLES3CmdFuncDestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader); -CC_GLES3_API void GLES3CmdFuncCreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); -CC_GLES3_API void GLES3CmdFuncDestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); -CC_GLES3_API void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); -CC_GLES3_API void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); +CC_GLES3_API void cmdFuncGLES3CreateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); +CC_GLES3_API void cmdFuncGLES3DestroyBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); +CC_GLES3_API void cmdFuncGLES3ResizeBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer); +CC_GLES3_API void cmdFuncGLES3CreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); +CC_GLES3_API void cmdFuncGLES3DestroyTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); +CC_GLES3_API void cmdFuncGLES3ResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture); +CC_GLES3_API void cmdFuncGLES3CreateSampler(GLES3Device *device, GLES3GPUSampler *gpuSampler); +CC_GLES3_API void cmdFuncGLES3DestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler); +CC_GLES3_API void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader); +CC_GLES3_API void cmdFuncGLES3DestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader); +CC_GLES3_API void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); +CC_GLES3_API void cmdFuncGLES3DestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); +CC_GLES3_API void cmdFuncGLES3CreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); +CC_GLES3_API void cmdFuncGLES3DestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); -CC_GLES3_API void GLES3CmdFuncBeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFBO, +CC_GLES3_API void cmdFuncGLES3BeginRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect &renderArea, size_t numClearColors, const Color *clearColors, float clearDepth, int clearStencil); -CC_GLES3_API void GLES3CmdFuncEndRenderPass(GLES3Device *device); -CC_GLES3_API void GLES3CmdFuncBindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, - vector &gpuDescriptorSets, vector &dynamicOffsets, - Viewport &viewport, Rect &scissor, float lineWidth, bool depthBiasEnabled, GLES3DepthBias &depthBias, Color &blendConstants, - GLES3DepthBounds &depthBounds, GLES3StencilWriteMask &stencilWriteMask, GLES3StencilCompareMask &stencilCompareMask); -CC_GLES3_API void GLES3CmdFuncDraw(GLES3Device *device, DrawInfo &drawInfo); -CC_GLES3_API void GLES3CmdFuncUpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size); -CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, +CC_GLES3_API void cmdFuncGLES3EndRenderPass(GLES3Device *device); +CC_GLES3_API void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, + const vector &gpuDescriptorSets, const vector &dynamicOffsets, + const Viewport &viewport, const Rect &scissor, float lineWidth, bool depthBiasEnabled, const GLES3DepthBias &depthBias, const Color &blendConstants, + const GLES3DepthBounds &depthBounds, const GLES3StencilWriteMask &stencilWriteMask, const GLES3StencilCompareMask &stencilCompareMask); +CC_GLES3_API void cmdFuncGLES3Draw(GLES3Device *device, const DrawInfo &drawInfo); +CC_GLES3_API void cmdFuncGLES3UpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size); +CC_GLES3_API void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count); -CC_GLES3_API void GLES3CmdFuncBlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc, GLES3GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter); -CC_GLES3_API void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage); -CC_GLES3_API void GLES3CmdFuncDispatch(GLES3Device *device, const GLES3GPUDispatchInfo &info); -CC_GLES3_API void GLES3CmdFuncMemoryBarrier(GLES3Device *device, GLbitfield barriers, GLbitfield barriersByRegion); +CC_GLES3_API void cmdFuncGLES3BlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc, GLES3GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter); +CC_GLES3_API void cmdFuncGLES3ExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage); +CC_GLES3_API void cmdFuncGLES3Dispatch(GLES3Device *device, const GLES3GPUDispatchInfo &info); +CC_GLES3_API void cmdFuncGLES3MemoryBarrier(GLES3Device *device, GLbitfield barriers, GLbitfield barriersByRegion); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp index 700fd83abd..a3b3f90d2b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp @@ -84,12 +84,9 @@ void GL_APIENTRY GLES3EGLDebugProc(GLenum source, GLenum type, GLuint id, GLenum #endif -GLES3Context::GLES3Context() -: Context() { -} +GLES3Context::GLES3Context() = default; -GLES3Context::~GLES3Context() { -} +GLES3Context::~GLES3Context() = default; #if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX) @@ -209,10 +206,10 @@ bool GLES3Context::doInit(const ContextInfo &info) { uint width = GLES3Device::getInstance()->getWidth(); uint height = GLES3Device::getInstance()->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); + ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); #endif - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), NULL)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); if (_eglSurface == EGL_NO_SURFACE) { auto err = eglGetError(); CC_LOG_ERROR("Window surface created failed. code %d", err); @@ -247,7 +244,7 @@ bool GLES3Context::doInit(const ContextInfo &info) { #endif ctxAttribs[n] = EGL_NONE; - EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs)); + EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, nullptr, ctxAttribs)); if (_eglContext) { _minorVersion = m; break; @@ -257,7 +254,7 @@ bool GLES3Context::doInit(const ContextInfo &info) { ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; ctxAttribs[n++] = _majorVersion; ctxAttribs[n] = EGL_NONE; - EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs)); + EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, nullptr, ctxAttribs)); } if (!_eglContext) { @@ -268,7 +265,7 @@ bool GLES3Context::doInit(const ContextInfo &info) { _eglSharedContext = _eglContext; } else { - GLES3Context *sharedCtx = (GLES3Context *)info.sharedCtx; + auto *sharedCtx = static_cast(info.sharedCtx); _majorVersion = sharedCtx->major_ver(); _minorVersion = sharedCtx->minor_ver(); @@ -346,12 +343,12 @@ void GLES3Context::doDestroy() { _isPrimaryContex = false; _windowHandle = 0; - _nativeDisplay = 0; + _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues _vsyncMode = VsyncMode::OFF; _isInitialized = false; } -void GLES3Context::releaseSurface(uintptr_t windowHandle) { +void GLES3Context::releaseSurface(uintptr_t /*windowHandle*/) { #if (CC_PLATFORM == CC_PLATFORM_ANDROID) if (_eglSurface != EGL_NO_SURFACE) { eglDestroySurface(_eglDisplay, _eglSurface); @@ -373,7 +370,7 @@ void GLES3Context::acquireSurface(uintptr_t windowHandle) { uint height = GLES3Device::getInstance()->getHeight(); ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), NULL)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("Recreate window surface failed."); return; @@ -412,7 +409,7 @@ bool GLES3Context::MakeCurrent(bool bound) { int interval = 1; switch (_vsyncMode) { case VsyncMode::OFF: interval = 0; break; - case VsyncMode::ON: interval = 1; break; + case VsyncMode::ON: case VsyncMode::RELAXED: interval = 1; break; case VsyncMode::MAILBOX: interval = 0; break; case VsyncMode::HALF: interval = 2; break; @@ -472,14 +469,13 @@ bool GLES3Context::MakeCurrent(bool bound) { GL_CHECK(glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD)); GL_CHECK(glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO)); GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)); - GL_CHECK(glBlendColor(0.0f, 0.0f, 0.0f, 0.0f)); + GL_CHECK(glBlendColor(0.0F, 0.0F, 0.0F, 0.0F)); CC_LOG_DEBUG("eglMakeCurrent() - SUCCEEDED, Context: 0x%p", this); return true; - } else { - CC_LOG_ERROR("MakeCurrent() - FAILED, Context: 0x%p", this); - return false; } + CC_LOG_ERROR("MakeCurrent() - FAILED, Context: 0x%p", this); + return false; } bool GLES3Context::CheckExtension(const String &extension) const { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index bc7dace259..5b80af275c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -46,24 +46,24 @@ namespace cc { namespace gfx { -GLES3Device *GLES3Device::_instance = nullptr; +GLES3Device *GLES3Device::instance = nullptr; GLES3Device *GLES3Device::getInstance() { - return GLES3Device::_instance; + return GLES3Device::instance; } GLES3Device::GLES3Device() { - _API = API::GLES3; + _api = API::GLES3; _deviceName = "GLES3"; - GLES3Device::_instance = this; + GLES3Device::instance = this; } GLES3Device::~GLES3Device() { - GLES3Device::_instance = nullptr; + GLES3Device::instance = nullptr; } -bool GLES3Device::doInit(const DeviceInfo &info) { +bool GLES3Device::doInit(const DeviceInfo & /*info*/) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; @@ -88,7 +88,7 @@ bool GLES3Device::doInit(const DeviceInfo &info) { bindRenderContext(true); - String extStr = (const char *)glGetString(GL_EXTENSIONS); + String extStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); _extensions = StringUtil::split(extStr, " "); _features[static_cast(Feature::TEXTURE_FLOAT)] = true; @@ -102,20 +102,25 @@ bool GLES3Device::doInit(const DeviceInfo &info) { _features[static_cast(Feature::ELEMENT_INDEX_UINT)] = true; uint minorVersion = static_cast(_context)->minor_ver(); - if (minorVersion) + if (minorVersion) { _features[static_cast(Feature::COMPUTE_SHADER)] = true; + } - if (checkExtension("color_buffer_float")) + if (checkExtension("color_buffer_float")) { _features[static_cast(Feature::COLOR_FLOAT)] = true; + } - if (checkExtension("color_buffer_half_float")) + if (checkExtension("color_buffer_half_float")) { _features[static_cast(Feature::COLOR_HALF_FLOAT)] = true; + } - if (checkExtension("texture_float_linear")) + if (checkExtension("texture_float_linear")) { _features[static_cast(Feature::TEXTURE_FLOAT_LINEAR)] = true; + } - if (checkExtension("texture_half_float_linear")) + if (checkExtension("texture_half_float_linear")) { _features[static_cast(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = true; + } String compressedFmts; @@ -147,9 +152,9 @@ bool GLES3Device::doInit(const DeviceInfo &info) { _features[static_cast(Feature::FORMAT_D24S8)] = true; _features[static_cast(Feature::FORMAT_D32FS8)] = true; - _renderer = (const char *)glGetString(GL_RENDERER); - _vendor = (const char *)glGetString(GL_VENDOR); - _version = (const char *)glGetString(GL_VERSION); + _renderer = reinterpret_cast(glGetString(GL_RENDERER)); + _vendor = reinterpret_cast(glGetString(GL_VENDOR)); + _version = reinterpret_cast(glGetString(GL_VERSION)); CC_LOG_INFO("GLES3 device initialized."); CC_LOG_INFO("RENDERER: %s", _renderer.c_str()); @@ -159,31 +164,31 @@ bool GLES3Device::doInit(const DeviceInfo &info) { CC_LOG_INFO("NATIVE_SIZE: %d x %d", _nativeWidth, _nativeHeight); CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str()); - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)&_caps.maxVertexAttributes); - glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, (GLint *)&_caps.maxVertexUniformVectors); - glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, (GLint *)&_caps.maxFragmentUniformVectors); - glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, (GLint *)&_caps.maxUniformBufferBindings); - glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, (GLint *)&_caps.maxUniformBlockSize); - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, (GLint *)&_caps.maxTextureUnits); - glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, (GLint *)&_caps.maxVertexTextureUnits); - glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&_caps.maxTextureSize); - glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint *)&_caps.maxCubeMapTextureSize); - glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, (GLint *)&_caps.uboOffsetAlignment); - glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_caps.depthBits); - glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_caps.stencilBits); + glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast(&_caps.maxVertexAttributes)); + glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, reinterpret_cast(&_caps.maxVertexUniformVectors)); + glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, reinterpret_cast(&_caps.maxFragmentUniformVectors)); + glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast(&_caps.maxUniformBufferBindings)); + glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, reinterpret_cast(&_caps.maxUniformBlockSize)); + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, reinterpret_cast(&_caps.maxTextureUnits)); + glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, reinterpret_cast(&_caps.maxVertexTextureUnits)); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast(&_caps.maxTextureSize)); + glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, reinterpret_cast(&_caps.maxCubeMapTextureSize)); + glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast(&_caps.uboOffsetAlignment)); + glGetIntegerv(GL_DEPTH_BITS, reinterpret_cast(&_caps.depthBits)); + glGetIntegerv(GL_STENCIL_BITS, reinterpret_cast(&_caps.stencilBits)); if (minorVersion) { - glGetIntegerv(GL_MAX_IMAGE_UNITS, (GLint *)&_caps.maxImageUnits); - glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, (GLint *)&_caps.maxShaderStorageBlockSize); - glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, (GLint *)&_caps.maxShaderStorageBufferBindings); - glGetIntegerv(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE, (GLint *)&_caps.maxComputeSharedMemorySize); - glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, (GLint *)&_caps.maxComputeWorkGroupInvocations); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, (GLint *)&_caps.maxComputeWorkGroupSize.x); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, (GLint *)&_caps.maxComputeWorkGroupSize.y); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, (GLint *)&_caps.maxComputeWorkGroupSize.z); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, (GLint *)&_caps.maxComputeWorkGroupCount.x); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, (GLint *)&_caps.maxComputeWorkGroupCount.y); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, (GLint *)&_caps.maxComputeWorkGroupCount.z); + glGetIntegerv(GL_MAX_IMAGE_UNITS, reinterpret_cast(&_caps.maxImageUnits)); + glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, reinterpret_cast(&_caps.maxShaderStorageBlockSize)); + glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, reinterpret_cast(&_caps.maxShaderStorageBufferBindings)); + glGetIntegerv(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE, reinterpret_cast(&_caps.maxComputeSharedMemorySize)); + glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, reinterpret_cast(&_caps.maxComputeWorkGroupInvocations)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, reinterpret_cast(&_caps.maxComputeWorkGroupSize.x)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, reinterpret_cast(&_caps.maxComputeWorkGroupSize.y)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, reinterpret_cast(&_caps.maxComputeWorkGroupSize.z)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, reinterpret_cast(&_caps.maxComputeWorkGroupCount.x)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, reinterpret_cast(&_caps.maxComputeWorkGroupCount.y)); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, reinterpret_cast(&_caps.maxComputeWorkGroupCount.z)); } _gpuStateCache->initialize(_caps.maxTextureUnits, _caps.maxImageUnits, _caps.maxUniformBufferBindings, _caps.maxShaderStorageBufferBindings, _caps.maxVertexAttributes); @@ -220,10 +225,10 @@ void GLES3Device::acquire() { } void GLES3Device::present() { - GLES3Queue *queue = (GLES3Queue *)_queue; - _numDrawCalls = queue->_numDrawCalls; - _numInstances = queue->_numInstances; - _numTriangles = queue->_numTriangles; + auto *queue = static_cast(_queue); + _numDrawCalls = queue->_numDrawCalls; + _numInstances = queue->_numInstances; + _numTriangles = queue->_numTriangles; _context->present(); @@ -325,7 +330,7 @@ TextureBarrier *GLES3Device::createTextureBarrier() { } void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { - GLES3CmdFuncCopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); + cmdFuncGLES3CopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 4b0b8d38b6..72ad27874f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -25,6 +25,7 @@ #pragma once +#include "GLES3Std.h" #include "gfx-base/GFXDevice.h" namespace cc { @@ -68,18 +69,15 @@ public: inline uint getThreadID() const { return _threadID; } inline bool checkExtension(const String &extension) const { - for (size_t i = 0; i < _extensions.size(); ++i) { - if (_extensions[i].find(extension) != String::npos) { - return true; - } - } - return false; + return std::any_of(_extensions.begin(), _extensions.end(), [&extension](auto &ext) { + return ext.find(extension) != String::npos; + }); } uint getMinorVersion() const; protected: - static GLES3Device *_instance; + static GLES3Device *instance; friend class DeviceManager; friend class GLES3Context; @@ -119,7 +117,7 @@ protected: StringArray _extensions; - uint _threadID = 0u; + uint _threadID = 0U; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp index 2ea47a4284..45ca5e241b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp @@ -25,18 +25,16 @@ #include "GLES3Std.h" -#include "GLES3Framebuffer.h" -#include "GLES3Device.h" #include "GLES3Commands.h" +#include "GLES3Device.h" +#include "GLES3Framebuffer.h" #include "GLES3RenderPass.h" #include "GLES3Texture.h" namespace cc { namespace gfx { -GLES3Framebuffer::GLES3Framebuffer() -: Framebuffer() { -} +GLES3Framebuffer::GLES3Framebuffer() = default; GLES3Framebuffer::~GLES3Framebuffer() { destroy(); @@ -52,7 +50,7 @@ void GLES3Framebuffer::doInit(const FramebufferInfo &info) { _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - GLES3Texture *colorTexture = (GLES3Texture *)_colorTextures[i]; + auto *colorTexture = static_cast(_colorTextures[i]); if (colorTexture) { _gpuFBO->gpuColorTextures[i] = colorTexture->gpuTexture(); } @@ -62,12 +60,12 @@ void GLES3Framebuffer::doInit(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilTexture = static_cast(_depthStencilTexture)->gpuTexture(); } - GLES3CmdFuncCreateFramebuffer(GLES3Device::getInstance(), _gpuFBO); + cmdFuncGLES3CreateFramebuffer(GLES3Device::getInstance(), _gpuFBO); } void GLES3Framebuffer::doDestroy() { if (_gpuFBO) { - GLES3CmdFuncDestroyFramebuffer(GLES3Device::getInstance(), _gpuFBO); + cmdFuncGLES3DestroyFramebuffer(GLES3Device::getInstance(), _gpuFBO); CC_DELETE(_gpuFBO); _gpuFBO = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index e2a40e21dc..169a6c19e8 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -25,7 +25,11 @@ #pragma once +#include + #include "gfx-base/GFXDef.h" + +#include "GLES3Std.h" #include "GLES3Wrangler.h" namespace cc { @@ -33,180 +37,182 @@ namespace gfx { class GLES3GPUBuffer final : public Object { public: - BufferUsage usage = BufferUsage::NONE; - MemoryUsage memUsage = MemoryUsage::NONE; - uint size = 0; - uint stride = 0; - uint count = 0; - GLenum glTarget = 0; - GLuint glBuffer = 0; - GLuint glOffset = 0; - uint8_t *buffer = nullptr; + BufferUsage usage = BufferUsage::NONE; + MemoryUsage memUsage = MemoryUsage::NONE; + uint size = 0; + uint stride = 0; + uint count = 0; + GLenum glTarget = 0; + GLuint glBuffer = 0; + GLuint glOffset = 0; + uint8_t * buffer = nullptr; DrawInfoList indirects; }; -typedef vector GLES3GPUBufferList; +using GLES3GPUBufferList = vector; class GLES3GPUTexture final : public Object { public: - TextureType type = TextureType::TEX2D; - Format format = Format::UNKNOWN; - TextureUsage usage = TextureUsageBit::NONE; - uint width = 0; - uint height = 0; - uint depth = 1; - uint size = 0; - uint arrayLayer = 1; - uint mipLevel = 1; - SampleCount samples = SampleCount::X1; - TextureFlags flags = TextureFlagBit::NONE; - bool isPowerOf2 = false; - GLenum glTarget = 0; - GLenum glInternelFmt = 0; - GLenum glFormat = 0; - GLenum glType = 0; - GLenum glUsage = 0; - GLuint glTexture = 0; - GLenum glWrapS = 0; - GLenum glWrapT = 0; - GLenum glMinFilter = 0; - GLenum glMagFilter = 0; + TextureType type = TextureType::TEX2D; + Format format = Format::UNKNOWN; + TextureUsage usage = TextureUsageBit::NONE; + uint width = 0; + uint height = 0; + uint depth = 1; + uint size = 0; + uint arrayLayer = 1; + uint mipLevel = 1; + SampleCount samples = SampleCount::X1; + TextureFlags flags = TextureFlagBit::NONE; + bool isPowerOf2 = false; + GLenum glTarget = 0; + GLenum glInternelFmt = 0; + GLenum glFormat = 0; + GLenum glType = 0; + GLenum glUsage = 0; + GLuint glTexture = 0; + GLenum glWrapS = 0; + GLenum glWrapT = 0; + GLenum glMinFilter = 0; + GLenum glMagFilter = 0; }; -typedef vector GLES3GPUTextureList; +using GLES3GPUTextureList = vector; class GLES3GPUSampler final : public Object { public: - Filter minFilter = Filter::NONE; - Filter magFilter = Filter::NONE; - Filter mipFilter = Filter::NONE; - Address addressU = Address::CLAMP; - Address addressV = Address::CLAMP; - Address addressW = Address::CLAMP; - GLuint glSampler = 0; - GLenum glMinFilter = 0; - GLenum glMagFilter = 0; - GLenum glWrapS = 0; - GLenum glWrapT = 0; - GLenum glWrapR = 0; + Filter minFilter = Filter::NONE; + Filter magFilter = Filter::NONE; + Filter mipFilter = Filter::NONE; + Address addressU = Address::CLAMP; + Address addressV = Address::CLAMP; + Address addressW = Address::CLAMP; + GLuint glSampler = 0; + GLenum glMinFilter = 0; + GLenum glMagFilter = 0; + GLenum glWrapS = 0; + GLenum glWrapT = 0; + GLenum glWrapR = 0; }; struct GLES3GPUInput final { - uint binding = 0; + uint binding = 0; String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; + Type type = Type::UNKNOWN; + uint stride = 0; + uint count = 0; + uint size = 0; GLenum glType = 0; - GLint glLoc = -1; + GLint glLoc = -1; }; -typedef vector GLES3GPUInputList; +using GLES3GPUInputList = vector; struct GLES3GPUUniform final { - uint binding = GFX_INVALID_BINDING; + uint binding = GFX_INVALID_BINDING; String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - uint offset = 0; + Type type = Type::UNKNOWN; + uint stride = 0; + uint count = 0; + uint size = 0; + uint offset = 0; GLenum glType = 0; - GLint glLoc = -1; + GLint glLoc = -1; }; -typedef vector GLES3GPUUniformList; +using GLES3GPUUniformList = vector; struct GLES3GPUUniformBuffer final { - uint set = GFX_INVALID_BINDING; - uint binding = GFX_INVALID_BINDING; + uint set = GFX_INVALID_BINDING; + uint binding = GFX_INVALID_BINDING; String name; - uint size = 0; - uint glBinding = 0xffffffff; - bool isStorage = false; + uint size = 0; + uint glBinding = 0xffffffff; + bool isStorage = false; }; -typedef vector GLES3GPUUniformBufferList; +using GLES3GPUUniformBufferList = vector; struct GLES3GPUUniformSamplerTexture final { - uint set = 0; - uint binding = 0; + uint set = 0; + uint binding = 0; String name; - Type type = Type::UNKNOWN; - uint count = 0u; + Type type = Type::UNKNOWN; + uint count = 0U; vector units; - GLenum glType = 0; - GLint glLoc = -1; + GLenum glType = 0; + GLint glLoc = -1; }; -typedef vector GLES3GPUUniformSamplerTextureList; +using GLES3GPUUniformSamplerTextureList = vector; struct GLES3GPUUniformStorageImage final { - uint set = 0; - uint binding = 0; + uint set = 0; + uint binding = 0; String name; - Type type = Type::UNKNOWN; - uint count = 0u; + Type type = Type::UNKNOWN; + uint count = 0U; vector units; - GLenum glMemoryAccess = GL_READ_WRITE; - GLint glLoc = -1; + GLenum glMemoryAccess = GL_READ_WRITE; + GLint glLoc = -1; }; -typedef vector GLES3GPUUniformStorageImageList; +using GLES3GPUUniformStorageImageList = vector; struct GLES3GPUShaderStage final { GLES3GPUShaderStage(ShaderStageFlagBit t, String s, GLuint shader = 0) - : type(t), source(s), glShader(shader) {} + : type(t), + source(std::move(std::move(s))), + glShader(shader) {} ShaderStageFlagBit type; - String source; - GLuint glShader = 0; + String source; + GLuint glShader = 0; }; -typedef vector GLES3GPUShaderStageList; +using GLES3GPUShaderStageList = vector; class GLES3GPUShader final : public Object { public: - String name; - UniformBlockList blocks; - UniformStorageBufferList buffers; - UniformSamplerTextureList samplerTextures; - UniformSamplerList samplers; - UniformTextureList textures; - UniformStorageImageList images; + String name; + UniformBlockList blocks; + UniformStorageBufferList buffers; + UniformSamplerTextureList samplerTextures; + UniformSamplerList samplers; + UniformTextureList textures; + UniformStorageImageList images; UniformInputAttachmentList subpassInputs; - GLES3GPUShaderStageList gpuStages; - GLuint glProgram = 0; - GLES3GPUInputList glInputs; - GLES3GPUUniformBufferList glBuffers; + GLES3GPUShaderStageList gpuStages; + GLuint glProgram = 0; + GLES3GPUInputList glInputs; + GLES3GPUUniformBufferList glBuffers; GLES3GPUUniformSamplerTextureList glSamplerTextures; - GLES3GPUUniformStorageImageList glImages; + GLES3GPUUniformStorageImageList glImages; }; struct GLES3GPUAttribute final { String name; - GLuint glBuffer = 0; - GLenum glType = 0; - uint size = 0; - uint count = 0; - uint stride = 1; - uint componentCount = 1; - bool isNormalized = false; - bool isInstanced = false; - uint offset = 0; + GLuint glBuffer = 0; + GLenum glType = 0; + uint size = 0; + uint count = 0; + uint stride = 1; + uint componentCount = 1; + bool isNormalized = false; + bool isInstanced = false; + uint offset = 0; }; -typedef vector GLES3GPUAttributeList; +using GLES3GPUAttributeList = vector; class GLES3GPUInputAssembler final : public Object { public: - AttributeList attributes; - GLES3GPUBufferList gpuVertexBuffers; - GLES3GPUBuffer *gpuIndexBuffer = nullptr; - GLES3GPUBuffer *gpuIndirectBuffer = nullptr; + AttributeList attributes; + GLES3GPUBufferList gpuVertexBuffers; + GLES3GPUBuffer * gpuIndexBuffer = nullptr; + GLES3GPUBuffer * gpuIndirectBuffer = nullptr; GLES3GPUAttributeList glAttribs; - GLenum glIndexType = 0; - map glVAOs; + GLenum glIndexType = 0; + map glVAOs; }; class GLES3GPURenderPass final : public Object { public: - ColorAttachmentList colorAttachments; + ColorAttachmentList colorAttachments; DepthStencilAttachment depthStencilAttachment; }; @@ -214,23 +220,23 @@ class GLES3GPUFramebuffer final : public Object { public: GLES3GPURenderPass *gpuRenderPass = nullptr; GLES3GPUTextureList gpuColorTextures; - vector colorMipmapLevels; - GLES3GPUTexture *gpuDepthStencilTexture = nullptr; - GLint depthStencilMipmapLevel = 0; - GLuint glFramebuffer = 0; - bool isOffscreen = false; + vector colorMipmapLevels; + GLES3GPUTexture * gpuDepthStencilTexture = nullptr; + GLint depthStencilMipmapLevel = 0; + GLuint glFramebuffer = 0; + bool isOffscreen = false; }; class GLES3GPUDescriptorSetLayout final : public Object { public: DescriptorSetLayoutBindingList bindings; - vector dynamicBindings; + vector dynamicBindings; vector bindingIndices; vector descriptorIndices; - uint descriptorCount = 0u; + uint descriptorCount = 0U; }; -typedef vector GLES3GPUDescriptorSetLayoutList; +using GLES3GPUDescriptorSetLayoutList = vector; class GLES3GPUPipelineLayout final : public Object { public: @@ -238,42 +244,42 @@ public: // helper storages vector> dynamicOffsetIndices; - vector dynamicOffsetOffsets; - vector dynamicOffsets; - uint dynamicOffsetCount; + vector dynamicOffsetOffsets; + vector dynamicOffsets; + uint dynamicOffsetCount; }; class GLES3GPUPipelineState final : public Object { public: - GLenum glPrimitive = GL_TRIANGLES; - GLES3GPUShader *gpuShader = nullptr; - RasterizerState rs; - DepthStencilState dss; - BlendState bs; - DynamicStateList dynamicStates; - GLES3GPUPipelineLayout *gpuLayout = nullptr; - GLES3GPURenderPass *gpuRenderPass = nullptr; + GLenum glPrimitive = GL_TRIANGLES; + GLES3GPUShader * gpuShader = nullptr; + RasterizerState rs; + DepthStencilState dss; + BlendState bs; + DynamicStateList dynamicStates; + GLES3GPUPipelineLayout *gpuLayout = nullptr; + GLES3GPURenderPass * gpuRenderPass = nullptr; GLES3GPUPipelineLayout *gpuPipelineLayout = nullptr; }; struct GLES3GPUDescriptor final { - DescriptorType type = DescriptorType::UNKNOWN; - GLES3GPUBuffer *gpuBuffer = nullptr; + DescriptorType type = DescriptorType::UNKNOWN; + GLES3GPUBuffer * gpuBuffer = nullptr; GLES3GPUTexture *gpuTexture = nullptr; GLES3GPUSampler *gpuSampler = nullptr; }; -typedef vector GLES3GPUDescriptorList; +using GLES3GPUDescriptorList = vector; class GLES3GPUDescriptorSet final : public Object { public: GLES3GPUDescriptorList gpuDescriptors; - const vector *descriptorIndices = nullptr; + const vector * descriptorIndices = nullptr; }; class GLES3GPUGlobalBarrier final : public Object { public: - GLbitfield glBarriers = 0u; - GLbitfield glBarriersByRegion = 0u; + GLbitfield glBarriers = 0U; + GLbitfield glBarriersByRegion = 0U; }; struct GLES3GPUDispatchInfo final : public Object { @@ -282,124 +288,123 @@ struct GLES3GPUDispatchInfo final : public Object { uint groupCountZ = 0; GLES3GPUBuffer *indirectBuffer = nullptr; - uint indirectOffset = 0; + uint indirectOffset = 0; }; struct GLES3ObjectCache final { - size_t numClearColors = 0u; - GLES3GPURenderPass *gpuRenderPass = nullptr; - GLES3GPUFramebuffer *gpuFramebuffer = nullptr; - GLES3GPUPipelineState *gpuPipelineState = nullptr; + size_t numClearColors = 0U; + GLES3GPURenderPass * gpuRenderPass = nullptr; + GLES3GPUFramebuffer * gpuFramebuffer = nullptr; + GLES3GPUPipelineState * gpuPipelineState = nullptr; GLES3GPUInputAssembler *gpuInputAssembler = nullptr; - uint reverseCW = 0u; - GLenum glPrimitive = 0; - GLenum invalidAttachments[GFX_MAX_ATTACHMENTS]; + uint reverseCW = 0U; + GLenum glPrimitive = 0; + GLenum invalidAttachments[GFX_MAX_ATTACHMENTS]; }; class GLES3GPUStateCache final : public Object { public: - GLuint glArrayBuffer = 0; - GLuint glElementArrayBuffer = 0; - GLuint glUniformBuffer = 0; - vector glBindUBOs; - vector glBindUBOOffsets; - GLuint glShaderStorageBuffer = 0; - vector glBindSSBOs; - vector glBindSSBOOffsets; - GLuint glDispatchIndirectBuffer = 0; - GLuint glVAO = 0; - uint texUint = 0; - vector glTextures; - vector glImages; - vector glSamplers; - GLuint glProgram = 0; - vector glEnabledAttribLocs; - vector glCurrentAttribLocs; - GLuint glReadFramebuffer = 0; - GLuint glDrawFramebuffer = 0; - Viewport viewport; - Rect scissor; - RasterizerState rs; - DepthStencilState dss; - BlendState bs; - bool isCullFaceEnabled = true; - bool isStencilTestEnabled = false; + GLuint glArrayBuffer = 0; + GLuint glElementArrayBuffer = 0; + GLuint glUniformBuffer = 0; + vector glBindUBOs; + vector glBindUBOOffsets; + GLuint glShaderStorageBuffer = 0; + vector glBindSSBOs; + vector glBindSSBOOffsets; + GLuint glDispatchIndirectBuffer = 0; + GLuint glVAO = 0; + uint texUint = 0; + vector glTextures; + vector glImages; + vector glSamplers; + GLuint glProgram = 0; + vector glEnabledAttribLocs; + vector glCurrentAttribLocs; + GLuint glReadFramebuffer = 0; + GLuint glDrawFramebuffer = 0; + Viewport viewport; + Rect scissor; + RasterizerState rs; + DepthStencilState dss; + BlendState bs; + bool isCullFaceEnabled = true; + bool isStencilTestEnabled = false; unordered_map texUnitCacheMap; - GLES3ObjectCache gfxStateCache; + GLES3ObjectCache gfxStateCache; void initialize(size_t texUnits, size_t imageUnits, size_t uboBindings, size_t ssboBindings, size_t vertexAttributes) { - glBindUBOs.resize(uboBindings, 0u); - glBindUBOOffsets.resize(uboBindings, 0u); - glBindSSBOs.resize(ssboBindings, 0u); - glBindSSBOOffsets.resize(ssboBindings, 0u); - glTextures.resize(texUnits, 0u); - glSamplers.resize(texUnits, 0u); - glImages.resize(imageUnits, 0u); + glBindUBOs.resize(uboBindings, 0U); + glBindUBOOffsets.resize(uboBindings, 0U); + glBindSSBOs.resize(ssboBindings, 0U); + glBindSSBOOffsets.resize(ssboBindings, 0U); + glTextures.resize(texUnits, 0U); + glSamplers.resize(texUnits, 0U); + glImages.resize(imageUnits, 0U); glEnabledAttribLocs.resize(vertexAttributes, false); glCurrentAttribLocs.resize(vertexAttributes, false); } void reset() { - glArrayBuffer = 0; + glArrayBuffer = 0; glElementArrayBuffer = 0; - glUniformBuffer = 0; - glBindUBOs.assign(glBindUBOs.size(), 0u); - glBindUBOOffsets.assign(glBindUBOOffsets.size(), 0u); + glUniformBuffer = 0; + glBindUBOs.assign(glBindUBOs.size(), 0U); + glBindUBOOffsets.assign(glBindUBOOffsets.size(), 0U); glShaderStorageBuffer = 0; - glBindSSBOs.assign(glBindSSBOs.size(), 0u); - glBindSSBOOffsets.assign(glBindSSBOOffsets.size(), 0u); + glBindSSBOs.assign(glBindSSBOs.size(), 0U); + glBindSSBOOffsets.assign(glBindSSBOOffsets.size(), 0U); glDispatchIndirectBuffer = 0; - glVAO = 0; - texUint = 0; - glTextures.assign(glTextures.size(), 0u); - glImages.assign(glImages.size(), 0u); - glSamplers.assign(glSamplers.size(), 0u); + glVAO = 0; + texUint = 0; + glTextures.assign(glTextures.size(), 0U); + glImages.assign(glImages.size(), 0U); + glSamplers.assign(glSamplers.size(), 0U); glProgram = 0; - glEnabledAttribLocs.assign(glEnabledAttribLocs.size(), 0u); - glCurrentAttribLocs.assign(glCurrentAttribLocs.size(), 0u); - glReadFramebuffer = 0; - glDrawFramebuffer = 0; - isCullFaceEnabled = true; + glEnabledAttribLocs.assign(glEnabledAttribLocs.size(), false); + glCurrentAttribLocs.assign(glCurrentAttribLocs.size(), false); + glReadFramebuffer = 0; + glDrawFramebuffer = 0; + isCullFaceEnabled = true; isStencilTestEnabled = false; viewport = Viewport(); - scissor = Rect(); - rs = RasterizerState(); - dss = DepthStencilState(); - bs = BlendState(); + scissor = Rect(); + rs = RasterizerState(); + dss = DepthStencilState(); + bs = BlendState(); - gfxStateCache.numClearColors = 0u; - gfxStateCache.gpuRenderPass = nullptr; - gfxStateCache.gpuFramebuffer = nullptr; - gfxStateCache.gpuPipelineState = nullptr; + gfxStateCache.numClearColors = 0U; + gfxStateCache.gpuRenderPass = nullptr; + gfxStateCache.gpuFramebuffer = nullptr; + gfxStateCache.gpuPipelineState = nullptr; gfxStateCache.gpuInputAssembler = nullptr; - gfxStateCache.glPrimitive = 0u; - gfxStateCache.reverseCW = false; + gfxStateCache.glPrimitive = 0U; + gfxStateCache.reverseCW = false; } }; class GLES3GPUFramebufferCacheMap final : public Object { public: - GLES3GPUFramebufferCacheMap(GLES3GPUStateCache *cache) : _cache(cache) {} + explicit GLES3GPUFramebufferCacheMap(GLES3GPUStateCache *cache) : _cache(cache) {} - ~GLES3GPUFramebufferCacheMap() { - } + ~GLES3GPUFramebufferCacheMap() override = default; GLuint getFramebufferFromTexture(const GLES3GPUTexture *gpuTexture, const TextureSubresLayers &subres) { - // TODO: single layer support using glFramebufferTextureLayer + // TODO(YunHsiao): single layer support using glFramebufferTextureLayer - if (_map[gpuTexture->glTexture].empty()) _map[gpuTexture->glTexture].resize(gpuTexture->mipLevel, 0u); + if (_map[gpuTexture->glTexture].empty()) _map[gpuTexture->glTexture].resize(gpuTexture->mipLevel, 0U); if (!_map[gpuTexture->glTexture][subres.mipLevel]) { - GLuint glFramebuffer = 0u; + GLuint glFramebuffer = 0U; GL_CHECK(glGenFramebuffers(1, &glFramebuffer)); if (_cache->glDrawFramebuffer != glFramebuffer) { GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, glFramebuffer)); _cache->glDrawFramebuffer = glFramebuffer; } - const FormatInfo &info = GFX_FORMAT_INFOS[(uint)gpuTexture->format]; - GLenum attachment = GL_COLOR_ATTACHMENT0; + const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)]; + GLenum attachment = GL_COLOR_ATTACHMENT0; if (info.hasStencil) { attachment = GL_DEPTH_STENCIL_ATTACHMENT; } else if (info.hasDepth) { @@ -433,14 +438,14 @@ public: } private: - GLES3GPUStateCache *_cache = nullptr; + GLES3GPUStateCache * _cache = nullptr; unordered_map> _map; // texture -> mip level -> framebuffer }; -constexpr size_t chunkSize = 16 * 1024 * 1024; // 16M per block by default +constexpr size_t CHUNK_SIZE = 16 * 1024 * 1024; // 16M per block by default class GLES3GPUStagingBufferPool final : public Object { public: - ~GLES3GPUStagingBufferPool() { + ~GLES3GPUStagingBufferPool() override { for (Buffer &buffer : _pool) { CC_FREE(buffer.mappedData); } @@ -448,19 +453,19 @@ public: } uint8_t *alloc(size_t size) { - size_t bufferCount = _pool.size(); - Buffer *buffer = nullptr; - for (size_t idx = 0u; idx < bufferCount; idx++) { + size_t bufferCount = _pool.size(); + Buffer *buffer = nullptr; + for (size_t idx = 0U; idx < bufferCount; idx++) { Buffer *cur = &_pool[idx]; - if (chunkSize - cur->curOffset >= size) { + if (CHUNK_SIZE - cur->curOffset >= size) { buffer = cur; break; } } if (!buffer) { _pool.resize(bufferCount + 1); - buffer = &_pool.back(); - buffer->mappedData = (uint8_t *)CC_MALLOC(chunkSize); + buffer = &_pool.back(); + buffer->mappedData = static_cast(CC_MALLOC(CHUNK_SIZE)); } uint8_t *data = buffer->mappedData + buffer->curOffset; buffer->curOffset += size; @@ -469,14 +474,14 @@ public: void reset() { for (Buffer &buffer : _pool) { - buffer.curOffset = 0u; + buffer.curOffset = 0U; } } private: struct Buffer { uint8_t *mappedData = nullptr; - size_t curOffset = 0u; + size_t curOffset = 0U; }; vector _pool; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp index ae8dc7cb8b..e0eaf817a7 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp @@ -33,9 +33,7 @@ namespace cc { namespace gfx { -GLES3InputAssembler::GLES3InputAssembler() -: InputAssembler() { -} +GLES3InputAssembler::GLES3InputAssembler() = default; GLES3InputAssembler::~GLES3InputAssembler() { destroy(); @@ -46,21 +44,23 @@ void GLES3InputAssembler::doInit(const InputAssemblerInfo &info) { _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { - GLES3Buffer *vb = (GLES3Buffer *)_vertexBuffers[i]; + auto *vb = static_cast(_vertexBuffers[i]); _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } - if (info.indexBuffer) + if (info.indexBuffer) { _gpuInputAssembler->gpuIndexBuffer = static_cast(info.indexBuffer)->gpuBuffer(); + } - if (info.indirectBuffer) + if (info.indirectBuffer) { _gpuInputAssembler->gpuIndirectBuffer = static_cast(info.indirectBuffer)->gpuBuffer(); + } - GLES3CmdFuncCreateInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); + cmdFuncGLES3CreateInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); } void GLES3InputAssembler::doDestroy() { if (_gpuInputAssembler) { - GLES3CmdFuncDestroyInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); + cmdFuncGLES3DestroyInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); CC_DELETE(_gpuInputAssembler); _gpuInputAssembler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp index 5e15fbb031..c9f41c277e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp @@ -39,15 +39,11 @@ namespace cc { namespace gfx { -GLES3PrimaryCommandBuffer::GLES3PrimaryCommandBuffer() -: GLES3CommandBuffer() { -} - GLES3PrimaryCommandBuffer::~GLES3PrimaryCommandBuffer() { destroy(); } -void GLES3PrimaryCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void GLES3PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -59,45 +55,44 @@ void GLES3PrimaryCommandBuffer::begin(RenderPass *renderPass, uint subpass, Fram void GLES3PrimaryCommandBuffer::end() { if (_isStateInvalid) { - BindStates(); + bindStates(); } _isInRenderPass = false; } -void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { +void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { _isInRenderPass = true; GLES3GPURenderPass * gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); GLES3GPUFramebuffer *gpuFramebuffer = static_cast(fbo)->gpuFBO(); - GLES3CmdFuncBeginRenderPass(GLES3Device::getInstance(), gpuRenderPass, gpuFramebuffer, + cmdFuncGLES3BeginRenderPass(GLES3Device::getInstance(), gpuRenderPass, gpuFramebuffer, renderArea, gpuRenderPass->colorAttachments.size(), colors, depth, stencil); } void GLES3PrimaryCommandBuffer::endRenderPass() { - GLES3CmdFuncEndRenderPass(GLES3Device::getInstance()); + cmdFuncGLES3EndRenderPass(GLES3Device::getInstance()); _isInRenderPass = false; } -void GLES3PrimaryCommandBuffer::draw(InputAssembler *ia) { +void GLES3PrimaryCommandBuffer::draw(const DrawInfo &info) { if (_isStateInvalid) { - BindStates(); + bindStates(); } - DrawInfo drawInfo; - ia->extractDrawInfo(drawInfo); - GLES3CmdFuncDraw(GLES3Device::getInstance(), drawInfo); + cmdFuncGLES3Draw(GLES3Device::getInstance(), info); ++_numDrawCalls; - _numInstances += ia->getInstanceCount(); + _numInstances += info.instanceCount; if (_curGPUPipelineState) { + uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { - _numTriangles += ia->getIndexCount() / 3 * std::max(ia->getInstanceCount(), 1U); + _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); break; } case GL_TRIANGLE_STRIP: case GL_TRIANGLE_FAN: { - _numTriangles += (ia->getIndexCount() - 2) * std::max(ia->getInstanceCount(), 1U); + _numTriangles += (indexCount - 2) * std::max(info.instanceCount, 1U); break; } default: @@ -109,14 +104,14 @@ void GLES3PrimaryCommandBuffer::draw(InputAssembler *ia) { void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { GLES3GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { - GLES3CmdFuncUpdateBuffer(GLES3Device::getInstance(), gpuBuffer, data, 0u, size); + cmdFuncGLES3UpdateBuffer(GLES3Device::getInstance(), gpuBuffer, data, 0U, size); } } void GLES3PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { GLES3GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { - GLES3CmdFuncCopyBuffersToTexture(GLES3Device::getInstance(), buffers, gpuTexture, regions, count); + cmdFuncGLES3CopyBuffersToTexture(GLES3Device::getInstance(), buffers, gpuTexture, regions, count); } } @@ -126,17 +121,17 @@ void GLES3PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTex if (srcTexture) gpuTextureSrc = static_cast(srcTexture)->gpuTexture(); if (dstTexture) gpuTextureDst = static_cast(dstTexture)->gpuTexture(); - GLES3CmdFuncBlitTexture(GLES3Device::getInstance(), gpuTextureSrc, gpuTextureDst, regions, count, filter); + cmdFuncGLES3BlitTexture(GLES3Device::getInstance(), gpuTextureSrc, gpuTextureDst, regions, count, filter); } void GLES3PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { - GLES3PrimaryCommandBuffer *cmdBuff = (GLES3PrimaryCommandBuffer *)cmdBuffs[i]; + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES3CmdFuncExecuteCmds(GLES3Device::getInstance(), cmdPackage); + cmdFuncGLES3ExecuteCmds(GLES3Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); @@ -150,16 +145,16 @@ void GLES3PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t } } -void GLES3PrimaryCommandBuffer::BindStates() { +void GLES3PrimaryCommandBuffer::bindStates() { vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; - for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) { + for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); } - GLES3CmdFuncBindState(GLES3Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, + cmdFuncGLES3BindState(GLES3Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); _isStateInvalid = false; @@ -167,7 +162,7 @@ void GLES3PrimaryCommandBuffer::BindStates() { void GLES3PrimaryCommandBuffer::dispatch(const DispatchInfo &info) { if (_isStateInvalid) { - BindStates(); + bindStates(); } GLES3GPUDispatchInfo gpuInfo; @@ -179,14 +174,14 @@ void GLES3PrimaryCommandBuffer::dispatch(const DispatchInfo &info) { gpuInfo.groupCountY = info.groupCountY; gpuInfo.groupCountZ = info.groupCountZ; } - GLES3CmdFuncDispatch(GLES3Device::getInstance(), gpuInfo); + cmdFuncGLES3Dispatch(GLES3Device::getInstance(), gpuInfo); } -void GLES3PrimaryCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void GLES3PrimaryCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint /*textureBarrierCount*/) { if (!barrier) return; - auto gpuBarrier = static_cast(barrier)->gpuBarrier(); - GLES3CmdFuncMemoryBarrier(GLES3Device::getInstance(), gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion); + const auto *gpuBarrier = static_cast(barrier)->gpuBarrier(); + cmdFuncGLES3MemoryBarrier(GLES3Device::getInstance(), gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h index 5fa90cc561..b1682b8878 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h @@ -32,14 +32,14 @@ namespace gfx { class CC_GLES3_API GLES3PrimaryCommandBuffer final : public GLES3CommandBuffer { public: - GLES3PrimaryCommandBuffer(); - ~GLES3PrimaryCommandBuffer(); + GLES3PrimaryCommandBuffer() = default; + ~GLES3PrimaryCommandBuffer() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; void endRenderPass() override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; @@ -50,7 +50,7 @@ public: protected: friend class GLES3Queue; - void BindStates() override; + void bindStates() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp index e4249f7407..b4540096a5 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp @@ -33,9 +33,7 @@ namespace cc { namespace gfx { -GLES3Queue::GLES3Queue() -: Queue() { -} +GLES3Queue::GLES3Queue() = default; GLES3Queue::~GLES3Queue() { destroy(); @@ -49,12 +47,12 @@ void GLES3Queue::doDestroy() { void GLES3Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { for (uint i = 0; i < count; ++i) { - GLES3CommandBuffer *cmdBuff = (GLES3CommandBuffer *)cmdBuffs[i]; + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES3CmdFuncExecuteCmds(GLES3Device::getInstance(), cmdPackage); + cmdFuncGLES3ExecuteCmds(GLES3Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp index e4308f581c..69f8fde7eb 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES3Sampler::GLES3Sampler() -: Sampler() { -} +GLES3Sampler::GLES3Sampler() = default; GLES3Sampler::~GLES3Sampler() { destroy(); } -void GLES3Sampler::doInit(const SamplerInfo &info) { +void GLES3Sampler::doInit(const SamplerInfo & /*info*/) { _gpuSampler = CC_NEW(GLES3GPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; @@ -49,12 +47,12 @@ void GLES3Sampler::doInit(const SamplerInfo &info) { _gpuSampler->addressV = _addressV; _gpuSampler->addressW = _addressW; - GLES3CmdFuncCreateSampler(GLES3Device::getInstance(), _gpuSampler); + cmdFuncGLES3CreateSampler(GLES3Device::getInstance(), _gpuSampler); } void GLES3Sampler::doDestroy() { if (_gpuSampler) { - GLES3CmdFuncDestroySampler(GLES3Device::getInstance(), _gpuSampler); + cmdFuncGLES3DestroySampler(GLES3Device::getInstance(), _gpuSampler); CC_DELETE(_gpuSampler); _gpuSampler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp index 5cfe925efd..0ec4984292 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES3Shader::GLES3Shader() -: Shader() { -} +GLES3Shader::GLES3Shader() = default; GLES3Shader::~GLES3Shader() { destroy(); } -void GLES3Shader::doInit(const ShaderInfo &info) { +void GLES3Shader::doInit(const ShaderInfo & /*info*/) { _gpuShader = CC_NEW(GLES3GPUShader); _gpuShader->name = _name; _gpuShader->blocks = _blocks; @@ -55,12 +53,12 @@ void GLES3Shader::doInit(const ShaderInfo &info) { _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } - GLES3CmdFuncCreateShader(GLES3Device::getInstance(), _gpuShader); + cmdFuncGLES3CreateShader(GLES3Device::getInstance(), _gpuShader); } void GLES3Shader::doDestroy() { if (_gpuShader) { - GLES3CmdFuncDestroyShader(GLES3Device::getInstance(), _gpuShader); + cmdFuncGLES3DestroyShader(GLES3Device::getInstance(), _gpuShader); CC_DELETE(_gpuShader); _gpuShader = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp index 4a37a510e8..99dd7734c1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -GLES3Texture::GLES3Texture() -: Texture() { -} +GLES3Texture::GLES3Texture() = default; GLES3Texture::~GLES3Texture() { destroy(); } -void GLES3Texture::doInit(const TextureInfo &info) { +void GLES3Texture::doInit(const TextureInfo & /*info*/) { _gpuTexture = CC_NEW(GLES3GPUTexture); _gpuTexture->type = _type; _gpuTexture->format = _format; @@ -55,16 +53,16 @@ void GLES3Texture::doInit(const TextureInfo &info) { _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); - GLES3CmdFuncCreateTexture(GLES3Device::getInstance(), _gpuTexture); + cmdFuncGLES3CreateTexture(GLES3Device::getInstance(), _gpuTexture); } -void GLES3Texture::doInit(const TextureViewInfo &info) { +void GLES3Texture::doInit(const TextureViewInfo & /*info*/) { CC_LOG_ERROR("GLES3 doesn't support texture view."); } void GLES3Texture::doDestroy() { if (_gpuTexture) { - GLES3CmdFuncDestroyTexture(GLES3Device::getInstance(), _gpuTexture); + cmdFuncGLES3DestroyTexture(GLES3Device::getInstance(), _gpuTexture); CC_DELETE(_gpuTexture); _gpuTexture = nullptr; } @@ -74,7 +72,7 @@ void GLES3Texture::doResize(uint width, uint height, uint size) { _gpuTexture->width = width; _gpuTexture->height = height; _gpuTexture->size = size; - GLES3CmdFuncResizeTexture(GLES3Device::getInstance(), _gpuTexture); + cmdFuncGLES3ResizeTexture(GLES3Device::getInstance(), _gpuTexture); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h index 3706ed843d..15280a0729 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h @@ -66,7 +66,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index e8ed589db8..acb02bdb50 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -262,13 +262,13 @@ void CCMTLCommandBuffer::setStencilCompareMask(StencilFace /*face*/, int /*ref*/ CC_LOG_ERROR("Don't support change stencil compare mask here."); } -void CCMTLCommandBuffer::draw(InputAssembler *ia) { +void CCMTLCommandBuffer::draw(const DrawInfo &info) { if (_firstDirtyDescriptorSet < _GPUDescriptorSets.size()) { bindDescriptorSets(); } - const auto *indirectBuffer = static_cast(ia->getIndirectBuffer()); - const auto *indexBuffer = static_cast(ia->getIndexBuffer()); + const auto *indirectBuffer = static_cast(_inputAssembler->getIndirectBuffer()); + const auto *indexBuffer = static_cast(_inputAssembler->getIndexBuffer()); auto mtlEncoder = _renderEncoder.getMTLEncoder(); if (indirectBuffer) { @@ -328,47 +328,46 @@ void CCMTLCommandBuffer::draw(InputAssembler *ia) { } } } else { - DrawInfo drawInfo; - static_cast(ia)->extractDrawInfo(drawInfo); - if (drawInfo.indexCount > 0) { + if (info.indexCount > 0) { uint offset = 0; - offset += drawInfo.firstIndex * indexBuffer->getStride(); - if (drawInfo.instanceCount == 0) { + offset += info.firstIndex * indexBuffer->getStride(); + if (info.instanceCount == 0) { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:drawInfo.indexCount + indexCount:info.indexCount indexType:indexBuffer->getIndexType() indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset]; } else { [mtlEncoder drawIndexedPrimitives:_mtlPrimitiveType - indexCount:drawInfo.indexCount + indexCount:info.indexCount indexType:indexBuffer->getIndexType() indexBuffer:indexBuffer->getMTLBuffer() indexBufferOffset:offset - instanceCount:drawInfo.instanceCount]; + instanceCount:info.instanceCount]; } - } else if (drawInfo.vertexCount) { - if (drawInfo.instanceCount == 0) { + } else if (info.vertexCount) { + if (info.instanceCount == 0) { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:drawInfo.firstIndex - vertexCount:drawInfo.vertexCount]; + vertexStart:info.firstIndex + vertexCount:info.vertexCount]; } else { [mtlEncoder drawPrimitives:_mtlPrimitiveType - vertexStart:drawInfo.firstIndex - vertexCount:drawInfo.vertexCount - instanceCount:drawInfo.instanceCount]; + vertexStart:info.firstIndex + vertexCount:info.vertexCount + instanceCount:info.instanceCount]; } } - _numInstances += drawInfo.instanceCount; + + _numInstances += info.instanceCount; _numDrawCalls++; if (_gpuPipelineState) { - uint indexCount = drawInfo.indexCount ? drawInfo.indexCount : drawInfo.vertexCount; + uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; switch (_mtlPrimitiveType) { case MTLPrimitiveTypeTriangle: - _numTriangles += indexCount / 3 * std::max(drawInfo.instanceCount, 1U); + _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); break; case MTLPrimitiveTypeTriangleStrip: - _numTriangles += (indexCount - 2) * std::max(drawInfo.instanceCount, 1U); + _numTriangles += (indexCount - 2) * std::max(info.instanceCount, 1U); break; default: break; } @@ -414,7 +413,7 @@ void CCMTLCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex auto h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; bufferSize[i] = w * h; stagingRegion.sourceBytesPerRow = mu::getBytesPerRow(convertedFormat, w); - stagingRegion.sourceBytesPerImage = FormatSize(convertedFormat, w, h, region.texExtent.depth); + stagingRegion.sourceBytesPerImage = formatSize(convertedFormat, w, h, region.texExtent.depth); stagingRegion.sourceSize = {w, h, region.texExtent.depth}; stagingRegion.destinationSlice = region.texSubres.baseArrayLayer; stagingRegion.destinationLevel = region.texSubres.mipLevel; @@ -525,7 +524,7 @@ void CCMTLCommandBuffer::bindDescriptorSets() { _renderEncoder.setFragmentTexture(gpuDescriptor.texture->getMTLTexture(), sampler.textureBinding); _renderEncoder.setFragmentSampler(gpuDescriptor.sampler->getMTLSamplerState(), sampler.samplerBinding); } - + if(sampler.stages & ShaderStageFlagBit::COMPUTE) { _computeEncoder.setTexture(gpuDescriptor.texture->getMTLTexture(), sampler.textureBinding); } @@ -544,11 +543,11 @@ void CCMTLCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, c } else { dst = static_cast(dstTexture)->getMTLTexture(); } - + if([src pixelFormat] != device->preferredPixelFormat()) { src = [src newTextureViewWithPixelFormat:(MTLPixelFormat)device->preferredPixelFormat()]; } - + for (uint i = 0; i < count; ++i) { [encoder copyFromTexture:src sourceSlice:regions[i].srcSubres.baseArrayLayer diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index e671fc824a..b4d6a262e2 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -55,7 +55,7 @@ CCMTLDevice *CCMTLDevice::getInstance() { } CCMTLDevice::CCMTLDevice() { - _API = API::METAL; + _api = API::METAL; _deviceName = "Metal"; _caps.clipSpaceMinZ = 0.0f; @@ -229,9 +229,9 @@ void CCMTLDevice::doDestroy() { void CCMTLDevice::resize(uint w, uint h) { this->_width = w; this->_height = h; - + [id(_dssTex) release]; - + MTLTextureDescriptor *dssDescriptor = [[MTLTextureDescriptor alloc] init]; const auto gpuFamily = mu::getGPUFamily(MTLFeatureSet(_mtlFeatureSet)); dssDescriptor.pixelFormat = mu::getSupportedDepthStencilFormat(id(this->_mtlDevice), gpuFamily, _caps.depthBits); diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index e87737d4c2..8834cf3bfa 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -323,34 +323,34 @@ GPUFamily getMacGPUFamily(MTLFeatureSet featureSet) { bool isASTCFormat(Format format) { switch (format) { - case Format::ASTC_RGBA_4x4: - case Format::ASTC_SRGBA_4x4: - case Format::ASTC_RGBA_5x4: - case Format::ASTC_SRGBA_5x4: - case Format::ASTC_RGBA_5x5: - case Format::ASTC_SRGBA_5x5: - case Format::ASTC_RGBA_6x5: - case Format::ASTC_SRGBA_6x5: - case Format::ASTC_RGBA_6x6: - case Format::ASTC_SRGBA_6x6: - case Format::ASTC_RGBA_8x5: - case Format::ASTC_SRGBA_8x5: - case Format::ASTC_RGBA_8x6: - case Format::ASTC_SRGBA_8x6: - case Format::ASTC_RGBA_8x8: - case Format::ASTC_SRGBA_8x8: - case Format::ASTC_RGBA_10x5: - case Format::ASTC_SRGBA_10x5: - case Format::ASTC_RGBA_10x6: - case Format::ASTC_SRGBA_10x6: - case Format::ASTC_RGBA_10x8: - case Format::ASTC_SRGBA_10x8: - case Format::ASTC_RGBA_10x10: - case Format::ASTC_SRGBA_10x10: - case Format::ASTC_RGBA_12x10: - case Format::ASTC_SRGBA_12x10: - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_12x12: + case Format::ASTC_RGBA_4X4: + case Format::ASTC_SRGBA_4X4: + case Format::ASTC_RGBA_5X4: + case Format::ASTC_SRGBA_5X4: + case Format::ASTC_RGBA_5X5: + case Format::ASTC_SRGBA_5X5: + case Format::ASTC_RGBA_6X5: + case Format::ASTC_SRGBA_6X5: + case Format::ASTC_RGBA_6X6: + case Format::ASTC_SRGBA_6X6: + case Format::ASTC_RGBA_8X5: + case Format::ASTC_SRGBA_8X5: + case Format::ASTC_RGBA_8X6: + case Format::ASTC_SRGBA_8X6: + case Format::ASTC_RGBA_8X8: + case Format::ASTC_SRGBA_8X8: + case Format::ASTC_RGBA_10X5: + case Format::ASTC_SRGBA_10X5: + case Format::ASTC_RGBA_10X6: + case Format::ASTC_SRGBA_10X6: + case Format::ASTC_RGBA_10X8: + case Format::ASTC_SRGBA_10X8: + case Format::ASTC_RGBA_10X10: + case Format::ASTC_SRGBA_10X10: + case Format::ASTC_RGBA_12X10: + case Format::ASTC_SRGBA_12X10: + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_12X12: return true; default: return false; @@ -590,35 +590,35 @@ MTLPixelFormat mu::toMTLPixelFormat(Format format) { case Format::BC3: return MTLPixelFormatBC3_RGBA; case Format::BC3_SRGB: return MTLPixelFormatBC3_RGBA_sRGB; #else - case Format::ASTC_RGBA_4x4: return MTLPixelFormatASTC_4x4_LDR; - case Format::ASTC_RGBA_5x4: return MTLPixelFormatASTC_5x4_LDR; - case Format::ASTC_RGBA_5x5: return MTLPixelFormatASTC_5x5_LDR; - case Format::ASTC_RGBA_6x5: return MTLPixelFormatASTC_6x5_LDR; - case Format::ASTC_RGBA_6x6: return MTLPixelFormatASTC_6x6_LDR; - case Format::ASTC_RGBA_8x5: return MTLPixelFormatASTC_8x5_LDR; - case Format::ASTC_RGBA_8x6: return MTLPixelFormatASTC_8x6_LDR; - case Format::ASTC_RGBA_8x8: return MTLPixelFormatASTC_8x8_LDR; - case Format::ASTC_RGBA_10x5: return MTLPixelFormatASTC_10x5_LDR; - case Format::ASTC_RGBA_10x6: return MTLPixelFormatASTC_10x6_LDR; - case Format::ASTC_RGBA_10x8: return MTLPixelFormatASTC_10x8_LDR; - case Format::ASTC_RGBA_10x10: return MTLPixelFormatASTC_10x10_LDR; - case Format::ASTC_RGBA_12x10: return MTLPixelFormatASTC_12x10_LDR; - case Format::ASTC_RGBA_12x12: return MTLPixelFormatASTC_12x12_LDR; + case Format::ASTC_RGBA_4X4: return MTLPixelFormatASTC_4x4_LDR; + case Format::ASTC_RGBA_5X4: return MTLPixelFormatASTC_5x4_LDR; + case Format::ASTC_RGBA_5X5: return MTLPixelFormatASTC_5x5_LDR; + case Format::ASTC_RGBA_6X5: return MTLPixelFormatASTC_6x5_LDR; + case Format::ASTC_RGBA_6X6: return MTLPixelFormatASTC_6x6_LDR; + case Format::ASTC_RGBA_8X5: return MTLPixelFormatASTC_8x5_LDR; + case Format::ASTC_RGBA_8X6: return MTLPixelFormatASTC_8x6_LDR; + case Format::ASTC_RGBA_8X8: return MTLPixelFormatASTC_8x8_LDR; + case Format::ASTC_RGBA_10X5: return MTLPixelFormatASTC_10x5_LDR; + case Format::ASTC_RGBA_10X6: return MTLPixelFormatASTC_10x6_LDR; + case Format::ASTC_RGBA_10X8: return MTLPixelFormatASTC_10x8_LDR; + case Format::ASTC_RGBA_10X10: return MTLPixelFormatASTC_10x10_LDR; + case Format::ASTC_RGBA_12X10: return MTLPixelFormatASTC_12x10_LDR; + case Format::ASTC_RGBA_12X12: return MTLPixelFormatASTC_12x12_LDR; - case Format::ASTC_SRGBA_4x4: return MTLPixelFormatASTC_4x4_sRGB; - case Format::ASTC_SRGBA_5x4: return MTLPixelFormatASTC_5x4_sRGB; - case Format::ASTC_SRGBA_5x5: return MTLPixelFormatASTC_5x5_sRGB; - case Format::ASTC_SRGBA_6x5: return MTLPixelFormatASTC_6x5_sRGB; - case Format::ASTC_SRGBA_6x6: return MTLPixelFormatASTC_6x6_sRGB; - case Format::ASTC_SRGBA_8x5: return MTLPixelFormatASTC_8x5_sRGB; - case Format::ASTC_SRGBA_8x6: return MTLPixelFormatASTC_8x6_sRGB; - case Format::ASTC_SRGBA_8x8: return MTLPixelFormatASTC_8x8_sRGB; - case Format::ASTC_SRGBA_10x5: return MTLPixelFormatASTC_10x5_sRGB; - case Format::ASTC_SRGBA_10x6: return MTLPixelFormatASTC_10x6_sRGB; - case Format::ASTC_SRGBA_10x8: return MTLPixelFormatASTC_10x8_sRGB; - case Format::ASTC_SRGBA_10x10: return MTLPixelFormatASTC_10x10_sRGB; - case Format::ASTC_SRGBA_12x10: return MTLPixelFormatASTC_12x10_sRGB; - case Format::ASTC_SRGBA_12x12: return MTLPixelFormatASTC_12x12_sRGB; + case Format::ASTC_SRGBA_4X4: return MTLPixelFormatASTC_4x4_sRGB; + case Format::ASTC_SRGBA_5X4: return MTLPixelFormatASTC_5x4_sRGB; + case Format::ASTC_SRGBA_5X5: return MTLPixelFormatASTC_5x5_sRGB; + case Format::ASTC_SRGBA_6X5: return MTLPixelFormatASTC_6x5_sRGB; + case Format::ASTC_SRGBA_6X6: return MTLPixelFormatASTC_6x6_sRGB; + case Format::ASTC_SRGBA_8X5: return MTLPixelFormatASTC_8x5_sRGB; + case Format::ASTC_SRGBA_8X6: return MTLPixelFormatASTC_8x6_sRGB; + case Format::ASTC_SRGBA_8X8: return MTLPixelFormatASTC_8x8_sRGB; + case Format::ASTC_SRGBA_10X5: return MTLPixelFormatASTC_10x5_sRGB; + case Format::ASTC_SRGBA_10X6: return MTLPixelFormatASTC_10x6_sRGB; + case Format::ASTC_SRGBA_10X8: return MTLPixelFormatASTC_10x8_sRGB; + case Format::ASTC_SRGBA_10X10: return MTLPixelFormatASTC_10x10_sRGB; + case Format::ASTC_SRGBA_12X10: return MTLPixelFormatASTC_12x10_sRGB; + case Format::ASTC_SRGBA_12X12: return MTLPixelFormatASTC_12x12_sRGB; case Format::ETC2_RGB8: return MTLPixelFormatETC2_RGB8; case Format::ETC2_SRGB8: return MTLPixelFormatETC2_RGB8_sRGB; @@ -923,7 +923,7 @@ String mu::compileGLSLShader2Msl(const String &src, gpuShader->blocks[mappedBinding].stages |= shaderType; } } - + for (const auto &ubo : resources.storage_buffers) { auto set = msl.get_decoration(ubo.id, spv::DecorationDescriptorSet); auto binding = msl.get_decoration(ubo.id, spv::DecorationBinding); @@ -1425,34 +1425,34 @@ const uint8_t *const mu::convertData(const uint8_t *source, uint length, Format uint mu::getBlockSize(Format format) { switch (format) { - case Format::ASTC_RGBA_4x4: - case Format::ASTC_SRGBA_4x4: - case Format::ASTC_RGBA_5x4: - case Format::ASTC_SRGBA_5x4: - case Format::ASTC_RGBA_5x5: - case Format::ASTC_SRGBA_5x5: - case Format::ASTC_RGBA_6x5: - case Format::ASTC_SRGBA_6x5: - case Format::ASTC_RGBA_6x6: - case Format::ASTC_SRGBA_6x6: - case Format::ASTC_RGBA_8x5: - case Format::ASTC_SRGBA_8x5: - case Format::ASTC_RGBA_8x6: - case Format::ASTC_SRGBA_8x6: - case Format::ASTC_RGBA_8x8: - case Format::ASTC_SRGBA_8x8: - case Format::ASTC_RGBA_10x5: - case Format::ASTC_SRGBA_10x5: - case Format::ASTC_RGBA_10x6: - case Format::ASTC_SRGBA_10x6: - case Format::ASTC_RGBA_10x8: - case Format::ASTC_SRGBA_10x8: - case Format::ASTC_RGBA_10x10: - case Format::ASTC_SRGBA_10x10: - case Format::ASTC_RGBA_12x10: - case Format::ASTC_SRGBA_12x10: - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_12x12: + case Format::ASTC_RGBA_4X4: + case Format::ASTC_SRGBA_4X4: + case Format::ASTC_RGBA_5X4: + case Format::ASTC_SRGBA_5X4: + case Format::ASTC_RGBA_5X5: + case Format::ASTC_SRGBA_5X5: + case Format::ASTC_RGBA_6X5: + case Format::ASTC_SRGBA_6X5: + case Format::ASTC_RGBA_6X6: + case Format::ASTC_SRGBA_6X6: + case Format::ASTC_RGBA_8X5: + case Format::ASTC_SRGBA_8X5: + case Format::ASTC_RGBA_8X6: + case Format::ASTC_SRGBA_8X6: + case Format::ASTC_RGBA_8X8: + case Format::ASTC_SRGBA_8X8: + case Format::ASTC_RGBA_10X5: + case Format::ASTC_SRGBA_10X5: + case Format::ASTC_RGBA_10X6: + case Format::ASTC_SRGBA_10X6: + case Format::ASTC_RGBA_10X8: + case Format::ASTC_SRGBA_10X8: + case Format::ASTC_RGBA_10X10: + case Format::ASTC_SRGBA_10X10: + case Format::ASTC_RGBA_12X10: + case Format::ASTC_SRGBA_12X10: + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_12X12: return 16u; case Format::PVRTC_RGB2: case Format::PVRTC_RGBA2: @@ -1481,44 +1481,44 @@ uint mu::getBytesPerRow(Format format, uint width) { uint blockSize = getBlockSize(format); uint widthInBlock = 1u; switch (format) { - case Format::ASTC_RGBA_4x4: - case Format::ASTC_SRGBA_4x4: + case Format::ASTC_RGBA_4X4: + case Format::ASTC_SRGBA_4X4: widthInBlock = (width + 3) / 4; break; - case Format::ASTC_RGBA_5x4: - case Format::ASTC_SRGBA_5x4: - case Format::ASTC_RGBA_5x5: - case Format::ASTC_SRGBA_5x5: + case Format::ASTC_RGBA_5X4: + case Format::ASTC_SRGBA_5X4: + case Format::ASTC_RGBA_5X5: + case Format::ASTC_SRGBA_5X5: widthInBlock = (width + 4) / 5; break; - case Format::ASTC_RGBA_6x5: - case Format::ASTC_SRGBA_6x5: - case Format::ASTC_RGBA_6x6: - case Format::ASTC_SRGBA_6x6: + case Format::ASTC_RGBA_6X5: + case Format::ASTC_SRGBA_6X5: + case Format::ASTC_RGBA_6X6: + case Format::ASTC_SRGBA_6X6: widthInBlock = (width + 5) / 6; break; - case Format::ASTC_RGBA_8x5: - case Format::ASTC_SRGBA_8x5: - case Format::ASTC_RGBA_8x6: - case Format::ASTC_SRGBA_8x6: - case Format::ASTC_RGBA_8x8: - case Format::ASTC_SRGBA_8x8: + case Format::ASTC_RGBA_8X5: + case Format::ASTC_SRGBA_8X5: + case Format::ASTC_RGBA_8X6: + case Format::ASTC_SRGBA_8X6: + case Format::ASTC_RGBA_8X8: + case Format::ASTC_SRGBA_8X8: widthInBlock = (width + 7) / 8; break; - case Format::ASTC_RGBA_10x5: - case Format::ASTC_SRGBA_10x5: - case Format::ASTC_RGBA_10x6: - case Format::ASTC_SRGBA_10x6: - case Format::ASTC_RGBA_10x8: - case Format::ASTC_SRGBA_10x8: - case Format::ASTC_RGBA_10x10: - case Format::ASTC_SRGBA_10x10: + case Format::ASTC_RGBA_10X5: + case Format::ASTC_SRGBA_10X5: + case Format::ASTC_RGBA_10X6: + case Format::ASTC_SRGBA_10X6: + case Format::ASTC_RGBA_10X8: + case Format::ASTC_SRGBA_10X8: + case Format::ASTC_RGBA_10X10: + case Format::ASTC_SRGBA_10X10: widthInBlock = (width + 9) / 10; break; - case Format::ASTC_RGBA_12x10: - case Format::ASTC_SRGBA_12x10: - case Format::ASTC_RGBA_12x12: - case Format::ASTC_SRGBA_12x12: + case Format::ASTC_RGBA_12X10: + case Format::ASTC_SRGBA_12X10: + case Format::ASTC_RGBA_12X12: + case Format::ASTC_SRGBA_12X12: widthInBlock = (width + 11) / 12; break; case Format::PVRTC_RGB2: diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index efe73703a2..aef63813f7 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -131,7 +131,7 @@ void CommandBufferValidator::execute(CommandBuffer *const *cmdBuffs, uint32_t co static vector cmdBuffActors; cmdBuffActors.resize(count); - for (uint i = 0u; i < count; ++i) { + for (uint i = 0U; i < count; ++i) { cmdBuffActors[i] = static_cast(cmdBuffs[i])->getActor(); } @@ -182,19 +182,19 @@ void CommandBufferValidator::setStencilCompareMask(StencilFace face, int ref, ui _actor->setStencilCompareMask(face, ref, mask); } -void CommandBufferValidator::draw(InputAssembler *ia) { +void CommandBufferValidator::draw(const DrawInfo &info) { CCASSERT(_insideRenderPass, "Command 'draw' must be recorded inside render passes."); /////////// execute /////////// - _actor->draw(static_cast(ia)->getActor()); + _actor->draw(info); } void CommandBufferValidator::updateBuffer(Buffer *buff, const void *data, uint size) { CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'updateBuffer' must be recorded in primary command buffers."); CCASSERT(!_insideRenderPass, "Command 'updateBuffer' must be recorded outside render passes."); - auto bufferValidator = static_cast(buff); + auto *bufferValidator = static_cast(buff); bufferValidator->updateRedundencyCheck(); /////////// execute /////////// @@ -206,7 +206,7 @@ void CommandBufferValidator::copyBuffersToTexture(const uint8_t *const *buffers, CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'copyBuffersToTexture' must be recorded in primary command buffers."); CCASSERT(!_insideRenderPass, "Command 'copyBuffersToTexture' must be recorded outside render passes."); - auto textureValidator = static_cast(texture); + auto *textureValidator = static_cast(texture); textureValidator->updateRedundencyCheck(); /////////// execute /////////// @@ -248,7 +248,7 @@ void CommandBufferValidator::pipelineBarrier(const GlobalBarrier *barrier, const Texture **actorTextures = nullptr; if (textureBarrierCount) { actorTextures = textureActors.data(); - for (uint i = 0u; i < textureBarrierCount; ++i) { + for (uint i = 0U; i < textureBarrierCount; ++i) { actorTextures[i] = textures[i] ? static_cast(textures[i])->getActor() : nullptr; } } diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.h b/native/cocos/renderer/gfx-validator/CommandBufferValidator.h index 0b0b787d7a..751dfff94e 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.h +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.h @@ -51,7 +51,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buff, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index 125bbeb8e8..2d641070fe 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -44,19 +44,19 @@ namespace cc { namespace gfx { -DeviceValidator *DeviceValidator::_instance = nullptr; +DeviceValidator *DeviceValidator::instance = nullptr; DeviceValidator *DeviceValidator::getInstance() { - return DeviceValidator::_instance; + return DeviceValidator::instance; } DeviceValidator::DeviceValidator(Device *device) : Agent(device) { - DeviceValidator::_instance = this; + DeviceValidator::instance = this; } DeviceValidator::~DeviceValidator() { CC_SAFE_DELETE(_actor); - DeviceValidator::_instance = nullptr; + DeviceValidator::instance = nullptr; } bool DeviceValidator::doInit(const DeviceInfo &info) { @@ -65,7 +65,7 @@ bool DeviceValidator::doInit(const DeviceInfo &info) { } _context = _actor->getContext(); - _API = _actor->getGfxAPI(); + _api = _actor->getGfxAPI(); _deviceName = _actor->getDeviceName(); _queue = CC_NEW(QueueValidator(_actor->getQueue())); _cmdBuff = CC_NEW(CommandBufferValidator(_actor->getCommandBuffer())); @@ -231,7 +231,7 @@ TextureBarrier *DeviceValidator::createTextureBarrier() { } void DeviceValidator::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { - auto textureValidator = static_cast(dst); + auto *textureValidator = static_cast(dst); textureValidator->updateRedundencyCheck(); _actor->copyBuffersToTexture(buffers, textureValidator->getActor(), regions, count); @@ -245,7 +245,7 @@ void DeviceValidator::flushCommands(CommandBuffer *const *cmdBuffs, uint count) static vector cmdBuffActors; cmdBuffActors.resize(count); - for (uint i = 0u; i < count; ++i) { + for (uint i = 0U; i < count; ++i) { cmdBuffActors[i] = static_cast(cmdBuffs[i])->getActor(); } diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.h b/native/cocos/renderer/gfx-validator/DeviceValidator.h index ae05459599..cd0ae37aac 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.h +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.h @@ -88,15 +88,15 @@ public: uint getNumTris() const override { return _actor->getNumTris(); } inline void enableRecording(bool recording) { _recording = recording; } - inline bool isRecording() { return _recording; } - inline uint currentFrame() { return _currentFrame; } + inline bool isRecording() const { return _recording; } + inline uint currentFrame() const { return _currentFrame; } protected: - static DeviceValidator *_instance; + static DeviceValidator *instance; friend class DeviceManager; - DeviceValidator(Device *device); + explicit DeviceValidator(Device *device); bool doInit(const DeviceInfo &info) override; void doDestroy() override; @@ -108,7 +108,7 @@ protected: void bindDeviceContext(bool bound) override { _actor->bindDeviceContext(bound); } bool _recording{false}; - uint _currentFrame{1u}; + uint _currentFrame{1U}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index 72bc6050d7..1c16be8302 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -33,15 +33,13 @@ namespace cc { namespace gfx { -CCVKBuffer::CCVKBuffer() -: Buffer() { -} +CCVKBuffer::CCVKBuffer() = default; CCVKBuffer::~CCVKBuffer() { destroy(); } -void CCVKBuffer::doInit(const BufferInfo &info) { +void CCVKBuffer::doInit(const BufferInfo & /*info*/) { _gpuBuffer = CC_NEW(CCVKGPUBuffer); _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; @@ -55,14 +53,14 @@ void CCVKBuffer::doInit(const BufferInfo &info) { _gpuBuffer->indirectCmds.resize(drawInfoCount); } - CCVKCmdFuncCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); + cmdFuncCCVKCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); _gpuBufferView = CC_NEW(CCVKGPUBufferView); createBufferView(); } void CCVKBuffer::doInit(const BufferViewInfo &info) { - CCVKBuffer *buffer = (CCVKBuffer *)info.buffer; + auto *buffer = static_cast(info.buffer); _gpuBuffer = buffer->gpuBuffer(); _gpuBufferView = CC_NEW(CCVKGPUBufferView); createBufferView(); @@ -98,7 +96,7 @@ void CCVKBuffer::doResize(uint size, uint count) { _gpuBuffer->size = size; _gpuBuffer->count = count; - CCVKCmdFuncCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); + cmdFuncCCVKCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); createBufferView(); @@ -110,7 +108,7 @@ void CCVKBuffer::doResize(uint size, uint count) { } void CCVKBuffer::update(void *buffer, uint size) { - CCVKCmdFuncUpdateBuffer(CCVKDevice::getInstance(), _gpuBuffer, buffer, size, nullptr); + cmdFuncCCVKUpdateBuffer(CCVKDevice::getInstance(), _gpuBuffer, buffer, size, nullptr); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.h b/native/cocos/renderer/gfx-vulkan/VKBuffer.h index 96ba996bfe..4b748b92d3 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXBuffer.h" namespace cc { @@ -36,9 +37,9 @@ class CCVKGPUBufferView; class CC_VULKAN_API CCVKBuffer final : public Buffer { public: CCVKBuffer(); - ~CCVKBuffer(); + ~CCVKBuffer() override; - void update(void *buffer, uint offset) override; + void update(void *buffer, uint size) override; CC_INLINE CCVKGPUBuffer *gpuBuffer() const { return _gpuBuffer; } CC_INLINE CCVKGPUBufferView *gpuBufferView() const { return _gpuBufferView; } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 26eab9bc38..6448a2d887 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -43,17 +43,13 @@ namespace cc { namespace gfx { -CCVKCommandBuffer::CCVKCommandBuffer() -: CommandBuffer() { -} - CCVKCommandBuffer::~CCVKCommandBuffer() { destroy(); } -void CCVKCommandBuffer::doInit(const CommandBufferInfo &info) { +void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) { _gpuCommandBuffer = CC_NEW(CCVKGPUCommandBuffer); - _gpuCommandBuffer->level = MapVkCommandBufferLevel(_type); + _gpuCommandBuffer->level = mapVkCommandBufferLevel(_type); _gpuCommandBuffer->queueFamilyIndex = static_cast(_queue)->gpuQueue()->queueFamilyIndex; size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().bufferOffsets.size(); @@ -78,7 +74,7 @@ void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); - _curDynamicOffsetCounts.assign(_curDynamicOffsetCounts.size(), 0u); + _curDynamicOffsetCounts.assign(_curDynamicOffsetCounts.size(), 0U); _firstDirtyDescriptorSet = UINT_MAX; _numDrawCalls = 0; @@ -94,10 +90,11 @@ void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer inheritanceInfo.subpass = subpass; if (frameBuffer) { CCVKGPUFramebuffer *gpuFBO = static_cast(frameBuffer)->gpuFBO(); - if (gpuFBO->isOffscreen) + if (gpuFBO->isOffscreen) { inheritanceInfo.framebuffer = gpuFBO->vkFramebuffer; - else + } else { inheritanceInfo.framebuffer = gpuFBO->swapchain->vkSwapchainFramebufferListMap[gpuFBO][gpuFBO->swapchain->curImageIndex]; + } } beginInfo.pInheritanceInfo = &inheritanceInfo; beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; @@ -114,7 +111,7 @@ void CCVKCommandBuffer::end() { _curGPUFBO = nullptr; _curGPUInputAssember = nullptr; - _curViewport.width = _curViewport.height = _curScissor.width = _curScissor.height = 0u; + _curViewport.width = _curViewport.height = _curScissor.width = _curScissor.height = 0U; VK_CHECK(vkEndCommandBuffer(_gpuCommandBuffer->vkCommandBuffer)); _gpuCommandBuffer->began = false; @@ -123,7 +120,7 @@ void CCVKCommandBuffer::end() { } void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, - float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { + float depth, int stencil, CommandBuffer *const * /*secondaryCBs*/, uint secondaryCBCount) { #if BARRIER_DEDUCTION_LEVEL >= BARRIER_DEDUCTION_LEVEL_BASIC // guard against RAW hazard VkMemoryBarrier vkBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; @@ -146,10 +143,10 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo size_t attachmentCount = clearValues.size(); if (attachmentCount) { - for (size_t i = 0u; i < attachmentCount - 1; ++i) { + for (size_t i = 0U; i < attachmentCount - 1; ++i) { clearValues[i].color = {{colors[i].x, colors[i].y, colors[i].z, colors[i].w}}; } - clearValues[attachmentCount - 1].depthStencil = {depth, (uint)stencil}; + clearValues[attachmentCount - 1].depthStencil = {depth, static_cast(stencil)}; } VkRenderPassBeginInfo passBeginInfo{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO}; @@ -157,12 +154,12 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo passBeginInfo.framebuffer = framebuffer; passBeginInfo.clearValueCount = clearValues.size(); passBeginInfo.pClearValues = clearValues.data(); - passBeginInfo.renderArea = {{(int)renderArea.x, (int)renderArea.y}, {renderArea.width, renderArea.height}}; + passBeginInfo.renderArea = {{renderArea.x, renderArea.y}, {renderArea.width, renderArea.height}}; vkCmdBeginRenderPass(_gpuCommandBuffer->vkCommandBuffer, &passBeginInfo, secondaryCBCount ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE); if (!secondaryCBCount) { - VkViewport viewport{(float)renderArea.x, (float)renderArea.y, (float)renderArea.width, (float)renderArea.height, 0.f, 1.f}; + VkViewport viewport{static_cast(renderArea.x), static_cast(renderArea.y), static_cast(renderArea.width), static_cast(renderArea.height), 0.F, 1.F}; vkCmdSetViewport(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &viewport); vkCmdSetScissor(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &passBeginInfo.renderArea); } @@ -172,7 +169,7 @@ void CCVKCommandBuffer::endRenderPass() { vkCmdEndRenderPass(_gpuCommandBuffer->vkCommandBuffer); size_t colorAttachmentCount = _curGPUFBO->gpuRenderPass->colorAttachments.size(); - for (size_t i = 0u; i < colorAttachmentCount; ++i) { + for (size_t i = 0U; i < colorAttachmentCount; ++i) { if (_curGPUFBO->gpuColorViews[i]) { _curGPUFBO->gpuColorViews[i]->gpuTexture->currentAccessTypes = _curGPUFBO->gpuRenderPass->endAccesses[i]; } else { @@ -202,7 +199,7 @@ void CCVKCommandBuffer::bindPipelineState(PipelineState *pso) { CCVKGPUPipelineState *gpuPipelineState = static_cast(pso)->gpuPipelineState(); if (_curGPUPipelineState != gpuPipelineState) { - vkCmdBindPipeline(_gpuCommandBuffer->vkCommandBuffer, VK_PIPELINE_BIND_POINTS[(uint)gpuPipelineState->bindPoint], gpuPipelineState->vkPipeline); + vkCmdBindPipeline(_gpuCommandBuffer->vkCommandBuffer, VK_PIPELINE_BIND_POINTS[static_cast(gpuPipelineState->bindPoint)], gpuPipelineState->vkPipeline); _curGPUPipelineState = gpuPipelineState; } } @@ -234,7 +231,7 @@ void CCVKCommandBuffer::bindInputAssembler(InputAssembler *ia) { gpuInputAssembler->vertexBufferOffsets.resize(vbCount); } - for (size_t i = 0u; i < vbCount; ++i) { + for (size_t i = 0U; i < vbCount; ++i) { gpuInputAssembler->vertexBuffers[i] = gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; gpuInputAssembler->vertexBufferOffsets[i] = gpuInputAssembler->gpuVertexBuffers[i]->startOffset; } @@ -254,7 +251,7 @@ void CCVKCommandBuffer::setViewport(const Viewport &vp) { if (_curViewport != vp) { _curViewport = vp; - VkViewport viewport{(float)vp.left, (float)vp.top, (float)vp.width, (float)vp.height, vp.minDepth, vp.maxDepth}; + VkViewport viewport{static_cast(vp.left), static_cast(vp.top), static_cast(vp.width), static_cast(vp.height), vp.minDepth, vp.maxDepth}; vkCmdSetViewport(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &viewport); } } @@ -263,7 +260,7 @@ void CCVKCommandBuffer::setScissor(const Rect &rect) { if (_curScissor != rect) { _curScissor = rect; - VkRect2D scissor = {{(int)rect.x, (int)rect.y}, {rect.width, rect.height}}; + VkRect2D scissor = {{rect.x, rect.y}, {rect.width, rect.height}}; vkCmdSetScissor(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &scissor); } } @@ -332,15 +329,12 @@ void CCVKCommandBuffer::setStencilCompareMask(StencilFace face, int reference, u } } -void CCVKCommandBuffer::draw(InputAssembler *ia) { +void CCVKCommandBuffer::draw(const DrawInfo &info) { if (_firstDirtyDescriptorSet < _curGPUDescriptorSets.size()) { bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS); } - CCVKGPUInputAssembler *gpuInputAssembler = static_cast(ia)->gpuInputAssembler(); - CCVKGPUBuffer * gpuIndirectBuffer = gpuInputAssembler->gpuIndirectBuffer; - - DrawInfo drawInfo; + CCVKGPUBuffer *gpuIndirectBuffer = _curGPUInputAssember->gpuIndirectBuffer; if (gpuIndirectBuffer) { uint drawInfoCount = gpuIndirectBuffer->count; @@ -362,7 +356,7 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) { } } else { if (gpuIndirectBuffer->isDrawIndirectByIndex) { - for (VkDeviceSize j = 0u; j < drawInfoCount; ++j) { + for (VkDeviceSize j = 0U; j < drawInfoCount; ++j) { vkCmdDrawIndexedIndirect(_gpuCommandBuffer->vkCommandBuffer, gpuIndirectBuffer->vkBuffer, offset + j * sizeof(VkDrawIndexedIndirectCommand), @@ -370,7 +364,7 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) { sizeof(VkDrawIndexedIndirectCommand)); } } else { - for (VkDeviceSize j = 0u; j < drawInfoCount; ++j) { + for (VkDeviceSize j = 0U; j < drawInfoCount; ++j) { vkCmdDrawIndirect(_gpuCommandBuffer->vkCommandBuffer, gpuIndirectBuffer->vkBuffer, offset + j * sizeof(VkDrawIndirectCommand), @@ -380,22 +374,21 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) { } } } else { - static_cast(ia)->extractDrawInfo(drawInfo); - uint instanceCount = std::max(drawInfo.instanceCount, 1u); - bool hasIndexBuffer = gpuInputAssembler->gpuIndexBuffer && drawInfo.indexCount > 0; + uint instanceCount = std::max(info.instanceCount, 1U); + bool hasIndexBuffer = _curGPUInputAssember->gpuIndexBuffer && info.indexCount > 0; if (hasIndexBuffer) { - vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, drawInfo.indexCount, instanceCount, - drawInfo.firstIndex, drawInfo.vertexOffset, drawInfo.firstInstance); + vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, info.indexCount, instanceCount, + info.firstIndex, info.vertexOffset, info.firstInstance); } else { - vkCmdDraw(_gpuCommandBuffer->vkCommandBuffer, drawInfo.vertexCount, instanceCount, - drawInfo.firstVertex, drawInfo.firstInstance); + vkCmdDraw(_gpuCommandBuffer->vkCommandBuffer, info.vertexCount, instanceCount, + info.firstVertex, info.firstInstance); } ++_numDrawCalls; - _numInstances += drawInfo.instanceCount; + _numInstances += info.instanceCount; if (_curGPUPipelineState) { - uint indexCount = hasIndexBuffer ? drawInfo.indexCount : drawInfo.vertexCount; + uint indexCount = hasIndexBuffer ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->primitive) { case PrimitiveMode::TRIANGLE_LIST: _numTriangles += indexCount / 3 * instanceCount; @@ -414,9 +407,9 @@ void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint count) { if (!count) return; _vkCommandBuffers.resize(count); - uint validCount = 0u; - for (uint i = 0u; i < count; ++i) { - CCVKCommandBuffer *cmdBuff = (CCVKCommandBuffer *)cmdBuffs[i]; + uint validCount = 0U; + for (uint i = 0U; i < count; ++i) { + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingQueue.empty()) { _vkCommandBuffers[validCount++] = cmdBuff->_pendingQueue.front(); cmdBuff->_pendingQueue.pop(); @@ -434,11 +427,11 @@ void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint count) { void CCVKCommandBuffer::updateBuffer(Buffer *buffer, const void *data, uint size) { CCVKGPUBuffer *gpuBuffer = static_cast(buffer)->gpuBuffer(); - CCVKCmdFuncUpdateBuffer(CCVKDevice::getInstance(), gpuBuffer, data, size, _gpuCommandBuffer); + cmdFuncCCVKUpdateBuffer(CCVKDevice::getInstance(), gpuBuffer, data, size, _gpuCommandBuffer); } void CCVKCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { - CCVKCmdFuncCopyBuffersToTexture(CCVKDevice::getInstance(), buffers, static_cast(texture)->gpuTexture(), regions, count, _gpuCommandBuffer); + cmdFuncCCVKCopyBuffersToTexture(CCVKDevice::getInstance(), buffers, static_cast(texture)->gpuTexture(), regions, count, _gpuCommandBuffer); } void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { @@ -469,7 +462,7 @@ void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, co } _blitRegions.resize(count); - for (uint i = 0u; i < count; ++i) { + for (uint i = 0U; i < count; ++i) { const TextureBlit ®ion = regions[i]; _blitRegions[i].srcSubresource.aspectMask = srcAspectMask; _blitRegions[i].srcSubresource.mipLevel = region.srcSubres.mipLevel; @@ -497,7 +490,7 @@ void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, co vkCmdBlitImage(_gpuCommandBuffer->vkCommandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, - count, _blitRegions.data(), VK_FILTERS[(uint)filter]); + count, _blitRegions.data(), VK_FILTERS[static_cast(filter)]); } void CCVKCommandBuffer::bindDescriptorSets(VkPipelineBindPoint bindPoint) { @@ -540,7 +533,7 @@ void CCVKCommandBuffer::dispatch(const DispatchInfo &info) { } if (info.indirectBuffer) { - CCVKBuffer *indirectBuffer = (CCVKBuffer *)info.indirectBuffer; + auto *indirectBuffer = static_cast(info.indirectBuffer); vkCmdDispatchIndirect(_gpuCommandBuffer->vkCommandBuffer, indirectBuffer->gpuBuffer()->vkBuffer, indirectBuffer->gpuBuffer()->startOffset + indirectBuffer->gpuBufferView()->offset + info.indirectOffset); } else { @@ -552,27 +545,27 @@ void CCVKCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const Text VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkMemoryBarrier const * pMemoryBarrier = nullptr; - uint memoryBarrierCount = 0u; + uint memoryBarrierCount = 0U; VkImageMemoryBarrier const *pImageMemoryBarriers = nullptr; if (barrier) { - auto gpuBarrier = static_cast(barrier)->gpuBarrier(); + const auto *gpuBarrier = static_cast(barrier)->gpuBarrier(); srcStageMask |= gpuBarrier->srcStageMask; dstStageMask |= gpuBarrier->dstStageMask; pMemoryBarrier = &gpuBarrier->vkBarrier; - memoryBarrierCount = 1u; + memoryBarrierCount = 1U; } if (textureBarrierCount > 0) { _imageMemoryBarriers.resize(textureBarrierCount); pImageMemoryBarriers = _imageMemoryBarriers.data(); - for (uint i = 0u; i < textureBarrierCount; ++i) { - auto gpuBarrier = static_cast(textureBarriers[i])->gpuBarrier(); + for (uint i = 0U; i < textureBarrierCount; ++i) { + const auto *gpuBarrier = static_cast(textureBarriers[i])->gpuBarrier(); _imageMemoryBarriers[i] = gpuBarrier->vkBarrier; if (textures[i]) { - auto gpuTexture = static_cast(textures[i])->gpuTexture(); + auto *gpuTexture = static_cast(textures[i])->gpuTexture(); _imageMemoryBarriers[i].image = gpuTexture->vkImage; _imageMemoryBarriers[i].subresourceRange.aspectMask = gpuTexture->aspectMask; gpuTexture->currentAccessTypes.assign(gpuBarrier->barrier.pNextAccesses, gpuBarrier->barrier.pNextAccesses + gpuBarrier->barrier.nextAccessCount); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index b0de93f42a..63c8068104 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -34,8 +34,8 @@ namespace gfx { class CC_VULKAN_API CCVKCommandBuffer final : public CommandBuffer { public: - CCVKCommandBuffer(); - ~CCVKCommandBuffer(); + CCVKCommandBuffer() = default; + ~CCVKCommandBuffer() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; @@ -52,7 +52,7 @@ public: void setDepthBound(float minBounds, float maxBounds) override; void setStencilWriteMask(StencilFace face, uint mask) override; void setStencilCompareMask(StencilFace face, int reference, uint mask) override; - void draw(InputAssembler *ia) override; + void draw(const DrawInfo &info) override; void updateBuffer(Buffer *buffer, const void *data, uint size) override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; @@ -85,7 +85,7 @@ protected: Viewport _curViewport; Rect _curScissor; - float _curLineWidth = 1.0f; + float _curLineWidth = 1.0F; CCVKDepthBias _curDepthBias; Color _curBlendConstants; CCVKDepthBounds _curDepthBounds; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 9bc41ccdcc..0c5a3e9fb9 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -52,19 +52,19 @@ CCVKGPUDescriptorSetPool *CCVKGPUDevice::getDescriptorSetPool(uint layoutID) { return &_descriptorSetPools[layoutID]; } -void insertVkDynamicStates(vector &out, const vector &dynamicStates) { +void insertVkDynamicStates(vector *out, const vector &dynamicStates) { for (DynamicStateFlagBit dynamicState : dynamicStates) { switch (dynamicState) { - case DynamicStateFlagBit::VIEWPORT: break; // we make this dynamic by default + case DynamicStateFlagBit::VIEWPORT: case DynamicStateFlagBit::SCISSOR: break; // we make this dynamic by default - case DynamicStateFlagBit::LINE_WIDTH: out.push_back(VK_DYNAMIC_STATE_LINE_WIDTH); break; - case DynamicStateFlagBit::DEPTH_BIAS: out.push_back(VK_DYNAMIC_STATE_DEPTH_BIAS); break; - case DynamicStateFlagBit::BLEND_CONSTANTS: out.push_back(VK_DYNAMIC_STATE_BLEND_CONSTANTS); break; - case DynamicStateFlagBit::DEPTH_BOUNDS: out.push_back(VK_DYNAMIC_STATE_DEPTH_BOUNDS); break; - case DynamicStateFlagBit::STENCIL_WRITE_MASK: out.push_back(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); break; + case DynamicStateFlagBit::LINE_WIDTH: out->push_back(VK_DYNAMIC_STATE_LINE_WIDTH); break; + case DynamicStateFlagBit::DEPTH_BIAS: out->push_back(VK_DYNAMIC_STATE_DEPTH_BIAS); break; + case DynamicStateFlagBit::BLEND_CONSTANTS: out->push_back(VK_DYNAMIC_STATE_BLEND_CONSTANTS); break; + case DynamicStateFlagBit::DEPTH_BOUNDS: out->push_back(VK_DYNAMIC_STATE_DEPTH_BOUNDS); break; + case DynamicStateFlagBit::STENCIL_WRITE_MASK: out->push_back(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); break; case DynamicStateFlagBit::STENCIL_COMPARE_MASK: - out.push_back(VK_DYNAMIC_STATE_STENCIL_REFERENCE); - out.push_back(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); + out->push_back(VK_DYNAMIC_STATE_STENCIL_REFERENCE); + out->push_back(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); break; default: { CCASSERT(false, "Unsupported DynamicStateFlagBit, convert to VkDynamicState failed."); @@ -74,8 +74,8 @@ void insertVkDynamicStates(vector &out, const vectortype) { case QueueType::GRAPHICS: @@ -89,7 +89,7 @@ void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) { const CCVKGPUContext *context = device->gpuContext(); size_t queueCount = context->queueFamilyProperties.size(); - for (size_t i = 0u; i < queueCount; ++i) { + for (size_t i = 0U; i < queueCount; ++i) { const VkQueueFamilyProperties &properties = context->queueFamilyProperties[i]; const VkBool32 isPresentable = context->queueFamilyPresentables[i]; if (properties.queueCount > 0 && (properties.queueFlags & queueType) && (!needPresentable || isPresentable)) { @@ -100,32 +100,32 @@ void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) { } } -void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { +void cmdFuncCCVKCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { if (!gpuTexture->size) return; - VkFormat format = MapVkFormat(gpuTexture->format); - VkFormatFeatureFlags features = MapVkFormatFeatureFlags(gpuTexture->usage); + VkFormat format = mapVkFormat(gpuTexture->format); + VkFormatFeatureFlags features = mapVkFormatFeatureFlags(gpuTexture->usage); VkFormatProperties formatProperties; vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, format, &formatProperties); if (!(formatProperties.optimalTilingFeatures & features)) { - const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str(); - CC_LOG_ERROR("CCVKCmdFuncCreateTexture: The specified usage for %s is not supported on this platform", formatName); + const char *formatName = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].name.c_str(); + CC_LOG_ERROR("cmdFuncCCVKCreateTexture: The specified usage for %s is not supported on this platform", formatName); return; } - VkImageUsageFlags usageFlags = MapVkImageUsageFlagBits(gpuTexture->usage); + VkImageUsageFlags usageFlags = mapVkImageUsageFlagBits(gpuTexture->usage); if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) { usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; } VkImageCreateInfo createInfo{VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO}; - createInfo.flags = MapVkImageCreateFlags(gpuTexture->type); - createInfo.imageType = MapVkImageType(gpuTexture->type); + createInfo.flags = mapVkImageCreateFlags(gpuTexture->type); + createInfo.imageType = mapVkImageType(gpuTexture->type); createInfo.format = format; createInfo.extent = {gpuTexture->width, gpuTexture->height, gpuTexture->depth}; createInfo.mipLevels = gpuTexture->mipLevels; createInfo.arrayLayers = gpuTexture->arrayLayers; - createInfo.samples = MapVkSampleCount(gpuTexture->samples); + createInfo.samples = mapVkSampleCount(gpuTexture->samples); createInfo.tiling = VK_IMAGE_TILING_OPTIMAL; createInfo.usage = usageFlags; createInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; @@ -137,17 +137,17 @@ void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { VK_CHECK(vmaCreateImage(device->gpuDevice()->memoryAllocator, &createInfo, &allocInfo, &gpuTexture->vkImage, &gpuTexture->vmaAllocation, &res)); //CC_LOG_DEBUG("Allocated texture: %llu %llx %llx %llu %x", res.size, gpuTexture->vkImage, res.deviceMemory, res.offset, res.pMappedData); - gpuTexture->aspectMask = MapVkImageAspectFlags(gpuTexture->format); + gpuTexture->aspectMask = mapVkImageAspectFlags(gpuTexture->format); } -void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) { +void cmdFuncCCVKCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) { if (!gpuTextureView->gpuTexture || !gpuTextureView->gpuTexture->vkImage) return; VkImageViewCreateInfo createInfo{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO}; createInfo.image = gpuTextureView->gpuTexture->vkImage; - createInfo.viewType = MapVkImageViewType(gpuTextureView->type); - createInfo.format = MapVkFormat(gpuTextureView->format); - createInfo.subresourceRange.aspectMask = GFX_FORMAT_INFOS[(uint)gpuTextureView->format].hasDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; + createInfo.viewType = mapVkImageViewType(gpuTextureView->type); + createInfo.format = mapVkFormat(gpuTextureView->format); + createInfo.subresourceRange.aspectMask = GFX_FORMAT_INFOS[static_cast(gpuTextureView->format)].hasDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; createInfo.subresourceRange.baseMipLevel = gpuTextureView->baseLevel; createInfo.subresourceRange.levelCount = gpuTextureView->levelCount; createInfo.subresourceRange.baseArrayLayer = gpuTextureView->baseLayer; @@ -158,21 +158,21 @@ void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTex device->gpuDescriptorHub()->update(gpuTextureView); } -void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { +void cmdFuncCCVKCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { VkSamplerCreateInfo createInfo{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; CCVKGPUContext * context = device->gpuContext(); - createInfo.magFilter = VK_FILTERS[(uint)gpuSampler->magFilter]; - createInfo.minFilter = VK_FILTERS[(uint)gpuSampler->minFilter]; - createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODES[(uint)gpuSampler->mipFilter]; - createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODES[(uint)gpuSampler->addressU]; - createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODES[(uint)gpuSampler->addressV]; - createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODES[(uint)gpuSampler->addressW]; + createInfo.magFilter = VK_FILTERS[static_cast(gpuSampler->magFilter)]; + createInfo.minFilter = VK_FILTERS[static_cast(gpuSampler->minFilter)]; + createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODES[static_cast(gpuSampler->mipFilter)]; + createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODES[static_cast(gpuSampler->addressU)]; + createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODES[static_cast(gpuSampler->addressV)]; + createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODES[static_cast(gpuSampler->addressW)]; createInfo.mipLodBias = gpuSampler->mipLODBias; createInfo.anisotropyEnable = gpuSampler->maxAnisotropy && context->physicalDeviceFeatures.samplerAnisotropy; - createInfo.maxAnisotropy = std::min(context->physicalDeviceProperties.limits.maxSamplerAnisotropy, (float)gpuSampler->maxAnisotropy); + createInfo.maxAnisotropy = std::min(context->physicalDeviceProperties.limits.maxSamplerAnisotropy, static_cast(gpuSampler->maxAnisotropy)); createInfo.compareEnable = gpuSampler->cmpFunc != ComparisonFunc::ALWAYS; - createInfo.compareOp = VK_CMP_FUNCS[(uint)gpuSampler->cmpFunc]; + createInfo.compareOp = VK_CMP_FUNCS[static_cast(gpuSampler->cmpFunc)]; createInfo.minLod = 0.0; // UNASSIGNED-BestPractices-vkCreateSampler-lod-clamping createInfo.maxLod = VK_LOD_CLAMP_NONE; // UNASSIGNED-BestPractices-vkCreateSampler-lod-clamping //createInfo.borderColor; // TODO @@ -180,16 +180,16 @@ void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { VK_CHECK(vkCreateSampler(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuSampler->vkSampler)); } -void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { +void cmdFuncCCVKCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { if (!gpuBuffer->size) { return; } - gpuBuffer->instanceSize = 0u; + gpuBuffer->instanceSize = 0U; VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; bufferInfo.size = gpuBuffer->size; - bufferInfo.usage = MapVkBufferUsageFlagBits(gpuBuffer->usage); + bufferInfo.usage = mapVkBufferUsageFlagBits(gpuBuffer->usage); VmaAllocationCreateInfo allocInfo{}; @@ -225,7 +225,7 @@ void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { if (gpuBuffer->usage & BufferUsageBit::INDIRECT) gpuBuffer->renderAccessTypes.push_back(THSVS_ACCESS_INDIRECT_BUFFER); } -void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { +void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { static vector attachmentDescriptions; static vector subpassDescriptions; static vector attachmentReferences; @@ -240,7 +240,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende vector beginAccessInfos(colorAttachmentCount + hasDepth); vector endAccessInfos(colorAttachmentCount + hasDepth); - for (size_t i = 0u; i < colorAttachmentCount; ++i) { + for (size_t i = 0U; i < colorAttachmentCount; ++i) { const ColorAttachment &attachment = gpuRenderPass->colorAttachments[i]; vector &beginAccesses = gpuRenderPass->beginAccesses[i]; @@ -249,18 +249,18 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende CCVKAccessInfo & endAccessInfo = endAccessInfos[i]; for (AccessType type : attachment.beginAccesses) { - beginAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]); + beginAccesses.push_back(THSVS_ACCESS_TYPES[static_cast(type)]); } for (AccessType type : attachment.endAccesses) { - endAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]); + endAccesses.push_back(THSVS_ACCESS_TYPES[static_cast(type)]); } thsvsGetAccessInfo(beginAccesses.size(), beginAccesses.data(), &beginAccessInfo.stageMask, &beginAccessInfo.accessMask, &beginAccessInfo.imageLayout, &beginAccessInfo.hasWriteAccess); thsvsGetAccessInfo(endAccesses.size(), endAccesses.data(), &endAccessInfo.stageMask, &endAccessInfo.accessMask, &endAccessInfo.imageLayout, &endAccessInfo.hasWriteAccess); - attachmentDescriptions[i].format = MapVkFormat(attachment.format); - attachmentDescriptions[i].samples = MapVkSampleCount(attachment.sampleCount); - attachmentDescriptions[i].loadOp = MapVkLoadOp(attachment.loadOp); - attachmentDescriptions[i].storeOp = MapVkStoreOp(attachment.storeOp); + attachmentDescriptions[i].format = mapVkFormat(attachment.format); + attachmentDescriptions[i].samples = mapVkSampleCount(attachment.sampleCount); + attachmentDescriptions[i].loadOp = mapVkLoadOp(attachment.loadOp); + attachmentDescriptions[i].storeOp = mapVkStoreOp(attachment.storeOp); attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; attachmentDescriptions[i].initialLayout = beginAccessInfo.imageLayout; @@ -275,20 +275,20 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende CCVKAccessInfo & endAccessInfo = endAccessInfos[colorAttachmentCount]; for (AccessType type : depthStencilAttachment.beginAccesses) { - beginAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]); + beginAccesses.push_back(THSVS_ACCESS_TYPES[static_cast(type)]); } for (AccessType type : depthStencilAttachment.endAccesses) { - endAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]); + endAccesses.push_back(THSVS_ACCESS_TYPES[static_cast(type)]); } thsvsGetAccessInfo(beginAccesses.size(), beginAccesses.data(), &beginAccessInfo.stageMask, &beginAccessInfo.accessMask, &beginAccessInfo.imageLayout, &beginAccessInfo.hasWriteAccess); thsvsGetAccessInfo(endAccesses.size(), endAccesses.data(), &endAccessInfo.stageMask, &endAccessInfo.accessMask, &endAccessInfo.imageLayout, &endAccessInfo.hasWriteAccess); - attachmentDescriptions[colorAttachmentCount].format = MapVkFormat(depthStencilAttachment.format); - attachmentDescriptions[colorAttachmentCount].samples = MapVkSampleCount(depthStencilAttachment.sampleCount); - attachmentDescriptions[colorAttachmentCount].loadOp = MapVkLoadOp(depthStencilAttachment.depthLoadOp); - attachmentDescriptions[colorAttachmentCount].storeOp = MapVkStoreOp(depthStencilAttachment.depthStoreOp); - attachmentDescriptions[colorAttachmentCount].stencilLoadOp = MapVkLoadOp(depthStencilAttachment.stencilLoadOp); - attachmentDescriptions[colorAttachmentCount].stencilStoreOp = MapVkStoreOp(depthStencilAttachment.stencilStoreOp); + attachmentDescriptions[colorAttachmentCount].format = mapVkFormat(depthStencilAttachment.format); + attachmentDescriptions[colorAttachmentCount].samples = mapVkSampleCount(depthStencilAttachment.sampleCount); + attachmentDescriptions[colorAttachmentCount].loadOp = mapVkLoadOp(depthStencilAttachment.depthLoadOp); + attachmentDescriptions[colorAttachmentCount].storeOp = mapVkStoreOp(depthStencilAttachment.depthStoreOp); + attachmentDescriptions[colorAttachmentCount].stencilLoadOp = mapVkLoadOp(depthStencilAttachment.stencilLoadOp); + attachmentDescriptions[colorAttachmentCount].stencilStoreOp = mapVkStoreOp(depthStencilAttachment.stencilStoreOp); attachmentDescriptions[colorAttachmentCount].initialLayout = beginAccessInfo.imageLayout; attachmentDescriptions[colorAttachmentCount].finalLayout = endAccessInfo.imageLayout; } @@ -299,18 +299,18 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende if (subpassCount) { // pass on user-specified subpasses subpassDescriptions.resize(subpassCount, {}); - // TODO + // TODO(YunHsiao): //for (size_t i = 0u; i < subpassCount; ++i) { // const SubPassInfo &subPassInfo = gpuRenderPass->subPasses[i]; // subpassDescriptions[i].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; //} } else { // generate a default subpass from attachment info - subpassCount = 1u; + subpassCount = 1U; subpassDescriptions.resize(subpassCount, {}); - for (size_t i = 0u; i < colorAttachmentCount; ++i) { - attachmentReferences.push_back({(uint32_t)i, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}); + for (size_t i = 0U; i < colorAttachmentCount; ++i) { + attachmentReferences.push_back({static_cast(i), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}); } - attachmentReferences.push_back({(uint32_t)colorAttachmentCount, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL}); + attachmentReferences.push_back({static_cast(colorAttachmentCount), VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL}); subpassDescriptions[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpassDescriptions[0].colorAttachmentCount = attachmentReferences.size() - 1; subpassDescriptions[0].pColorAttachments = attachmentReferences.data(); @@ -336,7 +336,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende } }; VkSubpassDescription &firstSubpass = subpassDescriptions[0]; - for (size_t j = 0u; j < firstSubpass.colorAttachmentCount; ++j) { + for (size_t j = 0U; j < firstSubpass.colorAttachmentCount; ++j) { beginDependencyCheck(firstSubpass.pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); } @@ -349,7 +349,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende } // make rendering result visible for the specified access types - VkSubpassDependency endDependency{(uint)subpassCount - 1, VK_SUBPASS_EXTERNAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; + VkSubpassDependency endDependency{static_cast(subpassCount) - 1, VK_SUBPASS_EXTERNAL, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; auto endDependencyCheck = [&endDependency, &endAccessInfos](const VkAttachmentReference &ref, VkPipelineStageFlags srcStage, VkAccessFlags srcAccess) { const VkAttachmentDescription &desc = attachmentDescriptions[ref.attachment]; if (desc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) { @@ -361,7 +361,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende } }; VkSubpassDescription &lastSubpass = subpassDescriptions[subpassCount - 1]; - for (size_t j = 0u; j < lastSubpass.colorAttachmentCount; ++j) { + for (size_t j = 0U; j < lastSubpass.colorAttachmentCount; ++j) { endDependencyCheck(lastSubpass.pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); } if (lastSubpass.pDepthStencilAttachment) { @@ -382,14 +382,14 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende VK_CHECK(vkCreateRenderPass(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass)); } -void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) { +void cmdFuncCCVKCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) { size_t colorViewCount = gpuFramebuffer->gpuColorViews.size(); bool depthSpecified = gpuFramebuffer->gpuDepthStencilView; bool hasDepth = gpuFramebuffer->gpuRenderPass->depthStencilAttachment.format == device->getDepthStencilFormat(); vector attachments(colorViewCount + (depthSpecified || hasDepth ? 1 : 0)); uint swapchainImageIndices = 0; CCVKGPUTexture * gpuTexture = nullptr; - for (size_t i = 0u; i < colorViewCount; ++i) { + for (size_t i = 0U; i < colorViewCount; ++i) { CCVKGPUTextureView *texView = gpuFramebuffer->gpuColorViews[i]; if (texView) { gpuTexture = gpuFramebuffer->gpuColorViews[i]->gpuTexture; @@ -419,9 +419,9 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra // swapchain-related framebuffers need special treatments: rebuild is needed // whenever a user-specified attachment or swapchain itself is changed - gpuFramebuffer->swapchain = device->gpuSwapchain(); - FramebufferListMap & fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; - auto fboListMapIter = fboListMap.find(gpuFramebuffer); + gpuFramebuffer->swapchain = device->gpuSwapchain(); + FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; + auto fboListMapIter = fboListMap.find(gpuFramebuffer); if (fboListMapIter != fboListMap.end() && !fboListMapIter->second.empty()) { return; } @@ -438,8 +438,8 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra createInfo.width = device->getWidth(); createInfo.height = device->getHeight(); createInfo.layers = 1; - for (size_t i = 0u; i < swapchainImageCount; ++i) { - for (size_t j = 0u; j < colorViewCount; ++j) { + for (size_t i = 0U; i < swapchainImageCount; ++i) { + for (size_t j = 0U; j < colorViewCount; ++j) { if (swapchainImageIndices & (1 << j)) { attachments[j] = gpuFramebuffer->swapchain->vkSwapchainImageViews[i]; } @@ -452,7 +452,7 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra } } -void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { +void cmdFuncCCVKCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, device->gpuDevice()->minorVersion); VkShaderModuleCreateInfo createInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; @@ -463,16 +463,16 @@ void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { CC_LOG_INFO("Shader '%s' compilation succeeded.", gpuShader->name.c_str()); } -void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { +void cmdFuncCCVKCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { CCVKGPUDevice *gpuDevice = device->gpuDevice(); size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); gpuDescriptorSetLayout->vkBindings.resize(bindingCount); - for (size_t i = 0u; i < bindingCount; ++i) { + for (size_t i = 0U; i < bindingCount; ++i) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; VkDescriptorSetLayoutBinding & vkBinding = gpuDescriptorSetLayout->vkBindings[i]; - vkBinding.stageFlags = MapVkShaderStageFlags(binding.stageFlags); - vkBinding.descriptorType = MapVkDescriptorType(binding.descriptorType); + vkBinding.stageFlags = mapVkShaderStageFlags(binding.stageFlags); + vkBinding.descriptorType = mapVkDescriptorType(binding.descriptorType); vkBinding.binding = binding.binding; vkBinding.descriptorCount = binding.count; } @@ -491,7 +491,7 @@ void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorS const vector &bindings = gpuDescriptorSetLayout->vkBindings; vector entries(bindingCount); - for (size_t j = 0u, k = 0u; j < bindingCount; ++j) { + for (size_t j = 0U, k = 0U; j < bindingCount; ++j) { const VkDescriptorSetLayoutBinding &binding = bindings[j]; if (binding.descriptorType != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { entries[j].dstBinding = binding.binding; @@ -501,7 +501,7 @@ void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorS entries[j].offset = sizeof(CCVKDescriptorInfo) * k; entries[j].stride = sizeof(CCVKDescriptorInfo); k += binding.descriptorCount; - } // TODO: inline UBOs + } // TODO(YunHsiao): inline UBOs } VkDescriptorUpdateTemplateCreateInfo createInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO}; @@ -517,7 +517,7 @@ void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorS } } -void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout) { +void cmdFuncCCVKCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout) { CCVKGPUDevice *gpuDevice = device->gpuDevice(); size_t layoutCount = gpuPipelineLayout->setLayouts.size(); @@ -532,14 +532,14 @@ void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout * VK_CHECK(vkCreatePipelineLayout(gpuDevice->vkDevice, &pipelineLayoutCreateInfo, nullptr, &gpuPipelineLayout->vkPipelineLayout)); } -void CCVKCmdFuncCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { +void cmdFuncCCVKCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { VkComputePipelineCreateInfo createInfo{VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; ///////////////////// Shader Stage ///////////////////// const CCVKGPUShaderStageList & stages = gpuPipelineState->gpuShader->gpuStages; VkPipelineShaderStageCreateInfo stageInfo{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; - stageInfo.stage = MapVkShaderStageFlagBits(stages[0].type); + stageInfo.stage = mapVkShaderStageFlagBits(stages[0].type); stageInfo.module = stages[0].vkShader; stageInfo.pName = "main"; @@ -552,7 +552,7 @@ void CCVKCmdFuncCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineSt 1, &createInfo, nullptr, &gpuPipelineState->vkPipeline)); } -void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { +void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { VkGraphicsPipelineCreateInfo createInfo{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; ///////////////////// Shader Stage ///////////////////// @@ -560,8 +560,8 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS const CCVKGPUShaderStageList & stages = gpuPipelineState->gpuShader->gpuStages; const size_t stageCount = stages.size(); vector stageInfos(stageCount, {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}); - for (size_t i = 0u; i < stageCount; ++i) { - stageInfos[i].stage = MapVkShaderStageFlagBits(stages[i].type); + for (size_t i = 0U; i < stageCount; ++i) { + stageInfos[i].stage = mapVkShaderStageFlagBits(stages[i].type); stageInfos[i].module = stages[i].vkShader; stageInfos[i].pName = "main"; } @@ -572,21 +572,21 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS const AttributeList &attributes = gpuPipelineState->inputState.attributes; const size_t attributeCount = attributes.size(); - size_t bindingCount = 1u; - for (size_t i = 0u; i < attributeCount; ++i) { + size_t bindingCount = 1U; + for (size_t i = 0U; i < attributeCount; ++i) { const Attribute &attr = attributes[i]; - bindingCount = std::max((size_t)bindingCount, (size_t)(attr.stream + 1)); + bindingCount = std::max(bindingCount, static_cast(attr.stream + 1)); } vector bindingDescriptions(bindingCount); - for (size_t i = 0u; i < bindingCount; ++i) { + for (size_t i = 0U; i < bindingCount; ++i) { bindingDescriptions[i].binding = i; bindingDescriptions[i].stride = 0; bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; } - for (size_t i = 0u; i < attributeCount; ++i) { + for (size_t i = 0U; i < attributeCount; ++i) { const Attribute &attr = attributes[i]; - bindingDescriptions[attr.stream].stride += GFX_FORMAT_INFOS[(uint)attr.format].size; + bindingDescriptions[attr.stream].stride += GFX_FORMAT_INFOS[static_cast(attr.format)].size; if (attr.isInstanced) { bindingDescriptions[attr.stream].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE; } @@ -604,17 +604,17 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS if (shaderAttrs[i].name == attr.name) { attributeDescriptions[i].location = shaderAttrs[i].location; attributeDescriptions[i].binding = attr.stream; - attributeDescriptions[i].format = MapVkFormat(attr.format); + attributeDescriptions[i].format = mapVkFormat(attr.format); attributeDescriptions[i].offset = offsets[attr.stream]; attributeFound = true; break; } - offsets[attr.stream] += GFX_FORMAT_INFOS[(uint)attr.format].size; + offsets[attr.stream] += GFX_FORMAT_INFOS[static_cast(attr.format)].size; } if (!attributeFound) { // handle absent attribute attributeDescriptions[i].location = shaderAttrs[i].location; attributeDescriptions[i].binding = 0; - attributeDescriptions[i].format = MapVkFormat(shaderAttrs[i].format); + attributeDescriptions[i].format = mapVkFormat(shaderAttrs[i].format); attributeDescriptions[i].offset = 0; // reuse the first attribute as dummy data } } @@ -629,13 +629,13 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS ///////////////////// Input Asembly State ///////////////////// VkPipelineInputAssemblyStateCreateInfo inputAssembly{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO}; - inputAssembly.topology = VK_PRIMITIVE_MODES[(uint)gpuPipelineState->primitive]; + inputAssembly.topology = VK_PRIMITIVE_MODES[static_cast(gpuPipelineState->primitive)]; createInfo.pInputAssemblyState = &inputAssembly; ///////////////////// Dynamic State ///////////////////// vector dynamicStates{VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; - insertVkDynamicStates(dynamicStates, gpuPipelineState->dynamicStates); + insertVkDynamicStates(&dynamicStates, gpuPipelineState->dynamicStates); VkPipelineDynamicStateCreateInfo dynamicState{VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO}; dynamicState.dynamicStateCount = dynamicStates.size(); @@ -655,8 +655,8 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS //rasterizationState.depthClampEnable; rasterizationState.rasterizerDiscardEnable = gpuPipelineState->rs.isDiscard; - rasterizationState.polygonMode = VK_POLYGON_MODES[(uint)gpuPipelineState->rs.polygonMode]; - rasterizationState.cullMode = VK_CULL_MODES[(uint)gpuPipelineState->rs.cullMode]; + rasterizationState.polygonMode = VK_POLYGON_MODES[static_cast(gpuPipelineState->rs.polygonMode)]; + rasterizationState.cullMode = VK_CULL_MODES[static_cast(gpuPipelineState->rs.cullMode)]; rasterizationState.frontFace = gpuPipelineState->rs.isFrontFaceCCW ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; rasterizationState.depthBiasEnable = gpuPipelineState->rs.depthBiasEnabled; rasterizationState.depthBiasConstantFactor = gpuPipelineState->rs.depthBias; @@ -681,23 +681,23 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS VkPipelineDepthStencilStateCreateInfo depthStencilState = {VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO}; depthStencilState.depthTestEnable = gpuPipelineState->dss.depthTest; depthStencilState.depthWriteEnable = gpuPipelineState->dss.depthWrite; - depthStencilState.depthCompareOp = VK_CMP_FUNCS[(uint)gpuPipelineState->dss.depthFunc]; + depthStencilState.depthCompareOp = VK_CMP_FUNCS[static_cast(gpuPipelineState->dss.depthFunc)]; depthStencilState.stencilTestEnable = gpuPipelineState->dss.stencilTestFront; depthStencilState.front = { - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilFailOpFront], - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilPassOpFront], - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilZFailOpFront], - VK_CMP_FUNCS[(uint)gpuPipelineState->dss.stencilFuncFront], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilFailOpFront)], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilPassOpFront)], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilZFailOpFront)], + VK_CMP_FUNCS[static_cast(gpuPipelineState->dss.stencilFuncFront)], gpuPipelineState->dss.stencilReadMaskFront, gpuPipelineState->dss.stencilWriteMaskFront, gpuPipelineState->dss.stencilRefFront, }; depthStencilState.back = { - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilFailOpBack], - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilPassOpBack], - VK_STENCIL_OPS[(uint)gpuPipelineState->dss.stencilZFailOpBack], - VK_CMP_FUNCS[(uint)gpuPipelineState->dss.stencilFuncBack], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilFailOpBack)], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilPassOpBack)], + VK_STENCIL_OPS[static_cast(gpuPipelineState->dss.stencilZFailOpBack)], + VK_CMP_FUNCS[static_cast(gpuPipelineState->dss.stencilFuncBack)], gpuPipelineState->dss.stencilReadMaskBack, gpuPipelineState->dss.stencilWriteMaskBack, gpuPipelineState->dss.stencilRefBack, @@ -711,16 +711,16 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS size_t blendTargetCount = gpuPipelineState->bs.targets.size(); vector blendTargets(blendTargetCount); - for (size_t i = 0u; i < blendTargetCount; ++i) { + for (size_t i = 0U; i < blendTargetCount; ++i) { BlendTarget &target = gpuPipelineState->bs.targets[i]; blendTargets[i].blendEnable = target.blend; - blendTargets[i].srcColorBlendFactor = VK_BLEND_FACTORS[(uint)target.blendSrc]; - blendTargets[i].dstColorBlendFactor = VK_BLEND_FACTORS[(uint)target.blendDst]; - blendTargets[i].colorBlendOp = VK_BLEND_OPS[(uint)target.blendEq]; - blendTargets[i].srcAlphaBlendFactor = VK_BLEND_FACTORS[(uint)target.blendSrcAlpha]; - blendTargets[i].dstAlphaBlendFactor = VK_BLEND_FACTORS[(uint)target.blendDstAlpha]; - blendTargets[i].alphaBlendOp = VK_BLEND_OPS[(uint)target.blendAlphaEq]; - blendTargets[i].colorWriteMask = MapVkColorComponentFlags(target.blendColorMask); + blendTargets[i].srcColorBlendFactor = VK_BLEND_FACTORS[static_cast(target.blendSrc)]; + blendTargets[i].dstColorBlendFactor = VK_BLEND_FACTORS[static_cast(target.blendDst)]; + blendTargets[i].colorBlendOp = VK_BLEND_OPS[static_cast(target.blendEq)]; + blendTargets[i].srcAlphaBlendFactor = VK_BLEND_FACTORS[static_cast(target.blendSrcAlpha)]; + blendTargets[i].dstAlphaBlendFactor = VK_BLEND_FACTORS[static_cast(target.blendDstAlpha)]; + blendTargets[i].alphaBlendOp = VK_BLEND_OPS[static_cast(target.blendAlphaEq)]; + blendTargets[i].colorWriteMask = mapVkColorComponentFlags(target.blendColorMask); } Color &blendColor = gpuPipelineState->bs.blendColor; @@ -746,20 +746,20 @@ void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS 1, &createInfo, nullptr, &gpuPipelineState->vkPipeline)); } -void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer) { +void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer) { if (!gpuBuffer) return; const void *dataToUpload = nullptr; - size_t sizeToUpload = 0u; + size_t sizeToUpload = 0U; if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { - size_t drawInfoCount = size / sizeof(DrawInfo); - const auto *drawInfo = static_cast(buffer); + size_t drawInfoCount = size / sizeof(DrawInfo); + const auto *drawInfo = static_cast(buffer); if (drawInfoCount > 0) { if (drawInfo->indexCount) { for (size_t i = 0; i < drawInfoCount; ++i) { gpuBuffer->indexedIndirectCmds[i].indexCount = drawInfo->indexCount; - gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1u); + gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1U); gpuBuffer->indexedIndirectCmds[i].firstIndex = drawInfo->firstIndex; gpuBuffer->indexedIndirectCmds[i].vertexOffset = drawInfo->vertexOffset; gpuBuffer->indexedIndirectCmds[i].firstInstance = drawInfo->firstInstance; @@ -824,7 +824,7 @@ void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const device->gpuBarrierManager()->checkIn(gpuBuffer); } -void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, +void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { vector &curTypes = gpuTexture->currentAccessTypes; @@ -839,10 +839,10 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b barrier.prevAccessCount = curTypes.size(); barrier.pPrevAccesses = curTypes.data(); barrier.nextAccessCount = 1; - barrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::TRANSFER_WRITE]; + barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_WRITE)]; if (gpuTexture->transferAccess != THSVS_ACCESS_TRANSFER_WRITE) { - CCVKCmdFuncImageMemoryBarrier(gpuCommandBuffer, barrier); + cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); } else { // guard against WAW hazard VkMemoryBarrier vkBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; @@ -854,23 +854,23 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b 0, 1, &vkBarrier, 0, nullptr, 0, nullptr); } - uint totalSize = 0u; + uint totalSize = 0U; vector regionSizes(count); - for (size_t i = 0u; i < count; ++i) { + for (size_t i = 0U; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; uint w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; uint h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; - totalSize += regionSizes[i] = FormatSize(gpuTexture->format, w, h, region.texExtent.depth); + totalSize += regionSizes[i] = formatSize(gpuTexture->format, w, h, region.texExtent.depth); } CCVKGPUBuffer stagingBuffer; stagingBuffer.size = totalSize; - uint texelSize = GFX_FORMAT_INFOS[(uint)gpuTexture->format].size; + uint texelSize = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].size; device->gpuStagingBufferPool()->alloc(&stagingBuffer, texelSize); vector stagingRegions(count); VkDeviceSize offset = 0; - for (size_t i = 0u; i < count; ++i) { + for (size_t i = 0U; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; VkBufferImageCopy & stagingRegion = stagingRegions[i]; stagingRegion.bufferOffset = stagingBuffer.startOffset + offset; @@ -889,7 +889,7 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) { VkFormatProperties formatProperties; - vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, MapVkFormat(gpuTexture->format), &formatProperties); + vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, mapVkFormat(gpuTexture->format), &formatProperties); VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; if (formatProperties.optimalTilingFeatures & mipmapFeatures) { @@ -905,12 +905,12 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b blitInfo.dstOffsets[1] = {std::max(width >> 1, 1), std::max(height >> 1, 1), 1}; barrier.subresourceRange.levelCount = 1; barrier.prevAccessCount = 1; - barrier.pPrevAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::TRANSFER_WRITE]; - barrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::TRANSFER_READ]; + barrier.pPrevAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_WRITE)]; + barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_READ)]; - for (uint i = 1u; i < gpuTexture->mipLevels; ++i) { + for (uint i = 1U; i < gpuTexture->mipLevels; ++i) { barrier.subresourceRange.baseMipLevel = i - 1; - CCVKCmdFuncImageMemoryBarrier(gpuCommandBuffer, barrier); + cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); blitInfo.srcSubresource.mipLevel = i - 1; blitInfo.dstSubresource.mipLevel = i; @@ -925,13 +925,13 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b barrier.subresourceRange.baseMipLevel = 0; barrier.subresourceRange.levelCount = gpuTexture->mipLevels - 1; - barrier.pPrevAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::TRANSFER_READ]; - barrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::TRANSFER_WRITE]; + barrier.pPrevAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_READ)]; + barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_WRITE)]; - CCVKCmdFuncImageMemoryBarrier(gpuCommandBuffer, barrier); + cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); } else { - const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str(); - CC_LOG_WARNING("CCVKCmdFuncCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName); + const char *formatName = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].name.c_str(); + CC_LOG_WARNING("cmdFuncCCVKCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName); } } @@ -940,38 +940,38 @@ void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b device->gpuBarrierManager()->checkIn(gpuTexture); } -void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) { +void cmdFuncCCVKDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) { if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) { vkDestroyRenderPass(gpuDevice->vkDevice, gpuRenderPass->vkRenderPass, nullptr); gpuRenderPass->vkRenderPass = VK_NULL_HANDLE; } } -void CCVKCmdFuncDestroySampler(CCVKGPUDevice *gpuDevice, CCVKGPUSampler *gpuSampler) { +void cmdFuncCCVKDestroySampler(CCVKGPUDevice *gpuDevice, CCVKGPUSampler *gpuSampler) { if (gpuSampler->vkSampler != VK_NULL_HANDLE) { vkDestroySampler(gpuDevice->vkDevice, gpuSampler->vkSampler, nullptr); gpuSampler->vkSampler = VK_NULL_HANDLE; } } -void CCVKCmdFuncDestroyShader(CCVKGPUDevice *gpuDevice, CCVKGPUShader *gpuShader) { +void cmdFuncCCVKDestroyShader(CCVKGPUDevice *gpuDevice, CCVKGPUShader *gpuShader) { for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { vkDestroyShaderModule(gpuDevice->vkDevice, stage.vkShader, nullptr); stage.vkShader = VK_NULL_HANDLE; } } -void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer *gpuFramebuffer) { +void cmdFuncCCVKDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer *gpuFramebuffer) { if (gpuFramebuffer->isOffscreen) { if (gpuFramebuffer->vkFramebuffer != VK_NULL_HANDLE) { vkDestroyFramebuffer(gpuDevice->vkDevice, gpuFramebuffer->vkFramebuffer, nullptr); gpuFramebuffer->vkFramebuffer = VK_NULL_HANDLE; } } else { - FramebufferListMap & fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; - auto fboListMapIter = fboListMap.find(gpuFramebuffer); + FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; + auto fboListMapIter = fboListMap.find(gpuFramebuffer); if (fboListMapIter != fboListMap.end()) { - for (auto & i : fboListMapIter->second) { + for (auto &i : fboListMapIter->second) { vkDestroyFramebuffer(gpuDevice->vkDevice, i, nullptr); } fboListMapIter->second.clear(); @@ -980,7 +980,7 @@ void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer } } -void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { +void cmdFuncCCVKDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout) { if (gpuDescriptorSetLayout->defaultDescriptorSet != VK_NULL_HANDLE) { gpuDevice->getDescriptorSetPool(gpuDescriptorSetLayout->id)->yield(gpuDescriptorSetLayout->defaultDescriptorSet, 0); gpuDescriptorSetLayout->defaultDescriptorSet = VK_NULL_HANDLE; @@ -1001,21 +1001,21 @@ void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *gpuDevice, CCVKGPUDesc } } -void CCVKCmdFuncDestroyPipelineLayout(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineLayout *gpuPipelineLayout) { +void cmdFuncCCVKDestroyPipelineLayout(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineLayout *gpuPipelineLayout) { if (gpuPipelineLayout->vkPipelineLayout != VK_NULL_HANDLE) { vkDestroyPipelineLayout(gpuDevice->vkDevice, gpuPipelineLayout->vkPipelineLayout, nullptr); gpuPipelineLayout->vkPipelineLayout = VK_NULL_HANDLE; } } -void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineState *gpuPipelineState) { +void cmdFuncCCVKDestroyPipelineState(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineState *gpuPipelineState) { if (gpuPipelineState->vkPipeline != VK_NULL_HANDLE) { vkDestroyPipeline(gpuDevice->vkDevice, gpuPipelineState->vkPipeline, nullptr); gpuPipelineState->vkPipeline = VK_NULL_HANDLE; } } -void CCVKCmdFuncImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsImageBarrier &imageBarrier) { +void cmdFuncCCVKImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsImageBarrier &imageBarrier) { VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkPipelineStageFlags tempSrcStageMask = 0; @@ -1028,7 +1028,7 @@ void CCVKCmdFuncImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, } void CCVKGPURecycleBin::clear() { - for (uint i = 0u; i < _count; ++i) { + for (uint i = 0U; i < _count; ++i) { Resource &res = _resources[i]; switch (res.type) { case RecycledType::BUFFER: @@ -1053,49 +1053,49 @@ void CCVKGPURecycleBin::clear() { break; case RecycledType::RENDER_PASS: if (res.gpuRenderPass) { - CCVKCmdFuncDestroyRenderPass(_device, res.gpuRenderPass); + cmdFuncCCVKDestroyRenderPass(_device, res.gpuRenderPass); CC_DELETE(res.gpuRenderPass); res.gpuRenderPass = nullptr; } break; case RecycledType::FRAMEBUFFER: if (res.gpuFramebuffer) { - CCVKCmdFuncDestroyFramebuffer(_device, res.gpuFramebuffer); + cmdFuncCCVKDestroyFramebuffer(_device, res.gpuFramebuffer); CC_DELETE(res.gpuFramebuffer); res.gpuFramebuffer = nullptr; } break; case RecycledType::SAMPLER: if (res.gpuSampler) { - CCVKCmdFuncDestroySampler(_device, res.gpuSampler); + cmdFuncCCVKDestroySampler(_device, res.gpuSampler); CC_DELETE(res.gpuSampler); res.gpuSampler = nullptr; } break; case RecycledType::SHADER: if (res.gpuShader) { - CCVKCmdFuncDestroyShader(_device, res.gpuShader); + cmdFuncCCVKDestroyShader(_device, res.gpuShader); CC_DELETE(res.gpuShader); res.gpuShader = nullptr; } break; case RecycledType::DESCRIPTOR_SET_LAYOUT: if (res.gpuDescriptorSetLayout) { - CCVKCmdFuncDestroyDescriptorSetLayout(_device, res.gpuDescriptorSetLayout); + cmdFuncCCVKDestroyDescriptorSetLayout(_device, res.gpuDescriptorSetLayout); CC_DELETE(res.gpuDescriptorSetLayout); res.gpuDescriptorSetLayout = nullptr; } break; case RecycledType::PIPELINE_LAYOUT: if (res.gpuPipelineLayout) { - CCVKCmdFuncDestroyPipelineLayout(_device, res.gpuPipelineLayout); + cmdFuncCCVKDestroyPipelineLayout(_device, res.gpuPipelineLayout); CC_DELETE(res.gpuPipelineLayout); res.gpuPipelineLayout = nullptr; } break; case RecycledType::PIPELINE_STATE: if (res.gpuPipelineState) { - CCVKCmdFuncDestroyPipelineState(_device, res.gpuPipelineState); + cmdFuncCCVKDestroyPipelineState(_device, res.gpuPipelineState); CC_DELETE(res.gpuPipelineState); res.gpuPipelineState = nullptr; } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.h b/native/cocos/renderer/gfx-vulkan/VKCommands.h index c09833e9ba..5af3458b16 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.h @@ -33,14 +33,14 @@ namespace gfx { class CCVKDevice; struct CCVKDepthBias { - float constant = 0.0f; - float clamp = 0.0f; - float slope = 0.0f; + float constant = 0.0F; + float clamp = 0.0F; + float slope = 0.0F; }; struct CCVKDepthBounds { - float minBounds = 0.0f; - float maxBounds = 0.0f; + float minBounds = 0.0F; + float maxBounds = 0.0F; }; struct CCVKStencilWriteMask { @@ -54,33 +54,33 @@ struct CCVKStencilCompareMask { uint32_t compareMask = 0; }; -CC_VULKAN_API void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue); +CC_VULKAN_API void cmdFuncCCVKGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue); -CC_VULKAN_API void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture); -CC_VULKAN_API void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView); -CC_VULKAN_API void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler); -CC_VULKAN_API void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer); -CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); -CC_VULKAN_API void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); -CC_VULKAN_API void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader); -CC_VULKAN_API void CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); -CC_VULKAN_API void CCVKCmdFuncCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); -CC_VULKAN_API void CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); -CC_VULKAN_API void CCVKCmdFuncCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); +CC_VULKAN_API void cmdFuncCCVKCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture); +CC_VULKAN_API void cmdFuncCCVKCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView); +CC_VULKAN_API void cmdFuncCCVKCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler); +CC_VULKAN_API void cmdFuncCCVKCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer); +CC_VULKAN_API void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); +CC_VULKAN_API void cmdFuncCCVKCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); +CC_VULKAN_API void cmdFuncCCVKCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader); +CC_VULKAN_API void cmdFuncCCVKCreateDescriptorSetLayout(CCVKDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); +CC_VULKAN_API void cmdFuncCCVKCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); +CC_VULKAN_API void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); +CC_VULKAN_API void cmdFuncCCVKCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); -CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer = nullptr); -CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *cmdBuff); +CC_VULKAN_API void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer = nullptr); +CC_VULKAN_API void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer); -CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *device, CCVKGPURenderPass *gpuRenderPass); -CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKGPUDevice *device, CCVKGPUSampler *gpuSampler); -CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKGPUDevice *device, CCVKGPUShader *gpuShader); -CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); -CC_VULKAN_API void CCVKCmdFuncDestroyDescriptorSetLayout(CCVKGPUDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); -CC_VULKAN_API void CCVKCmdFuncDestroyPipelineLayout(CCVKGPUDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); -CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *device, CCVKGPUPipelineState *gpuPipelineState); +CC_VULKAN_API void cmdFuncCCVKDestroyRenderPass(CCVKGPUDevice *device, CCVKGPURenderPass *gpuRenderPass); +CC_VULKAN_API void cmdFuncCCVKDestroySampler(CCVKGPUDevice *device, CCVKGPUSampler *gpuSampler); +CC_VULKAN_API void cmdFuncCCVKDestroyShader(CCVKGPUDevice *device, CCVKGPUShader *gpuShader); +CC_VULKAN_API void cmdFuncCCVKDestroyFramebuffer(CCVKGPUDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); +CC_VULKAN_API void cmdFuncCCVKDestroyDescriptorSetLayout(CCVKGPUDevice *device, CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout); +CC_VULKAN_API void cmdFuncCCVKDestroyPipelineLayout(CCVKGPUDevice *device, CCVKGPUPipelineLayout *gpuPipelineLayout); +CC_VULKAN_API void cmdFuncCCVKDestroyPipelineState(CCVKGPUDevice *device, CCVKGPUPipelineState *gpuPipelineState); -CC_VULKAN_API void CCVKCmdFuncImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsImageBarrier &imageBarrier); -CC_VULKAN_API void CCVKCmdFuncGlobalMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsGlobalBarrier &globalBarrier); +CC_VULKAN_API void cmdFuncCCVKImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsImageBarrier &imageBarrier); +CC_VULKAN_API void cmdFuncCCVKGlobalMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, const ThsvsGlobalBarrier &globalBarrier); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.cpp b/native/cocos/renderer/gfx-vulkan/VKContext.cpp index db3712febb..ecaac9f968 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKContext.cpp @@ -99,12 +99,9 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT fl #endif } // namespace -CCVKContext::CCVKContext() -: Context() { -} +CCVKContext::CCVKContext() = default; -CCVKContext::~CCVKContext() { -} +CCVKContext::~CCVKContext() = default; bool CCVKContext::doInit(const ContextInfo &info) { if (!info.sharedCtx) { @@ -226,9 +223,9 @@ bool CCVKContext::doInit(const ContextInfo &info) { VkInstanceCreateInfo instanceInfo{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO}; instanceInfo.pApplicationInfo = &app; - instanceInfo.enabledExtensionCount = toUint(_extensions.size()); + instanceInfo.enabledExtensionCount = utils::toUint(_extensions.size()); instanceInfo.ppEnabledExtensionNames = _extensions.data(); - instanceInfo.enabledLayerCount = toUint(_layers.size()); + instanceInfo.enabledLayerCount = utils::toUint(_layers.size()); instanceInfo.ppEnabledLayerNames = _layers.data(); #if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION @@ -276,15 +273,15 @@ bool CCVKContext::doInit(const ContextInfo &info) { #if defined(VK_USE_PLATFORM_ANDROID_KHR) VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR}; - surfaceCreateInfo.window = (ANativeWindow *)_windowHandle; + surfaceCreateInfo.window = reinterpret_cast(_windowHandle); VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); - EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [this](const CustomEvent &event) -> void { + EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [this](const CustomEvent &/*event*/) -> void { if (_gpuContext && _gpuContext->vkSurface != VK_NULL_HANDLE) { CCVKDevice *device = CCVKDevice::getInstance(); - CCVKQueue *queue = (CCVKQueue *)device->getQueue(); + auto *queue = static_cast(device->getQueue()); uint fenceCount = device->gpuFencePool()->size(); if (fenceCount) { @@ -301,12 +298,11 @@ bool CCVKContext::doInit(const ContextInfo &info) { }); EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [this](const CustomEvent &event) -> void { - _windowHandle = (uintptr_t)event.args->ptrVal; + _windowHandle = reinterpret_cast(event.args->ptrVal); if (_gpuContext && _gpuContext->vkSurface == VK_NULL_HANDLE) { - VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{ - VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR}; - surfaceCreateInfo.window = (ANativeWindow *)_windowHandle; + VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR}; + surfaceCreateInfo.window = reinterpret_cast(_windowHandle); VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); @@ -315,22 +311,22 @@ bool CCVKContext::doInit(const ContextInfo &info) { }); #elif defined(VK_USE_PLATFORM_WIN32_KHR) VkWin32SurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR}; - surfaceCreateInfo.hinstance = (HINSTANCE)GetModuleHandle(0); - surfaceCreateInfo.hwnd = (HWND)_windowHandle; + surfaceCreateInfo.hinstance = static_cast(GetModuleHandle(0)); + surfaceCreateInfo.hwnd = reinterpret_cast(_windowHandle); VK_CHECK(vkCreateWin32SurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); #elif defined(VK_USE_PLATFORM_METAL_EXT) VkMetalSurfaceCreateInfoEXT surfaceCreateInfo{VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT}; - surfaceCreateInfo.pLayer = (CAMetalLayer *)_windowHandle; + surfaceCreateInfo.pLayer = static_cast(_windowHandle); VK_CHECK(vkCreateMetalSurfaceEXT(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR}; surfaceCreateInfo.display = nullptr; // TODO - surfaceCreateInfo.surface = (wl_surface *)_windowHandle; + surfaceCreateInfo.surface = static_cast(_windowHandle); VK_CHECK(vkCreateWaylandSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); #elif defined(VK_USE_PLATFORM_XCB_KHR) VkXcbSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR}; surfaceCreateInfo.connection = nullptr; // TODO - surfaceCreateInfo.window = (xcb_window_t)_windowHandle; + surfaceCreateInfo.window = static_cast(_windowHandle); VK_CHECK(vkCreateXcbSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); #else #pragma error Platform not supported @@ -352,12 +348,12 @@ bool CCVKContext::doInit(const ContextInfo &info) { vector physicalDeviceProperties(physicalDeviceCount); uint deviceIndex; - for (deviceIndex = 0u; deviceIndex < physicalDeviceCount; ++deviceIndex) { + for (deviceIndex = 0U; deviceIndex < physicalDeviceCount; ++deviceIndex) { VkPhysicalDeviceProperties &properties = physicalDeviceProperties[deviceIndex]; vkGetPhysicalDeviceProperties(physicalDeviceHandles[deviceIndex], &properties); } - for (deviceIndex = 0u; deviceIndex < physicalDeviceCount; ++deviceIndex) { + for (deviceIndex = 0U; deviceIndex < physicalDeviceCount; ++deviceIndex) { VkPhysicalDeviceProperties &properties = physicalDeviceProperties[deviceIndex]; if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { break; @@ -406,12 +402,12 @@ bool CCVKContext::doInit(const ContextInfo &info) { VkSurfaceCapabilitiesKHR surfaceCapabilities{}; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceCapabilities); - uint surfaceFormatCount = 0u; + uint surfaceFormatCount = 0U; VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceFormatCount, nullptr)); vector surfaceFormats(surfaceFormatCount); VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &surfaceFormatCount, surfaceFormats.data())); - uint presentModeCount = 0u; + uint presentModeCount = 0U; VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &presentModeCount, nullptr)); vector presentModes(presentModeCount); VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(_gpuContext->physicalDevice, _gpuContext->vkSurface, &presentModeCount, presentModes.data())); @@ -478,7 +474,7 @@ bool CCVKContext::doInit(const ContextInfo &info) { case VsyncMode::ON: presentModePriorityList.insert(presentModePriorityList.end(), {VK_PRESENT_MODE_FIFO_KHR}); break; case VsyncMode::RELAXED: presentModePriorityList.insert(presentModePriorityList.end(), {VK_PRESENT_MODE_FIFO_RELAXED_KHR, VK_PRESENT_MODE_FIFO_KHR}); break; case VsyncMode::MAILBOX: presentModePriorityList.insert(presentModePriorityList.end(), {VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR}); break; - case VsyncMode::HALF: presentModePriorityList.insert(presentModePriorityList.end(), {VK_PRESENT_MODE_FIFO_KHR}); break; // TODO + case VsyncMode::HALF: presentModePriorityList.insert(presentModePriorityList.end(), {VK_PRESENT_MODE_FIFO_KHR}); break; // no easy fallback } VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; @@ -490,13 +486,13 @@ bool CCVKContext::doInit(const ContextInfo &info) { } // Determine the number of images - uint desiredNumberOfSwapchainImages = std::max(3u, surfaceCapabilities.minImageCount + 1); + uint desiredNumberOfSwapchainImages = std::max(3U, surfaceCapabilities.minImageCount + 1); if ((surfaceCapabilities.maxImageCount > 0) && (desiredNumberOfSwapchainImages > surfaceCapabilities.maxImageCount)) { desiredNumberOfSwapchainImages = surfaceCapabilities.maxImageCount; } - VkExtent2D imageExtent = {1u, 1u}; + VkExtent2D imageExtent = {1U, 1U}; VkSurfaceTransformFlagBitsKHR preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; // Find a supported composite alpha format (not all devices support alpha opaque) @@ -538,12 +534,12 @@ bool CCVKContext::doInit(const ContextInfo &info) { _gpuContext->swapchainCreateInfo.clipped = VK_TRUE; // Setting clipped to VK_TRUE allows the implementation to discard rendering outside of the surface area } else { - CCVKContext *sharedCtx = (CCVKContext *)info.sharedCtx; - _majorVersion = sharedCtx->majorVersion(); - _minorVersion = sharedCtx->minorVersion(); - _layers = sharedCtx->getLayers(); - _extensions = sharedCtx->getExtensions(); - _gpuContext = sharedCtx->gpuContext(); + auto *sharedCtx = static_cast(info.sharedCtx); + _majorVersion = sharedCtx->majorVersion(); + _minorVersion = sharedCtx->minorVersion(); + _layers = sharedCtx->getLayers(); + _extensions = sharedCtx->getExtensions(); + _gpuContext = sharedCtx->gpuContext(); } return true; diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.h b/native/cocos/renderer/gfx-vulkan/VKContext.h index cd41e87c26..b6af9f68bb 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.h +++ b/native/cocos/renderer/gfx-vulkan/VKContext.h @@ -23,9 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_CONTEXT_H_ -#define CC_GFXVULKAN_CONTEXT_H_ +#pragma once +#include "VKStd.h" #include "gfx-base/GFXContext.h" namespace cc { @@ -40,22 +40,21 @@ class CCVKGPUSemaphorePool; class CC_VULKAN_API CCVKContext final : public Context { public: CCVKContext(); - ~CCVKContext(); + ~CCVKContext() override; void present() override {} - CC_INLINE bool checkExtension(const String &extension) const { - return std::find_if(_extensions.begin(), _extensions.end(), - [extension](const char *device_extension) { - return std::strcmp(device_extension, extension.c_str()) == 0; - }) != _extensions.end(); + inline bool checkExtension(const String &extension) const { + return std::any_of(_extensions.begin(), _extensions.end(), [&extension](auto &ext) { + return std::strcmp(ext, extension.c_str()) == 0; + }); } - CC_INLINE int majorVersion() const { return _majorVersion; } - CC_INLINE int minorVersion() const { return _minorVersion; } - CC_INLINE CCVKGPUContext *gpuContext() { return _gpuContext; } - CC_INLINE const vector &getLayers() const { return _layers; } - CC_INLINE const vector &getExtensions() const { return _extensions; } + inline int majorVersion() const { return _majorVersion; } + inline int minorVersion() const { return _minorVersion; } + inline CCVKGPUContext * gpuContext() { return _gpuContext; } + inline const vector &getLayers() const { return _layers; } + inline const vector &getExtensions() const { return _extensions; } protected: bool doInit(const ContextInfo &info) override; @@ -71,5 +70,3 @@ protected: } // namespace gfx } // namespace cc - -#endif // CC_GFXVULKAN_CONTEXT_H_ diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index 19562bb2f4..63f91f5cb4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -38,15 +38,13 @@ namespace cc { namespace gfx { -CCVKDescriptorSet::CCVKDescriptorSet() -: DescriptorSet() { -} +CCVKDescriptorSet::CCVKDescriptorSet() = default; CCVKDescriptorSet::~CCVKDescriptorSet() { destroy(); } -void CCVKDescriptorSet::doInit(const DescriptorSetInfo &info) { +void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); const uint bindingCount = gpuDescriptorSetLayout->bindings.size(); const uint descriptorCount = gpuDescriptorSetLayout->descriptorCount; @@ -55,7 +53,7 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo &info) { _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount, {}); _gpuDescriptorSet->layoutID = gpuDescriptorSetLayout->id; - for (size_t i = 0u, k = 0u; i < bindingCount; ++i) { + for (size_t i = 0U, k = 0U; i < bindingCount; ++i) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; for (uint j = 0; j < binding.count; ++j, ++k) { CCVKGPUDescriptor &gpuDescriptor = _gpuDescriptorSet->gpuDescriptors[k]; @@ -95,12 +93,12 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo &info) { _gpuDescriptorSet->gpuLayout = gpuDescriptorSetLayout; _gpuDescriptorSet->instances.resize(gpuDevice->backBufferCount); - for (size_t t = 0u; t < gpuDevice->backBufferCount; ++t) { + for (size_t t = 0U; t < gpuDevice->backBufferCount; ++t) { CCVKGPUDescriptorSet::Instance &instance = _gpuDescriptorSet->instances[t]; instance.vkDescriptorSet = gpuDevice->getDescriptorSetPool(_gpuDescriptorSet->layoutID)->request(t); instance.descriptorInfos.resize(descriptorCount, {}); - for (size_t i = 0u, k = 0u; i < bindingCount; ++i) { + for (size_t i = 0U, k = 0U; i < bindingCount; ++i) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; for (uint j = 0; j < binding.count; ++j, ++k) { if (binding.descriptorType & DESCRIPTOR_BUFFER_TYPE) { @@ -121,9 +119,9 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo &info) { vector &entries = instance.descriptorUpdateEntries; entries.resize(descriptorCount, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}); - for (size_t i = 0u, j = 0u; i < bindingCount; i++) { + for (size_t i = 0U, j = 0U; i < bindingCount; i++) { const VkDescriptorSetLayoutBinding &descriptor = gpuDescriptorSetLayout->vkBindings[i]; - for (size_t k = 0u; k < descriptor.descriptorCount; k++, j++) { + for (size_t k = 0U; k < descriptor.descriptorCount; k++, j++) { entries[j].dstSet = instance.vkDescriptorSet; entries[j].dstBinding = descriptor.binding; entries[j].dstArrayElement = k; @@ -160,10 +158,10 @@ void CCVKDescriptorSet::doDestroy() { CCVKGPUDevice * gpuDevice = CCVKDevice::getInstance()->gpuDevice(); CCVKGPUDescriptorHub *descriptorHub = CCVKDevice::getInstance()->gpuDescriptorHub(); - for (size_t t = 0u; t < _gpuDescriptorSet->instances.size(); ++t) { + for (size_t t = 0U; t < _gpuDescriptorSet->instances.size(); ++t) { CCVKGPUDescriptorSet::Instance &instance = _gpuDescriptorSet->instances[t]; - for (uint i = 0u; i < _gpuDescriptorSet->gpuDescriptors.size(); i++) { + for (uint i = 0U; i < _gpuDescriptorSet->gpuDescriptors.size(); i++) { CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; @@ -196,14 +194,14 @@ void CCVKDescriptorSet::update() { CCVKGPUBarrierManager *layoutMgr = CCVKDevice::getInstance()->gpuBarrierManager(); uint descriptorCount = _gpuDescriptorSet->gpuDescriptors.size(); - for (size_t i = 0u; i < descriptorCount; i++) { + for (size_t i = 0U; i < descriptorCount; i++) { CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; if (binding.type & DESCRIPTOR_BUFFER_TYPE) { if (_buffers[i]) { CCVKGPUBufferView *bufferView = static_cast(_buffers[i])->gpuBufferView(); if (binding.gpuBufferView != bufferView) { - for (size_t t = 0u; t < _gpuDescriptorSet->instances.size(); ++t) { + for (size_t t = 0U; t < _gpuDescriptorSet->instances.size(); ++t) { CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->instances[t].descriptorInfos[i]; if (binding.gpuBufferView) { @@ -221,8 +219,8 @@ void CCVKDescriptorSet::update() { if (_textures[i]) { CCVKGPUTextureView *textureView = static_cast(_textures[i])->gpuTextureView(); if (binding.gpuTextureView != textureView) { - for (size_t t = 0u; t < _gpuDescriptorSet->instances.size(); ++t) { - CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->instances[t].descriptorInfos[i]; + for (auto &instance : _gpuDescriptorSet->instances) { + CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; if (binding.gpuTextureView) { descriptorHub->disengage(binding.gpuTextureView, &descriptorInfo.image); } @@ -238,8 +236,8 @@ void CCVKDescriptorSet::update() { if (_samplers[i]) { CCVKGPUSampler *sampler = static_cast(_samplers[i])->gpuSampler(); if (binding.gpuSampler != sampler) { - for (size_t t = 0u; t < _gpuDescriptorSet->instances.size(); ++t) { - CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->instances[t].descriptorInfos[i]; + for (auto &instance : _gpuDescriptorSet->instances) { + CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; if (binding.gpuSampler) { descriptorHub->disengage(binding.gpuSampler, &descriptorInfo.image); } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp index 7f8e136548..02b40aa9f4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -CCVKDescriptorSetLayout::CCVKDescriptorSetLayout() -: DescriptorSetLayout() { -} +CCVKDescriptorSetLayout::CCVKDescriptorSetLayout() = default; CCVKDescriptorSetLayout::~CCVKDescriptorSetLayout() { destroy(); } -void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { +void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo & /*info*/) { _gpuDescriptorSetLayout = CC_NEW(CCVKGPUDescriptorSetLayout); _gpuDescriptorSetLayout->id = generateID(); @@ -49,16 +47,15 @@ void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; _gpuDescriptorSetLayout->bindings = _bindings; - for (uint i = 0u; i < _bindings.size(); i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; + for (auto & binding : _bindings) { if (binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { - for (uint j = 0u; j < binding.count; j++) { + for (uint j = 0U; j < binding.count; j++) { _gpuDescriptorSetLayout->dynamicBindings.push_back(binding.binding); } } } - CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice::getInstance(), _gpuDescriptorSetLayout); + cmdFuncCCVKCreateDescriptorSetLayout(CCVKDevice::getInstance(), _gpuDescriptorSetLayout); } void CCVKDescriptorSetLayout::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index 886f6a46f9..789eacf420 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -59,31 +59,31 @@ namespace gfx { //#define DISABLE_PRE_TRANSFORM -CCVKDevice *CCVKDevice::_instance = nullptr; +CCVKDevice *CCVKDevice::instance = nullptr; CCVKDevice *CCVKDevice::getInstance() { - return CCVKDevice::_instance; + return CCVKDevice::instance; } CCVKDevice::CCVKDevice() { - _API = API::VULKAN; + _api = API::VULKAN; _deviceName = "Vulkan"; - _caps.clipSpaceMinZ = 0.0f; - _caps.screenSpaceSignY = -1.0f; - _caps.UVSpaceSignY = 1.0f; - CCVKDevice::_instance = this; + _caps.clipSpaceMinZ = 0.0F; + _caps.screenSpaceSignY = -1.0F; + _caps.UVSpaceSignY = 1.0F; + CCVKDevice::instance = this; } CCVKDevice::~CCVKDevice() { - CCVKDevice::_instance = nullptr; + CCVKDevice::instance = nullptr; } CCVKGPUContext *CCVKDevice::gpuContext() const { return static_cast(_context)->gpuContext(); } -bool CCVKDevice::doInit(const DeviceInfo &info) { +bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; @@ -93,8 +93,8 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { return false; } - const CCVKContext * context = (CCVKContext *)_context; - const CCVKGPUContext * gpuContext = static_cast(_context)->gpuContext(); + auto * context = static_cast(_context); + const CCVKGPUContext * gpuContext = context->gpuContext(); const VkPhysicalDeviceFeatures2 &deviceFeatures2 = gpuContext->physicalDeviceFeatures2; const VkPhysicalDeviceFeatures & deviceFeatures = deviceFeatures2.features; //const VkPhysicalDeviceVulkan11Features &deviceVulkan11Features = gpuContext->physicalDeviceVulkan11Features; @@ -164,14 +164,14 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { } // prepare the device queues - uint queueFamilyPropertiesCount = toUint(gpuContext->queueFamilyProperties.size()); + uint queueFamilyPropertiesCount = utils::toUint(gpuContext->queueFamilyProperties.size()); vector queueCreateInfos(queueFamilyPropertiesCount, {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}); vector> queuePriorities(queueFamilyPropertiesCount); - for (uint queueFamilyIndex = 0u; queueFamilyIndex < queueFamilyPropertiesCount; ++queueFamilyIndex) { + for (uint queueFamilyIndex = 0U; queueFamilyIndex < queueFamilyPropertiesCount; ++queueFamilyIndex) { const VkQueueFamilyProperties &queueFamilyProperty = gpuContext->queueFamilyProperties[queueFamilyIndex]; - queuePriorities[queueFamilyIndex].resize(queueFamilyProperty.queueCount, 1.0f); + queuePriorities[queueFamilyIndex].resize(queueFamilyProperty.queueCount, 1.0F); VkDeviceQueueCreateInfo &queueCreateInfo = queueCreateInfos[queueFamilyIndex]; @@ -182,11 +182,11 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { VkDeviceCreateInfo deviceCreateInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO}; - deviceCreateInfo.queueCreateInfoCount = toUint(queueCreateInfos.size()); + deviceCreateInfo.queueCreateInfoCount = utils::toUint(queueCreateInfos.size()); deviceCreateInfo.pQueueCreateInfos = queueCreateInfos.data(); - deviceCreateInfo.enabledLayerCount = toUint(_layers.size()); + deviceCreateInfo.enabledLayerCount = utils::toUint(_layers.size()); deviceCreateInfo.ppEnabledLayerNames = _layers.data(); - deviceCreateInfo.enabledExtensionCount = toUint(_extensions.size()); + deviceCreateInfo.enabledExtensionCount = utils::toUint(_extensions.size()); deviceCreateInfo.ppEnabledExtensionNames = _extensions.data(); if (_gpuDevice->minorVersion < 1 && !context->checkExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) { @@ -279,8 +279,8 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { _caps.maxVertexTextureUnits = limits.maxPerStageDescriptorSampledImages; _caps.maxTextureSize = limits.maxImageDimension2D; _caps.maxCubeMapTextureSize = limits.maxImageDimensionCube; - _caps.uboOffsetAlignment = (uint)limits.minUniformBufferOffsetAlignment; - MapDepthStencilBits(_context->getDepthStencilFormat(), _caps.depthBits, _caps.stencilBits); + _caps.uboOffsetAlignment = static_cast(limits.minUniformBufferOffsetAlignment); + mapDepthStencilBits(_context->getDepthStencilFormat(), &_caps.depthBits, &_caps.stencilBits); // compute shaders _caps.maxComputeSharedMemorySize = limits.maxComputeSharedMemorySize; _caps.maxComputeWorkGroupInvocations = limits.maxComputeWorkGroupInvocations; @@ -340,7 +340,7 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { VK_CHECK(vmaCreateAllocator(&allocatorInfo, &_gpuDevice->memoryAllocator)); uint backBufferCount = gpuContext->swapchainCreateInfo.minImageCount; - for (uint i = 0u; i < backBufferCount; i++) { + for (uint i = 0U; i < backBufferCount; i++) { _gpuFencePools.push_back(CC_NEW(CCVKGPUFencePool(_gpuDevice))); _gpuRecycleBins.push_back(CC_NEW(CCVKGPURecycleBin(_gpuDevice))); _gpuStagingBufferPools.push_back(CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice))); @@ -355,21 +355,21 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { _gpuDescriptorHub->link(_gpuDescriptorSetHub); - CCVKCmdFuncCreateSampler(this, &_gpuDevice->defaultSampler); + cmdFuncCCVKCreateSampler(this, &_gpuDevice->defaultSampler); _gpuDevice->defaultTexture.format = Format::RGBA8; _gpuDevice->defaultTexture.usage = TextureUsageBit::SAMPLED; - _gpuDevice->defaultTexture.width = _gpuDevice->defaultTexture.height = 1u; - _gpuDevice->defaultTexture.size = FormatSize(Format::RGBA8, 1u, 1u, 1u); - CCVKCmdFuncCreateTexture(this, &_gpuDevice->defaultTexture); + _gpuDevice->defaultTexture.width = _gpuDevice->defaultTexture.height = 1U; + _gpuDevice->defaultTexture.size = formatSize(Format::RGBA8, 1U, 1U, 1U); + cmdFuncCCVKCreateTexture(this, &_gpuDevice->defaultTexture); _gpuDevice->defaultTextureView.gpuTexture = &_gpuDevice->defaultTexture; _gpuDevice->defaultTextureView.format = Format::RGBA8; - CCVKCmdFuncCreateTextureView(this, &_gpuDevice->defaultTextureView); + cmdFuncCCVKCreateTextureView(this, &_gpuDevice->defaultTextureView); ThsvsImageBarrier barrier{}; barrier.nextAccessCount = 1; - barrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::VERTEX_SHADER_READ_TEXTURE]; + barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::VERTEX_SHADER_READ_TEXTURE)]; barrier.image = _gpuDevice->defaultTexture.vkImage; barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; @@ -378,27 +378,27 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; gpuTransportHub()->checkIn( [&barrier](const CCVKGPUCommandBuffer *gpuCommandBuffer) { - CCVKCmdFuncImageMemoryBarrier(gpuCommandBuffer, barrier); + cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); }, true); // submit immediately _gpuDevice->defaultBuffer.usage = BufferUsage::UNIFORM; _gpuDevice->defaultBuffer.memUsage = MemoryUsage::HOST | MemoryUsage::DEVICE; - _gpuDevice->defaultBuffer.size = _gpuDevice->defaultBuffer.stride = 16u; - _gpuDevice->defaultBuffer.count = 1u; - CCVKCmdFuncCreateBuffer(this, &_gpuDevice->defaultBuffer); + _gpuDevice->defaultBuffer.size = _gpuDevice->defaultBuffer.stride = 16U; + _gpuDevice->defaultBuffer.count = 1U; + cmdFuncCCVKCreateBuffer(this, &_gpuDevice->defaultBuffer); VkPipelineCacheCreateInfo pipelineCacheInfo{VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; VK_CHECK(vkCreatePipelineCache(_gpuDevice->vkDevice, &pipelineCacheInfo, nullptr, &_gpuDevice->vkPipelineCache)); - for (uint i = 0u; i < gpuContext->swapchainCreateInfo.minImageCount; i++) { + for (uint i = 0U; i < gpuContext->swapchainCreateInfo.minImageCount; i++) { TextureInfo depthStencilTexInfo; depthStencilTexInfo.type = TextureType::TEX2D; depthStencilTexInfo.usage = TextureUsageBit::DEPTH_STENCIL_ATTACHMENT | TextureUsageBit::SAMPLED; depthStencilTexInfo.format = _context->getDepthStencilFormat(); depthStencilTexInfo.width = _width; depthStencilTexInfo.height = _height; - CCVKTexture *texture = (CCVKTexture *)createTexture(depthStencilTexInfo); + auto *texture = static_cast(createTexture(depthStencilTexInfo)); _depthStencilTextures.push_back(texture); } @@ -407,7 +407,10 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { ///////////////////// Print Debug Info ///////////////////// - String instanceLayers, instanceExtensions, deviceLayers, deviceExtensions; + String instanceLayers; + String instanceExtensions; + String deviceLayers; + String deviceExtensions; for (const char *layer : static_cast(_context)->getLayers()) { instanceLayers += layer + String(" "); } @@ -423,7 +426,7 @@ bool CCVKDevice::doInit(const DeviceInfo &info) { uint32_t apiVersion = gpuContext->physicalDeviceProperties.apiVersion; _renderer = gpuContext->physicalDeviceProperties.deviceName; - _vendor = MapVendorName(gpuContext->physicalDeviceProperties.vendorID); + _vendor = mapVendorName(gpuContext->physicalDeviceProperties.vendorID); _version = StringUtil::format("%d.%d.%d", VK_VERSION_MAJOR(apiVersion), VK_VERSION_MINOR(apiVersion), VK_VERSION_PATCH(apiVersion)); @@ -464,7 +467,7 @@ void CCVKDevice::doDestroy() { CC_SAFE_DELETE(_gpuDescriptorSetHub); uint backBufferCount = static_cast(_context)->gpuContext()->swapchainCreateInfo.minImageCount; - for (uint i = 0u; i < backBufferCount; i++) { + for (uint i = 0U; i < backBufferCount; i++) { _gpuRecycleBins[i]->clear(); CC_SAFE_DELETE(_gpuStagingBufferPools[i]); @@ -501,7 +504,7 @@ void CCVKDevice::doDestroy() { _gpuDevice->defaultTexture.vkImage = VK_NULL_HANDLE; _gpuDevice->defaultTexture.vmaAllocation = VK_NULL_HANDLE; } - CCVKCmdFuncDestroySampler(_gpuDevice, &_gpuDevice->defaultSampler); + cmdFuncCCVKDestroySampler(_gpuDevice, &_gpuDevice->defaultSampler); if (_gpuDevice->memoryAllocator != VK_NULL_HANDLE) { VmaStats stats; @@ -535,7 +538,7 @@ void CCVKDevice::doDestroy() { void CCVKDevice::resize(uint width, uint height) {} void CCVKDevice::acquire() { - CCVKQueue *queue = (CCVKQueue *)_queue; + auto *queue = static_cast(_queue); if (!checkSwapchainStatus()) return; @@ -550,7 +553,7 @@ void CCVKDevice::acquire() { _gpuSemaphorePool->reset(); VkSemaphore acquireSemaphore = _gpuSemaphorePool->alloc(); - VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, ~0ull, + VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, ~0ULL, acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex)); #if !defined(VK_USE_PLATFORM_METAL_EXT) @@ -562,10 +565,10 @@ void CCVKDevice::acquire() { } void CCVKDevice::present() { - CCVKQueue *queue = (CCVKQueue *)_queue; - _numDrawCalls = queue->_numDrawCalls; - _numInstances = queue->_numInstances; - _numTriangles = queue->_numTriangles; + auto *queue = static_cast(_queue); + _numDrawCalls = queue->_numDrawCalls; + _numInstances = queue->_numInstances; + _numTriangles = queue->_numTriangles; if (queue->gpuQueue()->nextWaitSemaphore) { // don't present if not acquired VkPresentInfoKHR presentInfo{VK_STRUCTURE_TYPE_PRESENT_INFO_KHR}; @@ -598,7 +601,7 @@ CCVKGPUFencePool * CCVKDevice::gpuFencePool() { return _gpuFencePools[_gp CCVKGPURecycleBin * CCVKDevice::gpuRecycleBin() { return _gpuRecycleBins[_gpuDevice->curBackBufferIndex]; } CCVKGPUStagingBufferPool *CCVKDevice::gpuStagingBufferPool() { return _gpuStagingBufferPools[_gpuDevice->curBackBufferIndex]; } -CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { +CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo & /*info*/, bool /*hasAgent*/) { return CC_NEW(CCVKCommandBuffer); } @@ -660,7 +663,7 @@ TextureBarrier *CCVKDevice::createTextureBarrier() { void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { gpuTransportHub()->checkIn([this, buffers, dst, regions, count](CCVKGPUCommandBuffer *gpuCommandBuffer) { - CCVKCmdFuncCopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count, gpuCommandBuffer); + cmdFuncCCVKCopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count, gpuCommandBuffer); }); } @@ -689,7 +692,7 @@ bool CCVKDevice::checkSwapchainStatus() { return true; } - if (newWidth == (uint)-1) { + if (newWidth == static_cast(-1)) { context->swapchainCreateInfo.imageExtent.width = _width; context->swapchainCreateInfo.imageExtent.height = _height; } else { @@ -701,7 +704,7 @@ bool CCVKDevice::checkSwapchainStatus() { return _swapchainReady = false; } - _transform = MapSurfaceTransform(preTransform); + _transform = mapSurfaceTransform(preTransform); context->swapchainCreateInfo.preTransform = preTransform; context->swapchainCreateInfo.surface = context->vkSurface; context->swapchainCreateInfo.oldSwapchain = _gpuSwapchain->vkSwapchain; @@ -715,7 +718,7 @@ bool CCVKDevice::checkSwapchainStatus() { destroySwapchain(); - _gpuDevice->curBackBufferIndex = 0u; + _gpuDevice->curBackBufferIndex = 0U; _gpuSwapchain->curImageIndex = 0; _gpuSwapchain->vkSwapchain = vkSwapchain; @@ -726,7 +729,7 @@ bool CCVKDevice::checkSwapchainStatus() { assert(imageCount == context->swapchainCreateInfo.minImageCount); // assert if swapchain image count assumption is broken _gpuSwapchain->vkSwapchainImageViews.resize(imageCount); - for (uint i = 0u; i < imageCount; i++) { + for (uint i = 0U; i < imageCount; i++) { _depthStencilTextures[i]->resize(_width, _height); _gpuSwapchain->depthStencilImages.push_back(static_cast(_depthStencilTextures[i])->gpuTexture()->vkImage); _gpuSwapchain->depthStencilImageViews.push_back(static_cast(_depthStencilTextures[i])->gpuTextureView()->vkImageView); @@ -742,7 +745,7 @@ bool CCVKDevice::checkSwapchainStatus() { VK_CHECK(vkCreateImageView(_gpuDevice->vkDevice, &imageViewCreateInfo, nullptr, &_gpuSwapchain->vkSwapchainImageViews[i])); } - bool hasStencil = GFX_FORMAT_INFOS[(uint)_context->getDepthStencilFormat()].hasStencil; + bool hasStencil = GFX_FORMAT_INFOS[static_cast(_context->getDepthStencilFormat())].hasStencil; vector barriers(imageCount * 2, VkImageMemoryBarrier{}); VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; @@ -753,9 +756,9 @@ bool CCVKDevice::checkSwapchainStatus() { tempBarrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; VkPipelineStageFlags tempSrcStageMask = 0; VkPipelineStageFlags tempDstStageMask = 0; - for (uint i = 0u; i < imageCount; i++) { + for (uint i = 0U; i < imageCount; i++) { tempBarrier.nextAccessCount = 1; - tempBarrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::COLOR_ATTACHMENT_WRITE]; + tempBarrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::COLOR_ATTACHMENT_WRITE)]; tempBarrier.image = _gpuSwapchain->swapchainImages[i]; tempBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; thsvsGetVulkanImageMemoryBarrier(tempBarrier, &tempSrcStageMask, &tempDstStageMask, &barriers[i]); @@ -763,7 +766,7 @@ bool CCVKDevice::checkSwapchainStatus() { dstStageMask |= tempDstStageMask; tempBarrier.nextAccessCount = 1; - tempBarrier.pNextAccesses = &THSVS_ACCESS_TYPES[(uint)AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE]; + tempBarrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE)]; tempBarrier.image = _gpuSwapchain->depthStencilImages[i]; tempBarrier.subresourceRange.aspectMask = hasStencil ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; thsvsGetVulkanImageMemoryBarrier(tempBarrier, &tempSrcStageMask, &tempDstStageMask, &barriers[imageCount + i]); @@ -779,9 +782,8 @@ bool CCVKDevice::checkSwapchainStatus() { _gpuSwapchain->swapchainImageAccessTypes.assign(imageCount, {THSVS_ACCESS_PRESENT}); _gpuSwapchain->depthStencilImageAccessTypes.assign(imageCount, {THSVS_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ}); - for (FramebufferListMapIter it = _gpuSwapchain->vkSwapchainFramebufferListMap.begin(); - it != _gpuSwapchain->vkSwapchainFramebufferListMap.end(); it++) { - CCVKCmdFuncCreateFramebuffer(this, it->first); + for (auto &it : _gpuSwapchain->vkSwapchainFramebufferListMap) { + cmdFuncCCVKCreateFramebuffer(this, it.first); } return _swapchainReady = true; @@ -795,9 +797,8 @@ void CCVKDevice::destroySwapchain() { _gpuSwapchain->depthStencilImageViews.clear(); _gpuSwapchain->depthStencilImages.clear(); - for (FramebufferListMapIter it = _gpuSwapchain->vkSwapchainFramebufferListMap.begin(); - it != _gpuSwapchain->vkSwapchainFramebufferListMap.end(); it++) { - FramebufferList &list = it->second; + for (auto &it : _gpuSwapchain->vkSwapchainFramebufferListMap) { + FramebufferList &list = it.second; for (VkFramebuffer framebuffer : list) { vkDestroyFramebuffer(_gpuDevice->vkDevice, framebuffer, nullptr); } diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.h b/native/cocos/renderer/gfx-vulkan/VKDevice.h index 63dda58320..2b08377af4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXDevice.h" namespace cc { @@ -75,30 +76,29 @@ public: void acquire() override; void present() override; - CC_INLINE bool checkExtension(const String &extension) const { - return std::find_if(_extensions.begin(), _extensions.end(), - [extension](const char *device_extension) { - return std::strcmp(device_extension, extension.c_str()) == 0; - }) != _extensions.end(); + inline bool checkExtension(const String &extension) const { + return std::any_of(_extensions.begin(), _extensions.end(), [&extension](auto &ext) { + return std::strcmp(ext, extension.c_str()) == 0; + }); } - CCVKGPUContext *gpuContext() const; - CC_INLINE CCVKGPUDevice *gpuDevice() const { return _gpuDevice; } - CC_INLINE CCVKGPUSwapchain *gpuSwapchain() { return _gpuSwapchain; } + CCVKGPUContext * gpuContext() const; + inline CCVKGPUDevice * gpuDevice() const { return _gpuDevice; } + inline CCVKGPUSwapchain *gpuSwapchain() { return _gpuSwapchain; } - CC_INLINE CCVKGPUBufferHub *gpuBufferHub() { return _gpuBufferHub; } - CC_INLINE CCVKGPUTransportHub *gpuTransportHub() { return _gpuTransportHub; } - CC_INLINE CCVKGPUDescriptorHub *gpuDescriptorHub() { return _gpuDescriptorHub; } - CC_INLINE CCVKGPUSemaphorePool *gpuSemaphorePool() { return _gpuSemaphorePool; } - CC_INLINE CCVKGPUBarrierManager *gpuBarrierManager() { return _gpuBarrierManager; } - CC_INLINE CCVKGPUDescriptorSetHub *gpuDescriptorSetHub() { return _gpuDescriptorSetHub; } + inline CCVKGPUBufferHub * gpuBufferHub() { return _gpuBufferHub; } + inline CCVKGPUTransportHub * gpuTransportHub() { return _gpuTransportHub; } + inline CCVKGPUDescriptorHub * gpuDescriptorHub() { return _gpuDescriptorHub; } + inline CCVKGPUSemaphorePool * gpuSemaphorePool() { return _gpuSemaphorePool; } + inline CCVKGPUBarrierManager * gpuBarrierManager() { return _gpuBarrierManager; } + inline CCVKGPUDescriptorSetHub *gpuDescriptorSetHub() { return _gpuDescriptorSetHub; } CCVKGPUFencePool * gpuFencePool(); CCVKGPURecycleBin * gpuRecycleBin(); CCVKGPUStagingBufferPool *gpuStagingBufferPool(); protected: - static CCVKDevice *_instance; + static CCVKDevice *instance; friend class DeviceManager; diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp index 8a9d63b766..470d673eee 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp @@ -34,21 +34,19 @@ namespace cc { namespace gfx { -CCVKFramebuffer::CCVKFramebuffer() -: Framebuffer() { -} +CCVKFramebuffer::CCVKFramebuffer() = default; CCVKFramebuffer::~CCVKFramebuffer() { destroy(); } -void CCVKFramebuffer::doInit(const FramebufferInfo &info) { - _gpuFBO = CC_NEW(CCVKGPUFramebuffer); +void CCVKFramebuffer::doInit(const FramebufferInfo & /*info*/) { + _gpuFBO = CC_NEW(CCVKGPUFramebuffer); _gpuFBO->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorViews.resize(_colorTextures.size()); for (size_t i = 0; i < _colorTextures.size(); ++i) { - CCVKTexture *colorTex = (CCVKTexture *)_colorTextures[i]; + auto *colorTex = static_cast(_colorTextures[i]); if (colorTex) { _gpuFBO->gpuColorViews[i] = colorTex->gpuTextureView(); } @@ -58,7 +56,7 @@ void CCVKFramebuffer::doInit(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilView = static_cast(_depthStencilTexture)->gpuTextureView(); } - CCVKCmdFuncCreateFramebuffer(CCVKDevice::getInstance(), _gpuFBO); + cmdFuncCCVKCreateFramebuffer(CCVKDevice::getInstance(), _gpuFBO); } void CCVKFramebuffer::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index b8f96dacc7..94b8e4d2d6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -25,8 +25,12 @@ #pragma once +#include #include +#include "base/CachedArray.h" + +#include "VKStd.h" #include "VKUtils.h" #define TBB_USE_EXCEPTIONS 0 // no-rtti for now @@ -85,12 +89,12 @@ public: TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; TextureUsage usage = TextureUsageBit::NONE; - uint width = 0u; - uint height = 0u; - uint depth = 1u; - uint size = 0u; - uint arrayLayers = 1u; - uint mipLevels = 1u; + uint width = 0U; + uint height = 0U; + uint depth = 1U; + uint size = 0U; + uint arrayLayers = 1U; + uint mipLevels = 1U; SampleCount samples = SampleCount::X1; TextureFlags flags = TextureFlagBit::NONE; VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -110,10 +114,10 @@ public: CCVKGPUTexture *gpuTexture = nullptr; TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; - uint baseLevel = 0u; - uint levelCount = 1u; - uint baseLayer = 0u; - uint layerCount = 1u; + uint baseLevel = 0U; + uint levelCount = 1U; + uint baseLayer = 0U; + uint layerCount = 1U; // descriptor infos VkImageView vkImageView = VK_NULL_HANDLE; @@ -128,10 +132,10 @@ public: Address addressU = Address::WRAP; Address addressV = Address::WRAP; Address addressW = Address::WRAP; - uint maxAnisotropy = 0u; + uint maxAnisotropy = 0U; ComparisonFunc cmpFunc = ComparisonFunc::NEVER; Color borderColor; - float mipLODBias = 0.0f; + float mipLODBias = 0.0F; // descriptor infos VkSampler vkSampler; @@ -141,8 +145,8 @@ class CCVKGPUBuffer final : public Object { public: BufferUsage usage = BufferUsage::NONE; MemoryUsage memUsage = MemoryUsage::NONE; - uint stride = 0u; - uint count = 0u; + uint stride = 0U; + uint count = 0U; void * buffer = nullptr; bool isDrawIndirectByIndex = false; @@ -154,10 +158,10 @@ public: // descriptor infos VkBuffer vkBuffer = VK_NULL_HANDLE; - VkDeviceSize startOffset = 0u; - VkDeviceSize size = 0u; + VkDeviceSize startOffset = 0U; + VkDeviceSize size = 0U; - VkDeviceSize instanceSize = 0u; // per-back-buffer instance + VkDeviceSize instanceSize = 0U; // per-back-buffer instance // for barrier manager vector renderAccessTypes; // gathered from descriptor sets @@ -168,8 +172,8 @@ using CCVKGPUBufferList = vector; class CCVKGPUBufferView final : public Object { public: CCVKGPUBuffer *gpuBuffer = nullptr; - uint offset = 0u; - uint range = 0u; + uint offset = 0U; + uint range = 0U; }; class CCVKGPUSwapchain; @@ -183,13 +187,13 @@ public: bool isOffscreen = true; }; -using FramebufferList = vector; -using FramebufferListMap = unordered_map; +using FramebufferList = vector; +using FramebufferListMap = unordered_map; using FramebufferListMapIter = FramebufferListMap::iterator; class CCVKGPUSwapchain final : public Object { public: - uint curImageIndex = 0u; + uint curImageIndex = 0U; VkSwapchainKHR vkSwapchain = VK_NULL_HANDLE; vector vkSwapchainImageViews; FramebufferListMap vkSwapchainFramebufferListMap; @@ -205,7 +209,7 @@ class CCVKGPUCommandBuffer final : public Object { public: VkCommandBuffer vkCommandBuffer = VK_NULL_HANDLE; VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - uint queueFamilyIndex = 0u; + uint queueFamilyIndex = 0U; bool began = false; mutable unordered_set recordedBuffers; }; @@ -214,7 +218,7 @@ class CCVKGPUQueue final : public Object { public: QueueType type = QueueType::GRAPHICS; VkQueue vkQueue = VK_NULL_HANDLE; - uint queueFamilyIndex = 0u; + uint queueFamilyIndex = 0U; VkSemaphore nextWaitSemaphore = VK_NULL_HANDLE; VkSemaphore nextSignalSemaphore = VK_NULL_HANDLE; VkPipelineStageFlags submitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; @@ -280,7 +284,7 @@ public: }; vector instances; // per swapchain image - uint layoutID = 0u; + uint layoutID = 0U; }; using CCVKGPUDescriptorSetLayoutList = vector; @@ -313,8 +317,8 @@ public: class CCVKGPUGlobalBarrier final : public Object { public: - VkPipelineStageFlags srcStageMask = 0u; - VkPipelineStageFlags dstStageMask = 0u; + VkPipelineStageFlags srcStageMask = 0U; + VkPipelineStageFlags dstStageMask = 0U; VkMemoryBarrier vkBarrier{}; vector accessTypes; @@ -323,8 +327,8 @@ public: class CCVKGPUTextureBarrier final : public Object { public: - VkPipelineStageFlags srcStageMask = 0u; - VkPipelineStageFlags dstStageMask = 0u; + VkPipelineStageFlags srcStageMask = 0U; + VkPipelineStageFlags dstStageMask = 0U; VkImageMemoryBarrier vkBarrier{}; vector accessTypes; @@ -340,10 +344,10 @@ public: vector extensions; VmaAllocator memoryAllocator = VK_NULL_HANDLE; VkPipelineCache vkPipelineCache = VK_NULL_HANDLE; - uint minorVersion = 0u; + uint minorVersion = 0U; - uint curBackBufferIndex = 0u; - uint backBufferCount = 3u; + uint curBackBufferIndex = 0U; + uint backBufferCount = 3U; bool useDescriptorUpdateTemplate = false; bool useMultiDrawIndirect = false; @@ -384,7 +388,7 @@ public: : _device(device) { } - ~CCVKGPUFencePool() { + ~CCVKGPUFencePool() override { for (VkFence fence : _fences) { vkDestroyFence(_device->vkDevice, fence, nullptr); } @@ -423,7 +427,7 @@ public: private: CCVKGPUDevice * _device = nullptr; - uint _count = 0u; + uint _count = 0U; vector _fences; }; @@ -436,7 +440,7 @@ public: : _device(device) { } - ~CCVKGPUSemaphorePool() { + ~CCVKGPUSemaphorePool() override { for (VkSemaphore semaphore : _semaphores) { vkDestroySemaphore(_device->vkDevice, semaphore, nullptr); } @@ -468,7 +472,7 @@ public: private: CCVKGPUDevice * _device; - uint _count = 0u; + uint _count = 0U; vector _semaphores; }; @@ -477,20 +481,19 @@ private: */ class CCVKGPUDescriptorSetPool final : public Object { public: - ~CCVKGPUDescriptorSetPool() { + ~CCVKGPUDescriptorSetPool() override { for (vector &market : _fleaMarkets) { for (VkDescriptorSet set : market) { for (DescriptorSetPool &pool : _pools) { if (pool.activeSets.count(set)) { pool.activeSets.erase(set); - pool.freeSets.push_back(set); break; } } } } - uint leakedSetCount = 0u; + uint leakedSetCount = 0U; for (DescriptorSetPool &pool : _pools) { leakedSetCount += pool.activeSets.size(); vkDestroyDescriptorPool(_device->vkDevice, pool.vkPool, nullptr); @@ -500,14 +503,14 @@ public: _pools.clear(); } - void link(CCVKGPUDevice *device, uint maxSetsPerPool, vector &bindings, VkDescriptorSetLayout setLayout) { + void link(CCVKGPUDevice *device, uint maxSetsPerPool, const vector &bindings, VkDescriptorSetLayout setLayout) { _device = device; _maxSetsPerPool = maxSetsPerPool; _setLayouts.insert(_setLayouts.cbegin(), _maxSetsPerPool, setLayout); _fleaMarkets.resize(device->backBufferCount); unordered_map typeMap; - for (auto & vkBinding : bindings) { + for (const auto &vkBinding : bindings) { typeMap[vkBinding.descriptorType] += maxSetsPerPool * vkBinding.descriptorCount; } @@ -517,7 +520,7 @@ public: } _poolSizes.clear(); - for (auto & it : typeMap) { + for (auto &it : typeMap) { _poolSizes.push_back({it.first, it.second}); } } @@ -532,7 +535,7 @@ public: } size_t size = _pools.size(); - uint idx = 0u; + uint idx = 0U; for (; idx < size; idx++) { if (!_pools[idx].freeSets.empty()) { output = _pools[idx].freeSets.back(); @@ -545,7 +548,7 @@ public: if (idx >= size) { VkDescriptorPoolCreateInfo createInfo{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; createInfo.maxSets = _maxSetsPerPool; - createInfo.poolSizeCount = toUint(_poolSizes.size()); + createInfo.poolSizeCount = utils::toUint(_poolSizes.size()); createInfo.pPoolSizes = _poolSizes.data(); VkDescriptorPool descriptorPool = VK_NULL_HANDLE; @@ -592,7 +595,7 @@ private: vector _poolSizes; vector _setLayouts; - uint _maxSetsPerPool = 0u; + uint _maxSetsPerPool = 0U; }; class CCVKGPUDescriptorSetLayout final : public Object { @@ -607,10 +610,10 @@ public: vector bindingIndices; vector descriptorIndices; - uint descriptorCount = 0u; + uint descriptorCount = 0U; - uint id = 0u; - uint maxSetsPerPool = 10u; + uint id = 0U; + uint maxSetsPerPool = 10U; }; /** @@ -622,8 +625,8 @@ public: : _device(device) { } - ~CCVKGPUCommandBufferPool() { - for (auto & it : _pools) { + ~CCVKGPUCommandBufferPool() override { + for (auto &it : _pools) { CommandBufferPool &pool = it.second; if (pool.vkCommandPool != VK_NULL_HANDLE) { vkDestroyCommandPool(_device->vkDevice, pool.vkCommandPool, nullptr); @@ -638,7 +641,7 @@ public: uint getHash(uint queueFamilyIndex) { return (queueFamilyIndex << 10) | _device->curBackBufferIndex; } - uint getBackBufferIndex(uint hash) { + static uint getBackBufferIndex(uint hash) { return hash & ((1 << 10) - 1); } @@ -682,12 +685,14 @@ public: } void reset() { - for (auto & it : _pools) { - if (getBackBufferIndex(it.first) != _device->curBackBufferIndex) { continue; } + for (auto &it : _pools) { + if (getBackBufferIndex(it.first) != _device->curBackBufferIndex) { + continue; + } CommandBufferPool &pool = it.second; bool needsReset = false; - for (uint i = 0u; i < 2u; ++i) { + for (uint i = 0U; i < 2U; ++i) { CachedArray &usedList = pool.usedCommandBuffers[i]; if (usedList.size()) { pool.commandBuffers[i].concat(usedList); @@ -709,7 +714,7 @@ private: }; CCVKGPUDevice *_device = nullptr; - uint _lastBackBufferIndex = 0u; + uint _lastBackBufferIndex = 0U; unordered_map _pools; }; @@ -724,19 +729,19 @@ public: : _device(device) { } - ~CCVKGPUStagingBufferPool() { + ~CCVKGPUStagingBufferPool() override { for (Buffer &buffer : _pool) { vmaDestroyBuffer(_device->memoryAllocator, buffer.vkBuffer, buffer.vmaAllocation); } _pool.clear(); } - void alloc(CCVKGPUBuffer *gpuBuffer) { alloc(gpuBuffer, 1u); } + void alloc(CCVKGPUBuffer *gpuBuffer) { alloc(gpuBuffer, 1U); } void alloc(CCVKGPUBuffer *gpuBuffer, uint alignment) { size_t bufferCount = _pool.size(); Buffer * buffer = nullptr; - VkDeviceSize offset = 0u; - for (size_t idx = 0u; idx < bufferCount; idx++) { + VkDeviceSize offset = 0U; + for (size_t idx = 0U; idx < bufferCount; idx++) { Buffer *cur = &_pool[idx]; offset = roundUp(cur->curOffset, alignment); if (CHUNK_SIZE - offset >= gpuBuffer->size) { @@ -756,7 +761,7 @@ public: VmaAllocationInfo res; VK_CHECK(vmaCreateBuffer(_device->memoryAllocator, &bufferInfo, &allocInfo, &buffer->vkBuffer, &buffer->vmaAllocation, &res)); buffer->mappedData = reinterpret_cast(res.pMappedData); - offset = 0u; + offset = 0U; } gpuBuffer->vkBuffer = buffer->vkBuffer; gpuBuffer->startOffset = offset; @@ -766,7 +771,7 @@ public: void reset() { for (Buffer &buffer : _pool) { - buffer.curOffset = 0u; + buffer.curOffset = 0U; } } @@ -776,7 +781,7 @@ private: uint8_t * mappedData = nullptr; VmaAllocation vmaAllocation = VK_NULL_HANDLE; - VkDeviceSize curOffset = 0u; + VkDeviceSize curOffset = 0U; }; CCVKGPUDevice *_device = nullptr; @@ -800,7 +805,7 @@ public: void record(const CCVKGPUDescriptorSet *gpuDescriptorSet) { update(gpuDescriptorSet); - for (uint i = 0u; i < _device->backBufferCount; ++i) { + for (uint i = 0U; i < _device->backBufferCount; ++i) { if (i == _device->curBackBufferIndex) { _setsToBeUpdated[i].erase(gpuDescriptorSet); } else { @@ -810,7 +815,7 @@ public: } void erase(CCVKGPUDescriptorSet *gpuDescriptorSet) { - for (uint i = 0u; i < _device->backBufferCount; ++i) { + for (uint i = 0U; i < _device->backBufferCount; ++i) { if (_setsToBeUpdated[i].count(gpuDescriptorSet)) { _setsToBeUpdated[i].erase(gpuDescriptorSet); } @@ -833,7 +838,7 @@ private: gpuDescriptorSet->gpuLayout->vkDescriptorUpdateTemplate, instance.descriptorInfos.data()); } else { const vector &entries = instance.descriptorUpdateEntries; - vkUpdateDescriptorSets(_device->vkDevice, toUint(entries.size()), entries.data(), 0, nullptr); + vkUpdateDescriptorSets(_device->vkDevice, utils::toUint(entries.size()), entries.data(), 0, nullptr); } } @@ -874,7 +879,7 @@ public: auto it = _buffers.find(buffer); if (it == _buffers.end()) return; auto &info = it->second; - for (uint i = 0u; i < info.descriptors.size(); i++) { + for (uint i = 0U; i < info.descriptors.size(); i++) { doUpdate(buffer, info.descriptors[i]); } for (const auto *set : info.sets) { @@ -885,7 +890,7 @@ public: auto it = _buffers.find(buffer); if (it == _buffers.end()) return; auto &descriptors = it->second.descriptors; - for (uint i = 0u; i < descriptors.size(); i++) { + for (uint i = 0U; i < descriptors.size(); i++) { if (descriptors[i] == descriptor) { doUpdate(buffer, descriptor); break; @@ -896,7 +901,7 @@ public: auto it = _textures.find(texture); if (it == _textures.end()) return; auto &info = it->second; - for (uint i = 0u; i < info.descriptors.size(); i++) { + for (uint i = 0U; i < info.descriptors.size(); i++) { doUpdate(texture, info.descriptors[i]); } for (const auto *set : info.sets) { @@ -907,7 +912,7 @@ public: auto it = _textures.find(texture); if (it == _textures.end()) return; auto &descriptors = it->second.descriptors; - for (uint i = 0u; i < descriptors.size(); i++) { + for (uint i = 0U; i < descriptors.size(); i++) { if (descriptors[i] == descriptor) { doUpdate(texture, descriptor); break; @@ -918,7 +923,7 @@ public: auto it = _samplers.find(sampler); if (it == _samplers.end()) return; auto &descriptors = it->second; - for (uint i = 0u; i < descriptors.size(); ++i) { + for (uint i = 0U; i < descriptors.size(); ++i) { if (descriptors[i] == descriptor) { doUpdate(sampler, descriptor); break; @@ -972,11 +977,11 @@ private: descriptor->range = buffer->range; } - void doUpdate(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { + static void doUpdate(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { descriptor->imageView = texture->vkImageView; } - void doUpdate(const CCVKGPUSampler *sampler, VkDescriptorImageInfo *descriptor) { + static void doUpdate(const CCVKGPUSampler *sampler, VkDescriptorImageInfo *descriptor) { descriptor->sampler = sampler->vkSampler; } @@ -1005,15 +1010,16 @@ public: _resources.resize(16); } -#define DEFINE_RECYCLE_BIN_COLLECT_FN(_type, typeValue, expr) \ - void collect(_type *gpuRes) { \ - if (_resources.size() <= _count) { \ - _resources.resize(_count * 2); \ - } \ - Resource &res = _resources[_count++]; \ - res.type = typeValue; \ - expr; \ +#define DEFINE_RECYCLE_BIN_COLLECT_FN(_type, typeValue, expr) \ + void collect(_type *gpuRes) { /* NOLINT(bugprone-macro-parentheses) N/A */ \ + if (_resources.size() <= _count) { \ + _resources.resize(_count * 2); \ + } \ + Resource &res = _resources[_count++]; \ + res.type = typeValue; \ + expr; \ } + DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUBuffer, RecycledType::BUFFER, (res.buffer = {gpuRes->vkBuffer, gpuRes->vmaAllocation})) DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTexture, RecycledType::TEXTURE, (res.image = {gpuRes->vkImage, gpuRes->vmaAllocation})) DEFINE_RECYCLE_BIN_COLLECT_FN(CCVKGPUTextureView, RecycledType::TEXTURE_VIEW, res.vkImageView = gpuRes->vkImageView) @@ -1050,7 +1056,7 @@ private: VmaAllocation vmaAllocation; }; struct Resource { - RecycledType type = RecycledType::UNKNOWN; + RecycledType type = RecycledType::UNKNOWN; union { // resizable resources, cannot take over directly // or descriptor sets won't work @@ -1069,7 +1075,7 @@ private: }; CCVKGPUDevice * _device = nullptr; vector _resources; - uint _count = 0u; + uint _count = 0U; }; /** @@ -1089,7 +1095,7 @@ public: VK_CHECK(vkCreateFence(_device->vkDevice, &createInfo, nullptr, &_fence)); } - ~CCVKGPUTransportHub() { + ~CCVKGPUTransportHub() override { if (_fence) { vkDestroyFence(_device->vkDevice, _fence, nullptr); _fence = VK_NULL_HANDLE; @@ -1164,7 +1170,7 @@ public: void checkIn(CCVKGPUTexture *gpuTexture, const ThsvsAccessType *newTypes = nullptr, uint newTypeCount = 0) { vector &target = gpuTexture->renderAccessTypes; - for (uint i = 0u; i < newTypeCount; ++i) { + for (uint i = 0U; i < newTypeCount; ++i) { if (std::find(target.begin(), target.end(), newTypes[i]) == target.end()) { target.push_back(newTypes[i]); } @@ -1197,7 +1203,7 @@ public: uint backBufferIndex = _device->curBackBufferIndex; uint8_t *dst = gpuBuffer->mappedData + backBufferIndex * gpuBuffer->instanceSize; memcpy(dst, src, size); - for (uint i = 0u; i < _device->backBufferCount; ++i) { + for (uint i = 0U; i < _device->backBufferCount; ++i) { if (i == backBufferIndex) { _buffersToBeUpdated[i].erase(gpuBuffer); } else { @@ -1207,7 +1213,7 @@ public: } void erase(CCVKGPUBuffer *gpuBuffer) { - for (uint i = 0u; i < _device->backBufferCount; ++i) { + for (uint i = 0U; i < _device->backBufferCount; ++i) { if (_buffersToBeUpdated[i].count(gpuBuffer)) { _buffersToBeUpdated[i].erase(gpuBuffer); } @@ -1218,7 +1224,7 @@ public: auto &buffers = _buffersToBeUpdated[_device->curBackBufferIndex]; transportHub->checkIn([&](const CCVKGPUCommandBuffer *gpuCommandBuffer) { VkBufferCopy region; - for (auto & buffer : buffers) { + for (auto &buffer : buffers) { region.srcOffset = buffer.first->startOffset + buffer.second.srcIndex * buffer.first->instanceSize; region.dstOffset = buffer.first->startOffset + _device->curBackBufferIndex * buffer.first->instanceSize; region.size = buffer.second.size; @@ -1230,8 +1236,8 @@ public: private: struct BufferUpdate { - uint srcIndex = 0u; - size_t size = 0u; + uint srcIndex = 0U; + size_t size = 0U; }; vector> _buffersToBeUpdated; diff --git a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp index 122fd275c5..575e5d5dc6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp @@ -31,9 +31,7 @@ namespace cc { namespace gfx { -CCVKGlobalBarrier::CCVKGlobalBarrier() -: GlobalBarrier() { -} +CCVKGlobalBarrier::CCVKGlobalBarrier() = default; CCVKGlobalBarrier::~CCVKGlobalBarrier() { CC_SAFE_DELETE(_gpuBarrier); @@ -43,12 +41,12 @@ void CCVKGlobalBarrier::doInit(const GlobalBarrierInfo &info) { _gpuBarrier = CC_NEW(CCVKGPUGlobalBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); - uint index = 0u; + uint index = 0U; for (AccessType type : info.prevAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[(uint)type]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } for (AccessType type : info.nextAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[(uint)type]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } _gpuBarrier->barrier.prevAccessCount = info.prevAccesses.size(); diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp index 60dcd0bd33..dfb3045550 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp @@ -26,16 +26,14 @@ #include "VKStd.h" #include "VKBuffer.h" -#include "VKDevice.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKInputAssembler.h" namespace cc { namespace gfx { -CCVKInputAssembler::CCVKInputAssembler() -: InputAssembler() { -} +CCVKInputAssembler::CCVKInputAssembler() = default; CCVKInputAssembler::~CCVKInputAssembler() { destroy(); @@ -44,12 +42,12 @@ CCVKInputAssembler::~CCVKInputAssembler() { void CCVKInputAssembler::doInit(const InputAssemblerInfo &info) { size_t vbCount = _vertexBuffers.size(); - _gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler); + _gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler); _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(vbCount); - for (size_t i = 0u; i < vbCount; ++i) { - CCVKBuffer *vb = (CCVKBuffer *)_vertexBuffers[i]; + for (size_t i = 0U; i < vbCount; ++i) { + auto *vb = static_cast(_vertexBuffers[i]); _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } @@ -64,8 +62,8 @@ void CCVKInputAssembler::doInit(const InputAssemblerInfo &info) { _gpuInputAssembler->vertexBuffers.resize(vbCount); _gpuInputAssembler->vertexBufferOffsets.resize(vbCount); - for (size_t i = 0u; i < vbCount; i++) { - _gpuInputAssembler->vertexBuffers[i] = _gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; + for (size_t i = 0U; i < vbCount; i++) { + _gpuInputAssembler->vertexBuffers[i] = _gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; _gpuInputAssembler->vertexBufferOffsets[i] = _gpuInputAssembler->gpuVertexBuffers[i]->startOffset; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp index 2921729295..c5a12aa904 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp @@ -33,20 +33,17 @@ namespace cc { namespace gfx { -CCVKPipelineLayout::CCVKPipelineLayout() -: PipelineLayout() { -} +CCVKPipelineLayout::CCVKPipelineLayout() = default; CCVKPipelineLayout::~CCVKPipelineLayout() { destroy(); } -void CCVKPipelineLayout::doInit(const PipelineLayoutInfo &info) { +void CCVKPipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { _gpuPipelineLayout = CC_NEW(CCVKGPUPipelineLayout); - int offset = 0u; - for (uint i = 0u; i < _setLayouts.size(); i++) { - DescriptorSetLayout *setLayout = _setLayouts[i]; + int offset = 0U; + for (auto *setLayout : _setLayouts) { CCVKGPUDescriptorSetLayout *gpuSetLayout = static_cast(setLayout)->gpuDescriptorSetLayout(); size_t dynamicCount = gpuSetLayout->dynamicBindings.size(); _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); @@ -56,7 +53,7 @@ void CCVKPipelineLayout::doInit(const PipelineLayoutInfo &info) { _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); _gpuPipelineLayout->dynamicOffsetCount = offset; - CCVKCmdFuncCreatePipelineLayout(CCVKDevice::getInstance(), _gpuPipelineLayout); + cmdFuncCCVKCreatePipelineLayout(CCVKDevice::getInstance(), _gpuPipelineLayout); } void CCVKPipelineLayout::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp index 40c2f0f1b0..ba39897cd8 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp @@ -35,15 +35,13 @@ namespace cc { namespace gfx { -CCVKPipelineState::CCVKPipelineState() -: PipelineState() { -} +CCVKPipelineState::CCVKPipelineState() = default; CCVKPipelineState::~CCVKPipelineState() { destroy(); } -void CCVKPipelineState::doInit(const PipelineStateInfo &info) { +void CCVKPipelineState::doInit(const PipelineStateInfo & /*info*/) { _gpuPipelineState = CC_NEW(CCVKGPUPipelineState); _gpuPipelineState->bindPoint = _bindPoint; _gpuPipelineState->primitive = _primitive; @@ -56,15 +54,15 @@ void CCVKPipelineState::doInit(const PipelineStateInfo &info) { if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); for (uint i = 0; i < 31; i++) { - if ((uint)_dynamicStates & (1 << i)) { - _gpuPipelineState->dynamicStates.push_back((DynamicStateFlagBit)(1 << i)); + if (static_cast(_dynamicStates) & (1 << i)) { + _gpuPipelineState->dynamicStates.push_back(static_cast(1 << i)); } } if (_bindPoint == PipelineBindPoint::GRAPHICS) { - CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice::getInstance(), _gpuPipelineState); + cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice::getInstance(), _gpuPipelineState); } else { - CCVKCmdFuncCreateComputePipelineState(CCVKDevice::getInstance(), _gpuPipelineState); + cmdFuncCCVKCreateComputePipelineState(CCVKDevice::getInstance(), _gpuPipelineState); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp index 84d3965627..cb57c34e2e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp @@ -33,18 +33,16 @@ namespace cc { namespace gfx { -CCVKQueue::CCVKQueue() -: Queue() { -} +CCVKQueue::CCVKQueue() = default; CCVKQueue::~CCVKQueue() { destroy(); } -void CCVKQueue::doInit(const QueueInfo &info) { +void CCVKQueue::doInit(const QueueInfo & /*info*/) { _gpuQueue = CC_NEW(CCVKGPUQueue); _gpuQueue->type = _type; - CCVKCmdFuncGetDeviceQueue(CCVKDevice::getInstance(), _gpuQueue); + cmdFuncCCVKGetDeviceQueue(CCVKDevice::getInstance(), _gpuQueue); } void CCVKQueue::doDestroy() { @@ -67,8 +65,8 @@ void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { _gpuQueue->commandBuffers.push(device->gpuTransportHub()->packageForFlight()); } - for (uint i = 0u; i < count; ++i) { - CCVKCommandBuffer *cmdBuff = (CCVKCommandBuffer *)cmdBuffs[i]; + for (uint i = 0U; i < count; ++i) { + auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingQueue.empty()) { _gpuQueue->commandBuffers.push(cmdBuff->_pendingQueue.front()); cmdBuff->_pendingQueue.pop(); diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.h b/native/cocos/renderer/gfx-vulkan/VKQueue.h index 0bbb364a79..3bba692b89 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.h +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXQueue.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPUQueue; class CC_VULKAN_API CCVKQueue final : public Queue { public: CCVKQueue(); - ~CCVKQueue(); + ~CCVKQueue() override; void submit(CommandBuffer *const *cmdBuffs, uint count) override; diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp index 83c2f43d4e..e7d041e2e5 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp @@ -32,20 +32,18 @@ namespace cc { namespace gfx { -CCVKRenderPass::CCVKRenderPass() -: RenderPass() { -} +CCVKRenderPass::CCVKRenderPass() = default; CCVKRenderPass::~CCVKRenderPass() { destroy(); } -void CCVKRenderPass::doInit(const RenderPassInfo &info) { +void CCVKRenderPass::doInit(const RenderPassInfo & /*info*/) { _gpuRenderPass = CC_NEW(CCVKGPURenderPass); _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; _gpuRenderPass->subpasses = _subpasses; - CCVKCmdFuncCreateRenderPass(CCVKDevice::getInstance(), _gpuRenderPass); + cmdFuncCCVKCreateRenderPass(CCVKDevice::getInstance(), _gpuRenderPass); } void CCVKRenderPass::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKSampler.cpp b/native/cocos/renderer/gfx-vulkan/VKSampler.cpp index b5ee8ce59e..d314afd3c6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSampler.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKSampler.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -CCVKSampler::CCVKSampler() -: Sampler() { -} +CCVKSampler::CCVKSampler() = default; CCVKSampler::~CCVKSampler() { destroy(); } -void CCVKSampler::doInit(const SamplerInfo &info) { +void CCVKSampler::doInit(const SamplerInfo & /*info*/) { _gpuSampler = CC_NEW(CCVKGPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; @@ -53,7 +51,7 @@ void CCVKSampler::doInit(const SamplerInfo &info) { _gpuSampler->borderColor = _borderColor; _gpuSampler->mipLODBias = _mipLODBias; - CCVKCmdFuncCreateSampler(CCVKDevice::getInstance(), _gpuSampler); + cmdFuncCCVKCreateSampler(CCVKDevice::getInstance(), _gpuSampler); } void CCVKSampler::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.cpp b/native/cocos/renderer/gfx-vulkan/VKShader.cpp index c24ff97228..6272727634 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKShader.cpp @@ -32,15 +32,13 @@ namespace cc { namespace gfx { -CCVKShader::CCVKShader() -: Shader() { -} +CCVKShader::CCVKShader() = default; CCVKShader::~CCVKShader() { destroy(); } -void CCVKShader::doInit(const ShaderInfo &info) { +void CCVKShader::doInit(const ShaderInfo & /*info*/) { _gpuShader = CC_NEW(CCVKGPUShader); _gpuShader->name = _name; _gpuShader->attributes = _attributes; @@ -50,7 +48,7 @@ void CCVKShader::doInit(const ShaderInfo &info) { _gpuShader->gpuStages.push_back({stage.stage, stage.source}); } - CCVKCmdFuncCreateShader(CCVKDevice::getInstance(), _gpuShader); + cmdFuncCCVKCreateShader(CCVKDevice::getInstance(), _gpuShader); } void CCVKShader::doDestroy() { diff --git a/native/cocos/renderer/gfx-vulkan/VKStd.h b/native/cocos/renderer/gfx-vulkan/VKStd.h index 4308ada8c5..d65dd00963 100644 --- a/native/cocos/renderer/gfx-vulkan/VKStd.h +++ b/native/cocos/renderer/gfx-vulkan/VKStd.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __CC_GFXVULKAN_VK_STD_H__ -#define __CC_GFXVULKAN_VK_STD_H__ +#pragma once #include "base/CoreStd.h" @@ -55,5 +54,3 @@ #else #define VK_CHECK(x) x #endif - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp index 5cc9f97bc9..0d4c4e036a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp @@ -33,15 +33,13 @@ namespace cc { namespace gfx { -CCVKTexture::CCVKTexture() -: Texture() { -} +CCVKTexture::CCVKTexture() = default; CCVKTexture::~CCVKTexture() { destroy(); } -void CCVKTexture::doInit(const TextureInfo &info) { +void CCVKTexture::doInit(const TextureInfo & /*info*/) { _gpuTexture = CC_NEW(CCVKGPUTexture); _gpuTexture->type = _type; _gpuTexture->format = _format; @@ -55,7 +53,7 @@ void CCVKTexture::doInit(const TextureInfo &info) { _gpuTexture->samples = _samples; _gpuTexture->flags = _flags; - CCVKCmdFuncCreateTexture(CCVKDevice::getInstance(), _gpuTexture); + cmdFuncCCVKCreateTexture(CCVKDevice::getInstance(), _gpuTexture); _gpuTextureView = CC_NEW(CCVKGPUTextureView); createTextureView(); @@ -76,7 +74,7 @@ void CCVKTexture::createTextureView() { _gpuTextureView->levelCount = _levelCount; _gpuTextureView->baseLayer = _baseLayer; _gpuTextureView->layerCount = _layerCount; - CCVKCmdFuncCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); + cmdFuncCCVKCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); } void CCVKTexture::doDestroy() { @@ -104,9 +102,9 @@ void CCVKTexture::doResize(uint width, uint height, uint size) { _gpuTexture->width = width; _gpuTexture->height = height; _gpuTexture->size = size; - CCVKCmdFuncCreateTexture(CCVKDevice::getInstance(), _gpuTexture); + cmdFuncCCVKCreateTexture(CCVKDevice::getInstance(), _gpuTexture); - CCVKCmdFuncCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); + cmdFuncCCVKCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp index 57e048c5fb..bd8aa92de0 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp @@ -32,9 +32,7 @@ namespace cc { namespace gfx { -CCVKTextureBarrier::CCVKTextureBarrier() -: TextureBarrier() { -} +CCVKTextureBarrier::CCVKTextureBarrier() = default; CCVKTextureBarrier::~CCVKTextureBarrier() { CC_SAFE_DELETE(_gpuBarrier); @@ -44,12 +42,12 @@ void CCVKTextureBarrier::doInit(const TextureBarrierInfo &info) { _gpuBarrier = CC_NEW(CCVKGPUTextureBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); - uint index = 0u; + uint index = 0U; for (AccessType type : info.prevAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[(uint)type]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } for (AccessType type : info.nextAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[(uint)type]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } _gpuBarrier->barrier.prevAccessCount = info.prevAccesses.size(); @@ -59,9 +57,9 @@ void CCVKTextureBarrier::doInit(const TextureBarrierInfo &info) { _gpuBarrier->barrier.prevLayout = _gpuBarrier->barrier.nextLayout = THSVS_IMAGE_LAYOUT_OPTIMAL; _gpuBarrier->barrier.discardContents = info.discardContents; - _gpuBarrier->barrier.subresourceRange.baseMipLevel = 0u; + _gpuBarrier->barrier.subresourceRange.baseMipLevel = 0U; _gpuBarrier->barrier.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; - _gpuBarrier->barrier.subresourceRange.baseArrayLayer = 0u; + _gpuBarrier->barrier.subresourceRange.baseArrayLayer = 0U; _gpuBarrier->barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; _gpuBarrier->barrier.srcQueueFamilyIndex = info.srcQueue ? static_cast(info.srcQueue)->gpuQueue()->queueFamilyIndex diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.cpp b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp new file mode 100644 index 0000000000..28b178b03f --- /dev/null +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp @@ -0,0 +1,607 @@ +/**************************************************************************** + Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#include "VKUtils.h" + +namespace cc { +namespace gfx { + +VkFormat mapVkFormat(Format format) { + switch (format) { + case Format::R8: return VK_FORMAT_R8_UNORM; + case Format::R8SN: return VK_FORMAT_R8_SNORM; + case Format::R8UI: return VK_FORMAT_R8_UINT; + case Format::R8I: return VK_FORMAT_R8_SINT; + case Format::RG8: return VK_FORMAT_R8G8_UNORM; + case Format::RG8SN: return VK_FORMAT_R8G8_SNORM; + case Format::RG8UI: return VK_FORMAT_R8G8_UINT; + case Format::RG8I: return VK_FORMAT_R8G8_SINT; + case Format::RGB8: return VK_FORMAT_R8G8B8_UNORM; + case Format::RGB8SN: return VK_FORMAT_R8G8B8_SNORM; + case Format::RGB8UI: return VK_FORMAT_R8G8B8_UINT; + case Format::RGB8I: return VK_FORMAT_R8G8B8_SINT; + case Format::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM; + case Format::BGRA8: return VK_FORMAT_B8G8R8A8_UNORM; + case Format::SRGB8_A8: return VK_FORMAT_R8G8B8A8_SRGB; + case Format::RGBA8SN: return VK_FORMAT_R8G8B8A8_SNORM; + case Format::RGBA8UI: return VK_FORMAT_R8G8B8A8_UINT; + case Format::RGBA8I: return VK_FORMAT_R8G8B8A8_SINT; + case Format::R16I: return VK_FORMAT_R16_SINT; + case Format::R16UI: return VK_FORMAT_R16_UINT; + case Format::R16F: return VK_FORMAT_R16_SFLOAT; + case Format::RG16I: return VK_FORMAT_R16G16_SINT; + case Format::RG16UI: return VK_FORMAT_R16G16_UINT; + case Format::RG16F: return VK_FORMAT_R16G16_SFLOAT; + case Format::RGB16I: return VK_FORMAT_R16G16B16_SINT; + case Format::RGB16UI: return VK_FORMAT_R16G16B16_UINT; + case Format::RGB16F: return VK_FORMAT_R16G16B16_SFLOAT; + case Format::RGBA16I: return VK_FORMAT_R16G16B16A16_SINT; + case Format::RGBA16UI: return VK_FORMAT_R16G16B16A16_UINT; + case Format::RGBA16F: return VK_FORMAT_R16G16B16A16_SFLOAT; + case Format::R32I: return VK_FORMAT_R32_SINT; + case Format::R32UI: return VK_FORMAT_R32_UINT; + case Format::R32F: return VK_FORMAT_R32_SFLOAT; + case Format::RG32I: return VK_FORMAT_R32G32_SINT; + case Format::RG32UI: return VK_FORMAT_R32G32_UINT; + case Format::RG32F: return VK_FORMAT_R32G32_SFLOAT; + case Format::RGB32I: return VK_FORMAT_R32G32B32_SINT; + case Format::RGB32UI: return VK_FORMAT_R32G32B32_UINT; + case Format::RGB32F: return VK_FORMAT_R32G32B32_SFLOAT; + case Format::RGBA32I: return VK_FORMAT_R32G32B32A32_SINT; + case Format::RGBA32UI: return VK_FORMAT_R32G32B32A32_UINT; + case Format::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT; + + case Format::R5G6B5: return VK_FORMAT_R5G6B5_UNORM_PACK16; + case Format::R11G11B10F: return VK_FORMAT_B10G11R11_UFLOAT_PACK32; + case Format::RGB5A1: return VK_FORMAT_R5G5B5A1_UNORM_PACK16; + case Format::RGBA4: return VK_FORMAT_R4G4B4A4_UNORM_PACK16; + case Format::RGB10A2: return VK_FORMAT_A2B10G10R10_UNORM_PACK32; + case Format::RGB10A2UI: return VK_FORMAT_A2B10G10R10_UINT_PACK32; + case Format::RGB9E5: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; + case Format::D16: return VK_FORMAT_D16_UNORM; + case Format::D16S8: return VK_FORMAT_D16_UNORM_S8_UINT; + case Format::D24: return VK_FORMAT_X8_D24_UNORM_PACK32; + case Format::D24S8: return VK_FORMAT_D24_UNORM_S8_UINT; + case Format::D32F: return VK_FORMAT_D32_SFLOAT; + case Format::D32F_S8: return VK_FORMAT_D32_SFLOAT_S8_UINT; + + case Format::BC1: return VK_FORMAT_BC1_RGB_UNORM_BLOCK; + case Format::BC1_ALPHA: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK; + case Format::BC1_SRGB: return VK_FORMAT_BC1_RGB_SRGB_BLOCK; + case Format::BC1_SRGB_ALPHA: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK; + case Format::BC2: return VK_FORMAT_BC2_UNORM_BLOCK; + case Format::BC2_SRGB: return VK_FORMAT_BC2_SRGB_BLOCK; + case Format::BC3: return VK_FORMAT_BC3_UNORM_BLOCK; + case Format::BC3_SRGB: return VK_FORMAT_BC3_SRGB_BLOCK; + case Format::BC4: return VK_FORMAT_BC4_UNORM_BLOCK; + case Format::BC4_SNORM: return VK_FORMAT_BC4_SNORM_BLOCK; + case Format::BC5: return VK_FORMAT_BC5_UNORM_BLOCK; + case Format::BC5_SNORM: return VK_FORMAT_BC5_SNORM_BLOCK; + case Format::BC6H_UF16: return VK_FORMAT_BC6H_UFLOAT_BLOCK; + case Format::BC6H_SF16: return VK_FORMAT_BC6H_SFLOAT_BLOCK; + case Format::BC7: return VK_FORMAT_BC7_UNORM_BLOCK; + case Format::BC7_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK; + + case Format::ETC2_RGB8: return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; + case Format::ETC2_SRGB8: return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; + case Format::ETC2_RGB8_A1: return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; + case Format::ETC2_SRGB8_A1: return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK; + case Format::ETC2_RGBA8: return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; + case Format::ETC2_SRGB8_A8: return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK; + case Format::EAC_R11: return VK_FORMAT_EAC_R11_UNORM_BLOCK; + case Format::EAC_R11SN: return VK_FORMAT_EAC_R11_SNORM_BLOCK; + case Format::EAC_RG11: return VK_FORMAT_EAC_R11G11_UNORM_BLOCK; + case Format::EAC_RG11SN: return VK_FORMAT_EAC_R11G11_SNORM_BLOCK; + + case Format::PVRTC_RGB2: + case Format::PVRTC_RGBA2: return VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; + case Format::PVRTC_RGB4: + case Format::PVRTC_RGBA4: return VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; + case Format::PVRTC2_2BPP: return VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG; + case Format::PVRTC2_4BPP: return VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG; + + case Format::ASTC_RGBA_4X4: return VK_FORMAT_ASTC_4x4_UNORM_BLOCK; + case Format::ASTC_RGBA_5X4: return VK_FORMAT_ASTC_5x4_UNORM_BLOCK; + case Format::ASTC_RGBA_5X5: return VK_FORMAT_ASTC_5x5_UNORM_BLOCK; + case Format::ASTC_RGBA_6X5: return VK_FORMAT_ASTC_6x5_UNORM_BLOCK; + case Format::ASTC_RGBA_6X6: return VK_FORMAT_ASTC_6x6_UNORM_BLOCK; + case Format::ASTC_RGBA_8X5: return VK_FORMAT_ASTC_8x5_UNORM_BLOCK; + case Format::ASTC_RGBA_8X6: return VK_FORMAT_ASTC_8x6_UNORM_BLOCK; + case Format::ASTC_RGBA_8X8: return VK_FORMAT_ASTC_8x8_UNORM_BLOCK; + case Format::ASTC_RGBA_10X5: return VK_FORMAT_ASTC_10x5_UNORM_BLOCK; + case Format::ASTC_RGBA_10X6: return VK_FORMAT_ASTC_10x6_UNORM_BLOCK; + case Format::ASTC_RGBA_10X8: return VK_FORMAT_ASTC_10x8_UNORM_BLOCK; + case Format::ASTC_RGBA_10X10: return VK_FORMAT_ASTC_10x10_UNORM_BLOCK; + case Format::ASTC_RGBA_12X10: return VK_FORMAT_ASTC_12x10_UNORM_BLOCK; + case Format::ASTC_RGBA_12X12: return VK_FORMAT_ASTC_12x12_UNORM_BLOCK; + + case Format::ASTC_SRGBA_4X4: return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; + case Format::ASTC_SRGBA_5X4: return VK_FORMAT_ASTC_5x4_SRGB_BLOCK; + case Format::ASTC_SRGBA_5X5: return VK_FORMAT_ASTC_5x5_SRGB_BLOCK; + case Format::ASTC_SRGBA_6X5: return VK_FORMAT_ASTC_6x5_SRGB_BLOCK; + case Format::ASTC_SRGBA_6X6: return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; + case Format::ASTC_SRGBA_8X5: return VK_FORMAT_ASTC_8x5_SRGB_BLOCK; + case Format::ASTC_SRGBA_8X6: return VK_FORMAT_ASTC_8x6_SRGB_BLOCK; + case Format::ASTC_SRGBA_8X8: return VK_FORMAT_ASTC_8x8_SRGB_BLOCK; + case Format::ASTC_SRGBA_10X5: return VK_FORMAT_ASTC_10x5_SRGB_BLOCK; + case Format::ASTC_SRGBA_10X6: return VK_FORMAT_ASTC_10x6_SRGB_BLOCK; + case Format::ASTC_SRGBA_10X8: return VK_FORMAT_ASTC_10x8_SRGB_BLOCK; + case Format::ASTC_SRGBA_10X10: return VK_FORMAT_ASTC_10x10_SRGB_BLOCK; + case Format::ASTC_SRGBA_12X10: return VK_FORMAT_ASTC_12x10_SRGB_BLOCK; + case Format::ASTC_SRGBA_12X12: return VK_FORMAT_ASTC_12x12_SRGB_BLOCK; + + default: { + CCASSERT(false, "Unsupported Format, convert to VkFormat failed."); + return VK_FORMAT_B8G8R8A8_UNORM; + } + } +} + +VkAttachmentLoadOp mapVkLoadOp(LoadOp loadOp) { + switch (loadOp) { + case LoadOp::CLEAR: return VK_ATTACHMENT_LOAD_OP_CLEAR; + case LoadOp::LOAD: return VK_ATTACHMENT_LOAD_OP_LOAD; + case LoadOp::DISCARD: return VK_ATTACHMENT_LOAD_OP_DONT_CARE; + default: { + CCASSERT(false, "Unsupported LoadOp, convert to VkLoadOp failed."); + return VK_ATTACHMENT_LOAD_OP_LOAD; + } + } +} + +VkAttachmentStoreOp mapVkStoreOp(StoreOp storeOp) { + switch (storeOp) { + case StoreOp::STORE: return VK_ATTACHMENT_STORE_OP_STORE; + case StoreOp::DISCARD: return VK_ATTACHMENT_STORE_OP_DONT_CARE; + default: { + CCASSERT(false, "Unsupported StoreOp, convert to VkStoreOp failed."); + return VK_ATTACHMENT_STORE_OP_STORE; + } + } +} + +VkBufferUsageFlagBits mapVkBufferUsageFlagBits(BufferUsage usage) { + uint flags = 0U; + if (usage & BufferUsage::TRANSFER_SRC) flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + if (usage & BufferUsage::TRANSFER_DST) flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; + if (usage & BufferUsage::INDEX) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; + if (usage & BufferUsage::VERTEX) flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + if (usage & BufferUsage::UNIFORM) flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + if (usage & BufferUsage::STORAGE) flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; + if (usage & BufferUsage::INDIRECT) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; + return static_cast(flags); +} + +VkImageType mapVkImageType(TextureType type) { + switch (type) { + case TextureType::TEX1D: + case TextureType::TEX1D_ARRAY: return VK_IMAGE_TYPE_1D; + case TextureType::CUBE: + case TextureType::TEX2D: + case TextureType::TEX2D_ARRAY: return VK_IMAGE_TYPE_2D; + case TextureType::TEX3D: return VK_IMAGE_TYPE_3D; + default: { + CCASSERT(false, "Unsupported TextureType, convert to VkImageType failed."); + return VK_IMAGE_TYPE_2D; + } + } +} + +VkSampleCountFlagBits mapVkSampleCount(SampleCount count) { + switch (count) { + case SampleCount::X1: return VK_SAMPLE_COUNT_1_BIT; + case SampleCount::X2: return VK_SAMPLE_COUNT_2_BIT; + case SampleCount::X4: return VK_SAMPLE_COUNT_4_BIT; + case SampleCount::X8: return VK_SAMPLE_COUNT_8_BIT; + case SampleCount::X16: return VK_SAMPLE_COUNT_16_BIT; + case SampleCount::X32: return VK_SAMPLE_COUNT_32_BIT; + default: { + CCASSERT(false, "Unsupported TextureType, convert to VkImageType failed."); + return VK_SAMPLE_COUNT_1_BIT; + } + } +} + +VkFormatFeatureFlags mapVkFormatFeatureFlags(TextureUsage usage) { + uint flags = 0U; + if (usage & TextureUsage::TRANSFER_SRC) flags |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT; + if (usage & TextureUsage::TRANSFER_DST) flags |= VK_FORMAT_FEATURE_TRANSFER_DST_BIT; + if (usage & TextureUsage::SAMPLED) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; + if (usage & TextureUsage::STORAGE) flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; + if (usage & TextureUsage::COLOR_ATTACHMENT) flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; + if (usage & TextureUsage::DEPTH_STENCIL_ATTACHMENT) flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; + if (usage & TextureUsage::TRANSIENT_ATTACHMENT) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; + if (usage & TextureUsage::INPUT_ATTACHMENT) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; + return static_cast(flags); +} + +VkImageUsageFlagBits mapVkImageUsageFlagBits(TextureUsage usage) { + uint flags = 0U; + if (usage & TextureUsage::TRANSFER_SRC) flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + if (usage & TextureUsage::TRANSFER_DST) flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; + if (usage & TextureUsage::SAMPLED) flags |= VK_IMAGE_USAGE_SAMPLED_BIT; + if (usage & TextureUsage::STORAGE) flags |= VK_IMAGE_USAGE_STORAGE_BIT; + if (usage & TextureUsage::COLOR_ATTACHMENT) flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + if (usage & TextureUsage::DEPTH_STENCIL_ATTACHMENT) flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + if (usage & TextureUsage::TRANSIENT_ATTACHMENT) flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; + if (usage & TextureUsage::INPUT_ATTACHMENT) flags |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + return static_cast(flags); +} + +VkImageAspectFlags mapVkImageAspectFlags(Format format) { + VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + const FormatInfo & info = GFX_FORMAT_INFOS[static_cast(format)]; + if (info.hasDepth) { + aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + } + if (info.hasStencil) { + aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + return aspectMask; +} + +VkImageCreateFlags mapVkImageCreateFlags(TextureType type) { + uint res = 0U; + switch (type) { + case TextureType::CUBE: res |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; break; + case TextureType::TEX2D_ARRAY: res |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; break; + default: break; + } + return static_cast(res); +} + +VkImageViewType mapVkImageViewType(TextureType viewType) { + switch (viewType) { + case TextureType::TEX1D: return VK_IMAGE_VIEW_TYPE_1D; + case TextureType::TEX1D_ARRAY: return VK_IMAGE_VIEW_TYPE_1D_ARRAY; + case TextureType::TEX2D: return VK_IMAGE_VIEW_TYPE_2D; + case TextureType::TEX2D_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; + case TextureType::TEX3D: return VK_IMAGE_VIEW_TYPE_3D; + case TextureType::CUBE: return VK_IMAGE_VIEW_TYPE_CUBE; + default: { + CCASSERT(false, "Unsupported TextureViewType, convert to VkImageViewType failed."); + return VK_IMAGE_VIEW_TYPE_2D; + } + } +} + +VkCommandBufferLevel mapVkCommandBufferLevel(CommandBufferType type) { + switch (type) { + case CommandBufferType::PRIMARY: return VK_COMMAND_BUFFER_LEVEL_PRIMARY; + case CommandBufferType::SECONDARY: return VK_COMMAND_BUFFER_LEVEL_SECONDARY; + default: { + CCASSERT(false, "Unsupported CommandBufferType, convert to VkCommandBufferLevel failed."); + return VK_COMMAND_BUFFER_LEVEL_SECONDARY; + } + } +} + +VkDescriptorType mapVkDescriptorType(DescriptorType type) { + switch (type) { + case DescriptorType::DYNAMIC_UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + case DescriptorType::UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + case DescriptorType::DYNAMIC_STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; + case DescriptorType::STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + case DescriptorType::SAMPLER_TEXTURE: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + case DescriptorType::SAMPLER: return VK_DESCRIPTOR_TYPE_SAMPLER; + case DescriptorType::TEXTURE: return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + case DescriptorType::STORAGE_IMAGE: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; + case DescriptorType::INPUT_ATTACHMENT: return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + default: { + CCASSERT(false, "Unsupported DescriptorType, convert to VkDescriptorType failed."); + return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + } + } +} + +VkColorComponentFlags mapVkColorComponentFlags(ColorMask colorMask) { + uint flags = 0U; + if (colorMask & ColorMask::R) flags |= VK_COLOR_COMPONENT_R_BIT; + if (colorMask & ColorMask::G) flags |= VK_COLOR_COMPONENT_G_BIT; + if (colorMask & ColorMask::B) flags |= VK_COLOR_COMPONENT_B_BIT; + if (colorMask & ColorMask::A) flags |= VK_COLOR_COMPONENT_A_BIT; + if (colorMask & ColorMask::ALL) flags |= VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; + return static_cast(flags); +} + +VkShaderStageFlagBits mapVkShaderStageFlagBits(ShaderStageFlagBit stage) { + switch (stage) { + case ShaderStageFlagBit::VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; + case ShaderStageFlagBit::CONTROL: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + case ShaderStageFlagBit::EVALUATION: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + case ShaderStageFlagBit::GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT; + case ShaderStageFlagBit::FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT; + case ShaderStageFlagBit::COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; + default: { + CCASSERT(false, "Unsupported ShaderStageFlagBit, convert to VkShaderStageFlagBits failed."); + return VK_SHADER_STAGE_VERTEX_BIT; + } + } +} + +VkShaderStageFlags mapVkShaderStageFlags(ShaderStageFlagBit stages) { + uint flags = 0U; + if (stages & ShaderStageFlagBit::VERTEX) flags |= VK_SHADER_STAGE_VERTEX_BIT; + if (stages & ShaderStageFlagBit::CONTROL) flags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + if (stages & ShaderStageFlagBit::EVALUATION) flags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + if (stages & ShaderStageFlagBit::GEOMETRY) flags |= VK_SHADER_STAGE_GEOMETRY_BIT; + if (stages & ShaderStageFlagBit::FRAGMENT) flags |= VK_SHADER_STAGE_FRAGMENT_BIT; + if (stages & ShaderStageFlagBit::COMPUTE) flags |= VK_SHADER_STAGE_COMPUTE_BIT; + return static_cast(flags); +} + +SurfaceTransform mapSurfaceTransform(VkSurfaceTransformFlagBitsKHR transform) { + if (transform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) return SurfaceTransform::ROTATE_90; + if (transform & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) return SurfaceTransform::ROTATE_180; + if (transform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) return SurfaceTransform::ROTATE_270; + return SurfaceTransform::IDENTITY; +} + +String mapVendorName(uint32_t vendorID) { + switch (vendorID) { + case 0x1002: return "Advanced Micro Devices, Inc."; + case 0x1010: return "Imagination Technologies"; + case 0x106b: return "Apple Inc."; + case 0x10DE: return "Nvidia Corporation"; + case 0x13B5: return "Arm Limited"; + case 0x5143: return "Qualcomm Incorporated"; + case 0x8086: return "Intel Corporation"; + } + return StringUtil::format("Unknown VendorID %d", vendorID); +} + +void mapDepthStencilBits(Format format, uint *pDepthBits, uint *pStencilBits) { + switch (format) { + case Format::D16: + *pDepthBits = 16; + *pStencilBits = 0; + break; + case Format::D16S8: + *pDepthBits = 16; + *pStencilBits = 8; + break; + case Format::D24: + *pDepthBits = 24; + *pStencilBits = 0; + break; + case Format::D24S8: + *pDepthBits = 24; + *pStencilBits = 8; + break; + case Format::D32F: + *pDepthBits = 32; + *pStencilBits = 0; + break; + case Format::D32F_S8: + *pDepthBits = 32; + *pStencilBits = 8; + break; + default: break; + } +} + +const VkSurfaceTransformFlagsKHR TRANSFORMS_THAT_REQUIRE_FLIPPING = + VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR | + VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR; + +const VkPrimitiveTopology VK_PRIMITIVE_MODES[] = { + VK_PRIMITIVE_TOPOLOGY_POINT_LIST, // POINT_LIST + VK_PRIMITIVE_TOPOLOGY_LINE_LIST, // LINE_LIST + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, // LINE_STRIP + static_cast(0), // LINE_LOOP + VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, // LINE_LIST_ADJACENCY + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, // LINE_STRIP_ADJACENCY + static_cast(0), // ISO_LINE_LIST + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // TRIANGLE_LIST + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, // TRIANGLE_STRIP + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN, // TRIANGLE_FAN + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, // TRIANGLE_LIST_ADJACENCY + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, // TRIANGLE_STRIP_ADJACENCY, + static_cast(0), // TRIANGLE_PATCH_ADJACENCY, + VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, // QUAD_PATCH_LIST, +}; + +const VkCullModeFlags VK_CULL_MODES[] = { + VK_CULL_MODE_NONE, + VK_CULL_MODE_FRONT_BIT, + VK_CULL_MODE_BACK_BIT, +}; + +const VkPolygonMode VK_POLYGON_MODES[] = { + VK_POLYGON_MODE_FILL, + VK_POLYGON_MODE_LINE, + VK_POLYGON_MODE_POINT, +}; + +const VkCompareOp VK_CMP_FUNCS[] = { + VK_COMPARE_OP_NEVER, + VK_COMPARE_OP_LESS, + VK_COMPARE_OP_EQUAL, + VK_COMPARE_OP_LESS_OR_EQUAL, + VK_COMPARE_OP_GREATER, + VK_COMPARE_OP_NOT_EQUAL, + VK_COMPARE_OP_GREATER_OR_EQUAL, + VK_COMPARE_OP_ALWAYS, +}; + +const VkStencilOp VK_STENCIL_OPS[] = { + VK_STENCIL_OP_ZERO, + VK_STENCIL_OP_KEEP, + VK_STENCIL_OP_REPLACE, + VK_STENCIL_OP_INCREMENT_AND_CLAMP, + VK_STENCIL_OP_DECREMENT_AND_CLAMP, + VK_STENCIL_OP_INVERT, + VK_STENCIL_OP_INCREMENT_AND_WRAP, + VK_STENCIL_OP_DECREMENT_AND_WRAP, +}; + +const VkBlendOp VK_BLEND_OPS[] = { + VK_BLEND_OP_ADD, + VK_BLEND_OP_SUBTRACT, + VK_BLEND_OP_REVERSE_SUBTRACT, + VK_BLEND_OP_MIN, + VK_BLEND_OP_MAX, +}; + +const VkBlendFactor VK_BLEND_FACTORS[] = { + VK_BLEND_FACTOR_ZERO, + VK_BLEND_FACTOR_ONE, + VK_BLEND_FACTOR_SRC_ALPHA, + VK_BLEND_FACTOR_DST_ALPHA, + VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, + VK_BLEND_FACTOR_SRC_COLOR, + VK_BLEND_FACTOR_DST_COLOR, + VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR, + VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR, + VK_BLEND_FACTOR_SRC_ALPHA_SATURATE, + VK_BLEND_FACTOR_CONSTANT_COLOR, + VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, + VK_BLEND_FACTOR_CONSTANT_ALPHA, + VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA, +}; + +const VkFilter VK_FILTERS[] = { + static_cast(0), // NONE + VK_FILTER_NEAREST, // POINT + VK_FILTER_LINEAR, // LINEAR + static_cast(0), // ANISOTROPIC +}; + +const VkSamplerMipmapMode VK_SAMPLER_MIPMAP_MODES[] = { + static_cast(0), // NONE + VK_SAMPLER_MIPMAP_MODE_NEAREST, // POINT + VK_SAMPLER_MIPMAP_MODE_LINEAR, // LINEAR + VK_SAMPLER_MIPMAP_MODE_LINEAR, // ANISOTROPIC +}; + +const VkSamplerAddressMode VK_SAMPLER_ADDRESS_MODES[] = { + VK_SAMPLER_ADDRESS_MODE_REPEAT, // WRAP + VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, // MIRROR + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // CLAMP + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, // BORDER +}; + +const VkPipelineBindPoint VK_PIPELINE_BIND_POINTS[] = { + VK_PIPELINE_BIND_POINT_GRAPHICS, + VK_PIPELINE_BIND_POINT_COMPUTE, + VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, +}; + +const ThsvsAccessType THSVS_ACCESS_TYPES[] = { + THSVS_ACCESS_NONE, // NONE + THSVS_ACCESS_INDIRECT_BUFFER, // INDIRECT_BUFFER + THSVS_ACCESS_INDEX_BUFFER, // INDEX_BUFFER + THSVS_ACCESS_VERTEX_BUFFER, // VERTEX_BUFFER + THSVS_ACCESS_VERTEX_SHADER_READ_UNIFORM_BUFFER, // VERTEX_SHADER_READ_UNIFORM_BUFFER + THSVS_ACCESS_VERTEX_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // VERTEX_SHADER_READ_TEXTURE + THSVS_ACCESS_VERTEX_SHADER_READ_OTHER, // VERTEX_SHADER_READ_OTHER + THSVS_ACCESS_FRAGMENT_SHADER_READ_UNIFORM_BUFFER, // FRAGMENT_SHADER_READ_UNIFORM_BUFFER + THSVS_ACCESS_FRAGMENT_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // FRAGMENT_SHADER_READ_TEXTURE + THSVS_ACCESS_FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT, // FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT + THSVS_ACCESS_FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT, // FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT + THSVS_ACCESS_FRAGMENT_SHADER_READ_OTHER, // FRAGMENT_SHADER_READ_OTHER + THSVS_ACCESS_COLOR_ATTACHMENT_READ, // COLOR_ATTACHMENT_READ + THSVS_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ, // DEPTH_STENCIL_ATTACHMENT_READ + THSVS_ACCESS_COMPUTE_SHADER_READ_UNIFORM_BUFFER, // COMPUTE_SHADER_READ_UNIFORM_BUFFER + THSVS_ACCESS_COMPUTE_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // COMPUTE_SHADER_READ_TEXTURE + THSVS_ACCESS_COMPUTE_SHADER_READ_OTHER, // COMPUTE_SHADER_READ_OTHER + THSVS_ACCESS_TRANSFER_READ, // TRANSFER_READ + THSVS_ACCESS_HOST_READ, // HOST_READ + THSVS_ACCESS_PRESENT, // PRESENT + THSVS_ACCESS_VERTEX_SHADER_WRITE, // VERTEX_SHADER_WRITE + THSVS_ACCESS_FRAGMENT_SHADER_WRITE, // FRAGMENT_SHADER_WRITE + THSVS_ACCESS_COLOR_ATTACHMENT_WRITE, // COLOR_ATTACHMENT_WRITE + THSVS_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE, // DEPTH_STENCIL_ATTACHMENT_WRITE + THSVS_ACCESS_COMPUTE_SHADER_WRITE, // COMPUTE_SHADER_WRITE + THSVS_ACCESS_TRANSFER_WRITE, // TRANSFER_WRITE + THSVS_ACCESS_HOST_PREINITIALIZED, // HOST_PREINITIALIZED + THSVS_ACCESS_HOST_WRITE, // HOST_WRITE +}; + +const VkImageLayout VK_IMAGE_LAYOUTS[] = { + VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_GENERAL, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_PREINITIALIZED, + VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, +}; + +const VkAccessFlags FULL_ACCESS_FLAGS = + VK_ACCESS_INDIRECT_COMMAND_READ_BIT | + VK_ACCESS_INDEX_READ_BIT | + VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | + VK_ACCESS_UNIFORM_READ_BIT | + VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | + VK_ACCESS_SHADER_READ_BIT | + VK_ACCESS_SHADER_WRITE_BIT | + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | + VK_ACCESS_TRANSFER_READ_BIT | + VK_ACCESS_TRANSFER_WRITE_BIT | + VK_ACCESS_HOST_READ_BIT | + VK_ACCESS_HOST_WRITE_BIT; + +void fullPipelineBarrier(VkCommandBuffer cmdBuff) { +#if CC_DEBUG > 0 + VkMemoryBarrier memoryBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; + memoryBarrier.srcAccessMask = FULL_ACCESS_FLAGS; + memoryBarrier.dstAccessMask = FULL_ACCESS_FLAGS; + vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr); +#endif +} + +VkDeviceSize roundUp(VkDeviceSize numToRound, uint multiple) { + return ((numToRound + multiple - 1) / multiple) * multiple; +} + +bool isLayerSupported(const char *required, const vector &available) { + for (const VkLayerProperties &availableLayer : available) { + if (strcmp(availableLayer.layerName, required) == 0) { + return true; + } + } + return false; +} + +bool isExtensionSupported(const char *required, const vector &available) { + for (const VkExtensionProperties &availableExtension : available) { + if (strcmp(availableExtension.extensionName, required) == 0) { + return true; + } + } + return false; +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.h b/native/cocos/renderer/gfx-vulkan/VKUtils.h index b9a919cd76..a63bc45b43 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.h @@ -27,7 +27,9 @@ #define WIN32_LEAN_AND_MEAN +#include "base/Utils.h" #include "base/Macros.h" +#include "base/StringUtil.h" #include "gfx-base/GFXDef.h" #include "vk_mem_alloc.h" @@ -48,607 +50,46 @@ namespace cc { namespace gfx { -namespace { -VkFormat MapVkFormat(Format format) { - switch (format) { - case Format::R8: return VK_FORMAT_R8_UNORM; - case Format::R8SN: return VK_FORMAT_R8_SNORM; - case Format::R8UI: return VK_FORMAT_R8_UINT; - case Format::R8I: return VK_FORMAT_R8_SINT; - case Format::RG8: return VK_FORMAT_R8G8_UNORM; - case Format::RG8SN: return VK_FORMAT_R8G8_SNORM; - case Format::RG8UI: return VK_FORMAT_R8G8_UINT; - case Format::RG8I: return VK_FORMAT_R8G8_SINT; - case Format::RGB8: return VK_FORMAT_R8G8B8_UNORM; - case Format::RGB8SN: return VK_FORMAT_R8G8B8_SNORM; - case Format::RGB8UI: return VK_FORMAT_R8G8B8_UINT; - case Format::RGB8I: return VK_FORMAT_R8G8B8_SINT; - case Format::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM; - case Format::BGRA8: return VK_FORMAT_B8G8R8A8_UNORM; - case Format::SRGB8_A8: return VK_FORMAT_R8G8B8A8_SRGB; - case Format::RGBA8SN: return VK_FORMAT_R8G8B8A8_SNORM; - case Format::RGBA8UI: return VK_FORMAT_R8G8B8A8_UINT; - case Format::RGBA8I: return VK_FORMAT_R8G8B8A8_SINT; - case Format::R16I: return VK_FORMAT_R16_SINT; - case Format::R16UI: return VK_FORMAT_R16_UINT; - case Format::R16F: return VK_FORMAT_R16_SFLOAT; - case Format::RG16I: return VK_FORMAT_R16G16_SINT; - case Format::RG16UI: return VK_FORMAT_R16G16_UINT; - case Format::RG16F: return VK_FORMAT_R16G16_SFLOAT; - case Format::RGB16I: return VK_FORMAT_R16G16B16_SINT; - case Format::RGB16UI: return VK_FORMAT_R16G16B16_UINT; - case Format::RGB16F: return VK_FORMAT_R16G16B16_SFLOAT; - case Format::RGBA16I: return VK_FORMAT_R16G16B16A16_SINT; - case Format::RGBA16UI: return VK_FORMAT_R16G16B16A16_UINT; - case Format::RGBA16F: return VK_FORMAT_R16G16B16A16_SFLOAT; - case Format::R32I: return VK_FORMAT_R32_SINT; - case Format::R32UI: return VK_FORMAT_R32_UINT; - case Format::R32F: return VK_FORMAT_R32_SFLOAT; - case Format::RG32I: return VK_FORMAT_R32G32_SINT; - case Format::RG32UI: return VK_FORMAT_R32G32_UINT; - case Format::RG32F: return VK_FORMAT_R32G32_SFLOAT; - case Format::RGB32I: return VK_FORMAT_R32G32B32_SINT; - case Format::RGB32UI: return VK_FORMAT_R32G32B32_UINT; - case Format::RGB32F: return VK_FORMAT_R32G32B32_SFLOAT; - case Format::RGBA32I: return VK_FORMAT_R32G32B32A32_SINT; - case Format::RGBA32UI: return VK_FORMAT_R32G32B32A32_UINT; - case Format::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT; +extern VkFormat mapVkFormat(Format format); +extern VkAttachmentLoadOp mapVkLoadOp(LoadOp loadOp); +extern VkAttachmentStoreOp mapVkStoreOp(StoreOp storeOp); +extern VkBufferUsageFlagBits mapVkBufferUsageFlagBits(BufferUsage usage); +extern VkImageType mapVkImageType(TextureType type); +extern VkSampleCountFlagBits mapVkSampleCount(SampleCount count); +extern VkFormatFeatureFlags mapVkFormatFeatureFlags(TextureUsage usage); +extern VkImageUsageFlagBits mapVkImageUsageFlagBits(TextureUsage usage); +extern VkImageAspectFlags mapVkImageAspectFlags(Format format); +extern VkImageCreateFlags mapVkImageCreateFlags(TextureType type); +extern VkImageViewType mapVkImageViewType(TextureType viewType); +extern VkCommandBufferLevel mapVkCommandBufferLevel(CommandBufferType type); +extern VkDescriptorType mapVkDescriptorType(DescriptorType type); +extern VkColorComponentFlags mapVkColorComponentFlags(ColorMask colorMask); +extern VkShaderStageFlagBits mapVkShaderStageFlagBits(ShaderStageFlagBit stage); +extern VkShaderStageFlags mapVkShaderStageFlags(ShaderStageFlagBit stages); +extern SurfaceTransform mapSurfaceTransform(VkSurfaceTransformFlagBitsKHR transform); +extern String mapVendorName(uint32_t vendorID); +extern void mapDepthStencilBits(Format format, uint *pDepthBits, uint *pStencilBits); - case Format::R5G6B5: return VK_FORMAT_R5G6B5_UNORM_PACK16; - case Format::R11G11B10F: return VK_FORMAT_B10G11R11_UFLOAT_PACK32; - case Format::RGB5A1: return VK_FORMAT_R5G5B5A1_UNORM_PACK16; - case Format::RGBA4: return VK_FORMAT_R4G4B4A4_UNORM_PACK16; - case Format::RGB10A2: return VK_FORMAT_A2B10G10R10_UNORM_PACK32; - case Format::RGB10A2UI: return VK_FORMAT_A2B10G10R10_UINT_PACK32; - case Format::RGB9E5: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32; - case Format::D16: return VK_FORMAT_D16_UNORM; - case Format::D16S8: return VK_FORMAT_D16_UNORM_S8_UINT; - case Format::D24: return VK_FORMAT_X8_D24_UNORM_PACK32; - case Format::D24S8: return VK_FORMAT_D24_UNORM_S8_UINT; - case Format::D32F: return VK_FORMAT_D32_SFLOAT; - case Format::D32F_S8: return VK_FORMAT_D32_SFLOAT_S8_UINT; +extern void fullPipelineBarrier(VkCommandBuffer cmdBuff); +extern VkDeviceSize roundUp(VkDeviceSize numToRound, uint multiple); +extern bool isLayerSupported(const char *required, const vector &available); +extern bool isExtensionSupported(const char *required, const vector &available); - case Format::BC1: return VK_FORMAT_BC1_RGB_UNORM_BLOCK; - case Format::BC1_ALPHA: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK; - case Format::BC1_SRGB: return VK_FORMAT_BC1_RGB_SRGB_BLOCK; - case Format::BC1_SRGB_ALPHA: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK; - case Format::BC2: return VK_FORMAT_BC2_UNORM_BLOCK; - case Format::BC2_SRGB: return VK_FORMAT_BC2_SRGB_BLOCK; - case Format::BC3: return VK_FORMAT_BC3_UNORM_BLOCK; - case Format::BC3_SRGB: return VK_FORMAT_BC3_SRGB_BLOCK; - case Format::BC4: return VK_FORMAT_BC4_UNORM_BLOCK; - case Format::BC4_SNORM: return VK_FORMAT_BC4_SNORM_BLOCK; - case Format::BC5: return VK_FORMAT_BC5_UNORM_BLOCK; - case Format::BC5_SNORM: return VK_FORMAT_BC5_SNORM_BLOCK; - case Format::BC6H_UF16: return VK_FORMAT_BC6H_UFLOAT_BLOCK; - case Format::BC6H_SF16: return VK_FORMAT_BC6H_SFLOAT_BLOCK; - case Format::BC7: return VK_FORMAT_BC7_UNORM_BLOCK; - case Format::BC7_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK; - - case Format::ETC2_RGB8: return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; - case Format::ETC2_SRGB8: return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK; - case Format::ETC2_RGB8_A1: return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK; - case Format::ETC2_SRGB8_A1: return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK; - case Format::ETC2_RGBA8: return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK; - case Format::ETC2_SRGB8_A8: return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK; - case Format::EAC_R11: return VK_FORMAT_EAC_R11_UNORM_BLOCK; - case Format::EAC_R11SN: return VK_FORMAT_EAC_R11_SNORM_BLOCK; - case Format::EAC_RG11: return VK_FORMAT_EAC_R11G11_UNORM_BLOCK; - case Format::EAC_RG11SN: return VK_FORMAT_EAC_R11G11_SNORM_BLOCK; - - case Format::PVRTC_RGB2: return VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; - case Format::PVRTC_RGBA2: return VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG; - case Format::PVRTC_RGB4: return VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; - case Format::PVRTC_RGBA4: return VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG; - case Format::PVRTC2_2BPP: return VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG; - case Format::PVRTC2_4BPP: return VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG; - - case Format::ASTC_RGBA_4x4: return VK_FORMAT_ASTC_4x4_UNORM_BLOCK; - case Format::ASTC_RGBA_5x4: return VK_FORMAT_ASTC_5x4_UNORM_BLOCK; - case Format::ASTC_RGBA_5x5: return VK_FORMAT_ASTC_5x5_UNORM_BLOCK; - case Format::ASTC_RGBA_6x5: return VK_FORMAT_ASTC_6x5_UNORM_BLOCK; - case Format::ASTC_RGBA_6x6: return VK_FORMAT_ASTC_6x6_UNORM_BLOCK; - case Format::ASTC_RGBA_8x5: return VK_FORMAT_ASTC_8x5_UNORM_BLOCK; - case Format::ASTC_RGBA_8x6: return VK_FORMAT_ASTC_8x6_UNORM_BLOCK; - case Format::ASTC_RGBA_8x8: return VK_FORMAT_ASTC_8x8_UNORM_BLOCK; - case Format::ASTC_RGBA_10x5: return VK_FORMAT_ASTC_10x5_UNORM_BLOCK; - case Format::ASTC_RGBA_10x6: return VK_FORMAT_ASTC_10x6_UNORM_BLOCK; - case Format::ASTC_RGBA_10x8: return VK_FORMAT_ASTC_10x8_UNORM_BLOCK; - case Format::ASTC_RGBA_10x10: return VK_FORMAT_ASTC_10x10_UNORM_BLOCK; - case Format::ASTC_RGBA_12x10: return VK_FORMAT_ASTC_12x10_UNORM_BLOCK; - case Format::ASTC_RGBA_12x12: return VK_FORMAT_ASTC_12x12_UNORM_BLOCK; - - case Format::ASTC_SRGBA_4x4: return VK_FORMAT_ASTC_4x4_SRGB_BLOCK; - case Format::ASTC_SRGBA_5x4: return VK_FORMAT_ASTC_5x4_SRGB_BLOCK; - case Format::ASTC_SRGBA_5x5: return VK_FORMAT_ASTC_5x5_SRGB_BLOCK; - case Format::ASTC_SRGBA_6x5: return VK_FORMAT_ASTC_6x5_SRGB_BLOCK; - case Format::ASTC_SRGBA_6x6: return VK_FORMAT_ASTC_6x6_SRGB_BLOCK; - case Format::ASTC_SRGBA_8x5: return VK_FORMAT_ASTC_8x5_SRGB_BLOCK; - case Format::ASTC_SRGBA_8x6: return VK_FORMAT_ASTC_8x6_SRGB_BLOCK; - case Format::ASTC_SRGBA_8x8: return VK_FORMAT_ASTC_8x8_SRGB_BLOCK; - case Format::ASTC_SRGBA_10x5: return VK_FORMAT_ASTC_10x5_SRGB_BLOCK; - case Format::ASTC_SRGBA_10x6: return VK_FORMAT_ASTC_10x6_SRGB_BLOCK; - case Format::ASTC_SRGBA_10x8: return VK_FORMAT_ASTC_10x8_SRGB_BLOCK; - case Format::ASTC_SRGBA_10x10: return VK_FORMAT_ASTC_10x10_SRGB_BLOCK; - case Format::ASTC_SRGBA_12x10: return VK_FORMAT_ASTC_12x10_SRGB_BLOCK; - case Format::ASTC_SRGBA_12x12: return VK_FORMAT_ASTC_12x12_SRGB_BLOCK; - - default: { - CCASSERT(false, "Unsupported Format, convert to VkFormat failed."); - return VK_FORMAT_B8G8R8A8_UNORM; - } - } -} - -VkAttachmentLoadOp MapVkLoadOp(LoadOp loadOp) { - switch (loadOp) { - case LoadOp::CLEAR: return VK_ATTACHMENT_LOAD_OP_CLEAR; - case LoadOp::LOAD: return VK_ATTACHMENT_LOAD_OP_LOAD; - case LoadOp::DISCARD: return VK_ATTACHMENT_LOAD_OP_DONT_CARE; - default: { - CCASSERT(false, "Unsupported LoadOp, convert to VkLoadOp failed."); - return VK_ATTACHMENT_LOAD_OP_LOAD; - } - } -} - -VkAttachmentStoreOp MapVkStoreOp(StoreOp storeOp) { - switch (storeOp) { - case StoreOp::STORE: return VK_ATTACHMENT_STORE_OP_STORE; - case StoreOp::DISCARD: return VK_ATTACHMENT_STORE_OP_DONT_CARE; - default: { - CCASSERT(false, "Unsupported StoreOp, convert to VkStoreOp failed."); - return VK_ATTACHMENT_STORE_OP_STORE; - } - } -} - -VkBufferUsageFlagBits MapVkBufferUsageFlagBits(BufferUsage usage) { - uint flags = 0u; - if (usage & BufferUsage::TRANSFER_SRC) flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; - if (usage & BufferUsage::TRANSFER_DST) flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; - if (usage & BufferUsage::INDEX) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - if (usage & BufferUsage::VERTEX) flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - if (usage & BufferUsage::UNIFORM) flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - if (usage & BufferUsage::STORAGE) flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - if (usage & BufferUsage::INDIRECT) flags |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; - return (VkBufferUsageFlagBits)flags; -} - -VkImageType MapVkImageType(TextureType type) { - switch (type) { - case TextureType::TEX1D: - case TextureType::TEX1D_ARRAY: return VK_IMAGE_TYPE_1D; - case TextureType::CUBE: - case TextureType::TEX2D: - case TextureType::TEX2D_ARRAY: return VK_IMAGE_TYPE_2D; - case TextureType::TEX3D: return VK_IMAGE_TYPE_3D; - default: { - CCASSERT(false, "Unsupported TextureType, convert to VkImageType failed."); - return VK_IMAGE_TYPE_2D; - } - } -} - -VkSampleCountFlagBits MapVkSampleCount(SampleCount count) { - switch (count) { - case SampleCount::X1: return VK_SAMPLE_COUNT_1_BIT; - case SampleCount::X2: return VK_SAMPLE_COUNT_2_BIT; - case SampleCount::X4: return VK_SAMPLE_COUNT_4_BIT; - case SampleCount::X8: return VK_SAMPLE_COUNT_8_BIT; - case SampleCount::X16: return VK_SAMPLE_COUNT_16_BIT; - case SampleCount::X32: return VK_SAMPLE_COUNT_32_BIT; - default: { - CCASSERT(false, "Unsupported TextureType, convert to VkImageType failed."); - return VK_SAMPLE_COUNT_1_BIT; - } - } -} - -VkFormatFeatureFlags MapVkFormatFeatureFlags(TextureUsage usage) { - uint flags = 0u; - if (usage & TextureUsage::TRANSFER_SRC) flags |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT; - if (usage & TextureUsage::TRANSFER_DST) flags |= VK_FORMAT_FEATURE_TRANSFER_DST_BIT; - if (usage & TextureUsage::SAMPLED) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; - if (usage & TextureUsage::STORAGE) flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; - if (usage & TextureUsage::COLOR_ATTACHMENT) flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; - if (usage & TextureUsage::DEPTH_STENCIL_ATTACHMENT) flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; - if (usage & TextureUsage::TRANSIENT_ATTACHMENT) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; - if (usage & TextureUsage::INPUT_ATTACHMENT) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; - return (VkFormatFeatureFlags)flags; -} - -VkImageUsageFlagBits MapVkImageUsageFlagBits(TextureUsage usage) { - uint flags = 0u; - if (usage & TextureUsage::TRANSFER_SRC) flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; - if (usage & TextureUsage::TRANSFER_DST) flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; - if (usage & TextureUsage::SAMPLED) flags |= VK_IMAGE_USAGE_SAMPLED_BIT; - if (usage & TextureUsage::STORAGE) flags |= VK_IMAGE_USAGE_STORAGE_BIT; - if (usage & TextureUsage::COLOR_ATTACHMENT) flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - if (usage & TextureUsage::DEPTH_STENCIL_ATTACHMENT) flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - if (usage & TextureUsage::TRANSIENT_ATTACHMENT) flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; - if (usage & TextureUsage::INPUT_ATTACHMENT) flags |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; - return (VkImageUsageFlagBits)flags; -} - -VkImageAspectFlags MapVkImageAspectFlags(Format format) { - VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - const FormatInfo & info = GFX_FORMAT_INFOS[(uint)format]; - if (info.hasDepth) { - aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - } - if (info.hasStencil) { - aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; - } - return aspectMask; -} - -VkImageCreateFlags MapVkImageCreateFlags(TextureType type) { - uint res = 0u; - switch (type) { - case TextureType::CUBE: res |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; break; - case TextureType::TEX2D_ARRAY: res |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; break; - default: break; - } - return (VkImageCreateFlags)res; -} - -VkImageViewType MapVkImageViewType(TextureType viewType) { - switch (viewType) { - case TextureType::TEX1D: return VK_IMAGE_VIEW_TYPE_1D; - case TextureType::TEX1D_ARRAY: return VK_IMAGE_VIEW_TYPE_1D_ARRAY; - case TextureType::TEX2D: return VK_IMAGE_VIEW_TYPE_2D; - case TextureType::TEX2D_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; - case TextureType::TEX3D: return VK_IMAGE_VIEW_TYPE_3D; - case TextureType::CUBE: return VK_IMAGE_VIEW_TYPE_CUBE; - default: { - CCASSERT(false, "Unsupported TextureViewType, convert to VkImageViewType failed."); - return VK_IMAGE_VIEW_TYPE_2D; - } - } -} - -VkCommandBufferLevel MapVkCommandBufferLevel(CommandBufferType type) { - switch (type) { - case CommandBufferType::PRIMARY: return VK_COMMAND_BUFFER_LEVEL_PRIMARY; - case CommandBufferType::SECONDARY: return VK_COMMAND_BUFFER_LEVEL_SECONDARY; - default: { - CCASSERT(false, "Unsupported CommandBufferType, convert to VkCommandBufferLevel failed."); - return VK_COMMAND_BUFFER_LEVEL_SECONDARY; - } - } -} - -VkDescriptorType MapVkDescriptorType(DescriptorType type) { - switch (type) { - case DescriptorType::DYNAMIC_UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; - case DescriptorType::UNIFORM_BUFFER: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - case DescriptorType::DYNAMIC_STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; - case DescriptorType::STORAGE_BUFFER: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; - case DescriptorType::SAMPLER_TEXTURE: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - case DescriptorType::SAMPLER: return VK_DESCRIPTOR_TYPE_SAMPLER; - case DescriptorType::TEXTURE: return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; - case DescriptorType::STORAGE_IMAGE: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; - case DescriptorType::INPUT_ATTACHMENT: return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; - default: { - CCASSERT(false, "Unsupported DescriptorType, convert to VkDescriptorType failed."); - return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; - } - } -} - -VkColorComponentFlags MapVkColorComponentFlags(ColorMask colorMask) { - uint flags = 0u; - if (colorMask & ColorMask::R) flags |= VK_COLOR_COMPONENT_R_BIT; - if (colorMask & ColorMask::G) flags |= VK_COLOR_COMPONENT_G_BIT; - if (colorMask & ColorMask::B) flags |= VK_COLOR_COMPONENT_B_BIT; - if (colorMask & ColorMask::A) flags |= VK_COLOR_COMPONENT_A_BIT; - if (colorMask & ColorMask::ALL) flags |= VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - return (VkColorComponentFlags)flags; -} - -VkShaderStageFlagBits MapVkShaderStageFlagBits(ShaderStageFlagBit stage) { - switch (stage) { - case ShaderStageFlagBit::VERTEX: return VK_SHADER_STAGE_VERTEX_BIT; - case ShaderStageFlagBit::CONTROL: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - case ShaderStageFlagBit::EVALUATION: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - case ShaderStageFlagBit::GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT; - case ShaderStageFlagBit::FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT; - case ShaderStageFlagBit::COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT; - default: { - CCASSERT(false, "Unsupported ShaderStageFlagBit, convert to VkShaderStageFlagBits failed."); - return VK_SHADER_STAGE_VERTEX_BIT; - } - } -} - -VkShaderStageFlags MapVkShaderStageFlags(ShaderStageFlagBit stages) { - uint flags = 0u; - if (stages & ShaderStageFlagBit::VERTEX) flags |= VK_SHADER_STAGE_VERTEX_BIT; - if (stages & ShaderStageFlagBit::CONTROL) flags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - if (stages & ShaderStageFlagBit::EVALUATION) flags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - if (stages & ShaderStageFlagBit::GEOMETRY) flags |= VK_SHADER_STAGE_GEOMETRY_BIT; - if (stages & ShaderStageFlagBit::FRAGMENT) flags |= VK_SHADER_STAGE_FRAGMENT_BIT; - if (stages & ShaderStageFlagBit::COMPUTE) flags |= VK_SHADER_STAGE_COMPUTE_BIT; - return (VkShaderStageFlags)flags; -} - -SurfaceTransform MapSurfaceTransform(VkSurfaceTransformFlagBitsKHR transform) { - if (transform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) return SurfaceTransform::ROTATE_90; - if (transform & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) return SurfaceTransform::ROTATE_180; - if (transform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) return SurfaceTransform::ROTATE_270; - return SurfaceTransform::IDENTITY; -} - -String MapVendorName(uint32_t vendorID) { - switch (vendorID) { - case 0x1002: return "Advanced Micro Devices, Inc."; - case 0x1010: return "Imagination Technologies"; - case 0x106b: return "Apple Inc."; - case 0x10DE: return "Nvidia Corporation"; - case 0x13B5: return "Arm Limited"; - case 0x5143: return "Qualcomm Incorporated"; - case 0x8086: return "Intel Corporation"; - } - return StringUtil::format("Unknown VendorID %d", vendorID); -} - -void MapDepthStencilBits(Format format, uint &depthBits, uint &stencilBits) { - switch (format) { - case Format::D16: - depthBits = 16; - stencilBits = 0; - break; - case Format::D16S8: - depthBits = 16; - stencilBits = 8; - break; - case Format::D24: - depthBits = 24; - stencilBits = 0; - break; - case Format::D24S8: - depthBits = 24; - stencilBits = 8; - break; - case Format::D32F: - depthBits = 32; - stencilBits = 0; - break; - case Format::D32F_S8: - depthBits = 32; - stencilBits = 8; - break; - default: break; - } -} - -const VkSurfaceTransformFlagsKHR TRANSFORMS_THAT_REQUIRE_FLIPPING = - VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR | - VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR; - -const VkPrimitiveTopology VK_PRIMITIVE_MODES[] = { - VK_PRIMITIVE_TOPOLOGY_POINT_LIST, // POINT_LIST - VK_PRIMITIVE_TOPOLOGY_LINE_LIST, // LINE_LIST - VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, // LINE_STRIP - (VkPrimitiveTopology)0, // LINE_LOOP - VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, // LINE_LIST_ADJACENCY - VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, // LINE_STRIP_ADJACENCY - (VkPrimitiveTopology)0, // ISO_LINE_LIST - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // TRIANGLE_LIST - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, // TRIANGLE_STRIP - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN, // TRIANGLE_FAN - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, // TRIANGLE_LIST_ADJACENCY - VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, // TRIANGLE_STRIP_ADJACENCY, - (VkPrimitiveTopology)0, // TRIANGLE_PATCH_ADJACENCY, - VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, // QUAD_PATCH_LIST, -}; - -const VkCullModeFlags VK_CULL_MODES[] = { - VK_CULL_MODE_NONE, - VK_CULL_MODE_FRONT_BIT, - VK_CULL_MODE_BACK_BIT, -}; - -const VkPolygonMode VK_POLYGON_MODES[] = { - VK_POLYGON_MODE_FILL, - VK_POLYGON_MODE_LINE, - VK_POLYGON_MODE_POINT, -}; - -const VkCompareOp VK_CMP_FUNCS[] = { - VK_COMPARE_OP_NEVER, - VK_COMPARE_OP_LESS, - VK_COMPARE_OP_EQUAL, - VK_COMPARE_OP_LESS_OR_EQUAL, - VK_COMPARE_OP_GREATER, - VK_COMPARE_OP_NOT_EQUAL, - VK_COMPARE_OP_GREATER_OR_EQUAL, - VK_COMPARE_OP_ALWAYS, -}; - -const VkStencilOp VK_STENCIL_OPS[] = { - VK_STENCIL_OP_ZERO, - VK_STENCIL_OP_KEEP, - VK_STENCIL_OP_REPLACE, - VK_STENCIL_OP_INCREMENT_AND_CLAMP, - VK_STENCIL_OP_DECREMENT_AND_CLAMP, - VK_STENCIL_OP_INVERT, - VK_STENCIL_OP_INCREMENT_AND_WRAP, - VK_STENCIL_OP_DECREMENT_AND_WRAP, -}; - -const VkBlendOp VK_BLEND_OPS[] = { - VK_BLEND_OP_ADD, - VK_BLEND_OP_SUBTRACT, - VK_BLEND_OP_REVERSE_SUBTRACT, - VK_BLEND_OP_MIN, - VK_BLEND_OP_MAX, -}; - -const VkBlendFactor VK_BLEND_FACTORS[] = { - VK_BLEND_FACTOR_ZERO, - VK_BLEND_FACTOR_ONE, - VK_BLEND_FACTOR_SRC_ALPHA, - VK_BLEND_FACTOR_DST_ALPHA, - VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, - VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, - VK_BLEND_FACTOR_SRC_COLOR, - VK_BLEND_FACTOR_DST_COLOR, - VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR, - VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR, - VK_BLEND_FACTOR_SRC_ALPHA_SATURATE, - VK_BLEND_FACTOR_CONSTANT_COLOR, - VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, - VK_BLEND_FACTOR_CONSTANT_ALPHA, - VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA, -}; - -const VkFilter VK_FILTERS[] = { - (VkFilter)0, // NONE - VK_FILTER_NEAREST, // POINT - VK_FILTER_LINEAR, // LINEAR - (VkFilter)0, // ANISOTROPIC -}; - -const VkSamplerMipmapMode VK_SAMPLER_MIPMAP_MODES[] = { - (VkSamplerMipmapMode)0, // NONE - VK_SAMPLER_MIPMAP_MODE_NEAREST, // POINT - VK_SAMPLER_MIPMAP_MODE_LINEAR, // LINEAR - VK_SAMPLER_MIPMAP_MODE_LINEAR, // ANISOTROPIC -}; - -const VkSamplerAddressMode VK_SAMPLER_ADDRESS_MODES[] = { - VK_SAMPLER_ADDRESS_MODE_REPEAT, // WRAP - VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, // MIRROR - VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // CLAMP - VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, // BORDER -}; - -const VkPipelineBindPoint VK_PIPELINE_BIND_POINTS[] = { - VK_PIPELINE_BIND_POINT_GRAPHICS, - VK_PIPELINE_BIND_POINT_COMPUTE, - VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, -}; - -const ThsvsAccessType THSVS_ACCESS_TYPES[] = { - THSVS_ACCESS_NONE, // NONE - THSVS_ACCESS_INDIRECT_BUFFER, // INDIRECT_BUFFER - THSVS_ACCESS_INDEX_BUFFER, // INDEX_BUFFER - THSVS_ACCESS_VERTEX_BUFFER, // VERTEX_BUFFER - THSVS_ACCESS_VERTEX_SHADER_READ_UNIFORM_BUFFER, // VERTEX_SHADER_READ_UNIFORM_BUFFER - THSVS_ACCESS_VERTEX_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // VERTEX_SHADER_READ_TEXTURE - THSVS_ACCESS_VERTEX_SHADER_READ_OTHER, // VERTEX_SHADER_READ_OTHER - THSVS_ACCESS_FRAGMENT_SHADER_READ_UNIFORM_BUFFER, // FRAGMENT_SHADER_READ_UNIFORM_BUFFER - THSVS_ACCESS_FRAGMENT_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // FRAGMENT_SHADER_READ_TEXTURE - THSVS_ACCESS_FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT, // FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT - THSVS_ACCESS_FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT, // FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT - THSVS_ACCESS_FRAGMENT_SHADER_READ_OTHER, // FRAGMENT_SHADER_READ_OTHER - THSVS_ACCESS_COLOR_ATTACHMENT_READ, // COLOR_ATTACHMENT_READ - THSVS_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ, // DEPTH_STENCIL_ATTACHMENT_READ - THSVS_ACCESS_COMPUTE_SHADER_READ_UNIFORM_BUFFER, // COMPUTE_SHADER_READ_UNIFORM_BUFFER - THSVS_ACCESS_COMPUTE_SHADER_READ_SAMPLED_IMAGE_OR_UNIFORM_TEXEL_BUFFER, // COMPUTE_SHADER_READ_TEXTURE - THSVS_ACCESS_COMPUTE_SHADER_READ_OTHER, // COMPUTE_SHADER_READ_OTHER - THSVS_ACCESS_TRANSFER_READ, // TRANSFER_READ - THSVS_ACCESS_HOST_READ, // HOST_READ - THSVS_ACCESS_PRESENT, // PRESENT - THSVS_ACCESS_VERTEX_SHADER_WRITE, // VERTEX_SHADER_WRITE - THSVS_ACCESS_FRAGMENT_SHADER_WRITE, // FRAGMENT_SHADER_WRITE - THSVS_ACCESS_COLOR_ATTACHMENT_WRITE, // COLOR_ATTACHMENT_WRITE - THSVS_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE, // DEPTH_STENCIL_ATTACHMENT_WRITE - THSVS_ACCESS_COMPUTE_SHADER_WRITE, // COMPUTE_SHADER_WRITE - THSVS_ACCESS_TRANSFER_WRITE, // TRANSFER_WRITE - THSVS_ACCESS_HOST_PREINITIALIZED, // HOST_PREINITIALIZED - THSVS_ACCESS_HOST_WRITE, // HOST_WRITE -}; - -const VkImageLayout VK_IMAGE_LAYOUTS[] = { - VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_GENERAL, - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - VK_IMAGE_LAYOUT_PREINITIALIZED, - VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, -}; - -const VkAccessFlags FULL_ACCESS_FLAGS = - VK_ACCESS_INDIRECT_COMMAND_READ_BIT | - VK_ACCESS_INDEX_READ_BIT | - VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | - VK_ACCESS_UNIFORM_READ_BIT | - VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | - VK_ACCESS_SHADER_READ_BIT | - VK_ACCESS_SHADER_WRITE_BIT | - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | - VK_ACCESS_TRANSFER_READ_BIT | - VK_ACCESS_TRANSFER_WRITE_BIT | - VK_ACCESS_HOST_READ_BIT | - VK_ACCESS_HOST_WRITE_BIT; - -void fullPipelineBarrier(VkCommandBuffer cmdBuff) { -#if CC_DEBUG > 0 - VkMemoryBarrier memoryBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; - memoryBarrier.srcAccessMask = FULL_ACCESS_FLAGS; - memoryBarrier.dstAccessMask = FULL_ACCESS_FLAGS; - vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr); -#endif -} - -template -char (*countofHelper(T (&_Array)[Size]))[Size]; - -#define COUNTOF(array) (sizeof(*countofHelper(array)) + 0) - -template -uint toUint(T value) { - static_assert(std::is_arithmetic::value, "T must be numeric"); - - CCASSERT(static_cast(value) <= static_cast(std::numeric_limits::max()), - "value is too big to be converted to uint"); - - return static_cast(value); -} - -VkDeviceSize roundUp(VkDeviceSize numToRound, uint multiple) { - return ((numToRound + multiple - 1) / multiple) * multiple; -} - -uint nextPowerOf2(uint v) { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return ++v; -} - -bool isLayerSupported(const char *required, const vector &available) { - for (const VkLayerProperties &availableLayer : available) { - if (strcmp(availableLayer.layerName, required) == 0) { - return true; - } - } - return false; -} - -bool isExtensionSupported(const char *required, const vector &available) { - for (const VkExtensionProperties &availableExtension : available) { - if (strcmp(availableExtension.extensionName, required) == 0) { - return true; - } - } - return false; -} -} // namespace +extern const VkSurfaceTransformFlagsKHR TRANSFORMS_THAT_REQUIRE_FLIPPING; +extern const VkPrimitiveTopology VK_PRIMITIVE_MODES[]; +extern const VkCullModeFlags VK_CULL_MODES[]; +extern const VkPolygonMode VK_POLYGON_MODES[]; +extern const VkCompareOp VK_CMP_FUNCS[]; +extern const VkStencilOp VK_STENCIL_OPS[]; +extern const VkBlendOp VK_BLEND_OPS[]; +extern const VkBlendFactor VK_BLEND_FACTORS[]; +extern const VkFilter VK_FILTERS[]; +extern const VkSamplerMipmapMode VK_SAMPLER_MIPMAP_MODES[]; +extern const VkSamplerAddressMode VK_SAMPLER_ADDRESS_MODES[]; +extern const VkPipelineBindPoint VK_PIPELINE_BIND_POINTS[]; +extern const ThsvsAccessType THSVS_ACCESS_TYPES[]; +extern const VkImageLayout VK_IMAGE_LAYOUTS[]; +extern const VkAccessFlags FULL_ACCESS_FLAGS; } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/pipeline/PipelineStateManager.cpp b/native/cocos/renderer/pipeline/PipelineStateManager.cpp index 4d6bbc59a7..66249e50f9 100644 --- a/native/cocos/renderer/pipeline/PipelineStateManager.cpp +++ b/native/cocos/renderer/pipeline/PipelineStateManager.cpp @@ -25,9 +25,6 @@ #include "PipelineStateManager.h" #include "gfx-base/GFXDevice.h" -#include "gfx-base/GFXInputAssembler.h" -#include "gfx-base/GFXRenderPass.h" -#include "gfx-base/GFXShader.h" #include "helper/SharedMemory.h" namespace cc { @@ -45,10 +42,11 @@ gfx::PipelineState *PipelineStateManager::getOrCreatePipelineState(const PassVie const auto shaderID = shader->getID(); const auto hash = passHash ^ renderPassHash ^ iaHash ^ shaderID; - auto pso = _PSOHashMap[hash]; + auto *pso = _PSOHashMap[hash]; if (!pso) { - auto pipelineLayout = pass->getPipelineLayout(); - gfx::PipelineStateInfo info = { + auto *pipelineLayout = pass->getPipelineLayout(); + + pso = gfx::Device::getInstance()->createPipelineState({ shader, pipelineLayout, renderPass, @@ -57,9 +55,9 @@ gfx::PipelineState *PipelineStateManager::getOrCreatePipelineState(const PassVie *(pass->getDepthStencilState()), *(pass->getBlendState()), pass->getPrimitive(), - pass->getDynamicState()}; + pass->getDynamicState(), + }); - pso = gfx::Device::getInstance()->createPipelineState(std::move(info)); _PSOHashMap[hash] = pso; } @@ -70,7 +68,7 @@ gfx::PipelineState *PipelineStateManager::getOrCreatePipelineStateByJS(uint32_t gfx::Shader * shader, gfx::InputAssembler *inputAssembler, gfx::RenderPass * renderPass) { - const auto pass = GET_PASS(passHandle); + const auto *pass = GET_PASS(passHandle); CC_ASSERT(pass); return PipelineStateManager::getOrCreatePipelineState(pass, shader, inputAssembler, renderPass); } diff --git a/native/docs/LINTER_AUTOFIX_GUIDE.md b/native/docs/LINTER_AUTOFIX_GUIDE.md new file mode 100644 index 0000000000..4716a7f9b3 --- /dev/null +++ b/native/docs/LINTER_AUTOFIX_GUIDE.md @@ -0,0 +1,103 @@ +# Linter Auto-fix Guide + +This is a guide to help you setting up the appropriate environment to enable auto-fixing most of the coding style check rules, including both `clang-format` and `clang-tidy`. + +For now, **Visual Studio Code** is our first recommended IDE for the job, while a brief discussion about the support in different IDEs can be found at the end of this document. + +## VS Code Integration + +* Make sure both `clang-tidy` and `clang-format` are directly accessible in your terminal environment, i.e. install LLVM and add the bin folder into the environment path. LLVM 11+ is recommended. + + ![](imgs/LLVM.png) + +* Make sure you have `ANDROID_NDK_HOME` or `ANDROID_NDK_ROOT` or `NDK_ROOT` environment variable pointing to the Android NDK path. + + ![](imgs/NDK.png) + +* Open terminal (or git-bash if you are on windows), navigate to `engine-native` folder and run: + + ```bash + utils/generate_compile_commands_android.sh + ``` + + If it succeeds, you should see a `compile_commands.json` generated in the same folder, and ignored by git. + + ![](imgs/compile_commands.png) + +* Install both `C/C++` and `Clang-Tidy` extension from the market: + + ![](imgs/extensions.png) + +* If everything goes smoothly, after opening any source file, you should be able to see the `Clang-Tidy` extension's linting process and its output as warnings right inside the editor, without any errors. + + ![](imgs/tidy-output-editor.png) + +* But in the case when you do see errors popping up like this: (note the red color in the scroll bar) + + ![](imgs/tidy-output-error.png) + + That means you have compile errors **for this single file**. Since it does compile on our target platforms as part of the engine project library, the most common cause for this issue is that the dependent header declaration is not complete, i.e. the file is not self-contained. You should always declare all the headers your file depends on. + + In the case of this screenshot, the declaration of the base class `Object` is missing, so we are indeed missing headers. + +* If you've made any changes and need to re-lint the file, you should save the file and execute the `Clang-Tidy: Lint File` command: + + ![](imgs/re-lint.png) + + This process can be a bit repetitive if you are modifying lots of files together, so there are options to `Lint On Save` or even `Fix On Save`: + + ![](imgs/tidy-options.png) + +* After clearing the compile errors, you are ready to execute auto fix. For now the only way to do this is to just enable the `Fix On Save` option, and save the file. + + ![](imgs/auto-fix.gif) + + Note that auto-fix can not fix all the issues `Clang-Tidy` reports. You still have to manually fix some of the trickier issues, but generally most of the issues are trivial and can be auto-fixed. + + Also note that the linting and fixing process for `Clang-Tidy` is understandably time-consuming. So you should only enable the xx-on-save options when actually needed to. The screenshot does not reflect the actual time needed for the process. + +* Whenever in doubt, you can always refer to the `Clang-Tidy` extension output window for more detailed information. + + ![](imgs/tidy-output.png) + + This is a screenshot of linting issue-free files. + +* For `Clang-Format` issues, there will be no in-place editor suggestions, but all issues are strictly auto-fixable, and if the environment set up above goes smoothly, it is as simple as execute the `Format Document` command. (By default `Shift + Alt + F` on Windows) + + ![](imgs/format.png) + + This functionality is provided by the C/C++ extension. + + ![](imgs/auto-format.gif) + + On the contrary to `Clang-Tidy`, `Clang-Format` auto-formating is a immediate operation and should be used frequently. + +> Note: The `compile_commands.json` generated by current approach is essentially the Android development environment. So other platform-specific code may likely not be included in the check. This behavior is consistent with CI test environment. + +> Also note: Once new source files have been added to the project in the CMakeLists, the `compile_commands.json` has to be regenerated by running the same script in the third step. + +## Command Line Interface + +The second recommended way is to directly use the CLI. + +We provide a bash script to apply auto fix on all the changed files in arbitrary commit/range: + +First make sure the first three step in VS Code environment setup are done, i.e. `compile_commands.json` has been generated, then: + +```bash +utils/tidy-fix-commit.sh # run auto fix on files in the latest commit +utils/tidy-fix-commit.sh 70181ed # run auto fix on files in the specified commit +utils/tidy-fix-commit.sh HEAD~3..HEAD # run auto fix on files in the last 3 commit +``` + +All the issues will be reported in the standard output. This can be used as local self-test runs for CI checks. + +The CLI scripts can(and are recommended to) be used as complements to the VS Code environment. + +## Other IDEs + +It is possible to use other IDEs as long as they [support Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/Integrations.html). + +Notably there is `CLion`, or the `Resharper C++` MSVC extension that can do a fairly decent job on analysing and fixing linter issues. But both are commercially licensed and [intentionally](https://resharper-support.jetbrains.com/hc/en-us/articles/207242695-Can-I-fix-all-issues-Quick-Fixes-naming-suggestions-etc-at-once-) lacks the functionality to apply fixes to all the issues. They can either apply auto fix per instance, or apply to the whole project by issue types. + +Considering the current circumstances this is usually not what we want in daily development, since the more files we touch, the heavier the burden is to pass the CI check, which detects problems on all the changed files in a single pull request. diff --git a/native/docs/imgs/LLVM.png b/native/docs/imgs/LLVM.png new file mode 100644 index 0000000000..227ac7024b Binary files /dev/null and b/native/docs/imgs/LLVM.png differ diff --git a/native/docs/imgs/NDK.png b/native/docs/imgs/NDK.png new file mode 100644 index 0000000000..49bbbf0041 Binary files /dev/null and b/native/docs/imgs/NDK.png differ diff --git a/native/docs/imgs/auto-fix.gif b/native/docs/imgs/auto-fix.gif new file mode 100644 index 0000000000..8e681a982c Binary files /dev/null and b/native/docs/imgs/auto-fix.gif differ diff --git a/native/docs/imgs/auto-format.gif b/native/docs/imgs/auto-format.gif new file mode 100644 index 0000000000..c12d2673d9 Binary files /dev/null and b/native/docs/imgs/auto-format.gif differ diff --git a/native/docs/imgs/compile_commands.png b/native/docs/imgs/compile_commands.png new file mode 100644 index 0000000000..35e90992a7 Binary files /dev/null and b/native/docs/imgs/compile_commands.png differ diff --git a/native/docs/imgs/extensions.png b/native/docs/imgs/extensions.png new file mode 100644 index 0000000000..ba50222001 Binary files /dev/null and b/native/docs/imgs/extensions.png differ diff --git a/native/docs/imgs/format.png b/native/docs/imgs/format.png new file mode 100644 index 0000000000..f99c9eb38c Binary files /dev/null and b/native/docs/imgs/format.png differ diff --git a/native/docs/imgs/re-lint.png b/native/docs/imgs/re-lint.png new file mode 100644 index 0000000000..2ac467afe1 Binary files /dev/null and b/native/docs/imgs/re-lint.png differ diff --git a/native/docs/imgs/tidy-options.png b/native/docs/imgs/tidy-options.png new file mode 100644 index 0000000000..a336ce5339 Binary files /dev/null and b/native/docs/imgs/tidy-options.png differ diff --git a/native/docs/imgs/tidy-output-editor.png b/native/docs/imgs/tidy-output-editor.png new file mode 100644 index 0000000000..151a3e57c6 Binary files /dev/null and b/native/docs/imgs/tidy-output-editor.png differ diff --git a/native/docs/imgs/tidy-output-error.png b/native/docs/imgs/tidy-output-error.png new file mode 100644 index 0000000000..f542dac19c Binary files /dev/null and b/native/docs/imgs/tidy-output-error.png differ diff --git a/native/docs/imgs/tidy-output.png b/native/docs/imgs/tidy-output.png new file mode 100644 index 0000000000..fd9dfb9f31 Binary files /dev/null and b/native/docs/imgs/tidy-output.png differ diff --git a/native/utils/generate_compile_commands_android.sh b/native/utils/generate_compile_commands_android.sh new file mode 100755 index 0000000000..04f89fd9aa --- /dev/null +++ b/native/utils/generate_compile_commands_android.sh @@ -0,0 +1,17 @@ +if [ $# -ne 0 ]; then + ndk_path=$1 +elif [ -n "$ANDROID_NDK_HOME" ]; then + ndk_path=$ANDROID_NDK_HOME +elif [ -n "$ANDROID_NDK_ROOT" ]; then + ndk_path=$ANDROID_NDK_ROOT +elif [ -n "$NDK_ROOT" ]; then + ndk_path=$NDK_ROOT +else + echo "Cannot find NDK root path" + exit 1 +fi +cp CMakeLists.txt CMakeLists-bak.txt +echo -e "cmake_minimum_required(VERSION 3.8)\nproject(engine_native CXX)\nenable_language(C ASM)" | cat - CMakeLists-bak.txt > CMakeLists.txt +cmake -Bbuild -DCC_USE_GLES2=ON -DCC_USE_VULKAN=ON -DCC_USE_GLES3=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE="$ndk_path/build/cmake/android.toolchain.cmake" -DANDROID_PLATFORM=android-21 -G"Unix Makefiles" +mv CMakeLists-bak.txt CMakeLists.txt +cp build/compile_commands.json . diff --git a/native/utils/tidy-fix-commit.sh b/native/utils/tidy-fix-commit.sh new file mode 100755 index 0000000000..66ae576336 --- /dev/null +++ b/native/utils/tidy-fix-commit.sh @@ -0,0 +1,12 @@ +if [ $# -ne 0 ]; then + commit=$1 # can also pass ranges: HEAD~3..HEAD +else + commit=HEAD +fi +changes=`git diff-tree --no-commit-id --name-only -r $commit` +filtered=`node .github/workflows/filter_by_cdb.js $changes` +if [[ "$filtered-xxx" == "-xxx" ]]; then + echo "No source to be fixed" +else + clang-tidy --format-style=file --fix $filtered +fi