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
8 changes: 7 additions & 1 deletion runtime/d3d12/src/commands/compute_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl Bindings {
let mut storage = [None; 64]; // no root signature can consume more than 64 DWORDs
let bases = storage.get_mut(..table.lengths.len()).ok_or(E_INVALIDARG)?;
for (index, &length) in table.lengths.iter().enumerate().filter(|(_, len)| **len != 0) {
let slot = index as u32;
let slot = table.mirrors.iter().find(|(host, _)| *host as usize == index).map_or(index as u32, |&(_, guest)| guest);
let bound = if COMPUTE {
let Some(Argument::Table(table)) = self.compute_args.get(&slot) else { return Err(E_INVALIDARG.into()); };
table
Expand Down Expand Up @@ -308,6 +308,12 @@ impl Bindings {
let base = bases.get(slot as usize).copied().flatten().unwrap_or(bound.native);
list.SetGraphicsRootDescriptorTable(slot, base);
}
for &(host, guest) in &table.mirrors {
if let Some(bound) = self.graphics_tables.get(&guest) {
let base = bases.get(host as usize).copied().flatten().unwrap_or(bound.native);
list.SetGraphicsRootDescriptorTable(host, base);
}
}
if let Some((slot, address)) = index_map {
list.SetGraphicsRootShaderResourceView(slot, address);
static IDENTITY: std::sync::Once = std::sync::Once::new();
Expand Down
5 changes: 5 additions & 0 deletions runtime/d3d12/src/device/compute_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub(crate) struct ComputeTable {
pub(crate) lengths: Vec<u32>,
pub(crate) accessed_views: Vec<(usize, std::ops::Range<u32>)>,
pub(crate) index_map: Option<IndexMapBinding>,
/// LOCAL: appended host parameters that bind the same guest table
/// (host index, guest slot), e.g. a pixel-only copy of a mesh-rewritten table.
pub(crate) mirrors: Vec<(u32, u32)>,
}

#[derive(Clone, Copy)]
Expand Down Expand Up @@ -268,6 +271,7 @@ pub(super) fn reflected(
lengths: lengths.into(),
accessed_views,
index_map,
mirrors: Vec::new(),
})))
}
}
Expand Down Expand Up @@ -368,6 +372,7 @@ fn append_corroborated_ranges(
lengths,
accessed_views,
index_map: None,
mirrors: Vec::new(),
})))
}
}
Expand Down
46 changes: 40 additions & 6 deletions runtime/d3d12/src/device/mesh_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub(super) fn reflected(
accessed_views.push((binding.parameter, slot..end));
}
}
// Guest tables the pixel stage reads but the mesh layout rewrote. Each gets
// an appended pixel-only copy of its original ranges (see `mirrors`).
let mut mirrored = Vec::new();
if let Some(pixel) = pixel {
collect_pixel_accesses(&root, &layout, pixel, &mut lengths, &mut accessed_views)?;
collect_pixel_accesses(&root, &layout, pixel, &mut lengths, &mut accessed_views, &mut mirrored)?;
}
let bytes = original.serialized();
// SAFETY: the deserializer owns the source pointers throughout serialization.
Expand All @@ -58,6 +61,7 @@ pub(super) fn reflected(
return Err(E_INVALIDARG.into());
}
let mut params = std::slice::from_raw_parts(source.pParameters, root.params.len()).to_vec();
let originals = params.clone();
let mut range_storage = vec![Vec::new(); params.len()];
for (index, change) in layout.replacements {
let parameter = &mut params[index];
Expand Down Expand Up @@ -111,6 +115,20 @@ pub(super) fn reflected(
}
}
}
let mut mirrors = Vec::new();
for &guest in &mirrored {
let mut copy = originals[guest];
if copy.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE {
return Err(E_NOTIMPL.into());
}
copy.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
mirrors.push((params.len() as u32, guest as u32));
params.push(copy);
}
if lengths.len() < params.len() {
lengths.resize(params.len(), 0);
}
desc.Anonymous.Desc_1_1.NumParameters = params.len() as u32;
desc.Anonymous.Desc_1_1.pParameters = params.as_ptr();
let mut blob = None;
D3D12SerializeVersionedRootSignature(&desc, &mut blob, None)?;
Expand All @@ -124,6 +142,7 @@ pub(super) fn reflected(
lengths,
accessed_views,
index_map: None,
mirrors,
})))
}
}
Expand All @@ -132,8 +151,9 @@ fn collect_pixel_accesses(
root: &RootSig,
mesh: &MeshLayout,
pixel: &[u8],
lengths: &mut [u32],
lengths: &mut Vec<u32>,
views: &mut Vec<(usize, Range<u32>)>,
mirrored: &mut Vec<usize>,
) -> Result<()> {
for [ty, space, low, high] in shader_resources(pixel).ok_or(E_NOTIMPL)? {
let kind = match ty {
Expand Down Expand Up @@ -170,14 +190,28 @@ fn collect_pixel_accesses(
if from >= to {
continue;
}
if rewritten {
return Err(E_NOTIMPL.into());
// A rewritten table is mesh-only; the pixel stage reads
// its appended original copy at `target`.
let target = if rewritten {
let position = match mirrored.iter().position(|&m| m == index) {
Some(position) => position,
None => {
mirrored.push(index);
mirrored.len() - 1
}
};
root.params.len() + position
} else {
index
};
if lengths.len() <= target {
lengths.resize(target + 1, 0);
}
let start = u32::try_from(start + (from - base)).map_err(|_| E_NOTIMPL)?;
let end = start.checked_add((to - from) as u32).ok_or(E_NOTIMPL)?;
lengths[index] = lengths[index].max(end);
lengths[target] = lengths[target].max(end);
if kind != 2 {
views.push((index, start..end));
views.push((target, start..end));
}
}
}
Expand Down
Loading