Repository navigation
Update acceleration structure range info parsing - #4
Conversation
Avoids truncation of acceleration structure build's range info double pointer array by using a special length helper to know how to walk the inner loop of the array structure. Does involve a schema change which will need to be handled by integrating clients.
wpaul-samsung
left a comment
There was a problem hiding this comment.
Thanks, this fixes the truncation of ppBuildRangeInfos. I left some inline comments. 1–3 are correctness issues: (1) ppMaxPrimitiveCounts in vkCmdBuildAccelerationStructuresIndirectKHR has the same problem, (2) a non-null pointer is dumped as NULL when geometryCount == 0, and (3) the fallback length of 1 when pInfos is null. The rest are optional cleanups.
| # (it only gives the length of the outer array). Maps command -> parameter -> C++ expression for the length of inner | ||
| # array 'i'. These are dumped with dump_double_pointer_array_variable_length instead of dump_double_pointer_array, | ||
| # which would only dump the first element each pointer refers to. | ||
| SPECIAL_INNER_LENGTH = { |
There was a problem hiding this comment.
vkCmdBuildAccelerationStructuresIndirectKHR::ppMaxPrimitiveCounts has the same layout: ppMaxPrimitiveCounts[i] points to pInfos[i].geometryCount uint32_t values. It isn't in this table, so the generated code (api_dump_implementation.h:70368) still uses dump_pointer_array with dump_type<Format, const uint32_t*>. That prints only infoCount pointer addresses and none of the counts, so the indirect build path keeps the truncation.
Note: the element type is uint32_t, not a Vulkan-defined struct. The new branch would need to pass something like dump_type<Format, uint32_t> as the element dumper instead of the pointer-typed one.
| } | ||
| dump_array_start<Format>(array, len, settings, type_string, name, indents); | ||
| for (size_t i = 0; i < len; ++i) { | ||
| const ArrayElementName<Format> indexName(name, i); |
There was a problem hiding this comment.
When inner_length(i) is 0, dump_pointer_array falls through to dump_nullptr. A non-null ppBuildRangeInfos[i] is then printed as NULL and its real address is lost. The old dump_double_pointer_array printed the address. Someone debugging a bad range-info pointer would be told it was null when it wasn't. Could we print the pointer address (as an empty array) when array[i] != nullptr and the length is 0?
| SPECIAL_INNER_LENGTH = { | ||
| 'vkCmdBuildAccelerationStructuresKHR': { | ||
| # ppBuildRangeInfos[i] points to pInfos[i].geometryCount VkAccelerationStructureBuildRangeInfoKHR | ||
| 'ppBuildRangeInfos': 'pInfos ? pInfos[i].geometryCount : 1', |
There was a problem hiding this comment.
When pInfos is null, : 1 makes up an inner length. The layer then dereferences ppBuildRangeInfos[i][0] and prints it as valid data, even though the real length is unknown and the pointer may be invalid. Using 0 (or only dumping the outer addresses) would avoid reading possibly-invalid memory and show that the data is unknown.
| // dump_double_pointer_array (one struct per pointer), each element is dumped as an array of its own: | ||
| // [i] -> { "type": element_type, "name": "[i]", "address": ..., "elements": [ ... inner_length(i) structs ... ] } | ||
| // A null inner pointer, or an inner length of zero, is dumped as a null pointer. | ||
| template <ApiDumpFormat Format, typename T, typename InnerLength, typename DumpElement> |
There was a problem hiding this comment.
Nit: this copies the whole body of dump_double_pointer_array (null check, array start/end, index-name loop, JSON element end) and changes only the per-element call. A shared outer-loop helper that takes a per-element callback would keep the two from drifting apart if the JSON comma or indentation handling changes later.
| else: | ||
| array_len = get_array_length(var, parent) | ||
| if var.fullType.count('*') > 1 and var.type not in ['void', 'char'] and (call_type in self.vulkan_defined_types): | ||
| if parent.name in SPECIAL_INNER_LENGTH and var.name in SPECIAL_INNER_LENGTH[parent.name]: |
There was a problem hiding this comment.
Nit: this is a hard-coded per-command special case. Each new nested-length parameter (ppMaxPrimitiveCounts already, plus any future aliases or promotions of these commands) needs a manual entry under every command name, and a missed one silently falls back to the truncated dump. Could we key it by parameter name or element type, or combine it with SPECIAL_LENGTH, so it scales better?
| 'ppBuildRangeInfos': 'pInfos ? pInfos[i].geometryCount : 1', | ||
| }, | ||
| 'vkBuildAccelerationStructuresKHR': { | ||
| 'ppBuildRangeInfos': 'pInfos ? pInfos[i].geometryCount : 1', |
There was a problem hiding this comment.
Nit: the same expression string appears for both commands. A shared constant would stop it from drifting. Also, the generated lambda already returns size_t, so the static_cast<size_t>(inner_length(i)) in dump_double_pointer_array_variable_length does nothing.
Avoids truncation of acceleration structure build's range info double pointer array by using a special length helper to know how to walk the inner loop of the array structure.
Does involve a schema change which will need to be handled by integrating clients.
Related to https://github.com/sarc-acl/sokatoa-internal/issues/6698