GPU: a view moved to the first level with tiles keeps its minimum level
`ResourceMinLODClamp` is measured from mip 0 of the resource, not from the view's first level, so moving a view's start must not shift it. The test now samples the same resident level through the adjusted and the original view instead of expecting the adjusted one to read level 1. Ported from fxceless/victory-fork 41f9857 (fork pull request #1210). (cherry picked from commit 4bdf2b31f95f099091aa192791685ff2ba0c14ce)
This commit is contained in:
1 parent
1d3b4143ab
commit
d8b258a455
1 file changed
+22
-23
@@ -649,13 +649,13 @@ impl Drop for Tiled {
|
|||||||
/// Keeps a two-dimensional shader view (2D or 2D array) from the levels
|
/// Keeps a two-dimensional shader view (2D or 2D array) from the levels
|
||||||
/// before `first` of a texture of `levels` levels: it starts at `first` if
|
/// before `first` of a texture of `levels` levels: it starts at `first` if
|
||||||
/// it started before it, shows as many levels fewer (clamped to the
|
/// it started before it, shows as many levels fewer (clamped to the
|
||||||
/// remaining levels), and reduces `ResourceMinLODClamp` by the same shift so
|
/// remaining levels). `ResourceMinLODClamp` is measured from mip 0 of the
|
||||||
/// the effective minimum LOD stays at the same resource level.
|
/// resource, so moving the start of the view preserves that field.
|
||||||
pub(crate) fn show_from(desc: &mut D3D12_SHADER_RESOURCE_VIEW_DESC, first: u32, levels: u32) {
|
pub(crate) fn show_from(desc: &mut D3D12_SHADER_RESOURCE_VIEW_DESC, first: u32, levels: u32) {
|
||||||
if first >= levels {
|
if first >= levels {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let clamp = |most: &mut u32, mips: &mut u32, min_lod: &mut f32| {
|
let clamp = |most: &mut u32, mips: &mut u32| {
|
||||||
if first <= *most {
|
if first <= *most {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -664,20 +664,17 @@ pub(crate) fn show_from(desc: &mut D3D12_SHADER_RESOURCE_VIEW_DESC, first: u32,
|
|||||||
if *mips != u32::MAX {
|
if *mips != u32::MAX {
|
||||||
*mips = mips.saturating_sub(fewer).clamp(1, levels - first);
|
*mips = mips.saturating_sub(fewer).clamp(1, levels - first);
|
||||||
}
|
}
|
||||||
if *min_lod > 0.0 {
|
|
||||||
*min_lod = (*min_lod - fewer as f32).max(0.0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
match desc.ViewDimension {
|
match desc.ViewDimension {
|
||||||
D3D12_SRV_DIMENSION_TEXTURE2D => {
|
D3D12_SRV_DIMENSION_TEXTURE2D => {
|
||||||
// SAFETY: `ViewDimension` selects `Texture2D`.
|
// SAFETY: `ViewDimension` selects `Texture2D`.
|
||||||
let view = unsafe { &mut desc.Anonymous.Texture2D };
|
let view = unsafe { &mut desc.Anonymous.Texture2D };
|
||||||
clamp(&mut view.MostDetailedMip, &mut view.MipLevels, &mut view.ResourceMinLODClamp);
|
clamp(&mut view.MostDetailedMip, &mut view.MipLevels);
|
||||||
}
|
}
|
||||||
D3D12_SRV_DIMENSION_TEXTURE2DARRAY => {
|
D3D12_SRV_DIMENSION_TEXTURE2DARRAY => {
|
||||||
// SAFETY: `ViewDimension` selects `Texture2DArray`.
|
// SAFETY: `ViewDimension` selects `Texture2DArray`.
|
||||||
let view = unsafe { &mut desc.Anonymous.Texture2DArray };
|
let view = unsafe { &mut desc.Anonymous.Texture2DArray };
|
||||||
clamp(&mut view.MostDetailedMip, &mut view.MipLevels, &mut view.ResourceMinLODClamp);
|
clamp(&mut view.MostDetailedMip, &mut view.MipLevels);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -1265,10 +1262,10 @@ void look() {
|
|||||||
give_back(singles[1].1, &singles[1].2);
|
give_back(singles[1].1, &singles[1].2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// (v) A view made by [`show_from`] of a texture whose level 0 has no
|
/// (v) Sample LOD 0 through the adjusted and original views. Level 0
|
||||||
/// tiles returns level 1's colour for a sample at level 0; the view as
|
/// has no tiles. A minimum LOD inside the resident range should select
|
||||||
/// the title asked returns zero.
|
/// the same resource level through either view.
|
||||||
fn the_view_starts_at_the_first_level_with_tiles(rig: &mut Rig) -> Option<()> {
|
fn sample_resident_views(rig: &mut Rig, min_lod: f32) -> Option<[u32; 2]> {
|
||||||
rig.step = "step 5, the view from the first level with tiles";
|
rig.step = "step 5, the view from the first level with tiles";
|
||||||
let cs = compile(LOOK, s!("look"), s!("cs_5_1")).ok()?;
|
let cs = compile(LOOK, s!("look"), s!("cs_5_1")).ok()?;
|
||||||
let format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
let format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||||
@@ -1314,7 +1311,7 @@ void look() {
|
|||||||
MostDetailedMip: 0,
|
MostDetailedMip: 0,
|
||||||
MipLevels: u32::MAX,
|
MipLevels: u32::MAX,
|
||||||
PlaneSlice: 0,
|
PlaneSlice: 0,
|
||||||
ResourceMinLODClamp: 0.0,
|
ResourceMinLODClamp: min_lod,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -1356,14 +1353,12 @@ void look() {
|
|||||||
let mut data = std::ptr::null_mut();
|
let mut data = std::ptr::null_mut();
|
||||||
let range = D3D12_RANGE { Begin: 0, End: 16 };
|
let range = D3D12_RANGE { Begin: 0, End: 16 };
|
||||||
back.Map(0, Some(&range), Some(&mut data)).unwrap();
|
back.Map(0, Some(&range), Some(&mut data)).unwrap();
|
||||||
let read = std::slice::from_raw_parts(data.cast::<u32>(), 2).to_vec();
|
let read = data.cast::<[u32; 2]>().read();
|
||||||
back.Unmap(0, None);
|
back.Unmap(0, None);
|
||||||
read
|
read
|
||||||
};
|
};
|
||||||
eprintln!("a sample at level 0: {} through the view from level 1, {} through the view as asked", read[0], read[1]);
|
eprintln!("sample at LOD 0, minimum {min_lod}: adjusted and original {read:?}");
|
||||||
assert_eq!(read[0], 32, "the view from the first level with tiles reads level 1");
|
Some(read)
|
||||||
assert_eq!(read[1], 0, "the view from level 0 reads a level without tiles");
|
|
||||||
Some(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn a_full_card_keeps_new_levels_waiting(rig: &mut Rig) {
|
fn a_full_card_keeps_new_levels_waiting(rig: &mut Rig) {
|
||||||
@@ -1452,8 +1447,12 @@ void look() {
|
|||||||
a_level_on_several_ranges(&mut rig);
|
a_level_on_several_ranges(&mut rig);
|
||||||
a_full_card_keeps_new_levels_waiting(&mut rig);
|
a_full_card_keeps_new_levels_waiting(&mut rig);
|
||||||
a_claim_given_up_is_made_again(&mut rig);
|
a_claim_given_up_is_made_again(&mut rig);
|
||||||
if the_view_starts_at_the_first_level_with_tiles(&mut rig).is_none() {
|
for (min_lod, expected) in [(0.0, [32, 0]), (3.0, [64, 64])] {
|
||||||
eprintln!("the view test's shader or objects could not be made; that part was skipped");
|
let Some(read) = sample_resident_views(&mut rig, min_lod) else {
|
||||||
|
eprintln!("the view test's shader or objects could not be made; that part was skipped");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
assert_eq!(read, expected, "resource minimum LOD {min_lod}");
|
||||||
}
|
}
|
||||||
rig.step = "the end";
|
rig.step = "the end";
|
||||||
rig.check("every step done");
|
rig.check("every step done");
|
||||||
@@ -1482,7 +1481,7 @@ void look() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn show_from_clamps_2d_and_2d_array_and_adjusts_min_lod() {
|
fn show_from_preserves_resource_min_lod_for_2d_and_2d_array() {
|
||||||
let mut srv2d = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
let mut srv2d = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
||||||
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
ViewDimension: D3D12_SRV_DIMENSION_TEXTURE2D,
|
ViewDimension: D3D12_SRV_DIMENSION_TEXTURE2D,
|
||||||
@@ -1502,7 +1501,7 @@ void look() {
|
|||||||
assert_eq!(v2d.MostDetailedMip, 3);
|
assert_eq!(v2d.MostDetailedMip, 3);
|
||||||
// Clamped to remaining levels (11 - 3 = 8), not 12 - 3 = 9.
|
// Clamped to remaining levels (11 - 3 = 8), not 12 - 3 = 9.
|
||||||
assert_eq!(v2d.MipLevels, 8);
|
assert_eq!(v2d.MipLevels, 8);
|
||||||
assert_eq!(v2d.ResourceMinLODClamp, 0.5);
|
assert_eq!(v2d.ResourceMinLODClamp, 3.5);
|
||||||
|
|
||||||
let mut srv_arr = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
let mut srv_arr = D3D12_SHADER_RESOURCE_VIEW_DESC {
|
||||||
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
@@ -1524,7 +1523,7 @@ void look() {
|
|||||||
let varr = unsafe { srv_arr.Anonymous.Texture2DArray };
|
let varr = unsafe { srv_arr.Anonymous.Texture2DArray };
|
||||||
assert_eq!(varr.MostDetailedMip, 2);
|
assert_eq!(varr.MostDetailedMip, 2);
|
||||||
assert_eq!(varr.MipLevels, 4);
|
assert_eq!(varr.MipLevels, 4);
|
||||||
assert_eq!(varr.ResourceMinLODClamp, 0.0);
|
assert_eq!(varr.ResourceMinLODClamp, 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user