D3D12.X: a bias set by RSSetDepthBiasX is lost when the next pipeline is bound (dynamic depth bias) #3771

Open
opened 2026-12-03 06:19:07 +00:00 by fromthemoonx · 0 comments
fromthemoonx commented 2026-12-03 06:19:07 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T06:19:07Z.


A depth bias set with RSSetDepthBiasX is lost when the title binds another pipeline afterwards. The next draws use the new pipeline's own bias. This happens on GPUs with dynamic depth bias (DynamicDepthBiasSupported); the patched-pipeline fallback keeps the bias.

XCL means to keep it: on_set_pipeline_state (list_x.rs) takes s.depth_bias.unwrap_or(static_bias) as the bias after a bind.

Cause

on_set_pipeline_state runs after the native SetPipelineState. It sends RSSetDepthBias only when the wanted bias differs from native_bias, the last one XCL sent. But the native SetPipelineState has just set the new pipeline's own bias, so native_bias is out of date. The wanted bias equals it, and nothing is sent.

Measured

I drew a triangle into a D16 depth buffer and read the depth back. The numbers are the offset from a draw without bias. All pipelines have D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS. A and B have a bias of 0, C has 3.

calls before the draw XCL, main 16c2fd08 XCL with the line below plain D3D12, RTX 3060 plain D3D12, WARP
bind A, set 7 7 7 7 7
bind A, set 7, bind B 0 7 0 0
bind A, set 7, bind C 3 7 3 3
bind A, set 7, bind A again 7 7 7 0

The plain D3D12 columns use no XCL code, so the reset comes from D3D12 itself.

A fix that worked here

In on_set_pipeline_state, in the Some((true, static_bias)) arm, before the comparison:

s.native_bias = static_bias; // the bind before this set it
  • depth_bias_native_path_exact_f32_and_list9_fallback then fails at its check after the bind of pso_dyn_zero. It expects a call that sends 0, which is no longer needed because the bind already did that. The other three depth_bias tests pass. I did not run the whole suite with the line.
  • With #2858 merged, the line has to be static_bias.for_dsv(device_x::base_dsv_format(effective)).
  • XCL also binds pipelines later without this function (bind_pipeline_exact, for example at a draw when the pipeline was not ready before). From reading the code, those binds reset the bias too. I did not test them.

Not known

  • Whether the console keeps the bias over a pipeline change. The current code assumes it does.
  • Whether a retail title does this, and what it looks like (shadows and decals would be the places to look). I have no title to check with.

I am not opening a PR now, because a runtime change needs a regression run on a retail title. Anyone who can make one is welcome to take this.

Windows 11 Pro 26300, RTX 3060 12 GB (610.88). Found while checking #2858. AI use: Claude Code, Claude Opus 5.5 (found it, wrote the test and this text).

<!-- greyfinch-sync:ivall/xcl:issue:6762193806 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3771). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-03T06:19:07Z. --- A depth bias set with `RSSetDepthBiasX` is lost when the title binds another pipeline afterwards. The next draws use the new pipeline's own bias. This happens on GPUs with dynamic depth bias (`DynamicDepthBiasSupported`); the patched-pipeline fallback keeps the bias. XCL means to keep it: `on_set_pipeline_state` (`list_x.rs`) takes `s.depth_bias.unwrap_or(static_bias)` as the bias after a bind. **Cause** `on_set_pipeline_state` runs after the native `SetPipelineState`. It sends `RSSetDepthBias` only when the wanted bias differs from `native_bias`, the last one XCL sent. But the native `SetPipelineState` has just set the new pipeline's own bias, so `native_bias` is out of date. The wanted bias equals it, and nothing is sent. **Measured** I drew a triangle into a D16 depth buffer and read the depth back. The numbers are the offset from a draw without bias. All pipelines have `D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS`. A and B have a bias of 0, C has 3. | calls before the draw | XCL, main `16c2fd08` | XCL with the line below | plain D3D12, RTX 3060 | plain D3D12, WARP | |---|---|---|---|---| | bind A, set 7 | 7 | 7 | 7 | 7 | | bind A, set 7, bind B | **0** | 7 | 0 | 0 | | bind A, set 7, bind C | **3** | 7 | 3 | 3 | | bind A, set 7, bind A again | 7 | 7 | 7 | 0 | The plain D3D12 columns use no XCL code, so the reset comes from D3D12 itself. **A fix that worked here** In `on_set_pipeline_state`, in the `Some((true, static_bias))` arm, before the comparison: ```rust s.native_bias = static_bias; // the bind before this set it ``` - `depth_bias_native_path_exact_f32_and_list9_fallback` then fails at its check after the bind of `pso_dyn_zero`. It expects a call that sends 0, which is no longer needed because the bind already did that. The other three `depth_bias` tests pass. I did not run the whole suite with the line. - With #2858 merged, the line has to be `static_bias.for_dsv(device_x::base_dsv_format(effective))`. - XCL also binds pipelines later without this function (`bind_pipeline_exact`, for example at a draw when the pipeline was not ready before). From reading the code, those binds reset the bias too. I did not test them. **Not known** - Whether the console keeps the bias over a pipeline change. The current code assumes it does. - Whether a retail title does this, and what it looks like (shadows and decals would be the places to look). I have no title to check with. I am not opening a PR now, because a runtime change needs a regression run on a retail title. Anyone who can make one is welcome to take this. Windows 11 Pro 26300, RTX 3060 12 GB (610.88). Found while checking #2858. AI use: Claude Code, Claude Opus 5.5 (found it, wrote the test and this text).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#3771
No description provided.