From 5a51bc10e56c8709b55fe53cb438f7a42ac09ad4 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sat, 14 Mar 2015 10:15:19 +0100 Subject: SWVertexLoader: fix truncated components --- Source/Core/VideoBackends/Software/SWVertexLoader.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp index d824893243..859cf593b4 100644 --- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp +++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp @@ -100,16 +100,17 @@ static T ReadNormalized(I value) } template -static void ReadVertexAttribute(T* dst, DataReader src, const AttributeFormat& format, int base_component, int max_components, bool reverse) +static void ReadVertexAttribute(T* dst, DataReader src, const AttributeFormat& format, int base_component, int components, bool reverse) { if (format.enable) { src.Skip(format.offset); src.Skip(base_component * (1<<(format.type>>1))); - for (int i = 0; i < std::min(format.components - base_component, max_components); i++) + int i; + for (i = 0; i < std::min(format.components - base_component, components); i++) { - int i_dst = reverse ? max_components - i - 1 : i; + int i_dst = reverse ? components - i - 1 : i; switch (format.type) { case VAR_UNSIGNED_BYTE: @@ -131,6 +132,11 @@ static void ReadVertexAttribute(T* dst, DataReader src, const AttributeFormat& f _assert_msg_(VIDEO, !format.integer || format.type != VAR_FLOAT, "only non-float values are allowed to be streamed as integer"); } + for (; i < components; i++) + { + int i_dst = reverse ? components - i - 1 : i; + dst[i_dst] = i == 3; + } } } -- cgit v1.2.3 From 8d90ecda7f8e08a37964f8664aed571dbc6e9051 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Tue, 17 Mar 2015 07:05:19 +0100 Subject: VertexLoaders: make positions more compact --- Source/Core/VideoCommon/VertexLoader.cpp | 5 +++-- Source/Core/VideoCommon/VertexLoaderARM64.cpp | 5 +++-- Source/Core/VideoCommon/VertexLoaderX64.cpp | 5 +++-- Source/Core/VideoCommon/VertexLoader_Position.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index d27d5287ad..49b6d23e1a 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -131,12 +131,13 @@ void VertexLoader::CompileVertexTranslator() WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements)); m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements); - m_native_vtx_decl.position.components = 3; + int pos_elements = m_VtxAttr.PosElements + 2; + m_native_vtx_decl.position.components = pos_elements; m_native_vtx_decl.position.enable = true; m_native_vtx_decl.position.offset = nat_offset; m_native_vtx_decl.position.type = VAR_FLOAT; m_native_vtx_decl.position.integer = false; - nat_offset += 12; + nat_offset += pos_elements * sizeof(float); // Normals if (m_VtxDesc.Normal != NOT_PRESENT) diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index 4a404e9a75..397a179e9e 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -370,8 +370,9 @@ void VertexLoaderARM64::GenerateVertexLoader() load_size <<= 3; s32 offset = GetAddressImm(ARRAY_POSITION, m_VtxDesc.Position, EncodeRegTo64(scratch1_reg), load_size); - ReadVertex(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements + 2, 3, - m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position, offset); + int pos_elements = m_VtxAttr.PosElements + 2; + ReadVertex(m_VtxDesc.Position, m_VtxAttr.PosFormat, pos_elements, pos_elements, + m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position, offset); } if (m_VtxDesc.Normal) diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index 8d01a5d598..df1a5580b7 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -332,7 +332,8 @@ void VertexLoaderX64::GenerateVertexLoader() } OpArg data = GetVertexAddr(ARRAY_POSITION, m_VtxDesc.Position); - ReadVertex(data, m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements + 2, 3, + int pos_elements = 2 + m_VtxAttr.PosElements; + ReadVertex(data, m_VtxDesc.Position, m_VtxAttr.PosFormat, pos_elements, pos_elements, m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position); if (m_VtxDesc.Normal) @@ -408,7 +409,7 @@ void VertexLoaderX64::GenerateVertexLoader() m_native_vtx_decl.texcoords[i].offset = m_dst_ofs; PXOR(XMM0, R(XMM0)); CVTSI2SS(XMM0, R(scratch1)); - SHUFPS(XMM0, R(XMM0), 0x45); + SHUFPS(XMM0, R(XMM0), 0x45); // 000X -> 0X00 MOVUPS(MDisp(dst_reg, m_dst_ofs), XMM0); m_dst_ofs += sizeof(float) * 3; } diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 18460ff1e1..3c30d05ed6 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -30,8 +30,8 @@ void LOADERDECL Pos_ReadDirect(VertexLoader* loader) DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader src(g_video_buffer_read_ptr, nullptr); - for (int i = 0; i < 3; ++i) - dst.Write(i < N ? PosScale(src.Read(), scale) : 0.f); + for (int i = 0; i < N; ++i) + dst.Write(PosScale(src.Read(), scale)); g_vertex_manager_write_ptr = dst.GetPointer(); g_video_buffer_read_ptr = src.GetPointer(); @@ -50,8 +50,8 @@ void LOADERDECL Pos_ReadIndex(VertexLoader* loader) auto const scale = loader->m_posScale; DataReader dst(g_vertex_manager_write_ptr, nullptr); - for (int i = 0; i < 3; ++i) - dst.Write(i < N ? PosScale(Common::FromBigEndian(data[i]), scale) : 0.f); + for (int i = 0; i < N; ++i) + dst.Write(PosScale(Common::FromBigEndian(data[i]), scale)); g_vertex_manager_write_ptr = dst.GetPointer(); LOG_VTX(); -- cgit v1.2.3 From 9793fed7426b3f17bdfd301a71bc1e701c1be92b Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 8 Mar 2015 15:19:59 +0100 Subject: XEmitter: add PUNPCKLQDQ --- Source/Core/Common/x64Emitter.cpp | 1 + Source/Core/Common/x64Emitter.h | 1 + 2 files changed, 2 insertions(+) (limited to 'Source/Core') diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp index e7ab88396d..0f37c547d2 100644 --- a/Source/Core/Common/x64Emitter.cpp +++ b/Source/Core/Common/x64Emitter.cpp @@ -1638,6 +1638,7 @@ void XEmitter::PACKUSWB(X64Reg dest, OpArg arg) {WriteSSEOp(0x66, 0x67, dest, ar void XEmitter::PUNPCKLBW(X64Reg dest, const OpArg &arg) {WriteSSEOp(0x66, 0x60, dest, arg);} void XEmitter::PUNPCKLWD(X64Reg dest, const OpArg &arg) {WriteSSEOp(0x66, 0x61, dest, arg);} void XEmitter::PUNPCKLDQ(X64Reg dest, const OpArg &arg) {WriteSSEOp(0x66, 0x62, dest, arg);} +void XEmitter::PUNPCKLQDQ(X64Reg dest, const OpArg &arg) {WriteSSEOp(0x66, 0x6C, dest, arg);} void XEmitter::PSRLW(X64Reg reg, int shift) { diff --git a/Source/Core/Common/x64Emitter.h b/Source/Core/Common/x64Emitter.h index 1c32c54969..962f685108 100644 --- a/Source/Core/Common/x64Emitter.h +++ b/Source/Core/Common/x64Emitter.h @@ -680,6 +680,7 @@ public: void PUNPCKLBW(X64Reg dest, const OpArg &arg); void PUNPCKLWD(X64Reg dest, const OpArg &arg); void PUNPCKLDQ(X64Reg dest, const OpArg &arg); + void PUNPCKLQDQ(X64Reg dest, const OpArg &arg); void PTEST(X64Reg dest, OpArg arg); void PAND(X64Reg dest, OpArg arg); -- cgit v1.2.3 From 70305425462843af192489da00389559cd6f5834 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Wed, 18 Mar 2015 11:26:21 +0100 Subject: VertexLoaderX64: support SSE2 as a fallback With suggestions by Fiora and magumagu. --- Source/Core/VideoCommon/VertexLoaderX64.cpp | 119 +++++++++++++++++++++------- Source/Core/VideoCommon/VertexLoaderX64.h | 2 +- 2 files changed, 90 insertions(+), 31 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index df1a5580b7..a71daba28e 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -1,3 +1,4 @@ +#include "Common/BitSet.h" #include "Common/CPUDetect.h" #include "Common/Intrinsics.h" #include "Common/JitRegister.h" @@ -6,8 +7,6 @@ using namespace Gen; -#define VERTEX_LOADER_REGS {XMM0+16} - static const X64Reg src_reg = ABI_PARAM1; static const X64Reg dst_reg = ABI_PARAM2; static const X64Reg scratch1 = RAX; @@ -98,30 +97,103 @@ int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count int elem_size = 1 << (format / 2); int load_bytes = elem_size * count_in; - if (load_bytes > 8) - MOVDQU(coords, data); - else if (load_bytes > 4) - MOVQ_xmm(coords, data); - else - MOVD_xmm(coords, data); + OpArg dest = MDisp(dst_reg, m_dst_ofs); + + native_format->components = count_out; + native_format->enable = true; + native_format->offset = m_dst_ofs; + native_format->type = VAR_FLOAT; + native_format->integer = false; - PSHUFB(coords, M(&shuffle_lut[format][count_in - 1])); + m_dst_ofs += sizeof(float) * count_out; - if (format != FORMAT_FLOAT) + if (attribute == DIRECT) + m_src_ofs += load_bytes; + + if (cpu_info.bSSSE3) { - // Sign extend + if (load_bytes > 8) + MOVDQU(coords, data); + else if (load_bytes > 4) + MOVQ_xmm(coords, data); + else + MOVD_xmm(coords, data); + + PSHUFB(coords, M(&shuffle_lut[format][count_in - 1])); + + // Sign-extend. if (format == FORMAT_BYTE) PSRAD(coords, 24); if (format == FORMAT_SHORT) PSRAD(coords, 16); + } + else + { + // SSE2 + X64Reg temp = XMM1; + switch (format) + { + case FORMAT_UBYTE: + MOVD_xmm(coords, data); + PXOR(temp, R(temp)); + PUNPCKLBW(coords, R(temp)); + PUNPCKLWD(coords, R(temp)); + break; + case FORMAT_BYTE: + MOVD_xmm(coords, data); + PUNPCKLBW(coords, R(coords)); + PUNPCKLWD(coords, R(coords)); + PSRAD(coords, 24); + break; + case FORMAT_USHORT: + case FORMAT_SHORT: + switch (count_in) + { + case 1: + LoadAndSwap(32, scratch3, data); + MOVD_xmm(coords, R(scratch3)); // ......X. + break; + case 2: + LoadAndSwap(32, scratch3, data); + MOVD_xmm(coords, R(scratch3)); // ......XY + PSHUFLW(coords, R(coords), 0x24); // ....Y.X. + break; + case 3: + LoadAndSwap(64, scratch3, data); + MOVQ_xmm(coords, R(scratch3)); // ....XYZ. + PUNPCKLQDQ(coords, R(coords)); // ..Z.XYZ. + PSHUFLW(coords, R(coords), 0xAC); // ..Z.Y.X. + break; + } + if (format == FORMAT_SHORT) + PSRAD(coords, 16); + else + PSRLD(coords, 16); + break; + case FORMAT_FLOAT: + // Floats don't need to be scaled or converted, + // so we can just load/swap/store them directly + // and return early. + // (In SSSE3 we still need to store them.) + for (int i = 0; i < count_in; i++) + { + LoadAndSwap(32, scratch3, data); + MOV(32, dest, R(scratch3)); + data.offset += sizeof(float); + dest.offset += sizeof(float); + } + return load_bytes; + } + } + if (format != FORMAT_FLOAT) + { CVTDQ2PS(coords, R(coords)); if (dequantize && scaling_exponent) MULPS(coords, M(&scale_factors[scaling_exponent])); } - OpArg dest = MDisp(dst_reg, m_dst_ofs); switch (count_out) { case 1: MOVSS(dest, coords); break; @@ -129,16 +201,6 @@ int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count case 3: MOVUPS(dest, coords); break; } - native_format->components = count_out; - native_format->enable = true; - native_format->offset = m_dst_ofs; - native_format->type = VAR_FLOAT; - native_format->integer = false; - m_dst_ofs += sizeof(float) * count_out; - - if (attribute == DIRECT) - m_src_ofs += load_bytes; - return load_bytes; } @@ -290,7 +352,10 @@ void VertexLoaderX64::ReadColor(OpArg data, u64 attribute, int format) void VertexLoaderX64::GenerateVertexLoader() { - ABI_PushRegistersAndAdjustStack(VERTEX_LOADER_REGS, 8); + BitSet32 xmm_regs; + xmm_regs[XMM0+16] = true; + xmm_regs[XMM1+16] = !cpu_info.bSSSE3; + ABI_PushRegistersAndAdjustStack(xmm_regs, 8); // Backup count since we're going to count it down. PUSH(32, R(ABI_PARAM3)); @@ -427,7 +492,7 @@ void VertexLoaderX64::GenerateVertexLoader() // Get the original count. POP(32, R(ABI_RETURN)); - ABI_PopRegistersAndAdjustStack(VERTEX_LOADER_REGS, 8); + ABI_PopRegistersAndAdjustStack(xmm_regs, 8); if (m_VtxDesc.Position & MASK_INDEXED) { @@ -447,12 +512,6 @@ void VertexLoaderX64::GenerateVertexLoader() m_native_vtx_decl.stride = m_dst_ofs; } -bool VertexLoaderX64::IsInitialized() -{ - // Uses PSHUFB. - return cpu_info.bSSSE3; -} - int VertexLoaderX64::RunVertices(DataReader src, DataReader dst, int count, int primitive) { m_numLoadedVertices += count; diff --git a/Source/Core/VideoCommon/VertexLoaderX64.h b/Source/Core/VideoCommon/VertexLoaderX64.h index 0139d392b7..53b7b58d9e 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.h +++ b/Source/Core/VideoCommon/VertexLoaderX64.h @@ -8,7 +8,7 @@ public: protected: std::string GetName() const override { return "VertexLoaderX64"; } - bool IsInitialized() override; + bool IsInitialized() override { return true; } int RunVertices(DataReader src, DataReader dst, int count, int primitive) override; private: -- cgit v1.2.3 From 9da86092aeb1fda7470a661a36b794d94aa1e38b Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Wed, 18 Mar 2015 11:44:23 +0100 Subject: VertexLoaderX64: use common code for FORMAT_FLOAT --- Source/Core/VideoCommon/VertexLoaderX64.cpp | 42 +++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index a71daba28e..f218befa39 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -65,7 +65,7 @@ OpArg VertexLoaderX64::GetVertexAddr(int array, u64 attribute) int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count_in, int count_out, bool dequantize, u8 scaling_exponent, AttributeFormat* native_format) { - static const __m128i shuffle_lut[5][3] = { + static const __m128i shuffle_lut[4][3] = { {_mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFF00L), // 1x u8 _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFF01L, 0xFFFFFF00L), // 2x u8 _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFF02L, 0xFFFFFF01L, 0xFFFFFF00L)}, // 3x u8 @@ -78,9 +78,6 @@ int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count {_mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0x0001FFFFL), // 1x s16 _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0x0203FFFFL, 0x0001FFFFL), // 2x s16 _mm_set_epi32(0xFFFFFFFFL, 0x0405FFFFL, 0x0203FFFFL, 0x0001FFFFL)}, // 3x s16 - {_mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0x00010203L), // 1x float - _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0x04050607L, 0x00010203L), // 2x float - _mm_set_epi32(0xFFFFFFFFL, 0x08090A0BL, 0x04050607L, 0x00010203L)}, // 3x float }; static const __m128 scale_factors[32] = { _mm_set_ps1(1./(1u<< 0)), _mm_set_ps1(1./(1u<< 1)), _mm_set_ps1(1./(1u<< 2)), _mm_set_ps1(1./(1u<< 3)), @@ -110,6 +107,21 @@ int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count if (attribute == DIRECT) m_src_ofs += load_bytes; + if (format == FORMAT_FLOAT) + { + // Floats don't need to be scaled or converted, + // so we can just load/swap/store them directly + // and return early. + for (int i = 0; i < count_in; i++) + { + LoadAndSwap(32, scratch3, data); + MOV(32, dest, R(scratch3)); + data.offset += sizeof(float); + dest.offset += sizeof(float); + } + return load_bytes; + } + if (cpu_info.bSSSE3) { if (load_bytes > 8) @@ -170,29 +182,13 @@ int VertexLoaderX64::ReadVertex(OpArg data, u64 attribute, int format, int count else PSRLD(coords, 16); break; - case FORMAT_FLOAT: - // Floats don't need to be scaled or converted, - // so we can just load/swap/store them directly - // and return early. - // (In SSSE3 we still need to store them.) - for (int i = 0; i < count_in; i++) - { - LoadAndSwap(32, scratch3, data); - MOV(32, dest, R(scratch3)); - data.offset += sizeof(float); - dest.offset += sizeof(float); - } - return load_bytes; } } - if (format != FORMAT_FLOAT) - { - CVTDQ2PS(coords, R(coords)); + CVTDQ2PS(coords, R(coords)); - if (dequantize && scaling_exponent) - MULPS(coords, M(&scale_factors[scaling_exponent])); - } + if (dequantize && scaling_exponent) + MULPS(coords, M(&scale_factors[scaling_exponent])); switch (count_out) { -- cgit v1.2.3