VulkanRaytracingCycles 0.0.0
Cycles Render Engine With VulkanRaytracingShaderModules. ( Experiment , in progress)
vkmm::MemoryVk Struct Reference

#include <MemoryVk.h>

Public Types

typedef tbb::concurrent_unordered_map< std::string, BufferAllocation, std::hash< std::string >, std::equal_to< std::string >, front::tbbTAllocatortb_umapBA
 
typedef std::function< bool(BufferAllocation &balloc)> mapcbTy
 

Public Member Functions

 MemoryVk ()
 
 ~MemoryVk ()
 
template<class T >
void destroy (T *ptr)
 
template<typename T = mapcbTy>
void createBuffer (const char *name, VkDeviceSize size, VkBufferUsageFlags bflags, MemoryUsage mflag, T cb)
 
void deleteBuffer (std::string name)
 
void initialize ()
 
void deinitialize ()
 

Public Attributes

SRWLOCK slim
 
tb_umapBA bamp
 
vkmm::AllocatorCreateInfo allocInfo = {}
 

Detailed Description

Definition at line 46 of file MemoryVk.h.

Member Typedef Documentation

◆ mapcbTy

typedef std::function<bool(BufferAllocation& balloc)> vkmm::MemoryVk::mapcbTy

Definition at line 56 of file MemoryVk.h.

◆ tb_umapBA

typedef tbb::concurrent_unordered_map<std::string, BufferAllocation, std::hash<std::string>, std::equal_to<std::string>, front::tbbTAllocator> vkmm::MemoryVk::tb_umapBA

Definition at line 49 of file MemoryVk.h.

Constructor & Destructor Documentation

◆ MemoryVk()

vkmm::MemoryVk::MemoryVk ( )
inline

Definition at line 60 of file MemoryVk.h.

60 {
61 InitializeSRWLock(&slim);
62 };
SRWLOCK slim
Definition: MemoryVk.h:48

◆ ~MemoryVk()

vkmm::MemoryVk::~MemoryVk ( )
inline

Definition at line 63 of file MemoryVk.h.

63{};

Member Function Documentation

◆ createBuffer()

template<typename T = mapcbTy>
void vkmm::MemoryVk::createBuffer ( const char *  name,
VkDeviceSize  size,
VkBufferUsageFlags  bflags,
MemoryUsage  mflag,
cb 
)
inline

BufferInfo.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;

| vkmm::ALLOCATION_CREATE_MAPPED_BIT;

Definition at line 86 of file MemoryVk.h.

89 {
90
91
92 BufferAllocation balloc = {};
93
94 VkBufferCreateInfo BufferInfo = {};
95 BufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
96 BufferInfo.size = size;
98 BufferInfo.usage = bflags;
99
102 ainfo.usage = mflag; // vkmm::MEMORY_USAGE_GPU_ONLY; //vkmm::MEMORY_USAGE_CPU_TO_GPU;
103 ainfo.pool = VK_NULL_HANDLE;
104 ainfo.memoryTypeBits = 0;
105 ainfo.requiredFlags = 0;
106 ainfo.preferredFlags = 0;
107
108 strcpy(ainfo.name, name);
109 assert(bamp.count(name) == 0);
110
111 vkmm::CreateBuffer($pallocator, &BufferInfo, ainfo, &balloc.buffer, &balloc.alloc, NULL);
112
113 cb(balloc);
114 bamp[name] = balloc;
115
116 };
@ ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
Definition: AllocatorVk.h:609
VkResult CreateBuffer(Allocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, AllocationCreateInfo &pAllocationCreateInfo, VkBuffer *pBuffer, Allocation *pAllocation, AllocationInfo *pAllocationInfo)
VkMemoryPropertyFlags requiredFlags
Definition: AllocatorVk.h:633
VkMemoryPropertyFlags preferredFlags
Definition: AllocatorVk.h:635
AllocationCreateFlags flags
Use #VmaAllocationCreateFlagBits enum.
Definition: AllocatorVk.h:629
tb_umapBA bamp
Definition: MemoryVk.h:52

◆ deinitialize()

void vkmm::MemoryVk::deinitialize ( )
inline

Definition at line 156 of file MemoryVk.h.

156 {
157
158
159 printf(" leaking memory %zu ", bamp.size());
160 std::for_each(bamp.begin(), bamp.end(), [&](auto& p)
161 {
162
163 auto ba = p.second;
164 printf(" leaking memory be released. NAME [ %s] SIZE %zu \n ",(const char*)(p.first.c_str()), ba.alloc->GetSize()) ;
165 vkmm::UnmapMemory($pallocator, ba.alloc);
166 vkmm::DestroyBuffer($pallocator, ba.buffer, ba.alloc);
167
168 });
169
170 bamp.clear();
171 destroy($pallocator);
172 };
void destroy(T *ptr)
Definition: MemoryVk.h:66

◆ deleteBuffer()

void vkmm::MemoryVk::deleteBuffer ( std::string  name)
inline

Definition at line 119 of file MemoryVk.h.

119 {
120
121 if (bamp.count(name) > 0) {
122
123 auto ba = bamp[name];
124 AcquireSRWLockExclusive(&slim);
125 bamp.unsafe_erase(name);
126 ReleaseSRWLockExclusive(&slim);
127
128 vkmm::UnmapMemory($pallocator, ba.alloc);
129 vkmm::DestroyBuffer($pallocator, ba.buffer, ba.alloc);
130
131
132 }
133 }
void DestroyBuffer(Allocator allocator, VkBuffer buffer, Allocation allocation)
void UnmapMemory(Allocator allocator, Allocation allocation)

◆ destroy()

template<class T >
void vkmm::MemoryVk::destroy ( T *  ptr)
inline

Definition at line 66 of file MemoryVk.h.

66 {
67
68
69 if (ptr != nullptr)
70 {
71 ptr->~T();
72 if ((allocInfo.pAllocationCallbacks != nullptr) &&
74 {
76 }
77 else
78 {
79 _aligned_free(ptr);
80 }
81 }
82
83 };
const VkAllocationCallbacks * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: AllocatorVk.h:560
vkmm::AllocatorCreateInfo allocInfo
Definition: MemoryVk.h:55

◆ initialize()

void vkmm::MemoryVk::initialize ( )
inline

Definition at line 136 of file MemoryVk.h.

136 {
137
138 $Policy_AllocateMemory.pUserData = &$Temperance; // I don't care
139 $Policy_AllocateMemory.pfnAllocation = &VK_TB_AllocationFunction;
140 $Policy_AllocateMemory.pfnReallocation = &VK_ReallocationFunction;
141 $Policy_AllocateMemory.pfnFree = &VK_TB_FreeFunction;
142
143 $Policy_AllocateMemory.pfnInternalAllocation = nullptr;
144 $Policy_AllocateMemory.pfnInternalFree = nullptr;
145
146
148 allocInfo.pHeapSizeLimit = (VkDeviceSize*)HeapLimit;
149 allocInfo.preferredLargeHeapBlockSize = preferredLargeHeapBlock;
152 $pallocator = new(vkmm::Allocate<Allocator_T>(allocInfo.pAllocationCallbacks))(Allocator_T)(&allocInfo);
153
154
155 }
AllocatorCreateFlags flags
Flags for created allocator. Use #VmaAllocatorCreateFlagBits enum.
Definition: AllocatorVk.h:554
const VkDeviceSize * pHeapSizeLimit
Definition: AllocatorVk.h:565
VkDeviceSize preferredLargeHeapBlockSize
Definition: AllocatorVk.h:557

Member Data Documentation

◆ allocInfo

vkmm::AllocatorCreateInfo vkmm::MemoryVk::allocInfo = {}

Definition at line 55 of file MemoryVk.h.

◆ bamp

tb_umapBA vkmm::MemoryVk::bamp

Definition at line 52 of file MemoryVk.h.

◆ slim

SRWLOCK vkmm::MemoryVk::slim

Definition at line 48 of file MemoryVk.h.


The documentation for this struct was generated from the following file: