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

Commit 73a2de5

Browse files
Reverts "[Impeller] Encode directly to command buffer for Vulkan." (#49818)
Reverts #49780 Initiated by: jonahwilliams This change reverts the following previous change: Original Description: Part of flutter/flutter#140804 Rather than using impeller::Command, the impeller::RenderPass records most state directly into the Vulkan command buffer. This should remove allocation/free overhead of the intermediary structures and make further improvements to the backend even easier. This required a number of other changes to the renderer: 1. The render pass holds a strong ptr to the context. This helps avoid locking continually while encoding, which is quite slow. 2. barriers need to be encoded on the _producing_ side, and not the consuming side. This is because we'll actually run the consuming code before the producing code. i.e. we transition to shader read at the end of a render pass instead of when binding. 3. I've updated the binding code to also provide the descriptor type so that we don't need to look it up from the desc. set. 4. I added a test render pass class that records commands.
1 parent 60ce382 commit 73a2de5

40 files changed

+445
-805
lines changed

impeller/aiks/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impeller_component("context_spy") {
7676
"testing/context_spy.h",
7777
]
7878
deps = [
79-
"//flutter/impeller/entity:entity_test_helpers",
8079
"//flutter/impeller/renderer",
8180
"//flutter/testing:testing_lib",
8281
]

impeller/aiks/testing/context_spy.cc

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

5-
#include <memory>
6-
75
#include "impeller/aiks/testing/context_spy.h"
86

97
namespace impeller {
@@ -66,17 +64,14 @@ std::shared_ptr<ContextMock> ContextSpy::MakeContext(
6664
});
6765

6866
ON_CALL(*spy, OnCreateRenderPass)
69-
.WillByDefault([real_buffer, shared_this,
70-
real_context](const RenderTarget& render_target) {
71-
std::shared_ptr<RenderPass> result =
72-
CommandBufferMock::ForwardOnCreateRenderPass(
73-
real_buffer.get(), render_target);
74-
std::shared_ptr<RecordingRenderPass> recorder =
75-
std::make_shared<RecordingRenderPass>(result, real_context,
76-
render_target);
77-
shared_this->render_passes_.push_back(recorder);
78-
return recorder;
79-
});
67+
.WillByDefault(
68+
[real_buffer, shared_this](const RenderTarget& render_target) {
69+
std::shared_ptr<RenderPass> result =
70+
CommandBufferMock::ForwardOnCreateRenderPass(
71+
real_buffer.get(), render_target);
72+
shared_this->render_passes_.push_back(result);
73+
return result;
74+
});
8075

8176
ON_CALL(*spy, OnCreateBlitPass).WillByDefault([real_buffer]() {
8277
return CommandBufferMock::ForwardOnCreateBlitPass(real_buffer.get());

impeller/aiks/testing/context_spy.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#define FLUTTER_IMPELLER_AIKS_TESTING_CONTEXT_SPY_H_
77

88
#include <memory>
9-
109
#include "impeller/aiks/testing/context_mock.h"
11-
#include "impeller/entity/contents/test/recording_render_pass.h"
1210

1311
namespace impeller {
1412
namespace testing {
@@ -22,7 +20,7 @@ class ContextSpy : public std::enable_shared_from_this<ContextSpy> {
2220
std::shared_ptr<ContextMock> MakeContext(
2321
const std::shared_ptr<Context>& real_context);
2422

25-
std::vector<std::shared_ptr<RecordingRenderPass>> render_passes_;
23+
std::vector<std::shared_ptr<RenderPass>> render_passes_;
2624

2725
private:
2826
ContextSpy() = default;

impeller/compiler/code_gen_template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
161161
{% endfor %}) {
162162
return {{ proto.args.0.argument_name }}.BindResource({% for arg in proto.args %}
163163
{% if loop.is_first %}
164-
{{to_shader_stage(shader_stage)}}, {{ proto.descriptor_type }}, kResource{{ proto.name }}, kMetadata{{ proto.name }}, {% else %}
164+
{{to_shader_stage(shader_stage)}}, kResource{{ proto.name }}, kMetadata{{ proto.name }}, {% else %}
165165
std::move({{ arg.argument_name }}){% if not loop.is_last %}, {% endif %}
166166
{% endif %}
167167
{% endfor %});

impeller/compiler/reflector.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,6 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
13081308
auto& proto = prototypes.emplace_back(BindPrototype{});
13091309
proto.return_type = "bool";
13101310
proto.name = ToCamelCase(uniform_buffer.name);
1311-
proto.descriptor_type = "DescriptorType::kUniformBuffer";
13121311
{
13131312
std::stringstream stream;
13141313
stream << "Bind uniform buffer for resource named " << uniform_buffer.name
@@ -1328,7 +1327,6 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
13281327
auto& proto = prototypes.emplace_back(BindPrototype{});
13291328
proto.return_type = "bool";
13301329
proto.name = ToCamelCase(storage_buffer.name);
1331-
proto.descriptor_type = "DescriptorType::kStorageBuffer";
13321330
{
13331331
std::stringstream stream;
13341332
stream << "Bind storage buffer for resource named " << storage_buffer.name
@@ -1348,7 +1346,6 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
13481346
auto& proto = prototypes.emplace_back(BindPrototype{});
13491347
proto.return_type = "bool";
13501348
proto.name = ToCamelCase(sampled_image.name);
1351-
proto.descriptor_type = "DescriptorType::kSampledImage";
13521349
{
13531350
std::stringstream stream;
13541351
stream << "Bind combined image sampler for resource named "
@@ -1372,7 +1369,6 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
13721369
auto& proto = prototypes.emplace_back(BindPrototype{});
13731370
proto.return_type = "bool";
13741371
proto.name = ToCamelCase(separate_image.name);
1375-
proto.descriptor_type = "DescriptorType::kImage";
13761372
{
13771373
std::stringstream stream;
13781374
stream << "Bind separate image for resource named " << separate_image.name
@@ -1392,7 +1388,6 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
13921388
auto& proto = prototypes.emplace_back(BindPrototype{});
13931389
proto.return_type = "bool";
13941390
proto.name = ToCamelCase(separate_sampler.name);
1395-
proto.descriptor_type = "DescriptorType::kSampler";
13961391
{
13971392
std::stringstream stream;
13981393
stream << "Bind separate sampler for resource named "
@@ -1421,7 +1416,6 @@ nlohmann::json::array_t Reflector::EmitBindPrototypes(
14211416
item["return_type"] = res.return_type;
14221417
item["name"] = res.name;
14231418
item["docstring"] = res.docstring;
1424-
item["descriptor_type"] = res.descriptor_type;
14251419
auto& args = item["args"] = nlohmann::json::array_t{};
14261420
for (const auto& arg : res.args) {
14271421
auto& json_arg = args.emplace_back(nlohmann::json::object_t{});

impeller/compiler/reflector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class Reflector {
187187
std::string name;
188188
std::string return_type;
189189
std::string docstring;
190-
std::string descriptor_type = "";
191190
std::vector<BindPrototypeArgument> args;
192191
};
193192

impeller/core/resource_binder.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ struct ResourceBinder {
2424
virtual ~ResourceBinder() = default;
2525

2626
virtual bool BindResource(ShaderStage stage,
27-
DescriptorType type,
2827
const ShaderUniformSlot& slot,
2928
const ShaderMetadata& metadata,
3029
BufferView view) = 0;
3130

3231
virtual bool BindResource(ShaderStage stage,
33-
DescriptorType type,
3432
const SampledImageSlot& slot,
3533
const ShaderMetadata& metadata,
3634
std::shared_ptr<const Texture> texture,

impeller/entity/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ impeller_component("entity_test_helpers") {
257257
sources = [
258258
"contents/test/contents_test_helpers.cc",
259259
"contents/test/contents_test_helpers.h",
260-
"contents/test/recording_render_pass.cc",
261-
"contents/test/recording_render_pass.h",
262260
]
263261

264262
deps = [ ":entity" ]

impeller/entity/contents/checkerboard_contents_unittests.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "impeller/entity/contents/checkerboard_contents.h"
1111
#include "impeller/entity/contents/contents.h"
12-
#include "impeller/entity/contents/test/recording_render_pass.h"
1312
#include "impeller/entity/entity.h"
1413
#include "impeller/entity/entity_playground.h"
1514
#include "impeller/renderer/render_target.h"
@@ -39,14 +38,11 @@ TEST_P(EntityTest, RendersWithoutError) {
3938
*GetContentContext()->GetRenderTargetCache(), {100, 100},
4039
/*mip_count=*/1);
4140
auto render_pass = buffer->CreateRenderPass(render_target);
42-
auto recording_pass = std::make_shared<RecordingRenderPass>(
43-
render_pass, GetContext(), render_target);
44-
4541
Entity entity;
4642

47-
ASSERT_TRUE(recording_pass->GetCommands().empty());
48-
ASSERT_TRUE(contents->Render(*content_context, entity, *recording_pass));
49-
ASSERT_FALSE(recording_pass->GetCommands().empty());
43+
ASSERT_TRUE(render_pass->GetCommands().empty());
44+
ASSERT_TRUE(contents->Render(*content_context, entity, *render_pass));
45+
ASSERT_FALSE(render_pass->GetCommands().empty());
5046
}
5147
#endif // IMPELLER_DEBUG
5248

impeller/entity/contents/runtime_effect_contents.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
199199
ShaderUniformSlot uniform_slot;
200200
uniform_slot.name = uniform.name.c_str();
201201
uniform_slot.ext_res_0 = uniform.location;
202-
pass.BindResource(ShaderStage::kFragment,
203-
DescriptorType::kUniformBuffer, uniform_slot,
204-
metadata, buffer_view);
202+
pass.BindResource(ShaderStage::kFragment, uniform_slot, metadata,
203+
buffer_view);
205204
buffer_index++;
206205
buffer_offset += uniform.GetSize();
207206
break;
@@ -238,8 +237,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
238237
auto buffer_view = renderer.GetTransientsBuffer().Emplace(
239238
reinterpret_cast<const void*>(uniform_buffer.data()),
240239
sizeof(float) * uniform_buffer.size(), alignment);
241-
pass.BindResource(ShaderStage::kFragment,
242-
DescriptorType::kUniformBuffer, uniform_slot,
240+
pass.BindResource(ShaderStage::kFragment, uniform_slot,
243241
ShaderMetadata{}, buffer_view);
244242
}
245243
}
@@ -273,8 +271,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
273271

274272
image_slot.binding = sampler_binding_location;
275273
image_slot.texture_index = uniform.location - minimum_sampler_index;
276-
pass.BindResource(ShaderStage::kFragment, DescriptorType::kSampledImage,
277-
image_slot, *metadata, input.texture, sampler);
274+
pass.BindResource(ShaderStage::kFragment, image_slot, *metadata,
275+
input.texture, sampler);
278276

279277
sampler_index++;
280278
break;

0 commit comments

Comments
 (0)