From bb7e843b116eacfe40983dd686e9c4e2bfec751f Mon Sep 17 00:00:00 2001 From: Sergey Kosarevsky Date: Sat, 17 Aug 2024 13:19:24 -0700 Subject: [PATCH] Replaced run-time checks with a `static_assert` --- lvk/vulkan/VulkanClasses.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lvk/vulkan/VulkanClasses.cpp b/lvk/vulkan/VulkanClasses.cpp index b88aca7817..70be3ee800 100644 --- a/lvk/vulkan/VulkanClasses.cpp +++ b/lvk/vulkan/VulkanClasses.cpp @@ -3504,9 +3504,10 @@ lvk::Holder lvk::VulkanContext::createTexture(const TextureD return {this, handle}; } -VkSampler lvk::VulkanContext::getOrCreateYcbcrSampler(lvk::Format format) { - LVK_ASSERT(format < LVK_ARRAY_NUM_ELEMENTS(pimpl_->ycbcrConversionData_)); +static_assert(1 << (sizeof(lvk::Format) * 8) <= LVK_ARRAY_NUM_ELEMENTS(lvk::VulkanContextImpl::ycbcrConversionData_), + "There aren't enough elements in `ycbcrConversionData_` to be accessed by lvk::Format"); +VkSampler lvk::VulkanContext::getOrCreateYcbcrSampler(lvk::Format format) { const VkSamplerYcbcrConversionInfo* info = getOrCreateYcbcrConversionInfo(format); if (!info) { @@ -3517,8 +3518,6 @@ VkSampler lvk::VulkanContext::getOrCreateYcbcrSampler(lvk::Format format) { } const VkSamplerYcbcrConversionInfo* lvk::VulkanContext::getOrCreateYcbcrConversionInfo(lvk::Format format) { - LVK_ASSERT(format < LVK_ARRAY_NUM_ELEMENTS(pimpl_->ycbcrConversionData_)); - if (pimpl_->ycbcrConversionData_[format].info.sType) { return &pimpl_->ycbcrConversionData_[format].info; }