-
Notifications
You must be signed in to change notification settings - Fork 965
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
Separate Out Backend Options into Individual Structs #6895
Open
cwfitzgerald
wants to merge
1
commit into
gfx-rs:trunk
Choose a base branch
from
cwfitzgerald:cw/per-backend-configurations
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,74 @@ let desc: ShaderModuleDescriptor = include_wgsl!(...) | |
|
||
By @cwfitzgerald and @rudderbucky in [#6662](https://github.com/gfx-rs/wgpu/pull/6662). | ||
|
||
#### `wgpu::Instance::new` now takes `InstanceDescriptor` by reference | ||
|
||
Previously `wgpu::Instance::new` took `InstanceDescriptor` by value (which is overall fairly uncommon in wgpu). | ||
Furthermore, `InstanceDescriptor` is now cloneable. | ||
|
||
```diff | ||
- let instance = wgpu::Instance::new(instance_desc); | ||
+ let instance = wgpu::Instance::new(&instance_desc); | ||
``` | ||
|
||
By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849). | ||
|
||
#### Environment Variable Handling Overhaul | ||
|
||
Previously how various bits of code handled reading settings from environment variables was inconsistent and unideomatic. | ||
We have unified it to `Type::from_env()` for all types. | ||
|
||
```diff | ||
- wgpu::util::backend_bits_from_env() | ||
+ wgpu::Backends::from_env() | ||
|
||
- wgpu::util::power_preference_from_env() | ||
+ wgpu::PowerPreference::from_env() | ||
|
||
- wgpu::util::dx12_shader_compiler_from_env() | ||
+ wgpu::Dx12Compiler::from_env() | ||
|
||
- wgpu::util::gles_minor_version_from_env() | ||
+ wgpu::Gles3MinorVersion::from_env() | ||
|
||
- wgpu::util::instance_descriptor_from_env() | ||
+ wgpu::InstanceDescriptor::from_env() | ||
|
||
- wgpu::util::parse_backends_from_comma_list(&str) | ||
+ wgpu::Backends::from_comma_list(&str) | ||
``` | ||
|
||
By @cwfitzgerald in [#6895](https://github.com/gfx-rs/wgpu/pull/6895) | ||
|
||
#### Backend-specific instance options are now in separate structs | ||
|
||
In order to better facilitate growing more interesting backend options, we have put them into individual structs. This allows users to more easily understand what options can be defaulted and which they care about. All of these new structs implement `from_env()` and delegate to their respective `from_env()` methods. | ||
|
||
```diff | ||
- let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { | ||
- backends: wgpu::Backends::all(), | ||
- flags: wgpu::InstanceFlags::default(), | ||
- dx12_shader_compiler: wgpu::Dx12Compiler::Dxc, | ||
- gles_minor_version: wgpu::Gles3MinorVersion::Automatic, | ||
- }); | ||
+ let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { | ||
+ backends: wgpu::Backends::all(), | ||
+ flags: wgpu::InstanceFlags::default(), | ||
+ backend_options: wgpu::BackendOptions { | ||
+ dx12: wgpu::Dx12BackendOptions { | ||
+ shader_compiler: wgpu::Dx12ShaderCompiler::Dxc, | ||
+ }, | ||
+ gl: wgpu::GlBackendOptions { | ||
+ gles_minor_version: wgpu::Gles3MinorVersion::Automatic, | ||
+ }, | ||
Comment on lines
+131
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love it! |
||
+ }, | ||
+ }); | ||
``` | ||
|
||
If you do not need any of these options, or only need one backend's info use the `default()` impl to fill out the remaining feelds. | ||
|
||
By @cwfitzgerald in [#6895](https://github.com/gfx-rs/wgpu/pull/6895) | ||
|
||
#### The `diagnostic(…);` directive is now supported in WGSL | ||
|
||
Naga now parses `diagnostic(…);` directives according to the WGSL spec. This allows users to control certain lints, similar to Rust's `allow`, `warn`, and `deny` attributes. For example, in standard WGSL (but, notably, not Naga yet—see <https://github.com/gfx-rs/wgpu/issues/4369>) this snippet would emit a uniformity error: | ||
|
@@ -125,18 +193,6 @@ There are some limitations to keep in mind with this new functionality: | |
|
||
By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148](https://github.com/gfx-rs/wgpu/pull/6148), [#6533](https://github.com/gfx-rs/wgpu/pull/6533), [#6353](https://github.com/gfx-rs/wgpu/pull/6353), [#6537](https://github.com/gfx-rs/wgpu/pull/6537). | ||
|
||
#### `wgpu::Instance::new` now takes `InstanceDescriptor` by reference | ||
|
||
Previously `wgpu::Instance::new` took `InstanceDescriptor` by value (which is overall fairly uncommon in wgpu). | ||
Furthermore, `InstanceDescriptor` is now cloneable. | ||
|
||
```diff | ||
- let instance = wgpu::Instance::new(instance_desc); | ||
+ let instance = wgpu::Instance::new(&instance_desc); | ||
``` | ||
|
||
By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849). | ||
|
||
#### New Features | ||
|
||
##### Naga | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the
with_env
we had in a few places rather convenient as well. You'd do some settings and then instruct to be able to override it freely with environment variables.We can take that as a separate iteration ofc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case all
from_env
would just be a shortcut fordefault().with_env()
. How that that sound to you?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine just feels a little indirect and I'm not sure I'd think of that pattern when looking at the docs maybe having both is the answer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh both is exactly what you're suggesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An advantage of
from_env() -> Option<Self>
is that the caller knows whether the environment variable was used (by seeing whether theOption
isSome
). This can be useful to give users hints about the usage of the variables, in particular,Some of the benefit can be gotten from logging the final value, but it’s clearer to explicitly log the provenance of the value rather than requiring the user to infer from whether it is different.
(It happens that in the only case so far I do this it's for
initialize_adapter_from_env
, which isn't changed in this PR and arguably shouldn’t change, but since you’re stating a general principle, I felt I should give my general counterargument.)[Edit:] Several comments happened while I was writing, and I also see I wasn’t entirely clear. To be clear, what I’m asking for is that there should continue to be a
from_env()
function for each type-that-can-be-taken-from-environment, and it should continue to returnOption<Self>
(indicates whether the value was taken from environment) rather thanSelf
(doesn't indicate).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re your edit: does this include compound cases (BackendOptions) or just single env-var cases?