Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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: 6 additions & 0 deletions impeller/compiler/shader_lib/impeller/types.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#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
5 changes: 1 addition & 4 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,13 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.texture_sampler_y_coord_scale = texture->GetYCoordScale();

FS::FragInfo frag_info;
frag_info.alpha = alpha_;
frame_info.alpha = alpha_;

auto options = OptionsFromPassAndEntity(pass, entity);
cmd.pipeline = renderer.GetTexturePipeline(options);
cmd.stencil_reference = entity.GetStencilDepth();
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
FS::BindTextureSampler(cmd, texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
parent_.GetSamplerDescriptor()));
Expand Down
12 changes: 2 additions & 10 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,13 @@ bool ClipContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = ClipPipeline::VertexShader;
using FS = ClipPipeline::FragmentShader;

VS::FrameInfo info;

Command cmd;

FS::FragInfo frag_info;
// The color really doesn't matter.
frag_info.color = Color::SkyBlue();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
info.color = Color::SkyBlue();

auto options = OptionsFromPassAndEntity(pass, entity);
cmd.stencil_reference = entity.GetStencilDepth();
Expand Down Expand Up @@ -182,7 +179,6 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = ClipPipeline::VertexShader;
using FS = ClipPipeline::FragmentShader;

Command cmd;
cmd.label = "Restore Clip";
Expand All @@ -208,13 +204,9 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,

VS::FrameInfo info;
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
info.color = Color::SkyBlue();
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

FS::FragInfo frag_info;
// The color really doesn't matter.
frag_info.color = Color::SkyBlue();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

pass.AddCommand(std::move(cmd));
return true;
}
Expand Down
6 changes: 1 addition & 5 deletions impeller/entity/contents/solid_color_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ bool SolidColorContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = SolidFillPipeline::VertexShader;
using FS = SolidFillPipeline::FragmentShader;

Command cmd;
cmd.label = "Solid Fill";
Expand All @@ -75,12 +74,9 @@ bool SolidColorContents::Render(const ContentContext& renderer,

VS::FrameInfo frame_info;
frame_info.mvp = geometry_result.transform;
frame_info.color = GetColor().Premultiply();
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.color = GetColor().Premultiply();
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

if (!pass.AddCommand(std::move(cmd))) {
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions impeller/entity/contents/text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool TextContents::Render(const ContentContext& renderer,
frame_info.is_translation_scale =
entity.GetTransformation().IsTranslationScaleOnly();
frame_info.entity_transform = entity.GetTransformation();
frame_info.text_color = ToVector(color.Premultiply());

VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));

Expand All @@ -143,10 +144,6 @@ bool TextContents::Render(const ContentContext& renderer,
}
sampler_desc.mip_filter = MipFilter::kNearest;

FS::FragInfo frag_info;
frag_info.text_color = ToVector(color.Premultiply());
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));

FS::BindGlyphAtlasSampler(
cmd, // command
atlas->GetTexture(), // texture
Expand Down
5 changes: 1 addition & 4 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ bool TextureContents::Render(const ContentContext& renderer,
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();

FS::FragInfo frag_info;
frag_info.alpha = GetOpacity();
frame_info.alpha = GetOpacity();

Command cmd;
cmd.label = "Texture Fill";
Expand All @@ -155,7 +153,6 @@ bool TextureContents::Render(const ContentContext& renderer,
cmd.stencil_reference = entity.GetStencilDepth();
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
FS::BindTextureSampler(cmd, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_descriptor_));
Expand Down
7 changes: 1 addition & 6 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
VS::FrameInfo frame_info;
frame_info.mvp = geometry_result.transform;
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.alpha = GetOpacityFactor();

Command cmd;
cmd.label = uses_emulated_tile_mode ? "TiledTextureFill" : "TextureFill";
Expand All @@ -158,13 +159,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
FS::FragInfo frag_info;
frag_info.x_tile_mode = static_cast<Scalar>(x_tile_mode_);
frag_info.y_tile_mode = static_cast<Scalar>(y_tile_mode_);
frag_info.alpha = GetOpacityFactor();
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
} else {
TextureFillFragmentShader::FragInfo frag_info;
frag_info.alpha = GetOpacityFactor();
TextureFillFragmentShader::BindFragInfo(
cmd, host_buffer.EmplaceUniform(frag_info));
}

if (color_filter_) {
Expand Down
5 changes: 1 addition & 4 deletions impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,9 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
frame_info.mvp = geometry_result.transform;
frame_info.texture_sampler_y_coord_scale =
snapshot->texture->GetYCoordScale();
frame_info.alpha = alpha_ * snapshot->opacity;
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.alpha = alpha_ * snapshot->opacity;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));

FS::BindTextureSampler(cmd, snapshot->texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
snapshot->sampler_descriptor));
Expand Down
7 changes: 1 addition & 6 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ 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 @@ -884,14 +883,10 @@ TEST_P(EntityTest, BlendingModeOptions) {
VS::FrameInfo frame_info;
frame_info.mvp =
Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * world_matrix;
frame_info.color = color.Premultiply();
VS::BindFrameInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(frame_info));

FS::FragInfo frag_info;
frag_info.color = color.Premultiply();
FS::BindFragInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(frag_info));

return pass.AddCommand(std::move(cmd));
};

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

uniform f16sampler2D glyph_atlas_sampler;

uniform FragInfo {
f16vec4 text_color;
}
frag_info;

in highp vec2 v_uv;

IMPELLER_MAYBE_FLAT in f16vec4 v_text_color;

out f16vec4 frag_color;

void main() {
f16vec4 value = texture(glyph_atlas_sampler, v_uv);
frag_color = value.aaaa * frag_info.text_color;
frag_color = value.aaaa * v_text_color;
}
5 changes: 5 additions & 0 deletions impeller/entity/shaders/glyph_atlas.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// found in the LICENSE file.

#include <impeller/transform.glsl>
#include <impeller/types.glsl>

uniform FrameInfo {
mat4 mvp;
mat4 entity_transform;
vec2 atlas_size;
vec2 offset;
f16vec4 text_color;
float is_translation_scale;
}
frame_info;
Expand All @@ -23,6 +25,8 @@ in vec2 glyph_position;

out vec2 v_uv;

IMPELLER_MAYBE_FLAT out f16vec4 v_text_color;

mat4 basis(mat4 m) {
return mat4(m[0][0], m[0][1], m[0][2], 0.0, //
m[1][0], m[1][1], m[1][2], 0.0, //
Expand Down Expand Up @@ -77,4 +81,5 @@ void main() {

gl_Position = frame_info.mvp * position;
v_uv = uv_origin + unit_position * uv_size;
v_text_color = frame_info.text_color;
}
9 changes: 3 additions & 6 deletions impeller/entity/shaders/glyph_atlas_color.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ precision mediump float;

uniform f16sampler2D glyph_atlas_sampler;

uniform FragInfo {
f16vec4 text_color;
}
frag_info;

in highp vec2 v_uv;

IMPELLER_MAYBE_FLAT in f16vec4 v_text_color;

out f16vec4 frag_color;

void main() {
f16vec4 value = texture(glyph_atlas_sampler, v_uv);
frag_color = value * frag_info.text_color.aaaa;
frag_color = value * v_text_color.aaaa;
}
7 changes: 2 additions & 5 deletions impeller/entity/shaders/solid_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ precision mediump float;

#include <impeller/types.glsl>

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

out f16vec4 frag_color;

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

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

in vec2 position;

IMPELLER_MAYBE_FLAT out f16vec4 v_color;

void main() {
v_color = frame_info.color;
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
}
8 changes: 2 additions & 6 deletions impeller/entity/shaders/texture_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ precision mediump float;

uniform f16sampler2D texture_sampler;

uniform FragInfo {
float16_t alpha;
}
frag_info;

in highp vec2 v_texture_coords;
IMPELLER_MAYBE_FLAT in float16_t v_alpha;

out f16vec4 frag_color;

void main() {
f16vec4 sampled =
texture(texture_sampler, v_texture_coords, kDefaultMipBiasHalf);
frag_color = sampled * frag_info.alpha;
frag_color = sampled * v_alpha;
}
3 changes: 3 additions & 0 deletions impeller/entity/shaders/texture_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
uniform FrameInfo {
mat4 mvp;
float texture_sampler_y_coord_scale;
float16_t alpha;
}
frame_info;

in vec2 position;
in vec2 texture_coords;

out vec2 v_texture_coords;
IMPELLER_MAYBE_FLAT out float16_t v_alpha;

void main() {
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
v_alpha = frame_info.alpha;
v_texture_coords =
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale);
}
4 changes: 2 additions & 2 deletions impeller/entity/shaders/tiled_texture_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ uniform f16sampler2D texture_sampler;
uniform FragInfo {
float16_t x_tile_mode;
float16_t y_tile_mode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't used the tiled texture shader on vulkan, but we still need to move the alpha so that this can share the same vertex shader as texture.frag.

float16_t alpha;
}
frag_info;

in highp vec2 v_texture_coords;
IMPELLER_MAYBE_FLAT in float16_t v_alpha;

out f16vec4 frag_color;

Expand All @@ -27,5 +27,5 @@ void main() {
frag_info.x_tile_mode, // x tile mode
frag_info.y_tile_mode // y tile mode
) *
frag_info.alpha;
v_alpha;
}
Loading