From 3a3d264cb506febff60409ed5176207e8cb6f856 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 5 Apr 2016 19:12:08 +0200 Subject: [PATCH] rsx/common/d3d12/gl/vulkan: Set dst stride in write_vertex_array_data_to_buffer. --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 18 ++++++++---------- rpcs3/Emu/RSX/Common/BufferUtils.h | 2 +- rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp | 2 +- rpcs3/Emu/RSX/GL/vertex_buffer.cpp | 4 ++-- rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 8fc874fdae..34526bedb8 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -46,19 +46,17 @@ namespace } } -void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const gsl::byte *src_ptr, u32 first, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride) +void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const gsl::byte *src_ptr, u32 first, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride) { Expects(vector_element_count > 0); - u32 element_size = rsx::get_vertex_type_size_on_host(type, vector_element_count); - switch (type) { case rsx::vertex_base_type::ub: case rsx::vertex_base_type::ub256: { gsl::span dst_span = as_span_workaround(raw_dst_span); - copy_whole_attribute_array(dst_span, src_ptr, vector_element_count, element_size, attribute_src_stride, first, count); + copy_whole_attribute_array(dst_span, src_ptr, vector_element_count, dst_stride, attribute_src_stride, first, count); return; } case rsx::vertex_base_type::s1: @@ -66,13 +64,13 @@ void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const case rsx::vertex_base_type::s32k: { gsl::span dst_span = as_span_workaround(raw_dst_span); - copy_whole_attribute_array>(dst_span, src_ptr, vector_element_count, element_size, attribute_src_stride, first, count); + copy_whole_attribute_array>(dst_span, src_ptr, vector_element_count, dst_stride, attribute_src_stride, first, count); return; } case rsx::vertex_base_type::f: { gsl::span dst_span = as_span_workaround(raw_dst_span); - copy_whole_attribute_array>(dst_span, src_ptr, vector_element_count, element_size, attribute_src_stride, first, count); + copy_whole_attribute_array>(dst_span, src_ptr, vector_element_count, dst_stride, attribute_src_stride, first, count); return; } case rsx::vertex_base_type::cmp: @@ -82,10 +80,10 @@ void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const { auto* c_src = (const be_t*)(src_ptr + attribute_src_stride * (first + i)); const auto& decoded_vector = decode_cmp_vector(*c_src); - dst_span[i * element_size / sizeof(u16)] = decoded_vector[0]; - dst_span[i * element_size / sizeof(u16) + 1] = decoded_vector[1]; - dst_span[i * element_size / sizeof(u16) + 2] = decoded_vector[2]; - dst_span[i * element_size / sizeof(u16) + 3] = decoded_vector[3]; + dst_span[i * dst_stride / sizeof(u16)] = decoded_vector[0]; + dst_span[i * dst_stride / sizeof(u16) + 1] = decoded_vector[1]; + dst_span[i * dst_stride / sizeof(u16) + 2] = decoded_vector[2]; + dst_span[i * dst_stride / sizeof(u16) + 3] = decoded_vector[3]; } return; } diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.h b/rpcs3/Emu/RSX/Common/BufferUtils.h index e8605f5a85..2ba850af51 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.h +++ b/rpcs3/Emu/RSX/Common/BufferUtils.h @@ -7,7 +7,7 @@ * Write count vertex attributes from src_ptr starting at first. * src_ptr array layout is deduced from the type, vector element count and src_stride arguments. */ -void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const gsl::byte *src_ptr, u32 first, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride); +void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const gsl::byte *src_ptr, u32 first, u32 count, rsx::vertex_base_type type, u32 vector_element_count, u32 attribute_src_stride, u8 dst_stride); /* * If primitive mode is not supported and need to be emulated (using an index buffer) returns false. diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp index 480a795672..a6a94fffe6 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Buffer.cpp @@ -104,7 +104,7 @@ std::vector D3D12GSRender::upload_vertex_attrib for (const auto &range : vertex_ranges) { gsl::span mapped_buffer_span = { (gsl::byte*)mapped_buffer, gsl::narrow_cast(buffer_size) }; - write_vertex_array_data_to_buffer(mapped_buffer_span, src_ptr, range.first, range.second, info.type, info.size, info.stride); + write_vertex_array_data_to_buffer(mapped_buffer_span, src_ptr, range.first, range.second, info.type, info.size, info.stride, element_size); mapped_buffer = (char*)mapped_buffer + range.second * element_size; } m_buffer_data.unmap(CD3DX12_RANGE(heap_offset, heap_offset + buffer_size)); diff --git a/rpcs3/Emu/RSX/GL/vertex_buffer.cpp b/rpcs3/Emu/RSX/GL/vertex_buffer.cpp index af0c979558..27bd00410e 100644 --- a/rpcs3/Emu/RSX/GL/vertex_buffer.cpp +++ b/rpcs3/Emu/RSX/GL/vertex_buffer.cpp @@ -319,7 +319,7 @@ void GLGSRender::set_vertex_buffer() for (const auto &first_count : first_count_commands) { - write_vertex_array_data_to_buffer(dest_span.subspan(offset), src_ptr, first_count.first, first_count.second, vertex_info.type, vertex_info.size, vertex_info.stride); + write_vertex_array_data_to_buffer(dest_span.subspan(offset), src_ptr, first_count.first, first_count.second, vertex_info.type, vertex_info.size, vertex_info.stride, rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.stride)); offset += first_count.second * element_size; } } @@ -329,7 +329,7 @@ void GLGSRender::set_vertex_buffer() gsl::span dest_span(vertex_array); prepare_buffer_for_writing(vertex_array.data(), vertex_info.type, vertex_info.size, vertex_draw_count); - write_vertex_array_data_to_buffer(dest_span, src_ptr, 0, max_index + 1, vertex_info.type, vertex_info.size, vertex_info.stride); + write_vertex_array_data_to_buffer(dest_span, src_ptr, 0, max_index + 1, vertex_info.type, vertex_info.size, vertex_info.stride, rsx::get_vertex_type_size_on_host(vertex_info.type, vertex_info.stride)); } size_t size = vertex_array.size(); diff --git a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp index 792067f58d..6adff8ac03 100644 --- a/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp +++ b/rpcs3/Emu/RSX/VK/VKVertexBuffers.cpp @@ -398,7 +398,7 @@ VKGSRender::upload_vertex_data() for (const auto &first_count : first_count_commands) { - write_vertex_array_data_to_buffer(dest_span.subspan(offset), src_ptr, first_count.first, first_count.second, vertex_info.type, vertex_info.size, vertex_info.stride); + write_vertex_array_data_to_buffer(dest_span.subspan(offset), src_ptr, first_count.first, first_count.second, vertex_info.type, vertex_info.size, vertex_info.stride, element_size); offset += first_count.second * element_size; } } @@ -409,7 +409,7 @@ VKGSRender::upload_vertex_data() gsl::span dest_span(vertex_array); vk::prepare_buffer_for_writing(vertex_array.data(), vertex_info.type, vertex_info.size, vertex_draw_count); - write_vertex_array_data_to_buffer(dest_span, src_ptr, 0, max_index + 1, vertex_info.type, vertex_info.size, vertex_info.stride); + write_vertex_array_data_to_buffer(dest_span, src_ptr, 0, max_index + 1, vertex_info.type, vertex_info.size, vertex_info.stride, element_size); } std::vector converted_buffer;