Added support for resetting lists and retrieving function names.
This commit is contained in:
parent
1d073c0256
commit
4fd0760f75
@ -171,6 +171,7 @@ def generate_source(target, source, env):
|
||||
return None
|
||||
|
||||
pygen_builder = Builder(action = generate_source)
|
||||
env.Append(CCFLAGS = '-Wall -Wextra -Werror -pedantic -std=c++20')
|
||||
env.Append(BUILDERS = {'PyGen': pygen_builder})
|
||||
env.Append(CPPPATH = ['include'])
|
||||
|
||||
@ -178,6 +179,7 @@ source_files = Split("""
|
||||
source/data_pool.cpp
|
||||
source/dispatch_table.cpp
|
||||
source/functions.cpp
|
||||
source/function_ids.cpp
|
||||
source/layer.cpp
|
||||
source/record_list.cpp
|
||||
source/variant_pool.cpp
|
||||
@ -185,6 +187,7 @@ source_files = Split("""
|
||||
|
||||
# env.PyGen('source/functions.hpp', 'generators/functions.hpp.py')
|
||||
env.PyGen('include/vk_function_ids.h', 'generators/vk_function_ids.h.py')
|
||||
env.PyGen('source/function_ids.cpp', 'generators/function_ids.cpp.py')
|
||||
env.PyGen('source/functions.cpp', 'generators/functions.cpp.py')
|
||||
env.PyGen('source/variant_wrap.hpp', 'generators/variant_wrap.hpp.py')
|
||||
env.SharedLibrary(
|
||||
|
53
generators/function_ids.cpp.py
Normal file
53
generators/function_ids.cpp.py
Normal file
@ -0,0 +1,53 @@
|
||||
import binascii
|
||||
from common import func_name_to_caps, write_epilogue, write_preamble, FIRST_PARAM_BLACKLIST, FUNC_BLACKLIST
|
||||
|
||||
HEADER_GUARD = 'VK_CAPTURE_FUNCTION_IDS_H_INCLUDED'
|
||||
_dbg_hashes = set()
|
||||
|
||||
|
||||
def write_funccase(f, cmd):
|
||||
if 'alias' in cmd or cmd["name"] in FUNC_BLACKLIST:
|
||||
return
|
||||
if len(cmd['params']) > 0 and cmd['params'][0]['type'] in FIRST_PARAM_BLACKLIST:
|
||||
return
|
||||
funchash = binascii.crc32(cmd['name'].encode('utf8'))
|
||||
f.write(f"""
|
||||
case VK_FUNCTION_{func_name_to_caps(cmd['name'])}_MWN:
|
||||
*pName = "{cmd['name']}";
|
||||
return VK_SUCCESS;""")
|
||||
|
||||
# just to make sure there are no hash collisions, we wouldn't want that
|
||||
global _dbg_hashes
|
||||
assert(funchash not in _dbg_hashes)
|
||||
_dbg_hashes.add(funchash)
|
||||
|
||||
def generate(targets):
|
||||
assert(len(targets) == 1)
|
||||
with open(targets[0], 'w') as f:
|
||||
write_preamble(f, includes = ['<vulkan/vulkan.h>', '"vk_function_ids.h"'])
|
||||
commands = list(vulkan_hpp['commands'].values())
|
||||
commands.sort(key=lambda cmd: cmd['platform'])
|
||||
plat = ''
|
||||
f.write("""
|
||||
VkResult vkGetFunctionNameMWN(VkDevice /* device */, VkFunctionMWN function, const char** pName)
|
||||
{
|
||||
switch(function)
|
||||
{""")
|
||||
for cmd in commands:
|
||||
if plat != cmd['platform']:
|
||||
if plat != '':
|
||||
f.write(f"""
|
||||
#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
||||
plat = cmd['platform']
|
||||
f.write(f"""
|
||||
#if defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
||||
write_funccase(f, cmd)
|
||||
# finish the final platform
|
||||
f.write(f"""#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
||||
f.write("""
|
||||
default:
|
||||
return VK_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
""")
|
||||
write_epilogue(f)
|
@ -82,6 +82,7 @@ typedef struct VkVariantMWN {
|
||||
int64_t intValue;
|
||||
float floatValue;
|
||||
double doubleValue;
|
||||
const char* stringValue;
|
||||
const void* voidPointerValue;
|
||||
VkVariantMWN* pointerValue;
|
||||
VkVariantArrayValueMWN arrayValue;
|
||||
@ -99,11 +100,20 @@ typedef struct VkRecordListItemMWN
|
||||
VkVariantMWN* pParameterValues;
|
||||
} VkRecordListItemMWN;
|
||||
|
||||
typedef struct VkRecordListItemFormatMWN
|
||||
{
|
||||
int todo;
|
||||
} VkRecordListItemFormatMWN;
|
||||
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkAllocateRecordListMWN)(VkDevice device, const VkRecordListAllocateInfoMWN* pCreateInfo, VkRecordListMWN* pRecordList);
|
||||
typedef void (VKAPI_PTR *PFN_vkFreeRecordListMWN)(VkDevice device, VkRecordListMWN recordList);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkBeginRecordingMWN)(VkDevice device, const VkRecordInfoMWN* pRecordInfo);
|
||||
typedef void (VKAPI_PTR *PFN_vkEndRecordingMWN)(VkDevice device);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetRecordListItemsMWN)(VkDevice device, VkRecordListMWN recordList, uint32_t* pItemCount, VkRecordListItemMWN** pItems);
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkResetRecordListMWN)(VkDevice device, VkRecordListMWN recordList);
|
||||
|
||||
// utility
|
||||
typedef VkResult (VKAPI_PTR *PFN_vkGetFunctionNameMWN)(VkDevice device, VkFunctionMWN function, const char** pName);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
|
20
site_scons/pygen.py
Normal file
20
site_scons/pygen.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
def generate_source(target, source, env):
|
||||
import os
|
||||
import sys
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
|
||||
# allow the module to import from its current folder
|
||||
sys.path.append(os.path.dirname(source[0].abspath))
|
||||
python_spec = spec_from_file_location('source', source[0].abspath)
|
||||
python_mod = module_from_spec(python_spec)
|
||||
python_spec.loader.exec_module(python_mod)
|
||||
python_mod.generate(targets = [t.abspath for t in target])
|
||||
|
||||
# restore path
|
||||
sys.path = sys.path[:-1]
|
||||
|
||||
return None
|
||||
|
||||
pygen_builder = Builder(action = generate_source)
|
||||
# env.Append(BUILDERS = {'PyGen': pygen_builder})
|
@ -40,14 +40,16 @@ void* DataPool::allocate(std::size_t bytes, std::size_t alignment)
|
||||
}
|
||||
|
||||
const std::size_t remainingOnPage = PAGE_SIZE - (offset % PAGE_SIZE);
|
||||
const std::size_t page = offset / PAGE_SIZE;
|
||||
const std::size_t localOffset = offset % PAGE_SIZE;
|
||||
if (remainingOnPage == PAGE_SIZE || remainingOnPage < bytes)
|
||||
{
|
||||
// next page
|
||||
pages.push_back(std::make_unique<Page>());
|
||||
if (page + 1 >= pages.size()) {
|
||||
pages.push_back(std::make_unique<Page>());
|
||||
}
|
||||
offset = PAGE_SIZE * (pages.size() - 1);
|
||||
}
|
||||
const std::size_t page = offset / PAGE_SIZE;
|
||||
const std::size_t localOffset = offset % PAGE_SIZE;
|
||||
std::uint8_t* result = &(*pages[page])[localOffset];
|
||||
offset += bytes;
|
||||
assert(reinterpret_cast<std::uintptr_t>(result) % alignment == 0);
|
||||
|
1208
source/function_ids.cpp
Normal file
1208
source/function_ids.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -139,6 +139,12 @@ PFN_vkVoidFunction getLayerFunctionPtr(const char* pName)
|
||||
else if (std::strcmp(pName, "vkGetRecordListItemsMWN") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(&vkGetRecordListItemsMWN);
|
||||
}
|
||||
else if (std::strcmp(pName, "vkResetRecordListMWN") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(&vkResetRecordListMWN);
|
||||
}
|
||||
else if (std::strcmp(pName, "vkGetFunctionNameMWN") == 0) {
|
||||
return reinterpret_cast<PFN_vkVoidFunction>(&vkGetFunctionNameMWN);
|
||||
}
|
||||
else {
|
||||
return getWrappedFunctionPtr(pName);
|
||||
}
|
||||
|
@ -79,6 +79,17 @@ VkResult vkGetRecordListItemsMWN(VkDevice /* device */, VkRecordListMWN recordLi
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult vkResetRecordListMWN(VkDevice /* device */, VkRecordListMWN recordList)
|
||||
{
|
||||
assert(recordList);
|
||||
|
||||
recordList->items.clear();
|
||||
recordList->values.reset();
|
||||
recordList->data.reset();
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkVariantMWN* allocVariant(std::size_t num)
|
||||
{
|
||||
assert(g_activeRecordList);
|
||||
|
@ -47,11 +47,12 @@ void vkFreeRecordListMWN(VkDevice device, VkRecordListMWN recordList);
|
||||
VkResult vkBeginRecordingMWN(VkDevice device, const VkRecordInfoMWN* pRecordInfo);
|
||||
void vkEndRecordingMWN(VkDevice device);
|
||||
VkResult vkGetRecordListItemsMWN(VkDevice device, VkRecordListMWN recordList, uint32_t* pItemCount, VkRecordListItemMWN** pItems);
|
||||
VkResult vkResetRecordListMWN(VkDevice device, VkRecordListMWN recordList);
|
||||
VkResult vkGetFunctionNameMWN(VkDevice device, VkFunctionMWN function, const char** pName);
|
||||
|
||||
template<typename TResult, typename... TArgs>
|
||||
void recordFunction(VkFunctionMWN function, const TResult& result, const TArgs&... args)
|
||||
{
|
||||
(void) result;
|
||||
if (!g_activeRecordList) {
|
||||
return;
|
||||
}
|
||||
|
@ -34,14 +34,16 @@ VkVariantMWN* VariantPool::allocate(std::size_t num)
|
||||
{
|
||||
assert(num > 0 && num <= PAGE_SIZE);
|
||||
const std::size_t remainingOnPage = PAGE_SIZE - (nextIndex % PAGE_SIZE);
|
||||
const std::size_t page = nextIndex / PAGE_SIZE;
|
||||
const std::size_t localIndex = nextIndex % PAGE_SIZE;
|
||||
if (remainingOnPage == PAGE_SIZE || remainingOnPage < num)
|
||||
{
|
||||
// next page
|
||||
pages.push_back(std::make_unique<page_t>());
|
||||
if (page + 1 >= pages.size()) {
|
||||
pages.push_back(std::make_unique<page_t>());
|
||||
}
|
||||
nextIndex = PAGE_SIZE * (pages.size() - 1);
|
||||
}
|
||||
const std::size_t page = nextIndex / PAGE_SIZE;
|
||||
const std::size_t localIndex = nextIndex % PAGE_SIZE;
|
||||
VkVariantMWN* result = &(*pages[page])[localIndex];
|
||||
nextIndex += num;
|
||||
return result;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common.hpp"
|
||||
@ -110,6 +111,16 @@ inline void variantWrap(const void* value, VkVariantMWN& outVariant)
|
||||
outVariant.voidPointerValue = value;
|
||||
}
|
||||
|
||||
inline void variantWrap(const char* value, VkVariantMWN& outVariant)
|
||||
{
|
||||
const std::size_t len = std::strlen(value);
|
||||
outVariant.type = VK_VARIANT_TYPE_STRING_MWN;
|
||||
|
||||
char* copy = allocType<char>(len + 1);
|
||||
std::memcpy(copy, value, len + 1);
|
||||
outVariant.stringValue = copy;
|
||||
}
|
||||
|
||||
template<typename TPointed>
|
||||
inline void variantWrap(const TPointed* value, VkVariantMWN& outVariant);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user