Skip to content

Conversation

@andyleiserson
Copy link
Contributor

As noted in the description of 7e0eac3, the order of arguments to various set_* functions is different between metal and objc2-metal. To avoid possible confusion, this gives the variables passed for those arguments descriptive names rather than a1/a2/a3.

Since the long names would cause lines to split (presumably this was part of the reason for the short names originally), also introduce a helper to recover some characters and avoid that.

Preparation for #5641. CC @madsmtm.

Testing
Refactor, relying on existing tests.

Squash or Rebase? Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

* Give the `set_*` arguments descriptive names.
* Introduce a helper to recover some characters so the preceding change
  does not cause lines to split.
Copy link
Collaborator

@inner-daemons inner-daemons left a comment

Choose a reason for hiding this comment

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

Thanks for pinging me on this one, this is definitely the direction we want to be heading here. A number of places, some of which I didn't comment on, where we could maybe move the big match blocks to an out-of-the-way function. Otherwise LGTM

Comment on lines -149 to -154
#[expect(clippy::too_many_arguments)]
fn update_bind_group_state(
&mut self,
stage: naga::ShaderStage,
render_encoder: Option<&metal::RenderCommandEncoder>,
compute_encoder: Option<&metal::ComputeCommandEncoder>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Glad we've been able to get rid of some of this!

Comment on lines 208 to 212
E::Vertex(encoder) => encoder.set_vertex_buffer(index, buf_ptr, offset),
E::Fragment(encoder) => encoder.set_fragment_buffer(index, buf_ptr, offset),
E::Task(encoder) => encoder.set_object_buffer(index, buf_ptr, offset),
E::Mesh(encoder) => encoder.set_mesh_buffer(index, buf_ptr, offset),
E::Compute(encoder) => encoder.set_buffer(index, buf_ptr, offset),
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's some new and somewhat similar logic for mesh pipeline creation that was handled in #8139, although I doubt it would be applicable here. Still, maybe we could move this into a function on the encoder to simplify this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is the logic from #8139?

My preference would be to defer additional refactoring (extracting these to encoder methods) until after objc2 lands, to minimize conflict resolution. Do you mind putting it off for a bit? I can file an issue so I don't forget.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really mind. Yeah most of the code I'm commenting on is originally mine, but since you introduced the Encoder struct, I'm thinking we might as well use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see what you mean now. In my head I was thinking of something more complicated -- while working on this I started looking at changing the encoder Options in CommandState to an enum, but realized that was going to be a much bigger change. When I first read your comment I was thinking of something like that.

Moving them onto Encoder isn't that bad, I'll just do it.

Comment on lines -182 to -184
let a1 = (resource_indices.buffers + index) as u64;
let a2 = Some(buf.ptr.as_native());
let a3 = offset;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eww gross, glad we got rid of "a1, a2, a3"

Comment on lines 231 to 236
match encoder {
E::Vertex(encoder) => encoder.set_vertex_bytes(index, length, bytes_ptr),
E::Fragment(encoder) => encoder.set_fragment_bytes(index, length, bytes_ptr),
E::Task(encoder) => encoder.set_object_bytes(index, length, bytes_ptr),
E::Mesh(encoder) => encoder.set_mesh_bytes(index, length, bytes_ptr),
E::Compute(encoder) => encoder.set_bytes(index, length, bytes_ptr),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, lets put this on Encoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants