Skip to content

Commit 2a27434

Browse files
committed
descriptor arrays
1 parent f8a68cd commit 2a27434

File tree

11 files changed

+585
-326
lines changed

11 files changed

+585
-326
lines changed

Cargo.lock

Lines changed: 194 additions & 139 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ members = [
44
"wgpu-core",
55
"wgpu-types",
66
]
7+
8+
[patch.crates-io]
9+
gfx-hal = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }
10+
gfx-backend-empty = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }
11+
gfx-backend-vulkan = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }
12+
gfx-backend-dx12 = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }
13+
gfx-backend-dx11 = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }
14+
gfx-backend-metal = { version = "0.5.0", git = "https://github.com/cwfitzgerald/gfx.git", rev = "4ba8c5753b4aabed15bb80252f5198b008d6682d" }

player/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,11 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
254254
}
255255
}
256256
A::CreateBindGroupLayout { id, label, entries } => {
257-
let label = Label::new(&label);
258257
self.device_create_bind_group_layout::<B>(
259258
device,
260-
&wgc::binding_model::BindGroupLayoutDescriptor {
261-
label: label.as_ptr(),
262-
entries: entries.as_ptr(),
263-
entries_length: entries.len(),
259+
&wgt::BindGroupLayoutDescriptor {
260+
label: Some(&label),
261+
bindings: &entries,
264262
},
265263
id,
266264
)
@@ -294,7 +292,6 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
294292
entries,
295293
} => {
296294
use wgc::binding_model as bm;
297-
let label = Label::new(&label);
298295
let entry_vec = entries
299296
.into_iter()
300297
.map(|(binding, res)| wgc::binding_model::BindGroupEntry {
@@ -311,17 +308,19 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
311308
trace::BindingResource::TextureView(id) => {
312309
bm::BindingResource::TextureView(id)
313310
}
311+
trace::BindingResource::TextureViewArray(ref id_array) => {
312+
bm::BindingResource::TextureViewArray(id_array.clone())
313+
}
314314
},
315315
})
316316
.collect::<Vec<_>>();
317317
self.device_maintain_ids::<B>(device);
318318
self.device_create_bind_group::<B>(
319319
device,
320320
&wgc::binding_model::BindGroupDescriptor {
321-
label: label.as_ptr(),
321+
label: Some(&label),
322322
layout: layout_id,
323-
entries: entry_vec.as_ptr(),
324-
entries_length: entry_vec.len(),
323+
bindings: &entry_vec,
325324
},
326325
id,
327326
);

wgpu-core/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bitflags = "1.0"
2727
copyless = "0.1"
2828
fxhash = "0.2"
2929
log = "0.4"
30-
hal = { package = "gfx-hal", version = "0.5" }
30+
hal = { package = "gfx-hal", version = "0.5.1" }
3131
gfx-backend-empty = "0.5"
3232
gfx-descriptor = "0.1"
3333
gfx-memory = "0.1"
@@ -51,16 +51,16 @@ version = "0.5"
5151
features = ["peek-poke"]
5252

5353
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
54-
gfx-backend-metal = { version = "0.5" }
55-
gfx-backend-vulkan = { version = "0.5", optional = true }
54+
gfx-backend-metal = { version = "0.5.3" }
55+
gfx-backend-vulkan = { version = "0.5.7", optional = true }
5656

5757
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
58-
gfx-backend-vulkan = { version = "0.5" }
58+
gfx-backend-vulkan = { version = "0.5.7" }
5959

6060
[target.'cfg(windows)'.dependencies]
61-
gfx-backend-dx12 = { version = "0.5" }
62-
gfx-backend-dx11 = { version = "0.5" }
63-
gfx-backend-vulkan = { version = "0.5" }
61+
gfx-backend-dx12 = { version = "0.5.5" }
62+
gfx-backend-dx11 = { version = "0.5.1" }
63+
gfx-backend-vulkan = { version = "0.5.7" }
6464

6565
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
6666
battery = { version = "0.7", optional = true }

wgpu-core/src/binding_model.rs

Lines changed: 10 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,14 @@ use serde::Deserialize;
1717
use serde::Serialize;
1818
use std::borrow::Borrow;
1919

20-
#[repr(C)]
21-
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
22-
#[cfg_attr(feature = "trace", derive(Serialize))]
23-
#[cfg_attr(feature = "replay", derive(Deserialize))]
24-
pub enum BindingType {
25-
UniformBuffer = 0,
26-
StorageBuffer = 1,
27-
ReadonlyStorageBuffer = 2,
28-
Sampler = 3,
29-
ComparisonSampler = 4,
30-
SampledTexture = 5,
31-
ReadonlyStorageTexture = 6,
32-
WriteonlyStorageTexture = 7,
33-
}
34-
35-
#[repr(C)]
36-
#[derive(Clone, Debug, Hash, PartialEq)]
37-
#[cfg_attr(feature = "trace", derive(Serialize))]
38-
#[cfg_attr(feature = "replay", derive(Deserialize))]
39-
pub struct BindGroupLayoutEntry {
40-
pub binding: u32,
41-
pub visibility: wgt::ShaderStage,
42-
pub ty: BindingType,
43-
pub multisampled: bool,
44-
pub has_dynamic_offset: bool,
45-
pub view_dimension: wgt::TextureViewDimension,
46-
pub texture_component_type: wgt::TextureComponentType,
47-
pub storage_texture_format: wgt::TextureFormat,
48-
}
49-
50-
#[derive(Clone, Debug)]
51-
pub enum BindGroupLayoutEntryError {
52-
NoVisibility,
53-
UnexpectedHasDynamicOffset,
54-
UnexpectedMultisampled,
55-
}
56-
57-
impl BindGroupLayoutEntry {
58-
pub(crate) fn validate(&self) -> Result<(), BindGroupLayoutEntryError> {
59-
if self.visibility.is_empty() {
60-
return Err(BindGroupLayoutEntryError::NoVisibility);
61-
}
62-
match self.ty {
63-
BindingType::UniformBuffer | BindingType::StorageBuffer => {}
64-
_ => {
65-
if self.has_dynamic_offset {
66-
return Err(BindGroupLayoutEntryError::UnexpectedHasDynamicOffset);
67-
}
68-
}
69-
}
70-
match self.ty {
71-
BindingType::SampledTexture => {}
72-
_ => {
73-
if self.multisampled {
74-
return Err(BindGroupLayoutEntryError::UnexpectedMultisampled);
75-
}
76-
}
77-
}
78-
Ok(())
79-
}
80-
}
81-
82-
#[repr(C)]
83-
#[derive(Debug)]
84-
pub struct BindGroupLayoutDescriptor {
85-
pub label: *const std::os::raw::c_char,
86-
pub entries: *const BindGroupLayoutEntry,
87-
pub entries_length: usize,
88-
}
89-
9020
#[derive(Clone, Debug)]
9121
pub enum BindGroupLayoutError {
9222
ConflictBinding(u32),
93-
Entry(u32, BindGroupLayoutEntryError),
23+
/// Extension TEXTURE_BINDING_ARRAY must be enabled to use SampledTextureArray in a bind group layout
24+
MissingTextureBindingArrayExtension,
9425
}
9526

96-
pub(crate) type BindEntryMap = FastHashMap<u32, BindGroupLayoutEntry>;
27+
pub(crate) type BindEntryMap = FastHashMap<u32, wgt::BindGroupLayoutEntry>;
9728

9829
#[derive(Debug)]
9930
pub struct BindGroupLayout<B: hal::Backend> {
@@ -135,32 +66,30 @@ pub struct BufferBinding {
13566
pub size: wgt::BufferSize,
13667
}
13768

138-
#[repr(C)]
69+
// Note: Duplicated in wgpu-rs as BindingResource
13970
#[derive(Debug)]
14071
#[cfg_attr(feature = "trace", derive(Serialize))]
14172
#[cfg_attr(feature = "replay", derive(Deserialize))]
14273
pub enum BindingResource {
14374
Buffer(BufferBinding),
14475
Sampler(SamplerId),
14576
TextureView(TextureViewId),
77+
TextureViewArray(Vec<TextureViewId>),
14678
}
14779

148-
#[repr(C)]
80+
// Note: Duplicated in wgpu-rs as Binding
14981
#[derive(Debug)]
150-
#[cfg_attr(feature = "trace", derive(Serialize))]
151-
#[cfg_attr(feature = "replay", derive(Deserialize))]
15282
pub struct BindGroupEntry {
15383
pub binding: u32,
15484
pub resource: BindingResource,
15585
}
15686

157-
#[repr(C)]
87+
// Note: Duplicated in wgpu-rs as BindGroupDescriptor
15888
#[derive(Debug)]
159-
pub struct BindGroupDescriptor {
160-
pub label: *const std::os::raw::c_char,
89+
pub struct BindGroupDescriptor<'a> {
90+
pub label: Option<&'a str>,
16191
pub layout: BindGroupLayoutId,
162-
pub entries: *const BindGroupEntry,
163-
pub entries_length: usize,
92+
pub bindings: &'a [BindGroupEntry],
16493
}
16594

16695
#[derive(Debug)]

wgpu-core/src/conv.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use crate::{binding_model, resource, PrivateFeatures};
5+
use crate::{resource, PrivateFeatures};
66

77
pub fn map_buffer_usage(usage: wgt::BufferUsage) -> (hal::buffer::Usage, hal::memory::Properties) {
88
use hal::buffer::Usage as U;
@@ -75,40 +75,44 @@ pub fn map_texture_usage(
7575
value
7676
}
7777

78-
pub fn map_binding_type(binding: &binding_model::BindGroupLayoutEntry) -> hal::pso::DescriptorType {
79-
use crate::binding_model::BindingType as Bt;
78+
pub fn map_binding_type(binding: &wgt::BindGroupLayoutEntry) -> hal::pso::DescriptorType {
8079
use hal::pso;
80+
use wgt::BindingType as Bt;
8181
match binding.ty {
82-
Bt::UniformBuffer => pso::DescriptorType::Buffer {
82+
Bt::UniformBuffer { dynamic } => pso::DescriptorType::Buffer {
8383
ty: pso::BufferDescriptorType::Uniform,
8484
format: pso::BufferDescriptorFormat::Structured {
85-
dynamic_offset: binding.has_dynamic_offset,
85+
dynamic_offset: dynamic,
8686
},
8787
},
88-
Bt::StorageBuffer => pso::DescriptorType::Buffer {
89-
ty: pso::BufferDescriptorType::Storage { read_only: false },
90-
format: pso::BufferDescriptorFormat::Structured {
91-
dynamic_offset: binding.has_dynamic_offset,
88+
Bt::StorageBuffer { readonly, dynamic } => pso::DescriptorType::Buffer {
89+
ty: pso::BufferDescriptorType::Storage {
90+
read_only: readonly,
9291
},
93-
},
94-
Bt::ReadonlyStorageBuffer => pso::DescriptorType::Buffer {
95-
ty: pso::BufferDescriptorType::Storage { read_only: true },
9692
format: pso::BufferDescriptorFormat::Structured {
97-
dynamic_offset: binding.has_dynamic_offset,
93+
dynamic_offset: dynamic,
9894
},
9995
},
100-
Bt::Sampler | Bt::ComparisonSampler => pso::DescriptorType::Sampler,
101-
Bt::SampledTexture => pso::DescriptorType::Image {
96+
Bt::Sampler { .. } => pso::DescriptorType::Sampler,
97+
Bt::SampledTexture { .. } | Bt::SampledTextureArray { .. } => pso::DescriptorType::Image {
10298
ty: pso::ImageDescriptorType::Sampled {
10399
with_sampler: false,
104100
},
105101
},
106-
Bt::ReadonlyStorageTexture => pso::DescriptorType::Image {
107-
ty: pso::ImageDescriptorType::Storage { read_only: true },
108-
},
109-
Bt::WriteonlyStorageTexture => pso::DescriptorType::Image {
110-
ty: pso::ImageDescriptorType::Storage { read_only: false },
102+
Bt::StorageTexture { readonly, .. } => pso::DescriptorType::Image {
103+
ty: pso::ImageDescriptorType::Storage {
104+
read_only: readonly,
105+
},
111106
},
107+
_ => unreachable!(),
108+
}
109+
}
110+
111+
pub fn map_binding_count(binding: &wgt::BindGroupLayoutEntry) -> hal::pso::DescriptorArrayIndex {
112+
use wgt::BindingType as Bt;
113+
match binding.ty {
114+
Bt::SampledTextureArray { count, .. } => count,
115+
_ => 1,
112116
}
113117
}
114118

0 commit comments

Comments
 (0)