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

support push constants on metal #2258

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ impl super::PrivateCapabilities {
| F::MAPPABLE_PRIMARY_BUFFERS
| F::VERTEX_WRITABLE_STORAGE
| F::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES
| F::PUSH_CONSTANTS
| F::POLYGON_MODE_LINE
| F::CLEAR_COMMANDS;

Expand Down
22 changes: 21 additions & 1 deletion wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,27 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
_offset: u32,
_data: &[u32],
) {
//TODO
if _stages.contains(wgt::ShaderStages::COMPUTE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a tiny bit more complex.
The way it's supposed to work is if you have [u8; max_push_constants] array on the command encoder. set_push_constants would just overwrite some of these bytes, but the shaders would see as much as PipelineLayout have declared.

E.g. user could 0..4 with one set_push_constants and 4..8 with another call, and the shader needs to see all of them.

self.state.compute.as_ref().unwrap().set_bytes(
_offset as _,
(_data.len() * WORD_SIZE) as u64,
_data.as_ptr() as _,
)
}
if _stages.contains(wgt::ShaderStages::VERTEX) {
self.state.render.as_ref().unwrap().set_vertex_bytes(
_offset as _,
(_data.len() * WORD_SIZE) as u64,
_data.as_ptr() as _,
)
}
if _stages.contains(wgt::ShaderStages::FRAGMENT) {
self.state.render.as_ref().unwrap().set_fragment_bytes(
_offset as _,
(_data.len() * WORD_SIZE) as u64,
_data.as_ptr() as _,
)
}
}

unsafe fn insert_debug_marker(&mut self, label: &str) {
Expand Down