From 6f8044436eb366b8e5a055a4c4bf22b0642c0b64 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 29 Feb 2024 13:55:03 -0800 Subject: [PATCH] [Impeller] use specific format for bootstrap texture. (#51082) If we select a wide gamut format then 32 bits isn't enough to fill the texture. --- impeller/base/validation.cc | 12 ++++++++++-- impeller/base/validation.h | 10 ++++++++++ impeller/entity/contents/content_context.cc | 2 +- .../contents/content_context_unittests.cc | 19 +++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/impeller/base/validation.cc b/impeller/base/validation.cc index bbfd7efda3710..d68aa6d888bc6 100644 --- a/impeller/base/validation.cc +++ b/impeller/base/validation.cc @@ -11,7 +11,7 @@ namespace impeller { static std::atomic_int32_t sValidationLogsDisabledCount = 0; -static bool sValidationLogsAreFatal = false; +static std::atomic_int32_t sValidationLogsAreFatal = 0; void ImpellerValidationErrorsSetFatal(bool fatal) { sValidationLogsAreFatal = fatal; @@ -25,6 +25,14 @@ ScopedValidationDisable::~ScopedValidationDisable() { sValidationLogsDisabledCount--; } +ScopedValidationFatal::ScopedValidationFatal() { + sValidationLogsAreFatal++; +} + +ScopedValidationFatal::~ScopedValidationFatal() { + sValidationLogsAreFatal--; +} + ValidationLog::ValidationLog() = default; ValidationLog::~ValidationLog() { @@ -43,7 +51,7 @@ void ImpellerValidationBreak(const char* message) { std::stringstream stream; stream << "Break on '" << __FUNCTION__ << "' to inspect point of failure: " << message; - if (sValidationLogsAreFatal) { + if (sValidationLogsAreFatal > 0) { FML_LOG(FATAL) << stream.str(); } else { FML_LOG(ERROR) << stream.str(); diff --git a/impeller/base/validation.h b/impeller/base/validation.h index 50ebd0c440247..a015686c06851 100644 --- a/impeller/base/validation.h +++ b/impeller/base/validation.h @@ -49,6 +49,16 @@ struct ScopedValidationDisable { ScopedValidationDisable& operator=(const ScopedValidationDisable&) = delete; }; +struct ScopedValidationFatal { + ScopedValidationFatal(); + + ~ScopedValidationFatal(); + + ScopedValidationFatal(const ScopedValidationFatal&) = delete; + + ScopedValidationFatal& operator=(const ScopedValidationFatal&) = delete; +}; + } // namespace impeller //------------------------------------------------------------------------------ diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index e45d654bb9784..e6a2328de0dd7 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -662,7 +662,7 @@ void ContentContext::InitializeCommonlyUsedShadersIfNeeded() const { TextureDescriptor desc; desc.size = {1, 1}; desc.storage_mode = StorageMode::kHostVisible; - desc.format = context_->GetCapabilities()->GetDefaultColorFormat(); + desc.format = PixelFormat::kR8G8B8A8UNormInt; auto texture = GetContext()->GetResourceAllocator()->CreateTexture(desc); uint32_t color = 0; if (!texture->SetContents(reinterpret_cast(&color), 4u)) { diff --git a/impeller/entity/contents/content_context_unittests.cc b/impeller/entity/contents/content_context_unittests.cc index aaa71db6a6984..1736397de0553 100644 --- a/impeller/entity/contents/content_context_unittests.cc +++ b/impeller/entity/contents/content_context_unittests.cc @@ -15,6 +15,7 @@ #include "impeller/base/comparable.h" #include "impeller/core/allocator.h" #include "impeller/core/device_buffer_descriptor.h" +#include "impeller/core/formats.h" #include "impeller/core/texture_descriptor.h" #include "impeller/entity/contents/content_context.h" #include "impeller/entity/contents/test/recording_render_pass.h" @@ -50,6 +51,9 @@ class FakeTexture : public Texture { bool OnSetContents(const uint8_t* contents, size_t length, size_t slice) override { + if (GetTextureDescriptor().GetByteSizeOfBaseMipLevel() != length) { + return false; + } did_set_contents = true; return true; } @@ -209,11 +213,15 @@ class FakeCommandBuffer : public CommandBuffer { class FakeContext : public Context, public std::enable_shared_from_this { public: - explicit FakeContext(const std::string& gpu_model = "") + explicit FakeContext( + const std::string& gpu_model = "", + PixelFormat default_color_format = PixelFormat::kR8G8B8A8UNormInt) : Context(), allocator_(std::make_shared()), - capabilities_( - std::shared_ptr(CapabilitiesBuilder().Build())), + capabilities_(std::shared_ptr( + CapabilitiesBuilder() + .SetDefaultColorFormat(default_color_format) + .Build())), pipelines_(std::make_shared()), queue_(std::make_shared()), shader_library_(std::make_shared()), @@ -327,7 +335,10 @@ TEST(ContentContext, InvalidatesAllPipelinesWithSameUniqueNameOnClear) { } TEST(ContentContext, InitializeCommonlyUsedShadersIfNeeded) { - auto context = std::make_shared("Mali G70"); + ScopedValidationFatal fatal_validations; + // Set a pixel format that is larger than 32bpp. + auto context = std::make_shared("Mali G70", + PixelFormat::kR16G16B16A16Float); ContentContext content_context(context, nullptr); FakeAllocator& fake_allocator =