Skip to content

Commit

Permalink
Added format traits and extension inspections
Browse files Browse the repository at this point in the history
- Straightforward, since everything is hard-coded
  • Loading branch information
sharadhr committed Jun 16, 2023
1 parent 378087f commit 09a1177
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 71 deletions.
85 changes: 79 additions & 6 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <array>
#include <cassert>
#include <fstream>
#include <numeric>
#include <ranges>
#include <regex>
#include <sstream>
Expand Down Expand Up @@ -679,6 +680,8 @@ void VulkanHppGenerator::generateCppModuleFile() const
module;

#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_extension_inspection.hpp>
#include <vulkan/vulkan_format_traits.hpp>
#include <vulkan/vulkan_raii.hpp>

export module ${api};
Expand Down Expand Up @@ -4846,6 +4849,8 @@ std::string VulkanHppGenerator::generateCppModuleHandleUsings() const
//===============
//=== HANDLEs ===
//===============

using VULKAN_HPP_NAMESPACE::isVulkanHandleType;
)";

auto const generateUsingsAndProtection = [&usingTemplate, this]( std::vector<RequireData> const & requireData, std::string const & title )
Expand Down Expand Up @@ -4988,8 +4993,8 @@ std::string VulkanHppGenerator::generateCppModuleFuncsUsings() const
{
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${funcName};
)" };
auto funcUsings = std::stringstream{} << R"( //===========================

auto funcUsings = std::stringstream{} << R"( //===========================
//=== COMMAND Definitions ===
//===========================
)";
Expand Down Expand Up @@ -5071,6 +5076,71 @@ std::string VulkanHppGenerator::generateCppModuleEnumUsings() const
return enumUsings.str();
}

std::string VulkanHppGenerator::generateCppModuleFormatTraitsUsings() const
{
// everything is hardcoded, so things are very easy...
auto const formatTraits = std::string{ R"(
//=====================
//=== Format Traits ===
//=====================
)" };

auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${function};
)" };
auto const formatTraitFunctions = std::array{ "blockExtent",
"blockSize",
"compatibilityClass",
"componentBits",
"componentCount",
"componentName",
"componentNumericFormat",
"componentPlaneIndex",
"componentsAreCompressed",
"compressionScheme",
"isCompressed",
"packed",
"planeCompatibleFormat",
"planeCount",
"planeHeightDivisor",
"planeWidthDivisor",
"texelsPerBlock" };

auto usings = formatTraitFunctions |
std::views::transform(
[&]( auto const & func ) {
return replaceWithMap( usingTemplate, { { "function", func } } );
} ) |
std::views::common;

return std::accumulate( usings.begin(), usings.end(), formatTraits );
}

std::string VulkanHppGenerator::generateCppModuleExtensionInspectionUsings() const
{
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${function};
)" };

auto const extensionInspections = std::string{ R"(
//======================================
//=== Extension inspection functions ===
//======================================
)" };

auto const extensionInspectionFunctions =
std::array{ "getDeviceExtensions", "getInstanceExtensions", "getDeprecatedExtensions", "getExtensionDepends", "getExtensionDepends",
"getObsoletedExtensions", "getPromotedExtensions", "getExtensionDeprecatedBy", "getExtensionObsoletedBy", "getExtensionPromotedTo",
"isDeprecatedExtension", "isDeviceExtension", "isInstanceExtension", "isObsoletedExtension", "isPromotedExtension" };

auto usings = extensionInspectionFunctions |
std::views::transform(
[&]( auto const & func ) {
return replaceWithMap( usingTemplate, { { "function", func } } );
} ) |
std::views::common;

return std::accumulate( usings.begin(), usings.end(), extensionInspections );
}

std::string VulkanHppGenerator::generateCppModuleUsings() const
{
auto const usingTemplate = std::string{ R"( using VULKAN_HPP_NAMESPACE::${className};
Expand Down Expand Up @@ -5167,7 +5237,7 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
//=== EXCEPTIONs AND ERRORs ===
//=============================
)" << exceptionsEnter;

for ( auto const & name : hardCodedExceptionTypesAndFunctions )
{
exceptionsUsings << replaceWithMap( usingTemplate, { { "className", name } } );
Expand All @@ -5182,9 +5252,9 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const
{
if ( alias.empty() && enumName.starts_with( "VK_ERROR" ) )
{
auto [enter, leave] = generateProtection( protect );
enter = enter.empty() ? enter : "\n" + enter;
leave = leave.empty() ? leave : leave + "\n";
auto [enter, leave] = generateProtection( protect );
enter = enter.empty() ? enter : "\n" + enter;
leave = leave.empty() ? leave : leave + "\n";

auto const valueName = generateEnumValueName( name, enumName, false );
auto const className = stripPrefix( valueName, "eError" ) + "Error";
Expand Down Expand Up @@ -5220,6 +5290,9 @@ std::string VulkanHppGenerator::generateCppModuleUsings() const

usings << replaceWithMap( usingTemplate, { { "className", "DispatchLoaderDynamic" } } ) << std::endl;

usings << generateCppModuleFormatTraitsUsings();
usings << generateCppModuleExtensionInspectionUsings();

return usings.str();
}

Expand Down
Loading

0 comments on commit 09a1177

Please sign in to comment.