Quake II RTX doxygen  1.0 dev
draw.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2018 Christoph Schied
3 Copyright (C) 2019, NVIDIA CORPORATION. All rights reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include "shared/shared.h"
21 #include "refresh/refresh.h"
22 #include "client/client.h"
23 #include "refresh/images.h"
24 
25 #include <assert.h>
26 
27 #include "vkpt.h"
28 #include "shader/global_textures.h"
29 
30 #define TEXNUM_WHITE (~0)
31 #define MAX_STRETCH_PICS (1<<14)
32 
34  .scale = 1.0f,
35  .alpha_scale = 1.0f
36 };
37 
38 static int num_stretch_pics = 0;
39 typedef struct {
40  float x, y, w, h;
41  float s, t, w_s, h_t;
42  uint32_t color, tex_handle;
43 } StretchPic_t;
44 
45 static clipRect_t clip_rect;
46 static qboolean clip_enable = qfalse;
47 
49 
50 static VkPipelineLayout pipeline_layout_stretch_pic;
51 static VkPipelineLayout pipeline_layout_final_blit;
52 static VkRenderPass render_pass_stretch_pic;
53 static VkPipeline pipeline_stretch_pic;
54 static VkPipeline pipeline_final_blit;
57 static VkDescriptorSetLayout desc_set_layout_sbo;
58 static VkDescriptorPool desc_pool_sbo;
59 static VkDescriptorSet desc_set_sbo[MAX_FRAMES_IN_FLIGHT];
60 
61 VkExtent2D
63 {
64  return qvk.extent_unscaled;
65 }
66 
67 static inline void enqueue_stretch_pic(
68  float x, float y, float w, float h,
69  float s1, float t1, float s2, float t2,
70  uint32_t color, int tex_handle)
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 }
161 
162 static void
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 }
215 
216 VkResult
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 }
293 
294 VkResult
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 }
307 
308 VkResult
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 }
321 
322 VkResult
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 }
490 
491 VkResult
493 {
494  num_stretch_pics = 0;
495  return VK_SUCCESS;
496 }
497 
498 VkResult
499 vkpt_draw_submit_stretch_pics(VkCommandBuffer cmd_buf)
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 }
533 
534 VkResult
535 vkpt_final_blit_simple(VkCommandBuffer cmd_buf)
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 }
602 
603 VkResult
604 vkpt_final_blit_filtered(VkCommandBuffer cmd_buf)
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 }
628 
629 void R_SetClipRect_RTX(const clipRect_t *clip)
630 {
631  if (clip)
632  {
633  clip_enable = qtrue;
634  clip_rect = *clip;
635  }
636  else
637  {
638  clip_enable = qfalse;
639  }
640 }
641 
642 void
644 {
645  draw.colors[0].u32 = U32_WHITE;
646  draw.colors[1].u32 = U32_WHITE;
647 }
648 
649 void
650 R_SetAlpha_RTX(float alpha)
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 }
655 
656 void
658 {
659  draw.alpha_scale = alpha;
660 }
661 
662 void
664 {
665  draw.colors[0].u32 = color;
666  draw.colors[1].u8[3] = draw.colors[0].u8[3];
667 }
668 
669 void
670 R_LightPoint_RTX(vec3_t origin, vec3_t light)
671 {
672  VectorSet(light, 1, 1, 1);
673 }
674 
675 void
676 R_SetScale_RTX(float scale)
677 {
678  draw.scale = scale;
679 }
680 
681 void
682 R_DrawStretchPic_RTX(int x, int y, int w, int h, qhandle_t pic)
683 {
685  x, y, w, h,
686  0.0f, 0.0f, 1.0f, 1.0f,
687  draw.colors[0].u32, pic);
688 }
689 
690 void
691 R_DrawPic_RTX(int x, int y, qhandle_t pic)
692 {
693  image_t *image = IMG_ForHandle(pic);
694  R_DrawStretchPic(x, y, image->width, image->height, pic);
695 }
696 
697 #define DIV64 (1.0f / 64.0f)
698 
699 void
700 R_TileClear_RTX(int x, int y, int w, int h, qhandle_t pic)
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 }
706 
707 void
708 R_DrawFill8_RTX(int x, int y, int w, int h, int 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 }
715 
716 void
717 R_DrawFill32_RTX(int x, int y, int w, int h, uint32_t color)
718 {
719  if(!w || !h)
720  return;
721  enqueue_stretch_pic(x, y, w, h, 0.0f, 0.0f, 1.0f, 1.0f,
723 }
724 
725 static inline void
726 draw_char(int x, int y, int flags, int c, qhandle_t font)
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 }
748 
749 void
750 R_DrawChar_RTX(int x, int y, int flags, int c, qhandle_t font)
751 {
752  draw_char(x, y, flags, c & 255, font);
753 }
754 
755 int
756 R_DrawString_RTX(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font)
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 }
766 
767 // vim: shiftwidth=4 noexpandtab tabstop=4 cindent
QVK_s::desc_set_ubo
VkDescriptorSet desc_set_ubo
Definition: vkpt.h:226
R_LightPoint_RTX
void R_LightPoint_RTX(vec3_t origin, vec3_t light)
Definition: draw.c:670
drawStatic_t::alpha_scale
float alpha_scale
Definition: vkpt.h:716
vkpt_draw_destroy
VkResult vkpt_draw_destroy()
Definition: draw.c:295
R_SetClipRect_RTX
void R_SetClipRect_RTX(const clipRect_t *clip)
Definition: draw.c:629
CREATE_PIPELINE_LAYOUT
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
Definition: vk_util.h:82
LOG_FUNC
#define LOG_FUNC()
Definition: vkpt.h:54
vkpt_draw_destroy_pipelines
VkResult vkpt_draw_destroy_pipelines()
Definition: draw.c:309
vkpt_final_blit_filtered
VkResult vkpt_final_blit_filtered(VkCommandBuffer cmd_buf)
Definition: draw.c:604
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
vkpt_final_blit_simple
VkResult vkpt_final_blit_simple(VkCommandBuffer cmd_buf)
Definition: draw.c:535
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
R_SetColor_RTX
void R_SetColor_RTX(uint32_t color)
Definition: draw.c:663
R_DrawFill8_RTX
void R_DrawFill8_RTX(int x, int y, int w, int h, int c)
Definition: draw.c:708
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
vkpt.h
drawStatic_t::colors
color_t colors[2]
Definition: gl.h:402
global_textures.h
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
vkpt_draw_submit_stretch_pics
VkResult vkpt_draw_submit_stretch_pics(VkCommandBuffer cmd_buf)
Definition: draw.c:499
buffer_destroy
VkResult buffer_destroy(BufferResource_t *buf)
Definition: vk_util.c:132
R_SetAlpha_RTX
void R_SetAlpha_RTX(float alpha)
Definition: draw.c:650
R_DrawString_RTX
int R_DrawString_RTX(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font)
Definition: draw.c:756
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
R_SetScale_RTX
void R_SetScale_RTX(float scale)
Definition: draw.c:676
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
R_TileClear_RTX
void R_TileClear_RTX(int x, int y, int w, int h, qhandle_t pic)
Definition: draw.c:700
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
vkpt_draw_create_pipelines
VkResult vkpt_draw_create_pipelines()
Definition: draw.c:323
origin
static vec3_t origin
Definition: mesh.c:27
R_DrawStretchPic_RTX
void R_DrawStretchPic_RTX(int x, int y, int w, int h, qhandle_t pic)
Definition: draw.c:682
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
vkpt_draw_initialize
VkResult vkpt_draw_initialize()
Definition: draw.c:217
drawStatic_t
Definition: gl.h:401
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
R_DrawPic_RTX
void R_DrawPic_RTX(int x, int y, qhandle_t pic)
Definition: draw.c:691
client.h
R_DrawFill32_RTX
void R_DrawFill32_RTX(int x, int y, int w, int h, uint32_t color)
Definition: draw.c:717
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
R_ClearColor_RTX
void R_ClearColor_RTX(void)
Definition: draw.c:643
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
R_DrawChar_RTX
void R_DrawChar_RTX(int x, int y, int flags, int c, qhandle_t font)
Definition: draw.c:750
QVK_s::surf_format
VkSurfaceFormatKHR surf_format
Definition: vkpt.h:181
vkpt_draw_clear_stretch_pics
VkResult vkpt_draw_clear_stretch_pics()
Definition: draw.c:492
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
R_SetAlphaScale_RTX
void R_SetAlphaScale_RTX(float alpha)
Definition: draw.c:657