Skip to content

Commit 57b3b72

Browse files
committed
Implement TEXTURE_BINDING_ARRAY extension
1 parent f8a68cd commit 57b3b72

File tree

10 files changed

+616
-326
lines changed

10 files changed

+616
-326
lines changed

Cargo.lock

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

player/src/main.rs

Lines changed: 11 additions & 12 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,12 +292,11 @@ 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
299-
.into_iter()
296+
.iter()
300297
.map(|(binding, res)| wgc::binding_model::BindGroupEntry {
301-
binding,
302-
resource: match res {
298+
binding: *binding,
299+
resource: match *res {
303300
trace::BindingResource::Buffer { id, offset, size } => {
304301
bm::BindingResource::Buffer(bm::BufferBinding {
305302
buffer: id,
@@ -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)
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: 6 additions & 6 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" }
61+
gfx-backend-dx12 = { version = "0.5.5" }
6262
gfx-backend-dx11 = { version = "0.5" }
63-
gfx-backend-vulkan = { version = "0.5" }
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: 16 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,17 @@ 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+
MissingExtension(wgt::Extensions),
24+
/// Arrays of bindings can't be 0 elements long
25+
ZeroCount,
26+
/// Arrays of bindings unsupported for this type of binding
27+
ArrayUnsupported,
9428
}
9529

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

9832
#[derive(Debug)]
9933
pub struct BindGroupLayout<B: hal::Backend> {
@@ -135,32 +69,28 @@ pub struct BufferBinding {
13569
pub size: wgt::BufferSize,
13670
}
13771

138-
#[repr(C)]
72+
// Note: Duplicated in wgpu-rs as BindingResource
13973
#[derive(Debug)]
140-
#[cfg_attr(feature = "trace", derive(Serialize))]
141-
#[cfg_attr(feature = "replay", derive(Deserialize))]
142-
pub enum BindingResource {
74+
pub enum BindingResource<'a> {
14375
Buffer(BufferBinding),
14476
Sampler(SamplerId),
14577
TextureView(TextureViewId),
78+
TextureViewArray(&'a [TextureViewId]),
14679
}
14780

148-
#[repr(C)]
81+
// Note: Duplicated in wgpu-rs as Binding
14982
#[derive(Debug)]
150-
#[cfg_attr(feature = "trace", derive(Serialize))]
151-
#[cfg_attr(feature = "replay", derive(Deserialize))]
152-
pub struct BindGroupEntry {
83+
pub struct BindGroupEntry<'a> {
15384
pub binding: u32,
154-
pub resource: BindingResource,
85+
pub resource: BindingResource<'a>,
15586
}
15687

157-
#[repr(C)]
88+
// Note: Duplicated in wgpu-rs as BindGroupDescriptor
15889
#[derive(Debug)]
159-
pub struct BindGroupDescriptor {
160-
pub label: *const std::os::raw::c_char,
90+
pub struct BindGroupDescriptor<'a> {
91+
pub label: Option<&'a str>,
16192
pub layout: BindGroupLayoutId,
162-
pub entries: *const BindGroupEntry,
163-
pub entries_length: usize,
93+
pub bindings: &'a [BindGroupEntry<'a>],
16494
}
16595

16696
#[derive(Debug)]

wgpu-core/src/conv.rs

Lines changed: 16 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,36 @@ 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 { .. } => 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!(),
112108
}
113109
}
114110

0 commit comments

Comments
 (0)