mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #350
350: Implement Extensions Interface r=kvark a=cwfitzgerald This implements https://github.com/gfx-rs/wgpu/pull/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>
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
@@ -13,6 +13,7 @@ async fn run() {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
compatible_surface: None,
|
||||
},
|
||||
wgpu::UnsafeExtensions::disallow(),
|
||||
wgpu::BackendBit::PRIMARY,
|
||||
)
|
||||
.await
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -6,6 +6,7 @@ async fn run() {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
compatible_surface: None,
|
||||
},
|
||||
unsafe { wgpu::UnsafeExtensions::allow() },
|
||||
wgpu::BackendBit::PRIMARY,
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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] = [
|
||||
|
||||
@@ -223,6 +223,7 @@ 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(
|
||||
@@ -230,6 +231,7 @@ impl crate::Context for Context {
|
||||
power_preference: options.power_preference,
|
||||
compatible_surface: options.compatible_surface.map(|surface| surface.id),
|
||||
},
|
||||
unsafe_extensions,
|
||||
wgc::instance::AdapterInputs::Mask(backends, |_| PhantomData),
|
||||
);
|
||||
ready(id)
|
||||
|
||||
@@ -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.
|
||||
@@ -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();
|
||||
|
||||
21
src/lib.rs
21
src/lib.rs
@@ -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;
|
||||
@@ -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(
|
||||
@@ -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,
|
||||
@@ -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 }))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user