From 2ae5a7ff39c009e349e29d8610a314c628f77805 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 2 Apr 2016 20:07:12 +0200 Subject: [PATCH] rsx/common/d3d12/gl/vulkan: Use single overload for write_index_array_data_to_buffer. --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 16 +++++++++------- rpcs3/Emu/RSX/Common/BufferUtils.h | 4 ++-- rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp | 13 ++----------- rpcs3/Emu/RSX/GL/vertex_buffer.cpp | 11 ++--------- rpcs3/Emu/RSX/RSXThread.cpp | 7 +++---- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 4 ++-- 6 files changed, 20 insertions(+), 35 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index cce0c90075..8fc874fdae 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -391,14 +391,16 @@ std::tuple write_index_array_data_to_buffer_impl(gsl::span write_index_array_data_to_buffer(gsl::span dst, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments) +std::tuple write_index_array_data_to_buffer(gsl::span dst, rsx::index_array_type type, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments) { - return write_index_array_data_to_buffer_impl(dst, draw_mode, first_count_arguments); -} - -std::tuple write_index_array_data_to_buffer(gsl::span dst, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments) -{ - return write_index_array_data_to_buffer_impl(dst, draw_mode, first_count_arguments); + switch (type) + { + case rsx::index_array_type::u16: + return write_index_array_data_to_buffer_impl(as_span_workaround(dst), draw_mode, first_count_arguments); + case rsx::index_array_type::u32: + return write_index_array_data_to_buffer_impl(as_span_workaround(dst), draw_mode, first_count_arguments); + } + throw EXCEPTION("Unknow index type"); } std::tuple write_index_array_data_to_buffer_untouched(gsl::span dst, const std::vector > &first_count_arguments) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.h b/rpcs3/Emu/RSX/Common/BufferUtils.h index df0d0d18c2..e8605f5a85 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.h +++ b/rpcs3/Emu/RSX/Common/BufferUtils.h @@ -29,8 +29,8 @@ size_t get_index_type_size(rsx::index_array_type type); * Returns min/max index found during the process. * The function expands index buffer for non native primitive type. */ -std::tuple write_index_array_data_to_buffer(gsl::span dst, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments); -std::tuple write_index_array_data_to_buffer(gsl::span dst, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments); +std::tuple write_index_array_data_to_buffer(gsl::span dst, rsx::index_array_type, rsx::primitive_type draw_mode, const std::vector > &first_count_arguments); + /** * Doesn't expand index diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp index 05e635fbb3..480a795672 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp @@ -364,18 +364,9 @@ std::tuple> D3D12GSRe void *mapped_buffer = m_buffer_data.map(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); u32 min_index, max_index; + gsl::span dst{ reinterpret_cast(mapped_buffer), gsl::narrow(buffer_size) }; - if (indexed_type == rsx::index_array_type::u16) - { - gsl::span dst = { (u16*)mapped_buffer, gsl::narrow(buffer_size / index_size) }; - std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); - } - - if (indexed_type == rsx::index_array_type::u32) - { - gsl::span dst = { (u32*)mapped_buffer, gsl::narrow(buffer_size / index_size) }; - std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); - } + std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, indexed_type, draw_mode, first_count_commands); m_buffer_data.unmap(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); D3D12_INDEX_BUFFER_VIEW index_buffer_view = { diff --git a/rpcs3/Emu/RSX/GL/vertex_buffer.cpp b/rpcs3/Emu/RSX/GL/vertex_buffer.cpp index 2ee749981e..af0c979558 100644 --- a/rpcs3/Emu/RSX/GL/vertex_buffer.cpp +++ b/rpcs3/Emu/RSX/GL/vertex_buffer.cpp @@ -188,15 +188,8 @@ void GLGSRender::set_vertex_buffer() vertex_draw_count = (u32)get_index_count(draw_mode, gsl::narrow(vertex_draw_count)); vertex_index_array.resize(vertex_draw_count * type_size); - switch (type) - { - case rsx::index_array_type::u32: - std::tie(min_index, max_index) = write_index_array_data_to_buffer(gsl::span((u32*)vertex_index_array.data(), vertex_draw_count), draw_mode, first_count_commands); - break; - case rsx::index_array_type::u16: - std::tie(min_index, max_index) = write_index_array_data_to_buffer(gsl::span((u16*)vertex_index_array.data(), vertex_draw_count), draw_mode, first_count_commands); - break; - } + gsl::span dst{ reinterpret_cast(vertex_index_array.data()), gsl::narrow(vertex_index_array.size()) }; + std::tie(min_index, max_index) = write_index_array_data_to_buffer(dst, type, draw_mode, first_count_commands); } if (draw_command == rsx::draw_command::inlined_array) diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 7def771356..f3e28cf1a2 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -308,18 +308,17 @@ namespace rsx draw_state.vertex_count += range.second; } draw_state.index_type = rsx::to_index_array_type(rsx::method_registers[NV4097_SET_INDEX_ARRAY_DMA] >> 4); + if (draw_state.index_type == rsx::index_array_type::u16) { draw_state.index.resize(2 * draw_state.vertex_count); - gsl::span dst = { (u16*)draw_state.index.data(), gsl::narrow(draw_state.vertex_count) }; - write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); } if (draw_state.index_type == rsx::index_array_type::u32) { draw_state.index.resize(4 * draw_state.vertex_count); - gsl::span dst = { (u16*)draw_state.index.data(), gsl::narrow(draw_state.vertex_count) }; - write_index_array_data_to_buffer(dst, draw_mode, first_count_commands); } + gsl::span dst = { (gsl::byte*)draw_state.index.data(), gsl::narrow(draw_state.index.size()) }; + write_index_array_data_to_buffer(dst, draw_state.index_type, draw_mode, first_count_commands); } draw_state.programs = get_programs(); diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 8bd436877d..792067f58d 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -545,8 +545,8 @@ VKGSRender::upload_vertex_data() std::vector> ranges; ranges.push_back(std::pair(0, vertex_draw_count)); - gsl::span dst = { (u16*)indices.data(), gsl::narrow(index_count) }; - write_index_array_data_to_buffer(dst, draw_mode, ranges); + gsl::span dst = { (gsl::byte*)indices.data(), gsl::narrow(index_count * 2) }; + write_index_array_data_to_buffer(dst, rsx::index_array_type::u16, draw_mode, ranges); } else {