Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into LIGHT-surfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
res2k committed May 19, 2021
2 parents b620dea + 07fb453 commit 12f1a44
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 127 deletions.
3 changes: 0 additions & 3 deletions inc/client/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ void VID_UpdateGamma(const byte *table);
void *VID_GetCoreAddr(const char *sym);
void *VID_GetProcAddr(const char *sym);

qboolean VID_VideoSync(void);
void VID_VideoWait(void);

void VID_BeginFrame(void);
void VID_EndFrame(void);

Expand Down
3 changes: 1 addition & 2 deletions inc/refresh/refresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ typedef struct refdef_s {
typedef enum {
QVF_ACCELERATED = (1 << 0),
QVF_GAMMARAMP = (1 << 1),
QVF_FULLSCREEN = (1 << 2),
QVF_VIDEOSYNC = (1 << 3)
QVF_FULLSCREEN = (1 << 2)
} vidFlags_t;

typedef struct {
Expand Down
160 changes: 84 additions & 76 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cvar_t *cl_timeout;
cvar_t *cl_predict;
cvar_t *cl_gun;
cvar_t *cl_gunalpha;
cvar_t *cl_warn_on_fps_rounding;
cvar_t *cl_maxfps;
cvar_t *cl_async;
cvar_t *r_maxfps;
Expand Down Expand Up @@ -2625,11 +2626,51 @@ static void cl_updaterate_changed(cvar_t *self)
}
#endif

static inline int fps_to_msec(int fps)
{
#if 0
return (1000 + fps / 2) / fps;
#else
return 1000 / fps;
#endif
}

static void warn_on_fps_rounding(cvar_t *cvar)
{
static qboolean warned = qfalse;
int msec, real_maxfps;

if (cvar->integer <= 0 || cl_warn_on_fps_rounding->integer <= 0)
return;

msec = fps_to_msec(cvar->integer);
if (!msec)
return;

real_maxfps = 1000 / msec;
if (cvar->integer == real_maxfps)
return;

Com_WPrintf("%s value `%d' is inexact, using `%d' instead.\n",
cvar->name, cvar->integer, real_maxfps);
if (!warned) {
Com_Printf("(Set `%s' to `0' to disable this warning.)\n",
cl_warn_on_fps_rounding->name);
warned = qtrue;
}
}

static void cl_sync_changed(cvar_t *self)
{
CL_UpdateFrameTimes();
}

static void cl_maxfps_changed(cvar_t *self)
{
CL_UpdateFrameTimes();
warn_on_fps_rounding(self);
}

// allow downloads to be permanently disabled as a
// protection measure from malicious (or just stupid) servers
// that force downloads by stuffing commands
Expand Down Expand Up @@ -2742,12 +2783,13 @@ static void CL_InitLocal(void)
cl_predict = Cvar_Get("cl_predict", "1", 0);
cl_predict->changed = cl_predict_changed;
cl_kickangles = Cvar_Get("cl_kickangles", "1", CVAR_CHEAT);
cl_maxfps = Cvar_Get("cl_maxfps", "60", 0);
cl_maxfps->changed = cl_sync_changed;
cl_warn_on_fps_rounding = Cvar_Get("cl_warn_on_fps_rounding", "1", 0);
cl_maxfps = Cvar_Get("cl_maxfps", "62", 0);
cl_maxfps->changed = cl_maxfps_changed;
cl_async = Cvar_Get("cl_async", "1", 0);
cl_async->changed = cl_sync_changed;
r_maxfps = Cvar_Get("r_maxfps", "0", 0);
r_maxfps->changed = cl_sync_changed;
r_maxfps->changed = cl_maxfps_changed;
cl_autopause = Cvar_Get("cl_autopause", "1", 0);
cl_rollhack = Cvar_Get("cl_rollhack", "1", 0);
cl_noglow = Cvar_Get("cl_noglow", "0", 0);
Expand All @@ -2757,6 +2799,8 @@ static void CL_InitLocal(void)
com_timedemo->changed = cl_sync_changed;

CL_UpdateFrameTimes();
warn_on_fps_rounding(cl_maxfps);
warn_on_fps_rounding(r_maxfps);

#ifdef _DEBUG
cl_shownet = Cvar_Get("cl_shownet", "0", 0);
Expand Down Expand Up @@ -3090,25 +3134,19 @@ void CL_CheckForPause(void)
}

typedef enum {
SYNC_FULL,
SYNC_TIMEDEMO,
SYNC_MAXFPS,
SYNC_SLEEP_10,
SYNC_SLEEP_60,
SYNC_SLEEP_VIDEO,
ASYNC_VIDEO,
ASYNC_MAXFPS,
ASYNC_FULL
} sync_mode_t;

#ifdef _DEBUG
static const char *const sync_names[] = {
"SYNC_FULL",
"SYNC_TIMEDEMO",
"SYNC_MAXFPS",
"SYNC_SLEEP_10",
"SYNC_SLEEP_60",
"SYNC_SLEEP_VIDEO",
"ASYNC_VIDEO",
"ASYNC_MAXFPS",
"ASYNC_FULL"
};
#endif
Expand All @@ -3117,13 +3155,17 @@ static int ref_msec, phys_msec, main_msec;
static int ref_extra, phys_extra, main_extra;
static sync_mode_t sync_mode;

static inline int fps_to_msec(int fps)
#define MIN_PHYS_HZ 10
#define MAX_PHYS_HZ 125
#define MIN_REF_HZ MIN_PHYS_HZ
#define MAX_REF_HZ 1000

static int fps_to_clamped_msec(cvar_t *cvar, int min, int max)
{
#if 0
return (1000 + fps / 2) / fps;
#else
return 1000 / fps;
#endif
if (cvar->integer == 0)
return fps_to_msec(max);
else
return fps_to_msec(Cvar_ClampInteger(cvar, min, max));
}

/*
Expand All @@ -3139,60 +3181,33 @@ void CL_UpdateFrameTimes(void)
return; // not yet fully initialized
}

// check if video driver supports syncing to vertical retrace
if (cl_async->integer > 1 && !(r_config.flags & QVF_VIDEOSYNC)) {
Cvar_Reset(cl_async);
}
phys_msec = ref_msec = main_msec = 0;
ref_extra = phys_extra = main_extra = 0;

if (com_timedemo->integer) {
// timedemo just runs at full speed
ref_msec = phys_msec = main_msec = 0;
sync_mode = SYNC_FULL;
sync_mode = SYNC_TIMEDEMO;
} else if (cls.active == ACT_MINIMIZED) {
// run at 10 fps if minimized
ref_msec = phys_msec = 0;
main_msec = fps_to_msec(10);
sync_mode = SYNC_SLEEP_10;
} else if (cls.active == ACT_RESTORED || cls.state != ca_active) {
// run at 60 fps if not active
ref_msec = phys_msec = 0;
if (cl_async->integer > 1) {
main_msec = 0;
sync_mode = SYNC_SLEEP_VIDEO;
} else {
main_msec = fps_to_msec(60);
sync_mode = SYNC_SLEEP_60;
}
main_msec = fps_to_msec(60);
sync_mode = SYNC_SLEEP_60;
} else if (cl_async->integer > 0) {
// run physics and refresh separately
phys_msec = fps_to_msec(Cvar_ClampInteger(cl_maxfps, 10, 120));
if (cl_async->integer > 1) {
ref_msec = 0;
sync_mode = ASYNC_VIDEO;
} else if (r_maxfps->integer) {
ref_msec = fps_to_msec(Cvar_ClampInteger(r_maxfps, 10, 1000));
sync_mode = ASYNC_MAXFPS;
} else {
ref_msec = 1;
sync_mode = ASYNC_FULL;
}
main_msec = 0;
phys_msec = fps_to_clamped_msec(cl_maxfps, MIN_PHYS_HZ, MAX_PHYS_HZ);
ref_msec = fps_to_clamped_msec(r_maxfps, MIN_REF_HZ, MAX_REF_HZ);
sync_mode = ASYNC_FULL;
} else {
// everything ticks in sync with refresh
phys_msec = ref_msec = 0;
if (cl_maxfps->integer) {
main_msec = fps_to_msec(Cvar_ClampInteger(cl_maxfps, 10, 1000));
sync_mode = SYNC_MAXFPS;
} else {
main_msec = 1;
sync_mode = SYNC_FULL;
}
main_msec = fps_to_clamped_msec(cl_maxfps, MIN_PHYS_HZ, MAX_PHYS_HZ);
sync_mode = SYNC_MAXFPS;
}

Com_DDDPrintf("%s: mode=%s main_msec=%d ref_msec=%d, phys_msec=%d\n",
__func__, sync_names[sync_mode], main_msec, ref_msec, phys_msec);

ref_extra = phys_extra = main_extra = 0;
Com_DDPrintf("%s: mode=%s main_msec=%d ref_msec=%d, phys_msec=%d\n",
__func__, sync_names[sync_mode], main_msec, ref_msec, phys_msec);
}

/*
Expand All @@ -3203,7 +3218,7 @@ CL_Frame
*/
unsigned CL_Frame(unsigned msec)
{
qboolean phys_frame, ref_frame;
qboolean phys_frame = qtrue, ref_frame = qtrue;

time_after_ref = time_before_ref = 0;

Expand All @@ -3216,9 +3231,8 @@ unsigned CL_Frame(unsigned msec)

CL_ProcessEvents();

ref_frame = phys_frame = qtrue;
switch (sync_mode) {
case SYNC_FULL:
case SYNC_TIMEDEMO:
// timedemo just runs at full speed
break;
case SYNC_SLEEP_10:
Expand All @@ -3231,31 +3245,25 @@ unsigned CL_Frame(unsigned msec)
return main_msec - main_extra;
}
break;
case SYNC_SLEEP_VIDEO:
// wait for vertical retrace if not active
VID_VideoWait();
break;
case ASYNC_VIDEO:
case ASYNC_MAXFPS:
case ASYNC_FULL:
// run physics and refresh separately
phys_extra += main_extra;
phys_extra += msec;
ref_extra += msec;

if (phys_extra < phys_msec) {
phys_frame = qfalse;
} else if (phys_extra > phys_msec * 4) {
phys_extra = phys_msec;
}

if (sync_mode == ASYNC_VIDEO) {
// sync refresh to vertical retrace
ref_frame = VID_VideoSync();
} else {
ref_extra += main_extra;
if (ref_extra < ref_msec) {
ref_frame = qfalse;
} else if (ref_extra > ref_msec * 4) {
ref_extra = ref_msec;
}
if (ref_extra < ref_msec) {
ref_frame = qfalse;
} else if (ref_extra > ref_msec * 4) {
ref_extra = ref_msec;
}
// Return immediately if neither physics or refresh are scheduled
if(!phys_frame && !ref_frame) {
return min(phys_msec - phys_extra, ref_msec - ref_extra);
}
break;
case SYNC_MAXFPS:
Expand Down
2 changes: 1 addition & 1 deletion src/client/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ static void SCR_DrawFPS(void)
if (scr_fps->integer == 0)
return;

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

char buffer[MAX_QPATH];
Expand Down
28 changes: 4 additions & 24 deletions src/refresh/vkpt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,7 @@ create_command_pool_and_fences()

/* command pool and buffers */
_VK(vkCreateCommandPool(qvk.device, &cmd_pool_create_info, NULL, &qvk.cmd_buffers_graphics.command_pool));

cmd_pool_create_info.queueFamilyIndex = qvk.queue_idx_compute;
_VK(vkCreateCommandPool(qvk.device, &cmd_pool_create_info, NULL, &qvk.cmd_buffers_compute.command_pool));


cmd_pool_create_info.queueFamilyIndex = qvk.queue_idx_transfer;
_VK(vkCreateCommandPool(qvk.device, &cmd_pool_create_info, NULL, &qvk.cmd_buffers_transfer.command_pool));

Expand Down Expand Up @@ -1100,7 +1097,7 @@ init_vulkan()
{
Com_Error(ERR_FATAL, "Running Quake II RTX with KHR ray tracing extensions requires NVIDIA Graphics Driver version "
"to be at least %u.%02u, while the installed version is %u.%02u. Please update the NVIDIA Graphics Driver, or "
"switch to the legacy mode by adding \"+set nv_ray_tracing 1\" to the command line.",
"switch to the legacy mode by adding \"+set ray_tracing_api nv\" to the command line.",
required_major, required_minor, driver_major, driver_minor);
}
}
Expand Down Expand Up @@ -1157,7 +1154,6 @@ init_vulkan()
// Com_Printf("num queue families: %d\n", num_queue_families);

qvk.queue_idx_graphics = -1;
qvk.queue_idx_compute = -1;
qvk.queue_idx_transfer = -1;

for(int i = 0; i < num_queue_families; i++) {
Expand All @@ -1175,15 +1171,12 @@ init_vulkan()
continue;
qvk.queue_idx_graphics = i;
}
else if(supports_compute && qvk.queue_idx_compute < 0) {
qvk.queue_idx_compute = i;
}
else if(supports_transfer && qvk.queue_idx_transfer < 0) {
qvk.queue_idx_transfer = i;
}
}

if(qvk.queue_idx_graphics < 0 || qvk.queue_idx_compute < 0 || qvk.queue_idx_transfer < 0) {
if(qvk.queue_idx_graphics < 0 || qvk.queue_idx_transfer < 0) {
Com_Error(ERR_FATAL, "Could not find a suitable Vulkan queue family!\n");
return qfalse;
}
Expand All @@ -1202,16 +1195,7 @@ init_vulkan()

queue_create_info[num_create_queues++] = q;
};
if(qvk.queue_idx_compute != qvk.queue_idx_graphics) {
VkDeviceQueueCreateInfo q = {
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.queueCount = 1,
.pQueuePriorities = &queue_priorities,
.queueFamilyIndex = qvk.queue_idx_compute,
};
queue_create_info[num_create_queues++] = q;
};
if(qvk.queue_idx_transfer != qvk.queue_idx_graphics && qvk.queue_idx_transfer != qvk.queue_idx_compute) {
if(qvk.queue_idx_transfer != qvk.queue_idx_graphics) {
VkDeviceQueueCreateInfo q = {
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.queueCount = 1,
Expand Down Expand Up @@ -1382,7 +1366,6 @@ init_vulkan()
}

vkGetDeviceQueue(qvk.device, qvk.queue_idx_graphics, 0, &qvk.queue_graphics);
vkGetDeviceQueue(qvk.device, qvk.queue_idx_compute, 0, &qvk.queue_compute);
vkGetDeviceQueue(qvk.device, qvk.queue_idx_transfer, 0, &qvk.queue_transfer);

#define VK_EXTENSION_DO(a) \
Expand Down Expand Up @@ -1549,11 +1532,9 @@ destroy_vulkan()
vkDestroyFence(qvk.device, qvk.fence_vertex_sync, NULL);

vkpt_free_command_buffers(&qvk.cmd_buffers_graphics);
vkpt_free_command_buffers(&qvk.cmd_buffers_compute);
vkpt_free_command_buffers(&qvk.cmd_buffers_transfer);

vkDestroyCommandPool(qvk.device, qvk.cmd_buffers_graphics.command_pool, NULL);
vkDestroyCommandPool(qvk.device, qvk.cmd_buffers_compute.command_pool, NULL);
vkDestroyCommandPool(qvk.device, qvk.cmd_buffers_transfer.command_pool, NULL);

vkDestroyDevice(qvk.device, NULL);
Expand Down Expand Up @@ -3133,7 +3114,6 @@ retry:;
vkResetFences(qvk.device, 1, qvk.fences_frame_sync + qvk.current_frame_index);

vkpt_reset_command_buffers(&qvk.cmd_buffers_graphics);
vkpt_reset_command_buffers(&qvk.cmd_buffers_compute);
vkpt_reset_command_buffers(&qvk.cmd_buffers_transfer);

// Process the profiler queries - always enabled to support DRS
Expand Down
Loading

0 comments on commit 12f1a44

Please sign in to comment.