Skip to content

Commit 2e9ee0a

Browse files
[wgpu-hal.gles] Error log for failed GLES heuristics (#5266)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
1 parent a016a3a commit 2e9ee0a

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Bottom level categories:
103103
- `wgpu::Id` now implements `PartialOrd`/`Ord` allowing it to be put in `BTreeMap`s. By @cwfitzgerald and @9291Sam in [#5176](https://github.com/gfx-rs/wgpu/pull/5176)
104104
- `wgpu::CommandEncoder::write_timestamp` requires now the new `wgpu::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS` feature which is available on all native backends but not on WebGPU (due to a spec change `write_timestamp` is no longer supported on WebGPU). By @wumpf in [#5188](https://github.com/gfx-rs/wgpu/pull/5188)
105105

106+
#### GLES
107+
108+
- Log an error when GLES texture format heuristics fail. By @PolyMeilex in [#5266](https://github.com/gfx-rs/wgpu/issues/5266)
109+
106110
### Bug Fixes
107111

108112
#### General

wgpu-hal/src/gles/device.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,13 +1194,16 @@ impl crate::Device<super::Api> for super::Device {
11941194
let sampler = desc.samplers[entry.resource_index as usize];
11951195
super::RawBinding::Sampler(sampler.raw)
11961196
}
1197-
wgt::BindingType::Texture { .. } => {
1197+
wgt::BindingType::Texture { view_dimension, .. } => {
11981198
let view = desc.textures[entry.resource_index as usize].view;
11991199
if view.array_layers.start != 0 {
12001200
log::error!("Unable to create a sampled texture binding for non-zero array layer.\n{}",
12011201
"This is an implementation problem of wgpu-hal/gles backend.")
12021202
}
12031203
let (raw, target) = view.inner.as_native();
1204+
1205+
super::Texture::log_failing_target_heuristics(view_dimension, target);
1206+
12041207
super::RawBinding::Texture {
12051208
raw,
12061209
target,

wgpu-hal/src/gles/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ impl Texture {
366366
/// Returns the `target`, whether the image is 3d and whether the image is a cubemap.
367367
fn get_info_from_desc(desc: &TextureDescriptor) -> u32 {
368368
match desc.dimension {
369+
// WebGL (1 and 2) as well as some GLES versions do not have 1D textures, so we are
370+
// doing `TEXTURE_2D` instead
369371
wgt::TextureDimension::D1 => glow::TEXTURE_2D,
370372
wgt::TextureDimension::D2 => {
371373
// HACK: detect a cube map; forces cube compatible textures to be cube textures
@@ -379,6 +381,43 @@ impl Texture {
379381
wgt::TextureDimension::D3 => glow::TEXTURE_3D,
380382
}
381383
}
384+
385+
/// More information can be found in issues #1614 and #1574
386+
fn log_failing_target_heuristics(view_dimension: wgt::TextureViewDimension, target: u32) {
387+
let expected_target = match view_dimension {
388+
wgt::TextureViewDimension::D1 => glow::TEXTURE_2D,
389+
wgt::TextureViewDimension::D2 => glow::TEXTURE_2D,
390+
wgt::TextureViewDimension::D2Array => glow::TEXTURE_2D_ARRAY,
391+
wgt::TextureViewDimension::Cube => glow::TEXTURE_CUBE_MAP,
392+
wgt::TextureViewDimension::CubeArray => glow::TEXTURE_CUBE_MAP_ARRAY,
393+
wgt::TextureViewDimension::D3 => glow::TEXTURE_3D,
394+
};
395+
396+
if expected_target == target {
397+
return;
398+
}
399+
400+
let buffer;
401+
let got = match target {
402+
glow::TEXTURE_2D => "D2",
403+
glow::TEXTURE_2D_ARRAY => "D2Array",
404+
glow::TEXTURE_CUBE_MAP => "Cube",
405+
glow::TEXTURE_CUBE_MAP_ARRAY => "CubeArray",
406+
glow::TEXTURE_3D => "D3",
407+
target => {
408+
buffer = target.to_string();
409+
&buffer
410+
}
411+
};
412+
413+
log::error!(
414+
"wgpu-hal heuristics assumed that the view dimension will be equal to `{got}` rather than `{view_dimension:?}`.\n{}\n{}\n{}\n{}",
415+
"`D2` textures with `depth_or_array_layers == 1` are assumed to have view dimension `D2`",
416+
"`D2` textures with `depth_or_array_layers > 1` are assumed to have view dimension `D2Array`",
417+
"`D2` textures with `depth_or_array_layers == 6` are assumed to have view dimension `Cube`",
418+
"`D2` textures with `depth_or_array_layers > 6 && depth_or_array_layers % 6 == 0` are assumed to have view dimension `CubeArray`",
419+
);
420+
}
382421
}
383422

384423
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)