Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ComputeSystemVKWithAllocator.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#ifdef JPH_USE_VK
8
11
13
16class JPH_EXPORT ComputeSystemVKWithAllocator : public ComputeSystemVK
17{
18public:
20
22 virtual bool CreateBuffer(VkDeviceSize inSize, VkBufferUsageFlags inUsage, VkMemoryPropertyFlags inProperties, BufferVK &outBuffer) override;
23 virtual void FreeBuffer(BufferVK &ioBuffer) override;
24 virtual void * MapBuffer(BufferVK &ioBuffer) override;
25 virtual void UnmapBuffer(BufferVK &ioBuffer) override;
26
27protected:
28 virtual bool InitializeMemory() override;
29 virtual void ShutdownMemory() override;
30
31 uint32 FindMemoryType(uint32 inTypeFilter, VkMemoryPropertyFlags inProperties) const;
32 void AllocateMemory(VkDeviceSize inSize, uint32 inMemoryTypeBits, VkMemoryPropertyFlags inProperties, MemoryVK &ioMemory);
33 void FreeMemory(MemoryVK &ioMemory);
34
35 VkPhysicalDeviceMemoryProperties mMemoryProperties;
36
37private:
38 // Smaller allocations (from cMinAllocSize to cMaxAllocSize) will be done in blocks of cBlockSize bytes.
39 // We do this because there is a limit to the number of allocations that we can make in Vulkan.
40 static constexpr VkDeviceSize cMinAllocSize = 512;
41 static constexpr VkDeviceSize cMaxAllocSize = 65536;
42 static constexpr VkDeviceSize cBlockSize = 524288;
43
44 struct MemoryKey
45 {
46 bool operator == (const MemoryKey &inRHS) const
47 {
48 return mSize == inRHS.mSize && mProperties == inRHS.mProperties;
49 }
50
51 VkDeviceSize mSize;
52 VkMemoryPropertyFlags mProperties;
53 };
54
55 JPH_MAKE_HASH_STRUCT(MemoryKey, MemoryKeyHasher, t.mProperties, t.mSize)
56
57 struct Memory
58 {
59 Ref<MemoryVK> mMemory;
60 VkDeviceSize mOffset;
61 };
62
63 using MemoryCache = UnorderedMap<MemoryKey, Array<Memory>, MemoryKeyHasher>;
64
65 MemoryCache mMemoryCache;
66};
67
69
70#endif // JPH_USE_VK
#define JPH_EXPORT
Definition Core.h:275
#define JPH_NAMESPACE_END
Definition Core.h:425
std::uint32_t uint32
Definition Core.h:503
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_MAKE_HASH_STRUCT(type, name,...)
Definition HashCombine.h:198
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
Simple wrapper class to manage a Vulkan buffer.
Definition BufferVK.h:34
Simple wrapper class to manage a Vulkan memory block.
Definition BufferVK.h:15
Definition Reference.h:107
Definition UnorderedMap.h:30