From e68ae2d05194888e5de237a2e6bcbcae386b5c9a Mon Sep 17 00:00:00 2001 From: yahfz <17715080+Yahfz@users.noreply.github.com> Date: Fri, 2 Oct 2026 20:21:52 -0300 Subject: [PATCH] RSX: Use 32-bit generated indices --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 25 ++++--------------------- rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp | 6 +++--- rpcs3/Emu/RSX/RSXOffload.cpp | 2 +- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 4 ++-- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 6ff24848dc..28d089288d 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -6,6 +6,8 @@ #include "util/v128.hpp" #include "util/simd.hpp" +#include + #if defined(ARCH_X64) #include "BufferUtils_avx512.h" #endif @@ -514,25 +516,6 @@ namespace return primitive_restart_impl::upload_untouched(src, dst, static_cast(primitive_restart_index)); } - void iota16(u16* dst, u32 count) - { - unsigned i = 0; -#if defined(ARCH_X64) || defined(ARCH_ARM64) - const unsigned step = 8; // We do 8 entries per step - const __m128i vec_step = _mm_set1_epi16(8); // Constant to increment the raw values - __m128i values = _mm_set_epi16(7, 6, 5, 4, 3, 2, 1, 0); - __m128i* vec_ptr = utils::bless<__m128i>(dst); - - for (; (i + step) <= count; i += step, vec_ptr++) - { - _mm_stream_si128(vec_ptr, values); - values = _mm_add_epi16(values, vec_step); - } -#endif - for (; i < count; ++i) - dst[i] = i; - } - template std::tuple expand_indexed_triangle_fan(std::span> src, std::span dst, bool is_primitive_restart_enabled, u32 primitive_restart_index) { @@ -697,11 +680,11 @@ u32 get_index_type_size(rsx::index_array_type type) void write_index_array_for_non_indexed_non_native_primitive_to_buffer(char* dst, rsx::primitive_type draw_mode, unsigned count) { - auto typedDst = reinterpret_cast(dst); + auto typedDst = reinterpret_cast(dst); switch (draw_mode) { case rsx::primitive_type::line_loop: - iota16(typedDst, count); + std::iota(typedDst, typedDst + count, 0u); typedDst[count] = 0; return; case rsx::primitive_type::triangle_fan: diff --git a/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp b/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp index 76ff30e6c8..1de8daecbe 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexBuffers.cpp @@ -26,7 +26,7 @@ namespace const auto element_count = get_index_count(primitive_mode, vertex_count); ensure(!gl::is_primitive_native(primitive_mode)); - auto mapping = dst.alloc_from_heap(element_count * sizeof(u16), 256); + auto mapping = dst.alloc_from_heap(element_count * sizeof(u32), 256); auto mapped_buffer = static_cast(mapping.first); write_index_array_for_non_indexed_non_native_primitive_to_buffer(mapped_buffer, primitive_mode, vertex_count); @@ -77,7 +77,7 @@ namespace rsx::method_registers.current_draw_clause.primitive, m_index_ring_buffer, rsx::method_registers.current_draw_clause.get_elements_count()); - return{ false, min_index, max_index, index_count, 0, std::make_tuple(static_cast(GL_UNSIGNED_SHORT), offset_in_index_buffer) }; + return{ false, min_index, max_index, index_count, 0, std::make_tuple(static_cast(GL_UNSIGNED_INT), offset_in_index_buffer) }; } return{ false, min_index, max_index, vertex_count, 0, std::optional>() }; @@ -138,7 +138,7 @@ namespace std::tie(index_count, offset_in_index_buffer) = get_index_array_for_emulated_non_indexed_draw( rsx::method_registers.current_draw_clause.primitive, m_index_ring_buffer, vertex_count); - return{ false, 0, vertex_count, index_count, 0, std::make_tuple(static_cast(GL_UNSIGNED_SHORT), offset_in_index_buffer) }; + return{ false, 0, vertex_count, index_count, 0, std::make_tuple(static_cast(GL_UNSIGNED_INT), offset_in_index_buffer) }; } return{ false, 0, vertex_count, vertex_count, 0, std::optional>() }; diff --git a/rpcs3/Emu/RSX/RSXOffload.cpp b/rpcs3/Emu/RSX/RSXOffload.cpp index 4136c89aa9..9c711e552a 100644 --- a/rpcs3/Emu/RSX/RSXOffload.cpp +++ b/rpcs3/Emu/RSX/RSXOffload.cpp @@ -231,7 +231,7 @@ namespace rsx case index_emulate: ensure(writing); address = m_current_job->dst; - range = get_index_count(static_cast(m_current_job->aux_param0), m_current_job->length) * sizeof(u16); + range = get_index_count(static_cast(m_current_job->aux_param0), m_current_job->length) * sizeof(u32); break; default: fmt::throw_exception("Unreachable"); diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 1de785a579..7910f8f231 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -62,7 +62,7 @@ namespace vk::data_heap& m_index_buffer_ring_info) { u32 index_count = get_index_count(clause.primitive, vertex_count); - u32 upload_size = index_count * sizeof(u16); + u32 upload_size = index_count * sizeof(u32); VkDeviceSize offset_in_index_buffer = m_index_buffer_ring_info.alloc<256>(upload_size); void* buf = m_index_buffer_ring_info.map(offset_in_index_buffer, upload_size); @@ -71,7 +71,7 @@ namespace m_index_buffer_ring_info.unmap(); return std::make_tuple( - index_count, std::make_tuple(offset_in_index_buffer, VK_INDEX_TYPE_UINT16)); + index_count, std::make_tuple(offset_in_index_buffer, VK_INDEX_TYPE_UINT32)); } struct vertex_input_state