Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL ES3 backend #1510

Merged
merged 33 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
41bc9d0
hal/gl: start the backend, port the Instance
kvark Jun 18, 2021
d88bc44
hal/gles: describe format, adapter info
kvark Jun 19, 2021
804b17b
hal/gl: version parsing
kvark Jun 20, 2021
5083f56
Add more downlevel flags, implement device opening on Gles
kvark Jun 21, 2021
31e6ed8
hal/gles: creation of buffers, textures, view, and samplers
kvark Jun 21, 2021
31da0f2
hal/gles: command module
kvark Jun 21, 2021
4d42bef
hal/gles: encoding copies and draws
kvark Jun 22, 2021
b1fe865
hal/gles: queue module
kvark Jun 22, 2021
85e59c3
hal/gles: texture copies
kvark Jun 23, 2021
d29c450
hal/gles: bind group creation
kvark Jun 23, 2021
d3d2ed5
hal/gles: pipeline creation
kvark Jun 23, 2021
91f9806
hal/gles: fences and queries
kvark Jun 24, 2021
24ff58c
hal/gles: present, texture format caps
kvark Jun 24, 2021
51dd90b
hal/gles: render passes
kvark Jun 24, 2021
205327d
hal/gles: barriers
kvark Jun 24, 2021
13b0a61
hal/gles: stencil and vertex state
kvark Jun 24, 2021
91df157
Refactor downlevel support a bit, implement blending for hal/gles
kvark Jun 25, 2021
673ec60
hal/gles: resource binding
kvark Jun 25, 2021
c7356e1
hal/gles: storage texture bindings
kvark Jun 25, 2021
8fd6b36
hal/egl: add coherence preference, hook up EGL_KHR_debug message call…
kvark Jun 25, 2021
cf10138
hal/egl: add coherence preference, hook up EGL_KHR_debug message call…
kvark Jun 25, 2021
952173e
Enable Gles backend, add checks for downlevel flags
kvark Jun 26, 2021
bf61908
hal/gles: primitive state and framebuffer operations
kvark Jun 26, 2021
403ff6f
hal/gles: Update glow and fill up the missing methods
kvark Jun 27, 2021
e4aee90
hal/gles: object labels, view dimensions, and buffer clears
kvark Jun 28, 2021
25ec744
hal/gles: improve the exposed limits
kvark Jun 28, 2021
6025a8d
hal/gles: enable robust access by default
kvark Jun 29, 2021
3a796c2
hal/gles: fix buffer mapping
kvark Jun 29, 2021
582c128
Pick up naga's GLSL continuing and Y-flip fixes
kvark Jun 29, 2021
40e2c33
hal/gles: hack around cubemap support
kvark Jun 29, 2021
4be8864
hal/gles: totally rework the vertex data binding
kvark Jun 30, 2021
45074b2
hal: more implementation comments
kvark Jun 30, 2021
6f13eeb
hal/gles: compressed ETC2 texture support
kvark Jun 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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