From 56c917c749d94ba13c06c3ced5b9acadee3774c2 Mon Sep 17 00:00:00 2001 From: Ben Hansen Date: Sat, 2 Jul 2022 14:14:53 -0600 Subject: [PATCH] correcting code in tutorial3 and tutorial2 --- docs/beginner/tutorial2-surface/README.md | 17 +++++++++++------ docs/beginner/tutorial3-pipeline/README.md | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/beginner/tutorial2-surface/README.md b/docs/beginner/tutorial2-surface/README.md index 33c907c1..508262a6 100644 --- a/docs/beginner/tutorial2-surface/README.md +++ b/docs/beginner/tutorial2-surface/README.md @@ -376,7 +376,7 @@ Now we can get to clearing the screen (long time coming). We need to use the `en { let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), - color_attachments: &[wgpu::RenderPassColorAttachment { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: &view, resolve_target: None, ops: wgpu::Operations { @@ -388,7 +388,7 @@ Now we can get to clearing the screen (long time coming). We need to use the `en }), store: true, }, - }], + })], depth_stencil_attachment: None, }); } @@ -403,8 +403,6 @@ Now we can get to clearing the screen (long time coming). We need to use the `en First things first, let's talk about the extra block (`{}`) around `encoder.begin_render_pass(...)`. `begin_render_pass()` borrows `encoder` mutably (aka `&mut self`). We can't call `encoder.finish()` until we release that mutable borrow. The block tells rust to drop any variables within it when the code leaves that scope thus releasing the mutable borrow on `encoder` and allowing us to `finish()` it. If you don't like the `{}`, you can also use `drop(render_pass)` to achieve the same effect. -We can get the same results by removing the `{}`, and the `let _render_pass =` line, but we need access to the `_render_pass` in the next tutorial, so we'll leave it as is. - The last lines of the code tell `wgpu` to finish the command buffer, and to submit it to the gpu's render queue. We need to update the event loop again to call this method. We'll also call `update()` before it too. @@ -456,10 +454,17 @@ Some of you may be able to tell what's going on just by looking at it, but I'd b A `RenderPassDescriptor` only has three fields: `label`, `color_attachments` and `depth_stencil_attachment`. The `color_attachments` describe where we are going to draw our color to. We use the `TextureView` we created earlier to make sure that we render to the screen. +
+ +The `color_attachments` field is a "sparse" array. This allows you to use a pipeline that expects multiple render targets and only only supply the ones you care about. + +
+ + We'll use `depth_stencil_attachment` later, but we'll set it to `None` for now. ```rust -wgpu::RenderPassColorAttachment { +Some(wgpu::RenderPassColorAttachment { view: &view, resolve_target: None, ops: wgpu::Operations { @@ -471,7 +476,7 @@ wgpu::RenderPassColorAttachment { }), store: true, }, -} +}) ``` The `RenderPassColorAttachment` has the `view` field which informs `wgpu` what texture to save the colors to. In this case we specify the `view` that we created using `surface.get_current_texture()`. This means that any colors we draw to this attachment will get drawn to the screen. diff --git a/docs/beginner/tutorial3-pipeline/README.md b/docs/beginner/tutorial3-pipeline/README.md index a2607773..5877ce1e 100644 --- a/docs/beginner/tutorial3-pipeline/README.md +++ b/docs/beginner/tutorial3-pipeline/README.md @@ -156,7 +156,7 @@ let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { You can also use `include_wgsl!` macro as a small shortcut to create the `ShaderModuleDescriptor`. ```rust -let shader = device.create_shader_module(&include_wgsl!("shader.wgsl")); +let shader = device.create_shader_module(include_wgsl!("shader.wgsl")); ``` @@ -271,7 +271,7 @@ If you run your program now, it'll take a little longer to start, but it will st label: Some("Render Pass"), color_attachments: &[ // This is what @location(0) in the fragment shader targets - wgpu::RenderPassColorAttachment { + Some(wgpu::RenderPassColorAttachment { view: &view, resolve_target: None, ops: wgpu::Operations { @@ -285,7 +285,7 @@ If you run your program now, it'll take a little longer to start, but it will st ), store: true, } - } + }) ], depth_stencil_attachment: None, });