Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3d89dfa

Browse files
[Impeller] cleanup and test vk image usage flags. (#51301)
Cleanups to the vk::ImageUsageFlagBits * add unit tests * remove input attachment from depth stencil * remove defensive checks
1 parent c889344 commit 3d89dfa

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

impeller/renderer/backend/vulkan/allocator_vk.cc

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ int32_t AllocatorVK::FindMemoryTypeIndex(
196196
return type_index;
197197
}
198198

199-
static constexpr vk::ImageUsageFlags ToVKImageUsageFlags(
199+
vk::ImageUsageFlags AllocatorVK::ToVKImageUsageFlags(
200200
PixelFormat format,
201201
TextureUsageMask usage,
202202
StorageMode mode,
@@ -219,30 +219,16 @@ static constexpr vk::ImageUsageFlags ToVKImageUsageFlags(
219219
vk_usage |= vk::ImageUsageFlagBits::eDepthStencilAttachment;
220220
} else {
221221
vk_usage |= vk::ImageUsageFlagBits::eColorAttachment;
222+
vk_usage |= vk::ImageUsageFlagBits::eInputAttachment;
222223
}
223-
vk_usage |= vk::ImageUsageFlagBits::eInputAttachment;
224224
}
225225

226226
if (usage & TextureUsage::kShaderRead) {
227227
vk_usage |= vk::ImageUsageFlagBits::eSampled;
228-
// Device transient images can only be used as attachments. The caller
229-
// specified incorrect usage flags and is attempting to read a device
230-
// transient image in a shader. Unset the transient attachment flag. See:
231-
// https://github.com/flutter/flutter/issues/121633
232-
if (mode == StorageMode::kDeviceTransient) {
233-
vk_usage &= ~vk::ImageUsageFlagBits::eTransientAttachment;
234-
}
235228
}
236229

237230
if (usage & TextureUsage::kShaderWrite) {
238231
vk_usage |= vk::ImageUsageFlagBits::eStorage;
239-
// Device transient images can only be used as attachments. The caller
240-
// specified incorrect usage flags and is attempting to read a device
241-
// transient image in a shader. Unset the transient attachment flag. See:
242-
// https://github.com/flutter/flutter/issues/121633
243-
if (mode == StorageMode::kDeviceTransient) {
244-
vk_usage &= ~vk::ImageUsageFlagBits::eTransientAttachment;
245-
}
246232
}
247233

248234
if (mode != StorageMode::kDeviceTransient) {
@@ -314,9 +300,9 @@ class AllocatedTextureSourceVK final : public TextureSourceVK {
314300
image_info.arrayLayers = ToArrayLayerCount(desc.type);
315301
image_info.tiling = vk::ImageTiling::eOptimal;
316302
image_info.initialLayout = vk::ImageLayout::eUndefined;
317-
image_info.usage =
318-
ToVKImageUsageFlags(desc.format, desc.usage, desc.storage_mode,
319-
supports_memoryless_textures);
303+
image_info.usage = AllocatorVK::ToVKImageUsageFlags(
304+
desc.format, desc.usage, desc.storage_mode,
305+
supports_memoryless_textures);
320306
image_info.sharingMode = vk::SharingMode::eExclusive;
321307

322308
VmaAllocationCreateInfo alloc_nfo = {};

impeller/renderer/backend/vulkan/allocator_vk.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class AllocatorVK final : public Allocator {
3232
uint32_t memory_type_bits_requirement,
3333
vk::PhysicalDeviceMemoryProperties& memory_properties);
3434

35+
// Visible for testing.
36+
static vk::ImageUsageFlags ToVKImageUsageFlags(
37+
PixelFormat format,
38+
TextureUsageMask usage,
39+
StorageMode mode,
40+
bool supports_memoryless_textures);
41+
3542
private:
3643
friend class ContextVK;
3744

impeller/renderer/backend/vulkan/allocator_vk_unittests.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
namespace impeller {
1414
namespace testing {
1515

16+
TEST(AllocatorVKTest, ToVKImageUsageFlags) {
17+
EXPECT_EQ(AllocatorVK::ToVKImageUsageFlags(
18+
PixelFormat::kR8G8B8A8UNormInt,
19+
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget),
20+
StorageMode::kDeviceTransient,
21+
/*supports_memoryless_textures=*/true),
22+
vk::ImageUsageFlagBits::eInputAttachment |
23+
vk::ImageUsageFlagBits::eColorAttachment |
24+
vk::ImageUsageFlagBits::eTransientAttachment);
25+
26+
EXPECT_EQ(AllocatorVK::ToVKImageUsageFlags(
27+
PixelFormat::kD24UnormS8Uint,
28+
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget),
29+
StorageMode::kDeviceTransient,
30+
/*supports_memoryless_textures=*/true),
31+
vk::ImageUsageFlagBits::eDepthStencilAttachment |
32+
vk::ImageUsageFlagBits::eTransientAttachment);
33+
}
34+
1635
TEST(AllocatorVKTest, MemoryTypeSelectionSingleHeap) {
1736
vk::PhysicalDeviceMemoryProperties properties;
1837
properties.memoryTypeCount = 1;

0 commit comments

Comments
 (0)