Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 50d1eb6

Browse files
Merge #338
338: Add Extension/Limit Interface r=kvark a=cwfitzgerald Follow up to gfx-rs/wgpu#690. This forwards the extension/limit access interface into wgpu-rs. It appears that the web-sys doesn't actually implement any of the methods we need, so I had them return the defaults. `Device::limits` exists, but it returns `Object` not `GpuLimits`, so doesn't appear usable. Co-authored-by: Connor Fitzgerald <[email protected]>
2 parents d7abf5c + c4819cc commit 50d1eb6

File tree

8 files changed

+69
-4
lines changed

8 files changed

+69
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ vulkan = ["wgc/gfx-backend-vulkan"]
2828
package = "wgpu-core"
2929
version = "0.5"
3030
git = "https://github.com/gfx-rs/wgpu"
31-
rev = "1a569ebe89deabca2d8299a664d5cad4b437d8d8"
31+
rev = "3a6cdeec945b6e2795c5ad544101b273c3887037"
3232
features = ["raw-window-handle"]
3333

3434
[dependencies.wgt]
3535
package = "wgpu-types"
3636
version = "0.5"
3737
git = "https://github.com/gfx-rs/wgpu"
38-
rev = "1a569ebe89deabca2d8299a664d5cad4b437d8d8"
38+
rev = "3a6cdeec945b6e2795c5ad544101b273c3887037"
3939

4040
[dependencies]
4141
arrayvec = "0.5"

examples/cube/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ impl framework::Example for Example {
205205
lod_min_clamp: 0.0,
206206
lod_max_clamp: 100.0,
207207
compare: wgpu::CompareFunction::Undefined,
208+
anisotropy_clamp: 1,
208209
});
209210
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
210211
let mx_ref: &[f32; 16] = mx_total.as_ref();

examples/mipmap/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl Example {
157157
lod_min_clamp: 0.0,
158158
lod_max_clamp: 100.0,
159159
compare: wgpu::CompareFunction::Undefined,
160+
anisotropy_clamp: 1,
160161
});
161162

162163
let views = (0..mip_count)
@@ -309,6 +310,7 @@ impl framework::Example for Example {
309310
lod_min_clamp: 0.0,
310311
lod_max_clamp: 100.0,
311312
compare: wgpu::CompareFunction::Undefined,
313+
anisotropy_clamp: 1,
312314
});
313315
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
314316
let mx_ref: &[f32; 16] = mx_total.as_ref();

examples/shadow/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl framework::Example for Example {
351351
lod_min_clamp: -100.0,
352352
lod_max_clamp: 100.0,
353353
compare: wgpu::CompareFunction::LessEqual,
354+
anisotropy_clamp: 1,
354355
});
355356

356357
let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {

examples/skybox/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl framework::Example for Skybox {
130130
lod_min_clamp: 0.0,
131131
lod_max_clamp: 100.0,
132132
compare: wgpu::CompareFunction::Undefined,
133+
anisotropy_clamp: 1,
133134
});
134135

135136
let paths: [&'static [u8]; 6] = [

src/backend/direct.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
3-
BindingType, BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor,
4-
PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor, SwapChainStatus,
3+
BindingType, BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor, Extensions,
4+
Limits, PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor, SwapChainStatus,
55
TextureDescriptor, TextureViewDescriptor, TextureViewDimension,
66
};
77

@@ -251,6 +251,22 @@ impl crate::Context for Context {
251251
ready(Ok((device_id, device_id)))
252252
}
253253

254+
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions {
255+
gfx_select!(*adapter => self.adapter_extensions(*adapter))
256+
}
257+
258+
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits {
259+
gfx_select!(*adapter => self.adapter_limits(*adapter))
260+
}
261+
262+
fn device_extensions(&self, device: &Self::DeviceId) -> Extensions {
263+
gfx_select!(*device => self.device_extensions(*device))
264+
}
265+
266+
fn device_limits(&self, device: &Self::DeviceId) -> Limits {
267+
gfx_select!(*device => self.device_limits(*device))
268+
}
269+
254270
fn device_create_swap_chain(
255271
&self,
256272
device: &Self::DeviceId,

src/backend/web.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,30 @@ impl crate::Context for Context {
720720
)
721721
}
722722

723+
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> wgt::Extensions {
724+
// TODO: web-sys has no way of getting extensions on adapters
725+
wgt::Extensions {
726+
anisotropic_filtering: false,
727+
}
728+
}
729+
730+
fn adapter_limits(&self, adapter: &Self::AdapterId) -> wgt::Limits {
731+
// TODO: web-sys has no way of getting limits on adapters
732+
wgt::Limits::default()
733+
}
734+
735+
fn device_extensions(&self, device: &Self::DeviceId) -> wgt::Extensions {
736+
// TODO: web-sys has no way of getting extensions on devices
737+
wgt::Extensions {
738+
anisotropic_filtering: false,
739+
}
740+
}
741+
742+
fn device_limits(&self, device: &Self::DeviceId) -> wgt::Limits {
743+
// TODO: web-sys has a method for getting limits on devices, but it returns Object not GpuLimit
744+
wgt::Limits::default()
745+
}
746+
723747
fn device_create_swap_chain(
724748
&self,
725749
device: &Self::DeviceId,

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ trait Context: Sized {
134134
desc: &DeviceDescriptor,
135135
trace_dir: Option<&std::path::Path>,
136136
) -> Self::RequestDeviceFuture;
137+
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions;
138+
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits;
137139

140+
fn device_extensions(&self, device: &Self::DeviceId) -> Extensions;
141+
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
138142
fn device_create_swap_chain(
139143
&self,
140144
device: &Self::DeviceId,
@@ -999,6 +1003,14 @@ impl Adapter {
9991003
})
10001004
}
10011005

1006+
pub fn extensions(&self) -> Extensions {
1007+
Context::adapter_extensions(&*self.context, &self.id)
1008+
}
1009+
1010+
pub fn limits(&self) -> Limits {
1011+
Context::adapter_limits(&*self.context, &self.id)
1012+
}
1013+
10021014
#[cfg(not(target_arch = "wasm32"))]
10031015
pub fn get_info(&self) -> AdapterInfo {
10041016
//wgn::adapter_get_info(self.id)
@@ -1012,6 +1024,14 @@ impl Device {
10121024
Context::device_poll(&*self.context, &self.id, maintain);
10131025
}
10141026

1027+
pub fn extensions(&self) -> Extensions {
1028+
Context::device_extensions(&*self.context, &self.id)
1029+
}
1030+
1031+
pub fn limits(&self) -> Limits {
1032+
Context::device_limits(&*self.context, &self.id)
1033+
}
1034+
10151035
/// Creates a shader module from SPIR-V source code.
10161036
pub fn create_shader_module(&self, spv: &[u32]) -> ShaderModule {
10171037
ShaderModule {

0 commit comments

Comments
 (0)