Skip to content

Commit

Permalink
[Impeller] use specific format for bootstrap texture. (flutter#51082)
Browse files Browse the repository at this point in the history
If we select a wide gamut format then 32 bits isn't enough to fill the texture.
  • Loading branch information
jonahwilliams authored Feb 29, 2024
1 parent 7667c8a commit 6f80444
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
12 changes: 10 additions & 2 deletions impeller/base/validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +25,14 @@ ScopedValidationDisable::~ScopedValidationDisable() {
sValidationLogsDisabledCount--;
}

ScopedValidationFatal::ScopedValidationFatal() {
sValidationLogsAreFatal++;
}

ScopedValidationFatal::~ScopedValidationFatal() {
sValidationLogsAreFatal--;
}

ValidationLog::ValidationLog() = default;

ValidationLog::~ValidationLog() {
Expand All @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions impeller/base/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t*>(&color), 4u)) {
Expand Down
19 changes: 15 additions & 4 deletions impeller/entity/contents/content_context_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -209,11 +213,15 @@ class FakeCommandBuffer : public CommandBuffer {
class FakeContext : public Context,
public std::enable_shared_from_this<FakeContext> {
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<FakeAllocator>()),
capabilities_(
std::shared_ptr<Capabilities>(CapabilitiesBuilder().Build())),
capabilities_(std::shared_ptr<Capabilities>(
CapabilitiesBuilder()
.SetDefaultColorFormat(default_color_format)
.Build())),
pipelines_(std::make_shared<FakePipelineLibrary>()),
queue_(std::make_shared<CommandQueue>()),
shader_library_(std::make_shared<FakeShaderLibrary>()),
Expand Down Expand Up @@ -327,7 +335,10 @@ TEST(ContentContext, InvalidatesAllPipelinesWithSameUniqueNameOnClear) {
}

TEST(ContentContext, InitializeCommonlyUsedShadersIfNeeded) {
auto context = std::make_shared<FakeContext>("Mali G70");
ScopedValidationFatal fatal_validations;
// Set a pixel format that is larger than 32bpp.
auto context = std::make_shared<FakeContext>("Mali G70",
PixelFormat::kR16G16B16A16Float);
ContentContext content_context(context, nullptr);

FakeAllocator& fake_allocator =
Expand Down

0 comments on commit 6f80444

Please sign in to comment.