mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Clang-Tidy adaptations (#3379)
* gfx: CommandBuffer.draw accept DrawInfo * clang-tidy config * tidy adapt * enable function name check * better workflow
This commit is contained in:
+15
-30
@@ -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
|
||||
|
||||
+54
-75
@@ -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<xxx>() 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 }
|
||||
|
||||
+2
-4
@@ -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
|
||||
|
||||
+6
-7
@@ -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(" "));
|
||||
}
|
||||
console.log(ARGS.join(' '));
|
||||
}
|
||||
|
||||
+4
-3
@@ -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
|
||||
|
||||
Vendored
+23
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
--------------------------------
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Macros.h"
|
||||
#include <memory>
|
||||
|
||||
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 {}
|
||||
|
||||
@@ -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 <typename T>
|
||||
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_
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "memory/AllocatedObj.h"
|
||||
#include "memory/MemDef.h"
|
||||
#include "memory/Memory.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
|
||||
+34
-28
@@ -32,40 +32,46 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** @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 <typename T, size_t Size>
|
||||
char (*countOfHelper(T (&array)[Size]))[Size];
|
||||
|
||||
#define COUNTOF(array) (sizeof(*countOfHelper(array)) + 0)
|
||||
|
||||
template <class T>
|
||||
uint toUint(T value) {
|
||||
static_assert(std::is_arithmetic<T>::value, "T must be numeric");
|
||||
|
||||
CCASSERT(static_cast<uintmax_t>(value) <= static_cast<uintmax_t>(std::numeric_limits<uint>::max()),
|
||||
"value is too big to be converted to uint");
|
||||
|
||||
return static_cast<uint>(value);
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace cc
|
||||
|
||||
@@ -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 Alloc>
|
||||
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_
|
||||
|
||||
@@ -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<void>(_buffer, oldUsedSize), alignment);
|
||||
newUsedSize = reinterpret_cast<uintptr_t>(allocatedMemory) - reinterpret_cast<uintptr_t>(_buffer) + size;
|
||||
|
||||
if (newUsedSize > _capacity) // overflows
|
||||
{
|
||||
return nullptr;
|
||||
if (newUsedSize > _capacity) {
|
||||
return nullptr; // overflows
|
||||
}
|
||||
} while (!_usedSize.compare_exchange_weak(oldUsedSize, static_cast<uint32_t>(newUsedSize), std::memory_order_relaxed, std::memory_order_relaxed)); // 不可能存在ABA 不处理
|
||||
} while (!_usedSize.compare_exchange_weak(oldUsedSize, static_cast<uint32_t>(newUsedSize), std::memory_order_relaxed, std::memory_order_relaxed)); // no ABA possible
|
||||
|
||||
return allocatedMemory;
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "base/Macros.h"
|
||||
#include "base/memory/Memory.h"
|
||||
|
||||
using namespace se;
|
||||
namespace se {
|
||||
|
||||
cc::map<PoolType, BufferPool *> 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<uint>(_chunks.size()), _bytesPerChunk);
|
||||
|
||||
uint8_t *realPtr = nullptr;
|
||||
size_t len = 0;
|
||||
@@ -61,3 +61,5 @@ Object *BufferPool::allocateNewChunk() {
|
||||
|
||||
return jsObj;
|
||||
}
|
||||
|
||||
} // namespace se
|
||||
|
||||
+297
-312
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
|
||||
@@ -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 <typename DeviceCtor, typename Enable = std::enable_if_t<std::is_base_of<Device, DeviceCtor>::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);
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ namespace framegraph {
|
||||
|
||||
template <typename DescriptorType>
|
||||
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 <typename DeviceResourceType, typename DescriptorType>
|
||||
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<DeviceResourceType, DescriptorType, DeviceResourceCreatorType, Des
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DEFINE_GFX_RESOURCE(Type) \
|
||||
template <> \
|
||||
struct ResourceDescriptorHasher<gfx::Type##Info> final { \
|
||||
CC_INLINE uint32_t operator()(const gfx::Type##Info &desc) const noexcept { \
|
||||
return gfx::Type::computeHash(desc); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct DeviceResourceCreator<gfx::Type, gfx::Type##Info> final { \
|
||||
CC_INLINE gfx::Type *operator()(const gfx::Type##Info &desc) const noexcept { \
|
||||
return gfx::Device::getInstance()->create##Type(desc); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
using Type = Resource<gfx::Type, gfx::Type##Info>; \
|
||||
#define DEFINE_GFX_RESOURCE(Type) \
|
||||
template <> \
|
||||
struct ResourceDescriptorHasher<gfx::Type##Info> final { \
|
||||
CC_INLINE uint32_t operator()(const gfx::Type##Info &desc) const { \
|
||||
return gfx::Type::computeHash(desc); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct DeviceResourceCreator<gfx::Type, gfx::Type##Info> final { \
|
||||
CC_INLINE gfx::Type *operator()(const gfx::Type##Info &desc) const { \
|
||||
return gfx::Device::getInstance()->create##Type(desc); \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
using Type = Resource<gfx::Type, gfx::Type##Info>; /* NOLINT(bugprone-macro-parentheses) N/A */ \
|
||||
using Type##Handle = TypedHandle<Type>;
|
||||
|
||||
DEFINE_GFX_RESOURCE(Buffer)
|
||||
|
||||
@@ -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<CommandBuffer *>(count);
|
||||
auto **actorCmdBuffs = getAllocator()->allocate<CommandBuffer *>(count);
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
actorCmdBuffs[i] = static_cast<CommandBufferAgent *>(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<InputAssemblerAgent *>(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<uint8_t>(size);
|
||||
auto *actorData = getAllocator()->allocate<uint8_t>(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<BufferTextureCopy>(count);
|
||||
auto *actorRegions = allocator->allocate<BufferTextureCopy>(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<const uint8_t *>(bufferCount);
|
||||
for (uint i = 0u, n = 0u; i < count; i++) {
|
||||
const auto **actorBuffers = allocator->allocate<const uint8_t *>(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<uint8_t>(size);
|
||||
auto *buffer = allocator->allocate<uint8_t>(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<TextureAgent *>(srcTexture)->getActor();
|
||||
if (dstTexture) actorDstTexture = static_cast<TextureAgent *>(dstTexture)->getActor();
|
||||
|
||||
TextureBlit *actorRegions = getAllocator()->allocate<TextureBlit>(count);
|
||||
auto *actorRegions = getAllocator()->allocate<TextureBlit>(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<TextureBarrier *>(textureBarrierCount);
|
||||
memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(TextureBarrier *));
|
||||
memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(uintptr_t));
|
||||
|
||||
actorTextures = getAllocator()->allocate<Texture *>(textureBarrierCount);
|
||||
for (uint i = 0u; i < textureBarrierCount; ++i) {
|
||||
for (uint i = 0U; i < textureBarrierCount; ++i) {
|
||||
actorTextures[i] = textures[i] ? static_cast<const TextureAgent *>(textures[i])->getActor() : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<CommandBufferAgent *>(_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<BufferTextureCopy>(count);
|
||||
auto *actorRegions = allocator->allocate<BufferTextureCopy>(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<const uint8_t *>(bufferCount);
|
||||
for (uint i = 0u, n = 0u; i < count; i++) {
|
||||
const auto **actorBuffers = allocator->allocate<const uint8_t *>(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<uint8_t>(size);
|
||||
auto *buffer = allocator->allocate<uint8_t>(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<CommandBufferAgent *>(count);
|
||||
auto **agentCmdBuffs = getMainAllocator()->allocate<CommandBufferAgent *>(count);
|
||||
for (uint i = 0; i < count; ++i) {
|
||||
agentCmdBuffs[i] = static_cast<CommandBufferAgent *const>(cmdBuffs[i]);
|
||||
MessageQueue::freeChunksInFreeQueue(agentCmdBuffs[i]->_messageQueue);
|
||||
|
||||
@@ -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<Device> {
|
||||
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<LinearAllocatorPool *> _allocatorPools;
|
||||
Semaphore _frameBoundarySemaphore{MAX_CPU_FRAME_AHEAD};
|
||||
|
||||
|
||||
@@ -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<uint>(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.size) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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) {
|
||||
|
||||
@@ -35,8 +35,7 @@ CommandBuffer::CommandBuffer()
|
||||
: GFXObject(ObjectType::COMMAND_BUFFER) {
|
||||
}
|
||||
|
||||
CommandBuffer::~CommandBuffer() {
|
||||
}
|
||||
CommandBuffer::~CommandBuffer() = default;
|
||||
|
||||
void CommandBuffer::initialize(const CommandBufferInfo& info) {
|
||||
_type = info.type;
|
||||
|
||||
@@ -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<uint> &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<uint> &dynamicOffsets) {
|
||||
bindDescriptorSet(set, descriptorSet, static_cast<uint>(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<uint>(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<uint>(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<uint>(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<uint>(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<uint> &dynamicOffsets) {
|
||||
bindDescriptorSet(set, descriptorSet, static_cast<uint>(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<uint>(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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Color>;
|
||||
struct BindingMappingInfo {
|
||||
std::vector<int> bufferOffsets;
|
||||
std::vector<int> 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<DrawInfo>;
|
||||
|
||||
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<DispatchInfo>;
|
||||
@@ -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<Uniform>;
|
||||
|
||||
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<UniformBlock>;
|
||||
|
||||
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<UniformSamplerTexture>;
|
||||
|
||||
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<UniformSampler>;
|
||||
|
||||
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<UniformTexture>;
|
||||
|
||||
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<UniformStorageImage>;
|
||||
|
||||
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<UniformStorageBuffer>;
|
||||
|
||||
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<UniformInputAttachment>;
|
||||
@@ -1054,23 +1051,6 @@ struct ColorAttachment {
|
||||
StoreOp storeOp = StoreOp::STORE;
|
||||
std::vector<AccessType> beginAccesses;
|
||||
std::vector<AccessType> 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<AccessType> beginAccesses_ = {},
|
||||
std::vector<AccessType> endAccesses_ = {AccessType::PRESENT}) noexcept {
|
||||
format = format_;
|
||||
sampleCount = sampleCount_;
|
||||
loadOp = loadOp_;
|
||||
storeOp = storeOp_;
|
||||
beginAccesses = beginAccesses_;
|
||||
endAccesses = endAccesses_;
|
||||
}
|
||||
};
|
||||
|
||||
using ColorAttachmentList = vector<ColorAttachment>;
|
||||
@@ -1084,27 +1064,6 @@ struct DepthStencilAttachment {
|
||||
StoreOp stencilStoreOp = StoreOp::STORE;
|
||||
std::vector<AccessType> beginAccesses;
|
||||
std::vector<AccessType> 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<AccessType> beginAccesses_ = {},
|
||||
std::vector<AccessType> 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.
|
||||
|
||||
@@ -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<uint>(format)].isCompressed) {
|
||||
return (width * height * depth * GFX_FORMAT_INFOS[static_cast<uint>(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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<uint> 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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<uint>(regions.size()));
|
||||
copyBuffersToTexture(buffers.data(), dst, regions.data(), utils::toUint(regions.size()));
|
||||
}
|
||||
|
||||
void Device::flushCommands(const vector<CommandBuffer *> &cmdBuffs) {
|
||||
flushCommands(cmdBuffs.data(), static_cast<uint>(cmdBuffs.size()));
|
||||
flushCommands(cmdBuffs.data(), utils::toUint(cmdBuffs.size()));
|
||||
}
|
||||
|
||||
void Device::flushCommandsForJS(const vector<CommandBuffer *> &cmdBuffs) {
|
||||
flushCommands(cmdBuffs.data(), static_cast<uint>(cmdBuffs.size()));
|
||||
flushCommands(cmdBuffs.data(), utils::toUint(cmdBuffs.size()));
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -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<uint>(info.depthStencilMipmapLevel) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
return seed;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
for (const AccessType type : info.nextAccesses) {
|
||||
seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
|
||||
return seed;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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<std::string>{}(attribute.name) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (uint)(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(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
|
||||
|
||||
@@ -35,8 +35,7 @@ PipelineLayout::PipelineLayout()
|
||||
: GFXObject(ObjectType::PIPELINE_LAYOUT) {
|
||||
}
|
||||
|
||||
PipelineLayout::~PipelineLayout() {
|
||||
}
|
||||
PipelineLayout::~PipelineLayout() = default;
|
||||
|
||||
void PipelineLayout::initialize(const PipelineLayoutInfo& info) {
|
||||
_setLayouts = info.setLayouts;
|
||||
|
||||
@@ -35,8 +35,7 @@ PipelineState::PipelineState()
|
||||
: GFXObject(ObjectType::PIPELINE_STATE) {
|
||||
}
|
||||
|
||||
PipelineState::~PipelineState() {
|
||||
}
|
||||
PipelineState::~PipelineState() = default;
|
||||
|
||||
void PipelineState::initialize(const PipelineStateInfo &info) {
|
||||
_primitive = info.primitive;
|
||||
|
||||
@@ -35,8 +35,7 @@ Queue::Queue()
|
||||
: GFXObject(ObjectType::QUEUE) {
|
||||
}
|
||||
|
||||
Queue::~Queue() {
|
||||
}
|
||||
Queue::~Queue() = default;
|
||||
|
||||
void Queue::initialize(const QueueInfo& info) {
|
||||
_type = info.type;
|
||||
|
||||
@@ -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<uint>(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<uint>(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
|
||||
|
||||
@@ -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<uint>(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(_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<uint>(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(attachment.loadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(attachment.storeOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
for (AccessType type : attachment.beginAccesses) {
|
||||
seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
for (AccessType type : attachment.endAccesses) {
|
||||
seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(info.depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.depthStencilAttachment.depthLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.depthStencilAttachment.depthStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.depthStencilAttachment.stencilLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
for (AccessType type : info.depthStencilAttachment.endAccesses) {
|
||||
seed ^= (uint)type + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +209,7 @@ void RenderPass::destroy() {
|
||||
|
||||
_colorAttachments.clear();
|
||||
_subpasses.clear();
|
||||
_hash = 0u;
|
||||
_hash = 0U;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -37,8 +37,7 @@ Shader::Shader()
|
||||
_shaderID = generateShaderID();
|
||||
}
|
||||
|
||||
Shader::~Shader() {
|
||||
}
|
||||
Shader::~Shader() = default;
|
||||
|
||||
void Shader::initialize(const ShaderInfo &info) {
|
||||
_name = info.name;
|
||||
|
||||
@@ -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<uint>(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(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<uint>(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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<uint>(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
for (const AccessType type : info.nextAccesses) {
|
||||
seed ^= (uint)(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= static_cast<uint>(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<uint>(info.srcQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= (info.dstQueue ? static_cast<uint>(info.dstQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#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;
|
||||
};
|
||||
|
||||
@@ -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<GLES2Buffer *>(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
|
||||
|
||||
@@ -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<GLES2RenderPass *>(renderPass)->gpuRenderPass();
|
||||
cmd->gpuFBO = static_cast<GLES2Framebuffer *>(fbo)->gpuFBO();
|
||||
cmd->renderArea = renderArea;
|
||||
cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size();
|
||||
cmd->gpuRenderPass = static_cast<GLES2RenderPass *>(renderPass)->gpuRenderPass();
|
||||
cmd->gpuFBO = static_cast<GLES2Framebuffer *>(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<GLES2PipelineState *>(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<GLES2DescriptorSet *>(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<GLES2InputAssembler *>(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<GLES2InputAssembler *>(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<GLES2Buffer *>(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<const uint8_t *>(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<GLES2Texture *>(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<GLES2CommandBuffer *>(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<uint> &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);
|
||||
|
||||
@@ -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<GLES2CmdPackage *> _pendingPackages, _freePackages;
|
||||
GLES2GPUCommandAllocator *_cmdAllocator = nullptr;
|
||||
GLES2CmdPackage * _curCmdPackage = nullptr;
|
||||
queue<GLES2CmdPackage *> _pendingPackages, _freePackages;
|
||||
|
||||
bool _isInRenderPass = false;
|
||||
GLES2GPUPipelineState *_curGPUPipelineState = nullptr;
|
||||
bool _isInRenderPass = false;
|
||||
GLES2GPUPipelineState * _curGPUPipelineState = nullptr;
|
||||
vector<GLES2GPUDescriptorSet *> _curGPUDescriptorSets;
|
||||
vector<vector<uint>> _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<vector<uint>> _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
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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<GLES2GPUDescriptorSet *> gpuDescriptorSets;
|
||||
vector<uint> dynamicOffsets;
|
||||
Viewport viewport;
|
||||
Rect scissor;
|
||||
float lineWidth = 1.0f;
|
||||
bool depthBiasEnabled = false;
|
||||
GLES2DepthBias depthBias;
|
||||
Color blendConstants;
|
||||
GLES2DepthBounds depthBounds;
|
||||
GLES2StencilWriteMask stencilWriteMask;
|
||||
GLES2StencilCompareMask stencilCompareMask;
|
||||
vector<uint> 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<GLESCmdType> cmds;
|
||||
CachedArray<GLES2CmdBeginRenderPass *> beginRenderPassCmds;
|
||||
CachedArray<GLES2CmdBindStates *> bindStatesCmds;
|
||||
CachedArray<GLES2CmdDraw *> drawCmds;
|
||||
CachedArray<GLES2CmdUpdateBuffer *> updateBufferCmds;
|
||||
CachedArray<GLESCmdType> cmds;
|
||||
CachedArray<GLES2CmdBeginRenderPass *> beginRenderPassCmds;
|
||||
CachedArray<GLES2CmdBindStates *> bindStatesCmds;
|
||||
CachedArray<GLES2CmdDraw *> drawCmds;
|
||||
CachedArray<GLES2CmdUpdateBuffer *> updateBufferCmds;
|
||||
CachedArray<GLES2CmdCopyBufferToTexture *> copyBufferToTextureCmds;
|
||||
};
|
||||
|
||||
class GLES2GPUCommandAllocator final : public Object {
|
||||
public:
|
||||
CommandPool<GLES2CmdBeginRenderPass> beginRenderPassCmdPool;
|
||||
CommandPool<GLES2CmdBindStates> bindStatesCmdPool;
|
||||
CommandPool<GLES2CmdDraw> drawCmdPool;
|
||||
CommandPool<GLES2CmdUpdateBuffer> updateBufferCmdPool;
|
||||
CommandPool<GLES2CmdBeginRenderPass> beginRenderPassCmdPool;
|
||||
CommandPool<GLES2CmdBindStates> bindStatesCmdPool;
|
||||
CommandPool<GLES2CmdDraw> drawCmdPool;
|
||||
CommandPool<GLES2CmdUpdateBuffer> updateBufferCmdPool;
|
||||
CommandPool<GLES2CmdCopyBufferToTexture> 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<GLES2GPUDescriptorSet *> &gpuDescriptorSets, vector<uint> &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<GLES2GPUDescriptorSet *> &gpuDescriptorSets, const vector<uint> &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
|
||||
|
||||
@@ -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<ANativeWindow *>(_windowHandle), width, height, nFmt);
|
||||
#endif
|
||||
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_windowHandle), NULL));
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_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<uintptr_t>(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<ANativeWindow *>(_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<GLES2Context *>(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<GLES2Context *>(info.sharedCtx);
|
||||
auto *sharedCtx = static_cast<GLES2Context *>(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 {
|
||||
|
||||
@@ -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<const char *>(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<uint>(Feature::ELEMENT_INDEX_UINT)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("color_buffer_float"))
|
||||
if (checkExtension("color_buffer_float")) {
|
||||
_features[static_cast<uint>(Feature::COLOR_FLOAT)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("color_buffer_half_float"))
|
||||
if (checkExtension("color_buffer_half_float")) {
|
||||
_features[static_cast<uint>(Feature::COLOR_HALF_FLOAT)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("texture_float_linear"))
|
||||
if (checkExtension("texture_float_linear")) {
|
||||
_features[static_cast<uint>(Feature::TEXTURE_FLOAT_LINEAR)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("texture_half_float_linear"))
|
||||
if (checkExtension("texture_half_float_linear")) {
|
||||
_features[static_cast<uint>(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("draw_buffers"))
|
||||
if (checkExtension("draw_buffers")) {
|
||||
_features[static_cast<uint>(Feature::MULTIPLE_RENDER_TARGETS)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("blend_minmax"))
|
||||
if (checkExtension("blend_minmax")) {
|
||||
_features[static_cast<uint>(Feature::BLEND_MINMAX)] = true;
|
||||
}
|
||||
|
||||
_useVAO = checkExtension("vertex_array_object");
|
||||
_useDrawInstanced = checkExtension("draw_instanced");
|
||||
_useInstancedArrays = _features[static_cast<uint>(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<uint>(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<const char *>(glGetString(GL_RENDERER));
|
||||
_vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
|
||||
_version = reinterpret_cast<const char *>(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<GLint *>(&_caps.maxVertexAttributes));
|
||||
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, reinterpret_cast<GLint *>(&_caps.maxVertexUniformVectors));
|
||||
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, reinterpret_cast<GLint *>(&_caps.maxFragmentUniformVectors));
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxTextureUnits));
|
||||
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxVertexTextureUnits));
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast<GLint *>(&_caps.maxTextureSize));
|
||||
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, reinterpret_cast<GLint *>(&_caps.maxCubeMapTextureSize));
|
||||
glGetIntegerv(GL_DEPTH_BITS, reinterpret_cast<GLint *>(&_caps.depthBits));
|
||||
glGetIntegerv(GL_STENCIL_BITS, reinterpret_cast<GLint *>(&_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<GLES2Queue *>(_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<GLES2Texture *>(dst)->gpuTexture(), regions, count);
|
||||
cmdFuncGLES2CopyBuffersToTexture(this, buffers, static_cast<GLES2Texture *>(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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<GLES2Texture *>(_colorTextures[i]);
|
||||
if (colorTexture) {
|
||||
_gpuFBO->gpuColorTextures[i] = colorTexture->gpuTexture();
|
||||
}
|
||||
@@ -71,12 +69,12 @@ void GLES2Framebuffer::doInit(const FramebufferInfo &info) {
|
||||
_gpuFBO->gpuDepthStencilTexture = static_cast<GLES2Texture *>(_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;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#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<GLES2GPUBuffer *> GLES2GPUBufferList;
|
||||
using GLES2GPUBufferList = vector<GLES2GPUBuffer *>;
|
||||
|
||||
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<GLES2GPUTexture *> GLES2GPUTextureList;
|
||||
using GLES2GPUTextureList = vector<GLES2GPUTexture *>;
|
||||
|
||||
class GLES2GPUSampler final : public Object {
|
||||
public:
|
||||
@@ -105,7 +108,7 @@ struct GLES2GPUInput final {
|
||||
GLenum glType = 0;
|
||||
GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<GLES2GPUInput> GLES2GPUInputList;
|
||||
using GLES2GPUInputList = vector<GLES2GPUInput>;
|
||||
|
||||
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<uint8_t *>(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<GLES2GPUUniform> GLES2GPUUniformList;
|
||||
using GLES2GPUUniformList = vector<GLES2GPUUniform>;
|
||||
|
||||
struct GLES2GPUUniformBlock final {
|
||||
uint set = 0;
|
||||
@@ -160,29 +164,29 @@ struct GLES2GPUUniformBlock final {
|
||||
GLES2GPUUniformList glUniforms;
|
||||
GLES2GPUUniformList glActiveUniforms;
|
||||
};
|
||||
typedef vector<GLES2GPUUniformBlock> GLES2GPUUniformBlockList;
|
||||
using GLES2GPUUniformBlockList = vector<GLES2GPUUniformBlock>;
|
||||
|
||||
struct GLES2GPUUniformSampler final {
|
||||
uint set = 0;
|
||||
uint binding = 0;
|
||||
String name;
|
||||
Type type = Type::UNKNOWN;
|
||||
uint count = 0u;
|
||||
uint count = 0U;
|
||||
|
||||
vector<int> units;
|
||||
GLenum glType = 0;
|
||||
GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<GLES2GPUUniformSampler> GLES2GPUUniformSamplerList;
|
||||
using GLES2GPUUniformSamplerList = vector<GLES2GPUUniformSampler>;
|
||||
|
||||
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<GLES2GPUShaderStage> GLES2GPUShaderStageList;
|
||||
using GLES2GPUShaderStageList = vector<GLES2GPUShaderStage>;
|
||||
|
||||
class GLES2GPUShader final : public Object {
|
||||
public:
|
||||
@@ -208,7 +212,7 @@ struct GLES2GPUAttribute final {
|
||||
bool isInstanced = false;
|
||||
uint offset = 0;
|
||||
};
|
||||
typedef vector<GLES2GPUAttribute> GLES2GPUAttributeList;
|
||||
using GLES2GPUAttributeList = vector<GLES2GPUAttribute>;
|
||||
|
||||
class GLES2GPUInputAssembler final : public Object {
|
||||
public:
|
||||
@@ -243,9 +247,9 @@ public:
|
||||
|
||||
vector<uint> bindingIndices;
|
||||
vector<uint> descriptorIndices;
|
||||
uint descriptorCount = 0u;
|
||||
uint descriptorCount = 0U;
|
||||
};
|
||||
typedef vector<GLES2GPUDescriptorSetLayout *> GLES2GPUDescriptorSetLayoutList;
|
||||
using GLES2GPUDescriptorSetLayoutList = vector<GLES2GPUDescriptorSetLayout *>;
|
||||
|
||||
class GLES2GPUPipelineLayout final : public Object {
|
||||
public:
|
||||
@@ -278,7 +282,7 @@ struct GLES2GPUDescriptor final {
|
||||
GLES2GPUTexture *gpuTexture = nullptr;
|
||||
GLES2GPUSampler *gpuSampler = nullptr;
|
||||
};
|
||||
typedef vector<GLES2GPUDescriptor> GLES2GPUDescriptorList;
|
||||
using GLES2GPUDescriptorList = vector<GLES2GPUDescriptor>;
|
||||
|
||||
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<uint8_t *>(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<Buffer> _pool;
|
||||
};
|
||||
|
||||
@@ -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<GLES2Buffer *>(_vertexBuffers[i]);
|
||||
_gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer();
|
||||
}
|
||||
if (info.indexBuffer)
|
||||
if (info.indexBuffer) {
|
||||
_gpuInputAssembler->gpuIndexBuffer = static_cast<GLES2Buffer *>(info.indexBuffer)->gpuBuffer();
|
||||
}
|
||||
|
||||
if (info.indirectBuffer)
|
||||
if (info.indirectBuffer) {
|
||||
_gpuInputAssembler->gpuIndirectBuffer = static_cast<GLES2Buffer *>(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;
|
||||
}
|
||||
|
||||
@@ -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<GLES2RenderPass *>(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<GLES2RenderPass *>(renderPass)->gpuRenderPass();
|
||||
GLES2GPUFramebuffer *gpuFramebuffer = static_cast<GLES2Framebuffer *>(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<uint> &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets;
|
||||
vector<uint> &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets;
|
||||
for (size_t i = 0u; i < _curDynamicOffsets.size(); i++) {
|
||||
vector<uint> &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<GLES2Buffer *>(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<GLES2Texture *>(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<GLES2PrimaryCommandBuffer *>(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<uint> &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets;
|
||||
vector<uint> &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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<GLES2CommandBuffer *>(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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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;
|
||||
_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
|
||||
|
||||
@@ -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<GLES3InputAssembler *>(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<const uint8_t *>(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<GLES3CommandBuffer *>(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<uint> &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<const GLES3GlobalBarrier *>(barrier)->gpuBarrier();
|
||||
const auto *gpuBarrier = static_cast<const GLES3GlobalBarrier *>(barrier)->gpuBarrier();
|
||||
|
||||
GLES3CmdBarrier *cmd = _cmdAllocator->barrierCmdPool.alloc();
|
||||
cmd->barriers = gpuBarrier->glBarriers;
|
||||
|
||||
@@ -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<vector<uint>> _curDynamicOffsets;
|
||||
Viewport _curViewport;
|
||||
Rect _curScissor;
|
||||
float _curLineWidth = 1.0f;
|
||||
float _curLineWidth = 1.0F;
|
||||
GLES3DepthBias _curDepthBias;
|
||||
Color _curBlendConstants;
|
||||
GLES3DepthBounds _curDepthBounds;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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<GLES3GPUDescriptorSet *> gpuDescriptorSets;
|
||||
vector<uint> dynamicOffsets;
|
||||
Viewport viewport;
|
||||
Rect scissor;
|
||||
float lineWidth = 1.0f;
|
||||
bool depthBiasEnabled = false;
|
||||
GLES3DepthBias depthBias;
|
||||
Color blendConstants;
|
||||
GLES3DepthBounds depthBounds;
|
||||
GLES3StencilWriteMask stencilWriteMask;
|
||||
GLES3StencilCompareMask stencilCompareMask;
|
||||
vector<uint> 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<GLESCmdType> cmds;
|
||||
CachedArray<GLES3CmdBeginRenderPass *> beginRenderPassCmds;
|
||||
CachedArray<GLES3CmdBindStates *> bindStatesCmds;
|
||||
CachedArray<GLES3CmdDraw *> drawCmds;
|
||||
CachedArray<GLES3CmdDispatch *> dispatchCmds;
|
||||
CachedArray<GLES3CmdBarrier *> barrierCmds;
|
||||
CachedArray<GLES3CmdUpdateBuffer *> updateBufferCmds;
|
||||
CachedArray<GLESCmdType> cmds;
|
||||
CachedArray<GLES3CmdBeginRenderPass *> beginRenderPassCmds;
|
||||
CachedArray<GLES3CmdBindStates *> bindStatesCmds;
|
||||
CachedArray<GLES3CmdDraw *> drawCmds;
|
||||
CachedArray<GLES3CmdDispatch *> dispatchCmds;
|
||||
CachedArray<GLES3CmdBarrier *> barrierCmds;
|
||||
CachedArray<GLES3CmdUpdateBuffer *> updateBufferCmds;
|
||||
CachedArray<GLES3CmdCopyBufferToTexture *> copyBufferToTextureCmds;
|
||||
CachedArray<GLES3CmdBlitTexture *> blitTextureCmds;
|
||||
CachedArray<GLES3CmdBlitTexture *> blitTextureCmds;
|
||||
};
|
||||
|
||||
class GLES3GPUCommandAllocator final : public Object {
|
||||
public:
|
||||
CommandPool<GLES3CmdBeginRenderPass> beginRenderPassCmdPool;
|
||||
CommandPool<GLES3CmdBindStates> bindStatesCmdPool;
|
||||
CommandPool<GLES3CmdDraw> drawCmdPool;
|
||||
CommandPool<GLES3CmdDispatch> dispatchCmdPool;
|
||||
CommandPool<GLES3CmdBarrier> barrierCmdPool;
|
||||
CommandPool<GLES3CmdUpdateBuffer> updateBufferCmdPool;
|
||||
CommandPool<GLES3CmdBeginRenderPass> beginRenderPassCmdPool;
|
||||
CommandPool<GLES3CmdBindStates> bindStatesCmdPool;
|
||||
CommandPool<GLES3CmdDraw> drawCmdPool;
|
||||
CommandPool<GLES3CmdDispatch> dispatchCmdPool;
|
||||
CommandPool<GLES3CmdBarrier> barrierCmdPool;
|
||||
CommandPool<GLES3CmdUpdateBuffer> updateBufferCmdPool;
|
||||
CommandPool<GLES3CmdCopyBufferToTexture> copyBufferToTextureCmdPool;
|
||||
CommandPool<GLES3CmdBlitTexture> blitTextureCmdPool;
|
||||
CommandPool<GLES3CmdBlitTexture> 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<GLES3GPUDescriptorSet *> &gpuDescriptorSets, vector<uint> &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<GLES3GPUDescriptorSet *> &gpuDescriptorSets, const vector<uint> &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
|
||||
|
||||
@@ -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<ANativeWindow *>(_windowHandle), width, height, nFmt);
|
||||
#endif
|
||||
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_windowHandle), NULL));
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_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<GLES3Context *>(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<ANativeWindow *>(_windowHandle), width, height, nFmt);
|
||||
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_windowHandle), NULL));
|
||||
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast<EGLNativeWindowType>(_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 {
|
||||
|
||||
@@ -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<const char *>(glGetString(GL_EXTENSIONS));
|
||||
_extensions = StringUtil::split(extStr, " ");
|
||||
|
||||
_features[static_cast<uint>(Feature::TEXTURE_FLOAT)] = true;
|
||||
@@ -102,20 +102,25 @@ bool GLES3Device::doInit(const DeviceInfo &info) {
|
||||
_features[static_cast<uint>(Feature::ELEMENT_INDEX_UINT)] = true;
|
||||
|
||||
uint minorVersion = static_cast<GLES3Context *>(_context)->minor_ver();
|
||||
if (minorVersion)
|
||||
if (minorVersion) {
|
||||
_features[static_cast<uint>(Feature::COMPUTE_SHADER)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("color_buffer_float"))
|
||||
if (checkExtension("color_buffer_float")) {
|
||||
_features[static_cast<uint>(Feature::COLOR_FLOAT)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("color_buffer_half_float"))
|
||||
if (checkExtension("color_buffer_half_float")) {
|
||||
_features[static_cast<uint>(Feature::COLOR_HALF_FLOAT)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("texture_float_linear"))
|
||||
if (checkExtension("texture_float_linear")) {
|
||||
_features[static_cast<uint>(Feature::TEXTURE_FLOAT_LINEAR)] = true;
|
||||
}
|
||||
|
||||
if (checkExtension("texture_half_float_linear"))
|
||||
if (checkExtension("texture_half_float_linear")) {
|
||||
_features[static_cast<uint>(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = true;
|
||||
}
|
||||
|
||||
String compressedFmts;
|
||||
|
||||
@@ -147,9 +152,9 @@ bool GLES3Device::doInit(const DeviceInfo &info) {
|
||||
_features[static_cast<uint>(Feature::FORMAT_D24S8)] = true;
|
||||
_features[static_cast<uint>(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<const char *>(glGetString(GL_RENDERER));
|
||||
_vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
|
||||
_version = reinterpret_cast<const char *>(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<GLint *>(&_caps.maxVertexAttributes));
|
||||
glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, reinterpret_cast<GLint *>(&_caps.maxVertexUniformVectors));
|
||||
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, reinterpret_cast<GLint *>(&_caps.maxFragmentUniformVectors));
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<GLint *>(&_caps.maxUniformBufferBindings));
|
||||
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, reinterpret_cast<GLint *>(&_caps.maxUniformBlockSize));
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxTextureUnits));
|
||||
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, reinterpret_cast<GLint *>(&_caps.maxVertexTextureUnits));
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, reinterpret_cast<GLint *>(&_caps.maxTextureSize));
|
||||
glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, reinterpret_cast<GLint *>(&_caps.maxCubeMapTextureSize));
|
||||
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<GLint *>(&_caps.uboOffsetAlignment));
|
||||
glGetIntegerv(GL_DEPTH_BITS, reinterpret_cast<GLint *>(&_caps.depthBits));
|
||||
glGetIntegerv(GL_STENCIL_BITS, reinterpret_cast<GLint *>(&_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<GLint *>(&_caps.maxImageUnits));
|
||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, reinterpret_cast<GLint *>(&_caps.maxShaderStorageBlockSize));
|
||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, reinterpret_cast<GLint *>(&_caps.maxShaderStorageBufferBindings));
|
||||
glGetIntegerv(GL_MAX_COMPUTE_SHARED_MEMORY_SIZE, reinterpret_cast<GLint *>(&_caps.maxComputeSharedMemorySize));
|
||||
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupInvocations));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupSize.x));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupSize.y));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupSize.z));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupCount.x));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, reinterpret_cast<GLint *>(&_caps.maxComputeWorkGroupCount.y));
|
||||
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, reinterpret_cast<GLint *>(&_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<GLES3Queue *>(_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<GLES3Texture *>(dst)->gpuTexture(), regions, count);
|
||||
cmdFuncGLES3CopyBuffersToTexture(this, buffers, static_cast<GLES3Texture *>(dst)->gpuTexture(), regions, count);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<GLES3Texture *>(_colorTextures[i]);
|
||||
if (colorTexture) {
|
||||
_gpuFBO->gpuColorTextures[i] = colorTexture->gpuTexture();
|
||||
}
|
||||
@@ -62,12 +60,12 @@ void GLES3Framebuffer::doInit(const FramebufferInfo &info) {
|
||||
_gpuFBO->gpuDepthStencilTexture = static_cast<GLES3Texture *>(_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;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#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<GLES3GPUBuffer *> GLES3GPUBufferList;
|
||||
using GLES3GPUBufferList = vector<GLES3GPUBuffer *>;
|
||||
|
||||
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<GLES3GPUTexture *> GLES3GPUTextureList;
|
||||
using GLES3GPUTextureList = vector<GLES3GPUTexture *>;
|
||||
|
||||
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<GLES3GPUInput> GLES3GPUInputList;
|
||||
using GLES3GPUInputList = vector<GLES3GPUInput>;
|
||||
|
||||
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<GLES3GPUUniform> GLES3GPUUniformList;
|
||||
using GLES3GPUUniformList = vector<GLES3GPUUniform>;
|
||||
|
||||
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<GLES3GPUUniformBuffer> GLES3GPUUniformBufferList;
|
||||
using GLES3GPUUniformBufferList = vector<GLES3GPUUniformBuffer>;
|
||||
|
||||
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<int> units;
|
||||
GLenum glType = 0;
|
||||
GLint glLoc = -1;
|
||||
GLenum glType = 0;
|
||||
GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<GLES3GPUUniformSamplerTexture> GLES3GPUUniformSamplerTextureList;
|
||||
using GLES3GPUUniformSamplerTextureList = vector<GLES3GPUUniformSamplerTexture>;
|
||||
|
||||
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<int> units;
|
||||
GLenum glMemoryAccess = GL_READ_WRITE;
|
||||
GLint glLoc = -1;
|
||||
GLenum glMemoryAccess = GL_READ_WRITE;
|
||||
GLint glLoc = -1;
|
||||
};
|
||||
typedef vector<GLES3GPUUniformStorageImage> GLES3GPUUniformStorageImageList;
|
||||
using GLES3GPUUniformStorageImageList = vector<GLES3GPUUniformStorageImage>;
|
||||
|
||||
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<GLES3GPUShaderStage> GLES3GPUShaderStageList;
|
||||
using GLES3GPUShaderStageList = vector<GLES3GPUShaderStage>;
|
||||
|
||||
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<GLES3GPUAttribute> GLES3GPUAttributeList;
|
||||
using GLES3GPUAttributeList = vector<GLES3GPUAttribute>;
|
||||
|
||||
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<GLuint, GLuint> glVAOs;
|
||||
GLenum glIndexType = 0;
|
||||
map<GLuint, GLuint> 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<GLint> colorMipmapLevels;
|
||||
GLES3GPUTexture *gpuDepthStencilTexture = nullptr;
|
||||
GLint depthStencilMipmapLevel = 0;
|
||||
GLuint glFramebuffer = 0;
|
||||
bool isOffscreen = false;
|
||||
vector<GLint> colorMipmapLevels;
|
||||
GLES3GPUTexture * gpuDepthStencilTexture = nullptr;
|
||||
GLint depthStencilMipmapLevel = 0;
|
||||
GLuint glFramebuffer = 0;
|
||||
bool isOffscreen = false;
|
||||
};
|
||||
|
||||
class GLES3GPUDescriptorSetLayout final : public Object {
|
||||
public:
|
||||
DescriptorSetLayoutBindingList bindings;
|
||||
vector<uint> dynamicBindings;
|
||||
vector<uint> dynamicBindings;
|
||||
|
||||
vector<uint> bindingIndices;
|
||||
vector<uint> descriptorIndices;
|
||||
uint descriptorCount = 0u;
|
||||
uint descriptorCount = 0U;
|
||||
};
|
||||
typedef vector<GLES3GPUDescriptorSetLayout *> GLES3GPUDescriptorSetLayoutList;
|
||||
using GLES3GPUDescriptorSetLayoutList = vector<GLES3GPUDescriptorSetLayout *>;
|
||||
|
||||
class GLES3GPUPipelineLayout final : public Object {
|
||||
public:
|
||||
@@ -238,42 +244,42 @@ public:
|
||||
|
||||
// helper storages
|
||||
vector<vector<int>> dynamicOffsetIndices;
|
||||
vector<uint> dynamicOffsetOffsets;
|
||||
vector<uint> dynamicOffsets;
|
||||
uint dynamicOffsetCount;
|
||||
vector<uint> dynamicOffsetOffsets;
|
||||
vector<uint> 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<GLES3GPUDescriptor> GLES3GPUDescriptorList;
|
||||
using GLES3GPUDescriptorList = vector<GLES3GPUDescriptor>;
|
||||
|
||||
class GLES3GPUDescriptorSet final : public Object {
|
||||
public:
|
||||
GLES3GPUDescriptorList gpuDescriptors;
|
||||
const vector<uint> *descriptorIndices = nullptr;
|
||||
const vector<uint> * 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<GLuint> glBindUBOs;
|
||||
vector<GLuint> glBindUBOOffsets;
|
||||
GLuint glShaderStorageBuffer = 0;
|
||||
vector<GLuint> glBindSSBOs;
|
||||
vector<GLuint> glBindSSBOOffsets;
|
||||
GLuint glDispatchIndirectBuffer = 0;
|
||||
GLuint glVAO = 0;
|
||||
uint texUint = 0;
|
||||
vector<GLuint> glTextures;
|
||||
vector<GLuint> glImages;
|
||||
vector<GLuint> glSamplers;
|
||||
GLuint glProgram = 0;
|
||||
vector<bool> glEnabledAttribLocs;
|
||||
vector<bool> 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<GLuint> glBindUBOs;
|
||||
vector<GLuint> glBindUBOOffsets;
|
||||
GLuint glShaderStorageBuffer = 0;
|
||||
vector<GLuint> glBindSSBOs;
|
||||
vector<GLuint> glBindSSBOOffsets;
|
||||
GLuint glDispatchIndirectBuffer = 0;
|
||||
GLuint glVAO = 0;
|
||||
uint texUint = 0;
|
||||
vector<GLuint> glTextures;
|
||||
vector<GLuint> glImages;
|
||||
vector<GLuint> glSamplers;
|
||||
GLuint glProgram = 0;
|
||||
vector<bool> glEnabledAttribLocs;
|
||||
vector<bool> 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<String, uint> 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<uint>(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<GLuint, vector<GLuint>> _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<uint8_t *>(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<Buffer> _pool;
|
||||
};
|
||||
|
||||
@@ -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<GLES3Buffer *>(_vertexBuffers[i]);
|
||||
_gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer();
|
||||
}
|
||||
if (info.indexBuffer)
|
||||
if (info.indexBuffer) {
|
||||
_gpuInputAssembler->gpuIndexBuffer = static_cast<GLES3Buffer *>(info.indexBuffer)->gpuBuffer();
|
||||
}
|
||||
|
||||
if (info.indirectBuffer)
|
||||
if (info.indirectBuffer) {
|
||||
_gpuInputAssembler->gpuIndirectBuffer = static_cast<GLES3Buffer *>(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;
|
||||
}
|
||||
|
||||
@@ -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<GLES3RenderPass *>(renderPass)->gpuRenderPass();
|
||||
GLES3GPUFramebuffer *gpuFramebuffer = static_cast<GLES3Framebuffer *>(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<GLES3Buffer *>(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<GLES3Texture *>(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<GLES3Texture *>(srcTexture)->gpuTexture();
|
||||
if (dstTexture) gpuTextureDst = static_cast<GLES3Texture *>(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<GLES3PrimaryCommandBuffer *>(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<uint> &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets;
|
||||
vector<uint> &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<const GLES3GlobalBarrier *>(barrier)->gpuBarrier();
|
||||
GLES3CmdFuncMemoryBarrier(GLES3Device::getInstance(), gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion);
|
||||
const auto *gpuBarrier = static_cast<const GLES3GlobalBarrier *>(barrier)->gpuBarrier();
|
||||
cmdFuncGLES3MemoryBarrier(GLES3Device::getInstance(), gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion);
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<GLES3CommandBuffer *>(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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<CCMTLBuffer *>(ia->getIndirectBuffer());
|
||||
const auto *indexBuffer = static_cast<CCMTLBuffer *>(ia->getIndexBuffer());
|
||||
const auto *indirectBuffer = static_cast<CCMTLBuffer *>(_inputAssembler->getIndirectBuffer());
|
||||
const auto *indexBuffer = static_cast<CCMTLBuffer *>(_inputAssembler->getIndexBuffer());
|
||||
auto mtlEncoder = _renderEncoder.getMTLEncoder();
|
||||
|
||||
if (indirectBuffer) {
|
||||
@@ -328,47 +328,46 @@ void CCMTLCommandBuffer::draw(InputAssembler *ia) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DrawInfo drawInfo;
|
||||
static_cast<CCMTLInputAssembler *>(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<CCMTLTexture*>(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
|
||||
|
||||
@@ -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<MTLTexture>(_dssTex) release];
|
||||
|
||||
|
||||
MTLTextureDescriptor *dssDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||
const auto gpuFamily = mu::getGPUFamily(MTLFeatureSet(_mtlFeatureSet));
|
||||
dssDescriptor.pixelFormat = mu::getSupportedDepthStencilFormat(id<MTLDevice>(this->_mtlDevice), gpuFamily, _caps.depthBits);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -131,7 +131,7 @@ void CommandBufferValidator::execute(CommandBuffer *const *cmdBuffs, uint32_t co
|
||||
static vector<CommandBuffer *> cmdBuffActors;
|
||||
cmdBuffActors.resize(count);
|
||||
|
||||
for (uint i = 0u; i < count; ++i) {
|
||||
for (uint i = 0U; i < count; ++i) {
|
||||
cmdBuffActors[i] = static_cast<CommandBufferValidator *>(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<InputAssemblerValidator *>(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<BufferValidator *>(buff);
|
||||
auto *bufferValidator = static_cast<BufferValidator *>(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<TextureValidator *>(texture);
|
||||
auto *textureValidator = static_cast<TextureValidator *>(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<const TextureValidator *>(textures[i])->getActor() : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<TextureValidator *>(dst);
|
||||
auto *textureValidator = static_cast<TextureValidator *>(dst);
|
||||
textureValidator->updateRedundencyCheck();
|
||||
|
||||
_actor->copyBuffersToTexture(buffers, textureValidator->getActor(), regions, count);
|
||||
@@ -245,7 +245,7 @@ void DeviceValidator::flushCommands(CommandBuffer *const *cmdBuffs, uint count)
|
||||
static vector<CommandBuffer *> cmdBuffActors;
|
||||
cmdBuffActors.resize(count);
|
||||
|
||||
for (uint i = 0u; i < count; ++i) {
|
||||
for (uint i = 0U; i < count; ++i) {
|
||||
cmdBuffActors[i] = static_cast<CommandBufferValidator *>(cmdBuffs[i])->getActor();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<CCVKBuffer *>(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
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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<CCVKQueue *>(_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<CCVKFramebuffer *>(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<uint>(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<float>(renderArea.x), static_cast<float>(renderArea.y), static_cast<float>(renderArea.width), static_cast<float>(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<CCVKPipelineState *>(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<uint>(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<float>(vp.left), static_cast<float>(vp.top), static_cast<float>(vp.width), static_cast<float>(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<CCVKInputAssembler *>(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<CCVKInputAssembler *>(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<CCVKCommandBuffer *>(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<CCVKBuffer *>(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<CCVKTexture *>(texture)->gpuTexture(), regions, count, _gpuCommandBuffer);
|
||||
cmdFuncCCVKCopyBuffersToTexture(CCVKDevice::getInstance(), buffers, static_cast<CCVKTexture *>(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<uint>(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<CCVKBuffer *>(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<const CCVKGlobalBarrier *>(barrier)->gpuBarrier();
|
||||
const auto *gpuBarrier = static_cast<const CCVKGlobalBarrier *>(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<const CCVKTextureBarrier *const>(textureBarriers[i])->gpuBarrier();
|
||||
for (uint i = 0U; i < textureBarrierCount; ++i) {
|
||||
const auto *gpuBarrier = static_cast<const CCVKTextureBarrier *const>(textureBarriers[i])->gpuBarrier();
|
||||
_imageMemoryBarriers[i] = gpuBarrier->vkBarrier;
|
||||
|
||||
if (textures[i]) {
|
||||
auto gpuTexture = static_cast<const CCVKTexture *const>(textures[i])->gpuTexture();
|
||||
auto *gpuTexture = static_cast<const CCVKTexture *const>(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,19 +52,19 @@ CCVKGPUDescriptorSetPool *CCVKGPUDevice::getDescriptorSetPool(uint layoutID) {
|
||||
return &_descriptorSetPools[layoutID];
|
||||
}
|
||||
|
||||
void insertVkDynamicStates(vector<VkDynamicState> &out, const vector<DynamicStateFlagBit> &dynamicStates) {
|
||||
void insertVkDynamicStates(vector<VkDynamicState> *out, const vector<DynamicStateFlagBit> &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<VkDynamicState> &out, const vector<DynamicStat
|
||||
}
|
||||
}
|
||||
|
||||
void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) {
|
||||
uint queueType = 0u;
|
||||
void cmdFuncCCVKGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) {
|
||||
uint queueType = 0U;
|
||||
VkBool32 needPresentable = VK_FALSE;
|
||||
switch (gpuQueue->type) {
|
||||
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<uint>(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<uint>(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<uint>(gpuSampler->magFilter)];
|
||||
createInfo.minFilter = VK_FILTERS[static_cast<uint>(gpuSampler->minFilter)];
|
||||
createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODES[static_cast<uint>(gpuSampler->mipFilter)];
|
||||
createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODES[static_cast<uint>(gpuSampler->addressU)];
|
||||
createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODES[static_cast<uint>(gpuSampler->addressV)];
|
||||
createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODES[static_cast<uint>(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<float>(gpuSampler->maxAnisotropy));
|
||||
createInfo.compareEnable = gpuSampler->cmpFunc != ComparisonFunc::ALWAYS;
|
||||
createInfo.compareOp = VK_CMP_FUNCS[(uint)gpuSampler->cmpFunc];
|
||||
createInfo.compareOp = VK_CMP_FUNCS[static_cast<uint>(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<VkAttachmentDescription> attachmentDescriptions;
|
||||
static vector<VkSubpassDescription> subpassDescriptions;
|
||||
static vector<VkAttachmentReference> attachmentReferences;
|
||||
@@ -240,7 +240,7 @@ void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
|
||||
vector<CCVKAccessInfo> beginAccessInfos(colorAttachmentCount + hasDepth);
|
||||
vector<CCVKAccessInfo> 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<ThsvsAccessType> &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<uint>(type)]);
|
||||
}
|
||||
for (AccessType type : attachment.endAccesses) {
|
||||
endAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]);
|
||||
endAccesses.push_back(THSVS_ACCESS_TYPES[static_cast<uint>(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<uint>(type)]);
|
||||
}
|
||||
for (AccessType type : depthStencilAttachment.endAccesses) {
|
||||
endAccesses.push_back(THSVS_ACCESS_TYPES[(uint)type]);
|
||||
endAccesses.push_back(THSVS_ACCESS_TYPES[static_cast<uint>(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<uint32_t>(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<uint32_t>(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<uint>(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<VkImageView> 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<unsigned int> 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<VkDescriptorSetLayoutBinding> &bindings = gpuDescriptorSetLayout->vkBindings;
|
||||
|
||||
vector<VkDescriptorUpdateTemplateEntry> 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<VkPipelineShaderStageCreateInfo> 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<size_t>(attr.stream + 1));
|
||||
}
|
||||
|
||||
vector<VkVertexInputBindingDescription> 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<uint>(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<uint>(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<uint>(gpuPipelineState->primitive)];
|
||||
createInfo.pInputAssemblyState = &inputAssembly;
|
||||
|
||||
///////////////////// Dynamic State /////////////////////
|
||||
|
||||
vector<VkDynamicState> 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<uint>(gpuPipelineState->rs.polygonMode)];
|
||||
rasterizationState.cullMode = VK_CULL_MODES[static_cast<uint>(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<uint>(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<uint>(gpuPipelineState->dss.stencilFailOpFront)],
|
||||
VK_STENCIL_OPS[static_cast<uint>(gpuPipelineState->dss.stencilPassOpFront)],
|
||||
VK_STENCIL_OPS[static_cast<uint>(gpuPipelineState->dss.stencilZFailOpFront)],
|
||||
VK_CMP_FUNCS[static_cast<uint>(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<uint>(gpuPipelineState->dss.stencilFailOpBack)],
|
||||
VK_STENCIL_OPS[static_cast<uint>(gpuPipelineState->dss.stencilPassOpBack)],
|
||||
VK_STENCIL_OPS[static_cast<uint>(gpuPipelineState->dss.stencilZFailOpBack)],
|
||||
VK_CMP_FUNCS[static_cast<uint>(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<VkPipelineColorBlendAttachmentState> 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<uint>(target.blendSrc)];
|
||||
blendTargets[i].dstColorBlendFactor = VK_BLEND_FACTORS[static_cast<uint>(target.blendDst)];
|
||||
blendTargets[i].colorBlendOp = VK_BLEND_OPS[static_cast<uint>(target.blendEq)];
|
||||
blendTargets[i].srcAlphaBlendFactor = VK_BLEND_FACTORS[static_cast<uint>(target.blendSrcAlpha)];
|
||||
blendTargets[i].dstAlphaBlendFactor = VK_BLEND_FACTORS[static_cast<uint>(target.blendDstAlpha)];
|
||||
blendTargets[i].alphaBlendOp = VK_BLEND_OPS[static_cast<uint>(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<const DrawInfo *>(buffer);
|
||||
size_t drawInfoCount = size / sizeof(DrawInfo);
|
||||
const auto *drawInfo = static_cast<const DrawInfo *>(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<ThsvsAccessType> &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<uint>(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<uint> 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<uint>(gpuTexture->format)].size;
|
||||
device->gpuStagingBufferPool()->alloc(&stagingBuffer, texelSize);
|
||||
|
||||
vector<VkBufferImageCopy> 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<uint>(AccessType::TRANSFER_WRITE)];
|
||||
barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast<uint>(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<uint>(AccessType::TRANSFER_READ)];
|
||||
barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast<uint>(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<uint>(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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user