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

Add Extension/Limit Interface #338

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 = "1a569ebe89deabca2d8299a664d5cad4b437d8d8"
rev = "3a6cdeec945b6e2795c5ad544101b273c3887037"
features = ["raw-window-handle"]

[dependencies.wgt]
package = "wgpu-types"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "1a569ebe89deabca2d8299a664d5cad4b437d8d8"
rev = "3a6cdeec945b6e2795c5ad544101b273c3887037"

[dependencies]
arrayvec = "0.5"
Expand Down
1 change: 1 addition & 0 deletions examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl framework::Example for Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::Undefined,
anisotropy_clamp: 1,
});
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: 2 additions & 0 deletions examples/mipmap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::Undefined,
anisotropy_clamp: 1,
});

let views = (0..mip_count)
Expand Down Expand Up @@ -309,6 +310,7 @@ impl framework::Example for Example {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::Undefined,
anisotropy_clamp: 1,
});
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 examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ impl framework::Example for Example {
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::LessEqual,
anisotropy_clamp: 1,
});

let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {
Expand Down
1 change: 1 addition & 0 deletions examples/skybox/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl framework::Example for Skybox {
lod_min_clamp: 0.0,
lod_max_clamp: 100.0,
compare: wgpu::CompareFunction::Undefined,
anisotropy_clamp: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change most (if not all) sampler descriptors to end with .. Default::default(). That would be more future proof, match the web better, and avoid exposing stuff that is not relevant

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Should I change this in this PR? Or should that be separate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have this merged, the PR just continues the convention of the old code, it's not required to change that

});

let paths: [&'static [u8]; 6] = [
Expand Down
20 changes: 18 additions & 2 deletions src/backend/direct.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
BindingType, BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor,
PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor, SwapChainStatus,
BindingType, BufferDescriptor, CommandEncoderDescriptor, ComputePipelineDescriptor, Extensions,
Limits, PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor, SwapChainStatus,
TextureDescriptor, TextureViewDescriptor, TextureViewDimension,
};

Expand Down Expand Up @@ -251,6 +251,22 @@ impl crate::Context for Context {
ready(Ok((device_id, device_id)))
}

fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions {
gfx_select!(*adapter => self.adapter_extensions(*adapter))
}

fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits {
gfx_select!(*adapter => self.adapter_limits(*adapter))
}

fn device_extensions(&self, device: &Self::DeviceId) -> Extensions {
gfx_select!(*device => self.device_extensions(*device))
}

fn device_limits(&self, device: &Self::DeviceId) -> Limits {
gfx_select!(*device => self.device_limits(*device))
}

fn device_create_swap_chain(
&self,
device: &Self::DeviceId,
Expand Down
24 changes: 24 additions & 0 deletions src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,30 @@ impl crate::Context for Context {
)
}

fn adapter_extensions(&self, adapter: &Self::AdapterId) -> wgt::Extensions {
// TODO: web-sys has no way of getting extensions on adapters
wgt::Extensions {
anisotropic_filtering: false,
}
}

fn adapter_limits(&self, adapter: &Self::AdapterId) -> wgt::Limits {
// TODO: web-sys has no way of getting limits on adapters
wgt::Limits::default()
}

fn device_extensions(&self, device: &Self::DeviceId) -> wgt::Extensions {
// TODO: web-sys has no way of getting extensions on devices
wgt::Extensions {
anisotropic_filtering: false,
}
}

fn device_limits(&self, device: &Self::DeviceId) -> wgt::Limits {
// TODO: web-sys has a method for getting limits on devices, but it returns Object not GpuLimit
wgt::Limits::default()
}

fn device_create_swap_chain(
&self,
device: &Self::DeviceId,
Expand Down
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ trait Context: Sized {
desc: &DeviceDescriptor,
trace_dir: Option<&std::path::Path>,
) -> Self::RequestDeviceFuture;
fn adapter_extensions(&self, adapter: &Self::AdapterId) -> Extensions;
fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits;

fn device_extensions(&self, device: &Self::DeviceId) -> Extensions;
fn device_limits(&self, device: &Self::DeviceId) -> Limits;
fn device_create_swap_chain(
&self,
device: &Self::DeviceId,
Expand Down Expand Up @@ -999,6 +1003,14 @@ impl Adapter {
})
}

pub fn extensions(&self) -> Extensions {
Context::adapter_extensions(&*self.context, &self.id)
}

pub fn limits(&self) -> Limits {
Context::adapter_limits(&*self.context, &self.id)
}

#[cfg(not(target_arch = "wasm32"))]
pub fn get_info(&self) -> AdapterInfo {
//wgn::adapter_get_info(self.id)
Expand All @@ -1012,6 +1024,14 @@ impl Device {
Context::device_poll(&*self.context, &self.id, maintain);
}

pub fn extensions(&self) -> Extensions {
Context::device_extensions(&*self.context, &self.id)
}

pub fn limits(&self) -> Limits {
Context::device_limits(&*self.context, &self.id)
}

/// Creates a shader module from SPIR-V source code.
pub fn create_shader_module(&self, spv: &[u32]) -> ShaderModule {
ShaderModule {
Expand Down