VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
incomplete.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef INCOMPLETE_H
4#define INCOMPLETE_H
5
6
7#include "enum.hpp"
8#include "types.hpp"
11
12
13struct AttaCD {
15};
16
17
18
19
20
21struct DescriptorVk;
22template<class pool>
24struct ImmidiateCmdPool;
25struct CanvasVk;
26struct GuiMaterialVk;
27
28typedef struct Mache {
29 long id;
30 long refCnt;
32
33 void* mapped;
34 std::string_view type;
35 VkDeviceSize size;
36 std::vector<VkDeviceSize> sizeSet;
37
38 VkDeviceSize memSize;
39 VkDeviceSize reqSize;
40 VkDeviceSize align;
41 VkDeviceSize reqAlign;
42
44
45typedef struct Iache {
46
47
48 VkFormat format;
49 uint32_t multisample;
50 VkImageLayout layout;
51 VkDescriptorType type;
52 long refCnt;
53 const size_t hash;
55 VkImageView vkI;
56 std::string name;
57 Iache() :hash(size_t(-1)), refCnt(0), multisample(1) {};
58 Iache(size_t hash) :hash(hash), hach({ .id = -1,.version = 0,.hash = hash }), refCnt(0), multisample(1) { name = "new"; };
59 ~Iache() { log_once(" Call destructor Iache \n"); };
60
61
63 {
64 if (this->hash == hash) return *this;
65 if (refCnt > 0)log_bad("Iache reference exists. you lost the hash. \n");
66 this->~Iache();
67 new (this) Iache(hash);
68 return *this;
69 };
70 template<class T>
71 Iache& operator=(T& iach)
72 {
73
74 log_once(" Call Swap Iache %d %x <=> %x , %x <=> %x \n", refCnt, this->hach.id, iach.hach.id, this->hash, iach.hash);
75
76 if (this->hash == iach.hash) return *this;
77 if (refCnt > 0)log_bad("Iache reference exists. you lost the hash. \n");
78 this->~Iache();
79 new (this) Iache(iach.hash);
80 this->hach.id = iach.hach.id;
81 this->format = iach.format;
82 this->multisample = iach.multisample;
83 this->refCnt = iach.refCnt;
84 this->vkI = iach.vkI;
85 log_once(" Call Swap view %x id %x hash %x version %x\n", this->vkI, this->hach.id, this->hach.hash, this->hach.version);
86 return *this;
87 };
88
89 static size_t rehash(std::string imgName, size_t seed) noexcept
90 {
91 static std::hash<std::string> h_img{};
92 static std::hash<size_t> h_seed{};
93
94 std::size_t hash = 0;
95 hash += h_img(imgName);
96 hash += hash << 10;
97 hash ^= hash >> 6;
98
99 hash += h_seed(seed);
100 hash += hash << 3;
101 hash ^= hash >> 11;
102 hash += hash << 15;
103 return hash;
104 };
105
106 template<class I>
107 void Delete(I* im) {
108 long cnt = InterlockedDecrement(&refCnt);
109 log_once(" Decrement Iache %d \n", cnt);
110 if (cnt == 0) {
111 im->$Delete(&hach);
112 }
113 };
114
116
117typedef struct Bache {
118
119 long id;
120 long refCnt;
122
123 VkDeviceSize align;
124 VkDeviceSize reqAlign;
125
126 VkDeviceSize size;
127 VkDeviceSize offset;
128 VkDeviceSize reqSize;
129
130 std::queue<uint32_t> vacancy;
131 std::string_view type;
132
133 SRWLOCK excl;
134 VkBuffer vkBuffer;
135 void* mapped;
136
137 Bache();
138 Bache(size_t hash,
139 VkDeviceSize align,
141 );
142 Bache& operator=(const Bache& other);
143 template<class T>
144 void Undo(T desc) {
145
146 AcquireSRWLockExclusive(&excl);
147 vacancy.push(desc.id);
148 desc.info.buffer = VK_NULL_HANDLE;
149 refCnt--;
150 ReleaseSRWLockExclusive(&excl);
151
152 };
153
154 template<class T>
155 void Redo(T desc) {
156
157 AcquireSRWLockExclusive(&excl);
158 desc.id = vacancy.front();
159 vacancy.pop();
160 refCnt++;
161 ReleaseSRWLockExclusive(&excl);
162
163 };
164
166
167
168typedef struct TexBache {
169
170 long id;
172 VkDeviceSize align;
173 VkDeviceSize reqAlign;
174
175 VkDeviceSize size;
176 VkDeviceSize reqSize;
177
178 VkDeviceSize offset;
179
180
181 VkFormat format;
182 VkDescriptorBufferInfo info;
183 VkBufferView vkView;
184 VkBuffer vkBuffer;
185 void* mapped;
186
188 memset(this, 0, sizeof(TexBache));
189 buffer.id = -1;
190 vkView = VK_NULL_HANDLE;
191 };
193 dealloc();
194 }
195
196 void dealloc() {
197 if (vkView != VK_NULL_HANDLE) {
198 vkDestroyBufferView($device, vkView, NULL);
199 vkView = VK_NULL_HANDLE;
200 }
201 };
202
203
205
206typedef struct StoBache {
207
208 long id = { -1 };
210 VkDeviceSize align;
211 VkDeviceSize reqAlign;
212
213 VkDeviceSize size;
214 VkDeviceSize reqSize;
215 VkDeviceSize offset;
216 VkFormat format;
217 VkBuffer vkBuffer;
218 VkDescriptorBufferInfo info;
219 std::vector<VkBufferView> view;
220 uint32_t set,binding;
221
222 void* mapped;
223
225 memset(this, 0, sizeof(StoBache));
226 buffer.id = -1;
227 };
228
230 dealloc();
231 };
232 void dealloc() {
233 for (auto& v : view) {
234 if (v != VK_NULL_HANDLE) {
235 vkDestroyBufferView($device, v, NULL);
236 v = VK_NULL_HANDLE;
237 }
238 };
239 view.clear();
240 };
241
242
243 bool operator < (const StoBache& rhs) const {
244 return binding < rhs.binding;
245 }
246
248typedef struct StoBacheArray {
249
250 long id = { -1 };
251 Hache buffer = { -1,0,0 };
252 VkDeviceSize align = 0;
253 VkDeviceSize reqAlign = 0;
254
255 VkDeviceSize size = 0;
256 VkDeviceSize reqSize = 0;
257 VkDeviceSize offset = 0;
258 VkBuffer vkBuffer = VK_NULL_HANDLE;
259 VkFormat format;
260 VkDescriptorBufferInfo info;
261 std::vector<VkDescriptorBufferInfo> infos;
262
263 void* mapped = nullptr;
264
266
267
268namespace DescUniform {
269
270 static inline VkDeviceSize alignedSize(VkDeviceSize sz, VkDeviceSize align)
271 {
272 return ((sz + align - 1) / (align)) * align;
273 };
274 template<typename T>
275 VkDeviceSize alignmentSB(T& bach,VkDeviceSize size,VkDeviceSize _alignment = 0) {
276
277 const VkDeviceSize maxChunk = 512 * 1024 * 1024;
278 if (_alignment == 0) {
279 VkPhysicalDeviceLimits& limits = $properties.limits;
280 _alignment = limits.minStorageBufferOffsetAlignment;
281 }
283 auto alignment = _alignment - (size % _alignment);
284 if (alignment < _alignment)return size + alignment;
285 return size;
286
291
292 };
293
294
295 template<typename T>
296 void appendAlignScalar(T& bach , VkDeviceSize size,int expect = -1) {
297
298 size = alignmentSB(bach, size);
299 VkDescriptorBufferInfo info = {
300 .offset = bach.size,
301 .range = size
302 };
303 bach.infos.push_back(info);
304 if (expect > 0) assert(bach.infos.size() == expect);
305
306 bach.size += size;
307
308 };
309 template<typename T>
310 void setAlignScalar(T& bach) {
311 assert(bach.vkBuffer != VK_NULL_HANDLE);
312 for (auto& info : bach.infos) info.buffer = bach.vkBuffer;
313 };
314};
315
316
317#define $hb hb
318#define $Policy_AllocateMemory Callback_vkAllocateMemory
319#define $Temperance Tempera
320
321
322struct vkDSLMem;
323template<class Mem, size_t Size>
324struct CacheVk;
325
327#define MemType(vk,sz) CacheVk<vk, sz>
328#define MemStatic(vk,sz) CacheVk<vk, sz> vk##Cache##sz
329#define Mem(vk,sz) vk##Cache##sz
330#define MemExtern(vk,sz) extern CacheVk<vk, sz> vk##Cache##sz
331#define MemClear(vk,sz) vk##Cache##sz.clear();
332
333
334
335
336#define OBJ_GEOM(obj) ((obj)->geometry->attributes->buffer)
337
338
339
340namespace fon {
341 struct MSDFfont;
342};
343
344
345
346namespace arth {
347
348 std::string INPUT_String(arth::INPUT type);
349
350};
351
352#endif
struct TexBache TexBache
struct StoBacheArray StoBacheArray
struct Iache Iache
struct Bache Bache
struct Mache Mache
struct StoBache StoBache
#define log_bad(...)
Definition: log.hpp:37
#define log_once(...)
DELETE ALL ^((?!\w).)*log_once(.*; ^((?!\w).)*log_once((.* )+?.*;.
Definition: log.hpp:13
VkDeviceSize alignmentSB(T &bach, VkDeviceSize size, VkDeviceSize _alignment=0)
Definition: incomplete.h:275
void appendAlignScalar(T &bach, VkDeviceSize size, int expect=-1)
Definition: incomplete.h:296
void setAlignScalar(T &bach)
Definition: incomplete.h:310
std::string INPUT_String(arth::INPUT type)
Definition: incomplete.cpp:86
MIVvk depth
Definition: incomplete.h:14
MIVvk color
Definition: incomplete.h:14
long id
Definition: incomplete.h:119
void Undo(T desc)
Definition: incomplete.h:144
VkDeviceSize size
Definition: incomplete.h:126
VkDeviceSize align
Definition: incomplete.h:123
long refCnt
Definition: incomplete.h:120
VkBuffer vkBuffer
Definition: incomplete.h:134
SRWLOCK excl
Definition: incomplete.h:133
void * mapped
Definition: incomplete.h:135
Bache()
Definition: incomplete.cpp:7
VkDeviceSize reqSize
Definition: incomplete.h:128
Hache buffer
Definition: incomplete.h:121
VkDeviceSize reqAlign
Definition: incomplete.h:124
std::queue< uint32_t > vacancy
Definition: incomplete.h:130
VkDeviceSize offset
Definition: incomplete.h:127
std::string_view type
Definition: incomplete.h:131
void Redo(T desc)
Definition: incomplete.h:155
Bache & operator=(const Bache &other)
Definition: incomplete.cpp:41
#include <set>
Definition: ScriptorVk.h:60
VkDescriptorType type
Definition: incomplete.h:51
Iache(size_t hash)
Definition: incomplete.h:58
~Iache()
Definition: incomplete.h:59
static size_t rehash(std::string imgName, size_t seed) noexcept
Definition: incomplete.h:89
VkImageView vkI
Definition: incomplete.h:55
std::string name
Definition: incomplete.h:56
VkImageLayout layout
Definition: incomplete.h:50
void Delete(I *im)
Definition: incomplete.h:107
Iache & operator=(T &iach)
Definition: incomplete.h:71
const size_t hash
Definition: incomplete.h:53
long refCnt
Definition: incomplete.h:52
uint32_t multisample
Definition: incomplete.h:49
Iache()
Definition: incomplete.h:57
VkFormat format
Definition: incomplete.h:48
Hache hach
Definition: incomplete.h:54
Iache & operator=(size_t hash)
Definition: incomplete.h:62
std::string_view type
Definition: incomplete.h:34
VkDeviceSize align
Definition: incomplete.h:40
VkDeviceSize reqAlign
Definition: incomplete.h:41
VkDeviceSize memSize
Definition: incomplete.h:38
Hache mem
Definition: incomplete.h:31
std::vector< VkDeviceSize > sizeSet
Definition: incomplete.h:36
long refCnt
Definition: incomplete.h:30
long id
Definition: incomplete.h:29
VkDeviceSize size
Definition: incomplete.h:35
void * mapped
Definition: incomplete.h:33
VkDeviceSize reqSize
Definition: incomplete.h:39
VkBuffer vkBuffer
Definition: incomplete.h:258
VkDeviceSize reqAlign
Definition: incomplete.h:253
VkDeviceSize align
Definition: incomplete.h:252
VkDeviceSize reqSize
Definition: incomplete.h:256
VkFormat format
Definition: incomplete.h:259
void * mapped
Definition: incomplete.h:263
VkDeviceSize offset
Definition: incomplete.h:257
VkDeviceSize size
Definition: incomplete.h:255
VkDescriptorBufferInfo info
Definition: incomplete.h:260
std::vector< VkDescriptorBufferInfo > infos
Definition: incomplete.h:261
VkBuffer vkBuffer
Definition: incomplete.h:217
uint32_t binding
Definition: incomplete.h:220
VkDeviceSize reqAlign
Definition: incomplete.h:211
VkDeviceSize offset
Definition: incomplete.h:215
void * mapped
Definition: incomplete.h:222
std::vector< VkBufferView > view
Definition: incomplete.h:219
VkFormat format
Definition: incomplete.h:216
VkDeviceSize size
Definition: incomplete.h:213
bool operator<(const StoBache &rhs) const
Definition: incomplete.h:243
VkDeviceSize reqSize
Definition: incomplete.h:214
VkDescriptorBufferInfo info
Definition: incomplete.h:218
void dealloc()
Definition: incomplete.h:232
Hache buffer
Definition: incomplete.h:209
VkDeviceSize align
Definition: incomplete.h:210
uint32_t set
Definition: incomplete.h:220
long id
Definition: incomplete.h:170
VkDescriptorBufferInfo info
Definition: incomplete.h:182
VkBufferView vkView
Definition: incomplete.h:183
VkDeviceSize align
Definition: incomplete.h:172
void dealloc()
Definition: incomplete.h:196
VkBuffer vkBuffer
Definition: incomplete.h:184
void * mapped
Definition: incomplete.h:185
VkDeviceSize reqSize
Definition: incomplete.h:176
VkDeviceSize offset
Definition: incomplete.h:178
Hache buffer
Definition: incomplete.h:171
VkFormat format
Definition: incomplete.h:181
VkDeviceSize reqAlign
Definition: incomplete.h:173
VkDeviceSize size
Definition: incomplete.h:175
std::string_view LayoutType