711: Implement Descriptor Array Extension r=kvark a=cwfitzgerald
## Connections
Blocked on https://github.com/gfx-rs/gfx/pull/3269 and does some funky git overrides to get CI to return meaningful results what will be removed once that PR lands and is published.
## Description
This PR implements the `TEXTURE_BINDING_ARRAY` native extension. This allows users to specify a uniform sized array of textures for use in shaders.
As a corollary, this PR rustifies the Bind Group and Bind Group Layout interface. Two main actions were taken when doing this:
- Types that were able to be shared among wgt, wgc, and wgpu-rs were moved into wgt.
- Types that had references to other wgpu-rs specific structures were duplicated into wgc with wgpu-rs structures replaced with the appropriate ID. Notes were added to the wgc types that they were duplicated directly from wgpu-rs.
From what I can tell, this resulted in a significant reduction in code complexity when dealing with bind groups, favoring strong types over runtime assertions.
Naga validation of arrays of textures was not implemented.
Documentation was added to extensions to help users understand what underlying tech was being relied on as well as the platforms it should be expected to work on. I think this pattern should be implemented across the board for extensions as it makes them much more user friendly to use.
## Testing
There is an example included in the wgpu-rs PR which was used for testing this feature. It worked on DX12, Vulkan, and Metal (MSL > 2.0), as was expected.
Additionally the other examples were run and are still verified to run.
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
356: Add generic ranges to buffer mapping api and make it safe. r=kvark a=lachlansneff
[Rendered](https://charted.space/notes/wgpu-rs/wgpu/struct.Buffer.html)
The safety issues with the current api (being able to unmap while still holding a slice to mapped data) are fixed by having `get_mapped_range` and `get_mapped_range_mut` return `BufferView` and `BufferViewMut`, which notify the buffer that those ranges are no longer being used when they're dropped. `Buffer.unmap` asserts that the list of mapped ranges is empty, therefore it is safe.
Co-authored-by: Lachlan Sneff <lachlan.sneff@gmail.com>
* Basic glsl support
* Miscellaneous fixes and vertex shader works
* Added rudimentary texture and sampler support
* Basic preprocessor
* Added preprocessor if macros
* Pass tests and handle floats correctly
* Fix preprocessor if wrong precedence ordering when using macros
Refractor for the glsl parser
Partial primary expression parser
* Fix all clippy errors
* Cleanup
* Rollback formatting changes in lib.rs
710: Empty buffers are created internally with a size of 1 r=cwfitzgerald a=rukai
**Connections**
closes https://github.com/gfx-rs/wgpu/issues/709
**Description**
Empty buffers can be succesfully created.
**Testing**
Tested on my project and it resolves the above issue.
Co-authored-by: Rukai <rubickent@gmail.com>
708: Implement Mappable Primary Buffers Extension r=kvark a=cwfitzgerald
**Connections**
#675 made `MAP_WRITE | STORAGE` on buffers not possible. This extension re-enables it.
**Description**
UMA systems rejoice everywhere.
**Testing**
Hopefully it didn't break since it was usable a week or so ago, so this shouldn't need testing...
**Review Notes**
The name could be changed, particularly if primary has a certain meaning wrt buffers. It just seemed a reasonable description.
Knowing my luck, I got the bitflags call wrong...
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
707: Implement Bounds Checking on Buffers to Buffer and Texture Copies r=kvark a=cwfitzgerald
**Connections**
Closes#362, closes#554
This addresses issues found by @gretchenfrage when accidentally writing off the end of a texture causing a DEVICE_LOST error.
**Description**
Adds bounds checks to write_texture and write_buffer, and copy_texture_to_texture and friends. The bounds checking functions themselves follow guidance from the webgpu standard.
This doesn't make wgpu 100% to all the checks required by the standard, but takes care of the ones related to bounds and buffer overruns.
**Testing**
I tested this against all the examples, including intentionally making mistakes in texture copies, with this successfully catching those errors.
**Review Notes**
This code should be picked through fairly closely, as it's very likely there's some typos due to the close-but-not-quite repetition that these tests require. There's a bunch of LOC, but they are fairly boring and should be easy to understand.
I have tried to give assert messages that are as descriptive as possible, but if there is a message that could be changed to be more clear, let me know.
One thing that could change is the location of the functions. I left them where I originally wrote them, before I realized that the functions on queue also needed bounds checking, but they could have a better home elsewhere, maybe even their own file.
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
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>
706: Return errors on create_render_pipeline r=cwfitzgerald a=kvark
This is a follow-up to #705 that switches `create_render_pipeline` to return `Result`.
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
705: Shader input/output validation r=cwfitzgerald a=kvark
**Connections**
Fixes#269
It still has a few gaps (like the `storage_texture_format` matching, bugs, optional validation), but the main logic is there. Anything else should come in smaller issues as a follow-up.
**Description**
The main goal of this PR is to validate:
- vertex input stage against VS inputs
- VS outputs against FS inputs
- FS outputs against the pipeline attachment formats
I figured that `WGPU_SHADER_VALIDATION` environment is not a great path forward. It doesn't help engine authors, for example. So I'm switching it to just a boolean field in `DeviceDescriptor`. Hopefully, we'll remove it soon :)
**Testing**
Just running wgpu-rs examples - https://github.com/gfx-rs/wgpu-rs/pull/354
Review notes: the commit in the middle just moves stuff around. I think it's easier to just review the first and the last commit, ignoring the middle.
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
704: Pipeline layout validation r=cwfitzgerald a=kvark
**Connections**
Implements a solid part of #269
Starts converting the function to return results, related to #638
cc @GabrielMajeri
**Description**
This change matches shader bindings against the pipeline layout. It's *mostly* complete, minus some bugs and not handling the `storage_texture_format` properly.
The risk here is that Naga reflection may have bugs, or our validation may have bugs, and we don't want to break the user content while this is in flux. So the PR introduces an internal `WGPU_SHADER_VALIDATION` environment variable. Switching it to "0" skips Naga shader parsing completely and allows the users to unsafely use the API.
Another aspect of the PR is that some of the functions now return `Result`. The way I see us proceeding is that any errors that we don't expect users to handle should result in panics when `wgpu` is used natively (i.e. not from a browser). These panics would happen in the "direct" backend of wgpu-rs (as well as in wgpu-native), but the `Result` would not be exposed to wgpu-rs, so that it matches the Web behavior.
At the same time, browser implementations (Gecko and Servo) will check the result on their GPU process and implement the WebGPU error model accordingly. This means `wgpu-core` can be super Rusty and safe.
**Testing**
Running on wgpu-rs examples. Most of them fail to get parsed by Naga, but `boids` succeeds and passes validation 🎉
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
353: Properly honor `mapped_at_creation` in `Device::create_buffer` r=cwfitzgerald a=kyren
The returned `Buffer` should immediately be mappable. Fixes#351
Co-authored-by: kyren <kerriganw@gmail.com>
703: Implement Extensions Interface r=kvark a=cwfitzgerald
## Description
This is the first step of implementing #691. This implements the described changes to all the core structs and to `SamplerDescriptor`. I intend this PR to be an example of what the plan looks like. If we think this works, we can roll out the rest of the changes either in bulk or as we need them.
The rolling out of this is also tied to the rolling out of #689. Hopefully the macro work done in https://github.com/gfx-rs/wgpu-native/pull/34 will make this easier.
## Questions
One outstanding question I had is what the default values for lod_min/max should be. As of right now I just derive default, which puts them at zero, which is probably a reasonable default, though most of the examples use -100, 100 which is normally what you use when doing mipmapping.
## TODO:
- [ ] Discuss if this meets our needs
- [x] Implement this in wgpu-rs (https://github.com/gfx-rs/wgpu-rs/pull/350)
- [ ] Implement this in wgpu-native
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
348: Add aribitrary texture size handling to the capture example r=me a=rukai
* User can specify width + height via arguments.
* Defaults to (100, 200) when no arguments. Odd values chosen to make it more likely to pick up issues when testing.
* Converts from bgra as I believe that is the most commonly supported format for swapchains?
Co-authored-by: Rukai <rubickent@gmail.com>
702: Fix SwapChainOutput Related Segfault r=kvark a=cwfitzgerald
If a user accidentally recreates a swapchain after grabbing a SwapChainOutput, then renders to it, this will trigger a segfault on render. This can be reproduced by replacing the get_next_frame code in any example with:
```rust
let frame = swap_chain
.get_next_frame()
.expect("Failed to acquire next swap chain texture")
.output;
device.create_swap_chain(&surface, &sc_desc);
```
I have tested the examples, and they still work after this change, and it correctly detects this condition.
Oddly enough the following code does not panic, nor actually raise any errors, even with this PR.
```rust
let tmp = device.create_swap_chain(&surface, &sc_desc);
let frame = swap_chain
.get_next_frame()
.expect("Failed to acquire next swap chain texture")
.output;
swap_chain = tmp;
```
I'm not entirely sure why.
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
701: Prevent internal thread from cleanup r=kvark a=kvark
**Connections**
Fixes#700
**Description**
The logic that removes command allocators for threads that no longer use it was accidentally removing the one for the "main" thread.
**Testing**
Untested
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
346: Add Makefile for shader compilation r=kvark a=HanKruiger
I couldn't find clear instructions on how to compile the shaders in the examples, and had to do some digging. So I added instructions to the README to hopefully save other people's time.
Sidenote: When I compile the shaders as they are now (with my instructions), I end up with different `.spv` shaders with (seemingly) equivalent behaviour. I expect this is due to a different version/environment of `glslang` (see below) but it could be a mistake on my part.
```
> glslangValidator --version
Glslang Version: 8.13.3743
ESSL Version: OpenGL ES GLSL 3.20 glslang Khronos. 13.3743
GLSL Version: 4.60 glslang Khronos. 13.3743
SPIR-V Version 0x00010500, Revision 3
GLSL.std.450 Version 100, Revision 1
Khronos Tool ID 8
SPIR-V Generator Version 8
GL_KHR_vulkan_glsl version 100
ARB_GL_gl_spirv version 100
```
Cheers!
Co-authored-by: Han Kruiger <HanKruiger@users.noreply.github.com>
Add example shader compilation instructions
Arbitrary depth directory wildcard like globs aren't a thing in make wildcards.
Add phony targets as prerequisites of .PHONY
698: Add User Matrix Link r=kvark a=cwfitzgerald
Gone are the days of people not knowing there are two matrixes (matrices?)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
345: Rustify the example's use of Extensions and SamplerDescriptor r=kvark a=cwfitzgerald
Implements https://github.com/gfx-rs/wgpu/pull/696.
This didn't change any content from #338, just interface, but I tested a couple examples and it seems to work okay.
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
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 (https://github.com/gfx-rs/wgpu-native/pull/34)
- [x] wgpu-rs pr updating examples with the new structures (https://github.com/gfx-rs/wgpu-rs/pull/345)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
695: Fix tracing of buffers that are mapped at creation r=kvark a=kvark
**Connections**
Fixes API tracing for the new API introduced in #675
**Description**
When buffers are mapped at creation, we need to create a staging buffer and copy into them. This implies COPY_DST, which isn't visible to the user. And this only applies to buffers without MAP_WRITE, in which case we are just mapping directly.
**Testing**
Tested locally on the `cube`. It would be great to automate API trace testing on CI.
Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
344: Use the new map-async r=kvark a=kvark
Depends on https://github.com/gfx-rs/wgpu/pull/675
It changes the API of mapping and removes `create_buffer_mapped`.
The new functionality is not implemented in Gecko yet, so this breaks the web target, for now.
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>