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 1 commit
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
Next Next commit
[Impeller] compute UVs in vertex stage.
  • Loading branch information
jonahwilliams committed Apr 13, 2024
commit 65cf0afb29832daf965fe48ed9a45e5b39d6ce6d
2 changes: 1 addition & 1 deletion impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impeller_shaders("entity_shaders") {
"shaders/texture_fill.vert",
"shaders/texture_fill_external.frag",
"shaders/texture_fill_strict_src.frag",
"shaders/texture_uv_fill.vert",
"shaders/tiled_texture_fill.frag",
"shaders/tiled_texture_fill_external.frag",
"shaders/vertices.frag",
Expand Down Expand Up @@ -85,7 +86,6 @@ impeller_shaders("modern_entity_shaders") {
"shaders/radial_gradient_ssbo_fill.frag",
"shaders/sweep_gradient_ssbo_fill.frag",
"shaders/geometry/points.comp",
"shaders/geometry/uv.comp",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

1 for 1!

]
}

Expand Down
1 change: 0 additions & 1 deletion impeller/entity/contents/clip_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <memory>
#include <vector>

#include "flutter/fml/macros.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry/geometry.h"
Expand Down
10 changes: 2 additions & 8 deletions impeller/entity/contents/color_source_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ class ColorSourceContents : public Contents {
RenderPass& pass,
const PipelineBuilderCallback& pipeline_callback,
typename VertexShaderT::FrameInfo frame_info,
const BindFragmentCallback& bind_fragment_callback,
bool enable_uvs = false,
Rect texture_coverage = {},
const Matrix& effect_transform = {}) const {
const BindFragmentCallback& bind_fragment_callback) const {
auto options = OptionsFromPassAndEntity(pass, entity);

GeometryResult::Mode geometry_mode = GetGeometry()->GetResultMode();
Expand Down Expand Up @@ -181,10 +178,7 @@ class ColorSourceContents : public Contents {
}

GeometryResult geometry_result =
enable_uvs
? geometry.GetPositionUVBuffer(texture_coverage, effect_transform,
renderer, entity, pass)
: geometry.GetPositionBuffer(renderer, entity, pass);
geometry.GetPositionBuffer(renderer, entity, pass);
if (geometry_result.vertex_buffer.vertex_count == 0u) {
return true;
}
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,6 @@ ContentContext::ContentContext(
PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
point_field_compute_pipelines_ =
context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();

auto uv_pipeline_desc =
UvComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_);
uv_compute_pipelines_ =
context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get();
}

/// Setup default clip pipeline.
Expand Down
20 changes: 7 additions & 13 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/texture_fill_strict_src.frag.h"
#include "impeller/entity/texture_uv_fill.vert.h"
#include "impeller/entity/tiled_texture_fill.frag.h"
#include "impeller/entity/uv.comp.h"
#include "impeller/entity/vertices.frag.h"
Expand Down Expand Up @@ -129,14 +130,14 @@ using RRectBlurPipeline =
RenderPipelineT<RrectBlurVertexShader, RrectBlurFragmentShader>;
using BlendPipeline = RenderPipelineT<BlendVertexShader, BlendFragmentShader>;
using TexturePipeline =
RenderPipelineT<TextureFillVertexShader, TextureFillFragmentShader>;
RenderPipelineT<TextureUvFillVertexShader, TextureFillFragmentShader>;
using TextureStrictSrcPipeline =
RenderPipelineT<TextureFillVertexShader,
RenderPipelineT<TextureUvFillVertexShader,
TextureFillStrictSrcFragmentShader>;
using PositionUVPipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
using TiledTexturePipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
RenderPipelineT<TextureUvFillVertexShader, TiledTextureFillFragmentShader>;
using KernelDecalPipeline =
RenderPipelineT<KernelVertexShader, KernelDecalFragmentShader>;
using KernelPipeline =
Expand Down Expand Up @@ -259,10 +260,11 @@ using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;

#ifdef IMPELLER_ENABLE_OPENGLES
using TextureExternalPipeline =
RenderPipelineT<TextureFillVertexShader, TextureFillExternalFragmentShader>;
RenderPipelineT<TextureUvFillVertexShader,
TextureFillExternalFragmentShader>;

using TiledTextureExternalPipeline =
RenderPipelineT<TextureFillVertexShader,
RenderPipelineT<TextureUvFillVertexShader,
TiledTextureFillExternalFragmentShader>;
#endif // IMPELLER_ENABLE_OPENGLES

Expand Down Expand Up @@ -755,12 +757,6 @@ class ContentContext {
return point_field_compute_pipelines_;
}

std::shared_ptr<Pipeline<ComputePipelineDescriptor>> GetUvComputePipeline()
const {
FML_DCHECK(GetDeviceCapabilities().SupportsCompute());
return uv_compute_pipelines_;
}

std::shared_ptr<Context> GetContext() const;

const Capabilities& GetDeviceCapabilities() const;
Expand Down Expand Up @@ -1017,8 +1013,6 @@ class ContentContext {
framebuffer_blend_softlight_pipelines_;
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
point_field_compute_pipelines_;
mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
uv_compute_pipelines_;

template <class TypedPipeline>
std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
Expand Down
19 changes: 9 additions & 10 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool TextureContents::Render(const ContentContext& renderer,
RenderPass& pass) const {
auto capture = entity.GetCapture().CreateChild("TextureContents");

using VS = TextureFillVertexShader;
using VS = TextureUvFillVertexShader;
using FS = TextureFillFragmentShader;
using FSStrictSrc = TextureFillStrictSrcFragmentShader;
using FSExternal = TextureFillExternalFragmentShader;
Expand All @@ -125,18 +125,15 @@ bool TextureContents::Render(const ContentContext& renderer,
texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;

auto source_rect = capture.AddRect("Source rect", source_rect_);
auto texture_coords =
Rect::MakeSize(texture_->GetSize()).Project(source_rect);

VertexBufferBuilder<VS::PerVertexData> vertex_builder;

auto destination_rect =
capture.AddRect("Destination rect", destination_rect_);

VertexBufferBuilder<VS::PerVertexData> vertex_builder;
vertex_builder.AddVertices({
{destination_rect.GetLeftTop(), texture_coords.GetLeftTop()},
{destination_rect.GetRightTop(), texture_coords.GetRightTop()},
{destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()},
{destination_rect.GetRightBottom(), texture_coords.GetRightBottom()},
{destination_rect.GetLeftTop()},
{destination_rect.GetRightTop()},
{destination_rect.GetLeftBottom()},
{destination_rect.GetRightBottom()},
});

auto& host_buffer = renderer.GetTransientsBuffer();
Expand All @@ -145,6 +142,8 @@ bool TextureContents::Render(const ContentContext& renderer,
frame_info.mvp = entity.GetShaderTransform(pass);
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.alpha = capture.AddScalar("Alpha", GetOpacity());
// TODO: src/dst rect.
frame_info.uv_transform = destination_rect_.GetNormalizingTransform();

#ifdef IMPELLER_DEBUG
if (label_.empty()) {
Expand Down
10 changes: 5 additions & 5 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
return true;
}

using VS = TextureFillVertexShader;
using VS = TextureUvFillVertexShader;
using FS = TiledTextureFillFragmentShader;
using FSExternal = TiledTextureFillExternalFragmentShader;

Expand All @@ -133,6 +133,9 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
VS::FrameInfo frame_info;
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
frame_info.alpha = GetOpacityFactor();
frame_info.uv_transform =
Rect::MakeSize(texture_size).GetNormalizingTransform() *
GetInverseEffectTransform();

PipelineBuilderMethod pipeline_method;

Expand Down Expand Up @@ -214,10 +217,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
}

return true;
},
/*enable_uvs=*/true,
/*texture_coverage=*/Rect::MakeSize(texture_size),
/*effect_transform=*/GetInverseEffectTransform());
});
}

std::optional<Snapshot> TiledTextureContents::RenderToSnapshot(
Expand Down
3 changes: 1 addition & 2 deletions impeller/entity/contents/vertices_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
if (!coverage.has_value()) {
return false;
}
auto geometry_result = geometry->GetPositionUVBuffer(
coverage.value(), Matrix(), renderer, entity, pass);
auto geometry_result = geometry->GetPositionBuffer(renderer, entity, pass);
auto opts = OptionsFromPassAndEntity(pass, entity);
opts.primitive_type = geometry_result.type;
pass.SetPipeline(renderer.GetTexturePipeline(opts));
Expand Down
5 changes: 0 additions & 5 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2830,12 +2830,7 @@ TEST_P(EntityTest, CanComputeGeometryForEmptyPathsWithoutCrashing) {
auto position_result =
geom->GetPositionBuffer(*GetContentContext(), entity, render_pass);

auto uv_result =
geom->GetPositionUVBuffer(Rect::MakeLTRB(0, 0, 100, 100), Matrix(),
*GetContentContext(), entity, render_pass);

EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u);
EXPECT_EQ(uv_result.vertex_buffer.vertex_count, 0u);

EXPECT_EQ(geom->GetResultMode(), GeometryResult::Mode::kNormal);
}
Expand Down
25 changes: 0 additions & 25 deletions impeller/entity/geometry/circle_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,6 @@ GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer,
return ComputePositionGeometry(renderer, generator, entity, pass);
}

// |Geometry|
GeometryResult CircleGeometry::GetPositionUVBuffer(
Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
auto& transform = entity.GetTransform();
auto uv_transform =
texture_coverage.GetNormalizingTransform() * effect_transform;

Scalar half_width = stroke_width_ < 0 ? 0.0
: LineGeometry::ComputePixelHalfWidth(
transform, stroke_width_);
std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator();

// We call the StrokedCircle method which will simplify to a
// FilledCircleGenerator if the inner_radius is <= 0.
auto generator =
tessellator->StrokedCircle(transform, center_, radius_, half_width);

return ComputePositionUVGeometry(renderer, generator, uv_transform, entity,
pass);
}

GeometryVertexType CircleGeometry::GetVertexType() const {
return GeometryVertexType::kPosition;
}
Expand Down
7 changes: 0 additions & 7 deletions impeller/entity/geometry/circle_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class CircleGeometry final : public Geometry {
// |Geometry|
std::optional<Rect> GetCoverage(const Matrix& transform) const override;

// |Geometry|
GeometryResult GetPositionUVBuffer(Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const override;

Point center_;
Scalar radius_;
Scalar stroke_width_;
Expand Down
12 changes: 0 additions & 12 deletions impeller/entity/geometry/cover_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ GeometryResult CoverGeometry::GetPositionBuffer(const ContentContext& renderer,
};
}

// |Geometry|
GeometryResult CoverGeometry::GetPositionUVBuffer(
Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
auto rect = Rect::MakeSize(pass.GetRenderTargetSize());
return ComputeUVGeometryForRect(rect, texture_coverage, effect_transform,
renderer, entity, pass);
}

GeometryVertexType CoverGeometry::GetVertexType() const {
return GeometryVertexType::kPosition;
}
Expand Down
7 changes: 0 additions & 7 deletions impeller/entity/geometry/cover_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ class CoverGeometry final : public Geometry {
// |Geometry|
std::optional<Rect> GetCoverage(const Matrix& transform) const override;

// |Geometry|
GeometryResult GetPositionUVBuffer(Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const override;

CoverGeometry(const CoverGeometry&) = delete;

CoverGeometry& operator=(const CoverGeometry&) = delete;
Expand Down
14 changes: 0 additions & 14 deletions impeller/entity/geometry/ellipse_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ GeometryResult EllipseGeometry::GetPositionBuffer(
entity, pass);
}

// |Geometry|
GeometryResult EllipseGeometry::GetPositionUVBuffer(
Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
return ComputePositionUVGeometry(
renderer,
renderer.GetTessellator()->FilledEllipse(entity.GetTransform(), bounds_),
texture_coverage.GetNormalizingTransform() * effect_transform, entity,
pass);
}

GeometryVertexType EllipseGeometry::GetVertexType() const {
return GeometryVertexType::kPosition;
}
Expand Down
7 changes: 0 additions & 7 deletions impeller/entity/geometry/ellipse_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ class EllipseGeometry final : public Geometry {
// |Geometry|
std::optional<Rect> GetCoverage(const Matrix& transform) const override;

// |Geometry|
GeometryResult GetPositionUVBuffer(Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const override;

Rect bounds_;

EllipseGeometry(const EllipseGeometry&) = delete;
Expand Down
47 changes: 0 additions & 47 deletions impeller/entity/geometry/fill_path_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,53 +54,6 @@ GeometryResult FillPathGeometry::GetPositionBuffer(
};
}

// |Geometry|
GeometryResult FillPathGeometry::GetPositionUVBuffer(
Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = TextureFillVertexShader;

const auto& bounding_box = path_.GetBoundingBox();
if (bounding_box.has_value() && bounding_box->IsEmpty()) {
return GeometryResult{
.type = PrimitiveType::kTriangle,
.vertex_buffer =
VertexBuffer{
.vertex_buffer = {},
.vertex_count = 0,
.index_type = IndexType::k16bit,
},
.transform = pass.GetOrthographicTransform() * entity.GetTransform(),
};
}

auto uv_transform =
texture_coverage.GetNormalizingTransform() * effect_transform;

auto points = renderer.GetTessellator()->TessellateConvex(
path_, entity.GetTransform().GetMaxBasisLength());

VertexBufferBuilder<VS::PerVertexData> vertex_builder;
vertex_builder.Reserve(points.size());
for (auto i = 0u; i < points.size(); i++) {
VS::PerVertexData data;
data.position = points[i];
data.texture_coords = uv_transform * points[i];
vertex_builder.AppendVertex(data);
}

return GeometryResult{
.type = PrimitiveType::kTriangleStrip,
.vertex_buffer =
vertex_builder.CreateVertexBuffer(renderer.GetTransientsBuffer()),
.transform = entity.GetShaderTransform(pass),
.mode = GetResultMode(),
};
}

GeometryResult::Mode FillPathGeometry::GetResultMode() const {
const auto& bounding_box = path_.GetBoundingBox();
if (path_.IsConvex() ||
Expand Down
Loading