diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index b8c530ed30e..8c63f6e3d19 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -204,8 +204,10 @@ impl super::Device { naga_stage: naga::ShaderStage, stage: &crate::ProgrammableStage, context: CompilationContext, + primitive_topology: Option, ) -> Result { use naga::back::glsl; + let pipeline_options = glsl::PipelineOptions { shader_stage: naga_stage, entry_point: stage.entry_point.to_string(), @@ -237,12 +239,31 @@ impl super::Device { binding_array: BoundsCheckPolicy::Unchecked, }; + let update_naga_options = primitive_topology == Some(wgt::PrimitiveTopology::PointList) + && naga_stage == naga::ShaderStage::Vertex; + // Update naga options if mesh consist of point list and it is vertex shader + let naga_options = if update_naga_options { + let mut wrt_flags = context.layout.naga_options.writer_flags; + wrt_flags.set(glsl::WriterFlags::FORCE_POINT_SIZE, true); + glsl::Options { + version: context.layout.naga_options.version, + writer_flags: wrt_flags, + binding_map: context.layout.naga_options.binding_map.clone(), + zero_initialize_workgroup_memory: context + .layout + .naga_options + .zero_initialize_workgroup_memory, + } + } else { + context.layout.naga_options.clone() + }; + let mut output = String::new(); let mut writer = glsl::Writer::new( &mut output, &shader.module, &shader.info, - &context.layout.naga_options, + &naga_options, &pipeline_options, policies, ) @@ -274,6 +295,7 @@ impl super::Device { layout: &super::PipelineLayout, #[cfg_attr(target_arch = "wasm32", allow(unused))] label: Option<&str>, multiview: Option, + primitive_topology: Option, ) -> Result, crate::PipelineError> { let mut program_stages = ArrayVec::new(); let mut group_to_binding_to_slot = Vec::with_capacity(layout.group_infos.len()); @@ -312,6 +334,7 @@ impl super::Device { multiview, glsl_version, self.shared.private_caps, + primitive_topology, ) }) .to_owned()?; @@ -328,6 +351,7 @@ impl super::Device { multiview: Option, glsl_version: u16, private_caps: super::PrivateCapabilities, + primitive_topology: Option, ) -> Result, crate::PipelineError> { let program = unsafe { gl.create_program() }.unwrap(); #[cfg(not(target_arch = "wasm32"))] @@ -352,7 +376,7 @@ impl super::Device { multiview, }; - let shader = Self::create_shader(gl, naga_stage, stage, context)?; + let shader = Self::create_shader(gl, naga_stage, stage, context, primitive_topology)?; shaders_to_delete.push(shader); } @@ -1128,8 +1152,16 @@ impl crate::Device for super::Device { if let Some(ref fs) = desc.fragment_stage { shaders.push((naga::ShaderStage::Fragment, fs)); } - let inner = - unsafe { self.create_pipeline(gl, shaders, desc.layout, desc.label, desc.multiview) }?; + let inner = unsafe { + self.create_pipeline( + gl, + shaders, + desc.layout, + desc.label, + desc.multiview, + Some(desc.primitive.topology), + ) + }?; let (vertex_buffers, vertex_attributes) = { let mut buffers = Vec::new(); @@ -1210,7 +1242,8 @@ impl crate::Device for super::Device { let gl = &self.shared.context.lock(); let mut shaders = ArrayVec::new(); shaders.push((naga::ShaderStage::Compute, &desc.stage)); - let inner = unsafe { self.create_pipeline(gl, shaders, desc.layout, desc.label, None) }?; + let inner = + unsafe { self.create_pipeline(gl, shaders, desc.layout, desc.label, None, None) }?; Ok(super::ComputePipeline { inner }) } diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index 6175a4e462c..d64d85476a5 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -64,7 +64,10 @@ async fn run(event_loop: EventLoop<()>, window: Window) { entry_point: "fs_main", targets: &[Some(swapchain_format.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::PointList, + ..wgpu::PrimitiveState::default() + }, depth_stencil: None, multisample: wgpu::MultisampleState::default(), multiview: None, @@ -117,14 +120,14 @@ 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::Clear(wgpu::Color::WHITE), store: true, }, })], depth_stencil_attachment: None, }); rpass.set_pipeline(&render_pipeline); - rpass.draw(0..3, 0..1); + rpass.draw(0..64, 0..1); } queue.submit(Some(encoder.finish())); diff --git a/wgpu/examples/hello-triangle/shader.wgsl b/wgpu/examples/hello-triangle/shader.wgsl index f84ccfe94da..b555f97d051 100644 --- a/wgpu/examples/hello-triangle/shader.wgsl +++ b/wgpu/examples/hello-triangle/shader.wgsl @@ -1,8 +1,72 @@ @vertex fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4 { - let x = f32(i32(in_vertex_index) - 1); - let y = f32(i32(in_vertex_index & 1u) * 2 - 1); - return vec4(x, y, 0.0, 1.0); + var pos = array,64>( + vec2(0.5, 0.7), + vec2(0.51, 0.7), + vec2(0.52, 0.7), + vec2(0.53, 0.7), + vec2(0.54, 0.7), + vec2(0.55, 0.7), + vec2(0.56, 0.7), + vec2(0.57, 0.7), + vec2(0.6, 0.7), + vec2(0.61, 0.7), + vec2(0.62, 0.7), + vec2(0.63, 0.7), + vec2(0.64, 0.7), + vec2(0.65, 0.7), + vec2(0.66, 0.7), + vec2(0.67, 0.7), + vec2(0.7, 0.7), + vec2(0.71, 0.7), + vec2(0.72, 0.7), + vec2(0.73, 0.7), + vec2(0.74, 0.7), + vec2(0.75, 0.7), + vec2(0.76, 0.7), + vec2(0.77, 0.7), + vec2(0.8, 0.7), + vec2(0.81, 0.7), + vec2(0.82, 0.7), + vec2(0.83, 0.7), + vec2(0.84, 0.7), + vec2(0.85, 0.7), + vec2(0.86, 0.7), + vec2(0.87, 0.7), + vec2(0.5, 0.72), + vec2(0.51, 0.72), + vec2(0.52, 0.72), + vec2(0.53, 0.72), + vec2(0.54, 0.72), + vec2(0.55, 0.72), + vec2(0.56, 0.72), + vec2(0.57, 0.72), + vec2(0.6, 0.74), + vec2(0.61, 0.74), + vec2(0.62, 0.74), + vec2(0.63, 0.74), + vec2(0.64, 0.74), + vec2(0.65, 0.74), + vec2(0.66, 0.74), + vec2(0.67, 0.74), + vec2(0.7, 0.76), + vec2(0.71, 0.76), + vec2(0.72, 0.76), + vec2(0.73, 0.76), + vec2(0.74, 0.76), + vec2(0.75, 0.76), + vec2(0.76, 0.76), + vec2(0.77, 0.76), + vec2(0.8, 0.78), + vec2(0.81, 0.78), + vec2(0.82, 0.78), + vec2(0.83, 0.78), + vec2(0.84, 0.78), + vec2(0.85, 0.78), + vec2(0.86, 0.78), + vec2(0.87, 0.78), + ); + return vec4(pos[in_vertex_index], 0.0, 1.0); } @fragment