Skip to content

Commit ec10dae

Browse files
committed
renderer: Flush states when changing depth comparison mode
1 parent b204ce3 commit ec10dae

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
8888
- Fixed a stack overflow in debug mode by moving global scopes/pipelines to the heap
8989
- When a texture handle is explicitly set to `none`, Alkahest will now properly unset the texture instead of binding the fallback texture
9090
- Bake rustc version as a constant instead of checking it at runtime
91+
- Fixed solid geometry not rendering in simpler maps (Shard, Sunken, etc.)
9192

9293
## 0.5.0 - 2024-07-24
9394

crates/alkahest-renderer/src/gpu/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct GpuContext {
7373
current_depth_bias: AtomicUsize,
7474
current_input_topology: AtomicI32,
7575
current_depth_state: AtomicUsize,
76-
pub use_flipped_depth_comparison: AtomicBool,
76+
use_flipped_depth_comparison: AtomicBool,
7777

7878
pub current_states: AtomicCell<StateSelection>,
7979

@@ -373,6 +373,14 @@ impl GpuContext {
373373
}
374374
}
375375

376+
pub fn set_depth_mode(&self, mode: DepthMode) {
377+
let flipped = mode == DepthMode::Flipped;
378+
self.use_flipped_depth_comparison
379+
.store(flipped, Ordering::Relaxed);
380+
// cohae: Since the depth/stencil state only checks the index and not whether we changed the flipped state, we need to flush the depth state manually
381+
self.flush_states();
382+
}
383+
376384
pub fn present(&self, vsync: bool) {
377385
if let Some(swap_chain) = &self.swap_chain {
378386
unsafe {
@@ -559,3 +567,10 @@ impl GpuContext {
559567

560568
unsafe impl Send for GpuContext {}
561569
unsafe impl Sync for GpuContext {}
570+
571+
#[derive(PartialEq)]
572+
pub enum DepthMode {
573+
Normal,
574+
/// Used for rendering shadowmaps
575+
Flipped,
576+
}

crates/alkahest-renderer/src/renderer/shadows.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
visibility::{ViewVisibility, VisibilityHelper},
1515
Scene,
1616
},
17+
gpu::DepthMode,
1718
gpu_event, gpu_profile_event,
1819
renderer::Renderer,
1920
util::{black_magic::EntityRefDarkMagic, Hocus},
@@ -25,9 +26,7 @@ impl Renderer {
2526
return;
2627
}
2728

28-
self.gpu
29-
.use_flipped_depth_comparison
30-
.store(true, Ordering::Relaxed);
29+
self.gpu.set_depth_mode(DepthMode::Flipped);
3130

3231
gpu_profile_event!(self.gpu, "update_shadow_maps");
3332
self.gpu
@@ -80,9 +79,7 @@ impl Renderer {
8079
self.run_renderstage_systems(scene, TfxRenderStage::ShadowGenerate);
8180
}
8281

83-
self.gpu
84-
.use_flipped_depth_comparison
85-
.store(false, Ordering::Relaxed);
82+
self.gpu.set_depth_mode(DepthMode::Normal);
8683
}
8784
}
8885

0 commit comments

Comments
 (0)