1

wgpu::TextureView我在render如下方法中创建一个:

let mut encoder = self.device.create_command_encoder(...);

let texture_view = self
    .surface
    .get_current_frame()?
    .output
    .texture
    .create_view(&wgpu::TextureViewDescriptor::default());

let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
    color_attachments: &[wgpu::RenderPassColorAttachment { 
        view: &texture_view,
        ...
    }],
    ...
})

render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);  
render_pass.draw_indexed(...);


self.queue.submit(std::iter::once(encoder.finish()));

但是当我运行程序时,它会恐慌:

thread 'main' panicked at 'Texture[1] does not exist', /home/doliphin/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.10.0/src/hub.rs:129:32
4

1 回答 1

1

这有一个问题

这可以通过SurfaceTexture在 . 之后强制删除来解决TextureView

let mut encoder = self.device.create_command_encoder(...);

let surface_texture = self.surface.get_current_frame()?.output; // SurfaceTexture

{
    let texture_view = surface_texture
        .texture
        .create_view(&wgpu::TextureViewDescriptor::default()); // TextureView
    
    let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
        color_attachments: &[wgpu::RenderPassColorAttachment { 
            view: &texture_view,
            ...
        }],
        ...
    })
    
    render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);  
    render_pass.draw_indexed(...);
}
// drop(render_pass);
// drop(texture_view);


self.queue.submit(std::iter::once(encoder.finish()));
// drop(surface_texture) 
// drop(encoder)
于 2021-08-22T12:20:55.080 回答