KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.63k stars 402 forks source link

Adding constexpr modifiers to functions returning C++ string literal #2239

Closed ByunghoonKim closed 1 month ago

ByunghoonKim commented 1 month ago

Hi, I stumbled upon #2229 a bit late. I do not want to disrupt an already closed issue thread, hence opening a new one here.

From cppreference,

A constexpr specifier used in an object declaration or non-static member function(until C++14) implies const. A constexpr specifier used in a function or static data member(since C++17) declaration implies inline.

My understanding is that you should not omit const when you add constexpr to a function. Like, static constexpr const char* mvkGetReportingLevelString(MVKConfigLogLevel logLevel) {

If this approach works, couldn't many functions returning string literal in macOS/include/vulkan/vk_enum_string_helper.h, macOS/source/SPIRV-Reflect/spirv_reflect.h, etc., be turned into constexpr functions as well?

cdavis5e commented 1 month ago

Of course, but many of those aren't our sources, but are from other Khronos projects. I suppose we could look at doing this for our own sources, but for the rest, you'll have to take it up with the owning projects, e.g. KhronosGroup/SPIRV-Reflect.

ByunghoonKim commented 1 month ago

Thank you for the quick reply, and your effort going into this project in general. I realized that simply grepping VulkanSDK directory and reporting results here wasn't a prudent idea. Indeed it seems the large portion of my grep result was from KhronosGroup/Vulkan-Utility-Libraries and KhronosGroup/SPIRV-Reflect. I will reconsider whether this is an exercise worth a while, and open issues there if necessary.