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
Prev Previous commit
Next Next commit
++
  • Loading branch information
jonahwilliams committed Apr 19, 2024
commit 0adc252d4a62423973437ba48f7f3f37558f830e
1 change: 1 addition & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impeller_shaders("entity_shaders") {
"shaders/gradients/sweep_gradient_fill.frag",
"shaders/texture_fill.frag",
"shaders/texture_fill.vert",
"shaders/texture_uv_fill.vert",
"shaders/tiled_texture_fill.frag",
"shaders/tiled_texture_fill_external.frag",
"shaders/texture_fill_strict_src.frag",
Expand Down
5 changes: 2 additions & 3 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ ContentContext::ContentContext(
? std::make_shared<RenderTargetCache>(
context_->GetResourceAllocator())
: std::move(render_target_allocator)),
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())),
pending_command_buffers_(std::make_unique<PendingCommandBuffers>()) {
host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) {
if (!context_ || !context_->IsValid()) {
return;
}
Expand Down Expand Up @@ -423,7 +422,7 @@ ContentContext::ContentContext(
rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
texture_strict_src_pipelines_.CreateDefault(*context_, options);
position_uv_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal});
kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip);
kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip);
border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
Expand Down
33 changes: 2 additions & 31 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,15 @@ using SweepGradientSSBOFillPipeline =
using RRectBlurPipeline =
RenderPipelineHandle<RrectBlurVertexShader, RrectBlurFragmentShader>;
using TexturePipeline =
<<<<<<< HEAD
RenderPipelineT<TextureUvFillVertexShader, TextureFillFragmentShader>;
using TextureStrictSrcPipeline =
RenderPipelineT<TextureUvFillVertexShader,
TextureFillStrictSrcFragmentShader>;
using PositionUVPipeline =
RenderPipelineT<TextureFillVertexShader, TiledTextureFillFragmentShader>;
using TiledTexturePipeline =
RenderPipelineT<TextureUvFillVertexShader, TiledTextureFillFragmentShader>;
=======
RenderPipelineHandle<TextureFillVertexShader, TextureFillFragmentShader>;
using TextureStrictSrcPipeline =
RenderPipelineHandle<TextureFillVertexShader,
TextureFillStrictSrcFragmentShader>;
using PositionUVPipeline = RenderPipelineHandle<TextureFillVertexShader,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused

TiledTextureFillFragmentShader>;
using TiledTexturePipeline =
RenderPipelineHandle<TextureFillVertexShader,
RenderPipelineHandle<TextureUvFillVertexShader,
TiledTextureFillFragmentShader>;
>>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b
using KernelDecalPipeline =
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
using KernelPipeline =
Expand Down Expand Up @@ -264,30 +253,13 @@ using FramebufferBlendSoftLightPipeline =

/// Geometry Pipelines
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
using UvComputeShaderPipeline = ComputePipelineBuilder<UvComputeShader>;

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

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

// A struct used to isolate command buffer storage from the content
// context options to preserve const-ness.
struct PendingCommandBuffers {
std::vector<std::shared_ptr<CommandBuffer>> command_buffers;
};

/// Pipeline state configuration.
///
/// Each unique combination of these options requires a different pipeline state
Expand Down Expand Up @@ -1071,7 +1043,6 @@ class ContentContext {
#endif // IMPELLER_ENABLE_3D
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
std::shared_ptr<HostBuffer> host_buffer_;
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
bool wireframe_ = false;

ContentContext(const ContentContext&) = delete;
Expand Down
58 changes: 10 additions & 48 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#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/tiled_texture_fill_external.frag.h"
#include "impeller/geometry/constants.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/vertex_buffer_builder.h"
Expand Down Expand Up @@ -112,9 +111,8 @@ bool TextureContents::Render(const ContentContext& renderer,
RenderPass& pass) const {
auto capture = entity.GetCapture().CreateChild("TextureContents");

using VS = TextureUvFillVertexShader;
using VS = TextureFillVertexShader;
using FS = TextureFillFragmentShader;
using FSExternal = TiledTextureFillExternalFragmentShader;
using FSStrict = TextureFillStrictSrcFragmentShader;

if (destination_rect_.IsEmpty() || source_rect_.IsEmpty() ||
Expand All @@ -124,24 +122,20 @@ bool TextureContents::Render(const ContentContext& renderer,

bool is_external_texture =
texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;
FML_DCHECK(!is_external_texture);

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

VertexBufferBuilder<VS::PerVertexData> vertex_builder;
>>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b
auto destination_rect =
capture.AddRect("Destination rect", destination_rect_);

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

auto& host_buffer = renderer.GetTransientsBuffer();
Expand All @@ -164,46 +158,14 @@ bool TextureContents::Render(const ContentContext& renderer,
}
pipeline_options.primitive_type = PrimitiveType::kTriangleStrip;

std::shared_ptr<Pipeline<PipelineDescriptor>> pipeline;
#ifdef IMPELLER_ENABLE_OPENGLES
if (is_external_texture) {
pipeline = renderer.GetTiledTextureExternalPipeline(pipeline_options);
}
#endif // IMPELLER_ENABLE_OPENGLES

if (!pipeline) {
if (strict_source_rect_enabled_) {
pipeline = renderer.GetTextureStrictSrcPipeline(pipeline_options);
} else {
pipeline = renderer.GetTexturePipeline(pipeline_options);
}
}
pass.SetPipeline(pipeline);
pass.SetPipeline(strict_source_rect_enabled_
? renderer.GetTextureStrictSrcPipeline(pipeline_options)
: renderer.GetTexturePipeline(pipeline_options));

pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));

if (is_external_texture) {
FSExternal::FragInfo frag_info;
frag_info.x_tile_mode =
static_cast<int>(sampler_descriptor_.width_address_mode);
frag_info.y_tile_mode =
static_cast<int>(sampler_descriptor_.height_address_mode);
frag_info.alpha = capture.AddScalar("Alpha", GetOpacity());

auto sampler_descriptor = sampler_descriptor_;
// OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so
// we emulate all other tile modes here by remapping the texture
// coordinates.
sampler_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge;
sampler_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge;

FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
FSExternal::BindSAMPLEREXTERNALOESTextureSampler(
pass, texture_,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
sampler_descriptor));
} else if (strict_source_rect_enabled_) {
if (strict_source_rect_enabled_) {
// For a strict source rect, shrink the texture coordinate range by half a
// texel to ensure that linear filtering does not sample anything outside
// the source rect bounds.
Expand Down
29 changes: 4 additions & 25 deletions impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "fml/logging.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/tiled_texture_fill.frag.h"
#include "impeller/entity/tiled_texture_fill_external.frag.h"
#include "impeller/renderer/render_pass.h"
Expand Down Expand Up @@ -128,28 +126,19 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
bool is_external_texture =
texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES;

bool uses_emulated_tile_mode =
UsesEmulatedTileMode(renderer.GetDeviceCapabilities());

VS::FrameInfo frame_info;
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
<<<<<<< HEAD
frame_info.alpha = GetOpacityFactor();
frame_info.uv_transform =
Rect::MakeSize(texture_size).GetNormalizingTransform() *
GetInverseEffectTransform();
=======
>>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b

PipelineBuilderMethod pipeline_method;

#ifdef IMPELLER_ENABLE_OPENGLES
if (is_external_texture) {
pipeline_method = &ContentContext::GetTiledTextureExternalPipeline;
} else {
pipeline_method = uses_emulated_tile_mode
? &ContentContext::GetTiledTexturePipeline
: &ContentContext::GetTexturePipeline;
pipeline_method = &ContentContext::GetTiledTexturePipeline;
}
#else
pipeline_method = uses_emulated_tile_mode
Expand All @@ -163,33 +152,23 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
};
return ColorSourceContents::DrawGeometry<VS>(
renderer, entity, pass, pipeline_callback, frame_info,
[this, &renderer, &is_external_texture,
&uses_emulated_tile_mode](RenderPass& pass) {
[this, &renderer, &is_external_texture](RenderPass& pass) {
auto& host_buffer = renderer.GetTransientsBuffer();

if (uses_emulated_tile_mode) {
pass.SetCommandLabel("TiledTextureFill");
} else {
pass.SetCommandLabel("TextureFill");
}
pass.SetCommandLabel("TextureFill");

if (is_external_texture) {
FSExternal::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();
FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
} else if (uses_emulated_tile_mode) {
} else {
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(pass, host_buffer.EmplaceUniform(frag_info));
} else {
TextureFillFragmentShader::FragInfo frag_info;
frag_info.alpha = GetOpacityFactor();
TextureFillFragmentShader::BindFragInfo(
pass, host_buffer.EmplaceUniform(frag_info));
}

if (is_external_texture) {
Expand Down
4 changes: 0 additions & 4 deletions impeller/entity/shaders/texture_uv_fill.vert
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ uniform FrameInfo {
mat4 mvp;
// A normlizing transform created from the texture bounds and effect transform
mat4 uv_transform;
vec4 texture_coverage;
float texture_sampler_y_coord_scale;
float16_t alpha;
}
frame_info;

in vec2 position;

out vec2 v_texture_coords;
IMPELLER_MAYBE_FLAT out mediump float16_t v_alpha;

void main() {
gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0);
v_alpha = frame_info.alpha;
vec2 texture_coords = (frame_info.uv_transform * vec4(position, 0.0, 1.0)).xy;
v_texture_coords =
IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale);
Expand Down
23 changes: 16 additions & 7 deletions impeller/entity/shaders/tiled_texture_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ precision mediump float;
#include <impeller/texture.glsl>
#include <impeller/types.glsl>

layout(constant_id = 0) const float supports_decal = 1.0;

uniform f16sampler2D texture_sampler;

uniform FragInfo {
Expand All @@ -21,11 +23,18 @@ in highp vec2 v_texture_coords;
out f16vec4 frag_color;

void main() {
frag_color =
IPHalfSampleWithTileMode(texture_sampler, // sampler
v_texture_coords, // texture coordinates
float16_t(frag_info.x_tile_mode), // x tile mode
float16_t(frag_info.y_tile_mode) // y tile mode
) *
float16_t(frag_info.alpha);
if (supports_decal == 1.0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allows metal, vulkan, and most gles devices to use this shader at no additional cost over the texture_fill shader.

frag_color = texture(texture_sampler, // sampler
v_texture_coords, // texture coordinates
float16_t(kDefaultMipBias)) *
float16_t(frag_info.alpha);
} else {
frag_color = IPHalfSampleWithTileMode(
texture_sampler, // sampler
v_texture_coords, // texture coordinates
float16_t(frag_info.x_tile_mode), // x tile mode
float16_t(frag_info.y_tile_mode) // y tile mode
) *
float16_t(frag_info.alpha);
}
}
11 changes: 4 additions & 7 deletions impeller/tessellator/tessellator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ Path::Polyline Tessellator::CreateTempPolyline(const Path& path,

VertexBuffer Tessellator::TessellateConvex(const Path& path,
HostBuffer& host_buffer,
Scalar tolerance,
std::optional<Matrix> uv_transform) {
Scalar tolerance) {
FML_DCHECK(point_buffer_);
FML_DCHECK(index_buffer_);
TessellateConvexInternal(path, *point_buffer_, *index_buffer_, tolerance,
uv_transform);
TessellateConvexInternal(path, *point_buffer_, *index_buffer_, tolerance);

if (point_buffer_->empty()) {
return VertexBuffer{
Expand Down Expand Up @@ -68,12 +66,11 @@ VertexBuffer Tessellator::TessellateConvex(const Path& path,
void Tessellator::TessellateConvexInternal(const Path& path,
std::vector<Point>& point_buffer,
std::vector<uint16_t>& index_buffer,
Scalar tolerance,
std::optional<Matrix> uv_transform) {
Scalar tolerance) {
index_buffer_->clear();
point_buffer_->clear();

VertexWriter writer(point_buffer, index_buffer, uv_transform);
VertexWriter writer(point_buffer, index_buffer);

path.WritePolyline(tolerance, writer);
writer.EndContour();
Expand Down
20 changes: 7 additions & 13 deletions impeller/tessellator/tessellator.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,20 @@ class Tessellator {
/// path for rendering.
/// @param[in] host_buffer The host buffer for allocation of vertices/index
/// data.
/// @param[in] uv_transform If provided, then uvs are also generated into the
/// point buffer. Defaults to std::nullopt.
///
/// @return A vertex buffer containing all data from the provided curve.
VertexBuffer TessellateConvex(
const Path& path,
HostBuffer& host_buffer,
Scalar tolerance,
std::optional<Matrix> uv_transform = std::nullopt);
VertexBuffer TessellateConvex(const Path& path,
HostBuffer& host_buffer,
Scalar tolerance);

/// Visible for testing.
///
/// This method only exists for the ease of benchmarking without using the
/// real allocator needed by the [host_buffer].
void TessellateConvexInternal(
const Path& path,
std::vector<Point>& point_buffer,
std::vector<uint16_t>& index_buffer,
Scalar tolerance,
std::optional<Matrix> uv_transform = std::nullopt);
void TessellateConvexInternal(const Path& path,
std::vector<Point>& point_buffer,
std::vector<uint16_t>& index_buffer,
Scalar tolerance);

//----------------------------------------------------------------------------
/// @brief Create a temporary polyline. Only one per-process can exist at
Expand Down