Skip to content

Commit

Permalink
Address Review Points
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Oct 7, 2021
1 parent eab6a3f commit 6ef89a0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
5 changes: 1 addition & 4 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ pub mod resource;
mod track;
mod validation;

pub use hal::api;
pub use hal::MAX_BIND_GROUPS;
pub use hal::MAX_COLOR_TARGETS;
pub use hal::MAX_VERTEX_BUFFERS;
pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_TARGETS, MAX_VERTEX_BUFFERS};

use atomic::{AtomicUsize, Ordering};

Expand Down
24 changes: 14 additions & 10 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl super::Adapter {

log::info!("Vendor: {}", vendor);
log::info!("Renderer: {}", renderer);
log::info!("Version: {}", &version);
log::info!("Version: {}", version);

log::debug!("Extensions: {:#?}", extensions);

Expand Down Expand Up @@ -254,13 +254,9 @@ impl super::Adapter {
wgt::DownlevelFlags::VERTEX_STORAGE,
ver >= (3, 1)
&& max_storage_block_size != 0
&& (vertex_shader_storage_blocks != 0 || vertex_ssbo_false_zero)
&& !cfg!(target_arch = "wasm32"),
);
downlevel_flags.set(
wgt::DownlevelFlags::FRAGMENT_STORAGE,
ver >= (3, 1) && !cfg!(target_arch = "wasm32"),
&& (vertex_shader_storage_blocks != 0 || vertex_ssbo_false_zero),
);
downlevel_flags.set(wgt::DownlevelFlags::FRAGMENT_STORAGE, ver >= (3, 1));

let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_COMPRESSION_ETC2
Expand Down Expand Up @@ -294,6 +290,10 @@ impl super::Adapter {
super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE,
cfg!(not(target_arch = "wasm32")),
);
private_caps.set(
super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER,
cfg!(not(target_arch = "wasm32")),
);

let max_texture_size = gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) as u32;
let max_texture_3d_size = gl.get_parameter_i32(glow::MAX_3D_TEXTURE_SIZE) as u32;
Expand Down Expand Up @@ -352,8 +352,10 @@ impl super::Adapter {

let mut workarounds = super::Workarounds::empty();

#[cfg(target_arch = "wasm32")]
workarounds.set(super::Workarounds::EMULATE_BUFFER_MAP, true);
workarounds.set(
super::Workarounds::EMULATE_BUFFER_MAP,
cfg!(target_arch = "wasm32"),
);

let r = renderer.to_lowercase();
// Check for Mesa sRGB clear bug. See
Expand All @@ -373,7 +375,9 @@ impl super::Adapter {
let downlevel_defaults = wgt::DownlevelLimits {};

// Drop the GL guard so we can move the context into AdapterShared
#[cfg(not(target_arch = "wasm32"))]
// ( on WASM the gl handle is just a ref so we tell clippy to allow
// dropping the ref )
#[allow(clippy::drop_ref)]
drop(gl);

Some(crate::ExposedAdapter {
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ bitflags::bitflags! {
/// Indicates that buffers used as ELEMENT_ARRAY_BUFFER may be created / initialized / used
/// as other targets, if not present they must not be mixed with other targets.
const INDEX_BUFFER_ROLE_CHANGE = 1 << 4;
/// Indicates that the device supports disabling draw buffers
const CAN_DISABLE_DRAW_BUFFER = 1 << 5;
}
}

Expand Down
19 changes: 14 additions & 5 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,15 @@ impl super::Queue {
.map(|i| glow::COLOR_ATTACHMENT0 + i)
.collect::<ArrayVec<_, { crate::MAX_COLOR_TARGETS }>>();
gl.draw_buffers(&indices);
#[cfg(not(target_arch = "wasm32"))]
for draw_buffer in 0..count as u32 {
gl.disable_draw_buffer(glow::BLEND, draw_buffer);

if self
.shared
.private_caps
.contains(super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER)
{
for draw_buffer in 0..count as u32 {
gl.disable_draw_buffer(glow::BLEND, draw_buffer);
}
}
}
C::ClearColorF {
Expand Down Expand Up @@ -906,8 +912,11 @@ impl super::Queue {
gl.blend_equation_draw_buffer(index, blend.color.equation);
gl.blend_func_draw_buffer(index, blend.color.src, blend.color.dst);
}
} else {
#[cfg(not(target_arch = "wasm32"))]
} else if self
.shared
.private_caps
.contains(super::PrivateCapabilities::CAN_DISABLE_DRAW_BUFFER)
{
gl.disable_draw_buffer(index, glow::BLEND);
}
} else {
Expand Down
15 changes: 8 additions & 7 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,21 +691,22 @@ impl Limits {

/// These default limits are guarenteed to be compatible with GLES3, and D3D11, and WebGL2
pub fn downlevel_webgl2_defaults() -> Self {
Self {
#[cfg(target_arch = "wasm32")]
#[cfg(target_arch = "wasm32")]
let defaults = Self {
max_storage_buffers_per_shader_stage: 0,
#[cfg(target_arch = "wasm32")]
max_storage_textures_per_shader_stage: 0,
#[cfg(target_arch = "wasm32")]
max_dynamic_storage_buffers_per_pipeline_layout: 0,
#[cfg(target_arch = "wasm32")]
max_storage_buffer_binding_size: 0,
#[cfg(target_arch = "wasm32")]
max_vertex_buffer_array_stride: 255,

// Most of the values should be the same as the downlevel defaults
..Self::downlevel_defaults()
}
};

#[cfg(not(target_arch = "wasm32"))]
let defaults = Self::downlevel_defaults();

defaults
}

/// Modify the current limits to use the resolution limits of the other.
Expand Down
8 changes: 4 additions & 4 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
let level: log::Level = parse_url_query_string(&query_string, "RUST_LOG")
.map(|x| x.parse().ok())
.flatten()
.unwrap_or(log::Level::Info);
.unwrap_or(log::Level::Error);
console_log::init_with_level(level).expect("could not initialize logger");
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
// On wasm, append the canvas to the document body
Expand Down Expand Up @@ -419,10 +419,10 @@ pub fn run<E: Example>(title: &str) {
/// Parse the query string as returned by `web_sys::window()?.location().search()?` and get a
/// specific key out of it.
pub fn parse_url_query_string<'a>(query: &'a str, search_key: &str) -> Option<&'a str> {
let query_string = query.strip_prefix("?")?;
let query_string = query.strip_prefix('?')?;

for pair in query_string.split("&") {
let mut pair = pair.split("=");
for pair in query_string.split('&') {
let mut pair = pair.split('=');
let key = pair.next()?;
let value = pair.next()?;

Expand Down

0 comments on commit 6ef89a0

Please sign in to comment.