diff --git a/src/circle_shader.wgsl b/src/circle_shader.wgsl index 1c692398..4b03cae3 100644 --- a/src/circle_shader.wgsl +++ b/src/circle_shader.wgsl @@ -8,11 +8,11 @@ struct VertexInput { }; struct InstanceInput { - @location(4) center: vec2, - @location(5) radius: f32, - @location(6) stroke_width: f32, - @location(7) stroke_color: vec4, - @location(8) fill_color: vec4, + @location(5) center: vec2, + @location(6) radius: f32, + @location(7) stroke_width: f32, + @location(8) stroke_color: vec4, + @location(9) fill_color: vec4, }; struct VertexOutput { diff --git a/src/lib.rs b/src/lib.rs index cd40775b..4f0ebfd4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ struct Vertex { impl Vertex { fn desc() -> wgpu::VertexBufferLayout<'static> { wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as wgpu::BufferAddress, + array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { @@ -57,7 +57,7 @@ pub struct SpriteInstance { impl SpriteInstance { fn desc() -> wgpu::VertexBufferLayout<'static> { wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as wgpu::BufferAddress, + array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { @@ -98,40 +98,45 @@ pub struct CircleInstance { impl CircleInstance { fn desc() -> wgpu::VertexBufferLayout<'static> { wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as wgpu::BufferAddress, + array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Instance, attributes: &[ wgpu::VertexAttribute { + // center offset: 0, - shader_location: 4, + shader_location: 5, format: wgpu::VertexFormat::Float32x2, }, wgpu::VertexAttribute { + // radius offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress, - shader_location: 5, - format: wgpu::VertexFormat::Float32, - }, - wgpu::VertexAttribute { - offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::()) - as wgpu::BufferAddress, shader_location: 6, format: wgpu::VertexFormat::Float32, }, wgpu::VertexAttribute { + // stroke_width + offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::()) + as wgpu::BufferAddress, + shader_location: 7, + format: wgpu::VertexFormat::Float32, + }, + wgpu::VertexAttribute { + // stroke_color offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::() + std::mem::size_of::()) as wgpu::BufferAddress, - shader_location: 7, + shader_location: 8, format: wgpu::VertexFormat::Float32x4, }, wgpu::VertexAttribute { + // fill_color offset: (std::mem::size_of::<[f32; 2]>() + std::mem::size_of::() + std::mem::size_of::() + std::mem::size_of::<[f32; 4]>()) as wgpu::BufferAddress, - shader_location: 8, + shader_location: 9, format: wgpu::VertexFormat::Float32x4, }, ], @@ -180,7 +185,7 @@ impl WindowAndDevice { // The instance is a handle to our GPU // Backends::all => Vulkan + Metal + DX12 + Browser WebGPU let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::Backends::all(), + backends: wgpu::Backends::all() & !wgpu::Backends::VULKAN, dx12_shader_compiler: Default::default(), }); @@ -489,7 +494,7 @@ impl State { let circle_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("Sprite Pipeline Layout"), + label: Some("Circle Pipeline Layout"), bind_group_layouts: &[&screen_uniform_bind_group_layout], push_constant_ranges: &[], });