Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage Rewrite #2791

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ pub struct IdentityPassThrough<I>(PhantomData<I>);

impl<I: Clone + Debug + wgc::id::TypedId> wgc::hub::IdentityHandler<I> for IdentityPassThrough<I> {
type Input = I;
fn process(&self, id: I, backend: wgt::Backend) -> I {
fn process(&mut self, id: I, backend: wgt::Backend) -> (wgc::Index, I) {
let (index, epoch, _backend) = id.unzip();
I::zip(index, epoch, backend)
(index, I::zip(index, epoch, backend))
}
fn free(&mut self, id: I) -> (wgc::Index, wgc::Epoch) {
let (index, epoch, _) = id.unzip();
(index, epoch)
}
fn free(&self, _id: I) {}
}

pub struct IdentityPassThroughFactory;
Expand Down Expand Up @@ -371,7 +374,7 @@ impl GlobalPlay for wgc::hub::Global<IdentityPassThroughFactory> {
let (encoder, error) = self.device_create_command_encoder::<A>(
device,
&wgt::CommandEncoderDescriptor { label: None },
comb_manager.alloc(device.backend()),
comb_manager.alloc(device.backend()).1,
);
if let Some(e) = error {
panic!("{:?}", e);
Expand Down
2 changes: 1 addition & 1 deletion player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Test<'_> {
}
}

wgc::gfx_select!(device => global.clear_backend(()));
unsafe { wgc::gfx_select!(device => global.clear_backend(())) };
}
}

Expand Down
34 changes: 27 additions & 7 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::{
device::{DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT},
error::{ErrorFormatter, PrettyError},
hub::{HalApi, Resource},
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureId, TextureViewId, Valid},
id::{
BindGroupId, BindGroupLayoutId, BufferId, DeviceId, PipelineLayoutId, SamplerId, TextureId,
TextureViewId, Valid,
},
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
track::{BindGroupStates, UsageConflict},
validation::{MissingBufferUsageError, MissingTextureUsageError},
Expand Down Expand Up @@ -444,10 +447,15 @@ pub struct BindGroupLayout<A: hal::Api> {
}

impl<A: hal::Api> Resource for BindGroupLayout<A> {
type Raw = A::BindGroupLayout;
type Id = BindGroupLayoutId;
const TYPE: &'static str = "BindGroupLayout";

fn life_guard(&self) -> &LifeGuard {
unreachable!()
fn life_guard(&self) -> Option<&LifeGuard> {
None
}
fn device_id(&self) -> Valid<DeviceId> {
self.device_id.value
}

fn label(&self) -> &str {
Expand Down Expand Up @@ -638,10 +646,16 @@ impl<A: hal::Api> PipelineLayout<A> {
}

impl<A: hal::Api> Resource for PipelineLayout<A> {
type Raw = A::PipelineLayout;
type Id = PipelineLayoutId;
const TYPE: &'static str = "PipelineLayout";

fn life_guard(&self) -> &LifeGuard {
&self.life_guard
fn life_guard(&self) -> Option<&LifeGuard> {
Some(&self.life_guard)
}

fn device_id(&self) -> Valid<DeviceId> {
self.device_id.value
}
}

Expand Down Expand Up @@ -767,10 +781,16 @@ impl<A: HalApi> BindGroup<A> {
}

impl<A: HalApi> Resource for BindGroup<A> {
type Raw = A::BindGroup;
type Id = BindGroupId;
const TYPE: &'static str = "BindGroup";

fn life_guard(&self) -> &LifeGuard {
&self.life_guard
fn life_guard(&self) -> Option<&LifeGuard> {
Some(&self.life_guard)
}

fn device_id(&self) -> Valid<DeviceId> {
self.device_id.value
}
}

Expand Down
18 changes: 11 additions & 7 deletions wgpu-core/src/command/bind.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
binding_model::{BindGroup, LateMinBufferBindingSizeMismatch, PipelineLayout},
device::SHADER_STAGE_COUNT,
hub::{HalApi, Storage},
hub::{GlobalIdentityHandlerFactory, HalApi},
id::{BindGroupId, BindGroupLayoutId, PipelineLayoutId, Valid},
pipeline::LateSizedBufferGroup,
Stored,
registry, Stored,
};

use arrayvec::ArrayVec;
Expand Down Expand Up @@ -181,14 +181,18 @@ impl Binder {
}
}

pub(super) fn change_pipeline_layout<'a, A: HalApi>(
pub(super) fn change_pipeline_layout<'a, A, F>(
&'a mut self,
guard: &Storage<PipelineLayout<A>, PipelineLayoutId>,
storage: &registry::Registry<A, PipelineLayout<A>, F>,
new_id: Valid<PipelineLayoutId>,
late_sized_buffer_groups: &[LateSizedBufferGroup],
) -> (usize, &'a [EntryPayload]) {
) -> (usize, &'a [EntryPayload])
where
A: HalApi,
F: GlobalIdentityHandlerFactory,
{
let old_id_opt = self.pipeline_layout_id.replace(new_id);
let new = &guard[new_id];
let new = &storage[new_id];

let mut bind_range = self.manager.update_expectations(&new.bind_group_layout_ids);

Expand All @@ -215,7 +219,7 @@ impl Binder {
}

if let Some(old_id) = old_id_opt {
let old = &guard[old_id];
let old = &storage[old_id];
// root constants are the base compatibility property
if old.push_constant_ranges != new.push_constant_ranges {
bind_range.start = 0;
Expand Down
Loading