Skip to content

Fix black screen when r_forwardPlusShade invalidates pipelines#153

Draft
timfox wants to merge 2 commits intomainfrom
cursor/forwardplus-post-pipeline-refresh-f2d7
Draft

Fix black screen when r_forwardPlusShade invalidates pipelines#153
timfox wants to merge 2 commits intomainfrom
cursor/forwardplus-post-pipeline-refresh-f2d7

Conversation

@timfox
Copy link
Copy Markdown
Owner

@timfox timfox commented Apr 27, 2026

Summary

1. Forward+ shade: avoid full post stack teardown
r_forwardPlusShade only needs PBR world draw pipelines. Full vk_destroy_pipelines() also destroyed gamma/SMAA/bloom/etc. — fixed by vk_destroy_world_graphics_pipelines() (handles only, post stack untouched).

2. Critical: do not shrink pipelines_count on world invalidation (this commit)
shader_t caches uint32_t indices into vk.pipelines[]. The first version of vk_destroy_world_graphics_pipelines() set pipelines_count = pipelines_world_base and zeroed rows — that reused slot indices and could make cached vk_pipeline indices point at wrong/empty entries → corrupt draws, black screen, or vk_gen_pipeline fatal errors.

Fix: destroy only the VkPipeline handles in world rows; keep def and keep pipelines_count. vk_gen_pipeline recreates handles lazily with updated specialization.

Validation

  • Incremental idtech3_vulkan_x86 build
  • ctest (19/19 passed)
Open in Web Open in Cursor 

r_forwardPlusShade changes PBR fragment specialization on world draw pipelines
only. vk_destroy_pipelines() also destroyed gamma, overlay compose, bloom,
SMAA, and other post paths unrelated to Forward+, which could leave the
swapchain with no valid gamma blit (black screen with audio).

Add vk_destroy_world_graphics_pipelines() (same slice as vk_release_resources:
indices >= vk.pipelines_world_base) and use it for r_forwardPlusShade
invalidation. Persistent pipelines (skybox, fog, etc.) stay valid; PBR world
pipelines are recreated lazily via vk_gen_pipeline as before.

Co-authored-by: Tim Fox <timfox@outlook.com>
@cursor cursor Bot force-pushed the cursor/forwardplus-post-pipeline-refresh-f2d7 branch from d3c6ce5 to 0d5e677 Compare April 27, 2026 19:39
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants