diff --git a/CMakeLists.txt b/CMakeLists.txt index f1e4683..b587e18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(CMAKE_TOOLCHAIN_FILE ${EXTERNAL_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp) set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp) if(WIN32) - set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/x64-windows/) + set(VCPKG_BASE_FOLDER ${CMAKE_BINARY_DIR}/vcpkg_installed/x64-windows/) elseif(APPLE) set(VCPKG_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/arm64-osx/) endif() diff --git a/CMakeSettings.json b/CMakeSettings.json index 6f611fc..b47945e 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,65 +1,65 @@ { - "configurations": [ - { - "name": "Debug", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "configurationType": "Debug", - "generator": "Ninja", - "intelliSenseMode": "windows-msvc-x64", - "inheritEnvironments": [ "msvc_x64" ], - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildRoot": "${workspaceRoot}/build", - "installRoot": "C:/Program Files/Seele" - }, - { - "name": "Release", - "generator": "Ninja", - "configurationType": "Release", - "buildRoot": "${workspaceRoot}/build", - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64" ], - "intelliSenseMode": "windows-msvc-x64", - "installRoot": "C:/Program Files/Seele" - }, - { - "name": "RelWithDebInfo", - "generator": "Ninja", - "configurationType": "RelWithDebInfo", - "buildRoot": "${workspaceRoot}/build", - "installRoot": "C:/Program Files/Seele", - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64" ], - "intelliSenseMode": "windows-msvc-x64" - }, - { - "name": "AddressSanitizer", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "configurationType": "Debug", - "generator": "Ninja", - "intelliSenseMode": "windows-msvc-x64", - "inheritEnvironments": [ "msvc_x64" ], - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildRoot": "${workspaceRoot}/build", - "installRoot": "C:/Program Files/Seele", - "addressSanitizerEnabled": true - }, - { - "name": "MinSizeRel", - "generator": "Ninja", - "configurationType": "MinSizeRel", - "buildRoot": "${workspaceRoot}/build", - "installRoot": "C:/Program Files/Seele", - "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", - "buildCommandArgs": "", - "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64" ], - "intelliSenseMode": "windows-msvc-x64" - } - ] + "configurations": [ + { + "name": "Debug", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "configurationType": "Debug", + "generator": "Ninja", + "intelliSenseMode": "windows-msvc-x64", + "inheritEnvironments": [ "msvc_x64" ], + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "buildRoot": "${workspaceRoot}/build", + "installRoot": "C:/Program Files/Seele" + }, + { + "name": "Release", + "generator": "Ninja", + "configurationType": "Release", + "buildRoot": "${workspaceRoot}/build", + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64" ], + "intelliSenseMode": "windows-msvc-x64", + "installRoot": "C:/Program Files/Seele" + }, + { + "name": "RelWithDebInfo", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "buildRoot": "${workspaceRoot}/build", + "installRoot": "C:/Program Files/Seele", + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64" ], + "intelliSenseMode": "windows-msvc-x64" + }, + { + "name": "AddressSanitizer", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "configurationType": "Debug", + "generator": "Visual Studio 17 2022 Win64", + "intelliSenseMode": "windows-msvc-x64", + "inheritEnvironments": [ "msvc_x64" ], + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "buildRoot": "${workspaceRoot}/build", + "installRoot": "C:/Program Files/Seele", + "addressSanitizerEnabled": true + }, + { + "name": "MinSizeRel", + "generator": "Ninja", + "configurationType": "MinSizeRel", + "buildRoot": "${workspaceRoot}/build", + "installRoot": "C:/Program Files/Seele", + "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "inheritEnvironments": [ "msvc_x64" ], + "intelliSenseMode": "windows-msvc-x64" + } + ] } \ No newline at end of file diff --git a/res/shaders/Placeholder.json b/res/shaders/Placeholder.json new file mode 100644 index 0000000..08d2e12 --- /dev/null +++ b/res/shaders/Placeholder.json @@ -0,0 +1,15 @@ +{ + "name": "Placeholder", + "params": { + }, + "code": [ + { + "exp": "BRDF", + "profile": "BlinnPhong", + "values": { + "baseColor": "float3(0, 1, 0)", + "normal": "float3(0, 0, 1)" + } + } + ] +} \ No newline at end of file diff --git a/src/AssetViewer/main.cpp b/src/AssetViewer/main.cpp index 090fc24..4cd3ad0 100644 --- a/src/AssetViewer/main.cpp +++ b/src/AssetViewer/main.cpp @@ -36,7 +36,7 @@ int main(int, char**) { Array texCoords1(mesh->mNumVertices); if (mesh->HasTextureCoords(2)) abort(); - for (int32 i = 0; i < mesh->mNumVertices; ++i) { + for (uint32 i = 0; i < mesh->mNumVertices; ++i) { positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z); if (mesh->mTextureCoords[0] != nullptr) @@ -65,7 +65,7 @@ int main(int, char**) { return 0.5 * glm::length(glm::cross(p2 - p1, p3 - p1)); }; Array tris(mesh->mNumFaces); - for (int32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) { + for (uint32 faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) { tris[faceIndex].p[0] = mesh->mFaces[faceIndex].mIndices[0]; tris[faceIndex].p[1] = mesh->mFaces[faceIndex].mIndices[1]; tris[faceIndex].p[2] = mesh->mFaces[faceIndex].mIndices[2]; diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index a39e896..5063a4b 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -516,7 +516,7 @@ Vector4 MeshLoader::encodeQTangent(Matrix3 m) { void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array& materials, Array& globalMeshes, Component::Collider& collider) { List> work; - for (int32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) { + for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) { aiMesh* mesh = scene->mMeshes[meshIndex]; if (!(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE)) continue; diff --git a/src/Editor/Window/InspectorView.cpp b/src/Editor/Window/InspectorView.cpp index 37dcb25..16ea243 100644 --- a/src/Editor/Window/InspectorView.cpp +++ b/src/Editor/Window/InspectorView.cpp @@ -36,7 +36,7 @@ void InspectorView::prepareRender() {} void InspectorView::render() { renderGraph.render(Component::Camera()); } -void InspectorView::applyArea(URect area) {} +void InspectorView::applyArea(URect ) {} void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) {} diff --git a/src/Editor/Window/PlayView.cpp b/src/Editor/Window/PlayView.cpp index 75506f2..c0627e9 100644 --- a/src/Editor/Window/PlayView.cpp +++ b/src/Editor/Window/PlayView.cpp @@ -49,6 +49,7 @@ void PlayView::keyCallback(KeyCode code, InputAction action, KeyModifier modifie if (code == KeyCode::KEY_R && action == InputAction::RELEASE) { getGlobals().useRayTracing = !getGlobals().useRayTracing; } - //if (code == KeyCode::KEY_B && action == InputAction::RELEASE && modifier & KeyModifier::MOD_CONTROL) { - //} + if (code == KeyCode::KEY_H && action == InputAction::RELEASE) { + MemoryManager::printAllocations(); + } } diff --git a/src/Engine/Asset/FontAsset.cpp b/src/Engine/Asset/FontAsset.cpp index 4d6709c..8498c9e 100644 --- a/src/Engine/Asset/FontAsset.cpp +++ b/src/Engine/Asset/FontAsset.cpp @@ -28,16 +28,16 @@ void FontAsset::load(ArchiveBuffer& buffer) { } void FontAsset::loadFace() { - FT_Error error = FT_New_Memory_Face(ft, (unsigned char*)ttfFile.data(), ttfFile.size(), 0, &ft_face); + FT_Error error = FT_New_Memory_Face(ft, (unsigned char*)ttfFile.data(), (uint32)ttfFile.size(), 0, &ft_face); assert(!error); - blob = hb_blob_create(ttfFile.data(), ttfFile.size(), HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr); + blob = hb_blob_create(ttfFile.data(), (uint32)ttfFile.size(), HB_MEMORY_MODE_DUPLICATE, nullptr, nullptr); hb_face = hb_face_create(blob, 0); hb_font = hb_font_create(hb_face); } UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array& render) { loadGlyphs(fontSize); hb_buffer_t* buf = hb_buffer_create(); - hb_buffer_add_utf8(buf, view.data(), view.size(), 0, -1); + hb_buffer_add_utf8(buf, view.data(), (uint32)view.size(), 0, -1); hb_buffer_set_language(buf, hb_language_from_string("en", -1)); hb_buffer_set_script(buf, HB_SCRIPT_LATIN); hb_buffer_set_direction(buf, HB_DIRECTION_LTR); @@ -52,10 +52,10 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Arraynum_glyphs; ++i) { + for (int i = 0; i < ft_face->num_glyphs; ++i) { assert(FT_Load_Glyph(ft_face, i, FT_LOAD_RENDER) == 0); FontAsset::Glyph& glyph = fontSizes[fontSize].glyphs[i]; glyph.size = IVector2(ft_face->glyph->bitmap.width, ft_face->glyph->bitmap.rows); diff --git a/src/Engine/Asset/LevelAsset.cpp b/src/Engine/Asset/LevelAsset.cpp index 27ce4c8..c0d5a5e 100644 --- a/src/Engine/Asset/LevelAsset.cpp +++ b/src/Engine/Asset/LevelAsset.cpp @@ -9,6 +9,6 @@ LevelAsset::LevelAsset(std::string_view folderPath, std::string_view name) : Ass LevelAsset::~LevelAsset() {} -void LevelAsset::save(ArchiveBuffer& buffer) const { } +void LevelAsset::save(ArchiveBuffer&) const { } -void LevelAsset::load(ArchiveBuffer& buffer) { } +void LevelAsset::load(ArchiveBuffer&) { } diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 14482dd..c62a4cc 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -1,6 +1,7 @@ #pragma once -#include "EngineTypes.h" #include "Concepts.h" +#include "EngineTypes.h" +#include "MemoryResource.h" #include #include #include @@ -12,7 +13,7 @@ #endif namespace Seele { -template > struct Array { +template struct Array { public: template class IteratorBase { public: @@ -67,7 +68,7 @@ template > s }; using value_type = T; - using allocator_type = Allocator; + using allocator_type = std::pmr::polymorphic_allocator; using size_type = std::size_t; using difference_type = std::ptrdiff_t; using pointer = T*; @@ -82,12 +83,8 @@ template > s using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - constexpr Array() noexcept(noexcept(Allocator())) : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(Allocator()) { - _data = allocateArray(DEFAULT_ALLOC_SIZE); - assert(_data != nullptr); - } - - constexpr explicit Array(const allocator_type& alloc) noexcept : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) { + constexpr Array(const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) noexcept + : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) { _data = allocateArray(DEFAULT_ALLOC_SIZE); assert(_data != nullptr); } @@ -138,7 +135,8 @@ template > s assert(_data != nullptr); std::uninitialized_copy(other.begin(), other.end(), begin()); } - constexpr Array(const Array& other, const Allocator& alloc) : arraySize(other.arraySize), allocated(other.allocated), allocator(alloc) { + constexpr Array(const Array& other, const allocator_type& alloc) + : arraySize(other.arraySize), allocated(other.allocated), allocator(alloc) { _data = allocateArray(other.allocated); assert(_data != nullptr); std::uninitialized_copy(other.begin(), other.end(), begin()); @@ -150,7 +148,7 @@ template > s other.allocated = 0; other.arraySize = 0; } - constexpr Array(Array&& other, const Allocator& alloc) noexcept + constexpr Array(Array&& other, const allocator_type& alloc) noexcept : arraySize(std::move(other.arraySize)), allocated(std::move(other.allocated)), allocator(alloc) { _data = allocateArray(other.allocated); std::uninitialized_move(other.begin(), other.end(), begin()); @@ -179,8 +177,8 @@ template > s } return *this; } - Array& operator=(Array&& other) noexcept(std::allocator_traits::propagate_on_container_move_assignment::value || - std::allocator_traits::is_always_equal::value) { + Array& operator=(Array&& other) noexcept(std::allocator_traits::propagate_on_container_move_assignment::value || + std::allocator_traits::is_always_equal::value) { if (this != &other) { if (_data != nullptr) { clear(); @@ -294,7 +292,7 @@ template > s requires std::predicate constexpr void remove_if(Pred&& pred, bool keepOrder = true) { Iterator it; - while((it = find(pred)) != end()) { + while ((it = find(pred)) != end()) { erase(it, keepOrder); } } @@ -389,7 +387,11 @@ template > s assert(result != nullptr); return result; } - void deallocateArray(T* ptr, size_type size) { if(ptr == nullptr) return; allocator.deallocate(ptr, size); } + void deallocateArray(T* ptr, size_type size) { + if (ptr == nullptr) + return; + allocator.deallocate(ptr, size); + } template T& addInternal(Type&& t) noexcept { if (arraySize == allocated) { size_type newSize = arraySize + 1; @@ -449,7 +451,7 @@ template > s allocator_type allocator; }; -template constexpr bool operator==(const Array& lhs, const Array& rhs) { +template constexpr bool operator==(const Array& lhs, const Array& rhs) { if (lhs.size() != rhs.size()) { return false; } @@ -461,7 +463,7 @@ template constexpr bool operator==(const Array constexpr auto operator<=>(const Array& lhs, const Array& rhs) { +template constexpr auto operator<=>(const Array& lhs, const Array& rhs) { return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } diff --git a/src/Engine/Containers/CMakeLists.txt b/src/Engine/Containers/CMakeLists.txt index 75715e1..a0bb38e 100644 --- a/src/Engine/Containers/CMakeLists.txt +++ b/src/Engine/Containers/CMakeLists.txt @@ -3,6 +3,8 @@ target_sources(Engine Array.h List.h Map.h + MemoryResource.h + MemoryResource.cpp Pair.h Set.h Tree.h) @@ -13,6 +15,7 @@ target_sources(Engine Array.h List.h Map.h + MemoryResource.h Pair.h Set.h Tree.h) \ No newline at end of file diff --git a/src/Engine/Containers/Map.h b/src/Engine/Containers/Map.h index 6a17412..566ed4b 100644 --- a/src/Engine/Containers/Map.h +++ b/src/Engine/Containers/Map.h @@ -5,12 +5,11 @@ #include "Tree.h" #include - namespace Seele { template struct _KeyFun { const KeyType& operator()(const PairType& pair) const { return pair.key; } }; -template , typename Allocator = std::pmr::polymorphic_allocator>> +template , typename Allocator = std::pmr::polymorphic_allocator>> struct Map : public Tree, _KeyFun>, Compare, Allocator> { using Super = Tree, _KeyFun>, Compare, Allocator>; using key_type = Super::key_type; @@ -35,8 +34,8 @@ struct Map : public Tree, _KeyFun>, Compare, Allocat : Super(comp, alloc) {} constexpr explicit Map(const Allocator& alloc) noexcept(noexcept(Compare())) : Super(alloc) {} constexpr Map(std::initializer_list> init) : Super(init) {} - constexpr mapped_type& operator[](const key_type& key) { - auto [it, inserted] = Super::insert(Pair(key, V())); + constexpr mapped_type& operator[](const key_type& key) { + auto [it, _] = Super::insert(Pair(key)); return it->value; } constexpr const mapped_type& operator[](const key_type& key) const { return Super::find(key)->value; } diff --git a/src/Engine/Containers/MemoryResource.cpp b/src/Engine/Containers/MemoryResource.cpp new file mode 100644 index 0000000..51d31f4 --- /dev/null +++ b/src/Engine/Containers/MemoryResource.cpp @@ -0,0 +1,34 @@ +#include "MemoryResource.h" +#include "Map.h" +#include + +using namespace Seele; + +std::mutex allocationMutex; +std::map allocationCounters; +std::mutex resourcesMutex; +std::map debugResources; + +std::atomic_uint64_t& MemoryManager::getAllocationCounter(const std::string& name) { + std::unique_lock l(allocationMutex); + return allocationCounters[name]; +} + +void MemoryManager::printAllocations() { + std::unique_lock l(allocationMutex); + for (const auto& [name, counter] : allocationCounters) { + if (name.empty()) + { + std::cout << name << ": " << counter << std::endl; + } + else + { + std::cout << name << ": " << counter << std::endl; + } + } +} + +debug_resource* debug_resource::get(const std::string& name) { + std::unique_lock l(resourcesMutex); + return &debugResources[name]; +} \ No newline at end of file diff --git a/src/Engine/Containers/MemoryResource.h b/src/Engine/Containers/MemoryResource.h new file mode 100644 index 0000000..0a58f57 --- /dev/null +++ b/src/Engine/Containers/MemoryResource.h @@ -0,0 +1,39 @@ +#pragma once +#include + +namespace Seele { +class MemoryManager { + public: + static std::atomic_uint64_t& getAllocationCounter(const std::string& name); + static void printAllocations(); + + private: +}; + +class debug_resource : public std::pmr::memory_resource { + public: + static debug_resource* get(const std::string& name); + debug_resource() : name(""), upstream(std::pmr::get_default_resource()), counter(MemoryManager::getAllocationCounter(name)) {} + debug_resource(std::string name, std::pmr::memory_resource* up = std::pmr::get_default_resource()) + : name(name), upstream(up), counter(MemoryManager::getAllocationCounter(name)) {} + debug_resource(const debug_resource& other) = delete; + debug_resource& operator=(const debug_resource& other) = delete; + + void* do_allocate(size_t bytes, size_t alignment) override { + counter += bytes; + return upstream->allocate(bytes, alignment); + } + + void do_deallocate(void* ptr, size_t bytes, size_t alignment) override { + upstream->deallocate(ptr, bytes, alignment); + counter -= bytes; + } + + bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; } + + private: + std::string name; + std::pmr::memory_resource* upstream; + std::atomic_uint64_t& counter; +}; +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/Containers/Pair.h b/src/Engine/Containers/Pair.h index 45cb210..ac9121d 100644 --- a/src/Engine/Containers/Pair.h +++ b/src/Engine/Containers/Pair.h @@ -3,14 +3,6 @@ namespace Seele { template struct Pair { public: - constexpr Pair() : key(K()), value(V()) {} - constexpr Pair(const K& key, const V& value) : key(key), value(value) {} - template constexpr Pair(U1&& x, U2&& y) : key(std::forward(x)), value(std::forward(y)) {} - Pair(const Pair& other) = default; - Pair(Pair&& other) = default; - ~Pair() {} - Pair& operator=(const Pair& other) = default; - Pair& operator=(Pair&& other) = default; constexpr friend bool operator<(const Pair& left, const Pair& right) { return left.key < right.key || (!(right.key < left.key) && left.value < right.value); } diff --git a/src/Engine/Containers/Tree.h b/src/Engine/Containers/Tree.h index 5daf90a..bc099bb 100644 --- a/src/Engine/Containers/Tree.h +++ b/src/Engine/Containers/Tree.h @@ -1,15 +1,21 @@ #pragma once -#include "Pair.h" #include "Array.h" +#include "Pair.h" +#include #include - +#include namespace Seele { template struct Tree { protected: struct Node { - Node(Node* left, Node* right, const NodeData& nodeData) : leftChild(left), rightChild(right), data(nodeData) {} - Node(Node* left, Node* right, NodeData&& nodeData) : leftChild(left), rightChild(right), data(std::move(nodeData)) {} + Node(const NodeData& data) + : data(data) + {} + Node(NodeData&& data) + : data(std::move(data)) {} + + Node* parent = nullptr; Node* leftChild; Node* rightChild; NodeData data; @@ -17,79 +23,6 @@ template ::template rebind_alloc; public: - template class IteratorBase { - public: - using iterator_category = std::bidirectional_iterator_tag; - using value_type = IterType; - using difference_type = std::ptrdiff_t; - using reference = IterType&; - using pointer = IterType*; - - constexpr IteratorBase(Node* x = nullptr, Array&& beginIt = Array()) : node(x), traversal(std::move(beginIt)) {} - constexpr IteratorBase(const IteratorBase& i) : node(i.node), traversal(i.traversal) {} - constexpr IteratorBase(IteratorBase&& i) noexcept : node(std::move(i.node)), traversal(std::move(i.traversal)) {} - constexpr IteratorBase& operator=(const IteratorBase& other) { - if (this != &other) { - node = other.node; - traversal = other.traversal; - } - return *this; - } - constexpr IteratorBase& operator=(IteratorBase&& other) noexcept { - if (this != &other) { - node = std::move(other.node); - traversal = std::move(other.traversal); - } - return *this; - } - constexpr reference operator*() const { return node->data; } - constexpr pointer operator->() const { return &(node->data); } - constexpr bool operator!=(const IteratorBase& other) { return node != other.node; } - constexpr bool operator==(const IteratorBase& other) { return node == other.node; } - constexpr std::strong_ordering operator<=>(const IteratorBase& other) { return node <=> other.node; } - constexpr IteratorBase& operator++() { - node = node->rightChild; - while (node != nullptr && node->leftChild != nullptr) { - traversal.add(node); - node = node->leftChild; - } - if (node == nullptr && traversal.size() > 0) { - node = traversal.back(); - traversal.pop(); - } - return *this; - } - constexpr IteratorBase& operator--() { - node = node->leftChild; - while (node != nullptr && node->rightChild != nullptr) { - traversal.add(node); - node = node->rightchild; - } - if (node == nullptr && traversal.size() > 0) { - node = traversal.back(); - traversal.pop(); - } - return *this; - } - constexpr IteratorBase operator--(int) { - IteratorBase tmp(*this); - --*this; - return tmp; - } - constexpr IteratorBase operator++(int) { - IteratorBase tmp(*this); - ++*this; - return tmp; - } - Node* getNode() { return node; } - - private: - Node* node; - Array traversal; - }; - using Iterator = IteratorBase; - using ConstIterator = IteratorBase; - using key_type = KeyType; using value_type = NodeData; using allocator_type = Allocator; @@ -100,6 +33,95 @@ template ::pointer; using const_pointer = std::allocator_traits::const_pointer; + class ConstIterator { + public: + using iterator_category = std::bidirectional_iterator_tag; + using value_type = value_type; + using difference_type = difference_type; + using pointer = const_pointer; + using reference = const value_type&; + + constexpr ConstIterator(Node* x = nullptr) : node(x) {} + constexpr ConstIterator(const ConstIterator& i) = default; + constexpr ConstIterator(ConstIterator&& i) noexcept = default; + constexpr ConstIterator& operator=(const ConstIterator& other) = default; + constexpr ConstIterator& operator=(ConstIterator&& other) noexcept = default; + constexpr reference operator*() const noexcept { return node->data; } + constexpr pointer operator->() const noexcept { return std::pointer_traits::pointer_to(**this); } + constexpr bool operator==(const ConstIterator& other) { return node == other.node; } + constexpr bool operator!=(const ConstIterator& other) { return node != other.node; } + constexpr std::strong_ordering operator<=>(const ConstIterator& other) { return node <=> other.node; } + constexpr ConstIterator& operator++() noexcept { + node = node->rightChild; + while (node != nullptr && node->leftChild != nullptr) { + node = node->leftChild; + } + if (node == nullptr && node->parent != nullptr) { + node = node->parent; + } + return *this; + } + constexpr ConstIterator& operator--() { + node = node->leftChild; + while (node != nullptr && node->rightChild != nullptr) { + node = node->rightchild; + } + if (node == nullptr && node->parent != nullptr) { + node = node->parent; + } + return *this; + } + constexpr ConstIterator operator--(int) { + ConstIterator tmp(*this); + --*this; + return tmp; + } + constexpr ConstIterator operator++(int) { + ConstIterator tmp(*this); + ++*this; + return tmp; + } + + Node* getNode() { return node; } + + protected: + Node* node; + }; + + class Iterator : public ConstIterator { + public: + using value_type = value_type; + using difference_type = difference_type; + using pointer = pointer; + using reference = value_type&; + + constexpr Iterator(Node* x = nullptr) : ConstIterator(x) {} + constexpr Iterator(const Iterator& i) = default; + constexpr Iterator(Iterator&& i) noexcept = default; + constexpr Iterator& operator=(const Iterator& other) = default; + constexpr Iterator& operator=(Iterator&& other) noexcept = default; + constexpr reference operator*() const noexcept { return const_cast(ConstIterator::operator*()); } + constexpr pointer operator->() const noexcept { return std::pointer_traits::pointer_to(**this); } + constexpr Iterator& operator++() noexcept { + ConstIterator::operator++(); + return *this; + } + constexpr Iterator& operator--() noexcept { + ConstIterator::operator--(); + return *this; + } + constexpr Iterator& operator++(int) noexcept { + Iterator tmp = *this; + ConstIterator::operator++(); + return tmp; + } + constexpr Iterator& operator--(int) noexcept { + Iterator tmp = *this; + ConstIterator::operator--(); + return tmp; + } + }; + using iterator = Iterator; using const_iterator = ConstIterator; using reverse_iterator = std::reverse_iterator; @@ -212,12 +234,12 @@ template insert(const NodeData& data) { - auto [r, inserted] = _insert(root, data); + const auto& [r, inserted] = _insert(root, data); root = r; return Pair(iterator(root), inserted); } constexpr Pair insert(NodeData&& data) { - auto [r, inserted] = _insert(root, std::move(data)); + const auto& [r, inserted] = _insert(root, std::move(data)); root = r; return Pair(iterator(root), inserted); } @@ -242,25 +264,20 @@ template beginTraversal; while (begin != nullptr) { - beginTraversal.add(begin); begin = begin->leftChild; } - if (!beginTraversal.empty()) { - begin = beginTraversal.back(); - beginTraversal.pop(); + if (begin->parent != nullptr) { + begin = begin->parent; } - return Iterator(begin, std::move(beginTraversal)); + return Iterator(begin); } constexpr Iterator calcEndIterator() const { - Node* endIndex = root; - Array endTraversal; - while (endIndex != nullptr) { - endTraversal.add(endIndex); - endIndex = endIndex->rightChild; + Node* endNode = root; + while (endNode != nullptr) { + endNode = endNode->rightChild; } - return Iterator(endIndex, std::move(endTraversal)); + return Iterator(endNode); } NodeAlloc alloc; Node* root; @@ -273,20 +290,24 @@ template rightChild; x->rightChild = y->leftChild; + x->rightChild->parent = x; y->leftChild = x; + y->leftChild->parent = y; return y; } Node* rotateRight(Node* x) { Node* y = x->leftChild; x->leftChild = y->rightChild; + x->leftChild->parent = x; y->rightChild = x; + y->rightChild->parent = y; return y; } template Pair _insert(Node* r, NodeDataType&& data) { markIteratorsDirty(); if (r == nullptr) { root = alloc.allocate(1); - std::allocator_traits::construct(alloc, root, nullptr, nullptr, std::forward(data)); + std::allocator_traits::construct(alloc, root, std::forward(data)); _size++; return Pair(root, true); } @@ -296,15 +317,19 @@ template (r, false); Node* newNode = alloc.allocate(1); - std::allocator_traits::construct(alloc, newNode, nullptr, nullptr, std::forward(data)); + std::allocator_traits::construct(alloc, newNode, std::forward(data)); if (comp(keyFun(newNode->data), keyFun(r->data))) { newNode->rightChild = r; + newNode->rightChild->parent = newNode; newNode->leftChild = r->leftChild; + newNode->leftChild->parent = newNode; r->leftChild = nullptr; } else { newNode->leftChild = r; + newNode->leftChild->parent = newNode; newNode->rightChild = r->rightChild; + newNode->rightChild->parent = newNode; r->rightChild = nullptr; } _size++; @@ -329,6 +354,7 @@ template leftChild, key); r->rightChild = temp->rightChild; + r->rightChild->parent = r; } std::allocator_traits::destroy(alloc, temp); alloc.deallocate(temp, 1); @@ -346,13 +372,16 @@ template leftChild->data))) { r->leftChild->leftChild = _splay(r->leftChild->leftChild, key); + r->leftChild->leftChild->parent = r->leftChild; r = rotateRight(r); } else if (comp(keyFun(r->leftChild->data), key)) { r->leftChild->rightChild = _splay(r->leftChild->rightChild, key); + r->leftChild->rightChild->parent = r->leftChild; if (r->leftChild->rightChild != nullptr) { r->leftChild = rotateLeft(r->leftChild); + r->leftChild->parent = r; } } return (r->leftChild == nullptr) ? r : rotateRight(r); @@ -362,12 +391,15 @@ template rightChild->data))) { r->rightChild->leftChild = _splay(r->rightChild->leftChild, key); + r->rightChild->leftChild->parent = r->rightChild; if (r->rightChild->leftChild != nullptr) { r->rightChild = rotateRight(r->rightChild); + r->rightChild->parent = r; } } else if (comp(keyFun(r->rightChild->data), key)) { r->rightChild->rightChild = _splay(r->rightChild->rightChild, key); + r->rightChild->rightChild->parent = r->rightChild; r = rotateLeft(r); } diff --git a/src/Engine/Graphics/CBT/CBT.cpp b/src/Engine/Graphics/CBT/CBT.cpp index 46c7484..33baffc 100644 --- a/src/Engine/Graphics/CBT/CBT.cpp +++ b/src/Engine/Graphics/CBT/CBT.cpp @@ -120,7 +120,7 @@ uint32_t find_msb_64(uint64_t x) { CPUMesh Seele::generateCPUMesh(uint32 cbtNumElements) { CPUMesh result; - result.totalNumElements = edges.size() + cbtNumElements; + result.totalNumElements = (uint32)edges.size() + cbtNumElements; result.heapIDArray.resize(result.totalNumElements); result.neighborsArray.resize(result.totalNumElements); @@ -193,7 +193,6 @@ Matrix3 decodeSubdivisionMatrix(uint64 heapID) { void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) { cacheDepth = depth; uint32 matrixCount = 2ULL << cacheDepth; - Matrix3 m; std::vector table(matrixCount); table[0] = Matrix3({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}); for (uint64 heapID = 1ULL; heapID < (2ULL << cacheDepth); ++heapID) { @@ -799,7 +798,7 @@ void MeshUpdater::update(CBTMesh& mesh, Gfx::PDescriptorSet viewParamsSet, Gfx:: } void MeshUpdater::validation(CBTMesh& mesh, Gfx::PUniformBuffer geometryCB) { - uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE; + //uint32 numGroups = (mesh.totalNumElements + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE; /*Gfx::PDescriptorSet set = layout->allocateDescriptorSet(); set->updateBuffer(GEOMETRY_CB, 0, geometryCB); diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index c619c3d..2290016 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -1,4 +1,4 @@ -add_subdirectory(CBT/) +#add_subdirectory(CBT/) target_sources(Engine PRIVATE diff --git a/src/Engine/Graphics/Meshlet.cpp b/src/Engine/Graphics/Meshlet.cpp index 88fb9d1..f3e2cee 100644 --- a/src/Engine/Graphics/Meshlet.cpp +++ b/src/Engine/Graphics/Meshlet.cpp @@ -25,7 +25,7 @@ void buildAdjacency(const uint32 numVerts, const Array& indices, Adjacen triangleOffset += info.trianglesPerVertex[j]; } - uint32 numTriangles = indices.size() / 3; + uint32 numTriangles = (uint32)indices.size() / 3; info.triangleData.resize(triangleOffset); Array offsets = info.indexBufferOffset; for (uint32 k = 0; k < numTriangles; ++k) { diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index bf215e2..39d9458 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -200,8 +200,7 @@ void BasePass::render() { .attachmentCount = 1, }, }; - Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); - command->bindPipeline(pipeline); + command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo))); } else { Gfx::LegacyPipelineCreateInfo pipelineInfo = { .vertexShader = collection->vertexShader, @@ -221,8 +220,7 @@ void BasePass::render() { .attachmentCount = 1, }, }; - Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo)); - command->bindPipeline(pipeline); + command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo))); } command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(), opaqueCulling}); @@ -231,7 +229,7 @@ void BasePass::render() { Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets); if (graphics->supportMeshShading()) { - command->drawMesh(drawCall.instanceMeshData.size(), 1, 1); + command->drawMesh((uint32)drawCall.instanceMeshData.size(), 1, 1); } else { command->bindIndexBuffer(vertexData->getIndexBuffer()); for (const auto& meshData : drawCall.instanceMeshData) { @@ -252,7 +250,7 @@ void BasePass::render() { { Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender"); skyboxCommand->setViewport(viewport); - skyboxCommand->bindPipeline(pipeline); + skyboxCommand->bindPipeline(skyboxPipeline); skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet}); skyboxCommand->draw(36, 1, 0, 0); graphics->executeCommands(std::move(skyboxCommand)); @@ -623,6 +621,6 @@ void BasePass::createRenderPass() { .attachmentCount = 1, }, }; - pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo)); + skyboxPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo)); } } diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index 81507cc..7a2305f 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -2,7 +2,6 @@ #include "MinimalEngine.h" #include "RenderPass.h" #include "WaterRenderer.h" -#include "TerrainRenderer.h" namespace Seele { DECLARE_REF(CameraActor) @@ -56,7 +55,7 @@ class BasePass : public RenderPass { Gfx::PShaderBuffer cullingBuffer; //OWaterRenderer waterRenderer; - OTerrainRenderer terrainRenderer; + //OTerrainRenderer terrainRenderer; // Debug rendering Gfx::OVertexInput debugVertexInput; @@ -74,7 +73,7 @@ class BasePass : public RenderPass { Gfx::OVertexShader vertexShader; Gfx::OFragmentShader fragmentShader; Gfx::OPipelineLayout pipelineLayout; - Gfx::PGraphicsPipeline pipeline; + Gfx::PGraphicsPipeline skyboxPipeline; Gfx::OSampler skyboxSampler; struct SkyboxData { Matrix4 transformMatrix; diff --git a/src/Engine/Graphics/RenderPass/CMakeLists.txt b/src/Engine/Graphics/RenderPass/CMakeLists.txt index 7102259..a5fd61a 100644 --- a/src/Engine/Graphics/RenderPass/CMakeLists.txt +++ b/src/Engine/Graphics/RenderPass/CMakeLists.txt @@ -15,8 +15,8 @@ target_sources(Engine RenderGraphResources.cpp RenderPass.h RenderPass.cpp - TerrainRenderer.h - TerrainRenderer.cpp + #TerrainRenderer.h + #TerrainRenderer.cpp ToneMappingPass.h ToneMappingPass.cpp UIPass.h @@ -38,6 +38,6 @@ target_sources(Engine RenderGraph.h RenderGraphResources.h RenderPass.h - TerrainRenderer.h + #TerrainRenderer.h UIPass.h VisibilityPass.h) \ No newline at end of file diff --git a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp index 8b0b44a..91cb737 100644 --- a/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp +++ b/src/Engine/Graphics/RenderPass/CachedDepthPass.cpp @@ -111,7 +111,7 @@ void CachedDepthPass::render() { command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offsets); if (graphics->supportMeshShading()) { - command->drawMesh(vertexData->getNumInstances(), 1, 1); + command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1); } else { const auto& materials = vertexData->getMaterialData(); for (const auto& materialData : materials) { diff --git a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp index 0e6190d..3d72469 100644 --- a/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthCullingPass.cpp @@ -185,7 +185,7 @@ void DepthCullingPass::render() { command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), &offsets); if (graphics->supportMeshShading()) { - command->drawMesh(vertexData->getNumInstances(), 1, 1); + command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1); } else { const auto& materials = vertexData->getMaterialData(); for (const auto& materialData : materials) { diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 099031d..1c999e4 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -278,7 +278,7 @@ void LightCullingPass::setupFrustums() { frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet(); + dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet(); dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups); dispatchParamsSet->updateConstants("numThreads", 0, &numThreads); dispatchParamsSet->updateBuffer(FRUSTUMBUFFER_NAME, 0, frustumBuffer); @@ -292,8 +292,5 @@ void LightCullingPass::setupFrustums() { commands.add(std::move(command)); graphics->executeCommands(std::move(commands)); frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - Frustum* frustums = (Frustum*)frustumBuffer->map(); - graphics->waitDeviceIdle(); - + Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); } diff --git a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp index 045a2b4..fdb89ea 100644 --- a/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp +++ b/src/Engine/Graphics/RenderPass/TerrainRenderer.cpp @@ -25,7 +25,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe plainMesh.gpuCBT.bufferCount = 2; for (uint32 i = 0; i < 2; ++i) { uint32 bufferSize = cbt.bufferSize(i); - uint32 elementSize = cbt.elementSize(i); + //uint32 elementSize = cbt.elementSize(i); plainMesh.gpuCBT.bufferArray[i] = graphics->createShaderBuffer(ShaderBufferCreateInfo{ .sourceData = { @@ -189,7 +189,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe baseMesh.vertexBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); - uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector); + //uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector); Array indices; for (uint32 i = 0; i < cpuMesh.totalNumElements * 3; ++i) indices.add(i); diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index d019e03..0a27bbb 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -62,9 +62,9 @@ void UIPass::beginFrame(const Component::Camera& cam) { float x = render.position.x; float y = render.position.y; //todo: convert using actual tree depth - uint32 textureIndex = -1ul; + uint32 textureIndex = std::numeric_limits::max(); if (render.backgroundTexture != nullptr) { - textureIndex = usedTextures.size(); + textureIndex = (uint32)usedTextures.size(); usedTextures.add(render.backgroundTexture); } elements.add(RenderElementStyle{ @@ -112,7 +112,7 @@ void UIPass::render() { command->setViewport(viewport); command->bindPipeline(uiPipeline); command->bindDescriptor({viewParamsSet, uiDescriptorSet}); - command->draw(4, elements.size(), 0, 0); + command->draw(4, (uint32)elements.size(), 0, 0); commands.add(std::move(command)); graphics->executeCommands(std::move(commands)); graphics->endRenderPass(); diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h index 55a94ac..2162202 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.h +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -42,7 +42,7 @@ class UIPass : public RenderPass { Vector color; float opacity = 1; float z = 0; - uint32 textureIndex = -1ul; + uint32 textureIndex = std::numeric_limits::max(); uint32 pad0; uint32 pad1; }; diff --git a/src/Engine/Graphics/StaticMeshVertexData.cpp b/src/Engine/Graphics/StaticMeshVertexData.cpp index 3457866..6fc802a 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.cpp +++ b/src/Engine/Graphics/StaticMeshVertexData.cpp @@ -245,7 +245,7 @@ void StaticMeshVertexData::updateBuffers() { descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents); descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents); descriptorSet->updateBuffer(COLORS_NAME, 0, colors); - for (size_t i = 0; i < MAX_TEXCOORDS; ++i) { + for (uint32 i = 0; i < MAX_TEXCOORDS; ++i) { descriptorSet->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]); } descriptorSet->writeChanges(); diff --git a/src/Engine/Graphics/StaticMeshVertexData.h b/src/Engine/Graphics/StaticMeshVertexData.h index ed59ac2..f6e811e 100644 --- a/src/Engine/Graphics/StaticMeshVertexData.h +++ b/src/Engine/Graphics/StaticMeshVertexData.h @@ -5,7 +5,6 @@ #include "VertexData.h" #include "entt/entt.hpp" - namespace Seele { class StaticMeshVertexData : public VertexData { public: @@ -39,7 +38,6 @@ class StaticMeshVertexData : public VertexData { virtual void resizeBuffers() override; virtual void updateBuffers() override; - Gfx::OShaderBuffer positions; constexpr static const char* POSITIONS_NAME = "positions"; Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS]; @@ -52,7 +50,7 @@ class StaticMeshVertexData : public VertexData { constexpr static const char* BITANGENTS_NAME = "biTangents"; Gfx::OShaderBuffer colors; constexpr static const char* COLORS_NAME = "colors"; - Array posData; + Array posData{debug_resource::get("VertexPositions")}; Array texData[MAX_TEXCOORDS]; Array norData; Array tanData; diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index fa4e401..d30f3a1 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -90,7 +90,7 @@ void VertexData::createDescriptors() { Array cullingOffsets; for (auto& mat : materialData) { for (auto& instance : mat.instances) { - instance.offsets.instanceOffset = instanceData.size(); + instance.offsets.instanceOffset = (uint32)instanceData.size(); MaterialOffsets offsets = instance.materialInstance->getMaterialOffsets(); instance.offsets.textureOffset = offsets.textureOffset; instance.offsets.samplerOffset = offsets.samplerOffset; @@ -104,7 +104,7 @@ void VertexData::createDescriptors() { } } for (uint32 i = 0; i < transparentData.size(); ++i) { - transparentData[i].offsets.instanceOffset = instanceData.size(); + transparentData[i].offsets.instanceOffset = (uint32)instanceData.size(); cullingOffsets.add(transparentData[i].cullingOffset); instanceData.add(transparentData[i].instanceData); instanceMeshData.add(transparentData[i].meshData); @@ -139,17 +139,17 @@ void VertexData::createDescriptors() { void VertexData::loadMesh(MeshId id, Array loadedIndices, Array loadedMeshlets) { std::unique_lock l(vertexDataLock); for (auto&& chunk : loadedMeshlets | std::views::chunk(2048)) { - uint32 meshletOffset = meshlets.size(); + uint32 meshletOffset = (uint32)meshlets.size(); AABB meshAABB; uint32 numMeshlets = 0; for (auto&& m : chunk) { numMeshlets++; //... meshAABB = meshAABB.combine(m.boundingBox); - uint32 vertexOffset = vertexIndices.size(); + uint32 vertexOffset = (uint32)vertexIndices.size(); vertexIndices.resize(vertexOffset + m.numVertices); std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32)); - uint32 primitiveOffset = primitiveIndices.size(); + uint32 primitiveOffset = (uint32)primitiveIndices.size(); primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3)); std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8)); meshlets.add(MeshletDescription{ @@ -349,7 +349,7 @@ void VertexData::destroy() { } uint32 VertexData::addCullingMapping(MeshId id) { - uint32 result = meshletCount; + uint32 result = (uint32)meshletCount; for (const auto& md : getMeshData(id)) { meshletCount += md.numMeshlets; } diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 139fa50..843a3f4 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -8,7 +8,7 @@ #include "Meshlet.h" #include -constexpr uint64 MAX_TEXCOORDS = 8; +constexpr uint32 MAX_TEXCOORDS = 8; namespace Seele { DECLARE_REF(MaterialInstance) @@ -77,10 +77,8 @@ class VertexData { const Array& getTransparentData() const { return transparentData; } const Array& getRayTracingData() const { return rayTracingScene; } const Array& getMeshData(MeshId id) const { return meshData[id]; } - void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { - dataToBuild.add(blas); - } - uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; } + void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { dataToBuild.add(blas); } + uint32 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; } uint64 getNumInstances() const { return instanceData.size(); } static List getList(); static VertexData* findByTypeName(std::string name); @@ -110,6 +108,7 @@ class VertexData { uint32 indicesOffset = 0; }; std::mutex materialDataLock; + debug_resource vertexDataResource = {"VertexData"}; Array materialData; Array transparentData; diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 0e2c060..40d209e 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -51,11 +51,11 @@ void DescriptorLayout::create() { constantsSize += gfxBinding.uniformLength; constantsStages |= gfxBinding.shaderStages; } else { - mappings[gfxBinding.name] = { + mappings[gfxBinding.name] = DescriptorMapping{ .binding = (uint32)bindings.size(), .type = cast(gfxBinding.descriptorType), }; - bindings.add({ + bindings.add(VkDescriptorSetLayoutBinding{ .binding = (uint32)bindings.size(), .descriptorType = cast(gfxBinding.descriptorType), .descriptorCount = gfxBinding.descriptorCount, diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index dfcefc1..3e66038 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -321,7 +321,7 @@ Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std: return new PipelineStatisticsQuery(this, name); } -Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const std::string& name) { +Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64, const std::string& name) { return new TimestampQuery(this, name); } @@ -457,9 +457,6 @@ void Graphics::buildBottomLevelAccelerationStructures(Array // For the sake of simplicity we won't stage the vertex data to the GPU memory // Note that the buffer usage flags for buffers consumed by the bottom level acceleration structure require special flags - const VkBufferUsageFlags buffer_usage_flags = VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR | - VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - VkBufferCreateInfo transformBufferInfo = { .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .pNext = nullptr, @@ -593,7 +590,7 @@ void Graphics::buildBottomLevelAccelerationStructures(Array } PCommand cmd = graphicsCommands->getCommands(); - vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), buildGeometries.size(), buildGeometries.data(), buildRangePointers.data()); + vkCmdBuildAccelerationStructuresKHR(cmd->getHandle(), (uint32)buildGeometries.size(), buildGeometries.data(), buildRangePointers.data()); cmd->bindResource(PBufferAllocation(transformBuffer)); destructionManager->queueResourceForDestruction(std::move(transformBuffer)); for (auto& scratchAlloc : scratchBuffers) { diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index 15dec29..d28f484 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -508,7 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI uint32 intersectionIndex = VK_SHADER_UNUSED_KHR; if (hitgroup.anyHitShader != nullptr) { auto anyHit = hitgroup.anyHitShader.cast(); - anyHitIndex = shaderStages.size(); + anyHitIndex = (uint32)shaderStages.size(); shaderStages.add(VkPipelineShaderStageCreateInfo{ .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .pNext = nullptr, @@ -521,7 +521,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI } if (hitgroup.intersectionShader != nullptr) { auto intersect = hitgroup.intersectionShader.cast(); - intersectionIndex = shaderGroups.size(); + intersectionIndex = (uint32)shaderGroups.size(); shaderStages.add(VkPipelineShaderStageCreateInfo{ .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .pNext = nullptr, @@ -674,7 +674,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI Gfx::QueueType::GRAPHICS, sbtAlignment); Array sbt(sbtSize); - vkGetRayTracingShaderGroupHandlesKHR(graphics->getDevice(), pipelineHandle, 0, shaderGroups.size(), sbtSize, sbt.data()); + vkGetRayTracingShaderGroupHandlesKHR(graphics->getDevice(), pipelineHandle, 0, (uint32)shaderGroups.size(), sbtSize, sbt.data()); uint64 sbtOffset = 0; Array rayGenSbt(rayGenStride); diff --git a/src/Engine/Graphics/Vulkan/RayTracing.cpp b/src/Engine/Graphics/Vulkan/RayTracing.cpp index 1b4fb4e..dfd6b0d 100644 --- a/src/Engine/Graphics/Vulkan/RayTracing.cpp +++ b/src/Engine/Graphics/Vulkan/RayTracing.cpp @@ -106,7 +106,7 @@ TopLevelAS::TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& crea .pGeometries = &geometry, }; - const uint32 primitiveCount = instances.size(); + const uint32 primitiveCount = (uint32)instances.size(); VkAccelerationStructureBuildSizesInfoKHR buildSizesInfo = { .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR, diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index 55d8494..c8f7037 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -77,7 +77,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg }; sessionDesc.compilerOptionEntries = option.data(); - sessionDesc.compilerOptionEntryCount = option.size(); + sessionDesc.compilerOptionEntryCount = (uint32)option.size(); sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR; Array macros; for (const auto& [key, val] : info.defines) { @@ -140,7 +140,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef()); CHECK_DIAGNOSTICS(); std::cout << info.name << std::endl; - for (size_t i = 0; i < signature->getParameterCount(); ++i) { + for (uint32 i = 0; i < signature->getParameterCount(); ++i) { auto param = signature->getParameterByIndex(i); layout->addMapping(param->getName(), param->getBindingIndex()); //std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index 7f58c47..f317628 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -99,21 +99,21 @@ void Material::updateFloatData(uint32 offset, uint32 numFloats, float* data) { } uint32 Material::addTextures(uint32 numTextures) { - uint32 textureOffset = textures.size(); + uint32 textureOffset = (uint32)textures.size(); textures.resize(textures.size() + numTextures); assert(textures.size() < 512); return textureOffset; } uint32 Material::addSamplers(uint32 numSamplers) { - uint32 samplerOffset = samplers.size(); + uint32 samplerOffset = (uint32)samplers.size(); samplers.resize(samplers.size() + numSamplers); assert(textures.size() < 512); return samplerOffset; } uint32 Material::addFloats(uint32 numFloats) { - uint32 floatOffset = floatData.size(); + uint32 floatOffset = (uint32)floatData.size(); floatData.resize(floatData.size() + numFloats); return floatOffset; } diff --git a/src/Engine/Material/ShaderExpression.cpp b/src/Engine/Material/ShaderExpression.cpp index b626cb4..d2fec09 100644 --- a/src/Engine/Material/ShaderExpression.cpp +++ b/src/Engine/Material/ShaderExpression.cpp @@ -69,7 +69,7 @@ FloatParameter::FloatParameter(std::string name, float data, uint32 index) : Sha FloatParameter::~FloatParameter() {} -void FloatParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) { +void FloatParameter::updateDescriptorSet(uint32, uint32, uint32 floatOffset) { Material::updateFloatData(floatOffset + index, 1, &data); } @@ -98,7 +98,7 @@ VectorParameter::VectorParameter(std::string name, Vector data, uint32 index) VectorParameter::~VectorParameter() {} -void VectorParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) { +void VectorParameter::updateDescriptorSet(uint32, uint32, uint32 floatOffset) { Material::updateFloatData(floatOffset + index, 3, (float*) & data); } @@ -125,7 +125,7 @@ TextureParameter::TextureParameter(std::string name, PTextureAsset asset, uint32 TextureParameter::~TextureParameter() {} -void TextureParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) { +void TextureParameter::updateDescriptorSet(uint32 textureOffset, uint32, uint32) { Material::updateTexture(textureOffset + index, data->getTexture()); } @@ -158,7 +158,7 @@ SamplerParameter::SamplerParameter(std::string name, Gfx::OSampler sampler, uint SamplerParameter::~SamplerParameter() {} -void SamplerParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) { +void SamplerParameter::updateDescriptorSet(uint32, uint32 samplerOffset, uint32) { Material::updateSampler(samplerOffset + index, data); } @@ -183,9 +183,9 @@ CombinedTextureParameter::CombinedTextureParameter(std::string name, PTextureAss CombinedTextureParameter::~CombinedTextureParameter() {} -void CombinedTextureParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) { assert(false); } +void CombinedTextureParameter::updateDescriptorSet(uint32 , uint32 , uint32 ) { assert(false); } -std::string CombinedTextureParameter::evaluate(Map& varState) const { return ""; } +std::string CombinedTextureParameter::evaluate(Map&) const { return ""; } void CombinedTextureParameter::save(ArchiveBuffer& buffer) const { ShaderParameter::save(buffer); diff --git a/src/Engine/Physics/BVH.cpp b/src/Engine/Physics/BVH.cpp index eca8b9e..37cf414 100644 --- a/src/Engine/Physics/BVH.cpp +++ b/src/Engine/Physics/BVH.cpp @@ -85,7 +85,7 @@ void BVH::reinsertCollider(entt::entity entity, AABB aabb) { void BVH::removeCollider(entt::entity entity) { int32 nodeIndex = -1; - for (size_t i = 0; i < dynamicNodes.size(); i++) { + for (uint32_t i = 0; i < dynamicNodes.size(); i++) { if (dynamicNodes[i].isLeaf && dynamicNodes[i].owner == entity) { nodeIndex = i; break; @@ -275,7 +275,7 @@ int32 BVH::splitNode(Array aabbs) { } struct { bool operator()(const AABBCenter& lhs, const AABBCenter& rhs) { return lhs.center[longestAxis] < rhs.center[longestAxis]; } - int32 longestAxis; + int32 longestAxis = 0; } compare = {longestAxis}; std::sort(aabbs.begin(), aabbs.end(), compare); @@ -291,7 +291,7 @@ int32 BVH::splitNode(Array aabbs) { return rootIndex; } int32 BVH::allocateNode() { - for (size_t i = 0; i < dynamicNodes.size(); i++) { + for (uint32 i = 0; i < dynamicNodes.size(); i++) { if (!dynamicNodes[i].isValid) { return i; } @@ -309,7 +309,7 @@ void BVH::validateBVH() const { if (dynamicRoot != -1) { assert(dynamicNodes[dynamicRoot].parentIndex == -1); } - for (size_t i = 0; i < dynamicNodes.size(); ++i) { + for (uint32 i = 0; i < dynamicNodes.size(); ++i) { int32 nodeIdx = i; size_t counter = dynamicNodes.size(); if (!dynamicNodes[nodeIdx].isValid) diff --git a/src/Engine/Physics/PhysicsSystem.cpp b/src/Engine/Physics/PhysicsSystem.cpp index 538fede..137fbdf 100644 --- a/src/Engine/Physics/PhysicsSystem.cpp +++ b/src/Engine/Physics/PhysicsSystem.cpp @@ -144,7 +144,7 @@ void PhysicsSystem::writeRigidBody(const Body& body) const { } } -Array PhysicsSystem::integratePhysics(const Array& bodies, const float t0, const float tdelta) const { +Array PhysicsSystem::integratePhysics(const Array& bodies, const float, const float) const { Array result; Array buffer; result.resize(bodies.size()); diff --git a/src/Engine/Scene/LightEnvironment.cpp b/src/Engine/Scene/LightEnvironment.cpp index 52409da..854f141 100644 --- a/src/Engine/Scene/LightEnvironment.cpp +++ b/src/Engine/Scene/LightEnvironment.cpp @@ -57,8 +57,8 @@ void LightEnvironment::commit() { Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT); - uint32 numPointLights = points.size(); - uint32 numDirectionalLights = dirs.size(); + uint32 numPointLights = (uint32)points.size(); + uint32 numDirectionalLights = (uint32)dirs.size(); set->updateConstants("numPointLights", 0, &numPointLights); set->updateBuffer("pointLights", 0, pointLights); set->updateConstants("numDirectionalLights", 0, &numDirectionalLights); diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index c7ae0ee..9fe59be 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -17,12 +17,6 @@ Scene::Scene(Gfx::PGraphics graphics) : graphics(graphics), lightEnv(new LightEn Scene::~Scene() {} -void Scene::bakeLighting() { - const auto& matData = StaticMeshVertexData::getInstance()->getMaterialData(); - for (const auto& mat : matData) - { - - } -} +void Scene::bakeLighting() {} void Scene::update(float deltaTime) { physics.update(deltaTime); } diff --git a/src/Engine/System/MeshUpdater.cpp b/src/Engine/System/MeshUpdater.cpp index 5940733..748fea0 100644 --- a/src/Engine/System/MeshUpdater.cpp +++ b/src/Engine/System/MeshUpdater.cpp @@ -9,7 +9,7 @@ MeshUpdater::MeshUpdater(PScene scene) : ComponentSystemmeshes.size(); ++i) { comp.meshletOffsets.add(comp.asset->meshes[i]->vertexData->addCullingMapping(comp.asset->meshes[i]->id)); diff --git a/src/Engine/UI/Element.h b/src/Engine/UI/Element.h index bd3922d..6a47bf2 100644 --- a/src/Engine/UI/Element.h +++ b/src/Engine/UI/Element.h @@ -31,10 +31,10 @@ class Element { // calculates the relative positions of the child elements for the applied layout style virtual void layout(UVector2 parentSize) { if (style.maxWidthType == DimensionType::Auto) { - maxDimensions.x = parentSize.x; + maxDimensions.x = (float)parentSize.x; } if (style.maxHeightType == DimensionType::Auto) { - maxDimensions.y = parentSize.y; + maxDimensions.y = (float)parentSize.y; } if (style.widthType == DimensionType::Pixel) { dimensions.x = style.width; @@ -69,7 +69,7 @@ class Element { // create a new line in case the element doesnt fit on the current one anymore, // but keep in current line in case we are still at the start, as a new line wouldnt help here if (cursor.x + child->dimensions.x > maxDimensions.x - child->style.left && cursor.x != 0) { - cursor.x = style.paddingLeft; + cursor.x = (float)style.paddingLeft; cursor.y += lineHeight; lineHeight = 0; } @@ -90,7 +90,7 @@ class Element { if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) { // create a new line in case we are not already at one if (cursor.x != 0) { - cursor.x = style.paddingLeft; + cursor.x = (float)style.paddingLeft; cursor.y += lineHeight; } child->position.x = cursor.x + child->style.marginLeft; diff --git a/src/Engine/UI/Element/Text.h b/src/Engine/UI/Element/Text.h index f08fb96..6e1d43c 100644 --- a/src/Engine/UI/Element/Text.h +++ b/src/Engine/UI/Element/Text.h @@ -13,7 +13,7 @@ template class Text : public Element { style.outerDisplay = OuterDisplayType::Inline; (classes::apply(style), ...); } - virtual void layout(UVector2 parentSize) override { + virtual void layout(UVector2) override { UVector2 cursor = UVector2(0); dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders); } diff --git a/src/Engine/UI/Style/Class.h b/src/Engine/UI/Style/Class.h index d727fff..23f4129 100644 --- a/src/Engine/UI/Style/Class.h +++ b/src/Engine/UI/Style/Class.h @@ -67,24 +67,24 @@ using BG_Red = BackgroundColorClass; template struct MarginClass { static void apply(UI::Style& s) { - if (ml != -1) + if constexpr (ml != -1) s.marginLeft = ml; - if (mr != -1) + if constexpr (mr != -1) s.marginRight = mr; - if (mt != -1) + if constexpr (mt != -1) s.marginTop = mt; - if (mb != -1) + if constexpr (mb != -1) s.marginBottom = mb; } }; #define DECLARE_MARGIN_CLASSES(x) \ using M_##x = MarginClass; \ - using M_X##x = MarginClass; \ - using M_Y##x = MarginClass<-1u, -1u, x, x>; \ - using M_L##x = MarginClass; \ - using M_R##x = MarginClass<-1u, x, -1u, -1u>; \ - using M_T##x = MarginClass<-1u, -1u, x, -1u>; \ - using M_B##x = MarginClass<-1u, -1u, -1u, x>; + using M_X##x = MarginClass::max(), std::numeric_limits::max()>; \ + using M_Y##x = MarginClass::max(), std::numeric_limits::max(), x, x>; \ + using M_L##x = MarginClass::max(), std::numeric_limits::max(), std::numeric_limits::max()>; \ + using M_R##x = MarginClass::max(), x, std::numeric_limits::max(), std::numeric_limits::max()>; \ + using M_T##x = MarginClass::max(), std::numeric_limits::max(), x, std::numeric_limits::max()>; \ + using M_B##x = MarginClass::max(), std::numeric_limits::max(), std::numeric_limits::max(), x>; DECLARE_MARGIN_CLASSES(0) DECLARE_MARGIN_CLASSES(1)