Skip to content

Commit

Permalink
Merge #3771
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Frizi authored Jun 2, 2021
2 parents 5667a09 + 792717a commit 81cf879
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions src/backend/gl/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{

use hal::{
buffer, device as d,
format::{Format, Swizzle},
format::{ChannelType, Format, Swizzle},
image as i, memory, pass,
pool::CommandPoolCreateFlags,
pso, query, queue,
Expand Down Expand Up @@ -145,6 +145,8 @@ impl Device {
name_binding_map: &mut name_binding_map,
};

let mut shaders_to_delete = arrayvec::ArrayVec::<[_; 3]>::new();

for &(stage, point_maybe) in shaders {
if let Some(point) = point_maybe {
match stage {
Expand All @@ -161,7 +163,7 @@ impl Device {
})?;
unsafe {
gl.attach_shader(program, shader);
gl.delete_shader(shader);
shaders_to_delete.push(shader);
}
}
}
Expand All @@ -188,13 +190,20 @@ impl Device {
.unwrap();
unsafe {
gl.attach_shader(program, shader);
gl.delete_shader(shader);
shaders_to_delete.push(shader);
}
}

unsafe {
gl.link_program(program);
}

for shader in shaders_to_delete {
unsafe {
gl.delete_shader(shader);
}
}

log::info!("\tLinked program {:?}", program);
if let Err(err) = self.share.check() {
panic!("Error linking program: {:?}", err);
Expand Down Expand Up @@ -1496,6 +1505,21 @@ impl d::Device<B> for Device {
h = std::cmp::max(h / 2, 1);
}
}
match channel {
ChannelType::Uint | ChannelType::Sint => {
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MIN_FILTER,
glow::NEAREST as _,
);
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MAG_FILTER,
glow::NEAREST as _,
);
}
_ => {}
};
glow::TEXTURE_2D
}
i::Kind::D2(w, h, l, 1) => {
Expand Down Expand Up @@ -1536,6 +1560,21 @@ impl d::Device<B> for Device {
h = std::cmp::max(h / 2, 1);
}
}
match channel {
ChannelType::Uint | ChannelType::Sint => {
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MIN_FILTER,
glow::NEAREST as _,
);
gl.tex_parameter_i32(
glow::TEXTURE_2D,
glow::TEXTURE_MAG_FILTER,
glow::NEAREST as _,
);
}
_ => {}
};
glow::TEXTURE_2D_ARRAY
}
_ => unimplemented!(),
Expand Down Expand Up @@ -1670,7 +1709,7 @@ impl d::Device<B> for Device {
};
match conv::describe_format(view_format) {
Some(description) => {
let raw_view_format = description.tex_internal;
let raw_view_format = description.tex_external;
if format != raw_view_format {
log::warn!(
"View format {:?} is different from base {:?}",
Expand Down

0 comments on commit 81cf879

Please sign in to comment.