evan 2026.1.4
Evan
Loading...
Searching...
No Matches
ADeviceBackend.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** ADeviceBackend
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11#include "evan/Error.hpp"
12#include "evan/Version.hpp"
13
14#include "evan/IPlatform.hpp"
15#include "evan/QueueFamilyIndices.hpp"
16
17#include <utility/logging/loggable.hpp>
18#include <utility/logging/default_logger.hpp>
19
20#include <set>
21#include <iostream>
22
23namespace evan
24{
25 class ASwapchainContext;
26 class ASwapchainImage;
27
46 protected utility::logging::Loggable<ADeviceBackend,
47 utility::logging::DefaultLogger>
48 {
49 public:
73 VkCommandPool _commandPool;
82 VkBuffer _srcBuffer;
86 VkBuffer _dstBuffer;
90 VkDeviceSize _size;
91 };
92
106 VkCommandPool _commandPool;
115 VkBuffer _buffer;
119 VkImage _image;
123 uint32_t _width;
127 uint32_t _height;
128 };
129
146 VkCommandPool _commandPool;
155 VkImage _image;
159 VkFormat _format;
163 VkImageLayout _oldLayout;
167 VkImageLayout _newLayout;
171 uint32_t _mipLevels;
172 };
173
189 uint32_t _width;
193 uint32_t _height;
197 uint32_t _mipLevels;
202 VkSampleCountFlagBits _numSamples;
206 VkFormat _format;
211 VkImageTiling _tiling;
216 VkImageUsageFlags _usage;
221 VkMemoryPropertyFlags _properties;
225 VkImage &_image;
230 VkDeviceMemory &_imageMemory;
237 uint32_t _arrayLayers = 1;
238 };
239
255 VkDeviceSize _size;
260 VkBufferUsageFlags _usage;
265 VkMemoryPropertyFlags _properties;
269 VkBuffer &_buffer;
274 VkDeviceMemory &_bufferMemory;
275 };
276
281
294 virtual uint32_t countSwapchainFormats() const = 0;
295
312 virtual std::vector<int64_t>
313 enumerateSwapchainFormats(uint32_t swapchainFormatCount) const = 0;
314
330
349 virtual Error preprocessFrame(ASwapchainContext &swapchainContext) = 0;
350
364 virtual Error processFrame(VkPresentInfoKHR presentInfo,
365 ASwapchainImage &swapchainImage) = 0;
366
383 virtual Error postprocessFrame(ASwapchainContext &swapchainContext) = 0;
384
402 Error createBuffer(const CreateBufferProperties &properties) const;
403
419 const TransitionImageLayoutProperties &properties) const;
420
438 VkCommandBuffer
439 beginSingleTimeCommands(VkCommandPool commandPool) const;
440
462 void endSingleTimeCommands(VkCommandPool commandPool,
463 VkQueue graphicsQueue,
464 VkCommandBuffer commandBuffer) const;
465
483 Error createImage(const CreateImageProperties &properties) const;
484
504 const CopyBufferToImageProperties &properties) const;
505
524 Error copyBuffer(const CopyBufferProperties &properties) const;
525
547 Result<VkImageView> createImageView(VkImage image, VkFormat format,
548 VkImageAspectFlags aspectFlags,
549 uint32_t mipLevels,
550 uint32_t layerCount = 1) const;
551
562 virtual VkDevice getDevice() const
563 {
564 return _device;
565 }
566
572 virtual VkInstance getInstance() const
573 {
574 return _VkInstance;
575 }
576
583 virtual VkPhysicalDevice getPhysicalDevice() const
584 {
585 return _physicalDevice;
586 }
587
601 bool supportsMultiview() const
602 {
603 return _multiviewSupported;
604 }
605
617 [[nodiscard]] bool supportsTimestampQueries();
618
628 [[nodiscard]] float getTimestampPeriod() const;
629
639 [[nodiscard]] uint32_t getTimestampValidBits();
640
641 protected:
648 VkPhysicalDevice _physicalDevice = VK_NULL_HANDLE;
649
656 VkDevice _device = VK_NULL_HANDLE;
657
663 VkInstance _VkInstance = VK_NULL_HANDLE;
664
673
697 virtual void createInstance(const IPlatform &platform,
698 const std::string &appName,
699 Version &appVersion) = 0;
700
718 virtual void createLogicalDevice() = 0;
719
736 virtual void pickPhysicalDevice() = 0;
737
751 static bool queryMultiviewSupport(VkPhysicalDevice physicalDevice,
752 uint32_t apiVersion);
753
764 std::vector<VkLayerProperties> getAvailableLayers();
765
766 private:
782 bool hasStencilComponent(VkFormat format) const;
783
806 Result<uint32_t> findMemoryType(uint32_t typeFilter,
807 VkMemoryPropertyFlags properties) const;
808 };
809} // namespace evan
Abstract base class for Vulkan device backends.
VkCommandBuffer beginSingleTimeCommands(VkCommandPool commandPool) const
Begins recording a single-use command buffer for one-time operations.
virtual VkPhysicalDevice getPhysicalDevice() const
Retrieves the Vulkan physical device handle.
float getTimestampPeriod() const
Nanoseconds per timestamp tick.
virtual Error processFrame(VkPresentInfoKHR presentInfo, ASwapchainImage &swapchainImage)=0
Processes a frame for presentation.
virtual void pickPhysicalDevice()=0
Selects a suitable Vulkan physical device for rendering.
virtual void createLogicalDevice()=0
Creates a Vulkan logical device and selects a physical device for rendering.
Error transitionImageLayout(const TransitionImageLayoutProperties &properties) const
Transitions the layout of a Vulkan image.
bool supportsTimestampQueries()
Indicates whether GPU timestamp queries can be used.
virtual VkInstance getInstance() const
Retrieves the Vulkan instance handle.
void endSingleTimeCommands(VkCommandPool commandPool, VkQueue graphicsQueue, VkCommandBuffer commandBuffer) const
Ends recording of a single-use command buffer and submits it for execution.
virtual Error preprocessFrame(ASwapchainContext &swapchainContext)=0
Preprocesses a frame before presentation.
VkPhysicalDevice _physicalDevice
bool supportsMultiview() const
Indicates whether multiview rendering is available.
virtual ~ADeviceBackend()
Virtual destructor for the ADeviceBackend class.
uint32_t getTimestampValidBits()
Number of valid bits in a timestamp value.
virtual VkDevice getDevice() const
Retrieves the Vulkan logical device handle.
Result< VkImageView > createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels, uint32_t layerCount=1) const
Creates a Vulkan image view for a given image.
virtual std::vector< int64_t > enumerateSwapchainFormats(uint32_t swapchainFormatCount) const =0
Enumerates the available swapchain formats for the Vulkan device.
virtual uint32_t countSwapchainFormats() const =0
Counts the number of available swapchain formats for the Vulkan device.
virtual void createInstance(const IPlatform &platform, const std::string &appName, Version &appVersion)=0
Creates a Vulkan instance and initializes the device backend.
Error copyBuffer(const CopyBufferProperties &properties) const
Copies data from one Vulkan buffer to another.
Error createBuffer(const CreateBufferProperties &properties) const
Creates a Vulkan buffer and allocates memory for it.
Error createImage(const CreateImageProperties &properties) const
Creates a Vulkan image and allocates memory for it.
bool _multiviewSupported
Whether the multiview feature was enabled on the logical device created by this backend.
virtual evan::QueueFamilyIndices findQueueFamilies()=0
Finds the queue family indices for the Vulkan physical device.
std::vector< VkLayerProperties > getAvailableLayers()
Retrieves the available Vulkan layers on the system.
virtual Error postprocessFrame(ASwapchainContext &swapchainContext)=0
Postprocesses a frame after presentation.
Error copyBufferToImage(const CopyBufferToImageProperties &properties) const
Copies data from a Vulkan buffer to a Vulkan image.
static bool queryMultiviewSupport(VkPhysicalDevice physicalDevice, uint32_t apiVersion)
Queries whether a physical device can run multiview passes.
Represents the context for managing the swapchain in the rendering system.
ASwapchainImage is a class that represents an image in the swapchain of the Evan engine....
Abstract interface for platform-specific functionality.
Definition IPlatform.hpp:36
Represents a software version using major, minor, and patch numbers.
Definition Version.hpp:35
Encapsulates properties required for copying data between Vulkan buffers.
VkDevice _logicalDevice
The Vulkan logical device used for command buffer operations.
VkCommandPool _commandPool
The Vulkan command pool used to allocate command buffers for the copy operation.
VkQueue _graphicsQueue
The Vulkan graphics queue used to submit the command buffer for execution.
VkDeviceSize _size
The size of the data to copy in bytes.
VkBuffer _dstBuffer
The Vulkan buffer to which data will be copied.
VkBuffer _srcBuffer
The Vulkan buffer from which data will be copied.
Properties required to copy data from a buffer to an image in Vulkan.
VkQueue _graphicsQueue
The Vulkan graphics queue used to submit the command buffer for execution.
VkImage _image
The Vulkan image to which the data will be copied.
VkCommandPool _commandPool
The Vulkan command pool used to allocate command buffers for the copy operation.
uint32_t _width
The width of the image in pixels.
VkBuffer _buffer
The Vulkan buffer containing the image data to be copied.
uint32_t _height
The height of the image in pixels.
Properties required for creating a Vulkan buffer and allocating its memory.
VkDeviceSize _size
The size of the buffer in bytes.
VkDeviceMemory & _bufferMemory
A reference to the VkDeviceMemory object that will be allocated for the buffer.
VkMemoryPropertyFlags _properties
The memory property flags for the buffer (e.g., VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT).
VkBuffer & _buffer
A reference to the VkBuffer object that will be created.
VkBufferUsageFlags _usage
The usage flags for the buffer (e.g., VK_BUFFER_USAGE_VERTEX_BUFFER_BIT).
Encapsulates the properties required to create a Vulkan image and allocate its memory.
VkMemoryPropertyFlags _properties
The memory property flags for the image (e.g., VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT).
VkFormat _format
The format of the image (e.g., VK_FORMAT_R8G8B8A8_SRGB).
uint32_t _height
The height of the image in pixels.
VkImage & _image
A reference to the VkImage object that will be created.
VkImageTiling _tiling
The tiling arrangement of the image (e.g., VK_IMAGE_TILING_OPTIMAL).
VkImageUsageFlags _usage
The usage flags for the image (e.g., VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT).
uint32_t _arrayLayers
The number of array layers of the image.
uint32_t _mipLevels
The number of mipmap levels for the image.
VkDeviceMemory & _imageMemory
A reference to the VkDeviceMemory object that will be allocated for the image.
uint32_t _width
The width of the image in pixels.
VkSampleCountFlagBits _numSamples
The number of samples for multisample anti-aliasing (MSAA).
Encapsulates the properties required to perform an image layout transition in Vulkan.
VkCommandPool _commandPool
The Vulkan command pool used to allocate command buffers for the layout transition.
VkImage _image
The Vulkan image whose layout is to be transitioned.
VkImageLayout _oldLayout
The old layout of the image before the transition.
VkFormat _format
The format of the image being transitioned.
VkImageLayout _newLayout
The new layout of the image after the transition.
VkQueue _graphicsQueue
The Vulkan graphics queue used to submit the command buffer for execution.
uint32_t _mipLevels
The number of mipmap levels in the image.
A structure to represent Vulkan queue family indices.
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89