diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index df0d4e3655f15..93eccecdfab60 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -192,6 +192,7 @@ ../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk_unittests.cc +../../../flutter/impeller/renderer/backend/vulkan/formats_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_data_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/render_pass_builder_vk_unittests.cc ../../../flutter/impeller/renderer/backend/vulkan/render_pass_cache_unittests.cc diff --git a/impeller/core/shader_types.h b/impeller/core/shader_types.h index f3759552f4877..9396e4b938aea 100644 --- a/impeller/core/shader_types.h +++ b/impeller/core/shader_types.h @@ -153,13 +153,15 @@ struct ShaderStageBufferLayout { } }; +// These enum values were chosen to match the same values +// in the VK Descriptor Type enum. enum class DescriptorType { - kUniformBuffer, - kStorageBuffer, - kSampledImage, - kImage, - kSampler, - kInputAttachment, + kSampler = 0, + kSampledImage = 1, + kImage = 2, + kUniformBuffer = 6, + kStorageBuffer = 7, + kInputAttachment = 10, }; struct DescriptorSetLayout { diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 590a53a6f0ce4..a750494b49565 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -15,6 +15,7 @@ impeller_component("vulkan_unittests") { "descriptor_pool_vk_unittests.cc", "driver_info_vk_unittests.cc", "fence_waiter_vk_unittests.cc", + "formats_vk_unittests.cc", "pipeline_cache_data_vk_unittests.cc", "render_pass_builder_vk_unittests.cc", "render_pass_cache_unittests.cc", diff --git a/impeller/renderer/backend/vulkan/formats_vk.h b/impeller/renderer/backend/vulkan/formats_vk.h index cb9a5fadfed52..2dbb21c5af08e 100644 --- a/impeller/renderer/backend/vulkan/formats_vk.h +++ b/impeller/renderer/backend/vulkan/formats_vk.h @@ -276,28 +276,21 @@ constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage) { FML_UNREACHABLE(); } -constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) { - switch (type) { - case DescriptorType::kSampledImage: - return vk::DescriptorType::eCombinedImageSampler; - break; - case DescriptorType::kUniformBuffer: - return vk::DescriptorType::eUniformBuffer; - break; - case DescriptorType::kStorageBuffer: - return vk::DescriptorType::eStorageBuffer; - break; - case DescriptorType::kImage: - return vk::DescriptorType::eSampledImage; - break; - case DescriptorType::kSampler: - return vk::DescriptorType::eSampler; - break; - case DescriptorType::kInputAttachment: - return vk::DescriptorType::eInputAttachment; - } +static_assert(static_cast(DescriptorType::kSampledImage) == + static_cast(vk::DescriptorType::eCombinedImageSampler)); +static_assert(static_cast(DescriptorType::kUniformBuffer) == + static_cast(vk::DescriptorType::eUniformBuffer)); +static_assert(static_cast(DescriptorType::kStorageBuffer) == + static_cast(vk::DescriptorType::eStorageBuffer)); +static_assert(static_cast(DescriptorType::kImage) == + static_cast(vk::DescriptorType::eSampledImage)); +static_assert(static_cast(DescriptorType::kSampler) == + static_cast(vk::DescriptorType::eSampler)); +static_assert(static_cast(DescriptorType::kInputAttachment) == + static_cast(vk::DescriptorType::eInputAttachment)); - FML_UNREACHABLE(); +constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) { + return static_cast(type); } constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding( diff --git a/impeller/renderer/backend/vulkan/formats_vk_unittests.cc b/impeller/renderer/backend/vulkan/formats_vk_unittests.cc new file mode 100644 index 0000000000000..4c0ecbfdd393a --- /dev/null +++ b/impeller/renderer/backend/vulkan/formats_vk_unittests.cc @@ -0,0 +1,27 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gtest/gtest.h" // IWYU pragma: keep +#include "impeller/renderer/backend/vulkan/formats_vk.h" + +namespace impeller { +namespace testing { + +TEST(FormatsVKTest, DescriptorMapping) { + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampledImage), + vk::DescriptorType::eCombinedImageSampler); + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kUniformBuffer), + vk::DescriptorType::eUniformBuffer); + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kStorageBuffer), + vk::DescriptorType::eStorageBuffer); + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kImage), + vk::DescriptorType::eSampledImage); + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kSampler), + vk::DescriptorType::eSampler); + EXPECT_EQ(ToVKDescriptorType(DescriptorType::kInputAttachment), + vk::DescriptorType::eInputAttachment); +} + +} // namespace testing +} // namespace impeller