Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion crates/xcl/src/gpu/dxil/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ fn translate_entry(code: &[u8], o: KernelOptions, entry: Entry) -> Result<Kernel
/// (as the HLSL compute mode's `globallycoherent` windows).
fn mem_windows(s: &mut Shader, mem_windows: u32, coherent: bool) -> (Vec<RawUav>, Option<bool>) {
let heap = mem_windows & crate::gpu::recomp::HEAP_WINDOWS != 0;
let n = (mem_windows & !crate::gpu::recomp::HEAP_WINDOWS).clamp(1, 4);
let max = if heap { crate::gpu::uma::MAX_HEAP_WINDOWS as u32 } else { crate::gpu::uma::MAX_WINDOWS as u32 };
let n = (mem_windows & !crate::gpu::recomp::HEAP_WINDOWS).clamp(1, max);
if heap && n > 1 {
let z = s.m.i32c(0);
return (vec![RawUav { handle: z, binding: None }; n as usize], Some(coherent));
Expand Down
5 changes: 3 additions & 2 deletions crates/xcl/src/gpu/recomp/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4243,10 +4243,11 @@ impl Em {
// other groups wrote) relies on GLC / cache invalidation on the console: keep the flat
// memory coherent across the GPU there; graphics keeps the cached (faster) view
let coherent = if matches!(self.opt.mode, Mode::Compute(_)) { "globallycoherent " } else { "" };
let windows = self.opt.mem_windows.clamp(1, 4);
let max_win = if self.opt.heap_windows { crate::gpu::uma::MAX_HEAP_WINDOWS as u32 } else { crate::gpu::uma::MAX_WINDOWS as u32 };
let windows = self.opt.mem_windows.clamp(1, max_win);
let _ = writeln!(h, "{coherent}RWByteAddressBuffer mem : register(u2);");
if windows > 1 {
for k in 1..windows {
for k in 1..windows.min(crate::gpu::uma::MAX_WINDOWS as u32) {
let _ = writeln!(h, "{coherent}RWByteAddressBuffer mem{k} : register(u{});", 2 + k);
}
h.push_str("static uint xcl_w = 0u;\nstatic uint xcl_uma_base = 0u;\n");
Expand Down
8 changes: 8 additions & 0 deletions crates/xcl/src/gpu/recomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ pub const MEM_HEAP_BASE: u32 = 0;
/// Flag in a memory-windows count (`pso::mem_windows`, the translation caches' keys):
/// `Options::heap_windows`. `translate` takes it out of `mem_windows`.
pub const HEAP_WINDOWS: u32 = 0x100;

pub(crate) fn valid_window_count(windows: usize, heap: bool) -> bool {
windows <= crate::gpu::uma::MAX_WINDOWS
|| (heap && windows.is_power_of_two() && windows <= crate::gpu::uma::MAX_HEAP_WINDOWS)
}
pub mod upper_lanes;

use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -1397,6 +1402,9 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
} else {
opt
};
if !valid_window_count(opt.mem_windows as usize, opt.heap_windows) {
return Err(format!("unsupported shader memory layout: {} windows (heap: {})", opt.mem_windows, opt.heap_windows));
}
let mut insts: Vec<Decoded> = Vec::new();
let mut off = 0usize;
while off + 4 <= code.len() {
Expand Down
10 changes: 6 additions & 4 deletions crates/xcl/src/gpu/recomp/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,16 +1516,17 @@ fn run_in_region(dxil: &[u8], state: &KernelState, arena: &Arena) -> Result<Kern
}
// the windows as raw UAVs at MEM_HEAP_BASE.. of a shader-visible heap
// (`Options::heap_windows`; programs with the root-UAV switch ignore it)
let win_count = arena.windows.len().clamp(crate::gpu::uma::MAX_WINDOWS, crate::gpu::uma::MAX_HEAP_WINDOWS);
let dh: ID3D12DescriptorHeap = dev
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
NumDescriptors: super::MEM_HEAP_BASE + 4,
NumDescriptors: super::MEM_HEAP_BASE + win_count as u32,
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
NodeMask: 0,
})
.map_err(e)?;
let inc = dev.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) as usize;
for k in 0..4usize {
for k in 0..win_count {
let (b, size) = bufs.get(k).map_or((&mem_buf, arena.windows[0].1), |b| (b, arena.windows[k].1));
let mut h = dh.GetCPUDescriptorHandleForHeapStart();
h.ptr += (super::MEM_HEAP_BASE as usize + k) * inc;
Expand Down Expand Up @@ -1679,16 +1680,17 @@ fn dispatch_with(
// A PSO built by the backend's hook uses the runtime's window count: with heap windows
// (`Options::heap_windows`) its accesses go to ResourceDescriptorHeap[MEM_HEAP_BASE + w],
// so every window slot is a raw view of `mem` (no textures here to share the heap with).
let win_count = crate::gpu::uma::MAX_HEAP_WINDOWS;
let dh: ID3D12DescriptorHeap = dev
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
NumDescriptors: super::MEM_HEAP_BASE + 4,
NumDescriptors: super::MEM_HEAP_BASE + win_count as u32,
Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
NodeMask: 0,
})
.map_err(e)?;
let inc = dev.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) as usize;
for k in 0..4usize {
for k in 0..win_count {
let mut h = dh.GetCPUDescriptorHandleForHeapStart();
h.ptr += (super::MEM_HEAP_BASE as usize + k) * inc;
dev.CreateUnorderedAccessView(&mem_buf, None::<&ID3D12Resource>, Some(&raw_window_uav(mem_bytes)), h);
Expand Down
Loading
Loading