mirror of
https://github.com/KhronosGroup/Vulkan-Hpp
synced 2024-11-22 12:20:05 +00:00
Merge pull request #57 from asuessenbach/member_functions
Moved vulkan functions into the wrapper class of its first handle arg…
This commit is contained in:
commit
72cdec99c0
12
README.md
12
README.md
@ -39,10 +39,12 @@ to avoid incorrect or missing initializations and introduces type-safety with s
|
||||
errors into compile errors. Following is a list of features and conventions introduced by our Vulkan C++ layer:
|
||||
|
||||
* works along the official C version of the API
|
||||
* defines all symbols within the 'vk' namespace and to avoid redundancy the vk/Vk/VK_ prefixes have been removed from all symbols, i.e. <code>vk::commandBindPipeline</code> for vkCommandBindPipeline.
|
||||
* defines all symbols within the 'vk' namespace and to avoid redundancy the vk/Vk/VK_ prefixes have been removed from all symbols, i.e. <code>vk::ImageCreateInfo</code> for VkImageCreateInfo.
|
||||
* camel case syntax with an 'e' prefix has been introduced for all enums, i.e. <code>vk::ImageType::e2D</code> (the prefix was a compromise, more about that later) removes the 'BIT' suffix from all flag related enums, i.e. <code>vk::ImageUsage::eColorAttachment</code>.
|
||||
* introduces constructors for all structs, which by default set the appropriate <code>sType</code> and all other values to zero.
|
||||
* encapsulates member variables of the structs with getter and setter functions, i.e. <code>ci.imageType()</code> to get a value and <code>ci.imageType(vk::ImageType::e2D)</code> to set a value.
|
||||
* introduces wrapper classes around the vulkan handles, i.e. <code>vk::CommandBuffer</code> for VkCommandBuffer
|
||||
* introduces member functions of those wrapper classes, that map to vulkan functions getting the corresponding vulkan handle as its first argument. The type of that handle is stripped from the function name, i.e. <code>vk::Device::getProcAddr> for vkGetDeviceProcAddr. Note the special handling for the class CommandBuffer, where most of the vulkan functions would just include "Cmd", instead of "CommandBuffer", i.e. <code>vk::CommandBuffer::bindPipeline</code> for vkCmdBindPipeline.
|
||||
|
||||
With those changes applied, the updated code snippet looks like this:
|
||||
|
||||
@ -62,7 +64,7 @@ ci.sharingMode(vk::SharingMode::eExclusive);
|
||||
// ci.queueFamilyIndexCount(0) // no need to set, already initialized
|
||||
// ci.pQueueFamilyIndices(0) // no need to set, already initialized
|
||||
ci.initialLayout(vk::ImageLayout::eUndefined);
|
||||
vk::createImage(device, &ci, allocator, &image));
|
||||
device.createImage(&ci, allocator, &image);
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
@ -137,7 +139,7 @@ vk::ImageCreateInfo ci = vk::ImageCreateInfo()
|
||||
// .queueFamilyIndexCount(0) // no need to set, already initialized
|
||||
// .pQueueFamilyIndices(0) // no need to set, already initialized
|
||||
.initialLayout(vk::ImageLayout::eUndefined);
|
||||
vk::createImage(device, &ci, allocator, &image));
|
||||
device.createImage(&ci, allocator, &image);
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
@ -165,7 +167,7 @@ Here are a few code examples:
|
||||
// Get VkInstance from vk::Instance
|
||||
nativeInstance = i;
|
||||
|
||||
// Get an std::vector as result of an enumeration call.
|
||||
// Get a std::vector as result of an enumeration call.
|
||||
std::vector<vk::PhysicalDevice> physicalDevices = i.enumeratePhysicalDevices();
|
||||
vk::FormatProperties formatProperties = physicalDevices[0].getFormatProperties(vk::Format::eR8G8B8A8Unorm);
|
||||
|
||||
@ -194,7 +196,7 @@ To build the header for a given vk.xml specification continue with the following
|
||||
|
||||
* Build VkCppGenerator
|
||||
* Grab your favourite version vk.xml from Khronos
|
||||
* Version 1.0 of the API has a tiny bug. The <require> section of the VK_KHR_display extension is missing one symbol which
|
||||
* Up to Version 1.0.3 of the API there is a tiny bug in vk.xml. The <require> section of the VK_KHR_display extension is missing one symbol which
|
||||
can easily be fixed by adding the following line
|
||||
<pre>
|
||||
<type name="VkDisplayPlaneAlphaFlagsKHR"/>
|
||||
|
@ -345,12 +345,12 @@ void writeStructConstructor( std::ofstream & ofs, std::string const& name, std::
|
||||
void writeStructGetter( std::ofstream & ofs, MemberData const& memberData, std::string const& memberName, std::set<std::string> const& vkTypes, bool constVersion );
|
||||
void writeStructSetter( std::ofstream & ofs, std::string const& name, MemberData const& memberData, std::string const& memberName, std::set<std::string> const& vkTypes, std::map<std::string,StructData> const& structs );
|
||||
void writeTypeCommand( std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes );
|
||||
void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentation, std::string const& className, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes);
|
||||
void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes);
|
||||
void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, size_t templateIndex, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes, std::map<size_t, size_t> const& vectorParameters);
|
||||
void writeTypeCommandEnhancedSingleStep(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, std::string const& returnType, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes, size_t returnIndex, size_t templateIndex, std::map<size_t, size_t> const& vectorParameters);
|
||||
void writeTypeCommandEnhancedTwoStep(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, std::string const& returnType, size_t templateIndex, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes, std::map<size_t, size_t> const& vectorParameters);
|
||||
void writeTypeCommandEnhancedReplaceReturn(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, std::string const& returnType, size_t templateIndex, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes, size_t returnIndex, std::map<size_t, size_t> const& vectorParameters);
|
||||
void writeTypeCommandStandard(std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes);
|
||||
void writeTypeCommandStandard(std::ofstream & ofs, std::string const& indentation, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes);
|
||||
void writeTypeCommandComplexBody(std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::map<std::string,std::string> const& nameMap, std::map<size_t, size_t> const& vectorParameters, std::set<size_t> const& argIndices, size_t complexIndex, size_t returnIndex);
|
||||
void writeTypeCommandSimpleBody(std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::map<std::string, std::string> const& nameMap, std::map<size_t, size_t> const& vectorParameters, std::set<size_t> const& argIndices, std::map<size_t, std::vector<size_t>> const& sizeIndices, size_t returnIndex);
|
||||
void writeTypeEnum(std::ofstream & ofs, DependencyData const& dependencyData, EnumData const& enumData);
|
||||
@ -1947,19 +1947,19 @@ void writeStructSetter( std::ofstream & ofs, std::string const& name, MemberData
|
||||
|
||||
void writeTypeCommand( std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes )
|
||||
{
|
||||
enterProtect(ofs, commandData.protect);
|
||||
writeTypeCommandStandard(ofs, dependencyData, commandData, vkTypes);
|
||||
leaveProtect(ofs, commandData.protect);
|
||||
if (!commandData.handleCommand)
|
||||
{
|
||||
ofs << "#ifdef VKCPP_ENHANCED_MODE" << std::endl;
|
||||
writeTypeCommandEnhanced(ofs, " ", "", dependencyData, commandData, vkTypes);
|
||||
ofs << "#endif /*VKCPP_ENHANCED_MODE*/" << std::endl;
|
||||
writeTypeCommandStandard(ofs, " ", dependencyData.name, dependencyData, commandData, vkTypes);
|
||||
|
||||
ofs << std::endl
|
||||
<< "#ifdef VKCPP_ENHANCED_MODE" << std::endl;
|
||||
writeTypeCommandEnhanced(ofs, " ", "", dependencyData.name, dependencyData, commandData, vkTypes);
|
||||
ofs << "#endif /*VKCPP_ENHANCED_MODE*/" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
ofs << std::endl;
|
||||
}
|
||||
|
||||
void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentation, std::string const& className, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes)
|
||||
void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentation, std::string const& className, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes)
|
||||
{
|
||||
enterProtect(ofs, commandData.protect);
|
||||
std::map<size_t, size_t> vectorParameters = getVectorParameters(commandData);
|
||||
@ -1967,7 +1967,6 @@ void writeTypeCommandEnhanced(std::ofstream & ofs, std::string const& indentatio
|
||||
size_t templateIndex = findTemplateIndex(commandData, vectorParameters);
|
||||
std::map<size_t, size_t>::const_iterator returnVector = vectorParameters.find(returnIndex);
|
||||
std::string returnType = determineReturnType(commandData, returnIndex, returnVector != vectorParameters.end());
|
||||
std::string functionName = determineFunctionName(dependencyData.name, commandData);
|
||||
|
||||
writeFunctionHeader(ofs, indentation, returnType, functionName, commandData, returnIndex, templateIndex, vectorParameters);
|
||||
|
||||
@ -2183,12 +2182,19 @@ void writeTypeCommandEnhancedReplaceReturn(std::ofstream & ofs, std::string cons
|
||||
<< indentation << "}" << std::endl;
|
||||
}
|
||||
|
||||
void writeTypeCommandStandard(std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes)
|
||||
void writeTypeCommandStandard(std::ofstream & ofs, std::string const& indentation, std::string const& functionName, DependencyData const& dependencyData, CommandData const& commandData, std::set<std::string> const& vkTypes)
|
||||
{
|
||||
ofs << " inline " << commandData.returnType << " " << dependencyData.name << "( ";
|
||||
for (size_t i = 0; i<commandData.arguments.size(); i++)
|
||||
enterProtect(ofs, commandData.protect);
|
||||
ofs << indentation;
|
||||
if (!commandData.handleCommand)
|
||||
{
|
||||
if (0 < i)
|
||||
ofs << "inline ";
|
||||
}
|
||||
ofs << commandData.returnType << " " << functionName << "( ";
|
||||
bool argEncountered = false;
|
||||
for (size_t i = commandData.handleCommand ? 1 : 0; i < commandData.arguments.size(); i++)
|
||||
{
|
||||
if (argEncountered)
|
||||
{
|
||||
ofs << ", ";
|
||||
}
|
||||
@ -2197,10 +2203,11 @@ void writeTypeCommandStandard(std::ofstream & ofs, DependencyData const& depende
|
||||
{
|
||||
ofs << "[" << commandData.arguments[i].arraySize << "]";
|
||||
}
|
||||
argEncountered = true;
|
||||
}
|
||||
ofs << " )" << std::endl
|
||||
<< " {" << std::endl
|
||||
<< " ";
|
||||
<< indentation << "{" << std::endl
|
||||
<< indentation << " ";
|
||||
bool castReturn = false;
|
||||
if (commandData.returnType != "void")
|
||||
{
|
||||
@ -2217,7 +2224,12 @@ void writeTypeCommandStandard(std::ofstream & ofs, DependencyData const& depende
|
||||
callName[0] = toupper(callName[0]);
|
||||
|
||||
ofs << "vk" << callName << "( ";
|
||||
for (size_t i = 0; i<commandData.arguments.size(); i++)
|
||||
if (commandData.handleCommand)
|
||||
{
|
||||
ofs << "m_" << commandData.arguments[0].name;
|
||||
}
|
||||
argEncountered = false;
|
||||
for (size_t i = commandData.handleCommand ? 1 : 0; i < commandData.arguments.size(); i++)
|
||||
{
|
||||
if (0 < i)
|
||||
{
|
||||
@ -2231,7 +2243,8 @@ void writeTypeCommandStandard(std::ofstream & ofs, DependencyData const& depende
|
||||
ofs << " )";
|
||||
}
|
||||
ofs << ";" << std::endl
|
||||
<< " }" << std::endl;
|
||||
<< indentation << "}" << std::endl;
|
||||
leaveProtect(ofs, commandData.protect);
|
||||
}
|
||||
|
||||
void writeTypeCommandComplexBody(std::ofstream & ofs, DependencyData const& dependencyData, CommandData const& commandData, std::map<std::string,std::string> const& nameMap, std::map<size_t, size_t> const& vectorParameters, std::set<size_t> const& argIndices, size_t complexIndex, size_t returnIndex)
|
||||
@ -2517,9 +2530,9 @@ void writeTypeHandle(std::ofstream & ofs, DependencyData const& dependencyData,
|
||||
<< " }" << std::endl
|
||||
<< "#endif\n"
|
||||
<< std::endl;
|
||||
|
||||
if (!handle.commands.empty())
|
||||
{
|
||||
ofs << "#ifdef VKCPP_ENHANCED_MODE" << std::endl;
|
||||
for (size_t i = 0; i < handle.commands.size(); i++)
|
||||
{
|
||||
std::string commandName = handle.commands[i];
|
||||
@ -2527,14 +2540,22 @@ void writeTypeHandle(std::ofstream & ofs, DependencyData const& dependencyData,
|
||||
assert((cit != commands.end()) && cit->second.handleCommand);
|
||||
std::vector<DependencyData>::const_iterator dep = std::find_if(dependencies.begin(), dependencies.end(), [commandName](DependencyData const& dd) { return dd.name == commandName; });
|
||||
assert(dep != dependencies.end());
|
||||
writeTypeCommandEnhanced(ofs, " ", dependencyData.name, *dep, cit->second, vkTypes);
|
||||
std::string className = dependencyData.name;
|
||||
std::string functionName = determineFunctionName(dep->name, cit->second);
|
||||
|
||||
writeTypeCommandStandard(ofs, " ", functionName, *dep, cit->second, vkTypes);
|
||||
|
||||
ofs << std::endl
|
||||
<< "#ifdef VKCPP_ENHANCED_MODE" << std::endl;
|
||||
writeTypeCommandEnhanced(ofs, " ", className, functionName, *dep, cit->second, vkTypes);
|
||||
ofs << "#endif /*VKCPP_ENHANCED_MODE*/" << std::endl;
|
||||
|
||||
if (i < handle.commands.size() - 1)
|
||||
{
|
||||
ofs << std::endl;
|
||||
}
|
||||
}
|
||||
ofs << "#endif /*VKCPP_ENHANCED_MODE*/" << std::endl
|
||||
<< std::endl;
|
||||
ofs << std::endl;
|
||||
}
|
||||
ofs << "#if !defined(VK_CPP_TYPESAFE_CONVERSION)" << std::endl
|
||||
<< " explicit" << std::endl
|
||||
|
2081
vulkan/vk_cpp.h
2081
vulkan/vk_cpp.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user