Skip to content

Commit c9ab6d0

Browse files
bors[bot]kvark
andauthored
Merge #1510
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]>
2 parents 81214b2 + 6f13eeb commit c9ab6d0

File tree

41 files changed

+5524
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5524
-208
lines changed

Cargo.lock

Lines changed: 33 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ default-members = ["wgpu", "player", "wgpu-hal", "wgpu-info"]
2020
[patch."https://github.com/zakarumych/gpu-alloc"]
2121
#gpu-alloc = { path = "../gpu-alloc/gpu-alloc" }
2222

23+
[patch."https://github.com/grovesNL/glow"]
24+
#glow = { path = "../glow" }
25+
2326
[patch.crates-io]
2427
#web-sys = { path = "../wasm-bindgen/crates/web-sys" }
2528
#js-sys = { path = "../wasm-bindgen/crates/js-sys" }

wgpu-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ thiserror = "1"
3636

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

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

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

5959
[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
6060
hal = { path = "../wgpu-hal", package = "wgpu-hal", features = ["vulkan"] }

wgpu-core/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn main() {
1111
metal: { all(not(wasm), apple) },
1212
dx12: { all(false, not(wasm), windows) },
1313
dx11: { all(false, not(wasm), windows) },
14-
gl: { all(false, any(wasm, unix_wo_apple)) },
14+
gl: { all(not(wasm), unix_wo_apple) },
1515
}
1616
}

wgpu-core/src/binding_model.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
device::{DeviceError, MissingFeatures, SHADER_STAGE_COUNT},
2+
device::{DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT},
33
hub::Resource,
44
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId, Valid},
55
memory_init_tracker::MemoryInitTrackerAction,
@@ -28,6 +28,8 @@ pub enum BindGroupLayoutEntryError {
2828
ArrayUnsupported,
2929
#[error(transparent)]
3030
MissingFeatures(#[from] MissingFeatures),
31+
#[error(transparent)]
32+
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
3133
}
3234

3335
#[derive(Clone, Debug, Error)]

wgpu-core/src/command/bundle.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ use crate::{
3939
StateChange,
4040
},
4141
conv,
42-
device::{AttachmentData, Device, DeviceError, RenderPassContext, SHADER_STAGE_COUNT},
42+
device::{
43+
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
44+
SHADER_STAGE_COUNT,
45+
},
4346
hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Resource, Storage, Token},
4447
id,
4548
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
@@ -403,6 +406,10 @@ impl RenderBundleEncoder {
403406
indirect: true,
404407
pipeline: state.pipeline.last_state,
405408
};
409+
device
410+
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
411+
.map_pass_err(scope)?;
412+
406413
let buffer = state
407414
.trackers
408415
.buffers
@@ -439,6 +446,10 @@ impl RenderBundleEncoder {
439446
indirect: true,
440447
pipeline: state.pipeline.last_state,
441448
};
449+
device
450+
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
451+
.map_pass_err(scope)?;
452+
442453
let buffer = state
443454
.trackers
444455
.buffers
@@ -1104,6 +1115,8 @@ pub(super) enum RenderBundleErrorInner {
11041115
ResourceUsageConflict(#[from] UsageConflict),
11051116
#[error(transparent)]
11061117
Draw(#[from] DrawError),
1118+
#[error(transparent)]
1119+
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
11071120
}
11081121

11091122
impl<T> From<T> for RenderBundleErrorInner

wgpu-core/src/command/compute.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use crate::{
55
CommandEncoderError, CommandEncoderStatus, MapPassErr, PassErrorScope, QueryUseError,
66
StateChange,
77
},
8+
device::MissingDownlevelFlags,
89
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token},
910
id,
1011
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
1112
resource::{Buffer, Texture},
1213
track::{StatefulTrackerSubset, TrackerSet, UsageConflict, UseExtendError},
1314
validation::{check_buffer_usage, MissingBufferUsageError},
14-
Label, DOWNLEVEL_ERROR_WARNING_MESSAGE,
15+
Label,
1516
};
1617

1718
use hal::CommandEncoder as _;
@@ -149,11 +150,6 @@ pub enum ComputePassErrorInner {
149150
MissingBufferUsage(#[from] MissingBufferUsageError),
150151
#[error("cannot pop debug group, because number of pushed debug groups is zero")]
151152
InvalidPopDebugGroup,
152-
#[error(
153-
"Compute shaders are not supported by the underlying platform. {}",
154-
DOWNLEVEL_ERROR_WARNING_MESSAGE
155-
)]
156-
ComputeShadersUnsupported,
157153
#[error(transparent)]
158154
Dispatch(#[from] DispatchError),
159155
#[error(transparent)]
@@ -162,6 +158,8 @@ pub enum ComputePassErrorInner {
162158
PushConstants(#[from] PushConstantUploadError),
163159
#[error(transparent)]
164160
QueryUse(#[from] QueryUseError),
161+
#[error(transparent)]
162+
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
165163
}
166164

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

263+
let (device_guard, mut token) = hub.devices.read(&mut token);
264+
265265
let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token);
266266
let cmd_buf =
267267
CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, encoder_id).map_pass_err(scope)?;
268268
// will be reset to true if recording is done without errors
269269
cmd_buf.status = CommandEncoderStatus::Error;
270270
let raw = cmd_buf.encoder.open();
271271

272+
let device = &device_guard[cmd_buf.device_id.value];
273+
272274
#[cfg(feature = "trace")]
273275
if let Some(ref mut list) = cmd_buf.commands {
274276
list.push(crate::device::trace::Command::RunComputePass {
275277
base: BasePass::from_ref(base),
276278
});
277279
}
278280

279-
if !cmd_buf
280-
.downlevel
281-
.flags
282-
.contains(wgt::DownlevelFlags::COMPUTE_SHADERS)
283-
{
284-
return Err(ComputePassError {
285-
scope: PassErrorScope::Pass(encoder_id),
286-
inner: ComputePassErrorInner::ComputeShadersUnsupported,
287-
});
288-
}
289-
290281
let (_, mut token) = hub.render_bundles.read(&mut token);
291282
let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token);
292283
let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token);
@@ -516,6 +507,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
516507

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

510+
device
511+
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
512+
.map_pass_err(scope)?;
513+
519514
let indirect_buffer = state
520515
.trackers
521516
.buffers

wgpu-core/src/command/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub struct CommandBuffer<A: hal::Api> {
7777
pub(crate) used_swap_chains: SmallVec<[Stored<id::SwapChainId>; 1]>,
7878
pub(crate) buffer_memory_init_actions: Vec<MemoryInitTrackerAction<id::BufferId>>,
7979
limits: wgt::Limits,
80-
downlevel: wgt::DownlevelCapabilities,
8180
support_fill_buffer_texture: bool,
8281
#[cfg(feature = "trace")]
8382
pub(crate) commands: Option<Vec<crate::device::trace::Command>>,
@@ -88,7 +87,7 @@ impl<A: HalApi> CommandBuffer<A> {
8887
encoder: A::CommandEncoder,
8988
device_id: Stored<id::DeviceId>,
9089
limits: wgt::Limits,
91-
downlevel: wgt::DownlevelCapabilities,
90+
_downlevel: wgt::DownlevelCapabilities,
9291
features: wgt::Features,
9392
#[cfg(feature = "trace")] enable_tracing: bool,
9493
label: &Label,
@@ -106,7 +105,6 @@ impl<A: HalApi> CommandBuffer<A> {
106105
used_swap_chains: Default::default(),
107106
buffer_memory_init_actions: Default::default(),
108107
limits,
109-
downlevel,
110108
support_fill_buffer_texture: features.contains(wgt::Features::CLEAR_COMMANDS),
111109
#[cfg(feature = "trace")]
112110
commands: if enable_tracing {

wgpu-core/src/command/render.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
PassErrorScope, QueryResetMap, QueryUseError, RenderCommand, RenderCommandError,
77
StateChange,
88
},
9-
device::{AttachmentData, RenderPassCompatibilityError, RenderPassContext},
9+
device::{
10+
AttachmentData, MissingDownlevelFlags, MissingFeatures, RenderPassCompatibilityError,
11+
RenderPassContext,
12+
},
1013
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Storage, Token},
1114
id,
1215
memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction},
@@ -419,8 +422,10 @@ pub enum RenderPassErrorInner {
419422
SampleCountMismatch { actual: u32, expected: u32 },
420423
#[error("setting `values_offset` to be `None` is only for internal use in render bundles")]
421424
InvalidValuesOffset,
422-
#[error("required device features not enabled: {0:?}")]
423-
MissingDeviceFeatures(wgt::Features),
425+
#[error(transparent)]
426+
MissingFeatures(#[from] MissingFeatures),
427+
#[error(transparent)]
428+
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
424429
#[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)))]
425430
IndirectBufferOverrun {
426431
count: Option<NonZeroU32>,
@@ -483,17 +488,6 @@ where
483488
}
484489
}
485490

486-
fn check_device_features(
487-
actual: wgt::Features,
488-
expected: wgt::Features,
489-
) -> Result<(), RenderPassErrorInner> {
490-
if !actual.contains(expected) {
491-
Err(RenderPassErrorInner::MissingDeviceFeatures(expected))
492-
} else {
493-
Ok(())
494-
}
495-
}
496-
497491
struct RenderAttachment<'a> {
498492
texture_id: &'a Stored<id::TextureId>,
499493
selector: &'a TextureSelector,
@@ -745,6 +739,8 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> {
745739

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

14021399
if count.is_some() {
1403-
check_device_features(
1404-
device.features,
1405-
wgt::Features::MULTI_DRAW_INDIRECT,
1406-
)
1407-
.map_pass_err(scope)?;
1400+
device
1401+
.require_features(wgt::Features::MULTI_DRAW_INDIRECT)
1402+
.map_pass_err(scope)?;
14081403
}
1404+
device
1405+
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
1406+
.map_pass_err(scope)?;
14091407

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

1477-
check_device_features(
1478-
device.features,
1479-
wgt::Features::MULTI_DRAW_INDIRECT_COUNT,
1480-
)
1481-
.map_pass_err(scope)?;
1475+
device
1476+
.require_features(wgt::Features::MULTI_DRAW_INDIRECT_COUNT)
1477+
.map_pass_err(scope)?;
1478+
device
1479+
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
1480+
.map_pass_err(scope)?;
14821481

14831482
let indirect_buffer = info
14841483
.trackers

0 commit comments

Comments
 (0)