OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
instancestorage.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/Device>
4#include <Tempest/Matrix4x4>
5#include <Tempest/UniformBuffer>
6
7#include <condition_variable>
8#include <vector>
9#include <thread>
10
11#include "resources.h"
12
14 private:
15 struct Range {
16 size_t begin = 0;
17 size_t size = 0;
18 size_t asize = 0;
19 };
20
21 static constexpr size_t blockSz = 64;
22 static constexpr size_t alignment = 64;
23
24 public:
25 class Id {
26 public:
27 Id() = default;
28 Id(InstanceStorage& owner, Range rgn):owner(&owner), rgn(rgn){}
29 Id(Id&& other) noexcept;
30 Id& operator = (Id&& other) noexcept;
31 ~Id();
32
33 const size_t size() const { return rgn.asize; }
34 void set(const Tempest::Matrix4x4* anim);
35 void set(const Tempest::Matrix4x4& obj, size_t offset);
36 void set(const void* data, size_t offset, size_t size);
37
38 template<class T>
39 const uint32_t offsetId() const { return uint32_t(rgn.begin/sizeof(T)); }
40
41 bool isEmpty() const { return rgn.asize==0; }
42
43 private:
44 InstanceStorage* owner = nullptr;
45 Range rgn;
46 friend class InstanceStorage;
47 };
48
51
52 Id alloc(const size_t size);
53 bool realloc(Id& id, const size_t size);
54 auto ssbo () const -> const Tempest::StorageBuffer&;
55 bool commit(Tempest::Encoder<Tempest::CommandBuffer>& cmd, uint8_t fId);
56 void join();
57
58 private:
59 void free(const Range& r);
60 void uploadMain();
61
62 struct Path {
63 uint32_t dst;
64 uint32_t src;
65 uint32_t size;
66 };
67
68 std::vector<Range> rgn;
69 std::vector<uint32_t> durty;
70 size_t blockCnt = 0;
71
72 Tempest::StorageBuffer patchGpu[Resources::MaxFramesInFlight];
73 std::vector<uint8_t> patchCpu;
74 std::vector<Path> patchBlock;
75
76 Tempest::StorageBuffer dataGpu;
77 std::vector<uint8_t> dataCpu;
78
79 std::thread uploadTh;
80 std::mutex sync;
81 std::condition_variable uploadCnd;
82 int32_t uploadFId = -1;
83 };
const uint32_t offsetId() const
Id & operator=(Id &&other) noexcept
void set(const Tempest::Matrix4x4 *anim)
Id(InstanceStorage &owner, Range rgn)
const size_t size() const
Id alloc(const size_t size)
bool commit(Tempest::Encoder< Tempest::CommandBuffer > &cmd, uint8_t fId)
auto ssbo() const -> const Tempest::StorageBuffer &
bool realloc(Id &id, const size_t size)
@ MaxFramesInFlight
Definition resources.h:48