Skip to content

Commit f32021c

Browse files
author
Jonah Williams
authored
[Impeller] mark decoded images as optimized for GPU access (flutter#40356)
[Impeller] mark decoded images as optimized for GPU access
1 parent 8d0747f commit f32021c

12 files changed

Lines changed: 86 additions & 0 deletions

File tree

impeller/renderer/backend/gles/blit_pass_gles.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ bool BlitPassGLES::OnCopyTextureToBufferCommand(
130130
return true;
131131
}
132132

133+
bool BlitPassGLES::OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
134+
std::string label) {
135+
return true;
136+
}
137+
133138
// |BlitPass|
134139
bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
135140
std::string label) {

impeller/renderer/backend/gles/blit_pass_gles.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class BlitPassGLES final : public BlitPass {
5050
size_t destination_offset,
5151
std::string label) override;
5252

53+
// |BlitPass|
54+
bool OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
55+
std::string label) override;
56+
5357
// |BlitPass|
5458
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
5559
std::string label) override;

impeller/renderer/backend/metal/blit_command_mtl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,13 @@ struct BlitGenerateMipmapCommandMTL : public BlitGenerateMipmapCommand,
5050
[[nodiscard]] bool Encode(id<MTLBlitCommandEncoder> encoder) const override;
5151
};
5252

53+
struct BlitOptimizeGPUAccessCommandMTL : public BlitGenerateMipmapCommand,
54+
public BlitEncodeMTL {
55+
~BlitOptimizeGPUAccessCommandMTL() override;
56+
57+
std::string GetLabel() const override;
58+
59+
[[nodiscard]] bool Encode(id<MTLBlitCommandEncoder> encoder) const override;
60+
};
61+
5362
} // namespace impeller

impeller/renderer/backend/metal/blit_command_mtl.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,23 @@
112112
return true;
113113
};
114114

115+
BlitOptimizeGPUAccessCommandMTL::~BlitOptimizeGPUAccessCommandMTL() = default;
116+
117+
std::string BlitOptimizeGPUAccessCommandMTL::GetLabel() const {
118+
return label;
119+
}
120+
121+
bool BlitOptimizeGPUAccessCommandMTL::Encode(
122+
id<MTLBlitCommandEncoder> encoder) const {
123+
if (@available(macOS 10.14, iOS 12, tvOS 12, *)) {
124+
auto texture_mtl = TextureMTL::Cast(*texture).GetMTLTexture();
125+
if (!texture_mtl) {
126+
return false;
127+
}
128+
129+
[encoder optimizeContentsForGPUAccess:texture_mtl];
130+
}
131+
return true;
132+
}
133+
115134
} // namespace impeller

impeller/renderer/backend/metal/blit_pass_mtl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class BlitPassMTL final : public BlitPass {
5757
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
5858
std::string label) override;
5959

60+
// |BlitPass|
61+
bool OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
62+
std::string label) override;
63+
6064
FML_DISALLOW_COPY_AND_ASSIGN(BlitPassMTL);
6165
};
6266

impeller/renderer/backend/metal/blit_pass_mtl.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,15 @@
134134
return true;
135135
}
136136

137+
// |BlitPass|
138+
bool BlitPassMTL::OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
139+
std::string label) {
140+
auto command = std::make_unique<BlitOptimizeGPUAccessCommandMTL>();
141+
command->label = label;
142+
command->texture = std::move(texture);
143+
144+
commands_.emplace_back(std::move(command));
145+
return true;
146+
}
147+
137148
} // namespace impeller

impeller/renderer/backend/vulkan/blit_pass_vk.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ bool BlitPassVK::OnCopyTextureToBufferCommand(
8787
return true;
8888
}
8989

90+
// |BlitPass|
91+
bool BlitPassVK::OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
92+
std::string label) {
93+
return true;
94+
}
95+
9096
// |BlitPass|
9197
bool BlitPassVK::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
9298
std::string label) {

impeller/renderer/backend/vulkan/blit_pass_vk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class BlitPassVK final : public BlitPass {
5151
std::string label) override;
5252

5353
// |BlitPass|
54+
bool OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
55+
std::string label) override;
56+
// |BlitPass|
5457
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
5558
std::string label) override;
5659

impeller/renderer/blit_pass.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ bool BlitPass::AddCopy(std::shared_ptr<Texture> source,
116116
std::move(label));
117117
}
118118

119+
bool BlitPass::OptimizeForGPUAccess(std::shared_ptr<Texture> texture,
120+
std::string label) {
121+
return OnOptimizeForGPUAccess(std::move(texture), std::move(label));
122+
}
123+
119124
bool BlitPass::GenerateMipmap(std::shared_ptr<Texture> texture,
120125
std::string label) {
121126
if (!texture) {

impeller/renderer/blit_pass.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ class BlitPass {
9595
///
9696
bool GenerateMipmap(std::shared_ptr<Texture> texture, std::string label = "");
9797

98+
//----------------------------------------------------------------------------
99+
/// @brief Optimize the provided texture for GPU access.
100+
/// This will no-op on platforms where this functionality is
101+
/// unsupported.
102+
///
103+
/// @param[in] texture The texture to generate mipmaps for.
104+
/// @param[in] label The optional debug label to give the command.
105+
///
106+
/// @return If the command was valid for subsequent commitment.
107+
///
108+
bool OptimizeForGPUAccess(std::shared_ptr<Texture> texture,
109+
std::string label = "");
110+
98111
//----------------------------------------------------------------------------
99112
/// @brief Encode the recorded commands to the underlying command buffer.
100113
///
@@ -127,6 +140,9 @@ class BlitPass {
127140
size_t destination_offset,
128141
std::string label) = 0;
129142

143+
virtual bool OnOptimizeForGPUAccess(std::shared_ptr<Texture> texture,
144+
std::string label) = 0;
145+
130146
virtual bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
131147
std::string label) = 0;
132148

0 commit comments

Comments
 (0)