evan 2026.1.4
Evan
Loading...
Searching...
No Matches
evan::DeviceContext Class Reference

Represents the device context for the engine, managing Vulkan-related resources and operations. More...

#include <headers/evan/DeviceContext.hpp>

Inheritance diagram for evan::DeviceContext:
Collaboration diagram for evan::DeviceContext:

Public Member Functions

 DeviceContext (const IPlatform &platform)
 Constructs a DeviceContext instance using the provided platform.
 
VkSampleCountFlagBits getMsaaSamples () const
 Retrieves the number of MSAA samples used by this device context.
 
void setMsaaSamples (VkSampleCountFlagBits samples)
 Overrides the MSAA sample count used by this device context.
 
VkSampleCountFlagBits getMaxSupportedMsaaSamples () const
 Retrieves the highest MSAA sample count this device accepts.
 
std::shared_ptr< ADeviceBackend > getDeviceBackend () const
 Retrieves a shared pointer to the ADeviceBackend instance associated with this device context.
 
VkCommandPool getCommandPool () const
 Retrieves the Vulkan command pool associated with this device context.
 
VkQueue getGraphicsQueue () const
 Retrieves the Vulkan graphics queue associated with this device context.
 
TransferManager & getTransferManager ()
 Retrieves the transfer manager used to upload resources asynchronously without draining the graphics queue.
 
const PipelineCache & getPipelineCache () const
 Retrieves the pipeline cache used when creating pipelines.
 

Protected Attributes

VkQueue _graphicsQueue
 
VkCommandPool _commandPool
 
TransferManager _transferManager
 
PipelineCache _pipelineCache
 
VkSampleCountFlagBits _msaaSamples = VK_SAMPLE_COUNT_1_BIT
 
std::shared_ptr< ADeviceBackend > _deviceBackend
 
VkDebugUtilsMessengerEXT _debugMessenger = VK_NULL_HANDLE
 

Detailed Description

Represents the device context for the engine, managing Vulkan-related resources and operations.

The DeviceContext class encapsulates the Vulkan instance, physical device, logical device, graphics queue, command pool, and MSAA samples. It provides a structured way to manage these resources and perform operations related to Vulkan rendering.

Definition at line 36 of file DeviceContext.hpp.

Constructor & Destructor Documentation

◆ DeviceContext()

evan::DeviceContext::DeviceContext ( const IPlatform &  platform)

Constructs a DeviceContext instance using the provided platform.

This constructor initializes the device context by creating a Vulkan instance, selecting a physical device, creating a logical device, and setting up the graphics queue and command pool. It also determines the maximum usable sample count for MSAA and sets up the Vulkan debug messenger for validation layers.

Parameters
platformA reference to an IPlatform instance that provides platform-specific implementations for Vulkan device management operations. The platform is used to create the Vulkan instance, select the physical device, and create the logical device.
Note
The constructor performs several Vulkan initialization steps, including:
  • Creating a Vulkan instance using the platform's createInstance method.
  • Selecting a physical device using the platform's pickPhysicalDevice method.
  • Creating a logical device using the platform's createLogicalDevice method.
  • Creating a graphics queue and command pool for rendering operations.
  • Determining the maximum usable sample count for MSAA.
  • Setting up the Vulkan debug messenger for validation layers.

Member Function Documentation

◆ getCommandPool()

VkCommandPool evan::DeviceContext::getCommandPool ( ) const

Retrieves the Vulkan command pool associated with this device context.

Returns
VkCommandPool The Vulkan command pool used to allocate command buffers for recording rendering commands. The command pool is created during the initialization of the device context and is configured to allow individual command buffers to be reset.

◆ getDeviceBackend()

std::shared_ptr< ADeviceBackend > evan::DeviceContext::getDeviceBackend ( ) const

Retrieves a shared pointer to the ADeviceBackend instance associated with this device context.

Returns
std::shared_ptr<ADeviceBackend> A shared pointer to the ADeviceBackend instance, which provides platform-specific implementations for Vulkan device management operations. This allows access to methods for creating Vulkan instances, logical devices, and picking physical devices, enabling abstraction and flexibility in the device context implementation.
Here is the caller graph for this function:

◆ getGraphicsQueue()

VkQueue evan::DeviceContext::getGraphicsQueue ( ) const

Retrieves the Vulkan graphics queue associated with this device context.

Returns
VkQueue The Vulkan graphics queue used to submit rendering commands to the GPU. The graphics queue is created during the initialization of the device context and is obtained from the logical device based on the determined graphics queue family index.

◆ getMaxSupportedMsaaSamples()

VkSampleCountFlagBits evan::DeviceContext::getMaxSupportedMsaaSamples ( ) const

Retrieves the highest MSAA sample count this device accepts.

Derived from the sample counts supported by both the framebuffer color and depth attachments, capped at VK_SAMPLE_COUNT_4_BIT.

Returns
The highest sample count an application may request.

◆ getMsaaSamples()

VkSampleCountFlagBits evan::DeviceContext::getMsaaSamples ( ) const

Retrieves the number of MSAA samples used by this device context.

Defaults to VK_SAMPLE_COUNT_1_BIT, that is no multisampling.

Returns
VkSampleCountFlagBits The MSAA sample count flag bits representing the number of samples per pixel for multisample anti-aliasing operations.
Here is the caller graph for this function:

◆ getPipelineCache()

const PipelineCache & evan::DeviceContext::getPipelineCache ( ) const

Retrieves the pipeline cache used when creating pipelines.

The returned cache is passed to vkCreateGraphicsPipelines so the driver can reuse pipelines it already compiled, either earlier in this run or during a previous one when the blob was reloaded from disk.

Returns
A reference to the pipeline cache owned by this device context.

◆ getTransferManager()

TransferManager & evan::DeviceContext::getTransferManager ( )

Retrieves the transfer manager used to upload resources asynchronously without draining the graphics queue.

Returns
TransferManager& The transfer manager owned by this device context.

◆ setMsaaSamples()

void evan::DeviceContext::setMsaaSamples ( VkSampleCountFlagBits  samples)

Overrides the MSAA sample count used by this device context.

Multisampling is disabled by default: every draw pays the multiplied color and depth bandwidth and the resolve pass, whether or not the scene benefits from it. Applications raise the count to 2x or 4x when the extra edge quality is worth that cost.

The requested count is applied only when it is supported by both the framebuffer color and depth attachments of the physical device and stays within the supported cap (see getMaxSupportedMsaaSamples); otherwise the current value is kept and a warning is logged. The EVAN_MSAA environment variable takes precedence over samples, so the cost of multisampling can be measured without a rebuild.

Parameters
samplesThe MSAA sample count flag bits to use.

Member Data Documentation

◆ _commandPool

VkCommandPool evan::DeviceContext::_commandPool
protected

The command pool, which is used to allocate command buffers for recording rendering commands.

Definition at line 182 of file DeviceContext.hpp.

◆ _debugMessenger

VkDebugUtilsMessengerEXT evan::DeviceContext::_debugMessenger = VK_NULL_HANDLE
protected

Vulkan debug messenger for validation layers. This member variable holds the handle to the Vulkan debug messenger, which is used to receive debug messages from the Vulkan validation layers. The debug messenger is set up during the initialization of the device context and is configured to capture messages of various severity levels and types, providing valuable information for debugging and development purposes.

Note
The debug messenger is created using the vkCreateDebugUtilsMessengerEXT function and requires the VK_EXT_debug_utils extension to be enabled in the Vulkan instance. Ensure that the extension is available and enabled for proper functionality of the debug messenger.

Definition at line 230 of file DeviceContext.hpp.

◆ _deviceBackend

std::shared_ptr<ADeviceBackend> evan::DeviceContext::_deviceBackend
protected

A shared pointer to the ADeviceBackend instance, which provides platform-specific implementations for Vulkan device management operations. This allows the DeviceContext to utilize the backend's methods

Definition at line 213 of file DeviceContext.hpp.

◆ _graphicsQueue

VkQueue evan::DeviceContext::_graphicsQueue
protected

The graphics queue, which is used to submit rendering commands to the GPU.

Definition at line 175 of file DeviceContext.hpp.

◆ _msaaSamples

VkSampleCountFlagBits evan::DeviceContext::_msaaSamples = VK_SAMPLE_COUNT_1_BIT
protected

The number of samples used for multisampling anti-aliasing (MSAA), which is a technique used to improve the visual quality of rendered images by reducing aliasing artifacts.

Defaults to a single sample, which disables MSAA.

Definition at line 205 of file DeviceContext.hpp.

◆ _pipelineCache

PipelineCache evan::DeviceContext::_pipelineCache
protected

Pipeline cache shared by every pipeline created for this device.

It is created with the device and persisted on destruction, so the pipelines compiled by a run are available to the next one.

Definition at line 195 of file DeviceContext.hpp.

◆ _transferManager

TransferManager evan::DeviceContext::_transferManager
protected

Owns staging memory and command buffers for asynchronous uploads.

Definition at line 187 of file DeviceContext.hpp.


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