MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ allocate_raw_buffer()

void MayaFlux::Core::BackendResourceManager::allocate_raw_buffer ( size_t  size_bytes,
vk::BufferUsageFlags  usage,
vk::MemoryPropertyFlags  memory_properties,
bool  host_visible,
vk::Buffer &  out_buffer,
vk::DeviceMemory &  out_memory,
void *&  out_mapped_ptr 
)

Allocate a raw VkBuffer/VkDeviceMemory pair without an owning VKBuffer object.

Parameters
size_bytesBuffer capacity in bytes.
usageVulkan buffer usage flags.
memory_propertiesVulkan memory property flags.
host_visibleWhen true, the allocation is mapped and out_mapped_ptr is populated; when false, out_mapped_ptr is left null.
out_bufferReceives the created vk::Buffer.
out_memoryReceives the bound vk::DeviceMemory.
out_mapped_ptrReceives the mapped host pointer, or nullptr if host_visible is false.

Same allocation sequence as initialize_buffer() (createBuffer, getBufferMemoryRequirements, allocateMemory, bindBufferMemory, optional mapMemory), without requiring or populating a VKBuffer. Intended for VKBuffer subclasses that own secondary raw handle pairs directly in VKBufferResources::back_buffers rather than as separate VKBuffer objects.

Definition at line 189 of file BackendResoureManager.cpp.

197{
198 vk::BufferCreateInfo buffer_info {};
199 buffer_info.size = size_bytes;
200 buffer_info.usage = usage;
201 buffer_info.sharingMode = vk::SharingMode::eExclusive;
202
203 try {
204 out_buffer = m_context.get_device().createBuffer(buffer_info);
205 } catch (const vk::SystemError& e) {
209 std::source_location::current(),
210 "Failed to create raw VkBuffer: " + std::string(e.what()));
211 }
212
213 vk::MemoryRequirements mem_requirements = m_context.get_device().getBufferMemoryRequirements(out_buffer);
214
215 vk::MemoryAllocateInfo alloc_info;
216 alloc_info.allocationSize = mem_requirements.size;
217 alloc_info.memoryTypeIndex = find_memory_type(mem_requirements.memoryTypeBits, memory_properties);
218
219 try {
220 out_memory = m_context.get_device().allocateMemory(alloc_info);
221 } catch (const vk::SystemError& e) {
222 m_context.get_device().destroyBuffer(out_buffer);
226 std::source_location::current(),
227 "Failed to allocate raw VkDeviceMemory: " + std::string(e.what()));
228 }
229
230 try {
231 m_context.get_device().bindBufferMemory(out_buffer, out_memory, 0);
232 } catch (const vk::SystemError& e) {
233 m_context.get_device().freeMemory(out_memory);
234 m_context.get_device().destroyBuffer(out_buffer);
238 std::source_location::current(),
239 "Failed to bind raw buffer memory: " + std::string(e.what()));
240 }
241
242 out_mapped_ptr = nullptr;
243 if (host_visible) {
244 try {
245 out_mapped_ptr = m_context.get_device().mapMemory(out_memory, 0, size_bytes);
246 } catch (const vk::SystemError& e) {
247 m_context.get_device().freeMemory(out_memory);
248 m_context.get_device().destroyBuffer(out_buffer);
252 std::source_location::current(),
253 "Failed to map raw buffer memory: " + std::string(e.what()));
254 }
255 }
256}
uint32_t find_memory_type(uint32_t type_filter, vk::MemoryPropertyFlags properties) const
Find a suitable memory type for Vulkan buffer allocation.
vk::Device get_device() const
Get logical device.
Definition VKContext.hpp:49
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
void error_rethrow(Component component, Context context, std::source_location location=std::source_location::current(), std::string_view additional_context="")
Catch and log an exception, then rethrow it.
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, find_memory_type(), MayaFlux::Core::VKContext::get_device(), MayaFlux::Journal::GraphicsBackend, and m_context.

Referenced by initialize_buffer(), and setup_backend_service().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: