host_ab: dispatch_handles, dispatches of a kernel reading a texture through a handle
The encode workload's dispatch_handles variant dispatches tiny_handle_kernel, which reads a resident texture through its handle in an argument buffer (Gpu::texture_id writes the gpuResourceID on both sides), so each dispatch binds the device's texture table: the per-command heap-table cost is measured. encode takes the library to make its pipeline only where the variant runs. Verified: the example builds (clippy, all features). (cherry picked from commit 1d8f613081eec7cae21b1279e8661dfa2ab4b50d) (cherry picked from commit ec5573c6f17c7f404729a9811025beb688f46250) (cherry picked from commit de3aaea45f86a76432e6c459262f5612845d0194) (cherry picked from commit ca61dcb9423979f8397c674ef8a6b0809a1c99fd)
This commit is contained in:
1 parent
81681968e4
commit
05d0732d6b
6 files changed
+91
-4
No files matched your search
@@ -96,6 +96,8 @@ pub trait Gpu: Sync {
|
||||
fn commands_id(&self, commands: &Self::IndirectCommands) -> u64;
|
||||
/// The `gpuResourceID` of `state`, made with `supportIndirectCommandBuffers`.
|
||||
fn pipeline_id(&self, state: &Self::ComputePipeline) -> u64;
|
||||
/// The `gpuResourceID` of `texture`, as a kernel reads it from an argument buffer.
|
||||
fn texture_id(&self, texture: &Self::Texture) -> u64;
|
||||
/// `newIndirectCommandBufferWithDescriptor:maxCommandCount:options:` of `count` concurrent
|
||||
/// dispatches of `Shared` storage that inherit nothing and bind one kernel buffer, for the
|
||||
/// CPU to encode.
|
||||
|
||||
@@ -219,6 +219,18 @@ kernel void tiny_kernel_b(device uint *out [[buffer(0)]],
|
||||
out[tid] = value * 3u + tid + uint(NONCE);
|
||||
}
|
||||
|
||||
// The handle dispatches' kernel: it reads its texture through a handle in an argument buffer, so
|
||||
// each of its dispatches binds the device's texture table (`dispatch_handles`).
|
||||
struct TinyHandles {
|
||||
texture2d<float> texture;
|
||||
};
|
||||
|
||||
kernel void tiny_handle_kernel(device uint *out [[buffer(0)]],
|
||||
constant TinyHandles &handles [[buffer(1)]],
|
||||
uint tid [[thread_position_in_grid]]) {
|
||||
out[tid] = uint(handles.texture.read(uint2(0, 0)).x * 255.0) + tid + uint(NONCE);
|
||||
}
|
||||
|
||||
// The many-draws workload's functions: a small rectangle per draw, of its own uniforms, and four
|
||||
// fragment functions over two textures and one sampler.
|
||||
struct DrawUniforms {
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
//! wall time after it and the process's CPU time; `dispatch_resident_moving_0`, `_16`, `_256`
|
||||
//! and `_4096`: as many after none, 16, 256 or 4096 buffers made resident, the output buffer's
|
||||
//! offset moved before each dispatch; `dispatch_resident_textures_256` and `_4096`: as many after
|
||||
//! 256 or 4096 textures made resident.
|
||||
//! 256 or 4096 textures made resident; `dispatch_handles`: as many of a kernel reading a
|
||||
//! resident texture through a handle in an argument buffer.
|
||||
//! - `fixed`: a command buffer's creation, an encoder of one command each (render, compute,
|
||||
//! blit), and the commit call of a command buffer of 30 such encoders.
|
||||
//! - `calls`: the frames of a guest as reims-vgpu's `frame_cost` measures them, call by call: one
|
||||
@@ -208,7 +209,7 @@
|
||||
//! `draw_static`, `draw_offset`, `draw_bind`, `draw_pipeline`, `draw_passes`, `dispatch_static`,
|
||||
//! `dispatch_offsets`, `dispatch_churn`, `dispatch_resident_0`, `_1`, `_256`, `_4096`,
|
||||
//! `_same_4096`, `dispatch_resident_moving_0`, `_16`, `_256`, `_4096`,
|
||||
//! `dispatch_resident_textures_256`, `_4096`; for a profile of one; and the memory workload's parts alone: `create`,
|
||||
//! `dispatch_resident_textures_256`, `_4096`, `dispatch_handles`; for a profile of one; and the memory workload's parts alone: `create`,
|
||||
//! `no_copy`, `held_1m`, `held_64m`, `texture`), `--announce-each a,b,...` (the runtime's device
|
||||
//! announces these degradation kinds, by code with or without its `metal2vulkan-degrade-` prefix,
|
||||
//! or `all` of them, at every occurrence, `DeviceOptions::announce_each`, as a consumer that hears
|
||||
@@ -511,7 +512,7 @@ fn run<G: Gpu>(g: &G, opened: Instant, metallib: &Path, options: &Options) {
|
||||
);
|
||||
for workload in rest {
|
||||
match workload {
|
||||
"encode" => workloads::encode(g, &scene, sizes, &options.variants),
|
||||
"encode" => workloads::encode(g, &scene, &library, sizes, &options.variants),
|
||||
"fixed" => workloads::fixed(g, &scene, sizes),
|
||||
"calls" => workloads::calls(g, &scene, &library, sizes, &options.variants),
|
||||
"latency" => workloads::latency(g, &scene, sizes),
|
||||
|
||||
@@ -253,6 +253,10 @@ impl Gpu for Native {
|
||||
state.gpuResourceID().to_raw()
|
||||
}
|
||||
|
||||
fn texture_id(&self, texture: &Self::Texture) -> u64 {
|
||||
texture.gpuResourceID().to_raw()
|
||||
}
|
||||
|
||||
fn cpu_indirect_commands(&self, count: usize) -> Self::IndirectCommands {
|
||||
let descriptor = MTLIndirectCommandBufferDescriptor::new();
|
||||
descriptor.setCommandTypes(MTLIndirectCommandType::ConcurrentDispatch);
|
||||
|
||||
@@ -273,6 +273,10 @@ impl Gpu for Runtime {
|
||||
state.gpu_resource_id().0
|
||||
}
|
||||
|
||||
fn texture_id(&self, texture: &rt::Texture) -> u64 {
|
||||
texture.gpu_resource_id().0
|
||||
}
|
||||
|
||||
fn cpu_indirect_commands(&self, count: usize) -> rt::IndirectCommandBuffer {
|
||||
let mut descriptor = rt::IndirectCommandBufferDescriptor::new();
|
||||
descriptor.command_types = IndirectCommandType::CONCURRENT_DISPATCH;
|
||||
|
||||
@@ -502,7 +502,13 @@ pub fn threads<G: Gpu>(g: &G, library: &G::Library, shared: &G::RenderPipeline,
|
||||
/// The CPU cost of encoding: per draw and per dispatch, on the encoding thread (wall) and in the
|
||||
/// whole process (CPU time of every thread, from the command buffer's creation until its wait
|
||||
/// returned, which takes in work moved off the encoding thread to commit or to other threads).
|
||||
pub fn encode<G: Gpu>(g: &G, s: &Scene<G>, sizes: &Sizes, variants: &[String]) {
|
||||
pub fn encode<G: Gpu>(
|
||||
g: &G,
|
||||
s: &Scene<G>,
|
||||
library: &G::Library,
|
||||
sizes: &Sizes,
|
||||
variants: &[String],
|
||||
) {
|
||||
let n = sizes.draws;
|
||||
let runs = |name: String| variants.is_empty() || variants.contains(&name);
|
||||
for churn in [
|
||||
@@ -611,6 +617,64 @@ pub fn encode<G: Gpu>(g: &G, s: &Scene<G>, sizes: &Sizes, variants: &[String]) {
|
||||
emit_memo_shares(g, counts, dispatches, &format!("dispatch_{name}"));
|
||||
}
|
||||
encode_resident(g, s, sizes, &runs);
|
||||
encode_handles(g, s, library, sizes, &runs);
|
||||
}
|
||||
|
||||
/// The encode workload's `dispatch_handles` variant: a compute encoder of `draws`
|
||||
/// single-threadgroup dispatches of `tiny_handle_kernel`, which reads a texture made resident
|
||||
/// through its handle in an argument buffer, so each dispatch binds the device's texture table.
|
||||
/// Per dispatch: the encoding thread's wall time and the process's CPU time.
|
||||
fn encode_handles<G: Gpu>(
|
||||
g: &G,
|
||||
s: &Scene<G>,
|
||||
library: &G::Library,
|
||||
sizes: &Sizes,
|
||||
runs: &dyn Fn(String) -> bool,
|
||||
) {
|
||||
if !runs("dispatch_handles".to_owned()) {
|
||||
return;
|
||||
}
|
||||
let n = sizes.draws;
|
||||
let pipeline = g.compute_pipeline(library, "tiny_handle_kernel");
|
||||
let texture = &s.textures[0];
|
||||
let handles = g.buffer_with(&g.texture_id(texture).to_le_bytes());
|
||||
let (mut wall, mut cpu) = (vec![], vec![]);
|
||||
for run in 0..sizes.timed + 3 {
|
||||
g.pool(|| {
|
||||
let cpu0 = process_cpu();
|
||||
let command_buffer = g.command_buffer();
|
||||
let mut encoder = g.compute_encoder(&command_buffer);
|
||||
g.set_compute_pipeline(&mut encoder, &pipeline);
|
||||
g.set_buffer(&mut encoder, &s.tiny_out, 0, 0);
|
||||
g.set_buffer(&mut encoder, &handles, 0, 1);
|
||||
g.use_textures(&mut encoder, &[texture]);
|
||||
let t0 = Instant::now();
|
||||
for _ in 0..n {
|
||||
g.dispatch(&mut encoder, 1, 64);
|
||||
}
|
||||
let t1 = Instant::now();
|
||||
g.end_compute(encoder);
|
||||
g.commit(&command_buffer);
|
||||
g.wait(&command_buffer);
|
||||
let cpu1 = process_cpu();
|
||||
if run >= 3 {
|
||||
wall.push(us(t1 - t0) / n as f64);
|
||||
cpu.push(us(cpu1 - cpu0) / n as f64);
|
||||
}
|
||||
});
|
||||
}
|
||||
emit(
|
||||
"encode",
|
||||
"dispatch_handles_encode",
|
||||
"us/dispatch",
|
||||
&mut wall,
|
||||
);
|
||||
emit(
|
||||
"encode",
|
||||
"dispatch_handles_process_cpu",
|
||||
"us/dispatch",
|
||||
&mut cpu,
|
||||
);
|
||||
}
|
||||
|
||||
/// The resident buffers of the encode workload's `dispatch_resident` variants, of 256 bytes each.
|
||||
|
||||
Reference in new issue
Block a user