From 091cfe7b3b876690e5b9eb89afb19e77540c7bae Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 8 Jun 2026 10:04:31 +0000 Subject: [PATCH] Vulkan: remove dead USE_TESS_NEEDS_* and flatten USE_FOG_COLLAPSE USE_TESS_NEEDS_NORMAL and USE_TESS_NEEDS_ST2 were never defined in tr_local.h, so guarded tess assignments were dead and surface paths always copied normals and lightmap ST2. Drop the macros, unused shader/tess needsNormal/needsST2 fields, and DetectNeeds(). USE_FOG_COLLAPSE was unconditionally defined; remove the preprocessor wrappers and keep the active fog-collapse path unchanged. Co-authored-by: Tim Fox --- src/renderers/vulkan/tr_animation.c | 6 --- src/renderers/vulkan/tr_local.h | 18 +------ src/renderers/vulkan/tr_main.c | 3 -- src/renderers/vulkan/tr_shade.c | 18 +------ src/renderers/vulkan/tr_shader.c | 74 ----------------------------- src/renderers/vulkan/tr_surface.c | 33 ++----------- src/renderers/vulkan/vk_vbo.c | 6 --- 7 files changed, 6 insertions(+), 152 deletions(-) diff --git a/src/renderers/vulkan/tr_animation.c b/src/renderers/vulkan/tr_animation.c index 74aa8a49b1..864d915aa2 100644 --- a/src/renderers/vulkan/tr_animation.c +++ b/src/renderers/vulkan/tr_animation.c @@ -411,9 +411,6 @@ void RB_MDRSurfaceAnim( mdrSurface_t *surface ) tempVert[1] += w->boneWeight * ( DotProduct( bone->matrix[1], w->offset ) + bone->matrix[1][3] ); tempVert[2] += w->boneWeight * ( DotProduct( bone->matrix[2], w->offset ) + bone->matrix[2][3] ); -#ifdef USE_TESS_NEEDS_NORMAL - if ( tess.needsNormal ) -#endif { tempNormal[0] += w->boneWeight * DotProduct( bone->matrix[0], v->normal ); tempNormal[1] += w->boneWeight * DotProduct( bone->matrix[1], v->normal ); @@ -425,9 +422,6 @@ void RB_MDRSurfaceAnim( mdrSurface_t *surface ) tess.xyz[baseVertex + j][1] = tempVert[1]; tess.xyz[baseVertex + j][2] = tempVert[2]; -#ifdef USE_TESS_NEEDS_NORMAL - if ( tess.needsNormal ) -#endif { tess.normal[baseVertex + j][0] = tempNormal[0]; tess.normal[baseVertex + j][1] = tempNormal[1]; diff --git a/src/renderers/vulkan/tr_local.h b/src/renderers/vulkan/tr_local.h index 8d41478a67..acdc89e248 100644 --- a/src/renderers/vulkan/tr_local.h +++ b/src/renderers/vulkan/tr_local.h @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif #define USE_VBO // store static world geometry in VBO -#define USE_FOG_COLLAPSE // not compatible with legacy dlights +/* fog collapse path (not compatible with legacy dlights) */ #define MAX_REAL_DLIGHTS (MAX_DLIGHTS*2) #define MAX_LITSURFS (MAX_DRAWSURFS) #define MAX_FLARES 256 @@ -46,9 +46,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define USE_VBO_GRID /* put SF_GRID to VBO */ #endif -//#define USE_TESS_NEEDS_NORMAL -//#define USE_TESS_NEEDS_ST2 - #define SH_COEFF_COUNT 9 #include "../../qcommon/q_shared.h" @@ -546,11 +543,6 @@ typedef struct shader_s { fogPass_t fogPass; // draw a blended pass, possibly with depth test equals - qboolean needsNormal; // not all shaders will need all data to be gathered - //qboolean needsST1; - qboolean needsST2; - //qboolean needsColor; - int numDeforms; deformStage_t deforms[MAX_SHADER_DEFORMS]; @@ -2114,14 +2106,6 @@ typedef struct shaderCommands_s #endif #endif - // info extracted from current shader -#ifdef USE_TESS_NEEDS_NORMAL - int needsNormal; -#endif -#ifdef USE_TESS_NEEDS_ST2 - int needsST2; -#endif - int numPasses; shaderStage_t **xstages; diff --git a/src/renderers/vulkan/tr_main.c b/src/renderers/vulkan/tr_main.c index 5f1eef047b..9909ca4065 100644 --- a/src/renderers/vulkan/tr_main.c +++ b/src/renderers/vulkan/tr_main.c @@ -1078,9 +1078,6 @@ static qboolean SurfIsOffscreen( const drawSurf_t *drawSurf, qboolean *isMirror RB_BeginSurface( shader, fogNum ); #ifdef USE_VBO tess.allowVBO = qfalse; -#endif -#ifdef USE_TESS_NEEDS_NORMAL - tess.needsNormal = qtrue; #endif rb_surfaceTable[ *drawSurf->surface ]( drawSurf->surface ); diff --git a/src/renderers/vulkan/tr_shade.c b/src/renderers/vulkan/tr_shade.c index c05d28240f..769e6eceb8 100644 --- a/src/renderers/vulkan/tr_shade.c +++ b/src/renderers/vulkan/tr_shade.c @@ -390,17 +390,6 @@ void RB_BeginSurface( shader_t *shader, int fogNum ) { tess.dlightUpdateParams = qtrue; } -#ifdef USE_TESS_NEEDS_NORMAL - tess.needsNormal = state->needsNormal || tess.dlightPass || r_shownormals->integer || - ( backEnd.currentEntity == &tr.worldEntity && - ( ( r_shDebugView && r_shDebugView->integer ) || - ( r_shWorldLighting && r_shWorldLighting->integer && r_shLighting && r_shLighting->integer ) ) ); -#endif - -#ifdef USE_TESS_NEEDS_ST2 - tess.needsST2 = state->needsST2; -#endif - tess.numIndexes = 0; tess.numVertexes = 0; tess.sdfUiEdge = -1.0f; @@ -1289,15 +1278,12 @@ static void RB_IterateStagesGeneric( const shaderCommands_t *input ) is_pbr_surface = qfalse; -#ifdef USE_FOG_COLLAPSE if ( fogCollapse ) { VK_SetFogParams( &uniform, &fog_stage ); VectorCopy( backEnd.or.viewOrigin, uniform.eyePos ); vk_update_descriptor( VK_DESC_FOG_COLLAPSE, tr.fogImage->descriptor ); pushUniform = qtrue; - } else -#endif - { + } else { fog_stage = 0; if ( tess_flags & TESS_VPOS ) { VectorCopy( backEnd.or.viewOrigin, uniform.eyePos ); @@ -1961,9 +1947,7 @@ void RB_StageIteratorGeneric( void ) return; } -#ifdef USE_FOG_COLLAPSE fogCollapse = tess.fogNum && tess.shader->fogPass && tess.shader->fogCollapse; -#endif worldShOverride = ( r_shDebugView && r_shDebugView->integer == 3 ); // call shader function diff --git a/src/renderers/vulkan/tr_shader.c b/src/renderers/vulkan/tr_shader.c index 126c92b3e7..6e9aa11f62 100644 --- a/src/renderers/vulkan/tr_shader.c +++ b/src/renderers/vulkan/tr_shader.c @@ -3888,64 +3888,6 @@ static void InitShader( const char *name, int lightmapIndex ) { } -static void DetectNeeds( void ) -{ - int i, n; - - for ( i = 0; i < MAX_SHADER_STAGES; i++ ) - { - if ( !stages[i].active ) - break; - - for ( n = 0; n < NUM_TEXTURE_BUNDLES; n++ ) { - const texCoordGen_t t = stages[i].bundle[n].tcGen; - if ( t == TCGEN_LIGHTMAP ) - { - shader.needsST2 = qtrue; - } - if ( t == TCGEN_ENVIRONMENT_MAPPED || t == TCGEN_ENVIRONMENT_MAPPED_FP ) - { - shader.needsNormal = qtrue; - } - if ( stages[i].bundle[n].alphaGen == AGEN_LIGHTING_SPECULAR || stages[i].bundle[n].rgbGen == CGEN_LIGHTING_DIFFUSE ) - { - shader.needsNormal = qtrue; - } - } -#if 0 - t1 = stages[i].bundle[0].tcGen; - t2 = stages[i].bundle[1].tcGen; - - if ( t1 == TCGEN_LIGHTMAP || t2 == TCGEN_LIGHTMAP ) - { - shader.needsST2 = qtrue; - } - if ( t1 == TCGEN_ENVIRONMENT_MAPPED || t1 == TCGEN_ENVIRONMENT_MAPPED_FP ) - { - shader.needsNormal = qtrue; - } - if ( t2 == TCGEN_ENVIRONMENT_MAPPED || t2 == TCGEN_ENVIRONMENT_MAPPED_FP ) - { - shader.needsNormal = qtrue; - } - if ( stages[i].bundle[0].alphaGen == AGEN_LIGHTING_SPECULAR || stages[i].bundle[0].rgbGen == CGEN_LIGHTING_DIFFUSE ) - { - shader.needsNormal = qtrue; - } -#endif - } - for ( i = 0; i < shader.numDeforms; i++ ) - { - if ( shader.deforms[i].deformation == DEFORM_WAVE || shader.deforms[i].deformation == DEFORM_NORMALS || shader.deforms[i].deformation == DEFORM_BULGE ) { - shader.needsNormal = qtrue; - } - if ( shader.deforms[i].deformation >= DEFORM_TEXT0 && shader.deforms[i].deformation <= DEFORM_TEXT7 ) { - shader.needsNormal = qtrue; - } - } -} - - /* ========================= FinishShader @@ -4104,8 +4046,6 @@ static shader_t *FinishShader( void ) { } } - DetectNeeds(); - // fix alphaGen flags to avoid redundant comparisons in R_ComputeColors() for ( i = 0; i < MAX_SHADER_STAGES; i++ ) { shaderStage_t *pStage = &stages[ i ]; @@ -4196,7 +4136,6 @@ static shader_t *FinishShader( void ) { #ifdef USE_VULKAN -#ifdef USE_FOG_COLLAPSE if ( vk.maxBoundDescriptorSets >= 6 && !(shader.contentFlags & CONTENTS_FOG) && shader.fogPass != FP_NONE ) { fogCollapse = qtrue; if ( stage == 1 ) { @@ -4248,7 +4187,6 @@ static shader_t *FinishShader( void ) { // if there is no fogs - assume that we can apply all color optimizations without any restrictions fogCollapse = qtrue; } -#endif shader.tessFlags = TESS_XYZ; @@ -4541,7 +4479,6 @@ static shader_t *FinishShader( void ) { } -#ifdef USE_FOG_COLLAPSE if ( fogCollapse && tr.numFogs > 0 ) { Vk_Pipeline_Def fog_def; Vk_Pipeline_Def fog_def_mirror; @@ -4583,7 +4520,6 @@ static shader_t *FinishShader( void ) { shader.fogCollapse = qtrue; } -#endif } } #endif // USE_VULKAN @@ -4844,11 +4780,6 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag InitShader( strippedName, lightmapIndex ); - /* needsNormal etc. could be set based on stage requirements. */ - //shader.needsST1 = qtrue; - //shader.needsST2 = qtrue; - //shader.needsColor = qtrue; - // // attempt to define shader from an explicit parameter file // @@ -4933,11 +4864,6 @@ qhandle_t RE_RegisterShaderFromImage(const char *name, int lightmapIndex, image_ InitShader( name, lightmapIndex ); - /* needsNormal etc. could be set based on stage requirements. */ - //shader.needsST1 = qtrue; - //shader.needsST2 = qtrue; - //shader.needsColor = qtrue; - // // create the default shading commands // diff --git a/src/renderers/vulkan/tr_surface.c b/src/renderers/vulkan/tr_surface.c index 18a8aacabc..c484de07a2 100644 --- a/src/renderers/vulkan/tr_surface.c +++ b/src/renderers/vulkan/tr_surface.c @@ -405,9 +405,6 @@ static void RB_SurfaceTriangles( const srfTriangles_t *srf ) { xyz[1] = dv->xyz[1]; xyz[2] = dv->xyz[2]; -#ifdef USE_TESS_NEEDS_NORMAL - if ( tess.needsNormal ) -#endif { normal[0] = dv->normal[0]; normal[1] = dv->normal[1]; @@ -433,9 +430,6 @@ static void RB_SurfaceTriangles( const srfTriangles_t *srf ) { texCoords0[0] = dv->st[0]; texCoords0[1] = dv->st[1]; -#ifdef USE_TESS_NEEDS_ST2 - if ( tess.needsST2 ) -#endif { texCoords1[0] = dv->lightmap[0]; texCoords1[1] = dv->lightmap[1]; @@ -988,9 +982,6 @@ static void RB_SurfaceFace( const srfSurfaceFace_t *surf ) { numPoints = surf->numPoints; -#ifdef USE_TESS_NEEDS_NORMAL - if ( tess.needsNormal ) -#endif { if ( surf->normals ) { // per-vertex normals for non-coplanar faces @@ -1017,13 +1008,8 @@ static void RB_SurfaceFace( const srfSurfaceFace_t *surf ) { #ifdef USE_VK_PBR tess.texCoords[0][ndx][0] = v[6]; tess.texCoords[0][ndx][1] = v[7]; -#ifdef USE_TESS_NEEDS_ST2 - if ( tess.needsST2 ) -#endif - { - tess.texCoords[1][ndx][0] = v[8]; - tess.texCoords[1][ndx][1] = v[9]; - } + tess.texCoords[1][ndx][0] = v[8]; + tess.texCoords[1][ndx][1] = v[9]; { uint32_t color; Com_Memcpy( &color, &v[10], sizeof( color ) ); @@ -1032,13 +1018,8 @@ static void RB_SurfaceFace( const srfSurfaceFace_t *surf ) { #else tess.texCoords[0][ndx][0] = v[3]; tess.texCoords[0][ndx][1] = v[4]; -#ifdef USE_TESS_NEEDS_ST2 - if ( tess.needsST2 ) -#endif - { - tess.texCoords[1][ndx][0] = v[5]; - tess.texCoords[1][ndx][1] = v[6]; - } + tess.texCoords[1][ndx][0] = v[5]; + tess.texCoords[1][ndx][1] = v[6]; { uint32_t color; Com_Memcpy( &color, &v[7], sizeof( color ) ); @@ -1300,17 +1281,11 @@ static void RB_SurfaceGrid( srfGridMesh_t *cv ) { xyz[2] = dv->xyz[2]; texCoords0[0] = dv->st[0]; texCoords0[1] = dv->st[1]; -#ifdef USE_TESS_NEEDS_ST2 - if ( tess.needsST2 ) -#endif { texCoords1[0] = dv->lightmap[0]; texCoords1[1] = dv->lightmap[1]; texCoords1 += 2; } -#ifdef USE_TESS_NEEDS_NORMAL - if ( tess.needsNormal ) -#endif { normal[0] = dv->normal[0]; normal[1] = dv->normal[1]; diff --git a/src/renderers/vulkan/vk_vbo.c b/src/renderers/vulkan/vk_vbo.c index 021b58639f..e06642e2de 100644 --- a/src/renderers/vulkan/vk_vbo.c +++ b/src/renderers/vulkan/vk_vbo.c @@ -765,12 +765,6 @@ void R_BuildWorldVBO( msurface_t *surf, int surfCount ) initItem( vbo->items + i + 1 ); RB_BeginSurface( sf->shader, 0 ); tess.allowVBO = qfalse; // block execution of VBO path as we need to tesselate geometry -#ifdef USE_TESS_NEEDS_NORMAL - tess.needsNormal = qtrue; -#endif -#ifdef USE_TESS_NEEDS_ST2 - tess.needsST2 = qtrue; -#endif // tesselate rb_surfaceTable[ *sf->data ]( sf->data ); // VBO_PushData() may be called multiple times there // setup colors and texture coordinates