✅ Answer the fake's CPU ICB encodes nil unless scripted
The Vulkan platform answers the CPU's indirectRenderCommandAtIndex: and indirectComputeCommandAtIndex: nil, and its resetWithRange: resets nothing: its buffers' records are Private, which no CPU encode reaches (rt-unbuilt-icb). The fake answered a command and reset it, so 20 tests drove CPU encodes no host carries out. The fake now answers them as the platform does, each call still logged, unless the script answers a value for it, as it answers copyIndirectCommandBuffer. The decoder's record and slot tests, the rings' test and model_setters script values, so the decoder's handling of the records stays covered; the slot test that scripts a take's death clears its script and orders it.
This commit is contained in:
1 parent
8e4a85c162
commit
c4bc19dbe1
4 files changed
+108
-39
No files matched your search
@@ -1,11 +1,13 @@
|
||||
//! Fake: the `platform/icb.rs` traits over the fake models (architecture 13.2).
|
||||
//!
|
||||
//! An ICB's make is nil where the Vulkan platform refuses it ([`the_platform_refuses`]), unless
|
||||
//! the script answers a value for it. Its commands are per-index child objects, made at their
|
||||
//! first `…CommandAtIndex:`. Each logs its encoded commands, which are ordered, and records what
|
||||
//! they set in its [`IcbCommandModel`], which the free read-back getters answer from.
|
||||
//! An ICB's make is nil where the Vulkan platform refuses it ([`the_platform_refuses`]), and so
|
||||
//! are the CPU's encodes of its commands, while its reset of a range resets nothing, as the
|
||||
//! platform answers them (`rt-unbuilt-icb`), each unless the script answers a value for it. Its
|
||||
//! commands are per-index child objects, made at their first `…CommandAtIndex:` the script
|
||||
//! answers. Each logs its encoded commands, which are ordered, and records what they set in its
|
||||
//! [`IcbCommandModel`], which the free read-back getters answer from.
|
||||
|
||||
use crate::core::testkit::script::Policy;
|
||||
use crate::core::testkit::script::{Policy, Step};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use super::super::calllog::Arg;
|
||||
@@ -73,6 +75,23 @@ impl Fk<kind::Icb> {
|
||||
pub fn set_size(&self, size: u64) {
|
||||
self.with_model_mut(|m: &mut IcbModel| m.size = size);
|
||||
}
|
||||
|
||||
/// The command at `index` the CPU encodes (`sel`, `key` its kind of child): nil, as the
|
||||
/// Vulkan platform answers it, its buffers' records being Private, which no CPU encode reaches
|
||||
/// (`rt-unbuilt-icb`), once the call is logged and its script's raise or death taken, unless
|
||||
/// the script answers a value for it; then the same child for each index.
|
||||
fn cpu_command<C: Kind>(
|
||||
&self,
|
||||
sel: &'static str,
|
||||
key: &'static str,
|
||||
index: u64,
|
||||
) -> RaiseResult<Option<Fk<C>>> {
|
||||
let step = self.call(sel, vec![Arg::U64(index)]);
|
||||
let made = matches!(step, Step::Value(_));
|
||||
step.create(Policy::Caught, sel, || {
|
||||
made.then(|| self.child(key, index, || Model::None))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// What an ICB render or compute command's encoded commands set (zeros for a fresh or reset
|
||||
@@ -139,34 +158,27 @@ impl IndirectCommandBuffer<FakePlatform> for Fk<kind::Icb> {
|
||||
&self,
|
||||
command_index: u64,
|
||||
) -> RaiseResult<Option<<FakePlatform as Platform>::IndirectComputeCommand<'_>>> {
|
||||
self.index_child(
|
||||
Policy::Caught,
|
||||
"indirectComputeCommandAtIndex:",
|
||||
"compute",
|
||||
command_index,
|
||||
)
|
||||
self.cpu_command("indirectComputeCommandAtIndex:", "compute", command_index)
|
||||
}
|
||||
|
||||
fn render_command(
|
||||
&self,
|
||||
command_index: u64,
|
||||
) -> RaiseResult<Option<<FakePlatform as Platform>::IndirectRenderCommand<'_>>> {
|
||||
self.index_child(
|
||||
Policy::Caught,
|
||||
"indirectRenderCommandAtIndex:",
|
||||
"render",
|
||||
command_index,
|
||||
)
|
||||
self.cpu_command("indirectRenderCommandAtIndex:", "render", command_index)
|
||||
}
|
||||
|
||||
/// One call for the range: the commands made so far inside it lose what they were set, as
|
||||
/// a command's `reset` leaves one, each reached once, whatever the range's length.
|
||||
/// One call for the range, which resets nothing, as the Vulkan platform resets nothing
|
||||
/// (`rt-unbuilt-icb`), unless the script answers a value for it: then the commands made so far
|
||||
/// inside it lose what they were set, as a command's `reset` leaves one, each reached once,
|
||||
/// whatever the range's length.
|
||||
fn reset_with_range(&self, location: u64, length: u64) -> RaiseResult<()> {
|
||||
self.act(
|
||||
Policy::Caught,
|
||||
"resetWithRange:",
|
||||
vec![Arg::U64(location), Arg::U64(length)],
|
||||
)?;
|
||||
const SEL: &str = "resetWithRange:";
|
||||
let step = self.call(SEL, vec![Arg::U64(location), Arg::U64(length)]);
|
||||
step.throws(Policy::Caught, SEL)?;
|
||||
if !matches!(step, Step::Value(_)) {
|
||||
return Ok(());
|
||||
}
|
||||
let range = location..location.saturating_add(length);
|
||||
for (_, index, child) in self.children() {
|
||||
if !range.contains(&index) {
|
||||
|
||||
@@ -163,19 +163,6 @@ impl<K: Kind> Fk<K> {
|
||||
step.create_or_error(policy, sel, || init(&w).map(|c| self.adopt(c)))
|
||||
}
|
||||
|
||||
/// An indexed child getter whose position is observable (an ICB's command at an index): the
|
||||
/// same child for each index.
|
||||
pub fn index_child<C: Kind>(
|
||||
&self,
|
||||
policy: Policy,
|
||||
sel: &'static str,
|
||||
key: &'static str,
|
||||
index: u64,
|
||||
) -> RaiseResult<Option<Fk<C>>> {
|
||||
let step = self.call(sel, vec![Arg::U64(index)]);
|
||||
step.create(policy, sel, || Some(self.child(key, index, || Model::None)))
|
||||
}
|
||||
|
||||
/// Runs `f` on the common resource state, if the kind has one.
|
||||
pub fn with_common<T>(&self, f: impl FnOnce(&mut ResourceCommon) -> T) -> Option<T> {
|
||||
self.state().common().map(f)
|
||||
@@ -521,6 +508,11 @@ mod tests {
|
||||
.unwrap();
|
||||
icb.set_size(9);
|
||||
assert_eq!(icb.size(), 9);
|
||||
// The CPU's encodes, which the Vulkan platform answers nil: made as the script answers.
|
||||
p.script()
|
||||
.always("indirectRenderCommandAtIndex:", Step::value(()));
|
||||
p.script()
|
||||
.always("indirectComputeCommandAtIndex:", Step::value(()));
|
||||
let cmd = icb.render_command(0).unwrap().unwrap();
|
||||
cmd.set_command_type(0x10);
|
||||
assert_eq!(cmd.command_type(), 0x10);
|
||||
@@ -759,6 +751,46 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// The CPU's encodes of an indirect command buffer's commands answer nil, their calls still
|
||||
/// sent, and its reset of a range resets nothing, as the Vulkan platform answers them
|
||||
/// (`rt-unbuilt-icb`). Where the script answers a value for one, the command is answered, the
|
||||
/// same for its index, and the reset carried out
|
||||
#[test]
|
||||
fn an_icbs_cpu_encodes_are_nil_unless_scripted() {
|
||||
use crate::core::platform::icb::{
|
||||
IcbRenderCmd, IndirectCommandBuffer, IndirectRenderCommand,
|
||||
};
|
||||
const RENDER: &str = "indirectRenderCommandAtIndex:";
|
||||
const COMPUTE: &str = "indirectComputeCommandAtIndex:";
|
||||
const RESET: &str = "resetWithRange:";
|
||||
let p = FakePlatform::new();
|
||||
let icb = p
|
||||
.device()
|
||||
.new_indirect_command_buffer(&super::icb::made_desc(1, 1), 4, 0)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert!(icb.render_command(0).unwrap().is_none());
|
||||
assert!(icb.compute_command(1).unwrap().is_none());
|
||||
assert_eq!(
|
||||
(p.call_log().count(RENDER), p.call_log().count(COMPUTE)),
|
||||
(1, 1),
|
||||
"both sent"
|
||||
);
|
||||
p.script().push_n(RENDER, 2, Step::value(()));
|
||||
let cmd = icb.render_command(0).unwrap().unwrap();
|
||||
cmd.encode(IcbRenderCmd::SetBarrier).unwrap();
|
||||
icb.reset_with_range(0, 1).unwrap();
|
||||
assert_eq!(p.call_log().count(RESET), 1, "the reset sent");
|
||||
assert!(cmd.has_barrier(), "nothing reset");
|
||||
p.script().push(RESET, Step::value(()));
|
||||
icb.reset_with_range(0, 1).unwrap();
|
||||
assert!(!cmd.has_barrier(), "reset as scripted");
|
||||
let again = icb.render_command(0).unwrap().unwrap();
|
||||
assert_eq!(again.id(), cmd.id(), "the same command");
|
||||
p.script().push(COMPUTE, Step::value(()));
|
||||
assert!(icb.compute_command(1).unwrap().is_some());
|
||||
}
|
||||
|
||||
/// A texture placed in a heap is made where the Vulkan platform places one: at a multiple of
|
||||
/// the fake's alignment, 16 KiB, with all its bytes inside the heap. One off the alignment,
|
||||
/// past the heap's end, at an offset past it or whose end overflows is nil, as the platform
|
||||
|
||||
@@ -1831,6 +1831,21 @@ mod tests {
|
||||
fn made_anyway(p: &FakePlatform) {
|
||||
p.script().push(MAKE, Step::value(()));
|
||||
}
|
||||
|
||||
/// The CPU's takes of a render and a compute command, which the Vulkan platform answers nil.
|
||||
const RENDER_AT: &str = "indirectRenderCommandAtIndex:";
|
||||
const COMPUTE_AT: &str = "indirectComputeCommandAtIndex:";
|
||||
/// The CPU's reset of a range, which the Vulkan platform carries out nowhere.
|
||||
const RESET_RANGE: &str = "resetWithRange:";
|
||||
|
||||
/// Scripts every CPU take of a command, and every reset of a range, to be carried out, though
|
||||
/// the Vulkan platform answers each take nil and resets nothing, so the decoder's records and
|
||||
/// slots stay covered. A test that scripts one of them otherwise clears the script first.
|
||||
fn cpu_encodes(p: &FakePlatform) {
|
||||
for sel in [RENDER_AT, COMPUTE_AT, RESET_RANGE] {
|
||||
p.script().always(sel, Step::value(()));
|
||||
}
|
||||
}
|
||||
const RENDER_PIPELINE: u64 = 100;
|
||||
const COMPUTE_PIPELINE: u64 = 101;
|
||||
const RENDER_ICB: u64 = 50;
|
||||
@@ -1939,6 +1954,7 @@ mod tests {
|
||||
assert_eq!(dec.decode(&device, m.as_bytes()).unwrap(), Ok(()));
|
||||
}
|
||||
dec.end_message();
|
||||
cpu_encodes(&p);
|
||||
(p, dec)
|
||||
}
|
||||
|
||||
@@ -2808,8 +2824,12 @@ mod tests {
|
||||
for i in 0..3 {
|
||||
assert!(region.write(SLOTS + i * RENDER_STRIDE, &render_slot(&fixed, bindings)));
|
||||
}
|
||||
let at = "indirectRenderCommandAtIndex:";
|
||||
p.script().after(at, 1, Step::crash());
|
||||
let at = RENDER_AT;
|
||||
// The first take carried out, the second a death, the rest carried out.
|
||||
p.script().clear();
|
||||
p.script().push(at, Step::value(()));
|
||||
p.script().push(at, Step::crash());
|
||||
cpu_encodes(&p);
|
||||
let mark = p.call_log().mark();
|
||||
assert_eq!(dec.decode(&device, &message).unwrap(), Ok(()));
|
||||
let taken: Vec<_> = calls(&p, mark).into_iter().map(|(sel, _)| sel).collect();
|
||||
|
||||
@@ -11633,6 +11633,11 @@ fn icb_through_the_rings(slots: bool) {
|
||||
"newIndirectCommandBufferWithDescriptor:maxCommandCount:options:",
|
||||
Step::value(()),
|
||||
);
|
||||
// The CPU's takes of its commands, which the Vulkan platform answers nil: carried out as the
|
||||
// script answers.
|
||||
platform
|
||||
.script()
|
||||
.always("indirectComputeCommandAtIndex:", Step::value(()));
|
||||
guest.send(
|
||||
&device,
|
||||
RgfxIcbCreate {
|
||||
|
||||
Reference in new issue
Block a user