mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Introduce default initializers for member variables, simplify default values for constructor arguments (#455)
This commit is contained in:
parent
3f82338d9f
commit
0b01a8a74c
@ -2666,12 +2666,13 @@ bool VulkanHppGenerator::appendStructConstructorArgument(std::string & str, bool
|
|||||||
str += (listedArgument ? (",\n" + indentation) : "");
|
str += (listedArgument ? (",\n" + indentation) : "");
|
||||||
if (memberData.arraySize.empty())
|
if (memberData.arraySize.empty())
|
||||||
{
|
{
|
||||||
str += memberData.type.compose() + " " + memberData.name + "_ = " + ((!memberData.type.postfix.empty() && memberData.type.postfix.back() == '*') ? "nullptr" : defaultValue(memberData.type.type));
|
str += memberData.type.compose() + " ";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str += "std::array<" + memberData.type.compose() + "," + memberData.arraySize + "> const& " + memberData.name + "_ = { { " + defaultValue(memberData.type.type) + " } }";
|
str += "std::array<" + memberData.type.compose() + "," + memberData.arraySize + "> const& ";
|
||||||
}
|
}
|
||||||
|
str += memberData.name + "_ = {}";
|
||||||
listedArgument = true;
|
listedArgument = true;
|
||||||
}
|
}
|
||||||
return listedArgument;
|
return listedArgument;
|
||||||
@ -2716,15 +2717,21 @@ void VulkanHppGenerator::appendStructMembers(std::string & str, std::pair<std::s
|
|||||||
assert(nameIt != enumIt->second.values.end());
|
assert(nameIt != enumIt->second.values.end());
|
||||||
str += " = StructureType::" + nameIt->vkValue;
|
str += " = StructureType::" + nameIt->vkValue;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else if (member.name == "pNext") // special handling for pNext
|
|
||||||
{
|
{
|
||||||
str += " = nullptr";
|
// special handling for those nasty structs with an unspecified value for sType
|
||||||
|
str += " = {}";
|
||||||
}
|
}
|
||||||
else if (!member.arraySize.empty()) // special handling for arrays
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!member.arraySize.empty())
|
||||||
{
|
{
|
||||||
str += "[" + member.arraySize + "]";
|
str += "[" + member.arraySize + "]";
|
||||||
}
|
}
|
||||||
|
// as we don't have any meaningful default initialization values, everything can be initialized by just '{}' !
|
||||||
|
str += " = {}";
|
||||||
|
}
|
||||||
str += ";\n";
|
str += ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2917,8 +2924,7 @@ void VulkanHppGenerator::appendUnion(std::string & str, std::pair<std::string, S
|
|||||||
// just the very first constructor gets default arguments
|
// just the very first constructor gets default arguments
|
||||||
if (firstTime)
|
if (firstTime)
|
||||||
{
|
{
|
||||||
std::string value = defaultValue(member.type.type);
|
str += " = {}";
|
||||||
str += (member.arraySize.empty() ? (" = " + value) : (" = { { " + value + " } }"));
|
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
}
|
}
|
||||||
str += " )\n"
|
str += " )\n"
|
||||||
@ -3059,48 +3065,6 @@ void VulkanHppGenerator::checkCorrectness()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string VulkanHppGenerator::defaultValue(std::string const& type) const
|
|
||||||
{
|
|
||||||
if (beginsWith(type, "PFN_vk") || (type == "LPCWSTR"))
|
|
||||||
{
|
|
||||||
return "nullptr";
|
|
||||||
}
|
|
||||||
else if (beginsWith(type, "Vk"))
|
|
||||||
{
|
|
||||||
auto const baseTypeIt = m_baseTypes.find(type);
|
|
||||||
if (baseTypeIt != m_baseTypes.end())
|
|
||||||
{
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto const& bitmaskBitIt = m_bitmaskBits.find(type);
|
|
||||||
if (bitmaskBitIt != m_bitmaskBits.end())
|
|
||||||
{
|
|
||||||
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + (bitmaskBitIt->second.values.empty() ? "()" : ("::" + bitmaskBitIt->second.values.front().vkValue));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto const& enumIt = m_enums.find(type);
|
|
||||||
if (enumIt != m_enums.end())
|
|
||||||
{
|
|
||||||
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + (enumIt->second.values.empty() ? "()" : ("::" + enumIt->second.values.front().vkValue));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert((m_bitmasks.find(type) != m_bitmasks.end()) || (m_handles.find(type) != m_handles.end()) || (m_structures.find(type) != m_structures.end()));
|
|
||||||
return "VULKAN_HPP_NAMESPACE::" + stripPrefix(type, "Vk") + "()";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(m_defaultZeroTypes.find(type) != m_defaultZeroTypes.end());
|
|
||||||
return "0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string VulkanHppGenerator::determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const
|
std::string VulkanHppGenerator::determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const
|
||||||
{
|
{
|
||||||
assert((returnParamIndex == INVALID_INDEX) || (returnParamIndex < commandData.params.size()));
|
assert((returnParamIndex == INVALID_INDEX) || (returnParamIndex < commandData.params.size()));
|
||||||
@ -4067,8 +4031,6 @@ void VulkanHppGenerator::readRequires(tinyxml2::XMLElement const* element, std::
|
|||||||
|
|
||||||
auto nameIt = attributes.find("name");
|
auto nameIt = attributes.find("name");
|
||||||
assert(nameIt != attributes.end());
|
assert(nameIt != attributes.end());
|
||||||
assert(m_defaultZeroTypes.find(nameIt->second) == m_defaultZeroTypes.end());
|
|
||||||
m_defaultZeroTypes.insert(nameIt->second);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -4278,7 +4240,6 @@ void VulkanHppGenerator::readType(tinyxml2::XMLElement const* element)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert((attributes.size() == 1) && (attributes.begin()->first == "name") && (attributes.begin()->second == "int"));
|
assert((attributes.size() == 1) && (attributes.begin()->first == "name") && (attributes.begin()->second == "int"));
|
||||||
m_defaultZeroTypes.insert("int");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,6 +146,7 @@ class VulkanHppGenerator
|
|||||||
{
|
{
|
||||||
StructureData()
|
StructureData()
|
||||||
: returnedOnly(false)
|
: returnedOnly(false)
|
||||||
|
, isUnion(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool returnedOnly;
|
bool returnedOnly;
|
||||||
@ -205,7 +206,6 @@ class VulkanHppGenerator
|
|||||||
void appendUniqueTypes(std::string &str, std::string const& parentType, std::set<std::string> const& childrenTypes) const;
|
void appendUniqueTypes(std::string &str, std::string const& parentType, std::set<std::string> const& childrenTypes) const;
|
||||||
bool containsArray(std::string const& type) const;
|
bool containsArray(std::string const& type) const;
|
||||||
bool containsUnion(std::string const& type) const;
|
bool containsUnion(std::string const& type) const;
|
||||||
std::string defaultValue(std::string const& type) const;
|
|
||||||
std::string determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const;
|
std::string determineEnhancedReturnType(CommandData const& commandData, size_t returnParamIndex, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep, bool isStructureChain) const;
|
||||||
size_t determineReturnParamIndex(CommandData const& commandData, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep) const;
|
size_t determineReturnParamIndex(CommandData const& commandData, std::map<size_t, size_t> const& vectorParamIndices, bool twoStep) const;
|
||||||
std::string determineSubStruct(std::pair<std::string, StructureData> const& structure) const;
|
std::string determineSubStruct(std::pair<std::string, StructureData> const& structure) const;
|
||||||
@ -262,7 +262,6 @@ class VulkanHppGenerator
|
|||||||
std::string m_version;
|
std::string m_version;
|
||||||
std::string m_vulkanLicenseHeader;
|
std::string m_vulkanLicenseHeader;
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
std::set<std::string> m_defaultZeroTypes;
|
|
||||||
std::set<std::string> m_defines; // just used for verfication in readExtensionType
|
std::set<std::string> m_defines; // just used for verfication in readExtensionType
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -188,19 +188,27 @@ namespace vk
|
|||||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(NDEBUG)
|
||||||
|
std::vector<vk::LayerProperties> layerProperties = vk::enumerateInstanceLayerProperties();
|
||||||
|
std::vector<vk::ExtensionProperties> extensionProperties = vk::enumerateInstanceExtensionProperties();
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<char const*> enabledLayers;
|
std::vector<char const*> enabledLayers;
|
||||||
enabledLayers.reserve(layers.size());
|
enabledLayers.reserve(layers.size());
|
||||||
for (auto const& layer : layers)
|
for (auto const& layer : layers)
|
||||||
{
|
{
|
||||||
|
assert(std::find_if(layerProperties.begin(), layerProperties.end(), [layer](vk::LayerProperties const& lp) { return layer == lp.layerName; }) != layerProperties.end());
|
||||||
enabledLayers.push_back(layer.data());
|
enabledLayers.push_back(layer.data());
|
||||||
}
|
}
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
// Enable standard validation layer to find as much errors as possible!
|
// Enable standard validation layer to find as much errors as possible!
|
||||||
if (std::find(layers.begin(), layers.end(), "VK_LAYER_KHRONOS_validation") == layers.end())
|
if (std::find(layers.begin(), layers.end(), "VK_LAYER_KHRONOS_validation") == layers.end()
|
||||||
|
&& std::find_if(layerProperties.begin(), layerProperties.end(), [](vk::LayerProperties const& lp) { return (strcmp("VK_LAYER_KHRONOS_validation", lp.layerName) == 0); }) != layerProperties.end())
|
||||||
{
|
{
|
||||||
enabledLayers.push_back("VK_LAYER_KHRONOS_validation");
|
enabledLayers.push_back("VK_LAYER_KHRONOS_validation");
|
||||||
}
|
}
|
||||||
if (std::find(layers.begin(), layers.end(), "VK_LAYER_LUNARG_assistant_layer") == layers.end())
|
if (std::find(layers.begin(), layers.end(), "VK_LAYER_LUNARG_assistant_layer") == layers.end()
|
||||||
|
&& std::find_if(layerProperties.begin(), layerProperties.end(), [](vk::LayerProperties const& lp) { return (strcmp("VK_LAYER_LUNARG_assistant_layer", lp.layerName) == 0); }) != layerProperties.end())
|
||||||
{
|
{
|
||||||
enabledLayers.push_back("VK_LAYER_LUNARG_assistant_layer");
|
enabledLayers.push_back("VK_LAYER_LUNARG_assistant_layer");
|
||||||
}
|
}
|
||||||
@ -210,10 +218,12 @@ namespace vk
|
|||||||
enabledExtensions.reserve(extensions.size());
|
enabledExtensions.reserve(extensions.size());
|
||||||
for (auto const& ext : extensions)
|
for (auto const& ext : extensions)
|
||||||
{
|
{
|
||||||
|
assert(std::find_if(extensionProperties.begin(), extensionProperties.end(), [ext](vk::ExtensionProperties const& ep) { return ext == ep.extensionName; }) != extensionProperties.end());
|
||||||
enabledExtensions.push_back(ext.data());
|
enabledExtensions.push_back(ext.data());
|
||||||
}
|
}
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == extensions.end())
|
if (std::find(extensions.begin(), extensions.end(), VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == extensions.end()
|
||||||
|
&& std::find_if(extensionProperties.begin(), extensionProperties.end(), [](vk::ExtensionProperties const& ep) { return (strcmp(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, ep.extensionName) == 0); }) != extensionProperties.end())
|
||||||
{
|
{
|
||||||
enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
enabledExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||||
}
|
}
|
||||||
|
7704
vulkan/vulkan.hpp
7704
vulkan/vulkan.hpp
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user