safestruct: Accessors for non trivial globals

Adding Tracy in VVL showed that we are paying the price of initializing
global variables upon shared library entry, even if we do not
end up accessing those.
Adding accessors will make sure we pay this price
only when truly needed.
Also making the necessary changes in VVL.
This commit is contained in:
Arno 2024-07-17 16:02:41 +02:00 committed by Charles Giessen
parent 5f26cf65a1
commit 9479047902
5 changed files with 44 additions and 36 deletions

View file

@ -159,6 +159,10 @@ class SafeStructOutputGenerator(BaseGenerator):
#include <vulkan/utility/vk_safe_struct_utils.hpp>
namespace vku {
// Mapping of unknown stype codes to structure lengths. This should be set up by the application
// before vkCreateInstance() and not modified afterwards.
std::vector<std::pair<uint32_t, uint32_t>>& GetCustomStypeInfo();
\n''')
guard_helper = PlatformGuardHelper()
@ -251,8 +255,6 @@ class SafeStructOutputGenerator(BaseGenerator):
#include <vector>
#include <cstring>
extern std::vector<std::pair<uint32_t, uint32_t>> custom_stype_info;
namespace vku {
char *SafeStringCopy(const char *in_string) {
if (nullptr == in_string) return nullptr;
@ -305,7 +307,7 @@ void *SafePnextCopy(const void *pNext, PNextCopyState* copy_state) {
out.append('''
default: // Encountered an unknown sType -- skip (do not copy) this entry in the chain
// If sType is in custom list, construct blind copy
for (auto item : custom_stype_info) {
for (auto item : GetCustomStypeInfo()) {
if (item.first == static_cast<uint32_t>(header->sType)) {
safe_pNext = malloc(item.second);
memcpy(safe_pNext, header, item.second);
@ -361,7 +363,7 @@ void FreePnextChain(const void *pNext) {
out.append('''
default: // Encountered an unknown sType
// If sType is in custom list, free custom struct memory and clean up
for (auto item : custom_stype_info) {
for (auto item : GetCustomStypeInfo() ) {
if (item.first == static_cast<uint32_t>(header->sType)) {
free(current);
break;