Replace borrowed slices in Descriptor structs with copy on write slices (#822)

* Replace &[T] in descriptor structs with Cow<[T]>

* Changed label fields to use Cow<'a, str>

* Deduplicate types across the tracing API

Introduce the ToStatic trait

* Deduplicate trace::RenderBundleDescriptor

* Remove ugly ToOwned bounds

* Simplifiy Action variants

* Make Clone bounds on type defs less verbose

* Fix a error in play.rs

* Remove ToStatic, and Make Action<'a> borrow descriptors instead
This commit is contained in:
Marvin Löbel authored and GitHub committed 2020-07-20 12:31:05 -04:00
1 parent 3c6ee8766a
commit 4ed2c0a313
9 files changed
+162 -402

No files matched your search

+1 -1
View File
@@ -119,7 +119,7 @@ fn main() {
}
Event::RedrawRequested(_) => loop {
match actions.pop() {
Some(trace::Action::CreateSwapChain { id, desc }) => {
Some(trace::Action::CreateSwapChain(id, desc)) => {
log::info!("Initializing the swapchain");
assert_eq!(id.to_surface_id(), surface);
window.set_inner_size(winit::dpi::PhysicalSize::new(
+21 -127
View File
@@ -152,7 +152,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
A::CreateSwapChain { .. } | A::PresentSwapChain(_) => {
panic!("Unexpected SwapChain action: winit feature is not enabled")
}
A::CreateBuffer { id, desc } => {
A::CreateBuffer(id, desc) => {
let label = Label::new(&desc.label);
self.device_maintain_ids::<B>(device);
self.device_create_buffer::<B>(device, &desc.map_label(|_| label.as_ptr()), id)
@@ -161,7 +161,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
A::DestroyBuffer(id) => {
self.buffer_destroy::<B>(id);
}
A::CreateTexture { id, desc } => {
A::CreateTexture(id, desc) => {
let label = Label::new(&desc.label);
self.device_maintain_ids::<B>(device);
self.device_create_texture::<B>(device, &desc.map_label(|_| label.as_ptr()), id)
@@ -186,7 +186,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
A::DestroyTextureView(id) => {
self.texture_view_destroy::<B>(id);
}
A::CreateSampler { id, desc } => {
A::CreateSampler(id, desc) => {
let label = Label::new(&desc.label);
self.device_maintain_ids::<B>(device);
self.device_create_sampler::<B>(device, &desc.map_label(|_| label.as_ptr()), id);
@@ -202,83 +202,25 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
.unwrap();
}
}
A::CreateBindGroupLayout {
id,
ref label,
ref entries,
} => {
self.device_create_bind_group_layout::<B>(
device,
&wgt::BindGroupLayoutDescriptor {
label: Some(label),
entries,
},
id,
)
.unwrap();
A::CreateBindGroupLayout(id, desc) => {
self.device_create_bind_group_layout::<B>(device, &desc, id)
.unwrap();
}
A::DestroyBindGroupLayout(id) => {
self.bind_group_layout_destroy::<B>(id);
}
A::CreatePipelineLayout {
id,
bind_group_layouts,
push_constant_ranges,
} => {
A::CreatePipelineLayout(id, desc) => {
self.device_maintain_ids::<B>(device);
self.device_create_pipeline_layout::<B>(
device,
&wgt::PipelineLayoutDescriptor {
bind_group_layouts: &bind_group_layouts,
push_constant_ranges: &push_constant_ranges,
},
id,
)
.unwrap();
self.device_create_pipeline_layout::<B>(device, &desc, id)
.unwrap();
}
A::DestroyPipelineLayout(id) => {
self.pipeline_layout_destroy::<B>(id);
}
A::CreateBindGroup {
id,
label,
layout_id,
entries,
} => {
use wgc::binding_model as bm;
let entry_vec = entries
.iter()
.map(|(binding, res)| wgc::binding_model::BindGroupEntry {
binding: *binding,
resource: match *res {
trace::BindingResource::Buffer { id, offset, size } => {
bm::BindingResource::Buffer(bm::BufferBinding {
buffer_id: id,
offset,
size,
})
}
trace::BindingResource::Sampler(id) => bm::BindingResource::Sampler(id),
trace::BindingResource::TextureView(id) => {
bm::BindingResource::TextureView(id)
}
trace::BindingResource::TextureViewArray(ref binding_array) => {
bm::BindingResource::TextureViewArray(binding_array)
}
},
})
.collect::<Vec<_>>();
A::CreateBindGroup(id, desc) => {
self.device_maintain_ids::<B>(device);
self.device_create_bind_group::<B>(
device,
&wgc::binding_model::BindGroupDescriptor {
label: Some(&label),
layout: layout_id,
entries: &entry_vec,
},
id,
)
.unwrap();
self.device_create_bind_group::<B>(device, &desc, id)
.unwrap();
}
A::DestroyBindGroup(id) => {
self.bind_group_destroy::<B>(id);
@@ -298,74 +240,26 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
A::DestroyShaderModule(id) => {
self.shader_module_destroy::<B>(id);
}
A::CreateComputePipeline { id, desc } => {
let compute_stage = desc.compute_stage.to_core();
A::CreateComputePipeline(id, desc) => {
self.device_maintain_ids::<B>(device);
self.device_create_compute_pipeline::<B>(
device,
&wgc::pipeline::ComputePipelineDescriptor {
layout: desc.layout,
compute_stage,
},
id,
)
.unwrap();
self.device_create_compute_pipeline::<B>(device, &desc, id)
.unwrap();
}
A::DestroyComputePipeline(id) => {
self.compute_pipeline_destroy::<B>(id);
}
A::CreateRenderPipeline { id, desc } => {
let vertex_stage = desc.vertex_stage.to_core();
let fragment_stage = desc.fragment_stage.as_ref().map(|fs| fs.to_core());
let vertex_buffers = desc
.vertex_state
.vertex_buffers
.iter()
.map(|vb| wgt::VertexBufferDescriptor {
stride: vb.stride,
step_mode: vb.step_mode,
attributes: &vb.attributes,
})
.collect::<Vec<_>>();
A::CreateRenderPipeline(id, desc) => {
self.device_maintain_ids::<B>(device);
self.device_create_render_pipeline::<B>(
device,
&wgc::pipeline::RenderPipelineDescriptor {
layout: desc.layout,
vertex_stage,
fragment_stage,
primitive_topology: desc.primitive_topology,
rasterization_state: desc.rasterization_state,
color_states: &desc.color_states,
depth_stencil_state: desc.depth_stencil_state,
vertex_state: wgt::VertexStateDescriptor {
index_format: desc.vertex_state.index_format,
vertex_buffers: &vertex_buffers,
},
sample_count: desc.sample_count,
sample_mask: desc.sample_mask,
alpha_to_coverage_enabled: desc.alpha_to_coverage_enabled,
},
id,
)
.unwrap();
self.device_create_render_pipeline::<B>(device, &desc, id)
.unwrap();
}
A::DestroyRenderPipeline(id) => {
self.render_pipeline_destroy::<B>(id);
}
A::CreateRenderBundle { id, desc, base } => {
let label = Label::new(&desc.label);
let bundle = wgc::command::RenderBundleEncoder::new(
&wgt::RenderBundleEncoderDescriptor {
label: None,
color_formats: &desc.color_formats,
depth_stencil_format: desc.depth_stencil_format,
sample_count: desc.sample_count,
},
device,
Some(base),
)
.unwrap();
let label = Label::new(&desc.label.as_ref().unwrap());
let bundle =
wgc::command::RenderBundleEncoder::new(&desc, device, Some(base)).unwrap();
self.render_bundle_encoder_finish::<B>(
bundle,
&wgt::RenderBundleDescriptor {
+2 -2
View File
@@ -10,8 +10,8 @@
],
actions: [
CreateBuffer(
id: Id(0, 1, Empty),
desc: (
Id(0, 1, Empty),
(
label: "",
size: 16,
usage: (
+3 -3
View File
@@ -35,10 +35,10 @@ struct Expectation {
}
#[derive(serde::Deserialize)]
struct Test {
struct Test<'a> {
features: wgt::Features,
expectations: Vec<Expectation>,
actions: Vec<wgc::device::trace::Action>,
actions: Vec<wgc::device::trace::Action<'a>>,
}
extern "C" fn map_callback(status: wgc::resource::BufferMapAsyncStatus, _user_data: *mut u8) {
@@ -48,7 +48,7 @@ extern "C" fn map_callback(status: wgc::resource::BufferMapAsyncStatus, _user_da
}
}
impl Test {
impl Test<'_> {
fn load(path: PathBuf, backend: wgt::Backend) -> Self {
let backend_name = match backend {
wgt::Backend::Vulkan => "Vulkan",
+8 -3
View File
@@ -17,7 +17,10 @@ use serde::Deserialize;
#[cfg(feature = "trace")]
use serde::Serialize;
use std::{borrow::Borrow, ops::Range};
use std::{
borrow::{Borrow, Cow},
ops::Range,
};
use thiserror::Error;
@@ -396,12 +399,14 @@ pub struct BufferBinding {
// Note: Duplicated in `wgpu-rs` as `BindingResource`
// They're different enough that it doesn't make sense to share a common type
#[derive(Debug)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub enum BindingResource<'a> {
Buffer(BufferBinding),
Sampler(SamplerId),
TextureView(TextureViewId),
TextureViewArray(&'a [TextureViewId]),
TextureViewArray(Cow<'a, [TextureViewId]>),
}
pub type BindGroupEntry<'a> = wgt::BindGroupEntry<BindingResource<'a>>;
+1 -1
View File
@@ -922,7 +922,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let bundle = &bundle_guard[id];
trace.lock().add(trace::Action::CreateRenderBundle {
id,
desc: trace::RenderBundleDescriptor::new(desc.label, &bundle.context),
desc: trace::new_render_bundle_encoder_descriptor(desc.label, &bundle.context),
base: BasePass::from_ref(bundle.base.as_ref()),
});
}
+44 -102
View File
@@ -731,7 +731,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if mapped_at_creation && !desc.usage.contains(wgt::BufferUsage::MAP_WRITE) {
desc.usage |= wgt::BufferUsage::COPY_DST;
}
trace.lock().add(trace::Action::CreateBuffer { id, desc })
trace.lock().add(trace::Action::CreateBuffer(id, desc))
}
None => (),
};
@@ -915,10 +915,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.textures.register_identity(id_in, texture, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateTexture {
id,
desc: desc.map_label(own_label),
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateTexture(id, desc.map_label(own_label))),
None => (),
};
@@ -1137,10 +1136,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let id = hub.samplers.register_identity(id_in, sampler, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateSampler {
id,
desc: desc.map_label(own_label),
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateSampler(id, desc.map_label(own_label))),
None => (),
};
@@ -1185,7 +1183,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut token = Token::root();
let hub = B::hub(self);
let mut entry_map = FastHashMap::default();
for entry in desc.entries {
for entry in desc.entries.iter() {
if entry_map.insert(entry.binding, entry.clone()).is_some() {
return Err(binding_model::BindGroupLayoutError::ConflictBinding(
entry.binding,
@@ -1256,7 +1254,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.raw
.create_descriptor_set_layout(&raw_bindings, &[])
.unwrap();
if let Some(label) = desc.label {
if let Some(label) = desc.label.as_ref() {
device
.raw
.set_descriptor_set_layout_name(&mut raw_layout, label);
@@ -1296,11 +1294,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.register_identity(id_in, layout, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateBindGroupLayout {
id,
label: desc.label.map_or_else(String::new, str::to_string),
entries: desc.entries.to_owned(),
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateBindGroupLayout(id, desc.clone())),
None => (),
};
Ok(id)
@@ -1400,7 +1396,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut count_validator = binding_model::BindingTypeMaxCountValidator::default();
let pipeline_layout = {
let (bind_group_layout_guard, _) = hub.bind_group_layouts.read(&mut token);
for &id in desc.bind_group_layouts {
for &id in desc.bind_group_layouts.iter() {
let bind_group_layout = &bind_group_layout_guard[id];
count_validator.merge(&bind_group_layout.count_validator);
}
@@ -1448,11 +1444,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.register_identity(id_in, layout, &mut token);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreatePipelineLayout {
id,
bind_group_layouts: desc.bind_group_layouts.to_owned(),
push_constant_ranges: desc.push_constant_ranges.iter().cloned().collect(),
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreatePipelineLayout(id, desc.clone())),
None => (),
};
Ok(id)
@@ -1526,7 +1520,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
// Set the descriptor set's label for easier debugging.
if let Some(label) = desc.label {
if let Some(label) = desc.label.as_ref() {
unsafe {
device
.raw
@@ -1551,7 +1545,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
//TODO: group writes into contiguous sections
let mut writes = Vec::new();
for entry in desc.entries {
for entry in desc.entries.iter() {
let binding = entry.binding;
// Find the corresponding declaration in the layout
let decl = bind_group_layout
@@ -1844,30 +1838,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateBindGroup {
id,
label: desc.label.map_or_else(String::new, str::to_string),
layout_id: desc.layout,
entries: desc
.entries
.iter()
.map(|entry| {
let res = match entry.resource {
Br::Buffer(ref binding) => trace::BindingResource::Buffer {
id: binding.buffer_id,
offset: binding.offset,
size: binding.size,
},
Br::TextureView(id) => trace::BindingResource::TextureView(id),
Br::Sampler(id) => trace::BindingResource::Sampler(id),
Br::TextureViewArray(ref binding_array) => {
trace::BindingResource::TextureViewArray(binding_array.to_vec())
}
};
(entry.binding, res)
})
.collect(),
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateBindGroup(id, desc.clone())),
None => (),
};
@@ -2132,7 +2105,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
sc as u8
};
let color_states = desc.color_states;
let color_states = &desc.color_states;
let depth_stencil_state = desc.depth_stencil_state.as_ref();
let rasterization_state = desc.rasterization_state.as_ref();
@@ -2143,7 +2116,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut interface = validation::StageInterface::default();
let mut validated_stages = wgt::ShaderStage::empty();
let desc_vbs = desc.vertex_state.vertex_buffers;
let desc_vbs = &desc.vertex_state.vertex_buffers;
let mut vertex_strides = Vec::with_capacity(desc_vbs.len());
let mut vertex_buffers = Vec::with_capacity(desc_vbs.len());
let mut attributes = Vec::new();
@@ -2162,8 +2135,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
InputStepMode::Instance => hal::pso::VertexInputRate::Instance(1),
},
});
let desc_atts = vb_state.attributes;
for attribute in desc_atts {
let desc_atts = &vb_state.attributes;
for attribute in desc_atts.iter() {
if attribute.offset >= 0x10000000 {
return Err(
pipeline::RenderPipelineError::InvalidVertexAttributeOffset {
@@ -2276,7 +2249,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
let vertex = {
let entry_point_name = desc.vertex_stage.entry_point;
let entry_point_name = &desc.vertex_stage.entry_point;
let shader_module = &shader_module_guard[desc.vertex_stage.module];
@@ -2285,7 +2258,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
interface = validation::check_stage(
module,
&group_layouts,
entry_point_name,
&entry_point_name,
ExecutionModel::Vertex,
interface,
)
@@ -2294,7 +2267,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
hal::pso::EntryPoint::<B> {
entry: entry_point_name, // TODO
entry: &entry_point_name, // TODO
module: &shader_module.raw,
specialization: hal::pso::Specialization::EMPTY,
}
@@ -2302,7 +2275,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let fragment = match &desc.fragment_stage {
Some(stage) => {
let entry_point_name = stage.entry_point;
let entry_point_name = &stage.entry_point;
let shader_module = &shader_module_guard[stage.module];
@@ -2312,7 +2285,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
interface = validation::check_stage(
module,
&group_layouts,
entry_point_name,
&entry_point_name,
ExecutionModel::Fragment,
interface,
)
@@ -2324,7 +2297,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
Some(hal::pso::EntryPoint::<B> {
entry: entry_point_name,
entry: &entry_point_name,
module: &shader_module.raw,
specialization: hal::pso::Specialization::EMPTY,
})
@@ -2408,7 +2381,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
let mut flags = pipeline::PipelineFlags::empty();
for state in color_states {
for state in color_states.iter() {
if state.color_blend.uses_color() | state.alpha_blend.uses_color() {
flags |= pipeline::PipelineFlags::BLEND_COLOR;
}
@@ -2445,35 +2418,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateRenderPipeline {
id,
desc: trace::RenderPipelineDescriptor {
layout: desc.layout,
vertex_stage: trace::ProgrammableStageDescriptor::new(&desc.vertex_stage),
fragment_stage: desc
.fragment_stage
.as_ref()
.map(trace::ProgrammableStageDescriptor::new),
primitive_topology: desc.primitive_topology,
rasterization_state: rasterization_state.cloned(),
color_states: color_states.to_vec(),
depth_stencil_state: depth_stencil_state.cloned(),
vertex_state: trace::VertexStateDescriptor {
index_format: desc.vertex_state.index_format,
vertex_buffers: desc_vbs
.iter()
.map(|vbl| trace::VertexBufferDescriptor {
stride: vbl.stride,
step_mode: vbl.step_mode,
attributes: vbl.attributes.to_owned(),
})
.collect(),
},
sample_count: desc.sample_count,
sample_mask: desc.sample_mask,
alpha_to_coverage_enabled: desc.alpha_to_coverage_enabled,
},
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateRenderPipeline(id, desc.clone())),
None => (),
};
Ok(id)
@@ -2530,7 +2477,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let pipeline_stage = &desc.compute_stage;
let (shader_module_guard, _) = hub.shader_modules.read(&mut token);
let entry_point_name = pipeline_stage.entry_point;
let entry_point_name = &pipeline_stage.entry_point;
let shader_module = &shader_module_guard[pipeline_stage.module];
@@ -2538,7 +2485,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let _ = validation::check_stage(
module,
&group_layouts,
entry_point_name,
&entry_point_name,
ExecutionModel::GLCompute,
interface,
)
@@ -2546,7 +2493,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
let shader = hal::pso::EntryPoint::<B> {
entry: entry_point_name, // TODO
entry: &entry_point_name, // TODO
module: &shader_module.raw,
specialization: hal::pso::Specialization::EMPTY,
};
@@ -2590,13 +2537,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(trace::Action::CreateComputePipeline {
id,
desc: trace::ComputePipelineDescriptor {
layout: desc.layout,
compute_stage: trace::ProgrammableStageDescriptor::new(&desc.compute_stage),
},
}),
Some(ref trace) => trace
.lock()
.add(trace::Action::CreateComputePipeline(id, desc.clone())),
None => (),
};
Ok(id)
@@ -2722,10 +2665,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
#[cfg(feature = "trace")]
match device.trace {
Some(ref trace) => trace.lock().add(Action::CreateSwapChain {
id: sc_id,
desc: desc.clone(),
}),
Some(ref trace) => trace
.lock()
.add(Action::CreateSwapChain(sc_id, desc.clone())),
None => (),
};
+43 -144
View File
@@ -13,129 +13,30 @@ type FileName = String;
pub const FILE_NAME: &str = "trace.ron";
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub enum BindingResource {
Buffer {
id: id::BufferId,
offset: wgt::BufferAddress,
size: Option<wgt::BufferSize>,
},
Sampler(id::SamplerId),
TextureView(id::TextureViewId),
TextureViewArray(Vec<id::TextureViewId>),
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct ProgrammableStageDescriptor {
pub module: id::ShaderModuleId,
pub entry_point: String,
}
#[cfg(feature = "trace")]
impl ProgrammableStageDescriptor {
pub fn new(desc: &crate::pipeline::ProgrammableStageDescriptor) -> Self {
ProgrammableStageDescriptor {
module: desc.module,
entry_point: desc.entry_point.to_string(),
}
}
}
#[cfg(feature = "replay")]
impl ProgrammableStageDescriptor {
pub fn to_core(&self) -> crate::pipeline::ProgrammableStageDescriptor {
crate::pipeline::ProgrammableStageDescriptor {
module: self.module,
entry_point: &self.entry_point,
}
pub(crate) fn new_render_bundle_encoder_descriptor(
label: super::Label,
context: &super::RenderPassContext,
) -> wgt::RenderBundleEncoderDescriptor {
wgt::RenderBundleEncoderDescriptor {
label: Some(super::own_label(&label).into()),
color_formats: context.attachments.colors.to_vec().into(),
depth_stencil_format: context.attachments.depth_stencil,
sample_count: context.sample_count as u32,
}
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct ComputePipelineDescriptor {
pub layout: id::PipelineLayoutId,
pub compute_stage: ProgrammableStageDescriptor,
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct VertexBufferDescriptor {
pub stride: wgt::BufferAddress,
pub step_mode: wgt::InputStepMode,
pub attributes: Vec<wgt::VertexAttributeDescriptor>,
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct VertexStateDescriptor {
pub index_format: wgt::IndexFormat,
pub vertex_buffers: Vec<VertexBufferDescriptor>,
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct RenderPipelineDescriptor {
pub layout: id::PipelineLayoutId,
pub vertex_stage: ProgrammableStageDescriptor,
pub fragment_stage: Option<ProgrammableStageDescriptor>,
pub primitive_topology: wgt::PrimitiveTopology,
pub rasterization_state: Option<wgt::RasterizationStateDescriptor>,
pub color_states: Vec<wgt::ColorStateDescriptor>,
pub depth_stencil_state: Option<wgt::DepthStencilStateDescriptor>,
pub vertex_state: VertexStateDescriptor,
pub sample_count: u32,
pub sample_mask: u32,
pub alpha_to_coverage_enabled: bool,
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct RenderBundleDescriptor {
pub label: String,
pub color_formats: Vec<wgt::TextureFormat>,
pub depth_stencil_format: Option<wgt::TextureFormat>,
pub sample_count: u32,
}
#[cfg(feature = "trace")]
impl RenderBundleDescriptor {
pub(crate) fn new(label: super::Label, context: &super::RenderPassContext) -> Self {
RenderBundleDescriptor {
label: super::own_label(&label),
color_formats: context.attachments.colors.to_vec(),
depth_stencil_format: context.attachments.depth_stencil,
sample_count: context.sample_count as u32,
}
}
}
#[derive(Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub enum Action {
pub enum Action<'a> {
Init {
desc: wgt::DeviceDescriptor,
backend: wgt::Backend,
},
CreateBuffer {
id: id::BufferId,
desc: wgt::BufferDescriptor<String>,
},
CreateBuffer(id::BufferId, wgt::BufferDescriptor<String>),
DestroyBuffer(id::BufferId),
CreateTexture {
id: id::TextureId,
desc: wgt::TextureDescriptor<String>,
},
CreateTexture(id::TextureId, wgt::TextureDescriptor<String>),
DestroyTexture(id::TextureId),
CreateTextureView {
id: id::TextureViewId,
@@ -143,57 +44,55 @@ pub enum Action {
desc: Option<wgt::TextureViewDescriptor<String>>,
},
DestroyTextureView(id::TextureViewId),
CreateSampler {
id: id::SamplerId,
desc: wgt::SamplerDescriptor<String>,
},
CreateSampler(id::SamplerId, wgt::SamplerDescriptor<String>),
DestroySampler(id::SamplerId),
CreateSwapChain {
id: id::SwapChainId,
desc: wgt::SwapChainDescriptor,
},
CreateSwapChain(id::SwapChainId, wgt::SwapChainDescriptor),
GetSwapChainTexture {
id: Option<id::TextureViewId>,
parent_id: id::SwapChainId,
},
PresentSwapChain(id::SwapChainId),
CreateBindGroupLayout {
id: id::BindGroupLayoutId,
label: String,
entries: Vec<wgt::BindGroupLayoutEntry>,
},
CreateBindGroupLayout(id::BindGroupLayoutId, wgt::BindGroupLayoutDescriptor<'a>),
DestroyBindGroupLayout(id::BindGroupLayoutId),
CreatePipelineLayout {
id: id::PipelineLayoutId,
bind_group_layouts: Vec<id::BindGroupLayoutId>,
push_constant_ranges: Vec<wgt::PushConstantRange>,
},
CreatePipelineLayout(
id::PipelineLayoutId,
wgt::PipelineLayoutDescriptor<'a, id::BindGroupLayoutId>,
),
DestroyPipelineLayout(id::PipelineLayoutId),
CreateBindGroup {
id: id::BindGroupId,
label: String,
layout_id: id::BindGroupLayoutId,
entries: std::collections::BTreeMap<u32, BindingResource>,
},
CreateBindGroup(
id::BindGroupId,
wgt::BindGroupDescriptor<
'a,
id::BindGroupLayoutId,
wgt::BindGroupEntry<crate::binding_model::BindingResource<'a>>,
>,
),
DestroyBindGroup(id::BindGroupId),
CreateShaderModule {
id: id::ShaderModuleId,
data: FileName,
},
DestroyShaderModule(id::ShaderModuleId),
CreateComputePipeline {
id: id::ComputePipelineId,
desc: ComputePipelineDescriptor,
},
CreateComputePipeline(
id::ComputePipelineId,
wgt::ComputePipelineDescriptor<
id::PipelineLayoutId,
wgt::ProgrammableStageDescriptor<'a, id::ShaderModuleId>,
>,
),
DestroyComputePipeline(id::ComputePipelineId),
CreateRenderPipeline {
id: id::RenderPipelineId,
desc: RenderPipelineDescriptor,
},
CreateRenderPipeline(
id::RenderPipelineId,
wgt::RenderPipelineDescriptor<
'a,
id::PipelineLayoutId,
wgt::ProgrammableStageDescriptor<'a, id::ShaderModuleId>,
>,
),
DestroyRenderPipeline(id::RenderPipelineId),
CreateRenderBundle {
id: id::RenderBundleId,
desc: RenderBundleDescriptor,
desc: wgt::RenderBundleEncoderDescriptor<'a>,
base: crate::command::BasePass<crate::command::RenderCommand>,
},
DestroyRenderBundle(id::RenderBundleId),
+39 -19
View File
@@ -10,7 +10,7 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::ops::Range;
use std::{borrow::Cow, ops::Range};
/// Integral type used for buffer offsets.
pub type BufferAddress = u64;
@@ -854,23 +854,27 @@ pub struct VertexAttributeDescriptor {
}
/// Describes how the vertex buffer is interpreted.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct VertexBufferDescriptor<'a> {
/// The stride, in bytes, between elements of this buffer.
pub stride: BufferAddress,
/// How often this vertex buffer is "stepped" forward.
pub step_mode: InputStepMode,
/// The list of attributes which comprise a single vertex.
pub attributes: &'a [VertexAttributeDescriptor],
pub attributes: Cow<'a, [VertexAttributeDescriptor]>,
}
/// Describes vertex input state for a render pipeline.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct VertexStateDescriptor<'a> {
/// The format of any index buffers used with this pipeline.
pub index_format: IndexFormat,
/// The format of any vertex buffers used with this pipeline.
pub vertex_buffers: &'a [VertexBufferDescriptor<'a>],
pub vertex_buffers: Cow<'a, [VertexBufferDescriptor<'a>]>,
}
/// Vertex Format for a Vertex Attribute (input).
@@ -1141,9 +1145,9 @@ pub enum SwapChainStatus {
/// Describes the attachments of a render pass.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct RenderPassDescriptor<'a, C, D> {
pub struct RenderPassDescriptor<'a, C: Clone, D> {
/// The color attachments of the render pass.
pub color_attachments: &'a [C],
pub color_attachments: Cow<'a, [C]>,
/// The depth and stencil attachment of the render pass, if any.
pub depth_stencil_attachment: Option<D>,
}
@@ -1461,6 +1465,8 @@ impl<L> SamplerDescriptor<L> {
/// Bindable resource and the slot to bind it to.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct BindGroupEntry<R> {
/// Slot for which binding provides resource. Corresponds to an entry of the same
/// binding index in the [`BindGroupLayoutDescriptor`].
@@ -1471,29 +1477,33 @@ pub struct BindGroupEntry<R> {
/// Describes a group of bindings and the resources to be bound.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct BindGroupDescriptor<'a, L, B> {
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct BindGroupDescriptor<'a, L, B: Clone> {
/// Debug label of the bind group. This will show up in graphics debuggers for easy identification.
pub label: Option<&'a str>,
pub label: Option<Cow<'a, str>>,
/// The [`BindGroupLayout`] that corresponds to this bind group.
pub layout: L,
/// The resources to bind to this bind group.
pub entries: &'a [B],
pub entries: Cow<'a, [B]>,
}
/// Describes a pipeline layout.
///
/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PipelineLayoutDescriptor<'a, B> {
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct PipelineLayoutDescriptor<'a, B: Clone> {
/// Bind groups that this pipeline uses. The first entry will provide all the bindings for
/// "set = 0", second entry will provide all the bindings for "set = 1" etc.
pub bind_group_layouts: &'a [B],
pub bind_group_layouts: Cow<'a, [B]>,
/// Set of push constant ranges this pipeline uses. Each shader stage that uses push constants
/// must define the range in push constant memory that corresponds to its single `layout(push_constant)`
/// uniform block.
///
/// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled.
pub push_constant_ranges: &'a [PushConstantRange],
pub push_constant_ranges: Cow<'a, [PushConstantRange]>,
}
/// A range of push constant memory to pass to a shader stage.
@@ -1511,16 +1521,20 @@ pub struct PushConstantRange {
/// Describes a programmable pipeline stage.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct ProgrammableStageDescriptor<'a, M> {
/// The compiled shader module for this stage.
pub module: M,
/// The name of the entry point in the compiled shader. There must be a function that returns
/// void with this name in the shader.
pub entry_point: &'a str,
pub entry_point: Cow<'a, str>,
}
/// Describes a render (graphics) pipeline.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct RenderPipelineDescriptor<'a, L, D> {
/// The layout of bind groups for this pipeline.
pub layout: L,
@@ -1533,7 +1547,7 @@ pub struct RenderPipelineDescriptor<'a, L, D> {
/// The primitive topology used to interpret vertices.
pub primitive_topology: PrimitiveTopology,
/// The effect of draw calls on the color aspect of the output target.
pub color_states: &'a [ColorStateDescriptor],
pub color_states: Cow<'a, [ColorStateDescriptor]>,
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
pub depth_stencil_state: Option<DepthStencilStateDescriptor>,
/// The vertex input state for this pipeline.
@@ -1555,6 +1569,8 @@ pub struct RenderPipelineDescriptor<'a, L, D> {
/// Describes a compute pipeline.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct ComputePipelineDescriptor<L, D> {
/// The layout of bind groups for this pipeline.
pub layout: L,
@@ -1574,12 +1590,14 @@ pub struct CommandBufferDescriptor {
/// Describes a [`RenderBundleEncoder`].
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct RenderBundleEncoderDescriptor<'a> {
/// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification.
pub label: Option<&'a str>,
pub label: Option<Cow<'a, str>>,
/// The formats of the color attachments that this render bundle is capable to rendering to. This
/// must match the formats of the color attachments in the renderpass this render bundle is executed in.
pub color_formats: &'a [TextureFormat],
pub color_formats: Cow<'a, [TextureFormat]>,
/// The formats of the depth attachment that this render bundle is capable to rendering to. This
/// must match the formats of the depth attachments in the renderpass this render bundle is executed in.
pub depth_stencil_format: Option<TextureFormat>,
@@ -1841,12 +1859,14 @@ impl BindGroupLayoutEntry {
/// Describes a [`BindGroupLayout`].
#[derive(Clone, Debug)]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct BindGroupLayoutDescriptor<'a> {
/// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification.
pub label: Option<&'a str>,
pub label: Option<Cow<'a, str>>,
/// Array of entries in this BindGroupLayout
pub entries: &'a [BindGroupLayoutEntry],
pub entries: Cow<'a, [BindGroupLayoutEntry]>,
}
/// View of a buffer which can be used to copy to/from a texture.