Replay traces with pointers as IDs

This commit is contained in:
Andy Leiserson authored and Teodor Tanasoaia committed 2025-10-30 13:52:58 +01:00
1 parent 67da4cbc03
commit 07ce023cf1
25 files changed
+1415 -630

No files matched your search

Generated
+1
View File
@@ -3178,6 +3178,7 @@ version = "27.0.0"
dependencies = [
"bytemuck",
"env_logger",
"hashbrown 0.16.0",
"log",
"raw-window-handle 0.6.2",
"ron",
+2 -1
View File
@@ -3,7 +3,6 @@ resolver = "2"
members = [
"cts_runner",
"deno_webgpu",
"player",
# default members
"benches",
@@ -16,6 +15,7 @@ members = [
"naga/fuzz",
"naga/hlsl-snapshots",
"naga/xtask",
"player",
"tests",
"wgpu-core",
"wgpu-core/platform-deps/*",
@@ -38,6 +38,7 @@ default-members = [
"naga/fuzz",
"naga/hlsl-snapshots",
"naga/xtask",
"player",
"tests",
"wgpu-core",
"wgpu-core/platform-deps/*",
+2 -5
View File
@@ -577,11 +577,8 @@ impl GPUDevice {
multiview: None,
};
let res = wgpu_core::command::RenderBundleEncoder::new(
&wgpu_descriptor,
self.id,
None,
);
let res =
wgpu_core::command::RenderBundleEncoder::new(&wgpu_descriptor, self.id);
let (encoder, err) = match res {
Ok(encoder) => (encoder, None),
Err(e) => (
+1
View File
@@ -22,6 +22,7 @@ test = false
wgpu-types = { workspace = true, features = ["serde", "std"] }
env_logger.workspace = true
hashbrown.workspace = true
log.workspace = true
raw-window-handle.workspace = true
ron.workspace = true
+42 -58
View File
@@ -5,14 +5,15 @@ fn main() {
extern crate wgpu_core as wgc;
extern crate wgpu_types as wgt;
use player::GlobalPlay as _;
use player::Player;
use wgc::device::trace;
use wgpu_core::{command::IdReferences, identity::IdentityManager};
use wgpu_core::command::PointerReferences;
use std::{
fs,
path::{Path, PathBuf},
process::exit,
sync::Arc,
};
#[cfg(feature = "winit")]
@@ -52,7 +53,7 @@ fn main() {
log::info!("Loading trace '{trace:?}'");
let file = fs::File::open(trace).unwrap();
let mut actions: Vec<trace::Action<IdReferences>> = ron::de::from_reader(file).unwrap();
let mut actions: Vec<trace::Action<PointerReferences>> = ron::de::from_reader(file).unwrap();
actions.reverse(); // allows us to pop from the top
log::info!("Found {} actions", actions.len());
@@ -68,17 +69,14 @@ fn main() {
.build(&event_loop)
.unwrap();
let global =
wgc::global::Global::new("player", &wgt::InstanceDescriptor::from_env_or_default());
let mut command_encoder_id_manager = IdentityManager::new();
let mut command_buffer_id_manager = IdentityManager::new();
let instance_desc = wgt::InstanceDescriptor::from_env_or_default();
let instance = wgc::instance::Instance::new("player", &instance_desc);
#[cfg(feature = "winit")]
let surface = unsafe {
global.instance_create_surface(
instance.create_surface(
window.display_handle().unwrap().into(),
window.window_handle().unwrap().into(),
Some(wgc::id::Id::zip(0, 1)),
)
}
.unwrap();
@@ -93,29 +91,29 @@ fn main() {
None => (wgt::Backends::all(), wgt::DeviceDescriptor::default()),
};
let adapter = global
.request_adapter(
&wgc::instance::RequestAdapterOptions {
#[cfg(feature = "winit")]
compatible_surface: Some(surface),
#[cfg(not(feature = "winit"))]
compatible_surface: None,
..Default::default()
},
backends,
Some(wgc::id::AdapterId::zip(0, 1)),
)
.expect("Unable to obtain an adapter");
let adapter = Arc::new(
instance
.request_adapter(
&wgt::RequestAdapterOptions {
#[cfg(feature = "winit")]
compatible_surface: Some(&surface),
#[cfg(not(feature = "winit"))]
compatible_surface: None,
..Default::default()
},
backends,
)
.expect("Unable to obtain an adapter"),
);
let info = global.adapter_get_info(adapter);
let info = adapter.get_info();
log::info!("Using '{}'", info.name);
let device = wgc::id::Id::zip(0, 1);
let queue = wgc::id::Id::zip(0, 1);
let res = global.adapter_request_device(adapter, &device_desc, Some(device), Some(queue));
if let Err(e) = res {
panic!("{e:?}");
}
let (device, queue) = adapter
.create_device_and_queue(&device_desc, instance_desc.flags)
.unwrap();
let mut player = Player::default();
log::info!("Executing actions");
#[cfg(not(feature = "winit"))]
@@ -123,20 +121,13 @@ fn main() {
unsafe { global.device_start_graphics_debugger_capture(device) };
while let Some(action) = actions.pop() {
global.process(
device,
queue,
action,
&dir,
&mut command_encoder_id_manager,
&mut command_buffer_id_manager,
);
player.process(&device, &queue, action, &dir);
}
unsafe { global.device_stop_graphics_debugger_capture(device) };
global
.device_poll(device, wgt::PollType::wait_indefinitely())
.unwrap();
let (user_closures, result) = device.poll(wgt::PollType::wait_indefinitely());
user_closures.fire();
result.unwrap();
}
#[cfg(feature = "winit")]
{
@@ -170,33 +161,25 @@ fn main() {
resize_config = Some(config);
target.exit();
} else {
let error =
global.surface_configure(surface, device, &config);
let error = device.configure_surface(&surface, &config);
if let Some(e) = error {
panic!("{e:?}");
}
}
}
Some(trace::Action::Present(id)) => {
Some(trace::Action::Present(_id)) => {
frame_count += 1;
log::debug!("Presenting frame {frame_count}");
global.surface_present(id).unwrap();
surface.present().unwrap();
target.exit();
}
Some(trace::Action::DiscardSurfaceTexture(id)) => {
Some(trace::Action::DiscardSurfaceTexture(_id)) => {
log::debug!("Discarding frame {frame_count}");
global.surface_texture_discard(id).unwrap();
surface.discard().unwrap();
target.exit();
}
Some(action) => {
global.process(
device,
queue,
action,
&dir,
&mut command_encoder_id_manager,
&mut command_buffer_id_manager,
);
player.process(&device, &queue, action, &dir);
}
None => {
if !done {
@@ -209,7 +192,7 @@ fn main() {
}
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = global.surface_configure(surface, device, &config);
let error = device.configure_surface(&surface, &config);
if let Some(e) = error {
panic!("{e:?}");
}
@@ -229,9 +212,10 @@ fn main() {
},
Event::LoopExiting => {
log::info!("Closing");
global
.device_poll(device, wgt::PollType::wait_indefinitely())
.unwrap();
let (user_closures, result) =
device.poll(wgt::PollType::wait_indefinitely());
user_closures.fire();
result.unwrap();
}
_ => {}
}
+1093 -298
View File
File diff suppressed because it is too large. Load diff
+14 -14
View File
@@ -2,13 +2,13 @@
features: "",
expectations: [], //not crash!
actions: [
CreateBuffer(Id(0, 1), (
CreateBuffer(PointerId(0x10), (
label: None,
size: 16,
usage: "UNIFORM",
mapped_at_creation: false,
)),
CreateBindGroupLayout(Id(0, 1), (
CreateBindGroupLayout(PointerId(0x10), (
label: None,
entries: [
(
@@ -20,29 +20,29 @@
),
],
)),
CreateBindGroup(Id(0, 1), (
CreateBindGroup(PointerId(0x10), (
label: None,
layout: Id(0, 1),
layout: PointerId(0x10),
entries: [
(
binding: 0,
resource: Buffer((
buffer: Id(0, 1),
buffer: PointerId(0x10),
offset: 0,
size: None,
)),
)
],
)),
CreatePipelineLayout(Id(0, 1), (
CreatePipelineLayout(PointerId(0x10), (
label: Some("empty"),
bind_group_layouts: [
Id(0, 1),
PointerId(0x10),
],
push_constant_ranges: [],
)),
CreateShaderModule(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
flags: (bits: 3),
@@ -50,12 +50,12 @@
data: "empty.wgsl",
),
CreateComputePipeline(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
layout: Some(Id(0, 1)),
layout: Some(PointerId(0x10)),
stage: (
module: Id(0, 1),
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
@@ -65,14 +65,14 @@
),
Submit(1, [
RunComputePass(
base: (
pass: (
commands: [
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Some(Id(0, 1)),
bind_group: Some(PointerId(0x10)),
),
SetPipeline(Id(0, 1)),
SetPipeline(PointerId(0x10)),
],
dynamic_offsets: [],
string_data: [],
+3 -3
View File
@@ -3,14 +3,14 @@
expectations: [
(
name: "basic",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: Raw([0x00, 0x00, 0x80, 0xBF]),
)
],
actions: [
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("dummy"),
size: 16,
@@ -19,7 +19,7 @@
),
),
WriteBuffer(
id: Id(0, 1),
id: PointerId(0x10),
data: "data1.bin",
range: (
start: 0,
@@ -3,13 +3,13 @@
expectations: [
(
name: "Quad",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: File("clear-texture.bin", 16384),
),
(
name: "buffer clear",
buffer: (index: 1, epoch: 1),
buffer: PointerId(0x110),
offset: 0,
data: Raw([
0x00, 0x00, 0x80, 0xBF,
@@ -20,7 +20,7 @@
)
],
actions: [
CreateTexture(Id(0, 1), (
CreateTexture(PointerId(0x10), (
label: Some("Output Texture"),
size: (
width: 64,
@@ -36,7 +36,7 @@
// First fill the texture to ensure it wasn't just zero initialized or "happened" to be zero.
WriteTexture(
to: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
@@ -52,7 +52,7 @@
),
),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Output Buffer"),
size: 16384,
@@ -62,7 +62,7 @@
),
CreateBuffer(
Id(1, 1),
PointerId(0x110),
(
label: Some("Buffer to be cleared"),
size: 16,
@@ -72,7 +72,7 @@
),
// Make sure there is something in the buffer, otherwise it might be just zero init!
WriteBuffer(
id: Id(1, 1),
id: PointerId(0x110),
data: "data1.bin",
range: (
start: 0,
@@ -82,7 +82,7 @@
),
Submit(1, [
ClearTexture(
dst: Id(0, 1),
dst: PointerId(0x10),
subresource_range: ImageSubresourceRange(
aspect: all,
baseMipLevel: 0,
@@ -93,12 +93,12 @@
),
CopyTextureToBuffer(
src: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1),
buffer: PointerId(0x10),
layout: (
offset: 0,
bytes_per_row: Some(256),
@@ -112,7 +112,7 @@
),
// Partial clear to prove
ClearBuffer(
dst: Id(1, 1),
dst: PointerId(0x110),
offset: 4,
size: Some(8),
)
@@ -3,19 +3,19 @@
expectations: [
(
name: "Queried number of compute invocations is correct",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: U64([0x0, 0x2A]),
),
],
actions: [
CreatePipelineLayout(Id(0, 1), (
CreatePipelineLayout(PointerId(0x10), (
label: Some("empty"),
bind_group_layouts: [],
push_constant_ranges: [],
)),
CreateShaderModule(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
flags: (bits: 3),
@@ -23,12 +23,12 @@
data: "empty.wgsl",
),
CreateComputePipeline(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
layout: Some(Id(0, 1)),
layout: Some(PointerId(0x10)),
stage: (
module: Id(0, 1),
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
@@ -37,7 +37,7 @@
),
),
CreateQuerySet(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: Some("Compute Invocation QuerySet"),
count: 2,
@@ -45,7 +45,7 @@
),
),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Compute Invocation Result Buffer"),
size: 16,
@@ -55,11 +55,11 @@
),
Submit(1, [
RunComputePass(
base: (
pass: (
commands: [
SetPipeline(Id(0, 1)),
SetPipeline(PointerId(0x10)),
BeginPipelineStatisticsQuery(
query_set_id: Id(0, 1),
query_set: PointerId(0x10),
query_index: 0,
),
Dispatch((2, 3, 7,)),
@@ -71,10 +71,10 @@
),
),
ResolveQuerySet(
query_set_id: Id(0, 1),
query_set: PointerId(0x10),
start_query: 0,
query_count: 1,
destination: Id(0, 1),
destination: PointerId(0x10),
destination_offset: 0,
)
]),
+28 -26
View File
@@ -3,21 +3,21 @@
expectations: [
(
name: "Quad",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: File("quad.bin", 16384),
)
],
actions: [
CreateShaderModule(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
flags: (bits: 3),
),
data: "quad.wgsl",
),
CreateTexture(Id(0, 1), (
CreateTexture(PointerId(0x10), (
label: Some("Output Texture"),
size: (
width: 64,
@@ -31,12 +31,12 @@
view_formats: [],
)),
CreateTextureView(
id: Id(0, 1),
parent_id: Id(0, 1),
id: PointerId(0x10),
parent: PointerId(0x10),
desc: (),
),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Output Buffer"),
size: 16384,
@@ -44,29 +44,31 @@
mapped_at_creation: false,
),
),
CreatePipelineLayout(Id(0, 1), (
CreatePipelineLayout(PointerId(0x10), (
label: None,
bind_group_layouts: [],
push_constant_ranges: [],
)),
CreateRenderPipeline(
id: Id(0, 1),
CreateGeneralRenderPipeline(
id: PointerId(0x10),
desc: (
label: None,
layout: Some(Id(0, 1)),
vertex: (
stage: (
module: Id(0, 1),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
vertex_pulling_transform: false,
layout: Some(PointerId(0x10)),
vertex: Vertex(
VertexState(
stage: (
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
vertex_pulling_transform: false,
),
buffers: [],
),
buffers: [],
),
fragment: Some((
stage: (
module: Id(0, 1),
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
@@ -82,9 +84,9 @@
),
Submit(1, [
RunRenderPass(
base: (
pass: (
commands: [
SetPipeline(Id(0, 1)),
SetPipeline(PointerId(0x10)),
Draw(
vertex_count: 3,
instance_count: 1,
@@ -96,9 +98,9 @@
string_data: [],
push_constant_data: [],
),
target_colors: [
color_attachments: [
Some((
view: Id(0, 1),
view: PointerId(0x10),
resolve_target: None,
load_op: clear(Color(
r: 0,
@@ -109,16 +111,16 @@
store_op: store,
)),
],
target_depth_stencil: None,
depth_stencil_attachment: None,
),
CopyTextureToBuffer(
src: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1),
buffer: PointerId(0x10),
layout: (
offset: 0,
bytes_per_row: Some(256),
+22 -22
View File
@@ -4,19 +4,19 @@
// Ensuring that mapping zero-inits buffers.
(
name: "mapped_at_creation: false, with MAP_WRITE",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: Raw([0x00, 0x00, 0x00, 0x00]),
),
(
name: "mapped_at_creation: false, without MAP_WRITE",
buffer: (index: 1, epoch: 1),
buffer: PointerId(0x110),
offset: 0,
data: Raw([0x00, 0x00, 0x00, 0x00]),
),
(
name: "partially written buffer",
buffer: (index: 2, epoch: 1),
buffer: PointerId(0x120),
offset: 0,
data: Raw([0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xBF,
@@ -29,7 +29,7 @@
// (by observing correct side effects of compute shader reading & writing values)
(
name: "buffer has correct values",
buffer: (index: 3, epoch: 1),
buffer: PointerId(0x130),
offset: 0,
data: Raw([0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
@@ -39,7 +39,7 @@
],
actions: [
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("mapped_at_creation: false, with MAP_WRITE"),
size: 16,
@@ -48,7 +48,7 @@
),
),
CreateBuffer(
Id(1, 1),
PointerId(0x110),
(
label: Some("mapped_at_creation: false, without MAP_WRITE"),
size: 16,
@@ -57,7 +57,7 @@
),
),
CreateBuffer(
Id(2, 1),
PointerId(0x120),
(
label: Some("partially written"),
size: 24,
@@ -66,7 +66,7 @@
),
),
WriteBuffer(
id: Id(2, 1),
id: PointerId(0x120),
data: "data1.bin",
range: (
start: 4,
@@ -75,20 +75,20 @@
queued: true,
),
CreateShaderModule(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
flags: (bits: 3),
),
data: "zero-init-buffer-for-binding.wgsl",
),
CreateBuffer(Id(3, 1), (
CreateBuffer(PointerId(0x130), (
label: Some("used in binding"),
size: 16,
usage: "STORAGE | MAP_READ",
mapped_at_creation: false,
)),
CreateBindGroupLayout(Id(0, 1), (
CreateBindGroupLayout(PointerId(0x10), (
label: None,
entries: [
(
@@ -105,34 +105,34 @@
),
],
)),
CreateBindGroup(Id(0, 1), (
CreateBindGroup(PointerId(0x10), (
label: None,
layout: Id(0, 1),
layout: PointerId(0x10),
entries: [
(
binding: 0,
resource: Buffer((
buffer: Id(3, 1),
buffer: PointerId(0x130),
offset: 0,
size: Some(16),
)),
),
],
)),
CreatePipelineLayout(Id(0, 1), (
CreatePipelineLayout(PointerId(0x10), (
label: None,
bind_group_layouts: [
Id(0, 1),
PointerId(0x10),
],
push_constant_ranges: [],
)),
CreateComputePipeline(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
layout: Some(Id(0, 1)),
layout: Some(PointerId(0x10)),
stage: (
module: Id(0, 1),
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
@@ -142,14 +142,14 @@
),
Submit(1, [
RunComputePass(
base: (
pass: (
label: None,
commands: [
SetPipeline(Id(0, 1)),
SetPipeline(PointerId(0x10)),
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Some(Id(0, 1)),
bind_group: Some(PointerId(0x10)),
),
Dispatch((4, 1, 1)),
],
@@ -3,13 +3,13 @@
expectations: [
(
name: "Sampled Texture",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: File("zero-16k.bin", 16384),
),
(
name: "Storage Texture",
buffer: (index: 1, epoch: 1),
buffer: PointerId(0x110),
offset: 0,
data: File("zero-16k.bin", 16384),
),
@@ -17,7 +17,7 @@
// MISSING: Partial views
],
actions: [
CreateTexture(Id(0, 1), (
CreateTexture(PointerId(0x10), (
label: Some("Sampled Texture"),
size: (
width: 64,
@@ -31,12 +31,12 @@
view_formats: [],
)),
CreateTextureView(
id: Id(0, 1),
parent_id: Id(0, 1),
id: PointerId(0x10),
parent: PointerId(0x10),
desc: (),
),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Sampled Texture Buffer"),
size: 16384,
@@ -44,7 +44,7 @@
mapped_at_creation: false,
),
),
CreateTexture(Id(1, 1), (
CreateTexture(PointerId(0x110), (
label: Some("Storage Texture"),
size: (
width: 64,
@@ -58,12 +58,12 @@
view_formats: [],
)),
CreateTextureView(
id: Id(1, 1),
parent_id: Id(1, 1),
id: PointerId(0x110),
parent: PointerId(0x110),
desc: (),
),
CreateBuffer(
Id(1, 1),
PointerId(0x110),
(
label: Some("Storage Texture Buffer"),
size: 16384,
@@ -73,7 +73,7 @@
),
CreateBindGroupLayout(Id(0, 1), (
CreateBindGroupLayout(PointerId(0x10), (
label: None,
entries: [
(
@@ -98,29 +98,29 @@
),
],
)),
CreateBindGroup(Id(0, 1), (
CreateBindGroup(PointerId(0x10), (
label: None,
layout: Id(0, 1),
layout: PointerId(0x10),
entries: [
(
binding: 0,
resource: TextureView(Id(0, 1)),
resource: TextureView(PointerId(0x10)),
),
(
binding: 1,
resource: TextureView(Id(1, 1)),
resource: TextureView(PointerId(0x110)),
),
],
)),
CreatePipelineLayout(Id(0, 1), (
CreatePipelineLayout(PointerId(0x10), (
label: None,
bind_group_layouts: [
Id(0, 1),
PointerId(0x10),
],
push_constant_ranges: [],
)),
CreateShaderModule(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
flags: (bits: 3),
@@ -128,12 +128,12 @@
data: "zero-init-texture-binding.wgsl",
),
CreateComputePipeline(
id: Id(0, 1),
id: PointerId(0x10),
desc: (
label: None,
layout: Some(Id(0, 1)),
layout: Some(PointerId(0x10)),
stage: (
module: Id(0, 1),
module: PointerId(0x10),
entry_point: None,
constants: {},
zero_initialize_workgroup_memory: true,
@@ -144,13 +144,13 @@
Submit(1, [
RunComputePass(
base: (
pass: (
commands: [
SetPipeline(Id(0, 1)),
SetPipeline(PointerId(0x10)),
SetBindGroup(
index: 0,
num_dynamic_offsets: 0,
bind_group_id: Some(Id(0, 1)),
bind_group: Some(PointerId(0x10)),
),
Dispatch((4, 1, 1)),
],
@@ -161,12 +161,12 @@
),
CopyTextureToBuffer(
src: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1),
buffer: PointerId(0x10),
layout: (
offset: 0,
bytes_per_row: Some(256),
@@ -180,12 +180,12 @@
),
CopyTextureToBuffer(
src: (
texture: Id(1, 1),
texture: PointerId(0x110),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(1, 1),
buffer: PointerId(0x110),
layout: (
offset: 0,
bytes_per_row: Some(256),
@@ -3,14 +3,14 @@
expectations: [
(
name: "Copy to Buffer",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: File("zero-16k.bin", 16384),
),
// MISSING: Partial copies
],
actions: [
CreateTexture(Id(0, 1), (
CreateTexture(PointerId(0x10), (
label: Some("Copy To Buffer Texture"),
size: (
width: 64,
@@ -24,7 +24,7 @@
view_formats: [],
)),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Copy to Buffer Buffer"),
size: 16384,
@@ -35,12 +35,12 @@
Submit(1, [
CopyTextureToBuffer(
src: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1),
buffer: PointerId(0x10),
layout: (
offset: 0,
bytes_per_row: Some(256),
@@ -3,14 +3,14 @@
expectations: [
(
name: "Render Target",
buffer: (index: 0, epoch: 1),
buffer: PointerId(0x10),
offset: 0,
data: File("zero-16k.bin", 16384),
),
// MISSING: Partial view.
],
actions: [
CreateTexture(Id(0, 1), (
CreateTexture(PointerId(0x10), (
label: Some("Render Target Texture"),
size: (
width: 64,
@@ -24,12 +24,12 @@
view_formats: [],
)),
CreateTextureView(
id: Id(0, 1),
parent_id: Id(0, 1),
id: PointerId(0x10),
parent: PointerId(0x10),
desc: (),
),
CreateBuffer(
Id(0, 1),
PointerId(0x10),
(
label: Some("Render Target Buffer"),
size: 16384,
@@ -40,15 +40,15 @@
Submit(1, [
RunRenderPass(
base: (
pass: (
commands: [],
dynamic_offsets: [],
string_data: [],
push_constant_data: [],
),
target_colors: [
color_attachments: [
Some((
view: Id(0, 1),
view: PointerId(0x10),
resolve_target: None,
load_op: load,
store_op: store,
@@ -57,16 +57,16 @@
),
)),
],
target_depth_stencil: None,
depth_stencil_attachment: None,
),
CopyTextureToBuffer(
src: (
texture: Id(0, 1),
texture: PointerId(0x10),
mip_level: 0,
array_layer: 0,
),
dst: (
buffer: Id(0, 1),
buffer: PointerId(0x10),
layout: (
offset: 0,
bytes_per_row: Some(256),
+43 -74
View File
@@ -13,20 +13,15 @@
extern crate wgpu_core as wgc;
extern crate wgpu_types as wgt;
use player::GlobalPlay;
use player::Player;
use std::{
fs::{read_to_string, File},
io::{Read, Seek, SeekFrom},
path::{Path, PathBuf},
slice,
sync::Arc,
};
use wgc::{command::IdReferences, identity::IdentityManager};
#[derive(serde::Deserialize)]
struct RawId {
index: u32,
epoch: u32,
}
use wgc::command::PointerReferences;
#[derive(serde::Deserialize)]
enum ExpectedData {
@@ -48,7 +43,7 @@ impl ExpectedData {
#[derive(serde::Deserialize)]
struct Expectation {
name: String,
buffer: RawId,
buffer: wgc::id::PointerId<wgc::id::markers::Buffer>,
offset: wgt::BufferAddress,
data: ExpectedData,
}
@@ -57,7 +52,7 @@ struct Expectation {
struct Test<'a> {
features: wgt::Features,
expectations: Vec<Expectation>,
actions: Vec<wgc::device::trace::Action<'a, IdReferences>>,
actions: Vec<wgc::device::trace::Action<'a, PointerReferences>>,
}
fn map_callback(status: Result<(), wgc::resource::BufferAccessError>) {
@@ -82,48 +77,34 @@ impl Test<'_> {
fn run(
self,
dir: &Path,
global: &wgc::global::Global,
adapter: wgc::id::AdapterId,
test_num: u32,
instance_desc: &wgt::InstanceDescriptor,
adapter: Arc<wgc::instance::Adapter>,
) {
let device_id = wgc::id::Id::zip(test_num, 1);
let queue_id = wgc::id::Id::zip(test_num, 1);
let res = global.adapter_request_device(
adapter,
&wgt::DeviceDescriptor {
label: None,
required_features: self.features,
required_limits: wgt::Limits::default(),
experimental_features: unsafe { wgt::ExperimentalFeatures::enabled() },
memory_hints: wgt::MemoryHints::default(),
trace: wgt::Trace::Off,
},
Some(device_id),
Some(queue_id),
);
if let Err(e) = res {
panic!("{e:?}");
}
let (device, queue) = adapter
.create_device_and_queue(
&wgt::DeviceDescriptor {
label: None,
required_features: self.features,
required_limits: wgt::Limits::default(),
experimental_features: unsafe { wgt::ExperimentalFeatures::enabled() },
memory_hints: wgt::MemoryHints::default(),
trace: wgt::Trace::Off,
},
instance_desc.flags,
)
.unwrap();
let mut player = Player::default();
let mut command_encoder_id_manager = IdentityManager::new();
let mut command_buffer_id_manager = IdentityManager::new();
println!("\t\t\tRunning...");
for action in self.actions {
global.process(
device_id,
queue_id,
action,
dir,
&mut command_encoder_id_manager,
&mut command_buffer_id_manager,
);
player.process(&device, &queue, action, dir);
}
println!("\t\t\tMapping...");
for expect in &self.expectations {
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch);
global
.buffer_map_async(
buffer,
player
.get_buffer(expect.buffer)
.map_async(
expect.offset,
Some(expect.data.len() as u64),
wgc::resource::BufferMapOperation {
@@ -135,25 +116,18 @@ impl Test<'_> {
}
println!("\t\t\tWaiting...");
global
.device_poll(
device_id,
wgt::PollType::Wait {
submission_index: None,
timeout: Some(std::time::Duration::from_secs(1)), // Tests really shouldn't need longer than that!
},
)
.unwrap();
let (user_closures, result) = device.poll(wgt::PollType::Wait {
submission_index: None,
timeout: Some(std::time::Duration::from_secs(1)), // Tests really shouldn't need longer than that!
});
user_closures.fire();
result.unwrap();
for expect in self.expectations {
println!("\t\t\tChecking {}", expect.name);
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch);
let (ptr, size) = global
.buffer_get_mapped_range(
buffer,
expect.offset,
Some(expect.data.len() as wgt::BufferAddress),
)
let (ptr, size) = player
.get_buffer(expect.buffer)
.get_mapped_range(expect.offset, Some(expect.data.len() as wgt::BufferAddress))
.unwrap();
let contents = unsafe { slice::from_raw_parts(ptr.as_ptr(), size as usize) };
let expected_data = match expect.data {
@@ -204,30 +178,26 @@ impl Corpus {
if !corpus.backends.contains(backend.into()) {
continue;
}
let mut test_num = 0;
for test_path in &corpus.tests {
println!("\t\tTest '{test_path:?}'");
let global = wgc::global::Global::new(
"test",
&wgt::InstanceDescriptor::from_env_or_default(),
);
let adapter = match global.request_adapter(
&wgc::instance::RequestAdapterOptions {
let instance_desc = wgt::InstanceDescriptor::from_env_or_default();
let instance = wgc::instance::Instance::new("test", &instance_desc);
let adapter = match instance.request_adapter(
&wgt::RequestAdapterOptions {
power_preference: wgt::PowerPreference::None,
force_fallback_adapter: false,
compatible_surface: None,
},
wgt::Backends::from(backend),
Some(wgc::id::Id::zip(0, 1)),
) {
Ok(adapter) => adapter,
Ok(adapter) => Arc::new(adapter),
Err(_) => continue,
};
println!("\tBackend {backend:?}");
let supported_features = global.adapter_features(adapter);
let downlevel_caps = global.adapter_downlevel_capabilities(adapter);
let supported_features = adapter.features();
let downlevel_caps = adapter.downlevel_capabilities();
let test = Test::load(dir.join(test_path), backend);
if !supported_features.contains(test.features) {
@@ -244,8 +214,7 @@ impl Corpus {
println!("\t\tSkipped due to missing compute shader capability");
continue;
}
test.run(dir, &global, adapter, test_num);
test_num += 1;
test.run(dir, &instance_desc, adapter);
}
}
}
+1 -2
View File
@@ -173,7 +173,6 @@ impl RenderBundleEncoder {
pub fn new(
desc: &RenderBundleEncoderDescriptor,
parent_id: id::DeviceId,
base: Option<BasePass<RenderCommand<IdReferences>, Infallible>>,
) -> Result<Self, CreateRenderBundleError> {
let (is_depth_read_only, is_stencil_read_only) = match desc.depth_stencil {
Some(ds) => {
@@ -195,7 +194,7 @@ impl RenderBundleEncoder {
//TODO: validate that attachment formats are renderable,
// have expected aspects, support multisampling.
Ok(Self {
base: base.unwrap_or_else(|| BasePass::new(&desc.label)),
base: BasePass::new(&desc.label),
parent_id,
context: RenderPassContext {
attachments: AttachmentData {
+32 -4
View File
@@ -31,13 +31,14 @@ mod transition_resources;
use alloc::{borrow::ToOwned as _, boxed::Box, string::String, sync::Arc, vec::Vec};
use core::convert::Infallible;
use core::mem::{self, ManuallyDrop};
use core::ops;
use core::{ops, panic};
pub(crate) use self::clear::clear_texture;
#[cfg(feature = "serde")]
pub(crate) use self::encoder_command::serde_object_reference_struct;
#[cfg(feature = "trace")]
pub(crate) use self::encoder_command::PointerReferences;
#[cfg(any(feature = "trace", feature = "replay"))]
#[doc(hidden)]
pub use self::encoder_command::PointerReferences;
pub use self::{
bundle::*,
clear::ClearError,
@@ -152,6 +153,14 @@ pub(crate) enum CommandEncoderStatus {
}
impl CommandEncoderStatus {
#[doc(hidden)]
fn replay(&mut self, commands: Vec<Command<ArcReferences>>) {
let Self::Recording(cmd_buf_data) = self else {
panic!("encoder should be in the recording state");
};
cmd_buf_data.commands.extend(commands);
}
/// Push a command provided by a closure onto the encoder.
///
/// If the encoder is in the [`Self::Recording`] state, calls the closure to
@@ -1187,6 +1196,26 @@ impl CommandEncoder {
}
impl CommandBuffer {
/// Replay commands from a trace.
///
/// This is exposed for the `player` crate only. It is not a public API.
/// It is not guaranteed to apply all of the validation that the original
/// entrypoints provide.
#[doc(hidden)]
pub fn from_trace(device: &Arc<Device>, commands: Vec<Command<ArcReferences>>) -> Arc<Self> {
let encoder = device.create_command_encoder(&None).unwrap();
let mut cmd_enc_status = encoder.data.lock();
cmd_enc_status.replay(commands);
drop(cmd_enc_status);
let (cmd_buf, error) = encoder.finish(&wgt::CommandBufferDescriptor { label: None });
if let Some(err) = error {
panic!("CommandEncoder::finish failed: {err}");
}
cmd_buf
}
pub fn take_finished(&self) -> Result<CommandBufferMutable, CommandEncoderError> {
use CommandEncoderStatus as St;
match mem::replace(
@@ -1569,7 +1598,6 @@ impl Global {
profiling::scope!("CommandEncoder::finish");
let hub = &self.hub;
let cmd_enc = hub.command_encoders.get(encoder_id);
let (cmd_buf, error) = cmd_enc.finish(desc);
+3 -32
View File
@@ -215,18 +215,6 @@ impl Global {
fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
}
#[cfg(feature = "replay")]
pub fn device_set_buffer_data(
&self,
buffer_id: id::BufferId,
offset: BufferAddress,
data: &[u8],
) -> BufferAccessResult {
let buffer = self.hub.buffers.get(buffer_id).get()?;
let device = &buffer.device;
device.set_buffer_data(&buffer, offset, data)
}
pub fn buffer_destroy(&self, buffer_id: id::BufferId) {
profiling::scope!("Buffer::destroy");
api_log!("Buffer::destroy {buffer_id:?}");
@@ -1184,7 +1172,7 @@ impl Global {
) {
profiling::scope!("Device::create_render_bundle_encoder");
api_log!("Device::device_create_render_bundle_encoder");
let (encoder, error) = match command::RenderBundleEncoder::new(desc, device_id, None) {
let (encoder, error) = match command::RenderBundleEncoder::new(desc, device_id) {
Ok(encoder) => (encoder, None),
Err(e) => (command::RenderBundleEncoder::dummy(device_id), Some(e)),
};
@@ -1804,30 +1792,13 @@ impl Global {
let device = self.hub.devices.get(device_id);
let (closures, result) = Self::poll_single_device(&device, poll_type);
let (closures, result) = device.poll(poll_type);
closures.fire();
result
}
fn poll_single_device(
device: &crate::device::Device,
poll_type: wgt::PollType<crate::SubmissionIndex>,
) -> (UserClosures, Result<wgt::PollStatus, WaitIdleError>) {
let snatch_guard = device.snatchable_lock.read();
let fence = device.fence.read();
let maintain_result = device.maintain(fence, poll_type, snatch_guard);
device.lose_if_oom();
// Some deferred destroys are scheduled in maintain so run this right after
// to avoid holding on to them until the next device poll.
device.deferred_resource_destruction();
maintain_result
}
/// Poll all devices belonging to the specified backend.
///
/// If `force_wait` is true, block until all buffer mappings are done.
@@ -1854,7 +1825,7 @@ impl Global {
wgt::PollType::Poll
};
let (closures, result) = Self::poll_single_device(device, poll_type);
let (closures, result) = device.poll(poll_type);
let is_queue_empty = matches!(result, Ok(wgt::PollStatus::QueueEmpty));
+2 -1
View File
@@ -174,7 +174,8 @@ impl UserClosures {
.extend(other.device_lost_invocations);
}
fn fire(self) {
/// Not a public API. For use by `player` only.
pub fn fire(self) {
// Note: this logic is specifically moved out of `handle_mapping()` in order to
// have nothing locked by the time we execute users callback code.
+2 -2
View File
@@ -25,7 +25,7 @@ use hal::AccelerationStructureTriangleIndices;
use wgt::Features;
impl Device {
fn create_blas(
pub fn create_blas(
self: &Arc<Self>,
blas_desc: &resource::BlasDescriptor,
sizes: wgt::BlasGeometrySizeDescriptors,
@@ -172,7 +172,7 @@ impl Device {
}))
}
fn create_tlas(
pub fn create_tlas(
self: &Arc<Self>,
desc: &resource::TlasDescriptor,
) -> Result<Arc<resource::Tlas>, CreateTlasError> {
+31 -12
View File
@@ -712,6 +712,23 @@ impl Device {
assert!(self.queue.set(Arc::downgrade(queue)).is_ok());
}
pub fn poll(
&self,
poll_type: wgt::PollType<crate::SubmissionIndex>,
) -> (UserClosures, Result<wgt::PollStatus, WaitIdleError>) {
let snatch_guard = self.snatchable_lock.read();
let fence = self.fence.read();
let maintain_result = self.maintain(fence, poll_type, snatch_guard);
self.lose_if_oom();
// Some deferred destroys are scheduled in maintain so run this right after
// to avoid holding on to them until the next device poll.
self.deferred_resource_destruction();
maintain_result
}
/// Check the current status of the GPU and process any submissions that have
/// finished.
///
@@ -881,7 +898,7 @@ impl Device {
(user_closures, result)
}
pub(crate) fn create_buffer(
pub fn create_buffer(
self: &Arc<Self>,
desc: &resource::BufferDescriptor,
) -> Result<Arc<Buffer>, resource::CreateBufferError> {
@@ -1239,7 +1256,7 @@ impl Device {
}
}
pub(crate) fn create_texture(
pub fn create_texture(
self: &Arc<Self>,
desc: &resource::TextureDescriptor,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
@@ -1577,7 +1594,7 @@ impl Device {
Ok(texture)
}
pub(crate) fn create_texture_view(
pub fn create_texture_view(
self: &Arc<Self>,
texture: &Arc<Texture>,
desc: &resource::TextureViewDescriptor,
@@ -1915,7 +1932,7 @@ impl Device {
Ok(view)
}
pub(crate) fn create_external_texture(
pub fn create_external_texture(
self: &Arc<Self>,
desc: &resource::ExternalTextureDescriptor,
planes: &[Arc<TextureView>],
@@ -2010,7 +2027,7 @@ impl Device {
Ok(external_texture)
}
pub(crate) fn create_sampler(
pub fn create_sampler(
self: &Arc<Self>,
desc: &resource::SamplerDescriptor,
) -> Result<Arc<Sampler>, resource::CreateSamplerError> {
@@ -2121,7 +2138,7 @@ impl Device {
Ok(sampler)
}
pub(crate) fn create_shader_module<'a>(
pub fn create_shader_module<'a>(
self: &Arc<Self>,
desc: &pipeline::ShaderModuleDescriptor<'a>,
source: pipeline::ShaderModuleSource<'a>,
@@ -2249,8 +2266,10 @@ impl Device {
Ok(module)
}
/// Not a public API. For use by `player` only.
#[allow(unused_unsafe)]
pub(crate) unsafe fn create_shader_module_passthrough<'a>(
#[doc(hidden)]
pub unsafe fn create_shader_module_passthrough<'a>(
self: &Arc<Self>,
descriptor: &pipeline::ShaderModuleDescriptorPassthrough<'a>,
) -> Result<Arc<pipeline::ShaderModule>, pipeline::CreateShaderModuleError> {
@@ -3036,7 +3055,7 @@ impl Device {
// This function expects the provided bind group layout to be resolved
// (not passing a duplicate) beforehand.
pub(crate) fn create_bind_group(
pub fn create_bind_group(
self: &Arc<Self>,
desc: binding_model::ResolvedBindGroupDescriptor,
) -> Result<Arc<BindGroup>, binding_model::CreateBindGroupError> {
@@ -3491,7 +3510,7 @@ impl Device {
}
}
pub(crate) fn create_pipeline_layout(
pub fn create_pipeline_layout(
self: &Arc<Self>,
desc: &binding_model::ResolvedPipelineLayoutDescriptor,
) -> Result<Arc<binding_model::PipelineLayout>, binding_model::CreatePipelineLayoutError> {
@@ -3648,7 +3667,7 @@ impl Device {
Ok(layout)
}
pub(crate) fn create_compute_pipeline(
pub fn create_compute_pipeline(
self: &Arc<Self>,
desc: pipeline::ResolvedComputePipelineDescriptor,
) -> Result<Arc<pipeline::ComputePipeline>, pipeline::CreateComputePipelineError> {
@@ -3781,7 +3800,7 @@ impl Device {
Ok(pipeline)
}
pub(crate) fn create_render_pipeline(
pub fn create_render_pipeline(
self: &Arc<Self>,
desc: pipeline::ResolvedGeneralRenderPipelineDescriptor,
) -> Result<Arc<pipeline::RenderPipeline>, pipeline::CreateRenderPipelineError> {
@@ -4676,7 +4695,7 @@ impl Device {
Ok(())
}
pub(crate) fn create_query_set(
pub fn create_query_set(
self: &Arc<Self>,
desc: &resource::QuerySetDescriptor,
) -> Result<Arc<QuerySet>, resource::CreateQuerySetError> {
+19 -2
View File
@@ -425,6 +425,14 @@ pub struct MeshState<'a, SM = ShaderModuleId> {
pub type ResolvedMeshState<'a> = MeshState<'a, Arc<ShaderModule>>;
/// Describes a vertex processor for either a conventional or mesh shading
/// pipeline architecture.
///
/// This is not a public API. It is for use by `player` only. The public APIs
/// are [`VertexState`], [`TaskState`], and [`MeshState`].
///
/// cbindgen:ignore
#[doc(hidden)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RenderPipelineVertexProcessor<'a, SM = ShaderModuleId> {
@@ -497,7 +505,14 @@ pub struct MeshPipelineDescriptor<
pub cache: Option<PLC>,
}
/// Describes a render (graphics) pipeline.
/// Describes a render (graphics) pipeline, with either conventional or mesh
/// shading architecture.
///
/// This is not a public API. It is for use by `player` only. The public APIs
/// are [`RenderPipelineDescriptor`] and [`MeshPipelineDescriptor`].
///
/// cbindgen:ignore
#[doc(hidden)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GeneralRenderPipelineDescriptor<
@@ -563,8 +578,10 @@ impl<'a, PLL, SM, PLC> From<MeshPipelineDescriptor<'a, PLL, SM, PLC>>
}
}
/// Not a public API. For use by `player` only.
///
/// cbindgen:ignore
pub(crate) type ResolvedGeneralRenderPipelineDescriptor<'a> =
pub type ResolvedGeneralRenderPipelineDescriptor<'a> =
GeneralRenderPipelineDescriptor<'a, Arc<PipelineLayout>, Arc<ShaderModule>, Arc<PipelineCache>>;
#[derive(Clone, Debug)]
+5 -5
View File
@@ -573,7 +573,7 @@ impl Buffer {
/// Returns the mapping callback in case of error so that the callback can be fired outside
/// of the locks that are held in this function.
pub(crate) fn map_async(
pub fn map_async(
self: &Arc<Self>,
offset: wgt::BufferAddress,
size: Option<wgt::BufferAddress>,
@@ -797,7 +797,7 @@ impl Buffer {
}
// Note: This must not be called while holding a lock.
pub(crate) fn unmap(self: &Arc<Self>) -> Result<(), BufferAccessError> {
pub fn unmap(self: &Arc<Self>) -> Result<(), BufferAccessError> {
if let Some((mut operation, status)) = self.unmap_inner()? {
if let Some(callback) = operation.callback.take() {
callback(status);
@@ -902,7 +902,7 @@ impl Buffer {
Ok(None)
}
pub(crate) fn destroy(self: &Arc<Self>) {
pub fn destroy(self: &Arc<Self>) {
let device = &self.device;
let temp = {
@@ -1404,7 +1404,7 @@ impl Texture {
}
}
pub(crate) fn destroy(self: &Arc<Self>) {
pub fn destroy(self: &Arc<Self>) {
let device = &self.device;
let temp = {
@@ -1904,7 +1904,7 @@ impl Drop for ExternalTexture {
}
impl ExternalTexture {
pub(crate) fn destroy(self: &Arc<Self>) {
pub fn destroy(self: &Arc<Self>) {
self.params.destroy();
}
}
+1 -1
View File
@@ -1779,7 +1779,7 @@ impl dispatch::DeviceInterface for CoreDevice {
sample_count: desc.sample_count,
multiview: desc.multiview,
};
let encoder = match wgc::command::RenderBundleEncoder::new(&descriptor, self.id, None) {
let encoder = match wgc::command::RenderBundleEncoder::new(&descriptor, self.id) {
Ok(encoder) => encoder,
Err(e) => panic!("Error in Device::create_render_bundle_encoder: {e}"),
};