20 #include "system/system.h"
60 float effective_sigma = sigma_pixels * 0.25f;
61 effective_sigma = min(effective_sigma, 100.f);
62 effective_sigma = max(effective_sigma, 1.f);
83 static float mix(
float a,
float b,
float s)
85 return a * (1.f - s) + b * s;
103 static int menu_start_ms = -1;
107 if (menu_start_ms < 0)
111 float phase = max(0.f, min(1.f, (
float)(current_ms - menu_start_ms) / 150.f));
112 phase = powf(phase, 0.25f);
116 ubo->bloom_intensity = 1.f;
136 VkDescriptorSetLayout desc_set_layouts[] = {
141 VkPushConstantRange push_constant_range = {
142 .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
148 .setLayoutCount =
LENGTH(desc_set_layouts),
149 .pSetLayouts = desc_set_layouts,
150 .pushConstantRangeCount = 1,
151 .pPushConstantRanges = &push_constant_range
156 .setLayoutCount =
LENGTH(desc_set_layouts),
157 .pSetLayouts = desc_set_layouts,
180 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
181 .stage =
SHADER_STAGE(QVK_MOD_BLOOM_BLUR_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
185 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
186 .stage =
SHADER_STAGE(QVK_MOD_BLOOM_COMPOSITE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
205 #define BARRIER_COMPUTE(cmd_buf, img) \
207 VkImageSubresourceRange subresource_range = { \
208 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
211 .baseArrayLayer = 0, \
214 IMAGE_BARRIER(cmd_buf, \
216 .subresourceRange = subresource_range, \
217 .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, \
218 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, \
219 .oldLayout = VK_IMAGE_LAYOUT_GENERAL, \
220 .newLayout = VK_IMAGE_LAYOUT_GENERAL, \
224 #define BARRIER_TO_COPY_DEST(cmd_buf, img) \
226 VkImageSubresourceRange subresource_range = { \
227 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
230 .baseArrayLayer = 0, \
233 IMAGE_BARRIER(cmd_buf, \
235 .subresourceRange = subresource_range, \
236 .srcAccessMask = 0, \
237 .dstAccessMask = 0, \
238 .oldLayout = VK_IMAGE_LAYOUT_GENERAL, \
239 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, \
243 #define BARRIER_FROM_COPY_DEST(cmd_buf, img) \
245 VkImageSubresourceRange subresource_range = { \
246 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
249 .baseArrayLayer = 0, \
252 IMAGE_BARRIER(cmd_buf, \
254 .subresourceRange = subresource_range, \
255 .srcAccessMask = 0, \
256 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, \
257 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, \
258 .newLayout = VK_IMAGE_LAYOUT_GENERAL, \
262 #define BARRIER_TO_COPY_SRC(cmd_buf, img) \
264 VkImageSubresourceRange subresource_range = { \
265 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
268 .baseArrayLayer = 0, \
271 IMAGE_BARRIER(cmd_buf, \
273 .subresourceRange = subresource_range, \
274 .srcAccessMask = 0, \
275 .dstAccessMask = 0, \
276 .oldLayout = VK_IMAGE_LAYOUT_GENERAL, \
277 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, \
281 #define BARRIER_FROM_COPY_SRC(cmd_buf, img) \
283 VkImageSubresourceRange subresource_range = { \
284 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
287 .baseArrayLayer = 0, \
290 IMAGE_BARRIER(cmd_buf, \
292 .subresourceRange = subresource_range, \
293 .srcAccessMask = 0, \
294 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, \
295 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, \
296 .newLayout = VK_IMAGE_LAYOUT_GENERAL, \
309 VkImageSubresourceLayers subresource = {
310 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
316 VkOffset3D offset_UL = {
322 VkOffset3D offset_LR_mip_0 = {
328 VkOffset3D offset_LR_mip_1 = {
334 VkOffset3D offset_LR_mip_2 = {
340 VkImageBlit blit_mip_0_to_1 = {
341 .srcSubresource = subresource,
342 .srcOffsets[0] = offset_UL,
343 .srcOffsets[1] = offset_LR_mip_0,
344 .dstSubresource = subresource,
345 .dstOffsets[0] = offset_UL,
346 .dstOffsets[1] = offset_LR_mip_1,
349 VkImageBlit blit_mip_1_to_2 = {
350 .srcSubresource = subresource,
351 .srcOffsets[0] = offset_UL,
352 .srcOffsets[1] = offset_LR_mip_1,
353 .dstSubresource = subresource,
354 .dstOffsets[0] = offset_UL,
355 .dstOffsets[1] = offset_LR_mip_2,
361 vkCmdBlitImage(cmd_buf,
362 qvk.
images[VKPT_IMG_TAA_OUTPUT], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
363 qvk.
images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
364 1, &blit_mip_0_to_1, VK_FILTER_LINEAR);
372 vkCmdBlitImage(cmd_buf,
373 qvk.
images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
374 qvk.
images[VKPT_IMG_BLOOM_VBLUR], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
375 1, &blit_mip_1_to_2, VK_FILTER_LINEAR);
381 VkDescriptorSet desc_sets[] = {
391 vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
pipelines[
BLUR]);
392 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
397 vkCmdDispatch(cmd_buf,
407 vkCmdDispatch(cmd_buf,
416 VkImageSubresourceLayers subresource = {
417 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
423 VkOffset3D offset_UL = {
429 VkOffset3D offset_LR_input = {
435 VkImageBlit blit_region = {
436 .srcSubresource = subresource,
437 .srcOffsets[0] = offset_UL,
438 .dstSubresource = subresource,
439 .dstOffsets[0] = offset_UL,
440 .dstOffsets[1] = offset_LR_input,
449 vis_img = VKPT_IMG_BLOOM_DOWNSCALE_MIP_1;
450 blit_region.srcOffsets[1].x =
IMG_WIDTH / 2;
455 vis_img = VKPT_IMG_BLOOM_HBLUR;
456 blit_region.srcOffsets[1].x =
IMG_WIDTH / 4;
461 vis_img = VKPT_IMG_BLOOM_VBLUR;
462 blit_region.srcOffsets[1].x =
IMG_WIDTH / 4;
467 vkCmdBlitImage(cmd_buf,
468 qvk.
images[vis_img], VK_IMAGE_LAYOUT_GENERAL,
469 qvk.
images[VKPT_IMG_TAA_OUTPUT], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
470 1, &blit_region, VK_FILTER_LINEAR);
476 vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
478 vkCmdDispatch(cmd_buf,