Skip to content

Commit

Permalink
Merge #1510
Browse files Browse the repository at this point in the history
1510: OpenGL ES3 backend r=cwfitzgerald,Gordon-F,kvark a=kvark

**Connections**
Follow-up to #1471

**Description**
The new wgpu-hal backend for GLES3 ~~and WebGL2~~
Edit: WebGL2 is not included here

**Testing**
Examples!

Current status:
  - all examples work, minus the next issue
  - "mipmap" is buggy because we don't have a good way to do mipmap/layer selection
  - automated testing?


Co-authored-by: Dzmitry Malyshau <[email protected]>
Co-authored-by: Dzmitry Malyshau <[email protected]>
Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
4 people authored Jun 30, 2021
2 parents 81214b2 + 6f13eeb commit c9ab6d0
Show file tree
Hide file tree
Showing 41 changed files with 5,524 additions and 208 deletions.
34 changes: 33 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ default-members = ["wgpu", "player", "wgpu-hal", "wgpu-info"]
[patch."https://github.com/zakarumych/gpu-alloc"]
#gpu-alloc = { path = "../gpu-alloc/gpu-alloc" }

[patch."https://github.com/grovesNL/glow"]
#glow = { path = "../glow" }

[patch.crates-io]
#web-sys = { path = "../wasm-bindgen/crates/web-sys" }
#js-sys = { path = "../wasm-bindgen/crates/js-sys" }
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ thiserror = "1"

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "57b325602015ce6445749a4d8ee5d491edc818d7"
rev = "68a2efd3c5db62c2c011ccbad84f58be5e539fe3"
features = ["wgsl-in"]

[dependencies.wgt]
Expand All @@ -54,7 +54,7 @@ hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["metal"] }
#Note: could also enable "vulkan" for Vulkan Portability

[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan"] }
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan", "gles"] }

[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan"] }
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
metal: { all(not(wasm), apple) },
dx12: { all(false, not(wasm), windows) },
dx11: { all(false, not(wasm), windows) },
gl: { all(false, any(wasm, unix_wo_apple)) },
gl: { all(not(wasm), unix_wo_apple) },
}
}
4 changes: 3 additions & 1 deletion wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
device::{DeviceError, MissingFeatures, SHADER_STAGE_COUNT},
device::{DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT},
hub::Resource,
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId, Valid},
memory_init_tracker::MemoryInitTrackerAction,
Expand Down Expand Up @@ -28,6 +28,8 @@ pub enum BindGroupLayoutEntryError {
ArrayUnsupported,
#[error(transparent)]
MissingFeatures(#[from] MissingFeatures),
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
}

#[derive(Clone, Debug, Error)]
Expand Down
15 changes: 14 additions & 1 deletion wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ use crate::{
StateChange,
},
conv,
device::{AttachmentData, Device, DeviceError, RenderPassContext, SHADER_STAGE_COUNT},
device::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
SHADER_STAGE_COUNT,
},
hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Resource, Storage, Token},
id,
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
Expand Down Expand Up @@ -403,6 +406,10 @@ impl RenderBundleEncoder {
indirect: true,
pipeline: state.pipeline.last_state,
};
device
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
.map_pass_err(scope)?;

let buffer = state
.trackers
.buffers
Expand Down Expand Up @@ -439,6 +446,10 @@ impl RenderBundleEncoder {
indirect: true,
pipeline: state.pipeline.last_state,
};
device
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
.map_pass_err(scope)?;

let buffer = state
.trackers
.buffers
Expand Down Expand Up @@ -1104,6 +1115,8 @@ pub(super) enum RenderBundleErrorInner {
ResourceUsageConflict(#[from] UsageConflict),
#[error(transparent)]
Draw(#[from] DrawError),
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
}

impl<T> From<T> for RenderBundleErrorInner
Expand Down
29 changes: 12 additions & 17 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use crate::{
CommandEncoderError, CommandEncoderStatus, MapPassErr, PassErrorScope, QueryUseError,
StateChange,
},
device::MissingDownlevelFlags,
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token},
id,
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
resource::{Buffer, Texture},
track::{StatefulTrackerSubset, TrackerSet, UsageConflict, UseExtendError},
validation::{check_buffer_usage, MissingBufferUsageError},
Label, DOWNLEVEL_ERROR_WARNING_MESSAGE,
Label,
};

use hal::CommandEncoder as _;
Expand Down Expand Up @@ -149,11 +150,6 @@ pub enum ComputePassErrorInner {
MissingBufferUsage(#[from] MissingBufferUsageError),
#[error("cannot pop debug group, because number of pushed debug groups is zero")]
InvalidPopDebugGroup,
#[error(
"Compute shaders are not supported by the underlying platform. {}",
DOWNLEVEL_ERROR_WARNING_MESSAGE
)]
ComputeShadersUnsupported,
#[error(transparent)]
Dispatch(#[from] DispatchError),
#[error(transparent)]
Expand All @@ -162,6 +158,8 @@ pub enum ComputePassErrorInner {
PushConstants(#[from] PushConstantUploadError),
#[error(transparent)]
QueryUse(#[from] QueryUseError),
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
}

/// Error encountered when performing a compute pass.
Expand Down Expand Up @@ -262,31 +260,24 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let hub = A::hub(self);
let mut token = Token::root();

let (device_guard, mut token) = hub.devices.read(&mut token);

let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token);
let cmd_buf =
CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id).map_pass_err(scope)?;
// will be reset to true if recording is done without errors
cmd_buf.status = CommandEncoderStatus::Error;
let raw = cmd_buf.encoder.open();

let device = &device_guard[cmd_buf.device_id.value];

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
list.push(crate::device::trace::Command::RunComputePass {
base: BasePass::from_ref(base),
});
}

if !cmd_buf
.downlevel
.flags
.contains(wgt::DownlevelFlags::COMPUTE_SHADERS)
{
return Err(ComputePassError {
scope: PassErrorScope::Pass(encoder_id),
inner: ComputePassErrorInner::ComputeShadersUnsupported,
});
}

let (_, mut token) = hub.render_bundles.read(&mut token);
let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token);
let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token);
Expand Down Expand Up @@ -516,6 +507,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

state.is_ready().map_pass_err(scope)?;

device
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
.map_pass_err(scope)?;

let indirect_buffer = state
.trackers
.buffers
Expand Down
4 changes: 1 addition & 3 deletions wgpu-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pub struct CommandBuffer<A: hal::Api> {
pub(crate) used_swap_chains: SmallVec<[Stored<id::SwapChainId>; 1]>,
pub(crate) buffer_memory_init_actions: Vec<MemoryInitTrackerAction<id::BufferId>>,
limits: wgt::Limits,
downlevel: wgt::DownlevelCapabilities,
support_fill_buffer_texture: bool,
#[cfg(feature = "trace")]
pub(crate) commands: Option<Vec<crate::device::trace::Command>>,
Expand All @@ -88,7 +87,7 @@ impl<A: HalApi> CommandBuffer<A> {
encoder: A::CommandEncoder,
device_id: Stored<id::DeviceId>,
limits: wgt::Limits,
downlevel: wgt::DownlevelCapabilities,
_downlevel: wgt::DownlevelCapabilities,
features: wgt::Features,
#[cfg(feature = "trace")] enable_tracing: bool,
label: &Label,
Expand All @@ -106,7 +105,6 @@ impl<A: HalApi> CommandBuffer<A> {
used_swap_chains: Default::default(),
buffer_memory_init_actions: Default::default(),
limits,
downlevel,
support_fill_buffer_texture: features.contains(wgt::Features::CLEAR_COMMANDS),
#[cfg(feature = "trace")]
commands: if enable_tracing {
Expand Down
47 changes: 23 additions & 24 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{
PassErrorScope, QueryResetMap, QueryUseError, RenderCommand, RenderCommandError,
StateChange,
},
device::{AttachmentData, RenderPassCompatibilityError, RenderPassContext},
device::{
AttachmentData, MissingDownlevelFlags, MissingFeatures, RenderPassCompatibilityError,
RenderPassContext,
},
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token},
id,
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
Expand Down Expand Up @@ -419,8 +422,10 @@ pub enum RenderPassErrorInner {
SampleCountMismatch { actual: u32, expected: u32 },
#[error("setting `values_offset` to be `None` is only for internal use in render bundles")]
InvalidValuesOffset,
#[error("required device features not enabled: {0:?}")]
MissingDeviceFeatures(wgt::Features),
#[error(transparent)]
MissingFeatures(#[from] MissingFeatures),
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
#[error("indirect draw uses bytes {offset}..{end_offset} {} which overruns indirect buffer of size {buffer_size}", count.map_or_else(String::new, |v| format!("(using count {})", v)))]
IndirectBufferOverrun {
count: Option<NonZeroU32>,
Expand Down Expand Up @@ -483,17 +488,6 @@ where
}
}

fn check_device_features(
actual: wgt::Features,
expected: wgt::Features,
) -> Result<(), RenderPassErrorInner> {
if !actual.contains(expected) {
Err(RenderPassErrorInner::MissingDeviceFeatures(expected))
} else {
Ok(())
}
}

struct RenderAttachment<'a> {
texture_id: &'a Stored<id::TextureId>,
selector: &'a TextureSelector,
Expand Down Expand Up @@ -745,6 +739,8 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {

let hal_desc = hal::RenderPassDescriptor {
label,
extent,
sample_count,
color_attachments: &colors,
depth_stencil_attachment: depth_stencil,
};
Expand Down Expand Up @@ -1175,6 +1171,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
.inputs
.extend(iter::repeat(VertexBufferState::EMPTY).take(empty_slots));
let vertex_state = &mut state.vertex.inputs[slot as usize];
//TODO: where are we checking that the offset is in bound?
vertex_state.total_size = match size {
Some(s) => s.get(),
None => buffer.size - offset,
Expand Down Expand Up @@ -1400,12 +1397,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};

if count.is_some() {
check_device_features(
device.features,
wgt::Features::MULTI_DRAW_INDIRECT,
)
.map_pass_err(scope)?;
device
.require_features(wgt::Features::MULTI_DRAW_INDIRECT)
.map_pass_err(scope)?;
}
device
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
.map_pass_err(scope)?;

let indirect_buffer = info
.trackers
Expand Down Expand Up @@ -1474,11 +1472,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
true => mem::size_of::<wgt::DrawIndexedIndirectArgs>(),
} as u64;

check_device_features(
device.features,
wgt::Features::MULTI_DRAW_INDIRECT_COUNT,
)
.map_pass_err(scope)?;
device
.require_features(wgt::Features::MULTI_DRAW_INDIRECT_COUNT)
.map_pass_err(scope)?;
device
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
.map_pass_err(scope)?;

let indirect_buffer = info
.trackers
Expand Down
Loading

0 comments on commit c9ab6d0

Please sign in to comment.