20 #include "shared/shared.h"
21 #include "refresh/refresh.h"
23 #include "refresh/images.h"
30 #define TEXNUM_WHITE (~0)
31 #define MAX_STRETCH_PICS (1<<14)
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)
76 Com_EPrintf(
"Error: stretch pic queue full!\n");
91 s1 += dw / w * (s2 - s1);
101 s2 -= dw / w * (s2 - s1);
110 t1 += dh / h * (t2 - t1);
120 t2 -= dh / h * (t2 - t1);
130 x = 2.0f * x /
width - 1.0f;
131 y = 2.0f * y /
height - 1.0f;
133 w = 2.0f * w /
width;
148 float alpha = (
color >> 24) & 0xff;
150 alpha = max(0.f, min(255.f, alpha));
151 color = (
color & 0xffffff) | ((
int)(alpha) << 24);
156 if(tex_handle >= 0 && tex_handle < MAX_RIMAGES
166 VkAttachmentDescription color_attachment = {
168 .samples = VK_SAMPLE_COUNT_1_BIT,
169 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
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,
179 VkAttachmentReference color_attachment_ref = {
181 .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
184 VkSubpassDescription subpass = {
185 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
186 .colorAttachmentCount = 1,
187 .pColorAttachments = &color_attachment_ref,
190 VkSubpassDependency dependencies[] = {
192 .srcSubpass = VK_SUBPASS_EXTERNAL,
194 .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
196 .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
197 .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
198 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
202 VkRenderPassCreateInfo render_pass_info = {
203 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
204 .attachmentCount = 1,
205 .pAttachments = &color_attachment,
207 .pSubpasses = &subpass,
208 .dependencyCount =
LENGTH(dependencies),
209 .pDependencies = dependencies,
224 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
225 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
228 VkDescriptorSetLayoutBinding layout_bindings[] = {
230 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
231 .descriptorCount = 1,
233 .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
237 VkDescriptorSetLayoutCreateInfo layout_info = {
238 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
239 .bindingCount =
LENGTH(layout_bindings),
240 .pBindings = layout_bindings,
246 VkDescriptorPoolSize pool_size = {
247 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
251 VkDescriptorPoolCreateInfo pool_info = {
252 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
254 .pPoolSizes = &pool_size,
262 VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
263 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
265 .descriptorSetCount = 1,
273 VkDescriptorBufferInfo buf_info = {
279 VkWriteDescriptorSet output_buf_write = {
280 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
283 .dstArrayElement = 0,
284 .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
285 .descriptorCount = 1,
286 .pBufferInfo = &buf_info,
289 vkUpdateDescriptorSets(
qvk.
device, 1, &output_buf_write, 0, NULL);
328 VkDescriptorSetLayout desc_set_layouts[] = {
332 .setLayoutCount =
LENGTH(desc_set_layouts),
333 .pSetLayouts = desc_set_layouts
339 .setLayoutCount =
LENGTH(desc_set_layouts),
340 .pSetLayouts = desc_set_layouts
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)
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,
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,
362 VkViewport viewport = {
376 VkPipelineViewportStateCreateInfo viewport_state = {
377 .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
379 .pViewports = &viewport,
381 .pScissors = &scissor,
384 VkPipelineRasterizationStateCreateInfo rasterizer_state = {
385 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
386 .depthClampEnable = VK_FALSE,
387 .rasterizerDiscardEnable = VK_FALSE,
388 .polygonMode = VK_POLYGON_MODE_FILL,
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,
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,
404 .alphaToCoverageEnable = VK_FALSE,
405 .alphaToOneEnable = VK_FALSE,
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,
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 },
431 VkGraphicsPipelineCreateInfo pipeline_info = {
432 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
433 .stageCount =
LENGTH(shader_info),
434 .pStages = shader_info,
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,
449 .basePipelineHandle = VK_NULL_HANDLE,
450 .basePipelineIndex = -1,
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)
462 pipeline_info.pStages = shader_info_final_blit;
470 VkImageView attachments[] = {
474 VkFramebufferCreateInfo fb_create_info = {
475 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
477 .attachmentCount = 1,
478 .pAttachments = attachments,
510 VkRenderPassBeginInfo render_pass_info = {
511 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
514 .renderArea.offset = { 0, 0 },
518 VkDescriptorSet desc_sets[] = {
523 vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
524 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,
528 vkCmdEndRenderPass(cmd_buf);
537 VkImageSubresourceRange subresource_range = {
538 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
547 .subresourceRange = subresource_range,
549 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
550 .oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
551 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
554 int output_img = VKPT_IMG_TAA_OUTPUT;
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
565 VkOffset3D blit_size = {
568 VkOffset3D blit_size_unscaled = {
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 },
577 vkCmdBlitImage(cmd_buf,
578 qvk.
images[output_img], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
580 1, &img_blit, VK_FILTER_NEAREST);
584 .subresourceRange = subresource_range,
585 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
587 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
588 .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
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
606 VkRenderPassBeginInfo render_pass_info = {
607 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
610 .renderArea.offset = { 0, 0 },
614 VkDescriptorSet desc_sets[] = {
619 vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
620 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS,
623 vkCmdDraw(cmd_buf, 4, 1, 0, 0);
624 vkCmdEndRenderPass(cmd_buf);
652 alpha = powf(fabsf(alpha), 0.4545f);
672 VectorSet(light, 1, 1, 1);
686 0.0f, 0.0f, 1.0f, 1.0f,
697 #define DIV64 (1.0f / 64.0f)
728 if ((
c & 127) == 32) {
732 if (flags & UI_ALTCOLOR) {
735 if (flags & UI_XORCOLOR) {
739 float s = (
c & 15) * 0.0625f;
740 float t = (
c >> 4) * 0.0625f;
745 s + eps, t + eps, s + 0.0625f - eps, t + 0.0625f - eps,
758 while(maxlen-- && *s) {