mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
D3D12.X: constant buffer views are float4 rows (stride 16), not raw buffers
CreateConstantBufferView wrote every CBV as a raw V# (stride 0, num_records in bytes). Console shaders index constant-buffer arrays with buffer_load_* idxen and the row as the index; with stride 0 the index is ignored, so every row read returns row 0. A retail game's UI element shader reads its transform as two such rows: with both equal, every vertex lands on x = y and the UI collapses onto the screen's diagonal (#175, #307). Where the title writes this descriptor itself, it writes stride 16 and num_records = size / 16. desc::cbv_words: stride 16, num_records = ceil(size / 16). Loads by byte offset read the same addresses as before; scalar loads keep their byte limit (num_records x stride). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -365,6 +365,16 @@ pub fn buffer(w: &[u32; 4]) -> Buffer {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cbv_is_float4_rows() {
|
||||
let v = buffer(&cbv_words(0x4_4E10_DC00, 0x600));
|
||||
assert_eq!((v.address, v.stride, v.num_records, v.format), (0x4_4E10_DC00, 16, 0x60, 77));
|
||||
// an idxen load of row n reads base + 16 n; the scalar-load limit stays the view's size
|
||||
assert_eq!(v.num_records * v.stride, 0x600);
|
||||
// a size that is not a whole number of rows still covers its last bytes
|
||||
assert_eq!(buffer(&cbv_words(0x1000, 0x608)).num_records, 0x61);
|
||||
}
|
||||
|
||||
/// T# of a 2D BGRA-swizzled RGBA8 texture, 256×128, 8 mips, view of mips 1..3.
|
||||
fn tsharp() -> [u32; 8] {
|
||||
let (w, h) = (256u32 - 1, 128u32 - 1);
|
||||
@@ -655,6 +665,16 @@ pub fn format_bytes(f: u32) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// A V# for a constant buffer view: 16-byte elements (one float4 row each), num_records in
|
||||
/// rows, as the console writes it (a title that writes this descriptor itself writes stride 16
|
||||
/// and size / 16). Console shaders index constant-buffer arrays with `buffer_load_* … idxen`
|
||||
/// and the row as the index, which a stride of 0 ignores (every row would read row 0). Loads by
|
||||
/// byte offset read the same addresses as with a raw V#, and scalar loads keep their byte limit
|
||||
/// (num_records × stride).
|
||||
pub fn cbv_words(address: u64, size: u32) -> [u32; 4] {
|
||||
buffer_words(address, 16, size.div_ceil(16), 77)
|
||||
}
|
||||
|
||||
/// A V# for a buffer view: `stride` 0 = raw (num_records in bytes), else structured / typed
|
||||
/// (num_records in elements); `format` = GFX10 format for typed loads (raw: 32_FLOAT).
|
||||
pub fn buffer_words(address: u64, stride: u32, num_records: u32, format: u32) -> [u32; 4] {
|
||||
|
||||
@@ -1752,8 +1752,9 @@ fn note_buffer_view() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #17 CreateConstantBufferView: a raw V# of the buffer's console address (unified memory;
|
||||
/// anything else gets an empty V#). No PC CBV: translated shaders read buffers through `mem`.
|
||||
/// #17 CreateConstantBufferView: a V# of float4 rows at the buffer's console address
|
||||
/// (`desc::cbv_words`; unified memory, anything else gets an empty V#). No PC CBV: translated
|
||||
/// shaders read buffers through `mem`.
|
||||
unsafe extern "system" fn dev_create_cbv_x(this: *mut c_void, desc: *const D3D12_CONSTANT_BUFFER_VIEW_DESC, cpu: u64) {
|
||||
let Some(slot) = super::console_heap::slot(cpu).filter(|s| !s.sampler) else {
|
||||
let f: unsafe extern "system" fn(*mut c_void, *const D3D12_CONSTANT_BUFFER_VIEW_DESC, u64) = std::mem::transmute(orig_fn(this, 17));
|
||||
@@ -1765,7 +1766,7 @@ unsafe extern "system" fn dev_create_cbv_x(this: *mut c_void, desc: *const D3D12
|
||||
note_buffer_view();
|
||||
}
|
||||
let (va, size) = if in_uma { (va, size) } else { (0, 0) };
|
||||
super::console_heap::write(&slot, &crate::gpu::desc::buffer_words(va, 0, size, 22));
|
||||
super::console_heap::write(&slot, &crate::gpu::desc::cbv_words(va, size));
|
||||
}
|
||||
|
||||
/// #22 CreateSampler: the PC sampler at the slot's index, the S# in XCL ABI form (word 3
|
||||
|
||||
Reference in New Issue
Block a user