Shaders: normalized buffer codes give the nearest float, cube gradients take DXIL's base-2 logarithm, d16 data of integer views keeps its bits, unordered views of vertex programs are declared

- VIctory da82e444: the host's division was a step off for some codes, and a
  material index cut from one was the code below.
- DexNom/VIctory 921d8d3b (its cube part, with its test): the level was taken
  from a natural logarithm DXIL does not have, 1.44 times too high; the
  instruction's least level was lost.
- VIctory 4243a96a, for buffers a program picks from the heap.
- VIctory a1a2077a.
Every shader is translated anew.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 10:50:14 -06:00
1 parent 350c686481
commit 9a6c829d68
9 files changed
+501 -36

No files matched your search

+15 -11
View File
@@ -994,8 +994,8 @@ fn transition(
pub enum View<'a> {
/// An RGBA32F texture SRV (width, height, texels).
Texture(u32, u32, &'a [[f32; 4]]),
/// An RGBA32F cube SRV (face size, texels of faces +x -x +y -y +z -z).
Cube(u32, &'a [[f32; 4]]),
/// An RGBA32F cube SRV (face size, mip count, texels in D3D subresource order).
Cube(u32, u16, &'a [[f32; 4]]),
/// A raw buffer UAV of this many dwords, zeroed.
RawUav(u32),
/// An RGBA32F texture UAV (width, height), zeroed.
@@ -1170,20 +1170,23 @@ impl Host {
at.ptr += i * view_size;
match *v {
View::Texture(..) | View::Cube(..) => {
let (w, h, texels, faces) = match *v {
View::Texture(w, h, t) => (w, h, t, 1),
View::Cube(n, t) => (n, n, t, 6),
let (w, h, mut texels, faces, mips) = match *v {
View::Texture(w, h, t) => (w, h, t, 1, 1),
View::Cube(n, mips, t) => (n, n, t, 6, mips),
_ => unreachable!(),
};
let mut desc = texture(w, h, D3D12_RESOURCE_FLAG_NONE);
desc.DepthOrArraySize = faces as u16;
desc.MipLevels = mips;
let tex = make(
D3D12_HEAP_TYPE_DEFAULT,
&desc,
D3D12_RESOURCE_STATE_COPY_DEST,
)?;
let pitch = (w as usize * 16).next_multiple_of(256);
for face in 0..faces as usize {
for sub in 0..u32::from(mips) * faces {
let mip = sub % u32::from(mips);
let (w, h) = ((w >> mip).max(1), (h >> mip).max(1));
let pitch = (w as usize * 16).next_multiple_of(256);
let upload = make(
D3D12_HEAP_TYPE_UPLOAD,
&buffer((pitch * h as usize) as u64, D3D12_RESOURCE_FLAG_NONE),
@@ -1191,9 +1194,10 @@ impl Host {
)?;
let mut p = std::ptr::null_mut();
upload.Map(0, None, Some(&mut p)).map_err(err)?;
let texels = &texels[face * (w * h) as usize..];
let (level, rest) = texels.split_at((w * h) as usize);
texels = rest;
for y in 0..h as usize {
let row = &texels[y * w as usize..(y + 1) * w as usize];
let row = &level[y * w as usize..(y + 1) * w as usize];
std::ptr::copy_nonoverlapping(
row.as_ptr().cast::<u8>(),
p.cast::<u8>().add(y * pitch),
@@ -1202,7 +1206,7 @@ impl Host {
}
upload.Unmap(0, None);
let mut at_face = subresource(&tex);
at_face.Anonymous.SubresourceIndex = face as u32;
at_face.Anonymous.SubresourceIndex = sub;
list.CopyTextureRegion(
&at_face,
0,
@@ -1224,7 +1228,7 @@ impl Host {
Shader4ComponentMapping: D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING,
Anonymous: D3D12_SHADER_RESOURCE_VIEW_DESC_0 {
TextureCube: D3D12_TEXCUBE_SRV {
MipLevels: 1,
MipLevels: u32::from(mips),
..Default::default()
},
},