mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #1 from asuessenbach/RenameToVulkanHpp
Renamed from VkCpp to VulkanHpp
This commit is contained in:
commit
8e66e869df
@ -26,21 +26,21 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(VkCppGenerator)
|
||||
project(VulkanHppGenerator)
|
||||
|
||||
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Docs/src/spec/vk.xml vk_spec)
|
||||
string(REPLACE "\\" "\\\\" vk_spec ${vk_spec})
|
||||
add_definitions(-DVK_SPEC="${vk_spec}")
|
||||
|
||||
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/vulkan/vk_cpp.hpp vk_cpp)
|
||||
string(REPLACE "\\" "\\\\" vk_cpp ${vk_cpp})
|
||||
add_definitions(-DVK_CPP="${vk_cpp}")
|
||||
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/vulkan/vulkan.hpp vulkan_hpp)
|
||||
string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
|
||||
add_definitions(-DVULKAN_HPP="${vulkan_hpp}")
|
||||
|
||||
set(HEADERS
|
||||
)
|
||||
|
||||
set(SOURCES
|
||||
VkCppGenerator.cpp
|
||||
VulkanHppGenerator.cpp
|
||||
)
|
||||
|
||||
set(TINYXML2_SOURCES
|
||||
@ -57,13 +57,13 @@ source_group(sources FILES ${SOURCES})
|
||||
source_group(TinyXML2\\headers FILES ${TINYXML2_HEADERS})
|
||||
source_group(TinyXML2\\sources FILES ${TINYXML2_SOURCES})
|
||||
|
||||
add_executable(VkCppGenerator
|
||||
add_executable(VulkanHppGenerator
|
||||
${HEADERS}
|
||||
${SOURCES}
|
||||
${TINYXML2_SOURCES}
|
||||
${TINYXML2_HEADERS}
|
||||
)
|
||||
|
||||
set_property(TARGET VkCppGenerator PROPERTY CXX_STANDARD 11)
|
||||
set_property(TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 11)
|
||||
|
||||
target_include_directories(VkCppGenerator PRIVATE "${CMAKE_SOURCE_DIR}/tinyxml2")
|
||||
target_include_directories(VulkanHppGenerator PRIVATE "${CMAKE_SOURCE_DIR}/tinyxml2")
|
||||
|
20
README.md
20
README.md
@ -135,7 +135,7 @@ device.createImage(&ci, allocator, &image);
|
||||
# Enhancements beyond native Vulkan
|
||||
To provide a more object oriented feeling we're providing classes for each handle which include all Vulkan functions where the first
|
||||
parameter matches the handle. In addition to this we made a few changes to the signatures of the member functions
|
||||
* To disable the enhanced mode put ```#define VKCPP_DISABLE_ENHANCED_MODE``` before including ```vk_cpp.h```
|
||||
* To disable the enhanced mode put ```#define VULKAN_HPP_DISABLE_ENHANCED_MODE``` before including ```vulkan.hpp```
|
||||
* ```(count, T*)``` has been replaced by ```vk::ArrayProxy<T>```, which can be created out of a single T, a (count, T*) pair, a std::array<T,N>, a vector<T>, or an initializer_list<T>.
|
||||
* ```const char *``` has been replaced by ```const std::string &```
|
||||
* ```const T *``` has been replaced by ```const T &``` to allow temporary objects. This is useful to pass small structures like ```vk::ClearColorValue``` or ```vk::Extent*```
|
||||
@ -147,7 +147,7 @@ Here are a few code examples:
|
||||
try {
|
||||
VkInstance nativeInstance = nullptr; // Fetch the instance from a favorite toolkit
|
||||
|
||||
// create a vkcpp handle from a native handle
|
||||
// create a vk::Instance handle from a native handle
|
||||
vk::Instance i(nativeInstance);
|
||||
|
||||
// operator=(VkInstance const &) is also supported
|
||||
@ -177,7 +177,7 @@ Here are a few code examples:
|
||||
```
|
||||
# Exceptions and return types
|
||||
The wrapper functions will throw a ```std::system_error``` if the result of the wrapped function is not a success code.
|
||||
By defining ```VK_CPP_NO_EXCEPTIONS``` before include vk_cpp.hpp, this can be disabled.
|
||||
By defining ```VULKAN_HPP_NO_EXCEPTIONS``` before include vulkan.hpp, this can be disabled.
|
||||
Depending on exceptions being enabled or disabled, the return type of some functions change.
|
||||
|
||||
With exceptions enabled (the default) there are four different cases on the return types:
|
||||
@ -196,27 +196,27 @@ Note: With exceptions disabled, it is the user's responsibility to check for err
|
||||
|
||||
# Usage
|
||||
To start with the C++ version of the Vulkan API download header from GIT, put it in a vulkan subdirectory and add
|
||||
```#include <vulkan/vk_cpp.h>``` to your source code.
|
||||
```#include <vulkan/vulkan.hpp>``` to your source code.
|
||||
|
||||
To build the header for a given vk.xml specification continue with the following steps:
|
||||
|
||||
* Build VkCppGenerator
|
||||
* Build VulkanHppGenerator
|
||||
* Grab your favourite version vk.xml from Khronos
|
||||
* Excute ```VkCppGenerator <vk.xml>``` to generate ```vk_cpp.h``` in the current working directory.
|
||||
* Excute ```VulkanHppGenerator <vk.xml>``` to generate ```vulkan.hpp``` in the current working directory.
|
||||
|
||||
# Build instructions for VkCppGenerator
|
||||
# Build instructions for VulkanHppGenerator
|
||||
|
||||
* Clone the repository: ```git clone https://github.com/nvpro-pipeline/vkcpp.git```
|
||||
* Clone the repository: ```git clone https://github.com/KhronosGroup/vkcpp```
|
||||
* Update submodules: ```git submodule update --init --recursive```
|
||||
* Use CMake to generate a solution or makefile for your favourite build environment
|
||||
* Launch the build
|
||||
|
||||
# Samples
|
||||
Brad Davis started to port Sascha Willems Samples to vkcpp. You can find his work in his [repository](https://github.com/jherico/Vulkan).
|
||||
Brad Davis started to port Sascha Willems Samples to vulkan.hpp. You can find his work in his [repository](https://github.com/jherico/Vulkan).
|
||||
|
||||
# Providing Pull Requests
|
||||
|
||||
NVIDIA is happy to review and consider pull requests for merging into the main tree of vkcpp for bug fixes and features. Before providing a pull request to NVIDIA, please note the following:
|
||||
NVIDIA is happy to review and consider pull requests for merging into the main tree of vulkan.hpp for bug fixes and features. Before providing a pull request to NVIDIA, please note the following:
|
||||
|
||||
* A pull request provided to this repo by a developer constitutes permission from the developer for NVIDIA to merge the provided
|
||||
changes or any NVIDIA modified version of these changes to the repo. NVIDIA may remove or change the code at any time and in any
|
||||
|
@ -300,19 +300,19 @@ std::string const arrayProxyHeader = (
|
||||
);
|
||||
|
||||
std::string const versionCheckHeader = (
|
||||
"#if !defined(VK_CPP_HAS_UNRESTRICTED_UNIONS)\n"
|
||||
"#if !defined(VULKAN_HPP_HAS_UNRESTRICTED_UNIONS)\n"
|
||||
"# if defined(__clang__)\n"
|
||||
"# if __has_feature(cxx_unrestricted_unions)\n"
|
||||
"# define VK_CPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# endif\n"
|
||||
"# elif defined(__GNUC__)\n"
|
||||
"# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)\n"
|
||||
"# if 40600 <= GCC_VERSION\n"
|
||||
"# define VK_CPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# endif\n"
|
||||
"# elif defined(_MSC_VER)\n"
|
||||
"# if 1900 <= _MSC_VER\n"
|
||||
"# define VK_CPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS\n"
|
||||
"# endif\n"
|
||||
"# endif\n"
|
||||
"#endif\n"
|
||||
@ -335,7 +335,7 @@ std::string const resultValueHeader = (
|
||||
" template <typename T>\n"
|
||||
" struct ResultValueType\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" typedef ResultValue<T> type;\n"
|
||||
"#else\n"
|
||||
" typedef T type;\n"
|
||||
@ -345,7 +345,7 @@ std::string const resultValueHeader = (
|
||||
" template <>"
|
||||
" struct ResultValueType<void>\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" typedef Result type;\n"
|
||||
"#else\n"
|
||||
" typedef void type;\n"
|
||||
@ -357,7 +357,7 @@ std::string const resultValueHeader = (
|
||||
std::string const createResultValueHeader = (
|
||||
" inline ResultValueType<void>::type createResultValue( Result result, char const * message )\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" assert( result == Result::eSuccess );\n"
|
||||
" return result;\n"
|
||||
"#else\n"
|
||||
@ -371,7 +371,7 @@ std::string const createResultValueHeader = (
|
||||
" template <typename T>\n"
|
||||
" inline typename ResultValueType<T>::type createResultValue( Result result, T & data, char const * message )\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" assert( result == Result::eSuccess );\n"
|
||||
" return ResultValue<T>( result, data );\n"
|
||||
"#else\n"
|
||||
@ -385,7 +385,7 @@ std::string const createResultValueHeader = (
|
||||
"\n"
|
||||
" inline Result createResultValue( Result result, char const * message, std::initializer_list<Result> successCodes )\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" assert( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );\n"
|
||||
"#else\n"
|
||||
" if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )\n"
|
||||
@ -399,7 +399,7 @@ std::string const createResultValueHeader = (
|
||||
" template <typename T>\n"
|
||||
" inline ResultValue<T> createResultValue( Result result, T & data, char const * message, std::initializer_list<Result> successCodes )\n"
|
||||
" {\n"
|
||||
"#ifdef VK_CPP_NO_EXCEPTIONS\n"
|
||||
"#ifdef VULKAN_HPP_NO_EXCEPTIONS\n"
|
||||
" assert( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );\n"
|
||||
"#else\n"
|
||||
" if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )\n"
|
||||
@ -795,7 +795,7 @@ size_t findTemplateIndex(CommandData const& commandData, std::map<size_t, size_t
|
||||
return ~0;
|
||||
}
|
||||
|
||||
std::string getEnumName(std::string const& name) // get vkcpp enum name from vk enum name
|
||||
std::string getEnumName(std::string const& name) // get vulkan.hpp enum name from vk enum name
|
||||
{
|
||||
return strip(name, "Vk");
|
||||
}
|
||||
@ -1924,14 +1924,14 @@ void writeFunctionBody(std::ofstream & ofs, std::string const& indentation, std:
|
||||
{
|
||||
if ((it1->first != returnIndex) && (it0->second == it1->second))
|
||||
{
|
||||
ofs << "#ifdef VK_CPP_NO_EXCEPTIONS" << std::endl
|
||||
ofs << "#ifdef VULKAN_HPP_NO_EXCEPTIONS" << std::endl
|
||||
<< indentation << " assert( " << reduceName(commandData.arguments[it0->first].name) << ".size() == " << reduceName(commandData.arguments[it1->first].name) << ".size() );" << std::endl
|
||||
<< "#else" << std::endl
|
||||
<< indentation << " if ( " << reduceName(commandData.arguments[it0->first].name) << ".size() != " << reduceName(commandData.arguments[it1->first].name) << ".size() )" << std::endl
|
||||
<< indentation << " {" << std::endl
|
||||
<< indentation << " throw std::logic_error( \"vk::" << className << "::" << functionName << ": " << reduceName(commandData.arguments[it0->first].name) << ".size() != " << reduceName(commandData.arguments[it1->first].name) << ".size()\" );" << std::endl
|
||||
<< indentation << " }" << std::endl
|
||||
<< "#endif // VK_CPP_NO_EXCEPTIONS" << std::endl;
|
||||
<< "#endif // VULKAN_HPP_NO_EXCEPTIONS" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2397,9 +2397,9 @@ void writeTypeCommand(std::ofstream & ofs, VkData const& vkData, DependencyData
|
||||
writeTypeCommandStandard(ofs, " ", dependencyData.name, dependencyData, commandData, vkData.vkTypes);
|
||||
|
||||
ofs << std::endl
|
||||
<< "#ifndef VKCPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
<< "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
writeTypeCommandEnhanced(ofs, vkData, " ", "", dependencyData.name, dependencyData, commandData);
|
||||
ofs << "#endif /*VKCPP_DISABLE_ENHANCED_MODE*/" << std::endl
|
||||
ofs << "#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
@ -2602,7 +2602,7 @@ void writeTypeHandle(std::ofstream & ofs, VkData const& vkData, DependencyData c
|
||||
<< " : m_" << memberName << "(VK_NULL_HANDLE)" << std::endl
|
||||
<< " {}" << std::endl
|
||||
<< std::endl
|
||||
<< "#if defined(VK_CPP_TYPESAFE_CONVERSION)" << std::endl
|
||||
<< "#if defined(VULKAN_HPP_TYPESAFE_CONVERSION)" << std::endl
|
||||
// construct from native handle
|
||||
<< " " << dependencyData.name << "(Vk" << dependencyData.name << " " << memberName << ")" << std::endl
|
||||
<< " : m_" << memberName << "(" << memberName << ")" << std::endl
|
||||
@ -2632,18 +2632,18 @@ void writeTypeHandle(std::ofstream & ofs, VkData const& vkData, DependencyData c
|
||||
bool hasPointers = hasPointerArguments(cit->second);
|
||||
if (!hasPointers)
|
||||
{
|
||||
ofs << "#ifdef VKCPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
ofs << "#ifdef VULKAN_HPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
}
|
||||
writeTypeCommandStandard(ofs, " ", functionName, *dep, cit->second, vkData.vkTypes);
|
||||
if (!hasPointers)
|
||||
{
|
||||
ofs << "#endif /*!VKCPP_DISABLE_ENHANCED_MODE*/" << std::endl;
|
||||
ofs << "#endif /*!VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl;
|
||||
}
|
||||
|
||||
ofs << std::endl
|
||||
<< "#ifndef VKCPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
<< "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE" << std::endl;
|
||||
writeTypeCommandEnhanced(ofs, vkData, " ", className, functionName, *dep, cit->second);
|
||||
ofs << "#endif /*VKCPP_DISABLE_ENHANCED_MODE*/" << std::endl;
|
||||
ofs << "#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl;
|
||||
|
||||
if (i < handle.commands.size() - 1)
|
||||
{
|
||||
@ -2652,7 +2652,7 @@ void writeTypeHandle(std::ofstream & ofs, VkData const& vkData, DependencyData c
|
||||
}
|
||||
ofs << std::endl;
|
||||
}
|
||||
ofs << "#if !defined(VK_CPP_TYPESAFE_CONVERSION)" << std::endl
|
||||
ofs << "#if !defined(VULKAN_HPP_TYPESAFE_CONVERSION)" << std::endl
|
||||
<< " explicit" << std::endl
|
||||
<< "#endif" << std::endl
|
||||
<< " operator Vk" << dependencyData.name << "() const" << std::endl
|
||||
@ -2819,7 +2819,7 @@ void writeTypeUnion( std::ofstream & ofs, VkData const& vkData, DependencyData c
|
||||
}
|
||||
if (needsUnrestrictedUnions)
|
||||
{
|
||||
ofs << "#ifdef VK_CPP_HAS_UNRESTRICTED_UNIONS" << std::endl;
|
||||
ofs << "#ifdef VULKAN_HPP_HAS_UNRESTRICTED_UNIONS" << std::endl;
|
||||
for (size_t i = 0; i < unionData.members.size(); i++)
|
||||
{
|
||||
ofs << " " << unionData.members[i].type << " " << unionData.members[i].name;
|
||||
@ -2847,7 +2847,7 @@ void writeTypeUnion( std::ofstream & ofs, VkData const& vkData, DependencyData c
|
||||
}
|
||||
if (needsUnrestrictedUnions)
|
||||
{
|
||||
ofs << "#endif // VK_CPP_HAS_UNRESTRICTED_UNIONS" << std::endl;
|
||||
ofs << "#endif // VULKAN_HPP_HAS_UNRESTRICTED_UNIONS" << std::endl;
|
||||
}
|
||||
ofs << " };" << std::endl
|
||||
<< std::endl;
|
||||
@ -2904,9 +2904,9 @@ void writeVersionCheck(std::ofstream & ofs, std::string const& version)
|
||||
void writeTypesafeCheck(std::ofstream & ofs, std::string const& typesafeCheck)
|
||||
{
|
||||
ofs << "// 32-bit vulkan is not typesafe for handles, so don't allow copy constructors on this platform by default." << std::endl
|
||||
<< "// To enable this feature on 32-bit platforms please define VK_CPP_TYPESAFE_CONVERSION" << std::endl
|
||||
<< "// To enable this feature on 32-bit platforms please define VULKAN_HPP_TYPESAFE_CONVERSION" << std::endl
|
||||
<< typesafeCheck << std::endl
|
||||
<< "#define VK_CPP_TYPESAFE_CONVERSION 1" << std::endl
|
||||
<< "#define VULKAN_HPP_TYPESAFE_CONVERSION 1" << std::endl
|
||||
<< "#endif" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
@ -2918,7 +2918,7 @@ int main( int argc, char **argv )
|
||||
|
||||
std::string filename = (argc == 1) ? VK_SPEC : argv[1];
|
||||
std::cout << "Loading vk.xml from " << filename << std::endl;
|
||||
std::cout << "Writing vk_cpp.hpp to " << VK_CPP << std::endl;
|
||||
std::cout << "Writing vulkan.hpp to " << VULKAN_HPP << std::endl;
|
||||
|
||||
tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
|
||||
if (error != tinyxml2::XML_SUCCESS)
|
||||
@ -2973,13 +2973,13 @@ int main( int argc, char **argv )
|
||||
std::map<std::string, std::string> defaultValues;
|
||||
createDefaults(vkData, defaultValues);
|
||||
|
||||
std::ofstream ofs(VK_CPP);
|
||||
std::ofstream ofs(VULKAN_HPP);
|
||||
ofs << nvidiaLicenseHeader << std::endl
|
||||
<< vkData.vulkanLicenseHeader << std::endl
|
||||
<< std::endl
|
||||
<< std::endl
|
||||
<< "#ifndef VK_CPP_H_" << std::endl
|
||||
<< "#define VK_CPP_H_" << std::endl
|
||||
<< "#ifndef VULKAN_HPP" << std::endl
|
||||
<< "#define VULKAN_HPP" << std::endl
|
||||
<< std::endl
|
||||
<< "#include <array>" << std::endl
|
||||
<< "#include <cassert>" << std::endl
|
||||
@ -2988,9 +2988,9 @@ int main( int argc, char **argv )
|
||||
<< "#include <string>" << std::endl
|
||||
<< "#include <system_error>" << std::endl
|
||||
<< "#include <vulkan/vulkan.h>" << std::endl
|
||||
<< "#ifndef VKCPP_DISABLE_ENHANCED_MODE" << std::endl
|
||||
<< "#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE" << std::endl
|
||||
<< "# include <vector>" << std::endl
|
||||
<< "#endif /*VKCPP_DISABLE_ENHANCED_MODE*/" << std::endl
|
||||
<< "#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/" << std::endl
|
||||
<< std::endl;
|
||||
|
||||
writeVersionCheck(ofs, vkData.version);
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user