Upstream graphics state fixes: rectangle attributes, sampler bounds, A8 copies, depth footprints
Ports of 6f36cdf (normalized attributes of rectangle lists), 97c8783 (A8_UNORM is not of the R8 typeless family), b956320 (copy footprints of depth-stencil textures), c1c3281 (the descriptor ring's wrap), e6fe8ec and e34cb53 (CreateSamplerX bounds), 691236d (appended elements are aligned). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
6acade55fe
commit
fa97cdb3fe
5 files changed
+344
-30
No files matched your search
@@ -296,13 +296,19 @@ impl GraphicsState {
|
||||
.map(|e| {
|
||||
let slot = e.InputSlot.min(31) as usize;
|
||||
let format = e.Format.0 as u32;
|
||||
let bytes = crate::resource::element(format).map_or(0, |(b, _)| b as u32);
|
||||
// An appended element starts at the next multiple of
|
||||
// min(4, its size) after the previous one, where D3D12 (and
|
||||
// vkd3d) place it; the host pipeline gets the title's
|
||||
// descriptions, so the offsets read here must match.
|
||||
let offset = if e.AlignedByteOffset == D3D12_APPEND_ALIGNED_ELEMENT {
|
||||
next[slot]
|
||||
.checked_next_multiple_of(bytes.clamp(1, 4))
|
||||
.unwrap_or(u32::MAX)
|
||||
} else {
|
||||
e.AlignedByteOffset
|
||||
};
|
||||
let bytes = crate::resource::element(format).map_or(0, |(b, _)| b as u32);
|
||||
next[slot] = offset + bytes;
|
||||
next[slot] = offset.saturating_add(bytes);
|
||||
Input {
|
||||
slot: slot as u32,
|
||||
offset,
|
||||
@@ -1444,4 +1450,63 @@ mod tests {
|
||||
assert_eq!(run_draw(0.6, 1.0), 0, "depth 0.5 outside [0.6, 1.0] must be rejected");
|
||||
assert_eq!(run_draw(0.4, 0.6), 255, "depth 0.5 inside [0.4, 0.6] must pass");
|
||||
}
|
||||
|
||||
fn element(format: DXGI_FORMAT, offset: u32) -> D3D12_INPUT_ELEMENT_DESC {
|
||||
D3D12_INPUT_ELEMENT_DESC {
|
||||
SemanticName: PCSTR(c"TEXCOORD".as_ptr().cast()),
|
||||
SemanticIndex: 0,
|
||||
Format: format,
|
||||
InputSlot: 0,
|
||||
AlignedByteOffset: offset,
|
||||
InputSlotClass: D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA,
|
||||
InstanceDataStepRate: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn offsets(inputs: &[D3D12_INPUT_ELEMENT_DESC]) -> Vec<u32> {
|
||||
let state = GraphicsState {
|
||||
inputs: inputs.to_vec(),
|
||||
..GraphicsState::default()
|
||||
};
|
||||
state.elements().iter().map(|e| e.offset).collect()
|
||||
}
|
||||
|
||||
/// An appended element after one of 1 or 2 bytes started right after
|
||||
/// it; D3D12 aligns it to min(4, its size), so the rectangle expansion
|
||||
/// read its vertices from the wrong bytes.
|
||||
#[test]
|
||||
fn appended_elements_are_aligned() {
|
||||
const APPEND: u32 = D3D12_APPEND_ALIGNED_ELEMENT;
|
||||
// RG8 (2 bytes) then RG32 float: 4, not 2.
|
||||
let a = [
|
||||
element(DXGI_FORMAT_R8G8_UNORM, 0),
|
||||
element(DXGI_FORMAT_R32G32_FLOAT, APPEND),
|
||||
];
|
||||
assert_eq!(offsets(&a), [0, 4]);
|
||||
// R8 then R16 float: 2, not 1; then R8 packs right after it.
|
||||
let b = [
|
||||
element(DXGI_FORMAT_R8_UNORM, 0),
|
||||
element(DXGI_FORMAT_R16_FLOAT, APPEND),
|
||||
element(DXGI_FORMAT_R8_UNORM, APPEND),
|
||||
];
|
||||
assert_eq!(offsets(&b), [0, 2, 4]);
|
||||
// Already aligned layouts are unchanged.
|
||||
let c = [
|
||||
element(DXGI_FORMAT_R8G8B8A8_UNORM, 0),
|
||||
element(DXGI_FORMAT_R32G32_FLOAT, APPEND),
|
||||
element(DXGI_FORMAT_R32G32B32_FLOAT, APPEND),
|
||||
];
|
||||
assert_eq!(offsets(&c), [0, 4, 12]);
|
||||
}
|
||||
|
||||
/// An explicit offset near 4 GiB overflowed the next appended offset
|
||||
/// (a panic in debug builds).
|
||||
#[test]
|
||||
fn a_huge_explicit_offset_does_not_overflow() {
|
||||
let inputs = [
|
||||
element(DXGI_FORMAT_R32G32B32A32_FLOAT, u32::MAX - 8),
|
||||
element(DXGI_FORMAT_R32_FLOAT, D3D12_APPEND_ALIGNED_ELEMENT),
|
||||
];
|
||||
let _ = offsets(&inputs);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user