Skip to content

Commit e16ceaf

Browse files
committed
Epoch tracking of indices
1 parent ea18c8f commit e16ceaf

File tree

17 files changed

+216
-127
lines changed

17 files changed

+216
-127
lines changed

Cargo.lock

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

gfx-examples/src/framework.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use log::info;
22

33

4+
#[allow(dead_code)]
45
pub fn cast_slice<T>(data: &[T]) -> &[u8] {
56
use std::mem::size_of;
67
use std::slice::from_raw_parts;

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
newline_style = "Native"
2+
spaces_around_ranges = true

wgpu-bindings/wgpu.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ typedef enum {
153153
WGPUVertexFormat_IntR8G8B8A8 = 4,
154154
} WGPUVertexFormat;
155155

156-
typedef uint32_t WGPUId;
156+
typedef struct WGPUBufferMapAsyncStatus WGPUBufferMapAsyncStatus;
157+
158+
typedef struct WGPUId WGPUId;
157159

158160
typedef WGPUId WGPUDeviceId;
159161

@@ -169,6 +171,10 @@ typedef struct {
169171

170172
typedef WGPUId WGPUBufferId;
171173

174+
typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, const uint8_t *data, uint8_t *userdata);
175+
176+
typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status, uint8_t *data, uint8_t *userdata);
177+
172178
typedef WGPUId WGPUCommandBufferId;
173179

174180
typedef struct {
@@ -553,11 +559,25 @@ WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDevi
553559

554560
void wgpu_buffer_destroy(WGPUBufferId buffer_id);
555561

562+
void wgpu_buffer_map_read_async(WGPUBufferId buffer_id,
563+
uint32_t start,
564+
uint32_t size,
565+
WGPUBufferMapReadCallback callback,
566+
uint8_t *userdata);
567+
568+
void wgpu_buffer_map_write_async(WGPUBufferId buffer_id,
569+
uint32_t start,
570+
uint32_t size,
571+
WGPUBufferMapWriteCallback callback,
572+
uint8_t *userdata);
573+
556574
void wgpu_buffer_set_sub_data(WGPUBufferId buffer_id,
557575
uint32_t start,
558576
uint32_t count,
559577
const uint8_t *data);
560578

579+
void wgpu_buffer_unmap(WGPUBufferId buffer_id);
580+
561581
void wgpu_command_buffer_copy_buffer_to_buffer(WGPUCommandBufferId command_buffer_id,
562582
WGPUBufferId src,
563583
uint32_t src_offset,

wgpu-native/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ remote = ["serde"]
2222
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
2323

2424
[dependencies]
25+
arrayvec = "0.4"
2526
bitflags = "1.0"
2627
lazy_static = "1.1.0"
2728
log = "0.4"
@@ -34,4 +35,5 @@ gfx-backend-dx12 = { version = "0.1.0", optional = true }
3435
gfx-backend-metal = { version = "0.1.0", optional = true }
3536
#rendy-memory = { git = "https://github.com/rustgd/rendy", rev = "ce7dd7f", features = ["gfx-hal"] }
3637
serde = { version = "1.0", features = ["serde_derive"], optional = true }
38+
vec_map = "0.8"
3739
winit = { version = "0.18", optional = true }

wgpu-native/src/binding_model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::track::TrackerSet;
22
use crate::{
3-
LifeGuard, WeaklyStored,
3+
LifeGuard,
44
BindGroupLayoutId, BufferId, SamplerId, TextureViewId,
55
};
66

@@ -50,7 +50,7 @@ pub struct PipelineLayoutDescriptor {
5050

5151
pub struct PipelineLayout<B: hal::Backend> {
5252
pub(crate) raw: B::PipelineLayout,
53-
pub(crate) bind_group_layout_ids: Vec<WeaklyStored<BindGroupLayoutId>>,
53+
pub(crate) bind_group_layout_ids: Vec<BindGroupLayoutId>,
5454
}
5555

5656
#[repr(C)]
@@ -82,7 +82,7 @@ pub struct BindGroupDescriptor {
8282

8383
pub struct BindGroup<B: hal::Backend> {
8484
pub(crate) raw: B::DescriptorSet,
85-
pub(crate) layout_id: WeaklyStored<BindGroupLayoutId>,
85+
pub(crate) layout_id: BindGroupLayoutId,
8686
pub(crate) life_guard: LifeGuard,
8787
pub(crate) used: TrackerSet,
8888
}

wgpu-native/src/command/bind.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::{
2-
BindGroupHandle, Stored, WeaklyStored,
2+
BindGroupHandle, Stored,
33
BindGroupId, BindGroupLayoutId, PipelineLayoutId,
44
};
55

66

77
pub struct BindGroupPair {
8-
layout_id: WeaklyStored<BindGroupLayoutId>,
8+
layout_id: BindGroupLayoutId,
99
group_id: Stored<BindGroupId>,
1010
}
1111

1212
#[derive(Default)]
1313
pub struct BindGroupEntry {
14-
expected_layout_id: Option<WeaklyStored<BindGroupLayoutId>>,
14+
expected_layout_id: Option<BindGroupLayoutId>,
1515
provided: Option<BindGroupPair>,
1616
}
1717

@@ -38,12 +38,12 @@ impl BindGroupEntry {
3838
pub fn expect_layout(
3939
&mut self, bind_group_layout_id: BindGroupLayoutId,
4040
) -> Option<BindGroupId> {
41-
let some = Some(WeaklyStored(bind_group_layout_id));
41+
let some = Some(bind_group_layout_id);
4242
if self.expected_layout_id != some {
4343
self.expected_layout_id = some;
4444
match self.provided {
45-
Some(BindGroupPair { ref layout_id, ref group_id })
46-
if layout_id.0 == bind_group_layout_id => Some(group_id.value),
45+
Some(BindGroupPair { layout_id, ref group_id })
46+
if layout_id == bind_group_layout_id => Some(group_id.value),
4747
Some(_) | None => None,
4848
}
4949
} else {
@@ -54,7 +54,7 @@ impl BindGroupEntry {
5454

5555
#[derive(Default)]
5656
pub struct Binder {
57-
pub(crate) pipeline_layout_id: Option<WeaklyStored<PipelineLayoutId>>, //TODO: strongly `Stored`
57+
pub(crate) pipeline_layout_id: Option<PipelineLayoutId>, //TODO: strongly `Stored`
5858
pub(crate) entries: Vec<BindGroupEntry>,
5959
}
6060

@@ -70,7 +70,7 @@ impl Binder {
7070
) -> Option<PipelineLayoutId> {
7171
self.ensure_length(index + 1);
7272
if self.entries[index].provide(bind_group_id, bind_group) {
73-
self.pipeline_layout_id.as_ref().map(|&WeaklyStored(id)| id)
73+
self.pipeline_layout_id.as_ref().cloned()
7474
} else {
7575
None
7676
}

wgpu-native/src/command/compute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ pub extern "C" fn wgpu_compute_pass_set_pipeline(
112112
}
113113

114114
let pipeline_layout_guard = HUB.pipeline_layouts.read();
115-
let pipeline_layout = pipeline_layout_guard.get(pipeline.layout_id.0);
115+
let pipeline_layout = pipeline_layout_guard.get(pipeline.layout_id);
116116
let bing_group_guard = HUB.bind_groups.read();
117117

118118
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
119119
pass.binder.ensure_length(pipeline_layout.bind_group_layout_ids.len());
120120

121-
for (index, (entry, bgl_id)) in pass.binder.entries
121+
for (index, (entry, &bgl_id)) in pass.binder.entries
122122
.iter_mut()
123123
.zip(&pipeline_layout.bind_group_layout_ids)
124124
.enumerate()
125125
{
126-
if let Some(bg_id) = entry.expect_layout(bgl_id.0) {
126+
if let Some(bg_id) = entry.expect_layout(bgl_id) {
127127
let bind_group = bing_group_guard.get(bg_id);
128128
unsafe {
129129
pass.raw.bind_compute_descriptor_sets(

wgpu-native/src/command/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
BufferId, CommandBufferId, CommandEncoderId, DeviceId,
2323
TextureId, TextureViewId,
2424
BufferUsageFlags, TextureUsageFlags, Color,
25-
LifeGuard, Stored, WeaklyStored,
25+
LifeGuard, Stored,
2626
CommandBufferHandle,
2727
};
2828
#[cfg(feature = "local")]
@@ -294,9 +294,9 @@ pub fn command_encoder_begin_render_pass(
294294
let fb_key = FramebufferKey {
295295
attachments: color_attachments
296296
.iter()
297-
.map(|at| WeaklyStored(at.attachment))
297+
.map(|at| at.attachment)
298298
.chain(
299-
depth_stencil_attachment.map(|at| WeaklyStored(at.attachment)),
299+
depth_stencil_attachment.map(|at| at.attachment),
300300
)
301301
.collect(),
302302
};
@@ -308,7 +308,7 @@ pub fn command_encoder_begin_render_pass(
308308
.key()
309309
.attachments
310310
.iter()
311-
.map(|&WeaklyStored(id)| &view_guard.get(id).raw);
311+
.map(|&id| &view_guard.get(id).raw);
312312

313313
unsafe {
314314
device
@@ -374,7 +374,7 @@ pub extern "C" fn wgpu_command_encoder_begin_render_pass(
374374
desc: RenderPassDescriptor,
375375
) -> RenderPassId {
376376
let pass = command_encoder_begin_render_pass(command_encoder_id, desc);
377-
HUB.render_passes.register(pass)
377+
HUB.render_passes.register_local(pass)
378378
}
379379

380380
pub fn command_encoder_begin_compute_pass(
@@ -398,5 +398,5 @@ pub extern "C" fn wgpu_command_encoder_begin_compute_pass(
398398
command_encoder_id: CommandEncoderId,
399399
) -> ComputePassId {
400400
let pass = command_encoder_begin_compute_pass(command_encoder_id);
401-
HUB.compute_passes.register(pass)
401+
HUB.compute_passes.register_local(pass)
402402
}

wgpu-native/src/command/render.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,18 @@ pub extern "C" fn wgpu_render_pass_set_pipeline(
224224
}
225225

226226
let pipeline_layout_guard = HUB.pipeline_layouts.read();
227-
let pipeline_layout = pipeline_layout_guard.get(pipeline.layout_id.0);
227+
let pipeline_layout = pipeline_layout_guard.get(pipeline.layout_id);
228228
let bing_group_guard = HUB.bind_groups.read();
229229

230230
pass.binder.pipeline_layout_id = Some(pipeline.layout_id.clone());
231231
pass.binder.ensure_length(pipeline_layout.bind_group_layout_ids.len());
232232

233-
for (index, (entry, bgl_id)) in pass.binder.entries
233+
for (index, (entry, &bgl_id)) in pass.binder.entries
234234
.iter_mut()
235235
.zip(&pipeline_layout.bind_group_layout_ids)
236236
.enumerate()
237237
{
238-
if let Some(bg_id) = entry.expect_layout(bgl_id.0) {
238+
if let Some(bg_id) = entry.expect_layout(bgl_id) {
239239
let bind_group = bing_group_guard.get(bg_id);
240240
unsafe {
241241
pass.raw.bind_graphics_descriptor_sets(

0 commit comments

Comments
 (0)