1 
2 module gfx.vulkan.memory;
3 
4 package:
5 
6 import gfx.bindings.vulkan;
7 
8 import gfx.core.rc;
9 import gfx.graal.memory;
10 import gfx.vulkan.device;
11 
12 class VulkanDeviceMemory : VulkanDevObj!(VkDeviceMemory, "FreeMemory"), DeviceMemory
13 {
14     mixin(atomicRcCode);
15 
16     this(VkDeviceMemory vkObj, VulkanDevice dev, in MemProps props, in size_t size, in uint typeIndex)
17     {
18         super(vkObj, dev);
19         _props = props;
20         _size = size;
21         _typeIndex = typeIndex;
22     }
23 
24     override @property Device device() {
25         return dev;
26     }
27 
28     override @property MemProps props() {
29         return _props;
30     }
31 
32     override @property size_t size() {
33         return _size;
34     }
35 
36     override @property uint typeIndex() {
37         return _typeIndex;
38     }
39 
40     void* mapRaw(in size_t offset, in size_t size) {
41         void *data;
42         vulkanEnforce(
43             vk.MapMemory(vkDev, vkObj, offset, size, 0, &data),
44             "Could not map device memory"
45         );
46         return data;
47     }
48 
49     void unmapRaw() {
50         vk.UnmapMemory(vkDev, vkObj);
51     }
52 
53     private MemProps _props;
54     private size_t _size;
55     private uint _typeIndex;
56 }