Skip to content

Commit

Permalink
Improve the consistency of identifiers (#5108)
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog authored Jan 29, 2024
1 parent 4face1c commit dec6ea5
Show file tree
Hide file tree
Showing 31 changed files with 687 additions and 572 deletions.
6 changes: 3 additions & 3 deletions deno_webgpu/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn op_webgpu_queue_submit(
})
.collect::<Result<Vec<_>, AnyError>>()?;

let maybe_err = gfx_select!(queue => instance.queue_submit(queue, &ids)).err();
let maybe_err = gfx_select!(queue => instance.queue_submit(queue.transmute(), &ids)).err();

for rid in command_buffers {
let resource = state.resource_table.take::<WebGpuCommandBuffer>(rid)?;
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn op_webgpu_write_buffer(
None => &buf[data_offset..],
};
let maybe_err = gfx_select!(queue => instance.queue_write_buffer(
queue,
queue.transmute(),
buffer,
buffer_offset,
data
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn op_webgpu_write_texture(
let data_layout = data_layout.into();

gfx_ok!(queue => instance.queue_write_texture(
queue,
queue.transmute(),
&destination,
buf,
&data_layout,
Expand Down
13 changes: 6 additions & 7 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn main() {
global.instance_create_surface(
window.display_handle().unwrap().into(),
window.window_handle().unwrap().into(),
wgc::id::TypedId::zip(0, 1, wgt::Backend::Empty),
wgc::id::Id::zip(0, 1, wgt::Backend::Empty),
)
}
.unwrap();
Expand All @@ -79,22 +79,21 @@ fn main() {
#[cfg(not(feature = "winit"))]
compatible_surface: None,
},
wgc::instance::AdapterInputs::IdSet(
&[wgc::id::TypedId::zip(0, 0, backend)],
|id| id.backend(),
),
wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| {
id.backend()
}),
)
.expect("Unable to find an adapter for selected backend");

let info = gfx_select!(adapter => global.adapter_get_info(adapter)).unwrap();
log::info!("Picked '{}'", info.name);
let id = wgc::id::TypedId::zip(1, 0, backend);
let id = wgc::id::Id::zip(1, 0, backend);
let (_, _, error) = gfx_select!(adapter => global.adapter_request_device(
adapter,
&desc,
None,
id,
id
id.transmute()
));
if let Some(e) = error {
panic!("{:?}", e);
Expand Down
21 changes: 11 additions & 10 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::{borrow::Cow, fs, path::Path};

pub struct IdentityPassThroughFactory;

impl<I: wgc::id::TypedId> wgc::identity::IdentityHandlerFactory<I> for IdentityPassThroughFactory {
type Input = I;
impl<T: wgc::id::Marker> wgc::identity::IdentityHandlerFactory<T> for IdentityPassThroughFactory {
type Input = wgc::id::Id<T>;

fn input_to_id(id_in: Self::Input) -> I {
fn input_to_id(id_in: Self::Input) -> wgc::id::Id<T> {
id_in
}

Expand All @@ -38,7 +38,7 @@ pub trait GlobalPlay {
device: wgc::id::DeviceId,
action: trace::Action,
dir: &Path,
comb_manager: &mut wgc::identity::IdentityManager<wgc::id::CommandBufferId>,
comb_manager: &mut wgc::identity::IdentityManager<wgc::id::markers::CommandBuffer>,
);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
device: wgc::id::DeviceId,
action: trace::Action,
dir: &Path,
comb_manager: &mut wgc::identity::IdentityManager<wgc::id::CommandBufferId>,
comb_manager: &mut wgc::identity::IdentityManager<wgc::id::markers::CommandBuffer>,
) {
use wgc::device::trace::Action;
log::debug!("action {:?}", action);
Expand Down Expand Up @@ -350,7 +350,7 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
let bin = std::fs::read(dir.join(data)).unwrap();
let size = (range.end - range.start) as usize;
if queued {
self.queue_write_buffer::<A>(device, id, range.start, &bin)
self.queue_write_buffer::<A>(device.transmute(), id, range.start, &bin)
.unwrap();
} else {
self.device_wait_for_buffer::<A>(device, id).unwrap();
Expand All @@ -365,23 +365,24 @@ impl GlobalPlay for wgc::global::Global<IdentityPassThroughFactory> {
size,
} => {
let bin = std::fs::read(dir.join(data)).unwrap();
self.queue_write_texture::<A>(device, &to, &bin, &layout, &size)
self.queue_write_texture::<A>(device.transmute(), &to, &bin, &layout, &size)
.unwrap();
}
Action::Submit(_index, ref commands) if commands.is_empty() => {
self.queue_submit::<A>(device, &[]).unwrap();
self.queue_submit::<A>(device.transmute(), &[]).unwrap();
}
Action::Submit(_index, commands) => {
let (encoder, error) = self.device_create_command_encoder::<A>(
device,
&wgt::CommandEncoderDescriptor { label: None },
comb_manager.process(device.backend()),
comb_manager.process(device.backend()).transmute(),
);
if let Some(e) = error {
panic!("{e}");
}
let cmdbuf = self.encode_commands::<A>(encoder, commands);
self.queue_submit::<A>(device, &[cmdbuf]).unwrap();
self.queue_submit::<A>(device.transmute(), &[cmdbuf])
.unwrap();
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Test<'_> {
test_num: u32,
) {
let backend = adapter.backend();
let device_id = wgc::id::TypedId::zip(test_num, 0, backend);
let device_id = wgc::id::Id::zip(test_num, 0, backend);
let (_, _, error) = wgc::gfx_select!(adapter => global.adapter_request_device(
adapter,
&wgt::DeviceDescriptor {
Expand All @@ -115,7 +115,7 @@ impl Test<'_> {
},
None,
device_id,
device_id
device_id.transmute()
));
if let Some(e) = error {
panic!("{:?}", e);
Expand All @@ -128,7 +128,7 @@ impl Test<'_> {
}
println!("\t\t\tMapping...");
for expect in &self.expectations {
let buffer = wgc::id::TypedId::zip(expect.buffer.index, expect.buffer.epoch, backend);
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend);
wgc::gfx_select!(device_id => global.buffer_map_async(
buffer,
expect.offset .. expect.offset+expect.data.len() as wgt::BufferAddress,
Expand All @@ -148,7 +148,7 @@ impl Test<'_> {

for expect in self.expectations {
println!("\t\t\tChecking {}", expect.name);
let buffer = wgc::id::TypedId::zip(expect.buffer.index, expect.buffer.epoch, backend);
let buffer = wgc::id::Id::zip(expect.buffer.index, expect.buffer.epoch, backend);
let (ptr, size) =
wgc::gfx_select!(device_id => global.buffer_get_mapped_range(buffer, expect.offset, Some(expect.data.len() as wgt::BufferAddress)))
.unwrap();
Expand Down Expand Up @@ -221,10 +221,9 @@ impl Corpus {
force_fallback_adapter: false,
compatible_surface: None,
},
wgc::instance::AdapterInputs::IdSet(
&[wgc::id::TypedId::zip(0, 0, backend)],
|id| id.backend(),
),
wgc::instance::AdapterInputs::IdSet(&[wgc::id::Id::zip(0, 0, backend)], |id| {
id.backend()
}),
) {
Ok(adapter) => adapter,
Err(_) => continue,
Expand Down
37 changes: 20 additions & 17 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::{
},
error::{ErrorFormatter, PrettyError},
hal_api::HalApi,
id::{
BindGroupId, BindGroupLayoutId, BufferId, PipelineLayoutId, SamplerId, TextureId,
TextureViewId,
},
id::{BindGroupLayoutId, BufferId, SamplerId, TextureId, TextureViewId},
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
resource::{Resource, ResourceInfo, ResourceType},
resource_log,
Expand Down Expand Up @@ -441,7 +438,7 @@ pub struct BindGroupLayoutDescriptor<'a> {
pub entries: Cow<'a, [wgt::BindGroupLayoutEntry]>,
}

pub type BindGroupLayouts<A> = crate::storage::Storage<BindGroupLayout<A>, BindGroupLayoutId>;
pub type BindGroupLayouts<A> = crate::storage::Storage<BindGroupLayout<A>>;

/// Bind group layout.
#[derive(Debug)]
Expand All @@ -458,7 +455,7 @@ pub struct BindGroupLayout<A: HalApi> {
pub(crate) origin: bgl::Origin,
#[allow(unused)]
pub(crate) binding_count_validator: BindingTypeMaxCountValidator,
pub(crate) info: ResourceInfo<BindGroupLayoutId>,
pub(crate) info: ResourceInfo<BindGroupLayout<A>>,
pub(crate) label: String,
}

Expand All @@ -482,14 +479,16 @@ impl<A: HalApi> Drop for BindGroupLayout<A> {
}
}

impl<A: HalApi> Resource<BindGroupLayoutId> for BindGroupLayout<A> {
impl<A: HalApi> Resource for BindGroupLayout<A> {
const TYPE: ResourceType = "BindGroupLayout";

fn as_info(&self) -> &ResourceInfo<BindGroupLayoutId> {
type Marker = crate::id::markers::BindGroupLayout;

fn as_info(&self) -> &ResourceInfo<Self> {
&self.info
}

fn as_info_mut(&mut self) -> &mut ResourceInfo<BindGroupLayoutId> {
fn as_info_mut(&mut self) -> &mut ResourceInfo<Self> {
&mut self.info
}

Expand Down Expand Up @@ -602,7 +601,7 @@ pub struct PipelineLayoutDescriptor<'a> {
pub struct PipelineLayout<A: HalApi> {
pub(crate) raw: Option<A::PipelineLayout>,
pub(crate) device: Arc<Device<A>>,
pub(crate) info: ResourceInfo<PipelineLayoutId>,
pub(crate) info: ResourceInfo<PipelineLayout<A>>,
pub(crate) bind_group_layouts: ArrayVec<Arc<BindGroupLayout<A>>, { hal::MAX_BIND_GROUPS }>,
pub(crate) push_constant_ranges: ArrayVec<wgt::PushConstantRange, { SHADER_STAGE_COUNT }>,
}
Expand Down Expand Up @@ -716,14 +715,16 @@ impl<A: HalApi> PipelineLayout<A> {
}
}

impl<A: HalApi> Resource<PipelineLayoutId> for PipelineLayout<A> {
impl<A: HalApi> Resource for PipelineLayout<A> {
const TYPE: ResourceType = "PipelineLayout";

fn as_info(&self) -> &ResourceInfo<PipelineLayoutId> {
type Marker = crate::id::markers::PipelineLayout;

fn as_info(&self) -> &ResourceInfo<Self> {
&self.info
}

fn as_info_mut(&mut self) -> &mut ResourceInfo<PipelineLayoutId> {
fn as_info_mut(&mut self) -> &mut ResourceInfo<Self> {
&mut self.info
}
}
Expand Down Expand Up @@ -830,7 +831,7 @@ pub struct BindGroup<A: HalApi> {
pub(crate) raw: Snatchable<A::BindGroup>,
pub(crate) device: Arc<Device<A>>,
pub(crate) layout: Arc<BindGroupLayout<A>>,
pub(crate) info: ResourceInfo<BindGroupId>,
pub(crate) info: ResourceInfo<BindGroup<A>>,
pub(crate) used: BindGroupStates<A>,
pub(crate) used_buffer_ranges: Vec<BufferInitTrackerAction<A>>,
pub(crate) used_texture_ranges: Vec<TextureInitTrackerAction<A>>,
Expand Down Expand Up @@ -919,14 +920,16 @@ impl<A: HalApi> BindGroup<A> {
}
}

impl<A: HalApi> Resource<BindGroupId> for BindGroup<A> {
impl<A: HalApi> Resource for BindGroup<A> {
const TYPE: ResourceType = "BindGroup";

fn as_info(&self) -> &ResourceInfo<BindGroupId> {
type Marker = crate::id::markers::BindGroup;

fn as_info(&self) -> &ResourceInfo<Self> {
&self.info
}

fn as_info_mut(&mut self) -> &mut ResourceInfo<BindGroupId> {
fn as_info_mut(&mut self) -> &mut ResourceInfo<Self> {
&mut self.info
}
}
Expand Down
12 changes: 7 additions & 5 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use crate::{
error::{ErrorFormatter, PrettyError},
hal_api::HalApi,
hub::Hub,
id::{self, RenderBundleId},
id,
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
pipeline::{PipelineFlags, RenderPipeline, VertexStep},
resource::{Resource, ResourceInfo, ResourceType},
Expand Down Expand Up @@ -832,7 +832,7 @@ pub struct RenderBundle<A: HalApi> {
pub(super) buffer_memory_init_actions: Vec<BufferInitTrackerAction<A>>,
pub(super) texture_memory_init_actions: Vec<TextureInitTrackerAction<A>>,
pub(super) context: RenderPassContext,
pub(crate) info: ResourceInfo<RenderBundleId>,
pub(crate) info: ResourceInfo<RenderBundle<A>>,
discard_hal_labels: bool,
}

Expand Down Expand Up @@ -1067,14 +1067,16 @@ impl<A: HalApi> RenderBundle<A> {
}
}

impl<A: HalApi> Resource<RenderBundleId> for RenderBundle<A> {
impl<A: HalApi> Resource for RenderBundle<A> {
const TYPE: ResourceType = "RenderBundle";

fn as_info(&self) -> &ResourceInfo<RenderBundleId> {
type Marker = crate::id::markers::RenderBundle;

fn as_info(&self) -> &ResourceInfo<Self> {
&self.info
}

fn as_info_mut(&mut self) -> &mut ResourceInfo<RenderBundleId> {
fn as_info_mut(&mut self) -> &mut ResourceInfo<Self> {
&mut self.info
}
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<A: HalApi> State<A> {
&mut self,
raw_encoder: &mut A::CommandEncoder,
base_trackers: &mut Tracker<A>,
bind_group_guard: &Storage<BindGroup<A>, id::BindGroupId>,
bind_group_guard: &Storage<BindGroup<A>>,
indirect_buffer: Option<id::BufferId>,
snatch_guard: &SnatchGuard,
) -> Result<(), UsageConflict> {
Expand Down
Loading

0 comments on commit dec6ea5

Please sign in to comment.