From 35c2cd837e1634244b7caed93c516ab023a2b6d1 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 28 Mar 2024 13:34:47 -0700 Subject: [PATCH 1/5] [Impeller] Set MaxLod clamp to none so mipmaps work. --- impeller/entity/entity_unittests.cc | 63 +++++++++++++++++++ .../renderer/backend/vulkan/sampler_vk.cc | 1 + 2 files changed, 64 insertions(+) diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index ba3fccbc38e31..559fb98d68aa6 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2858,6 +2858,69 @@ TEST_P(EntityTest, CanRenderEmptyPathsWithoutCrashing) { ASSERT_TRUE(OpenPlaygroundHere(std::move(entity))); } +TEST_P(EntityTest, BlitPassMipmapGenerationWorksCorrectly) { + 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()); + + SamplerDescriptor descriptor; + descriptor.label = "Test Sampler"; + descriptor.mag_filter = MinMagFilter::kLinear; + descriptor.min_filter = MinMagFilter::kLinear; + + auto contents = std::make_shared(); + contents->SetTexture(texture); + contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); + contents->SetDestinationRect(Rect::MakeLTRB(0, 0, 100, 100)); + contents->SetStrictSourceRect(false); + contents->SetSamplerDescriptor(descriptor); + contents->SetOpacity(1.0); + contents->SetDeferApplyingOpacity(false); + + Entity entity; + entity.SetClipDepth(0); + entity.SetContents(contents); + + ASSERT_TRUE(OpenPlaygroundHere(std::move(entity))); +} + } // 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 = From 1f0726173b83f8354fe55aac144f5ba21163d1c4 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 28 Mar 2024 13:35:04 -0700 Subject: [PATCH 2/5] disable for testing. --- impeller/renderer/backend/vulkan/sampler_vk.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/renderer/backend/vulkan/sampler_vk.cc b/impeller/renderer/backend/vulkan/sampler_vk.cc index 2e0946302d5cf..c6746bb0b6dbf 100644 --- a/impeller/renderer/backend/vulkan/sampler_vk.cc +++ b/impeller/renderer/backend/vulkan/sampler_vk.cc @@ -37,7 +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; + // sampler_info.maxLod = VK_LOD_CLAMP_NONE; if (yuv_conversion && yuv_conversion->IsValid()) { sampler_chain.get().conversion = From 87ba7a31b561392cf2df4cc9c3f4993a92b8f81d Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 28 Mar 2024 14:22:50 -0700 Subject: [PATCH 3/5] move for golden. --- impeller/aiks/aiks_unittests.cc | 51 +++++++++++++++++++++++ impeller/entity/entity_unittests.cc | 63 ----------------------------- 2 files changed, 51 insertions(+), 63 deletions(-) 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/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 559fb98d68aa6..ba3fccbc38e31 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2858,69 +2858,6 @@ TEST_P(EntityTest, CanRenderEmptyPathsWithoutCrashing) { ASSERT_TRUE(OpenPlaygroundHere(std::move(entity))); } -TEST_P(EntityTest, BlitPassMipmapGenerationWorksCorrectly) { - 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()); - - SamplerDescriptor descriptor; - descriptor.label = "Test Sampler"; - descriptor.mag_filter = MinMagFilter::kLinear; - descriptor.min_filter = MinMagFilter::kLinear; - - auto contents = std::make_shared(); - contents->SetTexture(texture); - contents->SetSourceRect(Rect::MakeSize(texture->GetSize())); - contents->SetDestinationRect(Rect::MakeLTRB(0, 0, 100, 100)); - contents->SetStrictSourceRect(false); - contents->SetSamplerDescriptor(descriptor); - contents->SetOpacity(1.0); - contents->SetDeferApplyingOpacity(false); - - Entity entity; - entity.SetClipDepth(0); - entity.SetContents(contents); - - ASSERT_TRUE(OpenPlaygroundHere(std::move(entity))); -} - } // namespace testing } // namespace impeller From 9a808f3394f76f2cc0c6f851abb628c9059b9f19 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 28 Mar 2024 14:49:54 -0700 Subject: [PATCH 4/5] add to output. --- testing/impeller_golden_tests_output.txt | 3 +++ 1 file changed, 3 insertions(+) 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 From c4d9704a97e643596c644df4bbf48058cc74af7f Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 28 Mar 2024 15:40:04 -0700 Subject: [PATCH 5/5] Update sampler_vk.cc --- impeller/renderer/backend/vulkan/sampler_vk.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/renderer/backend/vulkan/sampler_vk.cc b/impeller/renderer/backend/vulkan/sampler_vk.cc index c6746bb0b6dbf..2e0946302d5cf 100644 --- a/impeller/renderer/backend/vulkan/sampler_vk.cc +++ b/impeller/renderer/backend/vulkan/sampler_vk.cc @@ -37,7 +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; + sampler_info.maxLod = VK_LOD_CLAMP_NONE; if (yuv_conversion && yuv_conversion->IsValid()) { sampler_chain.get().conversion =