Skip to content

Commit dad4edb

Browse files
author
Jonah Williams
authored
[Impeller] fix remaining Validation errors. (flutter#51692)
Fixes flutter#145039 Some of the errors were due to unconsumed fragment shader inputs. Enabling VK_KHR_maintenance4 relaxes this restriction.
1 parent d656625 commit dad4edb

7 files changed

Lines changed: 34 additions & 63 deletions

File tree

impeller/entity/entity_unittests.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ TEST_P(EntityTest, RuntimeEffect) {
22002200
ASSERT_TRUE(runtime_stage->IsDirty());
22012201

22022202
bool expect_dirty = true;
2203-
Pipeline<PipelineDescriptor>* first_pipeline = nullptr;
2203+
Pipeline<PipelineDescriptor>* first_pipeline;
22042204
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
22052205
EXPECT_EQ(runtime_stage->IsDirty(), expect_dirty);
22062206

@@ -2238,7 +2238,10 @@ TEST_P(EntityTest, RuntimeEffect) {
22382238
// Simulate some renders and hot reloading of the shader.
22392239
auto content_context = GetContentContext();
22402240
{
2241-
RenderTarget target;
2241+
RenderTarget target =
2242+
content_context->GetRenderTargetCache()->CreateOffscreen(
2243+
*content_context->GetContext(), {1, 1}, 1u);
2244+
22422245
testing::MockRenderPass mock_pass(GetContext(), target);
22432246
callback(*content_context, mock_pass);
22442247
callback(*content_context, mock_pass);
@@ -2252,10 +2255,7 @@ TEST_P(EntityTest, RuntimeEffect) {
22522255
expect_dirty = true;
22532256

22542257
callback(*content_context, mock_pass);
2255-
callback(*content_context, mock_pass);
22562258
}
2257-
2258-
ASSERT_TRUE(OpenPlaygroundHere(callback));
22592259
}
22602260

22612261
TEST_P(EntityTest, RuntimeEffectCanSuccessfullyRender) {
@@ -2319,7 +2319,6 @@ TEST_P(EntityTest, RuntimeEffectSetsRightSizeWhenUniformIsStruct) {
23192319

23202320
auto contents = std::make_shared<RuntimeEffectContents>();
23212321
contents->SetGeometry(Geometry::MakeCover());
2322-
23232322
contents->SetRuntimeStage(runtime_stage);
23242323

23252324
struct FragUniforms {
@@ -2338,7 +2337,9 @@ TEST_P(EntityTest, RuntimeEffectSetsRightSizeWhenUniformIsStruct) {
23382337
entity.SetContents(contents);
23392338

23402339
auto context = GetContentContext();
2341-
RenderTarget target;
2340+
RenderTarget target = context->GetRenderTargetCache()->CreateOffscreen(
2341+
*context->GetContext(), {1, 1}, 1u);
2342+
23422343
testing::MockRenderPass pass(GetContext(), target);
23432344
ASSERT_TRUE(contents->Render(*context, entity, pass));
23442345
ASSERT_EQ(pass.GetCommands().size(), 1u);

impeller/fixtures/runtime_stage_example.frag

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
layout(location = 0) uniform vec2 iResolution;
6-
layout(location = 1) uniform float iTime;
5+
#include <flutter/runtime_effect.glsl>
76

8-
layout(location = 0) out vec4 fragColor;
7+
uniform vec2 iResolution;
8+
uniform float iTime;
9+
10+
out vec4 fragColor;
911

1012
void main() {
11-
vec2 uv = gl_FragCoord.xy / iResolution;
13+
vec2 uv = FlutterFragCoord() / iResolution;
1214
float t = 4 * iTime;
1315
vec3 col = 0.5 + 0.5 * cos(t + uv.xyx + vec3(0, 1, 4));
1416
fragColor = vec4(col, 1.0);

impeller/golden_tests/golden_playground_test_mac.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ bool SaveScreenshot(std::unique_ptr<testing::Screenshot> screenshot) {
104104
return true;
105105
}
106106

107-
bool ShouldTestHaveVulkanValidations() {
108-
std::string test_name = GetTestName();
109-
return std::find(kVulkanDenyValidationTests.begin(),
110-
kVulkanDenyValidationTests.end(),
111-
test_name) == kVulkanDenyValidationTests.end();
112-
}
113107
} // namespace
114108

115109
struct GoldenPlaygroundTest::GoldenPlaygroundTestImpl {
@@ -144,14 +138,13 @@ void GoldenPlaygroundTest::SetUp() {
144138
std::filesystem::path icd_path = target_path / "vk_swiftshader_icd.json";
145139
setenv("VK_ICD_FILENAMES", icd_path.c_str(), 1);
146140

147-
bool enable_vulkan_validations = ShouldTestHaveVulkanValidations();
148141
switch (GetParam()) {
149142
case PlaygroundBackend::kMetal:
150143
pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
151144
break;
152145
case PlaygroundBackend::kVulkan: {
153146
const std::unique_ptr<PlaygroundImpl>& playground =
154-
GetSharedVulkanPlayground(enable_vulkan_validations);
147+
GetSharedVulkanPlayground(/*enable_validations=*/true);
155148
pimpl_->screenshotter =
156149
std::make_unique<testing::VulkanScreenshotter>(playground);
157150
break;
@@ -171,7 +164,7 @@ void GoldenPlaygroundTest::SetUp() {
171164
pimpl_->screenshotter = std::make_unique<testing::MetalScreenshotter>();
172165
} else if (GetParam() == PlaygroundBackend::kVulkan) {
173166
const std::unique_ptr<PlaygroundImpl>& playground =
174-
GetSharedVulkanPlayground(enable_vulkan_validations);
167+
GetSharedVulkanPlayground(/*enable_validations=*/true);
175168
pimpl_->screenshotter =
176169
std::make_unique<testing::VulkanScreenshotter>(playground);
177170
}
@@ -257,7 +250,7 @@ std::shared_ptr<Context> GoldenPlaygroundTest::MakeContext() const {
257250
/// On Metal we create a context for each test.
258251
return GetContext();
259252
} else if (GetParam() == PlaygroundBackend::kVulkan) {
260-
bool enable_vulkan_validations = ShouldTestHaveVulkanValidations();
253+
bool enable_vulkan_validations = true;
261254
FML_CHECK(!pimpl_->test_vulkan_playground)
262255
<< "We don't support creating multiple contexts for one test";
263256
pimpl_->test_vulkan_playground =

impeller/playground/playground.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ enum class PlaygroundBackend {
3232
kVulkan,
3333
};
3434

35-
// TODO(https://github.com/flutter/flutter/issues/145039)
36-
// clang-format off
37-
static const std::vector<std::string> kVulkanDenyValidationTests = {
38-
"impeller_Play_SceneTest_FlutterLogo_Vulkan",
39-
"impeller_Play_SceneTest_CuboidUnlit_Vulkan",
40-
"impeller_Play_RuntimeStageTest_CanCreatePipelineFromRuntimeStage_Vulkan",
41-
"impeller_Play_RuntimeEffectSetsRightSizeWhenUniformIsStruct_Vulkan",
42-
"impeller_Play_RuntimeEffectCanSuccessfullyRender_Vulkan",
43-
"impeller_Play_RuntimeEffect_Vulkan",
44-
"impeller_Play_EntityTest_RuntimeStageTest_CanCreatePipelineFromRuntimeStage_Vulkan",
45-
"impeller_Play_EntityTest_RuntimeEffectSetsRightSizeWhenUniformIsStruct_Vulkan",
46-
"impeller_Play_EntityTest_RuntimeEffectCanSuccessfullyRender_Vulkan",
47-
"impeller_Play_EntityTest_RuntimeEffect_Vulkan",
48-
};
49-
// clang-format on
50-
5135
constexpr inline RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(
5236
PlaygroundBackend backend) {
5337
switch (backend) {

impeller/playground/playground_impl.cc

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@
2020
#include "impeller/playground/backend/vulkan/playground_impl_vk.h"
2121
#endif // IMPELLER_ENABLE_VULKAN
2222

23-
namespace {
24-
25-
std::string GetTestName() {
26-
std::string suite_name =
27-
::testing::UnitTest::GetInstance()->current_test_suite()->name();
28-
std::string test_name =
29-
::testing::UnitTest::GetInstance()->current_test_info()->name();
30-
std::stringstream ss;
31-
ss << "impeller_" << suite_name << "_" << test_name;
32-
std::string result = ss.str();
33-
// Make sure there are no slashes in the test name.
34-
std::replace(result.begin(), result.end(), '/', '_');
35-
return result;
36-
}
37-
38-
bool ShouldTestHaveVulkanValidations() {
39-
std::string test_name = GetTestName();
40-
return std::find(impeller::kVulkanDenyValidationTests.begin(),
41-
impeller::kVulkanDenyValidationTests.end(),
42-
test_name) == impeller::kVulkanDenyValidationTests.end();
43-
}
44-
} // namespace
45-
4623
namespace impeller {
4724

4825
std::unique_ptr<PlaygroundImpl> PlaygroundImpl::Create(
@@ -64,7 +41,7 @@ std::unique_ptr<PlaygroundImpl> PlaygroundImpl::Create(
6441
"isn't available or was disabled on this platform: "
6542
<< PlaygroundBackendToString(backend);
6643
}
67-
switches.enable_vulkan_validation = ShouldTestHaveVulkanValidations();
44+
switches.enable_vulkan_validation = true;
6845
return std::make_unique<PlaygroundImplVK>(switches);
6946
#endif // IMPELLER_ENABLE_VULKAN
7047
default:

impeller/runtime_stage/runtime_stage_unittests.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,16 @@ TEST_P(RuntimeStageTest, CanCreatePipelineFromRuntimeStage) {
277277
auto vertex_descriptor = std::make_shared<VertexDescriptor>();
278278
vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
279279
VS::kInterleavedBufferLayout);
280-
vertex_descriptor->RegisterDescriptorSetLayouts(VS::kDescriptorSetLayouts);
280+
281+
std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
282+
VS::kDescriptorSetLayouts[0],
283+
DescriptorSetLayout{
284+
.binding = 64u,
285+
.descriptor_type = DescriptorType::kUniformBuffer,
286+
.shader_stage = ShaderStage::kFragment,
287+
},
288+
};
289+
vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
281290

282291
desc.SetVertexDescriptor(std::move(vertex_descriptor));
283292
ColorAttachmentDescriptor color0;

impeller/scene/shaders/unlit.frag

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ in vec4 v_color;
1717

1818
out vec4 frag_color;
1919

20+
float consume_unused() {
21+
return (v_position.x + v_tangent_space[0][0]) * 0.001;
22+
}
23+
2024
void main() {
2125
vec4 vertex_color = mix(vec4(1), v_color, frag_info.vertex_color_weight);
2226
frag_color = texture(base_color_texture, v_texture_coords) * vertex_color *
23-
frag_info.color;
27+
frag_info.color +
28+
consume_unused();
2429
}

0 commit comments

Comments
 (0)