Skip to content

Commit d13082f

Browse files
cursoragenttimfox
andcommitted
refactor(vulkan): drop USE_REVERSED_DEPTH dead branches
Vulkan always used reversed depth (vk.h defined USE_REVERSED_DEPTH unconditionally). Remove the compile-time toggle and keep the active path only in C, GLSL, and shader build script. Regenerate shader build metadata after recompiling shaders. Co-authored-by: Tim Fox <timfox@outlook.com>
1 parent 8d6297b commit d13082f

13 files changed

Lines changed: 5 additions & 101 deletions

scripts/compile_shaders.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,11 @@ def with_forward_plus_vert(defines):
170170
171171
def compile_individual_shaders():
172172
print("Compiling standalone GLSL stages...")
173-
# Shaders that need Vulkan reversed-depth define (matches vk.h USE_REVERSED_DEPTH)
174-
reversed_depth_shaders = {"atmosphere.frag", "oit_accum.frag"}
175173
for stage, ext in (("vert", ".vert"), ("frag", ".frag"), ("geom", ".geom")):
176174
for path in sorted(glsl_dir.glob(f"*{ext}")):
177175
base = path.name[: -len(ext)]
178176
array_name = f"{base}_{stage}_spv"
179-
extra_defines = "-DUSE_REVERSED_DEPTH" if path.name in reversed_depth_shaders else ""
180-
compile_shader(stage, path.name, array_name, defines=extra_defines)
177+
compile_shader(stage, path.name, array_name, defines="")
181178
182179
def compile_template_shaders():
183180
print("Compiling template-driven shaders...")

src/renderers/vulkan/shaders/glsl/atmosphere.frag

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,9 @@ float opticalDepth(vec3 origin, vec3 dir, float rayLength, float scaleHeight) {
6969
}
7070

7171
void main() {
72-
/* Depth test: only sky pixels pass (no geometry).
73-
* Standard depth: far=1.0, use LESS_OR_EQUAL frag=1.0.
74-
* Reversed depth: far=0.0, use EQUAL frag=0.0 so we pass only where stored==0.0. */
75-
#ifdef USE_REVERSED_DEPTH
72+
/* Depth test: only sky pixels pass (no geometry). Reversed depth: far=0.0;
73+
* use EQUAL in pipeline so we pass only where stored==0.0. */
7674
gl_FragDepth = 0.0;
77-
#else
78-
gl_FragDepth = 1.0;
79-
#endif
8075
vec2 uv = frag_tex_coord * 2.0 - 1.0;
8176
vec3 forward = normalize(atm.viewForward.xyz);
8277
vec3 right = normalize(atm.viewRight.xyz);

src/renderers/vulkan/shaders/glsl/oit_accum.frag

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
* MSAA path samples resolved opaque depth so transparent layers still reject
66
* against opaque geometry before accumulation.
77
*/
8-
#ifdef USE_REVERSED_DEPTH
98
#define DEPTH_TO_WEIGHT(z) (z)
10-
#else
11-
#define DEPTH_TO_WEIGHT(z) (1.0 - (z))
12-
#endif
139

1410
layout (constant_id = 0) const int manual_depth_test = 0;
1511

@@ -31,11 +27,7 @@ void main() {
3127
ivec2 depthSize = textureSize( opaqueDepthTex, 0 );
3228
vec2 depthUv = gl_FragCoord.xy / vec2( depthSize );
3329
float opaqueDepth = textureLod( opaqueDepthTex, depthUv, 0.0 ).r;
34-
#ifdef USE_REVERSED_DEPTH
3530
if ( gl_FragCoord.z + 1e-5 < opaqueDepth ) discard;
36-
#else
37-
if ( gl_FragCoord.z - 1e-5 > opaqueDepth ) discard;
38-
#endif
3931
}
4032

4133
float d = DEPTH_TO_WEIGHT(gl_FragCoord.z);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
glslang_validator_path=/usr/bin/glslangValidator
22
glslang_validator_version=Glslang Version: 11:15.1.0
3-
generated_at=2026-04-20T19:18:59Z
3+
generated_at=2026-04-23T10:07:12Z
44
shader_data_sha256=b6c7f805a5810cddfd7365a786824d42ea896f25f1d35c3ec412e157eaeee493
55
shader_binding_sha256=960921d52493ab4fcf2f8b60edb34fa0b64a852c47b5ad2ae3abdf06c35ebe4a

src/renderers/vulkan/tr_main.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -695,17 +695,10 @@ void R_SetupFirstPersonProjection( viewParms_t *dest, float *outProjection )
695695
const float depth = zFar - zNearClamped;
696696
if ( depth > 0.1f ) {
697697
#ifdef USE_VULKAN
698-
#ifdef USE_REVERSED_DEPTH
699698
outProjection[2] = 0.0f;
700699
outProjection[6] = 0.0f;
701700
outProjection[10] = zNearClamped / depth;
702701
outProjection[14] = zFar * zNearClamped / depth;
703-
#else
704-
outProjection[2] = 0.0f;
705-
outProjection[6] = 0.0f;
706-
outProjection[10] = -zFar / depth;
707-
outProjection[14] = -zFar * zNearClamped / depth;
708-
#endif
709702
#else
710703
outProjection[2] = 0.0f;
711704
outProjection[6] = 0.0f;
@@ -733,13 +726,8 @@ static void R_SetupProjectionZ( viewParms_t *dest )
733726
dest->projectionMatrix[2] = 0;
734727
dest->projectionMatrix[6] = 0;
735728
#ifdef USE_VULKAN
736-
#ifdef USE_REVERSED_DEPTH
737729
dest->projectionMatrix[10] = zNear / depth;
738730
dest->projectionMatrix[14] = zFar * zNear / depth;
739-
#else
740-
dest->projectionMatrix[10] = - zFar / depth;
741-
dest->projectionMatrix[14] = - zFar * zNear / depth;
742-
#endif
743731
#else
744732
dest->projectionMatrix[10] = -( zFar + zNear ) / depth;
745733
dest->projectionMatrix[14] = -2 * zFar * zNear / depth;
@@ -752,10 +740,8 @@ static void R_SetupProjectionZ( viewParms_t *dest )
752740
vec4_t q, c;
753741

754742
#ifdef USE_VULKAN
755-
#ifdef USE_REVERSED_DEPTH
756743
dest->projectionMatrix[10] = - zFar / depth;
757744
dest->projectionMatrix[14] = - zFar * zNear / depth;
758-
#endif
759745
#endif
760746
// transform portal plane into camera space
761747
plane[0] = dest->portalPlane.normal[0];
@@ -789,7 +775,7 @@ static void R_SetupProjectionZ( viewParms_t *dest )
789775
#endif
790776
dest->projectionMatrix[14] = c[3];
791777

792-
#ifdef USE_REVERSED_DEPTH
778+
#ifdef USE_VULKAN
793779
dest->projectionMatrix[2] = -dest->projectionMatrix[2];
794780
dest->projectionMatrix[6] = -dest->projectionMatrix[6];
795781
dest->projectionMatrix[10] = -(dest->projectionMatrix[10] + 1.0);

src/renderers/vulkan/vk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ typedef enum {
6767
VK_VOLUMETRY_QUERY_USED = 13
6868
} vk_volumetry_query_index_t;
6969

70-
#define USE_REVERSED_DEPTH
71-
7270
#define VK_NUM_BLOOM_PASSES 4
7371

7472
#ifndef _DEBUG

src/renderers/vulkan/vk_clear_attachments.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ void vk_clear_depth( qboolean clear_stencil )
6363
return;
6464

6565
attachment.colorAttachment = 0;
66-
#ifdef USE_REVERSED_DEPTH
6766
attachment.clearValue.depthStencil.depth = 0.0f;
68-
#else
69-
attachment.clearValue.depthStencil.depth = 1.0f;
70-
#endif
7167
attachment.clearValue.depthStencil.stencil = 0;
7268
if ( clear_stencil && glConfig.stencilBits > 0 ) {
7369
attachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;

src/renderers/vulkan/vk_create_pipeline.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,21 +1188,11 @@ VkPipeline vk_create_pipeline( const Vk_Pipeline_Def *def, renderPass_t renderPa
11881188
cvar_t *sv_units = ri.Cvar_Get( "r_shadowVolumeOffsetUnits", "1", CVAR_ARCHIVE_ND );
11891189
float factor = sv_factor ? sv_factor->value : 1.0f;
11901190
float units = sv_units ? sv_units->value : 1.0f;
1191-
#ifdef USE_REVERSED_DEPTH
11921191
rasterization_state.depthBiasConstantFactor = units;
11931192
rasterization_state.depthBiasSlopeFactor = factor;
1194-
#else
1195-
rasterization_state.depthBiasConstantFactor = -units;
1196-
rasterization_state.depthBiasSlopeFactor = -factor;
1197-
#endif
11981193
} else {
1199-
#ifdef USE_REVERSED_DEPTH
12001194
rasterization_state.depthBiasConstantFactor = -r_offsetUnits->value;
12011195
rasterization_state.depthBiasSlopeFactor = -r_offsetFactor->value;
1202-
#else
1203-
rasterization_state.depthBiasConstantFactor = r_offsetUnits->value;
1204-
rasterization_state.depthBiasSlopeFactor = r_offsetFactor->value;
1205-
#endif
12061196
}
12071197
} else {
12081198
rasterization_state.depthBiasEnable = VK_FALSE;
@@ -1241,11 +1231,7 @@ VkPipeline vk_create_pipeline( const Vk_Pipeline_Def *def, renderPass_t renderPa
12411231
depth_stencil_state.flags = 0;
12421232
depth_stencil_state.depthTestEnable = (state_bits & GLS_DEPTHTEST_DISABLE) ? VK_FALSE : VK_TRUE;
12431233
depth_stencil_state.depthWriteEnable = ( def->shader_type == TYPE_OCCLUSION_BBOX ) ? VK_FALSE : ( (state_bits & GLS_DEPTHMASK_TRUE) ? VK_TRUE : VK_FALSE );
1244-
#ifdef USE_REVERSED_DEPTH
12451234
depth_stencil_state.depthCompareOp = (state_bits & GLS_DEPTHFUNC_EQUAL) ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_GREATER_OR_EQUAL;
1246-
#else
1247-
depth_stencil_state.depthCompareOp = (state_bits & GLS_DEPTHFUNC_EQUAL) ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_LESS_OR_EQUAL;
1248-
#endif
12491235
depth_stencil_state.depthBoundsTestEnable = VK_FALSE;
12501236
depth_stencil_state.stencilTestEnable = (def->shadow_phase != SHADOW_DISABLED) ? VK_TRUE : VK_FALSE;
12511237

src/renderers/vulkan/vk_flares.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t
204204

205205
f->eyeZ = eye[2];
206206

207-
#ifdef USE_REVERSED_DEPTH
208207
f->drawZ = (clip[2]+0.20) / clip[3];
209-
#else
210-
f->drawZ = (clip[2]-0.20) / clip[3];
211-
#endif
212208

213209
}
214210

@@ -537,13 +533,8 @@ void RB_RenderFlares( void ) {
537533
return; // none visible
538534
}
539535

540-
#ifdef USE_REVERSED_DEPTH
541536
m = vk_ortho( backEnd.viewParms.viewportX, backEnd.viewParms.viewportX + backEnd.viewParms.viewportWidth,
542537
backEnd.viewParms.viewportY, backEnd.viewParms.viewportY + backEnd.viewParms.viewportHeight, 1.0, 0.0 );
543-
#else
544-
m = vk_ortho( backEnd.viewParms.viewportX, backEnd.viewParms.viewportX + backEnd.viewParms.viewportWidth,
545-
backEnd.viewParms.viewportY, backEnd.viewParms.viewportY + backEnd.viewParms.viewportHeight, 0.0, 1.0 );
546-
#endif
547538

548539
vk_update_mvp( m );
549540

src/renderers/vulkan/vk_pipeline_helpers.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,8 @@ void vk_create_atmosphere_pipeline( void )
8585
depth_stencil_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
8686
depth_stencil_state.depthTestEnable = VK_TRUE;
8787
depth_stencil_state.depthWriteEnable = VK_FALSE;
88-
#ifdef USE_REVERSED_DEPTH
8988
/* Reversed depth: far=0.0. Pass only where stored==0.0 (sky). Shader outputs gl_FragDepth=0.0. */
9089
depth_stencil_state.depthCompareOp = VK_COMPARE_OP_EQUAL;
91-
#else
92-
depth_stencil_state.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
93-
#endif
9490

9591
Com_Memset( &attachment_blend, 0, sizeof( attachment_blend ) );
9692
attachment_blend.blendEnable = VK_TRUE;

0 commit comments

Comments
 (0)