From 4272090d36caf2937c170d3b28d1be1acc94a440 Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 18 Feb 2024 06:12:15 +0100 Subject: [wgpu.image] Workaround WGPU OpenGL heuristics --- wgpu/src/image/atlas.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'wgpu/src/image') diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 789e35b4..0919f6df 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -24,10 +24,14 @@ pub struct Atlas { impl Atlas { pub fn new(device: &wgpu::Device) -> Self { + // We start with 2 layers, to help wgpu figure out that this texture is `GL_TEXTURE_2D_ARRAY` rather + // than `GL_TEXTURE_2D` + // https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371 + let layers = vec![Layer::Empty, Layer::Empty]; let extent = wgpu::Extent3d { width: SIZE, height: SIZE, - depth_or_array_layers: 1, + depth_or_array_layers: layers.len() as u32, }; let texture = device.create_texture(&wgpu::TextureDescriptor { @@ -55,7 +59,7 @@ impl Atlas { Atlas { texture, texture_view, - layers: vec![Layer::Empty], + layers, } } -- cgit From 04df889cacfc4dfe93c2640b75f65eaafa060dba Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 19 Feb 2024 08:18:51 +0100 Subject: Use two layers for `image::atlas` only on `Gl` backend --- wgpu/src/image/atlas.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'wgpu/src/image') diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 0919f6df..ea36e06d 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -23,11 +23,15 @@ pub struct Atlas { } impl Atlas { - pub fn new(device: &wgpu::Device) -> Self { - // We start with 2 layers, to help wgpu figure out that this texture is `GL_TEXTURE_2D_ARRAY` rather - // than `GL_TEXTURE_2D` - // https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371 - let layers = vec![Layer::Empty, Layer::Empty]; + pub fn new(device: &wgpu::Device, backend: wgpu::Backend) -> Self { + let layers = match backend { + // On the GL backend we start with 2 layers, to help wgpu figure + // out that this texture is `GL_TEXTURE_2D_ARRAY` rather than `GL_TEXTURE_2D` + // https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371 + wgpu::Backend::Gl => vec![Layer::Empty, Layer::Empty], + _ => vec![Layer::Empty], + }; + let extent = wgpu::Extent3d { width: SIZE, height: SIZE, -- cgit