Skip to content

Commit f633a57

Browse files
committed
mesh shaders init pipelies
save remove printlns some cleanup tiny fixes ask for task shader as well rewrite to use existing RenderPipeline FIX!
1 parent a203333 commit f633a57

File tree

12 files changed

+548
-59
lines changed

12 files changed

+548
-59
lines changed

Cargo.lock

Lines changed: 5 additions & 25 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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,39 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
402402
A::DestroyRenderPipeline(id) => {
403403
self.render_pipeline_destroy::<B>(id);
404404
}
405+
A::CreateMeshPipeline { id, desc } => {
406+
let task_stage = desc.task_stage.map(OwnedProgrammableStage::from);
407+
let mesh_stage = OwnedProgrammableStage::from(desc.mesh_stage);
408+
let fragment_stage = desc.fragment_stage.map(OwnedProgrammableStage::from);
409+
self.device_maintain_ids::<B>(device);
410+
self.device_create_mesh_pipeline::<B>(
411+
device,
412+
&wgc::pipeline::MeshPipelineDescriptor {
413+
layout: desc.layout,
414+
task_stage: task_stage.as_ref().map_or(ptr::null(), |s| &s.desc),
415+
mesh_stage: mesh_stage.desc,
416+
fragment_stage: fragment_stage.as_ref().map_or(ptr::null(), |s| &s.desc),
417+
primitive_topology: desc.primitive_topology,
418+
rasterization_state: desc
419+
.rasterization_state
420+
.as_ref()
421+
.map_or(ptr::null(), |rs| rs),
422+
color_states: desc.color_states.as_ptr(),
423+
color_states_length: desc.color_states.len(),
424+
depth_stencil_state: desc
425+
.depth_stencil_state
426+
.as_ref()
427+
.map_or(ptr::null(), |ds| ds),
428+
sample_count: desc.sample_count,
429+
sample_mask: desc.sample_mask,
430+
alpha_to_coverage_enabled: desc.alpha_to_coverage_enabled,
431+
},
432+
id,
433+
);
434+
}
435+
A::DestroyMeshPipeline(id) => {
436+
self.mesh_pipeline_destroy::<B>(id);
437+
}
405438
A::WriteBuffer {
406439
id,
407440
data,

wgpu-core/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ bitflags = "1.0"
2828
copyless = "0.1"
2929
fxhash = "0.2"
3030
log = "0.4"
31-
hal = { package = "gfx-hal", version = "0.5" }
32-
gfx-backend-empty = "0.5"
33-
gfx-descriptor = "0.1"
34-
gfx-memory = "0.1"
31+
hal = { package = "gfx-hal", path = "../../gfx/src/hal", version = "0.5" }
32+
gfx-backend-empty = { path = "../../gfx/src/backend/empty", version = "0.5" }
33+
gfx-descriptor = { path = "../../gfx-extras/gfx-descriptor", version = "0.1" }
34+
gfx-memory = { path = "../../gfx-extras/gfx-memory", version = "0.1" }
3535
parking_lot = "0.10"
3636
peek-poke = "0.2"
3737
raw-window-handle = { version = "0.3", optional = true }
@@ -52,16 +52,16 @@ version = "0.5"
5252
features = ["peek-poke"]
5353

5454
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
55-
gfx-backend-metal = { version = "0.5" }
56-
gfx-backend-vulkan = { version = "0.5", optional = true }
55+
gfx-backend-metal = { path = "../../gfx/src/backend/metal", version = "0.5" }
56+
gfx-backend-vulkan = { path = "../../gfx/src/backend/vulkan", version = "0.5", optional = true }
5757

5858
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
59-
gfx-backend-vulkan = { version = "0.5", features = ["x11"] }
59+
gfx-backend-vulkan = { path = "../../gfx/src/backend/vulkan", version = "0.5", features = ["x11"] }
6060

6161
[target.'cfg(windows)'.dependencies]
62-
gfx-backend-dx12 = { version = "0.5" }
63-
gfx-backend-dx11 = { version = "0.5" }
64-
gfx-backend-vulkan = { version = "0.5" }
62+
gfx-backend-dx12 = { path = "../../gfx/src/backend/dx12", version = "0.5" }
63+
gfx-backend-dx11 = { path = "../../gfx/src/backend/dx11", version = "0.5" }
64+
gfx-backend-vulkan = { path = "../../gfx/src/backend/vulkan", version = "0.5" }
6565

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

wgpu-core/src/command/render.rs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub enum RenderCommand {
6767
phantom_offsets: PhantomSlice<DynamicOffset>,
6868
},
6969
SetPipeline(id::RenderPipelineId),
70+
SetMeshPipeline(id::RenderPipelineId),
7071
SetIndexBuffer {
7172
buffer_id: id::BufferId,
7273
offset: BufferAddress,
@@ -108,6 +109,9 @@ pub enum RenderCommand {
108109
buffer_id: id::BufferId,
109110
offset: BufferAddress,
110111
},
112+
DrawMeshTasks {
113+
tasks_count: u32,
114+
},
111115
End,
112116
}
113117

@@ -820,7 +824,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
820824
.map(|resolve| view_guard[resolve].format)
821825
.collect(),
822826
depth_stencil: depth_stencil_attachment.map(|at| view_guard[at.attachment].format),
823-
};
827+
};
828+
824829
(context, sample_count)
825830
};
826831

@@ -847,6 +852,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
847852
first_vertex: 0,
848853
first_instance: 0,
849854
};
855+
850856
loop {
851857
assert!(
852858
unsafe { peeker.add(RenderCommand::max_size()) <= raw_data_end },
@@ -887,6 +893,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
887893
.bind_groups
888894
.use_extend(&*bind_group_guard, bind_group_id, (), ())
889895
.unwrap();
896+
890897
assert_eq!(bind_group.dynamic_count, offsets.len());
891898

892899
trackers.merge_extend(&bind_group.used);
@@ -1017,6 +1024,69 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
10171024
}
10181025
state.vertex.update_limits();
10191026
}
1027+
RenderCommand::SetMeshPipeline(pipeline_id) => {
1028+
state.pipeline = OptionalState::Set;
1029+
let pipeline = trackers
1030+
.render_pipes
1031+
.use_extend(&*pipeline_guard, pipeline_id, (), ())
1032+
.unwrap();
1033+
1034+
assert!(
1035+
context.compatible(&pipeline.pass_context),
1036+
"The mesh pipeline is not compatible with the pass!"
1037+
);
1038+
assert_eq!(
1039+
pipeline.sample_count, sample_count,
1040+
"The mesh pipeline and renderpass have mismatching sample_count"
1041+
);
1042+
1043+
state
1044+
.blend_color
1045+
.require(pipeline.flags.contains(PipelineFlags::BLEND_COLOR));
1046+
state
1047+
.stencil_reference
1048+
.require(pipeline.flags.contains(PipelineFlags::STENCIL_REFERENCE));
1049+
1050+
unsafe {
1051+
raw.bind_graphics_pipeline(&pipeline.raw);
1052+
}
1053+
1054+
// Rebind resource
1055+
if state.binder.pipeline_layout_id != Some(pipeline.layout_id.value) {
1056+
let pipeline_layout = &pipeline_layout_guard[pipeline.layout_id.value];
1057+
state.binder.pipeline_layout_id = Some(pipeline.layout_id.value);
1058+
state
1059+
.binder
1060+
.reset_expectations(pipeline_layout.bind_group_layout_ids.len());
1061+
let mut is_compatible = true;
1062+
1063+
for (index, (entry, bgl_id)) in state
1064+
.binder
1065+
.entries
1066+
.iter_mut()
1067+
.zip(&pipeline_layout.bind_group_layout_ids)
1068+
.enumerate()
1069+
{
1070+
match entry.expect_layout(bgl_id.value) {
1071+
LayoutChange::Match(bg_id, offsets) if is_compatible => {
1072+
let desc_set = bind_group_guard[bg_id].raw.raw();
1073+
unsafe {
1074+
raw.bind_graphics_descriptor_sets(
1075+
&pipeline_layout.raw,
1076+
index,
1077+
iter::once(desc_set),
1078+
offsets.iter().cloned(),
1079+
);
1080+
}
1081+
}
1082+
LayoutChange::Match(..) | LayoutChange::Unchanged => {}
1083+
LayoutChange::Mismatch => {
1084+
is_compatible = false;
1085+
}
1086+
}
1087+
}
1088+
}
1089+
}
10201090
RenderCommand::SetIndexBuffer {
10211091
buffer_id,
10221092
offset,
@@ -1210,6 +1280,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
12101280
raw.draw_indexed_indirect(&buffer.raw, offset, 1, 0);
12111281
}
12121282
}
1283+
RenderCommand::DrawMeshTasks {
1284+
tasks_count,
1285+
} => {
1286+
state.is_ready().unwrap();
1287+
unsafe {
1288+
raw.draw_mesh_tasks(
1289+
tasks_count,
1290+
0,
1291+
);
1292+
}
1293+
}
12131294
RenderCommand::End => break,
12141295
}
12151296
}
@@ -1311,6 +1392,14 @@ pub mod render_ffi {
13111392
pass.encode(&RenderCommand::SetPipeline(pipeline_id));
13121393
}
13131394

1395+
#[no_mangle]
1396+
pub unsafe extern "C" fn wgpu_render_pass_set_mesh_pipeline(
1397+
pass: &mut RawPass,
1398+
pipeline_id: id::RenderPipelineId,
1399+
) {
1400+
pass.encode(&RenderCommand::SetMeshPipeline(pipeline_id));
1401+
}
1402+
13141403
#[no_mangle]
13151404
pub unsafe extern "C" fn wgpu_render_pass_set_index_buffer(
13161405
pass: &mut RawPass,
@@ -1434,6 +1523,16 @@ pub mod render_ffi {
14341523
pass.encode(&RenderCommand::DrawIndexedIndirect { buffer_id, offset });
14351524
}
14361525

1526+
#[no_mangle]
1527+
pub unsafe extern "C" fn wgpu_render_pass_draw_mesh_tasks(
1528+
pass: &mut RawPass,
1529+
tasks_count: u32,
1530+
) {
1531+
pass.encode(&RenderCommand::DrawMeshTasks {
1532+
tasks_count
1533+
});
1534+
}
1535+
14371536
#[no_mangle]
14381537
pub extern "C" fn wgpu_render_pass_execute_bundles(
14391538
_pass: &mut RawPass,

wgpu-core/src/conv.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ pub fn map_shader_stage_flags(shader_stage_flags: wgt::ShaderStage) -> hal::pso:
126126
if shader_stage_flags.contains(Ss::COMPUTE) {
127127
value |= H::COMPUTE;
128128
}
129+
if shader_stage_flags.contains(Ss::TASK) {
130+
value |= H::TASK;
131+
}
132+
if shader_stage_flags.contains(Ss::MESH) {
133+
value |= H::MESH;
134+
}
129135
value
130136
}
131137

0 commit comments

Comments
 (0)