KiCad PCB EDA Suite
Loading...
Searching...
No Matches
rhi_vulkan_device.cpp File Reference
#include <rhi/rhi_vulkan_device.h>
#include <rhi/rhi_present_mode.h>
#include <wx/dynlib.h>
#include <vulkan/vulkan.h>
#include <trace_helpers.h>
#include <core/profile.h>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <vk_mem_alloc.h>
#include <wx/log.h>
#include <magic_enum.hpp>
#include <present_blit_vert.h>
#include <present_blit_frag.h>
#include <atomic>
#include <chrono>
#include <cstring>
#include <deque>
#include <mutex>
#include <optional>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Classes

struct  VulkanFunctions
 
struct  VK_ATTACHMENT
 
class  RHI_VULKAN_DEVICE
 
struct  RHI_VULKAN_DEVICE::BufferAllocation
 
struct  RHI_VULKAN_DEVICE::TextureAllocation
 
struct  RHI_VULKAN_DEVICE::StagingBuffer
 
struct  RHI_VULKAN_DEVICE::ShaderAllocation
 
struct  RHI_VULKAN_DEVICE::PipelineAllocation
 
struct  RHI_VULKAN_DEVICE::ComputePipelineAllocation
 
struct  RHI_VULKAN_DEVICE::BindGroupLayoutAllocation
 
struct  RHI_VULKAN_DEVICE::DescriptorPoolEntry
 
struct  RHI_VULKAN_DEVICE::BindGroupAllocation
 
struct  RHI_VULKAN_DEVICE::RenderPassAllocation
 
struct  RHI_VULKAN_DEVICE::FramebufferAllocation
 
struct  RHI_VULKAN_DEVICE::SurfaceAllocation
 
struct  RHI_VULKAN_DEVICE::SwapchainAllocation
 
struct  RHI_VULKAN_DEVICE::VkSwapchainTry
 

Macros

#define VMA_STATIC_VULKAN_FUNCTIONS   0
 
#define VMA_DYNAMIC_VULKAN_FUNCTIONS   1
 
#define LOAD_INST_FN(fn)
 
#define LOAD_DEV_FN(fn)
 

Functions

static const char * VkResultToString (VkResult aResult)
 
static long long VkElapsedMs (PROF_TIMER &aTimer)
 
static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugCallback (VkDebugUtilsMessageSeverityFlagBitsEXT aSeverity, VkDebugUtilsMessageTypeFlagsEXT aType, const VkDebugUtilsMessengerCallbackDataEXT *aCallbackData, void *aUserData)
 
static VkFormat RhiDefaultDepthFormat ()
 
static VkBlendFactor TranslateBlendFactor (RHI_BLEND_FACTOR factor)
 
static VkBlendOp TranslateBlendOp (RHI_BLEND_OP op)
 
static VkCompareOp TranslateCompareOp (RHI_COMPARE_OP op)
 
static VkFormat TranslateVertexFormat (RHI_VERTEX_FORMAT format)
 
static VkPrimitiveTopology TranslateTopology (RHI_PRIMITIVE_TOPOLOGY topology)
 
static VkDynamicState TranslateDynamicState (RHI_DYNAMIC_STATE state)
 
static VkAccessFlags LayoutToAccessMask (VkImageLayout layout)
 
static VkImageMemoryBarrier imageBarrier (VkImage aImage, VkImageAspectFlags aAspect, VkImageLayout aOld, VkImageLayout aNew, VkAccessFlags aSrcAccess, VkAccessFlags aDstAccess)
 
static VkDescriptorType TranslateBindingType (RHI_BINDING_TYPE type)
 
static VkShaderStageFlags TranslateShaderStage (RHI_SHADER_STAGE stages)
 
static VK_ATTACHMENT presentAttachment (VkFormat aFormat)
 
static VkAttachmentLoadOp TranslateLoadOp (RHI_LOAD_OP op)
 
static VkAttachmentStoreOp TranslateStoreOp (RHI_STORE_OP op)
 
static VkExtent2D swapchainExtent (const VkSurfaceCapabilitiesKHR &aCaps, uint32_t aWidth, uint32_t aHeight)
 
std::unique_ptr< RHI_DEVICE > RhiCreateVulkanDevice (bool enableValidation)
 Create the Vulkan device, loading libvulkan at run time.
 

Macro Definition Documentation

◆ LOAD_DEV_FN

#define LOAD_DEV_FN ( fn)
Value:
m_vk.fn = reinterpret_cast<PFN_vk##fn>( LoadDeviceFunction( "vk" #fn ) )

Referenced by RHI_VULKAN_DEVICE::LoadDeviceFunctions().

◆ LOAD_INST_FN

#define LOAD_INST_FN ( fn)
Value:
m_vk.fn = reinterpret_cast<PFN_vk##fn>( LoadInstanceFunction( "vk" #fn ) )

Referenced by RHI_VULKAN_DEVICE::CreateVkInstance().

◆ VMA_DYNAMIC_VULKAN_FUNCTIONS

#define VMA_DYNAMIC_VULKAN_FUNCTIONS   1

Definition at line 55 of file rhi_vulkan_device.cpp.

◆ VMA_STATIC_VULKAN_FUNCTIONS

#define VMA_STATIC_VULKAN_FUNCTIONS   0

Definition at line 54 of file rhi_vulkan_device.cpp.

Function Documentation

◆ imageBarrier()

static VkImageMemoryBarrier imageBarrier ( VkImage aImage,
VkImageAspectFlags aAspect,
VkImageLayout aOld,
VkImageLayout aNew,
VkAccessFlags aSrcAccess,
VkAccessFlags aDstAccess )
static

◆ LayoutToAccessMask()

static VkAccessFlags LayoutToAccessMask ( VkImageLayout layout)
static

Definition at line 2515 of file rhi_vulkan_device.cpp.

Referenced by RHI_VULKAN_DEVICE::TransitionTexture().

◆ presentAttachment()

static VK_ATTACHMENT presentAttachment ( VkFormat aFormat)
static

◆ RhiCreateVulkanDevice()

std::unique_ptr< RHI_DEVICE > RhiCreateVulkanDevice ( bool enableValidation = false)

Create the Vulkan device, loading libvulkan at run time.

Returns nullptr if Vulkan is not available or no suitable GPU is found.

Definition at line 6006 of file rhi_vulkan_device.cpp.

Referenced by RhiCreatePlatformDevice().

◆ RhiDefaultDepthFormat()

static VkFormat RhiDefaultDepthFormat ( )
static

◆ swapchainExtent()

static VkExtent2D swapchainExtent ( const VkSurfaceCapabilitiesKHR & aCaps,
uint32_t aWidth,
uint32_t aHeight )
static

◆ TranslateBindingType()

static VkDescriptorType TranslateBindingType ( RHI_BINDING_TYPE type)
static

◆ TranslateBlendFactor()

static VkBlendFactor TranslateBlendFactor ( RHI_BLEND_FACTOR factor)
static

Definition at line 1345 of file rhi_vulkan_device.cpp.

References ONE, ONE_MINUS_SRC_ALPHA, SRC_ALPHA, and ZERO.

Referenced by RHI_VULKAN_DEVICE::CreatePipeline().

◆ TranslateBlendOp()

static VkBlendOp TranslateBlendOp ( RHI_BLEND_OP op)
static

Definition at line 1359 of file rhi_vulkan_device.cpp.

References ADD.

Referenced by RHI_VULKAN_DEVICE::CreatePipeline().

◆ TranslateCompareOp()

static VkCompareOp TranslateCompareOp ( RHI_COMPARE_OP op)
static

Definition at line 1370 of file rhi_vulkan_device.cpp.

References LESS, and LESS_EQUAL.

Referenced by RHI_VULKAN_DEVICE::CreatePipeline().

◆ TranslateDynamicState()

static VkDynamicState TranslateDynamicState ( RHI_DYNAMIC_STATE state)
static

Definition at line 1409 of file rhi_vulkan_device.cpp.

References SCISSOR, and VIEWPORT.

Referenced by RHI_VULKAN_DEVICE::CreatePipeline().

◆ TranslateLoadOp()

static VkAttachmentLoadOp TranslateLoadOp ( RHI_LOAD_OP op)
static

Definition at line 3706 of file rhi_vulkan_device.cpp.

References CLEAR, DONT_CARE, and LOAD.

Referenced by RHI_VULKAN_DEVICE::CreateRenderPass().

◆ TranslateShaderStage()

static VkShaderStageFlags TranslateShaderStage ( RHI_SHADER_STAGE stages)
static

Definition at line 2563 of file rhi_vulkan_device.cpp.

References COMPUTE, FRAGMENT, NONE, and VERTEX.

Referenced by RHI_VULKAN_DEVICE::createSetLayout().

◆ TranslateStoreOp()

static VkAttachmentStoreOp TranslateStoreOp ( RHI_STORE_OP op)
static

Definition at line 3719 of file rhi_vulkan_device.cpp.

References DONT_CARE, and STORE.

Referenced by RHI_VULKAN_DEVICE::CreateRenderPass().

◆ TranslateTopology()

static VkPrimitiveTopology TranslateTopology ( RHI_PRIMITIVE_TOPOLOGY topology)
static

Definition at line 1398 of file rhi_vulkan_device.cpp.

References TRIANGLE_LIST.

Referenced by RHI_VULKAN_DEVICE::CreatePipeline().

◆ TranslateVertexFormat()

static VkFormat TranslateVertexFormat ( RHI_VERTEX_FORMAT format)
static

◆ VkElapsedMs()

static long long VkElapsedMs ( PROF_TIMER & aTimer)
static

Definition at line 106 of file rhi_vulkan_device.cpp.

References PROF_TIMER::msecs().

Referenced by RHI_VULKAN_DEVICE::Present().

◆ VkResultToString()

static const char * VkResultToString ( VkResult aResult)
static

◆ VulkanDebugCallback()

static VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugCallback ( VkDebugUtilsMessageSeverityFlagBitsEXT aSeverity,
VkDebugUtilsMessageTypeFlagsEXT aType,
const VkDebugUtilsMessengerCallbackDataEXT * aCallbackData,
void * aUserData )
static

Definition at line 1775 of file rhi_vulkan_device.cpp.

References traceRhi.

Referenced by RHI_VULKAN_DEVICE::CreateVkInstance().