Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
Chronos::Engine::Buffer Class Reference

Used to store buffers in GPU. More...

#include <buffers.hpp>

Inheritance diagram for Chronos::Engine::Buffer:
Collaboration diagram for Chronos::Engine::Buffer:

Public Member Functions

void create (Chronos::Engine::Device device, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties)
 This is used to initialize the buffer.
 
void copy (void *data, VkCommandPool commandPool)
 Copies the data to the buffer.
 
void destroy ()
 Destroys the buffer and frees the memory.
 

Public Attributes

VkBuffer buffer
 The buffer.
 
VkDeviceSize size
 The size of the buffer.
 
VkDeviceMemory memory
 The device memory of the buffer.
 

Private Attributes

Chronos::Engine::Device device
 The device on which the buffer is stored.
 

Detailed Description

Used to store buffers in GPU.

It contains the buffer, the size and the memory variables needed for this, along with the appropriate functions to use them.

Definition at line 39 of file buffers.hpp.

Member Function Documentation

◆ copy()

void Chronos::Engine::Buffer::copy ( void *  data,
VkCommandPool  commandPool 
)

Copies the data to the buffer.

It does this by coping the data into a temporary staging buffer and then copying it to the final buffer.

Parameters
dataThe data to copy.
commandPoolThe command pool to use for the staging buffer and commands during the copy.

Definition at line 39 of file buffers.cpp.

40{
41 // copies the data to a staging buffer in order to copy to device buffer
42 void* data;
43 VkBuffer stagingBuffer;
44 VkDeviceMemory stagingBufferMemory;
46 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
47 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
48 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
49 &stagingBuffer, &stagingBufferMemory);
50 vkMapMemory(device.device, stagingBufferMemory, 0, size, 0, &data);
51 memcpy(data, inputData, (size_t)size);
52 vkUnmapMemory(device.device, stagingBufferMemory);
54 device, stagingBuffer, buffer, size, commandPool);
55 vkDestroyBuffer(device.device, stagingBuffer, nullptr);
56 vkFreeMemory(device.device, stagingBufferMemory, nullptr);
57 LOG(3,
58 "Data [" + std::to_string((uint64_t)buffer)
59 + "] copied to device buffer [" + std::to_string((uint64_t)buffer)
60 + "]")
61}
VkBuffer buffer
The buffer.
Definition buffers.hpp:78
VkDeviceSize size
The size of the buffer.
Definition buffers.hpp:83
Chronos::Engine::Device device
The device on which the buffer is stored.
Definition buffers.hpp:94
VkDevice device
This is the logical device that is used by Vulkan.
Definition device.hpp:52
#define LOG(LEVEL, MESSAGE)
Definition logging.hpp:60
void createBuffer(Chronos::Engine::Device device, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer *buffer, VkDeviceMemory *bufferMemory)
Creates a buffer of a given size, usage and properties.
Definition helper.cpp:78
void copyBuffer(Chronos::Engine::Device device, VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size, VkCommandPool commandPool)
Copies data from one buffer to another.
Definition helper.cpp:111

References Chronos::Engine::copyBuffer(), Chronos::Engine::createBuffer(), and LOG.

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

◆ create()

void Chronos::Engine::Buffer::create ( Chronos::Engine::Device  device,
VkBufferUsageFlags  flags,
VkMemoryPropertyFlags  properties 
)

This is used to initialize the buffer.

It is calls the createBuffer function for this purpose and stores the results.

Parameters
deviceThe device on which the buffer should be stored.
flagsThe flags to use for the buffer. @params properties The memory properties to use for the buffer.

Definition at line 27 of file buffers.cpp.

29{
30 this->device = device;
32 this->device, size, flags, properties, &buffer, &memory);
33 LOG(2,
34 "Buffer [" + std::to_string((uint64_t)this->buffer)
35 + "] created for buffer object [" + std::to_string((uint64_t)this)
36 + "]")
37}
VkDeviceMemory memory
The device memory of the buffer.
Definition buffers.hpp:88

References buffer, Chronos::Engine::createBuffer(), device, LOG, memory, and size.

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

◆ destroy()

void Chronos::Engine::Buffer::destroy ( )

Destroys the buffer and frees the memory.

Definition at line 63 of file buffers.cpp.

64{
65 vkDestroyBuffer(device.device, buffer, nullptr);
66 vkFreeMemory(device.device, memory, nullptr);
67 LOG(2,
68 "Buffer [" + std::to_string((uint64_t)buffer)
69 + "] destroyed on device ["
70 + std::to_string((uint64_t)device.device) + "]")
71}

References LOG.

Member Data Documentation

◆ buffer

VkBuffer Chronos::Engine::Buffer::buffer

The buffer.

Definition at line 78 of file buffers.hpp.

◆ device

Chronos::Engine::Device Chronos::Engine::Buffer::device
private

The device on which the buffer is stored.

Definition at line 94 of file buffers.hpp.

◆ memory

VkDeviceMemory Chronos::Engine::Buffer::memory

The device memory of the buffer.

Definition at line 88 of file buffers.hpp.

◆ size

VkDeviceSize Chronos::Engine::Buffer::size

The size of the buffer.

Definition at line 83 of file buffers.hpp.


The documentation for this class was generated from the following files: