From 38d5b6b2729f711c5640fee8e75ba99308fecba8 Mon Sep 17 00:00:00 2001 From: Valaphee <32491319+valaphee@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:24:07 +0100 Subject: [PATCH 1/4] Add support for line and point polygone modes for Desktop GL --- CHANGELOG.md | 2 ++ wgpu-hal/src/gles/adapter.rs | 9 +++++---- wgpu-hal/src/gles/conv.rs | 17 +++++------------ wgpu-hal/src/gles/mod.rs | 1 + wgpu-hal/src/gles/queue.rs | 2 ++ 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b402c86dc..db9b8dbdfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ Previously, `DeviceExt::create_texture_with_data` only allowed data to be provid #### OpenGL - `@builtin(instance_index)` now properly reflects the range provided in the draw call instead of always counting from 0. By @cwfitzgerald in [#4722](https://github.com/gfx-rs/wgpu/pull/4722). +- Desktop GL now supports `POLYGON_MODE_LINE` and `POLYGON_MODE_POINT`. By @valaphee in #???? + #### Naga - Naga's WGSL front and back ends now have experimental support for 64-bit floating-point literals: `1.0lf` denotes an `f64` value. There has been experimental support for an `f64` type for a while, but until now there was no syntax for writing literals with that type. As before, Naga module validation rejects `f64` values unless `naga::valid::Capabilities::FLOAT64` is requested. By @jimblandy in [#4747](https://github.com/gfx-rs/wgpu/pull/4747). diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 8c35e452c1..02a447acec 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -219,10 +219,7 @@ impl super::Adapter { log::debug!("Version: {}", version); let full_ver = Self::parse_full_version(&version).ok(); - let es_ver = full_ver - .is_none() - .then_some(()) - .and_then(|_| Self::parse_version(&version).ok()); + let es_ver = full_ver.map_or_else(|| Self::parse_version(&version).ok(), |_| None); let web_gl = cfg!(target_arch = "wasm32"); if let Some(full_ver) = full_ver { @@ -556,6 +553,10 @@ impl super::Adapter { || extensions.contains("OES_texture_float_linear"), ); + if full_ver.is_some() { + features |= wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT; + } + // We *might* be able to emulate bgra8unorm-storage but currently don't attempt to. let mut private_caps = super::PrivateCapabilities::empty(); diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index ebf0c65f52..7b3bf6c8f8 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -285,18 +285,6 @@ pub fn map_primitive_topology(topology: wgt::PrimitiveTopology) -> u32 { } pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::PrimitiveState { - match state.polygon_mode { - wgt::PolygonMode::Fill => {} - wgt::PolygonMode::Line => panic!( - "{:?} is not enabled for this backend", - wgt::Features::POLYGON_MODE_LINE - ), - wgt::PolygonMode::Point => panic!( - "{:?} is not enabled for this backend", - wgt::Features::POLYGON_MODE_POINT - ), - } - super::PrimitiveState { //Note: we are flipping the front face, so that // the Y-flip in the generated GLSL keeps the same visibility. @@ -311,6 +299,11 @@ pub(super) fn map_primitive_state(state: &wgt::PrimitiveState) -> super::Primiti None => 0, }, unclipped_depth: state.unclipped_depth, + polygon_mode: match state.polygon_mode { + wgt::PolygonMode::Fill => glow::FILL, + wgt::PolygonMode::Line => glow::LINE, + wgt::PolygonMode::Point => glow::POINT, + }, } } diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 9525e45d13..ad3bbaf5ae 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -736,6 +736,7 @@ struct PrimitiveState { front_face: u32, cull_face: u32, unclipped_depth: bool, + polygon_mode: u32, } type InvalidatedAttachments = ArrayVec; diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 0ab88c91ca..04d6446ef7 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -1,5 +1,6 @@ use super::{conv::is_layered_target, Command as C, PrivateCapabilities}; use arrayvec::ArrayVec; +use bitflags::Flags; use glow::HasContext; use std::{ mem, slice, @@ -1330,6 +1331,7 @@ impl super::Queue { unsafe { gl.disable(glow::DEPTH_CLAMP) }; } } + unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) }; } C::SetBlendConstant(c) => { unsafe { gl.blend_color(c[0], c[1], c[2], c[3]) }; From d6ac1cb1bada9b5583762d314bc6e25a95a13050 Mon Sep 17 00:00:00 2001 From: Valaphee <32491319+valaphee@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:09:23 +0100 Subject: [PATCH 2/4] Update CHANGELOG.md, clippy --- CHANGELOG.md | 2 +- wgpu-hal/src/gles/queue.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db9b8dbdfb..c43230e2e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,7 @@ Previously, `DeviceExt::create_texture_with_data` only allowed data to be provid #### OpenGL - `@builtin(instance_index)` now properly reflects the range provided in the draw call instead of always counting from 0. By @cwfitzgerald in [#4722](https://github.com/gfx-rs/wgpu/pull/4722). -- Desktop GL now supports `POLYGON_MODE_LINE` and `POLYGON_MODE_POINT`. By @valaphee in #???? +- Desktop GL now supports `POLYGON_MODE_LINE` and `POLYGON_MODE_POINT`. By @valaphee in [#4836](https://github.com/gfx-rs/wgpu/pull/4836) #### Naga diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 04d6446ef7..ee76a6d490 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -1,6 +1,5 @@ use super::{conv::is_layered_target, Command as C, PrivateCapabilities}; use arrayvec::ArrayVec; -use bitflags::Flags; use glow::HasContext; use std::{ mem, slice, From 43e5293809971dbc7e2ce74ca68780d5fe6bff05 Mon Sep 17 00:00:00 2001 From: Valaphee <32491319+valaphee@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:21:31 +0100 Subject: [PATCH 3/4] Fix GLES check --- wgpu-hal/src/gles/adapter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 02a447acec..00db6aba61 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -553,7 +553,7 @@ impl super::Adapter { || extensions.contains("OES_texture_float_linear"), ); - if full_ver.is_some() { + if es_ver.is_none() { features |= wgt::Features::POLYGON_MODE_LINE | wgt::Features::POLYGON_MODE_POINT; } From dfaa6606603971ec4014f6c7d20c061ed05b6861 Mon Sep 17 00:00:00 2001 From: Valaphee <32491319+valaphee@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:43:54 +0100 Subject: [PATCH 4/4] Only call glPolygonMode if feature is enabled --- wgpu-hal/src/gles/queue.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index ee76a6d490..4ee6fb8e47 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -1330,7 +1330,10 @@ impl super::Queue { unsafe { gl.disable(glow::DEPTH_CLAMP) }; } } - unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) }; + // POLYGON_MODE_LINE also implies POLYGON_MODE_POINT + if self.features.contains(wgt::Features::POLYGON_MODE_LINE) { + unsafe { gl.polygon_mode(glow::FRONT_AND_BACK, state.polygon_mode) }; + } } C::SetBlendConstant(c) => { unsafe { gl.blend_color(c[0], c[1], c[2], c[3]) };