Pipelines with static samplers are not loaded from the pipeline library
The posterized light (PS_CompositeNMB reading its colour-grading tables unfiltered) is the host driver's: a pipeline stored in an ID3D12PipelineLibrary keeps the places its static samplers had in the driver's sampler table in the run that stored it. Loaded in a run that made static samplers in another order, it samples through other ones. Reproduced on the 4070 SUPER (examples/lut3d_probe.rs): the composite's three samplers (point, linear, trilinear), SM 6.6, the table read by heap index; stored, then loaded in a process that made ten other static samplers first: every sample is a table entry; made in that process: filtered. The runs that posterized loaded the composite from the library (coolfox-174945: 1,614 loaded, 2 made); those that did not had made it (175249, whose VICTORY_FILTER_3D translation was new). Such pipelines are now made every run (the driver's own cache keeps that quick) and neither loaded nor stored; the others keep the library. VICTORY_LIBRARY_STATIC_SAMPLERS=1: as before. Any loaded pipeline with static samplers could read through another's (filter, address mode, level, comparison), not only the composite. examples/lut3d_probe: the measurements (filtering of a 33^3 RGBA16F table by table or heap index, bound point-sampler heaps, writes past a heap, UAV state, background recompiles, 2,032 distinct static samplers at most: the next removes the device), documented. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5876706fb0
commit
7fa0e958e8
3 files changed
+790
-1
No files matched your search
@@ -255,6 +255,55 @@ static CALLS: Mutex<Vec<(u32, &'static str, String, u64)>> = Mutex::new(Vec::new
|
||||
thread_local! {
|
||||
/// The pipeline this thread is making (its shaders), for [`CALLS`].
|
||||
static LABEL: std::cell::RefCell<String> = const { std::cell::RefCell::new(String::new()) };
|
||||
/// Whether the pipeline this thread makes has static samplers
|
||||
/// ([`with_static_samplers`]).
|
||||
static STATIC_SAMPLERS: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||
}
|
||||
|
||||
/// The pipelines this thread makes while the guard lives have static
|
||||
/// samplers (`samplers`): they are made, never loaded from or stored in the
|
||||
/// library, unless `VICTORY_LIBRARY_STATIC_SAMPLERS=1`.
|
||||
///
|
||||
/// Why: the card's driver (NVIDIA, 4070 SUPER) keeps static samplers in a
|
||||
/// table of its own and puts their places in that table into the compiled
|
||||
/// pipeline. A pipeline loaded from the library in another process keeps the
|
||||
/// places of the process that stored it; where that process made other
|
||||
/// static samplers first, they are other samplers. Measured
|
||||
/// (`examples/lut3d_probe.rs`): a pipeline whose root signature has a point,
|
||||
/// a linear and a trilinear sampler, stored, then loaded in a process that
|
||||
/// made ten other static samplers before its own, sampled a 3D table
|
||||
/// through the linear one unfiltered (every result a table entry); made in
|
||||
/// that process instead, filtered. In the title, PS_CompositeNMB loaded so
|
||||
/// read its colour-grading tables unfiltered: posterized light in steps of
|
||||
/// 0.44 stops with green and magenta fringes (2026-11-26 runs; made in the
|
||||
/// run, the image was smooth). Every loaded pipeline with static samplers
|
||||
/// may read through another one's: other filters, address modes, levels
|
||||
/// and comparisons.
|
||||
/// shortcut: they are compiled every run (the driver's own cache on disk
|
||||
/// makes that quick); a fixed order of static samplers made before any
|
||||
/// pipeline would let the library keep them again.
|
||||
pub(crate) fn with_static_samplers(samplers: bool) -> StaticSamplers {
|
||||
StaticSamplers(STATIC_SAMPLERS.replace(samplers && !static_samplers_kept()))
|
||||
}
|
||||
|
||||
/// While it lives, the pipelines this thread makes skip the library if they
|
||||
/// have static samplers ([`with_static_samplers`]); the setting before it
|
||||
/// comes back when it is dropped.
|
||||
pub(crate) struct StaticSamplers(bool);
|
||||
|
||||
impl Drop for StaticSamplers {
|
||||
fn drop(&mut self) {
|
||||
STATIC_SAMPLERS.set(self.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// `VICTORY_LIBRARY_STATIC_SAMPLERS=1`: pipelines with static samplers are
|
||||
/// loaded from and stored in the library too, as before.
|
||||
fn static_samplers_kept() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| {
|
||||
std::env::var_os("VICTORY_LIBRARY_STATIC_SAMPLERS").is_some_and(|v| v == "1")
|
||||
})
|
||||
}
|
||||
|
||||
/// Names the pipeline this thread makes next.
|
||||
@@ -520,7 +569,7 @@ pub(crate) fn pipeline(
|
||||
create: impl FnOnce() -> windows::core::Result<ID3D12PipelineState>,
|
||||
) -> windows::core::Result<ID3D12PipelineState> {
|
||||
let wide = HSTRING::from(name);
|
||||
let Some(library) = library() else {
|
||||
let Some(library) = library().filter(|_| !STATIC_SAMPLERS.get()) else {
|
||||
MADE.fetch_add(1, Ordering::Relaxed);
|
||||
return create();
|
||||
};
|
||||
@@ -796,6 +845,32 @@ mod tests {
|
||||
assert_ne!(a, name("graphics", b"root", &[b"vsp", b"s"], "state"));
|
||||
}
|
||||
|
||||
/// A pipeline with static samplers is made, not looked up in the library
|
||||
/// (with or without a host); the guard gives the setting back.
|
||||
#[test]
|
||||
fn pipelines_with_static_samplers_skip_the_library() {
|
||||
let looked = std::cell::Cell::new(false);
|
||||
{
|
||||
let _guard = with_static_samplers(true);
|
||||
let made = pipeline(
|
||||
"with static samplers",
|
||||
|_, _| {
|
||||
looked.set(true);
|
||||
Err(windows::core::Error::empty())
|
||||
},
|
||||
|| Err(windows::core::Error::empty()),
|
||||
);
|
||||
assert!(made.is_err());
|
||||
assert!(!looked.get(), "the library was asked");
|
||||
{
|
||||
let _inner = with_static_samplers(false);
|
||||
assert!(!STATIC_SAMPLERS.get());
|
||||
}
|
||||
assert!(STATIC_SAMPLERS.get());
|
||||
}
|
||||
assert!(!STATIC_SAMPLERS.get());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rejected_blob_gives_an_empty_library() {
|
||||
let Some(device) = crate::host::host().and_then(|h| h.device.cast::<ID3D12Device1>().ok()) else {
|
||||
|
||||
Reference in new issue
Block a user