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

Surface write #2385

Merged
merged 1 commit into from
Jan 12, 2022
Merged

Surface write #2385

merged 1 commit into from
Jan 12, 2022

Conversation

kvark
Copy link
Member

@kvark kvark commented Jan 12, 2022

Connections
Fixes #2383

Description
We didn't handle write_texture properly for surface stuff.

Testing
Used the following modification in hello-triangle:

diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs
index 885ca201..26b6dc80 100644
--- a/wgpu/examples/hello-triangle/main.rs
+++ b/wgpu/examples/hello-triangle/main.rs
@@ -68,7 +68,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
     });
 
     let mut config = wgpu::SurfaceConfiguration {
-        usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
+        usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST,
         format: swapchain_format,
         width: size.width,
         height: size.height,
@@ -98,6 +98,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
                 let frame = surface
                     .get_current_texture()
                     .expect("Failed to acquire next swap chain texture");
+
                 let view = frame
                     .texture
                     .create_view(&wgpu::TextureViewDescriptor::default());
@@ -110,7 +111,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
                             view: &view,
                             resolve_target: None,
                             ops: wgpu::Operations {
-                                load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
+                                load: wgpu::LoadOp::Load,
                                 store: true,
                             },
                         }],
@@ -120,6 +121,22 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
                     rpass.draw(0..3, 0..1);
                 }
 
+                let data = vec![0xFF; (1024 * config.height * 4) as usize];
+                queue.write_texture(
+                    frame.texture.as_image_copy(),
+                    &data,
+                    wgpu::ImageDataLayout {
+                        offset: 0,
+                        bytes_per_row: std::num::NonZeroU32::new(config.width * 4),
+                        rows_per_image: None,
+                    },
+                    wgpu::Extent3d {
+                        width: config.width,
+                        height: config.height,
+                        depth_or_array_layers: 1,
+                    },
+                );
+
                 queue.submit(Some(encoder.finish()));
                 frame.present();
             }

@kvark kvark requested a review from cwfitzgerald January 12, 2022 18:11
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

LGTM

@kvark
Copy link
Member Author

kvark commented Jan 12, 2022

Thanks for the quick review!
I think this is a bit of a risky change, we should keep an eye for issues.

@kvark kvark merged commit 16edd91 into gfx-rs:master Jan 12, 2022
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.

2 participants