Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions impeller/renderer/backend/metal/compute_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ static bool Bind(ComputePassBindingsCache& pass,

// Special case for linear processing.
if (height == 1) {
int64_t threadGroups =
std::max(width / maxTotalThreadsPerThreadgroup, 1LL);
int64_t threadGroups = std::max(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Forgot these were ints so we were capped at 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Doing so required me to update the vulkan compute shaders to provide a specialization constant which contains the actual wg size, as these need to agree with the value in compute_pass.vk for anything to work correctly.

static_cast<int64_t>(
std::ceil(width * 1.0 / maxTotalThreadsPerThreadgroup * 1.0)),
1LL);
[encoder dispatchThreadgroups:MTLSizeMake(threadGroups, 1, 1)
threadsPerThreadgroup:MTLSizeMake(maxTotalThreadsPerThreadgroup,
1, 1)];
Expand Down
21 changes: 14 additions & 7 deletions impeller/renderer/backend/vulkan/compute_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,21 @@ bool ComputePassVK::OnEncodeCommands(const Context& context,
int64_t width = grid_size.width;
int64_t height = grid_size.height;

while (width > max_wg_size[0]) {
width = std::max(static_cast<int64_t>(1), width / 2);
// Special case for linear processing.
if (height == 1) {
int64_t threadGroups = std::max(
static_cast<int64_t>(std::ceil(width * 1.0 / max_wg_size[0] * 1.0)),
1LL);
cmd_buffer.dispatch(threadGroups, 1, 1);
} else {
while (width > max_wg_size[0]) {
width = std::max(static_cast<int64_t>(1), width / 2);
}
while (height > max_wg_size[1]) {
height = std::max(static_cast<int64_t>(1), height / 2);
}
cmd_buffer.dispatch(width, height, 1);
}
while (height > max_wg_size[1]) {
height = std::max(static_cast<int64_t>(1), height / 2);
}

cmd_buffer.dispatch(width, height, 1);
}
}

Expand Down