From f6acabba9b8b0bd718d93d92f21847370348242f Mon Sep 17 00:00:00 2001 From: Locke Lin Date: Thu, 7 Mar 2024 23:46:33 -0700 Subject: [PATCH] toCpp: Support 32-bit size_t --- framework/decode/vulkan_cpp_consumer_base.cpp | 18 +++--- .../generated_vulkan_cpp_consumer.cpp | 60 +++++++++---------- .../vulkan_cpp_consumer_body_generator.py | 18 ++++-- framework/util/platform.h | 9 +++ 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/framework/decode/vulkan_cpp_consumer_base.cpp b/framework/decode/vulkan_cpp_consumer_base.cpp index d374271b3d..165161857e 100644 --- a/framework/decode/vulkan_cpp_consumer_base.cpp +++ b/framework/decode/vulkan_cpp_consumer_base.cpp @@ -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"); @@ -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) @@ -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(flags).c_str()); @@ -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(flags).c_str(), @@ -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(plane_info.size()); ++i) { diff --git a/framework/generated/generated_vulkan_cpp_consumer.cpp b/framework/generated/generated_vulkan_cpp_consumer.cpp index 0af9518480..71b38b475d 100644 --- a/framework/generated/generated_vulkan_cpp_consumer.cpp +++ b/framework/generated/generated_vulkan_cpp_consumer.cpp @@ -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); } @@ -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", @@ -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(flags).c_str(), util::ToString(objectType).c_str(), object, - location, + util::platform::SizeTtoUint64(location), messageCode, pLayerPrefix->GetPointer(), pMessage->GetPointer()); @@ -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", @@ -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(returnValue).c_str()); fprintf(file, "\t}\n"); @@ -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", @@ -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(returnValue).c_str()); fprintf(file, "\t}\n"); @@ -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(returnValue).c_str()); fprintf(file, "\t}\n"); @@ -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(returnValue).c_str()); fprintf(file, "\t}\n"); @@ -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(queryType).c_str(), - dataSize, + util::platform::SizeTtoUint64(dataSize), pdata_name.c_str(), - stride, + util::platform::SizeTtoUint64(stride), util::ToString(returnValue).c_str()); fprintf(file, "\t}\n"); Post_APICall(format::ApiCallId::ApiCall_vkWriteMicromapsPropertiesEXT); @@ -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", @@ -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(queryType).c_str(), - dataSize, + util::platform::SizeTtoUint64(dataSize), pdata_name.c_str(), - stride, + util::platform::SizeTtoUint64(stride), util::ToString(returnValue).c_str()); fprintf(file, "\t}\n"); Post_APICall(format::ApiCallId::ApiCall_vkWriteAccelerationStructuresPropertiesKHR); @@ -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(returnValue).c_str()); fprintf(file, "\t}\n"); diff --git a/framework/generated/vulkan_generators/vulkan_cpp_consumer_body_generator.py b/framework/generated/vulkan_generators/vulkan_cpp_consumer_body_generator.py index f5bd7819bd..0078105278 100644 --- a/framework/generated/vulkan_generators/vulkan_cpp_consumer_body_generator.py +++ b/framework/generated/vulkan_generators/vulkan_cpp_consumer_body_generator.py @@ -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', @@ -913,7 +913,7 @@ 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]' @@ -921,11 +921,15 @@ def makeConsumerFuncBody(self, returnType, name, values): 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') @@ -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 diff --git a/framework/util/platform.h b/framework/util/platform.h index 09c7ab2525..78b0c83fd2 100644 --- a/framework/util/platform.h +++ b/framework/util/platform.h @@ -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(value); +#endif +} + GFXRECON_END_NAMESPACE(platform) GFXRECON_END_NAMESPACE(util) GFXRECON_END_NAMESPACE(gfxrecon)