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
add unit test.
  • Loading branch information
jonahwilliams committed Jun 18, 2024
commit 0c7d30716fd586fc87c4a57f63c34632836c5c71
1 change: 1 addition & 0 deletions impeller/fixtures/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impellerc("runtime_stages") {
"ink_sparkle.frag",
"runtime_stage_example.frag",
"gradient.frag",
"uniforms_and_sampler.frag",
]
sl_file_extension = "iplr"

Expand Down
13 changes: 13 additions & 0 deletions impeller/fixtures/uniforms_and_sampler.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

// sampler is specifically ordered before color.
uniform sampler2D u_texture;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps another test that flips this around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

uniform vec4 u_color;

out vec4 frag_color;

void main() {
frag_color = u_color + texture(u_texture, vec2(0.5, 0.5));
}
31 changes: 31 additions & 0 deletions impeller/runtime_stage/runtime_stage_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,37 @@ TEST_P(RuntimeStageTest, CanReadUniforms) {
}
}

TEST_P(RuntimeStageTest, CanReadUniformsUBOAndSampler) {
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("uniforms_and_sampler.frag.iplr");
ASSERT_TRUE(fixture);
ASSERT_GT(fixture->GetSize(), 0u);
auto stages = RuntimeStage::DecodeRuntimeStages(fixture);
auto stage = stages[PlaygroundBackendToRuntimeStageBackend(GetBackend())];

ASSERT_TRUE(stage->IsValid());
switch (GetBackend()) {
Copy link
Member

Choose a reason for hiding this comment

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

if (GetBackends() != PlaygroundBackend::kVulkan) {
  GTEST_SKIP() << "Only matters on Vulkan.";
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

case PlaygroundBackend::kMetal:
[[fallthrough]];
case PlaygroundBackend::kOpenGLES: {
break;
case PlaygroundBackend::kVulkan: {
EXPECT_EQ(stage->GetUniforms().size(), 2u);
auto uni = stage->GetUniform(RuntimeStage::kVulkanUBOName);
ASSERT_TRUE(uni);
// Struct must be offset at 65.
EXPECT_EQ(uni->type, RuntimeUniformType::kStruct);
EXPECT_EQ(uni->binding, 65u);
// Sampler should be offset at 64 but due to current bug
// has offset of 0, the correct offset is computed at runtime.
auto sampler_uniform = stage->GetUniform("u_texture");
EXPECT_EQ(sampler_uniform->type, RuntimeUniformType::kSampledImage);
EXPECT_EQ(sampler_uniform->binding, 64u);
}
}
}
}

TEST_P(RuntimeStageTest, CanRegisterStage) {
const std::shared_ptr<fml::Mapping> fixture =
flutter::testing::OpenFixtureAsMapping("ink_sparkle.frag.iplr");
Expand Down