Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VDR: Fix vertex offset in indirect draw calls #1984

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions framework/decode/vulkan_replay_dump_resources_draw_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,13 +1494,19 @@ VkResult DrawCallsDumpingContext::DumpVertexIndexBuffers(uint64_t qs_index, uint
// Dump index buffer
if (IsDrawCallIndexed(dc_params.type) && dc_params.referenced_index_buffer.buffer_info != nullptr)
{
// Store all (indexCount, firstIndex) pairs used by all draw calls (in case of indirect)
// associated with this index buffer. Then we will parse the index buffer using all these pairs in order to
// detect the greatest index.
std::vector<std::pair<uint32_t, uint32_t>> index_count_first_index_pairs;
struct DrawIndexedParams
{
uint32_t index_count;
uint32_t first_index;
int32_t vertex_offset;
};

uint32_t abs_index_count = 0;
int32_t greatest_vertex_offset = 0;
// Store all indexCount, firstIndex and vertexOffset used by all draw calls (in case of indirect)
// associated with this index buffer. Then we will parse the index buffer using all these pairs
// in order to detect the greatest index which should help calculate the size of the vertex buffer
// actually used by the draw calls.
std::vector<DrawIndexedParams> indexed_params;
uint32_t abs_index_count = 0;

if (IsDrawCallIndirect(dc_params.type))
{
Expand All @@ -1517,18 +1523,14 @@ VkResult DrawCallsDumpingContext::DumpVertexIndexBuffers(uint64_t qs_index, uint
const uint32_t indirect_index_count = ic_params.draw_indexed_params[d].indexCount;
const uint32_t indirect_first_index = ic_params.draw_indexed_params[d].firstIndex;

index_count_first_index_pairs.emplace_back(
std::make_pair(indirect_index_count, indirect_first_index));

if (abs_index_count < indirect_index_count + indirect_first_index)
{
abs_index_count = indirect_index_count + indirect_first_index;
}

if (greatest_vertex_offset < ic_params.draw_indexed_params[d].vertexOffset)
{
greatest_vertex_offset = ic_params.draw_indexed_params[d].vertexOffset;
}
indexed_params.emplace_back(DrawIndexedParams{ indirect_index_count,
indirect_first_index,
ic_params.draw_indexed_params[d].vertexOffset });
}
}
}
Expand All @@ -1545,18 +1547,13 @@ VkResult DrawCallsDumpingContext::DumpVertexIndexBuffers(uint64_t qs_index, uint
const uint32_t indirect_index_count = i_params.draw_indexed_params[d].indexCount;
const uint32_t indirect_first_index = i_params.draw_indexed_params[d].firstIndex;

index_count_first_index_pairs.emplace_back(
std::make_pair(indirect_index_count, indirect_first_index));

if (abs_index_count < indirect_index_count + indirect_first_index)
{
abs_index_count = indirect_index_count + indirect_first_index;
}

if (greatest_vertex_offset < i_params.draw_indexed_params[d].vertexOffset)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the vertex offset not be stored along in index_count_first_index_pairs (well, not as pair, but as struct or tuple)?
Would be much shorter and not need this min/max computation and be more precise.

{
greatest_vertex_offset = i_params.draw_indexed_params[d].vertexOffset;
}
indexed_params.emplace_back(DrawIndexedParams{
indirect_index_count, indirect_first_index, i_params.draw_indexed_params[d].vertexOffset });
}
}
}
Expand All @@ -1565,10 +1562,10 @@ VkResult DrawCallsDumpingContext::DumpVertexIndexBuffers(uint64_t qs_index, uint
{
const uint32_t index_count = dc_params.dc_params_union.draw_indexed.indexCount;
const uint32_t first_index = dc_params.dc_params_union.draw_indexed.firstIndex;
abs_index_count = index_count + first_index;

index_count_first_index_pairs.emplace_back(std::make_pair(index_count, first_index));
abs_index_count = index_count + first_index;
greatest_vertex_offset = dc_params.dc_params_union.draw_indexed.vertexOffset;
indexed_params.emplace_back(
DrawIndexedParams{ index_count, first_index, dc_params.dc_params_union.draw_indexed.vertexOffset });
}

if (abs_index_count)
Expand Down Expand Up @@ -1614,10 +1611,10 @@ VkResult DrawCallsDumpingContext::DumpVertexIndexBuffers(uint64_t qs_index, uint
}

// Parse all indices in order to find the smallest and greatest index
for (const auto& pairs : index_count_first_index_pairs)
for (const auto& params : indexed_params)
{
const std::pair<uint32_t, uint32_t> min_max_indices = FindMinMaxVertexIndices(
res_info.data, pairs.first, pairs.second, greatest_vertex_offset, index_type);
res_info.data, params.index_count, params.first_index, params.vertex_offset, index_type);
if (min_max_indices.first < min_max_vertex_indices.first)
{
min_max_vertex_indices.first = min_max_indices.first;
Expand Down