Skip to content

Commit

Permalink
toCpp: Support 32-bit size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
locke-lunarg committed Mar 8, 2024
1 parent 52fb604 commit f6acabb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
18 changes: 11 additions & 7 deletions framework/decode/vulkan_cpp_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ void VulkanCppConsumerBase::PrintOutGlobalVar()
}

fprintf(global_file,
"VkMemoryType originalMemoryTypes[%" PRId64 "][%" PRId64 "] = {\n",
original_memory_types_.size(),
max_second_dimension);
"VkMemoryType originalMemoryTypes[%" PRIu64 "][%" PRIu64 "] = {\n",
util::platform::SizeTtoUint64(original_memory_types_.size()),
util::platform::SizeTtoUint64(max_second_dimension));
for (const auto& pd_mem_types : original_memory_types_)
{
fprintf(global_file, " {\n");
Expand Down Expand Up @@ -1272,7 +1272,8 @@ void VulkanCppConsumerBase::Generate_vkGetQueryPoolResults(VkResult
frame_split_temp_memory_.push_back(temp_memory);
temp_memory_name = temp_memory.name;

fprintf(file, "\tuint8_t %s[%" PRId64 "];\n", temp_memory_name.c_str(), dataSize);
fprintf(
file, "\tuint8_t %s[%" PRIu64 "];\n", temp_memory_name.c_str(), util::platform::SizeTtoUint64(dataSize));
}

if (returnValue == VK_SUCCESS)
Expand All @@ -1284,7 +1285,7 @@ void VulkanCppConsumerBase::Generate_vkGetQueryPoolResults(VkResult
GetHandle(queryPool).c_str(),
firstQuery,
queryCount,
dataSize,
util::platform::SizeTtoUint64(dataSize),
temp_memory_name.c_str(),
stride,
util::ToString<VkQueryResultFlags>(flags).c_str());
Expand All @@ -1297,7 +1298,7 @@ void VulkanCppConsumerBase::Generate_vkGetQueryPoolResults(VkResult
GetHandle(queryPool).c_str(),
firstQuery,
queryCount,
dataSize,
util::platform::SizeTtoUint64(dataSize),
temp_memory_name.c_str(),
stride,
util::ToString<VkQueryResultFlags>(flags).c_str(),
Expand Down Expand Up @@ -3291,7 +3292,10 @@ void VulkanCppConsumerBase::ProcessCreateHardwareBufferCommand(
}
else
{
fprintf(file, "\t\t\t%s.plane_info.resize(%" PRId64 ");\n", memory_info.name.c_str(), plane_info.size());
fprintf(file,
"\t\t\t%s.plane_info.resize(%" PRIu64 ");\n",
memory_info.name.c_str(),
util::platform::SizeTtoUint64(plane_info.size()));
fprintf(file, "\n");
for (uint32_t i = 0; i < static_cast<uint32_t>(plane_info.size()); ++i)
{
Expand Down
60 changes: 30 additions & 30 deletions framework/generated/generated_vulkan_cpp_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6125,11 +6125,11 @@ void VulkanCppConsumer::Process_vkGetPhysicalDeviceXlibPresentationSupportKHR(
// visualID
pfn_loader_.AddMethodName("vkGetPhysicalDeviceXlibPresentationSupportKHR");
fprintf(file,
"\t\tloaded_vkGetPhysicalDeviceXlibPresentationSupportKHR(%s, %u, %s, %" PRId64 ");\n",
"\t\tloaded_vkGetPhysicalDeviceXlibPresentationSupportKHR(%s, %u, %s, %" PRIu64 ");\n",
this->GetHandle(physicalDevice).c_str(),
queueFamilyIndex,
dpy_name.c_str(),
visualID);
util::platform::SizeTtoUint64(visualID));
fprintf(file, "\t}\n");
Post_APICall(format::ApiCallId::ApiCall_vkGetPhysicalDeviceXlibPresentationSupportKHR);
}
Expand Down Expand Up @@ -8809,7 +8809,7 @@ void VulkanCppConsumer::Process_vkGetEncodedVideoSessionParametersKHR(
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
size_t* in_pdata_size = pDataSize->GetPointer();
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), *in_pdata_size);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(*in_pdata_size));
pfn_loader_.AddMethodName("vkGetEncodedVideoSessionParametersKHR");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetEncodedVideoSessionParametersKHR(%s, &%s, &%s, &%s, %s), %s);\n",
Expand Down Expand Up @@ -9796,12 +9796,12 @@ void VulkanCppConsumer::Process_vkDebugReportMessageEXT(
// pMessage
pfn_loader_.AddMethodName("vkDebugReportMessageEXT");
fprintf(file,
"\t\tloaded_vkDebugReportMessageEXT(%s, %s, %s, %" PRIu64 "UL, %" PRId64 ", %d, %p, %p);\n",
"\t\tloaded_vkDebugReportMessageEXT(%s, %s, %s, %" PRIu64 "UL, %" PRIu64 ", %d, %p, %p);\n",
this->GetHandle(instance).c_str(),
util::ToString<VkDebugReportFlagsEXT>(flags).c_str(),
util::ToString<VkDebugReportObjectTypeEXT>(objectType).c_str(),
object,
location,
util::platform::SizeTtoUint64(location),
messageCode,
pLayerPrefix->GetPointer(),
pMessage->GetPointer());
Expand Down Expand Up @@ -10292,7 +10292,7 @@ void VulkanCppConsumer::Process_vkGetShaderInfoAMD(
// pInfo
std::string pinfo_name = "pInfo_" + std::to_string(this->GetNextId());
size_t* in_pinfo_size = pInfoSize->GetPointer();
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pinfo_name.c_str(), *in_pinfo_size);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pinfo_name.c_str(), util::platform::SizeTtoUint64(*in_pinfo_size));
pfn_loader_.AddMethodName("vkGetShaderInfoAMD");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetShaderInfoAMD(%s, %s, %s, %s, &%s, %s), %s);\n",
Expand Down Expand Up @@ -10591,10 +10591,10 @@ void VulkanCppConsumer::Process_vkGetRandROutputDisplayEXT(
}
pfn_loader_.AddMethodName("vkGetRandROutputDisplayEXT");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetRandROutputDisplayEXT(%s, %s, %" PRId64 ", &%s), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkGetRandROutputDisplayEXT(%s, %s, %" PRIu64 ", &%s), %s);\n",
this->GetHandle(physicalDevice).c_str(),
dpy_name.c_str(),
rrOutput,
util::platform::SizeTtoUint64(rrOutput),
pdisplay_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Expand Down Expand Up @@ -11430,7 +11430,7 @@ void VulkanCppConsumer::Process_vkGetValidationCacheDataEXT(
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
size_t* in_pdata_size = pDataSize->GetPointer();
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), *in_pdata_size);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(*in_pdata_size));
pfn_loader_.AddMethodName("vkGetValidationCacheDataEXT");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetValidationCacheDataEXT(%s, %s, &%s, %s), %s);\n",
Expand Down Expand Up @@ -11796,13 +11796,13 @@ void VulkanCppConsumer::Process_vkGetAccelerationStructureHandleNV(
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
pfn_loader_.AddMethodName("vkGetAccelerationStructureHandleNV");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetAccelerationStructureHandleNV(%s, %s, %" PRId64 ", %s), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkGetAccelerationStructureHandleNV(%s, %s, %" PRIu64 ", %s), %s);\n",
this->GetHandle(device).c_str(),
this->GetHandle(accelerationStructure).c_str(),
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Expand Down Expand Up @@ -11857,15 +11857,15 @@ void VulkanCppConsumer::Process_vkGetRayTracingShaderGroupHandlesKHR(
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
pfn_loader_.AddMethodName("vkGetRayTracingShaderGroupHandlesKHR");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingShaderGroupHandlesKHR(%s, %s, %u, %u, %" PRId64 ", %s), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingShaderGroupHandlesKHR(%s, %s, %u, %u, %" PRIu64 ", %s), %s);\n",
this->GetHandle(device).c_str(),
this->GetHandle(pipeline).c_str(),
firstGroup,
groupCount,
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Expand All @@ -11891,15 +11891,15 @@ void VulkanCppConsumer::Process_vkGetRayTracingShaderGroupHandlesNV(
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
pfn_loader_.AddMethodName("vkGetRayTracingShaderGroupHandlesNV");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingShaderGroupHandlesNV(%s, %s, %u, %u, %" PRId64 ", %s), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingShaderGroupHandlesNV(%s, %s, %u, %u, %" PRIu64 ", %s), %s);\n",
this->GetHandle(device).c_str(),
this->GetHandle(pipeline).c_str(),
firstGroup,
groupCount,
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Expand Down Expand Up @@ -14799,18 +14799,18 @@ void VulkanCppConsumer::Process_vkWriteMicromapsPropertiesEXT(
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
// stride
pfn_loader_.AddMethodName("vkWriteMicromapsPropertiesEXT");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkWriteMicromapsPropertiesEXT(%s, %u, %s, %s, %" PRId64 ", %s, %" PRId64 "), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkWriteMicromapsPropertiesEXT(%s, %u, %s, %s, %" PRIu64 ", %s, %" PRIu64 "), %s);\n",
this->GetHandle(device).c_str(),
micromapCount,
pmicromaps_array.c_str(),
util::ToString<VkQueryType>(queryType).c_str(),
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
stride,
util::platform::SizeTtoUint64(stride),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Post_APICall(format::ApiCallId::ApiCall_vkWriteMicromapsPropertiesEXT);
Expand Down Expand Up @@ -16048,7 +16048,7 @@ void VulkanCppConsumer::Process_vkGetShaderBinaryDataEXT(
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
size_t* in_pdata_size = pDataSize->GetPointer();
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), *in_pdata_size);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(*in_pdata_size));
pfn_loader_.AddMethodName("vkGetShaderBinaryDataEXT");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetShaderBinaryDataEXT(%s, %s, &%s, %s), %s);\n",
Expand Down Expand Up @@ -16644,18 +16644,18 @@ void VulkanCppConsumer::Process_vkWriteAccelerationStructuresPropertiesKHR(
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
// stride
pfn_loader_.AddMethodName("vkWriteAccelerationStructuresPropertiesKHR");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkWriteAccelerationStructuresPropertiesKHR(%s, %u, %s, %s, %" PRId64 ", %s, %" PRId64 "), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkWriteAccelerationStructuresPropertiesKHR(%s, %u, %s, %s, %" PRIu64 ", %s, %" PRIu64 "), %s);\n",
this->GetHandle(device).c_str(),
accelerationStructureCount,
pacceleration_structures_array.c_str(),
util::ToString<VkQueryType>(queryType).c_str(),
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
stride,
util::platform::SizeTtoUint64(stride),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Post_APICall(format::ApiCallId::ApiCall_vkWriteAccelerationStructuresPropertiesKHR);
Expand Down Expand Up @@ -16811,15 +16811,15 @@ void VulkanCppConsumer::Process_vkGetRayTracingCaptureReplayShaderGroupHandlesKH
// dataSize
// pData
std::string pdata_name = "pData_" + std::to_string(this->GetNextId());
fprintf(file, "\t\tuint8_t %s[%" PRId64 "];\n", pdata_name.c_str(), dataSize);
fprintf(file, "\t\tuint8_t %s[%" PRIu64 "];\n", pdata_name.c_str(), util::platform::SizeTtoUint64(dataSize));
pfn_loader_.AddMethodName("vkGetRayTracingCaptureReplayShaderGroupHandlesKHR");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingCaptureReplayShaderGroupHandlesKHR(%s, %s, %u, %u, %" PRId64 ", %s), %s);\n",
"\t\tVK_CALL_CHECK(loaded_vkGetRayTracingCaptureReplayShaderGroupHandlesKHR(%s, %s, %u, %u, %" PRIu64 ", %s), %s);\n",
this->GetHandle(device).c_str(),
this->GetHandle(pipeline).c_str(),
firstGroup,
groupCount,
dataSize,
util::platform::SizeTtoUint64(dataSize),
pdata_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def makeConsumerFuncBody(self, returnType, name, values):
'int': '%d',
'int32_t': '%d',
'uint32_t': '%u',
'size_t': '%" PRId64 "',
'size_t': '%" PRIu64 "',
'int64_t': '%" PRId64 "',
'uint64_t': '%" PRIu64 "',
'float': '%f',
Expand Down Expand Up @@ -913,19 +913,23 @@ def makeConsumerFuncBody(self, returnType, name, values):
callTempl.append('%s')
arrayValue = f', {arg.array_length}'
if arg.array_length_value.base_type == 'size_t':
arrayInfo = '[%" PRId64 "]'
arrayInfo = '[%" PRIu64 "]'
else:
arrayInfo = '[%d]'

if arg.array_length_value.is_pointer:
arrayLenVarName = makeSnakeCaseName(f'in_{arg.array_length_value.name}')
if arg.array_length_value.base_type != 'size_t':
body += makeGen(f'const uint32_t* {arrayLenVarName} = {arg.array_length_value.name}->GetPointer();',locals(), indent=4)
arrayValue = f', *{arrayLenVarName}'
else:
body += makeGen(f'size_t* {arrayLenVarName} = {arg.array_length_value.name}->GetPointer();',locals(), indent=4)
arrayValue = f', *{arrayLenVarName}'
arrayValue = f', util::platform::SizeTtoUint64(*{arrayLenVarName})'
else:
arrayValue = f', {arg.array_length_value.name}'
if arg.array_length_value.base_type == 'size_t':
arrayValue = f', util::platform::SizeTtoUint64({arg.array_length_value.name})'
else:
arrayValue = f', {arg.array_length_value.name}'

else:
callTempl.append('&%s')
Expand Down Expand Up @@ -1023,8 +1027,10 @@ def makeConsumerFuncBody(self, returnType, name, values):
# simple input argument (float, etc..)
valueSuffix = valueSuffixDict.get(arg.base_type, '')
valueFormat = valueFormatDict[arg.base_type]

callArgs.append(f'{arg.name}')
if arg.base_type == "size_t":
callArgs.append(f'util::platform::SizeTtoUint64({arg.name})')
else:
callArgs.append(f'{arg.name}')
callTempl.append(valueFormat + valueSuffix)

# Build the vk* function call with arguments
Expand Down
9 changes: 9 additions & 0 deletions framework/util/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ inline T AlignValue(T original)
return (original + (alignment_t - 1)) & ~(alignment_t - 1);
}

inline uint64_t SizeTtoUint64(size_t value)
{
#if defined(_WIN64)
return value;
#else
return static_cast<uint64_t>(value);
#endif
}

GFXRECON_END_NAMESPACE(platform)
GFXRECON_END_NAMESPACE(util)
GFXRECON_END_NAMESPACE(gfxrecon)
Expand Down

0 comments on commit f6acabb

Please sign in to comment.