Repository navigation
Conversation
Rebased-head source follow-upChecked Confirmed a filtered-sample regression on
The candidate checks S# word 2 using the same min/mag/mip decoding as Tested — native Windows 10 Home 19045, Ryzen 7 7800X3D, Rust 1.98.1 MSVC, DXC 1.8.2502.11, debug. RTX 3090 driver 591.74 (split-wave64) and AMD Radeon(TM) Graphics iGPU driver 32.0.21030.2001 (native-wave64). Adapter names were printed and verified. For each of the four GPU/backend configurations:
Fixture detail: hardware filtering is not bit-exact ideal f32 arithmetic. On the 3090 the sample near 0.75 is slightly below it, so prior toward-zero packing yields 0x39ff; AMD gives 0x3a00. The final oracle checks exact exponent rebiasing/mantissa truncation of the separately sampled f32 result, with a small f32 sanity bound. Two earlier fixture versions wrongly required ideal quarter values (first in f32, then in half) and were corrected; their NVIDIA failures are not counted as proof of this bug. The final unchanged-head comparison still fails 64/64 on both GPUs/backends. Not tested — full workspace, retail smoke/gameplay, compile-time or memory effects, SNORM filtered samples, mip interpolation, anisotropic/reduction/comparison filters, or all native console D16 sampling rounding rules. Mixed filter modes conservatively use previous float packing when interpolation is possible. This is an adoptable candidate and failing/passing regression, not a merge-readiness claim. No source push or competing PR. AI use — Codex (GPT-6) investigated, wrote the candidate/regression, corrected the fixture against observed GPU precision, ran native tests, reviewed the diff, and prepared this report. Candidate and regression: 3 files, 71 additions / 2 deletionsdiff --git a/crates/xcl/src/gpu/dxil/lower_image.rs b/crates/xcl/src/gpu/dxil/lower_image.rs
index 56636f2..08b1be7 100644
--- a/crates/xcl/src/gpu/dxil/lower_image.rs
+++ b/crates/xcl/src/gpu/dxil/lower_image.rs
@@ -686,6 +686,13 @@ impl Lw {
};
let n = if gather { 4 } else { comps.len() };
let sel: Vec<usize> = (0..n).map(|k| if gather { k } else { comps[k] as usize }).collect();
+ // Match desc::sampler_d3d12: only point filtering returns original texel codes.
+ let s2 = self.sreg(ssamp + 2);
+ let xy = self.andc(s2, 0xF00000);
+ let xy_point = self.cmpc(Pred::Eq, xy, 0);
+ let mip = self.andc(s2, 0xC000000);
+ let mip_point = self.cmpc(Pred::Ne, mip, 0x8000000);
+ let point = self.bin(BinOp::And, xy_point, mip_point);
let vals: Vec<Value> = sel
.iter()
.map(|&c| {
@@ -694,7 +701,11 @@ impl Lw {
// gather's four values are of the one component DMASK names.
let comp = if gather { comps.first().copied().unwrap_or(0) as u32 } else { c as u32 };
let sel = self.c(4 + comp);
- self.d16_fmt(rb[c], sel, finfo)
+ let normalized = self.d16_fmt(rb[c], sel, finfo);
+ if gather { normalized } else {
+ let filtered = self.s.f32_to_f16(r[c]);
+ self.sel(point, normalized, filtered)
+ }
} else {
rb[c]
}
diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs
index da83276..17002b1 100644
--- a/crates/xcl/src/gpu/recomp/emit.rs
+++ b/crates/xcl/src/gpu/recomp/emit.rs
@@ -2245,7 +2245,15 @@ impl Em {
};
let f16 = {
let finfo = finfo.clone();
- move |e: &str| format!("d16_fmt({e}, {}u, {finfo})", 4 + comp_of(e))
+ let sampled = sampling && !base.starts_with("gather4");
+ let s2 = self.sreg(ssamp + 2);
+ move |e: &str| {
+ let normalized = format!("d16_fmt({e}, {}u, {finfo})", 4 + comp_of(e));
+ // Match desc::sampler_d3d12: any non-point min/mag or linear mip filter
+ // can produce values between texel codes. Keep point sampling exact.
+ if sampled { format!("((({s2} & 0xF00000u) == 0u && ({s2} & 0xC000000u) != 0x8000000u) ? {normalized} : f32tof16(asfloat({e})))") }
+ else { normalized }
+ }
};
if sampling {
diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs
index 608608a..871865f 100644
--- a/crates/xcl/src/gpu/recomp/tests.rs
+++ b/crates/xcl/src/gpu/recomp/tests.rs
@@ -7859,3 +7859,53 @@ fn gpu_image_d16_loads_of_unorm8_round_once() {
}
assert!(bad.is_empty(), "{} of 256 differ:\n{}", bad.len(), bad.join("\n"));
}
+
+#[test]
+fn gpu_image_d16_linear_samples_preserve_fractional_texel_values() {
+ if !gpu_ready() { return; }
+ use runner::{TestSampler, TestTexture, TexDim};
+ use windows::Win32::Graphics::Direct3D12::*;
+ use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM;
+ // Linear sampling between black and white gives exactly representable quarter values.
+ // Converting back to an 8-bit texel code would quantize those filtered values again.
+ let mut code = Vec::new();
+ for (dst, d16) in [(10, 1), (12, 0)] {
+ code.extend(encode("IMAGE_SAMPLE_LZ", "ENC_MIMG", &[("VDATA", dst), ("VADDR", 0),
+ ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 1), ("DIM", 1), ("D16", d16)], None).unwrap());
+ }
+ code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap());
+ let mut st = KernelState::default();
+ st.sgpr[16..24].copy_from_slice(&tsharp(0, 56, 9));
+ st.sgpr[24..28].copy_from_slice(&[0, 0, (1 << 20) | (1 << 22) | (2 << 26), 0]);
+ for (lane, r) in st.vgpr.iter_mut().enumerate() {
+ r[0] = f([0.375, 0.5, 0.625][lane % 3]);
+ r[1] = f(0.5);
+ }
+ let tex = [TestTexture { dim: TexDim::D2, format: DXGI_FORMAT_R8G8B8A8_UNORM,
+ width: 2, height: 1, depth: 1, texel_bytes: 4, data: vec![0, 0, 0, 0, 255, 255, 255, 255], uav: false }];
+ let samplers = [TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_LINEAR,
+ address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }];
+ let out = runner::run_code_with(&code, &st, &[], &tex, &samplers).unwrap();
+ let mut bad = 0;
+ for (lane, r) in out.vgpr.iter().enumerate() {
+ // Hardware filtering is not bit-exact f32 arithmetic. This tolerance is below
+ // one eighth of a half ULP here; the D16 result itself is still checked exactly.
+ let expected = [0.25f32, 0.5, 0.75][lane % 3];
+ assert!((f32::from_bits(r[12]) - expected).abs() < 1.0 / 65536.0, "f32 sample control lane {lane}");
+ // f32tof16 packs toward zero. These positive normal values need only exponent
+ // rebiasing and mantissa truncation; use the actual filtered f32, not ideal arithmetic.
+ let want = (((r[12] >> 23) - 112) << 10) | ((r[12] >> 13) & 0x3ff);
+ if lane < 3 { println!("filtered quarter {}: half={:#06x}, want={want:#06x}", lane + 1, r[10] & 0xffff); }
+ if r[10] & 0xffff != want { bad += 1; }
+ }
+ println!("filtered D16 sample: {bad}/64 mismatches, adapter={}", runner::adapter().unwrap());
+ // Keep the PR's point-sampled normalized rounding improvement as well.
+ st.sgpr[26] = 0;
+ let point_tex = [TestTexture { data: vec![9; 8], ..tex.into_iter().next().unwrap() }];
+ let point = [TestSampler { filter: D3D12_FILTER_MIN_MAG_MIP_POINT,
+ address: D3D12_TEXTURE_ADDRESS_MODE_CLAMP, comparison: None }];
+ let point_out = runner::run_code_with(&code, &st, &[], &point_tex, &point).unwrap();
+ for r in &point_out.vgpr { assert_eq!(r[10] & 0xffff, 0x2885, "point sample 9/255 rounds once"); }
+ println!("point D16 sample: 64/64 correct");
+ assert_eq!(bad, 0, "D16 packing must preserve the filtered sample, not reconstruct a texel code");
+} |
|
Tested Independent Windows/D3D12 check on exact head
Counts are per adapter and backend and were identical in all four combinations. Not tested Linear filtering, multisampling, mixed-width formats or swizzles, real-title smoke runs, and the full workspace test suite. AI use OpenAI Codex (GPT-6 family, exact variant unavailable) prepared and ran the temporary probe, checked the outputs, and drafted this report. |
|
Arc A770 verification of clean head Tested
& 'L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe' `
gpu::recomp::tests::gpu_image_d16_loads_of_unorm8_round_once --exact --nocapture --test-threads=1
Not tested Filtered sampling, gathers, MSAA, other texture formats or GPUs, buffer loads from #2027, the full suite, and retail-title smoke runs. AI use Codex ( Follow-up on 7009727Tested PR #2030 was open at STOR-WINLAB, Windows 11 Enterprise Evaluation 25H2 x64 (26200.9974), AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), Rust and Cargo 1.100.0 (
I ran the following command in a separate & 'L:/XclTooling/pr1778-2e2ee55-20261125-020159/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe' `
gpu::recomp::tests::gpu_image_d16_loads_of_unorm8_round_once --exact --nocapture --test-threads=1
The stock fixture checks all 256 Raw stdout, stderr and independent exit files are under Not tested Filtered sampling, gathers, MSAA, SNORM and other formats, buffer loads, other GPUs, the broader suite, or retail-title smoke runs. AI use T3 Code / Codex ( |
|
Confirmed two items needed on
|
2d941f0 to
0791d7e
Compare
A D16 buffer format load packed a UNORM / SNORM channel with f32tof16 of the decoded f32: two roundings, the second toward zero on D3D12. RDNA2 rounds code / (2^w - 1) once to nearest even, so about half of all codes came back one unit in the last place low (16_UNORM 0x0801: 0x2800 for 0x2801). That value's binary expansion repeats the w-bit code, so its first 32 bits, floor((code << 32) / (2^w - 1)), decide the rounding and a tie cannot happen. Both paths; checked against exact rounding for every code at w = 2..16. xcl-dev#2026 (XCL-BT-020's third item). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rest image_load / image_sample / image_gather4 with D16 packed each channel with f32tof16 of the f32 the view returned: rounded twice, the second time toward zero on D3D12. RDNA2 rounds code / (2^w - 1) once to nearest even: 123 of the 256 8_8_8_8_UNORM codes came back one unit in the last place low (code 9: 0x2884 for 0x2885). The channels go through d16_fmt with the T#'s format, as the buffer format loads do. xcl-dev#2026. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0791d7e to
7009727
Compare
|
A run with vkd3d-proton as the host D3D12 (DXIL → SPIR-V through dxil-spirv, then the NVIDIA Vulkan driver), so the DXIL goes through a different compiler than the native-Windows runs here: this PR's test passes. Tested
Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
d16_fmt passed float channels to f32tof16 / legacyF32ToF16, whose rounding is the host's: it truncates on the RTX 3070 and WARP but rounds to nearest under vkd3d-proton (Marvisak/VIctory#2006), where RDNA2 truncates (boykopovar/AnyPS5#22750). Use f16_rtz in both paths, as the format stores already do. gpu_buffer_d16_loads_of_32_bit_floats_truncate loads 32_FLOAT values that the two roundings tell apart (1 + 1.5 / 1.75 ulp, 65535, +/-70000, a denormal half-way, -1.5, +inf). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit b0aae2e)
|
RX 6800M focused check on the live PR head Tested: Windows 11 build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M (RDNA2), driver
The checked-in test covers all 256 RGBA8_UNORM codes for the unfiltered image-load path. This is RDNA2 coverage for that path. I did not test filtered sampling, the issue already identified by reviewers on this head, or other formats, the full suite, or a retail title. There is no smoke block from this run. AI use: OpenAI Codex (GPT-6, exact variant not exposed in this session) checked the live head, ran the focused GPU tests, and drafted this report. |
# Conflicts: # crates/xcl/src/gpu/dxil/lower_mem.rs # crates/xcl/src/gpu/recomp/tests.rs
d16_fmt reads a UNORM / SNORM value back as a code of the format and rounds code / (2^w - 1) once. A load, a gather or a point-sampled texel is such a code; a filtered sample is a blend of texels (or mips) and is not, so rounding it to a code quantizes it again: half way between codes 0 and 255 gave 0x3804 (code 128), not 0x3800 (reported on xcl-dev#2030, RTX 3090 and AMD). Both paths now pack a sample whose S# can filter (XY_MAG / XY_MIN_FILTER not point, or MIP_FILTER linear, as desc::sampler_d3d12 maps them) with f16_rtz of the host's value, as d16_fmt packs float channels. Gathers and point samplers keep d16_fmt. A static sampler decides it when translating; otherwise S# word 2 decides it when the shader runs. image_get_lod's D16 result, an LOD and not a texel, goes back to f32tof16 in the HLSL path, as the direct DXIL path packs it. gpu_image_d16_filtered_samples_keep_the_blend samples a 2x1 RGBA8_UNORM texture between codes 0 and 255 with heap and static linear samplers and checks f16_rtz of the f32 sample in every lane (0x3800 half way), and codes 9 and 128 through heap and static point samplers (0x2885, 0x3804). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks WebIdentity1 and raylitebull.
New test On the other points: this branch is stacked on #2027 and merges cleanly with Not tested: SNORM filtered samples, comparison or PCF filtering, anisotropic or min/max reduction, other GPUs. A sampler that is linear for minification but magnifies is treated as filtered, which is conservative. AI-assisted (Claude Code). |
d16_fmt reads a UNORM / SNORM value back as a code of the format and rounds code / (2^w - 1) once. A load, a gather or a point-sampled texel is such a code; a filtered sample is a blend of texels (or mips) and is not, so rounding it to a code quantizes it again: half way between codes 0 and 255 gave 0x3804 (code 128), not 0x3800 (reported on xcl-dev#2030, RTX 3090 and AMD). Both paths now pack a sample whose S# can filter (XY_MAG / XY_MIN_FILTER not point, or MIP_FILTER linear, as desc::sampler_d3d12 maps them) with f16_rtz of the host's value, as d16_fmt packs float channels. Gathers and point samplers keep d16_fmt. A static sampler decides it when translating; otherwise S# word 2 decides it when the shader runs. image_get_lod's D16 result, an LOD and not a texel, goes back to f32tof16 in the HLSL path, as the direct DXIL path packs it. gpu_image_d16_filtered_samples_keep_the_blend samples a 2x1 RGBA8_UNORM texture between codes 0 and 255 with heap and static linear samplers and checks f16_rtz of the f32 sample in every lane (0x3800 half way), and codes 9 and 128 through heap and static point samplers (0x2885, 0x3804). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 2d4b3a5)
|
RX 6800M follow-up on the updated exact head Environment: Native Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M (RDNA2), driver Fixed head: Test-only negative control: I kept the new test and checked out only Scope: Focused debug GPU tests. No full suite or retail-title smoke on this head; these results establish the synthetic filtered and unfiltered cases, not title-level D16 use. The negative control changes shader code shape as well as the filter gate, so it demonstrates a behavioral regression on the parent files without isolating a single emitted operation. AI use: OpenAI Codex ran the RX 6800M tests and parent-code control, counted the mismatch lines, restored and verified the exact clean head, and prepared this report. |
Stacked on #2027: only the second commit (
Recompiler: D16 image reads …) belongs to this PR. It uses #2027'sd16_fmt/norm16_rep. Part of #2026.image_load,image_sample*andimage_gather4*withD16=1packed each channel withf32tof16of the f32 the view returned. That's rounded twice, and on D3D12 the second time toward zero. RDNA2 roundscode / (2^w − 1)once, to nearest even (boykopovar/AnyPS5#22750 measured all 256 8-bit codes on gfx1036). So 123 of the 256 8_8_8_8_UNORM codes came back one unit in the last place low: code 9 gave0x2884, where RDNA2 gives0x2885.What is in it
dxil/lower_image.rs: the T#'s format info (FMT_INFO[min(fmt, 77)]) is read once per image instruction. The D16 float channel of a sample or gather, a load, and an MSAA load goes throughLw::d16_fmtwith its component. A gather's four values all belong to the one component DMASK names.recomp/emit.rs: the same in the HLSL path ({t}_finfo, andd16_fmtin thef16/ loadhalfclosures).recomp/tests.rs:gpu_image_d16_loads_of_unorm8_round_oncecovers all 256 codes of a 64×1 8_8_8_8_UNORM texture against exact single rounding.Formats whose components have different widths (2_10_10_10, 5_6_5) use the width of the channel in the result's position. With a T# swizzle that reorders them, that can be the wrong width. Uniform formats (8_8_8_8, 16_16, …) are exact either way. Float texels are unchanged, since D3D's truncation already matches RDNA2's toward-zero packing of 32-bit float texels.
2d4b3a5: D16 samples whose sampler can filter (linear/anisotropic min or mag, or linear mip; S# word 2, static samplers decided at translation time) keep the host's blended value, packed withf16_rtz; gathers, point samples and loads keepd16_fmt. The HLSLimage_get_lodD16 result goes back tof32tof16. Testgpu_image_d16_filtered_samples_keep_the_blend(review by WebIdentity1 / raylitebull).Tested
2d4b3a5, RTX 3070 (616.56): the new filtered-sample test fails ondb52da7(126 of 128 values: 0x3804 where 0x3800 is right) and passes with the fix, on both paths;d16tests 8 of 8 on both paths;gpu_suite: 136 passed withXCL_DIRECT_DXIL=0; with1, 135 passed and 1 failed:gpu_image_get_resinfo_1d_array, which fails onmaintoo (Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046). CI Build and test: passing.2d4b3a5, AMD Radeon RX 6800M (RDNA2, native wave64), driver 30.0.13002.13003, run by luckyteagirl (comment):gpu_image_d16_filtered_samples_keep_the_blendpasses withXCL_DIRECT_DXIL=0and1. Withrecomp/emit.rsanddxil/lower_image.rstaken fromdb52da7, it fails on each backend with 126 of 128 checks differing (63 heap trilinear and 63 static bilinear lanes).gpu_image_d16_loads_of_unorm8_round_oncealso passes on both backends (atdb52da7and with direct DXIL at2d4b3a5).main5ce558f(rebased; Recompiler: direct DXIL cache entries change when its sources do #1947 now keys the translated cache on thegpu/dxilsources, so there is noTRANSLATOR_VERSIONbump):maingives 123 of 256 one ULP low withXCL_DIRECT_DXIL=0and1. This branch passes with both.gpu_tests (--skip gpu_sparse_vram), with the whole stack (Recompiler: D16 format loads of UNORM / SNORM data round once to nearest #2027, Recompiler: D16 image reads of UNORM / SNORM texels round once to nearest #2030, Recompiler: D16 image loads of 32-bit integer texels saturate to 16 bits #2042): 135 passed withXCL_DIRECT_DXIL=0; with1, 134 passed and 1 failed,gpu_image_get_resinfo_1d_array, which fails the same way onmain5ce558f(Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046 fixes it).dxil::andbuffer_formatunits: 138 passed.Regression run
I have no retail title here. Could someone with one post the
xcl-smokeblocks formainand this head?Not tested
AI use
🤖 Generated with Claude Code