2525struct cvk_memory_allocation {
2626
2727 cvk_memory_allocation (VkDevice dev, VkDeviceSize size, uint32_t type_index,
28- bool coherent)
28+ bool coherent, bool keep_mapping )
2929 : m_device(dev), m_size(size), m_memory(VK_NULL_HANDLE),
30- m_memory_type_index (type_index), m_coherent(coherent) {}
30+ m_memory_type_index (type_index), m_coherent(coherent),
31+ m_keep_mapping(keep_mapping), m_map_ptr(nullptr ) {}
3132
3233 ~cvk_memory_allocation () {
34+ if (m_keep_mapping && m_map_ptr != nullptr ) {
35+ vkUnmapMemory (m_device, m_memory);
36+ }
3337 if (m_memory != VK_NULL_HANDLE) {
3438 vkFreeMemory (m_device, m_memory, nullptr );
3539 }
@@ -73,10 +77,19 @@ struct cvk_memory_allocation {
7377 }
7478
7579 VkResult map (void ** map_ptr) {
76- return vkMapMemory (m_device, m_memory, 0 , m_size, 0 , map_ptr);
80+ VkResult result = VK_SUCCESS;
81+ if (!m_keep_mapping || m_map_ptr == nullptr ) {
82+ result = vkMapMemory (m_device, m_memory, 0 , m_size, 0 , &m_map_ptr);
83+ }
84+ *map_ptr = m_map_ptr;
85+ return result;
7786 }
7887
79- void unmap () { vkUnmapMemory (m_device, m_memory); }
88+ void unmap () {
89+ if (!m_keep_mapping) {
90+ vkUnmapMemory (m_device, m_memory);
91+ }
92+ }
8093
8194 VkDeviceMemory vulkan_memory () { return m_memory; }
8295
@@ -86,6 +99,8 @@ struct cvk_memory_allocation {
8699 VkDeviceMemory m_memory;
87100 uint32_t m_memory_type_index;
88101 bool m_coherent;
102+ bool m_keep_mapping;
103+ void * m_map_ptr;
89104};
90105
91106using cvk_mem_callback_pointer_type = void (CL_CALLBACK*)(cl_mem mem,
0 commit comments