Adding basic memory resource

This commit is contained in:
Dynamitos
2025-03-20 20:15:38 +01:00
parent 51d759639e
commit e7ba74e258
47 changed files with 398 additions and 300 deletions
+1 -1
View File
@@ -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()
+63 -63
View File
@@ -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"
}
]
}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "Placeholder",
"params": {
},
"code": [
{
"exp": "BRDF",
"profile": "BlinnPhong",
"values": {
"baseColor": "float3(0, 1, 0)",
"normal": "float3(0, 0, 1)"
}
}
]
}
+2 -2
View File
@@ -36,7 +36,7 @@ int main(int, char**) {
Array<Vector> 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<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[1] = mesh->mFaces[faceIndex].mIndices[1];
tris[faceIndex].p[2] = mesh->mFaces[faceIndex].mIndices[2];
+1 -1
View File
@@ -516,7 +516,7 @@ Vector4 MeshLoader::encodeQTangent(Matrix3 m) {
void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialInstanceAsset>& materials, Array<OMesh>& globalMeshes,
Component::Collider& collider) {
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];
if (!(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE))
continue;
+1 -1
View File
@@ -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) {}
+3 -2
View File
@@ -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();
}
}
+8 -8
View File
@@ -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<RenderGlyph>& 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, Array<Rend
Vector2 cursor = Vector2(0);
for (uint32 i = 0; i < num_glyphs; ++i) {
hb_codepoint_t glyphid = glyphs[i].codepoint;
float xOffset = positions[i].x_offset * fontSize / xppem;
float yOffset = positions[i].y_offset * fontSize / yppem;
float xAdvance = positions[i].x_advance * fontSize / xppem;
float yAdvance = positions[i].y_advance * fontSize / yppem;
float xOffset = (float)positions[i].x_offset * fontSize / xppem;
float yOffset = (float)positions[i].y_offset * fontSize / yppem;
float xAdvance = (float)positions[i].x_advance * fontSize / xppem;
float yAdvance = (float)positions[i].y_advance * fontSize / yppem;
Vector2 position = cursor + Vector2(xOffset, yOffset);
Vector2 dimensions = fontSizes[fontSize].glyphs[glyphid].size;
render.add(RenderGlyph{
@@ -73,7 +73,7 @@ UVector2 FontAsset::shapeText(std::string_view view, uint32 fontSize, Array<Rend
void FontAsset::loadGlyphs(uint32 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);
FontAsset::Glyph& glyph = fontSizes[fontSize].glyphs[i];
glyph.size = IVector2(ft_face->glyph->bitmap.width, ft_face->glyph->bitmap.rows);
+2 -2
View File
@@ -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&) { }
+19 -17
View File
@@ -1,6 +1,7 @@
#pragma once
#include "EngineTypes.h"
#include "Concepts.h"
#include "EngineTypes.h"
#include "MemoryResource.h"
#include <algorithm>
#include <assert.h>
#include <initializer_list>
@@ -12,7 +13,7 @@
#endif
namespace Seele {
template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> struct Array {
template <typename T> struct Array {
public:
template <typename X> class IteratorBase {
public:
@@ -67,7 +68,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
};
using value_type = T;
using allocator_type = Allocator;
using allocator_type = std::pmr::polymorphic_allocator<T>;
using size_type = std::size_t;
using difference_type = std::ptrdiff_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 const_reverse_iterator = std::reverse_iterator<const_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 <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> 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 <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> 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 <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
}
return *this;
}
Array& operator=(Array&& other) noexcept(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
std::allocator_traits<Allocator>::is_always_equal::value) {
Array& operator=(Array&& other) noexcept(std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
std::allocator_traits<allocator_type>::is_always_equal::value) {
if (this != &other) {
if (_data != nullptr) {
clear();
@@ -294,7 +292,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
requires std::predicate<Pred, value_type>
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 <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> 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 <typename Type> T& addInternal(Type&& t) noexcept {
if (arraySize == allocated) {
size_type newSize = arraySize + 1;
@@ -449,7 +451,7 @@ template <typename T, typename Allocator = std::pmr::polymorphic_allocator<T>> s
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()) {
return false;
}
@@ -461,7 +463,7 @@ template <class Type, class Alloc> constexpr bool operator==(const Array<Type, A
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());
}
+3
View File
@@ -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)
+3 -4
View File
@@ -5,12 +5,11 @@
#include "Tree.h"
#include <utility>
namespace Seele {
template <typename KeyType, typename PairType> struct _KeyFun {
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> {
using Super = Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocator>;
using key_type = Super::key_type;
@@ -35,8 +34,8 @@ struct Map : public Tree<K, Pair<K, V>, _KeyFun<K, Pair<K, V>>, Compare, Allocat
: Super(comp, alloc) {}
constexpr explicit Map(const Allocator& alloc) noexcept(noexcept(Compare())) : Super(alloc) {}
constexpr Map(std::initializer_list<Pair<K, V>> init) : Super(init) {}
constexpr mapped_type& operator[](const key_type& key) {
auto [it, inserted] = Super::insert(Pair<K, V>(key, V()));
constexpr mapped_type& operator[](const key_type& key) {
auto [it, _] = Super::insert(Pair<K, V>(key));
return it->value;
}
constexpr const mapped_type& operator[](const key_type& key) const { return Super::find(key)->value; }
+34
View File
@@ -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];
}
+39
View File
@@ -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
-8
View File
@@ -3,14 +3,6 @@
namespace Seele {
template <typename K, typename V> struct Pair {
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) {
return left.key < right.key || (!(right.key < left.key) && left.value < right.value);
}
+125 -93
View File
@@ -1,15 +1,21 @@
#pragma once
#include "Pair.h"
#include "Array.h"
#include "Pair.h"
#include <map>
#include <memory_resource>
#include <memory>
namespace Seele {
template <typename KeyType, typename NodeData, typename KeyFun, typename Compare, typename Allocator> 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 <typename KeyType, typename NodeData, typename KeyFun, typename Compare
using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
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 value_type = NodeData;
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 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 const_iterator = ConstIterator;
using reverse_iterator = std::reverse_iterator<iterator>;
@@ -212,12 +234,12 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
return iterator(it);
}
constexpr Pair<iterator, bool> insert(const NodeData& data) {
auto [r, inserted] = _insert(root, data);
const auto& [r, inserted] = _insert(root, data);
root = r;
return Pair<iterator, bool>(iterator(root), inserted);
}
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;
return Pair<iterator, bool>(iterator(root), inserted);
}
@@ -242,25 +264,20 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
}
constexpr Iterator calcBeginIterator() const {
Node* begin = root;
Array<Node*> 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<Node*> 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 <typename KeyType, typename NodeData, typename KeyFun, typename Compare
Node* rotateLeft(Node* x) {
Node* y = x->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 <class NodeDataType> Pair<Node*, bool> _insert(Node* r, NodeDataType&& data) {
markIteratorsDirty();
if (r == nullptr) {
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++;
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);
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))) {
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 <typename KeyType, typename NodeData, typename KeyFun, typename Compare
r = _splay(r->leftChild, key);
r->rightChild = temp->rightChild;
r->rightChild->parent = r;
}
std::allocator_traits<NodeAlloc>::destroy(alloc, temp);
alloc.deallocate(temp, 1);
@@ -346,13 +372,16 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
if (comp(key, keyFun(r->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 <typename KeyType, typename NodeData, typename KeyFun, typename Compare
if (comp(key, keyFun(r->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);
}
+2 -3
View File
@@ -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<Matrix3> 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);
+1 -1
View File
@@ -1,4 +1,4 @@
add_subdirectory(CBT/)
#add_subdirectory(CBT/)
target_sources(Engine
PRIVATE
+1 -1
View File
@@ -25,7 +25,7 @@ void buildAdjacency(const uint32 numVerts, const Array<uint32>& indices, Adjacen
triangleOffset += info.trianglesPerVertex[j];
}
uint32 numTriangles = indices.size() / 3;
uint32 numTriangles = (uint32)indices.size() / 3;
info.triangleData.resize(triangleOffset);
Array<uint32> offsets = info.indexBufferOffset;
for (uint32 k = 0; k < numTriangles; ++k) {
+5 -7
View File
@@ -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));
}
}
+2 -3
View File
@@ -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;
@@ -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)
@@ -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) {
@@ -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) {
@@ -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);
}
@@ -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<uint32> indices;
for (uint32 i = 0; i < cpuMesh.totalNumElements * 3; ++i)
indices.add(i);
+3 -3
View File
@@ -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<uint32>::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();
+1 -1
View File
@@ -42,7 +42,7 @@ class UIPass : public RenderPass {
Vector color;
float opacity = 1;
float z = 0;
uint32 textureIndex = -1ul;
uint32 textureIndex = std::numeric_limits<uint32>::max();
uint32 pad0;
uint32 pad1;
};
+1 -1
View File
@@ -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();
+1 -3
View File
@@ -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<PositionType> posData;
Array<PositionType> posData{debug_resource::get("VertexPositions")};
Array<TexCoordType> texData[MAX_TEXCOORDS];
Array<NormalType> norData;
Array<TangentType> tanData;
+6 -6
View File
@@ -90,7 +90,7 @@ void VertexData::createDescriptors() {
Array<uint32> 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<uint32> loadedIndices, Array<Meshlet> 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;
}
+4 -5
View File
@@ -8,7 +8,7 @@
#include "Meshlet.h"
#include <entt/entt.hpp>
constexpr uint64 MAX_TEXCOORDS = 8;
constexpr uint32 MAX_TEXCOORDS = 8;
namespace Seele {
DECLARE_REF(MaterialInstance)
@@ -77,10 +77,8 @@ class VertexData {
const Array<TransparentDraw>& getTransparentData() const { return transparentData; }
const Array<Gfx::PBottomLevelAS>& getRayTracingData() const { return rayTracingScene; }
const Array<MeshData>& 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<VertexData*> 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> materialData;
Array<TransparentDraw> transparentData;
+2 -2
View File
@@ -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,
+2 -5
View File
@@ -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<Gfx::PBottomLevelAS>
// 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<Gfx::PBottomLevelAS>
}
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) {
+3 -3
View File
@@ -508,7 +508,7 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
uint32 intersectionIndex = VK_SHADER_UNUSED_KHR;
if (hitgroup.anyHitShader != nullptr) {
auto anyHit = hitgroup.anyHitShader.cast<AnyHitShader>();
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<IntersectionShader>();
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<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;
Array<uint8> rayGenSbt(rayGenStride);
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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<slang::PreprocessorMacroDesc> 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;
+3 -3
View File
@@ -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;
}
+6 -6
View File
@@ -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<std::string, std::string>& varState) const { return ""; }
std::string CombinedTextureParameter::evaluate(Map<std::string, std::string>&) const { return ""; }
void CombinedTextureParameter::save(ArchiveBuffer& buffer) const {
ShaderParameter::save(buffer);
+4 -4
View File
@@ -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<AABBCenter> 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<AABBCenter> 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)
+1 -1
View File
@@ -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<float> buffer;
result.resize(bodies.size());
+2 -2
View File
@@ -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);
+1 -7
View File
@@ -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); }
+1 -1
View File
@@ -9,7 +9,7 @@ MeshUpdater::MeshUpdater(PScene scene) : ComponentSystem<Component::Transform, C
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()) {
for (uint32 i = 0; i < comp.asset->meshes.size(); ++i) {
comp.meshletOffsets.add(comp.asset->meshes[i]->vertexData->addCullingMapping(comp.asset->meshes[i]->id));
+4 -4
View File
@@ -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;
+1 -1
View File
@@ -13,7 +13,7 @@ template <StyleClass... classes> 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);
}
+10 -10
View File
@@ -67,24 +67,24 @@ using BG_Red = BackgroundColorClass<Vector(1, 0, 0)>;
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> 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<x, x, x, x>; \
using M_X##x = MarginClass<x, x, -1u, -1u>; \
using M_Y##x = MarginClass<-1u, -1u, x, x>; \
using M_L##x = MarginClass<x, -1u, -1u, -1u>; \
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<x, x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
using M_Y##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, x>; \
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<std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
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<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x>;
DECLARE_MARGIN_CLASSES(0)
DECLARE_MARGIN_CLASSES(1)