|
18 | 18 | #include "flutter/display_list/dl_paint.h" |
19 | 19 | #include "flutter/impeller/display_list/dl_image_impeller.h" |
20 | 20 | #include "flutter/impeller/geometry/scalar.h" |
| 21 | +#include "fml/synchronization/count_down_latch.h" |
| 22 | +#include "impeller/core/device_buffer.h" |
21 | 23 | #include "impeller/display_list/aiks_context.h" |
22 | 24 | #include "impeller/display_list/dl_dispatcher.h" |
23 | 25 | #include "impeller/playground/playground.h" |
@@ -827,6 +829,87 @@ TEST_P(AiksTest, FramebufferAdvancedBlendCoverage) { |
827 | 829 | ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); |
828 | 830 | } |
829 | 831 |
|
| 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 | + |
830 | 913 | TEST_P(AiksTest, ColorWheel) { |
831 | 914 | // Compare with https://fiddle.skia.org/c/@BlendModes |
832 | 915 |
|
|
0 commit comments