Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl GPU {
force_fallback_adapter: options.force_fallback_adapter,
compatible_surface: None, // windowless
apply_limit_buckets: false,
xr_compatible: false,
};
let id = instance.request_adapter(&descriptor, backends, None).ok()?;

Expand Down
1 change: 1 addition & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ impl Global {
force_fallback_adapter: desc.force_fallback_adapter,
compatible_surface: compatible_surface.as_deref(),
apply_limit_buckets: desc.apply_limit_buckets,
xr_compatible: desc.xr_compatible,
};
let adapter = self.instance.request_adapter(&desc, backends)?;
let id = self.hub.adapters.prepare(id_in).assign(Arc::new(adapter));
Expand Down
6 changes: 6 additions & 0 deletions wgpu-types/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ pub struct RequestAdapterOptions<S> {
///
#[doc = link_to_wgc_docs!(["limit bucketing"]: "limits/index.html#Limit-bucketing")]
pub apply_limit_buckets: bool,
/// Indicates that the adapter must be compatible with WebXR immersive sessions.
///
/// Corresponds to [`xrCompatible`](https://www.w3.org/TR/webxr-gpu-binding/#dom-gpurequestadapteroptions-xrcompatible)
/// in the WebXR WebGPU Binding specification. Only has effect on the WebGPU backend.
pub xr_compatible: bool,
}

impl<S> Default for RequestAdapterOptions<S> {
Expand All @@ -63,6 +68,7 @@ impl<S> Default for RequestAdapterOptions<S> {
force_fallback_adapter: false,
compatible_surface: None,
apply_limit_buckets: false,
xr_compatible: false,
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions wgpu/src/api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,39 @@ impl Device {
unsafe { device.context.device_as_hal::<A>(device) }
}

/// Returns the underlying `GPUDevice` as a `JsValue`.
///
/// WebGPU backend equivalent of [`Device::as_hal`].
#[cfg(webgpu)]
pub fn as_webgpu(&self) -> &wasm_bindgen::JsValue {
self.inner.as_webgpu().gpu_device()
}

/// Creates a [`Texture`] from an externally-provided `GPUTexture`.
///
/// WebGPU backend equivalent of [`Device::create_texture_from_hal`].
///
/// # Safety
///
/// - `gpu_texture` must be created from this device's `GPUDevice`
/// - `desc` must accurately describe the texture
#[cfg(webgpu)]
pub unsafe fn create_texture_from_webgpu(
&self,
gpu_texture: wasm_bindgen::JsValue,
desc: &TextureDescriptor<'_>,
) -> Texture {
let texture = self.inner.as_webgpu().create_texture_from_web(gpu_texture);
Texture {
inner: texture,
descriptor: TextureDescriptor {
label: None,
view_formats: &[],
..desc.clone()
},
}
}

/// Destroy this device.
pub fn destroy(&self) {
self.inner.destroy()
Expand Down
22 changes: 22 additions & 0 deletions wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,25 @@ pub struct WebDevice {
error_scope_count: Rc<Cell<u32>>,
}

impl WebDevice {
pub(crate) fn gpu_device(&self) -> &JsValue {
self.inner.as_ref()
}

pub(crate) fn create_texture_from_web(
&self,
gpu_texture: JsValue,
) -> crate::dispatch::DispatchTexture {
use wasm_bindgen::JsCast;
let inner: webgpu_sys::GpuTexture = gpu_texture.unchecked_into();
WebTexture {
inner,
ident: crate::cmp::Identifier::create(),
}
.into()
}
}

#[derive(Debug, Clone)]
pub struct WebQueue {
pub(crate) inner: webgpu_sys::GpuQueue,
Expand Down Expand Up @@ -1599,6 +1618,9 @@ impl dispatch::InstanceInterface for ContextWebGpu {
if let Some(mapped_pref) = mapped_power_preference {
mapped_options.set_power_preference(mapped_pref);
}
if options.xr_compatible {
mapped_options.set_xr_compatible(true);
}

if let Some(gpu) = &self.gpu {
let adapter_promise = gpu.request_adapter_with_options(&mapped_options);
Expand Down
1 change: 1 addition & 0 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ impl dispatch::InstanceInterface for ContextWgpuCore {
.compatible_surface
.map(|surface| surface.inner.as_core().id),
apply_limit_buckets: false,
xr_compatible: options.xr_compatible,
},
wgt::Backends::all(),
None,
Expand Down
Loading