[Impeller] take advantage of native decal sampling, blend cleanups (flutter/engine#40839)

[Impeller] take advantage of native decal sampling, blend cleanups
This commit is contained in:
Jonah Williams
2023-03-31 19:11:35 -07:00
committed by GitHub
parent 0d6952f097
commit 6874163ca9
7 changed files with 293 additions and 297 deletions

View File

@@ -118,8 +118,13 @@ static std::optional<Entity> AdvancedBlend(
typename FS::BlendInfo blend_info;
typename VS::FrameInfo frame_info;
auto dst_sampler_descriptor = dst_snapshot->sampler_descriptor;
if (renderer.GetDeviceCapabilities().SupportsDecalTileMode()) {
dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_snapshot->sampler_descriptor);
dst_sampler_descriptor);
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
blend_info.dst_input_alpha = absorb_opacity ? dst_snapshot->opacity : 1.0;
@@ -132,8 +137,13 @@ static std::optional<Entity> AdvancedBlend(
// binding.
FS::BindTextureSamplerSrc(cmd, dst_snapshot->texture, dst_sampler);
} else {
auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
if (renderer.GetDeviceCapabilities().SupportsDecalTileMode()) {
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
}
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_snapshot->sampler_descriptor);
src_sampler_descriptor);
blend_info.color_factor = 0;
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale();
@@ -220,9 +230,10 @@ static std::optional<Entity> PipelineBlend(
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
Matrix::MakeTranslation(-coverage.origin) *
input->transform;
FS::FragInfo frag_info;
frag_info.texture_sampler_y_coord_scale =
frame_info.texture_sampler_y_coord_scale =
input->texture->GetYCoordScale();
FS::FragInfo frag_info;
frag_info.input_alpha = absorb_opacity ? input->opacity : 1.0;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
@@ -257,10 +268,8 @@ static std::optional<Entity> PipelineBlend(
if (foreground_color.has_value()) {
auto contents = std::make_shared<SolidColorContents>();
contents->SetGeometry(Geometry::MakeFillPath(
PathBuilder{}
.AddRect(Rect::MakeSize(pass.GetRenderTargetSize()))
.TakePath()));
contents->SetGeometry(
Geometry::MakeRect(Rect::MakeSize(pass.GetRenderTargetSize())));
contents->SetColor(foreground_color.value());
Entity foreground_entity;

View File

@@ -128,8 +128,15 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
VS::FrameInfo frame_info;
auto src_sampler_descriptor = src_snapshot->sampler_descriptor;
if (!renderer.GetDeviceCapabilities().SupportsDecalTileMode()) {
// No known devices that support framebuffer fetch but not decal tile mode.
return false;
}
src_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
src_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
src_snapshot->sampler_descriptor);
src_sampler_descriptor);
FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler);
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *

View File

@@ -22,19 +22,28 @@ in vec2 v_src_texture_coords;
out vec4 frag_color;
vec4 Sample(sampler2D texture_sampler, vec2 texture_coords) {
// gles 2.0 is the only backend without native decal support.
#ifdef IMPELLER_TARGET_OPENGLES
return IPSampleDecal(texture_sampler, texture_coords);
#else
return texture(texture_sampler, texture_coords);
#endif
}
void main() {
vec4 dst_sample = IPSampleDecal(texture_sampler_dst, // sampler
v_dst_texture_coords // texture coordinates
) *
vec4 dst_sample = Sample(texture_sampler_dst, // sampler
v_dst_texture_coords // texture coordinates
) *
blend_info.dst_input_alpha;
vec4 dst = IPUnpremultiply(dst_sample);
vec4 src = blend_info.color_factor > 0
? blend_info.color
: IPUnpremultiply(IPSampleDecal(
texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
vec4 src =
blend_info.color_factor > 0
? blend_info.color
: IPUnpremultiply(Sample(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;

View File

@@ -8,7 +8,6 @@
uniform sampler2D texture_sampler_src;
uniform FragInfo {
float texture_sampler_y_coord_scale;
float input_alpha;
}
frag_info;
@@ -18,7 +17,6 @@ in vec2 v_texture_coords;
out vec4 frag_color;
void main() {
frag_color = IPSample(texture_sampler_src, v_texture_coords,
frag_info.texture_sampler_y_coord_scale) *
frag_info.input_alpha;
frag_color =
texture(texture_sampler_src, v_texture_coords) * frag_info.input_alpha;
}

View File

@@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <impeller/texture.glsl>
#include <impeller/types.glsl>
uniform FrameInfo {
mat4 mvp;
float texture_sampler_y_coord_scale;
}
frame_info;
@@ -16,5 +18,6 @@ out vec2 v_texture_coords;
void main() {
gl_Position = frame_info.mvp * vec4(vertices, 0.0, 1.0);
v_texture_coords = texture_coords;
v_texture_coords =
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale);
}

View File

@@ -34,9 +34,9 @@ void main() {
vec4 dst_sample = ReadDestination();
vec4 dst = IPUnpremultiply(dst_sample);
vec4 src =
IPUnpremultiply(IPSampleDecal(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
IPUnpremultiply(texture(texture_sampler_src, // sampler
v_src_texture_coords // texture coordinates
));
vec4 blended = vec4(Blend(dst.rgb, src.rgb), 1) * dst.a;

File diff suppressed because it is too large Load Diff