1#ifndef NNGN_GRAPHICS_VULKAN_RESOURCE_H
2#define NNGN_GRAPHICS_VULKAN_RESOURCE_H
23 VkBuffer
id()
const {
return this->
h; }
30 bool init(VkDevice dev, VkDeviceSize
size, VkBufferUsageFlags usage);
43 VkDeviceMemory
mem()
const {
return this->
hm; }
44 template<VkMemoryPropertyFlags f>
47 VkDeviceSize
size, VkBufferUsageFlags usage);
50 VkDevice dev, VkDeviceSize off, std::span<const std::byte>
s)
const;
52 VkDevice dev, VkDeviceSize off, VkDeviceSize
n, VkDeviceSize stride,
53 std::span<const std::byte>
s)
const;
55 VkDeviceMemory
hm = {};
60 template<VkMemoryPropertyFlags f>
63 VkDeviceSize
size, VkBufferUsageFlags usage);
72 VkDeviceMemory
mem()
const {
return this->
hm; }
74 template<VkMemoryPropertyFlags f>
77 VkImageCreateFlags flags, VkImageType type, VkFormat format,
78 VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t n_layers,
79 VkSampleCountFlagBits n_samples, VkImageTiling tiling,
80 VkImageUsageFlags usage);
83 VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t base_layer,
84 std::uint32_t n_layers)
const;
86 VkDevice dev, VkImageViewType type, VkFormat format,
87 VkImageAspectFlags aspect_flags,
88 std::uint32_t mip_levels, std::uint32_t base_layer,
89 std::uint32_t n_layers, VkImageView *p)
const;
92 VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage,
93 VkAccessFlags src_mask, VkAccessFlags dst_mask,
94 VkImageLayout src, VkImageLayout dst,
95 const VkImageSubresourceRange &range)
const;
99 VkImageCreateFlags flags, VkImageType type, VkFormat format,
100 VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t n_layers,
101 VkSampleCountFlagBits n_samples, VkImageTiling tiling,
102 VkImageUsageFlags usage);
104 VkDeviceMemory
hm = {};
107template<VkMemoryPropertyFlags f>
110 VkDeviceSize size, VkBufferUsageFlags usage
116 if(!dev_mem->
alloc<
f>(this->id(), &this->hm))
118 vkBindBufferMemory(dev, this->
id(), this->
hm, 0);
123template<VkMemoryPropertyFlags f>
126 VkDeviceSize size, VkBufferUsageFlags usage
132 VkDeviceMemory mem = {};
133 VkDeviceSize off = {};
134 if(!dev_mem->
alloc<
f>(this->id(), &this->ha, &mem, &off))
136 vkBindBufferMemory(dev, this->
id(), mem, off);
141template<VkMemoryPropertyFlags f>
144 VkImageCreateFlags flags, VkImageType type, VkFormat format,
145 VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t n_layers,
146 VkSampleCountFlagBits n_samples, VkImageTiling tiling,
147 VkImageUsageFlags usage
151 dev, flags, type, format, extent, mip_levels, n_layers, n_samples,
154 && (vkBindImageMemory(dev, this->h, this->
hm, 0),
true);
MemoryAllocation ha
Definition resource.h:66
bool init(VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize size, VkBufferUsageFlags usage)
Definition resource.h:124
VkDeviceMemory hm
Definition resource.h:55
VkDeviceMemory mem() const
Definition resource.h:43
void memcpy(VkDevice dev, VkDeviceSize off, std::span< const std::byte > s) const
Definition resource.cpp:51
bool init(VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize size, VkBufferUsageFlags usage)
Definition resource.h:108
void fill(VkDevice dev, VkDeviceSize off, VkDeviceSize n, VkDeviceSize stride, std::span< const std::byte > s) const
Definition resource.cpp:37
Manages device memory queries, allocations, and lifetime.
Definition memory.h:20
bool alloc(const VkMemoryRequirements *req, VkDeviceMemory *p)
Allocates device memory from a type that fulfills req.
Definition memory.h:123
A buffer and its associated memory allocation.
Definition resource.h:21
VkDeviceSize m_capacity
Definition resource.h:36
VkBuffer id() const
Definition resource.h:23
void set_size(VkDeviceSize s)
Definition resource.h:26
bool init(VkDevice dev, VkDeviceSize size, VkBufferUsageFlags usage)
Definition resource.cpp:15
VkDeviceSize m_size
Definition resource.h:36
void set_capacity(VkDeviceSize c)
Definition resource.h:29
VkDeviceSize size() const
Definition resource.h:24
VkDeviceSize capacity() const
Definition resource.h:25
void destroy()
Definition resource.cpp:27
VkBuffer h
Definition resource.h:35
assert
Definition debug.lua:3
local n
Definition dump_lights.lua:5
local c
Definition gamma.lua:11
init
Definition img_common.lua:34
#define NNGN_LOG_CONTEXT_CF(c)
Definition log.h:11
std::uint64_t MemoryAllocation
Definition memory.h:17
VkCommandBuffer
Definition types.h:72
COMMAND_BUFFER DESCRIPTOR_POOL DESCRIPTOR_SET_LAYOUT FENCE VkImage
Definition types.h:72
VkDeviceMemory mem() const
Definition resource.h:72
bool init(VkDevice dev, DeviceMemory *dev_mem, VkImageCreateFlags flags, VkImageType type, VkFormat format, VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t n_layers, VkSampleCountFlagBits n_samples, VkImageTiling tiling, VkImageUsageFlags usage)
Definition resource.h:142
void transition_layout(VkCommandBuffer cmd, VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage, VkAccessFlags src_mask, VkAccessFlags dst_mask, VkImageLayout src, VkImageLayout dst, const VkImageSubresourceRange &range) const
Definition resource.cpp:219
VkDeviceMemory hm
Definition resource.h:104
bool init_mipmaps(VkCommandBuffer cmd, VkExtent3D extent, std::uint32_t mip_levels, std::uint32_t base_layer, std::uint32_t n_layers) const
Definition resource.cpp:110
void destroy(VkDevice dev, DeviceMemory *dev_mem)
Definition resource.cpp:76
VkImage h
Definition resource.h:103
bool create_view(VkDevice dev, VkImageViewType type, VkFormat format, VkImageAspectFlags aspect_flags, std::uint32_t mip_levels, std::uint32_t base_layer, std::uint32_t n_layers, VkImageView *p) const
Definition resource.cpp:196
VkImage id() const
Definition resource.h:71
std::chrono::seconds s
Definition timing.cpp:6