This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Support user defined structs in buffers, clean up compute tests #37084
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// 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/compute_playground_test.h" | ||
|
||
namespace impeller { | ||
|
||
ComputePlaygroundTest::ComputePlaygroundTest() = default; | ||
|
||
ComputePlaygroundTest::~ComputePlaygroundTest() = default; | ||
|
||
void ComputePlaygroundTest::SetUp() { | ||
if (!Playground::SupportsBackend(GetParam())) { | ||
GTEST_SKIP_("Playground doesn't support this backend type."); | ||
return; | ||
} | ||
|
||
if (!Playground::ShouldOpenNewPlaygrounds()) { | ||
GTEST_SKIP_("Skipping due to user action."); | ||
return; | ||
} | ||
|
||
SetupContext(GetParam()); | ||
|
||
start_time_ = fml::TimePoint::Now().ToEpochDelta(); | ||
} | ||
|
||
void ComputePlaygroundTest::TearDown() { | ||
TeardownWindow(); | ||
} | ||
|
||
// |Playground| | ||
std::unique_ptr<fml::Mapping> ComputePlaygroundTest::OpenAssetAsMapping( | ||
std::string asset_name) const { | ||
return flutter::testing::OpenFixtureAsMapping(asset_name); | ||
} | ||
|
||
std::shared_ptr<RuntimeStage> ComputePlaygroundTest::OpenAssetAsRuntimeStage( | ||
const char* asset_name) const { | ||
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name); | ||
if (!fixture || fixture->GetSize() == 0) { | ||
return nullptr; | ||
} | ||
auto stage = std::make_unique<RuntimeStage>(std::move(fixture)); | ||
if (!stage->IsValid()) { | ||
return nullptr; | ||
} | ||
return stage; | ||
} | ||
|
||
static std::string FormatWindowTitle(const std::string& test_name) { | ||
std::stringstream stream; | ||
stream << "Impeller Playground for '" << test_name | ||
<< "' (Press ESC or 'q' to quit)"; | ||
return stream.str(); | ||
} | ||
|
||
// |Playground| | ||
std::string ComputePlaygroundTest::GetWindowTitle() const { | ||
return FormatWindowTitle(flutter::testing::GetCurrentTestName()); | ||
} | ||
|
||
Scalar ComputePlaygroundTest::GetSecondsElapsed() const { | ||
return (fml::TimePoint::Now().ToEpochDelta() - start_time_).ToSecondsF(); | ||
} | ||
|
||
} // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#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 { | ||
|
||
class ComputePlaygroundTest | ||
: public Playground, | ||
public ::testing::TestWithParam<PlaygroundBackend> { | ||
public: | ||
ComputePlaygroundTest(); | ||
|
||
virtual ~ComputePlaygroundTest(); | ||
|
||
void SetUp() override; | ||
|
||
void TearDown() override; | ||
|
||
// |Playground| | ||
std::unique_ptr<fml::Mapping> OpenAssetAsMapping( | ||
std::string asset_name) const override; | ||
|
||
std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage( | ||
const char* asset_name) const; | ||
|
||
// |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(ComputePlaygroundTest); | ||
}; | ||
|
||
#define INSTANTIATE_COMPUTE_SUITE(playground) \ | ||
INSTANTIATE_TEST_SUITE_P( \ | ||
Compute, playground, ::testing::Values(PlaygroundBackend::kMetal), \ | ||
[](const ::testing::TestParamInfo<ComputePlaygroundTest::ParamType>& \ | ||
info) { return PlaygroundBackendToString(info.param); }); | ||
|
||
} // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
#include "flutter/testing/testing.h" | ||
#include "impeller/base/strings.h" | ||
#include "impeller/fixtures/sample.comp.h" | ||
#include "impeller/playground/playground_test.h" | ||
#include "impeller/playground/compute_playground_test.h" | ||
#include "impeller/renderer/command_buffer.h" | ||
#include "impeller/renderer/compute_command.h" | ||
#include "impeller/renderer/compute_pipeline_builder.h" | ||
|
@@ -17,17 +17,10 @@ | |
namespace impeller { | ||
namespace testing { | ||
|
||
using ComputeTest = PlaygroundTest; | ||
INSTANTIATE_PLAYGROUND_SUITE(ComputeTest); | ||
using ComputeTest = ComputePlaygroundTest; | ||
INSTANTIATE_COMPUTE_SUITE(ComputeTest); | ||
|
||
TEST_P(ComputeTest, CanCreateComputePass) { | ||
if (GetParam() == PlaygroundBackend::kOpenGLES) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean to remove these skips? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - this now gets skipped in the macro for setting up a compute playground. We can add Vulkan and GLES when/if we start supporting them. |
||
GTEST_SKIP_("Compute is not supported on GL."); | ||
} | ||
if (GetParam() == PlaygroundBackend::kVulkan) { | ||
GTEST_SKIP_("Compute is not supported on Vulkan yet."); | ||
} | ||
|
||
using CS = SampleComputeShader; | ||
auto context = GetContext(); | ||
ASSERT_TRUE(context); | ||
|
@@ -63,6 +56,7 @@ TEST_P(ComputeTest, CanCreateComputePass) { | |
input_0.fixed_array[1] = IPoint32(2, 2); | ||
input_1.fixed_array[0] = UintPoint32(3, 3); | ||
input_0.some_int = 5; | ||
input_1.some_struct = CS::SomeStruct{.vf = Point(3, 4), .i = 42}; | ||
|
||
DeviceBufferDescriptor buffer_desc; | ||
buffer_desc.storage_mode = StorageMode::kHostVisible; | ||
|
@@ -97,8 +91,10 @@ TEST_P(ComputeTest, CanCreateComputePass) { | |
for (size_t i = 0; i < kCount; i++) { | ||
Vector4 vector = output->elements[i]; | ||
Vector4 computed = input_0.elements[i] * input_1.elements[i]; | ||
EXPECT_EQ(vector, Vector4(computed.x + 2, computed.y + 3, | ||
computed.z + 5, computed.w)); | ||
EXPECT_EQ(vector, Vector4(computed.x + 2 + input_1.some_struct.i, | ||
computed.y + 3 + input_1.some_struct.vf.x, | ||
computed.z + 5 + input_1.some_struct.vf.y, | ||
computed.w)); | ||
} | ||
latch.Signal(); | ||
})); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this adds support for nested structs across all backend and stage types? Might be worth adding a small raster test that uses a nested struct (and make sure the GLES metadata doesn't need to be updated for this).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proooobably?
I'll give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to punt on this fornow - I'm still trying to track down what to do about the buffer to texture issue and want to keep making progress on compute right now.