Quake II RTX doxygen  1.0 dev
vkpt.h File Reference
#include <vulkan/vulkan.h>
#include <SDL.h>
#include <SDL_vulkan.h>
#include "vk_util.h"
#include "shared/shared.h"
#include "common/bsp.h"
#include "common/cmd.h"
#include "common/common.h"
#include "common/cvar.h"
#include "common/files.h"
#include "common/math.h"
#include "client/video.h"
#include "client/client.h"
#include "refresh/refresh.h"
#include "refresh/images.h"
#include "refresh/models.h"
#include "system/hunk.h"
#include "shader/global_ubo.h"
#include "shader/global_textures.h"
#include "shader/vertex_buffer.h"

Go to the source code of this file.

Classes

struct  cmd_buf_group_s
 
struct  semaphore_group_s
 
struct  QVK_s
 
struct  light_poly_s
 
struct  bsp_model_s
 
struct  aabb_s
 
struct  bsp_mesh_s
 
struct  vkpt_refdef_s
 
struct  sun_light_s
 
struct  EntityUploadInfo
 
struct  maliasframe_s
 
struct  maliasmesh_s
 
struct  drawStatic_t
 

Macros

#define HAVE_M_PI
 
#define LENGTH(a)   ((sizeof (a)) / (sizeof(*(a))))
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define LOG_FUNC_(f)   do {} while(0)
 
#define LOG_FUNC()   LOG_FUNC_(__func__)
 
#define _VK(...)   do { __VA_ARGS__; } while(0)
 
#define LIST_SHADER_MODULES
 
#define VKPT_SHADER_DIR   "shader_vkpt"
 
#define SHADER_PATH_TEMPLATE   VKPT_SHADER_DIR "/%s.spv"
 
#define SHADER_STAGE(_module, _stage)
 
#define SHADER_STAGE_SPEC(_module, _stage, _spec)
 
#define SHADER_MODULE_DO(a)   a,
 
#define MAX_FRAMES_IN_FLIGHT   2
 
#define MAX_SWAPCHAIN_IMAGES   4
 
#define _VK_INST_EXTENSION_LIST
 
#define _VK_INST_EXTENSION_DO(a)   extern PFN_##a q##a;
 
#define _VK_EXTENSION_LIST
 
#define _VK_EXTENSION_DO(a)   extern PFN_##a q##a;
 
#define MAX_SKY_CLUSTERS   1024
 
#define PROFILER_LIST
 
#define PROFILER_DO(a, ...)   a,
 
#define NUM_PROFILER_QUERIES_PER_FRAME   (NUM_PROFILER_ENTRIES * 2)
 
#define ALL_GPUS   (-1)
 
#define TESS_MAX_VERTICES   16384
 
#define TESS_MAX_INDICES   (3 * TESS_MAX_VERTICES)
 
#define QGL_INDEX_TYPE   GLuint
 
#define BEGIN_PERF_MARKER(command_buffer, name)   begin_perf_marker(command_buffer, name, #name)
 
#define END_PERF_MARKER(command_buffer, name)   end_perf_marker(command_buffer, name)
 

Typedefs

typedef struct cmd_buf_group_s cmd_buf_group_t
 
typedef struct semaphore_group_s semaphore_group_t
 
typedef struct QVK_s QVK_t
 
typedef struct light_poly_s light_poly_t
 
typedef struct bsp_model_s bsp_model_t
 
typedef struct aabb_s aabb_t
 
typedef struct bsp_mesh_s bsp_mesh_t
 
typedef struct vkpt_refdef_s vkpt_refdef_t
 
typedef struct sun_light_s sun_light_t
 
typedef struct EntityUploadInfo EntityUploadInfo
 
typedef struct maliasframe_s maliasframe_t
 
typedef struct maliasmesh_s maliasmesh_t
 

Enumerations

enum  QVK_SHADER_MODULES { NUM_QVK_SHADER_MODULES }
 
enum  { NUM_PROFILER_ENTRIES }
 
enum  VKPTProfilerAction { PROFILER_START, PROFILER_STOP }
 

Functions

void bsp_mesh_create_from_bsp (bsp_mesh_t *wm, bsp_t *bsp, const char *map_name)
 
void bsp_mesh_destroy (bsp_mesh_t *wm)
 
void bsp_mesh_register_textures (bsp_t *bsp)
 
void mult_matrix_matrix (float *p, const float *a, const float *b)
 
void mult_matrix_vector (float *p, const float *a, const float *b)
 
void create_entity_matrix (float matrix[16], entity_t *e, qboolean enable_left_hand)
 
void create_projection_matrix (float matrix[16], float znear, float zfar, float fov_x, float fov_y)
 
void create_view_matrix (float matrix[16], refdef_t *fd)
 
void inverse (const float *m, float *inv)
 
void create_orthographic_matrix (float matrix[16], float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
 
VkDescriptorSet qvk_get_current_desc_set_textures ()
 
VkResult vkpt_profiler_initialize ()
 
VkResult vkpt_profiler_destroy ()
 
VkResult vkpt_profiler_query (VkCommandBuffer cmd_buf, int idx, VKPTProfilerAction action)
 
VkResult vkpt_profiler_next_frame (VkCommandBuffer cmd_buf)
 
void draw_profiler (int enable_asvgf)
 
double vkpt_get_profiler_result (int idx)
 
VkResult vkpt_readback (struct ReadbackBuffer *dst)
 
VkResult vkpt_textures_initialize ()
 
VkResult vkpt_textures_destroy ()
 
VkResult vkpt_textures_end_registration ()
 
VkResult vkpt_textures_upload_envmap (int w, int h, byte *data)
 
void vkpt_textures_destroy_unused ()
 
void vkpt_textures_update_descriptor_set ()
 
void vkpt_normalize_normal_map (image_t *image)
 
void vkpt_extract_emissive_texture_info (image_t *image)
 
void vkpt_textures_prefetch ()
 
void vkpt_init_light_textures ()
 
VkCommandBuffer vkpt_begin_command_buffer (cmd_buf_group_t *group)
 
void vkpt_free_command_buffers (cmd_buf_group_t *group)
 
void vkpt_reset_command_buffers (cmd_buf_group_t *group)
 
void vkpt_wait_idle (VkQueue queue, cmd_buf_group_t *group)
 
void vkpt_submit_command_buffer (VkCommandBuffer cmd_buf, VkQueue queue, uint32_t execute_device_mask, int wait_semaphore_count, VkSemaphore *wait_semaphores, VkPipelineStageFlags *wait_stages, uint32_t *wait_device_indices, int signal_semaphore_count, VkSemaphore *signal_semaphores, uint32_t *signal_device_indices, VkFence fence)
 
void vkpt_submit_command_buffer_simple (VkCommandBuffer cmd_buf, VkQueue queue, qboolean all_gpus)
 
void set_current_gpu (VkCommandBuffer cmd_buf, int gpu_index)
 
VkResult allocate_gpu_memory (VkMemoryRequirements mem_req, VkDeviceMemory *pMemory)
 
void vkpt_image_copy (VkCommandBuffer cmd_buf, int src_image_index, int dst_image_index, VkOffset2D src_offset, VkOffset2D dst_offset, VkExtent2D size)
 
VkResult vkpt_draw_initialize ()
 
VkResult vkpt_draw_destroy ()
 
VkResult vkpt_draw_destroy_pipelines ()
 
VkResult vkpt_draw_create_pipelines ()
 
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)
 
VkResult vkpt_draw_clear_stretch_pics ()
 
VkResult vkpt_uniform_buffer_create ()
 
VkResult vkpt_uniform_buffer_destroy ()
 
VkResult vkpt_uniform_buffer_update (VkCommandBuffer command_buffer)
 
VkResult vkpt_vertex_buffer_create ()
 
VkResult vkpt_vertex_buffer_destroy ()
 
VkResult vkpt_vertex_buffer_upload_bsp_mesh_to_staging (bsp_mesh_t *bsp_mesh)
 
VkResult vkpt_vertex_buffer_create_pipelines ()
 
VkResult vkpt_vertex_buffer_destroy_pipelines ()
 
VkResult vkpt_vertex_buffer_create_instance (VkCommandBuffer cmd_buf, uint32_t num_instances, qboolean update_world_animations)
 
VkResult vkpt_vertex_buffer_upload_models_to_staging ()
 
VkResult vkpt_vertex_buffer_upload_staging ()
 
void vkpt_light_buffer_reset_counts ()
 
VkResult vkpt_light_buffer_upload_to_staging (qboolean render_world, bsp_mesh_t *bsp_mesh, bsp_t *bsp, int num_model_lights, light_poly_t *transformed_model_lights, const float *sky_radiance)
 
VkResult vkpt_light_buffer_upload_staging (VkCommandBuffer cmd_buf)
 
VkResult vkpt_light_stats_create (bsp_mesh_t *bsp_mesh)
 
VkResult vkpt_light_stats_destroy ()
 
VkResult vkpt_load_shader_modules ()
 
VkResult vkpt_destroy_shader_modules ()
 
VkResult vkpt_create_images ()
 
VkResult vkpt_destroy_images ()
 
VkResult vkpt_pt_init ()
 
VkResult vkpt_pt_destroy ()
 
VkResult vkpt_pt_create_pipelines ()
 
VkResult vkpt_pt_destroy_pipelines ()
 
VkResult vkpt_pt_create_toplevel (VkCommandBuffer cmd_buf, int idx, qboolean include_world, qboolean weapon_left_handed)
 
VkResult vkpt_pt_create_static (VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, int num_vertices_transparent, int num_vertices_sky, int num_vertices_custom_sky)
 
VkResult vkpt_pt_destroy_static ()
 
VkResult vkpt_pt_trace_primary_rays (VkCommandBuffer cmd_buf)
 
VkResult vkpt_pt_trace_reflections (VkCommandBuffer cmd_buf, int bounce)
 
VkResult vkpt_pt_trace_lighting (VkCommandBuffer cmd_buf, float num_bounce_rays)
 
VkResult vkpt_pt_update_descripter_set_bindings (int idx)
 
VkResult vkpt_pt_create_all_dynamic (VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, const EntityUploadInfo *upload_info)
 
VkResult vkpt_asvgf_initialize ()
 
VkResult vkpt_asvgf_destroy ()
 
VkResult vkpt_asvgf_create_pipelines ()
 
VkResult vkpt_asvgf_destroy_pipelines ()
 
VkResult vkpt_asvgf_filter (VkCommandBuffer cmd_buf, qboolean enable_lf)
 
VkResult vkpt_compositing (VkCommandBuffer cmd_buf)
 
VkResult vkpt_interleave (VkCommandBuffer cmd_buf)
 
VkResult vkpt_taa (VkCommandBuffer cmd_buf)
 
VkResult vkpt_asvgf_create_gradient_samples (VkCommandBuffer cmd_buf, uint32_t frame_num, int do_gradient_samples)
 
VkResult vkpt_bloom_initialize ()
 
VkResult vkpt_bloom_destroy ()
 
VkResult vkpt_bloom_create_pipelines ()
 
VkResult vkpt_bloom_destroy_pipelines ()
 
void vkpt_bloom_reset ()
 
void vkpt_bloom_update (QVKUniformBuffer_t *ubo, float frame_time, qboolean under_water, qboolean menu_mode)
 
VkResult vkpt_bloom_record_cmd_buffer (VkCommandBuffer cmd_buf)
 
VkResult vkpt_tone_mapping_initialize ()
 
VkResult vkpt_tone_mapping_destroy ()
 
VkResult vkpt_tone_mapping_create_pipelines ()
 
VkResult vkpt_tone_mapping_reset (VkCommandBuffer cmd_buf)
 
VkResult vkpt_tone_mapping_destroy_pipelines ()
 
VkResult vkpt_tone_mapping_record_cmd_buffer (VkCommandBuffer cmd_buf, float frame_time)
 
void vkpt_tone_mapping_request_reset ()
 
VkResult vkpt_shadow_map_initialize ()
 
VkResult vkpt_shadow_map_destroy ()
 
VkResult vkpt_shadow_map_create_pipelines ()
 
VkResult vkpt_shadow_map_destroy_pipelines ()
 
VkResult vkpt_shadow_map_render (VkCommandBuffer cmd_buf, float *view_projection_matrix, int num_static_verts, int num_dynamic_verts, int transparent_offset, int num_transparent_verts)
 
VkImageView vkpt_shadow_map_get_view ()
 
void vkpt_shadow_map_setup (const sun_light_t *light, const float *bbox_min, const float *bbox_max, float *VP, float *depth_scale, qboolean random_sampling)
 
qerror_t load_img (const char *name, image_t *image)
 
qboolean initialize_transparency ()
 
void destroy_transparency ()
 
void update_transparency (VkCommandBuffer command_buffer, const float *view_matrix, const particle_t *particles, int particle_num, const entity_t *entities, int entity_num)
 
void build_transparency_blas (VkCommandBuffer cmd_buf)
 
VkAccelerationStructureNV get_transparency_particle_blas ()
 
VkAccelerationStructureNV get_transparency_beam_blas ()
 
VkAccelerationStructureNV get_transparency_sprite_blas ()
 
VkBufferView get_transparency_particle_color_buffer_view ()
 
VkBufferView get_transparency_beam_color_buffer_view ()
 
VkBufferView get_transparency_sprite_info_buffer_view ()
 
void get_transparency_counts (int *particle_num, int *beam_num, int *sprite_num)
 
void vkpt_build_beam_lights (light_poly_t *light_list, int *num_lights, int max_lights, bsp_t *bsp, entity_t *entities, int num_entites, float adapted_luminance)
 
qboolean vkpt_build_cylinder_light (light_poly_t *light_list, int *num_lights, int max_lights, bsp_t *bsp, vec3_t begin, vec3_t end, vec3_t color, float radius)
 
qboolean get_triangle_off_center (const float *positions, float *center, float *anti_center)
 
VkResult vkpt_initialize_god_rays ()
 
VkResult vkpt_destroy_god_rays ()
 
VkResult vkpt_god_rays_create_pipelines ()
 
VkResult vkpt_god_rays_destroy_pipelines ()
 
VkResult vkpt_god_rays_update_images ()
 
VkResult vkpt_god_rays_noop ()
 
qboolean vkpt_god_rays_enabled (const sun_light_t *sun_light)
 
void vkpt_record_god_rays_trace_command_buffer (VkCommandBuffer command_buffer, int pass)
 
void vkpt_record_god_rays_filter_command_buffer (VkCommandBuffer command_buffer)
 
void vkpt_god_rays_prepare_ubo (QVKUniformBuffer_t *ubo, const aabb_t *world_aabb, const float *proj, const float *view, const float *shadowmap_viewproj, float shadowmap_depth_scale)
 
void vkpt_freecam_reset ()
 
void vkpt_freecam_update (float frame_time)
 
void vkpt_reset_accumulation ()
 
static void begin_perf_marker (VkCommandBuffer command_buffer, int index, const char *name)
 
static void end_perf_marker (VkCommandBuffer command_buffer, int index)
 
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)
 
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)
 
qboolean R_InterceptKey_RTX (unsigned key, qboolean down)
 
void IMG_Load_RTX (image_t *image, byte *pic)
 
void IMG_Unload_RTX (image_t *image)
 
byte * IMG_ReadPixels_RTX (int *width, int *height, int *rowbytes)
 
qerror_t MOD_LoadMD2_RTX (model_t *model, const void *rawdata, size_t length)
 
qerror_t MOD_LoadMD3_RTX (model_t *model, const void *rawdata, size_t length)
 
void MOD_Reference_RTX (model_t *model)
 

Variables

QVK_t qvk
 
vkpt_refdef_t vkpt_refdef
 
drawStatic_t draw
 

Macro Definition Documentation

◆ _VK

#define _VK (   ...)    do { __VA_ARGS__; } while(0)

Definition at line 65 of file vkpt.h.

◆ _VK_EXTENSION_DO

#define _VK_EXTENSION_DO (   a)    extern PFN_##a q##a;

Definition at line 309 of file vkpt.h.

◆ _VK_EXTENSION_LIST

#define _VK_EXTENSION_LIST
Value:
_VK_EXTENSION_DO(vkCreateAccelerationStructureNV) \
_VK_EXTENSION_DO(vkCreateAccelerationStructureNV) \
_VK_EXTENSION_DO(vkDestroyAccelerationStructureNV) \
_VK_EXTENSION_DO(vkGetAccelerationStructureMemoryRequirementsNV) \
_VK_EXTENSION_DO(vkBindAccelerationStructureMemoryNV) \
_VK_EXTENSION_DO(vkCmdBuildAccelerationStructureNV) \
_VK_EXTENSION_DO(vkCmdCopyAccelerationStructureNV) \
_VK_EXTENSION_DO(vkCmdTraceRaysNV) \
_VK_EXTENSION_DO(vkCreateRayTracingPipelinesNV) \
_VK_EXTENSION_DO(vkGetRayTracingShaderGroupHandlesNV) \
_VK_EXTENSION_DO(vkGetAccelerationStructureHandleNV) \
_VK_EXTENSION_DO(vkCmdWriteAccelerationStructuresPropertiesNV) \
_VK_EXTENSION_DO(vkCompileDeferredNV) \
_VK_EXTENSION_DO(vkDebugMarkerSetObjectNameEXT) \
_VK_EXTENSION_DO(vkGetDeviceGroupPeerMemoryFeaturesKHR) \
_VK_EXTENSION_DO(vkCmdSetDeviceMaskKHR) \
_VK_EXTENSION_DO(vkCmdDispatchBaseKHR) \
_VK_EXTENSION_DO(vkGetDeviceGroupPresentCapabilitiesKHR) \
_VK_EXTENSION_DO(vkGetDeviceGroupSurfacePresentModesKHR) \
_VK_EXTENSION_DO(vkGetPhysicalDevicePresentRectanglesKHR) \
_VK_EXTENSION_DO(vkAcquireNextImage2KHR) \
_VK_EXTENSION_DO(vkBindImageMemory2KHR)

Definition at line 284 of file vkpt.h.

◆ _VK_INST_EXTENSION_DO

#define _VK_INST_EXTENSION_DO (   a)    extern PFN_##a q##a;

Definition at line 280 of file vkpt.h.

◆ _VK_INST_EXTENSION_LIST

#define _VK_INST_EXTENSION_LIST
Value:
_VK_INST_EXTENSION_DO(vkCmdBeginDebugUtilsLabelEXT) \
_VK_INST_EXTENSION_DO(vkCmdEndDebugUtilsLabelEXT) \
_VK_INST_EXTENSION_DO(vkEnumeratePhysicalDeviceGroupsKHR)

Definition at line 275 of file vkpt.h.

◆ ALL_GPUS

#define ALL_GPUS   (-1)

Definition at line 535 of file vkpt.h.

◆ BEGIN_PERF_MARKER

#define BEGIN_PERF_MARKER (   command_buffer,
  name 
)    begin_perf_marker(command_buffer, name, #name)

Definition at line 742 of file vkpt.h.

◆ END_PERF_MARKER

#define END_PERF_MARKER (   command_buffer,
  name 
)    end_perf_marker(command_buffer, name)

Definition at line 743 of file vkpt.h.

◆ HAVE_M_PI

#define HAVE_M_PI

Definition at line 24 of file vkpt.h.

◆ LENGTH

#define LENGTH (   a)    ((sizeof (a)) / (sizeof(*(a))))

Definition at line 48 of file vkpt.h.

◆ LIST_SHADER_MODULES

#define LIST_SHADER_MODULES

Definition at line 70 of file vkpt.h.

◆ LOG_FUNC

#define LOG_FUNC ( )    LOG_FUNC_(__func__)

Definition at line 54 of file vkpt.h.

◆ LOG_FUNC_

#define LOG_FUNC_ (   f)    do {} while(0)

Definition at line 52 of file vkpt.h.

◆ MAX

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 50 of file vkpt.h.

◆ MAX_FRAMES_IN_FLIGHT

#define MAX_FRAMES_IN_FLIGHT   2

Definition at line 140 of file vkpt.h.

◆ MAX_SKY_CLUSTERS

#define MAX_SKY_CLUSTERS   1024

Definition at line 313 of file vkpt.h.

◆ MAX_SWAPCHAIN_IMAGES

#define MAX_SWAPCHAIN_IMAGES   4

Definition at line 141 of file vkpt.h.

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 49 of file vkpt.h.

◆ NUM_PROFILER_QUERIES_PER_FRAME

#define NUM_PROFILER_QUERIES_PER_FRAME   (NUM_PROFILER_ENTRIES * 2)

Definition at line 466 of file vkpt.h.

◆ PROFILER_DO

#define PROFILER_DO (   a,
  ... 
)    a,

Definition at line 460 of file vkpt.h.

◆ PROFILER_LIST

#define PROFILER_LIST
Value:
PROFILER_DO(PROFILER_FRAME_TIME, 0) \
PROFILER_DO(PROFILER_INSTANCE_GEOMETRY, 1) \
PROFILER_DO(PROFILER_BVH_UPDATE, 1) \
PROFILER_DO(PROFILER_ASVGF_GRADIENT_SAMPLES, 1) \
PROFILER_DO(PROFILER_ASVGF_DO_GRADIENT_SAMPLES, 2) \
PROFILER_DO(PROFILER_PRIMARY_RAYS, 1) \
PROFILER_DO(PROFILER_REFLECT_REFRACT_1, 1) \
PROFILER_DO(PROFILER_REFLECT_REFRACT_2, 1) \
PROFILER_DO(PROFILER_DIRECT_LIGHTING, 1) \
PROFILER_DO(PROFILER_INDIRECT_LIGHTING, 1) \
PROFILER_DO(PROFILER_ASVGF_FULL, 1) \
PROFILER_DO(PROFILER_ASVGF_RECONSTRUCT_GRADIENT, 2) \
PROFILER_DO(PROFILER_ASVGF_TEMPORAL, 2) \
PROFILER_DO(PROFILER_ASVGF_ATROUS, 2) \
PROFILER_DO(PROFILER_MGPU_TRANSFERS, 1) \
PROFILER_DO(PROFILER_INTERLEAVE, 1) \
PROFILER_DO(PROFILER_ASVGF_TAA, 2) \
PROFILER_DO(PROFILER_BLOOM, 1) \
PROFILER_DO(PROFILER_TONE_MAPPING, 1) \
PROFILER_DO(PROFILER_UPDATE_ENVIRONMENT, 1) \
PROFILER_DO(PROFILER_GOD_RAYS, 1) \
PROFILER_DO(PROFILER_GOD_RAYS_REFLECT_REFRACT, 1) \
PROFILER_DO(PROFILER_GOD_RAYS_FILTER, 1) \
PROFILER_DO(PROFILER_SHADOW_MAP, 1) \
PROFILER_DO(PROFILER_COMPOSITING, 1) \

Definition at line 432 of file vkpt.h.

◆ QGL_INDEX_TYPE

#define QGL_INDEX_TYPE   GLuint

Definition at line 711 of file vkpt.h.

◆ SHADER_MODULE_DO

#define SHADER_MODULE_DO (   a)    a,

Definition at line 134 of file vkpt.h.

◆ SHADER_PATH_TEMPLATE

#define SHADER_PATH_TEMPLATE   VKPT_SHADER_DIR "/%s.spv"

Definition at line 114 of file vkpt.h.

◆ SHADER_STAGE

#define SHADER_STAGE (   _module,
  _stage 
)
Value:
{ \
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, \
.stage = _stage, \
.module = qvk.shader_modules[_module], \
.pName = "main" \
}

Definition at line 116 of file vkpt.h.

◆ SHADER_STAGE_SPEC

#define SHADER_STAGE_SPEC (   _module,
  _stage,
  _spec 
)
Value:
{ \
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, \
.stage = _stage, \
.module = qvk.shader_modules[_module], \
.pName = "main", \
.pSpecializationInfo = _spec, \
}

Definition at line 124 of file vkpt.h.

◆ TESS_MAX_INDICES

#define TESS_MAX_INDICES   (3 * TESS_MAX_VERTICES)

Definition at line 709 of file vkpt.h.

◆ TESS_MAX_VERTICES

#define TESS_MAX_VERTICES   16384

Definition at line 708 of file vkpt.h.

◆ VKPT_SHADER_DIR

#define VKPT_SHADER_DIR   "shader_vkpt"

Definition at line 111 of file vkpt.h.

Typedef Documentation

◆ aabb_t

typedef struct aabb_s aabb_t

◆ bsp_mesh_t

typedef struct bsp_mesh_s bsp_mesh_t

◆ bsp_model_t

typedef struct bsp_model_s bsp_model_t

◆ cmd_buf_group_t

◆ EntityUploadInfo

◆ light_poly_t

typedef struct light_poly_s light_poly_t

◆ maliasframe_t

typedef struct maliasframe_s maliasframe_t

◆ maliasmesh_t

typedef struct maliasmesh_s maliasmesh_t

◆ QVK_t

typedef struct QVK_s QVK_t

◆ semaphore_group_t

◆ sun_light_t

typedef struct sun_light_s sun_light_t

◆ vkpt_refdef_t

typedef struct vkpt_refdef_s vkpt_refdef_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
NUM_PROFILER_ENTRIES 

Definition at line 459 of file vkpt.h.

459  {
460 #define PROFILER_DO(a, ...) a,
462 #undef PROFILER_DO
464 };

◆ QVK_SHADER_MODULES

Enumerator
NUM_QVK_SHADER_MODULES 

Definition at line 133 of file vkpt.h.

133  {
134 #define SHADER_MODULE_DO(a) a,
136 #undef SHADER_MODULE_DO
138 };

◆ VKPTProfilerAction

Enumerator
PROFILER_START 
PROFILER_STOP 

Definition at line 468 of file vkpt.h.

468  {

Function Documentation

◆ allocate_gpu_memory()

VkResult allocate_gpu_memory ( VkMemoryRequirements  mem_req,
VkDeviceMemory *  pMemory 
)

Definition at line 402 of file vk_util.c.

403 {
404  VkMemoryAllocateInfo mem_alloc_info = {
405  .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
406  .allocationSize = mem_req.size,
407  .memoryTypeIndex = get_memory_type(mem_req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
408  };
409 
410 #ifdef VKPT_DEVICE_GROUPS
411  VkMemoryAllocateFlagsInfoKHR mem_alloc_flags = {
412  .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR,
413  .flags = VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHR,
414  .deviceMask = (1 << qvk.device_count) - 1
415  };
416 
417  if (qvk.device_count > 1) {
418  mem_alloc_info.pNext = &mem_alloc_flags;
419  }
420 #endif
421 
422  return vkAllocateMemory(qvk.device, &mem_alloc_info, NULL, pMemory);
423 
424 }

Referenced by allocate_and_bind_memory_to_blas(), initializeEnvTexture(), load_blue_noise(), vkpt_create_images(), vkpt_pt_create_accel_bottom(), vkpt_pt_create_toplevel(), vkpt_shadow_map_initialize(), and vkpt_textures_upload_envmap().

◆ begin_perf_marker()

static void begin_perf_marker ( VkCommandBuffer  command_buffer,
int  index,
const char *  name 
)
inlinestatic

Definition at line 721 of file vkpt.h.

722 {
723  _VK(vkpt_profiler_query(command_buffer, index, PROFILER_START));
724 
725  const VkDebugUtilsLabelEXT label = {
726  .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
727  .pLabelName = name
728  };
729 
730  if (qvkCmdBeginDebugUtilsLabelEXT != NULL)
731  qvkCmdBeginDebugUtilsLabelEXT(command_buffer, &label);
732 }

◆ bsp_mesh_create_from_bsp()

void bsp_mesh_create_from_bsp ( bsp_mesh_t wm,
bsp_t *  bsp,
const char *  map_name 
)

Definition at line 1623 of file bsp_mesh.c.

1624 {
1625  const char* full_game_map_name = map_name;
1626  if (strcmp(map_name, "demo1") == 0)
1627  full_game_map_name = "base1";
1628  else if (strcmp(map_name, "demo2") == 0)
1629  full_game_map_name = "base2";
1630  else if (strcmp(map_name, "demo3") == 0)
1631  full_game_map_name = "base3";
1632 
1633  load_sky_and_lava_clusters(wm, full_game_map_name);
1634  load_cameras(wm, full_game_map_name);
1635 
1636  wm->models = Z_Malloc(bsp->nummodels * sizeof(bsp_model_t));
1637  memset(wm->models, 0, bsp->nummodels * sizeof(bsp_model_t));
1638 
1639  wm->num_models = bsp->nummodels;
1640  wm->num_clusters = bsp->vis->numclusters;
1641 
1642  if (wm->num_clusters + 1 >= MAX_LIGHT_LISTS)
1643  {
1644  Com_Error(ERR_FATAL, "The BSP model has too many clusters (%d)", wm->num_clusters);
1645  }
1646 
1647  wm->num_vertices = 0;
1648  wm->num_indices = 0;
1649  wm->positions = Z_Malloc(MAX_VERT_BSP * 3 * sizeof(*wm->positions));
1650  wm->tex_coords = Z_Malloc(MAX_VERT_BSP * 2 * sizeof(*wm->tex_coords));
1651  wm->materials = Z_Malloc(MAX_VERT_BSP / 3 * sizeof(*wm->materials));
1652  wm->clusters = Z_Malloc(MAX_VERT_BSP / 3 * sizeof(*wm->clusters));
1653 
1654  // clear these here because `bsp_mesh_load_custom_sky` creates lights before `collect_ligth_polys`
1655  wm->num_light_polys = 0;
1656  wm->allocated_light_polys = 0;
1657  wm->light_polys = NULL;
1658 
1659  int idx_ctr = 0;
1660 
1661 #if DUMP_WORLD_MESH_TO_OBJ
1662  {
1663  char filename[MAX_QPATH];
1664  Q_snprintf(filename, sizeof(filename), "C:\\temp\\%s.obj", map_name);
1665  obj_dump_file = fopen(filename, "w");
1666  obj_vertex_num = 1;
1667  }
1668 #endif
1669 
1670  collect_surfaces(&idx_ctr, wm, bsp, -1, filter_static_opaque);
1671  wm->world_idx_count = idx_ctr;
1672 
1673  wm->world_transparent_offset = idx_ctr;
1674  collect_surfaces(&idx_ctr, wm, bsp, -1, filter_static_transparent);
1676 
1677  wm->world_sky_offset = idx_ctr;
1678  collect_surfaces(&idx_ctr, wm, bsp, -1, filter_static_sky);
1679  wm->world_sky_count = idx_ctr - wm->world_sky_offset;
1680 
1681  wm->world_custom_sky_offset = idx_ctr;
1682  bsp_mesh_load_custom_sky(&idx_ctr, wm, bsp, full_game_map_name);
1683  wm->world_custom_sky_count = idx_ctr - wm->world_custom_sky_offset;
1684 
1685  for (int k = 0; k < bsp->nummodels; k++) {
1686  bsp_model_t* model = wm->models + k;
1687  model->idx_offset = idx_ctr;
1688  collect_surfaces(&idx_ctr, wm, bsp, k, filter_all);
1689  model->idx_count = idx_ctr - model->idx_offset;
1690  }
1691 
1692 #if DUMP_WORLD_MESH_TO_OBJ
1693  fclose(obj_dump_file);
1694  obj_dump_file = NULL;
1695 #endif
1696 
1697  if (!bsp->pvs_patched)
1698  {
1699  build_pvs2(bsp);
1700 
1701  if (!BSP_SavePatchedPVS(bsp))
1702  {
1703  Com_EPrintf("Couldn't save patched PVS for %s.\n", bsp->name);
1704  }
1705  }
1706 
1707  wm->num_indices = idx_ctr;
1708  wm->num_vertices = idx_ctr;
1709 
1710  wm->indices = Z_Malloc(idx_ctr * sizeof(int));
1711  for (int i = 0; i < wm->num_vertices; i++)
1712  wm->indices[i] = i;
1713 
1715 
1716  if (wm->num_vertices >= MAX_VERT_BSP) {
1717  Com_Error(ERR_FATAL, "The BSP model has too many vertices (%d)", wm->num_vertices);
1718  }
1719 
1720  for(int i = 0; i < wm->num_models; i++)
1721  {
1722  bsp_model_t* model = wm->models + i;
1723 
1724  compute_aabb(wm->positions + model->idx_offset * 3, model->idx_count, model->aabb_min, model->aabb_max);
1725 
1726  VectorAdd(model->aabb_min, model->aabb_max, model->center);
1727  VectorScale(model->center, 0.5f, model->center);
1728  }
1729 
1731 
1732  vec3_t margin = { 1.f, 1.f, 1.f };
1733  VectorSubtract(wm->world_aabb.mins, margin, wm->world_aabb.mins);
1734  VectorAdd(wm->world_aabb.maxs, margin, wm->world_aabb.maxs);
1735 
1737 
1740 
1741  for (int k = 0; k < bsp->nummodels; k++)
1742  {
1743  bsp_model_t* model = wm->models + k;
1744 
1745  model->num_light_polys = 0;
1746  model->allocated_light_polys = 0;
1747  model->light_polys = NULL;
1748 
1749  collect_ligth_polys(wm, bsp, k, &model->num_light_polys, &model->allocated_light_polys, &model->light_polys);
1750 
1751  model->transparent = is_model_transparent(wm, model);
1752  }
1753 
1754  collect_cluster_lights(wm, bsp);
1755 
1756  compute_sky_visibility(wm, bsp);
1757 }

Referenced by R_BeginRegistration_RTX().

◆ bsp_mesh_destroy()

void bsp_mesh_destroy ( bsp_mesh_t wm)

Definition at line 1760 of file bsp_mesh.c.

1761 {
1762  Z_Free(wm->models);
1763 
1764  Z_Free(wm->positions);
1765  Z_Free(wm->tex_coords);
1766  Z_Free(wm->tangents);
1767  Z_Free(wm->indices);
1768  Z_Free(wm->clusters);
1769  Z_Free(wm->materials);
1770  Z_Free(wm->texel_density);
1771 
1772  Z_Free(wm->light_polys);
1773  Z_Free(wm->cluster_lights);
1775  Z_Free(wm->cluster_aabbs);
1776 
1777  memset(wm, 0, sizeof(*wm));
1778 }

Referenced by R_BeginRegistration_RTX().

◆ bsp_mesh_register_textures()

void bsp_mesh_register_textures ( bsp_t *  bsp)

Definition at line 1781 of file bsp_mesh.c.

1782 {
1783  for (int i = 0; i < bsp->numtexinfo; i++) {
1784  mtexinfo_t *info = bsp->texinfo + i;
1785  imageflags_t flags;
1786  if (info->c.flags & SURF_WARP)
1787  flags = IF_TURBULENT;
1788  else
1789  flags = IF_NONE;
1790 
1791  char buffer[MAX_QPATH];
1792  Q_concat(buffer, sizeof(buffer), "textures/", info->name, ".wal", NULL);
1793  FS_NormalizePath(buffer, buffer);
1794 
1795  pbr_material_t * mat = MAT_FindPBRMaterial(buffer);
1796  if (!mat)
1797  Com_EPrintf("error finding material '%s'\n", buffer);
1798 
1799  image_t* image_diffuse = IMG_Find(buffer, IT_WALL, flags | IF_SRGB);
1800  image_t* image_normals = NULL;
1801  image_t* image_emissive = NULL;
1802 
1803  if (image_diffuse != R_NOTEXTURE)
1804  {
1805  // attempt loading the second texture
1806  Q_concat(buffer, sizeof(buffer), "textures/", info->name, "_n.tga", NULL);
1807  FS_NormalizePath(buffer, buffer);
1808  image_normals = IMG_Find(buffer, IT_WALL, flags);
1809  if (image_normals == R_NOTEXTURE) image_normals = NULL;
1810 
1811  if (image_normals && !image_normals->processing_complete)
1812  {
1813  vkpt_normalize_normal_map(image_normals);
1814  }
1815 
1816  // attempt loading the emissive texture
1817  Q_concat(buffer, sizeof(buffer), "textures/", info->name, "_light.tga", NULL);
1818  FS_NormalizePath(buffer, buffer);
1819  image_emissive = IMG_Find(buffer, IT_WALL, flags | IF_SRGB);
1820  if (image_emissive == R_NOTEXTURE) image_emissive = NULL;
1821 
1822  if (image_emissive && !image_emissive->processing_complete && (mat->emissive_scale > 0.f) && ((mat->flags & MATERIAL_FLAG_LIGHT) != 0 || MAT_IsKind(mat->flags, MATERIAL_KIND_LAVA)))
1823  {
1824  vkpt_extract_emissive_texture_info(image_emissive);
1825  }
1826  }
1827 
1828  // finish registration
1829  MAT_RegisterPBRMaterial(mat, image_diffuse, image_normals, image_emissive);
1830 
1831  info->material = mat;
1832  }
1833 
1834  // link the animation sequences
1835  for (int i = 0; i < bsp->numtexinfo; i++)
1836  {
1837  mtexinfo_t *texinfo = bsp->texinfo + i;
1838  pbr_material_t* material = texinfo->material;
1839 
1840  if (texinfo->numframes > 1)
1841  {
1842  assert(texinfo->next);
1843  assert(texinfo->next->material);
1844 
1845  material->num_frames = texinfo->numframes;
1846  material->next_frame = texinfo->next->material->flags & MATERIAL_INDEX_MASK;
1847  }
1848  }
1849 }

Referenced by R_BeginRegistration_RTX().

◆ build_transparency_blas()

void build_transparency_blas ( VkCommandBuffer  cmd_buf)

Definition at line 217 of file transparency.c.

218 {
219  update_particle_blas(cmd_buf);
220  update_beam_blas(cmd_buf);
221  update_sprite_blas(cmd_buf);
222 
223  // No barrier here because a single barrier is used later in the pipeline, after building all the BLAS-es
224 }

Referenced by R_RenderFrame_RTX().

◆ create_entity_matrix()

void create_entity_matrix ( float  matrix[16],
entity_t *  e,
qboolean  enable_left_hand 
)

Definition at line 23 of file matrix.c.

24 {
25  vec3_t axis[3];
26  vec3_t origin;
27  origin[0] = (1.f-e->backlerp) * e->origin[0] + e->backlerp * e->oldorigin[0];
28  origin[1] = (1.f-e->backlerp) * e->origin[1] + e->backlerp * e->oldorigin[1];
29  origin[2] = (1.f-e->backlerp) * e->origin[2] + e->backlerp * e->oldorigin[2];
30 
31  AnglesToAxis(e->angles, axis);
32 
33  float scale = (e->scale > 0.f) ? e->scale : 1.f;
34 
35  vec3_t scales = { scale, scale, scale };
36  if ((e->flags & RF_LEFTHAND) && enable_left_hand)
37  {
38  scales[1] *= -1.f;
39  }
40 
41  matrix[0] = axis[0][0] * scales[0];
42  matrix[4] = axis[1][0] * scales[1];
43  matrix[8] = axis[2][0] * scales[2];
44  matrix[12] = origin[0];
45 
46  matrix[1] = axis[0][1] * scales[0];
47  matrix[5] = axis[1][1] * scales[1];
48  matrix[9] = axis[2][1] * scales[2];
49  matrix[13] = origin[1];
50 
51  matrix[2] = axis[0][2] * scales[0];
52  matrix[6] = axis[1][2] * scales[1];
53  matrix[10] = axis[2][2] * scales[2];
54  matrix[14] = origin[2];
55 
56  matrix[3] = 0.0f;
57  matrix[7] = 0.0f;
58  matrix[11] = 0.0f;
59  matrix[15] = 1.0f;
60 }

Referenced by process_bsp_entity(), and process_regular_entity().

◆ create_orthographic_matrix()

void create_orthographic_matrix ( float  matrix[16],
float  xmin,
float  xmax,
float  ymin,
float  ymax,
float  znear,
float  zfar 
)

Definition at line 100 of file matrix.c.

102 {
103  float width, height, depth;
104 
105  width = xmax - xmin;
106  height = ymax - ymin;
107  depth = zfar - znear;
108 
109  matrix[0] = 2 / width;
110  matrix[4] = 0;
111  matrix[8] = 0;
112  matrix[12] = -(xmax + xmin) / width;
113 
114  matrix[1] = 0;
115  matrix[5] = 2 / height;
116  matrix[9] = 0;
117  matrix[13] = -(ymax + ymin) / height;
118 
119  matrix[2] = 0;
120  matrix[6] = 0;
121  matrix[10] = 1 / depth;
122  matrix[14] = -znear / depth;
123 
124  matrix[3] = 0;
125  matrix[7] = 0;
126  matrix[11] = 0;
127  matrix[15] = 1;
128 }

Referenced by vkpt_shadow_map_setup().

◆ create_projection_matrix()

void create_projection_matrix ( float  matrix[16],
float  znear,
float  zfar,
float  fov_x,
float  fov_y 
)

Definition at line 63 of file matrix.c.

64 {
65  float xmin, xmax, ymin, ymax;
66  float width, height, depth;
67 
68  ymax = znear * tan(fov_y * M_PI / 360.0);
69  ymin = -ymax;
70 
71  xmax = znear * tan(fov_x * M_PI / 360.0);
72  xmin = -xmax;
73 
74  width = xmax - xmin;
75  height = ymax - ymin;
76  depth = zfar - znear;
77 
78  matrix[0] = 2 * znear / width;
79  matrix[4] = 0;
80  matrix[8] = (xmax + xmin) / width;
81  matrix[12] = 0;
82 
83  matrix[1] = 0;
84  matrix[5] = -2 * znear / height;
85  matrix[9] = (ymax + ymin) / height;
86  matrix[13] = 0;
87 
88  matrix[2] = 0;
89  matrix[6] = 0;
90  matrix[10] = (zfar + znear) / depth;
91  matrix[14] = 2 * zfar * znear / depth;
92 
93  matrix[3] = 0;
94  matrix[7] = 0;
95  matrix[11] = 1;
96  matrix[15] = 0;
97 }

Referenced by prepare_ubo().

◆ create_view_matrix()

void create_view_matrix ( float  matrix[16],
refdef_t *  fd 
)

Definition at line 131 of file matrix.c.

132 {
133  vec3_t viewaxis[3];
134  AnglesToAxis(fd->viewangles, viewaxis);
135 
136  matrix[0] = -viewaxis[1][0];
137  matrix[4] = -viewaxis[1][1];
138  matrix[8] = -viewaxis[1][2];
139  matrix[12] = DotProduct(viewaxis[1], fd->vieworg);
140 
141  matrix[1] = viewaxis[2][0];
142  matrix[5] = viewaxis[2][1];
143  matrix[9] = viewaxis[2][2];
144  matrix[13] = -DotProduct(viewaxis[2], fd->vieworg);
145 
146  matrix[2] = viewaxis[0][0];
147  matrix[6] = viewaxis[0][1];
148  matrix[10] = viewaxis[0][2];
149  matrix[14] = -DotProduct(viewaxis[0], fd->vieworg);
150 
151  matrix[3] = 0;
152  matrix[7] = 0;
153  matrix[11] = 0;
154  matrix[15] = 1;
155 }

Referenced by prepare_ubo().

◆ destroy_transparency()

void destroy_transparency ( )

Definition at line 151 of file transparency.c.

152 {
153  vkDestroyBufferView(qvk.device, transparency.particle_color_buffer_view, NULL);
154  vkDestroyBufferView(qvk.device, transparency.beam_color_buffer_view, NULL);
155  vkDestroyBufferView(qvk.device, transparency.sprite_info_buffer_view, NULL);
156  vkDestroyBuffer(qvk.device, transparency.host_buffer, NULL);
157  vkDestroyBuffer(qvk.device, transparency.scratch_buffer, NULL);
158  vkDestroyBuffer(qvk.device, transparency.vertex_buffer, NULL);
159  vkDestroyBuffer(qvk.device, transparency.index_buffer, NULL);
160  vkDestroyBuffer(qvk.device, transparency.particle_color_buffer, NULL);
161  vkDestroyBuffer(qvk.device, transparency.beam_color_buffer, NULL);
162  vkDestroyBuffer(qvk.device, transparency.sprite_info_buffer, NULL);
163  qvkDestroyAccelerationStructureNV(qvk.device, transparency.particle_blas, NULL);
164  qvkDestroyAccelerationStructureNV(qvk.device, transparency.beam_blas, NULL);
165  qvkDestroyAccelerationStructureNV(qvk.device, transparency.sprite_blas, NULL);
166  vkFreeMemory(qvk.device, transparency.host_buffer_memory, NULL);
167  vkFreeMemory(qvk.device, transparency.device_buffer_memory, NULL);
168  vkFreeMemory(qvk.device, transparency.device_blas_memory, NULL);
169 }

Referenced by vkpt_destroy_all().

◆ draw_profiler()

void draw_profiler ( int  enable_asvgf)

Definition at line 134 of file profiler.c.

135 {
136  int x = 500;
137  int y = 100;
138 
139  qhandle_t font;
140  font = R_RegisterFont("conchars");
141  if(!font)
142  return;
143 
144 #define PROFILER_DO(name, indent) \
145  draw_query(x, y, font, #name + 9, name); y += 10;
146 
147  PROFILER_DO(PROFILER_FRAME_TIME, 0);
148  PROFILER_DO(PROFILER_INSTANCE_GEOMETRY, 1);
149  PROFILER_DO(PROFILER_BVH_UPDATE, 1);
150  PROFILER_DO(PROFILER_UPDATE_ENVIRONMENT, 1);
151  PROFILER_DO(PROFILER_SHADOW_MAP, 1);
152  PROFILER_DO(PROFILER_ASVGF_GRADIENT_SAMPLES, 1);
153  PROFILER_DO(PROFILER_ASVGF_DO_GRADIENT_SAMPLES, 2);
154  PROFILER_DO(PROFILER_PRIMARY_RAYS, 1);
155  if (cvar_pt_reflect_refract->integer > 0) { PROFILER_DO(PROFILER_REFLECT_REFRACT_1, 1); }
156  if (cvar_pt_reflect_refract->integer > 1) { PROFILER_DO(PROFILER_REFLECT_REFRACT_2, 1); }
157  PROFILER_DO(PROFILER_DIRECT_LIGHTING, 1);
158  PROFILER_DO(PROFILER_INDIRECT_LIGHTING, 1);
159  PROFILER_DO(PROFILER_GOD_RAYS, 1);
160  PROFILER_DO(PROFILER_GOD_RAYS_REFLECT_REFRACT, 1);
161  PROFILER_DO(PROFILER_GOD_RAYS_FILTER, 1);
162  if (enable_asvgf)
163  {
164  PROFILER_DO(PROFILER_ASVGF_FULL, 1);
165  PROFILER_DO(PROFILER_ASVGF_RECONSTRUCT_GRADIENT, 2);
166  PROFILER_DO(PROFILER_ASVGF_TEMPORAL, 2);
167  PROFILER_DO(PROFILER_ASVGF_ATROUS, 2);
168  PROFILER_DO(PROFILER_ASVGF_TAA, 2);
169  }
170  else
171  {
172  PROFILER_DO(PROFILER_COMPOSITING, 1);
173  }
174  if (qvk.device_count > 1) {
175  PROFILER_DO(PROFILER_MGPU_TRANSFERS, 1);
176  }
177  PROFILER_DO(PROFILER_INTERLEAVE, 1);
178  PROFILER_DO(PROFILER_BLOOM, 1);
179  PROFILER_DO(PROFILER_TONE_MAPPING, 2);
180 #undef PROFILER_DO
181 }

Referenced by R_EndFrame_RTX().

◆ end_perf_marker()

static void end_perf_marker ( VkCommandBuffer  command_buffer,
int  index 
)
inlinestatic

Definition at line 734 of file vkpt.h.

735 {
736  if (qvkCmdEndDebugUtilsLabelEXT != NULL)
737  qvkCmdEndDebugUtilsLabelEXT(command_buffer);
738 
739  _VK(vkpt_profiler_query(command_buffer, index, PROFILER_STOP));
740 }

◆ get_transparency_beam_blas()

VkAccelerationStructureNV get_transparency_beam_blas ( )

Definition at line 231 of file transparency.c.

232 {
233  return transparency.beam_blas;
234 }

Referenced by vkpt_pt_create_toplevel().

◆ get_transparency_beam_color_buffer_view()

VkBufferView get_transparency_beam_color_buffer_view ( )

Definition at line 246 of file transparency.c.

247 {
248  return transparency.beam_color_buffer_view;
249 }

Referenced by vkpt_pt_update_descripter_set_bindings().

◆ get_transparency_counts()

void get_transparency_counts ( int particle_num,
int beam_num,
int sprite_num 
)

Definition at line 256 of file transparency.c.

257 {
258  *particle_num = transparency.particle_num;
259  *beam_num = transparency.beam_num;
260  *sprite_num = transparency.sprite_num;
261 }

Referenced by vkpt_pt_create_toplevel().

◆ get_transparency_particle_blas()

VkAccelerationStructureNV get_transparency_particle_blas ( )

Definition at line 226 of file transparency.c.

227 {
228  return transparency.particle_blas;
229 }

Referenced by vkpt_pt_create_toplevel().

◆ get_transparency_particle_color_buffer_view()

VkBufferView get_transparency_particle_color_buffer_view ( )

Definition at line 241 of file transparency.c.

242 {
243  return transparency.particle_color_buffer_view;
244 }

Referenced by vkpt_pt_update_descripter_set_bindings().

◆ get_transparency_sprite_blas()

VkAccelerationStructureNV get_transparency_sprite_blas ( )

Definition at line 236 of file transparency.c.

237 {
238  return transparency.sprite_blas;
239 }

Referenced by vkpt_pt_create_toplevel().

◆ get_transparency_sprite_info_buffer_view()

VkBufferView get_transparency_sprite_info_buffer_view ( )

Definition at line 251 of file transparency.c.

252 {
253  return transparency.sprite_info_buffer_view;
254 }

Referenced by vkpt_pt_update_descripter_set_bindings().

◆ get_triangle_off_center()

qboolean get_triangle_off_center ( const float *  positions,
float *  center,
float *  anti_center 
)

Definition at line 282 of file bsp_mesh.c.

283 {
284  const float* v0 = positions + 0;
285  const float* v1 = positions + 3;
286  const float* v2 = positions + 6;
287 
288  // Compute the triangle center
289 
290  VectorCopy(v0, center);
291  VectorAdd(center, v1, center);
292  VectorAdd(center, v2, center);
293  VectorScale(center, 1.f / 3.f, center);
294 
295  // Compute the normal
296 
297  vec3_t e1, e2, normal;
298  VectorSubtract(v1, v0, e1);
299  VectorSubtract(v2, v0, e2);
300  CrossProduct(e1, e2, normal);
301  float length = VectorNormalize(normal);
302 
303  // Offset the center by one normal to make sure that the point is
304  // inside a BSP leaf and not on a boundary plane.
305 
306  VectorAdd(center, normal, center);
307 
308  if (anti_center)
309  {
310  VectorMA(center, -2.f, normal, anti_center);
311  }
312 
313  return (length > 0.f);
314 }

Referenced by bsp_mesh_load_custom_sky(), collect_ligth_polys(), collect_sky_and_lava_ligth_polys(), collect_surfaces(), and vkpt_build_cylinder_light().

◆ IMG_Load_RTX()

void IMG_Load_RTX ( image_t image,
byte *  pic 
)

Definition at line 632 of file textures.c.

633 {
634  image->pix_data = pic;
636 }

Referenced by R_RegisterFunctionsRTX().

◆ IMG_ReadPixels_RTX()

byte* IMG_ReadPixels_RTX ( int width,
int height,
int rowbytes 
)

Definition at line 3028 of file main.c.

3029 {
3030  if (qvk.surf_format.format != VK_FORMAT_B8G8R8A8_SRGB &&
3031  qvk.surf_format.format != VK_FORMAT_R8G8B8A8_SRGB)
3032  {
3033  Com_EPrintf("IMG_ReadPixels: unsupported swap chain format (%d)!\n", qvk.surf_format.format);
3034  return NULL;
3035  }
3036 
3037  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
3038 
3039  VkImage swap_chain_image = qvk.swap_chain_images[qvk.current_swap_chain_image_index];
3040 
3041  VkImageSubresourceRange subresource_range = {
3042  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
3043  .baseMipLevel = 0,
3044  .levelCount = 1,
3045  .baseArrayLayer = 0,
3046  .layerCount = 1
3047  };
3048 
3049  IMAGE_BARRIER(cmd_buf,
3050  .image = swap_chain_image,
3051  .subresourceRange = subresource_range,
3052  .srcAccessMask = 0,
3053  .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
3054  .oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
3055  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
3056  );
3057 
3058  IMAGE_BARRIER(cmd_buf,
3059  .image = qvk.screenshot_image,
3060  .subresourceRange = subresource_range,
3061  .srcAccessMask = VK_ACCESS_HOST_READ_BIT,
3062  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
3063  .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
3064  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
3065  );
3066 
3067  VkImageCopy img_copy_region = {
3068  .srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
3069  .dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 },
3070  .extent = { qvk.extent_unscaled.width, qvk.extent_unscaled.height, 1 }
3071  };
3072 
3073  vkCmdCopyImage(cmd_buf,
3074  swap_chain_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
3075  qvk.screenshot_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
3076  1, &img_copy_region);
3077 
3078  IMAGE_BARRIER(cmd_buf,
3079  .image = swap_chain_image,
3080  .subresourceRange = subresource_range,
3081  .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
3082  .dstAccessMask = 0,
3083  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
3084  .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
3085  );
3086 
3087  IMAGE_BARRIER(cmd_buf,
3088  .image = qvk.screenshot_image,
3089  .subresourceRange = subresource_range,
3090  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
3091  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
3092  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
3093  .newLayout = VK_IMAGE_LAYOUT_GENERAL
3094  );
3095 
3098 
3099  VkImageSubresource subresource = {
3100  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
3101  .arrayLayer = 0,
3102  .mipLevel = 0
3103  };
3104 
3105  VkSubresourceLayout subresource_layout;
3106  vkGetImageSubresourceLayout(qvk.device, qvk.screenshot_image, &subresource, &subresource_layout);
3107 
3108  void *device_data;
3109  _VK(vkMapMemory(qvk.device, qvk.screenshot_image_memory, 0, qvk.screenshot_image_memory_size, 0, &device_data));
3110 
3111  int pitch = qvk.extent_unscaled.width * 3;
3112  byte *pixels = FS_AllocTempMem(pitch * qvk.extent_unscaled.height);
3113 
3114  for (int row = 0; row < qvk.extent_unscaled.height; row++)
3115  {
3116  byte* src_row = (byte*)device_data + subresource_layout.rowPitch * row;
3117  byte* dst_row = pixels + pitch * (qvk.extent_unscaled.height - row - 1);
3118 
3119  if (qvk.surf_format.format == VK_FORMAT_B8G8R8A8_SRGB)
3120  {
3121  for (int col = 0; col < qvk.extent_unscaled.width; col++)
3122  {
3123  dst_row[0] = src_row[2];
3124  dst_row[1] = src_row[1];
3125  dst_row[2] = src_row[0];
3126 
3127  src_row += 4;
3128  dst_row += 3;
3129  }
3130  }
3131  else // must be VK_FORMAT_R8G8B8A8_SRGB then
3132  {
3133  for (int col = 0; col < qvk.extent_unscaled.width; col++)
3134  {
3135  dst_row[0] = src_row[0];
3136  dst_row[1] = src_row[1];
3137  dst_row[2] = src_row[2];
3138 
3139  src_row += 4;
3140  dst_row += 3;
3141  }
3142  }
3143  }
3144 
3145  vkUnmapMemory(qvk.device, qvk.screenshot_image_memory);
3146 
3147  *width = qvk.extent_unscaled.width;
3148  *height = qvk.extent_unscaled.height;
3149  *rowbytes = pitch;
3150  return pixels;
3151 }

Referenced by R_RegisterFunctionsRTX().

◆ IMG_Unload_RTX()

void IMG_Unload_RTX ( image_t image)

Definition at line 639 of file textures.c.

640 {
641  if(image->pix_data)
642  Z_Free(image->pix_data);
643  image->pix_data = NULL;
644 
645  const uint32_t index = image - r_images;
646 
647  if (tex_images[index])
648  {
649  const uint32_t frame_index = (qvk.frame_counter + MAX_FRAMES_IN_FLIGHT) % DESTROY_LATENCY;
650  UnusedResources* unused_resources = texture_system.unused_resources + frame_index;
651 
652  const uint32_t unused_index = unused_resources->image_num++;
653 
654  unused_resources->images[unused_index] = tex_images[index];
655  unused_resources->image_memory[unused_index] = tex_image_memory[index];
656  unused_resources->image_views[unused_index] = tex_image_views[index];
657 
658  tex_images[index] = VK_NULL_HANDLE;
659  tex_image_views[index] = VK_NULL_HANDLE;
660 
662  }
663 }

Referenced by R_RegisterFunctionsRTX().

◆ initialize_transparency()

qboolean initialize_transparency ( )

Definition at line 114 of file transparency.c.

115 {
116  cvar_pt_particle_size = Cvar_Get("pt_particle_size", "0.35", 0);
117  cvar_pt_beam_width = Cvar_Get("pt_beam_width", "1.0", 0);
118  cvar_pt_beam_lights = Cvar_Get("pt_beam_lights", "1.0", 0);
119 
120  memset(&transparency, 0, sizeof(transparency));
121 
122  const size_t particle_vertex_position_max_size = TR_VERTEX_MAX_NUM * TR_POSITION_SIZE;
123  const size_t particle_color_size = TR_PARTICLE_MAX_NUM * TR_COLOR_SIZE;
124  const size_t particle_data_size = particle_vertex_position_max_size + particle_color_size;
125 
126  const size_t beam_vertex_position_max_size = TR_BEAM_MAX_NUM * TR_POSITION_SIZE;
127  const size_t beam_color_size = TR_BEAM_MAX_NUM * TR_COLOR_SIZE;
128  const size_t beam_data_size = beam_vertex_position_max_size + beam_color_size;
129 
130  const size_t sprite_vertex_position_max_size = TR_SPRITE_MAX_NUM * TR_POSITION_SIZE;
131  const size_t sprite_info_size = TR_SPRITE_MAX_NUM * TR_SPRITE_INFO_SIZE;
132  const size_t sprite_data_size = sprite_vertex_position_max_size + sprite_info_size;
133 
134  transparency.host_buffered_frame_num = MAX_FRAMES_IN_FLIGHT;
135  transparency.host_frame_size = particle_data_size + beam_data_size + sprite_data_size;
136  transparency.host_buffer_size = transparency.host_buffered_frame_num * transparency.host_frame_size;
137 
140 
142  return qfalse;
143 
147 
148  return qtrue;
149 }

Referenced by vkpt_initialize_all().

◆ inverse()

void inverse ( const float *  m,
float *  inv 
)

Definition at line 158 of file matrix.c.

159 {
160  inv[0] = m[5] * m[10] * m[15] -
161  m[5] * m[11] * m[14] -
162  m[9] * m[6] * m[15] +
163  m[9] * m[7] * m[14] +
164  m[13] * m[6] * m[11] -
165  m[13] * m[7] * m[10];
166 
167  inv[1] = -m[1] * m[10] * m[15] +
168  m[1] * m[11] * m[14] +
169  m[9] * m[2] * m[15] -
170  m[9] * m[3] * m[14] -
171  m[13] * m[2] * m[11] +
172  m[13] * m[3] * m[10];
173 
174  inv[2] = m[1] * m[6] * m[15] -
175  m[1] * m[7] * m[14] -
176  m[5] * m[2] * m[15] +
177  m[5] * m[3] * m[14] +
178  m[13] * m[2] * m[7] -
179  m[13] * m[3] * m[6];
180 
181  inv[3] = -m[1] * m[6] * m[11] +
182  m[1] * m[7] * m[10] +
183  m[5] * m[2] * m[11] -
184  m[5] * m[3] * m[10] -
185  m[9] * m[2] * m[7] +
186  m[9] * m[3] * m[6];
187 
188  inv[4] = -m[4] * m[10] * m[15] +
189  m[4] * m[11] * m[14] +
190  m[8] * m[6] * m[15] -
191  m[8] * m[7] * m[14] -
192  m[12] * m[6] * m[11] +
193  m[12] * m[7] * m[10];
194 
195  inv[5] = m[0] * m[10] * m[15] -
196  m[0] * m[11] * m[14] -
197  m[8] * m[2] * m[15] +
198  m[8] * m[3] * m[14] +
199  m[12] * m[2] * m[11] -
200  m[12] * m[3] * m[10];
201 
202  inv[6] = -m[0] * m[6] * m[15] +
203  m[0] * m[7] * m[14] +
204  m[4] * m[2] * m[15] -
205  m[4] * m[3] * m[14] -
206  m[12] * m[2] * m[7] +
207  m[12] * m[3] * m[6];
208 
209  inv[7] = m[0] * m[6] * m[11] -
210  m[0] * m[7] * m[10] -
211  m[4] * m[2] * m[11] +
212  m[4] * m[3] * m[10] +
213  m[8] * m[2] * m[7] -
214  m[8] * m[3] * m[6];
215 
216  inv[8] = m[4] * m[9] * m[15] -
217  m[4] * m[11] * m[13] -
218  m[8] * m[5] * m[15] +
219  m[8] * m[7] * m[13] +
220  m[12] * m[5] * m[11] -
221  m[12] * m[7] * m[9];
222 
223  inv[9] = -m[0] * m[9] * m[15] +
224  m[0] * m[11] * m[13] +
225  m[8] * m[1] * m[15] -
226  m[8] * m[3] * m[13] -
227  m[12] * m[1] * m[11] +
228  m[12] * m[3] * m[9];
229 
230  inv[10] = m[0] * m[5] * m[15] -
231  m[0] * m[7] * m[13] -
232  m[4] * m[1] * m[15] +
233  m[4] * m[3] * m[13] +
234  m[12] * m[1] * m[7] -
235  m[12] * m[3] * m[5];
236 
237  inv[11] = -m[0] * m[5] * m[11] +
238  m[0] * m[7] * m[9] +
239  m[4] * m[1] * m[11] -
240  m[4] * m[3] * m[9] -
241  m[8] * m[1] * m[7] +
242  m[8] * m[3] * m[5];
243 
244  inv[12] = -m[4] * m[9] * m[14] +
245  m[4] * m[10] * m[13] +
246  m[8] * m[5] * m[14] -
247  m[8] * m[6] * m[13] -
248  m[12] * m[5] * m[10] +
249  m[12] * m[6] * m[9];
250 
251  inv[13] = m[0] * m[9] * m[14] -
252  m[0] * m[10] * m[13] -
253  m[8] * m[1] * m[14] +
254  m[8] * m[2] * m[13] +
255  m[12] * m[1] * m[10] -
256  m[12] * m[2] * m[9];
257 
258  inv[14] = -m[0] * m[5] * m[14] +
259  m[0] * m[6] * m[13] +
260  m[4] * m[1] * m[14] -
261  m[4] * m[2] * m[13] -
262  m[12] * m[1] * m[6] +
263  m[12] * m[2] * m[5];
264 
265  inv[15] = m[0] * m[5] * m[10] -
266  m[0] * m[6] * m[9] -
267  m[4] * m[1] * m[10] +
268  m[4] * m[2] * m[9] +
269  m[8] * m[1] * m[6] -
270  m[8] * m[2] * m[5];
271 
272  float det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12];
273 
274  det = 1.0f / det;
275 
276  for(int i = 0; i < 16; i++)
277  inv[i] = inv[i] * det;
278 }

Referenced by prepare_ubo().

◆ load_img()

qerror_t load_img ( const char *  name,
image_t image 
)

Definition at line 927 of file images.c.

928 {
929  byte *pic;
930  imageformat_t fmt;
931  qerror_t ret;
932 
933  size_t len = strlen(name);
934 
935  // must have an extension and at least 1 char of base name
936  if (len <= 4) {
937  return Q_ERR_NAMETOOSHORT;
938  }
939  if (name[len - 4] != '.') {
940  return Q_ERR_INVALID_PATH;
941  }
942 
943  memcpy(image->name, name, len + 1);
944  image->baselen = len - 4;
945  image->type = 0;
946  image->flags = 0;
947  image->registration_sequence = 1;
948 
949  // find out original extension
950  for (fmt = 0; fmt < IM_MAX; fmt++) {
951  if (!Q_stricmp(image->name + image->baselen + 1, img_loaders[fmt].ext)) {
952  break;
953  }
954  }
955 
956  // load the pic from disk
957  pic = NULL;
958 
959  // first try with original extension
960  ret = _try_image_format(fmt, image, &pic);
961  if (ret == Q_ERR_NOENT) {
962  // retry with remaining extensions
963  ret = try_other_formats(fmt, image, &pic);
964  }
965 
966  // if we are replacing 8-bit texture with a higher resolution 32-bit
967  // texture, we need to recover original image dimensions
968  if (fmt <= IM_WAL && ret > IM_WAL) {
969  get_image_dimensions(fmt, image);
970  }
971 
972  // if we are replacing 8-bit texture with a higher resolution 32-bit
973  // texture, we need to recover original image dimensions
974  if (fmt <= IM_WAL && ret > IM_WAL) {
975  get_image_dimensions(fmt, image);
976  }
977 
978  if (ret < 0) {
979  memset(image, 0, sizeof(*image));
980  return ret;
981  }
982 
983 #if USE_REF == REF_VKPT
984  image->pix_data = pic;
985 #endif
986 
987  return Q_ERR_SUCCESS;
988 }

Referenced by IMG_ReloadAll().

◆ MOD_LoadMD2_RTX()

qerror_t MOD_LoadMD2_RTX ( model_t *  model,
const void rawdata,
size_t  length 
)

Definition at line 186 of file models.c.

187 {
188  dmd2header_t header;
189  dmd2frame_t *src_frame;
190  dmd2trivertx_t *src_vert;
191  dmd2triangle_t *src_tri;
192  dmd2stvert_t *src_tc;
193  char *src_skin;
194  maliasframe_t *dst_frame;
195  maliasmesh_t *dst_mesh;
196  int val;
197  uint16_t remap[TESS_MAX_INDICES];
198  uint16_t vertIndices[TESS_MAX_INDICES];
199  uint16_t tcIndices[TESS_MAX_INDICES];
200  uint16_t finalIndices[TESS_MAX_INDICES];
201  int numverts, numindices;
202  char skinname[MAX_QPATH];
203  vec_t scale_s, scale_t;
204  vec3_t mins, maxs;
205  qerror_t ret;
206 
207  if (length < sizeof(header)) {
208  return Q_ERR_FILE_TOO_SMALL;
209  }
210 
211  // byte swap the header
212  header = *(dmd2header_t *)rawdata;
213  for (int i = 0; i < sizeof(header) / 4; i++) {
214  ((uint32_t *)&header)[i] = LittleLong(((uint32_t *)&header)[i]);
215  }
216 
217  // validate the header
218  ret = MOD_ValidateMD2(&header, length);
219  if (ret) {
220  if (ret == Q_ERR_TOO_FEW) {
221  // empty models draw nothing
222  model->type = MOD_EMPTY;
223  return Q_ERR_SUCCESS;
224  }
225  return ret;
226  }
227 
228  // load all triangle indices
229  numindices = 0;
230  src_tri = (dmd2triangle_t *)((byte *)rawdata + header.ofs_tris);
231  for (int i = 0; i < header.num_tris; i++) {
232  int good = 1;
233  for (int j = 0; j < 3; j++) {
234  uint16_t idx_xyz = LittleShort(src_tri->index_xyz[j]);
235  uint16_t idx_st = LittleShort(src_tri->index_st[j]);
236 
237  // some broken models have 0xFFFF indices
238  if (idx_xyz >= header.num_xyz || idx_st >= header.num_st) {
239  good = 0;
240  break;
241  }
242 
243  vertIndices[numindices + j] = idx_xyz;
244  tcIndices[numindices + j] = idx_st;
245  }
246  if (good) {
247  // only count good triangles
248  numindices += 3;
249  }
250  src_tri++;
251  }
252 
253  if (numindices < 3) {
254  return Q_ERR_TOO_FEW;
255  }
256 
257  qboolean all_normals_same = qtrue;
258  int same_normal = -1;
259 
260  src_frame = (dmd2frame_t *)((byte *)rawdata + header.ofs_frames);
261  for (int i = 0; i < numindices; i++)
262  {
263  int v = vertIndices[i];
264  int normal = src_frame->verts[v].lightnormalindex;
265 
266  // detect if the model has broken normals - they are all the same in that case
267  // it happens with players/w_<weapon>.md2 models for example
268  if (same_normal < 0)
269  same_normal = normal;
270  else if (normal != same_normal)
271  all_normals_same = qfalse;
272  }
273 
274  for (int i = 0; i < numindices; i++) {
275  remap[i] = 0xFFFF;
276  }
277 
278  // remap all triangle indices
279  numverts = 0;
280  src_tc = (dmd2stvert_t *)((byte *)rawdata + header.ofs_st);
281  for (int i = 0; i < numindices; i++) {
282  if (remap[i] != 0xFFFF) {
283  continue; // already remapped
284  }
285 
286  // only dedup vertices if we're not regenerating normals
287  if (!all_normals_same)
288  {
289  for (int j = i + 1; j < numindices; j++) {
290  if (vertIndices[i] == vertIndices[j] &&
291  (src_tc[tcIndices[i]].s == src_tc[tcIndices[j]].s &&
292  src_tc[tcIndices[i]].t == src_tc[tcIndices[j]].t)) {
293  // duplicate vertex
294  remap[j] = i;
295  finalIndices[j] = numverts;
296  }
297  }
298  }
299 
300  // new vertex
301  remap[i] = i;
302  finalIndices[i] = numverts++;
303  }
304 
305  Hunk_Begin(&model->hunk, 50u<<20);
306  model->type = MOD_ALIAS;
307  model->nummeshes = 1;
308  model->numframes = header.num_frames;
309  model->meshes = MOD_Malloc(sizeof(maliasmesh_t));
310  model->frames = MOD_Malloc(header.num_frames * sizeof(maliasframe_t));
311 
312  dst_mesh = model->meshes;
313  dst_mesh->numtris = numindices / 3;
314  dst_mesh->numindices = numindices;
315  dst_mesh->numverts = numverts;
316  dst_mesh->numskins = header.num_skins;
317  dst_mesh->positions = MOD_Malloc(numverts * header.num_frames * sizeof(vec3_t));
318  dst_mesh->normals = MOD_Malloc(numverts * header.num_frames * sizeof(vec3_t));
319  dst_mesh->tex_coords = MOD_Malloc(numverts * header.num_frames * sizeof(vec2_t));
320  dst_mesh->tangents = MOD_Malloc(numverts * header.num_frames * sizeof(vec4_t));
321  dst_mesh->indices = MOD_Malloc(numindices * sizeof(int));
322 
323  if (dst_mesh->numtris != header.num_tris) {
324  Com_DPrintf("%s has %d bad triangles\n", model->name, header.num_tris - dst_mesh->numtris);
325  }
326 
327  // store final triangle indices
328  for (int i = 0; i < numindices; i++) {
329  dst_mesh->indices[i] = finalIndices[i];
330  }
331 
332  // load all skins
333  src_skin = (char *)rawdata + header.ofs_skins;
334  for (int i = 0; i < header.num_skins; i++) {
335  if (!Q_memccpy(skinname, src_skin, 0, sizeof(skinname))) {
336  ret = Q_ERR_STRING_TRUNCATED;
337  goto fail;
338  }
339  FS_NormalizePath(skinname, skinname);
340 
341  pbr_material_t * mat = MAT_FindPBRMaterial(skinname);
342  if (!mat)
343  Com_EPrintf("error finding material '%s'\n", skinname);
344 
345  image_t* image_diffuse = IMG_Find(skinname, IT_SKIN, IF_SRGB);
346  image_t* image_normals = NULL;
347  image_t* image_emissive = NULL;
348 
349  if (image_diffuse != R_NOTEXTURE)
350  {
351  // attempt loading the normals texture
352  if (!Q_strlcpy(skinname, src_skin, strlen(src_skin) - 3))
353  return Q_ERR_STRING_TRUNCATED;
354 
355  Q_concat(skinname, sizeof(skinname), skinname, "_n.tga", NULL);
356  FS_NormalizePath(skinname, skinname);
357  image_normals = IMG_Find(skinname, IT_SKIN, IF_NONE);
358  if (image_normals == R_NOTEXTURE) image_normals = NULL;
359 
360  // attempt loading the emissive texture
361  if (!Q_strlcpy(skinname, src_skin, strlen(src_skin) - 3))
362  return Q_ERR_STRING_TRUNCATED;
363 
364  Q_concat(skinname, sizeof(skinname), skinname, "_light.tga", NULL);
365  FS_NormalizePath(skinname, skinname);
366  image_emissive = IMG_Find(skinname, IT_SKIN, IF_SRGB);
367  if (image_emissive == R_NOTEXTURE) image_emissive = NULL;
368  }
369 
370  MAT_RegisterPBRMaterial(mat, image_diffuse, image_normals, image_emissive);
371 
372  dst_mesh->materials[i] = mat;
373 
374  src_skin += MD2_MAX_SKINNAME;
375  }
376 
377  // load all tcoords
378  src_tc = (dmd2stvert_t *)((byte *)rawdata + header.ofs_st);
379  scale_s = 1.0f / header.skinwidth;
380  scale_t = 1.0f / header.skinheight;
381 
382  // load all frames
383  src_frame = (dmd2frame_t *)((byte *)rawdata + header.ofs_frames);
384  dst_frame = model->frames;
385  for (int j = 0; j < header.num_frames; j++) {
386  LittleVector(src_frame->scale, dst_frame->scale);
387  LittleVector(src_frame->translate, dst_frame->translate);
388 
389  // load frame vertices
390  ClearBounds(mins, maxs);
391 
392  for (int i = 0; i < numindices; i++) {
393  if (remap[i] != i) {
394  continue;
395  }
396  src_vert = &src_frame->verts[vertIndices[i]];
397  vec3_t *dst_pos = &dst_mesh->positions [j * numverts + finalIndices[i]];
398  vec3_t *dst_nrm = &dst_mesh->normals [j * numverts + finalIndices[i]];
399  vec2_t *dst_tc = &dst_mesh->tex_coords[j * numverts + finalIndices[i]];
400 
401  (*dst_tc)[0] = scale_s * src_tc[tcIndices[i]].s;
402  (*dst_tc)[1] = scale_t * src_tc[tcIndices[i]].t;
403 
404  (*dst_pos)[0] = src_vert->v[0] * dst_frame->scale[0] + dst_frame->translate[0];
405  (*dst_pos)[1] = src_vert->v[1] * dst_frame->scale[1] + dst_frame->translate[1];
406  (*dst_pos)[2] = src_vert->v[2] * dst_frame->scale[2] + dst_frame->translate[2];
407 
408  (*dst_nrm)[0] = 0.0f;
409  (*dst_nrm)[1] = 0.0f;
410  (*dst_nrm)[2] = 0.0f;
411 
412  val = src_vert->lightnormalindex;
413 
414  if (val < NUMVERTEXNORMALS) {
415  (*dst_nrm)[0] = bytedirs[val][0];
416  (*dst_nrm)[1] = bytedirs[val][1];
417  (*dst_nrm)[2] = bytedirs[val][2];
418  }
419 
420  for (int k = 0; k < 3; k++) {
421  val = (*dst_pos)[k];
422  if (val < mins[k])
423  mins[k] = val;
424  if (val > maxs[k])
425  maxs[k] = val;
426  }
427  }
428 
429  // if all normals are the same, rebuild them as flat triangle normals
430  if (all_normals_same)
431  {
432  for (int tri = 0; tri < numindices / 3; tri++)
433  {
434  int i0 = j * numverts + finalIndices[tri * 3 + 0];
435  int i1 = j * numverts + finalIndices[tri * 3 + 1];
436  int i2 = j * numverts + finalIndices[tri * 3 + 2];
437 
438  vec3_t *p0 = &dst_mesh->positions[i0];
439  vec3_t *p1 = &dst_mesh->positions[i1];
440  vec3_t *p2 = &dst_mesh->positions[i2];
441 
442  vec3_t e1, e2, n;
443  VectorSubtract(*p1, *p0, e1);
444  VectorSubtract(*p2, *p0, e2);
445  CrossProduct(e2, e1, n);
446  VectorNormalize(n);
447 
448  VectorCopy(n, dst_mesh->normals[i0]);
449  VectorCopy(n, dst_mesh->normals[i1]);
450  VectorCopy(n, dst_mesh->normals[i2]);
451  }
452  }
453 
454  VectorVectorScale(mins, dst_frame->scale, mins);
455  VectorVectorScale(maxs, dst_frame->scale, maxs);
456 
457  dst_frame->radius = RadiusFromBounds(mins, maxs);
458 
459  VectorAdd(mins, dst_frame->translate, dst_frame->bounds[0]);
460  VectorAdd(maxs, dst_frame->translate, dst_frame->bounds[1]);
461 
462  src_frame = (dmd2frame_t *)((byte *)src_frame + header.framesize);
463  dst_frame++;
464  }
465 
466  // fix winding order
467  for (int i = 0; i < dst_mesh->numindices; i += 3) {
468  int tmp = dst_mesh->indices[i + 1];
469  dst_mesh->indices[i + 1] = dst_mesh->indices[i + 2];
470  dst_mesh->indices[i + 2] = tmp;
471  }
472 
473  computeTangents(model);
474 
475  Hunk_End(&model->hunk);
476  return Q_ERR_SUCCESS;
477 
478 fail:
479  Hunk_Free(&model->hunk);
480  return ret;
481 }

Referenced by R_RegisterFunctionsRTX().

◆ MOD_LoadMD3_RTX()

qerror_t MOD_LoadMD3_RTX ( model_t *  model,
const void rawdata,
size_t  length 
)

Referenced by R_RegisterFunctionsRTX().

◆ MOD_Reference_RTX()

void MOD_Reference_RTX ( model_t *  model)

Definition at line 731 of file models.c.

732 {
733  int mesh_idx, skin_idx, frame_idx;
734 
735  // register any images used by the models
736  switch (model->type) {
737  case MOD_ALIAS:
738  for (mesh_idx = 0; mesh_idx < model->nummeshes; mesh_idx++) {
739  maliasmesh_t *mesh = &model->meshes[mesh_idx];
740  for (skin_idx = 0; skin_idx < mesh->numskins; skin_idx++) {
741  MAT_UpdateRegistration(mesh->materials[skin_idx]);
742  }
743  }
744  break;
745  case MOD_SPRITE:
746  for (frame_idx = 0; frame_idx < model->numframes; frame_idx++) {
747  model->spriteframes[frame_idx].image->registration_sequence = registration_sequence;
748  }
749  break;
750  case MOD_EMPTY:
751  break;
752  default:
753  Com_Error(ERR_FATAL, "%s: bad model type", __func__);
754  }
755 
756  model->registration_sequence = registration_sequence;
757 }

Referenced by R_RegisterFunctionsRTX().

◆ mult_matrix_matrix()

void mult_matrix_matrix ( float *  p,
const float *  a,
const float *  b 
)

Definition at line 281 of file matrix.c.

282 {
283  for(int i = 0; i < 4; i++) {
284  for(int j = 0; j < 4; j++) {
285  p[i * 4 + j] =
286  a[0 * 4 + j] * b[i * 4 + 0] +
287  a[1 * 4 + j] * b[i * 4 + 1] +
288  a[2 * 4 + j] * b[i * 4 + 2] +
289  a[3 * 4 + j] * b[i * 4 + 3];
290  }
291  }
292 }

Referenced by prepare_ubo(), UpdateTerrainShadowMapView(), and vkpt_shadow_map_setup().

◆ mult_matrix_vector()

void mult_matrix_vector ( float *  p,
const float *  a,
const float *  b 
)

Definition at line 295 of file matrix.c.

296 {
297  int j;
298  for (j = 0; j < 4; j++) {
299  p[j] =
300  a[0 * 4 + j] * b[0] +
301  a[1 * 4 + j] * b[1] +
302  a[2 * 4 + j] * b[2] +
303  a[3 * 4 + j] * b[3];
304  }
305 }

Referenced by process_regular_entity(), transform_point(), and vkpt_shadow_map_setup().

◆ qvk_get_current_desc_set_textures()

◆ 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_InterceptKey_RTX()

qboolean R_InterceptKey_RTX ( unsigned  key,
qboolean  down 
)

Definition at line 185 of file freecam.c.

186 {
187  if (cl_paused->integer != 2 || !sv_paused->integer)
188  return qfalse;
189 
190  const char* kb = Key_GetBindingForKey(key);
191  if (kb && strstr(kb, "pause"))
192  return qfalse;
193 
194  if (cvar_pt_dof->integer != 0 && down && (key == K_MWHEELUP || key == K_MWHEELDOWN))
195  {
196  cvar_t* var;
197  float minvalue;
198  float maxvalue;
199 
200  if (Key_IsDown(K_SHIFT))
201  {
202  var = cvar_pt_aperture;
203  minvalue = 0.01f;
204  maxvalue = 10.f;
205  }
206  else
207  {
208  var = cvar_pt_focus;
209  minvalue = 1.f;
210  maxvalue = 10000.f;
211  }
212 
213  float factor = Key_IsDown(K_CTRL) ? 1.01f : 1.1f;
214 
215  if (key == K_MWHEELDOWN)
216  factor = 1.f / factor;
217 
218  float value = var->value;
219  value *= factor;
220  value = max(minvalue, min(maxvalue, value));
221  Cvar_SetByVar(var, va("%f", value), FROM_CONSOLE);
222 
223  return qtrue;
224  }
225 
226  switch (key)
227  {
228  case 'w': freecam_keystate[0] = down; return qtrue;
229  case 's': freecam_keystate[1] = down; return qtrue;
230  case 'd': freecam_keystate[2] = down; return qtrue;
231  case 'a': freecam_keystate[3] = down; return qtrue;
232  case 'e': freecam_keystate[4] = down; return qtrue;
233  case 'q': freecam_keystate[5] = down; return qtrue;
234 
235  // make sure that other keys that control the freecam mode don't
236  // interfere with the game, for example MOUSE1 usually maps to fire
237  case K_CTRL:
238  case K_SHIFT:
239  case K_MWHEELDOWN:
240  case K_MWHEELUP:
241  case K_MOUSE1:
242  case K_MOUSE2:
243  return qtrue;
244  }
245 
246  return qfalse;
247 }

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().

◆ set_current_gpu()

void set_current_gpu ( VkCommandBuffer  cmd_buf,
int  gpu_index 
)

Definition at line 426 of file vk_util.c.

427 {
428 #ifdef VKPT_DEVICE_GROUPS
429  if (qvk.device_count > 1)
430  {
431  if(gpu_index == ALL_GPUS)
432  qvkCmdSetDeviceMaskKHR(cmd_buf, (1 << qvk.device_count) - 1);
433  else
434  qvkCmdSetDeviceMaskKHR(cmd_buf, 1 << gpu_index);
435  }
436 #endif
437 }

Referenced by vkpt_asvgf_create_gradient_samples(), vkpt_create_images(), vkpt_interleave(), vkpt_profiler_query(), vkpt_pt_trace_lighting(), vkpt_pt_trace_primary_rays(), and vkpt_pt_trace_reflections().

◆ update_transparency()

void update_transparency ( VkCommandBuffer  command_buffer,
const float *  view_matrix,
const particle_t *  particles,
int  particle_num,
const entity_t *  entities,
int  entity_num 
)

Definition at line 171 of file transparency.c.

173 {
174  transparency.host_frame_index = (transparency.host_frame_index + 1) % transparency.host_buffered_frame_num;
176 
177  uint32_t beam_num = 0;
178  uint32_t sprite_num = 0;
179  for (int i = 0; i < entity_num; i++)
180  {
181  if (entities[i].flags & RF_BEAM)
182  ++beam_num;
183  else if ((entities[i].model & 0x80000000) == 0)
184  {
185  const model_t* model = MOD_ForHandle(entities[i].model);
186  if (model && model->type == MOD_SPRITE)
187  ++sprite_num;
188  }
189  }
192 
193  transparency.beam_num = beam_num;
194  transparency.particle_num = particle_num;
195  transparency.sprite_num = sprite_num;
196 
197  const size_t particle_vertices_size = particle_num * 4 * TR_POSITION_SIZE;
198  const size_t beam_vertices_size = beam_num * 4 * TR_POSITION_SIZE;
199  const size_t sprite_vertices_size = sprite_num * 4 * TR_POSITION_SIZE;
200 
201  const size_t host_buffer_offset = transparency.host_frame_index * transparency.host_frame_size;
202 
203  transparency.vertex_position_host_offset = host_buffer_offset;
204  transparency.particle_color_host_offset = host_buffer_offset + particle_vertices_size + beam_vertices_size + sprite_vertices_size;
205  transparency.beam_color_host_offset = transparency.particle_color_host_offset + particle_num * TR_COLOR_SIZE;
206  transparency.sprite_info_host_offset = transparency.beam_color_host_offset + beam_num * TR_COLOR_SIZE;
207 
208  if (particle_num > 0 || beam_num > 0 || sprite_num > 0)
209  {
211  write_beam_geometry(view_matrix, entities, entity_num);
212  write_sprite_geometry(view_matrix, entities, entity_num);
213  upload_geometry(command_buffer);
214  }
215 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_asvgf_create_gradient_samples()

VkResult vkpt_asvgf_create_gradient_samples ( VkCommandBuffer  cmd_buf,
uint32_t  frame_num,
int  do_gradient_samples 
)

Definition at line 251 of file asvgf.c.

252 {
253  VkDescriptorSet desc_sets[] = {
257  };
258  VkClearColorValue clear_grd_smpl_pos = {
259  .uint32 = { 0, 0, 0, 0 }
260  };
261 
262  VkImageSubresourceRange subresource_range = {
263  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
264  .baseMipLevel = 0,
265  .levelCount = 1,
266  .baseArrayLayer = 0,
267  .layerCount = 1
268  };
269 
270  int current_sample_pos_image = VKPT_IMG_ASVGF_GRAD_SMPL_POS_A + (qvk.frame_counter & 1);
271 
272  BARRIER_TO_CLEAR(cmd_buf, qvk.images[current_sample_pos_image]);
273  vkCmdClearColorImage(cmd_buf, qvk.images[current_sample_pos_image],
274  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_grd_smpl_pos, 1, &subresource_range);
275  BARRIER_FROM_CLEAR(cmd_buf, qvk.images[current_sample_pos_image]);
276 
277  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_RNG_SEED_A + (qvk.frame_counter & 1)]);
278 
279  for(uint32_t gpu = 0; gpu < qvk.device_count; gpu++)
280  {
281  set_current_gpu(cmd_buf, gpu);
282 
283  uint32_t push_constants[1] = {
284  gpu
285  };
286 
287  vkCmdPushConstants(cmd_buf, pipeline_layout_atrous,
288  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants), push_constants);
289 
290  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[SEED_RNG]);
291  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
292  pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
293  vkCmdDispatch(cmd_buf,
294  (qvk.gpu_slice_width + 15) / 16,
295  (qvk.extent_render.height + 15) / 16,
296  1);
297  }
298 
299  set_current_gpu(cmd_buf, ALL_GPUS);
300 
301  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_RNG_SEED_A + (qvk.frame_counter & 1)]);
302 
303  if (do_gradient_samples)
304  {
305  BEGIN_PERF_MARKER(cmd_buf, PROFILER_ASVGF_DO_GRADIENT_SAMPLES);
306 
307  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[FWD_PROJECT]);
308  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
309  pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
310  vkCmdDispatch(cmd_buf,
311  (qvk.gpu_slice_width_prev / GRAD_DWN + 15) / 16,
312  (qvk.extent_render_prev.height / GRAD_DWN + 15) / 16,
313  1);
314 
315  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_RNG_SEED_A + (qvk.frame_counter & 1)]);
316  BARRIER_COMPUTE(cmd_buf, qvk.images[current_sample_pos_image]);
317 
318  END_PERF_MARKER(cmd_buf, PROFILER_ASVGF_DO_GRADIENT_SAMPLES);
319  }
320 
321  return VK_SUCCESS;
322 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_asvgf_create_pipelines()

VkResult vkpt_asvgf_create_pipelines ( )

Definition at line 91 of file asvgf.c.

92 {
93  VkSpecializationMapEntry specEntries[] = {
94  { .constantID = 0, .offset = 0, .size = sizeof(uint32_t) }
95  };
96 
97  uint32_t spec_data[] = {
98  0,
99  1,
100  2,
101  3
102  };
103 
104  VkSpecializationInfo specInfo[] = {
105  { .mapEntryCount = 1, .pMapEntries = specEntries, .dataSize = sizeof(uint32_t), .pData = &spec_data[0] },
106  { .mapEntryCount = 1, .pMapEntries = specEntries, .dataSize = sizeof(uint32_t), .pData = &spec_data[1] },
107  { .mapEntryCount = 1, .pMapEntries = specEntries, .dataSize = sizeof(uint32_t), .pData = &spec_data[2] },
108  { .mapEntryCount = 1, .pMapEntries = specEntries, .dataSize = sizeof(uint32_t), .pData = &spec_data[3] },
109  };
110 
111  VkComputePipelineCreateInfo pipeline_info[ASVGF_NUM_PIPELINES] = {
112  [SEED_RNG] = {
113  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
114  .stage = SHADER_STAGE(QVK_MOD_ASVGF_SEED_RNG_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
115  .layout = pipeline_layout_atrous,
116  },
117  [FWD_PROJECT] = {
118  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
119  .stage = SHADER_STAGE(QVK_MOD_ASVGF_FWD_PROJECT_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
120  .layout = pipeline_layout_general,
121  },
122  [GRADIENT_IMAGE] = {
123  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
124  .stage = SHADER_STAGE(QVK_MOD_ASVGF_GRADIENT_IMG_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
125  .layout = pipeline_layout_general,
126  },
127  [GRADIENT_ATROUS] = {
128  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
129  .stage = SHADER_STAGE(QVK_MOD_ASVGF_GRADIENT_ATROUS_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
130  .layout = pipeline_layout_atrous,
131  },
132  [TEMPORAL] = {
133  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
134  .stage = SHADER_STAGE(QVK_MOD_ASVGF_TEMPORAL_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
135  .layout = pipeline_layout_general,
136  },
137  [ATROUS_LF] = {
138  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
139  .stage = SHADER_STAGE(QVK_MOD_ASVGF_LF_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
140  .layout = pipeline_layout_atrous,
141  },
142  [ATROUS_ITER_0] = {
143  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
144  .stage = SHADER_STAGE_SPEC(QVK_MOD_ASVGF_ATROUS_COMP, VK_SHADER_STAGE_COMPUTE_BIT, &specInfo[0]),
145  .layout = pipeline_layout_atrous,
146  },
147  [ATROUS_ITER_1] = {
148  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
149  .stage = SHADER_STAGE_SPEC(QVK_MOD_ASVGF_ATROUS_COMP, VK_SHADER_STAGE_COMPUTE_BIT, &specInfo[1]),
150  .layout = pipeline_layout_atrous,
151  },
152  [ATROUS_ITER_2] = {
153  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
154  .stage = SHADER_STAGE_SPEC(QVK_MOD_ASVGF_ATROUS_COMP, VK_SHADER_STAGE_COMPUTE_BIT, &specInfo[2]),
155  .layout = pipeline_layout_atrous,
156  },
157  [ATROUS_ITER_3] = {
158  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
159  .stage = SHADER_STAGE_SPEC(QVK_MOD_ASVGF_ATROUS_COMP, VK_SHADER_STAGE_COMPUTE_BIT, &specInfo[3]),
160  .layout = pipeline_layout_atrous,
161  },
163  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
164  .stage = SHADER_STAGE(QVK_MOD_CHECKERBOARD_INTERLEAVE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
165  .layout = pipeline_layout_general,
166  },
167  [TAA] = {
168  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
169  .stage = SHADER_STAGE(QVK_MOD_ASVGF_TAA_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
170  .layout = pipeline_layout_general,
171  },
172  [COMPOSITING] = {
173  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
174  .stage = SHADER_STAGE(QVK_MOD_COMPOSITING_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
175  .layout = pipeline_layout_general,
176  },
177  };
178 
179  _VK(vkCreateComputePipelines(qvk.device, 0, LENGTH(pipeline_info), pipeline_info, 0, pipeline_asvgf));
180 
181  return VK_SUCCESS;
182 }

◆ vkpt_asvgf_destroy()

VkResult vkpt_asvgf_destroy ( )

Definition at line 81 of file asvgf.c.

82 {
83  vkDestroyPipelineLayout(qvk.device, pipeline_layout_atrous, NULL);
84  vkDestroyPipelineLayout(qvk.device, pipeline_layout_general, NULL);
85  vkDestroyPipelineLayout(qvk.device, pipeline_layout_taa, NULL);
86 
87  return VK_SUCCESS;
88 }

◆ vkpt_asvgf_destroy_pipelines()

VkResult vkpt_asvgf_destroy_pipelines ( )

Definition at line 185 of file asvgf.c.

186 {
187  for(int i = 0; i < ASVGF_NUM_PIPELINES; i++)
188  vkDestroyPipeline(qvk.device, pipeline_asvgf[i], NULL);
189  return VK_SUCCESS;
190 }

◆ vkpt_asvgf_filter()

VkResult vkpt_asvgf_filter ( VkCommandBuffer  cmd_buf,
qboolean  enable_lf 
)

Definition at line 325 of file asvgf.c.

326 {
327  VkDescriptorSet desc_sets[] = {
331  };
332  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_SH]);
333  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_COCG]);
334  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_HF]);
335  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_SPEC]);
336 
337  BEGIN_PERF_MARKER(cmd_buf, PROFILER_ASVGF_RECONSTRUCT_GRADIENT);
338 
339  /* create gradient image */
340  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[GRADIENT_IMAGE]);
341  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
342  pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
343  vkCmdDispatch(cmd_buf,
344  (qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
345  (qvk.extent_render.height / GRAD_DWN + 15) / 16,
346  1);
347 
348  // XXX BARRIERS!!!
349  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_LF_PING]);
350  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_HF_SPEC_PING]);
351 
352  //vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[GRADIENT_ATROUS]);
353  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
354  pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
355 
356  /* reconstruct gradient image */
357  const int num_atrous_iterations_gradient = 7;
358  for(int i = 0; i < num_atrous_iterations_gradient; i++) {
359  uint32_t push_constants[1] = {
360  i
361  };
362 
363  vkCmdPushConstants(cmd_buf, pipeline_layout_atrous,
364  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants), push_constants);
365 
366  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[GRADIENT_ATROUS]);
367 
368  vkCmdDispatch(cmd_buf,
369  (qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
370  (qvk.extent_render.height / GRAD_DWN + 15) / 16,
371  1);
372  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_LF_PING + !(i & 1)]);
373  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_HF_SPEC_PING + !(i & 1)]);
374 
375  }
376 
377  END_PERF_MARKER(cmd_buf, PROFILER_ASVGF_RECONSTRUCT_GRADIENT);
378  BEGIN_PERF_MARKER(cmd_buf, PROFILER_ASVGF_TEMPORAL);
379 
380  /* temporal accumulation / filtering */
381  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[TEMPORAL]);
382  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
383  pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
384  vkCmdDispatch(cmd_buf,
385  (qvk.gpu_slice_width + 14) / 15,
386  (qvk.extent_render.height + 14) / 15,
387  1);
388 
389 
390  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_SH]);
391  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_COCG]);
392  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_HF]);
393  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_MOMENTS]);
394  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_FILTERED_SPEC_A + (qvk.frame_counter & 1)]);
395  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_HIST_MOMENTS_HF_A]);
396  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_HIST_MOMENTS_HF_B]);
397 
398  END_PERF_MARKER(cmd_buf, PROFILER_ASVGF_TEMPORAL);
399  BEGIN_PERF_MARKER(cmd_buf, PROFILER_ASVGF_ATROUS);
400 
401  //vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[ATROUS]);
402  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
403  pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
404 
405  /* spatial reconstruction filtering */
406  const int num_atrous_iterations = 4;
407  for(int i = 0; i < num_atrous_iterations; i++)
408  {
409  if (enable_lf)
410  {
411  uint32_t push_constants[1] = {
412  i
413  };
414 
415  vkCmdPushConstants(cmd_buf, pipeline_layout_atrous,
416  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants), push_constants);
417 
418  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[ATROUS_LF]);
419 
420  vkCmdDispatch(cmd_buf,
421  (qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
422  (qvk.extent_render.height / GRAD_DWN + 15) / 16,
423  1);
424 
425  if (i == num_atrous_iterations - 1)
426  {
427  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_SH]);
428  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_COCG]);
429  }
430  }
431 
432  int specialization = ATROUS_ITER_0 + i;
433 
434  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[specialization]);
435  vkCmdDispatch(cmd_buf,
436  (qvk.gpu_slice_width + 15) / 16,
437  (qvk.extent_render.height + 15) / 16,
438  1);
439 
440  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_SH]);
441  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_COCG]);
442  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_HF]);
443  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_MOMENTS]);
444  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PONG_LF_SH]);
445  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PONG_LF_COCG]);
446  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PONG_HF]);
447  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PONG_MOMENTS]);
448  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_HIST_COLOR_HF]);
449  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_SH + !(i & 1)]);
450  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_COCG + !(i & 1)]);
451  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_COLOR]);
452  }
453 
454  END_PERF_MARKER(cmd_buf, PROFILER_ASVGF_ATROUS);
455 
456  return VK_SUCCESS;
457 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_asvgf_initialize()

VkResult vkpt_asvgf_initialize ( )

Definition at line 45 of file asvgf.c.

46 {
47  VkDescriptorSetLayout desc_set_layouts[] = {
50  };
51 
52  VkPushConstantRange push_constant_range_atrous = {
53  .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
54  .offset = 0,
55  .size = sizeof(uint32_t)
56  };
57 
59  .setLayoutCount = LENGTH(desc_set_layouts),
60  .pSetLayouts = desc_set_layouts,
61  .pushConstantRangeCount = 1,
62  .pPushConstantRanges = &push_constant_range_atrous
63  );
65 
67  .setLayoutCount = LENGTH(desc_set_layouts),
68  .pSetLayouts = desc_set_layouts,
69  );
71 
73  .setLayoutCount = LENGTH(desc_set_layouts),
74  .pSetLayouts = desc_set_layouts,
75  );
77  return VK_SUCCESS;
78 }

◆ vkpt_begin_command_buffer()

VkCommandBuffer vkpt_begin_command_buffer ( cmd_buf_group_t group)

Definition at line 3301 of file main.c.

3302 {
3303  if (group->used_this_frame == group->count_per_frame)
3304  {
3305  uint32_t new_count = max(4, group->count_per_frame * 2);
3306  VkCommandBuffer* new_buffers = Z_Mallocz(new_count * MAX_FRAMES_IN_FLIGHT * sizeof(VkCommandBuffer));
3307 
3308  for (int frame = 0; frame < MAX_FRAMES_IN_FLIGHT; frame++)
3309  {
3310  if (group->count_per_frame > 0)
3311  {
3312  memcpy(new_buffers + new_count * frame, group->buffers + group->count_per_frame * frame, group->count_per_frame * sizeof(VkCommandBuffer));
3313  }
3314 
3315  VkCommandBufferAllocateInfo cmd_buf_alloc_info = {
3316  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
3317  .commandPool = group->command_pool,
3318  .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
3319  .commandBufferCount = new_count - group->count_per_frame
3320  };
3321 
3322  _VK(vkAllocateCommandBuffers(qvk.device, &cmd_buf_alloc_info, new_buffers + new_count * frame + group->count_per_frame));
3323  }
3324 
3325 #ifdef _DEBUG
3326  void** new_addrs = Z_Mallocz(new_count * MAX_FRAMES_IN_FLIGHT * sizeof(void*));
3327 
3328  if (group->count_per_frame > 0)
3329  {
3330  for (int frame = 0; frame < MAX_FRAMES_IN_FLIGHT; frame++)
3331  {
3332  memcpy(new_addrs + new_count * frame, group->buffer_begin_addrs + group->count_per_frame * frame, group->count_per_frame * sizeof(void*));
3333  }
3334  }
3335 
3336  Z_Free(group->buffer_begin_addrs);
3337  group->buffer_begin_addrs = new_addrs;
3338 #endif
3339 
3340  Z_Free(group->buffers);
3341  group->buffers = new_buffers;
3342  group->count_per_frame = new_count;
3343  }
3344 
3345  VkCommandBuffer cmd_buf = group->buffers[group->count_per_frame * qvk.current_frame_index + group->used_this_frame];
3346 
3347  VkCommandBufferBeginInfo begin_info = {
3348  .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
3349  .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
3350  .pInheritanceInfo = NULL,
3351  };
3352  _VK(vkResetCommandBuffer(cmd_buf, 0));
3353  _VK(vkBeginCommandBuffer(cmd_buf, &begin_info));
3354 
3355 
3356 #ifdef _DEBUG
3357  void** begin_addr = group->buffer_begin_addrs + group->count_per_frame * qvk.current_frame_index + group->used_this_frame;
3358 
3359 #if (defined __GNUC__)
3360  *begin_addr = __builtin_return_address(0);
3361 #elif (defined _MSC_VER)
3362  *begin_addr = _ReturnAddress();
3363 #else
3364  *begin_addr = NULL;
3365 #endif
3366 #endif
3367 
3368  group->used_this_frame += 1;
3369 
3370  return cmd_buf;
3371 }

Referenced by change_image_layouts(), create_invalid_texture(), create_swapchain(), fill_index_buffer(), FillVertexAndIndexBuffers(), IMG_ReadPixels_RTX(), load_blue_noise(), R_BeginFrame_RTX(), R_EndFrame_RTX(), R_RenderFrame_RTX(), UploadImage(), vkpt_create_images(), vkpt_pt_create_static(), vkpt_shadow_map_initialize(), vkpt_textures_end_registration(), vkpt_textures_upload_envmap(), and vkpt_vertex_buffer_upload_staging().

◆ vkpt_bloom_create_pipelines()

VkResult vkpt_bloom_create_pipelines ( )

Definition at line 176 of file bloom.c.

177 {
178  VkComputePipelineCreateInfo pipeline_info[BLOOM_NUM_PIPELINES] = {
179  [BLUR] = {
180  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
181  .stage = SHADER_STAGE(QVK_MOD_BLOOM_BLUR_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
182  .layout = pipeline_layout_blur,
183  },
184  [COMPOSITE] = {
185  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
186  .stage = SHADER_STAGE(QVK_MOD_BLOOM_COMPOSITE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
187  .layout = pipeline_layout_composite,
188  }
189  };
190 
191  _VK(vkCreateComputePipelines(qvk.device, 0, LENGTH(pipeline_info), pipeline_info, 0, pipelines));
192  return VK_SUCCESS;
193 }

◆ vkpt_bloom_destroy()

VkResult vkpt_bloom_destroy ( )

Definition at line 165 of file bloom.c.

166 {
167  vkDestroyPipelineLayout(qvk.device, pipeline_layout_blur, NULL);
168  pipeline_layout_blur = NULL;
169  vkDestroyPipelineLayout(qvk.device, pipeline_layout_composite, NULL);
171 
172  return VK_SUCCESS;
173 }

◆ vkpt_bloom_destroy_pipelines()

VkResult vkpt_bloom_destroy_pipelines ( )

Definition at line 196 of file bloom.c.

197 {
198  for(int i = 0; i < BLOOM_NUM_PIPELINES; i++)
199  vkDestroyPipeline(qvk.device, pipelines[i], NULL);
200 
201  return VK_SUCCESS;
202 }

◆ vkpt_bloom_initialize()

VkResult vkpt_bloom_initialize ( )

Definition at line 127 of file bloom.c.

128 {
129  cvar_bloom_enable = Cvar_Get("bloom_enable", "1", 0);
130  cvar_bloom_debug = Cvar_Get("bloom_debug", "0", 0);
131  cvar_bloom_sigma = Cvar_Get("bloom_sigma", "0.037", 0); // relative to screen height
132  cvar_bloom_intensity = Cvar_Get("bloom_intensity", "0.002", 0);
133  cvar_bloom_sigma_water = Cvar_Get("bloom_sigma_water", "0.037", 0);
134  cvar_bloom_intensity_water = Cvar_Get("bloom_intensity_water", "0.2", 0);
135 
136  VkDescriptorSetLayout desc_set_layouts[] = {
139  };
140 
141  VkPushConstantRange push_constant_range = {
142  .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
143  .offset = 0,
144  .size = sizeof(push_constants_hblur)
145  };
146 
148  .setLayoutCount = LENGTH(desc_set_layouts),
149  .pSetLayouts = desc_set_layouts,
150  .pushConstantRangeCount = 1,
151  .pPushConstantRanges = &push_constant_range
152  );
154 
156  .setLayoutCount = LENGTH(desc_set_layouts),
157  .pSetLayouts = desc_set_layouts,
158  );
160 
161  return VK_SUCCESS;
162 }

◆ vkpt_bloom_record_cmd_buffer()

VkResult vkpt_bloom_record_cmd_buffer ( VkCommandBuffer  cmd_buf)

Definition at line 301 of file bloom.c.

302 {
304 
305  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
306 
307  // downscale TAA_OUTPUT -> BLOOM_DOWNSCALE_MIP_1 -> BLOOM_VBLUR
308  {
309  VkImageSubresourceLayers subresource = {
310  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
311  .mipLevel = 0,
312  .baseArrayLayer = 0,
313  .layerCount = 1
314  };
315 
316  VkOffset3D offset_UL = {
317  .x = 0,
318  .y = 0,
319  .z = 0
320  };
321 
322  VkOffset3D offset_LR_mip_0 = {
323  .x = qvk.extent_screen_images.width,
324  .y = qvk.extent_screen_images.height,
325  .z = 1
326  };
327 
328  VkOffset3D offset_LR_mip_1 = {
329  .x = qvk.extent_screen_images.width / 2,
330  .y = qvk.extent_screen_images.height / 2,
331  .z = 1
332  };
333 
334  VkOffset3D offset_LR_mip_2 = {
335  .x = qvk.extent_screen_images.width / 4,
336  .y = qvk.extent_screen_images.height / 4,
337  .z = 1
338  };
339 
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,
347  };
348 
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,
356  };
357 
358  BARRIER_TO_COPY_SRC(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
359  BARRIER_TO_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1]);
360 
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);
365 
366  BARRIER_FROM_COPY_SRC(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
367  BARRIER_FROM_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1]);
368 
369  BARRIER_TO_COPY_SRC(cmd_buf, qvk.images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1]);
370  BARRIER_TO_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
371 
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);
376 
377  BARRIER_FROM_COPY_SRC(cmd_buf, qvk.images[VKPT_IMG_BLOOM_DOWNSCALE_MIP_1]);
378  BARRIER_FROM_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
379  }
380 
381  VkDescriptorSet desc_sets[] = {
385  };
386 
387  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
388  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_HBLUR]);
389 
390  // apply horizontal blur from BLOOM_VBLUR -> BLOOM_HBLUR
391  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipelines[BLUR]);
392  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
393  pipeline_layout_blur, 0, LENGTH(desc_sets), desc_sets, 0, 0);
394 
395  vkCmdPushConstants(cmd_buf, pipeline_layout_blur, VK_SHADER_STAGE_COMPUTE_BIT,
397  vkCmdDispatch(cmd_buf,
398  (qvk.extent_render.width / 4 + 15) / 16,
399  (qvk.extent_render.height / 4 + 15) / 16,
400  1);
401 
402  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_HBLUR]);
403 
404  // vertical blur from BLOOM_HBLUR -> BLOOM_VBLUR
405  vkCmdPushConstants(cmd_buf, pipeline_layout_blur, VK_SHADER_STAGE_COMPUTE_BIT,
407  vkCmdDispatch(cmd_buf,
408  (qvk.extent_render.width / 4 + 15) / 16,
409  (qvk.extent_render.height / 4 + 15) / 16,
410  1);
411 
412  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
413 
414  if (cvar_bloom_debug->integer)
415  {
416  VkImageSubresourceLayers subresource = {
417  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
418  .mipLevel = 0,
419  .baseArrayLayer = 0,
420  .layerCount = 1
421  };
422 
423  VkOffset3D offset_UL = {
424  .x = 0,
425  .y = 0,
426  .z = 0
427  };
428 
429  VkOffset3D offset_LR_input = {
430  .x = IMG_WIDTH,
431  .y = IMG_HEIGHT,
432  .z = 1
433  };
434 
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,
441  };
442 
443  BARRIER_TO_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
444 
445  int vis_img;
446  switch(cvar_bloom_debug->integer)
447  {
448  case 1:
449  vis_img = VKPT_IMG_BLOOM_DOWNSCALE_MIP_1;
450  blit_region.srcOffsets[1].x = IMG_WIDTH / 2;
451  blit_region.srcOffsets[1].y = IMG_HEIGHT / 2;
452  break;
453 
454  case 2:
455  vis_img = VKPT_IMG_BLOOM_HBLUR;
456  blit_region.srcOffsets[1].x = IMG_WIDTH / 4;
457  blit_region.srcOffsets[1].y = IMG_HEIGHT / 4;
458  break;
459 
460  default:
461  vis_img = VKPT_IMG_BLOOM_VBLUR;
462  blit_region.srcOffsets[1].x = IMG_WIDTH / 4;
463  blit_region.srcOffsets[1].y = IMG_HEIGHT / 4;
464  break;
465  }
466 
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);
471 
472  BARRIER_FROM_COPY_DEST(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
473  } else {
474  // composite bloom into TAA_OUTPUT
475  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipelines[COMPOSITE]);
476  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
477  pipeline_layout_composite, 0, LENGTH(desc_sets), desc_sets, 0, 0);
478  vkCmdDispatch(cmd_buf,
479  (qvk.extent_render.width + 15) / 16,
480  (qvk.extent_render.height + 15) / 16,
481  1);
482  }
483 
484  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
485  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
486 
487 
488  return VK_SUCCESS;
489 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_bloom_reset()

void vkpt_bloom_reset ( )

Definition at line 76 of file bloom.c.

77 {
81 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_bloom_update()

void vkpt_bloom_update ( QVKUniformBuffer_t ubo,
float  frame_time,
qboolean  under_water,
qboolean  menu_mode 
)

Definition at line 88 of file bloom.c.

89 {
90  if (under_water)
91  {
92  under_water_animation = min(1.f, under_water_animation + frame_time * 3.f);
95  }
96  else
97  {
98  under_water_animation = max(0.f, under_water_animation - frame_time * 3.f);
101  }
102 
103  static int menu_start_ms = -1;
104 
105  if (menu_mode)
106  {
107  if (menu_start_ms < 0)
108  menu_start_ms = Sys_Milliseconds();
109  int current_ms = Sys_Milliseconds();
110 
111  float phase = max(0.f, min(1.f, (float)(current_ms - menu_start_ms) / 150.f));
112  phase = powf(phase, 0.25f);
113 
114  bloom_sigma = phase * 0.03f;
115 
116  ubo->bloom_intensity = 1.f;
117  }
118  else
119  {
120  menu_start_ms = -1;
121 
122  ubo->bloom_intensity = bloom_intensity;
123  }
124 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_build_beam_lights()

void vkpt_build_beam_lights ( light_poly_t light_list,
int num_lights,
int  max_lights,
bsp_t *  bsp,
entity_t *  entities,
int  num_entites,
float  adapted_luminance 
)

Definition at line 492 of file transparency.c.

493 {
494  const float beam_width = cvar_pt_beam_width->value;
495  const float hdr_factor = cvar_pt_beam_lights->value * adapted_luminance * 20.f;
496 
497  if (hdr_factor <= 0.f)
498  return;
499 
500  int num_beams = 0;
501 
502  static entity_t* beams[MAX_BEAMS];
503 
504  for (int i = 0; i < num_entites; i++)
505  {
506  if(num_beams == MAX_BEAMS)
507  break;
508 
509  if ((entities[i].flags & RF_BEAM) != 0)
510  beams[num_beams++] = entities + i;
511  }
512 
513  if (num_beams == 0)
514  return;
515 
516  qsort(beams, num_beams, sizeof(entity_t*), compare_beams);
517 
518  for (int i = 0; i < num_beams; i++)
519  {
520  if (*num_lights >= max_lights)
521  return;
522 
523  const entity_t* beam = beams[i];
524 
525  vec3_t begin;
526  vec3_t end;
527  VectorCopy(beam->oldorigin, begin);
528  VectorCopy(beam->origin, end);
529 
530  vec3_t to_end;
531  VectorSubtract(end, begin, to_end);
532 
533  vec3_t norm_dir;
534  VectorCopy(to_end, norm_dir);
535  VectorNormalize(norm_dir);
536  VectorMA(begin, -5.f, norm_dir, begin);
537  VectorMA(end, 5.f, norm_dir, end);
538 
539  vec3_t color;
540  cast_u32_to_f32_color(beam->skinnum, &beam->rgba, color, hdr_factor);
541 
542  vkpt_build_cylinder_light(light_list, num_lights, max_lights, bsp, begin, end, color, beam_width);
543  }
544 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_build_cylinder_light()

qboolean vkpt_build_cylinder_light ( light_poly_t light_list,
int num_lights,
int  max_lights,
bsp_t *  bsp,
vec3_t  begin,
vec3_t  end,
vec3_t  color,
float  radius 
)

Definition at line 408 of file transparency.c.

409 {
410  vec3_t dir, norm_dir;
411  VectorSubtract(end, begin, dir);
412  VectorCopy(dir, norm_dir);
413  VectorNormalize(norm_dir);
414 
415  vec3_t up = { 0.f, 0.f, 1.f };
416  vec3_t left = { 1.f, 0.f, 0.f };
417  if (fabsf(norm_dir[2]) < 0.9f)
418  {
419  CrossProduct(up, norm_dir, left);
420  VectorNormalize(left);
421  CrossProduct(norm_dir, left, up);
423  }
424  else
425  {
426  CrossProduct(norm_dir, left, up);
428  CrossProduct(up, norm_dir, left);
429  VectorNormalize(left);
430  }
431 
432 
433  vec3_t vertices[6] = {
434  { 0.f, 1.f, 0.f },
435  { 0.866f, -0.5f, 0.f },
436  { -0.866f, -0.5f, 0.f },
437  { 0.f, -1.f, 1.f },
438  { -0.866f, 0.5f, 1.f },
439  { 0.866f, 0.5f, 1.f },
440  };
441 
442  const int indices[18] = {
443  0, 4, 2,
444  2, 4, 3,
445  2, 3, 1,
446  1, 3, 5,
447  1, 5, 0,
448  0, 5, 4
449  };
450 
451  for (int vert = 0; vert < 6; vert++)
452  {
453  vec3_t transformed;
454  VectorCopy(begin, transformed);
455  VectorMA(transformed, vertices[vert][0] * radius, up, transformed);
456  VectorMA(transformed, vertices[vert][1] * radius, left, transformed);
457  VectorMA(transformed, vertices[vert][2], dir, transformed);
458  VectorCopy(transformed, vertices[vert]);
459  }
460 
461  for (int tri = 0; tri < 6; tri++)
462  {
463  if (*num_lights >= max_lights)
464  return qfalse;
465 
466  int i0 = indices[tri * 3 + 0];
467  int i1 = indices[tri * 3 + 1];
468  int i2 = indices[tri * 3 + 2];
469 
470  light_poly_t* light = light_list + *num_lights;
471 
472  VectorCopy(vertices[i0], light->positions + 0);
473  VectorCopy(vertices[i1], light->positions + 3);
474  VectorCopy(vertices[i2], light->positions + 6);
475  get_triangle_off_center(light->positions, light->off_center, NULL);
476 
477  light->cluster = BSP_PointLeaf(bsp->nodes, light->off_center)->cluster;
478  light->material = NULL;
479  light->style = 0;
480 
481  VectorCopy(color, light->color);
482 
483  if (light->cluster >= 0)
484  {
485  (*num_lights)++;
486  }
487  }
488 
489  return qtrue;
490 }

Referenced by process_regular_entity(), and vkpt_build_beam_lights().

◆ vkpt_compositing()

VkResult vkpt_compositing ( VkCommandBuffer  cmd_buf)

Definition at line 460 of file asvgf.c.

461 {
462  VkDescriptorSet desc_sets[] = {
466  };
467  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_SH]);
468  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_COCG]);
469  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_HF]);
470  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_SPEC]);
471 
472  BEGIN_PERF_MARKER(cmd_buf, PROFILER_COMPOSITING);
473 
474  /* create gradient image */
475  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[COMPOSITING]);
476  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
477  pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
478 
479  vkCmdDispatch(cmd_buf,
480  (qvk.gpu_slice_width + 15) / 16,
481  (qvk.extent_render.height + 15) / 16,
482  1);
483 
484  END_PERF_MARKER(cmd_buf, PROFILER_COMPOSITING);
485 
486  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_COLOR]);
487 
488  return VK_SUCCESS;
489 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_create_images()

VkResult vkpt_create_images ( )

Definition at line 1442 of file textures.c.

1443 {
1444  VkImageCreateInfo images_create_info[NUM_VKPT_IMAGES] = {
1445 #define IMG_DO(_name, _binding, _vkformat, _glslformat, _w, _h) \
1446  [VKPT_IMG_##_name] = { \
1447  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, \
1448  .imageType = VK_IMAGE_TYPE_2D, \
1449  .format = VK_FORMAT_##_vkformat, \
1450  .extent = { \
1451  .width = _w, \
1452  .height = _h, \
1453  .depth = 1 \
1454  }, \
1455  .mipLevels = 1, \
1456  .arrayLayers = 1, \
1457  .samples = VK_SAMPLE_COUNT_1_BIT, \
1458  .tiling = VK_IMAGE_TILING_OPTIMAL, \
1459  .usage = VK_IMAGE_USAGE_STORAGE_BIT \
1460  | VK_IMAGE_USAGE_TRANSFER_SRC_BIT \
1461  | VK_IMAGE_USAGE_TRANSFER_DST_BIT \
1462  | VK_IMAGE_USAGE_SAMPLED_BIT \
1463  | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, \
1464  .sharingMode = VK_SHARING_MODE_EXCLUSIVE, \
1465  .queueFamilyIndexCount = qvk.queue_idx_graphics, \
1466  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, \
1467  },
1470 #undef IMG_DO
1471  };
1472 
1473 #ifdef VKPT_DEVICE_GROUPS
1474 #define IMG_DO(_name, _binding, _vkformat, _glslformat, _w, _h) \
1475  images_create_info[VKPT_IMG_##_name].flags |= \
1476  VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT;
1479 #undef IMG_DO
1480 #endif
1481 
1482  size_t total_size = 0;
1483 
1484  for(int i = 0; i < NUM_VKPT_IMAGES; i++)
1485  {
1486  _VK(vkCreateImage(qvk.device, images_create_info + i, NULL, qvk.images + i));
1487  ATTACH_LABEL_VARIABLE(qvk.images[i], IMAGE);
1488 
1489  VkMemoryRequirements mem_req;
1490  vkGetImageMemoryRequirements(qvk.device, qvk.images[i], &mem_req);
1491 
1492  total_size += align(mem_req.size, mem_req.alignment);
1493 
1494  _VK(allocate_gpu_memory(mem_req, &mem_images[i]));
1495 
1496  ATTACH_LABEL_VARIABLE(mem_images[i], DEVICE_MEMORY);
1497 
1498  _VK(vkBindImageMemory(qvk.device, qvk.images[i], mem_images[i], 0));
1499 
1500 #ifdef VKPT_DEVICE_GROUPS
1501  if (qvk.device_count > 1) {
1502  // create per-device local image bindings so we can copy back and forth
1503 
1504  // create copies of the same image object that will receive full per-GPU mappings
1505  for(int d = 0; d < qvk.device_count; d++)
1506  {
1507  _VK(vkCreateImage(qvk.device, images_create_info + i, NULL, &qvk.images_local[d][i]));
1508  ATTACH_LABEL_VARIABLE(qvk.images_local[d][i], IMAGE);
1509 
1510  uint32_t device_indices[VKPT_MAX_GPUS];
1511 
1512  for (int j = 0; j < VKPT_MAX_GPUS; j++)
1513  {
1514  // all GPUs attach to memory on one device for this image object
1515  device_indices[j] = (uint32_t)d;
1516  }
1517 
1518  // shut up lunarg
1519  {
1520  VkMemoryRequirements mem_req;
1521  vkGetImageMemoryRequirements(qvk.device, qvk.images_local[d][i], &mem_req);
1522  }
1523 
1524  VkBindImageMemoryDeviceGroupInfoKHR device_group_info = {
1525  .sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_DEVICE_GROUP_INFO_KHR,
1526  .pNext = NULL,
1527  .deviceIndexCount = qvk.device_count,
1528  .pDeviceIndices = device_indices,
1529  .splitInstanceBindRegionCount = 0,
1530  .pSplitInstanceBindRegions = NULL,
1531  };
1532 
1533  VkBindImageMemoryInfoKHR bind_info = {
1534  .sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR,
1535  .pNext = &device_group_info,
1536  .image = qvk.images_local[d][i],
1537  .memory = mem_images[i],
1538  .memoryOffset = 0,
1539  };
1540 
1541  _VK(qvkBindImageMemory2KHR(qvk.device, 1, &bind_info));
1542  }
1543  }
1544 #endif
1545  }
1546 
1547  Com_Printf("Screen-space image memory: %.2f MB\n", (float)total_size / 1048576.f);
1548 
1549  /* attach labels to images */
1550 #define IMG_DO(_name, _binding, ...) \
1551  ATTACH_LABEL_VARIABLE_NAME(qvk.images[VKPT_IMG_##_name], IMAGE, #_name);
1552  LIST_IMAGES
1554 #undef IMG_DO
1555  /* attach labels to images */
1556 #define IMG_DO(_name, _binding, ...) \
1557  ATTACH_LABEL_VARIABLE_NAME(qvk.images[VKPT_IMG_##_name], IMAGE, #_name);
1558  LIST_IMAGES
1560 #undef IMG_DO
1561 
1562 
1563 #define IMG_DO(_name, _binding, _vkformat, _glslformat, _w, _h) \
1564  [VKPT_IMG_##_name] = { \
1565  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, \
1566  .viewType = VK_IMAGE_VIEW_TYPE_2D, \
1567  .format = VK_FORMAT_##_vkformat, \
1568  .image = qvk.images[VKPT_IMG_##_name], \
1569  .subresourceRange = { \
1570  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, \
1571  .baseMipLevel = 0, \
1572  .levelCount = 1, \
1573  .baseArrayLayer = 0, \
1574  .layerCount = 1 \
1575  }, \
1576  .components = { \
1577  VK_COMPONENT_SWIZZLE_R, \
1578  VK_COMPONENT_SWIZZLE_G, \
1579  VK_COMPONENT_SWIZZLE_B, \
1580  VK_COMPONENT_SWIZZLE_A \
1581  }, \
1582  },
1583 
1584  VkImageViewCreateInfo images_view_create_info[NUM_VKPT_IMAGES] = {
1585  LIST_IMAGES
1587  };
1588 #undef IMG_DO
1589 
1590 
1591  for(int i = 0; i < NUM_VKPT_IMAGES; i++) {
1592  _VK(vkCreateImageView(qvk.device, images_view_create_info + i, NULL, qvk.images_views + i));
1593 
1594 #ifdef VKPT_DEVICE_GROUPS
1595  if (qvk.device_count > 1) {
1596  for(int d = 0; d < qvk.device_count; d++) {
1597  VkImageViewCreateInfo info = images_view_create_info[i];
1598  info.image = qvk.images_local[d][i];
1599  _VK(vkCreateImageView(qvk.device, &info, NULL, &qvk.images_views_local[d][i]));
1600  }
1601  }
1602 #endif
1603  }
1604 
1605  /* attach labels to image views */
1606 #define IMG_DO(_name, ...) \
1607  ATTACH_LABEL_VARIABLE_NAME(qvk.images_views[VKPT_IMG_##_name], IMAGE_VIEW, #_name);
1608  LIST_IMAGES
1610 #undef IMG_DO
1611 
1612 #define IMG_DO(_name, ...) \
1613  [VKPT_IMG_##_name] = { \
1614  .sampler = VK_NULL_HANDLE, \
1615  .imageView = qvk.images_views[VKPT_IMG_##_name], \
1616  .imageLayout = VK_IMAGE_LAYOUT_GENERAL \
1617  },
1618  VkDescriptorImageInfo desc_output_img_info[] = {
1619  LIST_IMAGES
1621  };
1622 #undef IMG_DO
1623 
1624  VkDescriptorImageInfo img_info[] = {
1625 #define IMG_DO(_name, ...) \
1626  [VKPT_IMG_##_name] = { \
1627  .imageLayout = VK_IMAGE_LAYOUT_GENERAL, \
1628  .imageView = qvk.images_views[VKPT_IMG_##_name], \
1629  .sampler = qvk.tex_sampler, \
1630  },
1631 
1632  LIST_IMAGES
1634  };
1635 #undef IMG_DO
1636 
1637  for(int i = VKPT_IMG_BLOOM_HBLUR; i <= VKPT_IMG_BLOOM_VBLUR; i++) {
1638  img_info[i].sampler = qvk.tex_sampler_linear_clamp;
1639  }
1640 
1641  VkWriteDescriptorSet output_img_write[NUM_IMAGES * 2];
1642 
1643  for (int even_odd = 0; even_odd < 2; even_odd++)
1644  {
1645  /* create information to update descriptor sets */
1646 #define IMG_DO(_name, _binding, ...) { \
1647  VkWriteDescriptorSet elem_image = { \
1648  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, \
1649  .dstSet = even_odd ? qvk.desc_set_textures_odd : qvk.desc_set_textures_even, \
1650  .dstBinding = BINDING_OFFSET_IMAGES + _binding, \
1651  .dstArrayElement = 0, \
1652  .descriptorCount = 1, \
1653  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, \
1654  .pImageInfo = desc_output_img_info + VKPT_IMG_##_name, \
1655  }; \
1656  VkWriteDescriptorSet elem_texture = { \
1657  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, \
1658  .dstSet = even_odd ? qvk.desc_set_textures_odd : qvk.desc_set_textures_even, \
1659  .dstBinding = BINDING_OFFSET_TEXTURES + _binding, \
1660  .dstArrayElement = 0, \
1661  .descriptorCount = 1, \
1662  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, \
1663  .pImageInfo = img_info + VKPT_IMG_##_name, \
1664  }; \
1665  output_img_write[VKPT_IMG_##_name] = elem_image; \
1666  output_img_write[VKPT_IMG_##_name + NUM_VKPT_IMAGES] = elem_texture; \
1667  }
1668  LIST_IMAGES;
1669  if (even_odd)
1670  {
1672  }
1673  else
1674  {
1676  }
1677 #undef IMG_DO
1678 
1679  vkUpdateDescriptorSets(qvk.device, LENGTH(output_img_write), output_img_write, 0, NULL);
1680  }
1681 
1683 #ifdef VKPT_IMAGE_DUMPS
1684  create_readback_image(&qvk.dump_image, &qvk.dump_image_memory, &qvk.dump_image_memory_size, VK_FORMAT_R16G16B16A16_SFLOAT, qvk.extent_screen_images.width, qvk.extent_screen_images.height);
1685 #endif
1686 
1687  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
1688 
1689  VkImageSubresourceRange subresource_range = {
1690  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1691  .baseMipLevel = 0,
1692  .levelCount = 1,
1693  .baseArrayLayer = 0,
1694  .layerCount = 1
1695  };
1696 
1697  for (int i = 0; i < NUM_VKPT_IMAGES; i++) {
1698  IMAGE_BARRIER(cmd_buf,
1699  .image = qvk.images[i],
1700  .subresourceRange = subresource_range,
1701  .srcAccessMask = 0,
1702  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
1703  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1704  .newLayout = VK_IMAGE_LAYOUT_GENERAL,
1705  );
1706 
1707 #ifdef VKPT_DEVICE_GROUPS
1708  if (qvk.device_count > 1) {
1709  for(int d = 0; d < qvk.device_count; d++)
1710  {
1711  set_current_gpu(cmd_buf, d);
1712 
1713  IMAGE_BARRIER(cmd_buf,
1714  .image = qvk.images_local[d][i],
1715  .subresourceRange = subresource_range,
1716  .srcAccessMask = 0,
1717  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
1718  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1719  .newLayout = VK_IMAGE_LAYOUT_GENERAL
1720  );
1721  }
1722 
1723  set_current_gpu(cmd_buf, ALL_GPUS);
1724  }
1725 #endif
1726 
1727  }
1728 
1729  IMAGE_BARRIER(cmd_buf,
1730  .image = qvk.screenshot_image,
1731  .subresourceRange = subresource_range,
1732  .srcAccessMask = 0,
1733  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
1734  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1735  .newLayout = VK_IMAGE_LAYOUT_GENERAL,
1736  );
1737 
1738 #ifdef VKPT_IMAGE_DUMPS
1739  IMAGE_BARRIER(cmd_buf,
1740  .image = qvk.dump_image,
1741  .subresourceRange = subresource_range,
1742  .srcAccessMask = 0,
1743  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
1744  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1745  .newLayout = VK_IMAGE_LAYOUT_GENERAL,
1746  );
1747 #endif
1748 
1750 
1751  vkQueueWaitIdle(qvk.queue_graphics);
1752 
1753  return VK_SUCCESS;
1754 }

◆ vkpt_destroy_god_rays()

VkResult vkpt_destroy_god_rays ( )

Definition at line 65 of file god_rays.c.

66 {
67  vkDestroySampler(qvk.device, god_rays.shadow_sampler, NULL);
68  vkDestroyDescriptorPool(qvk.device, god_rays.descriptor_pool, NULL);
69 
70  return VK_SUCCESS;
71 }

◆ vkpt_destroy_images()

VkResult vkpt_destroy_images ( )

Definition at line 1757 of file textures.c.

1758 {
1759  for(int i = 0; i < NUM_VKPT_IMAGES; i++) {
1760  vkDestroyImageView(qvk.device, qvk.images_views[i], NULL);
1761  vkDestroyImage (qvk.device, qvk.images[i], NULL);
1762 
1763  qvk.images_views[i] = VK_NULL_HANDLE;
1764  qvk.images[i] = VK_NULL_HANDLE;
1765 
1766 #ifdef VKPT_DEVICE_GROUPS
1767  if (qvk.device_count > 1) {
1768  for (int d = 0; d < qvk.device_count; d++)
1769  {
1770  vkDestroyImageView(qvk.device, qvk.images_views_local[d][i], NULL);
1771  vkDestroyImage(qvk.device, qvk.images_local[d][i], NULL);
1772  qvk.images_views_local[d][i] = VK_NULL_HANDLE;
1773  qvk.images_local[d][i] = VK_NULL_HANDLE;
1774  }
1775  }
1776 #endif
1777 
1778  if (mem_images[i])
1779  {
1780  vkFreeMemory(qvk.device, mem_images[i], NULL);
1781  mem_images[i] = VK_NULL_HANDLE;
1782  }
1783  }
1784 
1786 #ifdef VKPT_IMAGE_DUMPS
1787  destroy_readback_image(&qvk.dump_image, &qvk.dump_image_memory, &qvk.dump_image_memory_size);
1788 #endif
1789 
1790  return VK_SUCCESS;
1791 }

◆ vkpt_destroy_shader_modules()

VkResult vkpt_destroy_shader_modules ( )

Definition at line 1180 of file main.c.

1181 {
1182 #define SHADER_MODULE_DO(a) \
1183  vkDestroyShaderModule(qvk.device, qvk.shader_modules[a], NULL); \
1184  qvk.shader_modules[a] = VK_NULL_HANDLE;
1185 
1187 
1188 #undef SHADER_MODULE_DO
1189 
1190  return VK_SUCCESS;
1191 }

Referenced by R_Shutdown_RTX(), and vkpt_reload_shader().

◆ 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_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_extract_emissive_texture_info()

void vkpt_extract_emissive_texture_info ( image_t image)

Definition at line 532 of file textures.c.

533 {
534  int w = image->upload_width;
535  int h = image->upload_height;
536 
537  byte* current_pixel = image->pix_data;
538  vec3_t emissive_color;
539  VectorClear(emissive_color);
540 
541  int min_x = w;
542  int max_x = -1;
543  int min_y = h;
544  int max_y = -1;
545 
546  for (int y = 0; y < h; y++) {
547  for (int x = 0; x < w; x++) {
548  if(current_pixel[0] + current_pixel[1] + current_pixel[2] > 0)
549  {
550  vec3_t color;
551  color[0] = decode_srgb(current_pixel[0]);
552  color[1] = decode_srgb(current_pixel[1]);
553  color[2] = decode_srgb(current_pixel[2]);
554 
555  color[0] = max(0.f, color[0] + EMISSIVE_TRANSFORM_BIAS);
556  color[1] = max(0.f, color[1] + EMISSIVE_TRANSFORM_BIAS);
557  color[2] = max(0.f, color[2] + EMISSIVE_TRANSFORM_BIAS);
558 
559  VectorAdd(emissive_color, color, emissive_color);
560 
561  min_x = min(min_x, x);
562  min_y = min(min_y, y);
563  max_x = max(max_x, x);
564  max_y = max(max_y, y);
565  }
566 
567  current_pixel += 4;
568  }
569  }
570 
571  if (min_x <= max_x && min_y <= max_y)
572  {
573  float normalization = 1.f / (float)((max_x - min_x + 1) * (max_y - min_y + 1));
574  VectorScale(emissive_color, normalization, image->light_color);
575  }
576  else
577  {
578  VectorSet(image->light_color, 0.f, 0.f, 0.f);
579  }
580 
581  image->min_light_texcoord[0] = (float)min_x / (float)w;
582  image->min_light_texcoord[1] = (float)min_y / (float)h;
583  image->max_light_texcoord[0] = (float)(max_x + 1) / (float)w;
584  image->max_light_texcoord[1] = (float)(max_y + 1) / (float)h;
585 
586  image->entire_texture_emissive = (min_x == 0) && (min_y == 0) && (max_x == w - 1) && (max_y == h - 1);
587 
588  image->processing_complete = qtrue;
589 }

Referenced by bsp_mesh_register_textures().

◆ 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().

◆ vkpt_free_command_buffers()

void vkpt_free_command_buffers ( cmd_buf_group_t group)

Definition at line 3373 of file main.c.

3374 {
3375  if (group->count_per_frame == 0)
3376  return;
3377 
3378  vkFreeCommandBuffers(qvk.device, group->command_pool, group->count_per_frame * MAX_FRAMES_IN_FLIGHT, group->buffers);
3379 
3380  Z_Free(group->buffers);
3381  group->buffers = NULL;
3382 
3383 #ifdef _DEBUG
3384  Z_Free(group->buffer_begin_addrs);
3385  group->buffer_begin_addrs = NULL;
3386 #endif
3387 
3388  group->count_per_frame = 0;
3389  group->used_this_frame = 0;
3390 }

Referenced by destroy_vulkan().

◆ vkpt_freecam_reset()

void vkpt_freecam_reset ( )

Definition at line 55 of file freecam.c.

56 {
57  if (!freecam_active)
58  return;
59 
61  freecam_active = qfalse;
62 }

Referenced by R_Shutdown_RTX(), and vkpt_freecam_update().

◆ vkpt_freecam_update()

void vkpt_freecam_update ( float  frame_time)

Definition at line 120 of file freecam.c.

121 {
122  if (cl_paused->integer != 2 || !sv_paused->integer || !cvar_pt_freecam->integer)
123  {
125  return;
126  }
127 
128  if (!freecam_active)
129  {
130  VectorCopy(vkpt_refdef.fd->vieworg, freecam_vieworg);
131  VectorCopy(vkpt_refdef.fd->viewangles, freecam_viewangles);
132  freecam_zoom = 1.f;
134  freecam_active = qtrue;
135  }
136 
137  vec3_t prev_vieworg;
138  vec3_t prev_viewangles;
139  VectorCopy(freecam_vieworg, prev_vieworg);
140  VectorCopy(freecam_viewangles, prev_viewangles);
141  float prev_zoom = freecam_zoom;
142 
143  vec3_t velocity = { 0.f };
144  if (freecam_keystate[0]) velocity[0] += 1.f;
145  if (freecam_keystate[1]) velocity[0] -= 1.f;
146  if (freecam_keystate[2]) velocity[1] += 1.f;
147  if (freecam_keystate[3]) velocity[1] -= 1.f;
148  if (freecam_keystate[4]) velocity[2] += 1.f;
149  if (freecam_keystate[5]) velocity[2] -= 1.f;
150 
151  if (Key_IsDown(K_SHIFT))
152  VectorScale(velocity, 5.f, velocity);
153  else if (Key_IsDown(K_CTRL))
154  VectorScale(velocity, 0.1f, velocity);
155 
156  vec3_t forward, right, up;
158  float speed = 100.f;
159  VectorMA(freecam_vieworg, velocity[0] * frame_time * speed, forward, freecam_vieworg);
160  VectorMA(freecam_vieworg, velocity[1] * frame_time * speed, right, freecam_vieworg);
161  VectorMA(freecam_vieworg, velocity[2] * frame_time * speed, up, freecam_vieworg);
162 
164 
165  VectorCopy(freecam_vieworg, vkpt_refdef.fd->vieworg);
166  VectorCopy(freecam_viewangles, vkpt_refdef.fd->viewangles);
167  vkpt_refdef.fd->fov_x = RAD2DEG(atanf(tanf(DEG2RAD(vkpt_refdef.fd->fov_x) * 0.5f) / freecam_zoom)) * 2.f;
168  vkpt_refdef.fd->fov_y = RAD2DEG(atanf(tanf(DEG2RAD(vkpt_refdef.fd->fov_y) * 0.5f) / freecam_zoom)) * 2.f;
169 
170  if (!VectorCompare(freecam_vieworg, prev_vieworg) || !VectorCompare(freecam_viewangles, prev_viewangles))
171  {
174 
176  }
177 
178  if (freecam_zoom != prev_zoom)
179  {
180  // zoom doesn't reset the player model, but does reset the accumulation
182  }
183 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_get_profiler_result()

double vkpt_get_profiler_result ( int  idx)

Definition at line 183 of file profiler.c.

184 {
185  double ms = (double)(query_pool_results[idx * 2 + 1] - query_pool_results[idx * 2 + 0]) * 1e-6;
186  return ms;
187 }

Referenced by draw_query(), and drs_process().

◆ vkpt_god_rays_create_pipelines()

VkResult vkpt_god_rays_create_pipelines ( )

Definition at line 73 of file god_rays.c.

74 {
78 
79  // this is a noop outside a shader reload
81 
82  return VK_SUCCESS;
83 }

◆ vkpt_god_rays_destroy_pipelines()

VkResult vkpt_god_rays_destroy_pipelines ( )

Definition at line 85 of file god_rays.c.

86 {
87  for (size_t i = 0; i < LENGTH(god_rays.pipelines); i++) {
88  if (god_rays.pipelines[i]) {
89  vkDestroyPipeline(qvk.device, god_rays.pipelines[i], NULL);
90  god_rays.pipelines[i] = NULL;
91  }
92  }
93 
94  if (god_rays.pipeline_layout) {
95  vkDestroyPipelineLayout(qvk.device, god_rays.pipeline_layout, NULL);
96  god_rays.pipeline_layout = NULL;
97  }
98 
99  if (god_rays.descriptor_set_layout) {
100  vkDestroyDescriptorSetLayout(qvk.device, god_rays.descriptor_set_layout, NULL);
101  god_rays.descriptor_set_layout = NULL;
102  }
103 
104  return VK_SUCCESS;
105 }

◆ vkpt_god_rays_enabled()

qboolean vkpt_god_rays_enabled ( const sun_light_t sun_light)

Definition at line 379 of file god_rays.c.

380 {
381  return god_rays.enable->integer
382  && god_rays.intensity->value > 0.f
383  && sun_light->visible
384  && !physical_sky_space->integer; // god rays look weird in space because they also appear outside of the station
385 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_god_rays_noop()

VkResult vkpt_god_rays_noop ( )

Definition at line 116 of file god_rays.c.

117 {
118  return VK_SUCCESS;
119 }

◆ vkpt_god_rays_prepare_ubo()

void vkpt_god_rays_prepare_ubo ( QVKUniformBuffer_t ubo,
const aabb_t world_aabb,
const float *  proj,
const float *  view,
const float *  shadowmap_viewproj,
float  shadowmap_depth_scale 
)

Definition at line 203 of file god_rays.c.

210 {
211  VectorAdd(world_aabb->mins, world_aabb->maxs, ubo->world_center);
212  VectorScale(ubo->world_center, 0.5f, ubo->world_center);
213  VectorSubtract(world_aabb->maxs, world_aabb->mins, ubo->world_size);
214  VectorScale(ubo->world_size, 0.5f, ubo->world_half_size_inv);
215  ubo->world_half_size_inv[0] = 1.f / ubo->world_half_size_inv[0];
216  ubo->world_half_size_inv[1] = 1.f / ubo->world_half_size_inv[1];
217  ubo->world_half_size_inv[2] = 1.f / ubo->world_half_size_inv[2];
218  ubo->shadow_map_depth_scale = shadowmap_depth_scale;
219 
220  ubo->god_rays_intensity = max(0.f, god_rays.intensity->value);
221  ubo->god_rays_eccentricity = god_rays.eccentricity->value;
222 
223  // Shadow parameters
224  memcpy(ubo->shadow_map_VP, shadowmap_viewproj, 16 * sizeof(float));
225 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_god_rays_update_images()

VkResult vkpt_god_rays_update_images ( )

Definition at line 108 of file god_rays.c.

109 {
112  return VK_SUCCESS;
113 }

◆ vkpt_image_copy()

void vkpt_image_copy ( VkCommandBuffer  cmd_buf,
int  src_image_index,
int  dst_image_index,
VkOffset2D  src_offset,
VkOffset2D  dst_offset,
VkExtent2D  size 
)

Definition at line 111 of file mgpu.c.

117 {
118  VkImageSubresourceRange subresource_range = {
119  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
120  .baseMipLevel = 0,
121  .levelCount = 1,
122  .baseArrayLayer = 0,
123  .layerCount = 1
124  };
125 
126  VkImageSubresourceLayers subresource_layers = {
127  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
128  .mipLevel = 0,
129  .baseArrayLayer = 0,
130  .layerCount = 1
131  };
132 
133  VkImageCopy copy_region = {
134  .srcSubresource = subresource_layers,
135  .srcOffset.x = src_offset.x,
136  .srcOffset.y = src_offset.y,
137  .srcOffset.z = 0,
138  .dstSubresource = subresource_layers,
139  .dstOffset.x = dst_offset.x,
140  .dstOffset.y = dst_offset.y,
141  .dstOffset.z = 0,
142  .extent.width = size.width,
143  .extent.height = size.height,
144  .extent.depth = 1
145  };
146 
147  VkMemoryBarrier mem_barrier = {
148  .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
149  .pNext = NULL,
150  .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
151  .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
152  };
153 
154  vkCmdPipelineBarrier(cmd_buf,
155  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
156  0,
157  1, &mem_barrier,
158  0, NULL,
159  0, NULL);
160 
161  vkCmdCopyImage(cmd_buf,
162  qvk.images[src_image_index], VK_IMAGE_LAYOUT_GENERAL,
163  qvk.images[dst_image_index], VK_IMAGE_LAYOUT_GENERAL,
164  1, &copy_region);
165 }

◆ vkpt_init_light_textures()

void vkpt_init_light_textures ( )

◆ vkpt_initialize_god_rays()

VkResult vkpt_initialize_god_rays ( )

Definition at line 51 of file god_rays.c.

52 {
53  memset(&god_rays, 0, sizeof(god_rays));
54 
55  VkPhysicalDeviceProperties properties;
56  vkGetPhysicalDeviceProperties(qvk.physical_device, &properties);
57 
58  god_rays.intensity = Cvar_Get("gr_intensity", "2.0", 0);
59  god_rays.eccentricity = Cvar_Get("gr_eccentricity", "0.75", 0);
60  god_rays.enable = Cvar_Get("gr_enable", "1", 0);
61 
62  return VK_SUCCESS;
63 }

◆ vkpt_interleave()

VkResult vkpt_interleave ( VkCommandBuffer  cmd_buf)

Definition at line 492 of file asvgf.c.

493 {
494  VkDescriptorSet desc_sets[] = {
498  };
499 
500 #ifdef VKPT_DEVICE_GROUPS
501  if (qvk.device_count > 1) {
502  BEGIN_PERF_MARKER(cmd_buf, PROFILER_MGPU_TRANSFERS);
503 
504  // create full interleaved motion and color buffers on GPU 0
505  VkOffset2D offset_left = { 0, 0 };
506  VkOffset2D offset_right = { qvk.extent_render.width / 2, 0 };
507  VkExtent2D extent = { qvk.extent_render.width / 2, qvk.extent_render.height };
508 
509  vkpt_mgpu_image_copy(cmd_buf,
510  VKPT_IMG_PT_MOTION,
511  VKPT_IMG_PT_MOTION,
512  1,
513  0,
514  offset_left,
515  offset_right,
516  extent);
517 
518  vkpt_mgpu_image_copy(cmd_buf,
519  VKPT_IMG_ASVGF_COLOR,
520  VKPT_IMG_ASVGF_COLOR,
521  1,
522  0,
523  offset_left,
524  offset_right,
525  extent);
526 
527  vkpt_mgpu_global_barrier(cmd_buf);
528 
529  END_PERF_MARKER(cmd_buf, PROFILER_MGPU_TRANSFERS);
530  }
531 #endif
532 
533  BEGIN_PERF_MARKER(cmd_buf, PROFILER_INTERLEAVE);
534 
535  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[CHECKERBOARD_INTERLEAVE]);
536  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
537  pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
538 
539  set_current_gpu(cmd_buf, 0);
540 
541  // dispatch using the image dimensions, not render dimensions - to clear the unused area with black color
542  vkCmdDispatch(cmd_buf,
543  (qvk.extent_screen_images.width + 15) / 16,
544  (qvk.extent_screen_images.height + 15) / 16,
545  1);
546 
547  END_PERF_MARKER(cmd_buf, PROFILER_INTERLEAVE);
548 
549  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_FLAT_COLOR]);
550  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_FLAT_MOTION]);
551 
552  return VK_SUCCESS;
553 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_light_buffer_reset_counts()

void vkpt_light_buffer_reset_counts ( )

Definition at line 131 of file vertex_buffer.c.

132 {
134  max_model_lights = 0;
135 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_light_buffer_upload_staging()

VkResult vkpt_light_buffer_upload_staging ( VkCommandBuffer  cmd_buf)

Definition at line 69 of file vertex_buffer.c.

70 {
72 
73  assert(!staging->is_mapped);
74 
75  VkBufferCopy copyRegion = {
76  .size = sizeof(LightBuffer),
77  };
78  vkCmdCopyBuffer(cmd_buf, staging->buffer, qvk.buf_light.buffer, 1, &copyRegion);
79 
80  int buffer_idx = qvk.frame_counter % 3;
81  if (qvk.buf_light_stats[buffer_idx].buffer)
82  {
83  vkCmdFillBuffer(cmd_buf, qvk.buf_light_stats[buffer_idx].buffer, 0, qvk.buf_light_stats[buffer_idx].size, 0);
84  }
85 
86  return VK_SUCCESS;
87 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_light_buffer_upload_to_staging()

VkResult vkpt_light_buffer_upload_to_staging ( qboolean  render_world,
bsp_mesh_t bsp_mesh,
bsp_t *  bsp,
int  num_model_lights,
light_poly_t transformed_model_lights,
const float *  sky_radiance 
)

Definition at line 310 of file vertex_buffer.c.

311 {
312  assert(bsp_mesh);
313 
315 
316  LightBuffer *lbo = (LightBuffer *)buffer_map(staging);
317  assert(lbo);
318 
319  if (render_world)
320  {
321  assert(bsp_mesh->num_clusters + 1 < MAX_LIGHT_LISTS);
322  assert(bsp_mesh->num_cluster_lights < MAX_LIGHT_LIST_NODES);
324  assert(bsp_mesh->num_light_polys + num_model_lights < MAX_LIGHT_POLYS);
325 
326  int model_light_offset = bsp_mesh->num_light_polys;
328 
329  if(max_model_lights > 0)
330  {
331  // If any of the BSP models contain lights, inject these lights right into the visibility lists.
332  // The shader doesn't know that these lights are dynamic.
333 
334  inject_model_lights(bsp_mesh, bsp, num_model_lights, transformed_model_lights, model_light_offset, lbo->light_list_offsets, lbo->light_list_lights);
335  }
336  else
337  {
338  memcpy(lbo->light_list_offsets, bsp_mesh->cluster_light_offsets, (bsp_mesh->num_clusters + 1) * sizeof(uint32_t));
339  memcpy(lbo->light_list_lights, bsp_mesh->cluster_lights, bsp_mesh->num_cluster_lights * sizeof(uint32_t));
340  }
341 
342  for (int nlight = 0; nlight < bsp_mesh->num_light_polys; nlight++)
343  {
344  light_poly_t* light = bsp_mesh->light_polys + nlight;
345  float* vblight = lbo->light_polys + nlight * (LIGHT_POLY_VEC4S * 4);
346  copy_light(light, vblight, sky_radiance);
347  }
348 
349  for (int nlight = 0; nlight < num_model_lights; nlight++)
350  {
351  light_poly_t* light = transformed_model_lights + nlight;
352  float* vblight = lbo->light_polys + (nlight + model_light_offset) * (LIGHT_POLY_VEC4S * 4);
353  copy_light(light, vblight, sky_radiance);
354  }
355  }
356  else
357  {
358  lbo->light_list_offsets[0] = 0;
359  lbo->light_list_offsets[1] = 0;
360  }
361 
362  /* effects.c declares this - hence the assert below:
363  typedef struct clightstyle_s {
364  ...
365  float map[MAX_QPATH];
366  } clightstyle_t;
367  */
368 
369  assert(MAX_LIGHT_STYLES == MAX_QPATH);
370  for (int nstyle = 0; nstyle < MAX_LIGHT_STYLES; nstyle++)
371  {
372  float style_scale = 1.f;
373  if (vkpt_refdef.fd->lightstyles)
374  {
375  style_scale = vkpt_refdef.fd->lightstyles[nstyle].white;
376  style_scale = max(0, min(1, style_scale));
377  }
378  lbo->light_styles[nstyle] = style_scale;
379  }
380 
381  // materials
382  int nmaterials = MAT_GetNumPBRMaterials();
383  pbr_material_t const * materials = MAT_GetPBRMaterialsTable();
384 
385  for (int nmat = 0; nmat < nmaterials; nmat++)
386  {
387  pbr_material_t const * material = materials + nmat;
388  uint32_t* mat_data = lbo->material_table + nmat * 4;
389  memset(mat_data, 0, sizeof(uint32_t) * 4);
390 
391  if (material->image_diffuse) mat_data[0] |= (material->image_diffuse - r_images);
392  if (material->image_normals) mat_data[0] |= (material->image_normals - r_images) << 16;
393  if (material->image_emissive) mat_data[1] |= (material->image_emissive - r_images);
394  mat_data[1] |= (material->num_frames & 0x000f) << 28;
395  mat_data[1] |= (material->next_frame & 0x0fff) << 16;
396 
397  mat_data[2] = floatToHalf(material->bump_scale);
398  mat_data[2] |= floatToHalf(material->rough_override) << 16;
399  mat_data[3] = floatToHalf(material->specular_scale);
400  mat_data[3] |= floatToHalf(material->emissive_scale) << 16;
401  }
402 
403  memcpy(lbo->cluster_debug_mask, cluster_debug_mask, MAX_LIGHT_LISTS / 8);
404 
405  buffer_unmap(staging);
406  lbo = NULL;
407 
408  return VK_SUCCESS;
409 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_light_stats_create()

VkResult vkpt_light_stats_create ( bsp_mesh_t bsp_mesh)

Definition at line 699 of file vertex_buffer.c.

700 {
702 
703  // Light statistics: 2 uints (shadowed, unshadowed) per light per surface orientation (6) per cluster.
704  uint32_t num_stats = bsp_mesh->num_clusters * bsp_mesh->num_light_polys * 6 * 2;
705 
706  // Handle rare cases when the map has zero lights
707  if (num_stats == 0)
708  num_stats = 1;
709 
710  for (int frame = 0; frame < NUM_LIGHT_STATS_BUFFERS; frame++)
711  {
712  buffer_create(qvk.buf_light_stats + frame, sizeof(uint32_t) * num_stats,
713  VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
714  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
715  }
716 
717  assert(NUM_LIGHT_STATS_BUFFERS == 3);
718 
719  VkDescriptorBufferInfo light_stats_buf_info[] = { {
720  .buffer = qvk.buf_light_stats[0].buffer,
721  .offset = 0,
722  .range = qvk.buf_light_stats[0].size,
723  }, {
724  .buffer = qvk.buf_light_stats[1].buffer,
725  .offset = 0,
726  .range = qvk.buf_light_stats[1].size,
727  }, {
728  .buffer = qvk.buf_light_stats[2].buffer,
729  .offset = 0,
730  .range = qvk.buf_light_stats[2].size,
731  } };
732 
733  VkWriteDescriptorSet output_buf_write = {
734  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
735  .dstSet = qvk.desc_set_vertex_buffer,
736  .dstBinding = 6,
737  .dstArrayElement = 0,
738  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
739  .descriptorCount = LENGTH(light_stats_buf_info),
740  .pBufferInfo = light_stats_buf_info,
741  };
742 
743  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
744 
745  return VK_SUCCESS;
746 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_light_stats_destroy()

VkResult vkpt_light_stats_destroy ( )

Definition at line 748 of file vertex_buffer.c.

749 {
750  for (int frame = 0; frame < NUM_LIGHT_STATS_BUFFERS; frame++)
751  {
753  }
754 
755  return VK_SUCCESS;
756 }

Referenced by vkpt_destroy_all(), and vkpt_light_stats_create().

◆ vkpt_load_shader_modules()

VkResult vkpt_load_shader_modules ( )

Definition at line 1162 of file main.c.

1163 {
1164  VkResult ret = VK_SUCCESS;
1165 #define SHADER_MODULE_DO(a) do { \
1166  qvk.shader_modules[a] = create_shader_module_from_file(shader_module_file_names[a], #a); \
1167  ret = (ret == VK_SUCCESS && qvk.shader_modules[a]) ? VK_SUCCESS : VK_ERROR_INITIALIZATION_FAILED; \
1168  if(qvk.shader_modules[a]) { \
1169  ATTACH_LABEL_VARIABLE_NAME((uint64_t)qvk.shader_modules[a], SHADER_MODULE, #a); \
1170  }\
1171  } while(0);
1172 
1174 
1175 #undef SHADER_MODULE_DO
1176  return ret;
1177 }

Referenced by R_Init_RTX(), and vkpt_reload_shader().

◆ vkpt_normalize_normal_map()

void vkpt_normalize_normal_map ( image_t image)

Definition at line 592 of file textures.c.

593 {
594  int w = image->upload_width;
595  int h = image->upload_height;
596 
597  byte* current_pixel = image->pix_data;
598 
599  for (int y = 0; y < h; y++) {
600  for (int x = 0; x < w; x++)
601  {
602  vec3_t color;
603  color[0] = decode_linear(current_pixel[0]);
604  color[1] = decode_linear(current_pixel[1]);
605  color[2] = decode_linear(current_pixel[2]);
606 
607  color[0] = color[0] * 2.f - 1.f;
608  color[1] = color[1] * 2.f - 1.f;
609 
610  if (VectorNormalize(color) == 0.f)
611  {
612  color[0] = 0.f;
613  color[1] = 0.f;
614  color[2] = 1.f;
615  }
616 
617  color[0] = color[0] * 0.5f + 0.5f;
618  color[1] = color[1] * 0.5f + 0.5f;
619 
620  current_pixel[0] = encode_linear(color[0]);
621  current_pixel[1] = encode_linear(color[1]);
622  current_pixel[2] = encode_linear(color[2]);
623 
624  current_pixel += 4;
625  }
626  }
627 
628  image->processing_complete = qtrue;
629 }

Referenced by bsp_mesh_register_textures(), and IMG_ReloadAll().

◆ vkpt_profiler_destroy()

VkResult vkpt_profiler_destroy ( )

Definition at line 42 of file profiler.c.

43 {
44  vkDestroyQueryPool(qvk.device, query_pool, NULL);
45  return VK_SUCCESS;
46 }

◆ vkpt_profiler_initialize()

VkResult vkpt_profiler_initialize ( )

Definition at line 30 of file profiler.c.

31 {
32  VkQueryPoolCreateInfo query_pool_info = {
33  .sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO,
34  .queryType = VK_QUERY_TYPE_TIMESTAMP,
35  .queryCount = MAX_FRAMES_IN_FLIGHT * NUM_PROFILER_ENTRIES * 2,
36  };
37  vkCreateQueryPool(qvk.device, &query_pool_info, NULL, &query_pool);
38  return VK_SUCCESS;
39 }

◆ vkpt_profiler_next_frame()

VkResult vkpt_profiler_next_frame ( VkCommandBuffer  cmd_buf)

Definition at line 66 of file profiler.c.

67 {
68  qboolean any_queries_used = qfalse;
69 
70  for (int idx = 0; idx < NUM_PROFILER_QUERIES_PER_FRAME; idx++)
71  {
73  {
74  any_queries_used = qtrue;
75  break;
76  }
77  }
78 
79  if (any_queries_used)
80  {
81  VkResult result = vkGetQueryPoolResults(qvk.device, query_pool,
84  sizeof(query_pool_results),
86  sizeof(query_pool_results[0]),
87  VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
88 
89  if (result != VK_SUCCESS && result != VK_NOT_READY)
90  {
91  Com_EPrintf("Failed call to vkGetQueryPoolResults, error code = %d\n", result);
92  any_queries_used = qfalse;
93  }
94  }
95 
96  if (any_queries_used)
97  {
98  for (int idx = 0; idx < NUM_PROFILER_QUERIES_PER_FRAME; idx++)
99  {
101  query_pool_results[idx] = 0;
102  }
103  }
104  else
105  {
106  memset(query_pool_results, 0, sizeof(query_pool_results));
107  }
108 
109  vkCmdResetQueryPool(cmd_buf, query_pool,
112 
114 
115  return VK_SUCCESS;
116 }

Referenced by R_BeginFrame_RTX().

◆ vkpt_profiler_query()

VkResult vkpt_profiler_query ( VkCommandBuffer  cmd_buf,
int  idx,
VKPTProfilerAction  action 
)

Definition at line 49 of file profiler.c.

50 {
51  idx = idx * 2 + action + qvk.current_frame_index * NUM_PROFILER_QUERIES_PER_FRAME;
52 
53  set_current_gpu(cmd_buf, 0);
54 
55  vkCmdWriteTimestamp(cmd_buf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
56  query_pool, idx);
57 
58  set_current_gpu(cmd_buf, ALL_GPUS);
59 
60  profiler_queries_used[idx] = qtrue;
61 
62  return VK_SUCCESS;
63 }

Referenced by begin_perf_marker(), end_perf_marker(), and R_RenderFrame_RTX().

◆ vkpt_pt_create_all_dynamic()

VkResult vkpt_pt_create_all_dynamic ( VkCommandBuffer  cmd_buf,
int  idx,
VkBuffer  vertex_buffer,
const EntityUploadInfo upload_info 
)

Definition at line 781 of file path_tracer.c.

786 {
787  scratch_buf_ptr = 0;
788 
790  offsetof(VertexBuffer, positions_instanced), upload_info->dynamic_vertex_num);
791 
793  offsetof(VertexBuffer, positions_instanced), upload_info->transparent_model_vertex_num,
794  upload_info->transparent_model_vertex_offset);
795 
797  offsetof(VertexBuffer, positions_instanced), upload_info->viewer_model_vertex_num,
798  upload_info->viewer_model_vertex_offset);
799 
801  offsetof(VertexBuffer, positions_instanced), upload_info->viewer_weapon_vertex_num,
802  upload_info->viewer_weapon_vertex_offset);
803 
805  offsetof(VertexBuffer, positions_instanced), upload_info->explosions_vertex_num,
806  upload_info->explosions_vertex_offset);
807 
808  MEM_BARRIER_BUILD_ACCEL(cmd_buf);
809  scratch_buf_ptr = 0;
810 
811  return VK_SUCCESS;
812 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_pt_create_pipelines()

VkResult vkpt_pt_create_pipelines ( )

Definition at line 1216 of file path_tracer.c.

1217 {
1218  VkSpecializationMapEntry specEntry = {
1219  .constantID = 0,
1220  .offset = 0,
1221  .size = sizeof(uint32_t),
1222  };
1223 
1224  uint32_t numbers[2] = { 0, 1 };
1225 
1226  VkSpecializationInfo specInfo[2] = {
1227  {
1228  .mapEntryCount = 1,
1229  .pMapEntries = &specEntry,
1230  .dataSize = sizeof(uint32_t),
1231  .pData = &numbers[0],
1232  },
1233  {
1234  .mapEntryCount = 1,
1235  .pMapEntries = &specEntry,
1236  .dataSize = sizeof(uint32_t),
1237  .pData = &numbers[1],
1238  }
1239  };
1240 
1241  VkPipelineShaderStageCreateInfo shader_stages[] = {
1242  SHADER_STAGE(QVK_MOD_PRIMARY_RAYS_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV),
1243  SHADER_STAGE_SPEC(QVK_MOD_REFLECT_REFRACT_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[0]),
1244  SHADER_STAGE_SPEC(QVK_MOD_REFLECT_REFRACT_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[1]),
1245  SHADER_STAGE_SPEC(QVK_MOD_DIRECT_LIGHTING_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[0]),
1246  SHADER_STAGE_SPEC(QVK_MOD_DIRECT_LIGHTING_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[1]),
1247  SHADER_STAGE_SPEC(QVK_MOD_INDIRECT_LIGHTING_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[0]),
1248  SHADER_STAGE_SPEC(QVK_MOD_INDIRECT_LIGHTING_RGEN, VK_SHADER_STAGE_RAYGEN_BIT_NV, &specInfo[1]),
1249  SHADER_STAGE(QVK_MOD_PATH_TRACER_RMISS, VK_SHADER_STAGE_MISS_BIT_NV),
1250  SHADER_STAGE(QVK_MOD_PATH_TRACER_SHADOW_RMISS, VK_SHADER_STAGE_MISS_BIT_NV),
1251  SHADER_STAGE(QVK_MOD_PATH_TRACER_RCHIT, VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV),
1252  SHADER_STAGE(QVK_MOD_PATH_TRACER_PARTICLE_RAHIT, VK_SHADER_STAGE_ANY_HIT_BIT_NV),
1253  SHADER_STAGE(QVK_MOD_PATH_TRACER_BEAM_RAHIT, VK_SHADER_STAGE_ANY_HIT_BIT_NV),
1254  SHADER_STAGE(QVK_MOD_PATH_TRACER_EXPLOSION_RAHIT, VK_SHADER_STAGE_ANY_HIT_BIT_NV),
1255  SHADER_STAGE(QVK_MOD_PATH_TRACER_SPRITE_RAHIT, VK_SHADER_STAGE_ANY_HIT_BIT_NV),
1256  };
1257 
1258  VkRayTracingShaderGroupCreateInfoNV rt_shader_group_info[] = {
1259  [SBT_RGEN_PRIMARY_RAYS] = {
1260  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1261  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1262  .generalShader = 0,
1263  .closestHitShader = VK_SHADER_UNUSED_NV,
1264  .anyHitShader = VK_SHADER_UNUSED_NV,
1265  .intersectionShader = VK_SHADER_UNUSED_NV
1266  },
1268  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1269  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1270  .generalShader = 1,
1271  .closestHitShader = VK_SHADER_UNUSED_NV,
1272  .anyHitShader = VK_SHADER_UNUSED_NV,
1273  .intersectionShader = VK_SHADER_UNUSED_NV
1274  },
1276  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1277  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1278  .generalShader = 2,
1279  .closestHitShader = VK_SHADER_UNUSED_NV,
1280  .anyHitShader = VK_SHADER_UNUSED_NV,
1281  .intersectionShader = VK_SHADER_UNUSED_NV
1282  },
1284  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1285  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1286  .generalShader = 3,
1287  .closestHitShader = VK_SHADER_UNUSED_NV,
1288  .anyHitShader = VK_SHADER_UNUSED_NV,
1289  .intersectionShader = VK_SHADER_UNUSED_NV
1290  },
1292  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1293  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1294  .generalShader = 4,
1295  .closestHitShader = VK_SHADER_UNUSED_NV,
1296  .anyHitShader = VK_SHADER_UNUSED_NV,
1297  .intersectionShader = VK_SHADER_UNUSED_NV
1298  },
1300  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1301  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1302  .generalShader = 5,
1303  .closestHitShader = VK_SHADER_UNUSED_NV,
1304  .anyHitShader = VK_SHADER_UNUSED_NV,
1305  .intersectionShader = VK_SHADER_UNUSED_NV
1306  },
1308  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1309  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1310  .generalShader = 6,
1311  .closestHitShader = VK_SHADER_UNUSED_NV,
1312  .anyHitShader = VK_SHADER_UNUSED_NV,
1313  .intersectionShader = VK_SHADER_UNUSED_NV
1314  },
1315  [SBT_RMISS_PATH_TRACER] = {
1316  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1317  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1318  .generalShader = 7,
1319  .closestHitShader = VK_SHADER_UNUSED_NV,
1320  .anyHitShader = VK_SHADER_UNUSED_NV,
1321  .intersectionShader = VK_SHADER_UNUSED_NV
1322  },
1323  [SBT_RMISS_SHADOW] = {
1324  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1325  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV,
1326  .generalShader = 8,
1327  .closestHitShader = VK_SHADER_UNUSED_NV,
1328  .anyHitShader = VK_SHADER_UNUSED_NV,
1329  .intersectionShader = VK_SHADER_UNUSED_NV
1330  },
1331  [SBT_RCHIT_OPAQUE] = {
1332  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1333  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1334  .generalShader = VK_SHADER_UNUSED_NV,
1335  .closestHitShader = 9,
1336  .anyHitShader = VK_SHADER_UNUSED_NV,
1337  .intersectionShader = VK_SHADER_UNUSED_NV
1338  },
1339  [SBT_RAHIT_PARTICLE] = {
1340  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1341  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1342  .generalShader = VK_SHADER_UNUSED_NV,
1343  .closestHitShader = VK_SHADER_UNUSED_NV,
1344  .anyHitShader = 10,
1345  .intersectionShader = VK_SHADER_UNUSED_NV
1346  },
1347  [SBT_RAHIT_BEAM] = {
1348  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1349  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1350  .generalShader = VK_SHADER_UNUSED_NV,
1351  .closestHitShader = VK_SHADER_UNUSED_NV,
1352  .anyHitShader = 11,
1353  .intersectionShader = VK_SHADER_UNUSED_NV
1354  },
1355  [SBT_RAHIT_EXPLOSION] = {
1356  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1357  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1358  .generalShader = VK_SHADER_UNUSED_NV,
1359  .closestHitShader = VK_SHADER_UNUSED_NV,
1360  .anyHitShader = 12,
1361  .intersectionShader = VK_SHADER_UNUSED_NV
1362  },
1363  [SBT_RAHIT_SPRITE] = {
1364  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1365  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1366  .generalShader = VK_SHADER_UNUSED_NV,
1367  .closestHitShader = VK_SHADER_UNUSED_NV,
1368  .anyHitShader = 13,
1369  .intersectionShader = VK_SHADER_UNUSED_NV
1370  },
1371  [SBT_RCHIT_EMPTY] = {
1372  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_NV,
1373  .type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV,
1374  .generalShader = VK_SHADER_UNUSED_NV,
1375  .closestHitShader = VK_SHADER_UNUSED_NV,
1376  .anyHitShader = VK_SHADER_UNUSED_NV,
1377  .intersectionShader = VK_SHADER_UNUSED_NV
1378  },
1379  };
1380 
1381  VkRayTracingPipelineCreateInfoNV rt_pipeline_info = {
1382  .sType = VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV,
1383  .stageCount = LENGTH(shader_stages),
1384  .pStages = shader_stages,
1385  .groupCount = LENGTH(rt_shader_group_info),
1386  .pGroups = rt_shader_group_info,
1387  .layout = rt_pipeline_layout,
1388  .maxRecursionDepth = 1,
1389  };
1390 
1391  _VK(qvkCreateRayTracingPipelinesNV(qvk.device, NULL, 1, &rt_pipeline_info, NULL, &rt_pipeline ));
1392 
1393  uint32_t num_groups = LENGTH(rt_shader_group_info);
1394  uint32_t shader_binding_table_size = rt_properties.shaderGroupHandleSize * num_groups;
1395 
1396  /* pt */
1397  _VK(buffer_create(&buf_shader_binding_table, shader_binding_table_size,
1398  VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
1399 
1400  void *shader_binding_table = buffer_map(&buf_shader_binding_table);
1401  _VK(qvkGetRayTracingShaderGroupHandlesNV(qvk.device, rt_pipeline, 0, num_groups,
1402  shader_binding_table_size, shader_binding_table));
1404  shader_binding_table = NULL;
1405 
1406  return VK_SUCCESS;
1407 }

◆ vkpt_pt_create_static()

VkResult vkpt_pt_create_static ( VkBuffer  vertex_buffer,
size_t  buffer_offset,
int  num_vertices,
int  num_vertices_transparent,
int  num_vertices_sky,
int  num_vertices_custom_sky 
)

Definition at line 574 of file path_tracer.c.

582 {
583  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
584 
585  scratch_buf_ptr = 0;
586 
587  VkResult ret = vkpt_pt_create_accel_bottom(
589  buffer_offset,
590  num_vertices,
591  &accel_static,
592  NULL,
594  cmd_buf,
595  VK_FALSE);
596 
597  MEM_BARRIER_BUILD_ACCEL(cmd_buf);
598  scratch_buf_ptr = 0;
599 
602  buffer_offset + num_vertices * sizeof(float) * 3,
603  num_vertices_transparent,
605  NULL,
607  cmd_buf,
608  VK_FALSE);
609 
610  MEM_BARRIER_BUILD_ACCEL(cmd_buf);
611  scratch_buf_ptr = 0;
612 
615  buffer_offset + (num_vertices + num_vertices_transparent) * sizeof(float) * 3,
616  num_vertices_sky,
617  &accel_sky,
618  NULL,
619  &mem_accel_sky,
620  cmd_buf,
621  VK_FALSE);
622 
623  MEM_BARRIER_BUILD_ACCEL(cmd_buf);
624  scratch_buf_ptr = 0;
625 
628  buffer_offset + (num_vertices + num_vertices_transparent + num_vertices_sky) * sizeof(float) * 3,
629  num_vertices_custom_sky,
631  NULL,
633  cmd_buf,
634  VK_FALSE);
635 
636  MEM_BARRIER_BUILD_ACCEL(cmd_buf);
637  scratch_buf_ptr = 0;
638 
639  transparent_primitive_offset = num_vertices / 3;
640  sky_primitive_offset = transparent_primitive_offset + num_vertices_transparent / 3;
641  custom_sky_primitive_offset = sky_primitive_offset + num_vertices_sky / 3;
642 
645 
646  return ret;
647 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_pt_create_toplevel()

VkResult vkpt_pt_create_toplevel ( VkCommandBuffer  cmd_buf,
int  idx,
qboolean  include_world,
qboolean  weapon_left_handed 
)

Definition at line 852 of file path_tracer.c.

853 {
855  int num_instances = 0;
856 
857  if (include_world)
858  {
859  append_blas(instances, &num_instances, accel_static, 0, AS_FLAG_OPAQUE, 0, 0);
861  append_blas(instances, &num_instances, accel_sky, AS_INSTANCE_FLAG_SKY | sky_primitive_offset, AS_FLAG_SKY, 0, 0);
863  }
864  append_blas(instances, &num_instances, accel_dynamic[idx], AS_INSTANCE_FLAG_DYNAMIC, AS_FLAG_OPAQUE, 0, 0);
865 
867  {
869  }
870 
872  {
873  append_blas(instances, &num_instances, accel_viewer_models[idx], AS_INSTANCE_FLAG_DYNAMIC | viewer_model_primitive_offset, AS_FLAG_VIEWER_MODELS, VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV, 0);
874  append_blas(instances, &num_instances, accel_viewer_weapon[idx], AS_INSTANCE_FLAG_DYNAMIC | viewer_weapon_primitive_offset, AS_FLAG_VIEWER_WEAPON, weapon_left_handed ? VK_GEOMETRY_INSTANCE_TRIANGLE_FRONT_COUNTERCLOCKWISE_BIT_NV : 0, 0);
875  }
876 
879 
880  if (cvar_pt_enable_particles->integer != 0 && particle_num > 0)
881  {
882  append_blas(instances, &num_instances, get_transparency_particle_blas(), 0, AS_FLAG_PARTICLES, VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV, 1);
883  }
884 
885  if (cvar_pt_enable_beams->integer != 0 && beam_num > 0)
886  {
887  append_blas(instances, &num_instances, get_transparency_beam_blas(), 0, AS_FLAG_PARTICLES, VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV, 2);
888  }
889 
890  if (cvar_pt_enable_sprites->integer != 0 && sprite_num > 0)
891  {
892  append_blas(instances, &num_instances, get_transparency_sprite_blas(), 0, AS_FLAG_EXPLOSIONS, VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV, 4);
893  }
894 
896  {
898  }
899 
900  void *instance_data = buffer_map(buf_instances + idx);
901  memcpy(instance_data, &instances, sizeof(QvkGeometryInstance_t) * num_instances);
902 
904  instance_data = NULL;
905 
906  VkAccelerationStructureCreateInfoNV accel_create_info = {
907  .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_NV,
908  .info = {
909  .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
910  .instanceCount = num_instances,
911  .geometryCount = 0,
912  .pGeometries = NULL,
913  .type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV
914  }
915  };
916 
917  if (accel_top_match[idx].instanceCount < accel_create_info.info.instanceCount) {
919 
920  qvkCreateAccelerationStructureNV(qvk.device, &accel_create_info, NULL, accel_top + idx);
921 
922  /* XXX: do allocation only once with safety margin */
923  VkAccelerationStructureMemoryRequirementsInfoNV mem_req_info = {
924  .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV,
925  .accelerationStructure = accel_top[idx],
926  .type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV
927  };
928  VkMemoryRequirements2 mem_req = { 0 };
929  mem_req.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
930  qvkGetAccelerationStructureMemoryRequirementsNV(qvk.device, &mem_req_info, &mem_req);
931 
932  _VK(allocate_gpu_memory(mem_req.memoryRequirements, mem_accel_top + idx));
933 
934  VkBindAccelerationStructureMemoryInfoNV bind_info = {
935  .sType = VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV,
936  .accelerationStructure = accel_top[idx],
937  .memory = mem_accel_top[idx],
938  };
939 
940  _VK(qvkBindAccelerationStructureMemoryNV(qvk.device, 1, &bind_info));
941 
943 
944  accel_top_match[idx].instanceCount = accel_create_info.info.instanceCount;
945  }
946 
947  VkAccelerationStructureInfoNV as_info = {
948  .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
949  .type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV,
950  .geometryCount = 0,
951  .pGeometries = NULL,
952  .instanceCount = num_instances,
953  };
954 
955  qvkCmdBuildAccelerationStructureNV(
956  cmd_buf,
957  &as_info,
958  buf_instances[idx].buffer, /* instance buffer */
959  0 /* instance offset */,
960  VK_FALSE, /* update */
961  accel_top[idx],
962  VK_NULL_HANDLE, /* source acceleration structure ?? */
964  0 /* scratch offset */);
965 
966  MEM_BARRIER_BUILD_ACCEL(cmd_buf); /* probably not needed here but doesn't matter */
967 
968  return VK_SUCCESS;
969 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_pt_destroy()

VkResult vkpt_pt_destroy ( )

Definition at line 1196 of file path_tracer.c.

1197 {
1198  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
1206  }
1209  vkDestroyDescriptorSetLayout(qvk.device, rt_descriptor_set_layout, NULL);
1210  vkDestroyPipelineLayout(qvk.device, rt_pipeline_layout, NULL);
1211  vkDestroyDescriptorPool(qvk.device, rt_descriptor_pool, NULL);
1212  return VK_SUCCESS;
1213 }

◆ vkpt_pt_destroy_pipelines()

VkResult vkpt_pt_destroy_pipelines ( )

Definition at line 1410 of file path_tracer.c.

1411 {
1413  vkDestroyPipeline(qvk.device, rt_pipeline, NULL);
1414 
1415  return VK_SUCCESS;
1416 }

◆ vkpt_pt_destroy_static()

VkResult vkpt_pt_destroy_static ( )

Definition at line 345 of file path_tracer.c.

346 {
347  if(mem_accel_static) {
348  vkFreeMemory(qvk.device, mem_accel_static, NULL);
349  mem_accel_static = VK_NULL_HANDLE;
350  }
351  if (mem_accel_transparent) {
352  vkFreeMemory(qvk.device, mem_accel_transparent, NULL);
353  mem_accel_transparent = VK_NULL_HANDLE;
354  }
355  if (mem_accel_sky) {
356  vkFreeMemory(qvk.device, mem_accel_sky, NULL);
357  mem_accel_sky = VK_NULL_HANDLE;
358  }
359  if (mem_accel_custom_sky) {
360  vkFreeMemory(qvk.device, mem_accel_custom_sky, NULL);
361  mem_accel_custom_sky = VK_NULL_HANDLE;
362  }
363  if(accel_static) {
364  qvkDestroyAccelerationStructureNV(qvk.device, accel_static, NULL);
365  accel_static = VK_NULL_HANDLE;
366  }
367  if (accel_transparent) {
368  qvkDestroyAccelerationStructureNV(qvk.device, accel_transparent, NULL);
369  accel_transparent = VK_NULL_HANDLE;
370  }
371  if (accel_sky) {
372  qvkDestroyAccelerationStructureNV(qvk.device, accel_sky, NULL);
373  accel_sky = VK_NULL_HANDLE;
374  }
375  if (accel_custom_sky) {
376  qvkDestroyAccelerationStructureNV(qvk.device, accel_custom_sky, NULL);
377  accel_custom_sky = VK_NULL_HANDLE;
378  }
379  return VK_SUCCESS;
380 }

Referenced by R_BeginRegistration_RTX(), and vkpt_pt_destroy().

◆ vkpt_pt_init()

VkResult vkpt_pt_init ( )

Definition at line 134 of file path_tracer.c.

135 {
136  VkPhysicalDeviceProperties2 dev_props2 = {
137  .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
138  .pNext = &rt_properties,
139  };
140 
141  vkGetPhysicalDeviceProperties2(qvk.physical_device, &dev_props2);
142 
143  Com_Printf("Maximum recursion depth: %d\n", rt_properties.maxRecursionDepth);
144  Com_Printf("Shader group handle size: %d\n", rt_properties.shaderGroupHandleSize);
145 
146  buffer_create(&buf_accel_scratch, SIZE_SCRATCH_BUFFER, VK_BUFFER_USAGE_RAY_TRACING_BIT_NV,
147  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
148 
149  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
150  buffer_create(buf_instances + i, INSTANCE_MAX_NUM * sizeof(QvkGeometryInstance_t), VK_BUFFER_USAGE_RAY_TRACING_BIT_NV,
151  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
152  }
153 
154  /* create descriptor set layout */
155  VkDescriptorSetLayoutBinding bindings[] = {
156  {
158  .descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV,
159  .descriptorCount = 1,
160  .stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_NV,
161  },
162  {
164  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
165  .descriptorCount = 1,
166  .stageFlags = VK_SHADER_STAGE_ANY_HIT_BIT_NV,
167  },
168  {
170  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
171  .descriptorCount = 1,
172  .stageFlags = VK_SHADER_STAGE_ANY_HIT_BIT_NV,
173  },
174  {
176  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
177  .descriptorCount = 1,
178  .stageFlags = VK_SHADER_STAGE_ANY_HIT_BIT_NV,
179  },
180  };
181 
182  VkDescriptorSetLayoutCreateInfo layout_info = {
183  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
184  .bindingCount = LENGTH(bindings),
185  .pBindings = bindings
186  };
187  _VK(vkCreateDescriptorSetLayout(qvk.device, &layout_info, NULL, &rt_descriptor_set_layout));
188  ATTACH_LABEL_VARIABLE(rt_descriptor_set_layout, DESCRIPTOR_SET_LAYOUT);
189 
190 
191  VkDescriptorSetLayout desc_set_layouts[] = {
196  };
197 
198  /* create pipeline */
199  VkPushConstantRange push_constant_range = {
200  .stageFlags = VK_SHADER_STAGE_RAYGEN_BIT_NV,
201  .offset = 0,
202  .size = sizeof(int) * 2,
203  };
204 
205  VkPipelineLayoutCreateInfo pipeline_layout_create_info = {
206  .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
207  .setLayoutCount = LENGTH(desc_set_layouts),
208  .pSetLayouts = desc_set_layouts,
209  .pushConstantRangeCount = 1,
210  .pPushConstantRanges = &push_constant_range,
211  };
212 
213  _VK(vkCreatePipelineLayout(qvk.device, &pipeline_layout_create_info, NULL, &rt_pipeline_layout));
214  ATTACH_LABEL_VARIABLE(rt_pipeline_layout, PIPELINE_LAYOUT);
215 
216  VkDescriptorPoolSize pool_sizes[] = {
217  { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MAX_FRAMES_IN_FLIGHT },
218  { VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV, MAX_FRAMES_IN_FLIGHT }
219  };
220 
221  VkDescriptorPoolCreateInfo pool_create_info = {
222  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
223  .maxSets = MAX_FRAMES_IN_FLIGHT,
224  .poolSizeCount = LENGTH(pool_sizes),
225  .pPoolSizes = pool_sizes
226  };
227 
228  _VK(vkCreateDescriptorPool(qvk.device, &pool_create_info, NULL, &rt_descriptor_pool));
229  ATTACH_LABEL_VARIABLE(rt_descriptor_pool, DESCRIPTOR_POOL);
230 
231  VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
232  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
233  .descriptorPool = rt_descriptor_pool,
234  .descriptorSetCount = 1,
235  .pSetLayouts = &rt_descriptor_set_layout,
236  };
237 
238  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
239  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, rt_descriptor_set + i));
240  ATTACH_LABEL_VARIABLE(rt_descriptor_set[i], DESCRIPTOR_SET);
241  }
242 
243  cvar_pt_enable_particles = Cvar_Get("pt_enable_particles", "1", 0);
244  cvar_pt_enable_beams = Cvar_Get("pt_enable_beams", "1", 0);
245  cvar_pt_enable_sprites= Cvar_Get("pt_enable_sprites", "1", 0);
246 
247  return VK_SUCCESS;
248 }

◆ vkpt_pt_trace_lighting()

VkResult vkpt_pt_trace_lighting ( VkCommandBuffer  cmd_buf,
float  num_bounce_rays 
)

Definition at line 1105 of file path_tracer.c.

1106 {
1107  int frame_idx = qvk.frame_counter & 1;
1108 
1109  setup_rt_pipeline(cmd_buf);
1110 
1111  BEGIN_PERF_MARKER(cmd_buf, PROFILER_DIRECT_LIGHTING);
1112 
1113  for (int i = 0; i < qvk.device_count; i++)
1114  {
1115  set_current_gpu(cmd_buf, i);
1116 
1117  int idx = qvk.device_count == 1 ? -1 : i;
1118  vkCmdPushConstants(cmd_buf, rt_pipeline_layout, VK_SHADER_STAGE_RAYGEN_BIT_NV, 0, sizeof(int), &idx);
1119 
1120  int rgen_index = SBT_RGEN_DIRECT_LIGHTING;
1121  if (cvar_pt_caustics->value != 0)
1122  rgen_index = SBT_RGEN_DIRECT_LIGHTING_CAUSTICS;
1123 
1124  qvkCmdTraceRaysNV(cmd_buf,
1125  buf_shader_binding_table.buffer, rgen_index * rt_properties.shaderGroupHandleSize,
1126  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1127  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1128  VK_NULL_HANDLE, 0, 0,
1129  qvk.extent_render.width / 2, qvk.extent_render.height, qvk.device_count == 1 ? 2 : 1);
1130  }
1131 
1132  set_current_gpu(cmd_buf, ALL_GPUS);
1133 
1134  END_PERF_MARKER(cmd_buf, PROFILER_DIRECT_LIGHTING);
1135 
1136  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_SH]);
1137  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_COCG]);
1138  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_HF]);
1139  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_SPEC]);
1140 
1141  BUFFER_BARRIER(cmd_buf,
1142  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
1143  .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1144  .buffer = qvk.buf_readback.buffer,
1145  .offset = 0,
1146  .size = VK_WHOLE_SIZE,
1147  );
1148 
1149  BEGIN_PERF_MARKER(cmd_buf, PROFILER_INDIRECT_LIGHTING);
1150 
1151  if (num_bounce_rays > 0)
1152  {
1153  for (int i = 0; i < qvk.device_count; i++)
1154  {
1155  set_current_gpu(cmd_buf, i);
1156 
1157  int idx = qvk.device_count == 1 ? -1 : i;
1158  vkCmdPushConstants(cmd_buf, rt_pipeline_layout, VK_SHADER_STAGE_RAYGEN_BIT_NV, 0, sizeof(idx), &idx);
1159 
1160  for (int bounce_ray = 0; bounce_ray < (int)ceilf(num_bounce_rays); bounce_ray++)
1161  {
1162  int height;
1163  if (num_bounce_rays == 0.5f)
1164  height = qvk.extent_render.height / 2;
1165  else
1166  height = qvk.extent_render.height;
1167 
1168  int rgen_index = (bounce_ray == 0)
1171 
1172  qvkCmdTraceRaysNV(cmd_buf,
1173  buf_shader_binding_table.buffer, rgen_index * rt_properties.shaderGroupHandleSize,
1174  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1175  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1176  VK_NULL_HANDLE, 0, 0,
1177  qvk.extent_render.width / 2, height, qvk.device_count == 1 ? 2 : 1);
1178 
1179  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_SH]);
1180  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_LF_COCG]);
1181  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_HF]);
1182  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_COLOR_SPEC]);
1183  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_BOUNCE_THROUGHPUT]);
1184  }
1185  }
1186  }
1187 
1188  END_PERF_MARKER(cmd_buf, PROFILER_INDIRECT_LIGHTING);
1189 
1190  set_current_gpu(cmd_buf, ALL_GPUS);
1191 
1192  return VK_SUCCESS;
1193 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_pt_trace_primary_rays()

VkResult vkpt_pt_trace_primary_rays ( VkCommandBuffer  cmd_buf)

Definition at line 1009 of file path_tracer.c.

1010 {
1011  int frame_idx = qvk.frame_counter & 1;
1012 
1013  BUFFER_BARRIER(cmd_buf,
1014  .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1015  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
1016  .buffer = qvk.buf_readback.buffer,
1017  .offset = 0,
1018  .size = VK_WHOLE_SIZE,
1019  );
1020 
1021  setup_rt_pipeline(cmd_buf);
1022 
1023  BEGIN_PERF_MARKER(cmd_buf, PROFILER_PRIMARY_RAYS);
1024 
1025  for(int i = 0; i < qvk.device_count; i++)
1026  {
1027  set_current_gpu(cmd_buf, i);
1028 
1029  int idx = qvk.device_count == 1 ? -1 : i;
1030  vkCmdPushConstants(cmd_buf, rt_pipeline_layout, VK_SHADER_STAGE_RAYGEN_BIT_NV, 0, sizeof(int), &idx);
1031 
1032  qvkCmdTraceRaysNV(cmd_buf,
1034  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1035  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1036  VK_NULL_HANDLE, 0, 0,
1037  qvk.extent_render.width / 2, qvk.extent_render.height, qvk.device_count == 1 ? 2 : 1);
1038  }
1039 
1040  set_current_gpu(cmd_buf, ALL_GPUS);
1041 
1042  END_PERF_MARKER(cmd_buf, PROFILER_PRIMARY_RAYS);
1043 
1044  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_VISBUF]);
1045  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_TRANSPARENT]);
1046  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_TEX_GRADIENTS]);
1047  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_MOTION]);
1048  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_SHADING_POSITION]);
1049  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_VIEW_DIRECTION]);
1050  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_THROUGHPUT]);
1051  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_BOUNCE_THROUGHPUT]);
1052  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_GODRAYS_THROUGHPUT_DIST]);
1053  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_ALBEDO]);
1054  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_METALLIC]);
1055  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_CLUSTER]);
1056  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_VIEW_DEPTH_A + frame_idx]);
1057  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_NORMAL_A + frame_idx]);
1058 
1059  return VK_SUCCESS;
1060 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_pt_trace_reflections()

VkResult vkpt_pt_trace_reflections ( VkCommandBuffer  cmd_buf,
int  bounce 
)

Definition at line 1063 of file path_tracer.c.

1064 {
1065  int frame_idx = qvk.frame_counter & 1;
1066 
1067  setup_rt_pipeline(cmd_buf);
1068 
1069  for (int i = 0; i < qvk.device_count; i++)
1070  {
1071  set_current_gpu(cmd_buf, i);
1072 
1073  int idx = qvk.device_count == 1 ? -1 : i;
1074  vkCmdPushConstants(cmd_buf, rt_pipeline_layout, VK_SHADER_STAGE_RAYGEN_BIT_NV, 0, sizeof(int), &idx);
1075  vkCmdPushConstants(cmd_buf, rt_pipeline_layout, VK_SHADER_STAGE_RAYGEN_BIT_NV, sizeof(int), sizeof(int), &bounce);
1076 
1077  int shader = (bounce == 0) ? SBT_RGEN_REFLECT_REFRACT1 : SBT_RGEN_REFLECT_REFRACT2;
1078 
1079  qvkCmdTraceRaysNV(cmd_buf,
1080  buf_shader_binding_table.buffer, shader * rt_properties.shaderGroupHandleSize,
1081  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1082  buf_shader_binding_table.buffer, 0, rt_properties.shaderGroupHandleSize,
1083  VK_NULL_HANDLE, 0, 0,
1084  qvk.extent_render.width / 2, qvk.extent_render.height, qvk.device_count == 1 ? 2 : 1);
1085  }
1086 
1087  set_current_gpu(cmd_buf, ALL_GPUS);
1088 
1089  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_TRANSPARENT]);
1090  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_MOTION]);
1091  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_SHADING_POSITION]);
1092  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_VIEW_DIRECTION]);
1093  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_THROUGHPUT]);
1094  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_GODRAYS_THROUGHPUT_DIST]);
1095  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_ALBEDO]);
1096  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_METALLIC]);
1097  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_CLUSTER]);
1098  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_VIEW_DEPTH_A + frame_idx]);
1099  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_PT_NORMAL_A + frame_idx]);
1100 
1101  return VK_SUCCESS;
1102 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_pt_update_descripter_set_bindings()

VkResult vkpt_pt_update_descripter_set_bindings ( int  idx)

Definition at line 251 of file path_tracer.c.

252 {
253  /* update descriptor set bindings */
254  VkWriteDescriptorSetAccelerationStructureNV desc_accel_struct_info = {
255  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_NV,
256  .accelerationStructureCount = 1,
257  .pAccelerationStructures = accel_top + idx
258  };
259 
263 
264  VkWriteDescriptorSet writes[] = {
265  {
266  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
267  .pNext = &desc_accel_struct_info,
268  .dstSet = rt_descriptor_set[idx],
270  .descriptorCount = 1,
271  .descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV
272  },
273  {
274  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
275  .dstSet = rt_descriptor_set[idx],
277  .descriptorCount = 1,
278  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
279  .pTexelBufferView = &particle_color_buffer_view
280  },
281  {
282  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
283  .dstSet = rt_descriptor_set[idx],
285  .descriptorCount = 1,
286  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
287  .pTexelBufferView = &beam_color_buffer_view
288  },
289  {
290  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
291  .dstSet = rt_descriptor_set[idx],
293  .descriptorCount = 1,
294  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
295  .pTexelBufferView = &sprite_info_buffer_view
296  },
297  };
298 
299  vkUpdateDescriptorSets(qvk.device, LENGTH(writes), writes, 0, NULL);
300 
301  return VK_SUCCESS;
302 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_readback()

VkResult vkpt_readback ( struct ReadbackBuffer dst)

Definition at line 659 of file vertex_buffer.c.

660 {
662  void* mapped = buffer_map(buffer);
663 
664  if (mapped == NULL)
665  return VK_ERROR_MEMORY_MAP_FAILED;
666 
667  memcpy(dst, mapped, sizeof(ReadbackBuffer));
668 
669  buffer_unmap(buffer);
670 
671  return VK_SUCCESS;
672 }

Referenced by process_render_feedback().

◆ vkpt_record_god_rays_filter_command_buffer()

void vkpt_record_god_rays_filter_command_buffer ( VkCommandBuffer  command_buffer)

Definition at line 169 of file god_rays.c.

170 {
171  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_PT_TRANSPARENT]);
172 
173  const VkImageSubresourceRange subresource_range = {
174  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
175  .levelCount = 1,
176  .layerCount = 1
177  };
178 
179  vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, god_rays.pipelines[1]);
180 
181  VkDescriptorSet desc_sets[] = {
182  god_rays.descriptor_set,
186  };
187 
188  vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, god_rays.pipeline_layout, 0, LENGTH(desc_sets),
189  desc_sets, 0, NULL);
190 
191  int pass = 0;
192  vkCmdPushConstants(command_buffer, god_rays.pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(int), &pass);
193 
194  uint32_t group_size = FILTER_THREAD_GROUP_SIZE;
195  uint32_t group_num_x = (qvk.extent_render.width / qvk.device_count + (group_size - 1)) / group_size;
196  uint32_t group_num_y = (qvk.extent_render.height + (group_size - 1)) / group_size;
197 
198  vkCmdDispatch(command_buffer, group_num_x, group_num_y, 1);
199 
200  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_PT_TRANSPARENT]);
201 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_record_god_rays_trace_command_buffer()

void vkpt_record_god_rays_trace_command_buffer ( VkCommandBuffer  command_buffer,
int  pass 
)

Definition at line 140 of file god_rays.c.

141 {
142  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_PT_GODRAYS_THROUGHPUT_DIST]);
143  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_ASVGF_COLOR]);
144 
145  vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, god_rays.pipelines[0]);
146 
147  VkDescriptorSet desc_sets[] = {
148  god_rays.descriptor_set,
152  };
153 
154  vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, god_rays.pipeline_layout, 0, LENGTH(desc_sets),
155  desc_sets, 0, NULL);
156 
157  vkCmdPushConstants(command_buffer, god_rays.pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(int), &pass);
158 
159  uint32_t group_size = THREAD_GROUP_SIZE;
160  uint32_t group_num_x = (qvk.extent_render.width / (2 * qvk.device_count) + (group_size - 1)) / group_size;
161  uint32_t group_num_y = (qvk.extent_render.height / 2 + (group_size - 1)) / group_size;
162 
163  vkCmdDispatch(command_buffer, group_num_x, group_num_y, 1);
164 
165  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_PT_GODRAYS_THROUGHPUT_DIST]);
166  BARRIER_COMPUTE(command_buffer, qvk.images[VKPT_IMG_ASVGF_COLOR]);
167 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_reset_accumulation()

void vkpt_reset_accumulation ( )

Definition at line 219 of file main.c.

220 {
222 }

Referenced by physical_sky_cvar_changed(), and vkpt_freecam_update().

◆ vkpt_reset_command_buffers()

void vkpt_reset_command_buffers ( cmd_buf_group_t group)

Definition at line 3392 of file main.c.

3393 {
3394  group->used_this_frame = 0;
3395 
3396 #ifdef _DEBUG
3397  for (int i = 0; i < group->count_per_frame; i++)
3398  {
3399  void* addr = group->buffer_begin_addrs[group->count_per_frame * qvk.current_frame_index + i];
3400  assert(addr == 0);
3401  }
3402 #endif
3403 }

Referenced by R_BeginFrame_RTX(), and vkpt_wait_idle().

◆ vkpt_shadow_map_create_pipelines()

VkResult vkpt_shadow_map_create_pipelines ( )

Definition at line 209 of file shadow_map.c.

210 {
211  LOG_FUNC();
212 
213  VkPipelineShaderStageCreateInfo shader_info[] = {
214  SHADER_STAGE(QVK_MOD_SHADOW_MAP_VERT, VK_SHADER_STAGE_VERTEX_BIT)
215  };
216 
217  VkVertexInputBindingDescription vertex_binding_desc = {
218  .binding = 0,
219  .stride = sizeof(float) * 3,
220  .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
221  };
222 
223  VkVertexInputAttributeDescription vertex_attribute_desc = {
224  .location = 0,
225  .binding = 0,
226  .format = VK_FORMAT_R32G32B32_SFLOAT,
227  .offset = 0
228  };
229 
230  VkPipelineVertexInputStateCreateInfo vertex_input_info = {
231  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
232  .vertexBindingDescriptionCount = 1,
233  .pVertexBindingDescriptions = &vertex_binding_desc,
234  .vertexAttributeDescriptionCount = 1,
235  .pVertexAttributeDescriptions = &vertex_attribute_desc,
236  };
237 
238  VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
239  .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
240  .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
241  };
242 
243  VkViewport viewport = {
244  .x = 0.0f,
245  .y = 0.0f,
246  .width = (float)SHADOWMAP_SIZE,
247  .height = (float)SHADOWMAP_SIZE,
248  .minDepth = 0.0f,
249  .maxDepth = 1.0f,
250  };
251 
252  VkRect2D scissor = {
253  .offset = { 0, 0 },
254  .extent = { SHADOWMAP_SIZE, SHADOWMAP_SIZE }
255  };
256 
257  VkPipelineViewportStateCreateInfo viewport_state = {
258  .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
259  .viewportCount = 1,
260  .pViewports = &viewport,
261  .scissorCount = 1,
262  .pScissors = &scissor,
263  };
264 
265  VkPipelineRasterizationStateCreateInfo rasterizer_state = {
266  .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
267  .polygonMode = VK_POLYGON_MODE_FILL,
268  .lineWidth = 1.0f,
269  .cullMode = VK_CULL_MODE_FRONT_BIT,
270  .frontFace = VK_FRONT_FACE_CLOCKWISE,
271  };
272 
273  VkPipelineMultisampleStateCreateInfo multisample_state = {
274  .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
275  .sampleShadingEnable = VK_FALSE,
276  .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
277  .minSampleShading = 1.0f,
278  .pSampleMask = NULL,
279  .alphaToCoverageEnable = VK_FALSE,
280  .alphaToOneEnable = VK_FALSE,
281  };
282 
283  VkPipelineDepthStencilStateCreateInfo depth_stencil_state = {
284  .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
285  .depthTestEnable = VK_TRUE,
286  .depthWriteEnable = VK_TRUE,
287  .depthCompareOp = VK_COMPARE_OP_LESS,
288  };
289 
290  VkDynamicState dynamic_states[] = {
291  VK_DYNAMIC_STATE_VIEWPORT,
292  VK_DYNAMIC_STATE_SCISSOR
293  };
294 
295  VkPipelineDynamicStateCreateInfo dynamic_state_info = {
296  .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
297  .dynamicStateCount = LENGTH(dynamic_states),
298  .pDynamicStates = dynamic_states
299  };
300 
301  VkGraphicsPipelineCreateInfo pipeline_info = {
302  .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
303  .stageCount = LENGTH(shader_info),
304  .pStages = shader_info,
305 
306  .pVertexInputState = &vertex_input_info,
307  .pInputAssemblyState = &input_assembly_info,
308  .pViewportState = &viewport_state,
309  .pRasterizationState = &rasterizer_state,
310  .pMultisampleState = &multisample_state,
311  .pDepthStencilState = &depth_stencil_state,
312  .pColorBlendState = NULL,
313  .pDynamicState = &dynamic_state_info,
314 
315  .layout = pipeline_layout_smap,
316  .renderPass = render_pass_smap,
317  .subpass = 0,
318 
319  .basePipelineHandle = VK_NULL_HANDLE,
320  .basePipelineIndex = -1,
321  };
322 
323  _VK(vkCreateGraphicsPipelines(qvk.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline_smap));
325 
326  VkImageView attachments[] = {
328  };
329 
330  VkFramebufferCreateInfo fb_create_info = {
331  .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
332  .renderPass = render_pass_smap,
333  .attachmentCount = 1,
334  .pAttachments = attachments,
335  .width = SHADOWMAP_SIZE,
336  .height = SHADOWMAP_SIZE,
337  .layers = 1,
338  };
339 
340  _VK(vkCreateFramebuffer(qvk.device, &fb_create_info, NULL, &framebuffer_smap));
342 
343  attachments[0] = imv_smap_depth2;
344  _VK(vkCreateFramebuffer(qvk.device, &fb_create_info, NULL, &framebuffer_smap2));
346 
347  return VK_SUCCESS;
348 }

◆ vkpt_shadow_map_destroy()

VkResult vkpt_shadow_map_destroy ( )

Definition at line 182 of file shadow_map.c.

183 {
184  vkDestroyImageView(qvk.device, imv_smap_depth, NULL);
185  imv_smap_depth = VK_NULL_HANDLE;
186  vkDestroyImageView(qvk.device, imv_smap_depth2, NULL);
187  imv_smap_depth2 = VK_NULL_HANDLE;
188  vkDestroyImageView(qvk.device, imv_smap_depth_array, NULL);
189  imv_smap_depth_array = VK_NULL_HANDLE;
190  vkDestroyImage(qvk.device, img_smap, NULL);
191  img_smap = VK_NULL_HANDLE;
192  vkFreeMemory(qvk.device, mem_smap, NULL);
193  mem_smap = VK_NULL_HANDLE;
194 
195  vkDestroyRenderPass(qvk.device, render_pass_smap, NULL);
196  render_pass_smap = VK_NULL_HANDLE;
197  vkDestroyPipelineLayout(qvk.device, pipeline_layout_smap, NULL);
198  pipeline_layout_smap = VK_NULL_HANDLE;
199 
200  return VK_SUCCESS;
201 }

◆ vkpt_shadow_map_destroy_pipelines()

VkResult vkpt_shadow_map_destroy_pipelines ( )

Definition at line 351 of file shadow_map.c.

352 {
353  LOG_FUNC();
354  vkDestroyFramebuffer(qvk.device, framebuffer_smap, NULL);
355  framebuffer_smap = VK_NULL_HANDLE;
356  vkDestroyFramebuffer(qvk.device, framebuffer_smap2, NULL);
357  framebuffer_smap2 = VK_NULL_HANDLE;
358  vkDestroyPipeline(qvk.device, pipeline_smap, NULL);
359  pipeline_smap = VK_NULL_HANDLE;
360  return VK_SUCCESS;
361 }

◆ vkpt_shadow_map_get_view()

VkImageView vkpt_shadow_map_get_view ( )

Definition at line 203 of file shadow_map.c.

204 {
205  return imv_smap_depth_array;
206 }

Referenced by create_image_views().

◆ vkpt_shadow_map_initialize()

VkResult vkpt_shadow_map_initialize ( )

Definition at line 87 of file shadow_map.c.

88 {
90 
91  VkPushConstantRange push_constant_range = {
92  .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
93  .offset = 0,
94  .size = sizeof(float) * 16,
95  };
96 
98  .pushConstantRangeCount = 1,
99  .pPushConstantRanges = &push_constant_range,
100  );
101 
102 
103  VkImageCreateInfo img_info = {
104  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
105  .extent = {
106  .width = SHADOWMAP_SIZE,
107  .height = SHADOWMAP_SIZE,
108  .depth = 1,
109  },
110  .imageType = VK_IMAGE_TYPE_2D,
111  .format = VK_FORMAT_D32_SFLOAT,
112  .mipLevels = 1,
113  .arrayLayers = 2,
114  .samples = VK_SAMPLE_COUNT_1_BIT,
115  .tiling = VK_IMAGE_TILING_OPTIMAL,
116  .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
117  | VK_IMAGE_USAGE_SAMPLED_BIT,
118  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
119  .queueFamilyIndexCount = qvk.queue_idx_graphics,
120  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
121  };
122 
123  _VK(vkCreateImage(qvk.device, &img_info, NULL, &img_smap));
125 
126  VkMemoryRequirements mem_req;
127  vkGetImageMemoryRequirements(qvk.device, img_smap, &mem_req);
128 
129  _VK(allocate_gpu_memory(mem_req, &mem_smap));
130 
131  _VK(vkBindImageMemory(qvk.device, img_smap, mem_smap, 0));
132 
133  VkImageViewCreateInfo img_view_info = {
134  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
135  .viewType = VK_IMAGE_VIEW_TYPE_2D,
136  .format = VK_FORMAT_D32_SFLOAT,
137  .image = img_smap,
138  .subresourceRange = {
139  .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,
140  .baseMipLevel = 0,
141  .levelCount = 1,
142  .baseArrayLayer = 0,
143  .layerCount = 1,
144  },
145  .components = {
146  VK_COMPONENT_SWIZZLE_R,
147  VK_COMPONENT_SWIZZLE_G,
148  VK_COMPONENT_SWIZZLE_B,
149  VK_COMPONENT_SWIZZLE_A,
150  },
151  };
152  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth));
154 
155  img_view_info.subresourceRange.baseArrayLayer = 1;
156  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth2));
158 
159  img_view_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
160  img_view_info.subresourceRange.baseArrayLayer = 0;
161  img_view_info.subresourceRange.layerCount = 2;
162  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_smap_depth_array));
164 
165  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
166 
167  IMAGE_BARRIER(cmd_buf,
168  .image = img_smap,
169  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,.levelCount = 1,.layerCount = 2 },
170  .srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
171  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
172  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
173  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
174  );
175 
177 
178  return VK_SUCCESS;
179 }

◆ vkpt_shadow_map_render()

VkResult vkpt_shadow_map_render ( VkCommandBuffer  cmd_buf,
float *  view_projection_matrix,
int  num_static_verts,
int  num_dynamic_verts,
int  transparent_offset,
int  num_transparent_verts 
)

Definition at line 364 of file shadow_map.c.

365 {
366  IMAGE_BARRIER(cmd_buf,
367  .image = img_smap,
368  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT, .levelCount = 1, .layerCount = 2 },
369  .srcAccessMask = VK_ACCESS_SHADER_READ_BIT,
370  .dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
371  .oldLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
372  .newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
373  );
374 
375  VkClearValue clear_depth = { .depthStencil = { .depth = 1.f } };
376 
377  VkRenderPassBeginInfo render_pass_info = {
378  .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
379  .renderPass = render_pass_smap,
380  .framebuffer = framebuffer_smap,
381  .renderArea.offset = { 0, 0 },
382  .renderArea.extent = { SHADOWMAP_SIZE, SHADOWMAP_SIZE },
383  .clearValueCount = 1,
384  .pClearValues = &clear_depth
385  };
386 
387  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
388  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_smap);
389 
390  VkViewport viewport =
391  {
392  .width = (float)SHADOWMAP_SIZE,
393  .height = (float)SHADOWMAP_SIZE,
394  .minDepth = 0,
395  .maxDepth = 1.0f,
396  };
397 
398  vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
399 
400  VkRect2D scissor =
401  {
402  .extent.width = SHADOWMAP_SIZE,
403  .extent.height = SHADOWMAP_SIZE,
404  .offset.x = 0,
405  .offset.y = 0,
406  };
407 
408  vkCmdSetScissor(cmd_buf, 0, 1, &scissor);
409 
410  vkCmdPushConstants(cmd_buf, pipeline_layout_smap, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float) * 16, view_projection_matrix);
411 
412  VkDeviceSize vertex_offset = offsetof(struct VertexBuffer, positions_bsp);
413  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
414 
415  vkCmdDraw(cmd_buf, num_static_verts, 1, 0, 0);
416 
417  vertex_offset = offsetof(struct VertexBuffer, positions_instanced);
418  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
419 
420  vkCmdDraw(cmd_buf, num_dynamic_verts, 1, 0, 0);
421 
422  vkCmdEndRenderPass(cmd_buf);
423 
424 
425  render_pass_info.framebuffer = framebuffer_smap2;
426  vkCmdBeginRenderPass(cmd_buf, &render_pass_info, VK_SUBPASS_CONTENTS_INLINE);
427 
428  vertex_offset = offsetof(struct VertexBuffer, positions_bsp);
429  vkCmdBindVertexBuffers(cmd_buf, 0, 1, &qvk.buf_vertex.buffer, &vertex_offset);
430 
431  vkCmdDraw(cmd_buf, num_transparent_verts, 1, transparent_offset, 0);
432 
433  vkCmdEndRenderPass(cmd_buf);
434 
435 
436  IMAGE_BARRIER(cmd_buf,
437  .image = img_smap,
438  .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT,.levelCount = 1,.layerCount = 2 },
439  .srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
440  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
441  .oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
442  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
443  );
444 
445  return VK_SUCCESS;
446 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_shadow_map_setup()

void vkpt_shadow_map_setup ( const sun_light_t light,
const float *  bbox_min,
const float *  bbox_max,
float *  VP,
float *  depth_scale,
qboolean  random_sampling 
)

Definition at line 460 of file shadow_map.c.

461 {
462  vec3_t up_dir = { 0.0f, 0.0f, 1.0f };
463  if (light->direction[2] >= 0.99f)
464  VectorSet(up_dir, 1.f, 0.f, 0.f);
465 
466  vec3_t look_dir;
467  VectorScale(light->direction, -1.f, look_dir);
468  VectorNormalize(look_dir);
469  vec3_t left_dir;
470  CrossProduct(up_dir, look_dir, left_dir);
471  VectorNormalize(left_dir);
472  CrossProduct(look_dir, left_dir, up_dir);
473  VectorNormalize(up_dir);
474 
475  if (random_sampling)
476  {
477  float u, v;
478  sample_disk(&u, &v);
479 
480  VectorMA(look_dir, u * light->angular_size_rad * 0.5f, left_dir, look_dir);
481  VectorMA(look_dir, v * light->angular_size_rad * 0.5f, up_dir, look_dir);
482 
483  VectorNormalize(look_dir);
484 
485  CrossProduct(up_dir, look_dir, left_dir);
486  VectorNormalize(left_dir);
487  CrossProduct(look_dir, left_dir, up_dir);
488  VectorNormalize(up_dir);
489  }
490 
491  float view_matrix[16] = {
492  left_dir[0], up_dir[0], look_dir[0], 0.f,
493  left_dir[1], up_dir[1], look_dir[1], 0.f,
494  left_dir[2], up_dir[2], look_dir[2], 0.f,
495  0.f, 0.f, 0.f, 1.f
496  };
497 
498  vec3_t view_aabb_min = { FLT_MAX, FLT_MAX, FLT_MAX };
499  vec3_t view_aabb_max = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
500 
501  for (int i = 0; i < 8; i++)
502  {
503  float corner[4];
504  corner[0] = (i & 1) ? bbox_max[0] : bbox_min[0];
505  corner[1] = (i & 2) ? bbox_max[1] : bbox_min[1];
506  corner[2] = (i & 4) ? bbox_max[2] : bbox_min[2];
507  corner[3] = 1.f;
508 
509  float view_corner[4];
510  mult_matrix_vector(view_corner, view_matrix, corner);
511 
512  view_aabb_min[0] = min(view_aabb_min[0], view_corner[0]);
513  view_aabb_min[1] = min(view_aabb_min[1], view_corner[1]);
514  view_aabb_min[2] = min(view_aabb_min[2], view_corner[2]);
515  view_aabb_max[0] = max(view_aabb_max[0], view_corner[0]);
516  view_aabb_max[1] = max(view_aabb_max[1], view_corner[1]);
517  view_aabb_max[2] = max(view_aabb_max[2], view_corner[2]);
518  }
519 
520  vec3_t diagonal;
521  VectorSubtract(view_aabb_max, view_aabb_min, diagonal);
522 
523  float maxXY = max(diagonal[0], diagonal[1]);
524  vec3_t diff;
525  diff[0] = (maxXY - diagonal[0]) * 0.5f;
526  diff[1] = (maxXY - diagonal[1]) * 0.5f;
527  diff[2] = 0.f;
528  VectorSubtract(view_aabb_min, diff, view_aabb_min);
529  VectorAdd(view_aabb_max, diff, view_aabb_max);
530 
531  float projection_matrix[16];
532  create_orthographic_matrix(projection_matrix, view_aabb_min[0], view_aabb_max[0], view_aabb_min[1], view_aabb_max[1], view_aabb_min[2], view_aabb_max[2]);
533  mult_matrix_matrix(VP, projection_matrix, view_matrix);
534 
535  *depth_scale = view_aabb_max[2] - view_aabb_min[2];
536 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_submit_command_buffer()

void vkpt_submit_command_buffer ( VkCommandBuffer  cmd_buf,
VkQueue  queue,
uint32_t  execute_device_mask,
int  wait_semaphore_count,
VkSemaphore *  wait_semaphores,
VkPipelineStageFlags *  wait_stages,
uint32_t *  wait_device_indices,
int  signal_semaphore_count,
VkSemaphore *  signal_semaphores,
uint32_t *  signal_device_indices,
VkFence  fence 
)

Definition at line 3411 of file main.c.

3423 {
3424  _VK(vkEndCommandBuffer(cmd_buf));
3425 
3426  VkSubmitInfo submit_info = {
3427  .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
3428  .waitSemaphoreCount = wait_semaphore_count,
3429  .pWaitSemaphores = wait_semaphores,
3430  .pWaitDstStageMask = wait_stages,
3431  .signalSemaphoreCount = signal_semaphore_count,
3432  .pSignalSemaphores = signal_semaphores,
3433  .commandBufferCount = 1,
3434  .pCommandBuffers = &cmd_buf,
3435  };
3436 
3437 #ifdef VKPT_DEVICE_GROUPS
3438  VkDeviceGroupSubmitInfoKHR device_group_submit_info = {
3439  .sType = VK_STRUCTURE_TYPE_DEVICE_GROUP_SUBMIT_INFO_KHR,
3440  .pNext = NULL,
3441  .waitSemaphoreCount = wait_semaphore_count,
3442  .pWaitSemaphoreDeviceIndices = wait_device_indices,
3443  .commandBufferCount = 1,
3444  .pCommandBufferDeviceMasks = &execute_device_mask,
3445  .signalSemaphoreCount = signal_semaphore_count,
3446  .pSignalSemaphoreDeviceIndices = signal_device_indices,
3447  };
3448 
3449  if (qvk.device_count > 1) {
3450  submit_info.pNext = &device_group_submit_info;
3451  }
3452 #endif
3453 
3454  _VK(vkQueueSubmit(queue, 1, &submit_info, fence));
3455 
3456 #ifdef _DEBUG
3458  for (int ngroup = 0; ngroup < LENGTH(groups); ngroup++)
3459  {
3460  cmd_buf_group_t* group = groups[ngroup];
3461  for (int i = 0; i < MAX_FRAMES_IN_FLIGHT * group->count_per_frame; i++)
3462  {
3463  if (group->buffers[i] == cmd_buf)
3464  {
3465  group->buffer_begin_addrs[i] = NULL;
3466  return;
3467  }
3468  }
3469  }
3470 #endif
3471 }

Referenced by R_EndFrame_RTX(), R_RenderFrame_RTX(), vkpt_submit_command_buffer_simple(), and vkpt_vertex_buffer_upload_staging().

◆ vkpt_submit_command_buffer_simple()

void vkpt_submit_command_buffer_simple ( VkCommandBuffer  cmd_buf,
VkQueue  queue,
qboolean  all_gpus 
)

◆ vkpt_taa()

VkResult vkpt_taa ( VkCommandBuffer  cmd_buf)

Definition at line 555 of file asvgf.c.

556 {
557  VkDescriptorSet desc_sets[] = {
561  };
562 
563  BEGIN_PERF_MARKER(cmd_buf, PROFILER_ASVGF_TAA);
564 
565  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[TAA]);
566  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
567  pipeline_layout_taa, 0, LENGTH(desc_sets), desc_sets, 0, 0);
568 
569  VkExtent2D dispatch_size = qvk.extent_render;
570 
571  if(dispatch_size.width < qvk.extent_screen_images.width)
572  dispatch_size.width += 8;
573 
574  if (dispatch_size.height < qvk.extent_screen_images.height)
575  dispatch_size.height += 8;
576 
577  vkCmdDispatch(cmd_buf,
578  (dispatch_size.width + 15) / 16,
579  (dispatch_size.height + 15) / 16,
580  1);
581  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_TAA_A]);
582  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_TAA_B]);
583  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_TAA_B]);
584 
585  END_PERF_MARKER(cmd_buf, PROFILER_ASVGF_TAA);
586 
587  return VK_SUCCESS;
588 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_textures_destroy()

VkResult vkpt_textures_destroy ( )

Definition at line 1045 of file textures.c.

1046 {
1048  vkDestroyDescriptorSetLayout(qvk.device, qvk.desc_set_layout_textures, NULL);
1049  vkDestroyDescriptorPool(qvk.device, desc_pool_textures, NULL);
1050 
1051  vkFreeMemory (qvk.device, mem_blue_noise, NULL);
1052  vkDestroyImage (qvk.device, img_blue_noise, NULL);
1053  vkDestroyImageView(qvk.device, imv_blue_noise, NULL);
1054  vkDestroySampler (qvk.device, qvk.tex_sampler, NULL);
1055  vkDestroySampler (qvk.device, qvk.tex_sampler_nearest, NULL);
1056  vkDestroySampler (qvk.device, qvk.tex_sampler_linear_clamp, NULL);
1057 
1058  if(imv_envmap != VK_NULL_HANDLE) {
1059  vkDestroyImageView(qvk.device, imv_envmap, NULL);
1060  imv_envmap = NULL;
1061  }
1062  if(img_envmap != VK_NULL_HANDLE) {
1063  vkDestroyImage(qvk.device, img_envmap, NULL);
1064  img_envmap = NULL;
1065  }
1066  if (mem_envmap != VK_NULL_HANDLE) {
1067  vkFreeMemory(qvk.device, mem_envmap, NULL);
1068  mem_envmap = VK_NULL_HANDLE;
1069  }
1070 
1074 
1075  LOG_FUNC();
1076  return VK_SUCCESS;
1077 }

◆ vkpt_textures_destroy_unused()

void vkpt_textures_destroy_unused ( )

Definition at line 144 of file textures.c.

Referenced by R_BeginFrame_RTX(), and R_Shutdown_RTX().

◆ vkpt_textures_end_registration()

VkResult vkpt_textures_end_registration ( )

Definition at line 1087 of file textures.c.

1088 {
1090  return VK_SUCCESS;
1092 
1093  VkImageCreateInfo img_info = {
1094  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1095  .extent = {
1096  .width = 1337,
1097  .height = 1337,
1098  .depth = 1
1099  },
1100  .imageType = VK_IMAGE_TYPE_2D,
1101  .format = VK_FORMAT_UNDEFINED,
1102  .mipLevels = 1,
1103  .arrayLayers = 1,
1104  .samples = VK_SAMPLE_COUNT_1_BIT,
1105  .tiling = VK_IMAGE_TILING_OPTIMAL,
1106  .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
1107  | VK_IMAGE_USAGE_TRANSFER_SRC_BIT
1108  | VK_IMAGE_USAGE_SAMPLED_BIT,
1109  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
1110  .queueFamilyIndexCount = qvk.queue_idx_graphics,
1111  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1112  };
1113 
1114  VkImageViewCreateInfo img_view_info = {
1115  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1116  .viewType = VK_IMAGE_VIEW_TYPE_2D,
1117  .format = VK_FORMAT_UNDEFINED,
1118  .subresourceRange = {
1119  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1120  .baseMipLevel = 0,
1121  .levelCount = 1,
1122  .baseArrayLayer = 0,
1123  .layerCount = 1
1124  },
1125  .components = {
1126  VK_COMPONENT_SWIZZLE_R,
1127  VK_COMPONENT_SWIZZLE_G,
1128  VK_COMPONENT_SWIZZLE_B,
1129  VK_COMPONENT_SWIZZLE_A
1130  },
1131  };
1132 
1133 #ifdef VKPT_DEVICE_GROUPS
1134  if (qvk.device_count > 1) {
1135  mem_alloc_flags_broadcast.deviceMask = (1 << qvk.device_count) - 1;
1136  }
1137 #endif
1138 
1139  uint32_t new_image_num = 0;
1140  size_t total_size = 0;
1141  for(int i = 0; i < MAX_RIMAGES; i++) {
1142  image_t *q_img = r_images + i;
1143 
1144  if (tex_images[i] != VK_NULL_HANDLE || !q_img->registration_sequence || q_img->pix_data == NULL)
1145  continue;
1146 
1147  img_info.extent.width = q_img->upload_width;
1148  img_info.extent.height = q_img->upload_height;
1149  img_info.mipLevels = get_num_miplevels(q_img->upload_width, q_img->upload_height);
1150  img_info.format = q_img->is_srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
1151 
1152  _VK(vkCreateImage(qvk.device, &img_info, NULL, tex_images + i));
1153  ATTACH_LABEL_VARIABLE(tex_images[i], IMAGE);
1154 
1155  VkMemoryRequirements mem_req;
1156  vkGetImageMemoryRequirements(qvk.device, tex_images[i], &mem_req);
1157 
1158  assert(!(mem_req.alignment & (mem_req.alignment - 1)));
1159  total_size += mem_req.alignment - 1;
1160  total_size &= ~(mem_req.alignment - 1);
1161  total_size += mem_req.size;
1162 
1163  DeviceMemory* image_memory = tex_image_memory + i;
1164  image_memory->size = mem_req.size;
1165  image_memory->alignment = mem_req.alignment;
1166  image_memory->memory_type = get_memory_type(mem_req.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
1167 
1169 
1170  VkBindImageMemoryInfo* bind_info = tex_bind_image_info + new_image_num;
1171  bind_info->sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
1172  bind_info->image = tex_images[i];
1173  bind_info->memory = image_memory->memory;
1174  bind_info->memoryOffset = image_memory->memory_offset;
1175 
1176  new_image_num++;
1177  }
1178 
1179  if (new_image_num == 0)
1180  return VK_SUCCESS;
1181  vkBindImageMemory2(qvk.device, new_image_num, tex_bind_image_info);
1182 
1183  BufferResource_t buf_img_upload;
1184  buffer_create(&buf_img_upload, total_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
1185  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1186 
1187  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
1188 
1189  char *staging_buffer = buffer_map(&buf_img_upload);
1190 
1191  size_t offset = 0;
1192  for(int i = 0; i < MAX_RIMAGES; i++) {
1193  image_t *q_img = r_images + i;
1194 
1195  if (tex_images[i] == VK_NULL_HANDLE || tex_image_views[i] != VK_NULL_HANDLE)
1196  continue;
1197 
1198  int num_mip_levels = get_num_miplevels(q_img->upload_width, q_img->upload_height);
1199 
1200  VkMemoryRequirements mem_req;
1201  vkGetImageMemoryRequirements(qvk.device, tex_images[i], &mem_req);
1202 
1203  assert(!(mem_req.alignment & (mem_req.alignment - 1)));
1204  offset += mem_req.alignment - 1;
1205  offset &= ~(mem_req.alignment - 1);
1206 
1207  uint32_t wd = q_img->upload_width;
1208  uint32_t ht = q_img->upload_height;
1209 
1210  VkImageSubresourceRange subresource_range = {
1211  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1212  .baseMipLevel = 0,
1213  .levelCount = num_mip_levels,
1214  .baseArrayLayer = 0,
1215  .layerCount = 1
1216  };
1217 
1218  IMAGE_BARRIER(cmd_buf,
1219  .image = tex_images[i],
1220  .subresourceRange = subresource_range,
1221  .srcAccessMask = 0,
1222  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1223  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1224  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
1225  );
1226 
1227  {
1228  memcpy(staging_buffer + offset, q_img->pix_data, wd * ht * 4);
1229 
1230  VkBufferImageCopy cpy_info = {
1231  .bufferOffset = offset,
1232  .imageSubresource = {
1233  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1234  .mipLevel = 0,
1235  .baseArrayLayer = 0,
1236  .layerCount = 1,
1237  },
1238  .imageOffset = { 0, 0, 0 },
1239  .imageExtent = { wd, ht, 1 }
1240  };
1241 
1242  vkCmdCopyBufferToImage(cmd_buf, buf_img_upload.buffer, tex_images[i],
1243  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cpy_info);
1244  }
1245 
1246  subresource_range.levelCount = 1;
1247 
1248  for (int mip = 1; mip < num_mip_levels; mip++)
1249  {
1250  subresource_range.baseMipLevel = mip - 1;
1251 
1252  IMAGE_BARRIER(cmd_buf,
1253  .image = tex_images[i],
1254  .subresourceRange = subresource_range,
1255  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1256  .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1257  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1258  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1259  );
1260 
1261  int nwd = (wd > 1) ? (wd >> 1) : wd;
1262  int nht = (ht > 1) ? (ht >> 1) : ht;
1263 
1264  VkImageBlit region = {
1265  .srcSubresource = {
1266  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1267  .mipLevel = mip - 1,
1268  .baseArrayLayer = 0,
1269  .layerCount = 1
1270  },
1271  .srcOffsets = {
1272  { 0, 0, 0 },
1273  { wd, ht, 1 } },
1274 
1275  .dstSubresource = {
1276  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1277  .mipLevel = mip,
1278  .baseArrayLayer = 0,
1279  .layerCount = 1
1280  },
1281  .dstOffsets = {
1282  { 0, 0, 0 },
1283  { nwd, nht, 1 } }
1284  };
1285 
1286  vkCmdBlitImage(
1287  cmd_buf,
1288  tex_images[i], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1289  tex_images[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1290  1, &region,
1291  VK_FILTER_LINEAR);
1292 
1293  subresource_range.baseMipLevel = mip - 1;
1294 
1295  IMAGE_BARRIER(cmd_buf,
1296  .image = tex_images[i],
1297  .subresourceRange = subresource_range,
1298  .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1299  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
1300  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1301  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1302  );
1303 
1304  wd = nwd;
1305  ht = nht;
1306  }
1307 
1308  subresource_range.baseMipLevel = num_mip_levels - 1;
1309 
1310  IMAGE_BARRIER(cmd_buf,
1311  .image = tex_images[i],
1312  .subresourceRange = subresource_range,
1313  .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1314  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
1315  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1316  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1317  );
1318 
1319  img_view_info.image = tex_images[i];
1320  img_view_info.subresourceRange.levelCount = num_mip_levels;
1321  img_view_info.format = q_img->is_srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
1322  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, tex_image_views + i));
1323  ATTACH_LABEL_VARIABLE(tex_image_views[i], IMAGE_VIEW);
1324 
1325  offset += mem_req.size;
1326  }
1327 
1328  buffer_unmap(&buf_img_upload);
1329  staging_buffer = NULL;
1330 
1332 
1333 
1334  const uint32_t destroy_frame_index = (qvk.frame_counter + MAX_FRAMES_IN_FLIGHT) % DESTROY_LATENCY;
1335  UnusedResources* unused_resources = texture_system.unused_resources + destroy_frame_index;
1336 
1337  const uint32_t unused_index = unused_resources->buffer_num++;
1338  unused_resources->buffers[unused_index] = buf_img_upload.buffer;
1339  unused_resources->buffer_memory[unused_index] = buf_img_upload.memory;
1340 
1342 
1343  return VK_SUCCESS;
1344 }

Referenced by R_BeginFrame_RTX().

◆ vkpt_textures_initialize()

VkResult vkpt_textures_initialize ( )

Definition at line 821 of file textures.c.

822 {
824  memset(&texture_system, 0, sizeof(texture_system));
825 
827 
829 
830  VkSamplerCreateInfo sampler_info = {
831  .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
832  .magFilter = VK_FILTER_LINEAR,
833  .minFilter = VK_FILTER_LINEAR,
834  .addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
835  .addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
836  .addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
837  .anisotropyEnable = VK_TRUE,
838  .maxAnisotropy = 16,
839  .borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
840  .unnormalizedCoordinates = VK_FALSE,
841  .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
842  .minLod = 0.0f,
843  .maxLod = 128.0f,
844  };
845  _VK(vkCreateSampler(qvk.device, &sampler_info, NULL, &qvk.tex_sampler));
847  VkSamplerCreateInfo sampler_nearest_info = {
848  .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
849  .magFilter = VK_FILTER_NEAREST,
850  .minFilter = VK_FILTER_NEAREST,
851  .addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT,
852  .addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT,
853  .addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
854  .anisotropyEnable = VK_FALSE,
855  .maxAnisotropy = 16,
856  .borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
857  .unnormalizedCoordinates = VK_FALSE,
858  .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
859  };
860  _VK(vkCreateSampler(qvk.device, &sampler_nearest_info, NULL, &qvk.tex_sampler_nearest));
862 
863  VkSamplerCreateInfo sampler_linear_clamp_info = {
864  .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
865  .magFilter = VK_FILTER_LINEAR,
866  .minFilter = VK_FILTER_LINEAR,
867  .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
868  .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
869  .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
870  .anisotropyEnable = VK_FALSE,
871  .maxAnisotropy = 16,
872  .borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
873  .unnormalizedCoordinates = VK_FALSE,
874  .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
875  };
876  _VK(vkCreateSampler(qvk.device, &sampler_linear_clamp_info, NULL, &qvk.tex_sampler_linear_clamp));
878 
879  VkDescriptorSetLayoutBinding layout_bindings[] = {
880  {
881  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
882  .descriptorCount = MAX_RIMAGES,
883  .binding = 0,
884  .stageFlags = VK_SHADER_STAGE_ALL,
885  },
886 #define IMG_DO(_name, _binding, ...) \
887  { \
888  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, \
889  .descriptorCount = 1, \
890  .binding = BINDING_OFFSET_IMAGES + _binding, \
891  .stageFlags = VK_SHADER_STAGE_ALL, \
892  },
895 #undef IMG_DO
896 #define IMG_DO(_name, _binding, ...) \
897  { \
898  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, \
899  .descriptorCount = 1, \
900  .binding = BINDING_OFFSET_TEXTURES + _binding, \
901  .stageFlags = VK_SHADER_STAGE_ALL, \
902  },
905 #undef IMG_DO
906  {
907  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
908  .descriptorCount = 1,
909  .binding = BINDING_OFFSET_BLUE_NOISE,
910  .stageFlags = VK_SHADER_STAGE_ALL,
911  },
912  {
913  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
914  .descriptorCount = 1,
915  .binding = BINDING_OFFSET_ENVMAP,
916  .stageFlags = VK_SHADER_STAGE_ALL,
917  },
918  {
919  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
920  .descriptorCount = 1,
921  .binding = BINDING_OFFSET_PHYSICAL_SKY,
922  .stageFlags = VK_SHADER_STAGE_ALL,
923  },
924  {
925  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
926  .descriptorCount = 1,
928  .stageFlags = VK_SHADER_STAGE_ALL,
929  },
930  {
931  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
932  .descriptorCount = 1,
934  .stageFlags = VK_SHADER_STAGE_ALL,
935  },
936  {
937  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
938  .descriptorCount = 1,
940  .stageFlags = VK_SHADER_STAGE_ALL,
941  },
942  {
943  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
944  .descriptorCount = 1,
946  .stageFlags = VK_SHADER_STAGE_ALL,
947  },
948  {
949  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
950  .descriptorCount = 1,
951  .binding = BINDING_OFFSET_SKY_CLOUDS,
952  .stageFlags = VK_SHADER_STAGE_ALL,
953  },
954  {
955  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
956  .descriptorCount = 1,
958  .stageFlags = VK_SHADER_STAGE_ALL,
959  },
960  {
961  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
962  .descriptorCount = 1,
964  .stageFlags = VK_SHADER_STAGE_ALL,
965  },
966  {
967  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
968  .descriptorCount = 1,
969  .binding = BINDING_OFFSET_TERRAIN_DEPTH,
970  .stageFlags = VK_SHADER_STAGE_ALL,
971  },
972  {
973  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
974  .descriptorCount = 1,
976  .stageFlags = VK_SHADER_STAGE_ALL,
977  }
978  };
979 
980  VkDescriptorSetLayoutCreateInfo layout_info = {
981  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
982  .bindingCount = LENGTH(layout_bindings),
983  .pBindings = layout_bindings,
984  };
985 
986  _VK(vkCreateDescriptorSetLayout(qvk.device, &layout_info, NULL, &qvk.desc_set_layout_textures));
987  ATTACH_LABEL_VARIABLE(qvk.desc_set_layout_textures, DESCRIPTOR_SET_LAYOUT);
988  VkDescriptorPoolSize pool_size = {
989  .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
990  .descriptorCount = MAX_RIMAGES + 2 * NUM_VKPT_IMAGES + 128,
991  };
992 
993  VkDescriptorPoolCreateInfo pool_info = {
994  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
995  .poolSizeCount = 1,
996  .pPoolSizes = &pool_size,
997  .maxSets = 2,
998  };
999 
1000  _VK(vkCreateDescriptorPool(qvk.device, &pool_info, NULL, &desc_pool_textures));
1001  ATTACH_LABEL_VARIABLE(desc_pool_textures, DESCRIPTOR_POOL);
1002 
1003  VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
1004  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
1005  .descriptorPool = desc_pool_textures,
1006  .descriptorSetCount = 1,
1007  .pSetLayouts = &qvk.desc_set_layout_textures,
1008  };
1009 
1010  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, &qvk.desc_set_textures_even));
1011  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, &qvk.desc_set_textures_odd));
1012 
1015 
1016  if(load_blue_noise() != VK_SUCCESS)
1017  return VK_ERROR_INITIALIZATION_FAILED;
1018 
1019  LOG_FUNC();
1020  return VK_SUCCESS;
1021 }

◆ vkpt_textures_prefetch()

void vkpt_textures_prefetch ( )

Definition at line 75 of file textures.c.

76 {
77  byte* buffer = NULL;
78  ssize_t buffer_size = 0;
79  char const * filename = "prefetch.txt";
80  buffer_size = FS_LoadFile(filename, (void**)&buffer);
81  if (buffer == NULL)
82  {
83  Com_EPrintf("Can't load '%s'\n", filename);
84  return;
85  }
86 
87  char const * ptr = buffer;
88  char linebuf[MAX_QPATH];
89  while (sgets(linebuf, sizeof(linebuf), &ptr))
90  {
91  char* line = strtok(linebuf, " \t\r\n");
92  if (!line)
93  continue;
94 
95  image_t const * img1 = IMG_Find(line, IT_SKIN, IF_PERMANENT | IF_SRGB);
96 
97  char other_name[MAX_QPATH];
98 
99  // attempt loading a matching normal map
100  if (!Q_strlcpy(other_name, line, strlen(line) - 3))
101  continue;
102  Q_concat(other_name, sizeof(other_name), other_name, "_n.tga", NULL);
103  FS_NormalizePath(other_name, other_name);
104  image_t const * img2 = IMG_Find(other_name, IT_SKIN, IF_PERMANENT);
105  /* if (img2 != R_NOTEXTURE)
106  Com_Printf("Prefetched '%s' (%d)\n", other_name, (int)(img2 - r_images)); */
107 
108  // attempt loading a matching emissive map
109  if (!Q_strlcpy(other_name, line, strlen(line) - 3))
110  continue;
111  Q_concat(other_name, sizeof(other_name), other_name, "_light.tga", NULL);
112  FS_NormalizePath(other_name, other_name);
113  image_t const * img3 = IMG_Find(other_name, IT_SKIN, IF_PERMANENT | IF_SRGB);
114  }
115  // Com_Printf("Loaded '%s'\n", filename);
116  FS_FreeFile(buffer);
117 }

Referenced by vkpt_initialize_all().

◆ vkpt_textures_update_descriptor_set()

void vkpt_textures_update_descriptor_set ( )

Definition at line 1346 of file textures.c.

1347 {
1349  return;
1350 
1352 
1353  for(int i = 0; i < MAX_RIMAGES; i++) {
1354  image_t *q_img = r_images + i;
1355 
1356  VkImageView image_view = tex_image_views[i];
1357  if (image_view == VK_NULL_HANDLE)
1358  image_view = tex_invalid_texture_image_view;
1359 
1360  VkSampler sampler = qvk.tex_sampler;
1361  if (!strcmp(q_img->name, "pics/conchars.pcx") || !strcmp(q_img->name, "pics/ch1.pcx"))
1362  sampler = qvk.tex_sampler_nearest;
1363  else if (q_img->type == IT_SPRITE)
1364  sampler = qvk.tex_sampler_linear_clamp;
1365 
1366  VkDescriptorImageInfo img_info = {
1367  .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1368  .imageView = image_view,
1369  .sampler = sampler,
1370  };
1371 
1372  if (i >= VKPT_IMG_BLOOM_HBLUR &&
1373  i <= VKPT_IMG_BLOOM_VBLUR) {
1374  img_info.sampler = qvk.tex_sampler_linear_clamp;
1375  }
1376 
1377  VkWriteDescriptorSet descriptor_set_write = {
1378  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
1381  .dstArrayElement = i,
1382  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1383  .descriptorCount = 1,
1384  .pImageInfo = &img_info,
1385  };
1386 
1387  vkUpdateDescriptorSets(qvk.device, 1, &descriptor_set_write, 0, NULL);
1388  }
1389 }

Referenced by R_BeginFrame_RTX().

◆ vkpt_textures_upload_envmap()

VkResult vkpt_textures_upload_envmap ( int  w,
int  h,
byte *  data 
)

Definition at line 150 of file textures.c.

151 {
152  vkDeviceWaitIdle(qvk.device);
153  if(imv_envmap != VK_NULL_HANDLE) {
154  vkDestroyImageView(qvk.device, imv_envmap, NULL);
155  imv_envmap = NULL;
156  }
157  if(img_envmap != VK_NULL_HANDLE) {
158  vkDestroyImage(qvk.device, img_envmap, NULL);
159  img_envmap = NULL;
160  }
161 
162  const int num_images = 6;
163  size_t img_size = w * h * 4;
164 
165  BufferResource_t buf_img_upload;
166  buffer_create(&buf_img_upload, img_size * num_images, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
167  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
168 
169  byte *envmap = (byte *) buffer_map(&buf_img_upload);
170  memcpy(envmap, data, img_size * num_images);
171  buffer_unmap(&buf_img_upload);
172  envmap = NULL;
173 
174  VkImageCreateInfo img_info = {
175  .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
176  .extent = {
177  .width = w,
178  .height = h,
179  .depth = 1,
180  },
181  .imageType = VK_IMAGE_TYPE_2D,
182  .format = VK_FORMAT_R8G8B8A8_UNORM,
183  .mipLevels = 1,
184  .arrayLayers = num_images,
185  .samples = VK_SAMPLE_COUNT_1_BIT,
186  .tiling = VK_IMAGE_TILING_OPTIMAL,
187  .usage = VK_IMAGE_USAGE_STORAGE_BIT
188  | VK_IMAGE_USAGE_TRANSFER_DST_BIT
189  | VK_IMAGE_USAGE_SAMPLED_BIT,
190  .flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT,
191  .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
192  .queueFamilyIndexCount = qvk.queue_idx_graphics,
193  .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
194  };
195 
196  _VK(vkCreateImage(qvk.device, &img_info, NULL, &img_envmap));
198 
199  VkMemoryRequirements mem_req;
200  vkGetImageMemoryRequirements(qvk.device, img_envmap, &mem_req);
201  assert(mem_req.size >= buf_img_upload.size);
202 
203  _VK(allocate_gpu_memory(mem_req, &mem_envmap));
204 
205  _VK(vkBindImageMemory(qvk.device, img_envmap, mem_envmap, 0));
206 
207  VkImageViewCreateInfo img_view_info = {
208  .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
209  .viewType = VK_IMAGE_VIEW_TYPE_CUBE,
210  .format = VK_FORMAT_R8G8B8A8_UNORM,
211  .image = img_envmap,
212  .subresourceRange = {
213  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
214  .baseMipLevel = 0,
215  .levelCount = 1,
216  .baseArrayLayer = 0,
217  .layerCount = num_images,
218  },
219  .components = {
220  VK_COMPONENT_SWIZZLE_R,
221  VK_COMPONENT_SWIZZLE_G,
222  VK_COMPONENT_SWIZZLE_B,
223  VK_COMPONENT_SWIZZLE_A,
224  },
225  };
226  _VK(vkCreateImageView(qvk.device, &img_view_info, NULL, &imv_envmap));
227  ATTACH_LABEL_VARIABLE(imv_envmap, IMAGE_VIEW);
228 
229  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
230 
231  for(int layer = 0; layer < num_images; layer++) {
232 
233  VkImageSubresourceRange subresource_range = {
234  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
235  .baseMipLevel = 0,
236  .levelCount = 1,
237  .baseArrayLayer = layer,
238  .layerCount = 1,
239  };
240 
241  IMAGE_BARRIER(cmd_buf,
242  .image = img_envmap,
243  .subresourceRange = subresource_range,
244  .srcAccessMask = 0,
245  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
246  .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
247  .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
248  );
249 
250  VkBufferImageCopy cpy_info = {
251  .bufferOffset = img_size * layer,
252  .imageSubresource = {
253  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
254  .mipLevel = 0,
255  .baseArrayLayer = layer,
256  .layerCount = 1,
257  },
258  .imageOffset = { 0, 0, 0 },
259  .imageExtent = { w, h, 1 }
260  };
261  vkCmdCopyBufferToImage(cmd_buf, buf_img_upload.buffer, img_envmap,
262  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cpy_info);
263 
264 
265  IMAGE_BARRIER(cmd_buf,
266  .image = img_envmap,
267  .subresourceRange = subresource_range,
268  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
269  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
270  .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
271  .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
272  );
273  }
274 
276 
277  {
278  VkDescriptorImageInfo desc_img_info = {
279  .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
280  .imageView = imv_envmap,
281  .sampler = qvk.tex_sampler,
282  };
283 
284  VkWriteDescriptorSet s = {
285  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
286  .dstSet = qvk.desc_set_textures_even,
287  .dstBinding = BINDING_OFFSET_ENVMAP,
288  .dstArrayElement = 0,
289  .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
290  .descriptorCount = 1,
291  .pImageInfo = &desc_img_info,
292  };
293 
294  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
295 
296  s.dstSet = qvk.desc_set_textures_odd;
297  vkUpdateDescriptorSets(qvk.device, 1, &s, 0, NULL);
298  }
299 
300  vkQueueWaitIdle(qvk.queue_graphics);
301 
302  buffer_destroy(&buf_img_upload);
303 
304  return VK_SUCCESS;
305 }

Referenced by R_SetSky_RTX().

◆ vkpt_tone_mapping_create_pipelines()

VkResult vkpt_tone_mapping_create_pipelines ( )

Definition at line 146 of file tone_mapping.c.

147 {
148  VkComputePipelineCreateInfo pipeline_info[TM_NUM_PIPELINES] = {
150  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
151  .stage = SHADER_STAGE(QVK_MOD_TONE_MAPPING_HISTOGRAM_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
153  },
154  [TONE_MAPPING_CURVE] = {
155  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
156  .stage = SHADER_STAGE(QVK_MOD_TONE_MAPPING_CURVE_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
158  },
159  [TONE_MAPPING_APPLY] = {
160  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
161  .stage = SHADER_STAGE(QVK_MOD_TONE_MAPPING_APPLY_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
163  },
164  };
165 
166  _VK(vkCreateComputePipelines(qvk.device, 0, LENGTH(pipeline_info), pipeline_info, 0, pipelines));
167 
168  reset_required = 1;
169 
170  return VK_SUCCESS;
171 }

◆ vkpt_tone_mapping_destroy()

VkResult vkpt_tone_mapping_destroy ( )

Definition at line 126 of file tone_mapping.c.

127 {
128  vkDestroyPipelineLayout(qvk.device, pipeline_layout_tone_mapping_histogram, NULL);
129  vkDestroyPipelineLayout(qvk.device, pipeline_layout_tone_mapping_curve, NULL);
130  vkDestroyPipelineLayout(qvk.device, pipeline_layout_tone_mapping_apply, NULL);
131  return VK_SUCCESS;
132 }

◆ vkpt_tone_mapping_destroy_pipelines()

VkResult vkpt_tone_mapping_destroy_pipelines ( )

Definition at line 207 of file tone_mapping.c.

208 {
209  for (int i = 0; i < TM_NUM_PIPELINES; i++)
210  vkDestroyPipeline(qvk.device, pipelines[i], NULL);
211  return VK_SUCCESS;
212 }

◆ vkpt_tone_mapping_initialize()

VkResult vkpt_tone_mapping_initialize ( )

Definition at line 76 of file tone_mapping.c.

77 {
78  VkDescriptorSetLayout desc_set_layouts[] = {
82  };
83 
84  VkPushConstantRange push_constant_range_curve = {
85  .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
86  .offset = 0,
87  .size = 16*sizeof(float)
88  };
89 
90  VkPushConstantRange push_constant_range_apply = {
91  .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
92  .offset = 0,
93  .size = 3*sizeof(float)
94  };
95 
97  .setLayoutCount = LENGTH(desc_set_layouts),
98  .pSetLayouts = desc_set_layouts,
99  .pushConstantRangeCount = 0,
100  .pPushConstantRanges = NULL
101  );
103 
105  .setLayoutCount = LENGTH(desc_set_layouts),
106  .pSetLayouts = desc_set_layouts,
107  .pushConstantRangeCount = 1,
108  .pPushConstantRanges = &push_constant_range_curve
109  );
111 
113  .setLayoutCount = LENGTH(desc_set_layouts),
114  .pSetLayouts = desc_set_layouts,
115  .pushConstantRangeCount = 1,
116  .pPushConstantRanges = &push_constant_range_apply
117  );
119 
120  return VK_SUCCESS;
121 }

◆ vkpt_tone_mapping_record_cmd_buffer()

VkResult vkpt_tone_mapping_record_cmd_buffer ( VkCommandBuffer  cmd_buf,
float  frame_time 
)

Definition at line 241 of file tone_mapping.c.

242 {
243  if (reset_required)
244  {
245  // Clear the histogram image.
246  vkpt_tone_mapping_reset(cmd_buf);
247  }
248 
249  VkDescriptorSet desc_sets[] = {
253  };
254  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
255 
256 
257  // Record instructions to run the compute shader that updates the histogram.
258  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipelines[TONE_MAPPING_HISTOGRAM]);
259  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
260  pipeline_layout_tone_mapping_histogram, 0, LENGTH(desc_sets), desc_sets, 0, 0);
261 
262  vkCmdDispatch(cmd_buf,
263  (qvk.extent_render.width + 15) / 16,
264  (qvk.extent_render.height + 15) / 16,
265  1);
266 
267  BUFFER_BARRIER(cmd_buf,
268  .buffer = qvk.buf_tonemap.buffer,
269  .offset = 0,
270  .size = VK_WHOLE_SIZE,
271  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
272  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT
273  );
274 
275 
276  // Record instructions to run the compute shader that computes the tone
277  // curve and autoexposure constants from the histogram.
278  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipelines[TONE_MAPPING_CURVE]);
279  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
280  pipeline_layout_tone_mapping_curve, 0, LENGTH(desc_sets), desc_sets, 0, 0);
281 
282  // Compute the push constants for the tone curve generation shader:
283  // whether to ignore previous tone curve results, how much to blend this
284  // frame's tone curve with the previous frame's tone curve, and the kernel
285  // used to filter the tone curve's slopes.
286  // This is one of the things we added to Eilertsen's tone mapper, and helps
287  // prevent artifacts that occur when the tone curve's slopes become flat or
288  // change too suddenly (much like when you specify a curve in an image
289  // processing application that is too intense). This especially helps on
290  // shadow edges in some scenes.
291  // In addition, we assume the kernel is symmetric; this allows us to only
292  // specify half of it in our push constant buffer.
293 
294  // Note that the second argument of Cvar_Get only specifies the default
295  // value in code if none is set; the value of tm_slope_blur_sigma specified
296  // in global_ubo.h will override this.
297  float slope_blur_sigma = Cvar_Get("tm_slope_blur_sigma", "6.0", 0)->value;
298  float push_constants_tm2_curve[16] = {
299  reset_required ? 1.0 : 0.0, // 1 means reset the histogram
300  frame_time, // Frame time
301  0.0, 0.0, 0.0, 0.0, // Slope kernel filter
302  0.0, 0.0, 0.0, 0.0,
303  0.0, 0.0, 0.0, 0.0,
304  0.0, 0.0
305  };
306 
307  // Compute Gaussian curve and sum, taking symmetry into account.
308  float gaussian_sum = 0.0;
309  for (int i = 0; i < 14; ++i)
310  {
311  float kernel_value = exp(-i * i / (2.0 * slope_blur_sigma * slope_blur_sigma));
312  gaussian_sum += kernel_value * (i == 0 ? 1 : 2);
313  push_constants_tm2_curve[i + 2] = kernel_value;
314  }
315  // Normalize the result (since even with an analytic normalization factor,
316  // the results may not sum to one).
317  for (int i = 0; i < 14; ++i) {
318  push_constants_tm2_curve[i + 2] /= gaussian_sum;
319  }
320 
321  vkCmdPushConstants(cmd_buf, pipeline_layout_tone_mapping_curve,
322  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants_tm2_curve), push_constants_tm2_curve);
323 
324  vkCmdDispatch(cmd_buf, 1, 1, 1);
325 
326  BUFFER_BARRIER(cmd_buf,
327  .buffer = qvk.buf_tonemap.buffer,
328  .offset = 0,
329  .size = VK_WHOLE_SIZE,
330  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
331  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT
332  );
333 
334 
335  // Record instructions to apply our tone curve to the final image, apply
336  // the autoexposure tone mapper to the final image, and blend the results
337  // of the two techniques.
338  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipelines[TONE_MAPPING_APPLY]);
339  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
340  pipeline_layout_tone_mapping_apply, 0, LENGTH(desc_sets), desc_sets, 0, 0);
341 
342  // At the end of the hue-preserving tone mapper, the luminance of every
343  // pixel is mapped to the range [0,1]. However, because this tone
344  // mapper adjusts luminance while preserving hue and saturation, the values
345  // of some RGB channels may lie outside [0,1]. To finish off the tone
346  // mapping pipeline and since we want the brightest colors in the scene to
347  // be desaturated a bit for display, we apply a subtle user-configurable
348  // Reinhard tone mapping curve to the brighest values in the image at this
349  // point, preserving pixels with luminance below tm_knee_start.
350  //
351  // If we wanted to support an arbitrary SDR color grading pipeline here or
352  // implement an additional filmic tone mapping pass, for instance, this is
353  // roughly around where it would be applied. For applications that need to
354  // output both SDR and HDR images but for which creating custom grades
355  // for each format is impractical, one common approach is to
356  // (roughly) use the HDR->SDR transformation to map an SDR color grading
357  // function back to an HDR color grading function.
358 
359  // Defines the white point and where we switch from an identity transform
360  // to a Reinhard transform in the additional tone mapper we apply at the
361  // end of the previous tone mapping pipeline.
362  // Must be between 0 and 1; pixels with luminances above this value have
363  // their RGB values slowly clamped to 1, up to tm_white_point.
364  float knee_start = Cvar_Get("tm_knee_start", "0.9", 0)->value;
365  // Should be greater than 1; defines those RGB values that get mapped to 1.
366  float knee_white_point = Cvar_Get("tm_white_point", "10.0", 0)->value;
367 
368  // We modify Reinhard to smoothly blend with the identity transform up to tm_knee_start.
369  // We need to find w, a, and b such that in y(x) = (wx+a)/(x+b),
370  // * y(knee_start) = tm_knee_start
371  // * dy/dx(knee_start) = 1
372  // * y(knee_white_point) = tm_white_point.
373  // The solution is as follows:
374  float knee_w = (knee_start*(knee_start - 2.0) + knee_white_point) / (knee_white_point - 1.0);
375  float knee_a = -knee_start * knee_start;
376  float knee_b = knee_w - 2.0*knee_start;
377 
378  float push_constants_tm2_apply[3] = {
379  knee_w, // knee_w in piecewise knee adjustment
380  knee_a, // knee_a in piecewise knee adjustment
381  knee_b, // knee_b in piecewise knee adjustment
382  };
383 
384  vkCmdPushConstants(cmd_buf, pipeline_layout_tone_mapping_apply,
385  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants_tm2_apply), push_constants_tm2_apply);
386 
387  vkCmdDispatch(cmd_buf,
388  (qvk.extent_render.width + 15) / 16,
389  (qvk.extent_render.height + 15) / 16,
390  1);
391 
392  // Because VKPT_IMG_TAA_OUTPUT changed, we make sure to wait for the image
393  // to be written before continuing. This could be ensured in several
394  // other ways as well.
395  BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_TAA_OUTPUT]);
396 
397  reset_required = 0;
398 
399  return VK_SUCCESS;
400 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_tone_mapping_request_reset()

void vkpt_tone_mapping_request_reset ( )

Definition at line 138 of file tone_mapping.c.

139 {
140  reset_required = 1;
141 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_tone_mapping_reset()

VkResult vkpt_tone_mapping_reset ( VkCommandBuffer  cmd_buf)

Definition at line 176 of file tone_mapping.c.

177 {
178  VkClearColorValue clear_histogram = {
179  .uint32 = { 0, 0, 0, 0 }
180  };
181 
182  BUFFER_BARRIER(cmd_buf,
183  .buffer = qvk.buf_tonemap.buffer,
184  .offset = 0,
185  .size = VK_WHOLE_SIZE,
186  .srcAccessMask = 0,
187  .dstAccessMask = 0
188  );
189 
190  vkCmdFillBuffer(cmd_buf, qvk.buf_tonemap.buffer,
191  0, VK_WHOLE_SIZE, 0);
192 
193  BUFFER_BARRIER(cmd_buf,
194  .buffer = qvk.buf_tonemap.buffer,
195  .offset = 0,
196  .size = VK_WHOLE_SIZE,
197  .srcAccessMask = 0,
198  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT
199  );
200 
201  return VK_SUCCESS;
202 }

Referenced by vkpt_tone_mapping_record_cmd_buffer().

◆ vkpt_uniform_buffer_create()

VkResult vkpt_uniform_buffer_create ( )

Definition at line 30 of file uniform_buffer.c.

31 {
32  VkDescriptorSetLayoutBinding ubo_layout_bindings[2] = { 0 };
33 
34  ubo_layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
35  ubo_layout_bindings[0].descriptorCount = 1;
36  ubo_layout_bindings[0].binding = GLOBAL_UBO_BINDING_IDX;
37  ubo_layout_bindings[0].stageFlags = VK_SHADER_STAGE_ALL;
38 
39  ubo_layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
40  ubo_layout_bindings[1].descriptorCount = 1;
41  ubo_layout_bindings[1].binding = GLOBAL_INSTANCE_BUFFER_BINDING_IDX;
42  ubo_layout_bindings[1].stageFlags = VK_SHADER_STAGE_ALL;
43 
44  VkDescriptorSetLayoutCreateInfo layout_info = {
45  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
46  .bindingCount = LENGTH(ubo_layout_bindings),
47  .pBindings = ubo_layout_bindings,
48  };
49 
50  _VK(vkCreateDescriptorSetLayout(qvk.device, &layout_info, NULL, &qvk.desc_set_layout_ubo));
51 
52  const VkMemoryPropertyFlags host_memory_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
53  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
54 
55  const VkMemoryPropertyFlags device_memory_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
56 
57  VkPhysicalDeviceProperties properties;
58  vkGetPhysicalDeviceProperties(qvk.physical_device, &properties);
59  ubo_alignment = properties.limits.minUniformBufferOffsetAlignment;
60 
61  const size_t buffer_size = align(sizeof(QVKUniformBuffer_t), ubo_alignment) + sizeof(QVKInstanceBuffer_t);
62  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
63  buffer_create(host_uniform_buffers + i, buffer_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, host_memory_flags);
64 
65  buffer_create(&device_uniform_buffer, buffer_size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
66  device_memory_flags);
67 
68  VkDescriptorPoolSize pool_size = {
69  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
70  .descriptorCount = MAX_FRAMES_IN_FLIGHT,
71  };
72 
73  VkDescriptorPoolCreateInfo pool_info = {
74  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
75  .poolSizeCount = 1,
76  .pPoolSizes = &pool_size,
77  .maxSets = MAX_FRAMES_IN_FLIGHT,
78  };
79 
80  _VK(vkCreateDescriptorPool(qvk.device, &pool_info, NULL, &desc_pool_ubo));
81 
82  VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
83  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
84  .descriptorPool = desc_pool_ubo,
85  .descriptorSetCount = 1,
86  .pSetLayouts = &qvk.desc_set_layout_ubo,
87  };
88 
89  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, &qvk.desc_set_ubo));
90 
91  VkDescriptorBufferInfo buf_info = {
92  .buffer = device_uniform_buffer.buffer,
93  .offset = 0,
94  .range = sizeof(QVKUniformBuffer_t),
95  };
96 
97  VkDescriptorBufferInfo buf1_info = {
98  .buffer = device_uniform_buffer.buffer,
99  .offset = align(sizeof(QVKUniformBuffer_t), ubo_alignment),
100  .range = sizeof(QVKInstanceBuffer_t),
101  };
102 
103  VkWriteDescriptorSet writes[2] = { 0 };
104 
105  writes[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
106  writes[0].dstSet = qvk.desc_set_ubo,
107  writes[0].dstBinding = GLOBAL_UBO_BINDING_IDX,
108  writes[0].dstArrayElement = 0,
109  writes[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
110  writes[0].descriptorCount = 1,
111  writes[0].pBufferInfo = &buf_info,
112 
113  writes[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
114  writes[1].dstSet = qvk.desc_set_ubo,
115  writes[1].dstBinding = GLOBAL_INSTANCE_BUFFER_BINDING_IDX,
116  writes[1].dstArrayElement = 0,
117  writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
118  writes[1].descriptorCount = 1,
119  writes[1].pBufferInfo = &buf1_info,
120 
121  vkUpdateDescriptorSets(qvk.device, LENGTH(writes), writes, 0, NULL);
122 
123  return VK_SUCCESS;
124 }

◆ vkpt_uniform_buffer_destroy()

VkResult vkpt_uniform_buffer_destroy ( )

Definition at line 127 of file uniform_buffer.c.

128 {
129  vkDestroyDescriptorPool(qvk.device, desc_pool_ubo, NULL);
130  vkDestroyDescriptorSetLayout(qvk.device, qvk.desc_set_layout_ubo, NULL);
131  desc_pool_ubo = VK_NULL_HANDLE;
132  qvk.desc_set_layout_ubo = VK_NULL_HANDLE;
133 
134  for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
137 
138  return VK_SUCCESS;
139 }

◆ vkpt_uniform_buffer_update()

VkResult vkpt_uniform_buffer_update ( VkCommandBuffer  command_buffer)

Definition at line 142 of file uniform_buffer.c.

143 {
145  assert(ubo);
146  assert(ubo->memory != VK_NULL_HANDLE);
147  assert(ubo->buffer != VK_NULL_HANDLE);
149 
150  QVKUniformBuffer_t *mapped_ubo = buffer_map(ubo);
151  assert(mapped_ubo);
152  memcpy(mapped_ubo, &vkpt_refdef.uniform_buffer, sizeof(QVKUniformBuffer_t));
153 
154  const size_t offset = align(sizeof(QVKUniformBuffer_t), ubo_alignment);
155  memcpy((uint8_t*)mapped_ubo + offset, &vkpt_refdef.uniform_instance_buffer, sizeof(QVKInstanceBuffer_t));
156 
157  buffer_unmap(ubo);
158  mapped_ubo = NULL;
159 
160  VkBufferCopy copy = { 0 };
161  copy.size = align(sizeof(QVKUniformBuffer_t), ubo_alignment) + sizeof(QVKInstanceBuffer_t);
162  vkCmdCopyBuffer(command_buffer, ubo->buffer, device_uniform_buffer.buffer, 1, &copy);
163 
164  VkBufferMemoryBarrier barrier = {
165  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
166  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
167  .dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_SHADER_READ_BIT,
168  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
169  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
170  .buffer = device_uniform_buffer.buffer,
171  .size = copy.size
172  };
173 
174  vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
175  0, 0, NULL, 1, &barrier, 0, NULL);
176 
177  return VK_SUCCESS;
178 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_vertex_buffer_create()

VkResult vkpt_vertex_buffer_create ( )

Definition at line 492 of file vertex_buffer.c.

493 {
494  VkDescriptorSetLayoutBinding vbo_layout_bindings[] = {
495  {
496  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
497  .descriptorCount = 1,
498  .binding = VERTEX_BUFFER_BINDING_IDX,
499  .stageFlags = VK_SHADER_STAGE_ALL,
500  },
501  {
502  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
503  .descriptorCount = 1,
504  .binding = LIGHT_BUFFER_BINDING_IDX,
505  .stageFlags = VK_SHADER_STAGE_ALL,
506  },
507  {
508  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
509  .descriptorCount = 1,
510  .binding = READBACK_BUFFER_BINDING_IDX,
511  .stageFlags = VK_SHADER_STAGE_ALL,
512  },
513  {
514  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
515  .descriptorCount = 1,
517  .stageFlags = VK_SHADER_STAGE_ALL,
518  },
519  {
520  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
521  .descriptorCount = 1,
522  .binding = SUN_COLOR_BUFFER_BINDING_IDX,
523  .stageFlags = VK_SHADER_STAGE_ALL,
524  },
525  {
526  .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
527  .descriptorCount = 1,
528  .binding = SUN_COLOR_UBO_BINDING_IDX,
529  .stageFlags = VK_SHADER_STAGE_ALL,
530  },
531  {
532  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
533  .descriptorCount = 3,
535  .stageFlags = VK_SHADER_STAGE_ALL,
536  }
537  };
538 
539  VkDescriptorSetLayoutCreateInfo layout_info = {
540  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
541  .bindingCount = LENGTH(vbo_layout_bindings),
542  .pBindings = vbo_layout_bindings,
543  };
544 
545  _VK(vkCreateDescriptorSetLayout(qvk.device, &layout_info, NULL, &qvk.desc_set_layout_vertex_buffer));
546 
547  // Com_Printf("allocating %.02f MB of memory for vertex buffer\n", (double) sizeof(VertexBuffer) / (1024.0 * 1024.0));
549  VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
550  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
551 
552  // Com_Printf("allocating %.02f MB of memory for staging vertex buffer\n", (double) sizeof(VertexBuffer) / (1024.0 * 1024.0));
554  VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
555  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
556 
558  VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
559  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
560 
561  for (int frame = 0; frame < MAX_FRAMES_IN_FLIGHT; frame++)
562  {
564  VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
565  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
566  }
567 
569  VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
570  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
571 
573  VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
574  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
575 
577  VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
578  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
579 
580  for (int frame = 0; frame < MAX_FRAMES_IN_FLIGHT; frame++)
581  {
583  VK_BUFFER_USAGE_TRANSFER_DST_BIT,
584  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
585  }
586 
587  VkDescriptorPoolSize pool_size = {
588  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
589  .descriptorCount = LENGTH(vbo_layout_bindings),
590  };
591 
592  VkDescriptorPoolCreateInfo pool_info = {
593  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
594  .poolSizeCount = 1,
595  .pPoolSizes = &pool_size,
596  .maxSets = 1,
597  };
598 
599  _VK(vkCreateDescriptorPool(qvk.device, &pool_info, NULL, &desc_pool_vertex_buffer));
600 
601  VkDescriptorSetAllocateInfo descriptor_set_alloc_info = {
602  .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
603  .descriptorPool = desc_pool_vertex_buffer,
604  .descriptorSetCount = 1,
605  .pSetLayouts = &qvk.desc_set_layout_vertex_buffer,
606  };
607 
608  _VK(vkAllocateDescriptorSets(qvk.device, &descriptor_set_alloc_info, &qvk.desc_set_vertex_buffer));
609 
610  VkDescriptorBufferInfo buf_info = {
611  .buffer = qvk.buf_vertex.buffer,
612  .offset = 0,
613  .range = sizeof(VertexBuffer),
614  };
615 
616  VkWriteDescriptorSet output_buf_write = {
617  .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
618  .dstSet = qvk.desc_set_vertex_buffer,
619  .dstBinding = 0,
620  .dstArrayElement = 0,
621  .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
622  .descriptorCount = 1,
623  .pBufferInfo = &buf_info,
624  };
625 
626  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
627 
628  output_buf_write.dstBinding = 1;
629  buf_info.buffer = qvk.buf_light.buffer;
630  buf_info.range = sizeof(LightBuffer);
631  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
632 
633  output_buf_write.dstBinding = 2;
634  buf_info.buffer = qvk.buf_readback.buffer;
635  buf_info.range = sizeof(ReadbackBuffer);
636  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
637 
638  output_buf_write.dstBinding = 3;
639  buf_info.buffer = qvk.buf_tonemap.buffer;
640  buf_info.range = sizeof(ToneMappingBuffer);
641  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
642 
643  output_buf_write.dstBinding = 4;
644  buf_info.buffer = qvk.buf_sun_color.buffer;
645  buf_info.range = sizeof(SunColorBuffer);
646  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
647 
648  output_buf_write.dstBinding = 5;
649  output_buf_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
650  buf_info.buffer = qvk.buf_sun_color.buffer;
651  buf_info.range = sizeof(SunColorBuffer);
652  vkUpdateDescriptorSets(qvk.device, 1, &output_buf_write, 0, NULL);
653 
654 
655  return VK_SUCCESS;
656 }

◆ vkpt_vertex_buffer_create_instance()

VkResult vkpt_vertex_buffer_create_instance ( VkCommandBuffer  cmd_buf,
uint32_t  num_instances,
qboolean  update_world_animations 
)

Definition at line 818 of file vertex_buffer.c.

819 {
820  VkDescriptorSet desc_sets[] = {
823  };
824  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_instance_geometry);
825  vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
826  pipeline_layout_instance_geometry, 0, LENGTH(desc_sets), desc_sets, 0, 0);
827 
828  vkCmdDispatch(cmd_buf, num_instances, 1, 1);
829 
830  if (update_world_animations)
831  {
832  vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_animate_materials);
833 
835  vkCmdDispatch(cmd_buf, num_groups, 1, 1);
836  }
837 
838  VkBufferMemoryBarrier barrier = {
839  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
840  .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
841  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
842  .buffer = qvk.buf_vertex.buffer,
843  .size = qvk.buf_vertex.size,
844  .srcQueueFamilyIndex = qvk.queue_idx_graphics,
845  .dstQueueFamilyIndex = qvk.queue_idx_graphics
846  };
847 
848  vkCmdPipelineBarrier(
849  cmd_buf,
850  VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
851  VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
852  0,
853  0, NULL,
854  1, &barrier,
855  0, NULL);
856 
857  return VK_SUCCESS;
858 }

Referenced by R_RenderFrame_RTX().

◆ vkpt_vertex_buffer_create_pipelines()

VkResult vkpt_vertex_buffer_create_pipelines ( )

Definition at line 759 of file vertex_buffer.c.

760 {
764 
765  assert(qvk.desc_set_layout_ubo);
767 
768  VkDescriptorSetLayout desc_set_layouts[] = {
770  };
771 
773  .setLayoutCount = LENGTH(desc_set_layouts),
774  .pSetLayouts = desc_set_layouts,
775  );
776 
777  VkComputePipelineCreateInfo compute_pipeline_info[] = {
778  {
779  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
780  .stage = SHADER_STAGE(QVK_MOD_INSTANCE_GEOMETRY_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
782  },
783  {
784  .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
785  .stage = SHADER_STAGE(QVK_MOD_ANIMATE_MATERIALS_COMP, VK_SHADER_STAGE_COMPUTE_BIT),
787  },
788  };
789 
790  VkPipeline pipelines[2];
791  _VK(vkCreateComputePipelines(qvk.device, 0, LENGTH(compute_pipeline_info), compute_pipeline_info, 0, pipelines));
792 
795 
796  return VK_SUCCESS;
797 }

◆ vkpt_vertex_buffer_destroy()

VkResult vkpt_vertex_buffer_destroy ( )

Definition at line 675 of file vertex_buffer.c.

676 {
677  vkDestroyDescriptorPool(qvk.device, desc_pool_vertex_buffer, NULL);
678  vkDestroyDescriptorSetLayout(qvk.device, qvk.desc_set_layout_vertex_buffer, NULL);
679  desc_pool_vertex_buffer = VK_NULL_HANDLE;
680  qvk.desc_set_layout_vertex_buffer = VK_NULL_HANDLE;
681 
684 
687  for (int frame = 0; frame < MAX_FRAMES_IN_FLIGHT; frame++)
688  {
691  }
692 
695 
696  return VK_SUCCESS;
697 }

◆ vkpt_vertex_buffer_destroy_pipelines()

VkResult vkpt_vertex_buffer_destroy_pipelines ( )

Definition at line 800 of file vertex_buffer.c.

801 {
805 
806  vkDestroyPipeline(qvk.device, pipeline_instance_geometry, NULL);
807  vkDestroyPipeline(qvk.device, pipeline_animate_materials, NULL);
808  vkDestroyPipelineLayout(qvk.device, pipeline_layout_instance_geometry, NULL);
809 
810  pipeline_instance_geometry = VK_NULL_HANDLE;
811  pipeline_animate_materials = VK_NULL_HANDLE;
812  pipeline_layout_instance_geometry = VK_NULL_HANDLE;
813 
814  return VK_SUCCESS;
815 }

◆ vkpt_vertex_buffer_upload_bsp_mesh_to_staging()

VkResult vkpt_vertex_buffer_upload_bsp_mesh_to_staging ( bsp_mesh_t bsp_mesh)

Definition at line 90 of file vertex_buffer.c.

91 {
92  assert(bsp_mesh);
94  assert(vbo);
95 
96  int num_vertices = bsp_mesh->num_vertices;
97  if (num_vertices > MAX_VERT_BSP)
98  {
99  assert(!"Vertex buffer overflow");
100  num_vertices = MAX_VERT_BSP;
101  }
102 
103  memcpy(vbo->positions_bsp, bsp_mesh->positions, num_vertices * sizeof(float) * 3 );
104  memcpy(vbo->tex_coords_bsp, bsp_mesh->tex_coords,num_vertices * sizeof(float) * 2 );
105  memcpy(vbo->tangents_bsp, bsp_mesh->tangents, num_vertices * sizeof(float));
106  memcpy(vbo->materials_bsp, bsp_mesh->materials, num_vertices * sizeof(uint32_t) / 3);
107  memcpy(vbo->clusters_bsp, bsp_mesh->clusters, num_vertices * sizeof(uint32_t) / 3);
108  memcpy(vbo->texel_density_bsp, bsp_mesh->texel_density, num_vertices * sizeof(float) / 3);
109 
110  int num_clusters = bsp_mesh->num_clusters;
111  if (num_clusters > MAX_LIGHT_LISTS)
112  {
113  assert(!"Visibility buffer overflow");
114  num_clusters = MAX_LIGHT_LISTS;
115  }
116 
117  memcpy(vbo->sky_visibility, bsp_mesh->sky_visibility, (num_clusters + 7) / 8);
118 
120  vbo = NULL;
121 
122  return VK_SUCCESS;
123 }

Referenced by R_BeginRegistration_RTX().

◆ vkpt_vertex_buffer_upload_models_to_staging()

VkResult vkpt_vertex_buffer_upload_models_to_staging ( )

Definition at line 412 of file vertex_buffer.c.

413 {
415  assert(vbo);
416 
417  int idx_offset = 0;
418  int vertex_offset = 0;
419  for(int i = 0; i < MAX_MODELS; i++) {
420  if(!r_models[i].meshes) {
421  continue;
422  }
423 
424  for (int nmesh = 0; nmesh < r_models[i].nummeshes; nmesh++)
425  {
426  maliasmesh_t *m = r_models[i].meshes + nmesh;
427 
428  m->idx_offset = idx_offset;
429  m->vertex_offset = vertex_offset;
430 
431  assert(r_models[i].numframes > 0);
432 
433  int num_verts = r_models[i].numframes * m->numverts;
434  assert(num_verts > 0);
435 #if 0
436  for (int j = 0; j < num_verts; j++)
437  Com_Printf("%f %f %f\n",
438  m->positions[j][0],
439  m->positions[j][1],
440  m->positions[j][2]);
441 
442  for (int j = 0; j < m->numtris; j++)
443  Com_Printf("%d %d %d\n",
444  m->indices[j * 3 + 0],
445  m->indices[j * 3 + 1],
446  m->indices[j * 3 + 2]);
447 #endif
448 
449 #if 0
450  char buf[1024];
451  snprintf(buf, sizeof buf, "model_%04d.obj", i);
452  FILE *f = fopen(buf, "wb+");
453  assert(f);
454  for (int j = 0; j < m->numverts; j++) {
455  fprintf(f, "v %f %f %f\n",
456  m->positions[j][0],
457  m->positions[j][1],
458  m->positions[j][2]);
459  }
460  for (int j = 0; j < m->numindices / 3; j++) {
461  fprintf(f, "f %d %d %d\n",
462  m->indices[j * 3 + 0] + 1,
463  m->indices[j * 3 + 1] + 1,
464  m->indices[j * 3 + 2] + 1);
465  }
466  fclose(f);
467 #endif
468 
469  memcpy(vbo->positions_model + vertex_offset * 3, m->positions, sizeof(float) * 3 * num_verts);
470  memcpy(vbo->normals_model + vertex_offset * 3, m->normals, sizeof(float) * 3 * num_verts);
471  memcpy(vbo->tex_coords_model + vertex_offset * 2, m->tex_coords, sizeof(float) * 2 * num_verts);
472  memcpy(vbo->tangents_model + vertex_offset * 4, m->tangents, sizeof(float) * 4 * num_verts);
473  memcpy(vbo->idx_model + idx_offset, m->indices, sizeof(uint32_t) * m->numindices);
474 
475  vertex_offset += num_verts;
476  idx_offset += m->numtris * 3;
477 
478  assert(vertex_offset < MAX_VERT_MODEL);
479  assert(idx_offset < MAX_IDX_MODEL);
480  }
481  }
482 
484  vbo = NULL;
485 
486  // Com_Printf("uploaded %d vert, %d idx\n", vertex_offset, idx_offset);
487 
488  return VK_SUCCESS;
489 }

Referenced by R_BeginFrame_RTX().

◆ vkpt_vertex_buffer_upload_staging()

VkResult vkpt_vertex_buffer_upload_staging ( )

Definition at line 36 of file vertex_buffer.c.

37 {
38  vkWaitForFences(qvk.device, 1, &qvk.fence_vertex_sync, VK_TRUE, ~((uint64_t)0));
39  vkResetFences(qvk.device, 1, &qvk.fence_vertex_sync);
40 
41  VkCommandBuffer cmd_buf = vkpt_begin_command_buffer(&qvk.cmd_buffers_graphics);
42 
43  VkBufferCopy copyRegion = {
44  .size = sizeof(VertexBuffer),
45  };
46  vkCmdCopyBuffer(cmd_buf, qvk.buf_vertex_staging.buffer, qvk.buf_vertex.buffer, 1, &copyRegion);
47 
48  BUFFER_BARRIER(cmd_buf,
49  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
50  .dstAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_NV,
51  .buffer = qvk.buf_vertex.buffer,
52  .offset = 0,
53  .size = VK_WHOLE_SIZE,
54  );
55 
56  if (qvk.buf_light_stats[0].buffer)
57  {
58  vkCmdFillBuffer(cmd_buf, qvk.buf_light_stats[0].buffer, 0, qvk.buf_light_stats[0].size, 0);
59  vkCmdFillBuffer(cmd_buf, qvk.buf_light_stats[1].buffer, 0, qvk.buf_light_stats[1].size, 0);
60  vkCmdFillBuffer(cmd_buf, qvk.buf_light_stats[2].buffer, 0, qvk.buf_light_stats[2].size, 0);
61  }
62 
63  vkpt_submit_command_buffer(cmd_buf, qvk.queue_graphics, (1 << qvk.device_count) - 1, 0, NULL, NULL, NULL, 0, NULL, NULL, qvk.fence_vertex_sync);
64 
65  return VK_SUCCESS;
66 }

Referenced by R_BeginFrame_RTX(), and R_BeginRegistration_RTX().

◆ vkpt_wait_idle()

void vkpt_wait_idle ( VkQueue  queue,
cmd_buf_group_t group 
)

Definition at line 3405 of file main.c.

3406 {
3407  vkQueueWaitIdle(queue);
3409 }

Referenced by change_image_layouts(), create_swapchain(), fill_index_buffer(), IMG_ReadPixels_RTX(), and vkpt_pt_create_static().

Variable Documentation

◆ draw

◆ qvk

QVK_t qvk

Definition at line 377 of file main.c.

Referenced by allocate_and_bind_memory_to_blas(), allocate_and_bind_memory_to_buffers(), allocate_gpu_memory(), append_blas(), buffer_create(), buffer_destroy(), buffer_map(), buffer_unmap(), calculate_scratch_buffer_size(), change_image_layouts(), compute_push_constants(), create_blas(), create_buffer_views(), create_buffers(), create_command_pool_and_fences(), create_descriptor_set(), create_image_views(), create_invalid_texture(), create_pipeline_layout(), create_pipelines(), create_readback_image(), create_render_pass(), create_shader_module_from_file(), create_sub_allocator(), create_swapchain(), CreateShadowMap(), destroy_invalid_texture(), destroy_readback_image(), destroy_swapchain(), destroy_tex_images(), destroy_transparency(), destroy_vulkan(), destroyEnvTexture(), draw_profiler(), fill_index_buffer(), FillVertexAndIndexBuffers(), get_memory_type(), get_render_extent(), get_scratch_buffer_size(), get_screen_image_extent(), IMG_ReadPixels_RTX(), IMG_ReloadAll(), IMG_Unload_RTX(), init_vulkan(), initializeEnvTexture(), load_blue_noise(), prepare_ubo(), qvk_get_current_desc_set_textures(), R_BeginFrame_RTX(), R_BeginRegistration_RTX(), R_EndFrame_RTX(), R_Init_RTX(), R_ModeChanged_RTX(), R_RenderFrame_RTX(), R_Shutdown_RTX(), recreate_swapchain(), ReleaseInfo(), ReleaseShadowmap(), reset_sun_color_buffer(), set_current_gpu(), setup_rt_pipeline(), textures_destroy_unused_set(), update_descriptor_set(), UploadImage(), vkpt_asvgf_create_gradient_samples(), vkpt_asvgf_create_pipelines(), vkpt_asvgf_destroy(), vkpt_asvgf_destroy_pipelines(), vkpt_asvgf_filter(), vkpt_asvgf_initialize(), vkpt_begin_command_buffer(), vkpt_bloom_create_pipelines(), vkpt_bloom_destroy(), vkpt_bloom_destroy_pipelines(), vkpt_bloom_initialize(), vkpt_bloom_record_cmd_buffer(), vkpt_compositing(), vkpt_create_images(), vkpt_destroy_all(), vkpt_destroy_god_rays(), vkpt_destroy_images(), vkpt_draw_create_pipelines(), vkpt_draw_destroy(), vkpt_draw_destroy_pipelines(), vkpt_draw_get_extent(), vkpt_draw_initialize(), vkpt_draw_submit_stretch_pics(), vkpt_evaluate_sun_light(), vkpt_final_blit_filtered(), vkpt_final_blit_simple(), vkpt_free_command_buffers(), vkpt_god_rays_destroy_pipelines(), vkpt_image_copy(), vkpt_initialize_all(), vkpt_initialize_god_rays(), vkpt_interleave(), vkpt_light_buffer_upload_staging(), vkpt_light_buffer_upload_to_staging(), vkpt_light_stats_create(), vkpt_light_stats_destroy(), vkpt_physical_sky_create_pipelines(), vkpt_physical_sky_destroy(), vkpt_physical_sky_destroy_pipelines(), vkpt_physical_sky_initialize(), vkpt_physical_sky_record_cmd_buffer(), vkpt_profiler_destroy(), vkpt_profiler_initialize(), vkpt_profiler_next_frame(), vkpt_profiler_query(), vkpt_pt_create_accel_bottom(), vkpt_pt_create_all_dynamic(), vkpt_pt_create_pipelines(), vkpt_pt_create_static(), vkpt_pt_create_toplevel(), vkpt_pt_destroy(), vkpt_pt_destroy_dynamic(), vkpt_pt_destroy_explosions(), vkpt_pt_destroy_pipelines(), vkpt_pt_destroy_static(), vkpt_pt_destroy_toplevel(), vkpt_pt_destroy_transparent_models(), vkpt_pt_destroy_viewer_models(), vkpt_pt_destroy_viewer_weapon(), vkpt_pt_init(), vkpt_pt_trace_lighting(), vkpt_pt_trace_primary_rays(), vkpt_pt_trace_reflections(), vkpt_pt_update_descripter_set_bindings(), vkpt_readback(), vkpt_record_god_rays_filter_command_buffer(), vkpt_record_god_rays_trace_command_buffer(), vkpt_reset_command_buffers(), vkpt_shadow_map_create_pipelines(), vkpt_shadow_map_destroy(), vkpt_shadow_map_destroy_pipelines(), vkpt_shadow_map_initialize(), vkpt_shadow_map_render(), vkpt_submit_command_buffer(), vkpt_submit_command_buffer_simple(), vkpt_taa(), vkpt_textures_destroy(), vkpt_textures_destroy_unused(), vkpt_textures_end_registration(), vkpt_textures_initialize(), vkpt_textures_update_descriptor_set(), vkpt_textures_upload_envmap(), vkpt_tone_mapping_create_pipelines(), vkpt_tone_mapping_destroy(), vkpt_tone_mapping_destroy_pipelines(), vkpt_tone_mapping_initialize(), vkpt_tone_mapping_record_cmd_buffer(), vkpt_tone_mapping_reset(), vkpt_uniform_buffer_create(), vkpt_uniform_buffer_destroy(), vkpt_uniform_buffer_update(), vkpt_uniform_precomputed_buffer_create(), vkpt_uniform_precomputed_buffer_destroy(), vkpt_uniform_precomputed_buffer_update(), vkpt_vertex_buffer_create(), vkpt_vertex_buffer_create_instance(), vkpt_vertex_buffer_create_pipelines(), vkpt_vertex_buffer_destroy(), vkpt_vertex_buffer_destroy_pipelines(), vkpt_vertex_buffer_upload_bsp_mesh_to_staging(), vkpt_vertex_buffer_upload_models_to_staging(), and vkpt_vertex_buffer_upload_staging().

◆ vkpt_refdef

MAX_LIGHT_LIST_NODES
#define MAX_LIGHT_LIST_NODES
Definition: vertex_buffer.h:33
QVK_s::desc_set_ubo
VkDescriptorSet desc_set_ubo
Definition: vkpt.h:226
RadiusFromBounds
vec_t RadiusFromBounds(const vec3_t mins, const vec3_t maxs)
Definition: shared.c:127
update_sprite_blas
static void update_sprite_blas(VkCommandBuffer command_buffer)
Definition: transparency.c:797
BUFFER_BARRIER
#define BUFFER_BARRIER(cmd_buf,...)
Definition: vk_util.h:68
accel_dynamic
static VkAccelerationStructureNV accel_dynamic[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:70
Key_GetBindingForKey
char * Key_GetBindingForKey(int keynum)
Definition: keys.c:310
mem_accel_top
static VkDeviceMemory mem_accel_top[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:86
bsp_mesh_s::num_clusters
int num_clusters
Definition: vkpt.h:366
update_particle_blas
static void update_particle_blas(VkCommandBuffer command_buffer)
Definition: transparency.c:697
MAT_GetNumPBRMaterials
int MAT_GetNumPBRMaterials()
Definition: material.c:144
LIST_IMAGES_B_A
#define LIST_IMAGES_B_A
Definition: global_textures.h:101
drawStatic_t::alpha_scale
float alpha_scale
Definition: vkpt.h:716
SUN_COLOR_UBO_BINDING_IDX
#define SUN_COLOR_UBO_BINDING_IDX
Definition: vertex_buffer.h:50
TONE_MAPPING_APPLY
@ TONE_MAPPING_APPLY
Definition: tone_mapping.c:63
maliasmesh_s
Definition: gl.h:232
desc_pool_ubo
static VkDescriptorPool desc_pool_ubo
Definition: uniform_buffer.c:26
cvar_bloom_sigma_water
cvar_t * cvar_bloom_sigma_water
Definition: bloom.c:49
vkpt_pt_create_viewer_models
static VkResult vkpt_pt_create_viewer_models(VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, int vertex_offset)
Definition: path_tracer.c:703
TAA
@ TAA
Definition: asvgf.c:33
QVKUniformBuffer_s
Definition: global_ubo.h:247
cmd_buf_group_s::used_this_frame
uint32_t used_this_frame
Definition: vkpt.h:145
light_poly_s
Definition: vkpt.h:315
accel_viewer_models
static VkAccelerationStructureNV accel_viewer_models[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:74
TESS_MAX_INDICES
#define TESS_MAX_INDICES
Definition: gl.h:460
CREATE_PIPELINE_LAYOUT
#define CREATE_PIPELINE_LAYOUT(dev, layout,...)
Definition: vk_util.h:82
mem_images
static VkDeviceMemory mem_images[NUM_VKPT_IMAGES]
Definition: textures.c:66
filter_static_sky
static int filter_static_sky(int flags)
Definition: bsp_mesh.c:263
transparency
struct @17 transparency
UnusedResources::image_num
uint32_t image_num
Definition: textures.c:38
LOG_FUNC
#define LOG_FUNC()
Definition: vkpt.h:54
QVK_s::frame_counter
uint64_t frame_counter
Definition: vkpt.h:212
maliasmesh_s::numindices
int numindices
Definition: gl.h:235
SUN_COLOR_BUFFER_BINDING_IDX
#define SUN_COLOR_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:49
READBACK_BUFFER_BINDING_IDX
#define READBACK_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:47
max_model_lights
static int max_model_lights
Definition: vertex_buffer.c:129
PROFILER_START
@ PROFILER_START
Definition: vkpt.h:469
VKPTProfilerAction
VKPTProfilerAction
Definition: vkpt.h:468
MAX_VERT_MODEL
#define MAX_VERT_MODEL
Definition: vertex_buffer.h:25
SBT_RGEN_PRIMARY_RAYS
#define SBT_RGEN_PRIMARY_RAYS
Definition: constants.h:121
decode_srgb
static float decode_srgb(byte pix)
Definition: textures.c:497
QVK_s::num_swap_chain_images
uint32_t num_swap_chain_images
Definition: vkpt.h:189
vkpt_pt_destroy_explosions
VkResult vkpt_pt_destroy_explosions(int idx)
Definition: path_tracer.c:439
UnusedResources::buffers
VkBuffer buffers[MAX_RBUFFERS]
Definition: textures.c:39
SBT_RGEN_DIRECT_LIGHTING_CAUSTICS
#define SBT_RGEN_DIRECT_LIGHTING_CAUSTICS
Definition: constants.h:125
TR_COLOR_SIZE
#define TR_COLOR_SIZE
Definition: transparency.c:29
MATERIAL_KIND_LAVA
#define MATERIAL_KIND_LAVA
Definition: constants.h:62
MAX_FRAMES_IN_FLIGHT
#define MAX_FRAMES_IN_FLIGHT
Definition: vkpt.h:140
bsp_mesh_s::sky_visibility
char sky_visibility[VIS_MAX_BYTES]
Definition: vkpt.h:384
GLOBAL_TEXTURES_TEX_ARR_BINDING_IDX
#define GLOBAL_TEXTURES_TEX_ARR_BINDING_IDX
Definition: global_textures.h:124
height
static int height
Definition: physical_sky.c:39
get_transparency_beam_blas
VkAccelerationStructureNV get_transparency_beam_blas()
Definition: transparency.c:231
buf_shader_binding_table
static BufferResource_t buf_shader_binding_table
Definition: path_tracer.c:93
BARRIER_FROM_COPY_DEST
#define BARRIER_FROM_COPY_DEST(cmd_buf, img)
Definition: bloom.c:243
Q_snprintf
size_t Q_snprintf(char *dest, size_t size, const char *fmt,...)
Definition: shared.c:846
maliasframe_s::scale
vec3_t scale
Definition: gl.h:226
pipeline_layout_atrous
static VkPipelineLayout pipeline_layout_atrous
Definition: asvgf.c:40
sprite_info_buffer_view
VkBufferView sprite_info_buffer_view
Definition: transparency.c:74
bsp_mesh_s::cluster_aabbs
aabb_t * cluster_aabbs
Definition: vkpt.h:386
pbr_material_s::next_frame
int next_frame
Definition: material.h:45
num_accumulated_frames
int num_accumulated_frames
Definition: main.c:100
allocate_gpu_memory
VkResult allocate_gpu_memory(VkMemoryRequirements mem_req, VkDeviceMemory *pMemory)
Definition: vk_util.c:402
image_t
struct image_s image_t
Definition: material.h:27
viewer_model_primitive_offset
static int viewer_model_primitive_offset
Definition: path_tracer.c:66
SHADER_STAGE_SPEC
#define SHADER_STAGE_SPEC(_module, _stage, _spec)
Definition: vkpt.h:124
vkpt_freecam_mousemove
static void vkpt_freecam_mousemove()
Definition: freecam.c:64
mem_blue_noise
static VkDeviceMemory mem_blue_noise
Definition: textures.c:55
QVK_s::buf_tonemap
BufferResource_t buf_tonemap
Definition: vkpt.h:252
bsp_mesh_s::clusters
int * clusters
Definition: vkpt.h:367
destroy_invalid_texture
void destroy_invalid_texture()
Definition: textures.c:813
EntityUploadInfo::viewer_model_vertex_num
uint32_t viewer_model_vertex_num
Definition: vkpt.h:481
pipeline_asvgf
static VkPipeline pipeline_asvgf[ASVGF_NUM_PIPELINES]
Definition: asvgf.c:39
render_pass_stretch_pic
static VkRenderPass render_pass_stretch_pic
Definition: draw.c:52
get_scratch_buffer_size
static size_t get_scratch_buffer_size(VkAccelerationStructureNV ac)
Definition: path_tracer.c:306
allocate_and_bind_memory_to_buffers
static qboolean allocate_and_bind_memory_to_buffers()
Definition: transparency.c:932
QVK_s::device
VkDevice device
Definition: vkpt.h:172
Hunk_Begin
void Hunk_Begin(memhunk_t *hunk, size_t maxsize)
Definition: hunk.c:23
MOD_ForHandle
model_t * MOD_ForHandle(qhandle_t h)
Definition: models.c:430
rt_descriptor_pool
static VkDescriptorPool rt_descriptor_pool
Definition: path_tracer.c:95
freecam_keystate
static qboolean freecam_keystate[6]
Definition: freecam.c:37
pbr_material_s::image_normals
image_t * image_normals
Definition: material.h:36
compute_cluster_aabbs
static void compute_cluster_aabbs(bsp_mesh_t *wm)
Definition: bsp_mesh.c:1388
PROFILER_DO
#define PROFILER_DO(a,...)
Definition: vkpt.h:460
FILTER_THREAD_GROUP_SIZE
static const uint32_t FILTER_THREAD_GROUP_SIZE
Definition: god_rays.c:24
RAY_GEN_BEAM_COLOR_BUFFER_BINDING_IDX
#define RAY_GEN_BEAM_COLOR_BUFFER_BINDING_IDX
Definition: path_tracer.c:30
vkpt_pt_destroy_viewer_models
VkResult vkpt_pt_destroy_viewer_models(int idx)
Definition: path_tracer.c:411
texture_system
static TextureSystem texture_system
Definition: textures.c:51
bsp_mesh_s::texel_density
float * texel_density
Definition: vkpt.h:362
align
static size_t align(size_t x, size_t alignment)
Definition: vk_util.h:143
pipeline_layout_tone_mapping_histogram
static VkPipelineLayout pipeline_layout_tone_mapping_histogram
Definition: tone_mapping.c:68
pipeline_layout_blur
static VkPipelineLayout pipeline_layout_blur
Definition: bloom.c:30
EntityUploadInfo::dynamic_vertex_num
uint32_t dynamic_vertex_num
Definition: vkpt.h:477
vkpt_refdef
vkpt_refdef_t vkpt_refdef
Definition: main.c:372
computeTangents
static void computeTangents(model_t *model)
Definition: models.c:56
cmd_buf_group_s::count_per_frame
uint32_t count_per_frame
Definition: vkpt.h:144
accel_top_match
static accel_top_match_info_t accel_top_match[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:81
TONE_MAPPING_CURVE
@ TONE_MAPPING_CURVE
Definition: tone_mapping.c:62
get_transparency_sprite_blas
VkAccelerationStructureNV get_transparency_sprite_blas()
Definition: transparency.c:236
Cvar_Get
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags)
Definition: cvar.c:257
BLUR
@ BLUR
Definition: bloom.c:23
bsp_model_s::light_polys
light_poly_t * light_polys
Definition: vkpt.h:333
MAT_UpdateRegistration
void MAT_UpdateRegistration(pbr_material_t *mat)
Definition: material.c:421
particles
static cparticle_t particles[MAX_PARTICLES]
Definition: effects.c:830
QVK_s::cmd_buffers_transfer
cmd_buf_group_t cmd_buffers_transfer
Definition: vkpt.h:195
create_device_memory_allocator
DeviceMemoryAllocator * create_device_memory_allocator(VkDevice device)
Definition: device_memory_allocator.c:48
collect_ligth_polys
static void collect_ligth_polys(bsp_mesh_t *wm, bsp_t *bsp, int model_idx, int *num_lights, int *allocated_lights, light_poly_t **lights)
Definition: bsp_mesh.c:729
rt_pipeline_layout
static VkPipelineLayout rt_pipeline_layout
Definition: path_tracer.c:98
BINDING_OFFSET_SKY_CLOUDS
#define BINDING_OFFSET_SKY_CLOUDS
Definition: global_textures.h:134
QvkGeometryInstance_s
Definition: path_tracer.c:109
cast_u32_to_f32_color
void cast_u32_to_f32_color(int color_index, const color_t *pcolor, float *color_f32, float hdr_factor)
Definition: transparency.c:102
GLOBAL_INSTANCE_BUFFER_BINDING_IDX
#define GLOBAL_INSTANCE_BUFFER_BINDING_IDX
Definition: global_ubo.h:26
clip_rect
static clipRect_t clip_rect
Definition: draw.c:45
QVKInstanceBuffer_s
Definition: global_ubo.h:253
pbr_material_s::image_emissive
image_t * image_emissive
Definition: material.h:37
pipeline_layout_instance_geometry
static VkPipelineLayout pipeline_layout_instance_geometry
Definition: vertex_buffer.c:33
allocate_device_memory
DMAResult allocate_device_memory(DeviceMemoryAllocator *allocator, DeviceMemory *device_memory)
Definition: device_memory_allocator.c:60
light_poly_s::color
vec3_t color
Definition: vkpt.h:318
QVK_s::buf_vertex
BufferResource_t buf_vertex
Definition: vkpt.h:243
cluster_debug_mask
char cluster_debug_mask[VIS_MAX_BYTES]
Definition: main.c:83
pbr_material_s::flags
uint32_t flags
Definition: material.h:42
collect_surfaces
static void collect_surfaces(int *idx_ctr, bsp_mesh_t *wm, bsp_t *bsp, int model_idx, int(*filter)(int))
Definition: bsp_mesh.c:457
god_rays
struct @15 god_rays
light_poly_s::material
struct pbr_material_s * material
Definition: vkpt.h:319
cvar_pt_particle_size
cvar_t * cvar_pt_particle_size
Definition: transparency.c:95
_VK_EXTENSION_DO
#define _VK_EXTENSION_DO(a)
Definition: vkpt.h:309
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: path_tracer.c:971
desc_pool_textures
static VkDescriptorPool desc_pool_textures
Definition: textures.c:60
vkpt_build_cylinder_light
qboolean vkpt_build_cylinder_light(light_poly_t *light_list, int *num_lights, int max_lights, bsp_t *bsp, vec3_t begin, vec3_t end, vec3_t color, float radius)
Definition: transparency.c:408
ATROUS_ITER_0
@ ATROUS_ITER_0
Definition: asvgf.c:29
get_num_miplevels
static int get_num_miplevels(int w, int h)
Definition: textures.c:485
accel_static
static VkAccelerationStructureNV accel_static
Definition: path_tracer.c:57
compute_sky_visibility
static void compute_sky_visibility(bsp_mesh_t *wm, bsp_t *bsp)
Definition: bsp_mesh.c:1354
buffer_unmap
void buffer_unmap(BufferResource_t *buf)
Definition: vk_util.c:159
bsp_mesh_s::tex_coords
float * tex_coords
Definition: vkpt.h:359
bsp_mesh_load_custom_sky
static qboolean bsp_mesh_load_custom_sky(int *idx_ctr, bsp_mesh_t *wm, bsp_t *bsp, const char *map_name)
Definition: bsp_mesh.c:1538
tex_image_memory
static DeviceMemory tex_image_memory[MAX_RIMAGES]
Definition: textures.c:68
QVK_s::current_frame_index
uint32_t current_frame_index
Definition: vkpt.h:219
push_constants_hblur
static struct bloom_blur_push_constants push_constants_hblur
Definition: bloom.c:42
NUM_PROFILER_QUERIES_PER_FRAME
#define NUM_PROFILER_QUERIES_PER_FRAME
Definition: vkpt.h:466
QVK_s::tex_sampler
VkSampler tex_sampler
Definition: vkpt.h:255
QVK_s::buf_readback
BufferResource_t buf_readback
Definition: vkpt.h:249
write_particle_geometry
static void write_particle_geometry(const float *view_matrix, const particle_t *particles, int particle_num)
Definition: transparency.c:263
QVK_s::gpu_slice_width
uint32_t gpu_slice_width
Definition: vkpt.h:187
AS_FLAG_VIEWER_MODELS
#define AS_FLAG_VIEWER_MODELS
Definition: constants.h:110
get_transparency_counts
void get_transparency_counts(int *particle_num, int *beam_num, int *sprite_num)
Definition: transparency.c:256
drawStatic_t::colors
color_t colors[2]
Definition: gl.h:402
pipelines
static VkPipeline pipelines[TM_NUM_PIPELINES]
Definition: tone_mapping.c:67
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: bloom.c:205
AS_FLAG_SKY
#define AS_FLAG_SKY
Definition: constants.h:113
LIGHT_POLY_VEC4S
#define LIGHT_POLY_VEC4S
Definition: vertex_buffer.h:36
vkpt_pt_create_accel_bottom
static VkResult vkpt_pt_create_accel_bottom(VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, VkAccelerationStructureNV *accel, accel_bottom_match_info_t *match, VkDeviceMemory *mem_accel, VkCommandBuffer cmd_buf, int fast_build)
Definition: path_tracer.c:464
vkpt_pt_create_transparent_models
static VkResult vkpt_pt_create_transparent_models(VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, int vertex_offset)
Definition: path_tracer.c:670
get_transparency_sprite_info_buffer_view
VkBufferView get_transparency_sprite_info_buffer_view()
Definition: transparency.c:251
BINDING_OFFSET_BLUE_NOISE
#define BINDING_OFFSET_BLUE_NOISE
Definition: global_textures.h:127
MAX_STRETCH_PICS
#define MAX_STRETCH_PICS
Definition: draw.c:31
d_8to24table
uint32_t d_8to24table[256]
Definition: images.c:654
VERTEX_BUFFER_BINDING_IDX
#define VERTEX_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:45
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
accel_explosions
static VkAccelerationStructureNV accel_explosions[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:78
UnusedResources
Definition: textures.c:33
sv_paused
cvar_t * sv_paused
Definition: common.c:96
QVK_s::fence_vertex_sync
VkFence fence_vertex_sync
Definition: vkpt.h:207
bsp_mesh_s::num_models
int num_models
Definition: vkpt.h:346
filter_all
static int filter_all(int flags)
Definition: bsp_mesh.c:271
TextureSystem::unused_resources
UnusedResources unused_resources[DESTROY_LATENCY]
Definition: textures.c:48
SBT_RMISS_SHADOW
#define SBT_RMISS_SHADOW
Definition: constants.h:129
bsp_mesh_s::num_cluster_lights
int num_cluster_lights
Definition: vkpt.h:369
MATERIAL_FLAG_LIGHT
#define MATERIAL_FLAG_LIGHT
Definition: constants.h:73
BINDING_OFFSET_TERRAIN_ALBEDO
#define BINDING_OFFSET_TERRAIN_ALBEDO
Definition: global_textures.h:135
MAX_IDX_MODEL
#define MAX_IDX_MODEL
Definition: vertex_buffer.h:26
load_sky_and_lava_clusters
static void load_sky_and_lava_clusters(bsp_mesh_t *wm, const char *map_name)
Definition: bsp_mesh.c:1222
AS_INSTANCE_FLAG_DYNAMIC
#define AS_INSTANCE_FLAG_DYNAMIC
Definition: constants.h:117
destroy_readback_image
static void destroy_readback_image(VkImage *image, VkDeviceMemory *memory, VkDeviceSize *memory_size)
Definition: textures.c:1431
COMPOSITING
@ COMPOSITING
Definition: asvgf.c:35
vkpt_pt_destroy_viewer_weapon
VkResult vkpt_pt_destroy_viewer_weapon(int idx)
Definition: path_tracer.c:425
MOD_ValidateMD2
qerror_t MOD_ValidateMD2(dmd2header_t *header, size_t length)
Definition: models.c:142
tex_device_memory_allocator
static DeviceMemoryAllocator * tex_device_memory_allocator
Definition: textures.c:70
TR_SPRITE_MAX_NUM
#define TR_SPRITE_MAX_NUM
Definition: transparency.c:25
bsp_mesh_s::allocated_light_polys
int allocated_light_polys
Definition: vkpt.h:374
mem_accel_transparent
static VkDeviceMemory mem_accel_transparent
Definition: path_tracer.c:83
freecam_active
static qboolean freecam_active
Definition: freecam.c:38
imv_smap_depth_array
static VkImageView imv_smap_depth_array
Definition: shadow_map.c:32
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
maliasmesh_s::indices
QGL_INDEX_TYPE * indices
Definition: gl.h:236
accel_custom_sky
static VkAccelerationStructureNV accel_custom_sky
Definition: path_tracer.c:60
PROFILER_DO
#define PROFILER_DO(name, indent)
BSP_SavePatchedPVS
qboolean BSP_SavePatchedPVS(bsp_t *bsp)
Definition: bsp.c:1051
desc_pool_vertex_buffer
static VkDescriptorPool desc_pool_vertex_buffer
Definition: vertex_buffer.c:30
write_beam_geometry
static void write_beam_geometry(const float *view_matrix, const entity_t *entities, int entity_num)
Definition: transparency.c:325
bsp_mesh_s::tangents
float * tangents
Definition: vkpt.h:359
create_orthographic_matrix
void create_orthographic_matrix(float matrix[16], float xmin, float xmax, float ymin, float ymax, float znear, float zfar)
Definition: matrix.c:100
cvar_pt_aperture
cvar_t * cvar_pt_aperture
TONE_MAPPING_BUFFER_BINDING_IDX
#define TONE_MAPPING_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:48
pipeline_layout_general
static VkPipelineLayout pipeline_layout_general
Definition: asvgf.c:41
StretchPic_t
Definition: draw.c:39
cvar_bloom_intensity
cvar_t * cvar_bloom_intensity
Definition: bloom.c:48
bloom_intensity
static float bloom_intensity
Definition: bloom.c:52
create_buffer_views
static void create_buffer_views()
Definition: transparency.c:1114
aabb_s::mins
vec3_t mins
Definition: vkpt.h:339
buf_instances
static BufferResource_t buf_instances[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:56
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
QVK_s::cmd_buffers_graphics
cmd_buf_group_t cmd_buffers_graphics
Definition: vkpt.h:193
bsp_mesh_s::num_indices
int num_indices
Definition: vkpt.h:363
compare_beams
static int compare_beams(const void *_a, const void *_b)
Definition: transparency.c:388
QVK_s::shader_modules
VkShaderModule shader_modules[NUM_QVK_SHADER_MODULES]
Definition: vkpt.h:223
build_pvs2
static void build_pvs2(bsp_t *bsp)
Definition: bsp_mesh.c:436
create_render_pass
static void create_render_pass()
Definition: draw.c:163
framebuffer_smap2
static VkFramebuffer framebuffer_smap2
Definition: shadow_map.c:28
bsp_model_s::center
vec3_t center
Definition: vkpt.h:327
Sys_Milliseconds
unsigned Sys_Milliseconds(void)
Definition: system.c:644
framebuffer_smap
static VkFramebuffer framebuffer_smap
Definition: shadow_map.c:27
TEMPORAL
@ TEMPORAL
Definition: asvgf.c:27
BSP_PointLeaf
mleaf_t * BSP_PointLeaf(mnode_t *node, vec3_t p)
Definition: bsp.c:1439
MAT_RegisterPBRMaterial
qerror_t MAT_RegisterPBRMaterial(pbr_material_t *mat, image_t *image_diffuse, image_t *image_normals, image_t *image_emissive)
Definition: material.c:397
maliasmesh_s::tex_coords
vec2_t * tex_coords
Definition: vkpt.h:701
freecam_zoom
static float freecam_zoom
Definition: freecam.c:36
_try_image_format
static int _try_image_format(imageformat_t fmt, image_t *image, byte **pic)
Definition: images.c:787
imv_smap_depth2
static VkImageView imv_smap_depth2
Definition: shadow_map.c:31
ATROUS_ITER_1
@ ATROUS_ITER_1
Definition: asvgf.c:30
bsp_mesh_s::num_vertices
int num_vertices
Definition: vkpt.h:364
bsp_model_s::aabb_min
vec3_t aabb_min
Definition: vkpt.h:328
QVK_s::physical_device
VkPhysicalDevice physical_device
Definition: vkpt.h:163
END_PERF_MARKER
#define END_PERF_MARKER(command_buffer, name)
Definition: vkpt.h:743
maliasframe_s::translate
vec3_t translate
Definition: gl.h:227
profiler_queries_used
static qboolean profiler_queries_used[NUM_PROFILER_QUERIES_PER_FRAME *2]
Definition: profiler.c:27
under_water_animation
static float under_water_animation
Definition: bloom.c:54
TR_VERTEX_MAX_NUM
#define TR_VERTEX_MAX_NUM
Definition: transparency.c:26
beam_color_buffer_view
VkBufferView beam_color_buffer_view
Definition: transparency.c:73
QVK_s::desc_set_textures_even
VkDescriptorSet desc_set_textures_even
Definition: vkpt.h:229
cvar_pt_dof
cvar_t * cvar_pt_dof
Definition: main.c:57
pbr_material_s::specular_scale
float specular_scale
Definition: material.h:40
LIGHT_BUFFER_BINDING_IDX
#define LIGHT_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:46
draw
drawStatic_t draw
Definition: draw.c:21
sun_light_s::visible
qboolean visible
Definition: vkpt.h:420
custom_sky_primitive_offset
static int custom_sky_primitive_offset
Definition: path_tracer.c:63
CL_PLAYER_MODEL_DISABLED
#define CL_PLAYER_MODEL_DISABLED
Definition: client.h:553
compute_world_tangents
void compute_world_tangents(bsp_mesh_t *wm)
Definition: bsp_mesh.c:1131
QVK_s::screenshot_image_memory
VkDeviceMemory screenshot_image_memory
Definition: vkpt.h:262
image_loading_dirty_flag
static int image_loading_dirty_flag
Definition: textures.c:72
maliasmesh_s::numverts
int numverts
Definition: gl.h:233
accel_top
static VkAccelerationStructureNV accel_top[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:80
pipeline_layout_final_blit
static VkPipelineLayout pipeline_layout_final_blit
Definition: draw.c:51
Hunk_Free
void Hunk_Free(memhunk_t *hunk)
Definition: hunk.c:75
cvar_pt_enable_beams
cvar_t * cvar_pt_enable_beams
Definition: path_tracer.c:102
explosions_primitive_offset
static int explosions_primitive_offset
Definition: path_tracer.c:68
width
static int width
Definition: physical_sky.c:38
LightBuffer
struct LightBuffer LightBuffer
Definition: vertex_buffer.h:160
pipeline_instance_geometry
static VkPipeline pipeline_instance_geometry
Definition: vertex_buffer.c:31
AS_FLAG_PARTICLES
#define AS_FLAG_PARTICLES
Definition: constants.h:109
vkpt_refdef_s::fd
refdef_t * fd
Definition: vkpt.h:396
maliasmesh_s::positions
vec3_t * positions
Definition: vkpt.h:699
img_envmap
static VkImage img_envmap
Definition: textures.c:58
get_memory_type
uint32_t get_memory_type(uint32_t mem_req_type_bits, VkMemoryPropertyFlags mem_prop)
Definition: vk_util.c:45
_VK
#define _VK(...)
Definition: vkpt.h:65
DeviceMemory::alignment
uint64_t alignment
Definition: device_memory_allocator.h:33
vkpt_pt_create_viewer_weapon
static VkResult vkpt_pt_create_viewer_weapon(VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, int vertex_offset)
Definition: path_tracer.c:726
BINDING_OFFSET_SKY_SCATTERING
#define BINDING_OFFSET_SKY_SCATTERING
Definition: global_textures.h:132
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: asvgf.c:192
vkpt_normalize_normal_map
void vkpt_normalize_normal_map(image_t *image)
Definition: textures.c:592
vkpt_refdef_s::bsp_mesh_world
bsp_mesh_t bsp_mesh_world
Definition: vkpt.h:406
reset_required
static int reset_required
Definition: tone_mapping.c:71
tex_invalid_texture_image_view
static VkImageView tex_invalid_texture_image_view
Definition: textures.c:63
bsp_model_s::idx_count
uint32_t idx_count
Definition: vkpt.h:326
GLOBAL_UBO_BINDING_IDX
#define GLOBAL_UBO_BINDING_IDX
Definition: global_ubo.h:25
NUM_IMAGES
#define NUM_IMAGES
Definition: global_textures.h:121
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
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
DeviceMemory
Definition: device_memory_allocator.h:28
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: god_rays.c:121
collect_cluster_lights
static void collect_cluster_lights(bsp_mesh_t *wm, bsp_t *bsp)
Definition: bsp_mesh.c:1471
SBT_RAHIT_SPRITE
#define SBT_RAHIT_SPRITE
Definition: constants.h:134
maliasframe_s::bounds
vec3_t bounds[2]
Definition: gl.h:228
bsp_mesh_s::cluster_lights
int * cluster_lights
Definition: vkpt.h:371
PROFILER_LIST
#define PROFILER_LIST
Definition: vkpt.h:432
UnusedResources::image_views
VkImageView image_views[MAX_RIMAGES]
Definition: textures.c:36
MAX_BEAMS
#define MAX_BEAMS
Definition: transparency.c:386
img_smap
static VkImage img_smap
Definition: shadow_map.c:29
pbr_material_s::emissive_scale
float emissive_scale
Definition: material.h:41
bsp_mesh_s::cluster_light_offsets
int * cluster_light_offsets
Definition: vkpt.h:370
pbr_material_s::bump_scale
float bump_scale
Definition: material.h:38
pipeline_layout_taa
static VkPipelineLayout pipeline_layout_taa
Definition: asvgf.c:42
explosions_present
static int explosions_present
Definition: path_tracer.c:69
QVK_s::queue_idx_graphics
int32_t queue_idx_graphics
Definition: vkpt.h:176
pipeline_layout_smap
VkPipelineLayout pipeline_layout_smap
Definition: shadow_map.c:24
QVK_s::extent_screen_images
VkExtent2D extent_screen_images
Definition: vkpt.h:183
QVK_s::desc_set_vertex_buffer
VkDescriptorSet desc_set_vertex_buffer
Definition: vkpt.h:241
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
AS_FLAG_CUSTOM_SKY
#define AS_FLAG_CUSTOM_SKY
Definition: constants.h:114
SBT_RCHIT_EMPTY
#define SBT_RCHIT_EMPTY
Definition: constants.h:135
forward
static vec3_t forward
Definition: p_view.c:27
cmd_buf_group_s
Definition: vkpt.h:143
ATROUS_ITER_3
@ ATROUS_ITER_3
Definition: asvgf.c:32
pbr_material_s::num_frames
int num_frames
Definition: material.h:44
stretch_pic_queue
static StretchPic_t stretch_pic_queue[MAX_STRETCH_PICS]
Definition: draw.c:48
pipeline_layout_tone_mapping_curve
static VkPipelineLayout pipeline_layout_tone_mapping_curve
Definition: tone_mapping.c:69
LIST_IMAGES
#define LIST_IMAGES
Definition: global_textures.h:34
cl_player_model
cvar_t * cl_player_model
Definition: main.c:47
maliasframe_s::radius
vec_t radius
Definition: gl.h:229
RAY_GEN_PARTICLE_COLOR_BUFFER_BINDING_IDX
#define RAY_GEN_PARTICLE_COLOR_BUFFER_BINDING_IDX
Definition: path_tracer.c:29
ATROUS_ITER_2
@ ATROUS_ITER_2
Definition: asvgf.c:31
ToneMappingBuffer
Definition: vertex_buffer.h:116
mix
static float mix(float a, float b, float s)
Definition: bloom.c:83
tex_bind_image_info
static VkBindImageMemoryInfo tex_bind_image_info[MAX_RIMAGES]
Definition: textures.c:69
SBT_RAHIT_PARTICLE
#define SBT_RAHIT_PARTICLE
Definition: constants.h:131
PROFILER_STOP
@ PROFILER_STOP
Definition: vkpt.h:470
TR_SPRITE_INFO_SIZE
#define TR_SPRITE_INFO_SIZE
Definition: transparency.c:30
THREAD_GROUP_SIZE
static const uint32_t THREAD_GROUP_SIZE
Definition: god_rays.c:23
cvar_pt_beam_width
cvar_t * cvar_pt_beam_width
Definition: transparency.c:96
pbr_material_s
Definition: material.h:33
get_triangle_off_center
qboolean get_triangle_off_center(const float *positions, float *center, float *anti_center)
Definition: bsp_mesh.c:282
ToneMappingBuffer
struct ToneMappingBuffer ToneMappingBuffer
Definition: vertex_buffer.h:162
maliasmesh_s::materials
struct pbr_material_s * materials[MAX_ALIAS_SKINS]
Definition: vkpt.h:703
cvar_pt_freecam
cvar_t * cvar_pt_freecam
Definition: main.c:58
filter_static_opaque
static int filter_static_opaque(int flags)
Definition: bsp_mesh.c:245
QVK_s::buf_sun_color
BufferResource_t buf_sun_color
Definition: vkpt.h:253
MAX_VERT_BSP
#define MAX_VERT_BSP
Definition: vertex_buffer.h:23
va
char * va(const char *format,...)
Definition: shared.c:429
SBT_RGEN_REFLECT_REFRACT1
#define SBT_RGEN_REFLECT_REFRACT1
Definition: constants.h:122
Z_Free
void Z_Free(void *ptr)
Definition: zone.c:147
FWD_PROJECT
@ FWD_PROJECT
Definition: asvgf.c:24
num_stretch_pics
static int num_stretch_pics
Definition: draw.c:38
BufferResource_s::buffer
VkBuffer buffer
Definition: vk_util.h:34
create_render_pass
static void create_render_pass()
Definition: shadow_map.c:36
BLOOM_NUM_PIPELINES
@ BLOOM_NUM_PIPELINES
Definition: bloom.c:26
cvar_pt_focus
cvar_t * cvar_pt_focus
bsp_model_s::allocated_light_polys
int allocated_light_polys
Definition: vkpt.h:332
vkpt_pt_create_explosions
static VkResult vkpt_pt_create_explosions(VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices, int vertex_offset)
Definition: path_tracer.c:749
descriptor_set_dirty_flags
static uint8_t descriptor_set_dirty_flags[MAX_FRAMES_IN_FLIGHT]
Definition: textures.c:73
buf_stretch_pic_queue
static BufferResource_t buf_stretch_pic_queue[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:56
freecam_vieworg
static vec3_t freecam_vieworg
Definition: freecam.c:34
QVK_s::swap_chain_images
VkImage swap_chain_images[MAX_SWAPCHAIN_IMAGES]
Definition: vkpt.h:190
try_other_formats
static int try_other_formats(imageformat_t orig, image_t *image, byte **pic)
Definition: images.c:823
Key_IsDown
int Key_IsDown(int key)
Definition: keys.c:204
CL_PLAYER_MODEL_FIRST_PERSON
#define CL_PLAYER_MODEL_FIRST_PERSON
Definition: client.h:555
m
static struct mdfour * m
Definition: mdfour.c:32
buf_accel_scratch
static BufferResource_t buf_accel_scratch
Definition: path_tracer.c:54
vkpt_extract_emissive_texture_info
void vkpt_extract_emissive_texture_info(image_t *image)
Definition: textures.c:532
get_transparency_beam_color_buffer_view
VkBufferView get_transparency_beam_color_buffer_view()
Definition: transparency.c:246
pipeline_animate_materials
static VkPipeline pipeline_animate_materials
Definition: vertex_buffer.c:32
ClearBounds
void ClearBounds(vec3_t mins, vec3_t maxs)
Definition: shared.c:91
push_constants
push_constants
Definition: path_tracer.h:129
accel_viewer_weapon
static VkAccelerationStructureNV accel_viewer_weapon[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:76
cvar_bloom_intensity_water
cvar_t * cvar_bloom_intensity_water
Definition: bloom.c:50
GRADIENT_ATROUS
@ GRADIENT_ATROUS
Definition: asvgf.c:26
cmd_buf_group_s::buffers
VkCommandBuffer * buffers
Definition: vkpt.h:146
origin
static vec3_t origin
Definition: mesh.c:27
bsp_mesh_s::materials
uint32_t * materials
Definition: vkpt.h:361
IMG_WIDTH
#define IMG_WIDTH
Definition: global_textures.h:25
bsp_mesh_s::models
bsp_model_t * models
Definition: vkpt.h:345
NUM_QVK_SHADER_MODULES
@ NUM_QVK_SHADER_MODULES
Definition: vkpt.h:137
r_images
image_t r_images[MAX_RIMAGES]
Definition: images.c:651
AngleVectors
void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Definition: shared.c:23
max_cluster_model_lights
static int max_cluster_model_lights[MAX_MAP_LEAFS]
Definition: vertex_buffer.c:128
mem_accel_static
static VkDeviceMemory mem_accel_static
Definition: path_tracer.c:82
mult_matrix_vector
void mult_matrix_vector(float *p, const float *a, const float *b)
Definition: matrix.c:295
_VK_INST_EXTENSION_DO
#define _VK_INST_EXTENSION_DO(a)
Definition: vkpt.h:280
Hunk_End
void Hunk_End(memhunk_t *hunk)
Definition: hunk.c:66
encode_linear
static byte encode_linear(float x)
Definition: textures.c:524
viewer_weapon_primitive_offset
static int viewer_weapon_primitive_offset
Definition: path_tracer.c:67
transparent_models_present
static int transparent_models_present
Definition: path_tracer.c:65
freecam_viewangles
static vec3_t freecam_viewangles
Definition: freecam.c:35
QVK_s::images
VkImage images[NUM_VKPT_IMAGES]
Definition: vkpt.h:231
setup_rt_pipeline
static void setup_rt_pipeline(VkCommandBuffer cmd_buf)
Definition: path_tracer.c:990
UnusedResources::buffer_num
uint32_t buffer_num
Definition: textures.c:41
ubo_alignment
static size_t ubo_alignment
Definition: uniform_buffer.c:27
MAX_LIGHT_LISTS
#define MAX_LIGHT_LISTS
Definition: vertex_buffer.h:32
set_current_gpu
void set_current_gpu(VkCommandBuffer cmd_buf, int gpu_index)
Definition: vk_util.c:426
MEM_BARRIER_BUILD_ACCEL
#define MEM_BARRIER_BUILD_ACCEL(cmd_buf,...)
Definition: path_tracer.c:118
update_descriptor_set
static void update_descriptor_set()
Definition: god_rays.c:353
QVK_s::screenshot_image
VkImage screenshot_image
Definition: vkpt.h:261
create_descriptor_set
static void create_descriptor_set()
Definition: god_rays.c:327
IMG_HEIGHT
#define IMG_HEIGHT
Definition: global_textures.h:26
vkpt_refdef
vkpt_refdef_t vkpt_refdef
Definition: main.c:372
Cvar_SetByVar
void Cvar_SetByVar(cvar_t *var, const char *value, from_t from)
Definition: cvar.c:345
light_poly_s::style
int style
Definition: vkpt.h:321
Q_strlcpy
size_t Q_strlcpy(char *dst, const char *src, size_t size)
Definition: shared.c:715
cvar_pt_beam_lights
cvar_t * cvar_pt_beam_lights
Definition: transparency.c:97
freecam_player_model
static int freecam_player_model
Definition: freecam.c:39
ReadbackBuffer
Definition: vertex_buffer.h:134
AS_INSTANCE_FLAG_SKY
#define AS_INSTANCE_FLAG_SKY
Definition: constants.h:118
vkpt_reset_command_buffers
void vkpt_reset_command_buffers(cmd_buf_group_t *group)
Definition: main.c:3392
framebuffer_stretch_pic
static VkFramebuffer framebuffer_stretch_pic[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:55
beam_num
unsigned int beam_num
Definition: transparency.c:51
imv_blue_noise
static VkImageView imv_blue_noise
Definition: textures.c:57
vkpt_wait_idle
void vkpt_wait_idle(VkQueue queue, cmd_buf_group_t *group)
Definition: main.c:3405
bsp_model_s
Definition: vkpt.h:324
BARRIER_TO_COPY_SRC
#define BARRIER_TO_COPY_SRC(cmd_buf, img)
Definition: bloom.c:262
pipelines
VkPipeline pipelines[2]
Definition: god_rays.c:28
LENGTH
#define LENGTH(a)
Definition: tent.c:228
sprite_num
unsigned int sprite_num
Definition: transparency.c:52
cmd_buf_group_s::command_pool
VkCommandPool command_pool
Definition: vkpt.h:147
SHADOWMAP_SIZE
#define SHADOWMAP_SIZE
Definition: constants.h:24
sun_light_s::angular_size_rad
float angular_size_rad
Definition: vkpt.h:418
pbr_material_s::image_diffuse
image_t * image_diffuse
Definition: material.h:35
physical_sky_space
cvar_t * physical_sky_space
Definition: physical_sky.c:57
write_sprite_geometry
static void write_sprite_geometry(const float *view_matrix, const entity_t *entities, int entity_num)
Definition: transparency.c:546
BEGIN_PERF_MARKER
#define BEGIN_PERF_MARKER(command_buffer, name)
Definition: vkpt.h:742
SBT_RAHIT_BEAM
#define SBT_RAHIT_BEAM
Definition: constants.h:132
MAT_GetPBRMaterialsTable
const pbr_material_t * MAT_GetPBRMaterialsTable()
Definition: material.c:139
NUM_LIGHT_STATS_BUFFERS
#define NUM_LIGHT_STATS_BUFFERS
Definition: constants.h:44
AS_FLAG_OPAQUE
#define AS_FLAG_OPAQUE
Definition: constants.h:107
VertexBuffer
struct VertexBuffer VertexBuffer
Definition: vertex_buffer.h:159
MAT_IsKind
qboolean MAT_IsKind(uint32_t material, uint32_t kind)
Definition: material.c:665
bloom_sigma
static float bloom_sigma
Definition: bloom.c:53
VKPT_MAX_GPUS
#define VKPT_MAX_GPUS
Definition: vk_util.h:30
cvar_bloom_debug
cvar_t * cvar_bloom_debug
Definition: bloom.c:46
MAX_LIGHT_POLYS
#define MAX_LIGHT_POLYS
Definition: vertex_buffer.h:35
QVKUniformBuffer_t
struct QVKUniformBuffer_s QVKUniformBuffer_t
DeviceMemory::memory
VkDeviceMemory memory
Definition: device_memory_allocator.h:30
pipelines
static VkPipeline pipelines[BLOOM_NUM_PIPELINES]
Definition: bloom.c:29
maliasmesh_s::tangents
vec4_t * tangents
Definition: vkpt.h:702
push_constants_vblur
static struct bloom_blur_push_constants push_constants_vblur
Definition: bloom.c:43
bsp_mesh_s::world_sky_count
uint32_t world_sky_count
Definition: vkpt.h:354
vertex_buffer
VkBuffer vertex_buffer
Definition: transparency.c:64
SBT_RGEN_INDIRECT_LIGHTING_FIRST
#define SBT_RGEN_INDIRECT_LIGHTING_FIRST
Definition: constants.h:126
transparent_model_primitive_offset
static int transparent_model_primitive_offset
Definition: path_tracer.c:64
device_uniform_buffer
static BufferResource_t device_uniform_buffer
Definition: uniform_buffer.c:25
BINDING_OFFSET_SKY_IRRADIANCE
#define BINDING_OFFSET_SKY_IRRADIANCE
Definition: global_textures.h:133
DeviceMemory::memory_offset
uint64_t memory_offset
Definition: device_memory_allocator.h:31
UnusedResources::buffer_memory
VkDeviceMemory buffer_memory[MAX_RBUFFERS]
Definition: textures.c:40
host_uniform_buffers
static BufferResource_t host_uniform_buffers[MAX_FRAMES_IN_FLIGHT]
Definition: uniform_buffer.c:24
BINDING_OFFSET_PHYSICAL_SKY_IMG
#define BINDING_OFFSET_PHYSICAL_SKY_IMG
Definition: global_textures.h:130
NUM_PROFILER_ENTRIES
@ NUM_PROFILER_ENTRIES
Definition: vkpt.h:463
create_pipelines
static void create_pipelines()
Definition: god_rays.c:294
QVKInstanceBuffer_t
struct QVKInstanceBuffer_s QVKInstanceBuffer_t
BINDING_OFFSET_TERRAIN_DEPTH
#define BINDING_OFFSET_TERRAIN_DEPTH
Definition: global_textures.h:137
AS_FLAG_VIEWER_WEAPON
#define AS_FLAG_VIEWER_WEAPON
Definition: constants.h:111
vkpt_pt_destroy_toplevel
void vkpt_pt_destroy_toplevel(int idx)
Definition: path_tracer.c:815
cvar_pt_reflect_refract
cvar_t * cvar_pt_reflect_refract
cvar_pt_caustics
cvar_t * cvar_pt_caustics
Definition: main.c:52
light_poly_s::off_center
vec3_t off_center
Definition: vkpt.h:317
mem_envmap
static VkDeviceMemory mem_envmap
Definition: textures.c:55
sky_primitive_offset
static int sky_primitive_offset
Definition: path_tracer.c:62
QVK_s::tex_sampler_linear_clamp
VkSampler tex_sampler_linear_clamp
Definition: vkpt.h:257
create_pipeline_layout
static void create_pipeline_layout()
Definition: god_rays.c:251
QVK_s::desc_set_textures_odd
VkDescriptorSet desc_set_textures_odd
Definition: vkpt.h:230
QVK_s::cmd_buffers_compute
cmd_buf_group_t cmd_buffers_compute
Definition: vkpt.h:194
IMG_Find
image_t * IMG_Find(const char *name, imagetype_t type, imageflags_t flags)
Definition: images.c:1122
LIGHT_STATS_BUFFER_BINDING_IDX
#define LIGHT_STATS_BUFFER_BINDING_IDX
Definition: vertex_buffer.h:51
sun_light_s::direction
vec3_t direction
Definition: vkpt.h:415
BINDING_OFFSET_PHYSICAL_SKY
#define BINDING_OFFSET_PHYSICAL_SKY
Definition: global_textures.h:129
MAX_PBR_MATERIALS
#define MAX_PBR_MATERIALS
Definition: material.h:25
fill_index_buffer
static void fill_index_buffer()
Definition: transparency.c:1147
SBT_RMISS_PATH_TRACER
#define SBT_RMISS_PATH_TRACER
Definition: constants.h:128
filter_static_transparent
static int filter_static_transparent(int flags)
Definition: bsp_mesh.c:254
CHECKERBOARD_INTERLEAVE
@ CHECKERBOARD_INTERLEAVE
Definition: asvgf.c:34
qvk
QVK_t qvk
Definition: main.c:377
destroy_device_memory_allocator
void destroy_device_memory_allocator(DeviceMemoryAllocator *allocator)
Definition: device_memory_allocator.c:110
QVK_s::screenshot_image_memory_size
VkDeviceSize screenshot_image_memory_size
Definition: vkpt.h:263
particle_num
unsigned int particle_num
Definition: transparency.c:50
create_blas
static void create_blas()
Definition: transparency.c:1032
QVK_s::buf_light
BufferResource_t buf_light
Definition: vkpt.h:245
QVK_s::gpu_slice_width_prev
uint32_t gpu_slice_width_prev
Definition: vkpt.h:188
bsp_mesh_s::world_transparent_count
uint32_t world_transparent_count
Definition: vkpt.h:351
bsp_model_s::aabb_max
vec3_t aabb_max
Definition: vkpt.h:329
bsp_mesh_s::indices
int * indices
Definition: vkpt.h:360
img_loaders
static const struct @12 img_loaders[IM_MAX]
inject_model_lights
void inject_model_lights(bsp_mesh_t *bsp_mesh, bsp_t *bsp, int num_model_lights, light_poly_t *transformed_model_lights, int model_light_offset, uint32_t *dst_list_offsets, uint32_t *dst_lists)
Definition: vertex_buffer.c:138
c
statCounters_t c
Definition: main.c:30
num_model_lights
static int num_model_lights
Definition: main.c:1266
create_image_views
static void create_image_views()
Definition: god_rays.c:227
create_buffers
static void create_buffers()
Definition: transparency.c:872
GRADIENT_IMAGE
@ GRADIENT_IMAGE
Definition: asvgf.c:25
BINDING_OFFSET_TERRAIN_NORMALS
#define BINDING_OFFSET_TERRAIN_NORMALS
Definition: global_textures.h:136
bsp_mesh_s::light_polys
light_poly_t * light_polys
Definition: vkpt.h:375
TONE_MAPPING_HISTOGRAM
@ TONE_MAPPING_HISTOGRAM
Definition: tone_mapping.c:61
TR_PARTICLE_MAX_NUM
#define TR_PARTICLE_MAX_NUM
Definition: transparency.c:23
vkpt_submit_command_buffer_simple
void vkpt_submit_command_buffer_simple(VkCommandBuffer cmd_buf, VkQueue queue, qboolean all_gpus)
Definition: main.c:3473
ReadbackBuffer
struct ReadbackBuffer ReadbackBuffer
Definition: vertex_buffer.h:161
EMISSIVE_TRANSFORM_BIAS
#define EMISSIVE_TRANSFORM_BIAS
Definition: constants.h:35
sample_disk
static void sample_disk(float *u, float *v)
Definition: shadow_map.c:448
sgets
char * sgets(char *str, int num, char const **input)
Definition: vk_util.c:26
ALL_GPUS
#define ALL_GPUS
Definition: vkpt.h:535
imv_envmap
static VkImageView imv_envmap
Definition: textures.c:59
INSTANCE_MAX_NUM
#define INSTANCE_MAX_NUM
Definition: path_tracer.c:35
cvar_pt_enable_particles
cvar_t * cvar_pt_enable_particles
Definition: path_tracer.c:101
mem_accel_sky
static VkDeviceMemory mem_accel_sky
Definition: path_tracer.c:84
bsp_model_s::num_light_polys
int num_light_polys
Definition: vkpt.h:331
registration_sequence
int registration_sequence
Definition: main.c:34
up
static vec3_t up
Definition: p_view.c:27
vkpt_pt_destroy_static
VkResult vkpt_pt_destroy_static()
Definition: path_tracer.c:345
compute_aabb
void compute_aabb(const float *positions, int numvert, float *aabb_min, float *aabb_max)
Definition: bsp_mesh.c:1111
SHADER_STAGE
#define SHADER_STAGE(_module, _stage)
Definition: vkpt.h:116
accel_transparent
static VkAccelerationStructureNV accel_transparent
Definition: path_tracer.c:58
SBT_RCHIT_OPAQUE
#define SBT_RCHIT_OPAQUE
Definition: constants.h:130
rt_properties
static VkPhysicalDeviceRayTracingPropertiesNV rt_properties
Definition: path_tracer.c:37
UnusedResources::image_memory
DeviceMemory image_memory[MAX_RIMAGES]
Definition: textures.c:37
COMPOSITE
@ COMPOSITE
Definition: bloom.c:24
bsp_mesh_s::world_custom_sky_offset
uint32_t world_custom_sky_offset
Definition: vkpt.h:356
SIZE_SCRATCH_BUFFER
#define SIZE_SCRATCH_BUFFER
Definition: path_tracer.c:33
bsp_mesh_s::num_light_polys
int num_light_polys
Definition: vkpt.h:373
pipeline_smap
VkPipeline pipeline_smap
Definition: shadow_map.c:26
BARRIER_FROM_CLEAR
#define BARRIER_FROM_CLEAR(cmd_buf, img)
Definition: asvgf.c:230
QVK_s::extent_render
VkExtent2D extent_render
Definition: vkpt.h:184
get_transparency_particle_color_buffer_view
VkBufferView get_transparency_particle_color_buffer_view()
Definition: transparency.c:241
BufferResource_s::is_mapped
int is_mapped
Definition: vk_util.h:37
right
static vec3_t right
Definition: p_view.c:27
BARRIER_FROM_COPY_SRC
#define BARRIER_FROM_COPY_SRC(cmd_buf, img)
Definition: bloom.c:281
SunColorBuffer
struct SunColorBuffer SunColorBuffer
Definition: vertex_buffer.h:163
BufferResource_s
Definition: vk_util.h:33
bsp_mesh_s::positions
float * positions
Definition: vkpt.h:359
DeviceMemory::size
uint64_t size
Definition: device_memory_allocator.h:32
QVK_s::tex_sampler_nearest
VkSampler tex_sampler_nearest
Definition: vkpt.h:256
textures_destroy_unused_set
static void textures_destroy_unused_set(uint32_t set_index)
Definition: textures.c:119
rt_descriptor_set
static VkDescriptorSet rt_descriptor_set[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:96
QVK_s::extent_unscaled
VkExtent2D extent_unscaled
Definition: vkpt.h:186
accel_transparent_models
static VkAccelerationStructureNV accel_transparent_models[MAX_FRAMES_IN_FLIGHT]
Definition: path_tracer.c:72
mult_matrix_matrix
void mult_matrix_matrix(float *p, const float *a, const float *b)
Definition: matrix.c:281
QVK_s::buf_light_staging
BufferResource_t buf_light_staging[MAX_FRAMES_IN_FLIGHT]
Definition: vkpt.h:246
accel_sky
static VkAccelerationStructureNV accel_sky
Definition: path_tracer.c:59
cvar_bloom_sigma
cvar_t * cvar_bloom_sigma
Definition: bloom.c:47
diff
static q_noinline int diff(uint32_t A_u32, uint32_t B_u32)
Definition: hq2x.c:55
vkpt_reset_accumulation
void vkpt_reset_accumulation()
Definition: main.c:219
EntityUploadInfo::explosions_vertex_offset
uint32_t explosions_vertex_offset
Definition: vkpt.h:484
EntityUploadInfo::explosions_vertex_num
uint32_t explosions_vertex_num
Definition: vkpt.h:485
TM_NUM_PIPELINES
@ TM_NUM_PIPELINES
Definition: tone_mapping.c:64
EntityUploadInfo::transparent_model_vertex_num
uint32_t transparent_model_vertex_num
Definition: vkpt.h:479
maliasmesh_s::numtris
int numtris
Definition: gl.h:234
particle_color_buffer_view
VkBufferView particle_color_buffer_view
Definition: transparency.c:72
update_beam_blas
static void update_beam_blas(VkCommandBuffer command_buffer)
Definition: transparency.c:747
vkpt_refdef_s::uniform_instance_buffer
QVKInstanceBuffer_t uniform_instance_buffer
Definition: vkpt.h:395
upload_geometry
static void upload_geometry(VkCommandBuffer command_buffer)
Definition: transparency.c:635
LightBuffer
Definition: vertex_buffer.h:106
maliasmesh_s::normals
vec3_t * normals
Definition: vkpt.h:700
rt_descriptor_set_layout
static VkDescriptorSetLayout rt_descriptor_set_layout
Definition: path_tracer.c:97
img_blue_noise
static VkImage img_blue_noise
Definition: textures.c:56
rt_pipeline
static VkPipeline rt_pipeline
Definition: path_tracer.c:99
VertexBuffer
Definition: vertex_buffer.h:96
vkpt_pt_create_dynamic
static VkResult vkpt_pt_create_dynamic(VkCommandBuffer cmd_buf, int idx, VkBuffer vertex_buffer, size_t buffer_offset, int num_vertices)
Definition: path_tracer.c:650
NUM_VKPT_IMAGES
@ NUM_VKPT_IMAGES
Definition: global_textures.h:157
buffer_create
VkResult buffer_create(BufferResource_t *buf, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags mem_properties)
Definition: vk_util.c:57
LIST_SHADER_MODULES
#define LIST_SHADER_MODULES
Definition: vkpt.h:70
TR_BEAM_MAX_NUM
#define TR_BEAM_MAX_NUM
Definition: transparency.c:24
SBT_RGEN_DIRECT_LIGHTING
#define SBT_RGEN_DIRECT_LIGHTING
Definition: constants.h:124
pipeline_layout_composite
static VkPipelineLayout pipeline_layout_composite
Definition: bloom.c:31
bsp_mesh_s::world_idx_count
uint32_t world_idx_count
Definition: vkpt.h:344
TEXNUM_WHITE
#define TEXNUM_WHITE
Definition: draw.c:30
QVK_s::images_views
VkImageView images_views[NUM_VKPT_IMAGES]
Definition: vkpt.h:232
collect_sky_and_lava_ligth_polys
static void collect_sky_and_lava_ligth_polys(bsp_mesh_t *wm, bsp_t *bsp)
Definition: bsp_mesh.c:988
copy_light
static void copy_light(const light_poly_t *light, float *vblight, const float *sky_radiance)
Definition: vertex_buffer.c:215
Q_memccpy
void * Q_memccpy(void *dst, const void *src, int c, size_t size)
Definition: shared.c:895
cvar_pt_enable_sprites
cvar_t * cvar_pt_enable_sprites
Definition: path_tracer.c:103
bsp_mesh_s::world_sky_offset
uint32_t world_sky_offset
Definition: vkpt.h:353
EntityUploadInfo::viewer_weapon_vertex_num
uint32_t viewer_weapon_vertex_num
Definition: vkpt.h:483
SBT_RGEN_REFLECT_REFRACT2
#define SBT_RGEN_REFLECT_REFRACT2
Definition: constants.h:123
UnusedResources::images
VkImage images[MAX_RIMAGES]
Definition: textures.c:35
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
bsp_mesh_s::world_aabb
aabb_t world_aabb
Definition: vkpt.h:348
cvar_bloom_enable
cvar_t * cvar_bloom_enable
Definition: bloom.c:45
color
static vec4_t color
Definition: mesh.c:33
IMG_ForHandle
image_t * IMG_ForHandle(qhandle_t h)
Definition: images.c:1156
vkpt_tone_mapping_reset
VkResult vkpt_tone_mapping_reset(VkCommandBuffer cmd_buf)
Definition: tone_mapping.c:176
ATTACH_LABEL_VARIABLE
#define ATTACH_LABEL_VARIABLE(a, type)
Definition: vk_util.h:137
accel_top_match_info_s::instanceCount
uint32_t instanceCount
Definition: path_tracer.c:51
query_pool_results
static uint64_t query_pool_results[NUM_PROFILER_QUERIES_PER_FRAME+1]
Definition: profiler.c:23
vkpt_begin_command_buffer
VkCommandBuffer vkpt_begin_command_buffer(cmd_buf_group_t *group)
Definition: main.c:3301
MAX_LIGHT_STYLES
#define MAX_LIGHT_STYLES
Definition: constants.h:105
create_readback_image
static VkResult create_readback_image(VkImage *image, VkDeviceMemory *memory, VkDeviceSize *memory_size, VkFormat format, uint32_t width, uint32_t height)
Definition: textures.c:1392
drawStatic_t::scale
float scale
Definition: gl.h:404
vkpt_freecam_reset
void vkpt_freecam_reset()
Definition: freecam.c:55
QVK_s::buf_light_stats
BufferResource_t buf_light_stats[NUM_LIGHT_STATS_BUFFERS]
Definition: vkpt.h:247
load_blue_noise
static VkResult load_blue_noise()
Definition: textures.c:308
QVK_s::desc_set_layout_textures
VkDescriptorSetLayout desc_set_layout_textures
Definition: vkpt.h:228
floatToHalf
static uint16_t floatToHalf(float value)
Definition: vertex_buffer.c:265
Q_concat
size_t Q_concat(char *dest, size_t size,...)
Definition: shared.c:758
bsp_mesh_s::world_transparent_offset
uint32_t world_transparent_offset
Definition: vkpt.h:350
QVK_s::desc_set_layout_ubo
VkDescriptorSetLayout desc_set_layout_ubo
Definition: vkpt.h:225
RAY_GEN_ACCEL_STRUCTURE_BINDING_IDX
#define RAY_GEN_ACCEL_STRUCTURE_BINDING_IDX
Definition: path_tracer.c:28
imv_smap_depth
static VkImageView imv_smap_depth
Definition: shadow_map.c:30
QVK_s::buf_readback_staging
BufferResource_t buf_readback_staging[MAX_FRAMES_IN_FLIGHT]
Definition: vkpt.h:250
BINDING_OFFSET_ENVMAP
#define BINDING_OFFSET_ENVMAP
Definition: global_textures.h:128
vkpt_pt_destroy_dynamic
VkResult vkpt_pt_destroy_dynamic(int idx)
Definition: path_tracer.c:383
aabb_s::maxs
vec3_t maxs
Definition: vkpt.h:340
qvk
QVK_t qvk
Definition: main.c:377
pbr_material_s::rough_override
float rough_override
Definition: material.h:39
transparent_primitive_offset
static int transparent_primitive_offset
Definition: path_tracer.c:61
tex_images
static VkImage tex_images[MAX_RIMAGES]
Definition: textures.c:53
RAY_GEN_SPRITE_INFO_BUFFER_BINDING_IDX
#define RAY_GEN_SPRITE_INFO_BUFFER_BINDING_IDX
Definition: path_tracer.c:31
MATERIAL_INDEX_MASK
#define MATERIAL_INDEX_MASK
Definition: constants.h:86
buffer_map
void * buffer_map(BufferResource_t *buf)
Definition: vk_util.c:147
pipeline_layout_tone_mapping_apply
static VkPipelineLayout pipeline_layout_tone_mapping_apply
Definition: tone_mapping.c:70
SunColorBuffer
Definition: vertex_buffer.h:144
render_pass_smap
VkRenderPass render_pass_smap
Definition: shadow_map.c:25
get_transparency_particle_blas
VkAccelerationStructureNV get_transparency_particle_blas()
Definition: transparency.c:226
int
CONST PIXELFORMATDESCRIPTOR int
Definition: wgl.c:26
QVK_s::surf_format
VkSurfaceFormatKHR surf_format
Definition: vkpt.h:181
AS_FLAG_TRANSPARENT
#define AS_FLAG_TRANSPARENT
Definition: constants.h:108
LIST_IMAGES_A_B
#define LIST_IMAGES_A_B
Definition: global_textures.h:81
BufferResource_s::size
size_t size
Definition: vk_util.h:36
BARRIER_COMPUTE
#define BARRIER_COMPUTE(cmd_buf, img)
Definition: tone_mapping.c:218
bytedirs
const vec3_t bytedirs[NUMVERTEXNORMALS]
Definition: math.c:80
get_image_dimensions
static void get_image_dimensions(imageformat_t fmt, image_t *image)
Definition: images.c:851
load_cameras
static void load_cameras(bsp_mesh_t *wm, const char *map_name)
Definition: bsp_mesh.c:1300
decode_linear
static float decode_linear(byte pix)
Definition: textures.c:519
query_pool
static VkQueryPool query_pool
Definition: profiler.c:22
QVK_s::swap_chain_image_views
VkImageView swap_chain_image_views[MAX_SWAPCHAIN_IMAGES]
Definition: vkpt.h:191
BARRIER_TO_CLEAR
#define BARRIER_TO_CLEAR(cmd_buf, img)
Definition: asvgf.c:211
tex_image_views
static VkImageView tex_image_views[MAX_RIMAGES]
Definition: textures.c:54
ATROUS_LF
@ ATROUS_LF
Definition: asvgf.c:28
BINDING_OFFSET_TERRAIN_SHADOWMAP
#define BINDING_OFFSET_TERRAIN_SHADOWMAP
Definition: global_textures.h:138
DeviceMemory::memory_type
uint32_t memory_type
Definition: device_memory_allocator.h:34
desc_pool_sbo
static VkDescriptorPool desc_pool_sbo
Definition: draw.c:58
maliasframe_s
Definition: gl.h:225
vkpt_submit_command_buffer
void vkpt_submit_command_buffer(VkCommandBuffer cmd_buf, VkQueue queue, uint32_t execute_device_mask, int wait_semaphore_count, VkSemaphore *wait_semaphores, VkPipelineStageFlags *wait_stages, uint32_t *wait_device_indices, int signal_semaphore_count, VkSemaphore *signal_semaphores, uint32_t *signal_device_indices, VkFence fence)
Definition: main.c:3411
TR_POSITION_SIZE
#define TR_POSITION_SIZE
Definition: transparency.c:28
SEED_RNG
@ SEED_RNG
Definition: asvgf.c:23
DIV64
#define DIV64
Definition: draw.c:697
destroy_tex_images
static void destroy_tex_images()
Definition: textures.c:1024
create_invalid_texture
void create_invalid_texture()
Definition: textures.c:734
EntityUploadInfo::viewer_model_vertex_offset
uint32_t viewer_model_vertex_offset
Definition: vkpt.h:480
vkpt_light_stats_destroy
VkResult vkpt_light_stats_destroy()
Definition: vertex_buffer.c:748
bsp_model_s::idx_offset
uint32_t idx_offset
Definition: vkpt.h:325
compute_push_constants
static void compute_push_constants()
Definition: bloom.c:56
SBT_RAHIT_EXPLOSION
#define SBT_RAHIT_EXPLOSION
Definition: constants.h:133
QVK_s::extent_render_prev
VkExtent2D extent_render_prev
Definition: vkpt.h:185
vkpt_refdef_s::uniform_buffer
QVKUniformBuffer_t uniform_buffer
Definition: vkpt.h:394
DESTROY_LATENCY
#define DESTROY_LATENCY
Definition: textures.c:44
vkpt_pt_destroy_transparent_models
VkResult vkpt_pt_destroy_transparent_models(int idx)
Definition: path_tracer.c:397
append_blas
static void append_blas(QvkGeometryInstance_t *instances, int *num_instances, VkAccelerationStructureNV blas, int instance_id, int mask, int flags, int sbt_offset)
Definition: path_tracer.c:829
mem_smap
static VkDeviceMemory mem_smap
Definition: shadow_map.c:33
light_poly_s::cluster
int cluster
Definition: vkpt.h:320
VectorNormalize
vec_t VectorNormalize(vec3_t v)
Definition: shared.c:55
FS_NormalizePath
size_t FS_NormalizePath(char *out, const char *in)
Definition: files.c:331
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
AS_FLAG_EXPLOSIONS
#define AS_FLAG_EXPLOSIONS
Definition: constants.h:112
QVK_s::buf_vertex_staging
BufferResource_t buf_vertex_staging
Definition: vkpt.h:244
mem_accel_custom_sky
static VkDeviceMemory mem_accel_custom_sky
Definition: path_tracer.c:85
EntityUploadInfo::transparent_model_vertex_offset
uint32_t transparent_model_vertex_offset
Definition: vkpt.h:478
maliasmesh_s::numskins
int numskins
Definition: gl.h:240
SBT_RGEN_INDIRECT_LIGHTING_SECOND
#define SBT_RGEN_INDIRECT_LIGHTING_SECOND
Definition: constants.h:127
MAT_FindPBRMaterial
pbr_material_t * MAT_FindPBRMaterial(char const *name)
Definition: material.c:465
QVK_s::queue_graphics
VkQueue queue_graphics
Definition: vkpt.h:173
QVK_s::device_count
int device_count
Definition: vkpt.h:167
bsp_mesh_s::world_custom_sky_count
uint32_t world_custom_sky_count
Definition: vkpt.h:357
light_poly_s::positions
float positions[9]
Definition: vkpt.h:316
ASVGF_NUM_PIPELINES
@ ASVGF_NUM_PIPELINES
Definition: asvgf.c:36
scratch_buf_ptr
static size_t scratch_buf_ptr
Definition: path_tracer.c:55
vkpt_profiler_query
VkResult vkpt_profiler_query(VkCommandBuffer cmd_buf, int idx, VKPTProfilerAction action)
Definition: profiler.c:49
BINDING_OFFSET_SKY_TRANSMITTANCE
#define BINDING_OFFSET_SKY_TRANSMITTANCE
Definition: global_textures.h:131
is_model_transparent
static qboolean is_model_transparent(bsp_mesh_t *wm, bsp_model_t *model)
Definition: bsp_mesh.c:1062
BARRIER_TO_COPY_DEST
#define BARRIER_TO_COPY_DEST(cmd_buf, img)
Definition: bloom.c:224
desc_set_sbo
static VkDescriptorSet desc_set_sbo[MAX_FRAMES_IN_FLIGHT]
Definition: draw.c:59
QVK_s::desc_set_layout_vertex_buffer
VkDescriptorSetLayout desc_set_layout_vertex_buffer
Definition: vkpt.h:240
bsp_model_s::transparent
qboolean transparent
Definition: vkpt.h:335
BufferResource_s::memory
VkDeviceMemory memory
Definition: vk_util.h:35
allocate_and_bind_memory_to_blas
static void allocate_and_bind_memory_to_blas()
Definition: transparency.c:1075
GRAD_DWN
#define GRAD_DWN
Definition: constants.h:22
CL_PLAYER_MODEL_THIRD_PERSON
#define CL_PLAYER_MODEL_THIRD_PERSON
Definition: client.h:556
EntityUploadInfo::viewer_weapon_vertex_offset
uint32_t viewer_weapon_vertex_offset
Definition: vkpt.h:482
r_models
model_t r_models[MAX_RMODELS]
Definition: models.c:39