Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4a4df4b

Browse files
authored
[Impeller] Format shader sources. (#37770)
* Update format.dart to include glsl, format repo * format more
1 parent 55b0891 commit 4a4df4b

File tree

122 files changed

+496
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+496
-566
lines changed

ci/bin/format.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ FormatCheck nameToFormatCheck(String name) {
7171
String formatCheckToName(FormatCheck check) {
7272
switch (check) {
7373
case FormatCheck.clang:
74-
return 'C++/ObjC';
74+
return 'C++/ObjC/Shader';
7575
case FormatCheck.gn:
7676
return 'GN';
7777
case FormatCheck.java:
@@ -301,7 +301,7 @@ abstract class FormatChecker {
301301
}
302302
}
303303

304-
/// Checks and formats C++/ObjC files using clang-format.
304+
/// Checks and formats C++/ObjC/Shader files using clang-format.
305305
class ClangFormatChecker extends FormatChecker {
306306
ClangFormatChecker({
307307
ProcessManager processManager = const LocalProcessManager(),
@@ -350,7 +350,7 @@ class ClangFormatChecker extends FormatChecker {
350350

351351
@override
352352
Future<bool> fixFormatting() async {
353-
message('Fixing C++/ObjC formatting...');
353+
message('Fixing C++/ObjC/Shader formatting...');
354354
final List<String> failures = await _getCFormatFailures(fixing: true);
355355
if (failures.isEmpty) {
356356
return true;
@@ -365,7 +365,7 @@ class ClangFormatChecker extends FormatChecker {
365365
}
366366

367367
Future<List<String>> _getCFormatFailures({bool fixing = false}) async {
368-
message('Checking C++/ObjC formatting...');
368+
message('Checking C++/ObjC/Shader formatting...');
369369
const List<String> clangFiletypes = <String>[
370370
'*.c',
371371
'*.cc',
@@ -374,10 +374,17 @@ class ClangFormatChecker extends FormatChecker {
374374
'*.h',
375375
'*.m',
376376
'*.mm',
377+
'*.glsl',
378+
'*.hlsl',
379+
'*.comp',
380+
'*.tese',
381+
'*.tesc',
382+
'*.vert',
383+
'*.frag',
377384
];
378385
final List<String> files = await getFileList(clangFiletypes);
379386
if (files.isEmpty) {
380-
message('No C++/ObjC files with changes, skipping C++/ObjC format check.');
387+
message('No C++/ObjC/Shader files with changes, skipping C++/ObjC/Shader format check.');
381388
return <String>[];
382389
}
383390
if (verbose) {
@@ -416,10 +423,10 @@ class ClangFormatChecker extends FormatChecker {
416423
if (failed.isNotEmpty) {
417424
final bool plural = failed.length > 1;
418425
if (fixing) {
419-
message('Fixing ${failed.length} C++/ObjC file${plural ? 's' : ''}'
426+
message('Fixing ${failed.length} C++/ObjC/Shader file${plural ? 's' : ''}'
420427
' which ${plural ? 'were' : 'was'} formatted incorrectly.');
421428
} else {
422-
error('Found ${failed.length} C++/ObjC file${plural ? 's' : ''}'
429+
error('Found ${failed.length} C++/ObjC/Shader file${plural ? 's' : ''}'
423430
' which ${plural ? 'were' : 'was'} formatted incorrectly.');
424431
stdout.writeln('To fix, run:');
425432
stdout.writeln();
@@ -431,7 +438,7 @@ class ClangFormatChecker extends FormatChecker {
431438
stdout.writeln();
432439
}
433440
} else {
434-
message('Completed checking ${diffJobs.length} C++/ObjC files with no formatting problems.');
441+
message('Completed checking ${diffJobs.length} C++/ObjC/Shader files with no formatting problems.');
435442
}
436443
return failed.map<String>((WorkerJob job) {
437444
return job.result.stdout;

impeller/compiler/shader_lib/impeller/texture.glsl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ vec4 IPSample(sampler2D texture_sampler, vec2 coords, float y_coord_scale) {
2424
/// If `y_coord_scale` < 0.0, the Y coordinate is flipped. This is useful
2525
/// for Impeller graphics backends that use a flipped framebuffer coordinate
2626
/// space.
27-
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel]
28-
vec4 IPSampleLinear(sampler2D texture_sampler, vec2 coords, float y_coord_scale, vec2 half_texel) {
27+
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 -
28+
/// half_texel]
29+
vec4 IPSampleLinear(sampler2D texture_sampler,
30+
vec2 coords,
31+
float y_coord_scale,
32+
vec2 half_texel) {
2933
coords.x = mix(half_texel.x, 1 - half_texel.x, coords.x);
3034
coords.y = mix(half_texel.y, 1 - half_texel.y, coords.y);
3135
return IPSample(texture_sampler, coords, y_coord_scale);
@@ -79,7 +83,8 @@ vec4 IPSampleWithTileMode(sampler2D tex,
7983
return vec4(0);
8084
}
8185

82-
return IPSample(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), y_coord_scale);
86+
return IPSample(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode),
87+
y_coord_scale);
8388
}
8489

8590
/// Sample a texture, emulating a specific tile mode.
@@ -97,7 +102,8 @@ vec4 IPSampleWithTileMode(sampler2D tex,
97102
///
98103
/// This is useful for Impeller graphics backend that don't have native support
99104
/// for Decal.
100-
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel]
105+
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 -
106+
/// half_texel]
101107
vec4 IPSampleLinearWithTileMode(sampler2D tex,
102108
vec2 coords,
103109
float y_coord_scale,
@@ -109,20 +115,23 @@ vec4 IPSampleLinearWithTileMode(sampler2D tex,
109115
return vec4(0);
110116
}
111117

112-
return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode), y_coord_scale, half_texel);
118+
return IPSampleLinear(tex, IPVec2Tile(coords, x_tile_mode, y_tile_mode),
119+
y_coord_scale, half_texel);
113120
}
114121

115122
/// Sample a texture, emulating a specific tile mode.
116123
///
117124
/// This is useful for Impeller graphics backend that don't have native support
118125
/// for Decal.
119-
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 - half_texel]
126+
/// The range of `coods` will be mapped from [0, 1] to [half_texel, 1 -
127+
/// half_texel]
120128
vec4 IPSampleLinearWithTileMode(sampler2D tex,
121129
vec2 coords,
122130
float y_coord_scale,
123131
vec2 half_texel,
124132
float tile_mode) {
125-
return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel, tile_mode, tile_mode);
133+
return IPSampleLinearWithTileMode(tex, coords, y_coord_scale, half_texel,
134+
tile_mode, tile_mode);
126135
}
127136

128137
#endif

impeller/entity/shaders/blending/advanced_blend.glsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ uniform BlendInfo {
1212
float src_y_coord_scale;
1313
float color_factor;
1414
vec4 color; // This color input is expected to be unpremultiplied.
15-
} blend_info;
15+
}
16+
blend_info;
1617

1718
uniform sampler2D texture_sampler_dst;
1819
uniform sampler2D texture_sampler_src;
@@ -28,7 +29,8 @@ void main() {
2829
v_dst_texture_coords, // texture coordinates
2930
blend_info.dst_y_coord_scale, // y coordinate scale
3031
kTileModeDecal // tile mode
31-
) * blend_info.dst_input_alpha;
32+
) *
33+
blend_info.dst_input_alpha;
3234

3335
vec4 dst = IPUnpremultiply(dst_sample);
3436
vec4 src = blend_info.color_factor > 0
@@ -43,5 +45,5 @@ void main() {
4345
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;
4446

4547
frag_color = mix(dst_sample, blended, src.a);
46-
//frag_color = dst_sample;
48+
// frag_color = dst_sample;
4749
}

impeller/entity/shaders/blending/blend.frag

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ uniform sampler2D texture_sampler_src;
99
uniform FragInfo {
1010
float texture_sampler_y_coord_scale;
1111
float input_alpha;
12-
} frag_info;
12+
}
13+
frag_info;
1314

1415
in vec2 v_texture_coords;
1516

@@ -18,5 +19,5 @@ out vec4 frag_color;
1819
void main() {
1920
frag_color = IPSample(texture_sampler_src, v_texture_coords,
2021
frag_info.texture_sampler_y_coord_scale) *
21-
frag_info.input_alpha;
22+
frag_info.input_alpha;
2223
}

impeller/entity/shaders/blending/blend.vert

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
uniform FrameInfo {
66
mat4 mvp;
7-
} frame_info;
7+
}
8+
frame_info;
89

910
in vec2 vertices;
1011
in vec2 texture_coords;

impeller/entity/shaders/border_mask_blur.frag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ uniform sampler2D texture_sampler;
1818

1919
uniform FragInfo {
2020
float texture_sampler_y_coord_scale;
21-
} frag_info;
21+
}
22+
frag_info;
2223

2324
in vec2 v_texture_coords;
2425
in vec2 v_sigma_uv;

impeller/entity/shaders/color_matrix_color_filter.frag

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
// A color filter that transforms colors through a 4x5 color matrix.
99
//
10-
// This filter can be used to change the saturation of pixels, convert from YUV to RGB, etc.
10+
// This filter can be used to change the saturation of pixels, convert from YUV
11+
// to RGB, etc.
1112
//
1213
// 4x5 matrix for transforming the color and alpha components of a Bitmap.
1314
// The matrix can be passed as single array, and is treated as follows:
@@ -24,14 +25,16 @@
2425
// B’ = k*R + l*G + m*B + n*A + o;
2526
// A’ = p*R + q*G + r*B + s*A + t;
2627
//
27-
// That resulting color [R’, G’, B’, A’] then has each channel clamped to the 0 to 255 range.
28+
// That resulting color [R’, G’, B’, A’] then has each channel clamped to the 0
29+
// to 255 range.
2830

2931
uniform FragInfo {
3032
mat4 color_m;
3133
vec4 color_v;
3234
float texture_sampler_y_coord_scale;
3335
float input_alpha;
34-
} frag_info;
36+
}
37+
frag_info;
3538

3639
uniform sampler2D input_texture;
3740

@@ -41,14 +44,13 @@ out vec4 frag_color;
4144
void main() {
4245
vec4 input_color = IPSample(input_texture, v_position,
4346
frag_info.texture_sampler_y_coord_scale) *
44-
frag_info.input_alpha;
45-
47+
frag_info.input_alpha;
4648

4749
// unpremultiply first, as filter inputs are premultiplied.
4850
vec4 color = IPUnpremultiply(input_color);
4951

5052
color = clamp(frag_info.color_m * color + frag_info.color_v, 0.0, 1.0);
51-
53+
5254
// premultiply the outputs
5355
frag_color = vec4(color.rgb * color.a, color.a);
5456
}

impeller/entity/shaders/color_matrix_color_filter.vert

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
uniform FrameInfo {
66
mat4 mvp;
7-
} frame_info;
7+
}
8+
frame_info;
89

910
in vec2 position;
1011
out vec2 v_position;

impeller/entity/shaders/gradient_fill.vert

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
uniform FrameInfo {
88
mat4 mvp;
99
mat4 matrix;
10-
} frame_info;
10+
}
11+
frame_info;
1112

1213
in vec2 position;
1314

impeller/entity/shaders/linear_gradient_fill.frag

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@ uniform GradientInfo {
1313
float texture_sampler_y_coord_scale;
1414
float alpha;
1515
vec2 half_texel;
16-
} gradient_info;
16+
}
17+
gradient_info;
1718

1819
in vec2 v_position;
1920

2021
out vec4 frag_color;
2122

2223
void main() {
2324
float len = length(gradient_info.end_point - gradient_info.start_point);
24-
float dot = dot(
25-
v_position - gradient_info.start_point,
26-
gradient_info.end_point - gradient_info.start_point
27-
);
25+
float dot = dot(v_position - gradient_info.start_point,
26+
gradient_info.end_point - gradient_info.start_point);
2827
float t = dot / (len * len);
2928
frag_color = IPSampleLinearWithTileMode(
30-
texture_sampler,
31-
vec2(t, 0.5),
32-
gradient_info.texture_sampler_y_coord_scale,
33-
gradient_info.half_texel,
34-
gradient_info.tile_mode);
35-
frag_color = vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha;
29+
texture_sampler, vec2(t, 0.5),
30+
gradient_info.texture_sampler_y_coord_scale, gradient_info.half_texel,
31+
gradient_info.tile_mode);
32+
frag_color =
33+
vec4(frag_color.xyz * frag_color.a, frag_color.a) * gradient_info.alpha;
3634
}

0 commit comments

Comments
 (0)