Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] dont clamp mipmap level to 0 with Vulkan textures. #51761

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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<fml::NonOwnedMapping>(
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<Image>(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

Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/sampler_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defaults to 0 and clamps to the first mip level


if (yuv_conversion && yuv_conversion->IsValid()) {
sampler_chain.get<vk::SamplerYcbcrConversionInfo>().conversion =
Expand Down
3 changes: 3 additions & 0 deletions testing/impeller_golden_tests_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down