567: Notes on LoadOp r=kvark a=PENGUINLIONG
If the swapchain image was drawn with a pipeline that loads a render target that has not been cleared before, the validation layer gives a triplet of confusing feedbacks:
```log
[2020-09-15T06:42:23Z ERROR gfx_backend_vulkan]
VALIDATION [UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout (1303270965)] : Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x1d80787bfe8, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | Submitted command buffer expects VkImage 0x6dc7200000000005[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
object info: (type: COMMAND_BUFFER, hndl: 2027350900712)
[2020-09-15T06:42:23Z ERROR gfx_backend_vulkan]
VALIDATION [UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout (1303270965)] : Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x1d8078586a8, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | Submitted command buffer expects VkImage 0x3ba5830000000006[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
object info: (type: COMMAND_BUFFER, hndl: 2027350754984)
[2020-09-15T06:42:23Z ERROR gfx_backend_vulkan]
VALIDATION [UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout (1303270965)] : Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x1d8078614f8, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | Submitted command buffer expects VkImage 0x4c5b620000000007[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
object info: (type: COMMAND_BUFFER, hndl: 2027350791416)
```
And it turns out they come from the triple-buffering swapchain images. It seems `wgpu` would only re-layout the swapchain image if it's been loaded by a clear op. I would be great to warn the users beforehand. (I know it's not something I should ever do tho)
Co-authored-by: PENGUINLIONG <admin@penguinliong.moe>
565: Add context to errors r=kvark a=scoopr
ContextError is just a simple wrapper that contains a string and the original error, and it is used to decorate the error to give it more context.
Co-authored-by: Mikko Lehtonen <scoopr@iki.fi>
562: More errorsinkifying r=kvark a=scoopr
Continuing on with errorsinkifying more places, these wrap Buffer, Texture and CommandEncoder with a struct that includes the `error_sink`, and uses it for the error handling.
I think most of the apis are errorsinkified with this. The remaining ones may need some more thinking.
Queue would be wrapped mostly for the submit, the write_ stuff could in theory piggyback on the texture/buffer error-sink.
Others like swapchain, some mapping stuff, etc. needs some discussion or other implementation work.
Co-authored-by: Mikko Lehtonen <scoopr@iki.fi>
563: Document bind buffer alignment r=kvark a=kvark
Fixes #561
Also updates wgpu dependency to latest, and our exampels are now fully validated for the shader interface 🎉 .
Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
557: Pin web-sys version r=grovesNL a=rukai
As mentioned in https://github.com/gfx-rs/wgpu-rs/pull/553 this will prevent the wasm build from breaking.
@grovesNL Is pinning just web-sys and wasm-bindgen sufficient?
Co-authored-by: Rukai <rubickent@gmail.com>
555: Update to latest web-sys r=kvark a=grovesNL
Cherry-pick #497 into `master` now that new versions of web-sys/wasm-bindgen/js-sys/wasm-bindgen-futures are published.
We could also do this for `v0.6` too if we want CI to succeed there, or alternatively consider disabling CI for wasm builds on `v0.6`.
Co-authored-by: Joshua Groves <josh@joshgroves.com>
551: Replace unsafe impl Pod with safe derive r=kvark a=rukai
bytemuck now includes derives that will implement the Pod trait, failing to compile if the struct cannot safely be a Pod.
Lets use it to remove most of the unsafe usage from the examples.
closes https://github.com/gfx-rs/wgpu-rs/issues/190
Co-authored-by: Rukai <rubickent@gmail.com>
547: Implement on_uncaptured_error r=kvark,cwfitzgerald a=scoopr
This is very crude at the moment, I'm mostly just checking if the directions is at all viable.
So I set out to implement `on_caught_error`, focusing solely on the direct backend. It just accepts a `Fn(GPUError)` (and I named it GPUError because I didn't yet want to rename the import of `std::error::Error`).
I store the handler in a `ErrorSinkRaw` struct, which is then wrapped in Arc+Mutex, with the idea that other resources can point to the same Arc, so when `Device::on_uncaught_error` is called mid application, all resources will point to the right place. Otherwise I think something like `Buffer::unmap` would have to find the `Device` it was created with, to find the uncaught handler.
Now I store the `ErrorSink` in the `Device` struct, because it is a convenient place to hold it. But I guess it is a bit nonsensical with the web backend, so either it would need to be `cfg(not(wasm32))`, or move the whole thing in the backend side, but in the direct backend, I don't see a convenient place to store the closure. But the unwrapping is done in direct backend, so it can't really be moved up in to wgpu-core either, unless the error handling overall is moved there.
Also related, I'm now passing the `error_sink` argument to the few methods where I implemented the error handling, which I think is a bit ugly, but it works.
Co-authored-by: Mikko Lehtonen <scoopr@iki.fi>
540: Improve and fix examples/texture-arrays r=cwfitzgerald a=im-0
Original examples/texture-arrays produces following output on my machine (Linux, Mesa/RADV 20.2-rc3, Radeon VII):

Quick investigation showed that only shaders with non-uniform indexing are problematic (first commit helped with this). Then, after searching on the web, I figured out that the problem is in missing `nonuniformEXT`. Second commit fixes this.
I am new to graphics programming, and `nonuniformEXT` may work just by accident. So please confirm my finding before merging.
Co-authored-by: Ivan Mironov <mironov.ivan@gmail.com>
545: Remove bake.frag from shadow example r=kvark a=yutannihilation
Now that `fragment_stage` is a `Option`, I guess this is the case when we don't need fragment shader.
Co-authored-by: Hiroaki Yutani <yutani.ini@gmail.com>
* The conditional at the start of resize() already tests for and exits on the zero width and height condition.
The conditional removed here was then getting run on every other call to resize(), which doesn't seem logical, doesn't correspond to the comment, and seemed to be causing at least one issue with rendered viewport going black during resize.
Fixes#532
(probably) Fixes#519
* Defensive coding to prevent various issues when window size goes to zero, e.g. NaN being passed in cgmath::perspective() aspect ratio parameter.
Fixes#531