[rs] Expose adapter.get_info() everywhere

This commit is contained in:
Dzmitry Malyshau
2020-12-18 17:13:48 -05:00
committed by Dzmitry Malyshau
parent 6489a1190d
commit 7a8c6cefe1
4 changed files with 44 additions and 39 deletions

View File

@@ -25,13 +25,13 @@ vulkan-portability = ["wgc/gfx-backend-vulkan"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc]
package = "wgpu-core"
git = "https://github.com/gfx-rs/wgpu"
rev = "89e585af615c5ed2050a1cab7225f6e92a26b3ba"
rev = "4ebe1f50b057046e4d4f015eb006330d62f5fe91"
features = ["raw-window-handle"]
[dependencies.wgt]
package = "wgpu-types"
git = "https://github.com/gfx-rs/wgpu"
rev = "89e585af615c5ed2050a1cab7225f6e92a26b3ba"
rev = "4ebe1f50b057046e4d4f015eb006330d62f5fe91"
[dependencies]
arrayvec = "0.5"

View File

@@ -1,10 +1,10 @@
use crate::{
backend::{error::ContextError, native_gpu_future},
BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, CommandEncoderDescriptor,
ComputePassDescriptor, ComputePipelineDescriptor, Features, Label, Limits, LoadOp, MapMode,
Operations, PipelineLayoutDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor,
SamplerDescriptor, ShaderModuleDescriptor, ShaderSource, SwapChainStatus, TextureDescriptor,
TextureViewDescriptor,
AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
CommandEncoderDescriptor, ComputePassDescriptor, ComputePipelineDescriptor, Features, Label,
Limits, LoadOp, MapMode, Operations, PipelineLayoutDescriptor, RenderBundleEncoderDescriptor,
RenderPipelineDescriptor, SamplerDescriptor, ShaderModuleDescriptor, ShaderSource,
SwapChainStatus, TextureDescriptor, TextureViewDescriptor,
};
use arrayvec::ArrayVec;
@@ -37,14 +37,6 @@ impl Context {
&self.0
}
pub fn adapter_get_info(&self, id: wgc::id::AdapterId) -> wgc::instance::AdapterInfo {
let global = &self.0;
match wgc::gfx_select!(id => global.adapter_get_info(id)) {
Ok(info) => info,
Err(e) => panic!("{}", e),
}
}
pub fn enumerate_adapters(&self, backends: wgt::BackendBit) -> Vec<wgc::id::AdapterId> {
self.0
.enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| {
@@ -691,6 +683,14 @@ impl crate::Context for Context {
}
}
fn adapter_get_info(&self, adapter: &wgc::id::AdapterId) -> AdapterInfo {
let global = &self.0;
match wgc::gfx_select!(*adapter => global.adapter_get_info(*adapter)) {
Ok(info) => info,
Err(err) => self.handle_error_fatal(err, "Adapter::get_info"),
}
}
fn device_features(&self, device: &Self::DeviceId) -> Features {
let global = &self.0;
match wgc::gfx_select!(device.id => global.device_features(device.id)) {

View File

@@ -941,6 +941,17 @@ impl crate::Context for Context {
wgt::Limits::default()
}
fn adapter_get_info(&self, _adapter: &Self::AdapterId) -> wgt::AdapterInfo {
// TODO: web-sys has no way of getting information on adapters
wgt::AdapterInfo {
name: String::new(),
vendor: 0,
device: 0,
device_type: wgt::DeviceType::Other,
backend: wgt::Backend::BrowserWebGpu,
}
}
fn device_features(&self, _device: &Self::DeviceId) -> wgt::Features {
// TODO: web-sys has no way of getting extensions on devices
wgt::Features::empty()

View File

@@ -24,26 +24,20 @@ use std::{
use futures::FutureExt as _;
use parking_lot::Mutex;
#[cfg(feature = "replay")]
use serde::Deserialize;
#[cfg(feature = "trace")]
use serde::Serialize;
#[cfg(not(target_arch = "wasm32"))]
pub use wgc::instance::{AdapterInfo, DeviceType};
pub use wgt::{
AddressMode, Backend, BackendBit, BindGroupLayoutEntry, BindingType, BlendDescriptor,
BlendFactor, BlendOperation, BufferAddress, BufferBindingType, BufferSize, BufferUsage, Color,
ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction, CullMode,
DepthStencilStateDescriptor, DynamicOffset, Extent3d, Features, FilterMode, FrontFace,
IndexFormat, InputStepMode, Limits, Origin3d, PolygonMode, PowerPreference, PresentMode,
PrimitiveTopology, PushConstantRange, RasterizationStateDescriptor, SamplerBorderColor,
ShaderFlags, ShaderLocation, ShaderStage, StencilOperation, StencilStateDescriptor,
StencilStateFaceDescriptor, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus,
TextureAspect, TextureDataLayout, TextureDimension, TextureFormat, TextureSampleType,
TextureUsage, TextureViewDimension, VertexAttributeDescriptor, VertexFormat,
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
PUSH_CONSTANT_ALIGNMENT,
AdapterInfo, AddressMode, Backend, BackendBit, BindGroupLayoutEntry, BindingType,
BlendDescriptor, BlendFactor, BlendOperation, BufferAddress, BufferBindingType, BufferSize,
BufferUsage, Color, ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction,
CullMode, DepthStencilStateDescriptor, DeviceType, DynamicOffset, Extent3d, Features,
FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, Origin3d, PolygonMode,
PowerPreference, PresentMode, PrimitiveTopology, PushConstantRange,
RasterizationStateDescriptor, SamplerBorderColor, ShaderFlags, ShaderLocation, ShaderStage,
StencilOperation, StencilStateDescriptor, StencilStateFaceDescriptor, StorageTextureAccess,
SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDataLayout, TextureDimension,
TextureFormat, TextureSampleType, TextureUsage, TextureViewDimension,
VertexAttributeDescriptor, VertexFormat, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT,
COPY_BYTES_PER_ROW_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
};
use backend::{BufferMappedRange, Context as C};
@@ -198,6 +192,7 @@ trait Context: Debug + Send + Sized + Sync {
) -> Self::RequestDeviceFuture;
fn adapter_features(&self, adapter: &Self::AdapterId) -> Features;
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits;
fn adapter_get_info(&self, adapter: &Self::AdapterId) -> AdapterInfo;
fn device_features(&self, device: &Self::DeviceId) -> Features;
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
@@ -915,8 +910,8 @@ pub enum BindingResource<'a> {
///
/// The render target must be cleared at least once before it's content be loaded.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub enum LoadOp<V> {
/// Clear with a specified value.
Clear(V),
@@ -932,8 +927,8 @@ impl<V: Default> Default for LoadOp<V> {
/// Pair of load and store operations for an attachment aspect.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub struct Operations<V> {
/// How data should be read through this attachment.
pub load: LoadOp<V>,
@@ -1406,9 +1401,8 @@ impl Adapter {
}
/// Get info about the adapter itself.
#[cfg(not(target_arch = "wasm32"))]
pub fn get_info(&self) -> AdapterInfo {
self.context.adapter_get_info(self.id)
Context::adapter_get_info(&*self.context, &self.id)
}
}