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
6 changes: 4 additions & 2 deletions crates/victory-gpu/src/descriptor/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,8 @@ fn view_stride(view: &View) -> u32 {
/// The view-stride table's format-kind bits of a buffer view: a typed view
/// (no structure stride, not raw) of an integer format gets
/// `VIEW_INTEGER`, a signed one also `VIEW_SIGNED`; anything else none.
/// Translated shaders pass 16-bit typed data of such views as bits, not as
/// halves (`victory_shader::emit`, "d16").
/// Translated shaders select integer typed-buffer overloads for such views,
/// and pass their 16-bit typed data as bits (`victory_shader::emit`, "d16").
fn view_kind(view: &View) -> u32 {
use victory_shader::emit::{VIEW_INTEGER, VIEW_SIGNED};
let (unordered, words): (bool, &[u32; 10]) = match view {
Expand Down Expand Up @@ -1801,6 +1801,8 @@ mod tests {
// Format, dimension (buffer), first element, count, stride, counter, flags.
let uav = |format, stride, flags| View::Unordered(0, 0, Some([format, 1, 0, 0, 64, stride, 0, 0, flags, 0]));
assert_eq!(view_kind(&uav(12, 0, 0)), VIEW_INTEGER, "R16G16B16A16_UINT");
assert_eq!(view_kind(&uav(7, 0, 0)), VIEW_INTEGER, "R32G32B32_UINT");
assert_eq!(view_kind(&uav(8, 0, 0)), VIEW_INTEGER | VIEW_SIGNED, "R32G32B32_SINT");
assert_eq!(view_kind(&uav(57, 0, 0)), VIEW_INTEGER, "R16_UINT");
assert_eq!(view_kind(&uav(59, 0, 0)), VIEW_INTEGER | VIEW_SIGNED, "R16_SINT");
assert_eq!(view_kind(&uav(64, 0, 0)), VIEW_INTEGER | VIEW_SIGNED, "R8_SINT");
Expand Down
25 changes: 19 additions & 6 deletions crates/victory-shader/src/emit/bitcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,28 @@ impl Module {
}
}

/// Calls of functions named `name` that [`Module::write`] writes, and the
/// blocks holding them.
#[cfg(test)]
pub fn written_call_blocks(&self, name: &str) -> Vec<usize> {
let plan = self.plan();
let mut blocks = Vec::new();
for &b in &plan.layout {
for &i in &self.blocks[b].body {
if plan.live[i as usize]
&& matches!(self.insts[i as usize].op, Op::Call(f, _) if self.funcs[f as usize].name == name)
{
blocks.push(b);
}
}
}
blocks
}

/// Calls of functions named `name` that [`Module::write`] writes.
#[cfg(test)]
pub fn written_calls(&self, name: &str) -> usize {
let plan = self.plan();
let calls = plan.layout.iter().flat_map(|&b| &self.blocks[b].body);
calls
.filter(|&&i| plan.live[i as usize])
.filter(|&&i| matches!(self.insts[i as usize].op, Op::Call(f, _) if self.funcs[f as usize].name == name))
.count()
self.written_call_blocks(name).len()
}

/// The globals and functions [`Module::write`] declares, each kept
Expand Down
40 changes: 36 additions & 4 deletions crates/victory-shader/src/emit/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@ pub fn under_wine() -> bool {
}

impl Host {
/// Whether this device can create a typed buffer UAV and both load and
/// store through it. D3DMetal advertises RGB32 support but aborts when the
/// view is created, so those formats are skipped on the hardware adapter
/// under Wine; WARP is still queried normally.
pub fn typed_buffer_access(&self, format: DXGI_FORMAT, warp: bool) -> bool {
if !warp && under_wine()
&& matches!(format, DXGI_FORMAT_R32G32B32_FLOAT | DXGI_FORMAT_R32G32B32_UINT | DXGI_FORMAT_R32G32B32_SINT)
{
return false;
}
let mut support = D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: format,
..Default::default()
};
// SAFETY: the query writes the structure of the given size.
let ok = unsafe {
self.device
.CheckFeatureSupport(
D3D12_FEATURE_FORMAT_SUPPORT,
(&raw mut support).cast(),
size_of_val(&support) as u32,
)
.is_ok()
};
ok && support.Support1.contains(D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
&& support.Support2.contains(
D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD | D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE,
)
}

/// Whether the device runs 64-bit atomics on typed resources in the
/// descriptor heap. `victory_gpu` refuses pipelines that need them on
/// devices without (D3DMetal 4.0 beta 3 has none).
Expand Down Expand Up @@ -1361,11 +1391,13 @@ pub enum View<'a> {
#[cfg(test)]
pub fn view_strides(views: &[View]) -> Vec<u32> {
let kind = |f: DXGI_FORMAT| match f {
DXGI_FORMAT_R32G32B32A32_UINT | DXGI_FORMAT_R16G16B16A16_UINT | DXGI_FORMAT_R32G32_UINT
| DXGI_FORMAT_R10G10B10A2_UINT | DXGI_FORMAT_R8G8B8A8_UINT | DXGI_FORMAT_R16G16_UINT
DXGI_FORMAT_R32G32B32A32_UINT | DXGI_FORMAT_R32G32B32_UINT | DXGI_FORMAT_R16G16B16A16_UINT
| DXGI_FORMAT_R32G32_UINT | DXGI_FORMAT_R10G10B10A2_UINT | DXGI_FORMAT_R8G8B8A8_UINT
| DXGI_FORMAT_R16G16_UINT
| DXGI_FORMAT_R32_UINT | DXGI_FORMAT_R8G8_UINT | DXGI_FORMAT_R16_UINT | DXGI_FORMAT_R8_UINT => super::VIEW_INTEGER,
DXGI_FORMAT_R32G32B32A32_SINT | DXGI_FORMAT_R16G16B16A16_SINT | DXGI_FORMAT_R32G32_SINT
| DXGI_FORMAT_R8G8B8A8_SINT | DXGI_FORMAT_R16G16_SINT | DXGI_FORMAT_R32_SINT
DXGI_FORMAT_R32G32B32A32_SINT | DXGI_FORMAT_R32G32B32_SINT | DXGI_FORMAT_R16G16B16A16_SINT
| DXGI_FORMAT_R32G32_SINT | DXGI_FORMAT_R8G8B8A8_SINT | DXGI_FORMAT_R16G16_SINT
| DXGI_FORMAT_R32_SINT
| DXGI_FORMAT_R8G8_SINT | DXGI_FORMAT_R16_SINT | DXGI_FORMAT_R8_SINT => super::VIEW_INTEGER | super::VIEW_SIGNED,
_ => 0,
};
Expand Down
Loading