Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Anisotropic Filtering Extension and Expose Extension Interface #690

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

cwfitzgerald
Copy link
Member

@cwfitzgerald cwfitzgerald commented Jun 1, 2020

Connections

Resolves #568.

Description

This PR solves two tightly related problems:

  • Adds the ability to create a sampler with anisotropic filtering
  • Adds the webgpu interface for getting the limits/extensions on adapters and devies.

Testing

I have tested this against my codebase which uses it. Adding an example in wgpu-rs on how to use extensions/limits would be good, especially as we have native/webgpu extensions, but can come as a future enhancement, once we feel the extension situation has stabilized a bit.

TODO

/// Before an extension is used, one must check the actual supported
/// extensions by ...
///
/// TODO: Allow user to check extensions available.
#[repr(C)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct Extensions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should Extensions/Limits be marked as #[non_exhaustive]?

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 would imagine so. I should add that note to #691. I anticipate discussion on that issue changing this PR before it's merged.

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 realize now that another benefit to this is that adding extensions that don't modify structures become a non breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, we may need to add extensions that do change structures in a non-breaking way, at some point, probably soon. I.e. we don't want to break wgpu-core API after WebGPU is out and we are just adding more extensions :/

We could do this by adding a private PhantomData field to structures, which implement Default.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we're okay with the MSRV bump, we can just use #[non_exhaustive] on basically every struct.

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Thank you!
It looks great overall, just a few small things to fix before we go.

wgpu-core/src/device/mod.rs Outdated Show resolved Hide resolved
wgpu-core/src/instance.rs Outdated Show resolved Hide resolved
@cwfitzgerald
Copy link
Member Author

Changes should be addressed

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Thank you! A few more notes...

wgpu-types/src/lib.rs Outdated Show resolved Hide resolved
@@ -88,6 +88,10 @@ impl From<Backend> for BackendBit {
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct Extensions {
/// This is a native only extension. Support is planned to be added to webgpu,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is even required to be specified, actually. If you are running on the Web, the adapter will just not expose this extension. There is no extra benefit of knowing that it's native-only.

wgpu-core/src/instance.rs Outdated Show resolved Hide resolved
@cwfitzgerald
Copy link
Member Author

Addressed as discussed

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Thank you!
bors r+

bors bot added a commit that referenced this pull request Jun 1, 2020
690: Implement Anisotropic Filtering Extension and Expose Extension Interface r=kvark a=cwfitzgerald

**Connections**

Resolves #568.

**Description**

This PR solves two tightly related problems:
 - Adds the ability to create a sampler with anisotropic filtering
 - Adds the webgpu interface for getting the limits/extensions on adapters and devies.

**Testing**

I have tested this against my codebase which uses it. Adding an example in wgpu-rs on how to use extensions/limits would be good, especially as we have native/webgpu extensions, but can come as a future enhancement, once we feel the extension situation has stabilized a bit.

**TODO**

- [x] Allow wgpu-rs to call limit/extension interface (gfx-rs/wgpu-rs#338)
- [ ] Determine how wgpu-native is going to adopt this functionality.
- [ ] After discussing #691, what changes need to be made. 

Co-authored-by: Connor Fitzgerald <[email protected]>
@kvark
Copy link
Member

kvark commented Jun 1, 2020

bors retry

@bors
Copy link
Contributor

bors bot commented Jun 1, 2020

Build succeeded:

@bors bors bot merged commit 3a6cdee into gfx-rs:master Jun 1, 2020
@cwfitzgerald cwfitzgerald deleted the anisotropic-filtering branch June 1, 2020 16:57
bors bot added a commit to gfx-rs/wgpu-rs that referenced this pull request Jun 1, 2020
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]>
bors bot added a commit that referenced this pull request Jun 3, 2020
696: Rustification of Extensions and SamplerDescriptor r=kvark a=cwfitzgerald

**Connections**

This begins the rustificaiton of `wgpu-types` as discussed in #689, starting with `Extensions` and `SamplerDescriptor`.

#691 and the resulting discussion was used to advise the shape of the extension struct.

**Description**

The PR should be fairly straight forward. As discussed, I have left extensions as a bitflag until the webgpu-native issue can be opened and discussed regarding allocation of extensions.

The most controversial part of this will be the `AnisotropyLevel` enum. I created it for two reasons, one that matters, one that doesn't:
 - It means that, with the exception of enabling the aniso extension (and lod_bias), the sampler is correct by construction, which is helpful to both beginners and experts. It also better exposes the range of valid values and means less panics in user code.
 - It saves a byte in the `Option<u8>` 😄 

I definitely think that, if at all possible, we should have explicitly typed enums for "numbers" which have a limited amount of valid values (so _not_ lod bias, though that may be better expressed, idk) to make it very explicit which values can be accepted. This also feels more "rusty" and reduces the amount of "magicness" in the interface.

Ofc, I'm not married to the idea.

**Testing**

Follow up PR into wgpu-rs will include conversion of the examples.

**TODO**

- [x] wgpu-native pr rolling up this PR and #690 (gfx-rs/wgpu-native#34)
- [x] wgpu-rs pr updating examples with the new structures (gfx-rs/wgpu-rs#345)

Co-authored-by: Connor Fitzgerald <[email protected]>
bors bot added a commit that referenced this pull request Jun 3, 2020
696: Rustification of Extensions and SamplerDescriptor r=kvark a=cwfitzgerald

**Connections**

This begins the rustificaiton of `wgpu-types` as discussed in #689, starting with `Extensions` and `SamplerDescriptor`.

#691 and the resulting discussion was used to advise the shape of the extension struct.

**Description**

The PR should be fairly straight forward. As discussed, I have left extensions as a bitflag until the webgpu-native issue can be opened and discussed regarding allocation of extensions.

The most controversial part of this will be the `AnisotropyLevel` enum. I created it for two reasons, one that matters, one that doesn't:
 - It means that, with the exception of enabling the aniso extension (and lod_bias), the sampler is correct by construction, which is helpful to both beginners and experts. It also better exposes the range of valid values and means less panics in user code.
 - It saves a byte in the `Option<u8>` 😄 

I definitely think that, if at all possible, we should have explicitly typed enums for "numbers" which have a limited amount of valid values (so _not_ lod bias, though that may be better expressed, idk) to make it very explicit which values can be accepted. This also feels more "rusty" and reduces the amount of "magicness" in the interface.

Ofc, I'm not married to the idea.

**Testing**

Follow up PR into wgpu-rs will include conversion of the examples.

**TODO**

- [x] wgpu-native pr rolling up this PR and #690 (gfx-rs/wgpu-native#34)
- [x] wgpu-rs pr updating examples with the new structures (gfx-rs/wgpu-rs#345)

Co-authored-by: Connor Fitzgerald <[email protected]>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
338: Add Extension/Limit Interface r=kvark a=cwfitzgerald

Follow up to gfx-rs#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]>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
690: Add `RenderEncoder` r=kvark a=0x182d4454fb211940

It seems like `RenderPass` and `RenderBundleEncoder` share many methods in common (`set_pipeline`, `draw_indexed`, etc). By creating a shared trait, it allows more reusable code. For instance:

```rust
impl RedCircle {
    fn new(...) -> Self { .. }
    fn draw<'a>(&'a self, encoder: &mut impl RenderEncoder<'a>) { .. }
}
```

This code would then work for both structs.

Moving the previous methods from their `impl`s to the trait's would break previous code, as to use these methods code would now have to import `RenderEncoder`. To avoid this, it is implemented by calling the direct methods.

It may be worth considering moving this to `wgpu::util`.

Co-authored-by: 0x182d4454fb211940 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to Enable Anisotropic Filtering on Sampler
4 participants