Raw twins of views off dwords are moved there too, not null

4.6 twins a frame of run crash-3 were null because they begin off a dword (16
bit values at an odd one); the typed view they stand for begins there as well.
Measured (raw_loads_past_views): a raw view moved on by 8 bytes gives the
bytes from there and ends where it should, uniform and per lane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 05:44:04 -06:00
1 parent 6ee5b724e5
commit 6fa0bbe02f
2 files changed
+42 -5

No files matched your search

+5 -3
View File
@@ -2848,8 +2848,10 @@ pub(crate) static TWINS: [std::sync::atomic::AtomicU64; 3] = [const { std::sync:
/// no raw view. An AMD descriptor of a raw buffer is its address (48 bits),
/// its bytes and flags; only one that says just that is changed, and only
/// where what the handle points at is the descriptor. False: not moved.
fn move_raw(at: D3D12_CPU_DESCRIPTOR_HANDLE, start: u64, bytes: u32, by: u32) -> bool {
if !by.is_multiple_of(4) || by >= bytes {
pub(crate) fn move_raw(at: D3D12_CPU_DESCRIPTOR_HANDLE, start: u64, bytes: u32, by: u32) -> bool {
// (Off dwords too, as the typed view it stands for begins there: a view
// of 16 bit values at an odd one.)
if by >= bytes {
return false;
}
let mut words = [0u8; 16];
@@ -4003,7 +4005,7 @@ mod tests {
let before = words();
assert!(!move_raw(at, start + 16, 400, 8), "another address");
assert!(!move_raw(at, start, 404, 8), "another size");
assert!(!move_raw(at, start, 400, 2), "not a dword");
assert!(!move_raw(at, start, 400, 400), "nothing left");
assert_eq!(words(), before);
if move_raw(at, start, 400, 8) {
let moved = words();
+37 -2
View File
@@ -1035,7 +1035,7 @@ void main(uint3 id : SV_DispatchThreadID, uint g : SV_GroupIndex) {
gpu.device.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) as usize,
)
};
let names = ["raw", "structured 24 at 24", "structured 16", "typed u32", "typed u16", "typed 4 x u32", "constant buffer", "null raw"];
let names = ["raw", "structured 24 at 24", "structured 16", "typed u32", "typed u16", "typed 4 x u32", "constant buffer", "raw, moved to 8"];
let view = |i: usize, format: i32, first: u64, count: u32, stride: u32, raw: bool, null: bool| {
let desc = D3D12_SHADER_RESOURCE_VIEW_DESC {
Format: DXGI_FORMAT(format),
@@ -1061,7 +1061,42 @@ void main(uint3 id : SV_DispatchThreadID, uint g : SV_GroupIndex) {
view(base + 3, 42, 0, 1024, 0, false, false);
view(base + 4, 57, 0, 2048, 0, false, false);
view(base + 5, 3, 0, 256, 0, false, false);
view(base + 7, 39, 0, 1, 0, true, true);
// 1,024 dwords from 0 made in a heap the card does not see, moved
// on by 8 bytes (`descriptor::host::move_raw`), copied in.
// SAFETY: plain heap creation, slots of live heaps.
unsafe {
let beside: ID3D12DescriptorHeap = gpu
.device
.CreateDescriptorHeap(&D3D12_DESCRIPTOR_HEAP_DESC {
Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
NumDescriptors: 1,
..Default::default()
})
.unwrap();
let at = beside.GetCPUDescriptorHandleForHeapStart();
let desc = D3D12_SHADER_RESOURCE_VIEW_DESC {
Format: DXGI_FORMAT(39),
ViewDimension: D3D12_SRV_DIMENSION_BUFFER,
Shader4ComponentMapping: D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING,
Anonymous: D3D12_SHADER_RESOURCE_VIEW_DESC_0 {
Buffer: D3D12_BUFFER_SRV {
FirstElement: 0,
NumElements: 1024,
StructureByteStride: 0,
Flags: D3D12_BUFFER_SRV_FLAG_RAW,
},
},
};
gpu.device.CreateShaderResourceView(&buffer, Some(&desc), at);
let moved = crate::descriptor::host::move_raw(at, buffer.GetGPUVirtualAddress(), 4096, 8);
println!("the raw view was moved: {moved}");
gpu.device.CopyDescriptorsSimple(
1,
D3D12_CPU_DESCRIPTOR_HANDLE { ptr: cpu + (base + 7) * step },
at,
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
);
}
let desc = D3D12_CONSTANT_BUFFER_VIEW_DESC {
// SAFETY: a live buffer.
BufferLocation: unsafe { buffer.GetGPUVirtualAddress() },