diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 7df6ebd554cb6..c6c3a0cf52749 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -3458,6 +3458,57 @@ TEST_P(AiksTest, CanRenderClippedBackdropFilter) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, MipmapGenerationWorksCorrectly) { + TextureDescriptor texture_descriptor; + texture_descriptor.size = ISize{1024, 1024}; + texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt; + texture_descriptor.storage_mode = StorageMode::kHostVisible; + texture_descriptor.mip_count = texture_descriptor.size.MipCount(); + + std::vector bytes(4194304); + bool alternate = false; + for (auto i = 0u; i < 4194304; i += 4) { + if (alternate) { + bytes[i] = 255; + bytes[i + 1] = 0; + bytes[i + 2] = 0; + bytes[i + 3] = 255; + } else { + bytes[i] = 0; + bytes[i + 1] = 255; + bytes[i + 2] = 0; + bytes[i + 3] = 255; + } + alternate = !alternate; + } + + ASSERT_EQ(texture_descriptor.GetByteSizeOfBaseMipLevel(), bytes.size()); + auto mapping = std::make_shared( + bytes.data(), // data + texture_descriptor.GetByteSizeOfBaseMipLevel() // size + ); + auto texture = + GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor); + + ASSERT_TRUE(!!texture); + ASSERT_TRUE(texture->SetContents(mapping)); + + auto command_buffer = GetContext()->CreateCommandBuffer(); + auto blit_pass = command_buffer->CreateBlitPass(); + + blit_pass->GenerateMipmap(texture); + EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator())); + EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({command_buffer}).ok()); + + auto image = std::make_shared(texture); + + Canvas canvas; + canvas.DrawImageRect(image, Rect::MakeSize(texture->GetSize()), + Rect::MakeLTRB(0, 0, 100, 100), {}); + + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + } // namespace testing } // namespace impeller diff --git a/impeller/renderer/backend/vulkan/sampler_vk.cc b/impeller/renderer/backend/vulkan/sampler_vk.cc index 175507d1ab9bf..2e0946302d5cf 100644 --- a/impeller/renderer/backend/vulkan/sampler_vk.cc +++ b/impeller/renderer/backend/vulkan/sampler_vk.cc @@ -37,6 +37,7 @@ static vk::UniqueSampler CreateSampler( sampler_info.addressModeW = address_mode_w; sampler_info.borderColor = vk::BorderColor::eFloatTransparentBlack; sampler_info.mipmapMode = mip_map; + sampler_info.maxLod = VK_LOD_CLAMP_NONE; if (yuv_conversion && yuv_conversion->IsValid()) { sampler_chain.get().conversion = diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index 6f301c29df503..d70382ff63afe 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -588,6 +588,9 @@ impeller_Play_AiksTest_MatrixImageFilterMagnify_Vulkan.png impeller_Play_AiksTest_MatrixSaveLayerFilter_Metal.png impeller_Play_AiksTest_MatrixSaveLayerFilter_OpenGLES.png impeller_Play_AiksTest_MatrixSaveLayerFilter_Vulkan.png +impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Metal.png +impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_OpenGLES.png +impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Vulkan.png impeller_Play_AiksTest_PaintBlendModeIsRespected_Metal.png impeller_Play_AiksTest_PaintBlendModeIsRespected_OpenGLES.png impeller_Play_AiksTest_PaintBlendModeIsRespected_Vulkan.png