diff --git a/engine/src/flutter/impeller/compiler/shader_lib/impeller/path.glsl b/engine/src/flutter/impeller/compiler/shader_lib/impeller/path.glsl index 774648f345a..e0e0a969347 100644 --- a/engine/src/flutter/impeller/compiler/shader_lib/impeller/path.glsl +++ b/engine/src/flutter/impeller/compiler/shader_lib/impeller/path.glsl @@ -5,11 +5,6 @@ #ifndef PATH_GLSL_ #define PATH_GLSL_ -#define MOVE 0 -#define LINE 1 -#define QUAD 2 -#define CUBIC 3 - struct LineData { vec2 p1; vec2 p2; diff --git a/engine/src/flutter/impeller/fixtures/cubic_to_quads.comp b/engine/src/flutter/impeller/fixtures/cubic_to_quads.comp index 3748a7a0f39..a2249f56caf 100644 --- a/engine/src/flutter/impeller/fixtures/cubic_to_quads.comp +++ b/engine/src/flutter/impeller/fixtures/cubic_to_quads.comp @@ -28,6 +28,19 @@ config; shared uint quad_counts[512]; shared uint count_sums[512]; +uint ComputePosition(uint index) { + if (index < gl_SubgroupSize) { + return count_sums[index]; + } + int position = -1; + uint count_sum = count_sums[index]; + do { + position += int(gl_SubgroupSize); + count_sum += count_sums[position]; + } while (position < index); + return count_sum; +} + void main() { uint ident = gl_GlobalInvocationID.x; CubicData cubic; @@ -45,9 +58,9 @@ void main() { count_sums[ident] = subgroupInclusiveAdd(quad_counts[ident]); - quads.count = count_sums[cubics.count - 1]; + quads.count = ComputePosition(cubics.count - 1); + uint offset = ComputePosition(ident) - quad_count; for (uint i = 0; i < quad_count; i++) { - uint offset = count_sums[ident] - quad_count; quads.data[offset + i] = GenerateQuadraticFromCubic(cubic, i, quad_count); } } diff --git a/engine/src/flutter/impeller/fixtures/quad_polyline.comp b/engine/src/flutter/impeller/fixtures/quad_polyline.comp index b483da8e35a..e581775bbac 100644 --- a/engine/src/flutter/impeller/fixtures/quad_polyline.comp +++ b/engine/src/flutter/impeller/fixtures/quad_polyline.comp @@ -28,6 +28,19 @@ config; shared uint point_counts[512]; shared uint count_sums[512]; +uint ComputePosition(uint index) { + if (index < gl_SubgroupSize) { + return count_sums[index]; + } + int position = -1; + uint count_sum = count_sums[index]; + do { + position += int(gl_SubgroupSize); + count_sum += count_sums[position]; + } while (position < index); + return count_sum; +} + void main() { uint ident = gl_GlobalInvocationID.x; QuadData quad; @@ -45,15 +58,16 @@ void main() { } count_sums[ident] = subgroupInclusiveAdd(point_counts[ident]); - polyline.count = count_sums[quads.count - 1] + 1; + polyline.count = ComputePosition(quads.count - 1) + 1; polyline.data[0] = quads.data[0].p1; // In theory this could be unrolled into a separate shader, but in practice // line_count usually pretty low and currently lack benchmark data to show // how much it would even help. + uint position = ComputePosition(ident); + uint offset = position - uint(decomposition.line_count); for (uint i = 1; i < decomposition.line_count; i += 1) { - uint offset = count_sums[ident] - uint(decomposition.line_count); polyline.data[offset + i] = GenerateLineFromQuad(quad, i, decomposition); } - polyline.data[count_sums[ident]] = quad.p2; + polyline.data[position] = quad.p2; } diff --git a/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc b/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc index 39c36c6ce28..e0f6b86dfec 100644 --- a/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc +++ b/engine/src/flutter/impeller/renderer/compute_subgroup_unittests.cc @@ -32,9 +32,7 @@ namespace testing { using ComputeTest = ComputePlaygroundTest; INSTANTIATE_COMPUTE_SUITE(ComputeTest); -// TODO(dnfield): Re-enable -// https://github.com/flutter/flutter/issues/122828 -TEST_P(ComputeTest, DISABLED_HeartCubicsToStrokeVertices) { +TEST_P(ComputeTest, HeartCubicsToStrokeVertices) { using CS = CubicToQuadsComputeShader; using QS = QuadPolylineComputeShader; using SS = StrokeComputeShader; @@ -258,9 +256,7 @@ TEST_P(ComputeTest, DISABLED_HeartCubicsToStrokeVertices) { ASSERT_TRUE(OpenPlaygroundHere(callback)); } -// TODO(dnfield): Re-enable -// https://github.com/flutter/flutter/issues/122828 -TEST_P(ComputeTest, DISABLED_QuadsToPolyline) { +TEST_P(ComputeTest, QuadsToPolyline) { using QS = QuadPolylineComputeShader; auto context = GetContext(); ASSERT_TRUE(context);