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

Commit 7cf63a0

Browse files
author
Jonah Williams
authored
[Impeller] use IPSampleDecal in advanced blends. (#39523)
* [impeller] use IPSampleDecal in advanced blends * update framebuffr_blend * ++ * ++ * YAY * fix relative paths from local work * Update malioc_diff.py
1 parent bddfc1c commit 7cf63a0

File tree

8 files changed

+31
-39
lines changed

8 files changed

+31
-39
lines changed

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ static std::optional<Entity> AdvancedBlend(
116116
cmd.pipeline = std::move(pipeline);
117117

118118
typename FS::BlendInfo blend_info;
119+
typename VS::FrameInfo frame_info;
119120

120121
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
121122
dst_snapshot->sampler_descriptor);
122123
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
123-
blend_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
124+
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
124125
blend_info.dst_input_alpha = absorb_opacity ? dst_snapshot->opacity : 1.0;
125126

126127
if (foreground_color.has_value()) {
@@ -135,12 +136,11 @@ static std::optional<Entity> AdvancedBlend(
135136
src_snapshot->sampler_descriptor);
136137
blend_info.color_factor = 0;
137138
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
138-
blend_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
139+
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
139140
}
140141
auto blend_uniform = host_buffer.EmplaceUniform(blend_info);
141142
FS::BindBlendInfo(cmd, blend_uniform);
142143

143-
typename VS::FrameInfo frame_info;
144144
frame_info.mvp = Matrix::MakeOrthographic(size);
145145

146146
auto uniform_view = host_buffer.EmplaceUniform(frame_info);

impeller/entity/contents/framebuffer_blend_contents.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,15 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
122122
return false;
123123
}
124124

125-
FS::BlendInfo blend_info;
126125
VS::FrameInfo frame_info;
127126

128127
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
129128
src_snapshot->sampler_descriptor);
130129
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
131-
blend_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
132-
133-
auto blend_uniform = host_buffer.EmplaceUniform(blend_info);
134-
FS::BindBlendInfo(cmd, blend_uniform);
135130

136131
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
137132
src_snapshot->transform;
133+
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
138134

139135
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
140136
VS::BindFrameInfo(cmd, uniform_view);

impeller/entity/shaders/blending/advanced_blend.glsl

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

1010
uniform BlendInfo {
1111
float dst_input_alpha;
12-
float dst_y_coord_scale;
13-
float src_y_coord_scale;
1412
float color_factor;
1513
vec4 color; // This color input is expected to be unpremultiplied.
1614
}
@@ -25,22 +23,17 @@ in vec2 v_src_texture_coords;
2523
out vec4 frag_color;
2624

2725
void main() {
28-
vec4 dst_sample =
29-
IPSampleWithTileMode(texture_sampler_dst, // sampler
30-
v_dst_texture_coords, // texture coordinates
31-
blend_info.dst_y_coord_scale, // y coordinate scale
32-
kTileModeDecal // tile mode
33-
) *
34-
blend_info.dst_input_alpha;
26+
vec4 dst_sample = IPSampleDecal(texture_sampler_dst, // sampler
27+
v_dst_texture_coords // texture coordinates
28+
) *
29+
blend_info.dst_input_alpha;
3530

3631
vec4 dst = IPUnpremultiply(dst_sample);
3732
vec4 src = blend_info.color_factor > 0
3833
? blend_info.color
39-
: IPUnpremultiply(IPSampleWithTileMode(
40-
texture_sampler_src, // sampler
41-
v_src_texture_coords, // texture coordinates
42-
blend_info.src_y_coord_scale, // y coordinate scale
43-
kTileModeDecal // tile mode
34+
: IPUnpremultiply(IPSampleDecal(
35+
texture_sampler_src, // sampler
36+
v_src_texture_coords // texture coordinates
4437
));
4538

4639
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;

impeller/entity/shaders/blending/advanced_blend.vert

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <impeller/texture.glsl>
56
#include <impeller/types.glsl>
67

78
uniform FrameInfo {
89
mat4 mvp;
10+
float dst_y_coord_scale;
11+
float src_y_coord_scale;
912
}
1013
frame_info;
1114

@@ -18,6 +21,8 @@ out vec2 v_src_texture_coords;
1821

1922
void main() {
2023
gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0);
21-
v_dst_texture_coords = dst_texture_coords;
22-
v_src_texture_coords = src_texture_coords;
24+
v_dst_texture_coords =
25+
IPRemapCoords(dst_texture_coords, frame_info.dst_y_coord_scale);
26+
v_src_texture_coords =
27+
IPRemapCoords(src_texture_coords, frame_info.src_y_coord_scale);
2328
}

impeller/entity/shaders/blending/ios/framebuffer_blend.glsl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ vec4 ReadDestination() {
2424
}
2525
#endif
2626

27-
uniform BlendInfo {
28-
float dst_input_alpha;
29-
float src_y_coord_scale;
30-
}
31-
blend_info;
32-
3327
uniform sampler2D texture_sampler_src;
3428

3529
in vec2 v_src_texture_coords;
@@ -39,12 +33,10 @@ out vec4 frag_color;
3933
void main() {
4034
vec4 dst_sample = ReadDestination();
4135
vec4 dst = IPUnpremultiply(dst_sample);
42-
vec4 src = IPUnpremultiply(IPSampleWithTileMode(
43-
texture_sampler_src, // sampler
44-
v_src_texture_coords, // texture coordinates
45-
blend_info.src_y_coord_scale, // y coordinate scale
46-
kTileModeDecal // tile mode
47-
));
36+
vec4 src =
37+
IPUnpremultiply(IPSampleDecal(texture_sampler_src, // sampler
38+
v_src_texture_coords // texture coordinates
39+
));
4840

4941
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;
5042

impeller/entity/shaders/blending/ios/framebuffer_blend.vert

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#include <impeller/texture.glsl>
56
#include <impeller/types.glsl>
67

78
uniform FrameInfo {
89
mat4 mvp;
10+
float src_y_coord_scale;
911
}
1012
frame_info;
1113

@@ -16,5 +18,6 @@ out vec2 v_src_texture_coords;
1618

1719
void main() {
1820
gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0);
19-
v_src_texture_coords = src_texture_coords;
21+
v_src_texture_coords =
22+
IPRemapCoords(src_texture_coords, frame_info.src_y_coord_scale);
2023
}

impeller/tools/malioc.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

impeller/tools/malioc_diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ def read_malioc_file(malioc_tree, json_file):
116116
if shader['hardware']['core'] not in CORES:
117117
continue
118118
result = {}
119-
result['filename'] = os.path.relpath(shader['filename'], build_gen_dir)
119+
filename = os.path.relpath(shader['filename'], build_gen_dir)
120+
if filename.startswith('../..'):
121+
filename = filename[6:]
122+
result['filename'] = filename
120123
result['core'] = shader['hardware']['core']
121124
result['type'] = shader['shader']['type']
122125
for prop in shader['properties']:

0 commit comments

Comments
 (0)