mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Take subgroup size into account when prefix summing (flutter/engine#40509)
[Impeller] Take subgroup size into account when prefix summing
This commit is contained in:
parent
5a38be2dc3
commit
447cc1fcda
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user