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

Commit ced0ea0

Browse files
author
jonahwilliams
committed
fix padding.
1 parent fee9a39 commit ced0ea0

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

impeller/core/shader_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ struct Padded {
183183
Padding<Size> _PADDING_;
184184

185185
Padded(T p_value) : value(p_value){}; // NOLINT(google-explicit-constructor)
186-
187-
Padded(){}; // NOLINT(google-explicit-constructor)
188186
};
189187

190188
inline constexpr Vector4 ToVector(Color color) {

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass(
399399

400400
TextureFillVertexShader::FrameInfo frame_info;
401401
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
402-
frame_info.texture_sampler_y_coord_scale = 1.0;
402+
frame_info.texture_sampler_y_coord_scale =
403+
input_texture->GetYCoordScale();
403404

404405
TextureDownsampleFragmentShader::FragInfo frag_info;
405406
frag_info.edge = edge;
@@ -928,16 +929,21 @@ GaussianBlurPipeline::FragmentShader::BlurInfo LerpHackKernelSamples(
928929

929930
for (int i = 0; i < result.sample_count; i++) {
930931
if (i == middle) {
931-
result.coefficients[i] = parameters.samples[j].coefficient;
932-
result.uv_offsets[i] = parameters.samples[j++].uv_offset;
932+
result.sample_data[i].x = parameters.samples[j].uv_offset.x;
933+
result.sample_data[i].y = parameters.samples[j].uv_offset.y;
934+
result.sample_data[i].z = parameters.samples[j].coefficient;
935+
j++;
933936
} else {
934937
KernelSample left = parameters.samples[j];
935938
KernelSample right = parameters.samples[j + 1];
936939

937-
result.coefficients[i] = left.coefficient + right.coefficient;
938-
result.uv_offsets[i] = (left.uv_offset * left.coefficient +
939-
right.uv_offset * right.coefficient) /
940-
(left.coefficient + right.coefficient);
940+
result.sample_data[i].z = left.coefficient + right.coefficient;
941+
942+
auto uv = (left.uv_offset * left.coefficient +
943+
right.uv_offset * right.coefficient) /
944+
(left.coefficient + right.coefficient);
945+
result.sample_data[i].x = uv.x;
946+
result.sample_data[i].y = uv.y;
941947
j += 2;
942948
}
943949
}

impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ TEST(GaussianBlurFilterContentsTest, LerpHackKernelSamplesSimple) {
517517
//////////////////////////////////////////////////////////////////////////////
518518
// Check output kernel.
519519

520-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[0].value.x, -1.3333333);
521-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[0].value.y, 0);
522-
EXPECT_FLOAT_EQ(blur_info.coefficients[0].value, 0.3);
523-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[1].value.x, 0);
524-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[1].value.y, 0);
525-
EXPECT_FLOAT_EQ(blur_info.coefficients[1].value, 0.4);
526-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[2].value.x, 1.3333333);
527-
EXPECT_FLOAT_EQ(blur_info.uv_offsets[2].value.y, 0);
528-
EXPECT_FLOAT_EQ(blur_info.coefficients[2].value, 0.3);
520+
EXPECT_FLOAT_EQ(blur_info.sample_data[0].x, -1.3333333);
521+
EXPECT_FLOAT_EQ(blur_info.sample_data[0].y, 0);
522+
EXPECT_FLOAT_EQ(blur_info.sample_data[0].z, 0.3);
523+
EXPECT_FLOAT_EQ(blur_info.sample_data[1].x, 0);
524+
EXPECT_FLOAT_EQ(blur_info.sample_data[1].y, 0);
525+
EXPECT_FLOAT_EQ(blur_info.sample_data[1].z, 0.4);
526+
EXPECT_FLOAT_EQ(blur_info.sample_data[2].x, 1.3333333);
527+
EXPECT_FLOAT_EQ(blur_info.sample_data[2].y, 0);
528+
EXPECT_FLOAT_EQ(blur_info.sample_data[2].z, 0.3);
529529

530530
//////////////////////////////////////////////////////////////////////////////
531531
// Check output of fast kernel versus original kernel.
@@ -546,11 +546,11 @@ TEST(GaussianBlurFilterContentsTest, LerpHackKernelSamplesSimple) {
546546
}
547547
};
548548
Scalar fast_output =
549-
/*1st*/ lerp(blur_info.uv_offsets[0].value, data[0], data[1]) *
550-
blur_info.coefficients[0].value +
551-
/*2nd*/ data[2] * blur_info.coefficients[1].value +
552-
/*3rd*/ lerp(blur_info.uv_offsets[2].value, data[3], data[4]) *
553-
blur_info.coefficients[2].value;
549+
/*1st*/ lerp(blur_info.sample_data[0].xy(), data[0], data[1]) *
550+
blur_info.sample_data[0].z +
551+
/*2nd*/ data[2] * blur_info.sample_data[1].z +
552+
/*3rd*/ lerp(blur_info.sample_data[2].xy(), data[3], data[4]) *
553+
blur_info.sample_data[2].z;
554554

555555
EXPECT_NEAR(original_output, fast_output, 0.01);
556556
}
@@ -602,8 +602,8 @@ TEST(GaussianBlurFilterContentsTest, LerpHackKernelSamplesComplex) {
602602

603603
Scalar fast_output = 0.0;
604604
for (int i = 0; i < fast_kernel_samples.sample_count; i++) {
605-
fast_output += fast_kernel_samples.coefficients[i].value *
606-
sampler(fast_kernel_samples.uv_offsets[i].value);
605+
fast_output += fast_kernel_samples.sample_data[i].z *
606+
sampler(fast_kernel_samples.sample_data[i].xy());
607607
}
608608

609609
EXPECT_NEAR(output, fast_output, 0.1);

impeller/entity/shaders/filters/gaussian.frag

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ layout(constant_id = 0) const float supports_decal = 1.0;
1313

1414
uniform BlurInfo {
1515
float sample_count;
16-
vec2 uv_offsets[50];
17-
float coefficients[50];
16+
17+
// X, Y are uv offset and Z is Coefficient. W is padding.
18+
vec4 sample_data[50];
1819
}
1920
blur_info;
2021

@@ -33,10 +34,10 @@ void main() {
3334
f16vec4 total_color = f16vec4(0.0hf);
3435

3536
for (int i = 0; i < int(blur_info.sample_count); i++) {
36-
float16_t coefficient = float16_t(blur_info.coefficients[i]);
37+
float16_t coefficient = float16_t(blur_info.sample_data[i].z);
3738
total_color +=
3839
coefficient *
39-
Sample(texture_sampler, v_texture_coords + blur_info.uv_offsets[i]);
40+
Sample(texture_sampler, v_texture_coords + blur_info.sample_data[i].xy);
4041
}
4142

4243
frag_color = total_color;

impeller/geometry/vector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ struct Vector4 {
310310
return *this + (v - *this) * t;
311311
}
312312

313+
constexpr Vector2 xy() const { return Vector2(x, y); }
314+
313315
std::string ToString() const;
314316
};
315317

impeller/renderer/backend/gles/buffer_bindings_gles.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,19 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
279279
auto* buffer_data =
280280
reinterpret_cast<const GLfloat*>(buffer_ptr + member.offset);
281281

282-
std::vector<uint8_t> array_element_buffer;
283-
if (element_count > 1) {
284-
// When binding uniform arrays, the elements must be contiguous. Copy
285-
// the uniforms to a temp buffer to eliminate any padding needed by the
286-
// other backends.
287-
array_element_buffer.resize(member.size * element_count);
282+
// When binding uniform arrays, the elements must be contiguous. Copy
283+
// the uniforms to a temp buffer to eliminate any padding needed by the
284+
// other backends if the array elements have padding.
285+
if (element_count > 1 && element_stride != member.size) {
286+
array_element_buffer_.resize(member.size * element_count);
288287
for (size_t element_i = 0; element_i < element_count; element_i++) {
289-
std::memcpy(array_element_buffer.data() + element_i * member.size,
288+
std::memcpy(array_element_buffer_.data() + element_i * member.size,
290289
reinterpret_cast<const char*>(buffer_data) +
291290
element_i * element_stride,
292291
member.size);
293292
}
294293
buffer_data =
295-
reinterpret_cast<const GLfloat*>(array_element_buffer.data());
294+
reinterpret_cast<const GLfloat*>(array_element_buffer_.data());
296295
}
297296

298297
switch (member.type) {

impeller/renderer/backend/gles/buffer_bindings_gles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class BufferBindingsGLES {
5757
std::vector<VertexAttribPointer> vertex_attrib_arrays_;
5858

5959
std::unordered_map<std::string, GLint> uniform_locations_;
60+
std::vector<uint8_t> array_element_buffer_;
6061

6162
using BindingMap = std::unordered_map<std::string, std::vector<GLint>>;
6263
BindingMap binding_map_ = {};

0 commit comments

Comments
 (0)