From 5ef7f8bf3ec7d8079851bd77e3628f81927180ea Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 22 Feb 2016 21:36:48 +0100 Subject: [PATCH 1/5] rsx/common: Fix handling of UB256 --- rpcs3-tests/ps3-rsx-common.cpp | 15 +++++++++++++++ rpcs3-tests/rpcs3-tests.vcxproj | 3 ++- rpcs3-tests/rpcs3-tests.vcxproj.filters | 3 +++ rpcs3/Emu/RSX/Common/BufferUtils.cpp | 2 +- rpcs3/Emu/RSX/GCM.cpp | 4 ++-- rpcs3/Emu/RSX/GCM.h | 4 ++-- rpcs3/Emu/RSX/RSXThread.cpp | 19 ++++++++----------- 7 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 rpcs3-tests/ps3-rsx-common.cpp diff --git a/rpcs3-tests/ps3-rsx-common.cpp b/rpcs3-tests/ps3-rsx-common.cpp new file mode 100644 index 0000000000..42ccbf9231 --- /dev/null +++ b/rpcs3-tests/ps3-rsx-common.cpp @@ -0,0 +1,15 @@ +#include "stdafx.h" +#include "Emu\RSX\Common\BufferUtils.h" + + +TEST_CLASS(rsx_common) +{ + // Check UB256 size is correctly set in write_vertex_array_data_to_buffer + TEST_METHOD(ub256_upload) + { + std::vector dest_buffer(2200); + std::vector src_buffer(100000); // Big enough + + write_vertex_array_data_to_buffer(gsl::span(dest_buffer), src_buffer.data(), 0, 550, rsx::vertex_base_type::ub256, 4, 20); + } +}; diff --git a/rpcs3-tests/rpcs3-tests.vcxproj b/rpcs3-tests/rpcs3-tests.vcxproj index 53638401fb..2c21977ca9 100644 --- a/rpcs3-tests/rpcs3-tests.vcxproj +++ b/rpcs3-tests/rpcs3-tests.vcxproj @@ -56,7 +56,7 @@ $(VCInstallDir)UnitTest\lib;..\OpenAL\libs\Win64;..\ffmpeg\Windows\x86_64\lib;%(AdditionalLibraryDirectories) - + @@ -76,6 +76,7 @@ + Create diff --git a/rpcs3-tests/rpcs3-tests.vcxproj.filters b/rpcs3-tests/rpcs3-tests.vcxproj.filters index 3ce2b4bc5d..8b971a7217 100644 --- a/rpcs3-tests/rpcs3-tests.vcxproj.filters +++ b/rpcs3-tests/rpcs3-tests.vcxproj.filters @@ -17,6 +17,9 @@ Source Files + + Source Files + diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 2ab5677c8d..5dec363f71 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -58,6 +58,7 @@ void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const 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); @@ -72,7 +73,6 @@ void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const } case rsx::vertex_base_type::f: case rsx::vertex_base_type::s32k: - 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); diff --git a/rpcs3/Emu/RSX/GCM.cpp b/rpcs3/Emu/RSX/GCM.cpp index 8e724eea5b..a8b0b9438f 100644 --- a/rpcs3/Emu/RSX/GCM.cpp +++ b/rpcs3/Emu/RSX/GCM.cpp @@ -1127,10 +1127,10 @@ namespace case rsx::vertex_base_type::s1: return "Short"; case rsx::vertex_base_type::f: return "Float"; case rsx::vertex_base_type::sf: return "Half float"; - case rsx::vertex_base_type::ub: return "Unsigned byte"; + case rsx::vertex_base_type::ub: return "Unsigned byte normalized"; case rsx::vertex_base_type::s32k: return "Signed int"; case rsx::vertex_base_type::cmp: return "CMP"; - case rsx::vertex_base_type::ub256: return "UB256"; + case rsx::vertex_base_type::ub256: return "Unsigned byte unormalized"; } } diff --git a/rpcs3/Emu/RSX/GCM.h b/rpcs3/Emu/RSX/GCM.h index 5d894e5ffa..882972911c 100644 --- a/rpcs3/Emu/RSX/GCM.h +++ b/rpcs3/Emu/RSX/GCM.h @@ -30,10 +30,10 @@ namespace rsx s1, ///< signed byte f, ///< float sf, ///< half float - ub, ///< unsigned byte + ub, ///< unsigned byte interpreted as 0.f and 1.f s32k, ///< signed 32bits int cmp, ///< compressed aka X11G11Z10 and always 1. W. - ub256, + ub256, ///< unsigned byte interpreted as between 0 and 255. }; vertex_base_type to_vertex_base_type(u8 in); diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 237f124bad..4ec46044d7 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -136,8 +136,8 @@ namespace rsx case 3: return sizeof(u16) * 4; } - throw new EXCEPTION("Wrong vector size"); - case vertex_base_type::f: return sizeof(f32) * size; + throw EXCEPTION("Wrong vector size"); + case vertex_base_type::f: return sizeof(f32) * size; case vertex_base_type::sf: switch (size) { @@ -148,7 +148,7 @@ namespace rsx case 3: return sizeof(f16) * 4; } - throw new EXCEPTION("Wrong vector size"); + throw EXCEPTION("Wrong vector size"); case vertex_base_type::ub: switch (size) { @@ -159,15 +159,12 @@ namespace rsx case 3: return sizeof(u8) * 4; } - throw new EXCEPTION("Wrong vector size"); - case vertex_base_type::s32k: return sizeof(u32) * size; - case vertex_base_type::cmp: return sizeof(u16) * 4; - case vertex_base_type::ub256: return sizeof(u8) * 4; - - default: - throw new EXCEPTION("RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type); - return 0; + throw EXCEPTION("Wrong vector size"); + case vertex_base_type::s32k: return sizeof(u32) * size; + case vertex_base_type::cmp: return sizeof(u16) * 4; + case vertex_base_type::ub256: Expects(size == 4); return sizeof(u8) * 4; } + throw EXCEPTION("RSXVertexData::GetTypeSize: Bad vertex data type (%d)!", type); } void tiled_region::write(const void *src, u32 width, u32 height, u32 pitch) From a6d8d1144c4f015e8f448b00ab885052d4f256a2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 22 Feb 2016 21:44:08 +0100 Subject: [PATCH 2/5] rsx/common: Supports D24X8 texture format when copying Some app uses this type before setting proper depth surface --- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index 6b1e2dba87..f5f66b8dae 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -295,6 +295,8 @@ std::vector upload_placed_texture(gsl::span mapped_b return copy_texture_data(as_span_workaround(mapped_buffer), reinterpret_cast(pixels), w, h, depth, layer, texture.mipmap(), texture.pitch()); else return copy_texture_data(as_span_workaround(mapped_buffer), reinterpret_cast(pixels), w, h, depth, layer, texture.mipmap(), texture.pitch()); + case CELL_GCM_TEXTURE_DEPTH24_D8: // Opaque type ; ATM do not copy anything + return std::vector(); } throw EXCEPTION("Wrong format %d", format); } From 62246f75c8825f55c4c34ef753a3d29afb94f9fb Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 22 Feb 2016 21:53:46 +0100 Subject: [PATCH 3/5] d3d12/gl: Supports SSA in Fragment Shader. --- rpcs3/Emu/RSX/D3D12/D3D12FragmentProgramDecompiler.cpp | 3 +++ rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12FragmentProgramDecompiler.cpp b/rpcs3/Emu/RSX/D3D12/D3D12FragmentProgramDecompiler.cpp index 811dd8caf1..5cf7c69190 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12FragmentProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12FragmentProgramDecompiler.cpp @@ -169,6 +169,8 @@ void D3D12FragmentDecompiler::insertMainStart(std::stringstream & OS) continue; } } + if (PI.name == "ssa") + continue; OS << " " << PT.type << " " << PI.name << " = In." << PI.name << ";" << std::endl; } } @@ -176,6 +178,7 @@ void D3D12FragmentDecompiler::insertMainStart(std::stringstream & OS) OS << " " << "float4 gl_FragCoord = In.Position;" << std::endl; if (m_prog.origin_mode == rsx::window_origin::bottom) OS << " gl_FragCoord.y = (" << std::to_string(m_prog.height) << " - gl_FragCoord.y);\n"; + OS << " float4 ssa = is_front_face ? float4(1., 1., 1., 1.) : float4(-1., -1., -1., -1.);\n"; // Declare output for (const ParamType &PT : m_parr.params[PF_PARAM_NONE]) { diff --git a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp index 3ef0038315..f332ab2175 100644 --- a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp @@ -116,6 +116,8 @@ void GLFragmentDecompilerThread::insertMainStart(std::stringstream & OS) OS << ";" << std::endl; } } + + OS << " vec4 ssa = gl_FrontFacing ? vec4(1.) : vec4(-1.);\n"; } void GLFragmentDecompilerThread::insertMainEnd(std::stringstream & OS) From a6ba47265fdd17d7527d893c28c6f9ff0a8a82df Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 22 Feb 2016 22:07:38 +0100 Subject: [PATCH 4/5] rsx/common/gl: s32k is actually signed short unormalized. gl fix --- rpcs3/Emu/RSX/Common/BufferUtils.cpp | 2 +- rpcs3/Emu/RSX/GCM.cpp | 4 ++-- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 8 ++++---- rpcs3/Emu/RSX/RSXThread.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index 5dec363f71..8ab9262116 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -66,13 +66,13 @@ void write_vertex_array_data_to_buffer(gsl::span raw_dst_span, const } case rsx::vertex_base_type::s1: case rsx::vertex_base_type::sf: + 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); return; } case rsx::vertex_base_type::f: - 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); diff --git a/rpcs3/Emu/RSX/GCM.cpp b/rpcs3/Emu/RSX/GCM.cpp index a8b0b9438f..27a8990281 100644 --- a/rpcs3/Emu/RSX/GCM.cpp +++ b/rpcs3/Emu/RSX/GCM.cpp @@ -1124,11 +1124,11 @@ namespace { switch (rsx::to_vertex_base_type(type)) { - case rsx::vertex_base_type::s1: return "Short"; + case rsx::vertex_base_type::s1: return "Signed short normalized"; case rsx::vertex_base_type::f: return "Float"; case rsx::vertex_base_type::sf: return "Half float"; case rsx::vertex_base_type::ub: return "Unsigned byte normalized"; - case rsx::vertex_base_type::s32k: return "Signed int"; + case rsx::vertex_base_type::s32k: return "Signed short unormalized"; case rsx::vertex_base_type::cmp: return "CMP"; case rsx::vertex_base_type::ub256: return "Unsigned byte unormalized"; } diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 6e11c4d0f1..55b0940adc 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -37,10 +37,10 @@ namespace * The buffer texture spec only allows fetches aligned to 8, 16, 32, etc... * This rules out most 3-component formats, except for the 32-wide RGB32F, RGB32I, RGB32UI */ - const u32 vec1_types[] = { GL_R16, GL_R32F, GL_R16F, GL_R8, GL_R32I, GL_R16, GL_R8UI }; - const u32 vec2_types[] = { GL_RG16, GL_RG32F, GL_RG16F, GL_RG8, GL_RG32I, GL_RG16, GL_RG8UI }; - const u32 vec3_types[] = { GL_RGBA16, GL_RGB32F, GL_RGBA16F, GL_RGBA8, GL_RGB32I, GL_RGBA16, GL_RGBA8UI }; //VEC3 COMPONENTS NOT SUPPORTED! - const u32 vec4_types[] = { GL_RGBA16, GL_RGBA32F, GL_RGBA16F, GL_RGBA8, GL_RGBA32I, GL_RGBA16, GL_RGBA8UI }; + const u32 vec1_types[] = { GL_R16, GL_R32F, GL_R16F, GL_R8, GL_R16I, GL_R16, GL_R8UI }; + const u32 vec2_types[] = { GL_RG16, GL_RG32F, GL_RG16F, GL_RG8, GL_RG16I, GL_RG16, GL_RG8UI }; + const u32 vec3_types[] = { GL_RGBA16, GL_RGB32F, GL_RGBA16F, GL_RGBA8, GL_RGBA16I, GL_RGBA16, GL_RGBA8UI }; //VEC3 COMPONENTS NOT SUPPORTED! + const u32 vec4_types[] = { GL_RGBA16, GL_RGBA32F, GL_RGBA16F, GL_RGBA8, GL_RGBA16I, GL_RGBA16, GL_RGBA8UI }; const u32* vec_selectors[] = { 0, vec1_types, vec2_types, vec3_types, vec4_types }; diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 4ec46044d7..1bfe3ff924 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -127,6 +127,7 @@ namespace rsx switch (type) { case vertex_base_type::s1: + case vertex_base_type::s32k: switch (size) { case 1: @@ -160,7 +161,6 @@ namespace rsx return sizeof(u8) * 4; } throw EXCEPTION("Wrong vector size"); - case vertex_base_type::s32k: return sizeof(u32) * size; case vertex_base_type::cmp: return sizeof(u16) * 4; case vertex_base_type::ub256: Expects(size == 4); return sizeof(u8) * 4; } From 35db227af4718d9dc055cb2d5fd9b9cb95906d9f Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 24 Feb 2016 18:45:43 +0100 Subject: [PATCH 5/5] rsx/common/d3d12: Separate int type buffer from float type buffer. --- .../D3D12/D3D12VertexProgramDecompiler.cpp | 2 +- rpcs3/Emu/RSX/RSXThread.cpp | 25 +++++++++++++++++-- rpcs3/Emu/RSX/RSXVertexProgram.h | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp index 53d44fbed7..be2b94db36 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12VertexProgramDecompiler.cpp @@ -44,7 +44,7 @@ namespace { if (static_cast(real_input.location) != std::get<0>(attribute)) continue; - OS << "Buffer " << std::get<1>(attribute) << "_buffer : register(t" << reg++ << ");\n"; + OS << "Buffer<" << (real_input.int_type ? "int4" : "float4") << "> " << std::get<1>(attribute) << "_buffer : register(t" << reg++ << ");\n"; return true; } return false; diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 1bfe3ff924..2c48036c73 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -568,6 +568,25 @@ namespace rsx } } + namespace + { + bool is_int_type(rsx::vertex_base_type type) + { + switch (type) + { + case rsx::vertex_base_type::s32k: + case rsx::vertex_base_type::ub256: + return true; + case rsx::vertex_base_type::f: + case rsx::vertex_base_type::cmp: + case rsx::vertex_base_type::sf: + case rsx::vertex_base_type::s1: + case rsx::vertex_base_type::ub: + return false; + } + } + } + std::array thread::get_color_surface_addresses() const { u32 offset_color[] = @@ -636,7 +655,8 @@ namespace rsx vertex_arrays_info[index].size, vertex_arrays_info[index].frequency, !!((modulo_mask >> index) & 0x1), - true + true, + is_int_type(vertex_arrays_info[index].type) } ); } @@ -648,7 +668,8 @@ namespace rsx register_vertex_info[index].size, register_vertex_info[index].frequency, !!((modulo_mask >> index) & 0x1), - false + false, + is_int_type(vertex_arrays_info[index].type) } ); } diff --git a/rpcs3/Emu/RSX/RSXVertexProgram.h b/rpcs3/Emu/RSX/RSXVertexProgram.h index 94f8198d8d..ba8d7fe875 100644 --- a/rpcs3/Emu/RSX/RSXVertexProgram.h +++ b/rpcs3/Emu/RSX/RSXVertexProgram.h @@ -197,10 +197,11 @@ struct rsx_vertex_input u16 frequency; bool is_modulo; // either modulo frequency or divide frequency bool is_array; // false if "reg value" + bool int_type; bool operator==(const rsx_vertex_input other) const { - return location == other.location && size == other.size && frequency == other.frequency && is_modulo == other.is_modulo && is_array == other.is_array; + return location == other.location && size == other.size && frequency == other.frequency && is_modulo == other.is_modulo && is_array == other.is_array && int_type == other.int_type; } };