Adding basic memory resource
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ set(CMAKE_TOOLCHAIN_FILE ${EXTERNAL_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake
|
|||||||
set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp)
|
set(CRCPP_ROOT ${EXTERNAL_ROOT}/CRCpp)
|
||||||
set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp)
|
set(METAL_ROOT ${EXTERNAL_ROOT}/metal-cpp)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(VCPKG_BASE_FOLDER ${VCPKG_INSTALLED_DIR}/x64-windows/)
|
set(VCPKG_BASE_FOLDER ${CMAKE_BINARY_DIR}/vcpkg_installed/x64-windows/)
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
set(VCPKG_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/arm64-osx/)
|
set(VCPKG_BASE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/build/vcpkg_installed/arm64-osx/)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
+1
-1
@@ -41,7 +41,7 @@
|
|||||||
"buildCommandArgs": "",
|
"buildCommandArgs": "",
|
||||||
"ctestCommandArgs": "",
|
"ctestCommandArgs": "",
|
||||||
"configurationType": "Debug",
|
"configurationType": "Debug",
|
||||||
"generator": "Ninja",
|
"generator": "Visual Studio 17 2022 Win64",
|
||||||
"intelliSenseMode": "windows-msvc-x64",
|
"intelliSenseMode": "windows-msvc-x64",
|
||||||
"inheritEnvironments": [ "msvc_x64" ],
|
"inheritEnvironments": [ "msvc_x64" ],
|
||||||
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
|
"cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64",
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "Placeholder",
|
||||||
|
"params": {
|
||||||
|
},
|
||||||
|
"code": [
|
||||||
|
{
|
||||||
|
"exp": "BRDF",
|
||||||
|
"profile": "BlinnPhong",
|
||||||
|
"values": {
|
||||||
|
"baseColor": "float3(0, 1, 0)",
|
||||||
|
"normal": "float3(0, 0, 1)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ int main(int, char**) {
|
|||||||
Array<Vector> texCoords1(mesh->mNumVertices);
|
Array<Vector> texCoords1(mesh->mNumVertices);
|
||||||
if (mesh->HasTextureCoords(2))
|
if (mesh->HasTextureCoords(2))
|
||||||
abort();
|
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);
|
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0] != nullptr)
|
if (mesh->mTextureCoords[0] != nullptr)
|
||||||
@@ -65,7 +65,7 @@ int main(int, char**) {
|
|||||||
return 0.5 * glm::length(glm::cross(p2 - p1, p3 - p1));
|
return 0.5 * glm::length(glm::cross(p2 - p1, p3 - p1));
|
||||||
};
|
};
|
||||||
Array<Tri> tris(mesh->mNumFaces);
|
Array<Tri> 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[0] = mesh->mFaces[faceIndex].mIndices[0];
|
||||||
tris[faceIndex].p[1] = mesh->mFaces[faceIndex].mIndices[1];
|
tris[faceIndex].p[1] = mesh->mFaces[faceIndex].mIndices[1];
|
||||||
tris[faceIndex].p[2] = mesh->mFaces[faceIndex].mIndices[2];
|
tris[faceIndex].p[2] = mesh->mFaces[faceIndex].mIndices[2];
|
||||||
|
|||||||
@@ -516,7 +516,7 @@ Vector4 MeshLoader::encodeQTangent(Matrix3 m) {
|
|||||||
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
|
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
|
||||||
Component::Collider& collider) {
|
Component::Collider& collider) {
|
||||||
List<std::function<void()>> work;
|
List<std::function<void()>> work;
|
||||||
for (int32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) {
|
for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) {
|
||||||
aiMesh* mesh = scene->mMeshes[meshIndex];
|
aiMesh* mesh = scene->mMeshes[meshIndex];
|
||||||
if (!(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE))
|
if (!(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ void InspectorView::prepareRender() {}
|
|||||||
|
|
||||||
void InspectorView::render() { renderGraph.render(Component::Camera()); }
|
void InspectorView::render() { renderGraph.render(Component::Camera()); }
|
||||||
|
|
||||||
void InspectorView::applyArea(URect area) {}
|
void InspectorView::applyArea(URect ) {}
|
||||||
|
|
||||||
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) {}
|
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) {}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ void PlayView::keyCallback(KeyCode code, InputAction action, KeyModifier modifie
|
|||||||
if (code == KeyCode::KEY_R && action == InputAction::RELEASE) {
|
if (code == KeyCode::KEY_R && action == InputAction::RELEASE) {
|
||||||
getGlobals().useRayTracing = !getGlobals().useRayTracing;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ void FontAsset::load(ArchiveBuffer& buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FontAsset::loadFace() {
|
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);
|
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_face = hb_face_create(blob, 0);
|
||||||
hb_font = hb_font_create(hb_face);
|
hb_font = hb_font_create(hb_face);
|
||||||
}
|
}
|
||||||
UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<RenderGlyph>& render) {
|
UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<RenderGlyph>& render) {
|
||||||
loadGlyphs(fontSize);
|
loadGlyphs(fontSize);
|
||||||
hb_buffer_t* buf = hb_buffer_create();
|
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_language(buf, hb_language_from_string("en", -1));
|
||||||
hb_buffer_set_script(buf, HB_SCRIPT_LATIN);
|
hb_buffer_set_script(buf, HB_SCRIPT_LATIN);
|
||||||
hb_buffer_set_direction(buf, HB_DIRECTION_LTR);
|
hb_buffer_set_direction(buf, HB_DIRECTION_LTR);
|
||||||
@@ -52,10 +52,10 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<Rend
|
|||||||
Vector2 cursor = Vector2(0);
|
Vector2 cursor = Vector2(0);
|
||||||
for (uint32 i = 0; i < num_glyphs; ++i) {
|
for (uint32 i = 0; i < num_glyphs; ++i) {
|
||||||
hb_codepoint_t glyphid = glyphs[i].codepoint;
|
hb_codepoint_t glyphid = glyphs[i].codepoint;
|
||||||
float xOffset = positions[i].x_offset * fontSize / xppem;
|
float xOffset = (float)positions[i].x_offset * fontSize / xppem;
|
||||||
float yOffset = positions[i].y_offset * fontSize / yppem;
|
float yOffset = (float)positions[i].y_offset * fontSize / yppem;
|
||||||
float xAdvance = positions[i].x_advance * fontSize / xppem;
|
float xAdvance = (float)positions[i].x_advance * fontSize / xppem;
|
||||||
float yAdvance = positions[i].y_advance * fontSize / yppem;
|
float yAdvance = (float)positions[i].y_advance * fontSize / yppem;
|
||||||
Vector2 position = cursor + Vector2(xOffset, yOffset);
|
Vector2 position = cursor + Vector2(xOffset, yOffset);
|
||||||
Vector2 dimensions = fontSizes[fontSize].glyphs[glyphid].size;
|
Vector2 dimensions = fontSizes[fontSize].glyphs[glyphid].size;
|
||||||
render.add(RenderGlyph{
|
render.add(RenderGlyph{
|
||||||
@@ -73,7 +73,7 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<Rend
|
|||||||
|
|
||||||
void FontAsset::loadGlyphs(uint32 fontSize) {
|
void FontAsset::loadGlyphs(uint32 fontSize) {
|
||||||
FT_Set_Pixel_Sizes(ft_face, 0, fontSize);
|
FT_Set_Pixel_Sizes(ft_face, 0, fontSize);
|
||||||
for (uint32 i = 0; i < ft_face->num_glyphs; ++i) {
|
for (int i = 0; i < ft_face->num_glyphs; ++i) {
|
||||||
assert(FT_Load_Glyph(ft_face, i, FT_LOAD_RENDER) == 0);
|
assert(FT_Load_Glyph(ft_face, i, FT_LOAD_RENDER) == 0);
|
||||||
FontAsset::Glyph& glyph = fontSizes[fontSize].glyphs[i];
|
FontAsset::Glyph& glyph = fontSizes[fontSize].glyphs[i];
|
||||||
glyph.size = IVector2(ft_face->glyph->bitmap.width, ft_face->glyph->bitmap.rows);
|
glyph.size = IVector2(ft_face->glyph->bitmap.width, ft_face->glyph->bitmap.rows);
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ LevelAsset::LevelAsset(std::string_view folderPath, std::string_view name) : Ass
|
|||||||
|
|
||||||
LevelAsset::~LevelAsset() {}
|
LevelAsset::~LevelAsset() {}
|
||||||
|
|
||||||
void LevelAsset::save(ArchiveBuffer& buffer) const { }
|
void LevelAsset::save(ArchiveBuffer&) const { }
|
||||||
|
|
||||||
void LevelAsset::load(ArchiveBuffer& buffer) { }
|
void LevelAsset::load(ArchiveBuffer&) { }
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "EngineTypes.h"
|
|
||||||
#include "Concepts.h"
|
#include "Concepts.h"
|
||||||
|
#include "EngineTypes.h"
|
||||||
|
#include "MemoryResource.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> struct Array {
|
template <typename T> struct Array {
|
||||||
public:
|
public:
|
||||||
template <typename X> class IteratorBase {
|
template <typename X> class IteratorBase {
|
||||||
public:
|
public:
|
||||||
@@ -67,7 +68,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
};
|
};
|
||||||
|
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
using allocator_type = Allocator;
|
using allocator_type = std::pmr::polymorphic_allocator<T>;
|
||||||
using size_type = std::size_t;
|
using size_type = std::size_t;
|
||||||
using difference_type = std::ptrdiff_t;
|
using difference_type = std::ptrdiff_t;
|
||||||
using pointer = T*;
|
using pointer = T*;
|
||||||
@@ -82,12 +83,8 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
|
||||||
constexpr Array() noexcept(noexcept(Allocator())) : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(Allocator()) {
|
constexpr Array(const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) noexcept
|
||||||
_data = allocateArray(DEFAULT_ALLOC_SIZE);
|
: arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) {
|
||||||
assert(_data != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr explicit Array(const allocator_type& alloc) noexcept : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) {
|
|
||||||
_data = allocateArray(DEFAULT_ALLOC_SIZE);
|
_data = allocateArray(DEFAULT_ALLOC_SIZE);
|
||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
}
|
}
|
||||||
@@ -138,7 +135,8 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
std::uninitialized_copy(other.begin(), other.end(), begin());
|
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);
|
_data = allocateArray(other.allocated);
|
||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
std::uninitialized_copy(other.begin(), other.end(), begin());
|
std::uninitialized_copy(other.begin(), other.end(), begin());
|
||||||
@@ -150,7 +148,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
other.allocated = 0;
|
other.allocated = 0;
|
||||||
other.arraySize = 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) {
|
: arraySize(std::move(other.arraySize)), allocated(std::move(other.allocated)), allocator(alloc) {
|
||||||
_data = allocateArray(other.allocated);
|
_data = allocateArray(other.allocated);
|
||||||
std::uninitialized_move(other.begin(), other.end(), begin());
|
std::uninitialized_move(other.begin(), other.end(), begin());
|
||||||
@@ -179,8 +177,8 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Array& operator=(Array&& other) noexcept(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
|
Array& operator=(Array&& other) noexcept(std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
|
||||||
std::allocator_traits<Allocator>::is_always_equal::value) {
|
std::allocator_traits<allocator_type>::is_always_equal::value) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
if (_data != nullptr) {
|
if (_data != nullptr) {
|
||||||
clear();
|
clear();
|
||||||
@@ -389,7 +387,11 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
assert(result != nullptr);
|
assert(result != nullptr);
|
||||||
return result;
|
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 <typename Type> T& addInternal(Type&& t) noexcept {
|
template <typename Type> T& addInternal(Type&& t) noexcept {
|
||||||
if (arraySize == allocated) {
|
if (arraySize == allocated) {
|
||||||
size_type newSize = arraySize + 1;
|
size_type newSize = arraySize + 1;
|
||||||
@@ -449,7 +451,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
|
|||||||
allocator_type allocator;
|
allocator_type allocator;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type, class Alloc> constexpr bool operator==(const Array<Type, Alloc>& lhs, const Array<Type, Alloc>& rhs) {
|
template <class Type> constexpr bool operator==(const Array<Type>& lhs, const Array<Type>& rhs) {
|
||||||
if (lhs.size() != rhs.size()) {
|
if (lhs.size() != rhs.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -461,7 +463,7 @@ template <class Type, class Alloc> constexpr bool operator==(const Array<Type, A
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Type, class Alloc> constexpr auto operator<=>(const Array<Type, Alloc>& lhs, const Array<Type, Alloc>& rhs) {
|
template <class Type> constexpr auto operator<=>(const Array<Type>& lhs, const Array<Type>& rhs) {
|
||||||
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ target_sources(Engine
|
|||||||
Array.h
|
Array.h
|
||||||
List.h
|
List.h
|
||||||
Map.h
|
Map.h
|
||||||
|
MemoryResource.h
|
||||||
|
MemoryResource.cpp
|
||||||
Pair.h
|
Pair.h
|
||||||
Set.h
|
Set.h
|
||||||
Tree.h)
|
Tree.h)
|
||||||
@@ -13,6 +15,7 @@ target_sources(Engine
|
|||||||
Array.h
|
Array.h
|
||||||
List.h
|
List.h
|
||||||
Map.h
|
Map.h
|
||||||
|
MemoryResource.h
|
||||||
Pair.h
|
Pair.h
|
||||||
Set.h
|
Set.h
|
||||||
Tree.h)
|
Tree.h)
|
||||||
@@ -5,12 +5,11 @@
|
|||||||
#include "Tree.h"
|
#include "Tree.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
template <typename KeyType, typename PairType> struct _KeyFun {
|
template <typename KeyType, typename PairType> struct _KeyFun {
|
||||||
const KeyType& operator()(const PairType& pair) const { return pair.key; }
|
const KeyType& operator()(const PairType& pair) const { return pair.key; }
|
||||||
};
|
};
|
||||||
template <typename K, typename V, typename Compare = std::less<K>, typename Allocator = std::pmr::polymorphic_allocator<Pair<const K, V>>>
|
template <typename K, typename V, typename Compare = std::less<K>, typename Allocator = std::pmr::polymorphic_allocator<Pair<K, V>>>
|
||||||
struct Map : public Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocator> {
|
struct Map : public Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocator> {
|
||||||
using Super = Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocator>;
|
using Super = Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocator>;
|
||||||
using key_type = Super::key_type;
|
using key_type = Super::key_type;
|
||||||
@@ -36,7 +35,7 @@ struct Map : public Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocat
|
|||||||
constexpr explicit Map(const Allocator& alloc) noexcept(noexcept(Compare())) : Super(alloc) {}
|
constexpr explicit Map(const Allocator& alloc) noexcept(noexcept(Compare())) : Super(alloc) {}
|
||||||
constexpr Map(std::initializer_list<Pair<K, V>> init) : Super(init) {}
|
constexpr Map(std::initializer_list<Pair<K, V>> init) : Super(init) {}
|
||||||
constexpr mapped_type& operator[](const key_type& key) {
|
constexpr mapped_type& operator[](const key_type& key) {
|
||||||
auto [it, inserted] = Super::insert(Pair<K, V>(key, V()));
|
auto [it, _] = Super::insert(Pair<K, V>(key));
|
||||||
return it->value;
|
return it->value;
|
||||||
}
|
}
|
||||||
constexpr const mapped_type& operator[](const key_type& key) const { return Super::find(key)->value; }
|
constexpr const mapped_type& operator[](const key_type& key) const { return Super::find(key)->value; }
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "MemoryResource.h"
|
||||||
|
#include "Map.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace Seele;
|
||||||
|
|
||||||
|
std::mutex allocationMutex;
|
||||||
|
std::map<std::string, std::atomic_uint64_t> allocationCounters;
|
||||||
|
std::mutex resourcesMutex;
|
||||||
|
std::map<std::string, debug_resource> 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];
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <memory_resource>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -3,14 +3,6 @@
|
|||||||
namespace Seele {
|
namespace Seele {
|
||||||
template <typename K, typename V> struct Pair {
|
template <typename K, typename V> struct Pair {
|
||||||
public:
|
public:
|
||||||
constexpr Pair() : key(K()), value(V()) {}
|
|
||||||
constexpr Pair(const K& key, const V& value) : key(key), value(value) {}
|
|
||||||
template <class U1 = K, class U2 = V> constexpr Pair(U1&& x, U2&& y) : key(std::forward<U1>(x)), value(std::forward<U2>(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) {
|
constexpr friend bool operator<(const Pair& left, const Pair& right) {
|
||||||
return left.key < right.key || (!(right.key < left.key) && left.value < right.value);
|
return left.key < right.key || (!(right.key < left.key) && left.value < right.value);
|
||||||
}
|
}
|
||||||
|
|||||||
+125
-93
@@ -1,15 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Pair.h"
|
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
|
#include "Pair.h"
|
||||||
|
#include <map>
|
||||||
#include <memory_resource>
|
#include <memory_resource>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
template <typename KeyType, typename NodeData, typename KeyFun, typename Compare, typename Allocator> struct Tree {
|
template <typename KeyType, typename NodeData, typename KeyFun, typename Compare, typename Allocator> struct Tree {
|
||||||
protected:
|
protected:
|
||||||
struct Node {
|
struct Node {
|
||||||
Node(Node* left, Node* right, const NodeData& nodeData) : leftChild(left), rightChild(right), data(nodeData) {}
|
Node(const NodeData& data)
|
||||||
Node(Node* left, Node* right, NodeData&& nodeData) : leftChild(left), rightChild(right), data(std::move(nodeData)) {}
|
: data(data)
|
||||||
|
{}
|
||||||
|
Node(NodeData&& data)
|
||||||
|
: data(std::move(data)) {}
|
||||||
|
|
||||||
|
Node* parent = nullptr;
|
||||||
Node* leftChild;
|
Node* leftChild;
|
||||||
Node* rightChild;
|
Node* rightChild;
|
||||||
NodeData data;
|
NodeData data;
|
||||||
@@ -17,79 +23,6 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
|
using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <typename IterType> 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<Node*>&& beginIt = Array<Node*>()) : 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<Node*> traversal;
|
|
||||||
};
|
|
||||||
using Iterator = IteratorBase<NodeData>;
|
|
||||||
using ConstIterator = IteratorBase<const NodeData>;
|
|
||||||
|
|
||||||
using key_type = KeyType;
|
using key_type = KeyType;
|
||||||
using value_type = NodeData;
|
using value_type = NodeData;
|
||||||
using allocator_type = Allocator;
|
using allocator_type = Allocator;
|
||||||
@@ -100,6 +33,95 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
using pointer = std::allocator_traits<Allocator>::pointer;
|
using pointer = std::allocator_traits<Allocator>::pointer;
|
||||||
using const_pointer = std::allocator_traits<Allocator>::const_pointer;
|
using const_pointer = std::allocator_traits<Allocator>::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>::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<reference>(ConstIterator::operator*()); }
|
||||||
|
constexpr pointer operator->() const noexcept { return std::pointer_traits<pointer>::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 iterator = Iterator;
|
||||||
using const_iterator = ConstIterator;
|
using const_iterator = ConstIterator;
|
||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
@@ -212,12 +234,12 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
return iterator(it);
|
return iterator(it);
|
||||||
}
|
}
|
||||||
constexpr Pair<iterator, bool> insert(const NodeData& data) {
|
constexpr Pair<iterator, bool> insert(const NodeData& data) {
|
||||||
auto [r, inserted] = _insert(root, data);
|
const auto& [r, inserted] = _insert(root, data);
|
||||||
root = r;
|
root = r;
|
||||||
return Pair<iterator, bool>(iterator(root), inserted);
|
return Pair<iterator, bool>(iterator(root), inserted);
|
||||||
}
|
}
|
||||||
constexpr Pair<iterator, bool> insert(NodeData&& data) {
|
constexpr Pair<iterator, bool> insert(NodeData&& data) {
|
||||||
auto [r, inserted] = _insert(root, std::move(data));
|
const auto& [r, inserted] = _insert(root, std::move(data));
|
||||||
root = r;
|
root = r;
|
||||||
return Pair<iterator, bool>(iterator(root), inserted);
|
return Pair<iterator, bool>(iterator(root), inserted);
|
||||||
}
|
}
|
||||||
@@ -242,25 +264,20 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
}
|
}
|
||||||
constexpr Iterator calcBeginIterator() const {
|
constexpr Iterator calcBeginIterator() const {
|
||||||
Node* begin = root;
|
Node* begin = root;
|
||||||
Array<Node*> beginTraversal;
|
|
||||||
while (begin != nullptr) {
|
while (begin != nullptr) {
|
||||||
beginTraversal.add(begin);
|
|
||||||
begin = begin->leftChild;
|
begin = begin->leftChild;
|
||||||
}
|
}
|
||||||
if (!beginTraversal.empty()) {
|
if (begin->parent != nullptr) {
|
||||||
begin = beginTraversal.back();
|
begin = begin->parent;
|
||||||
beginTraversal.pop();
|
|
||||||
}
|
}
|
||||||
return Iterator(begin, std::move(beginTraversal));
|
return Iterator(begin);
|
||||||
}
|
}
|
||||||
constexpr Iterator calcEndIterator() const {
|
constexpr Iterator calcEndIterator() const {
|
||||||
Node* endIndex = root;
|
Node* endNode = root;
|
||||||
Array<Node*> endTraversal;
|
while (endNode != nullptr) {
|
||||||
while (endIndex != nullptr) {
|
endNode = endNode->rightChild;
|
||||||
endTraversal.add(endIndex);
|
|
||||||
endIndex = endIndex->rightChild;
|
|
||||||
}
|
}
|
||||||
return Iterator(endIndex, std::move(endTraversal));
|
return Iterator(endNode);
|
||||||
}
|
}
|
||||||
NodeAlloc alloc;
|
NodeAlloc alloc;
|
||||||
Node* root;
|
Node* root;
|
||||||
@@ -273,20 +290,24 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
Node* rotateLeft(Node* x) {
|
Node* rotateLeft(Node* x) {
|
||||||
Node* y = x->rightChild;
|
Node* y = x->rightChild;
|
||||||
x->rightChild = y->leftChild;
|
x->rightChild = y->leftChild;
|
||||||
|
x->rightChild->parent = x;
|
||||||
y->leftChild = x;
|
y->leftChild = x;
|
||||||
|
y->leftChild->parent = y;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
Node* rotateRight(Node* x) {
|
Node* rotateRight(Node* x) {
|
||||||
Node* y = x->leftChild;
|
Node* y = x->leftChild;
|
||||||
x->leftChild = y->rightChild;
|
x->leftChild = y->rightChild;
|
||||||
|
x->leftChild->parent = x;
|
||||||
y->rightChild = x;
|
y->rightChild = x;
|
||||||
|
y->rightChild->parent = y;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
template <class NodeDataType> Pair<Node*, bool> _insert(Node* r, NodeDataType&& data) {
|
template <class NodeDataType> Pair<Node*, bool> _insert(Node* r, NodeDataType&& data) {
|
||||||
markIteratorsDirty();
|
markIteratorsDirty();
|
||||||
if (r == nullptr) {
|
if (r == nullptr) {
|
||||||
root = alloc.allocate(1);
|
root = alloc.allocate(1);
|
||||||
std::allocator_traits<NodeAlloc>::construct(alloc, root, nullptr, nullptr, std::forward<NodeDataType>(data));
|
std::allocator_traits<NodeAlloc>::construct(alloc, root, std::forward<NodeDataType>(data));
|
||||||
_size++;
|
_size++;
|
||||||
return Pair<Node*, bool>(root, true);
|
return Pair<Node*, bool>(root, true);
|
||||||
}
|
}
|
||||||
@@ -296,15 +317,19 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
return Pair<Node*, bool>(r, false);
|
return Pair<Node*, bool>(r, false);
|
||||||
|
|
||||||
Node* newNode = alloc.allocate(1);
|
Node* newNode = alloc.allocate(1);
|
||||||
std::allocator_traits<NodeAlloc>::construct(alloc, newNode, nullptr, nullptr, std::forward<NodeDataType>(data));
|
std::allocator_traits<NodeAlloc>::construct(alloc, newNode, std::forward<NodeDataType>(data));
|
||||||
|
|
||||||
if (comp(keyFun(newNode->data), keyFun(r->data))) {
|
if (comp(keyFun(newNode->data), keyFun(r->data))) {
|
||||||
newNode->rightChild = r;
|
newNode->rightChild = r;
|
||||||
|
newNode->rightChild->parent = newNode;
|
||||||
newNode->leftChild = r->leftChild;
|
newNode->leftChild = r->leftChild;
|
||||||
|
newNode->leftChild->parent = newNode;
|
||||||
r->leftChild = nullptr;
|
r->leftChild = nullptr;
|
||||||
} else {
|
} else {
|
||||||
newNode->leftChild = r;
|
newNode->leftChild = r;
|
||||||
|
newNode->leftChild->parent = newNode;
|
||||||
newNode->rightChild = r->rightChild;
|
newNode->rightChild = r->rightChild;
|
||||||
|
newNode->rightChild->parent = newNode;
|
||||||
r->rightChild = nullptr;
|
r->rightChild = nullptr;
|
||||||
}
|
}
|
||||||
_size++;
|
_size++;
|
||||||
@@ -329,6 +354,7 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
|
|
||||||
r = _splay(r->leftChild, key);
|
r = _splay(r->leftChild, key);
|
||||||
r->rightChild = temp->rightChild;
|
r->rightChild = temp->rightChild;
|
||||||
|
r->rightChild->parent = r;
|
||||||
}
|
}
|
||||||
std::allocator_traits<NodeAlloc>::destroy(alloc, temp);
|
std::allocator_traits<NodeAlloc>::destroy(alloc, temp);
|
||||||
alloc.deallocate(temp, 1);
|
alloc.deallocate(temp, 1);
|
||||||
@@ -346,13 +372,16 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
|
|
||||||
if (comp(key, keyFun(r->leftChild->data))) {
|
if (comp(key, keyFun(r->leftChild->data))) {
|
||||||
r->leftChild->leftChild = _splay(r->leftChild->leftChild, key);
|
r->leftChild->leftChild = _splay(r->leftChild->leftChild, key);
|
||||||
|
r->leftChild->leftChild->parent = r->leftChild;
|
||||||
|
|
||||||
r = rotateRight(r);
|
r = rotateRight(r);
|
||||||
} else if (comp(keyFun(r->leftChild->data), key)) {
|
} else if (comp(keyFun(r->leftChild->data), key)) {
|
||||||
r->leftChild->rightChild = _splay(r->leftChild->rightChild, key);
|
r->leftChild->rightChild = _splay(r->leftChild->rightChild, key);
|
||||||
|
r->leftChild->rightChild->parent = r->leftChild;
|
||||||
|
|
||||||
if (r->leftChild->rightChild != nullptr) {
|
if (r->leftChild->rightChild != nullptr) {
|
||||||
r->leftChild = rotateLeft(r->leftChild);
|
r->leftChild = rotateLeft(r->leftChild);
|
||||||
|
r->leftChild->parent = r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (r->leftChild == nullptr) ? r : rotateRight(r);
|
return (r->leftChild == nullptr) ? r : rotateRight(r);
|
||||||
@@ -362,12 +391,15 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
|
|||||||
|
|
||||||
if (comp(key, keyFun(r->rightChild->data))) {
|
if (comp(key, keyFun(r->rightChild->data))) {
|
||||||
r->rightChild->leftChild = _splay(r->rightChild->leftChild, key);
|
r->rightChild->leftChild = _splay(r->rightChild->leftChild, key);
|
||||||
|
r->rightChild->leftChild->parent = r->rightChild;
|
||||||
|
|
||||||
if (r->rightChild->leftChild != nullptr) {
|
if (r->rightChild->leftChild != nullptr) {
|
||||||
r->rightChild = rotateRight(r->rightChild);
|
r->rightChild = rotateRight(r->rightChild);
|
||||||
|
r->rightChild->parent = r;
|
||||||
}
|
}
|
||||||
} else if (comp(keyFun(r->rightChild->data), key)) {
|
} else if (comp(keyFun(r->rightChild->data), key)) {
|
||||||
r->rightChild->rightChild = _splay(r->rightChild->rightChild, key);
|
r->rightChild->rightChild = _splay(r->rightChild->rightChild, key);
|
||||||
|
r->rightChild->rightChild->parent = r->rightChild;
|
||||||
|
|
||||||
r = rotateLeft(r);
|
r = rotateLeft(r);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ uint32_t find_msb_64(uint64_t x) {
|
|||||||
|
|
||||||
CPUMesh Seele::generateCPUMesh(uint32 cbtNumElements) {
|
CPUMesh Seele::generateCPUMesh(uint32 cbtNumElements) {
|
||||||
CPUMesh result;
|
CPUMesh result;
|
||||||
result.totalNumElements = edges.size() + cbtNumElements;
|
result.totalNumElements = (uint32)edges.size() + cbtNumElements;
|
||||||
|
|
||||||
result.heapIDArray.resize(result.totalNumElements);
|
result.heapIDArray.resize(result.totalNumElements);
|
||||||
result.neighborsArray.resize(result.totalNumElements);
|
result.neighborsArray.resize(result.totalNumElements);
|
||||||
@@ -193,7 +193,6 @@ Matrix3 decodeSubdivisionMatrix(uint64 heapID) {
|
|||||||
void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) {
|
void LebMatrixCache::init(Gfx::PGraphics graphics, uint32 depth) {
|
||||||
cacheDepth = depth;
|
cacheDepth = depth;
|
||||||
uint32 matrixCount = 2ULL << cacheDepth;
|
uint32 matrixCount = 2ULL << cacheDepth;
|
||||||
Matrix3 m;
|
|
||||||
std::vector<Matrix3> table(matrixCount);
|
std::vector<Matrix3> table(matrixCount);
|
||||||
table[0] = Matrix3({1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
|
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) {
|
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) {
|
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();
|
/*Gfx::PDescriptorSet set = layout->allocateDescriptorSet();
|
||||||
set->updateBuffer(GEOMETRY_CB, 0, geometryCB);
|
set->updateBuffer(GEOMETRY_CB, 0, geometryCB);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
add_subdirectory(CBT/)
|
#add_subdirectory(CBT/)
|
||||||
|
|
||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void buildAdjacency(const uint32 numVerts, const Array<uint32>& indices, Adjacen
|
|||||||
triangleOffset += info.trianglesPerVertex[j];
|
triangleOffset += info.trianglesPerVertex[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 numTriangles = indices.size() / 3;
|
uint32 numTriangles = (uint32)indices.size() / 3;
|
||||||
info.triangleData.resize(triangleOffset);
|
info.triangleData.resize(triangleOffset);
|
||||||
Array<uint32> offsets = info.indexBufferOffset;
|
Array<uint32> offsets = info.indexBufferOffset;
|
||||||
for (uint32 k = 0; k < numTriangles; ++k) {
|
for (uint32 k = 0; k < numTriangles; ++k) {
|
||||||
|
|||||||
@@ -200,8 +200,7 @@ void BasePass::render() {
|
|||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
|
||||||
command->bindPipeline(pipeline);
|
|
||||||
} else {
|
} else {
|
||||||
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
|
Gfx::LegacyPipelineCreateInfo pipelineInfo = {
|
||||||
.vertexShader = collection->vertexShader,
|
.vertexShader = collection->vertexShader,
|
||||||
@@ -221,8 +220,7 @@ void BasePass::render() {
|
|||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Gfx::PGraphicsPipeline pipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
|
command->bindPipeline(graphics->createGraphicsPipeline(std::move(pipelineInfo)));
|
||||||
command->bindPipeline(pipeline);
|
|
||||||
}
|
}
|
||||||
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(),
|
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(),
|
||||||
scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(), opaqueCulling});
|
scene->getLightEnvironment()->getDescriptorSet(), Material::getDescriptorSet(), opaqueCulling});
|
||||||
@@ -231,7 +229,7 @@ void BasePass::render() {
|
|||||||
Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
|
0, sizeof(VertexData::DrawCallOffsets), &drawCall.offsets);
|
||||||
if (graphics->supportMeshShading()) {
|
if (graphics->supportMeshShading()) {
|
||||||
command->drawMesh(drawCall.instanceMeshData.size(), 1, 1);
|
command->drawMesh((uint32)drawCall.instanceMeshData.size(), 1, 1);
|
||||||
} else {
|
} else {
|
||||||
command->bindIndexBuffer(vertexData->getIndexBuffer());
|
command->bindIndexBuffer(vertexData->getIndexBuffer());
|
||||||
for (const auto& meshData : drawCall.instanceMeshData) {
|
for (const auto& meshData : drawCall.instanceMeshData) {
|
||||||
@@ -252,7 +250,7 @@ void BasePass::render() {
|
|||||||
{
|
{
|
||||||
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
|
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
|
||||||
skyboxCommand->setViewport(viewport);
|
skyboxCommand->setViewport(viewport);
|
||||||
skyboxCommand->bindPipeline(pipeline);
|
skyboxCommand->bindPipeline(skyboxPipeline);
|
||||||
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
|
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
|
||||||
skyboxCommand->draw(36, 1, 0, 0);
|
skyboxCommand->draw(36, 1, 0, 0);
|
||||||
graphics->executeCommands(std::move(skyboxCommand));
|
graphics->executeCommands(std::move(skyboxCommand));
|
||||||
@@ -623,6 +621,6 @@ void BasePass::createRenderPass() {
|
|||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
skyboxPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "MinimalEngine.h"
|
#include "MinimalEngine.h"
|
||||||
#include "RenderPass.h"
|
#include "RenderPass.h"
|
||||||
#include "WaterRenderer.h"
|
#include "WaterRenderer.h"
|
||||||
#include "TerrainRenderer.h"
|
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
DECLARE_REF(CameraActor)
|
DECLARE_REF(CameraActor)
|
||||||
@@ -56,7 +55,7 @@ class BasePass : public RenderPass {
|
|||||||
Gfx::PShaderBuffer cullingBuffer;
|
Gfx::PShaderBuffer cullingBuffer;
|
||||||
|
|
||||||
//OWaterRenderer waterRenderer;
|
//OWaterRenderer waterRenderer;
|
||||||
OTerrainRenderer terrainRenderer;
|
//OTerrainRenderer terrainRenderer;
|
||||||
|
|
||||||
// Debug rendering
|
// Debug rendering
|
||||||
Gfx::OVertexInput debugVertexInput;
|
Gfx::OVertexInput debugVertexInput;
|
||||||
@@ -74,7 +73,7 @@ class BasePass : public RenderPass {
|
|||||||
Gfx::OVertexShader vertexShader;
|
Gfx::OVertexShader vertexShader;
|
||||||
Gfx::OFragmentShader fragmentShader;
|
Gfx::OFragmentShader fragmentShader;
|
||||||
Gfx::OPipelineLayout pipelineLayout;
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
Gfx::PGraphicsPipeline pipeline;
|
Gfx::PGraphicsPipeline skyboxPipeline;
|
||||||
Gfx::OSampler skyboxSampler;
|
Gfx::OSampler skyboxSampler;
|
||||||
struct SkyboxData {
|
struct SkyboxData {
|
||||||
Matrix4 transformMatrix;
|
Matrix4 transformMatrix;
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ target_sources(Engine
|
|||||||
RenderGraphResources.cpp
|
RenderGraphResources.cpp
|
||||||
RenderPass.h
|
RenderPass.h
|
||||||
RenderPass.cpp
|
RenderPass.cpp
|
||||||
TerrainRenderer.h
|
#TerrainRenderer.h
|
||||||
TerrainRenderer.cpp
|
#TerrainRenderer.cpp
|
||||||
ToneMappingPass.h
|
ToneMappingPass.h
|
||||||
ToneMappingPass.cpp
|
ToneMappingPass.cpp
|
||||||
UIPass.h
|
UIPass.h
|
||||||
@@ -38,6 +38,6 @@ target_sources(Engine
|
|||||||
RenderGraph.h
|
RenderGraph.h
|
||||||
RenderGraphResources.h
|
RenderGraphResources.h
|
||||||
RenderPass.h
|
RenderPass.h
|
||||||
TerrainRenderer.h
|
#TerrainRenderer.h
|
||||||
UIPass.h
|
UIPass.h
|
||||||
VisibilityPass.h)
|
VisibilityPass.h)
|
||||||
@@ -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),
|
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
|
||||||
&offsets);
|
&offsets);
|
||||||
if (graphics->supportMeshShading()) {
|
if (graphics->supportMeshShading()) {
|
||||||
command->drawMesh(vertexData->getNumInstances(), 1, 1);
|
command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1);
|
||||||
} else {
|
} else {
|
||||||
const auto& materials = vertexData->getMaterialData();
|
const auto& materials = vertexData->getMaterialData();
|
||||||
for (const auto& materialData : materials) {
|
for (const auto& materialData : materials) {
|
||||||
|
|||||||
@@ -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),
|
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
|
||||||
&offsets);
|
&offsets);
|
||||||
if (graphics->supportMeshShading()) {
|
if (graphics->supportMeshShading()) {
|
||||||
command->drawMesh(vertexData->getNumInstances(), 1, 1);
|
command->drawMesh((uint32)vertexData->getNumInstances(), 1, 1);
|
||||||
} else {
|
} else {
|
||||||
const auto& materials = vertexData->getMaterialData();
|
const auto& materials = vertexData->getMaterialData();
|
||||||
for (const auto& materialData : materials) {
|
for (const auto& materialData : materials) {
|
||||||
|
|||||||
@@ -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,
|
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::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
|
|
||||||
Gfx::PDescriptorSet dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
dispatchParamsSet = dispatchParamsLayout->allocateDescriptorSet();
|
||||||
dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups);
|
dispatchParamsSet->updateConstants("numThreadGroups", 0, &numThreadGroups);
|
||||||
dispatchParamsSet->updateConstants("numThreads", 0, &numThreads);
|
dispatchParamsSet->updateConstants("numThreads", 0, &numThreads);
|
||||||
dispatchParamsSet->updateBuffer(FRUSTUMBUFFER_NAME, 0, frustumBuffer);
|
dispatchParamsSet->updateBuffer(FRUSTUMBUFFER_NAME, 0, frustumBuffer);
|
||||||
@@ -293,7 +293,4 @@ void LightCullingPass::setupFrustums() {
|
|||||||
graphics->executeCommands(std::move(commands));
|
graphics->executeCommands(std::move(commands));
|
||||||
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
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);
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
Frustum* frustums = (Frustum*)frustumBuffer->map();
|
|
||||||
graphics->waitDeviceIdle();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ TerrainRenderer::TerrainRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDe
|
|||||||
plainMesh.gpuCBT.bufferCount = 2;
|
plainMesh.gpuCBT.bufferCount = 2;
|
||||||
for (uint32 i = 0; i < 2; ++i) {
|
for (uint32 i = 0; i < 2; ++i) {
|
||||||
uint32 bufferSize = cbt.bufferSize(i);
|
uint32 bufferSize = cbt.bufferSize(i);
|
||||||
uint32 elementSize = cbt.elementSize(i);
|
//uint32 elementSize = cbt.elementSize(i);
|
||||||
plainMesh.gpuCBT.bufferArray[i] = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
plainMesh.gpuCBT.bufferArray[i] = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData =
|
.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,
|
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_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector);
|
//uint32 indexBufferSize = cpuMesh.totalNumElements * sizeof(UVector);
|
||||||
Array<uint32> indices;
|
Array<uint32> indices;
|
||||||
for (uint32 i = 0; i < cpuMesh.totalNumElements * 3; ++i)
|
for (uint32 i = 0; i < cpuMesh.totalNumElements * 3; ++i)
|
||||||
indices.add(i);
|
indices.add(i);
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ void UIPass::beginFrame(const Component::Camera& cam) {
|
|||||||
float x = render.position.x;
|
float x = render.position.x;
|
||||||
float y = render.position.y;
|
float y = render.position.y;
|
||||||
//todo: convert using actual tree depth
|
//todo: convert using actual tree depth
|
||||||
uint32 textureIndex = -1ul;
|
uint32 textureIndex = std::numeric_limits<uint32>::max();
|
||||||
if (render.backgroundTexture != nullptr) {
|
if (render.backgroundTexture != nullptr) {
|
||||||
textureIndex = usedTextures.size();
|
textureIndex = (uint32)usedTextures.size();
|
||||||
usedTextures.add(render.backgroundTexture);
|
usedTextures.add(render.backgroundTexture);
|
||||||
}
|
}
|
||||||
elements.add(RenderElementStyle{
|
elements.add(RenderElementStyle{
|
||||||
@@ -112,7 +112,7 @@ void UIPass::render() {
|
|||||||
command->setViewport(viewport);
|
command->setViewport(viewport);
|
||||||
command->bindPipeline(uiPipeline);
|
command->bindPipeline(uiPipeline);
|
||||||
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
|
command->bindDescriptor({viewParamsSet, uiDescriptorSet});
|
||||||
command->draw(4, elements.size(), 0, 0);
|
command->draw(4, (uint32)elements.size(), 0, 0);
|
||||||
commands.add(std::move(command));
|
commands.add(std::move(command));
|
||||||
graphics->executeCommands(std::move(commands));
|
graphics->executeCommands(std::move(commands));
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class UIPass : public RenderPass {
|
|||||||
Vector color;
|
Vector color;
|
||||||
float opacity = 1;
|
float opacity = 1;
|
||||||
float z = 0;
|
float z = 0;
|
||||||
uint32 textureIndex = -1ul;
|
uint32 textureIndex = std::numeric_limits<uint32>::max();
|
||||||
uint32 pad0;
|
uint32 pad0;
|
||||||
uint32 pad1;
|
uint32 pad1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ void StaticMeshVertexData::updateBuffers() {
|
|||||||
descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents);
|
descriptorSet->updateBuffer(TANGENTS_NAME, 0, tangents);
|
||||||
descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
|
descriptorSet->updateBuffer(BITANGENTS_NAME, 0, biTangents);
|
||||||
descriptorSet->updateBuffer(COLORS_NAME, 0, colors);
|
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->updateBuffer(TEXCOORDS_NAME, i, texCoords[i]);
|
||||||
}
|
}
|
||||||
descriptorSet->writeChanges();
|
descriptorSet->writeChanges();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include "VertexData.h"
|
#include "VertexData.h"
|
||||||
#include "entt/entt.hpp"
|
#include "entt/entt.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
class StaticMeshVertexData : public VertexData {
|
class StaticMeshVertexData : public VertexData {
|
||||||
public:
|
public:
|
||||||
@@ -39,7 +38,6 @@ class StaticMeshVertexData : public VertexData {
|
|||||||
virtual void resizeBuffers() override;
|
virtual void resizeBuffers() override;
|
||||||
virtual void updateBuffers() override;
|
virtual void updateBuffers() override;
|
||||||
|
|
||||||
|
|
||||||
Gfx::OShaderBuffer positions;
|
Gfx::OShaderBuffer positions;
|
||||||
constexpr static const char* POSITIONS_NAME = "positions";
|
constexpr static const char* POSITIONS_NAME = "positions";
|
||||||
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
|
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
|
||||||
@@ -52,7 +50,7 @@ class StaticMeshVertexData : public VertexData {
|
|||||||
constexpr static const char* BITANGENTS_NAME = "biTangents";
|
constexpr static const char* BITANGENTS_NAME = "biTangents";
|
||||||
Gfx::OShaderBuffer colors;
|
Gfx::OShaderBuffer colors;
|
||||||
constexpr static const char* COLORS_NAME = "colors";
|
constexpr static const char* COLORS_NAME = "colors";
|
||||||
Array<PositionType> posData;
|
Array<PositionType> posData{debug_resource::get("VertexPositions")};
|
||||||
Array<TexCoordType> texData[MAX_TEXCOORDS];
|
Array<TexCoordType> texData[MAX_TEXCOORDS];
|
||||||
Array<NormalType> norData;
|
Array<NormalType> norData;
|
||||||
Array<TangentType> tanData;
|
Array<TangentType> tanData;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ void VertexData::createDescriptors() {
|
|||||||
Array<uint32> cullingOffsets;
|
Array<uint32> cullingOffsets;
|
||||||
for (auto& mat : materialData) {
|
for (auto& mat : materialData) {
|
||||||
for (auto& instance : mat.instances) {
|
for (auto& instance : mat.instances) {
|
||||||
instance.offsets.instanceOffset = instanceData.size();
|
instance.offsets.instanceOffset = (uint32)instanceData.size();
|
||||||
MaterialOffsets offsets = instance.materialInstance->getMaterialOffsets();
|
MaterialOffsets offsets = instance.materialInstance->getMaterialOffsets();
|
||||||
instance.offsets.textureOffset = offsets.textureOffset;
|
instance.offsets.textureOffset = offsets.textureOffset;
|
||||||
instance.offsets.samplerOffset = offsets.samplerOffset;
|
instance.offsets.samplerOffset = offsets.samplerOffset;
|
||||||
@@ -104,7 +104,7 @@ void VertexData::createDescriptors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (uint32 i = 0; i < transparentData.size(); ++i) {
|
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);
|
cullingOffsets.add(transparentData[i].cullingOffset);
|
||||||
instanceData.add(transparentData[i].instanceData);
|
instanceData.add(transparentData[i].instanceData);
|
||||||
instanceMeshData.add(transparentData[i].meshData);
|
instanceMeshData.add(transparentData[i].meshData);
|
||||||
@@ -139,17 +139,17 @@ void VertexData::createDescriptors() {
|
|||||||
void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet> loadedMeshlets) {
|
void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet> loadedMeshlets) {
|
||||||
std::unique_lock l(vertexDataLock);
|
std::unique_lock l(vertexDataLock);
|
||||||
for (auto&& chunk : loadedMeshlets | std::views::chunk(2048)) {
|
for (auto&& chunk : loadedMeshlets | std::views::chunk(2048)) {
|
||||||
uint32 meshletOffset = meshlets.size();
|
uint32 meshletOffset = (uint32)meshlets.size();
|
||||||
AABB meshAABB;
|
AABB meshAABB;
|
||||||
uint32 numMeshlets = 0;
|
uint32 numMeshlets = 0;
|
||||||
for (auto&& m : chunk) {
|
for (auto&& m : chunk) {
|
||||||
numMeshlets++;
|
numMeshlets++;
|
||||||
//...
|
//...
|
||||||
meshAABB = meshAABB.combine(m.boundingBox);
|
meshAABB = meshAABB.combine(m.boundingBox);
|
||||||
uint32 vertexOffset = vertexIndices.size();
|
uint32 vertexOffset = (uint32)vertexIndices.size();
|
||||||
vertexIndices.resize(vertexOffset + m.numVertices);
|
vertexIndices.resize(vertexOffset + m.numVertices);
|
||||||
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
|
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));
|
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
||||||
meshlets.add(MeshletDescription{
|
meshlets.add(MeshletDescription{
|
||||||
@@ -349,7 +349,7 @@ void VertexData::destroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 VertexData::addCullingMapping(MeshId id) {
|
uint32 VertexData::addCullingMapping(MeshId id) {
|
||||||
uint32 result = meshletCount;
|
uint32 result = (uint32)meshletCount;
|
||||||
for (const auto& md : getMeshData(id)) {
|
for (const auto& md : getMeshData(id)) {
|
||||||
meshletCount += md.numMeshlets;
|
meshletCount += md.numMeshlets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "Meshlet.h"
|
#include "Meshlet.h"
|
||||||
#include <entt/entt.hpp>
|
#include <entt/entt.hpp>
|
||||||
|
|
||||||
constexpr uint64 MAX_TEXCOORDS = 8;
|
constexpr uint32 MAX_TEXCOORDS = 8;
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
DECLARE_REF(MaterialInstance)
|
DECLARE_REF(MaterialInstance)
|
||||||
@@ -77,10 +77,8 @@ class VertexData {
|
|||||||
const Array<TransparentDraw>& getTransparentData() const { return transparentData; }
|
const Array<TransparentDraw>& getTransparentData() const { return transparentData; }
|
||||||
const Array<Gfx::PBottomLevelAS>& getRayTracingData() const { return rayTracingScene; }
|
const Array<Gfx::PBottomLevelAS>& getRayTracingData() const { return rayTracingScene; }
|
||||||
const Array<MeshData>& getMeshData(MeshId id) const { return meshData[id]; }
|
const Array<MeshData>& getMeshData(MeshId id) const { return meshData[id]; }
|
||||||
void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) {
|
void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { dataToBuild.add(blas); }
|
||||||
dataToBuild.add(blas);
|
uint32 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
|
||||||
}
|
|
||||||
uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; }
|
|
||||||
uint64 getNumInstances() const { return instanceData.size(); }
|
uint64 getNumInstances() const { return instanceData.size(); }
|
||||||
static List<VertexData*> getList();
|
static List<VertexData*> getList();
|
||||||
static VertexData* findByTypeName(std::string name);
|
static VertexData* findByTypeName(std::string name);
|
||||||
@@ -110,6 +108,7 @@ class VertexData {
|
|||||||
uint32 indicesOffset = 0;
|
uint32 indicesOffset = 0;
|
||||||
};
|
};
|
||||||
std::mutex materialDataLock;
|
std::mutex materialDataLock;
|
||||||
|
debug_resource vertexDataResource = {"VertexData"};
|
||||||
Array<MaterialData> materialData;
|
Array<MaterialData> materialData;
|
||||||
Array<TransparentDraw> transparentData;
|
Array<TransparentDraw> transparentData;
|
||||||
|
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ void DescriptorLayout::create() {
|
|||||||
constantsSize += gfxBinding.uniformLength;
|
constantsSize += gfxBinding.uniformLength;
|
||||||
constantsStages |= gfxBinding.shaderStages;
|
constantsStages |= gfxBinding.shaderStages;
|
||||||
} else {
|
} else {
|
||||||
mappings[gfxBinding.name] = {
|
mappings[gfxBinding.name] = DescriptorMapping{
|
||||||
.binding = (uint32)bindings.size(),
|
.binding = (uint32)bindings.size(),
|
||||||
.type = cast(gfxBinding.descriptorType),
|
.type = cast(gfxBinding.descriptorType),
|
||||||
};
|
};
|
||||||
bindings.add({
|
bindings.add(VkDescriptorSetLayoutBinding{
|
||||||
.binding = (uint32)bindings.size(),
|
.binding = (uint32)bindings.size(),
|
||||||
.descriptorType = cast(gfxBinding.descriptorType),
|
.descriptorType = cast(gfxBinding.descriptorType),
|
||||||
.descriptorCount = gfxBinding.descriptorCount,
|
.descriptorCount = gfxBinding.descriptorCount,
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std:
|
|||||||
return new PipelineStatisticsQuery(this, name);
|
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);
|
return new TimestampQuery(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,9 +457,6 @@ void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>
|
|||||||
// For the sake of simplicity we won't stage the vertex data to the GPU memory
|
// 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
|
// 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 = {
|
VkBufferCreateInfo transformBufferInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -593,7 +590,7 @@ void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>
|
|||||||
}
|
}
|
||||||
|
|
||||||
PCommand cmd = graphicsCommands->getCommands();
|
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));
|
cmd->bindResource(PBufferAllocation(transformBuffer));
|
||||||
destructionManager->queueResourceForDestruction(std::move(transformBuffer));
|
destructionManager->queueResourceForDestruction(std::move(transformBuffer));
|
||||||
for (auto& scratchAlloc : scratchBuffers) {
|
for (auto& scratchAlloc : scratchBuffers) {
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
|||||||
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
|
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
|
||||||
if (hitgroup.anyHitShader != nullptr) {
|
if (hitgroup.anyHitShader != nullptr) {
|
||||||
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
|
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
|
||||||
anyHitIndex = shaderStages.size();
|
anyHitIndex = (uint32)shaderStages.size();
|
||||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -521,7 +521,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
|||||||
}
|
}
|
||||||
if (hitgroup.intersectionShader != nullptr) {
|
if (hitgroup.intersectionShader != nullptr) {
|
||||||
auto intersect = hitgroup.intersectionShader.cast<IntersectionShader>();
|
auto intersect = hitgroup.intersectionShader.cast<IntersectionShader>();
|
||||||
intersectionIndex = shaderGroups.size();
|
intersectionIndex = (uint32)shaderGroups.size();
|
||||||
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
shaderStages.add(VkPipelineShaderStageCreateInfo{
|
||||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
.pNext = nullptr,
|
.pNext = nullptr,
|
||||||
@@ -674,7 +674,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
|
|||||||
Gfx::QueueType::GRAPHICS, sbtAlignment);
|
Gfx::QueueType::GRAPHICS, sbtAlignment);
|
||||||
|
|
||||||
Array<uint8> sbt(sbtSize);
|
Array<uint8> 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;
|
uint64 sbtOffset = 0;
|
||||||
Array<uint8> rayGenSbt(rayGenStride);
|
Array<uint8> rayGenSbt(rayGenStride);
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ TopLevelAS::TopLevelAS(PGraphics graphics, const Gfx::TopLevelASCreateInfo& crea
|
|||||||
.pGeometries = &geometry,
|
.pGeometries = &geometry,
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32 primitiveCount = instances.size();
|
const uint32 primitiveCount = (uint32)instances.size();
|
||||||
|
|
||||||
VkAccelerationStructureBuildSizesInfoKHR buildSizesInfo = {
|
VkAccelerationStructureBuildSizesInfoKHR buildSizesInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
|||||||
};
|
};
|
||||||
|
|
||||||
sessionDesc.compilerOptionEntries = option.data();
|
sessionDesc.compilerOptionEntries = option.data();
|
||||||
sessionDesc.compilerOptionEntryCount = option.size();
|
sessionDesc.compilerOptionEntryCount = (uint32)option.size();
|
||||||
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
|
sessionDesc.defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR;
|
||||||
Array<slang::PreprocessorMacroDesc> macros;
|
Array<slang::PreprocessorMacroDesc> macros;
|
||||||
for (const auto& [key, val] : info.defines) {
|
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());
|
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
|
||||||
CHECK_DIAGNOSTICS();
|
CHECK_DIAGNOSTICS();
|
||||||
std::cout << info.name << std::endl;
|
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);
|
auto param = signature->getParameterByIndex(i);
|
||||||
layout->addMapping(param->getName(), param->getBindingIndex());
|
layout->addMapping(param->getName(), param->getBindingIndex());
|
||||||
//std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
|
//std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
|
||||||
|
|||||||
@@ -99,21 +99,21 @@ void Material::updateFloatData(uint32 offset, uint32 numFloats, float* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32 Material::addTextures(uint32 numTextures) {
|
uint32 Material::addTextures(uint32 numTextures) {
|
||||||
uint32 textureOffset = textures.size();
|
uint32 textureOffset = (uint32)textures.size();
|
||||||
textures.resize(textures.size() + numTextures);
|
textures.resize(textures.size() + numTextures);
|
||||||
assert(textures.size() < 512);
|
assert(textures.size() < 512);
|
||||||
return textureOffset;
|
return textureOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Material::addSamplers(uint32 numSamplers) {
|
uint32 Material::addSamplers(uint32 numSamplers) {
|
||||||
uint32 samplerOffset = samplers.size();
|
uint32 samplerOffset = (uint32)samplers.size();
|
||||||
samplers.resize(samplers.size() + numSamplers);
|
samplers.resize(samplers.size() + numSamplers);
|
||||||
assert(textures.size() < 512);
|
assert(textures.size() < 512);
|
||||||
return samplerOffset;
|
return samplerOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Material::addFloats(uint32 numFloats) {
|
uint32 Material::addFloats(uint32 numFloats) {
|
||||||
uint32 floatOffset = floatData.size();
|
uint32 floatOffset = (uint32)floatData.size();
|
||||||
floatData.resize(floatData.size() + numFloats);
|
floatData.resize(floatData.size() + numFloats);
|
||||||
return floatOffset;
|
return floatOffset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ FloatParameter::FloatParameter(std::string name, float data, uint32 index) : Sha
|
|||||||
|
|
||||||
FloatParameter::~FloatParameter() {}
|
FloatParameter::~FloatParameter() {}
|
||||||
|
|
||||||
void FloatParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) {
|
void FloatParameter::updateDescriptorSet(uint32, uint32, uint32 floatOffset) {
|
||||||
Material::updateFloatData(floatOffset + index, 1, &data);
|
Material::updateFloatData(floatOffset + index, 1, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ VectorParameter::VectorParameter(std::string name, Vector data, uint32 index)
|
|||||||
|
|
||||||
VectorParameter::~VectorParameter() {}
|
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);
|
Material::updateFloatData(floatOffset + index, 3, (float*) & data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ TextureParameter::TextureParameter(std::string name, PTextureAsset asset, uint32
|
|||||||
|
|
||||||
TextureParameter::~TextureParameter() {}
|
TextureParameter::~TextureParameter() {}
|
||||||
|
|
||||||
void TextureParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) {
|
void TextureParameter::updateDescriptorSet(uint32 textureOffset, uint32, uint32) {
|
||||||
Material::updateTexture(textureOffset + index, data->getTexture());
|
Material::updateTexture(textureOffset + index, data->getTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ SamplerParameter::SamplerParameter(std::string name, Gfx::OSampler sampler, uint
|
|||||||
|
|
||||||
SamplerParameter::~SamplerParameter() {}
|
SamplerParameter::~SamplerParameter() {}
|
||||||
|
|
||||||
void SamplerParameter::updateDescriptorSet(uint32 textureOffset, uint32 samplerOffset, uint32 floatOffset) {
|
void SamplerParameter::updateDescriptorSet(uint32, uint32 samplerOffset, uint32) {
|
||||||
Material::updateSampler(samplerOffset + index, data);
|
Material::updateSampler(samplerOffset + index, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,9 +183,9 @@ CombinedTextureParameter::CombinedTextureParameter(std::string name, PTextureAss
|
|||||||
|
|
||||||
CombinedTextureParameter::~CombinedTextureParameter() {}
|
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<std::string, std::string>& varState) const { return ""; }
|
std::string CombinedTextureParameter::evaluate(Map<std::string, std::string>&) const { return ""; }
|
||||||
|
|
||||||
void CombinedTextureParameter::save(ArchiveBuffer& buffer) const {
|
void CombinedTextureParameter::save(ArchiveBuffer& buffer) const {
|
||||||
ShaderParameter::save(buffer);
|
ShaderParameter::save(buffer);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ void BVH::reinsertCollider(entt::entity entity, AABB aabb) {
|
|||||||
|
|
||||||
void BVH::removeCollider(entt::entity entity) {
|
void BVH::removeCollider(entt::entity entity) {
|
||||||
int32 nodeIndex = -1;
|
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) {
|
if (dynamicNodes[i].isLeaf && dynamicNodes[i].owner == entity) {
|
||||||
nodeIndex = i;
|
nodeIndex = i;
|
||||||
break;
|
break;
|
||||||
@@ -275,7 +275,7 @@ int32 BVH::splitNode(Array<AABBCenter> aabbs) {
|
|||||||
}
|
}
|
||||||
struct {
|
struct {
|
||||||
bool operator()(const AABBCenter& lhs, const AABBCenter& rhs) { return lhs.center[longestAxis] < rhs.center[longestAxis]; }
|
bool operator()(const AABBCenter& lhs, const AABBCenter& rhs) { return lhs.center[longestAxis] < rhs.center[longestAxis]; }
|
||||||
int32 longestAxis;
|
int32 longestAxis = 0;
|
||||||
} compare = {longestAxis};
|
} compare = {longestAxis};
|
||||||
|
|
||||||
std::sort(aabbs.begin(), aabbs.end(), compare);
|
std::sort(aabbs.begin(), aabbs.end(), compare);
|
||||||
@@ -291,7 +291,7 @@ int32 BVH::splitNode(Array<AABBCenter> aabbs) {
|
|||||||
return rootIndex;
|
return rootIndex;
|
||||||
}
|
}
|
||||||
int32 BVH::allocateNode() {
|
int32 BVH::allocateNode() {
|
||||||
for (size_t i = 0; i < dynamicNodes.size(); i++) {
|
for (uint32 i = 0; i < dynamicNodes.size(); i++) {
|
||||||
if (!dynamicNodes[i].isValid) {
|
if (!dynamicNodes[i].isValid) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ void BVH::validateBVH() const {
|
|||||||
if (dynamicRoot != -1) {
|
if (dynamicRoot != -1) {
|
||||||
assert(dynamicNodes[dynamicRoot].parentIndex == -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;
|
int32 nodeIdx = i;
|
||||||
size_t counter = dynamicNodes.size();
|
size_t counter = dynamicNodes.size();
|
||||||
if (!dynamicNodes[nodeIdx].isValid)
|
if (!dynamicNodes[nodeIdx].isValid)
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ void PhysicsSystem::writeRigidBody(const Body& body) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<PhysicsSystem::Body> PhysicsSystem::integratePhysics(const Array<Body>& bodies, const float t0, const float tdelta) const {
|
Array<PhysicsSystem::Body> PhysicsSystem::integratePhysics(const Array<Body>& bodies, const float, const float) const {
|
||||||
Array<Body> result;
|
Array<Body> result;
|
||||||
Array<float> buffer;
|
Array<float> buffer;
|
||||||
result.resize(bodies.size());
|
result.resize(bodies.size());
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ void LightEnvironment::commit() {
|
|||||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
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_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
|
||||||
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
uint32 numPointLights = points.size();
|
uint32 numPointLights = (uint32)points.size();
|
||||||
uint32 numDirectionalLights = dirs.size();
|
uint32 numDirectionalLights = (uint32)dirs.size();
|
||||||
set->updateConstants("numPointLights", 0, &numPointLights);
|
set->updateConstants("numPointLights", 0, &numPointLights);
|
||||||
set->updateBuffer("pointLights", 0, pointLights);
|
set->updateBuffer("pointLights", 0, pointLights);
|
||||||
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
|
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
|
||||||
|
|||||||
@@ -17,12 +17,6 @@ Scene::Scene(Gfx::PGraphics graphics) : graphics(graphics), lightEnv(new LightEn
|
|||||||
|
|
||||||
Scene::~Scene() {}
|
Scene::~Scene() {}
|
||||||
|
|
||||||
void Scene::bakeLighting() {
|
void Scene::bakeLighting() {}
|
||||||
const auto& matData = StaticMeshVertexData::getInstance()->getMaterialData();
|
|
||||||
for (const auto& mat : matData)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::update(float deltaTime) { physics.update(deltaTime); }
|
void Scene::update(float deltaTime) { physics.update(deltaTime); }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ MeshUpdater::MeshUpdater(PScene scene) : ComponentSystem<Component::Transform, C
|
|||||||
|
|
||||||
MeshUpdater::~MeshUpdater() {}
|
MeshUpdater::~MeshUpdater() {}
|
||||||
|
|
||||||
void MeshUpdater::update(entt::entity id, Component::Transform& transform, Component::Mesh& comp) {
|
void MeshUpdater::update(entt::entity, Component::Transform& transform, Component::Mesh& comp) {
|
||||||
if (comp.meshletOffsets.empty()) {
|
if (comp.meshletOffsets.empty()) {
|
||||||
for (uint32 i = 0; i < comp.asset->meshes.size(); ++i) {
|
for (uint32 i = 0; i < comp.asset->meshes.size(); ++i) {
|
||||||
comp.meshletOffsets.add(comp.asset->meshes[i]->vertexData->addCullingMapping(comp.asset->meshes[i]->id));
|
comp.meshletOffsets.add(comp.asset->meshes[i]->vertexData->addCullingMapping(comp.asset->meshes[i]->id));
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ class Element {
|
|||||||
// calculates the relative positions of the child elements for the applied layout style
|
// calculates the relative positions of the child elements for the applied layout style
|
||||||
virtual void layout(UVector2 parentSize) {
|
virtual void layout(UVector2 parentSize) {
|
||||||
if (style.maxWidthType == DimensionType::Auto) {
|
if (style.maxWidthType == DimensionType::Auto) {
|
||||||
maxDimensions.x = parentSize.x;
|
maxDimensions.x = (float)parentSize.x;
|
||||||
}
|
}
|
||||||
if (style.maxHeightType == DimensionType::Auto) {
|
if (style.maxHeightType == DimensionType::Auto) {
|
||||||
maxDimensions.y = parentSize.y;
|
maxDimensions.y = (float)parentSize.y;
|
||||||
}
|
}
|
||||||
if (style.widthType == DimensionType::Pixel) {
|
if (style.widthType == DimensionType::Pixel) {
|
||||||
dimensions.x = style.width;
|
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,
|
// 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
|
// 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) {
|
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;
|
cursor.y += lineHeight;
|
||||||
lineHeight = 0;
|
lineHeight = 0;
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ class Element {
|
|||||||
if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) {
|
if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) {
|
||||||
// create a new line in case we are not already at one
|
// create a new line in case we are not already at one
|
||||||
if (cursor.x != 0) {
|
if (cursor.x != 0) {
|
||||||
cursor.x = style.paddingLeft;
|
cursor.x = (float)style.paddingLeft;
|
||||||
cursor.y += lineHeight;
|
cursor.y += lineHeight;
|
||||||
}
|
}
|
||||||
child->position.x = cursor.x + child->style.marginLeft;
|
child->position.x = cursor.x + child->style.marginLeft;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ template <StyleClass... classes> class Text : public Element {
|
|||||||
style.outerDisplay = OuterDisplayType::Inline;
|
style.outerDisplay = OuterDisplayType::Inline;
|
||||||
(classes::apply(style), ...);
|
(classes::apply(style), ...);
|
||||||
}
|
}
|
||||||
virtual void layout(UVector2 parentSize) override {
|
virtual void layout(UVector2) override {
|
||||||
UVector2 cursor = UVector2(0);
|
UVector2 cursor = UVector2(0);
|
||||||
dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders);
|
dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -67,24 +67,24 @@ using BG_Red = BackgroundColorClass<Vector(1, 0, 0)>;
|
|||||||
|
|
||||||
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
|
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
|
||||||
static void apply(UI::Style& s) {
|
static void apply(UI::Style& s) {
|
||||||
if (ml != -1)
|
if constexpr (ml != -1)
|
||||||
s.marginLeft = ml;
|
s.marginLeft = ml;
|
||||||
if (mr != -1)
|
if constexpr (mr != -1)
|
||||||
s.marginRight = mr;
|
s.marginRight = mr;
|
||||||
if (mt != -1)
|
if constexpr (mt != -1)
|
||||||
s.marginTop = mt;
|
s.marginTop = mt;
|
||||||
if (mb != -1)
|
if constexpr (mb != -1)
|
||||||
s.marginBottom = mb;
|
s.marginBottom = mb;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#define DECLARE_MARGIN_CLASSES(x) \
|
#define DECLARE_MARGIN_CLASSES(x) \
|
||||||
using M_##x = MarginClass<x, x, x, x>; \
|
using M_##x = MarginClass<x, x, x, x>; \
|
||||||
using M_X##x = MarginClass<x, x, -1u, -1u>; \
|
using M_X##x = MarginClass<x, x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||||
using M_Y##x = MarginClass<-1u, -1u, x, x>; \
|
using M_Y##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, x>; \
|
||||||
using M_L##x = MarginClass<x, -1u, -1u, -1u>; \
|
using M_L##x = MarginClass<x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||||
using M_R##x = MarginClass<-1u, x, -1u, -1u>; \
|
using M_R##x = MarginClass<std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||||
using M_T##x = MarginClass<-1u, -1u, x, -1u>; \
|
using M_T##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max()>; \
|
||||||
using M_B##x = MarginClass<-1u, -1u, -1u, x>;
|
using M_B##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x>;
|
||||||
|
|
||||||
DECLARE_MARGIN_CLASSES(0)
|
DECLARE_MARGIN_CLASSES(0)
|
||||||
DECLARE_MARGIN_CLASSES(1)
|
DECLARE_MARGIN_CLASSES(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user