Skip to content

Commit d8c73ea

Browse files
cursoragenttimfox
andcommitted
Vulkan: keep pipeline table indices when invalidating world PBR handles
vk_destroy_world_graphics_pipelines() must not shrink vk.pipelines_count or zero Vk_Pipeline_Def rows: shader_t stores uint32_t indices into the table; dropping the tail reuses slots and breaks cached indices (wrong draws or vk_gen_pipeline ERR_FATAL). Destroy only VkPipeline handles; lazy recreation picks up the new r_forwardPlusShade specialization. Co-authored-by: Tim Fox <timfox@outlook.com>
1 parent 0d5e677 commit d8c73ea

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/renderers/vulkan/vk_resource_destroy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ void vk_destroy_world_graphics_pipelines( void )
146146
if ( vk.device == VK_NULL_HANDLE || vk.pipelines_count <= (uint32_t)vk.pipelines_world_base ) {
147147
return;
148148
}
149+
/* Only destroy GPU objects. Keep vk.pipelines[i].def and do not shrink pipelines_count:
150+
* shaders cache uint32_t pipeline indices in shader_t::vk_pipeline; shrinking the table
151+
* would make those indices point at wrong or empty rows (black/corrupt draws or ERR_FATAL). */
149152
for ( i = (uint32_t)vk.pipelines_world_base; i < vk.pipelines_count; i++ ) {
150153
for ( j = 0; j < RENDER_PASS_COUNT; j++ ) {
151154
if ( vk.pipelines[i].handle[j] != VK_NULL_HANDLE ) {
@@ -154,9 +157,7 @@ void vk_destroy_world_graphics_pipelines( void )
154157
vk.pipeline_create_count--;
155158
}
156159
}
157-
Com_Memset( &vk.pipelines[i], 0, sizeof( vk.pipelines[0] ) );
158160
}
159-
vk.pipelines_count = (uint32_t)vk.pipelines_world_base;
160161
}
161162

162163
void vk_destroy_pipelines( qboolean resetCounter )

src/renderers/vulkan/vk_resource_destroy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
void vk_destroy_render_passes( void );
55
void vk_destroy_pipelines( qboolean resetCounter );
6-
/* Destroy only shader-table pipelines at/after vk.pipelines_world_base (PBR world draw),
7-
* not post/gamma/smaa bloom etc. Use when a cvar only invalidates world graphics (e.g. r_forwardPlusShade). */
6+
/* Destroy VkPipeline handles for shader-table rows at/after vk.pipelines_world_base only.
7+
* Preserves slot indices and Vk_Pipeline_Def entries so cached shader_t/vk_pipeline IDs stay valid;
8+
* vk_gen_pipeline() lazily recreates handles. Do not shrink vk.pipelines_count (would desync indices). */
89
void vk_destroy_world_graphics_pipelines( void );
910

1011
#endif

0 commit comments

Comments
 (0)