Skip to content

Commit

Permalink
Convert: Handling for non-void non-VkResult return (#913)
Browse files Browse the repository at this point in the history
Fixes Issue #912 and handles some other types noticed while
investigating that.
  • Loading branch information
andrew-lunarg authored Dec 8, 2022
1 parent 1741d0a commit 205a185
Show file tree
Hide file tree
Showing 4 changed files with 872 additions and 3,619 deletions.
44 changes: 38 additions & 6 deletions framework/decode/vulkan_ascii_consumer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class VulkanAsciiConsumerBase : public VulkanConsumer, public AnnotationHandler
DescriptorUpdateTemplateDecoder* pData) override;

protected:
/// @deprecated Prefer the shorter function signature without toStringFlags,
/// tabCount, tabSize in new code.
template <typename ToStringFunctionType>
inline void WriteApiCallToFile(const ApiCallInfo& call_info,
const std::string& functionName,
Expand All @@ -132,7 +134,9 @@ class VulkanAsciiConsumerBase : public VulkanConsumer, public AnnotationHandler
const uint32_t tabSize,
const ToStringFunctionType toStringFunction,
/// The formatted return string value excluding trailing comma
const std::string& return_val = std::string())
const std::string& return_val = std::string(),
// Set to false for bools and ints but leave true for enums, pointers, strings.
const bool quoteReturn = true)
{
// Output the start of a function call line, up to the arguments:
if (return_val.empty())
Expand All @@ -144,11 +148,24 @@ class VulkanAsciiConsumerBase : public VulkanConsumer, public AnnotationHandler
}
else
{
fprintf(file_,
"{\"index\":%llu,\"vkFunc\":{\"name\":\"%s\",\"return\":\"%s\",\"args\":{",
(long long unsigned int)call_info.index,
functionName.c_str(),
return_val.c_str());
if (quoteReturn == true)
{
fprintf(file_,
"{\"index\":%llu,\"vkFunc\":{\"name\":\"%s\",\"return\":\"%s\",\"args\":{",
(long long unsigned int)call_info.index,
functionName.c_str(),
return_val.c_str());
}
// Ugly to duplicate this but more efficient than adding conditionals above or
// having the caller quote with std::string manipulations.
else
{
fprintf(file_,
"{\"index\":%llu,\"vkFunc\":{\"name\":\"%s\",\"return\":%s,\"args\":{",
(long long unsigned int)call_info.index,
functionName.c_str(),
return_val.c_str());
}
}

// Reset the per-call reusable stringstream and use it to capture the full tree of
Expand All @@ -166,6 +183,21 @@ class VulkanAsciiConsumerBase : public VulkanConsumer, public AnnotationHandler
fflush(file_);
}

/// @brief Allow callers to be incrementally refactored away from the explicit
/// formatting using toStringFlags, tabCount, tabSize.
template <typename ToStringFunctionType>
inline void WriteApiCallToFile(const ApiCallInfo& call_info,
const std::string& functionName,
const ToStringFunctionType toStringFunction,
/// The formatted return string value excluding trailing comma
const std::string& return_val = std::string(),
// Set to false for bools and ints but leave true for enums, pointers, strings.
const bool quoteReturn = true)
{
WriteApiCallToFile(
call_info, functionName, util::kToString_Unformatted, 0, 0, toStringFunction, return_val, quoteReturn);
}

private:
/// File to write textual representation of capture out to.
/// @note This is passed to us in Initialize() and owned elsewhere.
Expand Down
Loading

0 comments on commit 205a185

Please sign in to comment.