Skip to content

Commit

Permalink
Avoid copying static code in the generator
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Dec 9, 2024
1 parent e181c48 commit 835af46
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 494 deletions.
14 changes: 0 additions & 14 deletions generator/generate_vulkan_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,6 @@ def main():
base_dir = os.path.dirname(__file__)
outdir = os.path.join(base_dir, '..', 'source_common', 'framework')

# Clean the output directory if needed
if os.path.exists(outdir):
if not os.path.isdir(outdir):
print(f'ERROR: Output location "{outdir}" is not a directory')
return 1

shutil.rmtree(outdir, ignore_errors=True)
os.makedirs(outdir)

# Parse the XML headers
tree = ET.parse('./khronos/vulkan/registry/vk.xml')
root = tree.getroot()
Expand Down Expand Up @@ -732,11 +723,6 @@ def main():
# Load hand written function bodies
manual_commands = load_handwritten_commands()

# Generate static resources
base_dir = os.path.dirname(__file__)
source_dir = os.path.join(base_dir, 'vk_common')
copy_resource(source_dir, outdir)

# Generate dynamic resources
outfile = os.path.join(outdir, 'instance_dispatch_table.hpp')
with open(outfile, 'w', encoding='utf-8', newline='\n') as handle:
Expand Down
1 change: 1 addition & 0 deletions generator/vk_codegen/device_dispatch_table.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vulkan/vulkan.h>

#include "framework/device_functions.hpp"
#include "framework/utils.hpp"
#include "utils/misc.hpp"

#if __has_include ("layer_device_functions.hpp")
Expand Down
6 changes: 2 additions & 4 deletions generator/vk_codegen/function_vkCreateDevice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

// Advance the link info for the next element on the chain
chainInfo->u.pLayerInfo = chainInfo->u.pLayerInfo->pNext;

auto res = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
if (res != VK_SUCCESS)
{
return res;
}

auto device = std::make_unique<Device>(layer, physicalDevice, *pDevice, fpGetDeviceProcAddr);

// Hold the lock to access layer-wide global store
// Retake the lock to access layer-wide global store
lock.lock();
auto device = std::make_unique<Device>(layer, physicalDevice, *pDevice, fpGetDeviceProcAddr);
Device::store(*pDevice, std::move(device));

return VK_SUCCESS;
2 changes: 1 addition & 1 deletion generator/vk_codegen/function_vkCreateInstance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return res;
}

// Hold the lock to access layer-wide global store
// Retake the lock to access layer-wide global store
auto instance = std::make_unique<Instance>(*pInstance, fpGetInstanceProcAddr);
{
std::lock_guard<std::mutex> lock { g_vulkanLock };
Expand Down
31 changes: 3 additions & 28 deletions generator/vk_codegen/instance_defs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,12 @@
#include <mutex>
#include <thread>

#include "utils.hpp"
#include "instance.hpp"
#include "device.hpp"
#include "entry_utils.hpp"
#include "instance.hpp"
#include "instance_functions.hpp"
#include "utils.hpp"

extern std::mutex g_vulkanLock;

static VkLayerInstanceCreateInfo* get_chain_info(
const VkInstanceCreateInfo* pCreateInfo,
VkLayerFunction func
) {
auto* info = static_cast<const VkLayerInstanceCreateInfo*>(pCreateInfo->pNext);
while (info && !(info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && info->function == func))
{
info = static_cast<const VkLayerInstanceCreateInfo*>(info->pNext);
}

return const_cast<VkLayerInstanceCreateInfo*>(info);
}

static VkLayerDeviceCreateInfo* get_chain_info(
const VkDeviceCreateInfo* pCreateInfo,
VkLayerFunction func
) {
auto* info = static_cast<const VkLayerDeviceCreateInfo*>(pCreateInfo->pNext);
while (info && !(info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && info->function == func))
{
info = static_cast<const VkLayerDeviceCreateInfo*>(info->pNext);
}

return const_cast<VkLayerDeviceCreateInfo*>(info);
}

{FUNCTION_DEFS}
1 change: 1 addition & 0 deletions generator/vk_codegen/instance_dispatch_table.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vulkan/vulkan.h>

#include "framework/instance_functions.hpp"
#include "framework/utils.hpp"
#include "utils/misc.hpp"

#if __has_include ("layer_instance_functions.hpp")
Expand Down
42 changes: 0 additions & 42 deletions generator/vk_common/CMakeLists.txt

This file was deleted.

101 changes: 0 additions & 101 deletions generator/vk_common/utils.hpp

This file was deleted.

5 changes: 4 additions & 1 deletion source_common/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ set(LIB_BINARY lib_layer_framework)
add_library(
${LIB_BINARY} STATIC
device_functions.cpp
entry_utils.cpp
instance_functions.cpp)

target_include_directories(
${LIB_BINARY} PRIVATE
# Note, this includes from the layer-specific tree
# Include from the layer-specific tree
${PROJECT_SOURCE_DIR}/source
# Needed for CMake generated version.hpp
${PROJECT_BINARY_DIR}/source
../)

target_include_directories(
Expand Down
1 change: 1 addition & 0 deletions source_common/framework/device_dispatch_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <vulkan/vulkan.h>

#include "framework/device_functions.hpp"
#include "framework/utils.hpp"
#include "utils/misc.hpp"

#if __has_include ("layer_device_functions.hpp")
Expand Down
Loading

0 comments on commit 835af46

Please sign in to comment.