Quake II RTX doxygen  1.0 dev
draw.c File Reference
#include "shared/shared.h"
#include "refresh/refresh.h"
#include "client/client.h"
#include "refresh/images.h"
#include <assert.h>
#include "vkpt.h"
#include "shader/global_textures.h"

Go to the source code of this file.

Classes

struct  StretchPic_t
 

Macros

#define TEXNUM_WHITE   (~0)
 
#define MAX_STRETCH_PICS   (1<<14)
 
#define DIV64   (1.0f / 64.0f)
 

Functions

VkExtent2D vkpt_draw_get_extent ()
 
static void enqueue_stretch_pic (float x, float y, float w, float h, float s1, float t1, float s2, float t2, uint32_t color, int tex_handle)
 
static void create_render_pass ()
 
VkResult vkpt_draw_initialize ()
 
VkResult vkpt_draw_destroy ()
 
VkResult vkpt_draw_destroy_pipelines ()
 
VkResult vkpt_draw_create_pipelines ()
 
VkResult vkpt_draw_clear_stretch_pics ()
 
VkResult vkpt_draw_submit_stretch_pics (VkCommandBuffer cmd_buf)
 
VkResult vkpt_final_blit_simple (VkCommandBuffer cmd_buf)
 
VkResult vkpt_final_blit_filtered (VkCommandBuffer cmd_buf)
 
void R_SetClipRect_RTX (const clipRect_t *clip)
 
void R_ClearColor_RTX (void)
 
void R_SetAlpha_RTX (float alpha)
 
void R_SetAlphaScale_RTX (float alpha)
 
void R_SetColor_RTX (uint32_t color)
 
void R_LightPoint_RTX (vec3_t origin, vec3_t light)
 
void R_SetScale_RTX (float scale)
 
void R_DrawStretchPic_RTX (int x, int y, int w, int h, qhandle_t pic)
 
void R_DrawPic_RTX (int x, int y, qhandle_t pic)
 
void R_TileClear_RTX (int x, int y, int w, int h, qhandle_t pic)
 
void R_DrawFill8_RTX (int x, int y, int w, int h, int c)
 
void R_DrawFill32_RTX (int x, int y, int w, int h, uint32_t color)
 
static void draw_char (int x, int y, int flags, int c, qhandle_t font)
 
void R_DrawChar_RTX (int x, int y, int flags, int c, qhandle_t font)
 
int R_DrawString_RTX (int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font)
 

Variables

drawStatic_t draw
 
static int num_stretch_pics = 0
 
static clipRect_t clip_rect
 
static qboolean clip_enable = qfalse
 
static StretchPic_t stretch_pic_queue [MAX_STRETCH_PICS]
 
static VkPipelineLayout pipeline_layout_stretch_pic
 
static VkPipelineLayout pipeline_layout_final_blit
 
static VkRenderPass render_pass_stretch_pic
 
static VkPipeline pipeline_stretch_pic
 
static VkPipeline pipeline_final_blit
 
static VkFramebuffer framebuffer_stretch_pic [MAX_FRAMES_IN_FLIGHT]
 
static BufferResource_t buf_stretch_pic_queue [MAX_FRAMES_IN_FLIGHT]
 
static VkDescriptorSetLayout desc_set_layout_sbo
 
static VkDescriptorPool desc_pool_sbo
 
static VkDescriptorSet desc_set_sbo [MAX_FRAMES_IN_FLIGHT]
 

Macro Definition Documentation

◆ DIV64

#define DIV64   (1.0f / 64.0f)

Definition at line 697 of file draw.c.

◆ MAX_STRETCH_PICS

#define MAX_STRETCH_PICS   (1<<14)

Definition at line 31 of file draw.c.

◆ TEXNUM_WHITE

#define TEXNUM_WHITE   (~0)

Definition at line 30 of file draw.c.

Function Documentation

◆ create_render_pass()

static void create_render_pass ( )
static

Definition at line 163 of file draw.c.

164 {
165  LOG_FUNC();
166  VkAttachmentDescription color_attachment = {
167  .format = qvk.surf_format.format,
168  .samples = VK_SAMPLE_COUNT_1_BIT,
169  .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
170  //.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
171  //.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
172  .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
173  .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
174  .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
175  .initialLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
176  .finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
177  };
178 
179  VkAttachmentReference color_attachment_ref = {
180  .attachment = 0, /* index in fragment shader */
181  .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
182  };
183 
184  VkSubpassDescription subpass = {
185  .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
186  .colorAttachmentCount = 1,
187  .pColorAttachments = &color_attachment_ref,
188  };
189 
190  VkSubpassDependency dependencies[] = {
191  {
192  .srcSubpass = VK_SUBPASS_EXTERNAL,
193  .dstSubpass = 0, /* index for own subpass */
194  .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
195  .srcAccessMask = 0, /* XXX verify */
196  .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
197  .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
198  | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
199  },
200  };
201 
202  VkRenderPassCreateInfo render_pass_info = {
203  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
204  .attachmentCount = 1,
205  .pAttachments = &color_attachment,
206  .subpassCount = 1,
207  .pSubpasses = &subpass,
208  .dependencyCount = LENGTH(dependencies),
209  .pDependencies = dependencies,
210  };
211 
212  _VK(vkCreateRenderPass(qvk.device, &render_pass_info, NULL, &render_pass_stretch_pic));
214 }

Referenced by vkpt_draw_initialize().

◆ draw_char()

static void draw_char ( int  x,
int  y,
int  flags,
int  c,
qhandle_t  font 
)
inlinestatic

Definition at line 726 of file draw.c.

727 {
728  if ((c & 127) == 32) {
729  return;
730  }
731 
732  if (flags & UI_ALTCOLOR) {
733  c |= 0x80;
734  }
735  if (flags & UI_XORCOLOR) {
736  c ^= 0x80;
737  }
738 
739  float s = (c & 15) * 0.0625f;
740  float t = (c >> 4) * 0.0625f;
741 
742  float eps = 1e-5f; /* fixes some ugly artifacts */
743 
744  enqueue_stretch_pic(x, y, CHAR_WIDTH, CHAR_HEIGHT,
745  s + eps, t + eps, s + 0.0625f - eps, t + 0.0625f - eps,
746  draw.colors[c >> 7].u32, font);
747 }

Referenced by R_DrawChar_RTX(), and R_DrawString_RTX().

◆ enqueue_stretch_pic()

static void enqueue_stretch_pic ( float  x,
float  y,
float  w,
float  h,
float  s1,
float  t1,
float  s2,
float  t2,
uint32_t  color,
int  tex_handle 
)
inlinestatic

Definition at line 67 of file draw.c.

71 {
72  if (draw.alpha_scale == 0.f)
73  return;
74 
76  Com_EPrintf("Error: stretch pic queue full!\n");
77  assert(0);
78  return;
79  }
80  assert(tex_handle);
82 
83  if (clip_enable)
84  {
85  if (x >= clip_rect.right || x + w <= clip_rect.left || y >= clip_rect.bottom || y + h <= clip_rect.top)
86  return;
87 
88  if (x < clip_rect.left)
89  {
90  float dw = clip_rect.left - x;
91  s1 += dw / w * (s2 - s1);
92  w -= dw;
93  x = clip_rect.left;
94 
95  if (w <= 0) return;
96  }
97 
98  if (x + w > clip_rect.right)
99  {
100  float dw = (x + w) - clip_rect.right;
101  s2 -= dw / w * (s2 - s1);
102  w -= dw;
103 
104  if (w <= 0) return;
105  }
106 
107  if (y < clip_rect.top)
108  {
109  float dh = clip_rect.top - y;
110  t1 += dh / h * (t2 - t1);
111  h -= dh;
112  y = clip_rect.top;
113 
114  if (h <= 0) return;
115  }
116 
117  if (y + h > clip_rect.bottom)
118  {
119  float dh = (y + h) - clip_rect.bottom;
120  t2 -= dh / h * (t2 - t1);
121  h -= dh;
122 
123  if (h <= 0) return;
124  }
125  }
126 
127  float width = r_config.width * draw.scale;
128  float height = r_config.height * draw.scale;
129 
130  x = 2.0f * x / width - 1.0f;
131  y = 2.0f * y / height - 1.0f;
132 
133  w = 2.0f * w / width;
134  h = 2.0f * h / height;
135 
136  sp->x = x;
137  sp->y = y;
138  sp->w = w;
139  sp->h = h;
140 
141  sp->s = s1;
142  sp->t = t1;
143  sp->w_s = s2 - s1;
144  sp->h_t = t2 - t1;
145 
146  if (draw.alpha_scale < 1.f)
147  {
148  float alpha = (color >> 24) & 0xff;
149  alpha *= draw.alpha_scale;
150  alpha = max(0.f, min(255.f, alpha));
151  color = (color & 0xffffff) | ((int)(alpha) << 24);
152  }
153 
154  sp->color = color;
155  sp->tex_handle = tex_handle;
156  if(tex_handle >= 0 && tex_handle < MAX_RIMAGES
157  && !r_images[tex_handle].registration_sequence) {
158  sp->tex_handle = TEXNUM_WHITE;
159  }
160 }

Referenced by draw_char(), R_DrawFill32_RTX(), R_DrawFill8_RTX(), R_DrawStretchPic_RTX(), and R_TileClear_RTX().

◆ R_ClearColor_RTX()

void R_ClearColor_RTX ( void  )

Definition at line 643 of file draw.c.

644 {
645  draw.colors[0].u32 = U32_WHITE;
646  draw.colors[1].u32 = U32_WHITE;
647 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawChar_RTX()

void R_DrawChar_RTX ( int  x,
int  y,
int  flags,
int  c,
qhandle_t  font 
)

Definition at line 750 of file draw.c.

751 {
752  draw_char(x, y, flags, c & 255, font);
753 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawFill32_RTX()

void R_DrawFill32_RTX ( int  x,
int  y,
int  w,
int  h,
uint32_t  color 
)

Definition at line 717 of file draw.c.

718 {
719  if(!w || !h)
720  return;
721  enqueue_stretch_pic(x, y, w, h, 0.0f, 0.0f, 1.0f, 1.0f,
723 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawFill8_RTX()

void R_DrawFill8_RTX ( int  x,
int  y,
int  w,
int  h,
int  c 
)

Definition at line 708 of file draw.c.

709 {
710  if(!w || !h)
711  return;
712  enqueue_stretch_pic(x, y, w, h, 0.0f, 0.0f, 1.0f, 1.0f,
713  d_8to24table[c & 0xff], TEXNUM_WHITE);
714 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawPic_RTX()

void R_DrawPic_RTX ( int  x,
int  y,
qhandle_t  pic 
)

Definition at line 691 of file draw.c.

692 {
693  image_t *image = IMG_ForHandle(pic);
694  R_DrawStretchPic(x, y, image->width, image->height, pic);
695 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawStretchPic_RTX()

void R_DrawStretchPic_RTX ( int  x,
int  y,
int  w,
int  h,
qhandle_t  pic 
)

Definition at line 682 of file draw.c.

683 {
685  x, y, w, h,
686  0.0f, 0.0f, 1.0f, 1.0f,
687  draw.colors[0].u32, pic);
688 }

Referenced by R_RegisterFunctionsRTX().

◆ R_DrawString_RTX()

int R_DrawString_RTX ( int  x,
int  y,
int  flags,
size_t  maxlen,
const char *  s,
qhandle_t  font 
)

Definition at line 756 of file draw.c.

757 {
758  while(maxlen-- && *s) {
759  byte c = *s++;
760  draw_char(x, y, flags, c, font);
761  x += CHAR_WIDTH;
762  }
763 
764  return x;
765 }

Referenced by R_RegisterFunctionsRTX().

◆ R_LightPoint_RTX()

void R_LightPoint_RTX ( vec3_t  origin,
vec3_t  light 
)

Definition at line 670 of file draw.c.

671 {
672  VectorSet(light, 1, 1, 1);
673 }

Referenced by R_RegisterFunctionsRTX().

◆ R_SetAlpha_RTX()

void R_SetAlpha_RTX ( float  alpha)

Definition at line 650 of file draw.c.

651 {
652  alpha = powf(fabsf(alpha), 0.4545f); // un-sRGB the alpha
653  draw.colors[0].u8[3] = draw.colors[1].u8[3] = alpha * 255;
654 }

Referenced by R_RegisterFunctionsRTX().

◆ R_SetAlphaScale_RTX()

void R_SetAlphaScale_RTX ( float  alpha)

Definition at line 657 of file draw.c.

658 {
659  draw.alpha_scale = alpha;
660 }

Referenced by R_RegisterFunctionsRTX().

◆ R_SetClipRect_RTX()

void R_SetClipRect_RTX ( const clipRect_t *  clip)

Definition at line 629 of file draw.c.

630 {
631  if (clip)
632  {
633  clip_enable = qtrue;
634  clip_rect = *clip;
635  }
636  else
637  {
638  clip_enable = qfalse;
639  }
640 }

Referenced by R_RegisterFunctionsRTX().

◆ R_SetColor_RTX()

void R_SetColor_RTX ( uint32_t  color)

Definition at line 663 of file draw.c.

664 {
665  draw.colors[0].u32 = color;
666  draw.colors[1].u8[3] = draw.colors[0].u8[3];
667 }

Referenced by R_RegisterFunctionsRTX().

◆ R_SetScale_RTX()

void R_SetScale_RTX ( float  scale)

Definition at line 676 of file draw.c.

677 {
678  draw.scale = scale;
679 }

Referenced by R_RegisterFunctionsRTX().

◆ R_TileClear_RTX()

void R_TileClear_RTX ( int  x,
int  y,
int  w,
int  h,
qhandle_t  pic 
)

Definition at line 700 of file draw.c.

701 {
702  enqueue_stretch_pic(x, y, w, h,
703  x * DIV64, y * DIV64, (x + w) * DIV64, (y + h) * DIV64,
704  U32_WHITE, pic);
705 }

Referenced by R_RegisterFunctionsRTX().

◆ vkpt_draw_clear_stretch_pics()

VkResult vkpt_draw_clear_stretch_pics ( )

Definition at line 492 of file draw.c.

493 {
494  num_stretch_pics = 0;
495  return VK_SUCCESS;
496 }

Referenced by R_BeginFrame_RTX().

◆ vkpt_draw_create_pipelines()

VkResult vkpt_draw_create_pipelines ( )

Definition at line 323 of file draw.c.

324 {
325  LOG_FUNC();
326 
327  assert(desc_set_layout_sbo);
328  VkDescriptorSetLayout desc_set_layouts[] = {
330  };
332  .setLayoutCount = LENGTH(desc_set_layouts),
333  .pSetLayouts = desc_set_layouts
334  );
335 
336  desc_set_layouts[0] = qvk.desc_set_layout_ubo;
337 
339  .setLayoutCount = LENGTH(desc_set_layouts),
340  .pSetLayouts = desc_set_layouts
341  );
342 
343  VkPipelineShaderStageCreateInfo shader_info[] = {
344  SHADER_STAGE(QVK_MOD_STRETCH_PIC_VERT, VK_SHADER_STAGE_VERTEX_BIT),
345  SHADER_STAGE(QVK_MOD_STRETCH_PIC_FRAG, VK_SHADER_STAGE_FRAGMENT_BIT)
346  };
347 
348  VkPipelineVertexInputStateCreateInfo vertex_input_info = {
349  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
350  .vertexBindingDescriptionCount = 0,
351  .pVertexBindingDescriptions = NULL,
352  .vertexAttributeDescriptionCount = 0,
353  .pVertexAttributeDescriptions = NULL,
354  };
355 
356  VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
357  .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
358  .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
359  .primitiveRestartEnable = VK_FALSE,
360  };
361 
362  VkViewport viewport = {
363  .x = 0.0f,
364  .y = 0.0f,
365  .width = (float) vkpt_draw_get_extent().width,
366  .height = (float) vkpt_draw_get_extent().height,
367  .minDepth = 0.0f,
368  .maxDepth = 1.0f,
369  };
370 
371  VkRect2D scissor = {
372  .offset = { 0, 0 },
373  .extent = vkpt_draw_get_extent(),
374  };
375 
376  VkPipelineViewportStateCreateInfo viewport_state = {
377  .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
378  .viewportCount = 1,
379  .pViewports = &viewport,
380  .scissorCount = 1,
381  .pScissors = &scissor,
382  };
383 
384  VkPipelineRasterizationStateCreateInfo rasterizer_state = {
385  .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
386  .depthClampEnable = VK_FALSE,
387  .rasterizerDiscardEnable = VK_FALSE, /* skip rasterizer */
388  .polygonMode = VK_POLYGON_MODE_FILL,
389  .lineWidth = 1.0f,
390  .cullMode = VK_CULL_MODE_BACK_BIT,
391  .frontFace = VK_FRONT_FACE_CLOCKWISE,
392  .depthBiasEnable = VK_FALSE,
393  .depthBiasConstantFactor = 0.0f,
394  .depthBiasClamp = 0.0f,
395  .depthBiasSlopeFactor = 0.0f,
396  };
397 
398  VkPipelineMultisampleStateCreateInfo multisample_state = {
399  .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
400  .sampleShadingEnable = VK_FALSE,
401  .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
402  .minSampleShading = 1.0f,
403  .pSampleMask = NULL,
404  .alphaToCoverageEnable = VK_FALSE,
405  .alphaToOneEnable = VK_FALSE,
406  };
407 
408  VkPipelineColorBlendAttachmentState color_blend_attachment = {
409  .colorWriteMask = VK_COLOR_COMPONENT_R_BIT
410  | VK_COLOR_COMPONENT_G_BIT
411  | VK_COLOR_COMPONENT_B_BIT
412  | VK_COLOR_COMPONENT_A_BIT,
413  .blendEnable = VK_TRUE,
414  .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
415  .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
416  .colorBlendOp = VK_BLEND_OP_ADD,
417  .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
418  .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO,
419  .alphaBlendOp = VK_BLEND_OP_ADD,
420  };
421 
422  VkPipelineColorBlendStateCreateInfo color_blend_state = {
423  .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
424  .logicOpEnable = VK_FALSE,
425  .logicOp = VK_LOGIC_OP_COPY,
426  .attachmentCount = 1,
427  .pAttachments = &color_blend_attachment,
428  .blendConstants = { 0.0f, 0.0f, 0.0f, 0.0f },
429  };
430 
431  VkGraphicsPipelineCreateInfo pipeline_info = {
432  .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
433  .stageCount = LENGTH(shader_info),
434  .pStages = shader_info,
435 
436  .pVertexInputState = &vertex_input_info,
437  .pInputAssemblyState = &input_assembly_info,
438  .pViewportState = &viewport_state,
439  .pRasterizationState = &rasterizer_state,
440  .pMultisampleState = &multisample_state,
441  .pDepthStencilState = NULL,
442  .pColorBlendState = &color_blend_state,
443  .pDynamicState = NULL,
444 
445  .layout = pipeline_layout_stretch_pic,
446  .renderPass = render_pass_stretch_pic,
447  .subpass = 0,
448 
449  .basePipelineHandle = VK_NULL_HANDLE,
450  .basePipelineIndex = -1,
451  };
452 
453  _VK(vkCreateGraphicsPipelines(qvk.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline_stretch_pic));
455 
456 
457  VkPipelineShaderStageCreateInfo shader_info_final_blit[] = {
458  SHADER_STAGE(QVK_MOD_FINAL_BLIT_VERT, VK_SHADER_STAGE_VERTEX_BIT),
459  SHADER_STAGE(QVK_MOD_FINAL_BLIT_LANCZOS_FRAG, VK_SHADER_STAGE_FRAGMENT_BIT)
460  };
461 
462  pipeline_info.pStages = shader_info_final_blit;
463  pipeline_info.layout = pipeline_layout_final_blit;
464 
465  _VK(vkCreateGraphicsPipelines(qvk.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline_final_blit));
467 
468 
469  for(int i = 0; i < qvk.num_swap_chain_images; i++) {
470  VkImageView attachments[] = {
472  };
473 
474  VkFramebufferCreateInfo fb_create_info = {
475  .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
476  .renderPass = render_pass_stretch_pic,
477  .attachmentCount = 1,
478  .pAttachments = attachments,
479  .width = vkpt_draw_get_extent().width,
480  .height = vkpt_draw_get_extent().height,
481  .layers = 1,
482  };
483 
484  _VK(vkCreateFramebuffer(qvk.device, &fb_create_info, NULL, framebuffer_stretch_pic + i));
486  }
487 
488  return VK_SUCCESS;
489 }

◆ vkpt_draw_destroy()

VkResult vkpt_draw_destroy ( )

Definition at line 295 of file draw.c.

296 {
297  LOG_FUNC();
298  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
300  }
301  vkDestroyRenderPass(qvk.device, render_pass_stretch_pic, NULL);
302  vkDestroyDescriptorPool(qvk.device, desc_pool_sbo, NULL);
303  vkDestroyDescriptorSetLayout(qvk.device, desc_set_layout_sbo, NULL);
304 
305  return VK_SUCCESS;
306 }

◆ vkpt_draw_destroy_pipelines()

VkResult vkpt_draw_destroy_pipelines ( )

Definition at line 309 of file draw.c.

310 {
311  LOG_FUNC();
312  vkDestroyPipeline(qvk.device, pipeline_stretch_pic, NULL);
313  vkDestroyPipeline(qvk.device, pipeline_final_blit, NULL);
314  vkDestroyPipelineLayout(qvk.device, pipeline_layout_stretch_pic, NULL);
315  vkDestroyPipelineLayout(qvk.device, pipeline_layout_final_blit, NULL);
316  for(int i = 0; i < qvk.num_swap_chain_images; i++) {
317  vkDestroyFramebuffer(qvk.device, framebuffer_stretch_pic[i], NULL);
318  }
319  return VK_SUCCESS;
320 }

◆ vkpt_draw_get_extent()

VkExtent2D vkpt_draw_get_extent ( )

Definition at line 62 of file draw.c.

63 {
64  return qvk.extent_unscaled;
65 }

Referenced by vkpt_draw_create_pipelines(), vkpt_draw_submit_stretch_pics(), and vkpt_final_blit_filtered().

◆ vkpt_draw_initialize()

VkResult vkpt_draw_initialize ( )

Definition at line 217 of file draw.c.

218 {
219  num_stretch_pics = 0;
220  LOG_FUNC();
222  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
224  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
225  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
226  }
227 
228  VkDescriptorSetLayoutBinding layout_bindings[] = {
229  {
230  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
231  .descriptorCount = 1,
232  .binding = 0,
233  .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
234  },
235  };
236 
237  VkDescriptorSetLayoutCreateInfo layout_info = {
238  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
239  .bindingCount = LENGTH(layout_bindings),
240  .pBindings = layout_bindings,
241  };
242 
243  _VK(vkCreateDescriptorSetLayout(qvk.device, &layout_info, NULL, &desc_set_layout_sbo));
244  ATTACH_LABEL_VARIABLE(desc_set_layout_sbo, DESCRIPTOR_SET_LAYOUT);
245 
246  VkDescriptorPoolSize pool_size = {
247  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
248  .descriptorCount = MAX_FRAMES_IN_FLIGHT,
249  };
250 
251  VkDescriptorPoolCreateInfo pool_info = {
252  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
253  .poolSizeCount = 1,
254  .pPoolSizes = &pool_size,
255  .maxSets = MAX_FRAMES_IN_FLIGHT,
256  };
257 
258  _VK(vkCreateDescriptorPool(qvk.device, &pool_info, NULL, &desc_pool_sbo));
259  ATTACH_LABEL_VARIABLE(desc_pool_sbo, DESCRIPTOR_POOL);
260 
261 
262  VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
263  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
264  .descriptorPool = desc_pool_sbo,
265  .descriptorSetCount = 1,
266  .pSetLayouts = &desc_set_layout_sbo,
267  };
268 
269  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
270  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, desc_set_sbo + i));
272 
273  VkDescriptorBufferInfo buf_info = {
274  .buffer = sbo->buffer,
275  .offset = 0,
276  .range = sizeof(stretch_pic_queue),
277  };
278 
279  VkWriteDescriptorSet output_buf_write = {
280  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
281  .dstSet = desc_set_sbo[i],
282  .dstBinding = 0,
283  .dstArrayElement = 0,
284  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
285  .descriptorCount = 1,
286  .pBufferInfo = &buf_info,
287  };
288 
289  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
290  }
291  return VK_SUCCESS;
292 }

◆ vkpt_draw_submit_stretch_pics()

VkResult vkpt_draw_submit_stretch_pics ( VkCommandBuffer  cmd_buf)

Definition at line 499 of file draw.c.

500 {
501  if (num_stretch_pics == 0)
502  return VK_SUCCESS;
503 
505  StretchPic_t *spq_dev = (StretchPic_t *) buffer_map(buf_spq);
506  memcpy(spq_dev, stretch_pic_queue, sizeof(StretchPic_t) * num_stretch_pics);
507  buffer_unmap(buf_spq);
508  spq_dev = NULL;
509 
510  VkRenderPassBeginInfo render_pass_info = {
511  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
512  .renderPass = render_pass_stretch_pic,
514  .renderArea.offset = { 0, 0 },
515  .renderArea.extent = vkpt_draw_get_extent()
516  };
517 
518  VkDescriptorSet desc_sets[] = {
521  };
522 
523  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
524  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,
525  pipeline_layout_stretch_pic, 0, LENGTH(desc_sets), desc_sets, 0, 0);
526  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_stretch_pic);
527  vkCmdDraw(cmd_buf, 4, num_stretch_pics, 0, 0);
528  vkCmdEndRenderPass(cmd_buf);
529 
530  num_stretch_pics = 0;
531  return VK_SUCCESS;
532 }

Referenced by R_EndFrame_RTX().

◆ vkpt_final_blit_filtered()

VkResult vkpt_final_blit_filtered ( VkCommandBuffer  cmd_buf)

Definition at line 604 of file draw.c.

605 {
606  VkRenderPassBeginInfo render_pass_info = {
607  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
608  .renderPass = render_pass_stretch_pic,
610  .renderArea.offset = { 0, 0 },
611  .renderArea.extent = vkpt_draw_get_extent()
612  };
613 
614  VkDescriptorSet desc_sets[] = {
617  };
618 
619  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
620  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,
621  pipeline_layout_final_blit, 0, LENGTH(desc_sets), desc_sets, 0, 0);
622  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_final_blit);
623  vkCmdDraw(cmd_buf, 4, 1, 0, 0);
624  vkCmdEndRenderPass(cmd_buf);
625 
626  return VK_SUCCESS;
627 }

Referenced by R_EndFrame_RTX().

◆ vkpt_final_blit_simple()

VkResult vkpt_final_blit_simple ( VkCommandBuffer  cmd_buf)

Definition at line 535 of file draw.c.

536 {
537  VkImageSubresourceRange subresource_range = {
538  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
539  .baseMipLevel = 0,
540  .levelCount = 1,
541  .baseArrayLayer = 0,
542  .layerCount = 1
543  };
544 
545  IMAGE_BARRIER(cmd_buf,
547  .subresourceRange = subresource_range,
548  .srcAccessMask = 0,
549  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
550  .oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
551  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
552  );
553 
554  int output_img = VKPT_IMG_TAA_OUTPUT;
555 
556  IMAGE_BARRIER(cmd_buf,
557  .image = qvk.images[output_img],
558  .subresourceRange = subresource_range,
559  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
560  .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
561  .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
562  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
563  );
564 
565  VkOffset3D blit_size = {
566  .x = qvk.extent_render.width,.y = qvk.extent_render.height,.z = 1
567  };
568  VkOffset3D blit_size_unscaled = {
569  .x = qvk.extent_unscaled.width,.y = qvk.extent_unscaled.height,.z = 1
570  };
571  VkImageBlit img_blit = {
572  .srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
573  .dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
574  .srcOffsets = { [1] = blit_size },
575  .dstOffsets = { [1] = blit_size_unscaled },
576  };
577  vkCmdBlitImage(cmd_buf,
578  qvk.images[output_img], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
579  qvk.swap_chain_images[qvk.current_swap_chain_image_index], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
580  1, &img_blit, VK_FILTER_NEAREST);
581 
582  IMAGE_BARRIER(cmd_buf,
584  .subresourceRange = subresource_range,
585  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
586  .dstAccessMask = 0,
587  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
588  .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
589  );
590 
591  IMAGE_BARRIER(cmd_buf,
592  .image = qvk.images[output_img],
593  .subresourceRange = subresource_range,
594  .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
595  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
596  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
597  .newLayout = VK_IMAGE_LAYOUT_GENERAL
598  );
599 
600  return VK_SUCCESS;
601 }

Referenced by R_EndFrame_RTX().

Variable Documentation

◆ buf_stretch_pic_queue

BufferResource_t buf_stretch_pic_queue[MAX_FRAMES_IN_FLIGHT]
static

Definition at line 56 of file draw.c.

Referenced by vkpt_draw_destroy(), vkpt_draw_initialize(), and vkpt_draw_submit_stretch_pics().

◆ clip_enable

qboolean clip_enable = qfalse
static

Definition at line 46 of file draw.c.

Referenced by enqueue_stretch_pic(), and R_SetClipRect_RTX().

◆ clip_rect

clipRect_t clip_rect
static

Definition at line 45 of file draw.c.

Referenced by enqueue_stretch_pic(), and R_SetClipRect_RTX().

◆ desc_pool_sbo

VkDescriptorPool desc_pool_sbo
static

Definition at line 58 of file draw.c.

Referenced by vkpt_draw_destroy(), and vkpt_draw_initialize().

◆ desc_set_layout_sbo

VkDescriptorSetLayout desc_set_layout_sbo
static

Definition at line 57 of file draw.c.

Referenced by vkpt_draw_create_pipelines(), vkpt_draw_destroy(), and vkpt_draw_initialize().

◆ desc_set_sbo

VkDescriptorSet desc_set_sbo[MAX_FRAMES_IN_FLIGHT]
static

Definition at line 59 of file draw.c.

Referenced by vkpt_draw_initialize(), and vkpt_draw_submit_stretch_pics().

◆ draw

Initial value:
= {
.scale = 1.0f,
.alpha_scale = 1.0f
}

Definition at line 33 of file draw.c.

◆ framebuffer_stretch_pic

VkFramebuffer framebuffer_stretch_pic[MAX_FRAMES_IN_FLIGHT]
static

◆ num_stretch_pics

int num_stretch_pics = 0
static

◆ pipeline_final_blit

VkPipeline pipeline_final_blit
static

◆ pipeline_layout_final_blit

VkPipelineLayout pipeline_layout_final_blit
static

◆ pipeline_layout_stretch_pic

VkPipelineLayout pipeline_layout_stretch_pic
static

◆ pipeline_stretch_pic

VkPipeline pipeline_stretch_pic
static

◆ render_pass_stretch_pic

VkRenderPass render_pass_stretch_pic
static

◆ stretch_pic_queue

StretchPic_t stretch_pic_queue[MAX_STRETCH_PICS]
static

Definition at line 48 of file draw.c.

Referenced by enqueue_stretch_pic(), vkpt_draw_initialize(), and vkpt_draw_submit_stretch_pics().

QVK_s::desc_set_ubo
VkDescriptorSet desc_set_ubo
Definition: vkpt.h:226
drawStatic_t::alpha_scale
float alpha_scale
Definition: vkpt.h:716
CREATE_PIPELINE_LAYOUT
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
Definition: vk_util.h:82
LOG_FUNC
#define LOG_FUNC()
Definition: vkpt.h:54
QVK_s::num_swap_chain_images
uint32_t num_swap_chain_images
Definition: vkpt.h:189
MAX_FRAMES_IN_FLIGHT
#define MAX_FRAMES_IN_FLIGHT
Definition: vkpt.h:140
height
static int height
Definition: physical_sky.c:39
StretchPic_t::y
float y
Definition: draw.c:40
image_t
struct image_s image_t
Definition: material.h:27
render_pass_stretch_pic
static VkRenderPass render_pass_stretch_pic
Definition: draw.c:52
QVK_s::device
VkDevice device
Definition: vkpt.h:172
StretchPic_t::x
float x
Definition: draw.c:40
clip_rect
static clipRect_t clip_rect
Definition: draw.c:45
buffer_unmap
void buffer_unmap(BufferResource_t *buf)
Definition: vk_util.c:159
QVK_s::current_frame_index
uint32_t current_frame_index
Definition: vkpt.h:219
drawStatic_t::colors
color_t colors[2]
Definition: gl.h:402
MAX_STRETCH_PICS
#define MAX_STRETCH_PICS
Definition: draw.c:31
d_8to24table
uint32_t d_8to24table[256]
Definition: images.c:654
R_DrawStretchPic
void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic)
Definition: draw.c:384
buffer_destroy
VkResult buffer_destroy(BufferResource_t *buf)
Definition: vk_util.c:132
StretchPic_t::h_t
float h_t
Definition: draw.c:41
pipeline_final_blit
static VkPipeline pipeline_final_blit
Definition: draw.c:54
vkpt_draw_get_extent
VkExtent2D vkpt_draw_get_extent()
Definition: draw.c:62
StretchPic_t::w
float w
Definition: draw.c:40
StretchPic_t
Definition: draw.c:39
enqueue_stretch_pic
static void enqueue_stretch_pic(float x, float y, float w, float h, float s1, float t1, float s2, float t2, uint32_t color, int tex_handle)
Definition: draw.c:67
create_render_pass
static void create_render_pass()
Definition: draw.c:163
draw
drawStatic_t draw
Definition: draw.c:21
StretchPic_t::s
float s
Definition: draw.c:41
pipeline_layout_final_blit
static VkPipelineLayout pipeline_layout_final_blit
Definition: draw.c:51
width
static int width
Definition: physical_sky.c:38
_VK
#define _VK(...)
Definition: vkpt.h:65
pipeline_layout_stretch_pic
static VkPipelineLayout pipeline_layout_stretch_pic
Definition: draw.c:50
pipeline_stretch_pic
static VkPipeline pipeline_stretch_pic
Definition: draw.c:53
draw_char
static void draw_char(int x, int y, int flags, int c, qhandle_t font)
Definition: draw.c:726
QVK_s::current_swap_chain_image_index
uint32_t current_swap_chain_image_index
Definition: vkpt.h:218
stretch_pic_queue
static StretchPic_t stretch_pic_queue[MAX_STRETCH_PICS]
Definition: draw.c:48
num_stretch_pics
static int num_stretch_pics
Definition: draw.c:38
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
buf_stretch_pic_queue
static BufferResource_t buf_stretch_pic_queue[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:56
QVK_s::swap_chain_images
VkImage swap_chain_images[MAX_SWAPCHAIN_IMAGES]
Definition: vkpt.h:190
r_images
image_t r_images[MAX_RIMAGES]
Definition: images.c:651
QVK_s::images
VkImage images[NUM_VKPT_IMAGES]
Definition: vkpt.h:231
StretchPic_t::t
float t
Definition: draw.c:41
framebuffer_stretch_pic
static VkFramebuffer framebuffer_stretch_pic[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:55
LENGTH
#define LENGTH(a)
Definition: tent.c:228
StretchPic_t::tex_handle
uint32_t tex_handle
Definition: draw.c:42
StretchPic_t::w_s
float w_s
Definition: draw.c:41
qvk
QVK_t qvk
Definition: main.c:377
c
statCounters_t c
Definition: main.c:30
registration_sequence
int registration_sequence
Definition: main.c:34
SHADER_STAGE
#define SHADER_STAGE(_module, _stage)
Definition: vkpt.h:116
QVK_s::extent_render
VkExtent2D extent_render
Definition: vkpt.h:184
BufferResource_s
Definition: vk_util.h:33
QVK_s::extent_unscaled
VkExtent2D extent_unscaled
Definition: vkpt.h:186
buffer_create
VkResult buffer_create(BufferResource_t *buf, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags mem_properties)
Definition: vk_util.c:57
TEXNUM_WHITE
#define TEXNUM_WHITE
Definition: draw.c:30
desc_set_layout_sbo
static VkDescriptorSetLayout desc_set_layout_sbo
Definition: draw.c:57
IMAGE_BARRIER
#define IMAGE_BARRIER(cmd_buf,...)
Definition: vk_util.h:55
color
static vec4_t color
Definition: mesh.c:33
IMG_ForHandle
image_t * IMG_ForHandle(qhandle_t h)
Definition: images.c:1156
ATTACH_LABEL_VARIABLE
#define ATTACH_LABEL_VARIABLE(a, type)
Definition: vk_util.h:137
StretchPic_t::color
uint32_t color
Definition: draw.c:42
drawStatic_t::scale
float scale
Definition: gl.h:404
QVK_s::desc_set_layout_textures
VkDescriptorSetLayout desc_set_layout_textures
Definition: vkpt.h:228
QVK_s::desc_set_layout_ubo
VkDescriptorSetLayout desc_set_layout_ubo
Definition: vkpt.h:225
buffer_map
void * buffer_map(BufferResource_t *buf)
Definition: vk_util.c:147
QVK_s::surf_format
VkSurfaceFormatKHR surf_format
Definition: vkpt.h:181
QVK_s::swap_chain_image_views
VkImageView swap_chain_image_views[MAX_SWAPCHAIN_IMAGES]
Definition: vkpt.h:191
StretchPic_t::h
float h
Definition: draw.c:40
desc_pool_sbo
static VkDescriptorPool desc_pool_sbo
Definition: draw.c:58
DIV64
#define DIV64
Definition: draw.c:697
qvk_get_current_desc_set_textures
VkDescriptorSet qvk_get_current_desc_set_textures()
Definition: main.c:1847
clip_enable
static qboolean clip_enable
Definition: draw.c:46
r_config
refcfg_t r_config
Definition: refresh.c:401
desc_set_sbo
static VkDescriptorSet desc_set_sbo[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:59