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

Port to gfx-extras and gfx-hal-0.5 #537

Merged
merged 2 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
244 changes: 127 additions & 117 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is an active GitHub mirror of the WebGPU implementation in Rust, which now
[![Crates.io](https://img.shields.io/crates/v/wgpu-core.svg?label=wgpu-core)](https://crates.io/crates/wgpu-core)
[![Crates.io](https://img.shields.io/crates/v/wgpu-native.svg?label=wgpu-native)](https://crates.io/crates/wgpu-native)

This is an experimental [WebGPU](https://www.w3.org/community/gpu/) implementation, exposing both Rust and C interfaces as a native static library. It's written in Rust and is based on [gfx-hal](https://github.com/gfx-rs/gfx) and a few [Rendy](https://github.com/amethyst/rendy) bits. See the upstream [WebGPU specification](https://gpuweb.github.io/gpuweb/) (work in progress).
This is an experimental [WebGPU](https://www.w3.org/community/gpu/) implementation, exposing both Rust and C interfaces as a native static library. It's written in Rust and is based on [gfx-hal](https://github.com/gfx-rs/gfx) with help of [gfx-extras](https://github.com/gfx-rs/gfx-extras). See the upstream [WebGPU specification](https://gpuweb.github.io/gpuweb/) (work in progress).

The implementation consists of the following parts:

Expand Down
26 changes: 13 additions & 13 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
"Joshua Groves <josh@joshgroves.com>",
]
edition = "2018"
description = "WebGPU core logic on gfx-hal/rendy"
description = "WebGPU core logic on gfx-hal"
homepage = "https://github.com/gfx-rs/wgpu"
repository = "https://github.com/gfx-rs/wgpu"
keywords = ["graphics"]
Expand All @@ -27,13 +27,13 @@ bitflags = "1.0"
copyless = "0.1"
fxhash = "0.2"
log = "0.4"
hal = { package = "gfx-hal", version = "0.4" }
gfx-backend-empty = { version = "0.4" }
parking_lot = "0.9"
hal = { package = "gfx-hal", version = "0.5" }
gfx-backend-empty = "0.5"
gfx-descriptor = "0.1"
gfx-memory = "0.1"
parking_lot = "0.10"
peek-poke = { git = "https://github.com/kvark/peek-poke", rev = "969bd7fe2be1a83f87916dc8b388c63cfd457075" }
rendy-memory = "0.5"
rendy-descriptor = "0.5"
smallvec = "1.0"
smallvec = "1"
vec_map = "0.8"

[dependencies.serde_crate]
Expand All @@ -49,16 +49,16 @@ version = "0.1"
features = ["peek-poke"]

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.4" }
gfx-backend-vulkan = { version = "0.4", optional = true }
gfx-backend-metal = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5", optional = true }

[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.4", features = ["x11"] }
gfx-backend-vulkan = { version = "0.5", features = ["x11"] }

[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { version = "0.4.1" }
gfx-backend-dx11 = { version = "0.4" }
gfx-backend-vulkan = { version = "0.4" }
gfx-backend-dx12 = { version = "0.5" }
gfx-backend-dx11 = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5" }

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
battery = { version = "0.7", optional = true }
4 changes: 2 additions & 2 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{

use wgt::BufferAddress;
use arrayvec::ArrayVec;
use rendy_descriptor::{DescriptorRanges, DescriptorSet};
use gfx_descriptor::{DescriptorCounts, DescriptorSet};

#[cfg(feature = "serde")]
use serde_crate::{Deserialize, Serialize};
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct BindGroupLayout<B: hal::Backend> {
pub(crate) raw: B::DescriptorSetLayout,
pub(crate) device_id: Stored<DeviceId>,
pub(crate) entries: FastHashMap<u32, BindGroupLayoutEntry>,
pub(crate) desc_ranges: DescriptorRanges,
pub(crate) desc_counts: DescriptorCounts,
pub(crate) dynamic_count: usize,
}

Expand Down
7 changes: 2 additions & 5 deletions wgpu-core/src/command/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ impl<B: hal::Backend> CommandPool<B> {

fn allocate(&mut self) -> B::CommandBuffer {
if self.available.is_empty() {
let extra = unsafe { self.raw.allocate_vec(20, hal::command::Level::Primary) };
self.available.extend(extra);
unsafe { self.raw.allocate(20, hal::command::Level::Primary, &mut self.available) };
}

self.available.pop().unwrap()
}
}
Expand Down Expand Up @@ -133,8 +131,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
let pool = inner.pools.get_mut(&cmd_buf.recorded_thread_id).unwrap();

if pool.available.is_empty() {
let extra = unsafe { pool.raw.allocate_vec(20, hal::command::Level::Primary) };
pool.available.extend(extra);
unsafe { pool.raw.allocate(20, hal::command::Level::Primary, &mut pool.available) };
}

pool.available.pop().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offsets
.iter()
.chain(follow_ups.flat_map(|(_, offsets)| offsets))
.map(|&off| off as hal::command::DescriptorSetOffset),
.cloned(),
);
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&pipeline_layout.raw,
index,
iter::once(desc_set),
offsets.iter().map(|offset| *offset as u32),
offsets.iter().cloned(),
);
}
}
Expand Down
27 changes: 19 additions & 8 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl State {
if bind_mask != 0 {
//let (expected, provided) = self.binder.entries[index as usize].info();
return Err(DrawError::IncompatibleBindGroup {
index: bind_mask.trailing_zeros() as u32,
index: bind_mask.trailing_zeros(),
});
}
if self.blend_color == OptionalState::Required {
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
clear_color: at.clear_color,
}
})
.collect::<arrayvec::ArrayVec<[_; MAX_COLOR_TARGETS]>>();
.collect::<ArrayVec<[_; MAX_COLOR_TARGETS]>>();
let depth_stencil_attachment = if targets.depth_stencil.attachment == id::TextureViewId::ERROR {
None
} else {
Expand Down Expand Up @@ -602,7 +602,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
} else {
let sample_count_check =
view_guard[color_attachments[i].attachment].samples;
assert!(sample_count_check > 1, "RenderPassColorAttachmentDescriptor with a resolve_target must have an attachment with sample_count > 1");
assert!(sample_count_check > 1,
"RenderPassColorAttachmentDescriptor with a resolve_target must have an attachment with sample_count > 1");
resolve_ids.push((
attachment_index,
hal::image::Layout::ColorAttachmentOptimal,
Expand Down Expand Up @@ -845,7 +846,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
offsets
.iter()
.chain(follow_ups.flat_map(|(_, offsets)| offsets))
.map(|&off| off as hal::command::DescriptorSetOffset),
.cloned()
);
}
};
Expand Down Expand Up @@ -897,7 +898,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
&pipeline_layout.raw,
index,
iter::once(desc_set),
offsets.iter().map(|offset| *offset as u32),
offsets.iter().cloned(),
);
}
}
Expand All @@ -922,7 +923,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let view = hal::buffer::IndexBufferView {
buffer: &buffer.raw,
offset: range.start,
range: hal::buffer::SubRange {
offset: range.start,
size: Some(range.end - range.start),
},
index_type: conv::map_index_format(state.index.format),
};

Expand Down Expand Up @@ -960,7 +964,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let view = hal::buffer::IndexBufferView {
buffer: &buffer.raw,
offset,
range: hal::buffer::SubRange {
offset,
size: Some(end - offset),
},
index_type: conv::map_index_format(state.index.format),
};

Expand All @@ -980,8 +987,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
buffer.size - offset
};

let range = hal::buffer::SubRange {
offset,
size: if size != 0 { Some(size) } else { None },
};
unsafe {
raw.bind_vertex_buffers(slot, iter::once((&buffer.raw, offset)));
raw.bind_vertex_buffers(slot, iter::once((&buffer.raw, range)));
}
state.vertex.update_limits();
}
Expand Down
79 changes: 57 additions & 22 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,61 @@ pub fn map_binding_type(
binding: &binding_model::BindGroupLayoutEntry,
) -> hal::pso::DescriptorType {
use crate::binding_model::BindingType as Bt;
use hal::pso::DescriptorType as H;
use hal::pso;
match binding.ty {
Bt::UniformBuffer => {
if binding.has_dynamic_offset {
H::UniformBufferDynamic
} else {
H::UniformBuffer
pso::DescriptorType::Buffer {
ty: pso::BufferDescriptorType::Uniform,
format: pso::BufferDescriptorFormat::Structured {
dynamic_offset: binding.has_dynamic_offset,
},
}
}
Bt::StorageBuffer => {
pso::DescriptorType::Buffer {
ty: pso::BufferDescriptorType::Storage {
read_only: false,
},
format: pso::BufferDescriptorFormat::Structured {
dynamic_offset: binding.has_dynamic_offset,
},
}
}
Bt::StorageBuffer |
Bt::ReadonlyStorageBuffer => {
if binding.has_dynamic_offset {
H::StorageBufferDynamic
} else {
H::StorageBuffer
pso::DescriptorType::Buffer {
ty: pso::BufferDescriptorType::Storage {
read_only: false,
},
format: pso::BufferDescriptorFormat::Structured {
dynamic_offset: binding.has_dynamic_offset,
},
}
}
Bt::Sampler |
Bt::ComparisonSampler => H::Sampler,
Bt::SampledTexture => H::SampledImage,
Bt::ReadonlyStorageTexture |
Bt::WriteonlyStorageTexture => H::StorageImage,
Bt::ComparisonSampler => {
pso::DescriptorType::Sampler
}
Bt::SampledTexture => {
pso::DescriptorType::Image {
ty: pso::ImageDescriptorType::Sampled {
with_sampler: false,
},
}
}
Bt::ReadonlyStorageTexture => {
pso::DescriptorType::Image {
ty: pso::ImageDescriptorType::Storage {
read_only: false,
},
}
}
Bt::WriteonlyStorageTexture => {
pso::DescriptorType::Image {
ty: pso::ImageDescriptorType::Storage {
read_only: true,
},
}
}
}
}

Expand Down Expand Up @@ -646,23 +679,24 @@ pub fn map_wrap(address: wgt::AddressMode) -> hal::image::WrapMode {
pub fn map_rasterization_state_descriptor(
desc: &RasterizationStateDescriptor,
) -> hal::pso::Rasterizer {
hal::pso::Rasterizer {
use hal::pso;
pso::Rasterizer {
depth_clamping: false,
polygon_mode: hal::pso::PolygonMode::Fill,
polygon_mode: pso::PolygonMode::Fill,
cull_face: match desc.cull_mode {
CullMode::None => hal::pso::Face::empty(),
CullMode::Front => hal::pso::Face::FRONT,
CullMode::Back => hal::pso::Face::BACK,
CullMode::None => pso::Face::empty(),
CullMode::Front => pso::Face::FRONT,
CullMode::Back => pso::Face::BACK,
},
front_face: match desc.front_face {
FrontFace::Ccw => hal::pso::FrontFace::CounterClockwise,
FrontFace::Cw => hal::pso::FrontFace::Clockwise,
FrontFace::Ccw => pso::FrontFace::CounterClockwise,
FrontFace::Cw => pso::FrontFace::Clockwise,
},
depth_bias: if desc.depth_bias != 0
|| desc.depth_bias_slope_scale != 0.0
|| desc.depth_bias_clamp != 0.0
{
Some(hal::pso::State::Static(hal::pso::DepthBias {
Some(pso::State::Static(pso::DepthBias {
const_factor: desc.depth_bias as f32,
slope_factor: desc.depth_bias_slope_scale,
clamp: desc.depth_bias_clamp,
Expand All @@ -671,6 +705,7 @@ pub fn map_rasterization_state_descriptor(
None
},
conservative: false,
line_width: pso::State::Static(1.0),
}
}

Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/device/life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
use copyless::VecHelper as _;
use hal::device::Device as _;
use parking_lot::Mutex;
use rendy_descriptor::{DescriptorAllocator, DescriptorSet};
use rendy_memory::{Heaps, MemoryBlock};
use gfx_descriptor::{DescriptorAllocator, DescriptorSet};
use gfx_memory::{Heaps, MemoryBlock};

use std::{
sync::atomic::Ordering,
Expand Down Expand Up @@ -555,10 +555,10 @@ impl<B: GfxBackend> LifetimeTracker<B> {
let mapping = buffer.pending_mapping.take().unwrap();
let result = match mapping.op {
resource::BufferMapOperation::Read { .. } => {
super::map_buffer(raw, buffer, mapping.range, super::HostMap::Read)
super::map_buffer(raw, buffer, mapping.sub_range, super::HostMap::Read)
}
resource::BufferMapOperation::Write { .. } => {
super::map_buffer(raw, buffer, mapping.range, super::HostMap::Write)
super::map_buffer(raw, buffer, mapping.sub_range, super::HostMap::Write)
}
};
(mapping.op, result)
Expand Down
Loading