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

Commit aa3423f

Browse files
author
Jonah Williams
authored
[Impeller] faster descriptor type mapping. (#56351)
This is a dumb performance optimization. because we only use the DescriptorType enum to represent vk descriptor types, lets just make the enum values match. Then we can static cast instead of switch. I do see this function showing up in profiles, though a very small slice.
1 parent 2bea694 commit aa3423f

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

ci/licenses_golden/excluded_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc
193193
../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk_unittests.cc
194194
../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk_unittests.cc
195+
../../../flutter/impeller/renderer/backend/vulkan/formats_vk_unittests.cc
195196
../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_data_vk_unittests.cc
196197
../../../flutter/impeller/renderer/backend/vulkan/render_pass_builder_vk_unittests.cc
197198
../../../flutter/impeller/renderer/backend/vulkan/render_pass_cache_unittests.cc

impeller/core/shader_types.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,15 @@ struct ShaderStageBufferLayout {
153153
}
154154
};
155155

156+
// These enum values were chosen to match the same values
157+
// in the VK Descriptor Type enum.
156158
enum class DescriptorType {
157-
kUniformBuffer,
158-
kStorageBuffer,
159-
kSampledImage,
160-
kImage,
161-
kSampler,
162-
kInputAttachment,
159+
kSampler = 0,
160+
kSampledImage = 1,
161+
kImage = 2,
162+
kUniformBuffer = 6,
163+
kStorageBuffer = 7,
164+
kInputAttachment = 10,
163165
};
164166

165167
struct DescriptorSetLayout {

impeller/renderer/backend/vulkan/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impeller_component("vulkan_unittests") {
1515
"descriptor_pool_vk_unittests.cc",
1616
"driver_info_vk_unittests.cc",
1717
"fence_waiter_vk_unittests.cc",
18+
"formats_vk_unittests.cc",
1819
"pipeline_cache_data_vk_unittests.cc",
1920
"render_pass_builder_vk_unittests.cc",
2021
"render_pass_cache_unittests.cc",

impeller/renderer/backend/vulkan/formats_vk.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -276,28 +276,21 @@ constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage) {
276276
FML_UNREACHABLE();
277277
}
278278

279-
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) {
280-
switch (type) {
281-
case DescriptorType::kSampledImage:
282-
return vk::DescriptorType::eCombinedImageSampler;
283-
break;
284-
case DescriptorType::kUniformBuffer:
285-
return vk::DescriptorType::eUniformBuffer;
286-
break;
287-
case DescriptorType::kStorageBuffer:
288-
return vk::DescriptorType::eStorageBuffer;
289-
break;
290-
case DescriptorType::kImage:
291-
return vk::DescriptorType::eSampledImage;
292-
break;
293-
case DescriptorType::kSampler:
294-
return vk::DescriptorType::eSampler;
295-
break;
296-
case DescriptorType::kInputAttachment:
297-
return vk::DescriptorType::eInputAttachment;
298-
}
279+
static_assert(static_cast<int>(DescriptorType::kSampledImage) ==
280+
static_cast<int>(vk::DescriptorType::eCombinedImageSampler));
281+
static_assert(static_cast<int>(DescriptorType::kUniformBuffer) ==
282+
static_cast<int>(vk::DescriptorType::eUniformBuffer));
283+
static_assert(static_cast<int>(DescriptorType::kStorageBuffer) ==
284+
static_cast<int>(vk::DescriptorType::eStorageBuffer));
285+
static_assert(static_cast<int>(DescriptorType::kImage) ==
286+
static_cast<int>(vk::DescriptorType::eSampledImage));
287+
static_assert(static_cast<int>(DescriptorType::kSampler) ==
288+
static_cast<int>(vk::DescriptorType::eSampler));
289+
static_assert(static_cast<int>(DescriptorType::kInputAttachment) ==
290+
static_cast<int>(vk::DescriptorType::eInputAttachment));
299291

300-
FML_UNREACHABLE();
292+
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) {
293+
return static_cast<vk::DescriptorType>(type);
301294
}
302295

303296
constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "gtest/gtest.h" // IWYU pragma: keep
6+
#include "impeller/renderer/backend/vulkan/formats_vk.h"
7+
8+
namespace impeller {
9+
namespace testing {
10+
11+
TEST(FormatsVKTest, DescriptorMapping) {
12+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampledImage),
13+
vk::DescriptorType::eCombinedImageSampler);
14+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kUniformBuffer),
15+
vk::DescriptorType::eUniformBuffer);
16+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kStorageBuffer),
17+
vk::DescriptorType::eStorageBuffer);
18+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kImage),
19+
vk::DescriptorType::eSampledImage);
20+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampler),
21+
vk::DescriptorType::eSampler);
22+
EXPECT_EQ(ToVKDescriptorType(DescriptorType::kInputAttachment),
23+
vk::DescriptorType::eInputAttachment);
24+
}
25+
26+
} // namespace testing
27+
} // namespace impeller

0 commit comments

Comments
 (0)