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

Add and implement dispatch indirect #244

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions blade-graphics/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
.push(super::Command::SetViewport(viewport.clone()));
}

fn set_stencil_reference(&mut self, reference: u32) {

Check warning on line 312 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 312 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
unimplemented!()
}
}
Expand Down Expand Up @@ -449,9 +449,17 @@

#[hidden_trait::expose]
impl crate::traits::ComputePipelineEncoder for super::PipelineEncoder<'_> {
type BufferPiece = crate::BufferPiece;

fn dispatch(&mut self, groups: [u32; 3]) {
self.commands.push(super::Command::Dispatch(groups));
}

fn dispatch_indirect(&mut self, indirect_buf: crate::BufferPiece) {
self.commands.push(super::Command::DispatchIndirect {
indirect_buf: indirect_buf.into(),
});
}
}

#[hidden_trait::expose]
Expand All @@ -465,7 +473,7 @@
.push(super::Command::SetViewport(viewport.clone()));
}

fn set_stencil_reference(&mut self, reference: u32) {

Check warning on line 476 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 476 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
unimplemented!()
}
}
Expand Down Expand Up @@ -821,10 +829,10 @@
gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, None);
}
Self::CopyTextureToBuffer {
ref src,

Check warning on line 832 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `src`

Check warning on line 832 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `src`
ref dst,

Check warning on line 833 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `dst`

Check warning on line 833 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `dst`
bytes_per_row,

Check warning on line 834 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `bytes_per_row`

Check warning on line 834 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `bytes_per_row`
ref size,

Check warning on line 835 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `size`

Check warning on line 835 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `size`
} => unimplemented!(),
Self::ResetFramebuffer => {
for &attachment in COLOR_ATTACHMENTS.iter() {
Expand Down Expand Up @@ -1048,9 +1056,9 @@
gl.scissor(rect.x, rect.y, rect.w as i32, rect.h as i32);
}
Self::SetStencilFunc {
face,

Check warning on line 1059 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `face`

Check warning on line 1059 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `face`
function,

Check warning on line 1060 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `function`

Check warning on line 1060 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `function`
reference,

Check warning on line 1061 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 1061 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
read_mask,
} => unimplemented!(),
Self::SetStencilOps {
Expand Down
13 changes: 13 additions & 0 deletions blade-graphics/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ impl crate::traits::PipelineEncoder for super::ComputePipelineContext<'_> {

#[hidden_trait::expose]
impl crate::traits::ComputePipelineEncoder for super::ComputePipelineContext<'_> {
type BufferPiece = crate::BufferPiece;

fn dispatch(&mut self, groups: [u32; 3]) {
let raw_count = metal::MTLSize {
width: groups[0] as usize,
Expand All @@ -721,6 +723,17 @@ impl crate::traits::ComputePipelineEncoder for super::ComputePipelineContext<'_>
self.encoder
.dispatchThreadgroups_threadsPerThreadgroup(raw_count, self.wg_size);
}

fn dispatch_indirect(&mut self, indirect_buf: crate::BufferPiece) {
unsafe {
self.encoder
.dispatchThreadgroupsWithIndirectBuffer_indirectBufferOffset_threadsPerThreadgroup(
indirect_buf.buffer.as_ref(),
indirect_buf.offset as usize,
self.wg_size,
);
}
}
}

impl Drop for super::ComputePipelineContext<'_> {
Expand Down
3 changes: 3 additions & 0 deletions blade-graphics/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ pub trait PipelineEncoder {
}

pub trait ComputePipelineEncoder: PipelineEncoder {
type BufferPiece: Send + Sync + Clone + Copy + Debug;

fn dispatch(&mut self, groups: [u32; 3]);
fn dispatch_indirect(&mut self, indirect_buf: Self::BufferPiece);
}

pub trait RenderPipelineEncoder: PipelineEncoder + RenderEncoder {
Expand Down
11 changes: 11 additions & 0 deletions blade-graphics/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,13 +940,24 @@ impl crate::traits::PipelineEncoder for super::PipelineEncoder<'_, '_> {

#[hidden_trait::expose]
impl crate::traits::ComputePipelineEncoder for super::PipelineEncoder<'_, '_> {
type BufferPiece = crate::BufferPiece;

fn dispatch(&mut self, groups: [u32; 3]) {
unsafe {
self.device
.core
.cmd_dispatch(self.cmd_buf.raw, groups[0], groups[1], groups[2])
};
}
fn dispatch_indirect(&mut self, indirect_buf: crate::BufferPiece) {
unsafe {
self.device.core.cmd_dispatch_indirect(
self.cmd_buf.raw,
indirect_buf.buffer.raw,
indirect_buf.offset,
)
};
}
}

#[hidden_trait::expose]
Expand Down
Loading