rename 'icd' namespace as 'load'

This commit is contained in:
Danny Robson 2019-03-03 11:53:31 +11:00
parent 68a9fa1d2e
commit 154e3b039b
14 changed files with 74 additions and 74 deletions

View File

@ -15,7 +15,7 @@ endif ()
###############################################################################
set (GENERATED_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/cruft/vk/")
file (MAKE_DIRECTORY "${GENERATED_PREFIX}/icd")
file (MAKE_DIRECTORY "${GENERATED_PREFIX}/load")
if (WIN32)
@ -31,8 +31,8 @@ endif()
add_custom_command (
OUTPUT
"${GENERATED_PREFIX}/vk.hpp"
"${GENERATED_PREFIX}/icd/dispatch.cpp"
"${GENERATED_PREFIX}/icd/vtable.hpp"
"${GENERATED_PREFIX}/load/dispatch.cpp"
"${GENERATED_PREFIX}/load/vtable.hpp"
COMMENT
"[spec.py] vk.hpp"
COMMAND
@ -40,8 +40,8 @@ COMMAND
"${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py"
"--src" "${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml"
"--dst" "${GENERATED_PREFIX}/vk.hpp"
"--icd" "${GENERATED_PREFIX}/icd/vtable.hpp"
"--dispatch" "${GENERATED_PREFIX}/icd/dispatch.cpp"
"--load" "${GENERATED_PREFIX}/load/vtable.hpp"
"--dispatch" "${GENERATED_PREFIX}/load/dispatch.cpp"
"--platform" "${VK_PLATFORM}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py"
@ -61,27 +61,27 @@ endif()
##-----------------------------------------------------------------------------
add_library (cruft-vk-icd STATIC
icd/fwd.hpp
${GENERATED_PREFIX}/icd/vtable.hpp
${GENERATED_PREFIX}/icd/dispatch.cpp
icd/dispatch.hpp
icd/ostream.cpp
icd/ostream.hpp
icd/vendor.hpp
icd/vendor.cpp
icd/vendor_${VK_LOADER_VENDOR}
icd/vtable.cpp
add_library (cruft-vk-load STATIC
load/fwd.hpp
${GENERATED_PREFIX}/load/vtable.hpp
${GENERATED_PREFIX}/load/dispatch.cpp
load/dispatch.hpp
load/ostream.cpp
load/ostream.hpp
load/vendor.hpp
load/vendor.cpp
load/vendor_${VK_LOADER_VENDOR}
load/vtable.cpp
)
target_include_directories (cruft-vk-icd
target_include_directories (cruft-vk-load
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan"
)
target_link_libraries (cruft-vk-icd cruft-json cruft)
target_link_libraries (cruft-vk-load cruft-json cruft)
###############################################################################
list (APPEND sources
@ -143,7 +143,7 @@ list (APPEND sources
##-----------------------------------------------------------------------------
add_library (cruft-vk STATIC ${sources})
target_link_libraries (cruft-vk cruft-vk-icd cruft)
target_link_libraries (cruft-vk cruft-vk-load cruft)
target_include_directories (cruft-vk
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"

View File

@ -1,8 +0,0 @@
#include <cruft/vk/icd/vtable.hpp>
using cruft::vk::icd::instance_table;
///////////////////////////////////////////////////////////////////////////////
cruft::vk::icd::vendor_table const *cruft::vk::icd::v_table = nullptr;
cruft::vk::icd::instance_table const *cruft::vk::icd::i_table = nullptr;

View File

@ -2,6 +2,6 @@
#include "vendor.hpp"
namespace cruft::vk::icd {
namespace cruft::vk::load {
void init (vendor const&);
}

View File

@ -9,6 +9,6 @@
#pragma once
namespace cruft::vk::icd {
namespace cruft::vk::load {
struct icd_t;
}

View File

@ -13,10 +13,10 @@
///////////////////////////////////////////////////////////////////////////////
std::ostream&
cruft::vk::icd::operator<< (std::ostream &os, icd_t const &value)
cruft::vk::load::operator<< (std::ostream &os, icd_t const &value)
{
return os << "{ file_format_version: '" << value.file_format_version << "'"
<< ", icd: { library_path: '" << value.icd.library_path << "'"
<< ", api_version: '" << value.icd.api_version << "'"
<< ", icd: { library_path: '" << value.icd.library_path << "'"
<< ", api_version: '" << value.icd.api_version << "'"
<< " } }";
};

View File

@ -12,6 +12,6 @@
#include <iosfwd>
namespace cruft::vk::icd {
namespace cruft::vk::load {
std::ostream& operator<< (std::ostream&, icd_t const&);
}

View File

@ -5,7 +5,7 @@
#include <cruft/util/std.hpp>
#include <cruft/util/log.hpp>
using cruft::vk::icd::vendor;
using cruft::vk::load::vendor;
#define MAP_ICD_COMMANDS(FUNC,...) MAP0(FUNC,\
@ -16,8 +16,8 @@ using cruft::vk::icd::vendor;
///////////////////////////////////////////////////////////////////////////////
template <>
cruft::vk::icd::icd_t
json::tree::io<cruft::vk::icd::icd_t>::deserialise (json::tree::node const &obj)
cruft::vk::load::icd_t
json::tree::io<cruft::vk::load::icd_t>::deserialise (json::tree::node const &obj)
{
return {
.file_format_version = obj["file_format_version"].as_string (),
@ -63,7 +63,7 @@ vendor::vendor (::cruft::library &&_library)
throw std::runtime_error (unknown_message);
case VK_SUCCESS:
LOG_INFO ("vk::icd version %!", version);
LOG_INFO ("vk::load version %!", version);
break;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <cruft/vk/vk.hpp>
#include <cruft/vk/icd/vtable.hpp>
#include <cruft/vk/load/vtable.hpp>
#include <cruft/util/library.hpp>
#include <cruft/util/std.hpp>
@ -11,7 +11,7 @@
///////////////////////////////////////////////////////////////////////////////
namespace cruft::vk::icd {
namespace cruft::vk::load {
struct icd_t {
std::string file_format_version;
struct {

View File

@ -12,8 +12,8 @@ namespace fs = std::filesystem;
///////////////////////////////////////////////////////////////////////////////
std::vector<cruft::vk::icd::icd_t>
cruft::vk::icd::enumerate (void)
std::vector<cruft::vk::load::icd_t>
cruft::vk::load::enumerate (void)
{
// The predefined, ordered, search locations for manifests
static char const *locations[] = {

View File

@ -9,8 +9,8 @@
///////////////////////////////////////////////////////////////////////////////
std::vector<cruft::vk::icd::icd_t>
cruft::vk::icd::enumerate()
std::vector<cruft::vk::load::icd_t>
cruft::vk::load::enumerate()
{
std::vector<icd_t> res;

8
load/vtable.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <cruft/vk/load/vtable.hpp>
using cruft::vk::load::instance_table;
///////////////////////////////////////////////////////////////////////////////
cruft::vk::load::vendor_table const *cruft::vk::load::v_table = nullptr;
cruft::vk::load::instance_table const *cruft::vk::load::i_table = nullptr;

View File

@ -293,15 +293,15 @@ public:
///////////////////////////////////////////////////////////////////////////////
#include <cruft/vk/icd/vtable.hpp>
#include <cruft/vk/icd/vendor.hpp>
#include <cruft/vk/load/vtable.hpp>
#include <cruft/vk/load/vendor.hpp>
int
main (void)
{
cruft::vk::icd::vendor v (cruft::vk::icd::enumerate ()[0]);
cruft::vk::icd::i_table = &v.itable;
cruft::vk::icd::v_table = &v.vtable;
cruft::vk::load::vendor v (cruft::vk::load::enumerate ()[0]);
cruft::vk::load::i_table = &v.itable;
cruft::vk::load::v_table = &v.vtable;
LOG_INFO ("intialising glfw");
glfw::instance glfw_instance;

View File

@ -9,8 +9,8 @@
#include <cruft/util/iterator.hpp>
#include <cruft/vk/icd/ostream.hpp>
#include <cruft/vk/icd/vtable.hpp>
#include <cruft/vk/load/ostream.hpp>
#include <cruft/vk/load/vtable.hpp>
#include <cruft/vk/instance.hpp>
#include <cruft/vk/physical_device.hpp>
@ -19,8 +19,8 @@
#include <iostream>
#include "../icd/vendor.hpp"
#include "icd/vtable.hpp"
#include "../load/vendor.hpp"
#include "load/vtable.hpp"
///////////////////////////////////////////////////////////////////////////////
@ -28,10 +28,10 @@ int
main (int, char**)
{
std::cout << "[ ";
for (auto const &i: cruft::vk::icd::enumerate ()) {
cruft::vk::icd::vendor v (i);
cruft::vk::icd::i_table = &v.itable;
cruft::vk::icd::v_table = &v.vtable;
for (auto const &i: cruft::vk::load::enumerate ()) {
cruft::vk::load::vendor v (i);
cruft::vk::load::i_table = &v.itable;
cruft::vk::load::v_table = &v.vtable;
cruft::vk::instance instance;

View File

@ -791,7 +791,7 @@ def write_header(dst: TextIO, q: List[Type], reg: Registry):
# -----------------------------------------------------------------------------
def write_icd(dst: TextIO, q: List[Type], reg: Registry):
def write_load(dst: TextIO, q: List[Type], reg: Registry):
commands = [i for i in q if isinstance(i, Command)]
collections = {
@ -806,7 +806,7 @@ def write_icd(dst: TextIO, q: List[Type], reg: Registry):
#include <cruft/util/preprocessor.hpp>
namespace cruft::vk::icd {{
namespace cruft::vk::load {{
class vendor;
#define MAP_COMMANDS(FUNC) MAP0(FUNC,{",".join(i.name for i in commands)})
@ -837,8 +837,8 @@ def write_icd(dst: TextIO, q: List[Type], reg: Registry):
dst.write("""
struct vendor_table;
extern cruft::vk::icd::vendor_table const *v_table;
extern cruft::vk::icd::instance_table const *i_table;
extern cruft::vk::load::vendor_table const *v_table;
extern cruft::vk::load::instance_table const *i_table;
}
""")
@ -847,8 +847,8 @@ def write_icd(dst: TextIO, q: List[Type], reg: Registry):
def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
dst.write("""
#include <cruft/vk/vk.hpp>
#include <cruft/vk/icd/vtable.hpp>
#include <cruft/vk/icd/dispatch.hpp>
#include <cruft/vk/load/vtable.hpp>
#include <cruft/vk/load/dispatch.hpp>
#include <cruft/util/debug.hpp>
@ -863,12 +863,12 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
implementations = {
'vkCreateInstance': """
auto res = std::make_unique<indirect<VkInstance,cruft::vk::icd::instance_table>> ();
auto err = cruft::vk::icd::i_table->vkCreateInstance (pCreateInfo, pAllocator, &res->handle);
auto res = std::make_unique<indirect<VkInstance,cruft::vk::load::instance_table>> ();
auto err = cruft::vk::load::i_table->vkCreateInstance (pCreateInfo, pAllocator, &res->handle);
if (err != VK_SUCCESS)
return err;
#define GET(NAME) res->table.NAME = reinterpret_cast<decltype(&NAME)> (cruft::vk::icd::v_table->vk_icdGetInstanceProcAddr (res->handle, #NAME));
#define GET(NAME) res->table.NAME = reinterpret_cast<decltype(&NAME)> (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (res->handle, #NAME));
MAP_INSTANCE_COMMANDS(GET)
#undef GET
@ -890,7 +890,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
'vkEnumeratePhysicalDevices': """
auto const entry = reinterpret_cast<
indirect<VkInstance,cruft::vk::icd::instance_table> const*
indirect<VkInstance,cruft::vk::load::instance_table> const*
> (instance);
if (!pPhysicalDeviceCount || !pPhysicalDevices) {
@ -909,7 +909,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
return err;
for (uint32_t i = 0; i < *pPhysicalDeviceCount; ++i) {
auto wrapped = std::make_unique<indirect<VkPhysicalDevice,cruft::vk::icd::instance_table>> ();
auto wrapped = std::make_unique<indirect<VkPhysicalDevice,cruft::vk::load::instance_table>> ();
wrapped->handle = res[i];
#define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: reinterpret_cast<decltype(&NAME)> (vkGetInstanceProcAddr (instance, #NAME));
@ -927,7 +927,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
first_arg = reg.types[obj.params[0].type]
instance_forward = f"""
return cruft::vk::icd::i_table->{obj.name} ({", ".join(p.name for p in obj.params)});
return cruft::vk::load::i_table->{obj.name} ({", ".join(p.name for p in obj.params)});
"""
if obj.is_instance(reg):
@ -945,10 +945,10 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
is_creating = False
if obj.is_instance(reg) and obj.params[0].type not in ['VkInstance', 'VkPhysicalDevice']:
forwarding = f"return ::cruft::vk::icd::i_table->{obj.name} ({', '.join (i.name for i in obj.params)});"
forwarding = f"return ::cruft::vk::load::i_table->{obj.name} ({', '.join (i.name for i in obj.params)});"
else:
forwarding = f"""
auto const entry = reinterpret_cast<indirect<{obj.params[0].type},cruft::vk::icd::{table}_table> const*> ({obj.params[0].name});
auto const entry = reinterpret_cast<indirect<{obj.params[0].type},cruft::vk::load::{table}_table> const*> ({obj.params[0].name});
return (entry->table.{obj.name})(
{", ".join(['entry->handle'] + [p.name for p in obj.params[1:]])}
@ -973,7 +973,7 @@ def main():
parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers')
parser.add_argument('--src', type=str, help='the path to the XML file to transform')
parser.add_argument('--dst', type=str, help='the output path for the result')
parser.add_argument('--icd', type=str, help='the output path for the icd loading routines')
parser.add_argument('--load', type=str, help='the output path for the loading routines')
parser.add_argument('--dispatch', type=str, help="the output path for function dispatch")
parser.add_argument(
'--platform',
@ -1064,12 +1064,12 @@ def main():
extensions = ["VK_KHR_swapchain", "VK_EXT_debug_report", "VK_KHR_external_memory"]
q = reg.serialise(args.platform)
# Finally write out the header, icd, and dispatch code.
# Finally write out the header, vtables, and dispatch code.
with open(args.dst, 'w') as dst:
write_header(dst, q, reg)
with open(args.icd, 'w') as dst:
write_icd(dst, q, reg)
with open(args.load, 'w') as dst:
write_load(dst, q, reg)
with open(args.dispatch, 'w') as dst:
write_dispatch(dst, q, reg)