2
3
4
5
6
10#include "Core/Thread/ThreadPoolBasic.h"
15
16
17
18
19
20
21
22
23
24
31
32
33 using item = std::array<
float, K>;
36
37
41
42
43
51
52
56
57
61
62
66
67
74
75
79
80
86
87
88
89
90
93 std::shared_ptr<std::vector<item>> points ,
98
99
100
101
102
103
106 std::shared_ptr<std::vector<item>> points ,
107 Spices::ThreadPool* threadPool,
112
113
114
115
116
117
125
126
127
128
129
130
131
135 const item& condition ,
136 std::vector<item>& rangePoints ,
141
142
143
144
148
149
150
156
157
164
165
169
170
171
172
173
174
175
176 void insert(
const std::vector<item>& points);
179
180
181
182
183
184
185
186
190
191
192
193
194
195
196
197
201
202
203
204
205
206
207
208
209
212 const item& condition
216
217
218
219
220
221
222
223
230
231
235
236
243 std::shared_ptr<std::vector<item>> points,
247 if (points->size() == 0)
return;
250
251
255
256
257 std::multimap<
float, uint32_t> sorted;
258 if (points->size() <= 512)
260 for (
int i = 0; i < points->size(); i++)
262 sorted.emplace((*points)[i][cd], i);
267 for (
int i = 0; i < 512; i++)
269 uint32_t index =
static_cast<uint32_t>((points->size() - 1) * std::rand() /
static_cast<
float>(RAND_MAX));
270 sorted.emplace((*points)[index][cd], index);
275
276
277 auto centerit = sorted.begin();
278 for (
int i = 0; i < std::floor(sorted.size() * 0.5); i++) ++centerit;
281
282
285 node =
new Node((*points)[centerit->second]);
290 SPICES_CORE_ERROR(
"Cannot insert a KDTree Node which is not empty.");
294
295
296 std::shared_ptr<std::vector<item>> leftPoints = std::make_shared<std::vector<item>>();
297 std::shared_ptr<std::vector<item>> rightPoints = std::make_shared<std::vector<item>>();
299 for (
int i = 0; i < points->size(); i++)
301 if (i == centerit->second)
continue;
302 else if ((*points)[i][cd] <= centerit->first)
304 leftPoints->push_back((*points)[i]);
308 rightPoints->push_back((*points)[i]);
313
314
315 insert_recursive(node->m_Left, leftPoints, depth + 1);
316 insert_recursive(node->m_Right, rightPoints, depth + 1);
322 std::shared_ptr<std::vector<item>> points ,
323 Spices::ThreadPool* threadPool ,
327 constexpr int nPointsWithoutSplitTask = 30000;
329 if (points->size() <= nPointsWithoutSplitTask)
331 const auto in = std::chrono::high_resolution_clock::now();
332 insert_recursive(node, points, depth);
333 const auto out = std::chrono::high_resolution_clock::now();
334 std::cout <<
" Cost: " << std::chrono::duration_cast<std::chrono::milliseconds>(out - in).count() <<
" " << points->size() << std::endl;
339
340
341 if (points->size() == 0)
return;
344
345
349
350
351 std::multimap<
float, uint32_t> sorted;
352 if (points->size() <= 512)
354 for (
int i = 0; i < points->size(); i++)
356 sorted.emplace((*points)[i][cd], i);
361 for (
int i = 0; i < 512; i++)
363 uint32_t index =
static_cast<uint32_t>((points->size() - 1) * std::rand() /
float(RAND_MAX));
364 sorted.emplace((*points)[index][cd], index);
369
370
371 auto centerit = sorted.begin();
372 for(
int i = 0; i < std::floor(sorted.size() * 0.5); i++) ++centerit;
375
376
379 node =
new Node((*points)[centerit->second]);
384 SPICES_CORE_ERROR(
"Cannot insert a KDTree Node which is not empty.");
388
389
390 threadPool->SubmitPoolTask([
this, cd, points, node, threadPool, depth](
float centerVal, uint32_t centerIndex) {
391 std::shared_ptr<std::vector<item>> leftPoints = std::make_shared<std::vector<item>>();
392 for (
int i = 0; i < points->size(); i++)
394 if (i == centerIndex)
continue;
395 else if ((*points)[i][cd] <= centerVal)
397 leftPoints->push_back((*points)[i]);
400 insert_recursive_async(node->m_Left, leftPoints, threadPool, depth + 1);
401 }, centerit->first, centerit->second);
404
405
406 threadPool->SubmitPoolTask([
this, cd, points, node, threadPool, depth](
float centerVal, uint32_t centerIndex) {
407 std::shared_ptr<std::vector<item>> rightPoints = std::make_shared<std::vector<item>>();
408 for (
int i = 0; i < points->size(); i++)
410 if (i == centerIndex)
continue;
411 else if ((*points)[i][cd] > centerVal)
413 rightPoints->push_back((*points)[i]);
416 insert_recursive_async(node->m_Right, rightPoints, threadPool, depth + 1);
417 }, centerit->first, centerit->second);
429
430
437
438
439 if (node->m_Point == point)
445
446
450
451
452 if (point[cd] < node->m_Point[cd])
466 const item& condition ,
467 std::vector<item>& rangePoints ,
472
473
474 if (node ==
nullptr)
return;
477
478
479 bool satisfied =
true;
480 for (
int i = 0; i < K; i++)
482 if (std::abs(node->m_Point[i] - point[i]) > condition[i])
490 rangePoints.push_back(node->m_Point);
494
495
499
500
501 if (std::abs(node->m_Point[cd] - point[cd]) <= condition[cd])
505 range_search_recursive(node->m_Left, point, condition, rangePoints, depth + 1);
509 range_search_recursive(node->m_Right, point, condition, rangePoints, depth + 1);
512 else if (node->m_Point[cd] - point[cd] > 0.0f)
516 range_search_recursive(node->m_Left, point, condition, rangePoints, depth + 1);
523 range_search_recursive(node->m_Right, point, condition, rangePoints, depth + 1);
532
533
534 if (node ==
nullptr)
return;
537
538
539 for (
int i = 0; i < depth; i++)
545 for (size_t i = 0; i < K; i++)
547 std::cout << node->m_Point[i];
553 std::cout <<
")" << std::endl;
556
557
567 if (!node->m_Left && !node->m_Right)
604 insert_recursive(m_Root, std::make_shared<std::vector<item>>(points), 0);
610 std::future<
bool> rval = threadPool->SubmitPoolTask([&]() {
611 insert_recursive_async(m_Root, std::make_shared<std::vector<item>>(points), threadPool, 0);
617
618
631 const item& condition
635 std::vector<kd_tree<K>::item> rangePoints;
636 range_search_recursive(m_Root, point, condition, rangePoints, 0);
638 if (rangePoints.size() == 0)
return {};
641 float nearRate = 1E11;
642 for (
int i = 0; i < rangePoints.size(); i++)
645 for (
int j = 0; j < K; j++)
647 rate += std::abs(rangePoints[i][j] - point[j]);
649 if (rate <= nearRate)
656 return rangePoints[nearIndex];
666 std::vector<kd_tree<K>::item> rangePoints;
667 range_search_recursive(m_Root, point, condition, rangePoints, 0);
#define ASSERT(expr)
Assert macro.
#define PROCESS_INSTANCE_ENTRY
Macros of modify Process instance state.
#define PROCESS_INSTANCE_EXIT
std::string AftermathErrorMessage(GFSDK_Aftermath_Result result)
Helper for checking Nsight Aftermath failures.
bool operator<(const GFSDK_Aftermath_ShaderDebugInfoIdentifier &lhs, const GFSDK_Aftermath_ShaderDebugInfoIdentifier &rhs)
Helper for comparing GFSDK_Aftermath_ShaderDebugInfoIdentifier.
#define SPICES_PROFILE_ZONE
#define VK_FUNCTION_POINTER(function)
Macro for declare function pointer variable in VulkanFunctions.
#define VMA_ALLOCATOR
Use VMA for memory allocate.
Application(const Application &)=delete
Copy Constructor Function.
virtual ~Application()
Destructor Function.
Application & operator=(const Application &)=delete
Copy Assignment Operation.
Application()
Constructor Function.
static void Run()
Run Our World.
Application Class. Our Engine Start here.
virtual bool OnCreatePack(bool isCreateBuffer=true) override
This interface is used for build specific mesh pack data.
uint32_t m_Columns
How much cols number we use.
uint32_t m_Rows
How much rows number we use.
CubePack(uint32_t rows=2, uint32_t columns=2, bool instanced=true)
Constructor Function. Init member variables.
virtual ~CubePack() override=default
Destructor Function.
CubePack Class. This class defines box type mesh pack.
Entity Class. This class defines the specific behaves of Entity.
virtual bool OnCreatePack(bool isCreateBuffer=true) override
This interface is used for build specific mesh pack data.
virtual ~FilePack() override=default
Destructor Function.
FilePack(const std::string &filePath, bool instanced=true)
Constructor Function. Init member variables.
std::string m_Path
The mesh file path in disk.
FilePack Class. This class defines file type mesh pack.
static void CrashDumpDescriptionCallback(PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription addDescription, void *pUserData)
GPU crash dump description callback.
static void Init()
Create single instance of this class.
static constexpr unsigned int c_MarkerFrameHistory
keep four frames worth of marker history.
void WriteShaderDebugInformationToFile(GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier, const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize) const
Helper for writing shader debug information to a file.
void SetMarker(uint64_t &markerId, const std::string &info)
Set Marker.
MarkerMap m_MarkerMap
App-managed marker tracking.
void OnShaderLookup(const GFSDK_Aftermath_ShaderBinaryHash &shaderHash, PFN_GFSDK_Aftermath_SetData setShaderBinary) const
Handler for shader lookup callbacks. This is used by the JSON decoder for mapping shader instruction ...
void SetFrameCut(uint64_t frameCut)
Set FrameCut.
static void OnDescription(PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription addDescription)
Handler for GPU crash dump description callbacks.
virtual ~GpuCrashTracker()
Destructor Function.
static void ShaderSourceDebugInfoLookupCallback(const GFSDK_Aftermath_ShaderDebugName *pShaderDebugName, PFN_GFSDK_Aftermath_SetData setShaderBinary, void *pUserData)
Shader source debug info lookup callback.
static void AftermathDeviceLostCheck()
Aftermath handle device lost function.
void OnResolveMarker(const void *pMarkerData, const uint32_t markerDataSize, void **ppResolvedMarkerData, uint32_t *pResolvedMarkerDataSize)
Handler for app-managed marker resolve callback.
std::mutex m_Mutex
For thread-safe access of GPU crash tracker state.
GpuCrashTracker()
Constructor Function.
static std::unique_ptr< GpuCrashTracker > m_GpuCrashTracker
GpuCrashTracker single instance.
static void ShaderDebugInfoCallback(const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize, void *pUserData)
Shader debug information callback.
bool m_Initialized
Is the GPU crash dump tracker initialized?
std::array< std::map< uint64_t, std::string >, c_MarkerFrameHistory > MarkerMap
static void ShaderDebugInfoLookupCallback(const GFSDK_Aftermath_ShaderDebugInfoIdentifier *pIdentifier, PFN_GFSDK_Aftermath_SetData setShaderDebugInfo, void *pUserData)
Shader debug information lookup callback.
uint32_t m_FrameCut
Frame Count cut.
void OnCrashDump(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize)
Handler for GPU crash dump callbacks from Nsight Aftermath.
void OnShaderDebugInfo(const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize)
Handler for shader debug information callbacks.
void Initialize()
Initialize the GPU crash dump tracker.
static void GpuCrashDumpCallback(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize, void *pUserData)
GPU crash dump callback.
static GpuCrashTracker & Get()
Get single instance of this class.
ShaderDataBase m_ShaderDataBase
The mock shader database.
ShaderDataBase & GetShaderDataBase()
Get ShaderDataBase.
void OnShaderSourceDebugInfoLookup(const GFSDK_Aftermath_ShaderDebugName &shaderDebugName, PFN_GFSDK_Aftermath_SetData setShaderBinary) const
Handler for shader source debug info lookup callbacks. This is used by the JSON decoder for mapping s...
void WriteGpuCrashDumpToFile(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize)
Helper for writing a GPU crash dump to a file.
static void ResolveMarkerCallback(const void *pMarkerData, const uint32_t markerDataSize, void *pUserData, void **ppResolvedMarkerData, uint32_t *pResolvedMarkerDataSize)
App-managed marker resolve callback.
void OnShaderDebugInfoLookup(const GFSDK_Aftermath_ShaderDebugInfoIdentifier &identifier, PFN_GFSDK_Aftermath_SetData setShaderDebugInfo) const
Handler for shader debug information lookup callbacks. This is used by the JSON decoder for mapping s...
static void ShaderLookupCallback(const GFSDK_Aftermath_ShaderBinaryHash *pShaderHash, PFN_GFSDK_Aftermath_SetData setShaderBinary, void *pUserData)
Shader lookup callback.
Implements GPU crash dump tracking using the Nsight Aftermath API.
static std::shared_ptr< spdlog::logger > s_ClientLogger
Game Stage Logger.
static bool m_IsInitialized
static std::shared_ptr< spdlog::logger > s_CoreLogger
Engine Stage Logger.
static void Init()
Init Log.
static std::shared_ptr< spdlog::logger > & GetCoreLogger()
Get Engine Stage Logger.
static std::shared_ptr< spdlog::logger > & GetClientLogger()
Get Game Stage Logger.
static void PostHandle(format_string_t< Args... > fmt, Args &&...args)
Post handle with log message.
static void ShutDown()
Shutdown Log.
static bool SaveDefaultMaterial()
Test function.
static bool Load(const std::string &fileName, Material *outMaterial)
Public called API, it is entrance.
static bool LoadFromSASSET(const std::string &fileName, Material *outMaterial)
Load data from a .sasset file.
static bool LoadFromMaterial(const std::string &fileName, Material *outMaterial)
Load data from a .material file.
This enum defines tree types of material file.
virtual ~MaterialProperties()=default
Destructor Function.
MaterialProperties()
Constructor Function.
Wrapper of material render options.
void BuildMaterial(bool isAutoRegistry=true)
This interface need to be overwritten by specific material. It defines how we build texture and descr...
void PushToTextureParams(const std::string &name, const TextureParam &texture)
Push item to ShaderPath.
const std::vector< std::string > & GetShaderPath(const std::string &stage)
Get material shader path.
scl::linked_unordered_map< std::string, ConstantParams > m_ConstantParams
Constant parameters. Key: parameter name, Value: parameter value.
T GetDefaultConstantParams(const std::string &name)
Get default material constant parameter.
bool m_AlreadyBuild
True if this material already build a buffer.
const std::unordered_map< std::string, std::vector< std::string > > & GetShaderPath() const
Get material shader path.
void UpdateMaterial()
Update material data to buffer.
std::unordered_map< std::string, std::vector< std::string > > m_Shaders
Shader path Key: shader usage, Value: shader file name.
void Deserialize()
Deserialize the data from a disk file(.material) to this class.
void PushToShaderPath(const std::string &name, const std::string &shader)
Push item to ShaderPath.
std::unordered_map< std::string, std::vector< std::string > > m_DefaultShaders
void PushToConstParams(const std::string &name, const ConstantParam ¶m)
Push item to ConstParams.
uint64_t GetMaterialParamsAddress() const
Get material parameter address on GPU.
const std::string & GetName() const
Get Material Path.
scl::runtime_memory_block m_Buffermemoryblocks
m_Buffers's c++ data container. Key: set, Value: scl::runtime_memory_block.
Material()=default
Constructor Function.
scl::linked_unordered_map< std::string, TextureParam > m_DefaultTextureParams
bool GetIsDrawWindow() const
Get boolean of whether draw a material window.
void SetIsDrawWindow(bool isDrawWindow)
Set boolean of whether draw a material window.
scl::linked_unordered_map< std::string, TextureParam > & GetTextureParams()
Get material texture parameters.
void SetName(const std::string &path)
Set material path.
bool m_IsDrawWindow
True if this material needs to draw a window.
scl::linked_unordered_map< std::string, ConstantParams > & GetConstantParams()
Get material constant parameters.
Material(const std::string &materialPath)
Constructor Function. Deserialize immediately. Usually call it.
scl::linked_unordered_map< std::string, TextureParam > m_TextureParams
Texture parameters. Key: parameter name, Value: parameter value.
std::mutex m_Mutex
Mutex of this material.
virtual ~Material()
Destructor Function.
std::unique_ptr< VulkanBuffer > m_MaterialParameterBuffer
MaterialProperties m_Properties
Properties of render options.
std::string m_MaterialPath
void Serialize()
Serialize this class data to a disk file(.material).
Material Class. This class contains a branch of parameter and shader, also descriptor.
MeshLoader Class. This class only defines static function for load data from mesh file.
AccelKHR m_Accel
This meshPack blas accel.
UUID GetUUID() const
Get mesh pack UUID.
std::optional< std::atomic_uint32_t > m_ShaderGroupHandle
specific shader group handle. Used in IndirectDGCPipeline.
void SetHitShaderHandle(uint32_t handle)
Set hit shader Handle.
std::string m_MeshPackName
MeshPack Name.
uint32_t GetNTasks() const
Get NTasks.
void OnDraw(const VkCommandBuffer &commandBuffer) const
Draw indexed.
virtual bool OnCreatePack(bool isCreateBuffer=true)
This interface is used for build specific mesh pack data.
MeshResource m_MeshResource
Mesh Resources.
uint32_t GetShaderGroupHandle() const
Get ShaderGroup Handle, which accessed by gdc buffer.
std::optional< std::atomic_uint32_t > m_HitShaderHandle
specific hit shader handle. Used in RayTracing Pipeline.
void OnDrawMeshTasks(const VkCommandBuffer &commandBuffer) const
Draw Mesh Tasks.
VkDrawMeshTasksIndirectCommandNV m_MeshTaskIndirectDrawCommand
Draw Command.
MeshDesc & GetMeshDesc()
Get Mesh Description.
const std::string & GetPackType() const
Get Pack Type.
uint32_t GetHitShaderHandle() const
Get Hit Shader Handle, which accessed by ray gen shader.
MeshPack(const std::string &name, bool instanced)
Constructor Function.
bool HasBlasAccel()
Is this meshPack has a valid blas.
std::string m_PackType
specific mesh pack type.
void CreateBuffer()
Create Vertices buffer anf Indices buffer.
VulkanRayTracing::BlasInput MeshPackToVkGeometryKHR()
Convert MeshPack into the ray tracing geometry used to build the BLAS.
std::atomic_bool m_IsRequiredAccel
True if required accel by BLAS Build.
void OnBind(const VkCommandBuffer &commandBuffer) const
Bind VBO and EBO.
MeshDesc m_Desc
Mesh Description.
std::shared_ptr< Material > GetMaterial()
Get material in this class.
const VkDrawMeshTasksIndirectCommandNV & GetDrawCommand() const
Get Draw Command.
void SetMaterial(std::shared_ptr< Material > material)
Set specific material for this class.
MeshPack & operator=(const MeshPack &)=delete
Copy Constructor Function.
void SetShaderGroupHandle(uint32_t handle)
Set hit shader Handle.
const MeshResource & GetResource() const
Get Resource.
std::shared_ptr< Material > m_Material
specific material pointer.
void SetMaterial(const std::string &materialPath)
Set specific material for this class.
uint32_t m_NTasks
Task Shader Work Group Size.
virtual ~MeshPack()=default
Destructor Function.
UUID m_UUID
UUID for mesh pack.
const std::vector< Meshlet > & GetMeshlets() const
Get Meshlets array.
MeshPack(const MeshPack &)=delete
Copy Constructor Function.
bool m_Instanced
If this mesh pack needs instanced.
AccelKHR & GetAccel()
Get this accel.
MeshPack Class. This class defines some basic behaves and variables. This class need to be inherited ...
static bool PackPrimVerticesFromSparseInputs(MeshPack *meshPack, const std::vector< glm::uvec3 > primVertices, std::vector< glm::vec3 > &packPoints, std::vector< glm::uvec3 > &packPrimPoints, std::unordered_map< uint32_t, uint32_t > &primVerticesMapReverse)
Pack PrimVertices from Sparse PrimVertices Inputs.
static SpicesShader::Sphere CalculateBoundSphere(const std::vector< glm::vec3 > &points)
Calculate BoundSphere from Points.
static bool FindBoundaryPoints(MeshPack *meshPack, const std::vector< glm::uvec3 > &primVertices, std::unordered_map< uint32_t, bool > &boundaryPoints, std::unordered_map< uint32_t, bool > &stableBoundaryPoints, std::unordered_map< uint32_t, EdgePoint > &boundaryEdgePoints, std::unordered_map< uint32_t, std::unordered_map< uint32_t, bool > > &pointConnect)
Find Points located in Boundaries.
static bool MergeByDistance(MeshPack *meshPack, std::vector< glm::uvec3 > &primVertices, scl::kd_tree< 6 > &kdTree, float maxDistance, float maxUVDistance)
Merge Vertex by Distance.
static void GenerateMeshLodClusterHierarchy(MeshPack *meshPack)
Generate Mesh Lod Resources.
static bool PackVertexToPoints(MeshPack *meshPack, const std::vector< glm::uvec3 > &primVertices, std::vector< glm::vec3 > &points)
Pack Vertices to Points.
static bool UnPackPrimVerticesToSparseInputs(std::vector< glm::uvec3 > &primVertices, std::unordered_map< uint32_t, uint32_t > &primVerticesMapReverse, const std::vector< glm::uvec3 > &packPrimPoints)
Unpack PrimVertices to Sparse PrimVertices Inputs.
static void AppendMeshlets(MeshPack *meshPack, uint32_t lod, const SpicesShader::Sphere &clusterBoundSphere, const std::vector< glm::uvec3 > &primVertices)
Create and Append Meshlets to MeshPack use given indices.
static std::vector< MeshletGroup > GroupMeshlets(MeshPack *meshPack, std::vector< Meshlet > &meshlets)
Split Meshlets to Groups.
static bool BuildKDTree(MeshPack *meshPack, const std::vector< glm::uvec3 > &primVertices, scl::kd_tree< 6 > &kdTree)
Build KDTree use specific meshlets.
Class for provide functions of process Meshpack.
uint32_t m_Columns
How much cols number we use.
uint32_t m_Rows
How much rows number we use.
virtual bool OnCreatePack(bool isCreateBuffer=true) override
This interface is used for build specific mesh pack data.
PlanePack(uint32_t rows=2, uint32_t columns=2, bool instanced=true)
Constructor Function. Init member variables.
virtual ~PlanePack() override=default
Destructor Function.
PlanePack Class. This class defines plane type mesh pack.
ResourcePool()=default
Constructor Function.
ResourcePool & operator=(const ResourcePool &)=delete
Copy Constructor Function.
static bool Has(const std::string &name)
Determine if specific resource is exist.
static std::shared_ptr< T > Load(const std::string &path, Args... args)
Load a resource by path. When we need a resource, we call this API. Load if resource is not found.
static void Registry(const std::string &name, std::shared_ptr< T > resource)
Registry a resource to this Pool.
static void Destroy()
Destroy this resource pool. Release all Resource Pointer, which means resource can be destructed afte...
ResourcePool(const ResourcePool &)=delete
Copy Constructor Function.
virtual ~ResourcePool()=default
Destructor Function.
static void UnLoad(const std::string &path)
UnLoad a resource by path.
static std::shared_ptr< T > Access(const std::string &path)
Access a resource by path directly. Do nothing if resource is not found.
static std::unordered_map< std::string, std::unique_ptr< Resource > > m_Resources
Static variable stores all specific resources in a basic type Pool.
static std::shared_mutex m_Mutex
Mutex for this pool.
Template ResourcePool Class. This class will assign Every Type of Resource per Pool....
virtual ~Resource()
Unload resource.
Resource(std::function< std::any()> fn)
Constructor Function.
std::any m_Resource
Resource instance wrapper.
void UnLoad()
UnLoad this resource.
std::function< std::any()> m_CreateFunction
Resource create function.
ResourceStateEnum
Enum of ResourceState.
std::shared_ptr< T > GetResource()
Get resource instance.
ResourceStateEnum m_State
Resource state.
std::mutex m_Mutex
Mutex of this resource.
ResourceStateEnum GetState() const
Get resource state.
void CreateResource()
Create resource instance.
Resource Wrapper of ResourceInstance.
static VkShaderStageFlagBits ToFlagBits(ShaderStage stage)
Convert ShaderStage to VkShaderStageFlagBits.
static std::string ToString(ShaderStage stage)
Convert ShaderStage to String.
static shaderc_shader_kind ToShaderCKind(ShaderStage stage)
Convert ShaderStage to shaderc_shader_kind.
static ShaderStage ToStage(std::string stage)
Convert String to ShaderStage.
SpherePack(uint32_t rows=15, uint32_t columns=24, bool instanced=true)
Constructor Function. Init member variables.
uint32_t m_Rows
How much rows number we use.
virtual ~SpherePack() override=default
Destructor Function.
virtual bool OnCreatePack(bool isCreateBuffer=true) override
This interface is used for build specific mesh pack data.
uint32_t m_Columns
How much cols number we use.
SpherePack Class. This class defines sphere type mesh pack.
Texture2DCube Class. This class defines the basic behaves of Texture2DCube.
Texture2D(const RendererResourceCreateInfo &info)
Constructor Function. Used for create render resource.
Texture2D(const std::string &path)
Constructor Function. Init class variable, load date immediately. Usually call it.
virtual ~Texture2D() override=default
Destructor Function.
Texture2D()=default
Constructor Function.
Texture2D Class. This class defines the basic behaves of texture2D.
static void Load(const std::string &fileName, Texture2DCube *outTexture)
Load image to a Texture2DCube object.
static void Load(const std::string &fileName, Texture2D *outTexture)
Load image to a Texture2D object.
static bool LoadSrc(const std::string &fileName, const std::string &it, Texture2D *outTexture, bool isCreateCompressTexture=true)
Function of load a src file.
static bool SearchFile(const std::string &fileName, std::function< void(const std::string &)> binF, std::function< void(const std::string &)> srcF)
Search texture file and load.
static bool LoadBin(const std::string &fileName, const std::string &it, Texture2D *outTexture)
Function of load a ktx file.
TextureLoader Class. This class only defines static function for load data from image file.
virtual ~Texture()=default
Destructor Function.
std::string m_ResourcePath
Texture's path in disk.
Texture(const std::string &path)
Constructor Function. Init class variable. Usually call it.
Texture()=default
Constructor Function.
std::shared_ptr< T > GetResource()
Get Specific resource, usually is a wrapper of VulkanImage.
std::any m_Resource
Texture's resource, coule be any kind of type.
Texture Class. This class defines the basic behaves of texture. When we add an new Texture,...
float m_FrameTime
time step(s) during frames.
std::chrono::steady_clock::time_point m_StartTime
Engine Start time.
void Flush()
Refresh time in each engine loop.
const float & ft() const
Get time step during frames.
TimeStep(const TimeStep &)=delete
Copy Constructor Function.
const uint64_t & fs() const
Get frames count.
TimeStep()
Constructor Function.
virtual ~TimeStep()=default
Destructor Function.
std::chrono::steady_clock::time_point m_LastTime
Last frame time.
float m_GameTime
time step(s) since Engine Start.
uint64_t m_Frames
Frames since Engine Start.
TimeStep & operator=(const TimeStep &)=delete
Copy Assignment Operation.
const float & gt() const
Get time step since Engine Start.
This Class handles our engine time step during frames. Global Unique.
static TracyGPUContext & Get()
Get this Single Instance.
static std::shared_ptr< TracyGPUContext > m_TracyGPUContext
This Single Instance.
virtual ~TracyGPUContext()=default
Destructor Function.
tracy::VkCtx * m_Context
Tracy Vulkan Context.
TracyGPUContext(VulkanState &state)
Constructor Function.
VulkanState & m_VulkanState
VulkanState.
tracy::VkCtx *& GetContext()
Get Context.
static void CreateInstance(VulkanState &state)
Create this Single Instance.
Wapper of Tracy GPU collect features.
UUID()
Constructor Function.
UUID(uint64_t uuid)
Constructor Function.
UUID(const UUID &)=default
Destructor Function.
std::string ToString()
Transform UUID to String.
operator uint64_t() const
Operator Function.
This class helps to generate a uuid for one resource.
VkBufferUsageFlags m_Usage
The buffer usage.
VkMemoryPropertyFlags m_Flags
The buffer memory requirement flags.
VkBuffer m_Buffer
The buffer this class handled.
void CreateBuffer(VulkanState &vulkanState, const std::string &name, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
Create a buffer.
VulkanBuffer(VulkanState &vulkanState, const std::string &name, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
Constructor Function. Create VkBuffer.
VmaAllocation m_Alloc
VMA allocation.
uint64_t GetSize() const
Get Buffer Size.
void CopyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size)
Copy data from a buffer to another.
void WriteToBuffer(const void *data, VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
Write data to buffer.
VkDeviceSize m_DeviceSize
The buffer size.
VkDeviceAddress & GetAddress()
Get VkBuffer Address.
void Map(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
Map buffer video memory to a local memory.
void WriteFromBuffer(void *data, VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
Write data from buffer.
VkDescriptorBufferInfo * GetBufferInfo(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
Get VkDescriptorBufferInfo.
virtual ~VulkanBuffer() override
Destructor Function.
VkDescriptorBufferInfo m_BufferInfo
VkDescriptorBufferInfo.
std::string m_Name
Buffer Name.
VkDeviceAddress m_BufferAddress
The buffer gpu address.
VulkanBuffer(VulkanState &vulkanState)
Constructor Function. Create VkBuffer.
VkBuffer & Get()
Get VkBuffer.
void Flush(VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
Flush the buffer's video memory data.
This Class is a Wrapper of VulkanBuffer.
static void EndLabel(VkCommandBuffer cmdBuffer)
End Record Commands with a Label.
static void BeginLabel(VkCommandBuffer cmdBuffer, const std::string &caption, glm::vec4 color=glm::vec4(1.0f))
Start Record Commands with a Label.
static void BeginQueueLabel(VkQueue queue, const std::string &caption, glm::vec4 color=glm::vec4(1.0f))
Start Record Queue with a Label.
static void SetObjectName(VkObjectType type, uint64_t handle, VkDevice &device, const std::string &caption)
Set Vulkan Object with a name, which can be captured.
static void InsertQueueLabel(VkQueue queue, const std::string &caption, glm::vec4 color=glm::vec4(1.0f))
Insert Record Queue with a Label.
static void SetObjectTag(VkObjectType type, uint64_t handle, VkDevice &device, const std::vector< char * > &captions)
Set Vulkan Object with tags, which can be captured.
static void InsertLabel(VkCommandBuffer cmdBuffer, const std::string &caption, glm::vec4 color=glm::vec4(1.0f))
Insert Record Commands with a Label.
static void EndQueueLabel(VkQueue queue)
End Record Queue with a Label.
This Class Defines static function for helping vulkan debug.
VulkanObject(const VulkanObject &)=delete
Copy Constructor Function.
virtual ~VulkanObject()=default
Destructor Function. We destroy pipeline layout here.
VulkanObject & operator=(const VulkanObject &)=delete
Copy Assignment Operation.
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
VulkanObject Class. This class defines the basic behaves of VulkanObject. When we create an new Vulka...
VkPipelineShaderStageCreateInfo GetShaderStageCreateInfo() const
virtual ~VulkanShaderModule() override
Destructor Function.
ShaderStage m_ShaderStage
std::string GetShaderPath(const std::string &name, const std::string &shaderType)
Get shader path string.
VkShaderModule m_ShaderModule
The VkShaderModule this class handled.
VkShaderModule & Get()
Get VkShaderModule this class handled.
VulkanShaderModule(VulkanState &vulkanState, const std::string &shaderName, const std::string &shaderStage)
Constructor Function. Create VkShaderModule.
VulkanShaderModule(VulkanState &vulkanState, const std::string &shaderName, const ShaderStage &shaderStage, const std::vector< uint8_t > &spirv, const std::string &fullPath)
Constructor Function. Create VkShaderModule.
This Class is a Wrapper of VkShaderModule.
static void CreateMeshEntity(World *world, const std::string &name, const std::shared_ptr< Mesh > &mesh, std::function< void(Entity &)> onAdded=nullptr)
Create Entity with MeshComponent. Lightweight for game thread.
static void CreateMeshEntity(World *world, const std::string &name, std::function< std::shared_ptr< Mesh >()> onMeshCreated, std::function< void(Entity &)> onAdded=nullptr)
Create Entity with a Basic MeshComponent Async.
WorldMarkFlags GetMarker() const
Get WorldMarkFlags this frame.
void ViewComponent(const std::vector< uint32_t > &ranges, uint32_t floor, uint32_t ceil, F &&fn)
View all component in this world in ranges.
void Mark(WorldMarkFlags flags)
Mark WorldMarkFlags with flags.
Entity CreateEntity(const std::string &name="None")
Create a new empty entity in this world.
void OnComponentAdded(Entity *entity, T &component)
Called On any Component Added to this world.
void ReserMark()
Reset WorldMarkFlags to Clean.
void ViewRoot(F &&fn)
View all root in this world.
Entity CreateEmptyEntity(UUID uuid)
Entity CreateEntityWithUUID(UUID uuid, const std::string &name="None")
Create a new empty entity with a uuid in this world.
void ViewComponent(F &&fn)
View all component in this world.
void ViewComponent(const std::vector< uint32_t > &ranges, F &&fn)
View all component in this world in ranges.
virtual void OnDeactivate()=0
This interface defines the specific world behaves after on activated.
virtual ~World()=default
Destructor Function.
Entity QueryEntitybyID(uint32_t id)
Get World Entity by id(entt::entity).
virtual void OnPreActivate()=0
This interface define the specific world behaves before on activated.
entt::registry m_Registry
This variable handles all entity.
std::shared_mutex m_Mutex
Mutex for world.
void DestroyEntity(Entity &entity)
Destroy a entity from this world.
T & GetComponent(entt::entity e)
Get Component owned by this entity.
void RemoveComponent(entt::entity e)
Remove Component owned from this entity.
WorldMarkFlags m_Marker
World State this frame.
entt::registry & GetRegistry()
Get Registry variable.
void RemoveFromRoot(Entity &entity)
Remove a entity from this world root.
virtual void OnActivate(TimeStep &ts)=0
This interface define the specific world behaves on activated.
void AddToRoot(Entity &entity)
Add a entity to this world root.
World()=default
Constructor Function.
std::unordered_map< UUID, entt::entity > m_RootEntityMap
This variable is a cache. @noto Not in use now.
bool IsRootEntity(Entity &entity)
Determine if a entity is in root.
void ClearMarkerWithBits(WorldMarkFlags flags)
Clear WorldMarkFlags with flags.
bool HasComponent(entt::entity e)
If Component is owned by this entity or not.
T & AddComponent(entt::entity e, Args &&... args)
Template Function. Used for add specific component to entity.
World Class. This class defines the basic behaves of World. When we create an new world,...
virtual ~kd_tree()
Destructor Function.
void insert_recursive_async(Node *&node, std::shared_ptr< std::vector< item > > points, Spices::ThreadPool *threadPool, int depth)
Recursive function to insert a point into the kd_tree async.
size_t size() const
Get KD Tree size.
kd_tree()
Constructor to initialize the kd_tree with a null root.
void insert_async(const std::vector< item > &points, Spices::ThreadPool *threadPool)
Insert a point into the kd_tree async. Start at the root, comparing the new point’s first dimension w...
void insert_recursive(Node *&node, std::shared_ptr< std::vector< item > > points, int depth)
Recursive function to insert a point into the kd_tree.
void print() const
Public function to print the kd_tree.
std::atomic_size_t m_Size
Sizes of this kd tree.
Node * m_Root
Pointer to the root node of the tree.
void insert(const std::vector< item > &points)
Insert a point into the kd_tree. Start at the root, comparing the new point’s first dimension with th...
void range_search_recursive(Node *node, const item &point, const item &condition, std::vector< item > &rangePoints, int depth) const
Recursive function to search for all nearest points in the kd_tree.
void deletenode_recursive(Node *node)
Delete all node created by this ke_tree.
bool search_recursive(Node *node, const item &point, int depth) const
Recursive function to search for a point in the kd_tree.
auto nearest_neighbour_search(const item &point, const item &condition) const -> item
Search for a nearest point in the kd_tree. Traverse the tree as in a normal search to find the leaf n...
auto range_search(const item &point, const item &condition) const -> std::vector< item >
Search for all points within given range. Start at the root. If the current node is within the range,...
bool search(const item &point) const
Search for a point in the kd_tree. Start at the root, comparing the search point’s first dimension wi...
void print_recursive(Node *node, int depth) const
Recursive function to print the kd_tree.
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...
void erase(const K &key)
Remove a element inside the container if founded by key.
V * find_value(const K &key)
Find the value by key.
void clear()
Clear this container's data.
V * prev_value(const K &key)
Get the previous element by the key.
std::shared_mutex m_Mutex
Mutex for this container.
void for_each(F &&fn)
Iter the container in order.
linked_unordered_map()
Constructor Function.
std::unordered_map< K, V > m_Map
void push_back(const K &key, const V &value)
Add a element to this container.
V * end()
Get the end element of this container.
bool has_key(const K &key)
Determine whether the key is in the container.
size_t size()
The container's element size.
void for_each(F &fn)
Iter the container in order.
std::list< K > m_Keys
The container keeps iter in order.
virtual ~linked_unordered_map()=default
Destructor Function.
std::atomic_int m_Size
This container size.
bool has_equal_size()
Determine whether the container's element size is same.
V * next_value(const K &key)
Get the next element by the key.
V * first()
Get the first element of this container.
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...
size_t bytes_
The bytes of the continue memory block handled.
bool has_value(const std::string &name)
Determine is item inside this container.
void for_each(const std::function< bool(const std::string &name, void *pt)> &fn) const
Iter the object_ and call explain_element() to filling data.
std::unordered_map< std::string, size_t > object_
The data information of the continue memory block handled. Data: parameter name - parameter position ...
void build()
Malloc a memory to begin_.
void add_element(const std::string &name, const std::string &type)
Add a element to object_, means a memory block will be occupied with given param type.
size_t item_location(const std::string &name)
Get item location in blocks.
size_t get_bytes() const
Get the bytes_.
virtual ~runtime_memory_block()
Destructor Function.
size_t size() const
Get the size of object_.
void * begin_
The begin pointer of the continue memory block handled.
void explain_element(const std::string &name, const T &value)
Fill in a memory with given data.
runtime_memory_block()=default
Constructor Function.
void * get_addr() const
Get the begin_.
T & get_value(const std::string &name)
Get value that explained by name.
The container is wrapper of a continue memory block. Used in Material::BuildMaterial(),...
ShaderStage
enum of shader stage.
static const char * memoryPoolNames[3]
MemoryPool's name.
glm::mat4 OtrhographicMatrix(float left, float right, float top, float bottom, float nearPlane, float farPlane)
Calculate Otrhographic Matrix.
glm::mat4 PerspectiveMatrixInverseZ(float fov, float nearPlane, float aspectRatio)
Calculate Perspective Matrix(reverse z version).
glm::mat4 PerspectiveMatrix(float fov, float nearPlane, float farPlane, float aspectRatio)
Calculate Perspective Matrix.
bool DecomposeTransform(const glm::mat4 &transform, glm::vec3 &outTranslation, glm::vec3 &outRotation, glm::vec3 &outScale)
Decompose matrix to split SRT transform.
TextureType
The enum of all Texture Type.
std::shared_ptr< World > CreateWorld()
extern WorldCreation definition in Game.
static void HandleVkResult(VkResult result)
Handle VkResult Function.
constexpr uint32_t MaxFrameInFlight
Max In Flight Frame. 2 buffers are enough in this program.
std::string to_string(const GFSDK_Aftermath_ShaderDebugInfoIdentifier &identifier)
Convert GFSDK_Aftermath_ShaderDebugInfoIdentifier to string.
std::string to_string(GFSDK_Aftermath_Result result)
Convert GFSDK_Aftermath_Result to string.
std::string to_hex_string(T n)
Convert T to hex string.
MeshResource's item template.
This struct's data is defined from .material file.
ConstantParam defaultValue
This struct's data is defined from .material file.
EdgePoint(uint32_t prev, uint32_t self, uint32_t next)
Constructor Function.
bool valid()
Determine whether this edge point is valid.
EdgePoint()
Constructor Function.
EdgePoint Class. This class defines what EdgePoint data.
Edge()=default
Constructor Function.
bool operator==(const Edge &other) const
Destructor Function. @attemtion Why Destructor causes bug here.
Edge(uint32_t f, uint32_t s)
Constructor Function.
bool operator<(const Edge &other) const
Less Operation.
Edge Class. This class defines what Edge data.
bool operator<(const HalfEdge &other) const
Less Operation.
HalfEdge()=default
Constructor Function.
bool operator==(const HalfEdge &other) const
Destructor Function. @attemtion Why Destructor causes bug here.
HalfEdge(uint32_t f, uint32_t s)
Constructor Function.
HalfEdge Class. This class defines what HalfEdge data.
uint32_t primVertexOffset
MeshDesc()
Constructor Function.
MeshDesc Copy() const
Copy a MeshDesc from this.
uint64_t GetBufferAddress() const
Get m_Buffer's Address.
Add Construction Functions to SpicesShader::MeshDesc.
MeshResource()=default
Constructor Function.
Positions positions
Declare value.
PrimitiveVertices primitiveVertices
PrimitiveLocations primitiveLocations
PrimitivePoints primitivePoints
virtual ~MeshResource()=default
Destructor Function.
void CreateBuffer(const std::string &name)
Create MeshResource Buffers.
std::vector< size_t > meshlets
MeshletGroup for simplify.
void FromMeshopt(const meshopt_Meshlet &m, const meshopt_Bounds &bounds)
Destructor Function. @attemtion Why Destructor causes bug here.
Meshlet()=default
Constructor Function.
Meshlet Class. This class defines what Meshlet data.
This struct defines the data used to create a texture2d. From render pass.
static constexpr char const * name
static constexpr uint32_t id
Define a named category tag type.
static constexpr char const * name
Define a custom domain tag type.
static constexpr char const * message
Define a registered string tag type.
String2()=default
Constructor Function.
std::string x
x component.
std::string y
y component.
virtual ~String2()=default
Destructor Function.
String2(const std::string &str0, const std::string &str1)
Constructor Function.
bool operator==(const String2 &other) const
equal operation.
This struct's data is defined from .material file.
UInt2()=default
Constructor Function.
bool operator==(const UInt2 &other) const
equal operation.
virtual ~UInt2()=default
Destructor Function.
UInt2(const uint32_t &x, const uint32_t &y)
Constructor Function.
void Init(VkInstance instance)
Init All Vulkan Function Pointer.
Vulkan Function Pointers Collection. It holds all function pointer which need get manually.
VulkanState(const VulkanState &)=delete
Copy Constructor Function.
VkSwapchainKHR m_SwapChain
VkCommandPool m_GraphicCommandPool
std::array< VkSemaphore, MaxFrameInFlight > m_ComputeQueueSemaphore
VmaAllocator m_VmaAllocator
std::array< VkImage, MaxFrameInFlight > m_SwapChainImages
std::array< VkImageView, MaxFrameInFlight > m_SwapChainImageViews
std::array< VkSemaphore, MaxFrameInFlight > m_GraphicQueueSemaphore
std::array< VkFence, MaxFrameInFlight > m_ComputeFence
std::array< VkSampler, MaxFrameInFlight > m_SwapChainImageSamplers
uint32_t m_ComputeQueueFamily
std::array< VkCommandBuffer, MaxFrameInFlight > m_GraphicCommandBuffer
uint32_t m_GraphicQueueFamily
VulkanState()=default
Constructor Function.
std::array< VkSemaphore, MaxFrameInFlight > m_GraphicImageSemaphore
std::array< VkCommandBuffer, MaxFrameInFlight > m_ComputeCommandBuffer
VkPhysicalDevice m_PhysicalDevice
VkCommandPool m_ComputeCommandPool
std::array< VkFence, MaxFrameInFlight > m_GraphicFence
VulkanState & operator=(const VulkanState &)=delete
Copy Assignment Operation.
This struct contains all Vulkan object in used global.
virtual ~Node()
Destructor Function.
Node * m_Right
Pointer to right child.
Node * m_Left
Pointer to left child.
Node(const item &pt)
Constructor Function.
item m_Point
Array to store the coordinates.
size_t operator()(Spices::EdgePoint const &edgeP) const
size_t operator()(Spices::Edge const &edge) const
size_t operator()(Spices::HalfEdge const &edge) const
size_t operator()(Spices::String2 const &info) const noexcept
size_t operator()(Spices::UInt2 const &info) const noexcept
std::size_t operator()(const Spices::UUID &uuid) const noexcept