Skip to content

Commit

Permalink
fix ci again
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Dec 19, 2022
1 parent 8f13df2 commit 0bdccf2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 47 deletions.
25 changes: 1 addition & 24 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
context::ObjectId, AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor,
context::{ObjectId, Unused}, AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor,
BindingResource, BufferBinding, CommandEncoderDescriptor, ComputePassDescriptor,
ComputePipelineDescriptor, DownlevelCapabilities, Features, Label, Limits, LoadOp, MapMode,
Operations, PipelineLayoutDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor,
Expand All @@ -16,14 +16,12 @@ use std::{
error::Error,
fmt,
future::{ready, Ready},
num::NonZeroU128,
ops::Range,
slice,
sync::Arc,
};
use wgc::command::{bundle_ffi::*, compute_ffi::*, render_ffi::*};
use wgc::id::TypedId;
use wgt::strict_assert_eq;

const LABEL: &str = "label";

Expand Down Expand Up @@ -452,27 +450,6 @@ pub struct CommandEncoder {
open: bool,
}

/// Representation of an object id that is not used.
///
/// This may be used as the id type when only a the data associated type is used for a specific type of object.
#[derive(Debug, Clone, Copy)]
pub struct Unused;

const UNUSED_SENTINEL: Option<NonZeroU128> = NonZeroU128::new(u128::MAX);

impl From<ObjectId> for Unused {
fn from(id: ObjectId) -> Self {
strict_assert_eq!(Some(NonZeroU128::from(id)), UNUSED_SENTINEL);
Self
}
}

impl From<Unused> for ObjectId {
fn from(_: Unused) -> Self {
ObjectId::from(UNUSED_SENTINEL.expect("This should never panic"))
}
}

impl crate::Context for Context {
type AdapterId = wgc::id::AdapterId;
type AdapterData = ();
Expand Down
26 changes: 4 additions & 22 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use wasm_bindgen::{
};

use crate::{
context::{ObjectId, QueueWriteBuffer},
context::{ObjectId, QueueWriteBuffer, Unused},
UncapturedErrorHandler,
};

Expand Down Expand Up @@ -52,7 +52,7 @@ impl<T: FromWasmAbi<Abi = u32> + JsCast> From<ObjectId> for Identified<T> {
//
// This assumption we sadly have to assume to prevent littering the code with unsafe blocks.
let wasm = unsafe { JsValue::from_abi(raw.get() as u32) };
strict_assert!(wasm.is_instance_of::<T>());
wgt::strict_assert!(wasm.is_instance_of::<T>());
// SAFETY: The ABI of the type must be a u32, and strict asserts ensure the right type is used.
Self(wasm.unchecked_into(), global_id)
}
Expand Down Expand Up @@ -695,24 +695,6 @@ extern "C" {
fn worker(this: &Global) -> JsValue;
}

// The web doesn't provide any way to identify specific queue
// submissions. But Clippy gets concerned if we pass around `()` as if
// it were meaningful.
#[derive(Debug, Clone, Copy)]
pub struct SubmissionIndex;

impl From<ObjectId> for SubmissionIndex {
fn from(_: ObjectId) -> Self {
Self
}
}

impl From<SubmissionIndex> for ObjectId {
fn from(_: SubmissionIndex) -> Self {
Self::dummy()
}
}

impl crate::context::Context for Context {
type AdapterId = Identified<web_sys::GpuAdapter>;
type AdapterData = ();
Expand Down Expand Up @@ -758,7 +740,7 @@ impl crate::context::Context for Context {
type SurfaceData = ();

type SurfaceOutputDetail = SurfaceOutputDetail;
type SubmissionIndex = SubmissionIndex;
type SubmissionIndex = Unused;
type SubmissionIndexData = ();

type RequestAdapterFuture = MakeSendFuture<
Expand Down Expand Up @@ -2364,7 +2346,7 @@ impl crate::context::Context for Context {

queue.0.submit(&temp_command_buffers);

(SubmissionIndex, ())
(Unused, ())
}

fn queue_get_timestamp_period(
Expand Down
23 changes: 22 additions & 1 deletion wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
use wgt::{
strict_assert, AdapterInfo, BufferAddress, BufferSize, Color, DownlevelCapabilities,
DynamicOffset, Extent3d, Features, ImageDataLayout, ImageSubresourceRange, IndexFormat, Limits,
ShaderStages, SurfaceConfiguration, SurfaceStatus, TextureFormat, TextureFormatFeatures,
ShaderStages, SurfaceConfiguration, SurfaceStatus, TextureFormat, TextureFormatFeatures, strict_assert_eq,
};

use crate::{
Expand Down Expand Up @@ -1017,6 +1017,27 @@ fn downcast_mut<T: Debug + Send + Sync + 'static>(data: &mut crate::Data) -> &mu
unsafe { &mut *(data as *mut dyn Any as *mut T) }
}

/// Representation of an object id that is not used.
///
/// This may be used as the id type when only a the data associated type is used for a specific type of object.
#[derive(Debug, Clone, Copy)]
pub struct Unused;

const UNUSED_SENTINEL: Option<NonZeroU128> = NonZeroU128::new(u128::MAX);

impl From<ObjectId> for Unused {
fn from(id: ObjectId) -> Self {
strict_assert_eq!(Some(NonZeroU128::from(id)), UNUSED_SENTINEL);
Self
}
}

impl From<Unused> for ObjectId {
fn from(_: Unused) -> Self {
ObjectId::from(UNUSED_SENTINEL.expect("This should never panic"))
}
}

pub(crate) struct DeviceRequest {
pub device_id: ObjectId,
pub device_data: Box<crate::Data>,
Expand Down

0 comments on commit 0bdccf2

Please sign in to comment.