evan 2026.1.4
Evan
Loading...
Searching...
No Matches
Frame.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** Frame
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11
12#include "evan/ADeviceBackend.hpp"
13#include "evan/DeviceContext.hpp"
14
15#include <utility/logging/loggable.hpp>
16#include <utility/logging/default_logger.hpp>
17
18#include <vector>
19
20namespace evan
21{
40 class Frame:
41 protected utility::logging::Loggable<Frame,
42 utility::logging::DefaultLogger>
43 {
44 public:
52 struct ViewUniform {
56 glm::mat4 view;
57
62 glm::mat4 proj;
63 };
64
83 glm::mat4 model;
84
89 ViewUniform views[MAX_MULTIVIEW_VIEWS];
90 };
91
110 Frame(std::shared_ptr<DeviceContext> deviceContext,
111 std::size_t perFrameSlotCount);
112
113 ~Frame();
114
125 void destroy(VkDevice device);
126
135 void resetCommandBuffer(std::size_t viewSlot);
136
143 VkCommandBuffer getCommandBuffer(std::size_t viewSlot) const;
144
151 std::size_t getPerFrameSlotCount() const;
152
162 VkBuffer getUniformBuffer() const;
163
170 VkDeviceSize getUniformBufferAlignedSize() const;
171
179 void *getUniformBufferMapped(std::size_t viewSlot) const;
180
193 VkBuffer getInstanceBuffer() const;
194
202 void *getInstanceBufferMapped(std::size_t viewSlot) const;
203
210 VkDeviceSize getInstanceBufferAlignedSize() const;
211
217 std::size_t getInstanceCapacity() const;
218
236 bool ensureInstanceCapacity(std::size_t transforms);
237
248 VkBuffer getIndirectBuffer() const;
249
257 void *getIndirectBufferMapped(std::size_t viewSlot) const;
258
265 VkDeviceSize getIndirectBufferAlignedSize() const;
266
276 [[nodiscard]] bool hasTimestampQueries() const noexcept
277 {
278 return _timestampQueryPool != VK_NULL_HANDLE;
279 }
280
291 [[nodiscard]] VkQueryPool getTimestampQueryPool() const noexcept
292 {
293 return _timestampQueryPool;
294 }
295
303 VkFence _inFlight = VK_NULL_HANDLE;
304
311 VkQueryPool _timestampQueryPool = VK_NULL_HANDLE;
312
318 std::vector<VkSemaphore> _imageAvailable;
319
323 std::vector<VkCommandBuffer> _commandBuffers;
324
329 std::vector<VkSemaphore> _renderFinished;
330
336 std::size_t _perFrameSlotCount = 1;
337
341 void *_uniformBufferMapped = nullptr;
342
343 protected:
352 void cleanup();
363 void createCommandBuffer(VkDevice device, VkCommandPool commandPool);
364
375 void createSyncObjects(VkDevice device);
376
389 void createUniformBuffer(const ADeviceBackend &deviceBackend);
390
402 void createInstanceBuffer(const ADeviceBackend &deviceBackend);
403
413 void createIndirectBuffer(const ADeviceBackend &deviceBackend);
414
424 void createTimestampQueryPool(VkDevice device);
425
434 VkBuffer _uniformBuffer = VK_NULL_HANDLE;
435
443 VkDeviceMemory _uniformBufferMemory = VK_NULL_HANDLE;
444
452
456 VkBuffer _instanceBuffer = VK_NULL_HANDLE;
457
461 VkDeviceMemory _instanceBufferMemory = VK_NULL_HANDLE;
462
466 void *_instanceBufferMapped = nullptr;
467
472
477 std::size_t _instanceCapacity = 0;
478
482 VkBuffer _indirectBuffer = VK_NULL_HANDLE;
483
487 VkDeviceMemory _indirectBufferMemory = VK_NULL_HANDLE;
488
492 void *_indirectBufferMapped = nullptr;
493
498
504 std::shared_ptr<DeviceContext> _deviceContext;
505 };
506} // namespace evan
Abstract base class for Vulkan device backends.
Frame class representing a single frame of rendering in the Vulkan application.
Definition Frame.hpp:43
VkBuffer _indirectBuffer
Vulkan buffer storing indirect draw commands.
Definition Frame.hpp:482
void * getUniformBufferMapped(std::size_t viewSlot) const
Gets the mapped CPU pointer of a view's uniform slot.
VkCommandBuffer getCommandBuffer(std::size_t viewSlot) const
Gets the command buffer of the given view slot.
void cleanup()
Releases the synchronization objects, command buffer and uniform buffer owned by this frame.
bool hasTimestampQueries() const noexcept
Indicates whether this frame owns GPU timestamp queries.
Definition Frame.hpp:276
VkDeviceSize getIndirectBufferAlignedSize() const
Gets the aligned byte size of one indirect buffer slot.
VkQueryPool _timestampQueryPool
Definition Frame.hpp:311
VkFence _inFlight
Definition Frame.hpp:303
void createTimestampQueryPool(VkDevice device)
Creates the timestamp query pool for this frame.
std::vector< VkCommandBuffer > _commandBuffers
Definition Frame.hpp:323
VkDeviceSize _uniformBufferAlignedSize
Aligned byte size of one view's uniform buffer slot.
Definition Frame.hpp:451
void createSyncObjects(VkDevice device)
Creates the synchronization objects for this frame.
void createInstanceBuffer(const ADeviceBackend &deviceBackend)
Creates the instance buffer for this frame.
VkBuffer getUniformBuffer() const
Gets the Vulkan uniform buffer associated with this frame.
VkDeviceSize getUniformBufferAlignedSize() const
Gets the aligned byte size of one uniform buffer slot.
void createIndirectBuffer(const ADeviceBackend &deviceBackend)
Creates the indirect draw buffer for this frame.
void createCommandBuffer(VkDevice device, VkCommandPool commandPool)
Creates the Vulkan command buffer for this frame.
VkBuffer _uniformBuffer
Vulkan buffer for the uniform buffer object (UBO) used in this frame.
Definition Frame.hpp:434
void destroy(VkDevice device)
Destroys the Vulkan resources associated with this frame.
std::size_t getPerFrameSlotCount() const
Gets the number of view/swapchain slots this frame was allocated for.
std::shared_ptr< DeviceContext > _deviceContext
The device context used to create this frame, kept alive for the lifetime of the frame so that cleanu...
Definition Frame.hpp:504
std::size_t _perFrameSlotCount
Definition Frame.hpp:336
VkDeviceMemory _instanceBufferMemory
Vulkan device memory associated with the instance buffer.
Definition Frame.hpp:461
void createUniformBuffer(const ADeviceBackend &deviceBackend)
Creates the uniform buffer for this frame.
std::size_t getInstanceCapacity() const
Gets the number of model matrices one instance slot holds.
void * _instanceBufferMapped
Pointer to the mapped memory of the instance buffer.
Definition Frame.hpp:466
VkDeviceSize _instanceBufferAlignedSize
Aligned byte size of one view's instance buffer slot.
Definition Frame.hpp:471
Frame(std::shared_ptr< DeviceContext > deviceContext, std::size_t perFrameSlotCount)
Constructs a Frame object.
std::vector< VkSemaphore > _renderFinished
Definition Frame.hpp:329
void * _indirectBufferMapped
Pointer to the mapped memory of the indirect buffer.
Definition Frame.hpp:492
void * getInstanceBufferMapped(std::size_t viewSlot) const
Gets the mapped CPU pointer of a view's instance slot.
void resetCommandBuffer(std::size_t viewSlot)
Resets the command buffer of the given view slot.
VkBuffer getIndirectBuffer() const
Gets the Vulkan indirect draw buffer associated with this frame.
bool ensureInstanceCapacity(std::size_t transforms)
Makes sure one instance slot can hold transforms matrices.
VkBuffer _instanceBuffer
Vulkan buffer storing per-instance model matrices.
Definition Frame.hpp:456
VkBuffer getInstanceBuffer() const
Gets the Vulkan instance buffer associated with this frame.
VkDeviceMemory _indirectBufferMemory
Vulkan device memory associated with the indirect buffer.
Definition Frame.hpp:487
void * _uniformBufferMapped
Pointer to the mapped memory of the uniform buffer.
Definition Frame.hpp:341
VkDeviceSize _indirectBufferAlignedSize
Aligned byte size of one view's indirect buffer slot.
Definition Frame.hpp:497
VkDeviceMemory _uniformBufferMemory
Vulkan device memory associated with the uniform buffer.
Definition Frame.hpp:443
VkQueryPool getTimestampQueryPool() const noexcept
Gets the timestamp query pool of this frame.
Definition Frame.hpp:291
std::size_t _instanceCapacity
Number of model matrices one instance buffer slot currently holds. Grown on demand by ensureInstanceC...
Definition Frame.hpp:477
VkDeviceSize getInstanceBufferAlignedSize() const
Gets the aligned byte size of one instance buffer slot.
void * getIndirectBufferMapped(std::size_t viewSlot) const
Gets the mapped CPU pointer of a view's indirect slot.
std::vector< VkSemaphore > _imageAvailable
Definition Frame.hpp:318
Uniform buffer object structure.
Definition Frame.hpp:77
ViewUniform views[MAX_MULTIVIEW_VIEWS]
Per-view view/projection matrices, indexed by gl_ViewIndex.
Definition Frame.hpp:89
glm::mat4 model
Model matrix representing the transformation of the object in the scene. It is used to position,...
Definition Frame.hpp:83
Per-view matrices consumed by the vertex shader.
Definition Frame.hpp:52
glm::mat4 proj
Projection matrix transforming camera space to clip space.
Definition Frame.hpp:62
glm::mat4 view
View matrix transforming world space to camera space.
Definition Frame.hpp:56