Skip to content

Commit 198a8ae

Browse files
committed
hal/egl: request ALPHA_SIZE for srgb, move shaders into a folder
1 parent 59e2c5b commit 198a8ae

File tree

8 files changed

+39
-29
lines changed

8 files changed

+39
-29
lines changed

wgpu-hal/src/gles/adapter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ impl super::Adapter {
431431
let vertex = gl
432432
.create_shader(glow::VERTEX_SHADER)
433433
.expect("Could not create shader");
434-
gl.shader_source(vertex, include_str!("./shader_clear.vert"));
434+
gl.shader_source(vertex, include_str!("./shaders/clear.vert"));
435435
gl.compile_shader(vertex);
436436
let fragment = gl
437437
.create_shader(glow::FRAGMENT_SHADER)
438438
.expect("Could not create shader");
439-
gl.shader_source(fragment, include_str!("./shader_clear.frag"));
439+
gl.shader_source(fragment, include_str!("./shaders/clear.frag"));
440440
gl.compile_shader(fragment);
441441
gl.attach_shader(program, vertex);
442442
gl.attach_shader(program, fragment);

wgpu-hal/src/gles/egl.rs

+34-24
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,21 @@ fn test_wayland_display() -> Option<libloading::Library> {
131131
Some(library)
132132
}
133133

134+
#[derive(Clone, Copy, Debug)]
135+
enum SrgbFrameBufferKind {
136+
/// No support for SRGB surface
137+
None,
138+
/// Using EGL 1.5's support for colorspaces
139+
Core,
140+
/// Using EGL_KHR_gl_colorspace
141+
Khr,
142+
}
143+
134144
/// Choose GLES framebuffer configuration.
135145
fn choose_config(
136146
egl: &egl::DynamicInstance<egl::EGL1_4>,
137147
display: egl::Display,
148+
srgb_kind: SrgbFrameBufferKind,
138149
) -> Result<(egl::Config, bool), crate::InstanceError> {
139150
//TODO: EGL_SLOW_CONFIG
140151
let tiers = [
@@ -147,7 +158,7 @@ fn choose_config(
147158
("native-render", &[egl::NATIVE_RENDERABLE, egl::TRUE as _]),
148159
];
149160

150-
let mut attributes = Vec::with_capacity(7);
161+
let mut attributes = Vec::with_capacity(9);
151162
for tier_max in (0..tiers.len()).rev() {
152163
let name = tiers[tier_max].0;
153164
log::info!("\tTrying {}", name);
@@ -156,6 +167,14 @@ fn choose_config(
156167
for &(_, tier_attr) in tiers[..=tier_max].iter() {
157168
attributes.extend_from_slice(tier_attr);
158169
}
170+
// make sure the Alpha is enough to support sRGB
171+
match srgb_kind {
172+
SrgbFrameBufferKind::None => {}
173+
_ => {
174+
attributes.push(egl::ALPHA_SIZE);
175+
attributes.push(8);
176+
}
177+
}
159178
attributes.push(egl::NONE);
160179

161180
match egl.choose_first_config(display, &attributes) {
@@ -227,16 +246,6 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
227246
}
228247
}
229248

230-
#[derive(Debug)]
231-
enum SrgbFrameBufferKind {
232-
/// No support for SRGB surface
233-
None,
234-
/// Using EGL 1.5's support for colorspaces
235-
Core,
236-
/// Using EGL_KHR_gl_colorspace
237-
Khr,
238-
}
239-
240249
/// A wrapper around a [`glow::Context`] and the required EGL context that uses locking to guarantee
241250
/// exclusive access when shared with multiple threads.
242251
pub struct AdapterContext {
@@ -356,22 +365,34 @@ impl Inner {
356365
display_extensions.split_whitespace().collect::<Vec<_>>()
357366
);
358367

368+
let srgb_kind = if version >= (1, 5) {
369+
log::info!("\tEGL surface: +srgb");
370+
SrgbFrameBufferKind::Core
371+
} else if display_extensions.contains("EGL_KHR_gl_colorspace") {
372+
log::info!("\tEGL surface: +srgb khr");
373+
SrgbFrameBufferKind::Khr
374+
} else {
375+
log::warn!("\tEGL surface: -srgb");
376+
SrgbFrameBufferKind::None
377+
};
378+
359379
if log::max_level() >= log::LevelFilter::Trace {
360380
log::trace!("Configurations:");
361381
let config_count = egl.get_config_count(display).unwrap();
362382
let mut configurations = Vec::with_capacity(config_count);
363383
egl.get_configs(display, &mut configurations).unwrap();
364384
for &config in configurations.iter() {
365-
log::trace!("\tCONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}",
385+
log::trace!("\tCONFORMANT=0x{:X}, RENDERABLE=0x{:X}, NATIVE_RENDERABLE=0x{:X}, SURFACE_TYPE=0x{:X}, ALPHA_SIZE={}",
366386
egl.get_config_attrib(display, config, egl::CONFORMANT).unwrap(),
367387
egl.get_config_attrib(display, config, egl::RENDERABLE_TYPE).unwrap(),
368388
egl.get_config_attrib(display, config, egl::NATIVE_RENDERABLE).unwrap(),
369389
egl.get_config_attrib(display, config, egl::SURFACE_TYPE).unwrap(),
390+
egl.get_config_attrib(display, config, egl::ALPHA_SIZE).unwrap(),
370391
);
371392
}
372393
}
373394

374-
let (config, supports_native_window) = choose_config(&egl, display)?;
395+
let (config, supports_native_window) = choose_config(&egl, display, srgb_kind)?;
375396
egl.bind_api(egl::OPENGL_ES_API).unwrap();
376397

377398
let needs_robustness = true;
@@ -439,17 +460,6 @@ impl Inner {
439460
})?
440461
};
441462

442-
let srgb_kind = if version >= (1, 5) {
443-
log::info!("\tEGL surface: +srgb");
444-
SrgbFrameBufferKind::Core
445-
} else if display_extensions.contains("EGL_KHR_gl_colorspace") {
446-
log::info!("\tEGL surface: +srgb khr");
447-
SrgbFrameBufferKind::Khr
448-
} else {
449-
log::warn!("\tEGL surface: -srgb");
450-
SrgbFrameBufferKind::None
451-
};
452-
453463
Ok(Self {
454464
egl,
455465
display,

wgpu-hal/src/gles/queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl super::Queue {
653653
.shared
654654
.workarounds
655655
.contains(super::Workarounds::MESA_I915_SRGB_SHADER_CLEAR)
656-
&& is_srgb
656+
&& is_srgb && false
657657
{
658658
self.perform_shader_clear(gl, draw_buffer, *color);
659659
} else {

wgpu-hal/src/gles/web.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ impl Surface {
153153
let vertex = gl
154154
.create_shader(glow::VERTEX_SHADER)
155155
.expect("Could not create shader");
156-
gl.shader_source(vertex, include_str!("./web/present.vert"));
156+
gl.shader_source(vertex, include_str!("./shaders/present.vert"));
157157
gl.compile_shader(vertex);
158158
let fragment = gl
159159
.create_shader(glow::FRAGMENT_SHADER)
160160
.expect("Could not create shader");
161-
gl.shader_source(fragment, include_str!("./web/present.frag"));
161+
gl.shader_source(fragment, include_str!("./shaders/present.frag"));
162162
gl.compile_shader(fragment);
163163
gl.attach_shader(program, vertex);
164164
gl.attach_shader(program, fragment);

0 commit comments

Comments
 (0)