vkQuake2 doxygen  1.0 dev
qvk.h File Reference
#include <windows.h>
#include <vulkan/vulkan.h>
#include "vk_mem_alloc.h"
#include "vk_shaders.h"

Go to the source code of this file.

Classes

struct  qvkdevice_t
 
struct  qvkswapchain_t
 
struct  qvktexture_t
 
struct  qvkrenderpass_t
 
struct  qvkbuffer_t
 
struct  qvkstagingbuffer_t
 
struct  qvkbufferopts_t
 
struct  qvkpipeline_t
 
struct  qvkshader_t
 

Macros

#define QVVKTEXTURE_INIT
 
#define QVVKTEXTURE_CLEAR(i)
 
#define QVKPIPELINE_INIT
 
#define QVk_DebugSetObjectName(a, b, c)
 
#define QVk_DebugSetObjectTag(a, b, c, d, e)
 
#define QVk_DebugLabelBegin(a, b, c, d, e)
 
#define QVk_DebugLabelEnd(a)
 
#define QVk_DebugLabelInsert(a, b, c, d, e)
 

Enumerations

enum  qvksampler_t {
  S_NEAREST = 0, S_LINEAR = 1, S_MIPMAP_NEAREST = 2, S_MIPMAP_LINEAR = 3,
  S_ANISO_NEAREST = 4, S_ANISO_LINEAR = 5, S_ANISO_MIPMAP_NEAREST = 6, S_ANISO_MIPMAP_LINEAR = 7,
  S_SAMPLER_CNT = 8
}
 
enum  qvkrenderpasstype_t { RP_WORLD = 0, RP_UI = 1, RP_WORLD_WARP = 2, RP_COUNT = 3 }
 

Functions

qboolean QVk_Init (void)
 
void QVk_Shutdown (void)
 
void QVk_CreateValidationLayers (void)
 
void QVk_DestroyValidationLayers (void)
 
qboolean QVk_CreateDevice (int preferredDeviceIdx)
 
VkResult QVk_CreateSwapchain (void)
 
VkFormat QVk_FindDepthFormat (void)
 
VkResult QVk_CreateCommandPool (VkCommandPool *commandPool, uint32_t queueFamilyIndex)
 
VkResult QVk_CreateImageView (const VkImage *image, VkImageAspectFlags aspectFlags, VkImageView *imageView, VkFormat format, uint32_t mipLevels)
 
VkResult QVk_CreateImage (uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VmaMemoryUsage memUsage, qvktexture_t *texture)
 
void QVk_CreateDepthBuffer (VkSampleCountFlagBits sampleCount, qvktexture_t *depthBuffer)
 
void QVk_CreateColorBuffer (VkSampleCountFlagBits sampleCount, qvktexture_t *colorBuffer, int extraFlags)
 
void QVk_CreateTexture (qvktexture_t *texture, const unsigned char *data, uint32_t width, uint32_t height, qvksampler_t samplerType)
 
void QVk_UpdateTextureData (qvktexture_t *texture, const unsigned char *data, uint32_t offset_x, uint32_t offset_y, uint32_t width, uint32_t height)
 
VkSampler QVk_UpdateTextureSampler (qvktexture_t *texture, qvksampler_t samplerType)
 
void QVk_ReleaseTexture (qvktexture_t *texture)
 
void QVk_ReadPixels (uint8_t *dstBuffer, uint32_t width, uint32_t height)
 
VkResult QVk_BeginCommand (const VkCommandBuffer *commandBuffer)
 
void QVk_SubmitCommand (const VkCommandBuffer *commandBuffer, const VkQueue *queue)
 
VkCommandBuffer QVk_CreateCommandBuffer (const VkCommandPool *commandPool, VkCommandBufferLevel level)
 
const char * QVk_GetError (VkResult errorCode)
 
VkResult QVk_BeginFrame (void)
 
VkResult QVk_EndFrame (qboolean force)
 
void QVk_BeginRenderpass (qvkrenderpasstype_t rpType)
 
void QVk_RecreateSwapchain (void)
 
VkResult QVk_CreateBuffer (VkDeviceSize size, qvkbuffer_t *dstBuffer, const qvkbufferopts_t options)
 
void QVk_FreeBuffer (qvkbuffer_t *buffer)
 
VkResult QVk_CreateStagingBuffer (VkDeviceSize size, qvkbuffer_t *dstBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
 
VkResult QVk_CreateUniformBuffer (VkDeviceSize size, qvkbuffer_t *dstBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
 
void QVk_CreateVertexBuffer (const void *data, VkDeviceSize size, qvkbuffer_t *dstBuffer, qvkbuffer_t *stagingBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
 
void QVk_CreateIndexBuffer (const void *data, VkDeviceSize size, qvkbuffer_t *dstBuffer, qvkbuffer_t *stagingBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
 
qvkshader_t QVk_CreateShader (const uint32_t *shaderSrc, size_t shaderCodeSize, VkShaderStageFlagBits shaderStage)
 
void QVk_CreatePipeline (const VkDescriptorSetLayout *descriptorLayout, const uint32_t desLayoutCount, const VkPipelineVertexInputStateCreateInfo *vertexInputInfo, qvkpipeline_t *pipeline, const qvkrenderpass_t *renderpass, const qvkshader_t *shaders, uint32_t shaderCount, VkPushConstantRange *pcRange)
 
void QVk_DestroyPipeline (qvkpipeline_t *pipeline)
 
uint8_t * QVk_GetVertexBuffer (VkDeviceSize size, VkBuffer *dstBuffer, VkDeviceSize *dstOffset)
 
uint8_t * QVk_GetIndexBuffer (VkDeviceSize size, VkDeviceSize *dstOffset)
 
uint8_t * QVk_GetUniformBuffer (VkDeviceSize size, uint32_t *dstOffset, VkDescriptorSet *dstUboDescriptorSet)
 
uint8_t * QVk_GetStagingBuffer (VkDeviceSize size, int alignment, VkCommandBuffer *cmdBuffer, VkBuffer *buffer, uint32_t *dstOffset)
 
VkBuffer QVk_GetTriangleFanIbo (VkDeviceSize indexCount)
 
void QVk_DrawColorRect (float *ubo, VkDeviceSize uboSize, qvkrenderpasstype_t rpType)
 
void QVk_DrawTexRect (float *ubo, VkDeviceSize uboSize, qvktexture_t *texture)
 
void QVk_BindPipeline (qvkpipeline_t *pipeline)
 
void QVk_SubmitStagingBuffers (void)
 

Variables

VkInstance vk_instance
 
VkSurfaceKHR vk_surface
 
qvkdevice_t vk_device
 
VmaAllocator vk_malloc
 
qvkswapchain_t vk_swapchain
 
VkCommandBuffer vk_activeCmdbuffer
 
VkCommandPool vk_commandPool
 
VkCommandPool vk_transferCommandPool
 
VkDescriptorPool vk_descriptorPool
 
VkDescriptorSetLayout vk_uboDescSetLayout
 
VkDescriptorSetLayout vk_samplerDescSetLayout
 
qvkpipeline_t vk_drawTexQuadPipeline
 
qvkpipeline_t vk_drawColorQuadPipeline [2]
 
qvkpipeline_t vk_drawModelPipelineStrip [2]
 
qvkpipeline_t vk_drawModelPipelineFan [2]
 
qvkpipeline_t vk_drawNoDepthModelPipelineStrip
 
qvkpipeline_t vk_drawNoDepthModelPipelineFan
 
qvkpipeline_t vk_drawLefthandModelPipelineStrip
 
qvkpipeline_t vk_drawLefthandModelPipelineFan
 
qvkpipeline_t vk_drawNullModelPipeline
 
qvkpipeline_t vk_drawParticlesPipeline
 
qvkpipeline_t vk_drawPointParticlesPipeline
 
qvkpipeline_t vk_drawSpritePipeline
 
qvkpipeline_t vk_drawPolyPipeline
 
qvkpipeline_t vk_drawPolyLmapPipeline
 
qvkpipeline_t vk_drawPolyWarpPipeline
 
qvkpipeline_t vk_drawBeamPipeline
 
qvkpipeline_t vk_drawSkyboxPipeline
 
qvkpipeline_t vk_drawDLightPipeline
 
qvkpipeline_t vk_showTrisPipeline
 
qvkpipeline_t vk_shadowsPipelineStrip
 
qvkpipeline_t vk_shadowsPipelineFan
 
qvkpipeline_t vk_worldWarpPipeline
 
qvkpipeline_t vk_postprocessPipeline
 
qvktexture_t vk_colorbuffer
 
qvktexture_t vk_colorbufferWarp
 
qboolean vk_frameStarted
 
PFN_vkCreateDebugUtilsMessengerEXT qvkCreateDebugUtilsMessengerEXT
 
PFN_vkDestroyDebugUtilsMessengerEXT qvkDestroyDebugUtilsMessengerEXT
 
PFN_vkSetDebugUtilsObjectNameEXT qvkSetDebugUtilsObjectNameEXT
 
PFN_vkSetDebugUtilsObjectTagEXT qvkSetDebugUtilsObjectTagEXT
 
PFN_vkCmdBeginDebugUtilsLabelEXT qvkCmdBeginDebugUtilsLabelEXT
 
PFN_vkCmdEndDebugUtilsLabelEXT qvkCmdEndDebugUtilsLabelEXT
 
PFN_vkCmdInsertDebugUtilsLabelEXT qvkInsertDebugUtilsLabelEXT
 

Macro Definition Documentation

◆ QVk_DebugLabelBegin

#define QVk_DebugLabelBegin (   a,
  b,
  c,
  d,
 
)

Definition at line 319 of file qvk.h.

◆ QVk_DebugLabelEnd

#define QVk_DebugLabelEnd (   a)

Definition at line 320 of file qvk.h.

◆ QVk_DebugLabelInsert

#define QVk_DebugLabelInsert (   a,
  b,
  c,
  d,
 
)

Definition at line 321 of file qvk.h.

◆ QVk_DebugSetObjectName

#define QVk_DebugSetObjectName (   a,
  b,
 
)

Definition at line 317 of file qvk.h.

◆ QVk_DebugSetObjectTag

#define QVk_DebugSetObjectTag (   a,
  b,
  c,
  d,
 
)

Definition at line 318 of file qvk.h.

◆ QVKPIPELINE_INIT

#define QVKPIPELINE_INIT
Value:
{ \
.layout = VK_NULL_HANDLE, \
.pl = VK_NULL_HANDLE, \
.flags = 0, \
.mode = VK_POLYGON_MODE_FILL, \
.cullMode = VK_CULL_MODE_BACK_BIT, \
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, \
.blendOpts = { \
.blendEnable = VK_FALSE, \
.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA, \
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, \
.colorBlendOp = VK_BLEND_OP_ADD, \
.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA, \
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, \
.alphaBlendOp = VK_BLEND_OP_ADD, \
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT \
}, \
.depthTestEnable = VK_TRUE, \
.depthWriteEnable = VK_TRUE \
}

Definition at line 172 of file qvk.h.

◆ QVVKTEXTURE_CLEAR

#define QVVKTEXTURE_CLEAR (   i)
Value:
{ \
(i).image = VK_NULL_HANDLE; \
(i).allocation = VK_NULL_HANDLE; \
(i).vmaFlags = 0; \
(i).imageView = VK_NULL_HANDLE; \
(i).sharingMode = VK_SHARING_MODE_MAX_ENUM; \
(i).sampleCount = VK_SAMPLE_COUNT_1_BIT; \
(i).format = VK_FORMAT_R8G8B8A8_UNORM; \
(i).mipLevels = 1; \
}

Definition at line 104 of file qvk.h.

◆ QVVKTEXTURE_INIT

#define QVVKTEXTURE_INIT
Value:
{ \
.image = VK_NULL_HANDLE, \
.allocation = VK_NULL_HANDLE, \
.allocInfo = VK_NULL_HANDLE, \
.vmaFlags = 0, \
.imageView = VK_NULL_HANDLE, \
.sharingMode = VK_SHARING_MODE_MAX_ENUM, \
.sampleCount = VK_SAMPLE_COUNT_1_BIT, \
.format = VK_FORMAT_R8G8B8A8_UNORM, \
.descriptorSet = VK_NULL_HANDLE, \
.mipLevels = 1, \
}

Definition at line 91 of file qvk.h.

Enumeration Type Documentation

◆ qvkrenderpasstype_t

Enumerator
RP_WORLD 
RP_UI 
RP_WORLD_WARP 
RP_COUNT 

Definition at line 194 of file qvk.h.

195 {
196  RP_WORLD = 0, // renders game world to offscreen buffer
197  RP_UI = 1, // render UI elements and game console
198  RP_WORLD_WARP = 2, // perform postprocessing on RP_WORLD (underwater screen warp)
199  RP_COUNT = 3

◆ qvksampler_t

Enumerator
S_NEAREST 
S_LINEAR 
S_MIPMAP_NEAREST 
S_MIPMAP_LINEAR 
S_ANISO_NEAREST 
S_ANISO_LINEAR 
S_ANISO_MIPMAP_NEAREST 
S_ANISO_MIPMAP_LINEAR 
S_SAMPLER_CNT 

Definition at line 63 of file qvk.h.

64 {
65  S_NEAREST = 0,
66  S_LINEAR = 1,
67  S_MIPMAP_NEAREST = 2,
68  S_MIPMAP_LINEAR = 3,
69  S_ANISO_NEAREST = 4,
70  S_ANISO_LINEAR = 5,
73  S_SAMPLER_CNT = 8
74 } qvksampler_t;

Function Documentation

◆ QVk_BeginCommand()

VkResult QVk_BeginCommand ( const VkCommandBuffer *  commandBuffer)

Definition at line 23 of file vk_cmd.c.

24 {
25  VkCommandBufferBeginInfo cmdInfo = {
26  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
27  .pNext = NULL,
28  .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
29  .pInheritanceInfo = NULL
30  };
31 
32  return vkBeginCommandBuffer(*commandBuffer, &cmdInfo);
33 }

Referenced by copyBuffer(), CreateStagingBuffers(), and QVk_ReadPixels().

◆ QVk_BeginFrame()

VkResult QVk_BeginFrame ( void  )

Definition at line 1824 of file vk_common.c.

1825 {
1826  // reset tracking variables
1827  vk_state.current_pipeline = VK_NULL_HANDLE;
1829  // triangle fan index buffer data will not be cleared between frames unless the buffer itself is too small
1833 
1835 
1836  VkResult result = vkAcquireNextImageKHR(vk_device.logical, vk_swapchain.sc, UINT32_MAX, vk_imageAvailableSemaphores[vk_activeBufferIdx], VK_NULL_HANDLE, &vk_imageIndex);
1838 
1839  // swap dynamic buffers
1843  // triangle fan index data is placed in the beginning of the buffer
1848 
1849  // for VK_OUT_OF_DATE_KHR and VK_SUBOPTIMAL_KHR it'd be fine to just rebuild the swapchain but let's take the easy way out and restart video system
1850  if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || result == VK_ERROR_SURFACE_LOST_KHR)
1851  {
1852  ri.Con_Printf(PRINT_ALL, "QVk_BeginFrame(): received %s after vkAcquireNextImageKHR - restarting video!\n", QVk_GetError(result));
1853  return result;
1854  }
1855  else if (result != VK_SUCCESS)
1856  {
1857  Sys_Error("QVk_BeginFrame(): unexpected error after vkAcquireNextImageKHR: %s", QVk_GetError(result));
1858  }
1859 
1860  VK_VERIFY(vkWaitForFences(vk_device.logical, 1, &vk_fences[vk_activeBufferIdx], VK_TRUE, UINT32_MAX));
1861  VK_VERIFY(vkResetFences(vk_device.logical, 1, &vk_fences[vk_activeBufferIdx]));
1862 
1863  // setup command buffers and render pass for drawing
1864  VkCommandBufferBeginInfo beginInfo = {
1865  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1866  .pNext = NULL,
1867  .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
1868  .pInheritanceInfo = NULL
1869  };
1870 
1871  VK_VERIFY(vkBeginCommandBuffer(vk_commandbuffers[vk_activeBufferIdx], &beginInfo));
1872 
1873  vkCmdSetViewport(vk_commandbuffers[vk_activeBufferIdx], 0, 1, &vk_viewport);
1874  vkCmdSetScissor(vk_commandbuffers[vk_activeBufferIdx], 0, 1, &vk_scissor);
1875 
1876  vk_frameStarted = true;
1877  return VK_SUCCESS;
1878 }

Referenced by R_BeginFrame().

◆ QVk_BeginRenderpass()

void QVk_BeginRenderpass ( qvkrenderpasstype_t  rpType)

Definition at line 1946 of file vk_common.c.

1947 {
1948  VkClearValue clearColors[3] = {
1949  {.color = { 1.f, .0f, .5f, 1.f } },
1950  {.depthStencil = { 1.f, 0 } },
1951  {.color = { 1.f, .0f, .5f, 1.f } },
1952  };
1953 
1954  VkRenderPassBeginInfo renderBeginInfo[] = {
1955  // RP_WORLD
1956  {
1957  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1958  .renderPass = vk_renderpasses[RP_WORLD].rp,
1959  .framebuffer = vk_framebuffers[RP_WORLD][vk_imageIndex],
1960  .renderArea.offset = { 0, 0 },
1961  .renderArea.extent = vk_swapchain.extent,
1962  .clearValueCount = vk_renderpasses[RP_WORLD].sampleCount != VK_SAMPLE_COUNT_1_BIT ? 3 : 2,
1963  .pClearValues = clearColors
1964  },
1965  // RP_UI
1966  {
1967  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1968  .renderPass = vk_renderpasses[RP_UI].rp,
1969  .framebuffer = vk_framebuffers[RP_UI][vk_imageIndex],
1970  .renderArea.offset = { 0, 0 },
1971  .renderArea.extent = vk_swapchain.extent,
1972  .clearValueCount = 2,
1973  .pClearValues = clearColors
1974  },
1975  // RP_WORLD_WARP
1976  {
1977  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1978  .renderPass = vk_renderpasses[RP_WORLD_WARP].rp,
1979  .framebuffer = vk_framebuffers[RP_WORLD_WARP][vk_imageIndex],
1980  .renderArea.offset = { 0, 0 },
1981  .renderArea.extent = vk_swapchain.extent,
1982  .clearValueCount = 1,
1983  .pClearValues = clearColors
1984  }
1985  };
1986 
1987 #if defined(_DEBUG) || defined(ENABLE_DEBUG_LABELS)
1988  if (rpType == RP_WORLD) {
1989  QVk_DebugLabelBegin(&vk_commandbuffers[vk_activeBufferIdx], "Draw World", 0.f, 1.f, 0.f);
1990  }
1991  if (rpType == RP_UI) {
1993  QVk_DebugLabelBegin(&vk_commandbuffers[vk_activeBufferIdx], "Draw UI", 1.f, 1.f, 0.f);
1994  }
1995  if (rpType == RP_WORLD_WARP) {
1997  QVk_DebugLabelBegin(&vk_commandbuffers[vk_activeBufferIdx], "Draw View Warp", 1.f, 0.f, .5f);
1998  }
1999 #endif
2000 
2001  vkCmdBeginRenderPass(vk_commandbuffers[vk_activeBufferIdx], &renderBeginInfo[rpType], VK_SUBPASS_CONTENTS_INLINE);
2002 }

Referenced by R_BeginFrame(), and R_EndWorldRenderpass().

◆ QVk_BindPipeline()

◆ QVk_CreateBuffer()

VkResult QVk_CreateBuffer ( VkDeviceSize  size,
qvkbuffer_t dstBuffer,
const qvkbufferopts_t  options 
)

Definition at line 70 of file vk_buffer.c.

71 {
72  VkBufferCreateInfo bcInfo = {
73  .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
74  .pNext = NULL,
75  .flags = 0,
76  .size = size,
77  .usage = options.usage,
78  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
79  .queueFamilyIndexCount = 0,
80  .pQueueFamilyIndices = NULL,
81  };
82 
83  // separate transfer queue makes sense only if the buffer is targetted for being transfered to GPU, so ignore it if it's CPU-only
84  uint32_t queueFamilies[] = { (uint32_t)vk_device.gfxFamilyIndex, (uint32_t)vk_device.transferFamilyIndex };
86  {
87  bcInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
88  bcInfo.queueFamilyIndexCount = 2;
89  bcInfo.pQueueFamilyIndices = queueFamilies;
90  }
91 
92  VmaAllocationCreateInfo vmallocInfo = {
93  .flags = options.vmaFlags,
94  .usage = options.vmaUsage,
95  .requiredFlags = options.reqMemFlags,
96  .preferredFlags = options.prefMemFlags,
97  .memoryTypeBits = 0,
98  .pool = VK_NULL_HANDLE,
99  .pUserData = NULL
100  };
101 
102  dstBuffer->currentOffset = 0;
103  return vmaCreateBuffer(vk_malloc, &bcInfo, &vmallocInfo, &dstBuffer->buffer, &dstBuffer->allocation, &dstBuffer->allocInfo);
104 }

Referenced by createStagedBuffer(), QVk_CreateStagingBuffer(), QVk_CreateUniformBuffer(), and QVk_ReadPixels().

◆ QVk_CreateColorBuffer()

void QVk_CreateColorBuffer ( VkSampleCountFlagBits  sampleCount,
qvktexture_t colorBuffer,
int  extraFlags 
)

Definition at line 367 of file vk_image.c.

368 {
369  colorBuffer->format = vk_swapchain.format;
370  colorBuffer->sampleCount = sampleCount;
371  // On 64-bit builds, Intel drivers throw a warning:
372  // "Mapping an image with layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used."
373  // Minor annoyance but we don't want any validation warnings, so we create dedicated allocation for color buffer.
374  // more details: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/34
375  // Note that this is a false positive which in other cases could be ignored: https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/general_considerations.html#general_considerations_validation_layer_warnings
377 
378  VK_VERIFY(QVk_CreateImage(vk_swapchain.extent.width, vk_swapchain.extent.height, colorBuffer->format, VK_IMAGE_TILING_OPTIMAL, extraFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VMA_MEMORY_USAGE_GPU_ONLY, colorBuffer));
379  VK_VERIFY(QVk_CreateImageView(&colorBuffer->image, VK_IMAGE_ASPECT_COLOR_BIT, &colorBuffer->imageView, colorBuffer->format, colorBuffer->mipLevels));
380 }

Referenced by CreateDrawBuffers().

◆ QVk_CreateCommandBuffer()

VkCommandBuffer QVk_CreateCommandBuffer ( const VkCommandPool *  commandPool,
VkCommandBufferLevel  level 
)

Definition at line 78 of file vk_cmd.c.

79 {
80  VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
81  VkCommandBufferAllocateInfo allocInfo = {
82  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
83  .pNext = NULL,
84  .commandPool = *commandPool,
85  .level = level,
86  .commandBufferCount = 1
87  };
88 
89  VK_VERIFY(vkAllocateCommandBuffers(vk_device.logical, &allocInfo, &commandBuffer));
90  return commandBuffer;
91 }

Referenced by copyBuffer(), CreateStagingBuffers(), and QVk_ReadPixels().

◆ QVk_CreateCommandPool()

VkResult QVk_CreateCommandPool ( VkCommandPool *  commandPool,
uint32_t  queueFamilyIndex 
)

Definition at line 65 of file vk_cmd.c.

66 {
67  VkCommandPoolCreateInfo cpCreateInfo = {
68  .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
69  .pNext = NULL,
70  // allow the command pool to be explicitly reset without reallocating it manually during recording each frame
71  .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
72  .queueFamilyIndex = queueFamilyIndex
73  };
74 
75  return vkCreateCommandPool(vk_device.logical, &cpCreateInfo, NULL, commandPool);
76 }

Referenced by CreateStagingBuffers(), and QVk_Init().

◆ QVk_CreateDepthBuffer()

void QVk_CreateDepthBuffer ( VkSampleCountFlagBits  sampleCount,
qvktexture_t depthBuffer 
)

Definition at line 352 of file vk_image.c.

353 {
354  depthBuffer->format = QVk_FindDepthFormat();
355  depthBuffer->sampleCount = sampleCount;
356  // On 64-bit builds, Intel drivers throw a warning:
357  // "Mapping an image with layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used."
358  // Minor annoyance but we don't want any validation warnings, so we create dedicated allocation for depth buffer.
359  // more details: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/34
360  // Note that this is a false positive which in other cases could be ignored: https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/general_considerations.html#general_considerations_validation_layer_warnings
362 
363  VK_VERIFY(QVk_CreateImage(vk_swapchain.extent.width, vk_swapchain.extent.height, depthBuffer->format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VMA_MEMORY_USAGE_GPU_ONLY, depthBuffer));
364  VK_VERIFY(QVk_CreateImageView(&depthBuffer->image, getDepthStencilAspect(depthBuffer->format), &depthBuffer->imageView, depthBuffer->format, depthBuffer->mipLevels));
365 }

Referenced by CreateDrawBuffers().

◆ QVk_CreateDevice()

qboolean QVk_CreateDevice ( int  preferredDeviceIdx)

Definition at line 264 of file vk_device.c.

265 {
266  if (!selectPhysicalDevice(preferredDeviceIdx))
267  return false;
268 
271 
272  VkResult res = createLogicalDevice();
273  if (res != VK_SUCCESS)
274  {
275  ri.Con_Printf(PRINT_ALL, "Could not create Vulkan logical device: %s\n", QVk_GetError(res));
276  return false;
277  }
278 
282 
283  return true;
284 }

Referenced by QVk_Init().

◆ QVk_CreateImage()

VkResult QVk_CreateImage ( uint32_t  width,
uint32_t  height,
VkFormat  format,
VkImageTiling  tiling,
VkImageUsageFlags  usage,
VmaMemoryUsage  memUsage,
qvktexture_t texture 
)

Definition at line 316 of file vk_image.c.

317 {
318  VkImageCreateInfo imageInfo = {
319  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
320  .imageType = VK_IMAGE_TYPE_2D,
321  .extent.width = width,
322  .extent.height = height,
323  .extent.depth = 1,
324  .mipLevels = texture->mipLevels,
325  .arrayLayers = 1,
326  .format = format,
327  .tiling = tiling,
328  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
329  .usage = usage,
330  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
331  .samples = texture->sampleCount,
332  .flags = 0
333  };
334 
335  uint32_t queueFamilies[] = { (uint32_t)vk_device.gfxFamilyIndex, (uint32_t)vk_device.transferFamilyIndex };
337  {
338  imageInfo.sharingMode = VK_SHARING_MODE_CONCURRENT;
339  imageInfo.queueFamilyIndexCount = 2;
340  imageInfo.pQueueFamilyIndices = queueFamilies;
341  }
342 
343  VmaAllocationCreateInfo vmallocInfo = {
344  .flags = texture->vmaFlags,
345  .usage = memUsage
346  };
347 
348  texture->sharingMode = imageInfo.sharingMode;
349  return vmaCreateImage(vk_malloc, &imageInfo, &vmallocInfo, &texture->image, &texture->allocation, &texture->allocInfo);
350 }

Referenced by createTextureImage(), QVk_CreateColorBuffer(), and QVk_CreateDepthBuffer().

◆ QVk_CreateImageView()

VkResult QVk_CreateImageView ( const VkImage *  image,
VkImageAspectFlags  aspectFlags,
VkImageView *  imageView,
VkFormat  format,
uint32_t  mipLevels 
)

Definition at line 293 of file vk_image.c.

294 {
295  VkImageViewCreateInfo ivCreateInfo = {
296  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
297  .pNext = NULL,
298  .flags = 0,
299  .image = *image,
300  .viewType = VK_IMAGE_VIEW_TYPE_2D,
301  .format = format,
302  .components.r = VK_COMPONENT_SWIZZLE_IDENTITY,
303  .components.g = VK_COMPONENT_SWIZZLE_IDENTITY,
304  .components.b = VK_COMPONENT_SWIZZLE_IDENTITY,
305  .components.a = VK_COMPONENT_SWIZZLE_IDENTITY,
306  .subresourceRange.aspectMask = aspectFlags,
307  .subresourceRange.baseArrayLayer = 0,
308  .subresourceRange.baseMipLevel = 0,
309  .subresourceRange.layerCount = 1,
310  .subresourceRange.levelCount = mipLevels
311  };
312 
313  return vkCreateImageView(vk_device.logical, &ivCreateInfo, NULL, imageView);
314 }

Referenced by CreateImageViews(), QVk_CreateColorBuffer(), QVk_CreateDepthBuffer(), and QVk_CreateTexture().

◆ QVk_CreateIndexBuffer()

void QVk_CreateIndexBuffer ( const void data,
VkDeviceSize  size,
qvkbuffer_t dstBuffer,
qvkbuffer_t stagingBuffer,
VkMemoryPropertyFlags  reqMemFlags,
VkMemoryPropertyFlags  prefMemFlags 
)

Definition at line 158 of file vk_buffer.c.

159 {
160  qvkbufferopts_t dstOpts = {
161  .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
162  .reqMemFlags = reqMemFlags,
163  .prefMemFlags = prefMemFlags,
164  .vmaUsage = VMA_MEMORY_USAGE_GPU_ONLY,
165  .vmaFlags = 0
166  };
167 
168  createStagedBuffer(data, size, dstBuffer, dstOpts, stagingBuffer);
169 }

Referenced by CreateDynamicBuffers(), CreateStaticBuffers(), and QVk_GetIndexBuffer().

◆ QVk_CreatePipeline()

void QVk_CreatePipeline ( const VkDescriptorSetLayout *  descriptorLayout,
const uint32_t  desLayoutCount,
const VkPipelineVertexInputStateCreateInfo *  vertexInputInfo,
qvkpipeline_t pipeline,
const qvkrenderpass_t renderpass,
const qvkshader_t shaders,
uint32_t  shaderCount,
VkPushConstantRange *  pcRange 
)

Definition at line 51 of file vk_pipeline.c.

53 {
54  VkPipelineShaderStageCreateInfo *ssCreateInfos = (VkPipelineShaderStageCreateInfo *)malloc(shaderCount * sizeof(VkPipelineShaderStageCreateInfo));
55  for (int i = 0; i < shaderCount; i++)
56  {
57  ssCreateInfos[i] = shaders[i].createInfo;
58  }
59 
60  VkPipelineInputAssemblyStateCreateInfo iaCreateInfo = {
61  .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
62  .pNext = NULL,
63  .flags = 0,
64  .topology = pipeline->topology,
65  .primitiveRestartEnable = VK_FALSE
66  };
67 
68  VkViewport viewport = {
69  .x = 0.f,
70  .y = 0.f,
71  .width = (float)vid.width,
72  .height = (float)vid.height,
73  .minDepth = 0.f,
74  .maxDepth = 1.f,
75  };
76 
77  VkRect2D scissor = {
78  .offset.x = 0,
79  .offset.y = 0,
80  .extent = vk_swapchain.extent
81  };
82 
83  VkPipelineViewportStateCreateInfo vpCreateInfo = {
84  .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
85  .pNext = NULL,
86  .flags = 0,
87  .viewportCount = 1,
88  .pViewports = &viewport,
89  .scissorCount = 1,
90  .pScissors = &scissor
91  };
92 
93  VkPipelineRasterizationStateCreateInfo rCreateInfo = {
94  .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
95  .pNext = NULL,
96  .flags = 0,
97  .depthClampEnable = VK_FALSE,
98  .rasterizerDiscardEnable = VK_FALSE,
99  .polygonMode = pipeline->mode,
100  .cullMode = pipeline->cullMode,
101  .frontFace = VK_FRONT_FACE_CLOCKWISE,
102  .depthBiasEnable = VK_FALSE,
103  .depthBiasConstantFactor = 0.f,
104  .depthBiasClamp = 0.f,
105  .depthBiasSlopeFactor = 0.f,
106  .lineWidth = 1.f
107  };
108 
109  VkPipelineMultisampleStateCreateInfo msCreateInfo = {
110  .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
111  .pNext = NULL,
112  .flags = 0,
113  .rasterizationSamples = renderpass->sampleCount,
114  .sampleShadingEnable = (vk_sampleshading->value > 0 && vk_device.features.sampleRateShading) ? VK_TRUE : VK_FALSE,
115  .minSampleShading = (vk_sampleshading->value > 0 && vk_device.features.sampleRateShading) ? 1.f : 0.f,
116  .pSampleMask = NULL,
117  .alphaToCoverageEnable = VK_FALSE,
118  .alphaToOneEnable = VK_FALSE
119  };
120 
121  VkPipelineDepthStencilStateCreateInfo dCreateInfo = {
122  .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
123  .pNext = NULL,
124  .flags = 0,
125  .depthTestEnable = pipeline->depthTestEnable,
126  .depthWriteEnable = pipeline->depthTestEnable == VK_TRUE ? pipeline->depthWriteEnable : VK_FALSE, // there should be NO depth writes if depthTestEnable is false but Intel seems to not follow the specs fully...
127  .depthCompareOp = VK_COMPARE_OP_LESS,
128  .depthBoundsTestEnable = VK_FALSE,
129  .stencilTestEnable = VK_FALSE,
130  .front = { VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_COMPARE_OP_NEVER, 0, 0, 0 },
131  .back = { VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_STENCIL_OP_KEEP, VK_COMPARE_OP_NEVER, 0, 0, 0 },
132  .minDepthBounds = 0.f,
133  .maxDepthBounds = 1.f
134  };
135 
136  VkPipelineColorBlendStateCreateInfo cbsCreateInfo = {
137  .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
138  .pNext = NULL,
139  .flags = 0,
140  .logicOpEnable = VK_FALSE,
141  .logicOp = VK_LOGIC_OP_COPY,
142  .attachmentCount = 1,
143  .pAttachments = &pipeline->blendOpts,
144  .blendConstants[0] = 0.f,
145  .blendConstants[1] = 0.f,
146  .blendConstants[2] = 0.f,
147  .blendConstants[3] = 0.f
148  };
149 
150  VkDynamicState dynamicStates[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
151  VkPipelineDynamicStateCreateInfo dsCreateInfo = {
152  .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
153  .pNext = NULL,
154  .flags = 0,
155  .dynamicStateCount = 2,
156  .pDynamicStates = dynamicStates
157  };
158 
159  VkPipelineLayoutCreateInfo plCreateInfo = {
160  .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
161  .pNext = NULL,
162  .flags = 0,
163  .setLayoutCount = descLayoutCount,
164  .pSetLayouts = descriptorLayout,
165  .pushConstantRangeCount = pcRange ? 1 : 0, // for simplicity assume only one push constant range is passed, so it's not the most flexible approach
166  .pPushConstantRanges = pcRange
167  };
168 
169  VK_VERIFY(vkCreatePipelineLayout(vk_device.logical, &plCreateInfo, NULL, &pipeline->layout));
170 
171  // create THE pipeline
172  VkGraphicsPipelineCreateInfo pCreateInfo = {
173  .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
174  .pNext = NULL,
175  .flags = pipeline->flags,
176  .stageCount = shaderCount,
177  .pStages = ssCreateInfos,
178  .pVertexInputState = vertexInputInfo,
179  .pInputAssemblyState = &iaCreateInfo,
180  .pTessellationState = NULL,
181  .pViewportState = &vpCreateInfo,
182  .pRasterizationState = &rCreateInfo,
183  .pMultisampleState = &msCreateInfo,
184  .pDepthStencilState = &dCreateInfo,
185  .pColorBlendState = &cbsCreateInfo,
186  .pDynamicState = &dsCreateInfo,
187  .layout = pipeline->layout,
188  .renderPass = renderpass->rp,
189  .subpass = 0,
190  .basePipelineHandle = VK_NULL_HANDLE,
191  .basePipelineIndex = -1
192  };
193 
194  VK_VERIFY(vkCreateGraphicsPipelines(vk_device.logical, VK_NULL_HANDLE, 1, &pCreateInfo, NULL, &pipeline->pl));
195  free(ssCreateInfos);
196 }

Referenced by CreatePipelines().

◆ QVk_CreateShader()

qvkshader_t QVk_CreateShader ( const uint32_t *  shaderSrc,
size_t  shaderCodeSize,
VkShaderStageFlagBits  shaderStage 
)

Definition at line 23 of file vk_pipeline.c.

24 {
25  qvkshader_t shader;
26  VkShaderModuleCreateInfo smCreateInfo = {
27  .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
28  .pNext = NULL,
29  .flags = 0,
30  .codeSize = shaderCodeSize,
31  .pCode = shaderSrc
32  };
33 
34  VK_VERIFY(vkCreateShaderModule(vk_device.logical, &smCreateInfo, NULL, &shader.module));
35 
36  VkPipelineShaderStageCreateInfo vssCreateInfo = {
37  .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
38  .pNext = NULL,
39  .flags = 0,
40  .stage = shaderStage,
41  .module = shader.module,
42  .pName = "main",
43  .pSpecializationInfo = NULL
44  };
45 
46  shader.createInfo = vssCreateInfo;
47 
48  return shader;
49 }

◆ QVk_CreateStagingBuffer()

VkResult QVk_CreateStagingBuffer ( VkDeviceSize  size,
qvkbuffer_t dstBuffer,
VkMemoryPropertyFlags  reqMemFlags,
VkMemoryPropertyFlags  prefMemFlags 
)

Definition at line 114 of file vk_buffer.c.

115 {
116  qvkbufferopts_t stagingOpts = {
117  .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
118  .reqMemFlags = reqMemFlags,
119  .prefMemFlags = prefMemFlags,
120  .vmaUsage = VMA_MEMORY_USAGE_CPU_ONLY,
121  .vmaFlags = 0
122  };
123 
124  return QVk_CreateBuffer(size, dstBuffer, stagingOpts);
125 }

Referenced by createStagedBuffer(), and CreateStagingBuffers().

◆ QVk_CreateSwapchain()

VkResult QVk_CreateSwapchain ( void  )

Definition at line 117 of file vk_swapchain.c.

118 {
119  VkSurfaceCapabilitiesKHR surfaceCaps;
120  VkSurfaceFormatKHR *surfaceFormats = NULL;
121  VkPresentModeKHR *presentModes = NULL;
122  uint32_t formatCount, presentModesCount;
123  VK_VERIFY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_device.physical, vk_surface, &surfaceCaps));
124  VK_VERIFY(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_device.physical, vk_surface, &formatCount, NULL));
125  VK_VERIFY(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_device.physical, vk_surface, &presentModesCount, NULL));
126 
127  if (formatCount > 0)
128  {
129  surfaceFormats = (VkSurfaceFormatKHR *)malloc(formatCount * sizeof(VkSurfaceFormatKHR));
130  VK_VERIFY(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_device.physical, vk_surface, &formatCount, surfaceFormats));
131  }
132 
133  if (presentModesCount > 0)
134  {
135  presentModes = (VkPresentModeKHR *)malloc(presentModesCount * sizeof(VkPresentModeKHR));
136  VK_VERIFY(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_device.physical, vk_surface, &presentModesCount, presentModes));
137 
138  ri.Con_Printf(PRINT_ALL, "Supported present modes: ");
139  for (int i = 0; i < presentModesCount; i++)
140  {
141  ri.Con_Printf(PRINT_ALL, "%s ", presentModeString(presentModes[i]));
143  }
144  ri.Con_Printf(PRINT_ALL, "\n");
145  }
146 
147  VkSurfaceFormatKHR swapSurfaceFormat = getSwapSurfaceFormat(surfaceFormats, formatCount);
148  VkPresentModeKHR swapPresentMode = getSwapPresentMode(presentModes, presentModesCount, vk_vsync->value > 0 ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_MAILBOX_KHR);
149  free(surfaceFormats);
150  free(presentModes);
151 
152  VkExtent2D extent = surfaceCaps.currentExtent;
153  if(extent.width == UINT32_MAX || extent.height == UINT32_MAX)
154  {
155  extent.width = max(surfaceCaps.minImageExtent.width, min(surfaceCaps.maxImageExtent.width, vid.width));
156  extent.height = max(surfaceCaps.minImageExtent.height, min(surfaceCaps.maxImageExtent.height, vid.height));
157  }
158 
159  // request at least 2 images - this fixes fullscreen crashes on AMD when launching the game in fullscreen
160  uint32_t imageCount = max(2, surfaceCaps.minImageCount);
161  if (swapPresentMode == VK_PRESENT_MODE_MAILBOX_KHR)
162  imageCount = max(3, surfaceCaps.minImageCount);
163 
164  if (surfaceCaps.maxImageCount > 0)
165  imageCount = min(imageCount, surfaceCaps.maxImageCount);
166 
167  VkSwapchainKHR oldSwapchain = vk_swapchain.sc;
168  VkSwapchainCreateInfoKHR scCreateInfo = {
169  .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
170  .pNext = NULL,
171  .flags = 0,
172  .surface = vk_surface,
173  .minImageCount = imageCount,
174  .imageFormat = swapSurfaceFormat.format,
175  .imageColorSpace = swapSurfaceFormat.colorSpace,
176  .imageExtent = extent,
177  .imageArrayLayers = 1,
178  .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // TRANSFER_SRC_BIT is required for taking screenshots
179  .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
180  .queueFamilyIndexCount = 0,
181  .pQueueFamilyIndices = NULL,
182  .preTransform = surfaceCaps.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ? VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR : surfaceCaps.currentTransform,
183  .compositeAlpha = getSupportedCompositeAlpha(surfaceCaps.supportedCompositeAlpha),
184  .presentMode = swapPresentMode,
185  .clipped = VK_TRUE,
186  .oldSwapchain = oldSwapchain
187  };
188 
189  uint32_t queueFamilyIndices[] = { (uint32_t)vk_device.gfxFamilyIndex, (uint32_t)vk_device.presentFamilyIndex };
191  {
192  scCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
193  scCreateInfo.queueFamilyIndexCount = 2;
194  scCreateInfo.pQueueFamilyIndices = queueFamilyIndices;
195  }
196 
197  vk_swapchain.format = swapSurfaceFormat.format;
198  vk_swapchain.extent = extent;
199  ri.Con_Printf(PRINT_ALL, "...trying swapchain extent: %dx%d\n", vk_swapchain.extent.width, vk_swapchain.extent.height);
200  ri.Con_Printf(PRINT_ALL, "...trying swapchain image format: %d\n", vk_swapchain.format);
201 
202  VkResult res = vkCreateSwapchainKHR(vk_device.logical, &scCreateInfo, NULL, &vk_swapchain.sc);
203  if (res != VK_SUCCESS)
204  return res;
205 
206  VK_VERIFY(vkGetSwapchainImagesKHR(vk_device.logical, vk_swapchain.sc, &imageCount, NULL));
207  vk_swapchain.images = (VkImage *)malloc(imageCount * sizeof(VkImage));
208  vk_swapchain.imageCount = imageCount;
209  res = vkGetSwapchainImagesKHR(vk_device.logical, vk_swapchain.sc, &imageCount, vk_swapchain.images);
210 
211  if (oldSwapchain != VK_NULL_HANDLE)
212  vkDestroySwapchainKHR(vk_device.logical, oldSwapchain, NULL);
213 
214  return res;
215 }

Referenced by QVk_Init(), and QVk_RecreateSwapchain().

◆ QVk_CreateTexture()

void QVk_CreateTexture ( qvktexture_t texture,
const unsigned char *  data,
uint32_t  width,
uint32_t  height,
qvksampler_t  samplerType 
)

Definition at line 382 of file vk_image.c.

383 {
385  VK_VERIFY(QVk_CreateImageView(&texture->image, VK_IMAGE_ASPECT_COLOR_BIT, &texture->imageView, texture->format, texture->mipLevels));
386 
387  // create descriptor set for the texture
388  VkDescriptorSetAllocateInfo dsAllocInfo = {
389  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
390  .pNext = NULL,
391  .descriptorPool = vk_descriptorPool,
392  .descriptorSetCount = 1,
393  .pSetLayouts = &vk_samplerDescSetLayout
394  };
395 
396  VK_VERIFY(vkAllocateDescriptorSets(vk_device.logical, &dsAllocInfo, &texture->descriptorSet));
397 
398  // attach sampler
399  QVk_UpdateTextureSampler(texture, samplerType);
400 }

Referenced by Draw_StretchRaw(), LM_UploadBlock(), Vk_BeginBuildingLightmaps(), and Vk_LoadPic().

◆ QVk_CreateUniformBuffer()

VkResult QVk_CreateUniformBuffer ( VkDeviceSize  size,
qvkbuffer_t dstBuffer,
VkMemoryPropertyFlags  reqMemFlags,
VkMemoryPropertyFlags  prefMemFlags 
)

Definition at line 127 of file vk_buffer.c.

128 {
129  qvkbufferopts_t dstOpts = {
130  .usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
131  .reqMemFlags = reqMemFlags,
132  .prefMemFlags = prefMemFlags,
133  .vmaUsage = VMA_MEMORY_USAGE_CPU_TO_GPU,
134  // When resizing dynamic uniform buffers on Intel, the Linux driver may throw a warning:
135  // "Mapping an image with layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used."
136  // Minor annoyance but we don't want any validation warnings, so we create dedicated allocation for uniform buffer.
137  // more details: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/34
138  // Note that this is a false positive which in other cases could be ignored: https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/general_considerations.html#general_considerations_validation_layer_warnings
140  };
141 
142  return QVk_CreateBuffer(size, dstBuffer, dstOpts);
143 }

Referenced by CreateDynamicBuffers(), and QVk_GetUniformBuffer().

◆ QVk_CreateValidationLayers()

void QVk_CreateValidationLayers ( void  )

Definition at line 74 of file vk_validation.c.

75 {
76  VkDebugUtilsMessengerCreateInfoEXT callbackInfo = {
77  .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
78  .pNext = NULL,
79  .flags = 0,
80  .messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
81  VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,
82  .messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
83  VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
84  VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
85  .pfnUserCallback = debugUtilsCallback,
86  .pUserData = NULL
87  };
88 
89  if( vk_validation->value > 1 )
90  {
91  callbackInfo.messageSeverity |= VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
92  VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
93  }
94 
96  ri.Con_Printf(PRINT_ALL, "...Vulkan validation layers enabled\n");
97 }

Referenced by QVk_Init().

◆ QVk_CreateVertexBuffer()

void QVk_CreateVertexBuffer ( const void data,
VkDeviceSize  size,
qvkbuffer_t dstBuffer,
qvkbuffer_t stagingBuffer,
VkMemoryPropertyFlags  reqMemFlags,
VkMemoryPropertyFlags  prefMemFlags 
)

Definition at line 145 of file vk_buffer.c.

146 {
147  qvkbufferopts_t dstOpts = {
148  .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
149  .reqMemFlags = reqMemFlags,
150  .prefMemFlags = prefMemFlags,
151  .vmaUsage = VMA_MEMORY_USAGE_GPU_ONLY,
152  .vmaFlags = 0
153  };
154 
155  createStagedBuffer(data, size, dstBuffer, dstOpts, stagingBuffer);
156 }

Referenced by CreateDynamicBuffers(), CreateStaticBuffers(), and QVk_GetVertexBuffer().

◆ QVk_DestroyPipeline()

void QVk_DestroyPipeline ( qvkpipeline_t pipeline)

Definition at line 198 of file vk_pipeline.c.

199 {
200  if (pipeline->layout != VK_NULL_HANDLE)
201  vkDestroyPipelineLayout(vk_device.logical, pipeline->layout, NULL);
202  if (pipeline->pl != VK_NULL_HANDLE)
203  vkDestroyPipeline(vk_device.logical, pipeline->pl, NULL);
204 
205  pipeline->layout = VK_NULL_HANDLE;
206  pipeline->pl = VK_NULL_HANDLE;
207 }

Referenced by QVk_Shutdown().

◆ QVk_DestroyValidationLayers()

void QVk_DestroyValidationLayers ( void  )

Definition at line 99 of file vk_validation.c.

100 {
101  if( validationMessenger != VK_NULL_HANDLE )
102  {
104  validationMessenger = VK_NULL_HANDLE;
105  }
106 }

Referenced by QVk_Shutdown().

◆ QVk_DrawColorRect()

void QVk_DrawColorRect ( float *  ubo,
VkDeviceSize  uboSize,
qvkrenderpasstype_t  rpType 
)

Definition at line 2253 of file vk_common.c.

2254 {
2255  uint32_t uboOffset;
2256  VkDescriptorSet uboDescriptorSet;
2257  uint8_t *vertData = QVk_GetUniformBuffer(uboSize, &uboOffset, &uboDescriptorSet);
2258  memcpy(vertData, ubo, uboSize);
2259 
2261  VkDeviceSize offsets = 0;
2262  vkCmdBindDescriptorSets(vk_activeCmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk_drawColorQuadPipeline[rpType].layout, 0, 1, &uboDescriptorSet, 1, &uboOffset);
2263  vkCmdBindVertexBuffers(vk_activeCmdbuffer, 0, 1, &vk_colorRectVbo.buffer, &offsets);
2264  vkCmdBindIndexBuffer(vk_activeCmdbuffer, vk_rectIbo.buffer, 0, VK_INDEX_TYPE_UINT32);
2265  vkCmdDrawIndexed(vk_activeCmdbuffer, 6, 1, 0, 0, 0);
2266 }

Referenced by Draw_FadeScreen(), Draw_Fill(), R_PolyBlend(), and R_SetupFrame().

◆ QVk_DrawTexRect()

void QVk_DrawTexRect ( float *  ubo,
VkDeviceSize  uboSize,
qvktexture_t texture 
)

Definition at line 2268 of file vk_common.c.

2269 {
2270  uint32_t uboOffset;
2271  VkDescriptorSet uboDescriptorSet;
2272  uint8_t *uboData = QVk_GetUniformBuffer(uboSize, &uboOffset, &uboDescriptorSet);
2273  memcpy(uboData, ubo, uboSize);
2274 
2276  VkDeviceSize offsets = 0;
2277  VkDescriptorSet descriptorSets[] = { texture->descriptorSet, uboDescriptorSet };
2278  vkCmdBindDescriptorSets(vk_activeCmdbuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vk_drawTexQuadPipeline.layout, 0, 2, descriptorSets, 1, &uboOffset);
2279  vkCmdBindVertexBuffers(vk_activeCmdbuffer, 0, 1, &vk_texRectVbo.buffer, &offsets);
2280  vkCmdBindIndexBuffer(vk_activeCmdbuffer, vk_rectIbo.buffer, 0, VK_INDEX_TYPE_UINT32);
2281  vkCmdDrawIndexed(vk_activeCmdbuffer, 6, 1, 0, 0, 0);
2282 }

Referenced by Draw_Char(), Draw_StretchPic(), Draw_StretchRaw(), and Draw_TileClear().

◆ QVk_EndFrame()

VkResult QVk_EndFrame ( qboolean  force)

Definition at line 1880 of file vk_common.c.

1881 {
1882  // continue only if QVk_BeginFrame() had been previously issued
1883  if (!vk_frameStarted)
1884  return VK_NOT_READY;
1885  // this may happen if Sys_Error is issued mid-frame, so we need to properly advance the draw pipeline
1886  if (force)
1887  {
1888  extern void R_EndWorldRenderpass(void);
1890  }
1891 
1892  // submit
1896  vmaFlushAllocation(vk_malloc, vk_dynIndexBuffers[vk_activeDynBufferIdx].allocation, 0, VK_WHOLE_SIZE);
1897 
1898  vkCmdEndRenderPass(vk_commandbuffers[vk_activeBufferIdx]);
1900  VK_VERIFY(vkEndCommandBuffer(vk_commandbuffers[vk_activeBufferIdx]));
1901 
1902  VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1903  VkSubmitInfo submitInfo = {
1904  .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
1905  .waitSemaphoreCount = 1,
1906  .pWaitSemaphores = &vk_imageAvailableSemaphores[vk_activeBufferIdx],
1907  .signalSemaphoreCount = 1,
1908  .pSignalSemaphores = &vk_renderFinishedSemaphores[vk_activeBufferIdx],
1909  .pWaitDstStageMask = &waitStages,
1910  .commandBufferCount = 1,
1911  .pCommandBuffers = &vk_commandbuffers[vk_activeBufferIdx]
1912  };
1913 
1914  VK_VERIFY(vkQueueSubmit(vk_device.gfxQueue, 1, &submitInfo, vk_fences[vk_activeBufferIdx]));
1915 
1916  // present
1917  VkPresentInfoKHR presentInfo = {
1918  .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
1919  .waitSemaphoreCount = 1,
1920  .pWaitSemaphores = &vk_renderFinishedSemaphores[vk_activeBufferIdx],
1921  .swapchainCount = 1,
1922  .pSwapchains = &vk_swapchain.sc,
1923  .pImageIndices = &vk_imageIndex,
1924  .pResults = NULL
1925  };
1926 
1927  VkResult renderResult = vkQueuePresentKHR(vk_device.presentQueue, &presentInfo);
1928 
1929  // for VK_OUT_OF_DATE_KHR and VK_SUBOPTIMAL_KHR it'd be fine to just rebuild the swapchain but let's take the easy way out and restart video system
1930  if (renderResult == VK_ERROR_OUT_OF_DATE_KHR || renderResult == VK_SUBOPTIMAL_KHR || renderResult == VK_ERROR_SURFACE_LOST_KHR)
1931  {
1932  ri.Con_Printf(PRINT_ALL, "QVk_EndFrame(): received %s after vkQueuePresentKHR - restarting video!\n", QVk_GetError(renderResult));
1933  vid_ref->modified = true;
1934  }
1935  else if (renderResult != VK_SUCCESS)
1936  {
1937  Sys_Error("QVk_EndFrame(): unexpected error after vkQueuePresentKHR: %s", QVk_GetError(renderResult));
1938  }
1939 
1941 
1942  vk_frameStarted = false;
1943  return renderResult;
1944 }

Referenced by R_BeginFrame(), and R_EndFrame().

◆ QVk_FindDepthFormat()

VkFormat QVk_FindDepthFormat ( void  )

Definition at line 267 of file vk_common.c.

268 {
269  VkFormat depthFormats[] = {
270  VK_FORMAT_D32_SFLOAT_S8_UINT,
271  VK_FORMAT_D32_SFLOAT,
272  VK_FORMAT_D24_UNORM_S8_UINT,
273  VK_FORMAT_D16_UNORM_S8_UINT,
274  VK_FORMAT_D16_UNORM
275  };
276 
277  for (int i = 0; i < 5; ++i)
278  {
279  VkFormatProperties formatProps;
280  vkGetPhysicalDeviceFormatProperties(vk_device.physical, depthFormats[i], &formatProps);
281 
282  if (formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
283  return depthFormats[i];
284  }
285 
286  return VK_FORMAT_D16_UNORM;
287 }

Referenced by CreateRenderpasses(), and QVk_CreateDepthBuffer().

◆ QVk_FreeBuffer()

void QVk_FreeBuffer ( qvkbuffer_t buffer)

Definition at line 106 of file vk_buffer.c.

107 {
108  vmaDestroyBuffer(vk_malloc, buffer->buffer, buffer->allocation);
109  buffer->buffer = VK_NULL_HANDLE;
110  buffer->allocation = VK_NULL_HANDLE;
111  buffer->currentOffset = 0;
112 }

Referenced by createStagedBuffer(), QVk_ReadPixels(), QVk_Shutdown(), and ReleaseSwapBuffers().

◆ QVk_GetError()

const char* QVk_GetError ( VkResult  errorCode)

Definition at line 2293 of file vk_common.c.

2294 {
2295 #define ERRSTR(r) case VK_ ##r: return "VK_"#r
2296  switch (errorCode)
2297  {
2298  ERRSTR(SUCCESS);
2299  ERRSTR(NOT_READY);
2300  ERRSTR(TIMEOUT);
2301  ERRSTR(EVENT_SET);
2302  ERRSTR(EVENT_RESET);
2303  ERRSTR(INCOMPLETE);
2304  ERRSTR(ERROR_OUT_OF_HOST_MEMORY);
2305  ERRSTR(ERROR_OUT_OF_DEVICE_MEMORY);
2306  ERRSTR(ERROR_INITIALIZATION_FAILED);
2307  ERRSTR(ERROR_DEVICE_LOST);
2308  ERRSTR(ERROR_MEMORY_MAP_FAILED);
2309  ERRSTR(ERROR_LAYER_NOT_PRESENT);
2310  ERRSTR(ERROR_EXTENSION_NOT_PRESENT);
2311  ERRSTR(ERROR_FEATURE_NOT_PRESENT);
2312  ERRSTR(ERROR_INCOMPATIBLE_DRIVER);
2313  ERRSTR(ERROR_TOO_MANY_OBJECTS);
2314  ERRSTR(ERROR_FORMAT_NOT_SUPPORTED);
2315  ERRSTR(ERROR_SURFACE_LOST_KHR);
2316  ERRSTR(ERROR_NATIVE_WINDOW_IN_USE_KHR);
2317  ERRSTR(SUBOPTIMAL_KHR);
2318  ERRSTR(ERROR_OUT_OF_DATE_KHR);
2319  ERRSTR(ERROR_INCOMPATIBLE_DISPLAY_KHR);
2320  ERRSTR(ERROR_VALIDATION_FAILED_EXT);
2321  ERRSTR(ERROR_INVALID_SHADER_NV);
2322  default: return "<unknown>";
2323  }
2324 #undef ERRSTR
2325  return "UNKNOWN ERROR";
2326 }

Referenced by CreateFramebuffers(), CreateRenderpasses(), QVk_BeginFrame(), QVk_CreateDevice(), QVk_EndFrame(), and QVk_Init().

◆ QVk_GetIndexBuffer()

uint8_t* QVk_GetIndexBuffer ( VkDeviceSize  size,
VkDeviceSize *  dstOffset 
)

Definition at line 2058 of file vk_common.c.

2059 {
2060  // align to 4 bytes, so that we can reuse the buffer for both VK_INDEX_TYPE_UINT16 and VK_INDEX_TYPE_UINT32
2061  const int align_mod = size % 4;
2062  const uint32_t aligned_size = ((size % 4) == 0) ? size : (size + 4 - align_mod);
2063 
2064  if (vk_dynIndexBuffers[vk_activeDynBufferIdx].currentOffset + aligned_size > vk_config.index_buffer_size)
2065  {
2067 
2068  ri.Con_Printf(PRINT_ALL, "Resizing dynamic index buffer to %ukB\n", vk_config.index_buffer_size / 1024);
2069  int swapBufferOffset = vk_swapBuffersCnt[vk_activeSwapBufferIdx];
2071 
2074  else
2076 
2077  for (int i = 0; i < NUM_DYNBUFFERS; ++i)
2078  {
2081 
2082  QVk_CreateIndexBuffer(NULL, vk_config.index_buffer_size, &vk_dynIndexBuffers[i], NULL, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
2083  VK_VERIFY(vmaMapMemory(vk_malloc, vk_dynIndexBuffers[i].allocation, &vk_dynIndexBuffers[i].allocInfo.pMappedData));
2084 
2085  QVk_DebugSetObjectName((uint64_t)vk_dynIndexBuffers[i].buffer, VK_OBJECT_TYPE_BUFFER, va("Dynamic Index Buffer #%d", i));
2086  QVk_DebugSetObjectName((uint64_t)vk_dynIndexBuffers[i].allocInfo.deviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY, va("Memory: Dynamic Index Buffer #%d", i));
2087  }
2088  }
2089 
2092 
2096 
2097  return (uint8_t *)vk_dynIndexBuffers[vk_activeDynBufferIdx].allocInfo.pMappedData + (*dstOffset);
2098 }

Referenced by RebuildTriangleFanIndexBuffer().

◆ QVk_GetStagingBuffer()

uint8_t* QVk_GetStagingBuffer ( VkDeviceSize  size,
int  alignment,
VkCommandBuffer *  cmdBuffer,
VkBuffer *  buffer,
uint32_t *  dstOffset 
)

Definition at line 2153 of file vk_common.c.

2154 {
2156  const int align_mod = stagingBuffer->buffer.currentOffset % alignment;
2157  stagingBuffer->buffer.currentOffset = ((stagingBuffer->buffer.currentOffset % alignment) == 0)
2158  ? stagingBuffer->buffer.currentOffset : (stagingBuffer->buffer.currentOffset + alignment - align_mod);
2159 
2160  if (size > STAGING_BUFFER_MAXSIZE)
2161  Sys_Error("QVk_GetStagingBuffer(): Cannot allocate staging buffer space!");
2162 
2163  if ((stagingBuffer->buffer.currentOffset + size) >= STAGING_BUFFER_MAXSIZE && !stagingBuffer->submitted)
2165 
2166  stagingBuffer = &vk_stagingBuffers[vk_activeStagingBuffer];
2167  if (stagingBuffer->submitted)
2168  {
2169  VK_VERIFY(vkWaitForFences(vk_device.logical, 1, &stagingBuffer->fence, VK_TRUE, UINT64_MAX));
2170  VK_VERIFY(vkResetFences(vk_device.logical, 1, &stagingBuffer->fence));
2171 
2172  stagingBuffer->buffer.currentOffset = 0;
2173  stagingBuffer->submitted = false;
2174 
2175  VkCommandBufferBeginInfo beginInfo = {
2176  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
2177  .pNext = NULL,
2178  .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
2179  .pInheritanceInfo = NULL
2180  };
2181 
2182  VK_VERIFY(vkBeginCommandBuffer(stagingBuffer->cmdBuffer, &beginInfo));
2183  }
2184 
2185  if (cmdBuffer)
2186  *cmdBuffer = stagingBuffer->cmdBuffer;
2187  if (buffer)
2188  *buffer = stagingBuffer->buffer.buffer;
2189  if (dstOffset)
2190  *dstOffset = stagingBuffer->buffer.currentOffset;
2191 
2192  unsigned char *data = (uint8_t *)stagingBuffer->buffer.allocInfo.pMappedData + stagingBuffer->buffer.currentOffset;
2193  stagingBuffer->buffer.currentOffset += size;
2194 
2195  return data;
2196 }

Referenced by createTextureImage(), and QVk_UpdateTextureData().

◆ QVk_GetTriangleFanIbo()

VkBuffer QVk_GetTriangleFanIbo ( VkDeviceSize  indexCount)

◆ QVk_GetUniformBuffer()

uint8_t* QVk_GetUniformBuffer ( VkDeviceSize  size,
uint32_t *  dstOffset,
VkDescriptorSet *  dstUboDescriptorSet 
)

Definition at line 2100 of file vk_common.c.

2101 {
2102  // 0x100 alignment is required by Vulkan spec
2103  const int align_mod = size % 256;
2104  const uint32_t aligned_size = ((size % 256) == 0) ? size : (size + 256 - align_mod);
2105 
2107  {
2109 
2110  ri.Con_Printf(PRINT_ALL, "Resizing dynamic uniform buffer to %ukB\n", vk_config.uniform_buffer_size / 1024);
2111  int swapBufferOffset = vk_swapBuffersCnt[vk_activeSwapBufferIdx];
2112  int swapDescSetsOffset = vk_swapDescSetsCnt[vk_activeSwapBufferIdx];
2115 
2118  else
2120 
2123  else
2125 
2126  for (int i = 0; i < NUM_DYNBUFFERS; ++i)
2127  {
2131 
2132  VK_VERIFY(QVk_CreateUniformBuffer(vk_config.uniform_buffer_size, &vk_dynUniformBuffers[i], VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT));
2133  VK_VERIFY(vmaMapMemory(vk_malloc, vk_dynUniformBuffers[i].allocation, &vk_dynUniformBuffers[i].allocInfo.pMappedData));
2135 
2136  QVk_DebugSetObjectName((uint64_t)vk_uboDescriptorSets[i], VK_OBJECT_TYPE_DESCRIPTOR_SET, va("Dynamic UBO Descriptor Set #%d", i));
2137  QVk_DebugSetObjectName((uint64_t)vk_dynUniformBuffers[i].buffer, VK_OBJECT_TYPE_BUFFER, va("Dynamic Uniform Buffer #%d", i));
2138  QVk_DebugSetObjectName((uint64_t)vk_dynUniformBuffers[i].allocInfo.deviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY, va("Memory: Dynamic Uniform Buffer #%d", i));
2139  }
2140  }
2141 
2143  *dstUboDescriptorSet = vk_uboDescriptorSets[vk_activeDynBufferIdx];
2145 
2149 
2150  return (uint8_t *)vk_dynUniformBuffers[vk_activeDynBufferIdx].allocInfo.pMappedData + (*dstOffset);
2151 }

Referenced by DrawVkFlowingPoly(), DrawVkPoly(), EmitWaterPolys(), QVk_DrawColorRect(), QVk_DrawTexRect(), R_DrawBeam(), R_DrawNullModel(), R_DrawParticles(), R_DrawSkyBox(), R_DrawTriangleOutlines(), R_RenderDlight(), Vk_DrawAliasFrameLerp(), Vk_DrawAliasShadow(), and Vk_RenderLightmappedPoly().

◆ QVk_GetVertexBuffer()

uint8_t* QVk_GetVertexBuffer ( VkDeviceSize  size,
VkBuffer *  dstBuffer,
VkDeviceSize *  dstOffset 
)

Definition at line 2019 of file vk_common.c.

2020 {
2022  {
2024 
2025  ri.Con_Printf(PRINT_ALL, "Resizing dynamic vertex buffer to %ukB\n", vk_config.vertex_buffer_size / 1024);
2026  int swapBufferOffset = vk_swapBuffersCnt[vk_activeSwapBufferIdx];
2028 
2031  else
2033 
2034  for (int i = 0; i < NUM_DYNBUFFERS; ++i)
2035  {
2038 
2039  QVk_CreateVertexBuffer(NULL, vk_config.vertex_buffer_size, &vk_dynVertexBuffers[i], NULL, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
2040  VK_VERIFY(vmaMapMemory(vk_malloc, vk_dynVertexBuffers[i].allocation, &vk_dynVertexBuffers[i].allocInfo.pMappedData));
2041 
2042  QVk_DebugSetObjectName((uint64_t)vk_dynVertexBuffers[i].buffer, VK_OBJECT_TYPE_BUFFER, va("Dynamic Vertex Buffer #%d", i));
2043  QVk_DebugSetObjectName((uint64_t)vk_dynVertexBuffers[i].allocInfo.deviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY, va("Memory: Dynamic Vertex Buffer #%d", i));
2044  }
2045  }
2046 
2050 
2054 
2055  return (uint8_t *)vk_dynVertexBuffers[vk_activeDynBufferIdx].allocInfo.pMappedData + (*dstOffset);
2056 }

Referenced by DrawVkFlowingPoly(), DrawVkPoly(), EmitWaterPolys(), R_DrawBeam(), R_DrawNullModel(), R_DrawParticles(), R_DrawSkyBox(), R_DrawSpriteModel(), R_DrawTriangleOutlines(), R_RenderDlight(), Vk_DrawAliasFrameLerp(), Vk_DrawAliasShadow(), Vk_DrawParticles(), and Vk_RenderLightmappedPoly().

◆ QVk_Init()

qboolean QVk_Init ( void  )

Definition at line 1510 of file vk_common.c.

1511 {
1512  PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion = (PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion");
1513  uint32_t instanceVersion = VK_API_VERSION_1_0;
1514 
1515  if (vkEnumerateInstanceVersion)
1516  {
1517  VK_VERIFY(vkEnumerateInstanceVersion(&instanceVersion));
1518  }
1519 
1520  VkApplicationInfo appInfo = {
1521  .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
1522  .pNext = NULL,
1523  .pApplicationName = "Quake 2",
1524  .applicationVersion = VK_MAKE_VERSION(3, 21, 0),
1525  .pEngineName = "id Tech 2",
1526  .engineVersion = VK_MAKE_VERSION(2, 0, 0),
1527  .apiVersion = instanceVersion
1528  };
1529 
1530  uint32_t extCount;
1531  char **wantedExtensions;
1532  memset((char*)vk_config.supported_present_modes, 0, 256);
1533  memset((char*)vk_config.extensions, 0, 256);
1534  memset((char*)vk_config.layers, 0, 256);
1535  vk_config.vk_version = instanceVersion;
1548 
1549  Vkimp_GetSurfaceExtensions(NULL, &extCount);
1550 
1551  if (vk_validation->value)
1552  extCount++;
1553 #if defined(_DEBUG) || defined(ENABLE_DEBUG_LABELS)
1554  else
1555  extCount++;
1556 #endif
1557 
1558  wantedExtensions = (char **)malloc(extCount * sizeof(const char *));
1559  Vkimp_GetSurfaceExtensions(wantedExtensions, NULL);
1560 
1561  if (vk_validation->value)
1562  wantedExtensions[extCount - 1] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
1563 #if defined(_DEBUG) || defined(ENABLE_DEBUG_LABELS)
1564  else
1565  wantedExtensions[extCount - 1] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME;
1566 #endif
1567 
1568  ri.Con_Printf(PRINT_ALL, "Enabled extensions: ");
1569  for (int i = 0; i < extCount; i++)
1570  {
1571  ri.Con_Printf(PRINT_ALL, "%s ", wantedExtensions[i]);
1572  vk_config.extensions[i] = wantedExtensions[i];
1573  }
1574  ri.Con_Printf(PRINT_ALL, "\n");
1575 
1576  VkInstanceCreateInfo createInfo = {
1577  .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
1578  .pNext = NULL,
1579  .pApplicationInfo = &appInfo,
1580  .enabledLayerCount = 0,
1581  .ppEnabledLayerNames = NULL,
1582  .enabledExtensionCount = extCount,
1583  .ppEnabledExtensionNames = (const char* const*)wantedExtensions
1584  };
1585 
1586 #if VK_HEADER_VERSION > 101
1587  const char *validationLayers[] = { "VK_LAYER_KHRONOS_validation" };
1588 #else
1589  const char *validationLayers[] = { "VK_LAYER_LUNARG_standard_validation" };
1590 #endif
1591 
1592  if (vk_validation->value)
1593  {
1594  createInfo.enabledLayerCount = sizeof(validationLayers) / sizeof(validationLayers[0]);
1595  createInfo.ppEnabledLayerNames = validationLayers;
1596  for (int i = 0; i < createInfo.enabledLayerCount; i++)
1597  {
1598  vk_config.layers[i] = validationLayers[i];
1599  }
1600  }
1601 
1602  VkResult res = vkCreateInstance(&createInfo, NULL, &vk_instance);
1603  free(wantedExtensions);
1604 
1605  if (res != VK_SUCCESS)
1606  {
1607  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan instance: %s\n", QVk_GetError(res));
1608  return false;
1609  }
1610  ri.Con_Printf(PRINT_ALL, "...created Vulkan instance\n");
1611 
1612  // initialize function pointers
1613  qvkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkCreateDebugUtilsMessengerEXT");
1614  qvkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk_instance, "vkDestroyDebugUtilsMessengerEXT");
1615  qvkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectNameEXT");
1616  qvkSetDebugUtilsObjectTagEXT = (PFN_vkSetDebugUtilsObjectTagEXT)vkGetInstanceProcAddr(vk_instance, "vkSetDebugUtilsObjectTagEXT");
1617  qvkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdBeginDebugUtilsLabelEXT");
1618  qvkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdEndDebugUtilsLabelEXT");
1619  qvkInsertDebugUtilsLabelEXT = (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(vk_instance, "vkCmdInsertDebugUtilsLabelEXT");
1620 
1621  if (vk_validation->value)
1623 
1624  res = Vkimp_CreateSurface();
1625  if (res != VK_SUCCESS)
1626  {
1627  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan surface: %s\n", QVk_GetError(res));
1628  return false;
1629  }
1630  ri.Con_Printf(PRINT_ALL, "...created Vulkan surface\n");
1631 
1632  // create Vulkan device - see if the user prefers any specific device if there's more than one GPU in the system
1634  QVk_DebugSetObjectName((uint64_t)vk_device.physical, VK_OBJECT_TYPE_PHYSICAL_DEVICE, va("Physical Device: %s", vk_config.vendor_name));
1635 
1636  // create memory allocator
1637  VmaAllocatorCreateInfo allocInfo = {
1638  .flags = 0,
1639  .physicalDevice = vk_device.physical,
1640  .device = vk_device.logical,
1641  .preferredLargeHeapBlockSize = 0,
1642  .pAllocationCallbacks = NULL,
1643  .pDeviceMemoryCallbacks = NULL,
1644  .frameInUseCount = 0,
1645  .pHeapSizeLimit = NULL,
1646  .pVulkanFunctions = NULL,
1647  .pRecordSettings = NULL
1648  };
1649 
1650  res = vmaCreateAllocator(&allocInfo, &vk_malloc);
1651  if (res != VK_SUCCESS)
1652  {
1653  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan memory allocator: %s\n", QVk_GetError(res));
1654  return false;
1655  }
1656  ri.Con_Printf(PRINT_ALL, "...created Vulkan memory allocator\n");
1657 
1658  // setup swapchain
1659  res = QVk_CreateSwapchain();
1660  if (res != VK_SUCCESS)
1661  {
1662  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan swapchain: %s\n", QVk_GetError(res));
1663  return false;
1664  }
1665  ri.Con_Printf(PRINT_ALL, "...created Vulkan swapchain\n");
1666 
1667  // set viewport and scissor
1668  vk_viewport.x = 0.f;
1669  vk_viewport.y = 0.f;
1670  vk_viewport.minDepth = 0.f;
1671  vk_viewport.maxDepth = 1.f;
1672  vk_viewport.width = (float)vid.width;
1673  vk_viewport.height = (float)vid.height;
1674  vk_scissor.offset.x = 0;
1675  vk_scissor.offset.y = 0;
1676  vk_scissor.extent = vk_swapchain.extent;
1677 
1678  // setup fences and semaphores
1679  VkFenceCreateInfo fCreateInfo = {
1680  .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
1681  .pNext = NULL,
1682  .flags = VK_FENCE_CREATE_SIGNALED_BIT
1683  };
1684  VkSemaphoreCreateInfo sCreateInfo = {
1685  .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
1686  .pNext = NULL,
1687  .flags = 0
1688  };
1689  for (int i = 0; i < NUM_CMDBUFFERS; ++i)
1690  {
1691  VK_VERIFY(vkCreateFence(vk_device.logical, &fCreateInfo, NULL, &vk_fences[i]));
1692  VK_VERIFY(vkCreateSemaphore(vk_device.logical, &sCreateInfo, NULL, &vk_imageAvailableSemaphores[i]));
1693  VK_VERIFY(vkCreateSemaphore(vk_device.logical, &sCreateInfo, NULL, &vk_renderFinishedSemaphores[i]));
1694 
1695  QVk_DebugSetObjectName((uint64_t)vk_fences[i], VK_OBJECT_TYPE_FENCE, va("Fence #%d", i));
1696  QVk_DebugSetObjectName((uint64_t)vk_imageAvailableSemaphores[i], VK_OBJECT_TYPE_SEMAPHORE, va("Semaphore: image available #%d", i));
1697  QVk_DebugSetObjectName((uint64_t)vk_renderFinishedSemaphores[i], VK_OBJECT_TYPE_SEMAPHORE, va("Semaphore: render finished #%d", i));
1698  }
1699  ri.Con_Printf(PRINT_ALL, "...created synchronization objects\n");
1700 
1701  // setup render passes
1702  for (int i = 0; i < RP_COUNT; ++i)
1703  {
1704  vk_renderpasses[i].colorLoadOp = vk_clear->value ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1705  }
1706 
1707  VkSampleCountFlagBits msaaMode = GetSampleCount();
1708  VkSampleCountFlagBits supportedMsaa = vk_device.properties.limits.framebufferColorSampleCounts;
1709  if (!(supportedMsaa & msaaMode))
1710  {
1711  ri.Con_Printf(PRINT_ALL, "MSAAx%d mode not supported, aborting...\n", msaaMode);
1712  ri.Cvar_Set("vk_msaa", "0");
1713  msaaMode = VK_SAMPLE_COUNT_1_BIT;
1714  // avoid secondary video reload
1715  vk_msaa->modified = false;
1716  }
1717 
1718  // MSAA setting will be only relevant for the primary world render pass
1719  vk_renderpasses[RP_WORLD].sampleCount = msaaMode;
1720 
1721  res = CreateRenderpasses();
1722  if (res != VK_SUCCESS)
1723  {
1724  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan render passes: %s\n", QVk_GetError(res));
1725  return false;
1726  }
1727  ri.Con_Printf(PRINT_ALL, "...created %d Vulkan render passes\n", RP_COUNT);
1728 
1729  // setup command pools
1731  if (res != VK_SUCCESS)
1732  {
1733  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan command pool for graphics: %s\n", QVk_GetError(res));
1734  return false;
1735  }
1737  if (res != VK_SUCCESS)
1738  {
1739  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan command pool for transfer: %s\n", QVk_GetError(res));
1740  return false;
1741  }
1742 
1743  QVk_DebugSetObjectName((uint64_t)vk_commandPool, VK_OBJECT_TYPE_COMMAND_POOL, "Command Pool: Graphics");
1744  QVk_DebugSetObjectName((uint64_t)vk_transferCommandPool, VK_OBJECT_TYPE_COMMAND_POOL, "Command Pool: Transfer");
1745  ri.Con_Printf(PRINT_ALL, "...created Vulkan command pools\n");
1746 
1747  // setup draw buffers
1749 
1750  // setup image views
1751  res = CreateImageViews();
1752  if (res != VK_SUCCESS)
1753  {
1754  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan image views: %s\n", QVk_GetError(res));
1755  return false;
1756  }
1757  ri.Con_Printf(PRINT_ALL, "...created %d Vulkan image view(s)\n", vk_swapchain.imageCount);
1758 
1759  // setup framebuffers
1760  res = CreateFramebuffers();
1761  if (res != VK_SUCCESS)
1762  {
1763  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan framebuffers: %s\n", QVk_GetError(res));
1764  return false;
1765  }
1766  ri.Con_Printf(PRINT_ALL, "...created %d Vulkan framebuffers\n", vk_swapchain.imageCount);
1767 
1768  // setup command buffers (double buffering)
1769  vk_commandbuffers = (VkCommandBuffer *)malloc(NUM_CMDBUFFERS * sizeof(VkCommandBuffer));
1770 
1771  VkCommandBufferAllocateInfo cbInfo = {
1772  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
1773  .pNext = NULL,
1774  .commandPool = vk_commandPool,
1775  .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
1776  .commandBufferCount = NUM_CMDBUFFERS
1777  };
1778 
1779  res = vkAllocateCommandBuffers(vk_device.logical, &cbInfo, vk_commandbuffers);
1780  if (res != VK_SUCCESS)
1781  {
1782  ri.Con_Printf(PRINT_ALL, "QVk_Init(): Could not create Vulkan commandbuffers: %s\n", QVk_GetError(res));
1783  free(vk_commandbuffers);
1785  return false;
1786  }
1787  ri.Con_Printf(PRINT_ALL, "...created %d Vulkan commandbuffers\n", NUM_CMDBUFFERS);
1788 
1789  // initialize tracker variables
1791 
1794  // create static vertex/index buffers reused in the games
1796  // create vertex, index and uniform buffer pools
1798  // create staging buffers
1800  // assign a dynamic index buffer for triangle fan emulation
1802  CreatePipelines();
1803  CreateSamplers();
1804 
1805  // main and world warp color buffers will be sampled for postprocessing effects, so they need descriptors and samplers
1806  VkDescriptorSetAllocateInfo dsAllocInfo = {
1807  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
1808  .pNext = NULL,
1809  .descriptorPool = vk_descriptorPool,
1810  .descriptorSetCount = 1,
1811  .pSetLayouts = &vk_samplerDescSetLayout
1812  };
1813 
1814  VK_VERIFY(vkAllocateDescriptorSets(vk_device.logical, &dsAllocInfo, &vk_colorbuffer.descriptorSet));
1816  VK_VERIFY(vkAllocateDescriptorSets(vk_device.logical, &dsAllocInfo, &vk_colorbufferWarp.descriptorSet));
1818 
1819  QVk_DebugSetObjectName((uint64_t)vk_colorbuffer.descriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, "Descriptor Set: World Color Buffer");
1820  QVk_DebugSetObjectName((uint64_t)vk_colorbufferWarp.descriptorSet, VK_OBJECT_TYPE_DESCRIPTOR_SET, "Descriptor Set: Warp Postprocess Color Buffer");
1821  return true;
1822 }

Referenced by R_Init().

◆ QVk_ReadPixels()

void QVk_ReadPixels ( uint8_t *  dstBuffer,
uint32_t  width,
uint32_t  height 
)

Definition at line 465 of file vk_image.c.

466 {
467  qvkbuffer_t buff;
468  VkCommandBuffer cmdBuffer;
469  qvkbufferopts_t buffOpts = {
470  .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT,
471  .reqMemFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
472  .prefMemFlags = VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
473  .vmaUsage = VMA_MEMORY_USAGE_CPU_ONLY,
474  // When taking a screenshot on Intel, the Linux driver may throw a warning:
475  // "Mapping an image with layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL can result in undefined behavior if this memory is used by the device. Only GENERAL or PREINITIALIZED should be used."
476  // Minor annoyance but we don't want any validation warnings, so we create dedicated allocation for the image buffer.
477  // more details: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/34
478  // Note that this is a false positive which in other cases could be ignored: https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/general_considerations.html#general_considerations_validation_layer_warnings
480  };
481 
482  VK_VERIFY(QVk_CreateBuffer(width * height * 4, &buff, buffOpts));
483  cmdBuffer = QVk_CreateCommandBuffer(&vk_commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
484  VK_VERIFY(QVk_BeginCommand(&cmdBuffer));
485 
486  // transition the current swapchain image to be a source of data transfer to our buffer
487  extern int vk_activeBufferIdx;
488  VkImageMemoryBarrier imgBarrier = {
489  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
490  .pNext = NULL,
491  .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
492  .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
493  .oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
494  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
495  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
496  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
498  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
499  .subresourceRange.baseMipLevel = 0,
500  .subresourceRange.baseArrayLayer = 0,
501  .subresourceRange.layerCount = 1,
502  .subresourceRange.levelCount = 1
503  };
504 
505  vkCmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, &imgBarrier);
506 
507  VkBufferImageCopy region = {
508  .bufferOffset = 0,
509  .bufferRowLength = width,
510  .bufferImageHeight = height,
511  .imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
512  .imageSubresource.mipLevel = 0,
513  .imageSubresource.baseArrayLayer = 0,
514  .imageSubresource.layerCount = 1,
515  .imageOffset = { 0, 0, 0 },
516  .imageExtent = { width, height, 1 }
517  };
518 
519  // copy the swapchain image
520  vkCmdCopyImageToBuffer(cmdBuffer, vk_swapchain.images[vk_activeBufferIdx], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buff.buffer, 1, &region);
521  VK_VERIFY(vkDeviceWaitIdle(vk_device.logical));
522  QVk_SubmitCommand(&cmdBuffer, &vk_device.gfxQueue);
523 
524  // store image in destination buffer
525  memcpy(dstBuffer, (uint8_t *)buff.allocInfo.pMappedData, width * height * 4);
526 
527  QVk_FreeBuffer(&buff);
528 }

Referenced by Vk_ScreenShot_f().

◆ QVk_RecreateSwapchain()

void QVk_RecreateSwapchain ( void  )

Definition at line 2004 of file vk_common.c.

2005 {
2006  vkDeviceWaitIdle( vk_device.logical );
2010  vk_viewport.width = (float)vid.width;
2011  vk_viewport.height = (float)vid.height;
2012  vk_scissor.extent = vk_swapchain.extent;
2017 }

◆ QVk_ReleaseTexture()

void QVk_ReleaseTexture ( qvktexture_t texture)

Definition at line 448 of file vk_image.c.

449 {
451  vkDeviceWaitIdle(vk_device.logical);
452 
453  if (texture->image != VK_NULL_HANDLE)
454  vmaDestroyImage(vk_malloc, texture->image, texture->allocation);
455  if (texture->imageView != VK_NULL_HANDLE)
456  vkDestroyImageView(vk_device.logical, texture->imageView, NULL);
457  if (texture->descriptorSet != VK_NULL_HANDLE)
458  vkFreeDescriptorSets(vk_device.logical, vk_descriptorPool, 1, &texture->descriptorSet);
459 
460  texture->image = VK_NULL_HANDLE;
461  texture->imageView = VK_NULL_HANDLE;
462  texture->descriptorSet = VK_NULL_HANDLE;
463 }

Referenced by Vk_FreeUnusedImages(), and Vk_ShutdownImages().

◆ QVk_Shutdown()

void QVk_Shutdown ( void  )

Definition at line 1376 of file vk_common.c.

1377 {
1378  if (vk_instance != VK_NULL_HANDLE)
1379  {
1380  ri.Con_Printf(PRINT_ALL, "Shutting down Vulkan\n");
1381 
1382  for (int i = 0; i < 2; ++i)
1383  {
1387  }
1411  for (int i = 0; i < NUM_DYNBUFFERS; ++i)
1412  {
1413  if (vk_dynUniformBuffers[i].buffer != VK_NULL_HANDLE)
1414  {
1417  }
1418  if (vk_dynIndexBuffers[i].buffer != VK_NULL_HANDLE)
1419  {
1422  }
1423  if (vk_dynVertexBuffers[i].buffer != VK_NULL_HANDLE)
1424  {
1427  }
1428  if (vk_stagingBuffers[i].buffer.buffer != VK_NULL_HANDLE)
1429  {
1432  vkDestroyFence(vk_device.logical, vk_stagingBuffers[i].fence, NULL);
1433  }
1434  }
1435  if (vk_descriptorPool != VK_NULL_HANDLE)
1436  vkDestroyDescriptorPool(vk_device.logical, vk_descriptorPool, NULL);
1437  if (vk_uboDescSetLayout != VK_NULL_HANDLE)
1438  vkDestroyDescriptorSetLayout(vk_device.logical, vk_uboDescSetLayout, NULL);
1439  if (vk_samplerDescSetLayout != VK_NULL_HANDLE)
1440  vkDestroyDescriptorSetLayout(vk_device.logical, vk_samplerDescSetLayout, NULL);
1441  if (vk_samplerLightmapDescSetLayout != VK_NULL_HANDLE)
1442  vkDestroyDescriptorSetLayout(vk_device.logical, vk_samplerLightmapDescSetLayout, NULL);
1443  for (int i = 0; i < RP_COUNT; i++)
1444  {
1445  if (vk_renderpasses[i].rp != VK_NULL_HANDLE)
1446  vkDestroyRenderPass(vk_device.logical, vk_renderpasses[i].rp, NULL);
1447  vk_renderpasses[i].rp = VK_NULL_HANDLE;
1448  }
1449  if (vk_commandbuffers)
1450  {
1452  free(vk_commandbuffers);
1454  }
1455  if (vk_commandPool != VK_NULL_HANDLE)
1456  vkDestroyCommandPool(vk_device.logical, vk_commandPool, NULL);
1457  if (vk_transferCommandPool != VK_NULL_HANDLE)
1458  vkDestroyCommandPool(vk_device.logical, vk_transferCommandPool, NULL);
1459  if (vk_stagingCommandPool != VK_NULL_HANDLE)
1460  vkDestroyCommandPool(vk_device.logical, vk_stagingCommandPool, NULL);
1461  DestroySamplers();
1465  if (vk_swapchain.sc != VK_NULL_HANDLE)
1466  {
1467  vkDestroySwapchainKHR(vk_device.logical, vk_swapchain.sc, NULL);
1468  free(vk_swapchain.images);
1469  vk_swapchain.sc = VK_NULL_HANDLE;
1472  }
1473  for (int i = 0; i < NUM_CMDBUFFERS; ++i)
1474  {
1475  vkDestroySemaphore(vk_device.logical, vk_imageAvailableSemaphores[i], NULL);
1476  vkDestroySemaphore(vk_device.logical, vk_renderFinishedSemaphores[i], NULL);
1477  vkDestroyFence(vk_device.logical, vk_fences[i], NULL);
1478  }
1479  if (vk_malloc != VK_NULL_HANDLE)
1481  if (vk_device.logical != VK_NULL_HANDLE)
1482  vkDestroyDevice(vk_device.logical, NULL);
1483  if(vk_surface != VK_NULL_HANDLE)
1484  vkDestroySurfaceKHR(vk_instance, vk_surface, NULL);
1486 
1487  vkDestroyInstance(vk_instance, NULL);
1488  vk_instance = VK_NULL_HANDLE;
1489  vk_activeCmdbuffer = VK_NULL_HANDLE;
1490  vk_descriptorPool = VK_NULL_HANDLE;
1491  vk_uboDescSetLayout = VK_NULL_HANDLE;
1492  vk_samplerDescSetLayout = VK_NULL_HANDLE;
1493  vk_samplerLightmapDescSetLayout = VK_NULL_HANDLE;
1494  vk_commandPool = VK_NULL_HANDLE;
1495  vk_transferCommandPool = VK_NULL_HANDLE;
1496  vk_stagingCommandPool = VK_NULL_HANDLE;
1497  vk_activeBufferIdx = 0;
1498  vk_imageIndex = 0;
1499  }
1500 }

Referenced by R_Shutdown().

◆ QVk_SubmitCommand()

void QVk_SubmitCommand ( const VkCommandBuffer *  commandBuffer,
const VkQueue *  queue 
)

Definition at line 35 of file vk_cmd.c.

36 {
37  VK_VERIFY(vkEndCommandBuffer(*commandBuffer));
38 
39  VkSubmitInfo submitInfo = {
40  .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
41  .pNext = NULL,
42  .waitSemaphoreCount = 0,
43  .pWaitSemaphores = NULL,
44  .pWaitDstStageMask = NULL,
45  .commandBufferCount = 1,
46  .pCommandBuffers = commandBuffer,
47  .signalSemaphoreCount = 0,
48  .pSignalSemaphores = NULL
49  };
50 
51  VkFenceCreateInfo fCreateInfo = {
52  .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
53  .pNext = NULL,
54  .flags = 0
55  };
56 
57  VkFence queueFence;
58  VK_VERIFY(vkCreateFence(vk_device.logical, &fCreateInfo, NULL, &queueFence));
59  VK_VERIFY(vkQueueSubmit(*queue, 1, &submitInfo, queueFence));
60  VK_VERIFY(vkWaitForFences(vk_device.logical, 1, &queueFence, VK_TRUE, UINT64_MAX));
61 
62  vkDestroyFence(vk_device.logical, queueFence, NULL);
63 }

Referenced by copyBuffer(), and QVk_ReadPixels().

◆ QVk_SubmitStagingBuffers()

void QVk_SubmitStagingBuffers ( void  )

Definition at line 2216 of file vk_common.c.

2217 {
2218  for (int i = 0; i < NUM_DYNBUFFERS; ++i)
2219  {
2220  if (!vk_stagingBuffers[i].submitted && vk_stagingBuffers[i].buffer.currentOffset > 0)
2222  }
2223 }

Referenced by QVk_EndFrame(), and QVk_ReleaseTexture().

◆ QVk_UpdateTextureData()

void QVk_UpdateTextureData ( qvktexture_t texture,
const unsigned char *  data,
uint32_t  offset_x,
uint32_t  offset_y,
uint32_t  width,
uint32_t  height 
)

Definition at line 402 of file vk_image.c.

403 {
404  int unifiedTransferAndGfx = vk_device.transferQueue == vk_device.gfxQueue ? 1 : 0;
405  // assuming 32bit images
406  uint32_t imageSize = width * height * 4;
407 
408  VkBuffer staging_buffer;
409  VkCommandBuffer command_buffer;
410  uint32_t staging_offset;
411  void *imgData = QVk_GetStagingBuffer(imageSize, 4, &command_buffer, &staging_buffer, &staging_offset);
412  memcpy(imgData, data, (size_t)imageSize);
413 
414  transitionImageLayout(&command_buffer, &vk_device.transferQueue, texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
415  // copy buffer to image
416  VkBufferImageCopy region = {
417  .bufferOffset = staging_offset,
418  .bufferRowLength = 0,
419  .bufferImageHeight = 0,
420  .imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
421  .imageSubresource.mipLevel = 0,
422  .imageSubresource.baseArrayLayer = 0,
423  .imageSubresource.layerCount = 1,
424  .imageOffset = { offset_x, offset_y, 0 },
425  .imageExtent = { width, height, 1 }
426  };
427 
428  vkCmdCopyBufferToImage(command_buffer, staging_buffer, texture->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
429 
430  if (texture->mipLevels > 1)
431  {
432  // vkCmdBlitImage requires a queue with GRAPHICS_BIT present
433  generateMipmaps(&command_buffer, texture, width, height);
434  }
435  else
436  {
437  // for non-unified transfer and graphics, this step begins queue ownership transfer to graphics queue (for exclusive sharing only)
438  if (unifiedTransferAndGfx || texture->sharingMode == VK_SHARING_MODE_EXCLUSIVE)
439  transitionImageLayout(&command_buffer, &vk_device.transferQueue, texture, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
440 
441  if (!unifiedTransferAndGfx)
442  {
443  transitionImageLayout(&command_buffer, &vk_device.gfxQueue, texture, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
444  }
445  }
446 }

Referenced by Draw_StretchRaw(), LM_UploadBlock(), R_RenderBrushPoly(), Vk_LoadPic(), and Vk_RenderLightmappedPoly().

◆ QVk_UpdateTextureSampler()

VkSampler QVk_UpdateTextureSampler ( qvktexture_t texture,
qvksampler_t  samplerType 
)

Definition at line 2225 of file vk_common.c.

2226 {
2227  assert((vk_samplers[samplerType] != VK_NULL_HANDLE) && "Sampler is VK_NULL_HANDLE!");
2228 
2229  VkDescriptorImageInfo dImgInfo = {
2230  .sampler = vk_samplers[samplerType],
2231  .imageView = texture->imageView,
2232  .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
2233  };
2234 
2235  VkWriteDescriptorSet writeSet = {
2236  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2237  .pNext = NULL,
2238  .dstSet = texture->descriptorSet,
2239  .dstBinding = 0,
2240  .dstArrayElement = 0,
2241  .descriptorCount = 1,
2242  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
2243  .pImageInfo = &dImgInfo,
2244  .pBufferInfo = NULL,
2245  .pTexelBufferView = NULL
2246  };
2247 
2248  vkUpdateDescriptorSets(vk_device.logical, 1, &writeSet, 0, NULL);
2249 
2250  return vk_samplers[samplerType];
2251 }

Referenced by QVk_CreateTexture(), QVk_Init(), Vk_LmapTextureMode(), and Vk_TextureMode().

Variable Documentation

◆ qvkCmdBeginDebugUtilsLabelEXT

PFN_vkCmdBeginDebugUtilsLabelEXT qvkCmdBeginDebugUtilsLabelEXT

Definition at line 170 of file vk_common.c.

Referenced by QVk_Init().

◆ qvkCmdEndDebugUtilsLabelEXT

PFN_vkCmdEndDebugUtilsLabelEXT qvkCmdEndDebugUtilsLabelEXT

Definition at line 171 of file vk_common.c.

Referenced by QVk_Init().

◆ qvkCreateDebugUtilsMessengerEXT

PFN_vkCreateDebugUtilsMessengerEXT qvkCreateDebugUtilsMessengerEXT

Definition at line 166 of file vk_common.c.

Referenced by QVk_CreateValidationLayers(), and QVk_Init().

◆ qvkDestroyDebugUtilsMessengerEXT

PFN_vkDestroyDebugUtilsMessengerEXT qvkDestroyDebugUtilsMessengerEXT

Definition at line 167 of file vk_common.c.

Referenced by QVk_DestroyValidationLayers(), and QVk_Init().

◆ qvkInsertDebugUtilsLabelEXT

PFN_vkCmdInsertDebugUtilsLabelEXT qvkInsertDebugUtilsLabelEXT

Definition at line 172 of file vk_common.c.

Referenced by QVk_Init().

◆ qvkSetDebugUtilsObjectNameEXT

PFN_vkSetDebugUtilsObjectNameEXT qvkSetDebugUtilsObjectNameEXT

Definition at line 168 of file vk_common.c.

Referenced by QVk_Init().

◆ qvkSetDebugUtilsObjectTagEXT

PFN_vkSetDebugUtilsObjectTagEXT qvkSetDebugUtilsObjectTagEXT

Definition at line 169 of file vk_common.c.

Referenced by QVk_Init().

◆ vk_activeCmdbuffer

◆ vk_colorbuffer

◆ vk_colorbufferWarp

qvktexture_t vk_colorbufferWarp

◆ vk_commandPool

VkCommandPool vk_commandPool

Definition at line 95 of file vk_common.c.

Referenced by QVk_Init(), QVk_ReadPixels(), and QVk_Shutdown().

◆ vk_descriptorPool

VkDescriptorPool vk_descriptorPool

◆ vk_device

◆ vk_drawBeamPipeline

qvkpipeline_t vk_drawBeamPipeline

Definition at line 153 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawBeam().

◆ vk_drawColorQuadPipeline

qvkpipeline_t vk_drawColorQuadPipeline[2]

Definition at line 139 of file vk_common.c.

Referenced by CreatePipelines(), QVk_DrawColorRect(), and QVk_Shutdown().

◆ vk_drawDLightPipeline

qvkpipeline_t vk_drawDLightPipeline

Definition at line 155 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_RenderDlight().

◆ vk_drawLefthandModelPipelineFan

qvkpipeline_t vk_drawLefthandModelPipelineFan

Definition at line 145 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawLefthandModelPipelineStrip

qvkpipeline_t vk_drawLefthandModelPipelineStrip

Definition at line 144 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawModelPipelineFan

qvkpipeline_t vk_drawModelPipelineFan[2]

Definition at line 141 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawModelPipelineStrip

qvkpipeline_t vk_drawModelPipelineStrip[2]

Definition at line 140 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawNoDepthModelPipelineFan

qvkpipeline_t vk_drawNoDepthModelPipelineFan

Definition at line 143 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawNoDepthModelPipelineStrip

qvkpipeline_t vk_drawNoDepthModelPipelineStrip

Definition at line 142 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasFrameLerp().

◆ vk_drawNullModelPipeline

qvkpipeline_t vk_drawNullModelPipeline

Definition at line 146 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawNullModel().

◆ vk_drawParticlesPipeline

qvkpipeline_t vk_drawParticlesPipeline

Definition at line 147 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawParticles().

◆ vk_drawPointParticlesPipeline

qvkpipeline_t vk_drawPointParticlesPipeline

Definition at line 148 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawParticles().

◆ vk_drawPolyLmapPipeline

qvkpipeline_t vk_drawPolyLmapPipeline

Definition at line 151 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_RenderLightmappedPoly().

◆ vk_drawPolyPipeline

qvkpipeline_t vk_drawPolyPipeline

Definition at line 150 of file vk_common.c.

Referenced by CreatePipelines(), DrawVkFlowingPoly(), DrawVkPoly(), and QVk_Shutdown().

◆ vk_drawPolyWarpPipeline

qvkpipeline_t vk_drawPolyWarpPipeline

Definition at line 152 of file vk_common.c.

Referenced by CreatePipelines(), EmitWaterPolys(), and QVk_Shutdown().

◆ vk_drawSkyboxPipeline

qvkpipeline_t vk_drawSkyboxPipeline

Definition at line 154 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawSkyBox().

◆ vk_drawSpritePipeline

qvkpipeline_t vk_drawSpritePipeline

Definition at line 149 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawSpriteModel().

◆ vk_drawTexQuadPipeline

qvkpipeline_t vk_drawTexQuadPipeline

◆ vk_frameStarted

qboolean vk_frameStarted

Definition at line 135 of file vk_common.c.

Referenced by QVk_BeginFrame(), QVk_EndFrame(), and R_EndWorldRenderpass().

◆ vk_instance

◆ vk_malloc

◆ vk_postprocessPipeline

qvkpipeline_t vk_postprocessPipeline

Definition at line 160 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_SetVulkan2D().

◆ vk_samplerDescSetLayout

VkDescriptorSetLayout vk_samplerDescSetLayout

◆ vk_shadowsPipelineFan

qvkpipeline_t vk_shadowsPipelineFan

Definition at line 158 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasShadow().

◆ vk_shadowsPipelineStrip

qvkpipeline_t vk_shadowsPipelineStrip

Definition at line 157 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and Vk_DrawAliasShadow().

◆ vk_showTrisPipeline

qvkpipeline_t vk_showTrisPipeline

Definition at line 156 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_DrawTriangleOutlines().

◆ vk_surface

VkSurfaceKHR vk_surface

◆ vk_swapchain

◆ vk_transferCommandPool

VkCommandPool vk_transferCommandPool

Definition at line 96 of file vk_common.c.

Referenced by copyBuffer(), QVk_Init(), and QVk_Shutdown().

◆ vk_uboDescSetLayout

VkDescriptorSetLayout vk_uboDescSetLayout

◆ vk_worldWarpPipeline

qvkpipeline_t vk_worldWarpPipeline

Definition at line 159 of file vk_common.c.

Referenced by CreatePipelines(), QVk_Shutdown(), and R_EndWorldRenderpass().

QVk_GetUniformBuffer
uint8_t * QVk_GetUniformBuffer(VkDeviceSize size, uint32_t *dstOffset, VkDescriptorSet *dstUboDescriptorSet)
Definition: vk_common.c:2100
vk_activeCmdbuffer
VkCommandBuffer vk_activeCmdbuffer
Definition: vk_common.c:127
QVk_DebugSetObjectName
#define QVk_DebugSetObjectName(a, b, c)
Definition: qvk.h:317
qvkshader_t
Definition: qvk.h:166
qvkdevice_t::gfxQueue
VkQueue gfxQueue
Definition: qvk.h:43
createStagedBuffer
static void createStagedBuffer(const void *data, VkDeviceSize size, qvkbuffer_t *dstBuffer, qvkbufferopts_t bufferOpts, qvkbuffer_t *stagingBuffer)
Definition: vk_buffer.c:41
qvkpipeline_t::mode
VkPolygonMode mode
Definition: qvk.h:157
height
GLsizei height
Definition: qgl_win.c:69
qvkstagingbuffer_t::cmdBuffer
VkCommandBuffer cmdBuffer
Definition: qvk.h:136
vk_dynVertexBuffers
static qvkbuffer_t vk_dynVertexBuffers[NUM_DYNBUFFERS]
Definition: vk_common.c:227
qvkstagingbuffer_t::fence
VkFence fence
Definition: qvk.h:137
qvkdevice_t::logical
VkDevice logical
Definition: qvk.h:40
qvkbuffer_t::buffer
VkBuffer buffer
Definition: qvk.h:126
qvkpipeline_t::flags
VkPipelineCreateFlags flags
Definition: qvk.h:156
vk_activeBufferIdx
int vk_activeBufferIdx
Definition: vk_common.c:129
QVk_DebugLabelBegin
#define QVk_DebugLabelBegin(a, b, c, d, e)
Definition: qvk.h:319
CreateDescriptorSetLayouts
static void CreateDescriptorSetLayouts()
Definition: vk_common.c:761
QVk_FindDepthFormat
VkFormat QVk_FindDepthFormat(void)
Definition: vk_common.c:267
vmaInvalidateAllocation
void vmaInvalidateAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
Invalidates memory of given allocation.
vk_drawDLightPipeline
qvkpipeline_t vk_drawDLightPipeline
Definition: vk_common.c:155
qvkrenderpass_t::rp
VkRenderPass rp
Definition: qvk.h:118
qvktexture_t::format
VkFormat format
Definition: qvk.h:86
vendorNameString
static const char * vendorNameString(uint32_t vendorId)
Definition: vk_device.c:250
qvkstagingbuffer_t::submitted
qboolean submitted
Definition: qvk.h:138
NUM_CMDBUFFERS
#define NUM_CMDBUFFERS
Definition: vk_common.c:117
vkstate_t::current_pipeline
VkPipeline current_pipeline
Definition: vk_local.h:347
QVk_GetStagingBuffer
uint8_t * QVk_GetStagingBuffer(VkDeviceSize size, int alignment, VkCommandBuffer *cmdBuffer, VkBuffer *buffer, uint32_t *dstOffset)
Definition: vk_common.c:2153
vk_instance
VkInstance vk_instance
Definition: vk_common.c:46
qvkshader_t::createInfo
VkPipelineShaderStageCreateInfo createInfo
Definition: qvk.h:168
vkconfig_t::device_type
const char * device_type
Definition: vk_local.h:308
ri
refimport_t ri
Definition: r_main.c:25
vk_fences
VkFence vk_fences[NUM_CMDBUFFERS]
Definition: vk_common.c:121
vk_viewport
VkViewport vk_viewport
Definition: vk_common.c:114
vk_renderFinishedSemaphores
VkSemaphore vk_renderFinishedSemaphores[NUM_CMDBUFFERS]
Definition: vk_common.c:125
vk_swapBuffersCnt
static int vk_swapBuffersCnt[NUM_SWAPBUFFER_SLOTS]
Definition: vk_common.c:241
QVk_CreateVertexBuffer
void QVk_CreateVertexBuffer(const void *data, VkDeviceSize size, qvkbuffer_t *dstBuffer, qvkbuffer_t *stagingBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
Definition: vk_buffer.c:145
cvar_s::modified
qboolean modified
Definition: q_shared.h:330
QVk_CreateBuffer
VkResult QVk_CreateBuffer(VkDeviceSize size, qvkbuffer_t *dstBuffer, const qvkbufferopts_t options)
Definition: vk_buffer.c:70
S_MIPMAP_NEAREST
@ S_MIPMAP_NEAREST
Definition: qvk.h:67
vk_texRectVbo
qvkbuffer_t vk_texRectVbo
Definition: vk_common.c:221
createLogicalDevice
static VkResult createLogicalDevice()
Definition: vk_device.c:161
qvkdevice_t::properties
VkPhysicalDeviceProperties properties
Definition: qvk.h:41
vk_drawPolyPipeline
qvkpipeline_t vk_drawPolyPipeline
Definition: vk_common.c:150
vk_drawPolyWarpPipeline
qvkpipeline_t vk_drawPolyWarpPipeline
Definition: vk_common.c:152
BUFFER_RESIZE_FACTOR
#define BUFFER_RESIZE_FACTOR
Definition: vk_common.c:247
QVk_UpdateTextureSampler
VkSampler QVk_UpdateTextureSampler(qvktexture_t *texture, qvksampler_t samplerType)
Definition: vk_common.c:2225
validationMessenger
static VkDebugUtilsMessengerEXT validationMessenger
Definition: vk_validation.c:23
Sys_Error
void Sys_Error(char *error,...)
Definition: sys_win.c:68
QVk_CreateValidationLayers
void QVk_CreateValidationLayers(void)
Definition: vk_validation.c:74
QVk_BindPipeline
void QVk_BindPipeline(qvkpipeline_t *pipeline)
Definition: vk_common.c:2284
qvktexture_t::vmaFlags
VmaAllocationCreateFlags vmaFlags
Definition: qvk.h:82
vmaUnmapMemory
void vmaUnmapMemory(VmaAllocator allocator, VmaAllocation allocation)
Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().
i
int i
Definition: q_shared.c:305
STAGING_BUFFER_MAXSIZE
#define STAGING_BUFFER_MAXSIZE
Definition: vk_common.c:255
vkconfig_t::uniform_buffer_max_usage
uint32_t uniform_buffer_max_usage
Definition: vk_local.h:320
vk_instance
VkInstance vk_instance
Definition: vk_common.c:46
QVk_CreateSwapchain
VkResult QVk_CreateSwapchain(void)
Definition: vk_swapchain.c:117
vkconfig_t::uniform_buffer_usage
uint32_t uniform_buffer_usage
Definition: vk_local.h:319
qvkstagingbuffer_t
Definition: qvk.h:133
VmaAllocatorCreateInfo
Description of a Allocator to be created.
Definition: vk_mem_alloc.h:1866
RP_WORLD_WARP
@ RP_WORLD_WARP
Definition: qvk.h:198
buffer
GLenum GLfloat * buffer
Definition: qgl_win.c:151
CreateFramebuffers
static VkResult CreateFramebuffers()
Definition: vk_common.c:358
vkconfig_t::layers
const char * layers[256]
Definition: vk_local.h:312
qvkdevice_t::gfxFamilyIndex
int gfxFamilyIndex
Definition: qvk.h:46
QVk_CreateUniformBuffer
VkResult QVk_CreateUniformBuffer(VkDeviceSize size, qvkbuffer_t *dstBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
Definition: vk_buffer.c:127
refimport_t::Cvar_Set
cvar_t *(* Cvar_Set)(char *name, char *value)
Definition: ref.h:217
vk_swapBuffers
static qvkbuffer_t * vk_swapBuffers[NUM_SWAPBUFFER_SLOTS]
Definition: vk_common.c:243
transitionImageLayout
static void transitionImageLayout(const VkCommandBuffer *cmdBuffer, const VkQueue *queue, const qvktexture_t *texture, const VkImageLayout oldLayout, const VkImageLayout newLayout)
Definition: vk_image.c:60
DestroyFramebuffers
static void DestroyFramebuffers()
Definition: vk_common.c:340
width
GLint GLsizei width
Definition: qgl_win.c:115
qvkpipeline_t::pl
VkPipeline pl
Definition: qvk.h:155
qvkshader_t::module
VkShaderModule module
Definition: qvk.h:169
vk_device_idx
cvar_t * vk_device_idx
Definition: vk_rmain.c:122
createTextureImage
static void createTextureImage(qvktexture_t *dstTex, const unsigned char *data, uint32_t width, uint32_t height)
Definition: vk_image.c:240
vk_stagingBuffers
static qvkstagingbuffer_t vk_stagingBuffers[NUM_DYNBUFFERS]
Definition: vk_common.c:231
vk_samplerDescSetLayout
VkDescriptorSetLayout vk_samplerDescSetLayout
Definition: vk_common.c:261
vk_transferCommandPool
VkCommandPool vk_transferCommandPool
Definition: vk_common.c:96
qvkSetDebugUtilsObjectNameEXT
PFN_vkSetDebugUtilsObjectNameEXT qvkSetDebugUtilsObjectNameEXT
Definition: vk_common.c:168
vk_surface
VkSurfaceKHR vk_surface
Definition: vk_common.c:47
vk_swapchain
qvkswapchain_t vk_swapchain
Definition: vk_common.c:63
vk_swapDescriptorSets
static VkDescriptorSet * vk_swapDescriptorSets[NUM_SWAPBUFFER_SLOTS]
Definition: vk_common.c:244
vk_scissor
VkRect2D vk_scissor
Definition: vk_common.c:115
vk_clear
cvar_t * vk_clear
Definition: vk_rmain.c:99
vk_device
qvkdevice_t vk_device
Definition: vk_common.c:51
vk_imageAvailableSemaphores
VkSemaphore vk_imageAvailableSemaphores[NUM_CMDBUFFERS]
Definition: vk_common.c:123
qvkbufferopts_t::prefMemFlags
VkMemoryPropertyFlags prefMemFlags
Definition: qvk.h:146
vkconfig_t::triangle_fan_index_count
uint32_t triangle_fan_index_count
Definition: vk_local.h:324
vk_drawNoDepthModelPipelineStrip
qvkpipeline_t vk_drawNoDepthModelPipelineStrip
Definition: vk_common.c:142
vkconfig_t::index_buffer_size
uint32_t index_buffer_size
Definition: vk_local.h:318
qvkpipeline_t::topology
VkPrimitiveTopology topology
Definition: qvk.h:159
VERTEX_BUFFER_SIZE
#define VERTEX_BUFFER_SIZE
Definition: vk_common.c:251
qvkdevice_t::presentFamilyIndex
int presentFamilyIndex
Definition: qvk.h:47
va
char * va(char *format,...)
Definition: q_shared.c:1050
presentModeString
static const char * presentModeString(VkPresentModeKHR presentMode)
Definition: vk_swapchain.c:24
CreateDrawBuffers
static void CreateDrawBuffers()
Definition: vk_common.c:708
vk_framebuffers
VkFramebuffer * vk_framebuffers[RP_COUNT]
Definition: vk_common.c:102
qvkInsertDebugUtilsLabelEXT
PFN_vkCmdInsertDebugUtilsLabelEXT qvkInsertDebugUtilsLabelEXT
Definition: vk_common.c:172
qvktexture_t::descriptorSet
VkDescriptorSet descriptorSet
Definition: qvk.h:87
vk_drawTexQuadPipeline
qvkpipeline_t vk_drawTexQuadPipeline
Definition: vk_common.c:138
vkconfig_t::index_buffer_usage
uint32_t index_buffer_usage
Definition: vk_local.h:316
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
RP_COUNT
@ RP_COUNT
Definition: qvk.h:199
qvkrenderpass_t::colorLoadOp
VkAttachmentLoadOp colorLoadOp
Definition: qvk.h:119
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
@ VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
Set this flag if the allocation should have its own memory block.
Definition: vk_mem_alloc.h:2114
Vkimp_GetSurfaceExtensions
void Vkimp_GetSurfaceExtensions(char **extensions, uint32_t *extCount)
Definition: vk_imp.c:158
vk_commandPool
VkCommandPool vk_commandPool
Definition: vk_common.c:95
CreateRenderpasses
static VkResult CreateRenderpasses()
Definition: vk_common.c:428
vk_vsync
static cvar_t * vk_vsync
Definition: vid_menu.c:48
QVk_CreateDevice
qboolean QVk_CreateDevice(int preferredDeviceIdx)
Definition: vk_device.c:264
CreateDynamicBuffers
static void CreateDynamicBuffers()
Definition: vk_common.c:940
vkconfig_t::extensions
const char * extensions[256]
Definition: vk_local.h:311
qvktexture_t::image
VkImage image
Definition: qvk.h:79
qvkswapchain_t::format
VkFormat format
Definition: qvk.h:55
qvkswapchain_t::extent
VkExtent2D extent
Definition: qvk.h:57
qvkrenderpasstype_t
qvkrenderpasstype_t
Definition: qvk.h:194
VMA_MEMORY_USAGE_CPU_ONLY
@ VMA_MEMORY_USAGE_CPU_ONLY
Memory will be mappable on host.
Definition: vk_mem_alloc.h:2086
S_ANISO_MIPMAP_NEAREST
@ S_ANISO_MIPMAP_NEAREST
Definition: qvk.h:71
ERRSTR
#define ERRSTR(r)
vk_malloc
VmaAllocator vk_malloc
Definition: vk_common.c:48
UNIFORM_ALLOC_SIZE
#define UNIFORM_ALLOC_SIZE
Definition: vk_common.c:249
viddef_t::width
unsigned width
Definition: vid.h:29
qvkbufferopts_t
Definition: qvk.h:142
qvktexture_t::sampleCount
VkSampleCountFlagBits sampleCount
Definition: qvk.h:85
UNIFORM_BUFFER_SIZE
#define UNIFORM_BUFFER_SIZE
Definition: vk_common.c:253
DestroySamplers
static void DestroySamplers()
Definition: vk_common.c:863
qvksampler_t
qvksampler_t
Definition: qvk.h:63
selectPhysicalDevice
static qboolean selectPhysicalDevice(int preferredDeviceIdx)
Definition: vk_device.c:132
getDepthStencilAspect
static VkImageAspectFlags getDepthStencilAspect(VkFormat depthFormat)
Definition: vk_image.c:46
vk_colorbufferWarp
qvktexture_t vk_colorbufferWarp
Definition: vk_common.c:106
qvkpipeline_t::depthTestEnable
VkBool32 depthTestEnable
Definition: qvk.h:161
S_ANISO_NEAREST
@ S_ANISO_NEAREST
Definition: qvk.h:69
vkconfig_t::index_buffer_max_usage
uint32_t index_buffer_max_usage
Definition: vk_local.h:317
qvkbuffer_t
Definition: qvk.h:124
qvkpipeline_t::cullMode
VkCullModeFlags cullMode
Definition: qvk.h:158
QVk_GetError
const char * QVk_GetError(VkResult errorCode)
Definition: vk_common.c:2293
vk_triangleFanIbo
static VkBuffer * vk_triangleFanIbo
Definition: vk_common.c:236
CreateDescriptorPool
static void CreateDescriptorPool()
Definition: vk_common.c:876
qvkpipeline_t::blendOpts
VkPipelineColorBlendAttachmentState blendOpts
Definition: qvk.h:160
vk_swapchain
qvkswapchain_t vk_swapchain
Definition: vk_common.c:63
DestroyDrawBuffers
static void DestroyDrawBuffers()
Definition: vk_common.c:751
min
#define min(a, b)
Definition: vk_local.h:72
vk_drawPolyLmapPipeline
qvkpipeline_t vk_drawPolyLmapPipeline
Definition: vk_common.c:151
CreatePipelines
static void CreatePipelines()
Definition: vk_common.c:1123
viddef_t::height
unsigned height
Definition: vid.h:29
QVk_SubmitStagingBuffers
void QVk_SubmitStagingBuffers()
Definition: vk_common.c:2216
vkconfig_t::vk_version
uint32_t vk_version
Definition: vk_local.h:306
vkconfig_t::vertex_buffer_usage
uint32_t vertex_buffer_usage
Definition: vk_local.h:313
QVk_DebugLabelEnd
#define QVk_DebugLabelEnd(a)
Definition: qvk.h:320
cvar_s::value
float value
Definition: q_shared.h:331
qvkswapchain_t::imageCount
int imageCount
Definition: qvk.h:59
vk_validation
cvar_t * vk_validation
Definition: vk_rmain.c:90
vk_stagingCommandPool
static VkCommandPool vk_stagingCommandPool
Definition: vk_common.c:98
VMA_MEMORY_USAGE_GPU_ONLY
@ VMA_MEMORY_USAGE_GPU_ONLY
Memory will be used on device only, so fast access from the device is preferred.
Definition: vk_mem_alloc.h:2076
vk_state
vkstate_t vk_state
Definition: vk_rmain.c:31
qvkbuffer_t::currentOffset
VkDeviceSize currentOffset
Definition: qvk.h:129
qvkdevice_t::features
VkPhysicalDeviceFeatures features
Definition: qvk.h:42
qvkCreateDebugUtilsMessengerEXT
PFN_vkCreateDebugUtilsMessengerEXT qvkCreateDebugUtilsMessengerEXT
Definition: vk_common.c:166
QVk_SubmitCommand
void QVk_SubmitCommand(const VkCommandBuffer *commandBuffer, const VkQueue *queue)
Definition: vk_cmd.c:35
SubmitStagingBuffer
static void SubmitStagingBuffer(int index)
Definition: vk_common.c:1066
vk_shadowsPipelineFan
qvkpipeline_t vk_shadowsPipelineFan
Definition: vk_common.c:158
qvkCmdBeginDebugUtilsLabelEXT
PFN_vkCmdBeginDebugUtilsLabelEXT qvkCmdBeginDebugUtilsLabelEXT
Definition: vk_common.c:170
CreateSamplers
static void CreateSamplers()
Definition: vk_common.c:794
NULL
#define NULL
Definition: q_shared.h:67
vk_commandPool
VkCommandPool vk_commandPool
Definition: vk_common.c:95
S_MIPMAP_LINEAR
@ S_MIPMAP_LINEAR
Definition: qvk.h:68
vk_colorbuffer
qvktexture_t vk_colorbuffer
Definition: vk_common.c:104
vk_drawParticlesPipeline
qvkpipeline_t vk_drawParticlesPipeline
Definition: vk_common.c:147
GetSampleCount
static VkSampleCountFlagBits GetSampleCount()
Definition: vk_common.c:290
vid_ref
cvar_t * vid_ref
Definition: vid_dll.c:44
vk_showTrisPipeline
qvkpipeline_t vk_showTrisPipeline
Definition: vk_common.c:156
vk_device
qvkdevice_t vk_device
Definition: vk_common.c:51
vk_config
vkconfig_t vk_config
Definition: vk_rmain.c:30
vk_drawLefthandModelPipelineStrip
qvkpipeline_t vk_drawLefthandModelPipelineStrip
Definition: vk_common.c:144
qvktexture_t::imageView
VkImageView imageView
Definition: qvk.h:83
Vkimp_CreateSurface
VkResult Vkimp_CreateSurface()
Definition: vk_imp.c:170
qvkstagingbuffer_t::buffer
qvkbuffer_t buffer
Definition: qvk.h:135
qvkpipeline_t::depthWriteEnable
VkBool32 depthWriteEnable
Definition: qvk.h:162
TRIANGLE_FAN_INDEX_CNT
#define TRIANGLE_FAN_INDEX_CNT
Definition: vk_common.c:257
R_EndWorldRenderpass
void R_EndWorldRenderpass(void)
Definition: r_main.c:1249
qvkbuffer_t::allocation
VmaAllocation allocation
Definition: qvk.h:127
QVk_BeginCommand
VkResult QVk_BeginCommand(const VkCommandBuffer *commandBuffer)
Definition: vk_cmd.c:23
qvkbuffer_t::allocInfo
VmaAllocationInfo allocInfo
Definition: qvk.h:128
QVk_FreeBuffer
void QVk_FreeBuffer(qvkbuffer_t *buffer)
Definition: vk_buffer.c:106
vk_activeDynBufferIdx
static int vk_activeDynBufferIdx
Definition: vk_common.c:232
QVk_CreateCommandBuffer
VkCommandBuffer QVk_CreateCommandBuffer(const VkCommandPool *commandPool, VkCommandBufferLevel level)
Definition: vk_cmd.c:78
qvkpipeline_t::layout
VkPipelineLayout layout
Definition: qvk.h:154
S_ANISO_MIPMAP_LINEAR
@ S_ANISO_MIPMAP_LINEAR
Definition: qvk.h:72
VK_VERIFY
#define VK_VERIFY(x)
Definition: vk_local.h:59
QVk_CreateImageView
VkResult QVk_CreateImageView(const VkImage *image, VkImageAspectFlags aspectFlags, VkImageView *imageView, VkFormat format, uint32_t mipLevels)
Definition: vk_image.c:293
qvktexture_t::mipLevels
uint32_t mipLevels
Definition: qvk.h:88
qvkdevice_t::presentQueue
VkQueue presentQueue
Definition: qvk.h:44
vk_imageIndex
uint32_t vk_imageIndex
Definition: vk_common.c:131
vmaDestroyAllocator
void vmaDestroyAllocator(VmaAllocator allocator)
Destroys allocator object.
INDEX_BUFFER_SIZE
#define INDEX_BUFFER_SIZE
Definition: vk_common.c:252
qvkswapchain_t::sc
VkSwapchainKHR sc
Definition: qvk.h:54
vk_sampleshading
static cvar_t * vk_sampleshading
Definition: vid_menu.c:45
vk_uboDescSetLayout
VkDescriptorSetLayout vk_uboDescSetLayout
Definition: vk_common.c:260
vmaMapMemory
VkResult vmaMapMemory(VmaAllocator allocator, VmaAllocation allocation, void **ppData)
Maps memory represented by given allocation and returns pointer to it.
S_NEAREST
@ S_NEAREST
Definition: qvk.h:65
vk_drawNoDepthModelPipelineFan
qvkpipeline_t vk_drawNoDepthModelPipelineFan
Definition: vk_common.c:143
qvkDestroyDebugUtilsMessengerEXT
PFN_vkDestroyDebugUtilsMessengerEXT qvkDestroyDebugUtilsMessengerEXT
Definition: vk_common.c:167
CreateStaticBuffers
static void CreateStaticBuffers()
Definition: vk_common.c:1096
vmaCreateImage
VkResult vmaCreateImage(VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkImage *pImage, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
Function similar to vmaCreateBuffer().
CreateImageViews
static VkResult CreateImageViews()
Definition: vk_common.c:318
vkconfig_t::vertex_buffer_max_usage
uint32_t vertex_buffer_max_usage
Definition: vk_local.h:314
vkconfig_t::uniform_buffer_size
uint32_t uniform_buffer_size
Definition: vk_local.h:321
QVk_UpdateTextureSampler
VkSampler QVk_UpdateTextureSampler(qvktexture_t *texture, qvksampler_t samplerType)
Definition: vk_common.c:2225
qvkrenderpass_t::sampleCount
VkSampleCountFlagBits sampleCount
Definition: qvk.h:120
qvkswapchain_t::images
VkImage * images
Definition: qvk.h:58
vk_rectIbo
qvkbuffer_t vk_rectIbo
Definition: vk_common.c:223
vk_drawSkyboxPipeline
qvkpipeline_t vk_drawSkyboxPipeline
Definition: vk_common.c:154
VmaAllocationInfo::pMappedData
void * pMappedData
Pointer to the beginning of this allocation as mapped data.
Definition: vk_mem_alloc.h:2564
vk_colorRectVbo
qvkbuffer_t vk_colorRectVbo
Definition: vk_common.c:222
VmaAllocatorCreateInfo::flags
VmaAllocatorCreateFlags flags
Flags for created allocator. Use VmaAllocatorCreateFlagBits enum.
Definition: vk_mem_alloc.h:1869
S_ANISO_LINEAR
@ S_ANISO_LINEAR
Definition: qvk.h:70
vkconfig_t::vendor_name
const char * vendor_name
Definition: vk_local.h:307
RP_UI
@ RP_UI
Definition: qvk.h:197
vk_drawSpritePipeline
qvkpipeline_t vk_drawSpritePipeline
Definition: vk_common.c:149
vk_worldWarpPipeline
qvkpipeline_t vk_worldWarpPipeline
Definition: vk_common.c:159
QVk_DestroyPipeline
void QVk_DestroyPipeline(qvkpipeline_t *pipeline)
Definition: vk_pipeline.c:198
RebuildTriangleFanIndexBuffer
static void RebuildTriangleFanIndexBuffer()
Definition: vk_common.c:1004
qvkSetDebugUtilsObjectTagEXT
PFN_vkSetDebugUtilsObjectTagEXT qvkSetDebugUtilsObjectTagEXT
Definition: vk_common.c:169
vk_malloc
VmaAllocator vk_malloc
Definition: vk_common.c:48
VMA_MEMORY_USAGE_CPU_TO_GPU
@ VMA_MEMORY_USAGE_CPU_TO_GPU
Memory that is both mappable on host (guarantees to be HOST_VISIBLE) and preferably fast to access by...
Definition: vk_mem_alloc.h:2093
S_SAMPLER_CNT
@ S_SAMPLER_CNT
Definition: qvk.h:73
level
GLint level
Definition: qgl_win.c:116
vk_triangleFanIboUsage
static uint32_t vk_triangleFanIboUsage
Definition: vk_common.c:237
vk_drawModelPipelineFan
qvkpipeline_t vk_drawModelPipelineFan[2]
Definition: vk_common.c:141
qvkbufferopts_t::usage
VkBufferUsageFlags usage
Definition: qvk.h:144
getSupportedCompositeAlpha
static VkCompositeAlphaFlagBitsKHR getSupportedCompositeAlpha(VkCompositeAlphaFlagsKHR supportedFlags)
Definition: vk_swapchain.c:99
vk_swapDescSetsCnt
static int vk_swapDescSetsCnt[NUM_SWAPBUFFER_SLOTS]
Definition: vk_common.c:242
vkconfig_t::triangle_fan_index_usage
uint32_t triangle_fan_index_usage
Definition: vk_local.h:322
vk_msaa
cvar_t * vk_msaa
Definition: vk_rmain.c:113
vmaCreateBuffer
VkResult vmaCreateBuffer(VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
QVk_CreateCommandPool
VkResult QVk_CreateCommandPool(VkCommandPool *commandPool, uint32_t queueFamilyIndex)
Definition: vk_cmd.c:65
qvkCreateDebugUtilsMessengerEXT
PFN_vkCreateDebugUtilsMessengerEXT qvkCreateDebugUtilsMessengerEXT
Definition: vk_common.c:166
vmaCreateAllocator
VkResult vmaCreateAllocator(const VmaAllocatorCreateInfo *pCreateInfo, VmaAllocator *pAllocator)
Creates Allocator object.
S_LINEAR
@ S_LINEAR
Definition: qvk.h:66
vk_descriptorPool
VkDescriptorPool vk_descriptorPool
Definition: vk_common.c:97
vk_postprocessPipeline
qvkpipeline_t vk_postprocessPipeline
Definition: vk_common.c:160
vk_descriptorPool
VkDescriptorPool vk_descriptorPool
Definition: vk_common.c:97
vk_drawBeamPipeline
qvkpipeline_t vk_drawBeamPipeline
Definition: vk_common.c:153
vk_frameStarted
qboolean vk_frameStarted
Definition: vk_common.c:135
vmaFlushAllocation
void vmaFlushAllocation(VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
Flushes memory of given allocation.
vk_shadowsPipelineStrip
qvkpipeline_t vk_shadowsPipelineStrip
Definition: vk_common.c:157
format
GLsizei GLenum format
Definition: qgl_win.c:131
qvkbufferopts_t::vmaUsage
VmaMemoryUsage vmaUsage
Definition: qvk.h:147
qvkdevice_t::transferQueue
VkQueue transferQueue
Definition: qvk.h:45
ReleaseSwapBuffers
static void ReleaseSwapBuffers()
Definition: vk_common.c:965
vk_surface
VkSurfaceKHR vk_surface
Definition: vk_common.c:47
CreateUboDescriptorSet
static void CreateUboDescriptorSet(VkDescriptorSet *descSet, VkBuffer buffer)
Definition: vk_common.c:905
vk_drawColorQuadPipeline
qvkpipeline_t vk_drawColorQuadPipeline[2]
Definition: vk_common.c:139
vk_commandbuffers
VkCommandBuffer * vk_commandbuffers
Definition: vk_common.c:119
debugUtilsCallback
static VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsCallback(VkDebugUtilsMessageSeverityFlagBitsEXT msgSeverity, VkDebugUtilsMessageTypeFlagsEXT msgType, const VkDebugUtilsMessengerCallbackDataEXT *callbackData, void *userData)
Definition: vk_validation.c:46
vmaDestroyImage
void vmaDestroyImage(VmaAllocator allocator, VkImage image, VmaAllocation allocation)
Destroys Vulkan image and frees allocated memory.
texture
GLuint texture
Definition: qgl_win.c:68
getSwapSurfaceFormat
static VkSurfaceFormatKHR getSwapSurfaceFormat(const VkSurfaceFormatKHR *surfaceFormats, uint32_t formatCount)
Definition: vk_swapchain.c:40
VMA_ALLOCATION_CREATE_MAPPED_BIT
@ VMA_ALLOCATION_CREATE_MAPPED_BIT
Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.
Definition: vk_mem_alloc.h:2138
vmaDestroyBuffer
void vmaDestroyBuffer(VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation)
Destroys Vulkan buffer and frees allocated memory.
QVk_CreateImage
VkResult QVk_CreateImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VmaMemoryUsage memUsage, qvktexture_t *texture)
Definition: vk_image.c:316
vk_uboDescriptorSets
static VkDescriptorSet vk_uboDescriptorSets[NUM_DYNBUFFERS]
Definition: vk_common.c:230
CreateStagingBuffers
static void CreateStagingBuffers()
Definition: vk_common.c:1037
NUM_DYNBUFFERS
#define NUM_DYNBUFFERS
Definition: vk_common.c:226
QVk_CreateBuffer
VkResult QVk_CreateBuffer(VkDeviceSize size, qvkbuffer_t *dstBuffer, const qvkbufferopts_t options)
Definition: vk_buffer.c:70
qvkdevice_t::transferFamilyIndex
int transferFamilyIndex
Definition: qvk.h:48
vk_drawPointParticlesPipeline
qvkpipeline_t vk_drawPointParticlesPipeline
Definition: vk_common.c:148
qvkbufferopts_t::vmaFlags
VmaAllocationCreateFlags vmaFlags
Definition: qvk.h:148
vk_dynUniformBuffers
static qvkbuffer_t vk_dynUniformBuffers[NUM_DYNBUFFERS]
Definition: vk_common.c:229
qvkbufferopts_t::reqMemFlags
VkMemoryPropertyFlags reqMemFlags
Definition: qvk.h:145
qvkCmdEndDebugUtilsLabelEXT
PFN_vkCmdEndDebugUtilsLabelEXT qvkCmdEndDebugUtilsLabelEXT
Definition: vk_common.c:171
vk_drawModelPipelineStrip
qvkpipeline_t vk_drawModelPipelineStrip[2]
Definition: vk_common.c:140
VmaAllocationCreateInfo::flags
VmaAllocationCreateFlags flags
Use VmaAllocationCreateFlagBits enum.
Definition: vk_mem_alloc.h:2217
vk_dynIndexBuffers
static qvkbuffer_t vk_dynIndexBuffers[NUM_DYNBUFFERS]
Definition: vk_common.c:228
vkconfig_t::vertex_buffer_size
uint32_t vertex_buffer_size
Definition: vk_local.h:315
VmaAllocationCreateInfo
Definition: vk_mem_alloc.h:2214
vk_renderpasses
qvkrenderpass_t vk_renderpasses[RP_COUNT]
Definition: vk_common.c:73
vk_samplers
static VkSampler vk_samplers[S_SAMPLER_CNT]
Definition: vk_common.c:163
getSwapPresentMode
static VkPresentModeKHR getSwapPresentMode(const VkPresentModeKHR *presentModes, uint32_t presentModesCount, VkPresentModeKHR desiredMode)
Definition: vk_swapchain.c:62
qvkDestroyDebugUtilsMessengerEXT
PFN_vkDestroyDebugUtilsMessengerEXT qvkDestroyDebugUtilsMessengerEXT
Definition: vk_common.c:167
RP_WORLD
@ RP_WORLD
Definition: qvk.h:196
QVk_CreateIndexBuffer
void QVk_CreateIndexBuffer(const void *data, VkDeviceSize size, qvkbuffer_t *dstBuffer, qvkbuffer_t *stagingBuffer, VkMemoryPropertyFlags reqMemFlags, VkMemoryPropertyFlags prefMemFlags)
Definition: vk_buffer.c:158
vk_samplerDescSetLayout
VkDescriptorSetLayout vk_samplerDescSetLayout
Definition: vk_common.c:261
max
#define max(a, b)
Definition: vk_local.h:75
QVk_SubmitStagingBuffers
void QVk_SubmitStagingBuffers(void)
Definition: vk_common.c:2216
DestroyImageViews
static void DestroyImageViews()
Definition: vk_common.c:304
vk_drawLefthandModelPipelineFan
qvkpipeline_t vk_drawLefthandModelPipelineFan
Definition: vk_common.c:145
vk_activeSwapBufferIdx
static int vk_activeSwapBufferIdx
Definition: vk_common.c:233
vk_activeStagingBuffer
int vk_activeStagingBuffer
Definition: vk_common.c:133
generateMipmaps
static void generateMipmaps(const VkCommandBuffer *cmdBuffer, const qvktexture_t *texture, uint32_t width, uint32_t height)
Definition: vk_image.c:169
deviceTypeString
static const char * deviceTypeString(VkPhysicalDeviceType dType)
Definition: vk_device.c:233
QVk_DestroyValidationLayers
void QVk_DestroyValidationLayers(void)
Definition: vk_validation.c:99
qvkdevice_t::physical
VkPhysicalDevice physical
Definition: qvk.h:39
NextPow2
static int NextPow2(int v)
Definition: vk_common.c:991
vkconfig_t::triangle_fan_index_max_usage
uint32_t triangle_fan_index_max_usage
Definition: vk_local.h:323
vkconfig_t::supported_present_modes
const char * supported_present_modes[256]
Definition: vk_local.h:310
vk_drawNullModelPipeline
qvkpipeline_t vk_drawNullModelPipeline
Definition: vk_common.c:146
vk_samplerLightmapDescSetLayout
VkDescriptorSetLayout vk_samplerLightmapDescSetLayout
Definition: vk_common.c:262
vid
viddef_t vid
Definition: r_main.c:24
QVk_GetError
const char * QVk_GetError(VkResult errorCode)
Definition: vk_common.c:2293