Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions crates/xcl/src/hle/d3d12x/device_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,13 @@ pub fn pc_resource_desc(x: &[u8; 0x38]) -> [u8; 0x38] {
if matches!(format, 86 | 115) && flags & 5 != 0 {
d[0x20..0x24].copy_from_slice(&28u32.to_le_bytes());
}
// R9G9B9E5_SHAREDEXP targets / UAVs: PC D3D12 forbids ALLOW_RENDER_TARGET and
// ALLOW_UNORDERED_ACCESS on format 67 (Series S 1920x1080 target, flags 0x300005:
// E_INVALIDARG) – R11G11B10_FLOAT is the same 32 bpp unsigned HDR float format with full
// PC RTV/UAV/SRV support. Sampled-only R9G9B9E5 textures stay format 67.
if format == 67 && flags & 5 != 0 {
d[0x20..0x24].copy_from_slice(&26u32.to_le_bytes());
}
// a depth buffer the console also lets shaders write (a retail game's: ALLOW_DEPTH_STENCIL |
// ALLOW_UNORDERED_ACCESS): the PC refuses the pair – the depth buffer stays
if flags & 2 != 0 {
Expand Down Expand Up @@ -711,10 +718,11 @@ fn depth_typeless(f: u32) -> Option<u32> {
}

/// The format of a render target / depth view or pipeline on the PC: `pc_view_format`, and a
/// B5G5R5A1 / B4G4R4A4 target is R8G8B8A8 (`pc_resource_desc`).
/// B5G5R5A1 / B4G4R4A4 target is R8G8B8A8, an R9G9B9E5 target is R11G11B10_FLOAT (`pc_resource_desc`).
pub fn pc_target_format(f: u32) -> u32 {
match f {
86 | 115 => 28,
67 => 26,
f => pc_view_format(f),
}
}
Expand All @@ -737,6 +745,8 @@ pub fn pc_shader_view_format(resource: u32, view: u32) -> u32 {
(53 | 55, 0 | 53 | 55) => 56,
// a target made R8G8B8A8 (`pc_resource_desc`)
(28, 86 | 115) => 28,
// a target made R11G11B10_FLOAT (`pc_resource_desc`)
(26, 67) => 26,
(_, v) => v,
}
}
Expand Down Expand Up @@ -1063,6 +1073,11 @@ mod tests {
x[0x20] = 86; // B5G5R5A1 target that is also a UAV
x[0x30..0x34].copy_from_slice(&0x5u32.to_le_bytes());
assert_eq!(desc(&x), (28, 0x5));
x[0x20] = 67; // R9G9B9E5_SHAREDEXP target + UAV
x[0x30..0x34].copy_from_slice(&0x30_0005u32.to_le_bytes());
assert_eq!(desc(&x), (26, 0x5));
x[0x30..0x34].copy_from_slice(&0x0u32.to_le_bytes()); // sampled-only R9G9B9E5 stays format 67
assert_eq!(desc(&x), (67, 0));
// views: a D24S8 format or R16_UNORM of the D16S8 buffer read depth; stencil formats plane 1
assert_eq!(pc_shader_view_format(44, 45), 46);
assert_eq!(pc_shader_view_format(44, 56), 46);
Expand All @@ -1073,7 +1088,9 @@ mod tests {
assert_eq!(pc_shader_view_format(19, 62), 22);
assert_eq!(pc_shader_view_format(28, 86), 28);
assert_eq!(pc_shader_view_format(86, 86), 86, "a B5G5R5A1 texture that stayed one");
assert_eq!((pc_target_format(86), pc_target_format(118), pc_view_format(117)), (28, 45, 10));
assert_eq!(pc_shader_view_format(26, 67), 26);
assert_eq!(pc_shader_view_format(67, 67), 67, "a sampled-only R9G9B9E5 texture that stayed one");
assert_eq!((pc_target_format(86), pc_target_format(67), pc_target_format(118), pc_view_format(117)), (28, 26, 45, 10));
}

#[test]
Expand Down
Loading