Skip to content

Commit

Permalink
[rs] Merge gfx-rs#682
Browse files Browse the repository at this point in the history
682: Expose adapter.get_info() everywhere r=grovesNL a=kvark



Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com>
  • Loading branch information
bors[bot] and kvark authored Dec 19, 2020
2 parents 6489a11 + 7a8c6ce commit 860265e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 13 additions & 13 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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, |_| {
Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
42 changes: 18 additions & 24 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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>,
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 860265e

Please sign in to comment.