Skip to content

Commit 8d033d9

Browse files
committed
Fix supports_decal check in framebuffer_blend.frag
1 parent dab7c59 commit 8d033d9

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

‎engine/src/flutter/impeller/display_list/aiks_dl_blend_unittests.cc‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "flutter/display_list/dl_paint.h"
1919
#include "flutter/impeller/display_list/dl_image_impeller.h"
2020
#include "flutter/impeller/geometry/scalar.h"
21+
#include "fml/synchronization/count_down_latch.h"
22+
#include "impeller/core/device_buffer.h"
2123
#include "impeller/display_list/aiks_context.h"
2224
#include "impeller/display_list/dl_dispatcher.h"
2325
#include "impeller/playground/playground.h"
@@ -827,6 +829,87 @@ TEST_P(AiksTest, FramebufferAdvancedBlendCoverage) {
827829
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
828830
}
829831

832+
TEST_P(AiksTest,
833+
FramebufferBlendDoesNotApplyMipBiasWhenHardwareDecalSupported) {
834+
std::shared_ptr<Context> context = GetContext();
835+
const auto& caps = context->GetCapabilities();
836+
if (!caps->SupportsFramebufferFetch() ||
837+
!caps->SupportsDecalSamplerAddressMode()) {
838+
GTEST_SKIP() << "Requires framebuffer fetch and hardware decal support.";
839+
}
840+
841+
// Mip 0 (8x8) is transparent black (0); mip 1 (4x4) is opaque white (255).
842+
// Drawing at 0.5x scale selects LOD = 1.0 (white) when framebuffer_blend.frag
843+
// takes the unbiased hardware decal path (`supports_decal > 0.0`). With the
844+
// old `supports_decal > 1` check, `1.0 > 1` was false and `IPSampleDecal`
845+
// applied `kDefaultMipBias = -0.475` (LOD = 0.525), dropping output to ~134.
846+
TextureDescriptor tex_desc;
847+
tex_desc.storage_mode = StorageMode::kDevicePrivate;
848+
tex_desc.format = PixelFormat::kR8G8B8A8UNormInt;
849+
tex_desc.size = ISize{8, 8};
850+
tex_desc.mip_count = 2u;
851+
tex_desc.usage = TextureUsage::kShaderRead;
852+
auto mip_texture = context->GetResourceAllocator()->CreateTexture(tex_desc);
853+
ASSERT_TRUE(mip_texture);
854+
855+
const std::vector<uint8_t> mip0_clear(8 * 8 * 4, 0);
856+
const std::vector<uint8_t> mip1_white(4 * 4 * 4, 255);
857+
auto buf0 = context->GetResourceAllocator()->CreateBufferWithCopy(
858+
mip0_clear.data(), mip0_clear.size());
859+
auto buf1 = context->GetResourceAllocator()->CreateBufferWithCopy(
860+
mip1_white.data(), mip1_white.size());
861+
{
862+
auto cmd = context->CreateCommandBuffer();
863+
auto blit = cmd->CreateBlitPass();
864+
ASSERT_TRUE(blit->AddCopy(DeviceBuffer::AsBufferView(buf0), mip_texture,
865+
IRect::MakeSize(ISize{8, 8}), "mip0", 0u));
866+
ASSERT_TRUE(blit->AddCopy(DeviceBuffer::AsBufferView(buf1), mip_texture,
867+
IRect::MakeSize(ISize{4, 4}), "mip1", 1u));
868+
ASSERT_TRUE(blit->ConvertTextureToShaderRead(mip_texture));
869+
ASSERT_TRUE(blit->EncodeCommands());
870+
ASSERT_TRUE(context->GetCommandQueue()->Submit({cmd}).ok());
871+
}
872+
873+
DisplayListBuilder builder;
874+
builder.DrawPaint(DlPaint().setColor(DlColor::kBlack()));
875+
builder.Scale(0.5f, 0.5f);
876+
DlPaint blend_paint;
877+
blend_paint.setBlendMode(DlBlendMode::kScreen);
878+
builder.DrawImage(DlImageImpeller::Make(mip_texture), DlPoint(0, 0),
879+
DlImageSampling::kMipmapLinear, &blend_paint);
880+
881+
AiksContext renderer(context, nullptr);
882+
auto out_texture =
883+
DisplayListToTexture(builder.Build(), ISize{4, 4}, renderer);
884+
ASSERT_TRUE(out_texture);
885+
886+
DeviceBufferDescriptor readback_desc;
887+
readback_desc.size =
888+
out_texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
889+
readback_desc.readback = true;
890+
readback_desc.storage_mode = StorageMode::kHostVisible;
891+
auto readback = context->GetResourceAllocator()->CreateBuffer(readback_desc);
892+
ASSERT_TRUE(readback);
893+
{
894+
auto cmd = context->CreateCommandBuffer();
895+
auto blit = cmd->CreateBlitPass();
896+
ASSERT_TRUE(blit->AddCopy(out_texture, readback));
897+
ASSERT_TRUE(blit->EncodeCommands());
898+
auto latch = std::make_shared<fml::CountDownLatch>(1u);
899+
ASSERT_TRUE(
900+
context->GetCommandQueue()
901+
->Submit({cmd},
902+
[latch](CommandBuffer::Status) { latch->CountDown(); })
903+
.ok());
904+
latch->Wait();
905+
}
906+
907+
const uint8_t* pixel = readback->OnGetContents() + (2 * 4 + 2) * 4;
908+
EXPECT_GE(pixel[0], 253u);
909+
EXPECT_GE(pixel[1], 253u);
910+
EXPECT_GE(pixel[2], 253u);
911+
}
912+
830913
TEST_P(AiksTest, ColorWheel) {
831914
// Compare with https://fiddle.skia.org/c/@BlendModes
832915

‎engine/src/flutter/impeller/entity/shaders/blending/framebuffer_blend.frag‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ in vec2 v_src_texture_coords;
3737
out vec4 frag_color;
3838

3939
vec4 Sample(sampler2D texture_sampler, vec2 texture_coords) {
40-
if (supports_decal > 1) {
40+
if (supports_decal > 0.0) {
4141
return texture(texture_sampler, texture_coords);
4242
}
4343
return IPSampleDecal(texture_sampler, texture_coords);

0 commit comments

Comments
 (0)