mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 17:19:11 +01:00
Convert Extensions + Capabilities into Features
This commit is contained in:
1 parent
b67d3f43e7
commit
5529b60da4
10 files changed
+114
-123
No files matched your search
+10
-18
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
|
||||
BufferDescriptor, Capabilities, CommandEncoderDescriptor, ComputePipelineDescriptor,
|
||||
Extensions, Limits, LoadOp, MapMode, Operations, PipelineLayoutDescriptor,
|
||||
RenderPipelineDescriptor, SamplerDescriptor, ShaderModuleSource, SwapChainStatus,
|
||||
TextureDescriptor, TextureViewDescriptor,
|
||||
BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor, Features, Limits,
|
||||
LoadOp, MapMode, Operations, PipelineLayoutDescriptor, RenderPipelineDescriptor,
|
||||
SamplerDescriptor, ShaderModuleSource, SwapChainStatus, TextureDescriptor,
|
||||
TextureViewDescriptor,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@@ -365,14 +365,14 @@ impl crate::Context for Context {
|
||||
fn instance_request_adapter(
|
||||
&self,
|
||||
options: &crate::RequestAdapterOptions<'_>,
|
||||
unsafe_extensions: wgt::UnsafeExtensions,
|
||||
unsafe_features: wgt::UnsafeFeatures,
|
||||
) -> Self::RequestAdapterFuture {
|
||||
let id = self.pick_adapter(
|
||||
&wgc::instance::RequestAdapterOptions {
|
||||
power_preference: options.power_preference,
|
||||
compatible_surface: options.compatible_surface.map(|surface| surface.id),
|
||||
},
|
||||
unsafe_extensions,
|
||||
unsafe_features,
|
||||
wgc::instance::AdapterInputs::Mask(wgt::BackendBit::all(), |_| PhantomData),
|
||||
);
|
||||
ready(id)
|
||||
@@ -388,30 +388,22 @@ impl crate::Context for Context {
|
||||
ready(Ok((device_id, device_id)))
|
||||
}
|
||||
|
||||
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions {
|
||||
gfx_select!(*adapter => self.adapter_extensions(*adapter))
|
||||
fn adapter_features(&self, adapter: &Self::AdapterId) -> Features {
|
||||
gfx_select!(*adapter => self.adapter_features(*adapter))
|
||||
}
|
||||
|
||||
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits {
|
||||
gfx_select!(*adapter => self.adapter_limits(*adapter))
|
||||
}
|
||||
|
||||
fn adapter_capabilities(&self, adapter: &Self::AdapterId) -> Capabilities {
|
||||
gfx_select!(*adapter => self.adapter_capabilities(*adapter))
|
||||
}
|
||||
|
||||
fn device_extensions(&self, device: &Self::DeviceId) -> Extensions {
|
||||
gfx_select!(*device => self.device_extensions(*device))
|
||||
fn device_features(&self, device: &Self::DeviceId) -> Features {
|
||||
gfx_select!(*device => self.device_features(*device))
|
||||
}
|
||||
|
||||
fn device_limits(&self, device: &Self::DeviceId) -> Limits {
|
||||
gfx_select!(*device => self.device_limits(*device))
|
||||
}
|
||||
|
||||
fn device_capabilities(&self, device: &Self::DeviceId) -> Capabilities {
|
||||
gfx_select!(*device => self.device_capabilities(*device))
|
||||
}
|
||||
|
||||
fn device_create_swap_chain(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
|
||||
+7
-17
@@ -687,7 +687,7 @@ impl crate::Context for Context {
|
||||
fn instance_request_adapter(
|
||||
&self,
|
||||
options: &crate::RequestAdapterOptions<'_>,
|
||||
_unsafe_extensions: wgt::UnsafeExtensions,
|
||||
_unsafe_extensions: wgt::UnsafeFeatures,
|
||||
) -> Self::RequestAdapterFuture {
|
||||
//TODO: support this check, return `None` if the flag is not set.
|
||||
// It's not trivial, since we need the Future logic to have this check,
|
||||
@@ -717,9 +717,9 @@ impl crate::Context for Context {
|
||||
//Error: Tracing isn't supported on the Web target
|
||||
}
|
||||
assert!(
|
||||
!desc.extensions.intersects(crate::Extensions::ALL_NATIVE),
|
||||
!desc.features.intersects(crate::Features::ALL_NATIVE),
|
||||
"The web backend doesn't support any native extensions. Enabled native extensions: {:?}",
|
||||
desc.extensions & crate::Extensions::ALL_NATIVE
|
||||
desc.features & crate::Features::ALL_NATIVE
|
||||
);
|
||||
let mut mapped_desc = web_sys::GpuDeviceDescriptor::new();
|
||||
// TODO: label, extensions
|
||||
@@ -733,9 +733,9 @@ impl crate::Context for Context {
|
||||
)
|
||||
}
|
||||
|
||||
fn adapter_extensions(&self, _adapter: &Self::AdapterId) -> wgt::Extensions {
|
||||
fn adapter_features(&self, _adapter: &Self::AdapterId) -> wgt::Features {
|
||||
// TODO: web-sys has no way of getting extensions on adapters
|
||||
wgt::Extensions::empty()
|
||||
wgt::Features::empty()
|
||||
}
|
||||
|
||||
fn adapter_limits(&self, _adapter: &Self::AdapterId) -> wgt::Limits {
|
||||
@@ -743,14 +743,9 @@ impl crate::Context for Context {
|
||||
wgt::Limits::default()
|
||||
}
|
||||
|
||||
fn adapter_capabilities(&self, _adapter: &Self::AdapterId) -> wgt::Capabilities {
|
||||
// TODO: webgpu doesn't support capabilities, so return an empty set of capabilities
|
||||
wgt::Capabilities::default()
|
||||
}
|
||||
|
||||
fn device_extensions(&self, _device: &Self::DeviceId) -> wgt::Extensions {
|
||||
fn device_features(&self, _device: &Self::DeviceId) -> wgt::Features {
|
||||
// TODO: web-sys has no way of getting extensions on devices
|
||||
wgt::Extensions::empty()
|
||||
wgt::Features::empty()
|
||||
}
|
||||
|
||||
fn device_limits(&self, _device: &Self::DeviceId) -> wgt::Limits {
|
||||
@@ -758,11 +753,6 @@ impl crate::Context for Context {
|
||||
wgt::Limits::default()
|
||||
}
|
||||
|
||||
fn device_capabilities(&self, _device: &Self::DeviceId) -> wgt::Capabilities {
|
||||
// TODO: webgpu doesn't support capabilities, so return an empty set of capabilities
|
||||
wgt::Capabilities::default()
|
||||
}
|
||||
|
||||
fn device_create_swap_chain(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
|
||||
+26
-41
@@ -22,16 +22,15 @@ use parking_lot::Mutex;
|
||||
pub use wgc::instance::{AdapterInfo, DeviceType};
|
||||
pub use wgt::{
|
||||
AddressMode, Backend, BackendBit, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
|
||||
BlendDescriptor, BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage,
|
||||
Capabilities, Color, ColorStateDescriptor, ColorWrite, CommandBufferDescriptor,
|
||||
CompareFunction, CullMode, DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset,
|
||||
Extensions, Extent3d, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, Origin3d,
|
||||
PowerPreference, PresentMode, PrimitiveTopology, RasterizationStateDescriptor,
|
||||
RenderBundleEncoderDescriptor, ShaderLocation, ShaderStage, StencilOperation,
|
||||
StencilStateFaceDescriptor, SwapChainDescriptor, SwapChainStatus, TextureAspect,
|
||||
TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, TextureUsage,
|
||||
TextureViewDimension, UnsafeExtensions, VertexAttributeDescriptor, VertexFormat,
|
||||
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
|
||||
BlendDescriptor, BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage, Color,
|
||||
ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction, CullMode,
|
||||
DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset, Extent3d, Features, FilterMode,
|
||||
FrontFace, IndexFormat, InputStepMode, Limits, Origin3d, PowerPreference, PresentMode,
|
||||
PrimitiveTopology, RasterizationStateDescriptor, RenderBundleEncoderDescriptor, ShaderLocation,
|
||||
ShaderStage, StencilOperation, StencilStateFaceDescriptor, SwapChainDescriptor,
|
||||
SwapChainStatus, TextureAspect, TextureComponentType, TextureDataLayout, TextureDimension,
|
||||
TextureFormat, TextureUsage, TextureViewDimension, UnsafeFeatures, VertexAttributeDescriptor,
|
||||
VertexFormat, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
|
||||
};
|
||||
|
||||
use backend::Context as C;
|
||||
@@ -143,7 +142,7 @@ trait Context: Sized {
|
||||
fn instance_request_adapter(
|
||||
&self,
|
||||
options: &RequestAdapterOptions<'_>,
|
||||
unsafe_extensions: UnsafeExtensions,
|
||||
unsafe_extensions: UnsafeFeatures,
|
||||
) -> Self::RequestAdapterFuture;
|
||||
fn adapter_request_device(
|
||||
&self,
|
||||
@@ -151,13 +150,11 @@ trait Context: Sized {
|
||||
desc: &DeviceDescriptor,
|
||||
trace_dir: Option<&std::path::Path>,
|
||||
) -> Self::RequestDeviceFuture;
|
||||
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions;
|
||||
fn adapter_features(&self, adapter: &Self::AdapterId) -> Features;
|
||||
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits;
|
||||
fn adapter_capabilities(&self, adapter: &Self::AdapterId) -> Capabilities;
|
||||
|
||||
fn device_extensions(&self, device: &Self::DeviceId) -> Extensions;
|
||||
fn device_features(&self, device: &Self::DeviceId) -> Features;
|
||||
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
|
||||
fn device_capabilities(&self, device: &Self::DeviceId) -> Capabilities;
|
||||
fn device_create_swap_chain(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
@@ -1016,13 +1013,13 @@ impl Instance {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn enumerate_adapters(
|
||||
&self,
|
||||
unsafe_extensions: UnsafeExtensions,
|
||||
unsafe_features: UnsafeFeatures,
|
||||
backends: BackendBit,
|
||||
) -> impl Iterator<Item = Adapter> {
|
||||
let context = Arc::clone(&self.context);
|
||||
self.context
|
||||
.enumerate_adapters(
|
||||
unsafe_extensions,
|
||||
unsafe_features,
|
||||
wgc::instance::AdapterInputs::Mask(backends, |_| PhantomData),
|
||||
)
|
||||
.into_iter()
|
||||
@@ -1078,11 +1075,11 @@ impl Instance {
|
||||
pub fn request_adapter(
|
||||
&self,
|
||||
options: &RequestAdapterOptions<'_>,
|
||||
unsafe_extensions: UnsafeExtensions,
|
||||
unsafe_features: UnsafeFeatures,
|
||||
) -> impl Future<Output = Option<Adapter>> + Send {
|
||||
let context = Arc::clone(&self.context);
|
||||
self.context
|
||||
.instance_request_adapter(options, unsafe_extensions)
|
||||
.instance_request_adapter(options, unsafe_features)
|
||||
.map(|option| option.map(|id| Adapter { context, id }))
|
||||
}
|
||||
}
|
||||
@@ -1093,8 +1090,8 @@ impl Adapter {
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// - Extensions specified by `desc` are not supported by this adapter.
|
||||
/// - Unsafe extensions were requested but enabled when requesting the adapter.
|
||||
/// - Features specified by `desc` are not supported by this adapter.
|
||||
/// - Unsafe features were requested but not enabled when requesting the adapter.
|
||||
/// - Limits requested exceed the values provided by the adapter.
|
||||
/// - Adapter does not support all features wgpu requires to safely operate.
|
||||
pub fn request_device(
|
||||
@@ -1119,12 +1116,12 @@ impl Adapter {
|
||||
})
|
||||
}
|
||||
|
||||
/// List all extensions that are supported with this adapter.
|
||||
/// List all features that are supported with this adapter.
|
||||
///
|
||||
/// Extensions must be explicitly requested in [`Adapter::request_device`] in order
|
||||
/// Features must be explicitly requested in [`Adapter::request_device`] in order
|
||||
/// to use them.
|
||||
pub fn extensions(&self) -> Extensions {
|
||||
Context::adapter_extensions(&*self.context, &self.id)
|
||||
pub fn features(&self) -> Features {
|
||||
Context::adapter_features(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// List the "best" limits that are supported by this adapter.
|
||||
@@ -1135,11 +1132,6 @@ impl Adapter {
|
||||
Context::adapter_limits(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// List all capabilities that may be used wth this adapter.
|
||||
pub fn capabilities(&self) -> Capabilities {
|
||||
Context::adapter_capabilities(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// Get info about the adapter itself.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn get_info(&self) -> AdapterInfo {
|
||||
@@ -1156,11 +1148,11 @@ impl Device {
|
||||
Context::device_poll(&*self.context, &self.id, maintain);
|
||||
}
|
||||
|
||||
/// List all extensions that may be used with this device.
|
||||
/// List all features that may be used with this device.
|
||||
///
|
||||
/// Functions may panic if you use unsupported extensions.
|
||||
pub fn extensions(&self) -> Extensions {
|
||||
Context::device_extensions(&*self.context, &self.id)
|
||||
/// Functions may panic if you use unsupported features.
|
||||
pub fn features(&self) -> Features {
|
||||
Context::device_features(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// List all limits that were requested of this device.
|
||||
@@ -1170,13 +1162,6 @@ impl Device {
|
||||
Context::device_limits(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// List all capabilities that may be used wth this device.
|
||||
///
|
||||
/// Functions may panic if you use unsupported capabilities.
|
||||
pub fn capabilities(&self) -> Capabilities {
|
||||
Context::device_capabilities(&*self.context, &self.id)
|
||||
}
|
||||
|
||||
/// Creates a shader module from either SPIR-V or WGSL source code.
|
||||
pub fn create_shader_module(&self, source: ShaderModuleSource) -> ShaderModule {
|
||||
ShaderModule {
|
||||
|
||||
Reference in new issue
Block a user