Refactor: Skip max velocity computation for single values

This patch skips the max velocity computation for single value velocity
inputs in the Vector Blur node. It just returns the velocity as is. The
patch also clarifies the names of some functions/variables to match the
CPU code.

Pull Request: https://projects.blender.org/blender/blender/pulls/162529
This commit is contained in:
Omar Emara 2026-08-10 13:55:15 +02:00 • committed by Omar Emara
parent 7c4588736d
commit 7a3c23b71b

View file

@ -525,8 +525,8 @@ class VectorBlurOperation : public NodeOperation {
void execute_gpu()
{
Result max_tile_velocity = this->compute_max_tile_velocity();
gpu::StorageBuf *tile_indirection_buffer = this->dilate_max_velocity(max_tile_velocity);
Result max_tile_velocity = this->compute_max_tile_velocity_gpu();
gpu::StorageBuf *tile_indirection_buffer = this->dilate_max_velocity_gpu(max_tile_velocity);
this->compute_motion_blur(max_tile_velocity, tile_indirection_buffer);
max_tile_velocity.release();
GPU_storagebuf_free(tile_indirection_buffer);
@ -534,25 +534,32 @@ class VectorBlurOperation : public NodeOperation {
/* Reduces each 32x32 block of velocity pixels into a single velocity whose magnitude is largest.
* Each of the previous and next velocities are reduces independently. */
Result compute_max_tile_velocity()
Result compute_max_tile_velocity_gpu()
{
Result &velocity = get_input("Speed");
if (velocity.is_single_value()) {
Result output = this->context().create_result(ResultType::Float4);
output.allocate_single_value();
output.set_single_value(velocity.get_single_value<float4>());
return output;
}
gpu::Shader *shader = context().get_shader("compositor_max_velocity");
GPU_shader_bind(shader);
GPU_shader_uniform_1b(shader, "is_initial_reduction", true);
Result &input = get_input("Speed");
input.bind_as_texture(shader, "input_tx");
velocity.bind_as_texture(shader, "input_tx");
Result output = context().create_result(ResultType::Float4);
const int2 tiles_count = math::divide_ceil(input.domain().data_size, int2(32));
const int2 tiles_count = math::divide_ceil(velocity.domain().data_size, int2(32));
output.allocate_texture(Domain(tiles_count));
output.bind_as_image(shader, "output_img");
GPU_compute_dispatch(shader, tiles_count.x, tiles_count.y, 1);
GPU_shader_unbind();
input.unbind_as_texture();
velocity.unbind_as_texture();
output.unbind_as_image();
return output;
@ -564,7 +571,7 @@ class VectorBlurOperation : public NodeOperation {
* the output will be an indirection buffer that points to a particular tile in the original max
* tile velocity image. This is done as a form of performance optimization, see the shader for
* more information. */
gpu::StorageBuf *dilate_max_velocity(Result &max_tile_velocity)
gpu::StorageBuf *dilate_max_velocity_gpu(Result &max_tile_velocity)
{
gpu::Shader *shader = context().get_shader("compositor_motion_blur_max_velocity_dilate");
GPU_shader_bind(shader);