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

Commit b0c07af

Browse files
committed
[Impeller] Add buffer-to-texture capability check; fix gl/vk playgrounds
1 parent 3c5a279 commit b0c07af

File tree

7 files changed

+93
-63
lines changed

7 files changed

+93
-63
lines changed

impeller/playground/playground.cc

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -395,82 +395,82 @@ std::optional<DecompressedImage> Playground::DecodeImageRGBA(
395395
return image;
396396
}
397397

398-
namespace {
399-
std::shared_ptr<Texture> CreateTextureForDecompressedImage(
398+
static std::shared_ptr<Texture> CreateTextureForDecompressedImage(
400399
const std::shared_ptr<Context>& context,
401400
DecompressedImage& decompressed_image,
402401
bool enable_mipmapping) {
403402
// TODO(https://github.com/flutter/flutter/issues/123468): copying buffers to
404403
// textures is not implemented for GLES/Vulkan.
405-
#if FML_OS_MACOSX
406-
impeller::TextureDescriptor texture_descriptor;
407-
texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate;
408-
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
409-
texture_descriptor.size = decompressed_image.GetSize();
410-
texture_descriptor.mip_count =
411-
enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u;
412-
413-
auto dest_texture =
414-
context->GetResourceAllocator()->CreateTexture(texture_descriptor);
415-
if (!dest_texture) {
416-
FML_DLOG(ERROR) << "Could not create Impeller texture.";
417-
return nullptr;
418-
}
419-
420-
auto buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
421-
*decompressed_image.GetAllocation().get());
404+
if (context->GetCapabilities()->SupportsBufferToTextureBlits()) {
405+
impeller::TextureDescriptor texture_descriptor;
406+
texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate;
407+
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
408+
texture_descriptor.size = decompressed_image.GetSize();
409+
texture_descriptor.mip_count =
410+
enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u;
411+
412+
auto dest_texture =
413+
context->GetResourceAllocator()->CreateTexture(texture_descriptor);
414+
if (!dest_texture) {
415+
FML_DLOG(ERROR) << "Could not create Impeller texture.";
416+
return nullptr;
417+
}
422418

423-
dest_texture->SetLabel(
424-
impeller::SPrintF("ui.Image(%p)", dest_texture.get()).c_str());
419+
auto buffer = context->GetResourceAllocator()->CreateBufferWithCopy(
420+
*decompressed_image.GetAllocation().get());
425421

426-
auto command_buffer = context->CreateCommandBuffer();
427-
if (!command_buffer) {
428-
FML_DLOG(ERROR) << "Could not create command buffer for mipmap generation.";
429-
return nullptr;
430-
}
431-
command_buffer->SetLabel("Mipmap Command Buffer");
422+
dest_texture->SetLabel(
423+
impeller::SPrintF("ui.Image(%p)", dest_texture.get()).c_str());
432424

433-
auto blit_pass = command_buffer->CreateBlitPass();
434-
if (!blit_pass) {
435-
FML_DLOG(ERROR) << "Could not create blit pass for mipmap generation.";
436-
return nullptr;
437-
}
438-
blit_pass->SetLabel("Mipmap Blit Pass");
439-
blit_pass->AddCopy(buffer->AsBufferView(), dest_texture);
440-
if (enable_mipmapping) {
441-
blit_pass->GenerateMipmap(dest_texture);
442-
}
425+
auto command_buffer = context->CreateCommandBuffer();
426+
if (!command_buffer) {
427+
FML_DLOG(ERROR)
428+
<< "Could not create command buffer for mipmap generation.";
429+
return nullptr;
430+
}
431+
command_buffer->SetLabel("Mipmap Command Buffer");
443432

444-
blit_pass->EncodeCommands(context->GetResourceAllocator());
445-
if (!command_buffer->SubmitCommands()) {
446-
FML_DLOG(ERROR) << "Failed to submit blit pass command buffer.";
447-
return nullptr;
448-
}
449-
return dest_texture;
450-
#else
451-
auto texture_descriptor = TextureDescriptor{};
452-
texture_descriptor.storage_mode = StorageMode::kHostVisible;
453-
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
454-
texture_descriptor.size = decompressed_image.GetSize();
455-
texture_descriptor.mip_count =
456-
enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u;
433+
auto blit_pass = command_buffer->CreateBlitPass();
434+
if (!blit_pass) {
435+
FML_DLOG(ERROR) << "Could not create blit pass for mipmap generation.";
436+
return nullptr;
437+
}
438+
blit_pass->SetLabel("Mipmap Blit Pass");
439+
blit_pass->AddCopy(buffer->AsBufferView(), dest_texture);
440+
if (enable_mipmapping) {
441+
blit_pass->GenerateMipmap(dest_texture);
442+
}
457443

458-
auto texture =
459-
context->GetResourceAllocator()->CreateTexture(texture_descriptor);
460-
if (!texture) {
461-
VALIDATION_LOG << "Could not allocate texture for fixture.";
462-
return nullptr;
463-
}
444+
blit_pass->EncodeCommands(context->GetResourceAllocator());
445+
if (!command_buffer->SubmitCommands()) {
446+
FML_DLOG(ERROR) << "Failed to submit blit pass command buffer.";
447+
return nullptr;
448+
}
449+
return dest_texture;
450+
} else { // Doesn't support buffer-to-texture blits.
451+
auto texture_descriptor = TextureDescriptor{};
452+
texture_descriptor.storage_mode = StorageMode::kHostVisible;
453+
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
454+
texture_descriptor.size = decompressed_image.GetSize();
455+
texture_descriptor.mip_count =
456+
enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u;
457+
458+
auto texture =
459+
context->GetResourceAllocator()->CreateTexture(texture_descriptor);
460+
if (!texture) {
461+
VALIDATION_LOG << "Could not allocate texture for fixture.";
462+
return nullptr;
463+
}
464464

465-
auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
466-
if (!uploaded) {
467-
VALIDATION_LOG << "Could not upload texture to device memory for fixture.";
468-
return nullptr;
465+
auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
466+
if (!uploaded) {
467+
VALIDATION_LOG
468+
<< "Could not upload texture to device memory for fixture.";
469+
return nullptr;
470+
}
471+
return texture;
469472
}
470-
return texture;
471-
#endif // FML_OS_MACOS
472473
}
473-
} // namespace
474474

475475
std::shared_ptr<Texture> Playground::CreateTextureForMapping(
476476
const std::shared_ptr<Context>& context,

impeller/renderer/backend/gles/context_gles.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ContextGLES::ContextGLES(std::unique_ptr<ProcTableGLES> gl,
6565
.SetHasThreadingRestrictions(true)
6666
.SetSupportsOffscreenMSAA(false)
6767
.SetSupportsSSBO(false)
68+
.SetSupportsBufferToTextureBlits(false)
6869
.SetSupportsTextureToTextureBlits(
6970
reactor_->GetProcTable().BlitFramebuffer.IsAvailable())
7071
.SetSupportsFramebufferFetch(false)

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {
5252
.SetHasThreadingRestrictions(false)
5353
.SetSupportsOffscreenMSAA(true)
5454
.SetSupportsSSBO(true)
55+
.SetSupportsBufferToTextureBlits(true)
5556
.SetSupportsTextureToTextureBlits(true)
5657
.SetSupportsDecalTileMode(true)
5758
.SetSupportsFramebufferFetch(DeviceSupportsFramebufferFetch(device))

impeller/renderer/backend/vulkan/capabilities_vk.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ bool CapabilitiesVK::SupportsSSBO() const {
313313
return true;
314314
}
315315

316+
// |Capabilities|
317+
bool CapabilitiesVK::SupportsBufferToTextureBlits() const {
318+
return false;
319+
}
320+
316321
// |Capabilities|
317322
bool CapabilitiesVK::SupportsTextureToTextureBlits() const {
318323
return true;

impeller/renderer/backend/vulkan/capabilities_vk.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class CapabilitiesVK final : public Capabilities,
5555
// |Capabilities|
5656
bool SupportsSSBO() const override;
5757

58+
// |Capabilities|
59+
bool SupportsBufferToTextureBlits() const override;
60+
5861
// |Capabilities|
5962
bool SupportsTextureToTextureBlits() const override;
6063

impeller/renderer/capabilities.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class StandardCapabilities final : public Capabilities {
2828
// |Capabilities|
2929
bool SupportsSSBO() const override { return supports_ssbo_; }
3030

31+
// |Capabilities|
32+
bool SupportsBufferToTextureBlits() const override {
33+
return supports_buffer_to_texture_blits_;
34+
}
35+
3136
// |Capabilities|
3237
bool SupportsTextureToTextureBlits() const override {
3338
return supports_texture_to_texture_blits_;
@@ -75,6 +80,7 @@ class StandardCapabilities final : public Capabilities {
7580
StandardCapabilities(bool has_threading_restrictions,
7681
bool supports_offscreen_msaa,
7782
bool supports_ssbo,
83+
bool supports_buffer_to_texture_blits,
7884
bool supports_texture_to_texture_blits,
7985
bool supports_framebuffer_fetch,
8086
bool supports_compute,
@@ -87,6 +93,7 @@ class StandardCapabilities final : public Capabilities {
8793
: has_threading_restrictions_(has_threading_restrictions),
8894
supports_offscreen_msaa_(supports_offscreen_msaa),
8995
supports_ssbo_(supports_ssbo),
96+
supports_buffer_to_texture_blits_(supports_buffer_to_texture_blits),
9097
supports_texture_to_texture_blits_(supports_texture_to_texture_blits),
9198
supports_framebuffer_fetch_(supports_framebuffer_fetch),
9299
supports_compute_(supports_compute),
@@ -103,6 +110,7 @@ class StandardCapabilities final : public Capabilities {
103110
bool has_threading_restrictions_ = false;
104111
bool supports_offscreen_msaa_ = false;
105112
bool supports_ssbo_ = false;
113+
bool supports_buffer_to_texture_blits_ = false;
106114
bool supports_texture_to_texture_blits_ = false;
107115
bool supports_framebuffer_fetch_ = false;
108116
bool supports_compute_ = false;
@@ -136,6 +144,12 @@ CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsSSBO(bool value) {
136144
return *this;
137145
}
138146

147+
CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsBufferToTextureBlits(
148+
bool value) {
149+
supports_buffer_to_texture_blits_ = value;
150+
return *this;
151+
}
152+
139153
CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsTextureToTextureBlits(
140154
bool value) {
141155
supports_texture_to_texture_blits_ = value;
@@ -189,6 +203,7 @@ std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
189203
has_threading_restrictions_, //
190204
supports_offscreen_msaa_, //
191205
supports_ssbo_, //
206+
supports_buffer_to_texture_blits_, //
192207
supports_texture_to_texture_blits_, //
193208
supports_framebuffer_fetch_, //
194209
supports_compute_, //

impeller/renderer/capabilities.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Capabilities {
2121

2222
virtual bool SupportsSSBO() const = 0;
2323

24+
virtual bool SupportsBufferToTextureBlits() const = 0;
25+
2426
virtual bool SupportsTextureToTextureBlits() const = 0;
2527

2628
virtual bool SupportsFramebufferFetch() const = 0;
@@ -57,6 +59,8 @@ class CapabilitiesBuilder {
5759

5860
CapabilitiesBuilder& SetSupportsSSBO(bool value);
5961

62+
CapabilitiesBuilder& SetSupportsBufferToTextureBlits(bool value);
63+
6064
CapabilitiesBuilder& SetSupportsTextureToTextureBlits(bool value);
6165

6266
CapabilitiesBuilder& SetSupportsFramebufferFetch(bool value);
@@ -80,6 +84,7 @@ class CapabilitiesBuilder {
8084
bool has_threading_restrictions_ = false;
8185
bool supports_offscreen_msaa_ = false;
8286
bool supports_ssbo_ = false;
87+
bool supports_buffer_to_texture_blits_ = false;
8388
bool supports_texture_to_texture_blits_ = false;
8489
bool supports_framebuffer_fetch_ = false;
8590
bool supports_compute_ = false;

0 commit comments

Comments
 (0)