rsx: Handle non-zero base vertex better

- Vertex buffer contents treat the base vertex as vertex 0 so we do the same for indices

rsx: Fix vertex base indexing

rsx: Properly fix non-zero offset indexed rendering
This commit is contained in:
kd-11 2017-06-16 16:03:12 +03:00
parent 5c6cf77c57
commit 11317acdbe
2 changed files with 21 additions and 19 deletions

View File

@ -465,6 +465,7 @@ std::tuple<T, T> upload_untouched(gsl::span<to_be_t<const T>> src, gsl::span<T>
max_index = std::max(max_index, index);
min_index = std::min(min_index, index);
}
dst[dst_idx++] = index;
}
return std::make_tuple(min_index, max_index);
@ -661,7 +662,7 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
case rsx::primitive_type::polygon:
for (unsigned i = 0; i < (count - 2); i++)
{
typedDst[3 * i] = first;
typedDst[3 * i] = 0;
typedDst[3 * i + 1] = i + 2 - 1;
typedDst[3 * i + 2] = i + 2;
}
@ -670,26 +671,26 @@ void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst,
for (unsigned i = 0; i < count / 4; i++)
{
// First triangle
typedDst[6 * i] = 4 * i + first;
typedDst[6 * i + 1] = 4 * i + 1 + first;
typedDst[6 * i + 2] = 4 * i + 2 + first;
typedDst[6 * i] = 4 * i;
typedDst[6 * i + 1] = 4 * i + 1;
typedDst[6 * i + 2] = 4 * i + 2;
// Second triangle
typedDst[6 * i + 3] = 4 * i + 2 + first;
typedDst[6 * i + 4] = 4 * i + 3 + first;
typedDst[6 * i + 5] = 4 * i + first;
typedDst[6 * i + 3] = 4 * i + 2;
typedDst[6 * i + 4] = 4 * i + 3;
typedDst[6 * i + 5] = 4 * i;
}
return;
case rsx::primitive_type::quad_strip:
for (unsigned i = 0; i < (count - 2) / 2; i++)
{
// First triangle
typedDst[6 * i] = 2 * i + first;
typedDst[6 * i + 1] = 2 * i + 1 + first;
typedDst[6 * i + 2] = 2 * i + 2 + first;
typedDst[6 * i] = 2 * i;
typedDst[6 * i + 1] = 2 * i + 1;
typedDst[6 * i + 2] = 2 * i + 2;
// Second triangle
typedDst[6 * i + 3] = 2 * i + 2 + first;
typedDst[6 * i + 4] = 2 * i + 1 + first;
typedDst[6 * i + 5] = 2 * i + 3 + first;
typedDst[6 * i + 3] = 2 * i + 2;
typedDst[6 * i + 4] = 2 * i + 1;
typedDst[6 * i + 5] = 2 * i + 3;
}
return;
case rsx::primitive_type::points:
@ -726,21 +727,21 @@ namespace
u32 count;
std::tie(first, count) = get_first_count_from_draw_indexed_clause(first_count_arguments);
if (!expands(draw_mode)) return upload_untouched<T>(src.subspan(first), dst, restart_index_enabled, restart_index);
if (!expands(draw_mode)) return upload_untouched<T>(src, dst, restart_index_enabled, restart_index);
switch (draw_mode)
{
case rsx::primitive_type::line_loop:
{
const auto &returnvalue = upload_untouched<T>(src.subspan(first), dst, restart_index_enabled, restart_index);
dst[count] = src[first];
const auto &returnvalue = upload_untouched<T>(src, dst, restart_index_enabled, restart_index);
dst[count] = src[0];
return returnvalue;
}
case rsx::primitive_type::polygon:
case rsx::primitive_type::triangle_fan:
return expand_indexed_triangle_fan<T>(src.subspan(first), dst, restart_index_enabled, restart_index);
return expand_indexed_triangle_fan<T>(src, dst, restart_index_enabled, restart_index);
case rsx::primitive_type::quads:
return expand_indexed_quads<T>(src.subspan(first), dst, restart_index_enabled, restart_index);
return expand_indexed_quads<T>(src, dst, restart_index_enabled, restart_index);
}
fmt::throw_exception("Unknown draw mode (0x%x)" HERE, (u32)draw_mode);
}

View File

@ -673,8 +673,9 @@ namespace rsx
}
u32 first = std::get<0>(draw_indexed_clause.front());
u32 count = std::get<0>(draw_indexed_clause.back()) + std::get<1>(draw_indexed_clause.back()) - first;
const gsl::byte* ptr = static_cast<const gsl::byte*>(vm::base(address));
return{ ptr, count * type_size };
return{ ptr + first * type_size, count * type_size };
}
gsl::span<const gsl::byte> thread::get_raw_vertex_buffer(const rsx::data_array_format_info& vertex_array_info, u32 base_offset, const std::vector<std::pair<u32, u32>>& vertex_ranges) const