Fix panic in wgpu::color::convert
This commit is contained in:
parent
72b78a9a8d
commit
ffa6614026
1 changed files with 50 additions and 18 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use wgpu::util::DeviceExt;
|
||||||
|
|
||||||
pub fn convert(
|
pub fn convert(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
|
|
@ -15,28 +17,58 @@ pub fn convert(
|
||||||
..wgpu::SamplerDescriptor::default()
|
..wgpu::SamplerDescriptor::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
//sampler in 0
|
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
|
||||||
let sampler_layout =
|
#[repr(C)]
|
||||||
|
struct Ratio {
|
||||||
|
u: f32,
|
||||||
|
v: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
let ratio = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
|
label: Some("iced-wgpu::triangle::msaa ratio"),
|
||||||
|
contents: bytemuck::bytes_of(&Ratio { u: 1.0, v: 1.0 }),
|
||||||
|
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::UNIFORM,
|
||||||
|
});
|
||||||
|
|
||||||
|
let constant_layout =
|
||||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
label: Some("iced_wgpu.offscreen.blit.sampler_layout"),
|
label: Some("iced_wgpu.offscreen.blit.sampler_layout"),
|
||||||
entries: &[wgpu::BindGroupLayoutEntry {
|
entries: &[
|
||||||
binding: 0,
|
wgpu::BindGroupLayoutEntry {
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
binding: 0,
|
||||||
ty: wgpu::BindingType::Sampler(
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
wgpu::SamplerBindingType::NonFiltering,
|
ty: wgpu::BindingType::Sampler(
|
||||||
),
|
wgpu::SamplerBindingType::NonFiltering,
|
||||||
count: None,
|
),
|
||||||
}],
|
count: None,
|
||||||
|
},
|
||||||
|
wgpu::BindGroupLayoutEntry {
|
||||||
|
binding: 1,
|
||||||
|
visibility: wgpu::ShaderStages::VERTEX,
|
||||||
|
ty: wgpu::BindingType::Buffer {
|
||||||
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
|
has_dynamic_offset: false,
|
||||||
|
min_binding_size: None,
|
||||||
|
},
|
||||||
|
count: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
let sampler_bind_group =
|
let constant_bind_group =
|
||||||
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
label: Some("iced_wgpu.offscreen.sampler.bind_group"),
|
label: Some("iced_wgpu.offscreen.sampler.bind_group"),
|
||||||
layout: &sampler_layout,
|
layout: &constant_layout,
|
||||||
entries: &[wgpu::BindGroupEntry {
|
entries: &[
|
||||||
binding: 0,
|
wgpu::BindGroupEntry {
|
||||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
binding: 0,
|
||||||
}],
|
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||||
|
},
|
||||||
|
wgpu::BindGroupEntry {
|
||||||
|
binding: 1,
|
||||||
|
resource: ratio.as_entire_binding(),
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
let texture_layout =
|
let texture_layout =
|
||||||
|
|
@ -59,7 +91,7 @@ pub fn convert(
|
||||||
let pipeline_layout =
|
let pipeline_layout =
|
||||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
label: Some("iced_wgpu.offscreen.blit.pipeline_layout"),
|
label: Some("iced_wgpu.offscreen.blit.pipeline_layout"),
|
||||||
bind_group_layouts: &[&sampler_layout, &texture_layout],
|
bind_group_layouts: &[&constant_layout, &texture_layout],
|
||||||
push_constant_ranges: &[],
|
push_constant_ranges: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -152,7 +184,7 @@ pub fn convert(
|
||||||
});
|
});
|
||||||
|
|
||||||
pass.set_pipeline(&pipeline);
|
pass.set_pipeline(&pipeline);
|
||||||
pass.set_bind_group(0, &sampler_bind_group, &[]);
|
pass.set_bind_group(0, &constant_bind_group, &[]);
|
||||||
pass.set_bind_group(1, &texture_bind_group, &[]);
|
pass.set_bind_group(1, &texture_bind_group, &[]);
|
||||||
pass.draw(0..6, 0..1);
|
pass.draw(0..6, 0..1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue