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

[Impeller] remove varying interpolation for solid colors. #53281

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions impeller/compiler/shader_lib/impeller/types.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#extension GL_AMD_gpu_shader_half_float_fetch : enable
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable

#ifdef IMPELLER_TARGET_OPENGLES
#define IMPELLER_MAYBE_FLAT
#else
#define IMPELLER_MAYBE_FLAT flat
#endif

#ifndef IMPELLER_TARGET_METAL_IOS

precision mediump sampler2D;
Expand Down
8 changes: 6 additions & 2 deletions impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ bool SolidColorContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = SolidFillPipeline::VertexShader;
using FS = SolidFillPipeline::FragmentShader;
auto& host_buffer = renderer.GetTransientsBuffer();

VS::FrameInfo frame_info;
frame_info.color =
FS::FragInfo frag_info;
frag_info.color =
GetColor().Premultiply() * GetGeometry()->ComputeAlphaCoverage(entity);

PipelineBuilderCallback pipeline_callback =
Expand All @@ -60,7 +63,8 @@ bool SolidColorContents::Render(const ContentContext& renderer,
};
return ColorSourceContents::DrawGeometry<VS>(
renderer, entity, pass, pipeline_callback, frame_info,
[](RenderPass& pass) {
[&frag_info, &host_buffer](RenderPass& pass) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This callback is used synchronously with DrawGeometry, so the fact it is capturing references looks good.

FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but "EmplaceUniform" is a poor name if it isn't taking in an rvalue.

pass.SetCommandLabel("Solid Fill");
return true;
});
Expand Down
7 changes: 5 additions & 2 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ TEST_P(EntityTest, BlendingModeOptions) {
auto draw_rect = [&context, &pass, &world_matrix](
Rect rect, Color color, BlendMode blend_mode) -> bool {
using VS = SolidFillPipeline::VertexShader;
using FS = SolidFillPipeline::FragmentShader;

VertexBufferBuilder<VS::PerVertexData> vtx_builder;
{
Expand All @@ -947,10 +948,12 @@ TEST_P(EntityTest, BlendingModeOptions) {

VS::FrameInfo frame_info;
frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
frame_info.color = color.Premultiply();
VS::BindFrameInfo(
pass, context.GetTransientsBuffer().EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.color = color.Premultiply();
FS::BindFragInfo(
pass, context.GetTransientsBuffer().EmplaceUniform(frame_info));
return pass.Draw().ok();
};

Expand Down
9 changes: 6 additions & 3 deletions impeller/entity/shaders/solid_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ precision mediump float;

#include <impeller/types.glsl>

IMPELLER_MAYBE_FLAT in f16vec4 v_color;
uniform FragInfo {
vec4 color;
}
frag_info;

out f16vec4 frag_color;
out vec4 frag_color;

void main() {
frag_color = v_color;
frag_color = frag_info.color;
}
4 changes: 0 additions & 4 deletions impeller/entity/shaders/solid_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

uniform FrameInfo {
mat4 mvp;
f16vec4 color;
}
frame_info;

in vec2 position;

IMPELLER_MAYBE_FLAT out mediump f16vec4 v_color;

void main() {
v_color = frame_info.color;
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
}
10 changes: 10 additions & 0 deletions impeller/renderer/shader_stage_compatibility_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_
#define FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_

#include <cstddef>

#include "impeller/core/shader_types.h"

namespace impeller {
/// This is a classed use to check that the input slots of fragment shaders
/// match the output slots of the vertex shaders.
Expand Down Expand Up @@ -58,11 +62,17 @@ class ShaderStageCompatibilityChecker {
// TODO(https://github.com/flutter/flutter/issues/146852): Make impellerc emit
// an empty array for output slots.
struct ClipVertexShader;
struct SolidFillVertexShader;

template <typename FragmentShaderT>
class ShaderStageCompatibilityChecker<ClipVertexShader, FragmentShaderT> {
public:
static constexpr bool Check() { return true; }
};
template <typename FragmentShaderT>
class ShaderStageCompatibilityChecker<SolidFillVertexShader, FragmentShaderT> {
public:
static constexpr bool Check() { return true; }
};
} // namespace impeller
#endif // FLUTTER_IMPELLER_RENDERER_SHADER_STAGE_COMPATIBILITY_CHECKER_H_
Loading