mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
DirectStorage: count BCPack refusals per mode, opt-in solid fill of their destinations
A BCPack refusal was logged once per run (warn_once "BCPack"), so a log showed the first refused request and nothing about the rest. Now: - one warning per mode and zlib stage, and a running count line on the first 16 refusals and every power of two; - report.json gets dstorage.bcpack_refused: requests, zlib-combined requests, destination bytes and filled bytes per DSTORAGE_BCPACK_MODE; - XCL_DSTORAGE_BCPACK_FILL=1 fills each refused BCPack destination with solid blocks of its BCn format (magenta, red for BC4/BC5), exactly destination_size bytes, into committed writable memory or the physical pages snapshot at enqueue. The request still fails with E_DECOMPRESSION; nothing changes without the switch. Tests: per-mode counts, the fill blocks decoded by small BC1/BC4/BC6H mode 11/BC7 mode 6 decoders in the test module, and a memory queue run with and without the switch (status unchanged, no byte past the size). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+382
-14
@@ -33,9 +33,11 @@
|
||||
use std::ffi::c_void;
|
||||
use std::os::windows::fs::FileExt;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU32, Ordering};
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU32, AtomicU64, Ordering};
|
||||
use std::sync::{mpsc, Arc, Condvar, Mutex, OnceLock};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use windows_sys::core::GUID;
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, DuplicateHandle, DUPLICATE_SAME_ACCESS, HANDLE};
|
||||
use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT};
|
||||
@@ -118,6 +120,172 @@ fn warn_once(what: &str, why: std::fmt::Arguments) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// BCPack refusals (report.json → dstorage)
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
/// `DSTORAGE_BCPACK_MODE` names (GDK `dstorage_xs.h`); 8..=15 are not in the enum.
|
||||
const BCPACK_NAMES: [&str; 8] = ["none", "BC1", "BC2", "BC3", "BC4", "BC5", "BC6H", "BC7"];
|
||||
|
||||
fn bcpack_name(mode: u8) -> String {
|
||||
BCPACK_NAMES.get(mode as usize).map_or_else(|| format!("mode {mode}"), |n| n.to_string())
|
||||
}
|
||||
|
||||
/// BCPack requests refused at enqueue (XCL has no BCPack decoder), by mode.
|
||||
struct BcpackRefusals {
|
||||
requests: [AtomicU64; 16],
|
||||
with_zlib: [AtomicU64; 16],
|
||||
bytes: [AtomicU64; 16],
|
||||
filled_bytes: [AtomicU64; 16],
|
||||
total: AtomicU64,
|
||||
}
|
||||
|
||||
impl BcpackRefusals {
|
||||
const fn new() -> Self {
|
||||
const Z: AtomicU64 = AtomicU64::new(0);
|
||||
Self { requests: [Z; 16], with_zlib: [Z; 16], bytes: [Z; 16], filled_bytes: [Z; 16], total: AtomicU64::new(0) }
|
||||
}
|
||||
|
||||
/// Count a refused request; the number of BCPack refusals so far, this one included.
|
||||
fn note(&self, r: &Request) -> u64 {
|
||||
let m = r.bcpack() as usize & 0xF;
|
||||
self.requests[m].fetch_add(1, Ordering::Relaxed);
|
||||
if r.zlib() {
|
||||
self.with_zlib[m].fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
self.bytes[m].fetch_add(r.destination_size as u64, Ordering::Relaxed);
|
||||
self.total.fetch_add(1, Ordering::Relaxed) + 1
|
||||
}
|
||||
|
||||
fn stats(&self) -> BTreeMap<String, BcpackStats> {
|
||||
(1..16u8)
|
||||
.filter(|&m| self.requests[m as usize].load(Ordering::Relaxed) > 0)
|
||||
.map(|m| {
|
||||
let i = m as usize;
|
||||
let s = BcpackStats {
|
||||
requests: self.requests[i].load(Ordering::Relaxed),
|
||||
with_zlib: self.with_zlib[i].load(Ordering::Relaxed),
|
||||
destination_bytes: self.bytes[i].load(Ordering::Relaxed),
|
||||
filled_bytes: self.filled_bytes[i].load(Ordering::Relaxed),
|
||||
};
|
||||
(bcpack_name(m), s)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn summary(&self) -> String {
|
||||
let s = self.stats();
|
||||
let parts: Vec<String> = s.iter().map(|(n, v)| format!("{n} {} ({} bytes)", v.requests, v.destination_bytes)).collect();
|
||||
parts.join(", ")
|
||||
}
|
||||
}
|
||||
|
||||
static BCPACK: BcpackRefusals = BcpackRefusals::new();
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct BcpackStats {
|
||||
pub requests: u64,
|
||||
/// of `requests`, zlib then BCPack (two-stage)
|
||||
pub with_zlib: u64,
|
||||
/// bytes the title's destinations were to receive
|
||||
pub destination_bytes: u64,
|
||||
/// bytes written by `XCL_DSTORAGE_BCPACK_FILL`
|
||||
pub filled_bytes: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct DStorageStats {
|
||||
/// BCPack requests refused (no decoder), by `DSTORAGE_BCPACK_MODE`
|
||||
pub bcpack_refused: BTreeMap<String, BcpackStats>,
|
||||
}
|
||||
|
||||
pub fn stats() -> DStorageStats {
|
||||
DStorageStats { bcpack_refused: BCPACK.stats() }
|
||||
}
|
||||
|
||||
/// Log a refused BCPack request: one warning per mode and zlib stage, then a running count on
|
||||
/// the first 16 refusals and every power of two.
|
||||
fn log_bcpack_refusal(r: &Request, k: u64) {
|
||||
let bc = r.bcpack();
|
||||
let key = format!("BCPack {}{}", bcpack_name(bc), if r.zlib() { " after zlib" } else { "" });
|
||||
warn_once(
|
||||
&key,
|
||||
format_args!(
|
||||
"mode {bc} unsupported (src={}, intermediate={}, dst={}, swizzle={}); the request fails with E_DECOMPRESSION",
|
||||
r.source_size,
|
||||
r.intermediate_size,
|
||||
r.destination_size,
|
||||
r.swizzle()
|
||||
),
|
||||
);
|
||||
if k <= 16 || k.is_power_of_two() {
|
||||
crate::xlog_info!("DirectStorage: BCPack refusals so far: {k} requests: {}", BCPACK.summary());
|
||||
}
|
||||
}
|
||||
|
||||
/// `XCL_DSTORAGE_BCPACK_FILL=1`: a refused BCPack destination gets solid blocks of its BCn
|
||||
/// format (magenta; red for BC4/BC5) instead of staying as it was, so the title's textures
|
||||
/// that wait on BCPack show where they are. The request still fails.
|
||||
fn bcpack_fill_from_env() -> bool {
|
||||
std::env::var("XCL_DSTORAGE_BCPACK_FILL").is_ok_and(|v| !v.trim().is_empty() && v.trim() != "0")
|
||||
}
|
||||
|
||||
/// BC1 colour block: both endpoints magenta (565 `0xF81F`), every index 0.
|
||||
const BC1_MAGENTA: [u8; 8] = [0x1F, 0xF8, 0x1F, 0xF8, 0, 0, 0, 0];
|
||||
/// BC4 block: both endpoints 255, every index 0.
|
||||
const BC4_FULL: [u8; 8] = [0xFF, 0xFF, 0, 0, 0, 0, 0, 0];
|
||||
/// BC4 block: both endpoints 0.
|
||||
const BC4_ZERO: [u8; 8] = [0; 8];
|
||||
|
||||
/// One solid block of `mode`'s BCn format.
|
||||
fn bcpack_fill_block(mode: u8) -> Option<Vec<u8>> {
|
||||
let cat = |a: &[u8], b: &[u8]| [a, b].concat();
|
||||
Some(match mode {
|
||||
1 => BC1_MAGENTA.to_vec(),
|
||||
2 => cat(&[0xFF; 8], &BC1_MAGENTA),
|
||||
3 => cat(&BC4_FULL, &BC1_MAGENTA),
|
||||
4 => BC4_FULL.to_vec(),
|
||||
5 => cat(&BC4_FULL, &BC4_ZERO),
|
||||
// mode 11 (5 bits 00011): one region, 10-bit endpoints r/g/b = 495/0/495 (1.0 in UF16), indices 0
|
||||
6 => (3u128 | 495 << 5 | 495 << 25 | 495 << 35 | 495 << 55).to_le_bytes().to_vec(),
|
||||
// mode 6 (bit 6): 7-bit endpoints r/g/b/a = 127/0/127/127, both p-bits 1, indices 0
|
||||
7 => (1u128 << 6 | 127 << 7 | 127 << 14 | 127 << 35 | 127 << 42 | 127 << 49 | 127 << 56 | 1 << 63 | 1 << 64)
|
||||
.to_le_bytes()
|
||||
.to_vec(),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Where a refused BCPack request's fill goes: its virtual destination, or the physical pages
|
||||
/// it named (snapshot at enqueue, as for a request that runs).
|
||||
enum FillTarget {
|
||||
Virtual,
|
||||
Pages(Vec<usize>),
|
||||
}
|
||||
|
||||
/// Fill the title's destination of `r` (exactly `destination_size` bytes) with solid blocks.
|
||||
unsafe fn bcpack_fill(r: &Request, target: &FillTarget) -> bool {
|
||||
let Some(block) = bcpack_fill_block(r.bcpack()) else { return false };
|
||||
let n = r.destination_size as usize;
|
||||
let bytes: Vec<u8> = block.iter().copied().cycle().take(n).collect();
|
||||
let ok = match target {
|
||||
FillTarget::Pages(pages) => crate::hle::kernelx::write_physical_pages(pages, r.destination_page_offset as usize, &bytes),
|
||||
FillTarget::Virtual => {
|
||||
if !writable(r.destination as usize, n) {
|
||||
return false;
|
||||
}
|
||||
if n > 0 {
|
||||
std::ptr::copy_nonoverlapping(bytes.as_ptr(), r.destination as *mut u8, n);
|
||||
}
|
||||
true
|
||||
}
|
||||
};
|
||||
if ok {
|
||||
BCPACK.filled_bytes[r.bcpack() as usize & 0xF].fetch_add(n as u64, Ordering::Relaxed);
|
||||
}
|
||||
ok
|
||||
}
|
||||
|
||||
/// A vtable: the listed methods, then logged E_NOTIMPL stubs up to `total` entries.
|
||||
fn vtable(iface: &str, methods: &[usize], total: usize) -> &'static [usize] {
|
||||
let mut v = methods.to_vec();
|
||||
@@ -484,23 +652,19 @@ impl Request {
|
||||
return Err(E_DESTINATION_SIZE);
|
||||
}
|
||||
}
|
||||
// Two-stage zlib -> BCPack: validate intermediate bounds when supplied, then refuse BCPack.
|
||||
(true, bc) => {
|
||||
// Two-stage zlib -> BCPack: validate intermediate bounds when supplied, then refuse BCPack
|
||||
// (counted and logged at enqueue, `BcpackRefusals`).
|
||||
(true, _) => {
|
||||
if self.intermediate_size != 0 && (self.intermediate_size <= self.source_size || self.destination_size <= self.intermediate_size) {
|
||||
return Err(E_DESTINATION_SIZE);
|
||||
}
|
||||
warn_once(
|
||||
"BCPack",
|
||||
format_args!("zlib + BCPack mode {bc} unsupported (src={}, intermediate={}, dst={})", self.source_size, self.intermediate_size, self.destination_size),
|
||||
);
|
||||
return Err(E_DECOMPRESSION);
|
||||
}
|
||||
// Single-stage BCPack: `intermediate_size` must be 0, then refuse BCPack.
|
||||
(false, bc) => {
|
||||
(false, _) => {
|
||||
if self.intermediate_size != 0 {
|
||||
return Err(E_DESTINATION_SIZE);
|
||||
}
|
||||
warn_once("BCPack", format_args!("BCPack mode {bc} unsupported (src={}, dst={})", self.source_size, self.destination_size));
|
||||
return Err(E_DECOMPRESSION);
|
||||
}
|
||||
}
|
||||
@@ -672,6 +836,8 @@ enum Entry {
|
||||
hr: HRESULT,
|
||||
req: Request,
|
||||
file: Option<Arc<FileInner>>,
|
||||
/// a refused BCPack request under `XCL_DSTORAGE_BCPACK_FILL`: where its solid blocks go
|
||||
fill: Option<FillTarget>,
|
||||
},
|
||||
Status(Arc<StatusInner>, u32),
|
||||
/// a fence (one reference held) and the value it gets
|
||||
@@ -710,6 +876,8 @@ struct QueueInner {
|
||||
closed: AtomicBool,
|
||||
error_event: usize,
|
||||
errors: Mutex<(u32, Option<FirstError>)>,
|
||||
/// `XCL_DSTORAGE_BCPACK_FILL` when the queue was made
|
||||
bcpack_fill: AtomicBool,
|
||||
}
|
||||
|
||||
impl QueueInner {
|
||||
@@ -796,7 +964,11 @@ impl QueueInner {
|
||||
}
|
||||
}
|
||||
}
|
||||
Entry::Refused { hr, req, file } => {
|
||||
Entry::Refused { hr, req, file, fill } => {
|
||||
if let Some(t) = &fill {
|
||||
// the destination gets solid blocks; the request still fails
|
||||
unsafe { bcpack_fill(&req, t) };
|
||||
}
|
||||
self.fail(hr, req, file.as_deref());
|
||||
if since_status >= 0 {
|
||||
since_status = hr;
|
||||
@@ -923,6 +1095,7 @@ unsafe extern "system" fn factory_create_queue(_p: *mut c_void, desc: *const u8,
|
||||
closed: AtomicBool::new(false),
|
||||
error_event: ev as usize,
|
||||
errors: Mutex::new((0, None)),
|
||||
bcpack_fill: AtomicBool::new(bcpack_fill_from_env()),
|
||||
});
|
||||
let o = new_object(queue_vtbl(), inner);
|
||||
let hr = queue_qi(o, riid, out);
|
||||
@@ -966,7 +1139,18 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8)
|
||||
let r = Request::parse(&*(req as *const [u8; REQUEST_BYTES]));
|
||||
if let Err(hr) = r.check(q.source_memory) {
|
||||
warn_once("EnqueueRequest", format_args!("refused ({hr:#x}): {r:x?}"));
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file: None });
|
||||
let mut fill = None;
|
||||
if hr == E_DECOMPRESSION && r.bcpack() != 0 {
|
||||
log_bcpack_refusal(&r, BCPACK.note(&r));
|
||||
if q.bcpack_fill.load(Ordering::Relaxed) {
|
||||
fill = if !r.dest_physical_pages() {
|
||||
Some(FillTarget::Virtual)
|
||||
} else {
|
||||
snapshot_page_array(r.destination, r.destination_page_offset, r.destination_size).ok().map(FillTarget::Pages)
|
||||
};
|
||||
}
|
||||
}
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file: None, fill });
|
||||
}
|
||||
let file = if r.memory_source() {
|
||||
None
|
||||
@@ -974,7 +1158,7 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8)
|
||||
// only a file this factory opened
|
||||
let f = r.source as *mut c_void;
|
||||
if !crate::gpu::shader::readable(f as usize, 8) || *(f as *const *const usize) != file_vtbl().as_ptr() {
|
||||
return q.enqueue(Entry::Refused { hr: E_FILE_HANDLE, req: r, file: None });
|
||||
return q.enqueue(Entry::Refused { hr: E_FILE_HANDLE, req: r, file: None, fill: None });
|
||||
}
|
||||
Some(Arc::clone(inner::<FileInner>(f)))
|
||||
};
|
||||
@@ -982,7 +1166,7 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8)
|
||||
match snapshot_page_array(r.destination, r.destination_page_offset, r.destination_size) {
|
||||
Ok(pages) => Some(pages),
|
||||
Err(hr) => {
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file });
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file, fill: None });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -992,7 +1176,7 @@ unsafe extern "system" fn queue_enqueue_request(p: *mut c_void, req: *const u8)
|
||||
match snapshot_page_array(r.source, r.source_page_offset, r.source_size) {
|
||||
Ok(pages) => Some(pages),
|
||||
Err(hr) => {
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file });
|
||||
return q.enqueue(Entry::Refused { hr, req: r, file, fill: None });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1768,4 +1952,188 @@ mod tests {
|
||||
status_release(s);
|
||||
}
|
||||
}
|
||||
// Small reference decoders for the fill blocks (from the BCn block layouts; only what the
|
||||
// solid blocks use is decoded).
|
||||
|
||||
fn bits(v: u128, at: u32, n: u32) -> u32 {
|
||||
((v >> at) & ((1u128 << n) - 1)) as u32
|
||||
}
|
||||
|
||||
/// BC1 colour block → 16 RGBA texels (`opaque`: the BC2/BC3 colour half, always 4 colours).
|
||||
fn bc1_texels(b: &[u8], opaque: bool) -> [[u8; 4]; 16] {
|
||||
let c0 = u16::from_le_bytes([b[0], b[1]]);
|
||||
let c1 = u16::from_le_bytes([b[2], b[3]]);
|
||||
let rgb = |c: u16| {
|
||||
let (r, g, bl) = ((c >> 11) as u32, ((c >> 5) & 63) as u32, (c & 31) as u32);
|
||||
[(r * 255 + 15) / 31, (g * 255 + 31) / 63, (bl * 255 + 15) / 31]
|
||||
};
|
||||
let (e0, e1) = (rgb(c0), rgb(c1));
|
||||
let four = opaque || c0 > c1;
|
||||
let mut pal = [[0u8, 0, 0, 255]; 4];
|
||||
for c in 0..3 {
|
||||
pal[0][c] = e0[c] as u8;
|
||||
pal[1][c] = e1[c] as u8;
|
||||
if four {
|
||||
pal[2][c] = ((2 * e0[c] + e1[c]) / 3) as u8;
|
||||
pal[3][c] = ((e0[c] + 2 * e1[c]) / 3) as u8;
|
||||
} else {
|
||||
pal[2][c] = ((e0[c] + e1[c]) / 2) as u8;
|
||||
}
|
||||
}
|
||||
if !four {
|
||||
pal[3] = [0, 0, 0, 0];
|
||||
}
|
||||
let idx = u32::from_le_bytes([b[4], b[5], b[6], b[7]]);
|
||||
std::array::from_fn(|i| pal[((idx >> (2 * i)) & 3) as usize])
|
||||
}
|
||||
|
||||
/// BC4 block (also the BC3 alpha half) → 16 values.
|
||||
fn bc4_values(b: &[u8]) -> [u8; 16] {
|
||||
let v = u64::from_le_bytes(b[..8].try_into().unwrap());
|
||||
let (a0, a1) = (b[0] as u32, b[1] as u32);
|
||||
std::array::from_fn(|i| {
|
||||
let k = ((v >> (16 + 3 * i)) & 7) as u32;
|
||||
match k {
|
||||
0 => a0 as u8,
|
||||
1 => a1 as u8,
|
||||
_ if a0 > a1 => (((8 - k) * a0 + (k - 1) * a1) / 7) as u8,
|
||||
6 => 0,
|
||||
7 => 255,
|
||||
_ => (((6 - k) * a0 + (k - 1) * a1) / 5) as u8,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// 4-bit index weights of BC6H and BC7.
|
||||
const WEIGHTS4: [u32; 16] = [0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64];
|
||||
|
||||
/// Index `i` of a one-region block whose 4-bit indices start at bit 65 (index 0 has 3 bits).
|
||||
fn index4(v: u128, i: usize) -> usize {
|
||||
(if i == 0 { bits(v, 65, 3) } else { bits(v, 68 + 4 * (i as u32 - 1), 4) }) as usize
|
||||
}
|
||||
|
||||
/// BC7 mode 6 block → 16 RGBA texels.
|
||||
fn bc7_mode6_texels(b: &[u8]) -> [[u8; 4]; 16] {
|
||||
let v = u128::from_le_bytes(b.try_into().unwrap());
|
||||
assert_eq!(v.trailing_zeros(), 6, "BC7 mode 6");
|
||||
let p = [bits(v, 63, 1), bits(v, 64, 1)];
|
||||
let ep = |c: usize, e: usize| bits(v, 7 + 14 * c as u32 + 7 * e as u32, 7) << 1 | p[e];
|
||||
std::array::from_fn(|i| {
|
||||
let w = WEIGHTS4[index4(v, i)];
|
||||
std::array::from_fn(|c| ((ep(c, 0) * (64 - w) + ep(c, 1) * w + 32) >> 6) as u8)
|
||||
})
|
||||
}
|
||||
|
||||
/// BC6H (UF16) mode 11 block → 16 RGB half-float bit patterns.
|
||||
fn bc6h_mode11_texels(b: &[u8]) -> [[u16; 3]; 16] {
|
||||
let v = u128::from_le_bytes(b.try_into().unwrap());
|
||||
assert_eq!(bits(v, 0, 5), 3, "BC6H mode 11");
|
||||
let unq = |e: u32| match e {
|
||||
0 => 0,
|
||||
1023 => 0xFFFF,
|
||||
_ => ((e << 16) + 0x8000) >> 10,
|
||||
};
|
||||
std::array::from_fn(|i| {
|
||||
let w = WEIGHTS4[index4(v, i)];
|
||||
std::array::from_fn(|c| {
|
||||
let (a, z) = (unq(bits(v, 5 + 10 * c as u32, 10)), unq(bits(v, 35 + 10 * c as u32, 10)));
|
||||
let l = (a * (64 - w) + z * w + 32) >> 6;
|
||||
((l * 31) >> 6) as u16
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bcpack_fill_blocks_are_solid_in_their_bcn_format() {
|
||||
const MAGENTA: [u8; 4] = [255, 0, 255, 255];
|
||||
let b = |m| bcpack_fill_block(m).unwrap();
|
||||
assert_eq!(b(1).len(), 8);
|
||||
assert!(bc1_texels(&b(1), false).iter().all(|t| *t == MAGENTA), "BC1");
|
||||
assert_eq!((b(2).len(), &b(2)[..8]), (16, &[0xFF; 8][..]), "BC2 explicit alpha 15");
|
||||
assert!(bc1_texels(&b(2)[8..], true).iter().all(|t| *t == MAGENTA), "BC2 colour");
|
||||
assert!(bc4_values(&b(3)[..8]).iter().all(|&a| a == 255), "BC3 alpha");
|
||||
assert!(bc1_texels(&b(3)[8..], true).iter().all(|t| *t == MAGENTA), "BC3 colour");
|
||||
assert_eq!(b(4).len(), 8);
|
||||
assert!(bc4_values(&b(4)).iter().all(|&r| r == 255), "BC4");
|
||||
assert!(bc4_values(&b(5)[..8]).iter().all(|&r| r == 255) && bc4_values(&b(5)[8..]).iter().all(|&g| g == 0), "BC5");
|
||||
assert!(bc6h_mode11_texels(&b(6)).iter().all(|t| *t == [0x3C00, 0, 0x3C00]), "BC6H: 1.0, 0, 1.0");
|
||||
assert!(bc7_mode6_texels(&b(7)).iter().all(|t| *t == [255, 1, 255, 255]), "BC7");
|
||||
assert_eq!((bcpack_fill_block(0), bcpack_fill_block(8)), (None, None), "not a BCn mode");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bcpack_refusals_are_counted_per_mode_and_still_fail() {
|
||||
let counts = BcpackRefusals::new();
|
||||
let bc7 = Request::parse(&request(SOURCE_MEMORY_BIT | 7 << BCPACK_SHIFT, 0x1000, 0x10000, 0x2000, 0, 0x4000));
|
||||
let bc7_zlib = Request::parse(&request(SOURCE_MEMORY_BIT | ZLIB_BIT | 7 << BCPACK_SHIFT, 0x1000, 0x10000, 0x2000, 0, 0x4000));
|
||||
let bc1 = Request::parse(&request(SOURCE_MEMORY_BIT | 1 << BCPACK_SHIFT, 0x1000, 0x8000, 0x2000, 0, 0x1000));
|
||||
for (i, r) in [&bc7, &bc7_zlib, &bc1, &bc7].into_iter().enumerate() {
|
||||
assert_eq!(r.check(true), Err(E_DECOMPRESSION), "the request fails as before");
|
||||
assert_eq!(counts.note(r), i as u64 + 1);
|
||||
}
|
||||
let s = counts.stats();
|
||||
assert_eq!(s.keys().collect::<Vec<_>>(), ["BC1", "BC7"]);
|
||||
assert_eq!((s["BC7"].requests, s["BC7"].with_zlib, s["BC7"].destination_bytes), (3, 1, 0x30000));
|
||||
assert_eq!((s["BC1"].requests, s["BC1"].with_zlib, s["BC1"].destination_bytes), (1, 0, 0x8000));
|
||||
assert_eq!(counts.summary(), "BC1 1 (32768 bytes), BC7 3 (196608 bytes)");
|
||||
for m in 1..=7u64 {
|
||||
let r = Request::parse(&request(SOURCE_MEMORY_BIT | m << BCPACK_SHIFT, 0x1000, 64, 0x2000, 0, 20));
|
||||
assert_eq!(r.check(true), Err(E_DECOMPRESSION));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_bcpack_request_is_filled_only_under_the_switch() {
|
||||
unsafe {
|
||||
let mut f = std::ptr::null_mut();
|
||||
assert_eq!(DStorageGetFactory(&IID_FACTORY, &mut f), S_OK);
|
||||
let vt = *(f as *const *const usize);
|
||||
let create_queue: unsafe extern "system" fn(*mut c_void, *const u8, *const GUID, *mut *mut c_void) -> HRESULT = std::mem::transmute(*vt.add(3));
|
||||
let create_status: unsafe extern "system" fn(*mut c_void, u32, *const u8, *const GUID, *mut *mut c_void) -> HRESULT = std::mem::transmute(*vt.add(5));
|
||||
let mut desc = [0u8; 0x18];
|
||||
desc[0..4].copy_from_slice(&1u32.to_le_bytes());
|
||||
desc[8..10].copy_from_slice(&8u16.to_le_bytes());
|
||||
desc[10] = 2;
|
||||
let mut q = std::ptr::null_mut();
|
||||
assert_eq!(create_queue(f, desc.as_ptr(), &IID_QUEUE, &mut q), S_OK);
|
||||
let mut s = std::ptr::null_mut();
|
||||
assert_eq!(create_status(f, 2, std::ptr::null(), &IID_STATUS_ARRAY, &mut s), S_OK);
|
||||
let qv = *(q as *const *const usize);
|
||||
let enqueue: unsafe extern "system" fn(*mut c_void, *const u8) = std::mem::transmute(*qv.add(3));
|
||||
let status: unsafe extern "system" fn(*mut c_void, *mut c_void, u32) = std::mem::transmute(*qv.add(4));
|
||||
let submit: unsafe extern "system" fn(*mut c_void) = std::mem::transmute(*qv.add(6));
|
||||
let sv = *(s as *const *const usize);
|
||||
let complete: unsafe extern "system" fn(*mut c_void, u32) -> bool = std::mem::transmute(*sv.add(3));
|
||||
let hresult: unsafe extern "system" fn(*mut c_void, u32) -> HRESULT = std::mem::transmute(*sv.add(4));
|
||||
let packed = [0x5Au8; 64];
|
||||
let run = |dst: &mut [u8], n: u32, index: u32| {
|
||||
let r = request(SOURCE_MEMORY_BIT | 7 << BCPACK_SHIFT, dst.as_mut_ptr() as u64, n, packed.as_ptr() as u64, 0, packed.len() as u32);
|
||||
enqueue(q, r.as_ptr());
|
||||
status(q, s, index);
|
||||
submit(q);
|
||||
let t = std::time::Instant::now();
|
||||
while !complete(s, index) && t.elapsed().as_secs() < 5 {
|
||||
std::thread::yield_now();
|
||||
}
|
||||
hresult(s, index)
|
||||
};
|
||||
// a BC7 destination of 0x1008 bytes (a part block at the end), then guard bytes
|
||||
let n = 0x1008usize;
|
||||
let mut dst = vec![0xCDu8; n + 64];
|
||||
assert!(!queue(q).bcpack_fill.load(Ordering::Relaxed), "off unless XCL_DSTORAGE_BCPACK_FILL is set");
|
||||
assert_eq!(run(&mut dst, n as u32, 0), E_DECOMPRESSION);
|
||||
assert!(dst.iter().all(|&b| b == 0xCD), "without the switch the destination is left as it was");
|
||||
|
||||
queue(q).bcpack_fill.store(true, Ordering::Relaxed);
|
||||
let before = BCPACK.filled_bytes[7].load(Ordering::Relaxed);
|
||||
assert_eq!(run(&mut dst, n as u32, 1), E_DECOMPRESSION, "the fill does not change the status");
|
||||
let block = bcpack_fill_block(7).unwrap();
|
||||
assert!(dst[..n].chunks(16).all(|c| c == &block[..c.len()]), "solid BC7 blocks up to the destination size");
|
||||
assert!(dst[n..].iter().all(|&b| b == 0xCD), "nothing past the destination size");
|
||||
assert!(BCPACK.filled_bytes[7].load(Ordering::Relaxed) >= before + n as u64);
|
||||
queue_close(q);
|
||||
queue_release(q);
|
||||
status_release(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ pub struct Report {
|
||||
/// XCL slots it called that XCL does not implement
|
||||
#[serde(default)]
|
||||
pub xgameruntime: crate::hle::xgameruntime::api::ApiStats,
|
||||
/// DirectStorage: BCPack requests refused (no decoder) by mode, and bytes filled under
|
||||
/// `XCL_DSTORAGE_BCPACK_FILL`
|
||||
#[serde(default)]
|
||||
pub dstorage: crate::hle::dstorage::DStorageStats,
|
||||
pub notes: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -135,6 +139,7 @@ pub fn build() -> Report {
|
||||
d3d12: crate::hle::d3d12x::real::stats(),
|
||||
audio: crate::hle::xaudio2::stats(),
|
||||
xgameruntime: crate::hle::xgameruntime::api::stats(),
|
||||
dstorage: crate::hle::dstorage::stats(),
|
||||
notes: vec![
|
||||
"D3D12.X methods missing on PC show up in called_stubs as '<Interface>::#slot (not on PC)'.".into(),
|
||||
"Console-format shaders are replaced (fallback_pipelines) until the RDNA2 recompiler is finished.".into(),
|
||||
|
||||
Reference in New Issue
Block a user