Skip to content

Commit

Permalink
[rs] Merge gfx-rs#350
Browse files Browse the repository at this point in the history
350: Implement Extensions Interface r=kvark a=cwfitzgerald

This implements gfx-rs#703 in wgpu-rs. Notable changes include the removal of the anisotropic field from the examples, in favor of the now mandatory `..Default::default()` syntax.

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
  • Loading branch information
bors[bot] and cwfitzgerald authored Jun 8, 2020
2 parents e655053 + 28c0b8f commit 5f567e2
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 17 deletions.
4 changes: 2 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ vulkan = ["wgc/gfx-backend-vulkan"]
package = "wgpu-core"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "ac9587e9ced5b043abad68e260cb8c9e812cffb5"
rev = "041db60f9080769b5edc40888cf9683ccb255399"
features = ["raw-window-handle"]

[dependencies.wgt]
package = "wgpu-types"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "ac9587e9ced5b043abad68e260cb8c9e812cffb5"
rev = "041db60f9080769b5edc40888cf9683ccb255399"

[dependencies]
arrayvec = "0.5"
Expand Down
11 changes: 8 additions & 3 deletions wgpu/examples/capture/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::env;
/// This example shows how to capture an image by rendering it to a texture, copying the texture to
/// a buffer, and retrieving it from the buffer. This could be used for "taking a screenshot," with
/// the added benefit that this method doesn't require a window to be created.
use std::fs::File;
use std::mem::size_of;
use std::env;
use std::io::Write;
use std::mem::size_of;

async fn run() {
let adapter = wgpu::Instance::new()
Expand All @@ -13,6 +13,7 @@ async fn run() {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: None,
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
Expand Down Expand Up @@ -132,7 +133,11 @@ async fn run() {
if let Ok(()) = buffer_future.await {
let padded_buffer = output_buffer.get_mapped_range(0, wgt::BufferSize::WHOLE);

let mut png_encoder = png::Encoder::new(File::create("red.png").unwrap(), width as u32, height as u32);
let mut png_encoder = png::Encoder::new(
File::create("red.png").unwrap(),
width as u32,
height as u32,
);
png_encoder.set_depth(png::BitDepth::Eight);
png_encoder.set_color(png::ColorType::RGBA);
let mut png_writer = png_encoder
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl framework::Example for Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
anisotropy_clamp: None,
..Default::default()
});
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
let mx_ref: &[f32; 16] = mx_total.as_ref();
Expand Down
1 change: 1 addition & 0 deletions wgpu/examples/describe/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async fn run() {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: None,
},
unsafe { wgpu::UnsafeExtensions::allow() },
wgpu::BackendBit::PRIMARY,
)
.await
Expand Down
1 change: 1 addition & 0 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async fn run_async<E: Example>(event_loop: EventLoop<()>, window: Window) {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: Some(&surface),
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
Expand Down
1 change: 1 addition & 0 deletions wgpu/examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: None,
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
Expand Down
1 change: 1 addition & 0 deletions wgpu/examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
power_preference: wgpu::PowerPreference::Default,
compatible_surface: Some(&surface),
},
wgpu::UnsafeExtensions::disallow(),
wgpu::BackendBit::PRIMARY,
)
.await
Expand Down
4 changes: 2 additions & 2 deletions wgpu/examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
anisotropy_clamp: None,
..Default::default()
});

let views = (0..mip_count)
Expand Down Expand Up @@ -310,7 +310,7 @@ impl framework::Example for Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
anisotropy_clamp: None,
..Default::default()
});
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
let mx_ref: &[f32; 16] = mx_total.as_ref();
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl framework::Example for Example {
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
compare: Some(wgpu::CompareFunction::LessEqual),
anisotropy_clamp: None,
..Default::default()
});

let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {
Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl framework::Example for Skybox {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: None,
anisotropy_clamp: None,
..Default::default()
});

let paths: [&'static [u8]; 6] = [
Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,15 @@ impl crate::Context for Context {
fn instance_request_adapter(
&self,
options: &crate::RequestAdapterOptions<'_>,
unsafe_extensions: wgt::UnsafeExtensions,
backends: wgt::BackendBit,
) -> 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,
wgc::instance::AdapterInputs::Mask(backends, |_| PhantomData),
);
ready(id)
Expand Down
6 changes: 6 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ impl crate::Context for Context {
fn instance_request_adapter(
&self,
options: &crate::RequestAdapterOptions<'_>,
_unsafe_extensions: wgt::UnsafeExtensions,
_backends: wgt::BackendBit,
) -> Self::RequestAdapterFuture {
//TODO: support this check, return `None` if the flag is not set.
Expand Down Expand Up @@ -689,6 +690,11 @@ impl crate::Context for Context {
if trace_dir.is_some() {
//Error: Tracing isn't supported on the Web target
}
assert!(
!desc.extensions.intersects(crate::Extensions::ALL_NATIVE),
"The web backend doesn't support any native extensions. Enabled native extensions: {:?}",
desc.extensions & crate::Extensions::ALL_NATIVE
);
let mut mapped_desc = web_sys::GpuDeviceDescriptor::new();
// TODO: label, extensions
let mut mapped_limits = web_sys::GpuLimits::new();
Expand Down
21 changes: 14 additions & 7 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub use wgt::{
RasterizationStateDescriptor, ShaderLocation, ShaderStage, StencilOperation,
StencilStateFaceDescriptor, StoreOp, SwapChainDescriptor, SwapChainStatus, TextureAspect,
TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, TextureUsage,
TextureViewDimension, VertexAttributeDescriptor, VertexFormat, BIND_BUFFER_ALIGNMENT,
COPY_BYTES_PER_ROW_ALIGNMENT,
TextureViewDimension, UnsafeExtensions, VertexAttributeDescriptor, VertexFormat,
BIND_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
};

use backend::Context as C;
Expand Down Expand Up @@ -123,6 +123,7 @@ trait Context: Sized {
fn instance_request_adapter(
&self,
options: &RequestAdapterOptions<'_>,
unsafe_extensions: wgt::UnsafeExtensions,
backends: wgt::BackendBit,
) -> Self::RequestAdapterFuture;
fn adapter_request_device(
Expand Down Expand Up @@ -923,12 +924,17 @@ impl Instance {

/// Retrieves all available [`Adapter`]s that match the given backends.
#[cfg(not(target_arch = "wasm32"))]
pub fn enumerate_adapters(&self, backends: wgt::BackendBit) -> impl Iterator<Item = Adapter> {
pub fn enumerate_adapters(
&self,
unsafe_extensions: wgt::UnsafeExtensions,
backends: wgt::BackendBit,
) -> impl Iterator<Item = Adapter> {
let context = Arc::clone(&self.context);
self.context
.enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| {
PhantomData
}))
.enumerate_adapters(
unsafe_extensions,
wgc::instance::AdapterInputs::Mask(backends, |_| PhantomData),
)
.into_iter()
.map(move |id| crate::Adapter {
id,
Expand Down Expand Up @@ -982,11 +988,12 @@ impl Instance {
pub fn request_adapter(
&self,
options: &RequestAdapterOptions<'_>,
unsafe_extensions: wgt::UnsafeExtensions,
backends: BackendBit,
) -> impl Future<Output = Option<Adapter>> + Send {
let context = Arc::clone(&self.context);
self.context
.instance_request_adapter(options, backends)
.instance_request_adapter(options, unsafe_extensions, backends)
.map(|option| option.map(|id| Adapter { context, id }))
}
}
Expand Down

0 comments on commit 5f567e2

Please sign in to comment.