Skip to content

Commit

Permalink
[Impeller] Fix stuttering in playgrounds due to precision issue (flut…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored Oct 26, 2022
1 parent e07d8a4 commit e39c4df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
3 changes: 1 addition & 2 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2053,8 +2053,7 @@ TEST_P(EntityTest, RuntimeEffect) {
Scalar iTime;
Vector2 iResolution;
} frag_uniforms = {
.iTime = static_cast<Scalar>(
fml::TimePoint::Now().ToEpochDelta().ToSecondsF()),
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
.iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
};
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
Expand Down
8 changes: 8 additions & 0 deletions impeller/playground/playground_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/fml/time/time_point.h"

#include "impeller/playground/playground_test.h"

namespace impeller {
Expand All @@ -22,6 +24,8 @@ void PlaygroundTest::SetUp() {
}

SetupWindow(GetParam());

start_time_ = fml::TimePoint::Now().ToEpochDelta();
}

void PlaygroundTest::TearDown() {
Expand Down Expand Up @@ -59,4 +63,8 @@ std::string PlaygroundTest::GetWindowTitle() const {
return FormatWindowTitle(flutter::testing::GetCurrentTestName());
}

Scalar PlaygroundTest::GetSecondsElapsed() const {
return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF();
}

} // namespace impeller
8 changes: 8 additions & 0 deletions impeller/playground/playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <memory>

#include "flutter/fml/macros.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/testing/testing.h"
#include "impeller/geometry/scalar.h"
#include "impeller/playground/playground.h"

namespace impeller {
Expand All @@ -33,7 +35,13 @@ class PlaygroundTest : public Playground,
// |Playground|
std::string GetWindowTitle() const override;

/// @brief Get the amount of time elapsed from the start of the playground
/// test's execution.
Scalar GetSecondsElapsed() const;

private:
fml::TimeDelta start_time_;

FML_DISALLOW_COPY_AND_ASSIGN(PlaygroundTest);
};

Expand Down
13 changes: 6 additions & 7 deletions impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/fml/time/time_point.h"
#include "flutter/testing/testing.h"
#include "impeller/base/strings.h"
#include "impeller/fixtures/array.frag.h"
Expand Down Expand Up @@ -92,7 +91,7 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) {
pass.GetTransientsBuffer().EmplaceUniform(uniforms));

FS::FrameInfo frame_info;
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
frame_info.current_time = GetSecondsElapsed();
frame_info.cursor_position = GetCursorPosition();
frame_info.window_size.x = GetWindowSize().width;
frame_info.window_size.y = GetWindowSize().height;
Expand Down Expand Up @@ -181,7 +180,7 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
cmd.BindVertices(vertex_buffer);

VS::UniformBuffer uniforms;
Scalar time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
Scalar time = GetSecondsElapsed();
euler_angles = Vector3(0.19 * time, 0.7 * time, 0.43 * time);

uniforms.mvp =
Expand Down Expand Up @@ -244,7 +243,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
cmd.BindVertices(vertex_buffer);

FS::FrameInfo frame_info;
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
frame_info.current_time = GetSecondsElapsed();
frame_info.cursor_position = GetCursorPosition();
frame_info.window_size.x = GetWindowSize().width;
frame_info.window_size.y = GetWindowSize().height;
Expand Down Expand Up @@ -359,7 +358,7 @@ TEST_P(RendererTest, CanRenderToTexture) {
cmd.BindVertices(vertex_buffer);

FS::FrameInfo frame_info;
frame_info.current_time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
frame_info.current_time = GetSecondsElapsed();
frame_info.cursor_position = GetCursorPosition();
frame_info.window_size.x = GetWindowSize().width;
frame_info.window_size.y = GetWindowSize().height;
Expand Down Expand Up @@ -722,7 +721,7 @@ TEST_P(RendererTest, TheImpeller) {

FS::FragInfo fs_uniform;
fs_uniform.texture_size = Point(size);
fs_uniform.time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
fs_uniform.time = GetSecondsElapsed();
FS::BindFragInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
FS::BindBlueNoise(cmd, blue_noise, noise_sampler);
Expand Down Expand Up @@ -768,7 +767,7 @@ TEST_P(RendererTest, ArrayUniforms) {
VS::BindVertInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(vs_uniform));

auto time = fml::TimePoint::Now().ToEpochDelta().ToSecondsF();
auto time = GetSecondsElapsed();
auto y_pos = [&time](float x) {
return 400 + 10 * std::cos(time * 5 + x / 6);
};
Expand Down

0 comments on commit e39c4df

Please sign in to comment.