Skip to content

Commit

Permalink
hal/gles: Update glow and fill up the missing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 27, 2021
1 parent c5aa8f8 commit aedea45
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ impl HalApi for hal::api::Dx11 {
}
}
*/

#[cfg(gl)]
impl HalApi for hal::api::Gles {
const VARIANT: Backend = Backend::Gl;
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gpu-descriptor = { version = "0.1", optional = true }
inplace_it = { version ="0.3.3", optional = true }
renderdoc-sys = { version = "0.7.1", optional = true }
# backend: Gles
glow = { git = "https://github.com/grovesNL/glow", rev = "23d16276aaa8095d9ae507b1f70d0c9edfe3527f", optional = true }
glow = { git = "https://github.com/kvark/glow", branch = "missing-stuff", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egl = { package = "khronos-egl", version = "4.1", features = ["dynamic"], optional = true }
Expand Down
6 changes: 4 additions & 2 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ impl super::Adapter {
| wgt::DownlevelFlags::CUBE_ARRAY_TEXTURES
| wgt::DownlevelFlags::COMPARISON_SAMPLERS;
downlevel_flags.set(wgt::DownlevelFlags::COMPUTE_SHADERS, ver >= (3, 1));
//Note: storage textures aren't supported atm, only buffers. See
// https://github.com/grovesNL/glow/issues/174
downlevel_flags.set(
wgt::DownlevelFlags::FRAGMENT_WRITABLE_STORAGE,
ver >= (3, 1),
Expand Down Expand Up @@ -245,6 +243,10 @@ impl super::Adapter {
};

let mut private_caps = super::PrivateCapability::empty();
private_caps.set(
super::PrivateCapability::SHADER_BINDING_LAYOUT,
ver >= (3, 1),
);
private_caps.set(super::PrivateCapability::MEMORY_BARRIERS, ver >= (3, 1));

Some(crate::ExposedAdapter {
Expand Down
44 changes: 31 additions & 13 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ impl super::Device {
use naga::back::glsl;
let options = glsl::Options {
version: self.shared.shading_language_version,
binding_map: Default::default(), //TODO
};
let pipeline_options = glsl::PipelineOptions {
shader_stage: naga_stage,
entry_point: stage.entry_point.to_string(),
};
Expand All @@ -127,11 +130,17 @@ impl super::Device {
.ok_or(crate::PipelineError::EntryPoint(naga_stage))?;

let mut output = String::new();
let mut writer = glsl::Writer::new(&mut output, &shader.module, &shader.info, &options)
.map_err(|e| {
let msg = format!("{}", e);
crate::PipelineError::Linkage(map_naga_stage(naga_stage), msg)
})?;
let mut writer = glsl::Writer::new(
&mut output,
&shader.module,
&shader.info,
&options,
&pipeline_options,
)
.map_err(|e| {
let msg = format!("{}", e);
crate::PipelineError::Linkage(map_naga_stage(naga_stage), msg)
})?;

let reflection_info = writer.write().map_err(|e| {
let msg = format!("{}", e);
Expand Down Expand Up @@ -206,8 +215,13 @@ impl super::Device {
log::warn!("\tLink: {}", msg);
}

//TODO: check for `PrivateCapability::EXPLICIT_LAYOUTS_IN_SHADER`?
if !self
.shared
.private_caps
.contains(super::PrivateCapability::SHADER_BINDING_LAYOUT)
{
// This remapping is only needed if we aren't able to put the binding layout
// in the shader. We can't remap storage buffers this way.
gl.use_program(Some(program));
for (ref name, (register, slot)) in name_binding_map {
log::trace!("Get binding {:?} from program {:?}", name, program);
Expand All @@ -223,7 +237,6 @@ impl super::Device {
name,
index
);
//gl.shader_storage_block_binding(program, index, slot as _);
return Err(crate::DeviceError::Lost.into());
}
super::BindingRegister::Textures | super::BindingRegister::Images => {
Expand Down Expand Up @@ -432,10 +445,15 @@ impl crate::Device<super::Api> for super::Device {
if desc.sample_count > 1 {
let target = glow::TEXTURE_2D;
gl.bind_texture(target, Some(raw));
// https://github.com/grovesNL/glow/issues/169
//gl.tex_storage_2d_multisample(target, desc.sample_count as i32, format_desc.tex_internal, desc.size.width as i32, desc.size.height as i32, true);
log::error!("TODO: support `tex_storage_2d_multisample` (https://github.com/grovesNL/glow/issues/169)");
return Err(crate::DeviceError::Lost);
gl.tex_storage_2d_multisample(
target,
desc.sample_count as i32,
format_desc.internal,
desc.size.width as i32,
desc.size.height as i32,
true,
);
target
} else if desc.size.depth_or_array_layers > 1 {
let target = glow::TEXTURE_2D_ARRAY;
gl.bind_texture(target, Some(raw));
Expand Down Expand Up @@ -579,12 +597,12 @@ impl crate::Device<super::Api> for super::Device {
);

if let Some(border_color) = desc.border_color {
let mut border = match border_color {
let border = match border_color {
wgt::SamplerBorderColor::TransparentBlack => [0.0; 4],
wgt::SamplerBorderColor::OpaqueBlack => [0.0, 0.0, 0.0, 1.0],
wgt::SamplerBorderColor::OpaqueWhite => [1.0; 4],
};
gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &mut border);
gl.sampler_parameter_f32_slice(raw, glow::TEXTURE_BORDER_COLOR, &border);
}

if let Some(ref range) = desc.lod_clamp {
Expand Down
4 changes: 3 additions & 1 deletion wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ bitflags::bitflags! {
/// Flags that affect internal code paths but do not
/// change the exposed feature set.
struct PrivateCapability: u32 {
/// Support explicit layouts in shader.
const SHADER_BINDING_LAYOUT = 0x0001;
/// Support memory barriers.
const MEMORY_BARRIERS = 0x0001;
const MEMORY_BARRIERS = 0x0002;
}
}

Expand Down
75 changes: 46 additions & 29 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl super::Queue {
let gl = &self.shared.context;
gl.use_program(None);
gl.bind_framebuffer(glow::FRAMEBUFFER, None);
gl.polygon_offset(0.0, 0.0);
gl.disable(glow::DEPTH_TEST);
gl.disable(glow::STENCIL_TEST);
gl.disable(glow::SCISSOR_TEST);
Expand Down Expand Up @@ -119,22 +118,21 @@ impl super::Queue {
),
},
C::DrawIndirect {
topology: _,
topology,
indirect_buf,
indirect_offset: _,
indirect_offset,
} => {
gl.bind_buffer(glow::DRAW_INDIRECT_BUFFER, Some(indirect_buf));
//TODO: https://github.com/grovesNL/glow/issues/172
//gl.draw_arrays_indirect(topology, indirect_offset);
gl.draw_arrays_indirect_offset(topology, indirect_offset as i32);
}
C::DrawIndexedIndirect {
topology: _,
index_type: _,
topology,
index_type,
indirect_buf,
indirect_offset: _,
indirect_offset,
} => {
gl.bind_buffer(glow::DRAW_INDIRECT_BUFFER, Some(indirect_buf));
//TODO: https://github.com/grovesNL/glow/issues/172
gl.draw_elements_indirect_offset(topology, index_type, indirect_offset as i32);
}
C::Dispatch(group_counts) => {
gl.dispatch_compute(group_counts[0], group_counts[1], group_counts[2]);
Expand Down Expand Up @@ -194,12 +192,29 @@ impl super::Queue {
);
}
gl.bind_texture(dst_target, Some(dst));
//TODO: https://github.com/grovesNL/glow/issues/173
#[allow(clippy::if_same_then_else)]
if is_3d_target(dst_target) {
//gl.copy_tex_sub_image_3d(dst_target, copy.dst_base.mip_level, copy.dst_base.origin.x, copy.dst_base.origin.y, copy.dst_base.origin.z + layer, copy.src_base.origin.x, copy.src_base.origin.y, copy.size.width, copy.size.height);
gl.copy_tex_sub_image_3d(
dst_target,
copy.dst_base.mip_level as i32,
copy.dst_base.origin.x as i32,
copy.dst_base.origin.y as i32,
copy.dst_base.origin.z as i32 + layer,
copy.src_base.origin.x as i32,
copy.src_base.origin.y as i32,
copy.size.width as i32,
copy.size.height as i32,
);
} else {
//gl.copy_tex_sub_image_2d(dst_target, copy.dst_base.mip_level, copy.dst_base.origin.x, copy.dst_base.origin.y, copy.src_base.origin.x, copy.src_base.origin.y, copy.size.width, copy.size.height);
gl.copy_tex_sub_image_2d(
dst_target,
copy.dst_base.mip_level as i32,
copy.dst_base.origin.x as i32,
copy.dst_base.origin.y as i32,
copy.src_base.origin.x as i32,
copy.src_base.origin.y as i32,
copy.size.width as i32,
copy.size.height as i32,
);
}
}
}
Expand Down Expand Up @@ -404,20 +419,20 @@ impl super::Queue {
gl.disable_draw_buffer(glow::BLEND, draw_buffer);
}
}
C::ClearColorF(draw_buffer, mut color) => {
gl.clear_buffer_f32_slice(glow::COLOR, draw_buffer, &mut color);
C::ClearColorF(draw_buffer, ref color) => {
gl.clear_buffer_f32_slice(glow::COLOR, draw_buffer, color);
}
C::ClearColorU(draw_buffer, mut color) => {
gl.clear_buffer_u32_slice(glow::COLOR, draw_buffer, &mut color);
C::ClearColorU(draw_buffer, ref color) => {
gl.clear_buffer_u32_slice(glow::COLOR, draw_buffer, color);
}
C::ClearColorI(draw_buffer, mut color) => {
gl.clear_buffer_i32_slice(glow::COLOR, draw_buffer, &mut color);
C::ClearColorI(draw_buffer, ref color) => {
gl.clear_buffer_i32_slice(glow::COLOR, draw_buffer, color);
}
C::ClearDepth(depth) => {
gl.clear_buffer_f32_slice(glow::DEPTH, 0, &mut [depth]);
gl.clear_buffer_f32_slice(glow::DEPTH, 0, &[depth]);
}
C::ClearStencil(value) => {
gl.clear_buffer_i32_slice(glow::STENCIL, 0, &mut [value as i32]);
gl.clear_buffer_i32_slice(glow::STENCIL, 0, &[value as i32]);
}
C::BufferBarrier(raw, usage) => {
let mut flags = 0;
Expand Down Expand Up @@ -658,14 +673,16 @@ impl super::Queue {
gl.active_texture(glow::TEXTURE0 + slot);
gl.bind_texture(target, Some(texture));
}
C::BindImage {
slot: _,
binding: _,
} => {
//TODO: https://github.com/grovesNL/glow/issues/174
//gl.bind_image_texture(slot, Some(binding.raw), binding.mip_level as i32,
// binding.array_layer.is_none(), binding.array_layer.unwrap_or_default(),
// binding.access, binding.format);
C::BindImage { slot, ref binding } => {
gl.bind_image_texture(
slot,
binding.raw,
binding.mip_level as i32,
binding.array_layer.is_none(),
binding.array_layer.unwrap_or_default() as i32,
binding.access,
binding.format,
);
}
C::InsertDebugMarker(ref range) => {
let marker = extract_marker(data_bytes, range);
Expand Down

0 comments on commit aedea45

Please sign in to comment.