Skip to content
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

Mesh shaders - initial wgpu hal changes #7089

Open
wants to merge 17 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 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
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
26 changes: 26 additions & 0 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,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 @@ -1188,6 +1196,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 @@ -1228,6 +1244,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 @@ -1881,6 +1881,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 @@ -129,6 +129,12 @@ pub trait DynCommandEncoder: DynResource + std::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 @@ -141,6 +147,12 @@ pub trait DynCommandEncoder: DynResource + std::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 @@ -157,6 +169,14 @@ pub trait DynCommandEncoder: DynResource + std::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 @@ -460,6 +480,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 @@ -480,6 +509,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 @@ -517,6 +556,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 @@ -2,10 +2,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 @@ -98,6 +98,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 @@ -391,6 +399,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
33 changes: 33 additions & 0 deletions wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ impl crate::Device for Context {
) -> Result<Resource, crate::PipelineError> {
Ok(Resource)
}
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<Resource, crate::PipelineError> {
Ok(Resource)
}
unsafe fn destroy_render_pipeline(&self, pipeline: Resource) {}
unsafe fn create_compute_pipeline(
&self,
Expand Down Expand Up @@ -452,6 +462,13 @@ impl crate::CommandEncoder for Encoder {
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: &Resource,
Expand All @@ -466,6 +483,13 @@ impl crate::CommandEncoder for Encoder {
draw_count: u32,
) {
}
unsafe fn draw_mesh_tasks_indirect(
&mut self,
buffer: &<Self::A as crate::Api>::Buffer,
offset: wgt::BufferAddress,
draw_count: u32,
) {
}
unsafe fn draw_indirect_count(
&mut self,
buffer: &Resource,
Expand All @@ -484,6 +508,15 @@ impl crate::CommandEncoder for Encoder {
max_count: u32,
) {
}
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,
) {
}

// compute

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 @@ -1074,6 +1074,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 @@ -1117,6 +1125,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 @@ -1137,6 +1153,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 @@ -1416,6 +1416,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
Loading