rt: fix pcie bus thrashing; add profiler scopes

turns out it's not cool to read color from on-gpu kusok data, modify it, and write back
This commit is contained in:
Ivan 'provod' Avdeev 2022-02-21 23:46:50 -08:00
parent 3ebdeb876e
commit 00652f0e7d
3 changed files with 50 additions and 6 deletions

View File

@ -42,7 +42,10 @@ static struct {
} g_frame;
#define PROFILER_SCOPES(X) \
X(end_frame , "R_EndFrame"); \
X(frame, "Frame"); \
X(begin_frame, "R_BeginFrame"); \
X(render_frame, "VK_RenderFrame"); \
X(end_frame, "R_EndFrame"); \
X(frame_gpu_wait, "Wait for GPU"); \
#define SCOPE_DECLARE(scope, name) APROF_SCOPE_DECLARE(scope)
@ -199,6 +202,9 @@ void R_BeginFrame( qboolean clearScene ) {
showProfilingData();
aprof_scope_frame();
APROF_SCOPE_BEGIN(frame);
APROF_SCOPE_BEGIN(begin_frame);
if (vk_core.rtx && FBitSet( vk_rtx->flags, FCVAR_CHANGED )) {
g_frame.rtx_enabled = CVAR_TO_BOOL( vk_rtx );
}
@ -225,11 +231,14 @@ void R_BeginFrame( qboolean clearScene ) {
}
g_frame.current.phase = Phase_FrameBegan;
APROF_SCOPE_END(begin_frame);
}
void VK_RenderFrame( const struct ref_viewpass_s *rvp )
{
APROF_SCOPE_BEGIN(render_frame);
VK_SceneRender( rvp );
APROF_SCOPE_END(render_frame);
}
static void enqueueRendering( VkCommandBuffer cmdbuf ) {
@ -340,6 +349,7 @@ void R_EndFrame( void )
}
APROF_SCOPE_END(end_frame);
APROF_SCOPE_END(frame);
}
static void toggleRaytracing( void ) {

View File

@ -395,10 +395,14 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render
kusok->tex_base_color |= KUSOK_MATERIAL_FLAG_SKYBOX;
}
Vector4Copy(color, kusok->color);
kusok->color[0] *= mat->base_color[0];
kusok->color[1] *= mat->base_color[1];
kusok->color[2] *= mat->base_color[2];
{
vec4_t gcolor;
gcolor[0] = color[0] * mat->base_color[0];
gcolor[1] = color[1] * mat->base_color[1];
gcolor[2] = color[2] * mat->base_color[2];
gcolor[3] = color[3];
Vector4Copy(gcolor, kusok->color);
}
if (geom->material == kXVkMaterialEmissive) {
VectorCopy( geom->emissive, kusok->emissive );

View File

@ -16,6 +16,7 @@
#include "vk_materials.h"
#include "camera.h"
#include "vk_mapents.h"
#include "profiler.h"
#include "com_strings.h"
#include "ref_params.h"
@ -25,6 +26,19 @@
#include <stdlib.h> // qsort
#include <memory.h>
#define PROFILER_SCOPES(X) \
X(scene_render, "VK_SceneRender"); \
X(draw_viewmodel, "draw viewmodel"); \
X(draw_worldbrush, "draw worldbrush"); \
X(draw_opaques, "draw opaque entities"); \
X(draw_opaque_beams, "draw opaque beams"); \
X(draw_translucent, "draw translucent entities"); \
X(draw_transparent_beams, "draw transparent beams"); \
#define SCOPE_DECLARE(scope, name) APROF_SCOPE_DECLARE(scope)
PROFILER_SCOPES(SCOPE_DECLARE)
#undef SCOPE_DECLARE
typedef struct vk_trans_entity_s {
struct cl_entity_s *entity;
int render_mode;
@ -75,6 +89,8 @@ static void reloadMaterials( void ) {
void VK_SceneInit( void )
{
PROFILER_SCOPES(APROF_SCOPE_INIT);
g_lists.draw_list = g_lists.draw_stack;
g_lists.draw_stack_pos = 0;
if (vk_core.rtx) {
@ -603,6 +619,7 @@ static void drawEntity( cl_entity_t *ent, int render_mode )
static float g_frametime = 0;
void VK_SceneRender( const ref_viewpass_t *rvp ) {
APROF_SCOPE_BEGIN_EARLY(scene_render);
const cl_entity_t* const local_player = gEngine.GetLocalPlayer();
g_frametime = /*FIXME VK RP_NORMALPASS( )) ? */
@ -619,13 +636,16 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
// Draw view model
{
APROF_SCOPE_BEGIN(draw_viewmodel);
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f );
R_RunViewmodelEvents();
R_DrawViewModel();
APROF_SCOPE_END(draw_viewmodel);
}
// Draw world brush
{
APROF_SCOPE_BEGIN(draw_worldbrush);
cl_entity_t *world = gEngine.GetEntityByIndex( 0 );
if( world && world->model )
{
@ -634,6 +654,7 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f);
VK_BrushModelDraw( world, kRenderNormal, NULL );
}
APROF_SCOPE_END(draw_worldbrush);
}
{
@ -643,6 +664,7 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
}
}
APROF_SCOPE_BEGIN(draw_opaques);
// Draw opaque entities
for (int i = 0; i < g_lists.draw_list->num_solid_entities; ++i)
{
@ -654,15 +676,19 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
R_LightAddFlashlight(ent, false);
}
}
APROF_SCOPE_END(draw_opaques);
// Draw opaque beams
APROF_SCOPE_BEGIN(draw_opaque_beams);
gEngine.CL_DrawEFX( g_frametime, false );
APROF_SCOPE_END(draw_opaque_beams);
VK_RenderDebugLabelEnd();
VK_RenderDebugLabelBegin( "tranparent" );
{
APROF_SCOPE_BEGIN(draw_translucent);
// sort translucents entities by rendermode and distance
qsort( g_lists.draw_list->trans_entities, g_lists.draw_list->num_trans_entities, sizeof( vk_trans_entity_t ), R_TransEntityCompare );
@ -672,11 +698,13 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
const vk_trans_entity_t *ent = g_lists.draw_list->trans_entities + i;
drawEntity(ent->entity, ent->render_mode);
}
APROF_SCOPE_END(draw_translucent);
}
// Draw transparent beams
APROF_SCOPE_BEGIN(draw_transparent_beams);
gEngine.CL_DrawEFX( g_frametime, true );
APROF_SCOPE_END(draw_transparent_beams);
VK_RenderDebugLabelEnd();
@ -685,6 +713,8 @@ void VK_SceneRender( const ref_viewpass_t *rvp ) {
if (ui_infotool->value > 0)
XVK_CameraDebugPrintCenterEntity();
APROF_SCOPE_END(scene_render);
}
/*