mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-26 00:33:51 +00:00
hal: remove the cows
This commit is contained in:
parent
502c57501f
commit
a0b51ce35c
@ -750,7 +750,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
|
||||
|
||||
let hal_desc = hal::RenderPassDescriptor {
|
||||
label,
|
||||
color_attachments: colors.iter().cloned().collect(),
|
||||
color_attachments: &colors,
|
||||
depth_stencil_attachment: depth_stencil,
|
||||
};
|
||||
unsafe {
|
||||
|
@ -11,8 +11,7 @@ use crate::{
|
||||
pipeline, resource, swap_chain,
|
||||
track::{BufferState, TextureSelector, TextureState, TrackerSet, UsageConflict},
|
||||
validation::{self, check_buffer_usage, check_texture_usage},
|
||||
CowHelpers as _, FastHashMap, Label, LabelHelpers as _, LifeGuard, MultiRefCount, Stored,
|
||||
SubmissionIndex,
|
||||
FastHashMap, Label, LabelHelpers as _, LifeGuard, MultiRefCount, Stored, SubmissionIndex,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@ -957,7 +956,7 @@ impl<A: HalApi> Device<A> {
|
||||
let hal_bindings = entry_map.values().cloned().collect::<Vec<_>>();
|
||||
let hal_desc = hal::BindGroupLayoutDescriptor {
|
||||
label,
|
||||
entries: Cow::Owned(hal_bindings),
|
||||
entries: &hal_bindings,
|
||||
};
|
||||
let raw = unsafe {
|
||||
self.raw
|
||||
@ -1432,7 +1431,7 @@ impl<A: HalApi> Device<A> {
|
||||
let hal_desc = hal::BindGroupDescriptor {
|
||||
label: desc.label.borrow_option(),
|
||||
layout: &layout.raw,
|
||||
entries: hal_entries.into(),
|
||||
entries: &hal_entries,
|
||||
};
|
||||
let raw = unsafe {
|
||||
self.raw
|
||||
@ -1522,14 +1521,15 @@ impl<A: HalApi> Device<A> {
|
||||
.validate(&self.limits)
|
||||
.map_err(Error::TooManyBindings)?;
|
||||
|
||||
let bgl_vec = desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| &bgl_guard.get(id).unwrap().raw)
|
||||
.collect::<Vec<_>>();
|
||||
let hal_desc = hal::PipelineLayoutDescriptor {
|
||||
label: desc.label.borrow_option(),
|
||||
bind_group_layouts: desc
|
||||
.bind_group_layouts
|
||||
.iter()
|
||||
.map(|&id| &bgl_guard.get(id).unwrap().raw)
|
||||
.collect(),
|
||||
push_constant_ranges: desc.push_constant_ranges.reborrow(),
|
||||
bind_group_layouts: &bgl_vec,
|
||||
push_constant_ranges: desc.push_constant_ranges.as_ref(),
|
||||
};
|
||||
|
||||
let raw = unsafe {
|
||||
@ -1688,7 +1688,7 @@ impl<A: HalApi> Device<A> {
|
||||
label: desc.label.borrow_option(),
|
||||
layout: &layout.raw,
|
||||
stage: hal::ProgrammableStage {
|
||||
entry_point: desc.stage.entry_point.reborrow(),
|
||||
entry_point: desc.stage.entry_point.as_ref(),
|
||||
module: &shader_module.raw,
|
||||
},
|
||||
};
|
||||
@ -1779,7 +1779,7 @@ impl<A: HalApi> Device<A> {
|
||||
vertex_buffers.alloc().init(hal::VertexBufferLayout {
|
||||
array_stride: vb_state.array_stride,
|
||||
step_mode: vb_state.step_mode,
|
||||
attributes: Cow::Borrowed(vb_state.attributes.as_ref()),
|
||||
attributes: vb_state.attributes.as_ref(),
|
||||
});
|
||||
|
||||
for attribute in vb_state.attributes.iter() {
|
||||
@ -1960,7 +1960,7 @@ impl<A: HalApi> Device<A> {
|
||||
|
||||
hal::ProgrammableStage {
|
||||
module: &shader_module.raw,
|
||||
entry_point: stage.entry_point.reborrow(),
|
||||
entry_point: stage.entry_point.as_ref(),
|
||||
}
|
||||
};
|
||||
|
||||
@ -2005,7 +2005,7 @@ impl<A: HalApi> Device<A> {
|
||||
|
||||
Some(hal::ProgrammableStage {
|
||||
module: &shader_module.raw,
|
||||
entry_point: fragment.stage.entry_point.reborrow(),
|
||||
entry_point: fragment.stage.entry_point.as_ref(),
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
@ -2063,13 +2063,13 @@ impl<A: HalApi> Device<A> {
|
||||
let pipeline_desc = hal::RenderPipelineDescriptor {
|
||||
label: desc.label.borrow_option(),
|
||||
layout: &layout.raw,
|
||||
vertex_buffers: vertex_buffers.into(),
|
||||
vertex_buffers: &vertex_buffers,
|
||||
vertex_stage,
|
||||
primitive: desc.primitive,
|
||||
depth_stencil: desc.depth_stencil.clone(),
|
||||
multisample: desc.multisample,
|
||||
fragment_stage,
|
||||
color_targets: Cow::Borrowed(color_targets),
|
||||
color_targets: color_targets,
|
||||
};
|
||||
let raw =
|
||||
unsafe { self.raw.create_render_pipeline(&pipeline_desc) }.map_err(
|
||||
|
@ -76,15 +76,6 @@ impl<'a> LabelHelpers<'a> for Label<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
trait CowHelpers<'a> {
|
||||
fn reborrow(&'a self) -> Self;
|
||||
}
|
||||
impl<'a, T: ToOwned + ?Sized> CowHelpers<'a> for Cow<'a, T> {
|
||||
fn reborrow(&'a self) -> Self {
|
||||
Cow::Borrowed(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
/// Reference count object that is 1:1 with each reference.
|
||||
#[derive(Debug)]
|
||||
struct RefCount(ptr::NonNull<AtomicUsize>);
|
||||
|
@ -2,13 +2,7 @@ extern crate wgpu_hal as hal;
|
||||
|
||||
use hal::{Adapter as _, CommandBuffer as _, Device as _, Instance as _, Queue as _, Surface as _};
|
||||
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
iter, mem,
|
||||
num::NonZeroU32,
|
||||
ptr,
|
||||
time::Instant,
|
||||
};
|
||||
use std::{borrow::Borrow, iter, mem, num::NonZeroU32, ptr, time::Instant};
|
||||
|
||||
const MAX_BUNNIES: usize = 1 << 20;
|
||||
const BUNNY_SIZE: f32 = 0.15 * 256.0;
|
||||
@ -104,7 +98,7 @@ impl<A: hal::Api> Example<A> {
|
||||
|
||||
let global_bgl_desc = hal::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: Cow::Borrowed(&[
|
||||
entries: &[
|
||||
wgt::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgt::ShaderStage::VERTEX,
|
||||
@ -134,14 +128,14 @@ impl<A: hal::Api> Example<A> {
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
]),
|
||||
],
|
||||
};
|
||||
|
||||
let global_bind_group_layout =
|
||||
unsafe { device.create_bind_group_layout(&global_bgl_desc).unwrap() };
|
||||
|
||||
let local_bgl_desc = hal::BindGroupLayoutDescriptor {
|
||||
entries: Cow::Borrowed(&[wgt::BindGroupLayoutEntry {
|
||||
entries: &[wgt::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgt::ShaderStage::VERTEX,
|
||||
ty: wgt::BindingType::Buffer {
|
||||
@ -150,7 +144,7 @@ impl<A: hal::Api> Example<A> {
|
||||
min_binding_size: wgt::BufferSize::new(mem::size_of::<Locals>() as _),
|
||||
},
|
||||
count: None,
|
||||
}]),
|
||||
}],
|
||||
label: None,
|
||||
};
|
||||
let local_bind_group_layout =
|
||||
@ -158,11 +152,8 @@ impl<A: hal::Api> Example<A> {
|
||||
|
||||
let pipeline_layout_desc = hal::PipelineLayoutDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: Cow::Borrowed(&[
|
||||
&global_bind_group_layout,
|
||||
&local_bind_group_layout,
|
||||
]),
|
||||
push_constant_ranges: Cow::Borrowed(&[]),
|
||||
bind_group_layouts: &[&global_bind_group_layout, &local_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
};
|
||||
let pipeline_layout = unsafe {
|
||||
device
|
||||
@ -175,12 +166,12 @@ impl<A: hal::Api> Example<A> {
|
||||
layout: &pipeline_layout,
|
||||
vertex_stage: hal::ProgrammableStage {
|
||||
module: &shader,
|
||||
entry_point: Cow::Borrowed("vs_main"),
|
||||
entry_point: "vs_main",
|
||||
},
|
||||
vertex_buffers: Cow::Borrowed(&[]),
|
||||
vertex_buffers: &[],
|
||||
fragment_stage: Some(hal::ProgrammableStage {
|
||||
module: &shader,
|
||||
entry_point: Cow::Borrowed("fs_main"),
|
||||
entry_point: "fs_main",
|
||||
}),
|
||||
primitive: wgt::PrimitiveState {
|
||||
topology: wgt::PrimitiveTopology::TriangleStrip,
|
||||
@ -188,11 +179,11 @@ impl<A: hal::Api> Example<A> {
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgt::MultisampleState::default(),
|
||||
color_targets: Cow::Borrowed(&[wgt::ColorTargetState {
|
||||
color_targets: &[wgt::ColorTargetState {
|
||||
format: surface_config.format,
|
||||
blend: Some(wgt::BlendState::ALPHA_BLENDING),
|
||||
write_mask: wgt::ColorWrite::default(),
|
||||
}]),
|
||||
}],
|
||||
};
|
||||
let pipeline = unsafe { device.create_render_pipeline(&pipeline_desc).unwrap() };
|
||||
|
||||
@ -341,7 +332,7 @@ impl<A: hal::Api> Example<A> {
|
||||
let global_group_desc = hal::BindGroupDescriptor {
|
||||
label: Some("global"),
|
||||
layout: &global_bind_group_layout,
|
||||
entries: Cow::Borrowed(&[
|
||||
entries: &[
|
||||
hal::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: hal::BindingResource::Buffers(
|
||||
@ -359,7 +350,7 @@ impl<A: hal::Api> Example<A> {
|
||||
binding: 2,
|
||||
resource: hal::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
};
|
||||
unsafe { device.create_bind_group(&global_group_desc).unwrap() }
|
||||
};
|
||||
@ -373,12 +364,12 @@ impl<A: hal::Api> Example<A> {
|
||||
let local_group_desc = hal::BindGroupDescriptor {
|
||||
label: Some("local"),
|
||||
layout: &local_bind_group_layout,
|
||||
entries: Cow::Borrowed(&[hal::BindGroupEntry {
|
||||
entries: &[hal::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: hal::BindingResource::Buffers(
|
||||
iter::once(local_buffer_binding).collect(),
|
||||
),
|
||||
}]),
|
||||
}],
|
||||
};
|
||||
unsafe { device.create_bind_group(&local_group_desc).unwrap() }
|
||||
};
|
||||
@ -493,7 +484,7 @@ impl<A: hal::Api> Example<A> {
|
||||
};
|
||||
let pass_desc = hal::RenderPassDescriptor {
|
||||
label: None,
|
||||
color_attachments: Cow::Borrowed(&[hal::ColorAttachment {
|
||||
color_attachments: &[hal::ColorAttachment {
|
||||
target: hal::Attachment {
|
||||
view: &surface_tex_view,
|
||||
usage: hal::TextureUse::COLOR_TARGET,
|
||||
@ -507,7 +498,7 @@ impl<A: hal::Api> Example<A> {
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
},
|
||||
}]),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
};
|
||||
unsafe {
|
||||
|
@ -47,7 +47,7 @@ pub mod api {
|
||||
}
|
||||
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
borrow::Borrow,
|
||||
fmt,
|
||||
num::NonZeroU8,
|
||||
ops::{Range, RangeInclusive},
|
||||
@ -688,14 +688,14 @@ pub struct SamplerDescriptor<'a> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BindGroupLayoutDescriptor<'a> {
|
||||
pub label: Label<'a>,
|
||||
pub entries: Cow<'a, [wgt::BindGroupLayoutEntry]>,
|
||||
pub entries: &'a [wgt::BindGroupLayoutEntry],
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PipelineLayoutDescriptor<'a, A: Api> {
|
||||
pub label: Label<'a>,
|
||||
pub bind_group_layouts: Cow<'a, [&'a A::BindGroupLayout]>,
|
||||
pub push_constant_ranges: Cow<'a, [wgt::PushConstantRange]>,
|
||||
pub bind_group_layouts: &'a [&'a A::BindGroupLayout],
|
||||
pub push_constant_ranges: &'a [wgt::PushConstantRange],
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -744,7 +744,7 @@ pub struct BindGroupEntry<'a, A: Api> {
|
||||
pub struct BindGroupDescriptor<'a, A: Api> {
|
||||
pub label: Label<'a>,
|
||||
pub layout: &'a A::BindGroupLayout,
|
||||
pub entries: Cow<'a, [BindGroupEntry<'a, A>]>,
|
||||
pub entries: &'a [BindGroupEntry<'a, A>],
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -771,7 +771,7 @@ pub struct ProgrammableStage<'a, A: Api> {
|
||||
pub module: &'a A::ShaderModule,
|
||||
/// 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: Cow<'a, str>,
|
||||
pub entry_point: &'a str,
|
||||
}
|
||||
|
||||
// Rust gets confused about the impl requirements for `A`
|
||||
@ -802,7 +802,7 @@ pub struct VertexBufferLayout<'a> {
|
||||
/// How often this vertex buffer is "stepped" forward.
|
||||
pub step_mode: wgt::InputStepMode,
|
||||
/// The list of attributes which comprise a single vertex.
|
||||
pub attributes: Cow<'a, [wgt::VertexAttribute]>,
|
||||
pub attributes: &'a [wgt::VertexAttribute],
|
||||
}
|
||||
|
||||
/// Describes a render (graphics) pipeline.
|
||||
@ -812,7 +812,7 @@ pub struct RenderPipelineDescriptor<'a, A: Api> {
|
||||
/// The layout of bind groups for this pipeline.
|
||||
pub layout: &'a A::PipelineLayout,
|
||||
/// The format of any vertex buffers used with this pipeline.
|
||||
pub vertex_buffers: Cow<'a, [VertexBufferLayout<'a>]>,
|
||||
pub vertex_buffers: &'a [VertexBufferLayout<'a>],
|
||||
/// The vertex stage for this pipeline.
|
||||
pub vertex_stage: ProgrammableStage<'a, A>,
|
||||
/// The properties of the pipeline at the primitive assembly and rasterization level.
|
||||
@ -824,7 +824,7 @@ pub struct RenderPipelineDescriptor<'a, A: Api> {
|
||||
/// The fragment stage for this pipeline.
|
||||
pub fragment_stage: Option<ProgrammableStage<'a, A>>,
|
||||
/// The effect of draw calls on the color aspect of the output target.
|
||||
pub color_targets: Cow<'a, [wgt::ColorTargetState]>,
|
||||
pub color_targets: &'a [wgt::ColorTargetState],
|
||||
}
|
||||
|
||||
/// Specifies how the alpha channel of the textures should be handled during (martin mouv i step)
|
||||
@ -969,7 +969,7 @@ pub struct DepthStencilAttachment<'a, A: Api> {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RenderPassDescriptor<'a, A: Api> {
|
||||
pub label: Label<'a>,
|
||||
pub color_attachments: Cow<'a, [ColorAttachment<'a, A>]>,
|
||||
pub color_attachments: &'a [ColorAttachment<'a, A>],
|
||||
pub depth_stencil_attachment: Option<DepthStencilAttachment<'a, A>>,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user