Skip to content

Commit 81cf879

Browse files
bors[bot]Frizi
andauthored
Merge #3771
3771: Fix WebGL backend for wgpu-rs cube example r=kvark a=Frizi Fixes "cube" example in wgpu-rs for webgl backend on Windows. Will also fix MacOS once gfx-rs/naga#936 gets included. `delete_shader` is delayed after linking the program. Not doing that seems to be randomly triggering linking issues. I'm not exactly sure under what circumstances it tends to happen, but the fix made it reliable. The most important fix is about texture filtering for intager textures. ANGLE decides to ignore integer textures if their filtering is kept as default. Instead, it silently substitutes an empty 1px placeholder texture into the shader binding. Forcing the integer textures to NEAREST filtering makes that problem go away. Co-authored-by: Frizi <[email protected]>
2 parents 5667a09 + 792717a commit 81cf879

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/backend/gl/src/device.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99

1010
use hal::{
1111
buffer, device as d,
12-
format::{Format, Swizzle},
12+
format::{ChannelType, Format, Swizzle},
1313
image as i, memory, pass,
1414
pool::CommandPoolCreateFlags,
1515
pso, query, queue,
@@ -145,6 +145,8 @@ impl Device {
145145
name_binding_map: &mut name_binding_map,
146146
};
147147

148+
let mut shaders_to_delete = arrayvec::ArrayVec::<[_; 3]>::new();
149+
148150
for &(stage, point_maybe) in shaders {
149151
if let Some(point) = point_maybe {
150152
match stage {
@@ -161,7 +163,7 @@ impl Device {
161163
})?;
162164
unsafe {
163165
gl.attach_shader(program, shader);
164-
gl.delete_shader(shader);
166+
shaders_to_delete.push(shader);
165167
}
166168
}
167169
}
@@ -188,13 +190,20 @@ impl Device {
188190
.unwrap();
189191
unsafe {
190192
gl.attach_shader(program, shader);
191-
gl.delete_shader(shader);
193+
shaders_to_delete.push(shader);
192194
}
193195
}
194196

195197
unsafe {
196198
gl.link_program(program);
197199
}
200+
201+
for shader in shaders_to_delete {
202+
unsafe {
203+
gl.delete_shader(shader);
204+
}
205+
}
206+
198207
log::info!("\tLinked program {:?}", program);
199208
if let Err(err) = self.share.check() {
200209
panic!("Error linking program: {:?}", err);
@@ -1496,6 +1505,21 @@ impl d::Device<B> for Device {
14961505
h = std::cmp::max(h / 2, 1);
14971506
}
14981507
}
1508+
match channel {
1509+
ChannelType::Uint | ChannelType::Sint => {
1510+
gl.tex_parameter_i32(
1511+
glow::TEXTURE_2D,
1512+
glow::TEXTURE_MIN_FILTER,
1513+
glow::NEAREST as _,
1514+
);
1515+
gl.tex_parameter_i32(
1516+
glow::TEXTURE_2D,
1517+
glow::TEXTURE_MAG_FILTER,
1518+
glow::NEAREST as _,
1519+
);
1520+
}
1521+
_ => {}
1522+
};
14991523
glow::TEXTURE_2D
15001524
}
15011525
i::Kind::D2(w, h, l, 1) => {
@@ -1536,6 +1560,21 @@ impl d::Device<B> for Device {
15361560
h = std::cmp::max(h / 2, 1);
15371561
}
15381562
}
1563+
match channel {
1564+
ChannelType::Uint | ChannelType::Sint => {
1565+
gl.tex_parameter_i32(
1566+
glow::TEXTURE_2D,
1567+
glow::TEXTURE_MIN_FILTER,
1568+
glow::NEAREST as _,
1569+
);
1570+
gl.tex_parameter_i32(
1571+
glow::TEXTURE_2D,
1572+
glow::TEXTURE_MAG_FILTER,
1573+
glow::NEAREST as _,
1574+
);
1575+
}
1576+
_ => {}
1577+
};
15391578
glow::TEXTURE_2D_ARRAY
15401579
}
15411580
_ => unimplemented!(),
@@ -1670,7 +1709,7 @@ impl d::Device<B> for Device {
16701709
};
16711710
match conv::describe_format(view_format) {
16721711
Some(description) => {
1673-
let raw_view_format = description.tex_internal;
1712+
let raw_view_format = description.tex_external;
16741713
if format != raw_view_format {
16751714
log::warn!(
16761715
"View format {:?} is different from base {:?}",

0 commit comments

Comments
 (0)