Pyrogenesis  trunk
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Renderer::Backend::Vulkan::CDevice Class Referencefinal

#include <Device.h>

Inheritance diagram for Renderer::Backend::Vulkan::CDevice:
Inheritance graph
[legend]
Collaboration diagram for Renderer::Backend::Vulkan::CDevice:
Collaboration graph
[legend]

Classes

struct  ObjectToDestroy
 

Public Member Functions

 ~CDevice () override
 
Backend GetBackend () const override
 
const std::string & GetName () const override
 
const std::string & GetVersion () const override
 
const std::string & GetDriverInformation () const override
 
const std::vector< std::string > & GetExtensions () const override
 
void Report (const ScriptRequest &rq, JS::HandleValue settings) override
 
std::unique_ptr< IDeviceCommandContextCreateCommandContext () override
 
std::unique_ptr< IGraphicsPipelineStateCreateGraphicsPipelineState (const SGraphicsPipelineStateDesc &pipelineStateDesc) override
 Creates a graphics pipeline state. More...
 
std::unique_ptr< IVertexInputLayoutCreateVertexInputLayout (const PS::span< const SVertexAttributeFormat > attributes) override
 Creates a vertex input layout. More...
 
std::unique_ptr< ITextureCreateTexture (const char *name, const ITexture::Type type, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc &defaultSamplerDesc, const uint32_t MIPLevelCount, const uint32_t sampleCount) override
 
std::unique_ptr< ITextureCreateTexture2D (const char *name, const uint32_t usage, const Format format, const uint32_t width, const uint32_t height, const Sampler::Desc &defaultSamplerDesc, const uint32_t MIPLevelCount=1, const uint32_t sampleCount=1) override
 
std::unique_ptr< IFramebufferCreateFramebuffer (const char *name, SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment) override
 
std::unique_ptr< IBufferCreateBuffer (const char *name, const IBuffer::Type type, const uint32_t size, const bool dynamic) override
 
std::unique_ptr< CBufferCreateCBuffer (const char *name, const IBuffer::Type type, const uint32_t size, const bool dynamic)
 
std::unique_ptr< IShaderProgramCreateShaderProgram (const CStr &name, const CShaderDefines &defines) override
 
bool AcquireNextBackbuffer () override
 Acquires a backbuffer for rendering a frame. More...
 
IFramebufferGetCurrentBackbuffer (const AttachmentLoadOp colorAttachmentLoadOp, const AttachmentStoreOp colorAttachmentStoreOp, const AttachmentLoadOp depthStencilAttachmentLoadOp, const AttachmentStoreOp depthStencilAttachmentStoreOp) override
 Returns a framebuffer for the current backbuffer with the required attachment operations. More...
 
void Present () override
 Presents the backbuffer to the swapchain queue to be flipped on a screen. More...
 
void OnWindowResize (const uint32_t width, const uint32_t height) override
 Should be called on window surface resize. More...
 
bool IsTextureFormatSupported (const Format format) const override
 
bool IsFramebufferFormatSupported (const Format format) const override
 
Format GetPreferredDepthStencilFormat (const uint32_t usage, const bool depth, const bool stencil) const override
 Returns the most suitable format for the usage. More...
 
const CapabilitiesGetCapabilities () const override
 
VkDevice GetVkDevice ()
 
VmaAllocator GetVMAAllocator ()
 
void ScheduleObjectToDestroy (VkObjectType type, const void *handle, const VmaAllocation allocation)
 
void ScheduleObjectToDestroy (VkObjectType type, const uint64_t handle, const VmaAllocation allocation)
 
void ScheduleTextureToDestroy (const CTexture::UID uid)
 
void SetObjectName (VkObjectType type, const void *handle, const char *name)
 
void SetObjectName (VkObjectType type, const uint64_t handle, const char *name)
 
std::unique_ptr< CRingCommandContextCreateRingCommandContext (const size_t size)
 
const SAvailablePhysicalDeviceGetChoosenPhysicalDevice () const
 
CRenderPassManagerGetRenderPassManager ()
 
CSamplerManagerGetSamplerManager ()
 
CDescriptorManagerGetDescriptorManager ()
 
- Public Member Functions inherited from Renderer::Backend::IDevice
virtual ~IDevice ()
 

Static Public Member Functions

static std::unique_ptr< CDeviceCreate (SDL_Window *window)
 Creates the Vulkan device. More...
 

Private Member Functions

 CDevice ()
 
void RecreateSwapChain ()
 
bool IsSwapChainValid ()
 
void ProcessObjectToDestroyQueue (const bool ignoreFrameID=false)
 
void ProcessTextureToDestroyQueue (const bool ignoreFrameID=false)
 
bool IsFormatSupportedForUsage (const Format format, const uint32_t usage) const
 

Private Attributes

std::string m_Name
 
std::string m_Version
 
std::string m_VendorID
 
std::string m_DriverInformation
 
std::vector< std::string > m_Extensions
 
std::vector< std::string > m_InstanceExtensions
 
std::vector< std::string > m_ValidationLayers
 
SAvailablePhysicalDevice m_ChoosenDevice {}
 
std::vector< SAvailablePhysicalDevicem_AvailablePhysicalDevices
 
Capabilities m_Capabilities {}
 
VkInstance m_Instance = VK_NULL_HANDLE
 
VkDebugUtilsMessengerEXT m_DebugMessenger = VK_NULL_HANDLE
 
SDL_Windowm_Window = nullptr
 
VkSurfaceKHR m_Surface = VK_NULL_HANDLE
 
VkDevice m_Device = VK_NULL_HANDLE
 
VmaAllocator m_VMAAllocator = VK_NULL_HANDLE
 
VkQueue m_GraphicsQueue = VK_NULL_HANDLE
 
uint32_t m_GraphicsQueueFamilyIndex = std::numeric_limits<uint32_t>::max()
 
std::unique_ptr< CSwapChainm_SwapChain
 
uint32_t m_FrameID = 0
 
std::queue< ObjectToDestroym_ObjectToDestroyQueue
 
std::queue< std::pair< uint32_t, CTexture::UID > > m_TextureToDestroyQueue
 
std::unique_ptr< CRenderPassManagerm_RenderPassManager
 
std::unique_ptr< CSamplerManagerm_SamplerManager
 
std::unique_ptr< CDescriptorManagerm_DescriptorManager
 
std::unique_ptr< CSubmitSchedulerm_SubmitScheduler
 

Constructor & Destructor Documentation

◆ ~CDevice()

Renderer::Backend::Vulkan::CDevice::~CDevice ( )
override

◆ CDevice()

Renderer::Backend::Vulkan::CDevice::CDevice ( )
privatedefault

Member Function Documentation

◆ AcquireNextBackbuffer()

bool Renderer::Backend::Vulkan::CDevice::AcquireNextBackbuffer ( )
overridevirtual

Acquires a backbuffer for rendering a frame.

Returns
True if it was successfully acquired and we can render to it.

Implements Renderer::Backend::IDevice.

◆ Create()

std::unique_ptr< CDevice > Renderer::Backend::Vulkan::CDevice::Create ( SDL_Window window)
static

Creates the Vulkan device.

◆ CreateBuffer()

std::unique_ptr< IBuffer > Renderer::Backend::Vulkan::CDevice::CreateBuffer ( const char *  name,
const IBuffer::Type  type,
const uint32_t  size,
const bool  dynamic 
)
overridevirtual

◆ CreateCBuffer()

std::unique_ptr< CBuffer > Renderer::Backend::Vulkan::CDevice::CreateCBuffer ( const char *  name,
const IBuffer::Type  type,
const uint32_t  size,
const bool  dynamic 
)

◆ CreateCommandContext()

std::unique_ptr< IDeviceCommandContext > Renderer::Backend::Vulkan::CDevice::CreateCommandContext ( )
overridevirtual

◆ CreateFramebuffer()

std::unique_ptr< IFramebuffer > Renderer::Backend::Vulkan::CDevice::CreateFramebuffer ( const char *  name,
SColorAttachment colorAttachment,
SDepthStencilAttachment depthStencilAttachment 
)
overridevirtual
See also
IFramebuffer

The color attachment and the depth-stencil attachment should not be nullptr at the same time. There should not be many different clear colors along all color attachments for all framebuffers created for the device.

Returns
A valid framebuffer if it was created successfully else nullptr.

Implements Renderer::Backend::IDevice.

◆ CreateGraphicsPipelineState()

std::unique_ptr< IGraphicsPipelineState > Renderer::Backend::Vulkan::CDevice::CreateGraphicsPipelineState ( const SGraphicsPipelineStateDesc pipelineStateDesc)
overridevirtual

Creates a graphics pipeline state.

It's a caller responsibility to guarantee a lifespan of IShaderProgram stored in the description.

Implements Renderer::Backend::IDevice.

◆ CreateRingCommandContext()

std::unique_ptr< CRingCommandContext > Renderer::Backend::Vulkan::CDevice::CreateRingCommandContext ( const size_t  size)

◆ CreateShaderProgram()

std::unique_ptr< IShaderProgram > Renderer::Backend::Vulkan::CDevice::CreateShaderProgram ( const CStr &  name,
const CShaderDefines defines 
)
overridevirtual

◆ CreateTexture()

std::unique_ptr< ITexture > Renderer::Backend::Vulkan::CDevice::CreateTexture ( const char *  name,
const ITexture::Type  type,
const uint32_t  usage,
const Format  format,
const uint32_t  width,
const uint32_t  height,
const Sampler::Desc defaultSamplerDesc,
const uint32_t  MIPLevelCount,
const uint32_t  sampleCount 
)
overridevirtual

◆ CreateTexture2D()

std::unique_ptr< ITexture > Renderer::Backend::Vulkan::CDevice::CreateTexture2D ( const char *  name,
const uint32_t  usage,
const Format  format,
const uint32_t  width,
const uint32_t  height,
const Sampler::Desc defaultSamplerDesc,
const uint32_t  MIPLevelCount = 1,
const uint32_t  sampleCount = 1 
)
overridevirtual

◆ CreateVertexInputLayout()

std::unique_ptr< IVertexInputLayout > Renderer::Backend::Vulkan::CDevice::CreateVertexInputLayout ( const PS::span< const SVertexAttributeFormat attributes)
overridevirtual

Creates a vertex input layout.

It's recommended to use as few different layouts as posible.

Implements Renderer::Backend::IDevice.

◆ GetBackend()

Backend Renderer::Backend::Vulkan::CDevice::GetBackend ( ) const
inlineoverridevirtual

◆ GetCapabilities()

const Capabilities& Renderer::Backend::Vulkan::CDevice::GetCapabilities ( ) const
inlineoverridevirtual

◆ GetChoosenPhysicalDevice()

const SAvailablePhysicalDevice& Renderer::Backend::Vulkan::CDevice::GetChoosenPhysicalDevice ( ) const
inline

◆ GetCurrentBackbuffer()

IFramebuffer * Renderer::Backend::Vulkan::CDevice::GetCurrentBackbuffer ( const AttachmentLoadOp  colorAttachmentLoadOp,
const AttachmentStoreOp  colorAttachmentStoreOp,
const AttachmentLoadOp  depthStencilAttachmentLoadOp,
const AttachmentStoreOp  depthStencilAttachmentStoreOp 
)
overridevirtual

Returns a framebuffer for the current backbuffer with the required attachment operations.

It should not be called if the last AcquireNextBackbuffer call returned false.

It's guaranteed that for the same acquired backbuffer this function returns a framebuffer with the same attachments and properties except load and store operations.

Returns
The last successfully acquired framebuffer that wasn't presented.

Implements Renderer::Backend::IDevice.

◆ GetDescriptorManager()

CDescriptorManager& Renderer::Backend::Vulkan::CDevice::GetDescriptorManager ( )
inline

◆ GetDriverInformation()

const std::string& Renderer::Backend::Vulkan::CDevice::GetDriverInformation ( ) const
inlineoverridevirtual

◆ GetExtensions()

const std::vector<std::string>& Renderer::Backend::Vulkan::CDevice::GetExtensions ( ) const
inlineoverridevirtual

◆ GetName()

const std::string& Renderer::Backend::Vulkan::CDevice::GetName ( ) const
inlineoverridevirtual

◆ GetPreferredDepthStencilFormat()

Format Renderer::Backend::Vulkan::CDevice::GetPreferredDepthStencilFormat ( const uint32_t  usage,
const bool  depth,
const bool  stencil 
) const
overridevirtual

Returns the most suitable format for the usage.

Returns Format::UNDEFINED if there is no such format.

Implements Renderer::Backend::IDevice.

◆ GetRenderPassManager()

CRenderPassManager& Renderer::Backend::Vulkan::CDevice::GetRenderPassManager ( )
inline

◆ GetSamplerManager()

CSamplerManager& Renderer::Backend::Vulkan::CDevice::GetSamplerManager ( )
inline

◆ GetVersion()

const std::string& Renderer::Backend::Vulkan::CDevice::GetVersion ( ) const
inlineoverridevirtual

◆ GetVkDevice()

VkDevice Renderer::Backend::Vulkan::CDevice::GetVkDevice ( )
inline

◆ GetVMAAllocator()

VmaAllocator Renderer::Backend::Vulkan::CDevice::GetVMAAllocator ( )
inline

◆ IsFormatSupportedForUsage()

bool Renderer::Backend::Vulkan::CDevice::IsFormatSupportedForUsage ( const Format  format,
const uint32_t  usage 
) const
private

◆ IsFramebufferFormatSupported()

bool Renderer::Backend::Vulkan::CDevice::IsFramebufferFormatSupported ( const Format  format) const
overridevirtual

◆ IsSwapChainValid()

bool Renderer::Backend::Vulkan::CDevice::IsSwapChainValid ( )
private

◆ IsTextureFormatSupported()

bool Renderer::Backend::Vulkan::CDevice::IsTextureFormatSupported ( const Format  format) const
overridevirtual

◆ OnWindowResize()

void Renderer::Backend::Vulkan::CDevice::OnWindowResize ( const uint32_t  width,
const uint32_t  height 
)
overridevirtual

Should be called on window surface resize.

It's the device owner responsibility to call that function. Shouldn't be called during rendering to an acquired backbuffer.

Implements Renderer::Backend::IDevice.

◆ Present()

void Renderer::Backend::Vulkan::CDevice::Present ( )
overridevirtual

Presents the backbuffer to the swapchain queue to be flipped on a screen.

Should be called only if the last AcquireNextBackbuffer call returned true.

Implements Renderer::Backend::IDevice.

◆ ProcessObjectToDestroyQueue()

void Renderer::Backend::Vulkan::CDevice::ProcessObjectToDestroyQueue ( const bool  ignoreFrameID = false)
private

◆ ProcessTextureToDestroyQueue()

void Renderer::Backend::Vulkan::CDevice::ProcessTextureToDestroyQueue ( const bool  ignoreFrameID = false)
private

◆ RecreateSwapChain()

void Renderer::Backend::Vulkan::CDevice::RecreateSwapChain ( )
private

◆ Report()

void Renderer::Backend::Vulkan::CDevice::Report ( const ScriptRequest rq,
JS::HandleValue  settings 
)
overridevirtual

◆ ScheduleObjectToDestroy() [1/2]

void Renderer::Backend::Vulkan::CDevice::ScheduleObjectToDestroy ( VkObjectType  type,
const void *  handle,
const VmaAllocation  allocation 
)
inline

◆ ScheduleObjectToDestroy() [2/2]

void Renderer::Backend::Vulkan::CDevice::ScheduleObjectToDestroy ( VkObjectType  type,
const uint64_t  handle,
const VmaAllocation  allocation 
)

◆ ScheduleTextureToDestroy()

void Renderer::Backend::Vulkan::CDevice::ScheduleTextureToDestroy ( const CTexture::UID  uid)

◆ SetObjectName() [1/2]

void Renderer::Backend::Vulkan::CDevice::SetObjectName ( VkObjectType  type,
const void *  handle,
const char *  name 
)
inline

◆ SetObjectName() [2/2]

void Renderer::Backend::Vulkan::CDevice::SetObjectName ( VkObjectType  type,
const uint64_t  handle,
const char *  name 
)

Member Data Documentation

◆ m_AvailablePhysicalDevices

std::vector<SAvailablePhysicalDevice> Renderer::Backend::Vulkan::CDevice::m_AvailablePhysicalDevices
private

◆ m_Capabilities

Capabilities Renderer::Backend::Vulkan::CDevice::m_Capabilities {}
private

◆ m_ChoosenDevice

SAvailablePhysicalDevice Renderer::Backend::Vulkan::CDevice::m_ChoosenDevice {}
private

◆ m_DebugMessenger

VkDebugUtilsMessengerEXT Renderer::Backend::Vulkan::CDevice::m_DebugMessenger = VK_NULL_HANDLE
private

◆ m_DescriptorManager

std::unique_ptr<CDescriptorManager> Renderer::Backend::Vulkan::CDevice::m_DescriptorManager
private

◆ m_Device

VkDevice Renderer::Backend::Vulkan::CDevice::m_Device = VK_NULL_HANDLE
private

◆ m_DriverInformation

std::string Renderer::Backend::Vulkan::CDevice::m_DriverInformation
private

◆ m_Extensions

std::vector<std::string> Renderer::Backend::Vulkan::CDevice::m_Extensions
private

◆ m_FrameID

uint32_t Renderer::Backend::Vulkan::CDevice::m_FrameID = 0
private

◆ m_GraphicsQueue

VkQueue Renderer::Backend::Vulkan::CDevice::m_GraphicsQueue = VK_NULL_HANDLE
private

◆ m_GraphicsQueueFamilyIndex

uint32_t Renderer::Backend::Vulkan::CDevice::m_GraphicsQueueFamilyIndex = std::numeric_limits<uint32_t>::max()
private

◆ m_Instance

VkInstance Renderer::Backend::Vulkan::CDevice::m_Instance = VK_NULL_HANDLE
private

◆ m_InstanceExtensions

std::vector<std::string> Renderer::Backend::Vulkan::CDevice::m_InstanceExtensions
private

◆ m_Name

std::string Renderer::Backend::Vulkan::CDevice::m_Name
private

◆ m_ObjectToDestroyQueue

std::queue<ObjectToDestroy> Renderer::Backend::Vulkan::CDevice::m_ObjectToDestroyQueue
private

◆ m_RenderPassManager

std::unique_ptr<CRenderPassManager> Renderer::Backend::Vulkan::CDevice::m_RenderPassManager
private

◆ m_SamplerManager

std::unique_ptr<CSamplerManager> Renderer::Backend::Vulkan::CDevice::m_SamplerManager
private

◆ m_SubmitScheduler

std::unique_ptr<CSubmitScheduler> Renderer::Backend::Vulkan::CDevice::m_SubmitScheduler
private

◆ m_Surface

VkSurfaceKHR Renderer::Backend::Vulkan::CDevice::m_Surface = VK_NULL_HANDLE
private

◆ m_SwapChain

std::unique_ptr<CSwapChain> Renderer::Backend::Vulkan::CDevice::m_SwapChain
private

◆ m_TextureToDestroyQueue

std::queue<std::pair<uint32_t, CTexture::UID> > Renderer::Backend::Vulkan::CDevice::m_TextureToDestroyQueue
private

◆ m_ValidationLayers

std::vector<std::string> Renderer::Backend::Vulkan::CDevice::m_ValidationLayers
private

◆ m_VendorID

std::string Renderer::Backend::Vulkan::CDevice::m_VendorID
private

◆ m_Version

std::string Renderer::Backend::Vulkan::CDevice::m_Version
private

◆ m_VMAAllocator

VmaAllocator Renderer::Backend::Vulkan::CDevice::m_VMAAllocator = VK_NULL_HANDLE
private

◆ m_Window

SDL_Window* Renderer::Backend::Vulkan::CDevice::m_Window = nullptr
private

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