Skip to content

Mesh shaders - initial wgpu hal changes #7089

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f7e6e18
Initial(untested commit), vulkan and gles only supported
SupaMaggie70Incorporated Jan 17, 2025
4e5772b
Maybe fixed compiles for metal and dx12
SupaMaggie70Incorporated Jan 18, 2025
a5f8909
Merge branch 'gfx-rs:trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Jan 18, 2025
ab83fa7
Hopefully fixed compiles for other backends and updated to functional…
SupaMaggie70Incorporated Jan 18, 2025
0b2bb72
I don't get git
SupaMaggie70Incorporated Jan 18, 2025
06d3f52
Fixed the clippy warning
SupaMaggie70Incorporated Jan 18, 2025
1939260
Merge recent changes, most significantly features type overhaul
SupaMaggie70Incorporated Feb 8, 2025
5a66eab
Fixed silly documentation mistake
SupaMaggie70Incorporated Feb 9, 2025
4840189
Fixed issue with multiview feature
SupaMaggie70Incorporated Feb 13, 2025
6c2c9ac
Dummy commit for dummy CI
SupaMaggie70Incorporated Feb 13, 2025
8c07665
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 13, 2025
fd54843
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 14, 2025
d145778
Re trigger CI checks, to avoid #7126
SupaMaggie70Incorporated Feb 14, 2025
e67c399
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 14, 2025
d34935e
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 14, 2025
bd9fa21
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 14, 2025
34cc46a
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 15, 2025
e6f9d94
Changes based on code review
SupaMaggie70Incorporated Feb 22, 2025
64907d3
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 22, 2025
e4e2651
Fixed clippy warning, broken cargo.lock
SupaMaggie70Incorporated Feb 22, 2025
d725d95
Unfucked cargo.lock for real this time
SupaMaggie70Incorporated Feb 22, 2025
08b31da
Switched match to if-let in accordance with review
SupaMaggie70Incorporated Feb 25, 2025
7e979cb
Updated changelog
SupaMaggie70Incorporated Feb 26, 2025
68e31ea
Merge branch 'gfx-rs:trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Feb 26, 2025
f28dbc2
Fix CI error
SupaMaggie70Incorporated Feb 26, 2025
8f9e4e1
CI is very angry 😡
SupaMaggie70Incorporated Feb 26, 2025
38063e5
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Mar 2, 2025
7582bfa
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Mar 3, 2025
30c7722
Removed comment in following request
SupaMaggie70Incorporated Mar 3, 2025
6b285cf
Update wgpu-hal/src/vulkan/adapter.rs
cwfitzgerald Mar 3, 2025
76a6768
Merge branch 'trunk' into mesh-shading/wgpu-hal
SupaMaggie70Incorporated Mar 4, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ By @jamienicol in [#6929](https://github.com/gfx-rs/wgpu/pull/6929) and [#7080](

### New Features

- Added mesh shader support to `wgpu_hal`. By @SupaMaggie70Incorporated in [#7089](https://github.com/gfx-rs/wgpu/pull/7089)

#### General

- It is now possible to create a dummy `wgpu` device even when no GPU is available. This may be useful for testing of code which manages graphics resources. Currently, it supports reading and writing buffers, and other resource types can be created but do nothing.
Expand Down
26 changes: 26 additions & 0 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,14 @@ impl crate::CommandEncoder for super::CommandEncoder {
)
}
}
unsafe fn draw_mesh_tasks(
&mut self,
_group_count_x: u32,
_group_count_y: u32,
_group_count_z: u32,
) {
unreachable!()
}
unsafe fn draw_indirect(
&mut self,
buffer: &super::Buffer,
Expand Down Expand Up @@ -1215,6 +1223,14 @@ impl crate::CommandEncoder for super::CommandEncoder {
)
}
}
unsafe fn draw_mesh_tasks_indirect(
&mut self,
_buffer: &<Self::A as crate::Api>::Buffer,
_offset: wgt::BufferAddress,
_draw_count: u32,
) {
unreachable!()
}
unsafe fn draw_indirect_count(
&mut self,
buffer: &super::Buffer,
Expand Down Expand Up @@ -1255,6 +1271,16 @@ impl crate::CommandEncoder for super::CommandEncoder {
)
}
}
unsafe fn draw_mesh_tasks_indirect_count(
&mut self,
_buffer: &<Self::A as crate::Api>::Buffer,
_offset: wgt::BufferAddress,
_count_buffer: &<Self::A as crate::Api>::Buffer,
_count_offset: wgt::BufferAddress,
_max_count: u32,
) {
unreachable!()
}

// compute

Expand Down
12 changes: 12 additions & 0 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,18 @@ impl crate::Device for super::Device {
vertex_strides,
})
}

unsafe fn create_mesh_pipeline(
&self,
_desc: &crate::MeshPipelineDescriptor<
<Self::A as crate::Api>::PipelineLayout,
<Self::A as crate::Api>::ShaderModule,
<Self::A as crate::Api>::PipelineCache,
>,
) -> Result<<Self::A as crate::Api>::RenderPipeline, crate::PipelineError> {
unreachable!()
}

unsafe fn destroy_render_pipeline(&self, _pipeline: super::RenderPipeline) {
self.counters.render_pipelines.sub(1);
}
Expand Down
61 changes: 61 additions & 0 deletions wgpu-hal/src/dynamic/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ pub trait DynCommandEncoder: DynResource + core::fmt::Debug {
first_instance: u32,
instance_count: u32,
);
unsafe fn draw_mesh_tasks(
&mut self,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32,
);
unsafe fn draw_indirect(
&mut self,
buffer: &dyn DynBuffer,
Expand All @@ -142,6 +148,12 @@ pub trait DynCommandEncoder: DynResource + core::fmt::Debug {
offset: wgt::BufferAddress,
draw_count: u32,
);
unsafe fn draw_mesh_tasks_indirect(
&mut self,
buffer: &dyn DynBuffer,
offset: wgt::BufferAddress,
draw_count: u32,
);
unsafe fn draw_indirect_count(
&mut self,
buffer: &dyn DynBuffer,
Expand All @@ -158,6 +170,14 @@ pub trait DynCommandEncoder: DynResource + core::fmt::Debug {
count_offset: wgt::BufferAddress,
max_count: u32,
);
unsafe fn draw_mesh_tasks_indirect_count(
&mut self,
buffer: &dyn DynBuffer,
offset: wgt::BufferAddress,
count_buffer: &dyn DynBuffer,
count_offset: wgt::BufferAddress,
max_count: u32,
);

unsafe fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor<dyn DynQuerySet>);
unsafe fn end_compute_pass(&mut self);
Expand Down Expand Up @@ -473,6 +493,15 @@ impl<C: CommandEncoder + DynResource> DynCommandEncoder for C {
};
}

unsafe fn draw_mesh_tasks(
&mut self,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32,
) {
unsafe { C::draw_mesh_tasks(self, group_count_x, group_count_y, group_count_z) };
}

unsafe fn draw_indirect(
&mut self,
buffer: &dyn DynBuffer,
Expand All @@ -493,6 +522,16 @@ impl<C: CommandEncoder + DynResource> DynCommandEncoder for C {
unsafe { C::draw_indexed_indirect(self, buffer, offset, draw_count) };
}

unsafe fn draw_mesh_tasks_indirect(
&mut self,
buffer: &dyn DynBuffer,
offset: wgt::BufferAddress,
draw_count: u32,
) {
let buffer = buffer.expect_downcast_ref();
unsafe { C::draw_mesh_tasks_indirect(self, buffer, offset, draw_count) };
}

unsafe fn draw_indirect_count(
&mut self,
buffer: &dyn DynBuffer,
Expand Down Expand Up @@ -530,6 +569,28 @@ impl<C: CommandEncoder + DynResource> DynCommandEncoder for C {
};
}

unsafe fn draw_mesh_tasks_indirect_count(
&mut self,
buffer: &dyn DynBuffer,
offset: wgt::BufferAddress,
count_buffer: &dyn DynBuffer,
count_offset: wgt::BufferAddress,
max_count: u32,
) {
let buffer = buffer.expect_downcast_ref();
let count_buffer = count_buffer.expect_downcast_ref();
unsafe {
C::draw_mesh_tasks_indirect_count(
self,
buffer,
offset,
count_buffer,
count_offset,
max_count,
)
};
}

unsafe fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor<dyn DynQuerySet>) {
let desc = ComputePassDescriptor {
label: desc.label,
Expand Down
42 changes: 38 additions & 4 deletions wgpu-hal/src/dynamic/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
AccelerationStructureBuildSizes, AccelerationStructureDescriptor, Api, BindGroupDescriptor,
BindGroupLayoutDescriptor, BufferDescriptor, BufferMapping, CommandEncoderDescriptor,
ComputePipelineDescriptor, Device, DeviceError, FenceValue,
GetAccelerationStructureBuildSizesDescriptor, Label, MemoryRange, PipelineCacheDescriptor,
PipelineCacheError, PipelineError, PipelineLayoutDescriptor, RenderPipelineDescriptor,
SamplerDescriptor, ShaderError, ShaderInput, ShaderModuleDescriptor, TextureDescriptor,
TextureViewDescriptor, TlasInstance,
GetAccelerationStructureBuildSizesDescriptor, Label, MemoryRange, MeshPipelineDescriptor,
PipelineCacheDescriptor, PipelineCacheError, PipelineError, PipelineLayoutDescriptor,
RenderPipelineDescriptor, SamplerDescriptor, ShaderError, ShaderInput, ShaderModuleDescriptor,
TextureDescriptor, TextureViewDescriptor, TlasInstance,
};

use super::{
Expand Down Expand Up @@ -100,6 +100,14 @@ pub trait DynDevice: DynResource {
dyn DynPipelineCache,
>,
) -> Result<Box<dyn DynRenderPipeline>, PipelineError>;
unsafe fn create_mesh_pipeline(
&self,
desc: &MeshPipelineDescriptor<
dyn DynPipelineLayout,
dyn DynShaderModule,
dyn DynPipelineCache,
>,
) -> Result<Box<dyn DynRenderPipeline>, PipelineError>;
unsafe fn destroy_render_pipeline(&self, pipeline: Box<dyn DynRenderPipeline>);

unsafe fn create_compute_pipeline(
Expand Down Expand Up @@ -393,6 +401,32 @@ impl<D: Device + DynResource> DynDevice for D {
.map(|b| -> Box<dyn DynRenderPipeline> { Box::new(b) })
}

unsafe fn create_mesh_pipeline(
&self,
desc: &MeshPipelineDescriptor<
dyn DynPipelineLayout,
dyn DynShaderModule,
dyn DynPipelineCache,
>,
) -> Result<Box<dyn DynRenderPipeline>, PipelineError> {
let desc = MeshPipelineDescriptor {
label: desc.label,
layout: desc.layout.expect_downcast_ref(),
task_stage: desc.task_stage.clone().map(|f| f.expect_downcast()),
mesh_stage: desc.mesh_stage.clone().expect_downcast(),
primitive: desc.primitive,
depth_stencil: desc.depth_stencil.clone(),
multisample: desc.multisample,
fragment_stage: desc.fragment_stage.clone().map(|f| f.expect_downcast()),
color_targets: desc.color_targets,
multiview: desc.multiview,
cache: desc.cache.map(|c| c.expect_downcast_ref()),
};

unsafe { D::create_mesh_pipeline(self, &desc) }
.map(|b| -> Box<dyn DynRenderPipeline> { Box::new(b) })
}

unsafe fn destroy_render_pipeline(&self, pipeline: Box<dyn DynRenderPipeline>) {
unsafe { D::destroy_render_pipeline(self, pipeline.unbox()) };
}
Expand Down
26 changes: 26 additions & 0 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,14 @@ impl crate::CommandEncoder for super::CommandEncoder {
first_instance_location: self.state.first_instance_location.clone(),
});
}
unsafe fn draw_mesh_tasks(
&mut self,
_group_count_x: u32,
_group_count_y: u32,
_group_count_z: u32,
) {
unreachable!()
}
unsafe fn draw_indirect(
&mut self,
buffer: &super::Buffer,
Expand Down Expand Up @@ -1116,6 +1124,14 @@ impl crate::CommandEncoder for super::CommandEncoder {
});
}
}
unsafe fn draw_mesh_tasks_indirect(
&mut self,
_buffer: &<Self::A as crate::Api>::Buffer,
_offset: wgt::BufferAddress,
_draw_count: u32,
) {
unreachable!()
}
unsafe fn draw_indirect_count(
&mut self,
_buffer: &super::Buffer,
Expand All @@ -1136,6 +1152,16 @@ impl crate::CommandEncoder for super::CommandEncoder {
) {
unreachable!()
}
unsafe fn draw_mesh_tasks_indirect_count(
&mut self,
_buffer: &<Self::A as crate::Api>::Buffer,
_offset: wgt::BufferAddress,
_count_buffer: &<Self::A as crate::Api>::Buffer,
_count_offset: wgt::BufferAddress,
_max_count: u32,
) {
unreachable!()
}

// compute

Expand Down
10 changes: 10 additions & 0 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,16 @@ impl crate::Device for super::Device {
alpha_to_coverage_enabled: desc.multisample.alpha_to_coverage_enabled,
})
}
unsafe fn create_mesh_pipeline(
&self,
_desc: &crate::MeshPipelineDescriptor<
<Self::A as crate::Api>::PipelineLayout,
<Self::A as crate::Api>::ShaderModule,
<Self::A as crate::Api>::PipelineCache,
>,
) -> Result<<Self::A as crate::Api>::RenderPipeline, crate::PipelineError> {
unreachable!()
}

unsafe fn destroy_render_pipeline(&self, pipeline: super::RenderPipeline) {
// If the pipeline only has 2 strong references remaining, they're `pipeline` and `program_cache`
Expand Down
59 changes: 58 additions & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ use wgt::WasmNotSendSync;

// - Vertex + Fragment
// - Compute
pub const MAX_CONCURRENT_SHADER_STAGES: usize = 2;
// Task + Mesh + Fragment
pub const MAX_CONCURRENT_SHADER_STAGES: usize = 3;
pub const MAX_ANISOTROPY: u8 = 16;
pub const MAX_BIND_GROUPS: usize = 8;
pub const MAX_VERTEX_BUFFERS: usize = 16;
Expand Down Expand Up @@ -901,6 +902,15 @@ pub trait Device: WasmNotSendSync {
<Self::A as Api>::PipelineCache,
>,
) -> Result<<Self::A as Api>::RenderPipeline, PipelineError>;
#[allow(clippy::type_complexity)]
unsafe fn create_mesh_pipeline(
&self,
desc: &MeshPipelineDescriptor<
<Self::A as Api>::PipelineLayout,
<Self::A as Api>::ShaderModule,
<Self::A as Api>::PipelineCache,
>,
) -> Result<<Self::A as Api>::RenderPipeline, PipelineError>;
unsafe fn destroy_render_pipeline(&self, pipeline: <Self::A as Api>::RenderPipeline);

#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -1458,6 +1468,26 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
count_offset: wgt::BufferAddress,
max_count: u32,
);
unsafe fn draw_mesh_tasks(
&mut self,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32,
);
unsafe fn draw_mesh_tasks_indirect(
&mut self,
buffer: &<Self::A as Api>::Buffer,
offset: wgt::BufferAddress,
draw_count: u32,
);
unsafe fn draw_mesh_tasks_indirect_count(
&mut self,
buffer: &<Self::A as Api>::Buffer,
offset: wgt::BufferAddress,
count_buffer: &<Self::A as Api>::Buffer,
count_offset: wgt::BufferAddress,
max_count: u32,
);

// compute passes

Expand Down Expand Up @@ -2158,6 +2188,33 @@ pub struct RenderPipelineDescriptor<
/// The cache which will be used and filled when compiling this pipeline
pub cache: Option<&'a Pc>,
}
pub struct MeshPipelineDescriptor<
'a,
Pl: DynPipelineLayout + ?Sized,
M: DynShaderModule + ?Sized,
Pc: DynPipelineCache + ?Sized,
> {
pub label: Label<'a>,
/// The layout of bind groups for this pipeline.
pub layout: &'a Pl,
pub task_stage: Option<ProgrammableStage<'a, M>>,
pub mesh_stage: ProgrammableStage<'a, M>,
/// The properties of the pipeline at the primitive assembly and rasterization level.
pub primitive: wgt::PrimitiveState,
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
pub depth_stencil: Option<wgt::DepthStencilState>,
/// The multi-sampling properties of the pipeline.
pub multisample: wgt::MultisampleState,
/// The fragment stage for this pipeline.
pub fragment_stage: Option<ProgrammableStage<'a, M>>,
/// The effect of draw calls on the color aspect of the output target.
pub color_targets: &'a [Option<wgt::ColorTargetState>],
/// If the pipeline will be used with a multiview render pass, this indicates how many array
/// layers the attachments will have.
pub multiview: Option<NonZeroU32>,
/// The cache which will be used and filled when compiling this pipeline
pub cache: Option<&'a Pc>,
}

#[derive(Debug, Clone)]
pub struct SurfaceConfiguration {
Expand Down
Loading