fixing lots of warnings

This commit is contained in:
Dynamitos
2025-03-26 13:38:48 +01:00
parent edfe34a394
commit 9cce5977c5
33 changed files with 204 additions and 185 deletions
+5 -5
View File
@@ -74,7 +74,7 @@ int main(int, char**) {
uint32 p0 = tris[i].p[0]; uint32 p0 = tris[i].p[0];
uint32 p1 = tris[i].p[1]; uint32 p1 = tris[i].p[1];
uint32 p2 = tris[i].p[2]; uint32 p2 = tris[i].p[2];
uint32 p3 = positions.size(); uint32 p3 = (uint32)positions.size();
positions.add(interpolate(positions[p0], positions[p1], positions[p2])); positions.add(interpolate(positions[p0], positions[p1], positions[p2]));
if (mesh->mTextureCoords[0] != nullptr) if (mesh->mTextureCoords[0] != nullptr)
@@ -102,7 +102,7 @@ int main(int, char**) {
//for (uint32 i = 0; i < tris.size(); ++i) { //for (uint32 i = 0; i < tris.size(); ++i) {
// stats << calcArea(tris[i]) << std::endl; // stats << calcArea(tris[i]) << std::endl;
//} //}
bool tess = false; //bool tess = false;
//while (!tess) { //while (!tess) {
// tess = true; // tess = true;
// for (uint32 i = 0; i < tris.size(); ++i) { // for (uint32 i = 0; i < tris.size(); ++i) {
@@ -143,7 +143,7 @@ int main(int, char**) {
mesh->mBitangents = newBit; mesh->mBitangents = newBit;
} }
uint32 numFaces = tris.size(); uint32 numFaces = (uint32)tris.size();
aiFace* newFaces = new aiFace[numFaces]; aiFace* newFaces = new aiFace[numFaces];
for (uint32 i = 0; i < numFaces; ++i) { for (uint32 i = 0; i < numFaces; ++i) {
newFaces[i].mNumIndices = 3; newFaces[i].mNumIndices = 3;
@@ -153,10 +153,10 @@ int main(int, char**) {
newFaces[i].mIndices[2] = tris[i].p[2]; newFaces[i].mIndices[2] = tris[i].p[2];
} }
mesh->mNumVertices = positions.size(); mesh->mNumVertices = (uint32)positions.size();
mesh->mVertices = newPos; mesh->mVertices = newPos;
mesh->mFaces = newFaces; mesh->mFaces = newFaces;
mesh->mNumFaces = tris.size(); mesh->mNumFaces = (uint32)tris.size();
} }
Assimp::Exporter exporter; Assimp::Exporter exporter;
+2 -3
View File
@@ -28,7 +28,6 @@ PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
"VisibilityMS," "VisibilityMS,"
<< std::endl; << std::endl;
uint64 start = 0; uint64 start = 0;
uint64 prevBegin = 0;
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));
stats << std::fixed << std::setprecision(0); stats << std::fixed << std::setprecision(0);
while (getGlobals().running) { while (getGlobals().running) {
@@ -37,8 +36,8 @@ PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
auto baseResults = baseQuery->getResults(); auto baseResults = baseQuery->getResults();
auto lightCullResults = lightCullQuery->getResults(); auto lightCullResults = lightCullQuery->getResults();
auto visiblityResults = visibilityQuery->getResults(); auto visiblityResults = visibilityQuery->getResults();
int64 renderBegin = renderTimestamp->getResult().time; //int64 renderBegin = renderTimestamp->getResult().time;
int64 renderEnd = renderTimestamp->getResult().time; //int64 renderEnd = renderTimestamp->getResult().time;
Map<std::string, uint64> results; Map<std::string, uint64> results;
for (uint32 i = 0; i < 11; ++i) { for (uint32 i = 0; i < 11; ++i) {
auto ts = timestamps->getResult(); auto ts = timestamps->getResult();
+12 -12
View File
@@ -151,7 +151,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
uint32 uvIndex = 0; uint32 uvIndex = 0;
aiTextureMapMode mapMode = aiTextureMapMode_Clamp; aiTextureMapMode mapMode = aiTextureMapMode_Clamp;
float blend = std::numeric_limits<float>::max(); float blend = std::numeric_limits<float>::max();
aiTextureOp op; aiTextureOp op = aiTextureOp_Add;
if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS) { if (material->GetTexture(type, index, &texPath, &mapping, &uvIndex, nullptr, nullptr, nullptr) != AI_SUCCESS) {
std::cout << "fuck" << std::endl; std::cout << "fuck" << std::endl;
} }
@@ -488,23 +488,23 @@ Vector4 MeshLoader::encodeQTangent(Matrix3 m) {
Vector4 r; Vector4 r;
if (t > 2.9999999) { if (t > 2.9999999) {
r = Vector4(0.0, 0.0, 0.0, 1.0); r = Vector4(0.0, 0.0, 0.0, 1.0);
} else if (t > 0.0000001) { } else if (t > 0.0000001f) {
float s = sqrt(1.0 + t) * 2.0; float s = sqrt(1.0f + t) * 2.0f;
r = Vector4(Vector(m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0]) / s, s * 0.25); r = Vector4(Vector(m[1][2] - m[2][1], m[2][0] - m[0][2], m[0][1] - m[1][0]) / s, s * 0.25f);
} else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) { } else if ((m[0][0] > m[1][1]) && (m[0][0] > m[2][2])) {
float s = sqrt(1.0 + (m[0][0] - (m[1][1] + m[2][2]))) * 2.0; float s = sqrt(1.0f + (m[0][0] - (m[1][1] + m[2][2]))) * 2.0;
r = Vector4(s * 0.25, Vector(m[1][0] - m[0][1], m[2][0] - m[0][2], m[0][2] - m[2][1]) / s); r = Vector4(s * 0.25, Vector(m[1][0] - m[0][1], m[2][0] - m[0][2], m[0][2] - m[2][1]) / s);
} else if (m[1][1] > m[2][2]) { } else if (m[1][1] > m[2][2]) {
float s = sqrt(1.0 + (m[1][1] - (m[0][0] + m[2][2]))) * 2.0; float s = sqrt(1.0f + (m[1][1] - (m[0][0] + m[2][2]))) * 2.0f;
r = Vector4(Vector(m[1][0] + m[0][1], m[2][1] + m[1][2], m[2][0] - m[0][2]) / s, s * 0.25); r = Vector4(Vector(m[1][0] + m[0][1], m[2][1] + m[1][2], m[2][0] - m[0][2]) / s, s * 0.25f);
r = Vector4(r.x, r.w, r.y, r.z); r = Vector4(r.x, r.w, r.y, r.z);
} else { } else {
float s = sqrt(1.0 + (m[2][2] - (m[0][0] + m[1][1]))) * 2.0; float s = sqrt(1.0f + (m[2][2] - (m[0][0] + m[1][1]))) * 2.0f;
r = Vector4(Vector(m[2][0] + m[0][2], m[2][1] + m[1][2], m[0][1] - m[1][0]) / s, s * 0.25); r = Vector4(Vector(m[2][0] + m[0][2], m[2][1] + m[1][2], m[0][1] - m[1][0]) / s, s * 0.25f);
r = Vector4(r.x, r.y, r.w, r.z); r = Vector4(r.x, r.y, r.w, r.z);
} }
r = normalize(r); r = normalize(r);
const float threshold = 1.0 / 32767.0; const float threshold = 1.0f / 32767.0f;
if (r.w <= threshold) { if (r.w <= threshold) {
r = Vector4(Vector(r) * (float)sqrt(1.0 - (threshold * threshold)), (r.w > 0.0) ? threshold : -threshold); r = Vector4(Vector(r) * (float)sqrt(1.0 - (threshold * threshold)), (r.w > 0.0) ? threshold : -threshold);
} }
@@ -539,9 +539,9 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices); Array<StaticMeshVertexData::BiTangentType> biTangents(mesh->mNumVertices);
Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices); Array<StaticMeshVertexData::ColorType> colors(mesh->mNumVertices);
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);
for (size_t j = 0; j < MAX_TEXCOORDS; ++j) { for (uint32 j = 0; j < MAX_TEXCOORDS; ++j) {
if (mesh->HasTextureCoords(j)) { if (mesh->HasTextureCoords(j)) {
texCoords[j][i] = U16Vector2(mesh->mTextureCoords[j][i].x * 65535, mesh->mTextureCoords[j][i].y * 65535); texCoords[j][i] = U16Vector2(mesh->mTextureCoords[j][i].x * 65535, mesh->mTextureCoords[j][i].y * 65535);
} else { } else {
+1 -1
View File
@@ -13,7 +13,7 @@ ViewportControl::ViewportControl(const URect& viewportDimensions, Vector initial
ViewportControl::~ViewportControl() {} ViewportControl::~ViewportControl() {}
void ViewportControl::update(Component::Camera& camera, float deltaTime) { void ViewportControl::update(Component::Camera&, float deltaTime) {
float cameraMove = deltaTime * 20; float cameraMove = deltaTime * 20;
if (keys[KeyCode::KEY_LEFT_SHIFT]) { if (keys[KeyCode::KEY_LEFT_SHIFT]) {
cameraMove *= 4; cameraMove *= 4;
+1 -1
View File
@@ -36,7 +36,7 @@ Array<Halfedge> generateEdges() {
UVector(13, 10, 14), UVector(10, 11, 14), UVector(14, 11, 15)}; UVector(13, 10, 14), UVector(10, 11, 14), UVector(14, 11, 15)};
Array<Halfedge> edges; Array<Halfedge> edges;
for (auto ind : indices) { for (auto ind : indices) {
uint32 baseIndex = edges.size(); uint32 baseIndex = (uint32)edges.size();
edges.add(Halfedge{ind.x, baseIndex + 1, baseIndex + 2, UINT32_MAX}); edges.add(Halfedge{ind.x, baseIndex + 1, baseIndex + 2, UINT32_MAX});
edges.add(Halfedge{ind.y, baseIndex + 2, baseIndex, UINT32_MAX}); edges.add(Halfedge{ind.y, baseIndex + 2, baseIndex, UINT32_MAX});
edges.add(Halfedge{ind.z, baseIndex, baseIndex + 1, UINT32_MAX}); edges.add(Halfedge{ind.z, baseIndex, baseIndex + 1, UINT32_MAX});
+8 -8
View File
@@ -5,14 +5,14 @@ namespace Seele {
namespace Component { namespace Component {
struct KeyboardInput { struct KeyboardInput {
Seele::StaticArray<bool, static_cast<size_t>(Seele::KeyCode::KEY_LAST)> keys; Seele::StaticArray<bool, static_cast<size_t>(Seele::KeyCode::KEY_LAST)> keys;
bool mouse1; bool mouse1 = false;
bool mouse2; bool mouse2 = false;
float mouseX; float mouseX = 0.0f;
float mouseY; float mouseY = 0.0f;
float deltaX; float deltaX = 0.0f;
float deltaY; float deltaY = 0.0f;
float scrollX; float scrollX = 0.0f;
float scrollY; float scrollY = 0.0f;
}; };
} // namespace Component } // namespace Component
} // namespace Seele } // namespace Seele
+5 -5
View File
@@ -83,12 +83,12 @@ template <typename T> struct Array {
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(const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) noexcept constexpr Array(const allocator_type& alloc = allocator_type()) noexcept
: arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) { : arraySize(0), allocated(DEFAULT_ALLOC_SIZE), allocator(alloc) {
_data = allocateArray(DEFAULT_ALLOC_SIZE); _data = allocateArray(DEFAULT_ALLOC_SIZE);
assert(_data != nullptr); assert(_data != nullptr);
} }
constexpr Array(size_type size, const value_type& value, const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) constexpr Array(size_type size, const value_type& value, const allocator_type& alloc = allocator_type())
: arraySize(size), allocated(size), allocator(alloc) { : arraySize(size), allocated(size), allocator(alloc) {
_data = allocateArray(size); _data = allocateArray(size);
assert(_data != nullptr); assert(_data != nullptr);
@@ -96,7 +96,7 @@ template <typename T> struct Array {
std::allocator_traits<allocator_type>::construct(allocator, &_data[i], value); std::allocator_traits<allocator_type>::construct(allocator, &_data[i], value);
} }
} }
constexpr explicit Array(size_type size, const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) constexpr explicit Array(size_type size, const allocator_type& alloc = allocator_type())
: arraySize(size), allocated(size), allocator(alloc) { : arraySize(size), allocated(size), allocator(alloc) {
_data = allocateArray(size); _data = allocateArray(size);
assert(_data != nullptr); assert(_data != nullptr);
@@ -108,14 +108,14 @@ template <typename T> struct Array {
} }
} }
} }
constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type())
: arraySize(init.size()), allocated(init.size()), allocator(alloc) { : arraySize(init.size()), allocated(init.size()), allocator(alloc) {
_data = allocateArray(init.size()); _data = allocateArray(init.size());
assert(_data != nullptr); assert(_data != nullptr);
std::uninitialized_copy(init.begin(), init.end(), begin()); std::uninitialized_copy(init.begin(), init.end(), begin());
} }
template <container_compatible_range<T> Range> template <container_compatible_range<T> Range>
constexpr Array(std::from_range_t, Range&& rg, const allocator_type& alloc = allocator_type(debug_resource::get("Array"))) constexpr Array(std::from_range_t, Range&& rg, const allocator_type& alloc = allocator_type())
: arraySize(0), allocated(0), allocator(alloc) { : arraySize(0), allocated(0), allocator(alloc) {
if constexpr (std::ranges::sized_range<Range> || std::ranges::forward_range<Range>) { if constexpr (std::ranges::sized_range<Range> || std::ranges::forward_range<Range>) {
arraySize = std::ranges::size(rg); arraySize = std::ranges::size(rg);
+6 -3
View File
@@ -5,8 +5,11 @@
using namespace Seele; using namespace Seele;
std::atomic_uint64_t& MemoryManager::getAllocationCounter(const std::string& name) { RefPtr<uint64> MemoryManager::getAllocationCounter(const std::string& name) {
std::unique_lock l(getInstance().allocationMutex); std::unique_lock l(getInstance().allocationMutex);
if (!getInstance().allocationCounters.contains(name)) {
getInstance().allocationCounters[name] = new uint64(0);
}
return getInstance().allocationCounters[name]; return getInstance().allocationCounters[name];
} }
@@ -14,9 +17,9 @@ void MemoryManager::printAllocations() {
std::unique_lock l(getInstance().allocationMutex); std::unique_lock l(getInstance().allocationMutex);
for (const auto& [name, counter] : getInstance().allocationCounters) { for (const auto& [name, counter] : getInstance().allocationCounters) {
if (name.empty()) { if (name.empty()) {
std::cout << name << ": " << counter << std::endl; std::cout << name << ": " << **counter << std::endl;
} else { } else {
std::cout << name << ": " << counter << std::endl; std::cout << name << ": " << **counter << std::endl;
} }
} }
} }
+8 -5
View File
@@ -1,17 +1,18 @@
#pragma once #pragma once
#include <memory_resource> #include <memory_resource>
#include <map> #include <map>
#include "MinimalEngine.h"
namespace Seele { namespace Seele {
class MemoryManager { class MemoryManager {
public: public:
static std::atomic_uint64_t& getAllocationCounter(const std::string& name); static RefPtr<uint64> getAllocationCounter(const std::string& name);
static void printAllocations(); static void printAllocations();
private: private:
static MemoryManager& getInstance(); static MemoryManager& getInstance();
std::mutex allocationMutex; std::mutex allocationMutex;
std::map<std::string, std::atomic_uint64_t> allocationCounters; std::map<std::string, OwningPtr<uint64>> allocationCounters;
}; };
class debug_resource : public std::pmr::memory_resource { class debug_resource : public std::pmr::memory_resource {
@@ -26,13 +27,15 @@ class debug_resource : public std::pmr::memory_resource {
debug_resource& operator=(debug_resource&& other) = default; debug_resource& operator=(debug_resource&& other) = default;
void* do_allocate(size_t bytes, size_t alignment) override { void* do_allocate(size_t bytes, size_t alignment) override {
counter += bytes; // std::cout << name << " + " << bytes << std::endl;
*counter.getHandle() += bytes;
return upstream->allocate(bytes, alignment); return upstream->allocate(bytes, alignment);
} }
void do_deallocate(void* ptr, size_t bytes, size_t alignment) override { void do_deallocate(void* ptr, size_t bytes, size_t alignment) override {
upstream->deallocate(ptr, bytes, alignment); upstream->deallocate(ptr, bytes, alignment);
counter -= bytes; // std::cout << name << " - " << bytes << std::endl;
*counter.getHandle() -= bytes;
} }
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; } bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; }
@@ -40,6 +43,6 @@ class debug_resource : public std::pmr::memory_resource {
private: private:
std::string name; std::string name;
std::pmr::memory_resource* upstream; std::pmr::memory_resource* upstream;
std::atomic_uint64_t& counter; RefPtr<uint64> counter;
}; };
} // namespace Seele } // namespace Seele
+81 -57
View File
@@ -7,11 +7,25 @@ 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(Node* left, Node* right, const NodeData& nodeData) : leftChild(left), rightChild(right), data(nodeData) {} 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(Node* left, Node* right, NodeData&& nodeData) : leftChild(left), rightChild(right), data(std::move(nodeData)) {}
Node* leftChild; Node* leftChild = nullptr;
Node* rightChild; Node* rightChild = nullptr;
Node* parent = nullptr;
NodeData data; NodeData data;
void setLeftChild(Node* child) {
leftChild = child;
if (child != nullptr) {
child->parent = this;
}
}
void setRightChild(Node* child) {
rightChild = child;
if (child != nullptr) {
child->parent = this;
}
}
}; };
using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>; using NodeAlloc = std::allocator_traits<Allocator>::template rebind_alloc<Node>;
@@ -24,49 +38,65 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
using reference = IterType&; using reference = IterType&;
using pointer = IterType*; using pointer = IterType*;
constexpr IteratorBase(Node* x = nullptr, Array<Node*>&& beginIt = Array<Node*>()) : node(x), traversal(std::move(beginIt)) {} constexpr IteratorBase(Node* x = nullptr) : node(x) {}
constexpr IteratorBase(const IteratorBase& i) : node(i.node), traversal(i.traversal) {} constexpr IteratorBase(const IteratorBase& i) : node(i.node) {}
constexpr IteratorBase(IteratorBase&& i) noexcept : node(std::move(i.node)), traversal(std::move(i.traversal)) {} constexpr IteratorBase(IteratorBase&& i) noexcept : node(std::move(i.node)) {}
constexpr IteratorBase& operator=(const IteratorBase& other) { constexpr IteratorBase& operator=(const IteratorBase& other) {
if (this != &other) { if (this != &other) {
node = other.node; node = other.node;
traversal = other.traversal;
} }
return *this; return *this;
} }
constexpr IteratorBase& operator=(IteratorBase&& other) noexcept { constexpr IteratorBase& operator=(IteratorBase&& other) noexcept {
if (this != &other) { if (this != &other) {
node = std::move(other.node); node = std::move(other.node);
traversal = std::move(other.traversal);
} }
return *this; return *this;
} }
constexpr reference operator*() const { return node->data; } constexpr reference operator*() const { return node->data; }
constexpr pointer operator->() const { return &(node->data); } constexpr pointer operator->() const { return std::pointer_traits<pointer>::pointer_to(**this); }
constexpr bool operator!=(const IteratorBase& other) { return node != other.node; } constexpr bool operator!=(const IteratorBase& other) { return node != other.node; }
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 std::strong_ordering operator<=>(const IteratorBase& other) { return node <=> other.node; }
constexpr IteratorBase& operator++() { constexpr IteratorBase& operator++() {
// if current node has no right subtree
if (node->rightChild == nullptr) {
Node* temp = node;
node = node->parent;
// walk up hierarchy until we were the left subtree of any parent
// this means that that parent is the correct next element
while (node->rightChild == temp) {
temp = node;
node = node->parent;
}
} else {
// if there is a right subtree, descend there
node = node->rightChild; node = node->rightChild;
while (node != nullptr && node->leftChild != nullptr) { // and find the leftmost node in that tree
traversal.add(node); while (node->leftChild != nullptr) {
node = node->leftChild; node = node->leftChild;
} }
if (node == nullptr && traversal.size() > 0) {
node = traversal.back();
traversal.pop();
} }
return *this; return *this;
} }
constexpr IteratorBase& operator--() { constexpr IteratorBase& operator--() {
// if current node has no left subtree
if (node->leftChild == nullptr) {
Node* temp = node;
node = node->parent;
// walk up hierarchy until we were the right subtree of any parent
// this means that that parent is the correct next element
while (node->leftChild == temp) {
temp = node;
node = node->parent;
}
} else {
// if there is a left subtree, descend there
node = node->leftChild; node = node->leftChild;
while (node != nullptr && node->rightChild != nullptr) { // and find the rightmost node in that tree
traversal.add(node); while (node->rightChild != nullptr) {
node = node->rightchild; node = node->rightChild;
} }
if (node == nullptr && traversal.size() > 0) {
node = traversal.back();
traversal.pop();
} }
return *this; return *this;
} }
@@ -80,11 +110,10 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
++*this; ++*this;
return tmp; return tmp;
} }
Node* getNode() { return node; } Node* getNode() const { return node; }
private: private:
Node* node; Node* node;
Array<Node*> traversal;
}; };
using Iterator = IteratorBase<NodeData>; using Iterator = IteratorBase<NodeData>;
using ConstIterator = IteratorBase<const NodeData>; using ConstIterator = IteratorBase<const NodeData>;
@@ -122,8 +151,8 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
} }
} }
constexpr Tree(Tree&& other) noexcept constexpr Tree(Tree&& other) noexcept
: alloc(std::move(other.alloc)), root(std::move(other.root)), iteratorsDirty(true), _size(std::move(other._size)), : alloc(std::move(other.alloc)), root(std::move(other.root)), pseudoRoot(std::move(other.pseudoRoot)), iteratorsDirty(true),
comp(std::move(other.comp)) { _size(std::move(other._size)), comp(std::move(other.comp)) {
other._size = 0; other._size = 0;
} }
constexpr ~Tree() noexcept { clear(); } constexpr ~Tree() noexcept { clear(); }
@@ -147,6 +176,7 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
alloc = std::move(other.alloc); alloc = std::move(other.alloc);
} }
root = std::move(other.root); root = std::move(other.root);
pseudoRoot = std::move(other.pseudoRoot);
_size = std::move(other._size); _size = std::move(other._size);
comp = std::move(other.comp); comp = std::move(other.comp);
other._size = 0; other._size = 0;
@@ -159,6 +189,7 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
root = _remove(root, keyFun(root->data)); root = _remove(root, keyFun(root->data));
} }
root = nullptr; root = nullptr;
pseudoRoot.setLeftChild(nullptr);
markIteratorsDirty(); markIteratorsDirty();
} }
constexpr iterator begin() { constexpr iterator begin() {
@@ -191,6 +222,7 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
protected: protected:
constexpr iterator find(const key_type& key) { constexpr iterator find(const key_type& key) {
root = _splay(root, key); root = _splay(root, key);
pseudoRoot.setLeftChild(root);
if (root == nullptr || !equal(root->data, key)) { if (root == nullptr || !equal(root->data, key)) {
return end(); return end();
} }
@@ -213,15 +245,18 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
constexpr Pair<iterator, bool> insert(const NodeData& data) { constexpr Pair<iterator, bool> insert(const NodeData& data) {
auto [r, inserted] = _insert(root, data); auto [r, inserted] = _insert(root, data);
root = r; root = r;
pseudoRoot.setLeftChild(root);
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)); auto [r, inserted] = _insert(root, std::move(data));
root = r; root = r;
pseudoRoot.setLeftChild(root);
return Pair<iterator, bool>(iterator(root), inserted); return Pair<iterator, bool>(iterator(root), inserted);
} }
constexpr iterator remove(const key_type& key) { constexpr iterator remove(const key_type& key) {
root = _remove(root, key); root = _remove(root, key);
pseudoRoot.setLeftChild(root);
return iterator(root); return iterator(root);
} }
@@ -240,29 +275,18 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
iteratorsDirty = false; iteratorsDirty = false;
} }
constexpr Iterator calcBeginIterator() const { constexpr Iterator calcBeginIterator() const {
Node* begin = root; // start at pseudoroot so that if no regular nodes exist begin == end
Array<Node*> beginTraversal; Node* begin = const_cast<Node*>(&pseudoRoot);
while (begin != nullptr) { while (begin != nullptr && begin->leftChild != nullptr) {
beginTraversal.add(begin);
begin = begin->leftChild; begin = begin->leftChild;
} }
if (!beginTraversal.empty()) { return Iterator(begin);
begin = beginTraversal.back();
beginTraversal.pop();
}
return Iterator(begin, std::move(beginTraversal));
}
constexpr Iterator calcEndIterator() const {
Node* endIndex = root;
Array<Node*> endTraversal;
while (endIndex != nullptr) {
endTraversal.add(endIndex);
endIndex = endIndex->rightChild;
}
return Iterator(endIndex, std::move(endTraversal));
} }
constexpr Iterator calcEndIterator() const { return Iterator(const_cast<Node*>(&pseudoRoot)); }
NodeAlloc alloc; NodeAlloc alloc;
Node* root; Node* root;
// where the end iterator points to
Node pseudoRoot;
Iterator beginIt; Iterator beginIt;
Iterator endIt; Iterator endIt;
bool iteratorsDirty; bool iteratorsDirty;
@@ -271,14 +295,14 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
KeyFun keyFun = KeyFun(); KeyFun keyFun = KeyFun();
Node* rotateLeft(Node* x) { Node* rotateLeft(Node* x) {
Node* y = x->rightChild; Node* y = x->rightChild;
x->rightChild = y->leftChild; x->setRightChild(y->leftChild);
y->leftChild = x; y->setLeftChild(x);
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->setLeftChild(y->rightChild);
y->rightChild = x; y->setRightChild(x);
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) {
@@ -298,13 +322,13 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
std::allocator_traits<NodeAlloc>::construct(alloc, newNode, nullptr, nullptr, std::forward<NodeDataType>(data)); std::allocator_traits<NodeAlloc>::construct(alloc, newNode, nullptr, nullptr, std::forward<NodeDataType>(data));
if (comp(keyFun(newNode->data), keyFun(r->data))) { if (comp(keyFun(newNode->data), keyFun(r->data))) {
newNode->rightChild = r; newNode->setRightChild(r);
newNode->leftChild = r->leftChild; newNode->setLeftChild(r->leftChild);
r->leftChild = nullptr; r->setLeftChild(nullptr);
} else { } else {
newNode->leftChild = r; newNode->setLeftChild(r);
newNode->rightChild = r->rightChild; newNode->setRightChild(r->rightChild);
r->rightChild = nullptr; r->setRightChild(nullptr);
} }
_size++; _size++;
return Pair<Node*, bool>(newNode, true); return Pair<Node*, bool>(newNode, true);
@@ -327,7 +351,7 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
temp = r; temp = r;
r = _splay(r->leftChild, key); r = _splay(r->leftChild, key);
r->rightChild = temp->rightChild; r->setRightChild(temp->rightChild);
} }
std::allocator_traits<NodeAlloc>::destroy(alloc, temp); std::allocator_traits<NodeAlloc>::destroy(alloc, temp);
alloc.deallocate(temp, 1); alloc.deallocate(temp, 1);
@@ -344,11 +368,11 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
return r; return r;
if (comp(key, keyFun(r->leftChild->data))) { if (comp(key, keyFun(r->leftChild->data))) {
r->leftChild->leftChild = _splay(r->leftChild->leftChild, key); r->leftChild->setLeftChild(_splay(r->leftChild->leftChild, key));
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->setRightChild(_splay(r->leftChild->rightChild, key));
if (r->leftChild->rightChild != nullptr) { if (r->leftChild->rightChild != nullptr) {
r->leftChild = rotateLeft(r->leftChild); r->leftChild = rotateLeft(r->leftChild);
@@ -360,13 +384,13 @@ template <typename KeyType, typename NodeData, typename KeyFun, typename Compare
return r; return r;
if (comp(key, keyFun(r->rightChild->data))) { if (comp(key, keyFun(r->rightChild->data))) {
r->rightChild->leftChild = _splay(r->rightChild->leftChild, key); r->rightChild->setLeftChild(_splay(r->rightChild->leftChild, key));
if (r->rightChild->leftChild != nullptr) { if (r->rightChild->leftChild != nullptr) {
r->rightChild = rotateRight(r->rightChild); r->setRightChild(rotateRight(r->rightChild));
} }
} 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->setRightChild(_splay(r->rightChild->rightChild, key));
r = rotateLeft(r); r = rotateLeft(r);
} }
+3 -3
View File
@@ -52,7 +52,7 @@ class IndexBuffer : public Buffer {
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
Gfx::SeIndexType indexType; Gfx::SeIndexType indexType;
uint64 numIndices; uint64 numIndices = 0;
}; };
DEFINE_REF(IndexBuffer) DEFINE_REF(IndexBuffer)
@@ -81,7 +81,7 @@ class ShaderBuffer : public Buffer {
virtual void updateContents(uint64 offset, uint64 size, void* data) = 0; virtual void updateContents(uint64 offset, uint64 size, void* data) = 0;
virtual void* map() = 0; virtual void* map() = 0;
virtual void unmap() = 0; virtual void unmap() = 0;
constexpr uint32 getNumElements() const { return numElements; } constexpr uint64 getNumElements() const { return numElements; }
virtual void clear() = 0; virtual void clear() = 0;
@@ -91,7 +91,7 @@ class ShaderBuffer : public Buffer {
virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess, virtual void executePipelineBarrier(SeAccessFlags srcAccess, SePipelineStageFlags srcStage, SeAccessFlags dstAccess,
SePipelineStageFlags dstStage) = 0; SePipelineStageFlags dstStage) = 0;
uint32 numElements; uint64 numElements;
}; };
DEFINE_REF(ShaderBuffer) DEFINE_REF(ShaderBuffer)
} // namespace Gfx } // namespace Gfx
@@ -74,6 +74,8 @@ void RayTracingPass::beginFrame(const Component::Camera& cam) {
} }
void RayTracingPass::render() { void RayTracingPass::render() {
texture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
Array<Gfx::RayTracingHitGroup> callableGroups; Array<Gfx::RayTracingHitGroup> callableGroups;
Array<Gfx::PBottomLevelAS> accelerationStructures; Array<Gfx::PBottomLevelAS> accelerationStructures;
Array<InstanceData> instanceData; Array<InstanceData> instanceData;
@@ -168,15 +170,9 @@ void RayTracingPass::render() {
} }
pass++; pass++;
std::cout << pass << std::endl; std::cout << pass << std::endl;
texture->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
Gfx::SE_ACCESS_TRANSFER_READ_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
commands.add(std::move(command)); commands.add(std::move(command));
graphics->executeCommands(std::move(commands)); graphics->executeCommands(std::move(commands));
viewport->getOwner()->getBackBuffer()->changeLayout(Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, Gfx::SE_ACCESS_NONE,
Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
graphics->copyTexture(Gfx::PTexture2D(texture), viewport->getOwner()->getBackBuffer());
} }
void RayTracingPass::endFrame() {} void RayTracingPass::endFrame() {}
@@ -200,6 +196,8 @@ void RayTracingPass::publishOutputs() {
texture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, texture->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
resources->registerRenderPassOutput("BASEPASS_COLOR", Gfx::RenderTargetAttachment(texture, Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
ShaderCompilationInfo compileInfo = { ShaderCompilationInfo compileInfo = {
.name = "RayGenMiss", .name = "RayGenMiss",
.modules = {"RayGen", "AnyHit", "Miss"}, .modules = {"RayGen", "AnyHit", "Miss"},
@@ -131,7 +131,7 @@ void ToneMappingPass::render() {
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);
histogramLayout->reset(); histogramLayout->reset();
Gfx::PDescriptorSet histogramSet = histogramLayout->allocateDescriptorSet(); histogramSet = histogramLayout->allocateDescriptorSet();
histogramSet->updateConstants("minLogLum", 0, &minLogLum); histogramSet->updateConstants("minLogLum", 0, &minLogLum);
histogramSet->updateConstants("inverseLogLumRange", 0, &inverseLogLumRange); histogramSet->updateConstants("inverseLogLumRange", 0, &inverseLogLumRange);
histogramSet->updateConstants("timeCoeff", 0, &timeCoeff); histogramSet->updateConstants("timeCoeff", 0, &timeCoeff);
@@ -10,8 +10,8 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
: graphics(graphics), scene(scene) { : graphics(graphics), scene(scene) {
skyBox = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>(); skyBox = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>();
logN = (int)log2(params.N); logN = (int)log2(params.N);
threadGroupsX = ceil(params.N / 8.0f); threadGroupsX = (uint32)ceil(params.N / 8.0f);
threadGroupsY = ceil(params.N / 8.0f); threadGroupsY = (uint32)ceil(params.N / 8.0f);
materialUniforms = graphics->createUniformBuffer(UniformBufferCreateInfo{ materialUniforms = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = .sourceData =
@@ -263,7 +263,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
.windSpeed = 2, .windSpeed = 2,
.windDirection = 22, .windDirection = 22,
.fetch = 100000, .fetch = 100000,
.spreadBlend = 0.642, .spreadBlend = 0.642f,
.swell = 1, .swell = 1,
.peakEnhancement = 1, .peakEnhancement = 1,
.shortWavesFade = 0.25f, .shortWavesFade = 0.25f,
@@ -523,8 +523,8 @@ void WaterRenderer::updateFFTDescriptor() {
spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
params.deltaTime = Gfx::getCurrentFrameDelta(); params.deltaTime = (float)Gfx::getCurrentFrameDelta();
params.frameTime = Gfx::getCurrentFrameTime(); params.frameTime = (float)Gfx::getCurrentFrameTime();
paramsBuffer->updateContents(0, sizeof(ComputeParams), &params); paramsBuffer->updateContents(0, sizeof(ComputeParams), &params);
paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT, paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT); Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
@@ -57,8 +57,8 @@ class WaterRenderer {
}; };
StaticArray<DisplaySpectrumSettings, 8> displaySpectrums; StaticArray<DisplaySpectrumSettings, 8> displaySpectrums;
struct ComputeParams { struct ComputeParams {
float frameTime; float frameTime = 0.0f;
float deltaTime; float deltaTime = 0.0f;
float gravity = 9.81f; float gravity = 9.81f;
float repeatTime = 200.0f; float repeatTime = 200.0f;
float depth = 20.0f; float depth = 20.0f;
+1 -1
View File
@@ -50,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{debug_resource::get("VertexPositions")}; Array<PositionType> posData;
Array<TexCoordType> texData[MAX_TEXCOORDS]; Array<TexCoordType> texData[MAX_TEXCOORDS];
Array<NormalType> norData; Array<NormalType> norData;
Array<TangentType> tanData; Array<TangentType> tanData;
+6 -6
View File
@@ -111,7 +111,7 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
vmaUnmapMemory(graphics->getAllocator(), staging->allocation); vmaUnmapMemory(graphics->getAllocator(), staging->allocation);
Gfx::QueueType prevOwner = owner; Gfx::QueueType prevOwner = owner;
// transferOwnership(Gfx::QueueType::TRANSFER); transferOwnership(Gfx::QueueType::TRANSFER);
PCommand cmd = graphics->getQueueCommands(Gfx::QueueType::GRAPHICS)->getCommands(); PCommand cmd = graphics->getQueueCommands(Gfx::QueueType::GRAPHICS)->getCommands();
VkBufferCopy copy = { VkBufferCopy copy = {
@@ -125,7 +125,7 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT); VK_PIPELINE_STAGE_TRANSFER_BIT);
// transferOwnership(prevOwner); transferOwnership(prevOwner);
graphics->getDestructionManager()->queueResourceForDestruction(std::move(staging)); graphics->getDestructionManager()->queueResourceForDestruction(std::move(staging));
} }
@@ -147,7 +147,7 @@ void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void
OBufferAllocation staging = new BufferAllocation(graphics, "ReadStaging", stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS); OBufferAllocation staging = new BufferAllocation(graphics, "ReadStaging", stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS);
Gfx::QueueType prevOwner = owner; Gfx::QueueType prevOwner = owner;
// transferOwnership(Gfx::QueueType::TRANSFER); transferOwnership(Gfx::QueueType::TRANSFER);
PCommandPool pool = graphics->getQueueCommands(Gfx::QueueType::TRANSFER); PCommandPool pool = graphics->getQueueCommands(Gfx::QueueType::TRANSFER);
PCommand cmd = pool->getCommands(); PCommand cmd = pool->getCommands();
@@ -164,7 +164,7 @@ void BufferAllocation::readContents(uint64 regionOffset, uint64 regionSize, void
pool->submitCommands(); pool->submitCommands();
cmd->getFence()->wait(1000000); cmd->getFence()->wait(1000000);
// transferOwnership(prevOwner); transferOwnership(prevOwner);
uint8* data; uint8* data;
VK_CHECK(vmaMapMemory(graphics->getAllocator(), staging->allocation, (void**)&data)); VK_CHECK(vmaMapMemory(graphics->getAllocator(), staging->allocation, (void**)&data));
@@ -276,11 +276,11 @@ void Buffer::rotateBuffer(uint64 size, bool preserveContents) {
return; return;
} }
buffers.add(nullptr); buffers.add(nullptr);
createBuffer(size, buffers.size() - 1); createBuffer(size, (uint32)buffers.size() - 1);
if (preserveContents) { if (preserveContents) {
copyBuffer(currentBuffer, buffers.size() - 1); copyBuffer(currentBuffer, buffers.size() - 1);
} }
currentBuffer = buffers.size() - 1; currentBuffer = (uint32)buffers.size() - 1;
} }
void Buffer::createBuffer(uint64 size, uint32 destIndex) { void Buffer::createBuffer(uint64 size, uint32 destIndex) {
+6 -11
View File
@@ -18,7 +18,6 @@ class Command {
Command(PGraphics graphics, PCommandPool pool); Command(PGraphics graphics, PCommandPool pool);
~Command(); ~Command();
constexpr VkCommandBuffer getHandle() { return handle; } constexpr VkCommandBuffer getHandle() { return handle; }
void reset();
void begin(); void begin();
void end(); void end();
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer); void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
@@ -46,8 +45,6 @@ class Command {
OFence fence; OFence fence;
OSemaphore signalSemaphore; OSemaphore signalSemaphore;
State state; State state;
VkViewport currentViewport;
VkRect2D currentScissor;
VkCommandBuffer handle; VkCommandBuffer handle;
PRenderPass boundRenderPass; PRenderPass boundRenderPass;
PFramebuffer boundFramebuffer; PFramebuffer boundFramebuffer;
@@ -91,12 +88,12 @@ class RenderCommand : public Gfx::RenderCommand {
virtual void traceRays(uint32 width, uint32 height, uint32 depth) override; virtual void traceRays(uint32 width, uint32 height, uint32 depth) override;
private: private:
PGraphicsPipeline pipeline; PGraphicsPipeline pipeline = nullptr;
PRayTracingPipeline rtPipeline; PRayTracingPipeline rtPipeline = nullptr;
bool ready; bool ready = false;
Array<PCommandBoundResource> boundResources; Array<PCommandBoundResource> boundResources;
VkViewport currentViewport; VkViewport currentViewport = VkViewport();
VkRect2D currentScissor; VkRect2D currentScissor = VkRect2D();
PGraphics graphics; PGraphics graphics;
std::thread::id threadId; std::thread::id threadId;
VkCommandBuffer handle; VkCommandBuffer handle;
@@ -123,10 +120,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
private: private:
PComputePipeline pipeline; PComputePipeline pipeline;
bool ready; bool ready = false;
Array<PCommandBoundResource> boundResources; Array<PCommandBoundResource> boundResources;
VkViewport currentViewport;
VkRect2D currentScissor;
PGraphics graphics; PGraphics graphics;
std::thread::id threadId; std::thread::id threadId;
VkCommandBuffer handle; VkCommandBuffer handle;
+2 -2
View File
@@ -3,8 +3,8 @@
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
VkBool32 Seele::Vulkan::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, VkBool32 Seele::Vulkan::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT, VkDebugUtilsMessageTypeFlagsEXT,
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) { const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void*) {
std::cerr << pCallbackData->pMessage << std::endl; std::cerr << pCallbackData->pMessage << std::endl;
return VK_FALSE; return VK_FALSE;
} }
+6 -6
View File
@@ -97,11 +97,11 @@ DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout)
perTypeSizes[binding.descriptorType] += 512; perTypeSizes[binding.descriptorType] += 512;
} }
Array<VkDescriptorPoolSize> poolSizes; Array<VkDescriptorPoolSize> poolSizes;
for (const auto [type, num] : perTypeSizes) { for (const auto& [type, num] : perTypeSizes) {
VkDescriptorPoolSize size; poolSizes.add(VkDescriptorPoolSize{
size.descriptorCount = num; .type = cast(type),
size.type = cast(type); .descriptorCount = num,
poolSizes.add(size); });
} }
VkDescriptorPoolCreateInfo createInfo = { VkDescriptorPoolCreateInfo createInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
@@ -473,7 +473,7 @@ std::mutex layoutLock;
Map<uint32, VkPipelineLayout> cachedLayouts; Map<uint32, VkPipelineLayout> cachedLayouts;
void PipelineLayout::create() { void PipelineLayout::create() {
for (auto [name, desc] : descriptorSetLayouts) { for (const auto& [_, desc] : descriptorSetLayouts) {
PDescriptorLayout layout = desc.cast<DescriptorLayout>(); PDescriptorLayout layout = desc.cast<DescriptorLayout>();
layout->create(); layout->create();
uint32 parameterIndex = parameterMapping[layout->getName()]; uint32 parameterIndex = parameterMapping[layout->getName()];
+1 -2
View File
@@ -24,7 +24,7 @@ class DescriptorLayout : public Gfx::DescriptorLayout {
private: private:
PGraphics graphics; PGraphics graphics;
uint32 constantsSize = 0; uint32 constantsSize = 0;
VkShaderStageFlags constantsStages; VkShaderStageFlags constantsStages = 0;
Array<VkDescriptorSetLayoutBinding> bindings; Array<VkDescriptorSetLayoutBinding> bindings;
Map<std::string, DescriptorMapping> mappings; Map<std::string, DescriptorMapping> mappings;
VkDescriptorSetLayout layoutHandle; VkDescriptorSetLayout layoutHandle;
@@ -74,7 +74,6 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
private: private:
std::vector<uint8> constantData; std::vector<uint8> constantData;
OBufferAllocation constantsBuffer; OBufferAllocation constantsBuffer;
VkShaderStageFlags constantsStageFlags;
List<VkDescriptorImageInfo> imageInfos; List<VkDescriptorImageInfo> imageInfos;
List<VkDescriptorBufferInfo> bufferInfos; List<VkDescriptorBufferInfo> bufferInfos;
List<VkWriteDescriptorSetAccelerationStructureKHR> accelerationInfos; List<VkWriteDescriptorSetAccelerationStructureKHR> accelerationInfos;
+2 -2
View File
@@ -968,11 +968,11 @@ void Graphics::createDevice(GraphicsInitializer initializer) {
transferQueue = 0; transferQueue = 0;
queues.add(new Queue(this, graphicsQueueInfo.familyIndex, graphicsQueueInfo.queueIndex)); queues.add(new Queue(this, graphicsQueueInfo.familyIndex, graphicsQueueInfo.queueIndex));
if (computeQueueInfo.familyIndex != -1) { if (computeQueueInfo.familyIndex != -1) {
computeQueue = queues.size(); computeQueue = (uint32)queues.size();
queues.add(new Queue(this, computeQueueInfo.familyIndex, computeQueueInfo.queueIndex)); queues.add(new Queue(this, computeQueueInfo.familyIndex, computeQueueInfo.queueIndex));
} }
if (transferQueueInfo.familyIndex != -1) { if (transferQueueInfo.familyIndex != -1) {
transferQueue = queues.size(); transferQueue = (uint32)queues.size();
queues.add(new Queue(this, transferQueueInfo.familyIndex, transferQueueInfo.queueIndex)); queues.add(new Queue(this, transferQueueInfo.familyIndex, transferQueueInfo.queueIndex));
} }
+12 -14
View File
@@ -11,23 +11,23 @@ using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
PipelineCache::PipelineCache(PGraphics graphics, const std::string& cacheFilePath) : graphics(graphics), cacheFile(cacheFilePath) { PipelineCache::PipelineCache(PGraphics graphics, const std::string& cacheFilePath) : graphics(graphics), cacheFile(cacheFilePath) {
std::ifstream stream(cacheFilePath, std::ios::binary | std::ios::ate);
VkPipelineCacheCreateInfo cacheCreateInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.initialDataSize = 0,
};
if (stream.good()) {
Array<uint8> cacheData; Array<uint8> cacheData;
std::ifstream stream(cacheFilePath, std::ios::binary | std::ios::ate);
if (stream.good()) {
uint32 fileSize = static_cast<uint32>(stream.tellg()); uint32 fileSize = static_cast<uint32>(stream.tellg());
cacheData.resize(fileSize); cacheData.resize(fileSize);
stream.seekg(0); stream.seekg(0);
stream.read((char*)cacheData.data(), fileSize); stream.read((char*)cacheData.data(), fileSize);
cacheCreateInfo.initialDataSize = fileSize;
cacheCreateInfo.pInitialData = cacheData.data();
std::cout << "Loaded " << fileSize << " bytes from pipeline cache" << std::endl; std::cout << "Loaded " << fileSize << " bytes from pipeline cache" << std::endl;
} }
VkPipelineCacheCreateInfo cacheCreateInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.initialDataSize = cacheData.size(),
.pInitialData = cacheData.data(),
};
VK_CHECK(vkCreatePipelineCache(graphics->getDevice(), &cacheCreateInfo, nullptr, &cache)); VK_CHECK(vkCreatePipelineCache(graphics->getDevice(), &cacheCreateInfo, nullptr, &cache));
} }
@@ -685,7 +685,6 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
rayGenBuffer->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_READ_BIT, rayGenBuffer->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR); VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
Array<uint8> hitSbt(hitStride * createInfo.hitGroups.size()); Array<uint8> hitSbt(hitStride * createInfo.hitGroups.size());
for (uint64 i = 0; i < createInfo.hitGroups.size(); ++i) { for (uint64 i = 0; i < createInfo.hitGroups.size(); ++i) {
std::memcpy(hitSbt.data() + i * hitStride, sbt.data() + sbtOffset, handleSize); std::memcpy(hitSbt.data() + i * hitStride, sbt.data() + sbtOffset, handleSize);
@@ -697,7 +696,6 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
hitBuffer->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_READ_BIT, hitBuffer->pipelineBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR); VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
Array<uint8> missSbt(missStride * createInfo.missGroups.size()); Array<uint8> missSbt(missStride * createInfo.missGroups.size());
for (uint64 i = 0; i < createInfo.missGroups.size(); ++i) { for (uint64 i = 0; i < createInfo.missGroups.size(); ++i) {
std::memcpy(missSbt.data() + i * missStride, sbt.data() + sbtOffset, handleSize); std::memcpy(missSbt.data() + i * missStride, sbt.data() + sbtOffset, handleSize);
@@ -710,8 +708,8 @@ PRayTracingPipeline PipelineCache::createPipeline(Gfx::RayTracingPipelineCreateI
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR); VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
ORayTracingPipeline pipeline = ORayTracingPipeline pipeline =
new RayTracingPipeline(graphics, pipelineHandle, std::move(rayGenBuffer), rayGenStride, std::move(hitBuffer), new RayTracingPipeline(graphics, pipelineHandle, std::move(rayGenBuffer), rayGenStride, std::move(hitBuffer), hitStride,
hitStride, std::move(missBuffer), missStride, nullptr, 0, createInfo.pipelineLayout); std::move(missBuffer), missStride, nullptr, 0, createInfo.pipelineLayout);
PRayTracingPipeline handle = pipeline; PRayTracingPipeline handle = pipeline;
rayTracingPipelines[hash] = std::move(pipeline); rayTracingPipelines[hash] = std::move(pipeline);
return handle; return handle;
+2 -2
View File
@@ -23,8 +23,8 @@ class QueryPool {
std::string name; std::string name;
VkQueryPipelineStatisticFlags flags; VkQueryPipelineStatisticFlags flags;
// ring buffer // ring buffer
uint64 head = 0; uint32 head = 0;
uint64 tail = 0; uint32 tail = 0;
uint64 numAvailable; uint64 numAvailable;
uint32 numQueries; uint32 numQueries;
uint32 resultsStride; uint32 resultsStride;
+1 -1
View File
@@ -34,7 +34,7 @@ void Semaphore::rotateSemaphore() {
currentHandle = i; currentHandle = i;
return; return;
} }
currentHandle = handles.size(); currentHandle = (uint32)handles.size();
handles.add(new SemaphoreHandle(graphics, "Semaphore")); handles.add(new SemaphoreHandle(graphics, "Semaphore"));
} }
+1 -1
View File
@@ -139,7 +139,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 (uint32 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());
+2 -2
View File
@@ -11,9 +11,9 @@ struct BoundingSphere {
}; };
struct AABB { struct AABB {
Vector min = Vector(std::numeric_limits<float>::max()); Vector min = Vector(std::numeric_limits<float>::max());
float pad0; // So that it can be used directly in shaders float pad0 = 0; // So that it can be used directly in shaders
Vector max = Vector(std::numeric_limits<float>::lowest()); // cause of reasons Vector max = Vector(std::numeric_limits<float>::lowest()); // cause of reasons
float pad1; float pad1 = 0;
BoundingSphere toSphere() const { BoundingSphere toSphere() const {
Vector center = (min + max) / 2.f; Vector center = (min + max) / 2.f;
StaticArray<Vector, 8> corners; StaticArray<Vector, 8> corners;
-1
View File
@@ -311,7 +311,6 @@ void BVH::validateBVH() const {
} }
for (uint32 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();
if (!dynamicNodes[nodeIdx].isValid) if (!dynamicNodes[nodeIdx].isValid)
continue; continue;
while (dynamicNodes[nodeIdx].parentIndex != -1) { while (dynamicNodes[nodeIdx].parentIndex != -1) {
+4 -4
View File
@@ -17,17 +17,17 @@ class BVH {
private: private:
struct AABBCenter { struct AABBCenter {
AABB bb; AABB bb;
Vector center; Vector center = Vector();
entt::entity id; entt::entity id = entt::entity();
}; };
struct Node { struct Node {
AABB box; AABB box;
int32 parentIndex = -1; int32 parentIndex = -1;
int32 left = -1; int32 left = -1;
int32 right = -1; int32 right = -1;
bool isLeaf; bool isLeaf = false;
bool isValid = true; bool isValid = true;
entt::entity owner; entt::entity owner = entt::entity();
}; };
void traverseStaticTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps); void traverseStaticTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps);
void traverseDynamicTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps); void traverseDynamicTree(const AABB& aabb, entt::entity source, int32 nodeIndex, Array<Pair<entt::entity, entt::entity>>& overlaps);
+4 -4
View File
@@ -28,8 +28,8 @@ void KeyboardInput::update(Component::KeyboardInput& input) {
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier) { keys[code] = action != InputAction::RELEASE; } void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier) { keys[code] = action != InputAction::RELEASE; }
void KeyboardInput::mouseCallback(double x, double y) { void KeyboardInput::mouseCallback(double x, double y) {
mouseX = x; mouseX = (float)x;
mouseY = y; mouseY = (float)y;
} }
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier) { void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier) {
@@ -42,6 +42,6 @@ void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action,
} }
void KeyboardInput::scrollCallback(double xScroll, double yScroll) { void KeyboardInput::scrollCallback(double xScroll, double yScroll) {
scrollX = xScroll; scrollX = (float)xScroll;
scrollY = yScroll; scrollY = (float)yScroll;
} }
+1 -1
View File
@@ -16,7 +16,7 @@ class SystemBase {
virtual void update() {} virtual void update() {}
protected: protected:
double deltaTime; double deltaTime = 0.0;
entt::registry& registry; entt::registry& registry;
PScene scene; PScene scene;
}; };
+1
View File
@@ -32,6 +32,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
renderGraph.createRenderPass(); renderGraph.createRenderPass();
if (graphics->supportRayTracing()) { if (graphics->supportRayTracing()) {
rayTracingGraph.addPass(new RayTracingPass(graphics, scene)); rayTracingGraph.addPass(new RayTracingPass(graphics, scene));
rayTracingGraph.addPass(new ToneMappingPass(graphics));
rayTracingGraph.setViewport(viewport); rayTracingGraph.setViewport(viewport);
rayTracingGraph.createRenderPass(); rayTracingGraph.createRenderPass();
} }
+1 -1
View File
@@ -31,7 +31,7 @@ TEST(CachedMap, for_each)
map[6] = 4; map[6] = 4;
map[4] = 7; map[4] = 7;
int count = 0; int count = 0;
for(auto [key, val] : map) for(const auto& [key, val] : map)
{ {
count++; count++;
} }