Skip to content

Commit

Permalink
Added support for dynamic resolution scaling.
Browse files Browse the repository at this point in the history
(Squashed from a feature branch)
  • Loading branch information
apanteleev committed Oct 30, 2019
1 parent b1a18d1 commit 8c38252
Show file tree
Hide file tree
Showing 26 changed files with 397 additions and 144 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.2.0

**New Features:**
* Added support for dynamic resolution scaling that adjusts rendering resolution to meet an FPS target.
* Added support for multiple reflection or refraction bounces.
* Added light coloring by tinted glass.
* Added support for security camera views on some monitors in the game.
Expand Down
1 change: 1 addition & 0 deletions inc/refresh/refresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typedef struct ref_feedback_s {
int viewcluster;
int lookatcluster;
int num_light_polys;
int resolution_scale;

char view_material[MAX_QPATH];
char view_material_override[MAX_QPATH];
Expand Down
18 changes: 17 additions & 1 deletion src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ static size_t CL_DemoPos_m(char *buffer, size_t size)
"%d:%02d.%d", min, sec, framenum);
}

size_t CL_Fps_m(char *buffer, size_t size)
static size_t CL_Fps_m(char *buffer, size_t size)
{
return Q_scnprintf(buffer, size, "%i", C_FPS);
}
Expand Down Expand Up @@ -2364,6 +2364,21 @@ static size_t CL_HdrColor_m(char *buffer, size_t size)
return Q_scnprintf(buffer, size, "(%.5f, %.5f, %.5f)", color[0], color[1], color[2]);
}

static size_t CL_ResolutionScale_m(char *buffer, size_t size)
{
return Q_scnprintf(buffer, size, "%d", cl.refdef.feedback.resolution_scale);
}

int CL_GetFps()
{
return C_FPS;
}

int CL_GetResolutionScale()
{
return cl.refdef.feedback.resolution_scale;
}

/*
===============
CL_WriteConfig
Expand Down Expand Up @@ -2841,6 +2856,7 @@ static void CL_InitLocal(void)
Cmd_AddMacro("cl_viewpos", CL_ViewPos_m);
Cmd_AddMacro("cl_viewdir", CL_ViewDir_m);
Cmd_AddMacro("cl_hdr_color", CL_HdrColor_m);
Cmd_AddMacro("cl_resolution_scale", CL_ResolutionScale_m);
}

/*
Expand Down
20 changes: 13 additions & 7 deletions src/client/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,18 +848,22 @@ static void SCR_DrawObjects(void)
}
}

extern size_t CL_Fps_m(char *buffer, size_t size);
extern int CL_GetFps();
extern int CL_GetResolutionScale();

static void SCR_DrawFPS(void)
{
if (scr_fps->integer == 0)
return;

int fps = CL_GetFps();
int scale = CL_GetResolutionScale();

char buffer[MAX_QPATH];
CL_Fps_m(buffer, sizeof(buffer));

int len = strlen(buffer);
strncat(buffer, " FPS", max(0, sizeof(buffer) - len - 1));
if (scr_fps->integer == 2 && vid_rtx->integer)
Q_snprintf(buffer, MAX_QPATH, "%d FPS at %3d%%", fps, scale);
else
Q_snprintf(buffer, MAX_QPATH, "%d FPS", fps);

int x = scr.hud_width - 2;
int y = 1;
Expand Down Expand Up @@ -1093,7 +1097,8 @@ Keybinding command
*/
static void SCR_SizeUp_f(void)
{
Cvar_SetInteger(scr_viewsize, scr_viewsize->integer + 10, FROM_CONSOLE);
int delta = (scr_viewsize->integer < 100) ? 5 : 10;
Cvar_SetInteger(scr_viewsize, scr_viewsize->integer + delta, FROM_CONSOLE);
}

/*
Expand All @@ -1105,7 +1110,8 @@ Keybinding command
*/
static void SCR_SizeDown_f(void)
{
Cvar_SetInteger(scr_viewsize, scr_viewsize->integer - 10, FROM_CONSOLE);
int delta = (scr_viewsize->integer <= 100) ? 5 : 10;
Cvar_SetInteger(scr_viewsize, scr_viewsize->integer - delta, FROM_CONSOLE);
}

/*
Expand Down
40 changes: 25 additions & 15 deletions src/refresh/vkpt/asvgf.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ vkpt_asvgf_create_gradient_samples(VkCommandBuffer cmd_buf, uint32_t frame_num,
pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width + 15) / 16,
(qvk.extent.height + 15) / 16,
(qvk.extent_render.height + 15) / 16,
1);
}

Expand All @@ -308,8 +308,8 @@ vkpt_asvgf_create_gradient_samples(VkCommandBuffer cmd_buf, uint32_t frame_num,
vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
pipeline_layout_general, 0, LENGTH(desc_sets), desc_sets, 0, 0);
vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
(qvk.extent.height / GRAD_DWN + 15) / 16,
(qvk.gpu_slice_width_prev / GRAD_DWN + 15) / 16,
(qvk.extent_render_prev.height / GRAD_DWN + 15) / 16,
1);

BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_RNG_SEED_A + (qvk.frame_counter & 1)]);
Expand Down Expand Up @@ -342,7 +342,7 @@ vkpt_asvgf_filter(VkCommandBuffer cmd_buf, qboolean enable_lf)
pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
(qvk.extent.height / GRAD_DWN + 15) / 16,
(qvk.extent_render.height / GRAD_DWN + 15) / 16,
1);

// XXX BARRIERS!!!
Expand All @@ -367,7 +367,7 @@ vkpt_asvgf_filter(VkCommandBuffer cmd_buf, qboolean enable_lf)

vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
(qvk.extent.height / GRAD_DWN + 15) / 16,
(qvk.extent_render.height / GRAD_DWN + 15) / 16,
1);
BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_LF_PING + !(i & 1)]);
BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_GRAD_HF_SPEC_PING + !(i & 1)]);
Expand All @@ -383,7 +383,7 @@ vkpt_asvgf_filter(VkCommandBuffer cmd_buf, qboolean enable_lf)
pipeline_layout_atrous, 0, LENGTH(desc_sets), desc_sets, 0, 0);
vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width + 14) / 15,
(qvk.extent.height + 14) / 15,
(qvk.extent_render.height + 14) / 15,
1);


Expand Down Expand Up @@ -419,7 +419,7 @@ vkpt_asvgf_filter(VkCommandBuffer cmd_buf, qboolean enable_lf)

vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width / GRAD_DWN + 15) / 16,
(qvk.extent.height / GRAD_DWN + 15) / 16,
(qvk.extent_render.height / GRAD_DWN + 15) / 16,
1);

if (i == num_atrous_iterations - 1)
Expand All @@ -434,7 +434,7 @@ vkpt_asvgf_filter(VkCommandBuffer cmd_buf, qboolean enable_lf)
vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[specialization]);
vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width + 15) / 16,
(qvk.extent.height + 15) / 16,
(qvk.extent_render.height + 15) / 16,
1);

BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_ATROUS_PING_LF_SH]);
Expand Down Expand Up @@ -478,7 +478,7 @@ vkpt_compositing(VkCommandBuffer cmd_buf)

vkCmdDispatch(cmd_buf,
(qvk.gpu_slice_width + 15) / 16,
(qvk.extent.height + 15) / 16,
(qvk.extent_render.height + 15) / 16,
1);

END_PERF_MARKER(cmd_buf, PROFILER_COMPOSITING);
Expand All @@ -503,8 +503,8 @@ vkpt_interleave(VkCommandBuffer cmd_buf)

// create full interleaved motion and color buffers on GPU 0
VkOffset2D offset_left = { 0, 0 };
VkOffset2D offset_right = { qvk.extent.width / 2, 0 };
VkExtent2D extent = { qvk.extent.width / 2, qvk.extent.height };
VkOffset2D offset_right = { qvk.extent_render.width / 2, 0 };
VkExtent2D extent = { qvk.extent_render.width / 2, qvk.extent_render.height };

vkpt_mgpu_image_copy(cmd_buf,
VKPT_IMG_PT_MOTION,
Expand Down Expand Up @@ -538,9 +538,10 @@ vkpt_interleave(VkCommandBuffer cmd_buf)

set_current_gpu(cmd_buf, 0);

// dispatch using the image dimensions, not render dimensions - to clear the unused area with black color
vkCmdDispatch(cmd_buf,
(qvk.extent.width + 15) / 16,
(qvk.extent.height + 15) / 16,
(qvk.extent_screen_images.width + 15) / 16,
(qvk.extent_screen_images.height + 15) / 16,
1);

END_PERF_MARKER(cmd_buf, PROFILER_INTERLEAVE);
Expand All @@ -564,9 +565,18 @@ VkResult vkpt_taa(VkCommandBuffer cmd_buf)
vkCmdBindPipeline(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_asvgf[TAA]);
vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
pipeline_layout_taa, 0, LENGTH(desc_sets), desc_sets, 0, 0);

VkExtent2D dispatch_size = qvk.extent_render;

if(dispatch_size.width < qvk.extent_screen_images.width)
dispatch_size.width += 8;

if (dispatch_size.height < qvk.extent_screen_images.height)
dispatch_size.height += 8;

vkCmdDispatch(cmd_buf,
(qvk.extent.width + 15) / 16,
(qvk.extent.height + 15) / 16,
(dispatch_size.width + 15) / 16,
(dispatch_size.height + 15) / 16,
1);
BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_TAA_A]);
BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_ASVGF_TAA_B]);
Expand Down
36 changes: 18 additions & 18 deletions src/refresh/vkpt/bloom.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ static float under_water_animation;

static void compute_push_constants()
{
float sigma_pixels = bloom_sigma;
float sigma_pixels = bloom_sigma * qvk.extent_render.height;

float effective_sigma = sigma_pixels * 0.25f;
effective_sigma = min(effective_sigma, 100.f);
effective_sigma = max(effective_sigma, 1.f);

push_constants_hblur.pixstep_x = 1.f / (IMG_WIDTH / 4.0);
push_constants_hblur.pixstep_x = 1.f;
push_constants_hblur.pixstep_y = 0.f;
push_constants_hblur.argument_scale = -1.f / (2.0 * effective_sigma * effective_sigma);
push_constants_hblur.normalization_scale = 1.f / (sqrtf(2 * M_PI) * effective_sigma);
Expand All @@ -70,7 +70,7 @@ static void compute_push_constants()

push_constants_vblur = push_constants_hblur;
push_constants_vblur.pixstep_x = 0.f;
push_constants_vblur.pixstep_y = 1.f / (IMG_HEIGHT / 4.0);
push_constants_vblur.pixstep_y = 1.f;
push_constants_vblur.pass = 1;
}
void vkpt_bloom_reset()
Expand Down Expand Up @@ -111,7 +111,7 @@ void vkpt_bloom_update(QVKUniformBuffer_t * ubo, float frame_time, qboolean unde
float phase = max(0.f, min(1.f, (float)(current_ms - menu_start_ms) / 150.f));
phase = powf(phase, 0.25f);

bloom_sigma = phase * 30.f;
bloom_sigma = phase * 0.03f;

ubo->bloom_intensity = 1.f;
}
Expand All @@ -128,9 +128,9 @@ vkpt_bloom_initialize()
{
cvar_bloom_enable = Cvar_Get("bloom_enable", "1", 0);
cvar_bloom_debug = Cvar_Get("bloom_debug", "0", 0);
cvar_bloom_sigma = Cvar_Get("bloom_sigma", "40", 0);
cvar_bloom_sigma = Cvar_Get("bloom_sigma", "0.037", 0); // relative to screen height
cvar_bloom_intensity = Cvar_Get("bloom_intensity", "0.002", 0);
cvar_bloom_sigma_water = Cvar_Get("bloom_sigma_water", "40", 0);
cvar_bloom_sigma_water = Cvar_Get("bloom_sigma_water", "0.037", 0);
cvar_bloom_intensity_water = Cvar_Get("bloom_intensity_water", "0.2", 0);

VkDescriptorSetLayout desc_set_layouts[] = {
Expand Down Expand Up @@ -320,20 +320,20 @@ vkpt_bloom_record_cmd_buffer(VkCommandBuffer cmd_buf)
};

VkOffset3D offset_LR_mip_0 = {
.x = IMG_WIDTH,
.y = IMG_HEIGHT,
.x = qvk.extent_screen_images.width,
.y = qvk.extent_screen_images.height,
.z = 1
};

VkOffset3D offset_LR_mip_1 = {
.x = IMG_WIDTH / 2,
.y = IMG_HEIGHT / 2,
.x = qvk.extent_screen_images.width / 2,
.y = qvk.extent_screen_images.height / 2,
.z = 1
};

VkOffset3D offset_LR_mip_2 = {
.x = IMG_WIDTH / 4,
.y = IMG_HEIGHT / 4,
.x = qvk.extent_screen_images.width / 4,
.y = qvk.extent_screen_images.height / 4,
.z = 1
};

Expand Down Expand Up @@ -395,8 +395,8 @@ vkpt_bloom_record_cmd_buffer(VkCommandBuffer cmd_buf)
vkCmdPushConstants(cmd_buf, pipeline_layout_blur, VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(push_constants_hblur), &push_constants_hblur);
vkCmdDispatch(cmd_buf,
(qvk.extent.width / 4 + 15) / 16,
(qvk.extent.height / 4 + 15) / 16,
(qvk.extent_render.width / 4 + 15) / 16,
(qvk.extent_render.height / 4 + 15) / 16,
1);

BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_HBLUR]);
Expand All @@ -405,8 +405,8 @@ vkpt_bloom_record_cmd_buffer(VkCommandBuffer cmd_buf)
vkCmdPushConstants(cmd_buf, pipeline_layout_blur, VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(push_constants_vblur), &push_constants_vblur);
vkCmdDispatch(cmd_buf,
(qvk.extent.width / 4 + 15) / 16,
(qvk.extent.height / 4 + 15) / 16,
(qvk.extent_render.width / 4 + 15) / 16,
(qvk.extent_render.height / 4 + 15) / 16,
1);

BARRIER_COMPUTE(cmd_buf, qvk.images[VKPT_IMG_BLOOM_VBLUR]);
Expand Down Expand Up @@ -476,8 +476,8 @@ vkpt_bloom_record_cmd_buffer(VkCommandBuffer cmd_buf)
vkCmdBindDescriptorSets(cmd_buf, VK_PIPELINE_BIND_POINT_COMPUTE,
pipeline_layout_composite, 0, LENGTH(desc_sets), desc_sets, 0, 0);
vkCmdDispatch(cmd_buf,
(qvk.extent.width + 15) / 16,
(qvk.extent.height + 15) / 16,
(qvk.extent_render.width + 15) / 16,
(qvk.extent_render.height + 15) / 16,
1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/refresh/vkpt/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ vkpt_final_blit_simple(VkCommandBuffer cmd_buf)
);

VkOffset3D blit_size = {
.x = qvk.extent.width,.y = qvk.extent.height,.z = 1
.x = qvk.extent_render.width,.y = qvk.extent_render.height,.z = 1
};
VkOffset3D blit_size_unscaled = {
.x = qvk.extent_unscaled.width,.y = qvk.extent_unscaled.height,.z = 1
Expand Down
8 changes: 4 additions & 4 deletions src/refresh/vkpt/god_rays.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void vkpt_record_god_rays_trace_command_buffer(VkCommandBuffer command_buffer, i
vkCmdPushConstants(command_buffer, god_rays.pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(int), &pass);

uint32_t group_size = THREAD_GROUP_SIZE;
uint32_t group_num_x = (qvk.extent.width / (2 * qvk.device_count) + (group_size - 1)) / group_size;
uint32_t group_num_y = (qvk.extent.height / 2 + (group_size - 1)) / group_size;
uint32_t group_num_x = (qvk.extent_render.width / (2 * qvk.device_count) + (group_size - 1)) / group_size;
uint32_t group_num_y = (qvk.extent_render.height / 2 + (group_size - 1)) / group_size;

vkCmdDispatch(command_buffer, group_num_x, group_num_y, 1);

Expand Down Expand Up @@ -192,8 +192,8 @@ void vkpt_record_god_rays_filter_command_buffer(VkCommandBuffer command_buffer)
vkCmdPushConstants(command_buffer, god_rays.pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(int), &pass);

uint32_t group_size = FILTER_THREAD_GROUP_SIZE;
uint32_t group_num_x = (qvk.extent.width / qvk.device_count + (group_size - 1)) / group_size;
uint32_t group_num_y = (qvk.extent.height + (group_size - 1)) / group_size;
uint32_t group_num_x = (qvk.extent_render.width / qvk.device_count + (group_size - 1)) / group_size;
uint32_t group_num_y = (qvk.extent_render.height + (group_size - 1)) / group_size;

vkCmdDispatch(command_buffer, group_num_x, group_num_y, 1);

Expand Down
Loading

0 comments on commit 8c38252

Please sign in to comment.