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

View File

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

View File

@ -13,10 +13,10 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::ostream& 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 << "'" return os << "{ file_format_version: '" << value.file_format_version << "'"
<< ", icd: { library_path: '" << value.icd.library_path << "'" << ", icd: { library_path: '" << value.icd.library_path << "'"
<< ", api_version: '" << value.icd.api_version << "'" << ", api_version: '" << value.icd.api_version << "'"
<< " } }"; << " } }";
}; };

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,8 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::vector<cruft::vk::icd::icd_t> std::vector<cruft::vk::load::icd_t>
cruft::vk::icd::enumerate() cruft::vk::load::enumerate()
{ {
std::vector<icd_t> res; 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/load/vtable.hpp>
#include <cruft/vk/icd/vendor.hpp> #include <cruft/vk/load/vendor.hpp>
int int
main (void) main (void)
{ {
cruft::vk::icd::vendor v (cruft::vk::icd::enumerate ()[0]); cruft::vk::load::vendor v (cruft::vk::load::enumerate ()[0]);
cruft::vk::icd::i_table = &v.itable; cruft::vk::load::i_table = &v.itable;
cruft::vk::icd::v_table = &v.vtable; cruft::vk::load::v_table = &v.vtable;
LOG_INFO ("intialising glfw"); LOG_INFO ("intialising glfw");
glfw::instance glfw_instance; glfw::instance glfw_instance;

View File

@ -9,8 +9,8 @@
#include <cruft/util/iterator.hpp> #include <cruft/util/iterator.hpp>
#include <cruft/vk/icd/ostream.hpp> #include <cruft/vk/load/ostream.hpp>
#include <cruft/vk/icd/vtable.hpp> #include <cruft/vk/load/vtable.hpp>
#include <cruft/vk/instance.hpp> #include <cruft/vk/instance.hpp>
#include <cruft/vk/physical_device.hpp> #include <cruft/vk/physical_device.hpp>
@ -19,8 +19,8 @@
#include <iostream> #include <iostream>
#include "../icd/vendor.hpp" #include "../load/vendor.hpp"
#include "icd/vtable.hpp" #include "load/vtable.hpp"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -28,10 +28,10 @@ int
main (int, char**) main (int, char**)
{ {
std::cout << "[ "; std::cout << "[ ";
for (auto const &i: cruft::vk::icd::enumerate ()) { for (auto const &i: cruft::vk::load::enumerate ()) {
cruft::vk::icd::vendor v (i); cruft::vk::load::vendor v (i);
cruft::vk::icd::i_table = &v.itable; cruft::vk::load::i_table = &v.itable;
cruft::vk::icd::v_table = &v.vtable; cruft::vk::load::v_table = &v.vtable;
cruft::vk::instance instance; 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)] commands = [i for i in q if isinstance(i, Command)]
collections = { collections = {
@ -806,7 +806,7 @@ def write_icd(dst: TextIO, q: List[Type], reg: Registry):
#include <cruft/util/preprocessor.hpp> #include <cruft/util/preprocessor.hpp>
namespace cruft::vk::icd {{ namespace cruft::vk::load {{
class vendor; class vendor;
#define MAP_COMMANDS(FUNC) MAP0(FUNC,{",".join(i.name for i in commands)}) #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(""" dst.write("""
struct vendor_table; struct vendor_table;
extern cruft::vk::icd::vendor_table const *v_table; extern cruft::vk::load::vendor_table const *v_table;
extern cruft::vk::icd::instance_table const *i_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): def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
dst.write(""" dst.write("""
#include <cruft/vk/vk.hpp> #include <cruft/vk/vk.hpp>
#include <cruft/vk/icd/vtable.hpp> #include <cruft/vk/load/vtable.hpp>
#include <cruft/vk/icd/dispatch.hpp> #include <cruft/vk/load/dispatch.hpp>
#include <cruft/util/debug.hpp> #include <cruft/util/debug.hpp>
@ -863,12 +863,12 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
implementations = { implementations = {
'vkCreateInstance': """ 'vkCreateInstance': """
auto res = std::make_unique<indirect<VkInstance,cruft::vk::icd::instance_table>> (); auto res = std::make_unique<indirect<VkInstance,cruft::vk::load::instance_table>> ();
auto err = cruft::vk::icd::i_table->vkCreateInstance (pCreateInfo, pAllocator, &res->handle); auto err = cruft::vk::load::i_table->vkCreateInstance (pCreateInfo, pAllocator, &res->handle);
if (err != VK_SUCCESS) if (err != VK_SUCCESS)
return err; 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) MAP_INSTANCE_COMMANDS(GET)
#undef GET #undef GET
@ -890,7 +890,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
'vkEnumeratePhysicalDevices': """ 'vkEnumeratePhysicalDevices': """
auto const entry = reinterpret_cast< auto const entry = reinterpret_cast<
indirect<VkInstance,cruft::vk::icd::instance_table> const* indirect<VkInstance,cruft::vk::load::instance_table> const*
> (instance); > (instance);
if (!pPhysicalDeviceCount || !pPhysicalDevices) { if (!pPhysicalDeviceCount || !pPhysicalDevices) {
@ -909,7 +909,7 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
return err; return err;
for (uint32_t i = 0; i < *pPhysicalDeviceCount; ++i) { 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]; wrapped->handle = res[i];
#define GET(NAME) wrapped->table.NAME = wrapped->table.NAME ?: reinterpret_cast<decltype(&NAME)> (vkGetInstanceProcAddr (instance, #NAME)); #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] first_arg = reg.types[obj.params[0].type]
instance_forward = f""" 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): if obj.is_instance(reg):
@ -945,10 +945,10 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry):
is_creating = False is_creating = False
if obj.is_instance(reg) and obj.params[0].type not in ['VkInstance', 'VkPhysicalDevice']: 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: else:
forwarding = f""" 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})( return (entry->table.{obj.name})(
{", ".join(['entry->handle'] + [p.name for p in obj.params[1:]])} {", ".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 = 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('--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('--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('--dispatch', type=str, help="the output path for function dispatch")
parser.add_argument( parser.add_argument(
'--platform', '--platform',
@ -1064,12 +1064,12 @@ def main():
extensions = ["VK_KHR_swapchain", "VK_EXT_debug_report", "VK_KHR_external_memory"] extensions = ["VK_KHR_swapchain", "VK_EXT_debug_report", "VK_KHR_external_memory"]
q = reg.serialise(args.platform) 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: with open(args.dst, 'w') as dst:
write_header(dst, q, reg) write_header(dst, q, reg)
with open(args.icd, 'w') as dst: with open(args.load, 'w') as dst:
write_icd(dst, q, reg) write_load(dst, q, reg)
with open(args.dispatch, 'w') as dst: with open(args.dispatch, 'w') as dst:
write_dispatch(dst, q, reg) write_dispatch(dst, q, reg)