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

Hardware Abstraction Layer #1471

Merged
merged 48 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
569cd0c
WIP new wgpu-hal
kvark Jun 4, 2021
0ea4cac
Rework shader and pipeline creation
kvark Jun 5, 2021
bae3c69
Documentation update
kvark Jun 5, 2021
738ae2b
Surface API
kvark Jun 6, 2021
6d51fab
hal:: Fill the command buffer calls
kvark Jun 6, 2021
c61ee12
hal: transfer operations
kvark Jun 7, 2021
0a82c23
hal: port the rest of wgpu-core
kvark Jun 8, 2021
ff2a3e8
update synchronization, fix last errors in wgc
kvark Jun 8, 2021
a421c1c
Instance plumbing
kvark Jun 8, 2021
502c575
hal: bunnymark example
kvark Jun 8, 2021
a0b51ce
hal: remove the cows
kvark Jun 8, 2021
6d22984
hal: redesign the bind group descriptor
kvark Jun 8, 2021
3475d83
hal/metal: instance,adapter, and surface
kvark Jun 9, 2021
f46459c
hal/mtl: buffer, texture, and view creation
kvark Jun 9, 2021
9f90470
hal/mtl: creation of bind groups
kvark Jun 9, 2021
bdaf57d
hal/mtl: pipelines and fences
kvark Jun 10, 2021
3109b1b
hal/mtl: most of the command encoding
kvark Jun 10, 2021
782c72d
hal/mtl: queue
kvark Jun 10, 2021
3172377
hal: rename bunnymark to halmark
kvark Jun 10, 2021
006f8ab
build and clippy fixes, command buffer cleanup
kvark Jun 10, 2021
38e13a1
hal/mtl: array length support
kvark Jun 10, 2021
d88aa99
Fix rows-per-image treatment, clippy warnings
kvark Jun 10, 2021
faf8f7e
Simple API for coherent mapping
kvark Jun 10, 2021
e345ad1
hal: make example to destroy temporary views
kvark Jun 10, 2021
75b6ece
hal: Fix iOS build
kvark Jun 10, 2021
dc34042
hal/vk: instance and adapter
kvark Jun 11, 2021
9ae5e36
hal/vk: format mapping
kvark Jun 11, 2021
b4380e4
hal/vk: buffer and texture creation
kvark Jun 11, 2021
61e2e24
hal/vk: textures and samplers
kvark Jun 11, 2021
006c1ba
hal/vk: pipeline layout, object labels and logging
kvark Jun 12, 2021
4eae5a3
hal/vk: hook up gpu-descriptor
kvark Jun 12, 2021
c2bb2d5
Experimental command pool API
kvark Jun 14, 2021
d8979ca
hal/vk: command pools, clippy warnings
kvark Jun 14, 2021
9d85602
hal: re-architect command encoding and pooling
kvark Jun 14, 2021
00de159
hal/vk: pipeline creation
kvark Jun 15, 2021
668fedd
hal: rename aux to util
kvark Jun 15, 2021
a260cff
hal/vk: queue operations
kvark Jun 15, 2021
6f655e0
hal/vk: barriers and copies
kvark Jun 15, 2021
bc6bb0c
hal/vk: render passes and queries
kvark Jun 16, 2021
67dfdb9
hal/vk: debug markers, bind groups, viewports
kvark Jun 16, 2021
1952ecb
hal/vk: enable vulkan portability support on macos
kvark Jun 16, 2021
c53adda
hal/vk: draws and dispatches. Refactor query set descriptor
kvark Jun 16, 2021
fb662df
hal/vk: polishing to run halmark with no validation issues
kvark Jun 16, 2021
54d7391
Minor tweaks to make CI happy
kvark Jun 17, 2021
7410b70
fix swapchain recycling, copies, device destruction, RODS
kvark Jun 17, 2021
0b506af
hal/vk: use non-coherent-atom-size
kvark Jun 17, 2021
5578222
Switch ubuntu CI to 20.04
kvark Jun 17, 2021
220f359
Address review notes
kvark Jun 17, 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
362 changes: 14 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ members = [
"player",
"wgpu",
"wgpu-core",
"wgpu-hal",
"wgpu-types",
]
default-members = ["wgpu"]
default-members = ["wgpu", "player"]

[patch."https://github.com/gfx-rs/naga"]
#naga = { path = "../naga" }
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
[![codecov.io](https://codecov.io/gh/gfx-rs/wgpu/branch/master/graph/badge.svg?token=84qJTesmeS)](https://codecov.io/gh/gfx-rs/wgpu)

This is an implementation of [WebGPU](https://www.w3.org/community/gpu/) API in Rust, targeting both native and the Web.
It's written in Rust and is based on [gfx-hal](https://github.com/gfx-rs/gfx) with help of [gpu-alloc](https://github.com/zakarumych/gpu-alloc) and [gpu-descriptor](https://github.com/zakarumych/gpu-descriptor). See the upstream [WebGPU specification](https://gpuweb.github.io/gpuweb/) (work in progress).
See the upstream [WebGPU specification](https://gpuweb.github.io/gpuweb/) (work in progress).

The repository hosts the following parts:

- [![Crates.io](https://img.shields.io/crates/v/wgpu.svg?label=wgpu)](https://crates.io/crates/wgpu) [![docs.rs](https://docs.rs/wgpu/badge.svg)](https://docs.rs/wgpu/) - public Rust API for users
- [![Crates.io](https://img.shields.io/crates/v/wgpu-core.svg?label=wgpu-core)](https://crates.io/crates/wgpu-core) [![docs.rs](https://docs.rs/wgpu-core/badge.svg)](https://docs.rs/wgpu-core/) - internal Rust API for WebGPU implementations to use
- [![Crates.io](https://img.shields.io/crates/v/wgpu-hal.svg?label=wgpu-hal)](https://crates.io/crates/wgpu-hal) [![docs.rs](https://docs.rs/wgpu-hal/badge.svg)](https://docs.rs/wgpu-hal/) - internal unsafe GPU abstraction API
- [![Crates.io](https://img.shields.io/crates/v/wgpu-types.svg?label=wgpu-types)](https://crates.io/crates/wgpu-types) [![docs.rs](https://docs.rs/wgpu-types/badge.svg)](https://docs.rs/wgpu-types/) - Rust types shared between `wgpu-core` and `wgpu-rs`
- `player` - standalone application for replaying the API traces, uses `winit`

Expand Down
1 change: 0 additions & 1 deletion player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ license = "MPL-2.0"
publish = false

[features]
cross = ["wgc/cross"]

[dependencies]
env_logger = "0.8"
Expand Down
120 changes: 60 additions & 60 deletions player/src/lib.rs

Large diffs are not rendered by default.

31 changes: 6 additions & 25 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ license = "MPL-2.0"

[features]
default = []
# Enable SPIRV-Cross
cross = ["gfx-backend-metal/cross", "gfx-backend-gl/cross"]
# Enable API tracing
trace = ["ron", "serde", "wgt/trace", "arrayvec/serde"]
# Enable API replaying
Expand All @@ -36,38 +34,21 @@ serde = { version = "1.0", features = ["serde_derive"], optional = true }
smallvec = "1"
thiserror = "1"

gpu-alloc = "0.4"
gpu-descriptor = "0.1"

hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }

[target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies]
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521", features = ["naga"] }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }

[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
#TODO: could also depend on gfx-backend-vulkan for Vulkan Portability

[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521", features = ["naga"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "27a1dae3796d33d23812f2bb8c7e3b5aea18b521" }

[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
tag = "gfx-25"
features = ["spv-in", "spv-out", "wgsl-in"]
features = ["spv-in", "wgsl-in"]

[dependencies.wgt]
path = "../wgpu-types"
package = "wgpu-types"
version = "0.8"

[dependencies.hal]
path = "../wgpu-hal"
package = "wgpu-hal"
version = "0.1"

[dev-dependencies]
loom = "0.3"

Expand Down
34 changes: 15 additions & 19 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::{
device::{
descriptor::{DescriptorSet, DescriptorTotalCount},
DeviceError, MissingFeatures, SHADER_STAGE_COUNT,
},
device::{DeviceError, MissingFeatures, SHADER_STAGE_COUNT},
hub::Resource,
id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId, Valid},
memory_init_tracker::MemoryInitTrackerAction,
track::{TrackerSet, UsageConflict, DUMMY_SELECTOR},
validation::{MissingBufferUsageError, MissingTextureUsageError},
FastHashMap, Label, LifeGuard, MultiRefCount, Stored, MAX_BIND_GROUPS,
FastHashMap, Label, LifeGuard, MultiRefCount, Stored,
};

use arrayvec::ArrayVec;
Expand Down Expand Up @@ -389,19 +386,18 @@ pub struct BindGroupLayoutDescriptor<'a> {
pub(crate) type BindEntryMap = FastHashMap<u32, wgt::BindGroupLayoutEntry>;

#[derive(Debug)]
pub struct BindGroupLayout<B: hal::Backend> {
pub(crate) raw: B::DescriptorSetLayout,
pub struct BindGroupLayout<A: hal::Api> {
pub(crate) raw: A::BindGroupLayout,
pub(crate) device_id: Stored<DeviceId>,
pub(crate) multi_ref_count: MultiRefCount,
pub(crate) entries: BindEntryMap,
pub(crate) desc_count: DescriptorTotalCount,
pub(crate) dynamic_count: usize,
pub(crate) count_validator: BindingTypeMaxCountValidator,
#[cfg(debug_assertions)]
pub(crate) label: String,
}

impl<B: hal::Backend> Resource for BindGroupLayout<B> {
impl<A: hal::Api> Resource for BindGroupLayout<A> {
const TYPE: &'static str = "BindGroupLayout";

fn life_guard(&self) -> &LifeGuard {
Expand Down Expand Up @@ -498,15 +494,15 @@ pub struct PipelineLayoutDescriptor<'a> {
}

#[derive(Debug)]
pub struct PipelineLayout<B: hal::Backend> {
pub(crate) raw: B::PipelineLayout,
pub struct PipelineLayout<A: hal::Api> {
pub(crate) raw: A::PipelineLayout,
pub(crate) device_id: Stored<DeviceId>,
pub(crate) life_guard: LifeGuard,
pub(crate) bind_group_layout_ids: ArrayVec<[Valid<BindGroupLayoutId>; MAX_BIND_GROUPS]>,
pub(crate) bind_group_layout_ids: ArrayVec<[Valid<BindGroupLayoutId>; hal::MAX_BIND_GROUPS]>,
pub(crate) push_constant_ranges: ArrayVec<[wgt::PushConstantRange; SHADER_STAGE_COUNT]>,
}

impl<B: hal::Backend> PipelineLayout<B> {
impl<A: hal::Api> PipelineLayout<A> {
/// Validate push constants match up with expected ranges.
pub(crate) fn validate_push_constant_ranges(
&self,
Expand Down Expand Up @@ -586,7 +582,7 @@ impl<B: hal::Backend> PipelineLayout<B> {
}
}

impl<B: hal::Backend> Resource for PipelineLayout<B> {
impl<A: hal::Api> Resource for PipelineLayout<A> {
const TYPE: &'static str = "PipelineLayout";

fn life_guard(&self) -> &LifeGuard {
Expand Down Expand Up @@ -636,8 +632,8 @@ pub struct BindGroupDynamicBindingData {
}

#[derive(Debug)]
pub struct BindGroup<B: hal::Backend> {
pub(crate) raw: DescriptorSet<B>,
pub struct BindGroup<A: hal::Api> {
pub(crate) raw: A::BindGroup,
pub(crate) device_id: Stored<DeviceId>,
pub(crate) layout_id: Valid<BindGroupLayoutId>,
pub(crate) life_guard: LifeGuard,
Expand All @@ -646,7 +642,7 @@ pub struct BindGroup<B: hal::Backend> {
pub(crate) dynamic_binding_info: Vec<BindGroupDynamicBindingData>,
}

impl<B: hal::Backend> BindGroup<B> {
impl<A: hal::Api> BindGroup<A> {
pub(crate) fn validate_dynamic_bindings(
&self,
offsets: &[wgt::DynamicOffset],
Expand Down Expand Up @@ -681,13 +677,13 @@ impl<B: hal::Backend> BindGroup<B> {
}
}

impl<B: hal::Backend> Borrow<()> for BindGroup<B> {
impl<A: hal::Api> Borrow<()> for BindGroup<A> {
fn borrow(&self) -> &() {
&DUMMY_SELECTOR
}
}

impl<B: hal::Backend> Resource for BindGroup<B> {
impl<A: hal::Api> Resource for BindGroup<A> {
const TYPE: &'static str = "BindGroup";

fn life_guard(&self) -> &LifeGuard {
Expand Down
Loading