diff --git a/Common/ColorConvNEON.cpp b/Common/ColorConvNEON.cpp index c5d6fb0213..f54a5b225d 100644 --- a/Common/ColorConvNEON.cpp +++ b/Common/ColorConvNEON.cpp @@ -28,26 +28,29 @@ void ConvertRGBA4444ToABGR4444NEON(u16 *dst, const u16 *src, const u32 numPixels) { const uint16x8_t mask0040 = vdupq_n_u16(0x00F0); - u32 simdable = (numPixels / 8) * 8; - const u16 *srcp = src; - u16 *dstp = dst; - for (u32 i = 0; i < simdable; i += 8) { - uint16x8_t c = vld1q_u16(srcp); + if (((uintptr_t)dst & 15) == 0 && ((uintptr_t)src & 15) == 0) { + u32 simdable = (numPixels / 8) * 8; + const u16 *srcp = src; + u16 *dstp = dst; + for (u32 i = 0; i < simdable; i += 8) { + uint16x8_t c = vld1q_u16(srcp); - const uint16x8_t a = vshrq_n_u16(c, 12); - const uint16x8_t b = vandq_u16(vshrq_n_u16(c, 4), mask0040); - const uint16x8_t g = vshlq_n_u16(vandq_u16(c, mask0040), 4); - const uint16x8_t r = vshlq_n_u16(c, 12); + const uint16x8_t a = vshrq_n_u16(c, 12); + const uint16x8_t b = vandq_u16(vshrq_n_u16(c, 4), mask0040); + const uint16x8_t g = vshlq_n_u16(vandq_u16(c, mask0040), 4); + const uint16x8_t r = vshlq_n_u16(c, 12); - uint16x8_t res = vorrq_u16(vorrq_u16(r, g), vorrq_u16(b, a)); - vst1q_u16(dstp, res); + uint16x8_t res = vorrq_u16(vorrq_u16(r, g), vorrq_u16(b, a)); + vst1q_u16(dstp, res); - srcp += 8; - dstp += 8; + srcp += 8; + dstp += 8; + } + numPixels -= simdable; } // Finish off the rest, if there were any outside the simdable range. - if (numPixels > simdable) { + if (numPixels > 0) { // Note that we've already moved srcp/dstp forward. ConvertRGBA4444ToABGR4444Basic(dstp, srcp, numPixels - simdable); } @@ -57,55 +60,60 @@ void ConvertRGBA5551ToABGR1555NEON(u16 *dst, const u16 *src, const u32 numPixels const uint16x8_t maskB = vdupq_n_u16(0x003E); const uint16x8_t maskG = vdupq_n_u16(0x07C0); - u32 simdable = (numPixels / 8) * 8; - const u16 *srcp = src; - u16 *dstp = dst; - for (u32 i = 0; i < simdable; i += 8) { - uint16x8_t c = vld1q_u16(srcp); + if (((uintptr_t)dst & 15) == 0 && ((uintptr_t)src & 15) == 0) { + u32 simdable = (numPixels / 8) * 8; + const u16 *srcp = src; + u16 *dstp = dst; + for (u32 i = 0; i < simdable; i += 8) { + uint16x8_t c = vld1q_u16(srcp); - const uint16x8_t a = vshrq_n_u16(c, 15); - const uint16x8_t b = vandq_u16(vshrq_n_u16(c, 9), maskB); - const uint16x8_t g = vandq_u16(vshlq_n_u16(c, 1), maskG); - const uint16x8_t r = vshlq_n_u16(c, 11); + const uint16x8_t a = vshrq_n_u16(c, 15); + const uint16x8_t b = vandq_u16(vshrq_n_u16(c, 9), maskB); + const uint16x8_t g = vandq_u16(vshlq_n_u16(c, 1), maskG); + const uint16x8_t r = vshlq_n_u16(c, 11); - uint16x8_t res = vorrq_u16(vorrq_u16(r, g), vorrq_u16(b, a)); - vst1q_u16(dstp, res); + uint16x8_t res = vorrq_u16(vorrq_u16(r, g), vorrq_u16(b, a)); + vst1q_u16(dstp, res); - srcp += 8; - dstp += 8; + srcp += 8; + dstp += 8; + } + numPixels -= simdable; } // Finish off the rest, if there were any outside the simdable range. - if (numPixels > simdable) { + if (numPixels > 0) { // Note that we've already moved srcp/dstp forward. - ConvertRGBA5551ToABGR1555Basic(dstp, srcp, numPixels - simdable); + ConvertRGBA5551ToABGR1555Basic(dstp, srcp, numPixels); } } void ConvertRGB565ToBGR565NEON(u16 *dst, const u16 *src, const u32 numPixels) { const uint16x8_t maskG = vdupq_n_u16(0x07E0); - u32 simdable = (numPixels / 8) * 8; - const u16 *srcp = src; - u16 *dstp = dst; - for (u32 i = 0; i < simdable; i += 8) { - uint16x8_t c = vld1q_u16(srcp); + if (((uintptr_t)dst & 15) == 0 && ((uintptr_t)src & 15) == 0) { + u32 simdable = (numPixels / 8) * 8; + const u16 *srcp = src; + u16 *dstp = dst; + for (u32 i = 0; i < simdable; i += 8) { + uint16x8_t c = vld1q_u16(srcp); - const uint16x8_t b = vshrq_n_u16(c, 11); - const uint16x8_t g = vandq_u16(c, maskG); - const uint16x8_t r = vshlq_n_u16(c, 11); + const uint16x8_t b = vshrq_n_u16(c, 11); + const uint16x8_t g = vandq_u16(c, maskG); + const uint16x8_t r = vshlq_n_u16(c, 11); - uint16x8_t res = vorrq_u16(vorrq_u16(r, g), b); - vst1q_u16(dstp, res); + uint16x8_t res = vorrq_u16(vorrq_u16(r, g), b); + vst1q_u16(dstp, res); - srcp += 8; - dstp += 8; + srcp += 8; + dstp += 8; + } + numPixels -= simdable; } - // Finish off the rest, if there were any outside the simdable range. - if (numPixels > simdable) { + if (numPixels > 0) { // Note that we've already moved srcp/dstp forward. - ConvertRGB565ToBGR565Basic(dstp, srcp, numPixels - simdable); + ConvertRGB565ToBGR565Basic(dstp, srcp, numPixels); } } diff --git a/Core/MIPS/IR/IRPassSimplify.cpp b/Core/MIPS/IR/IRPassSimplify.cpp index 487023f8bf..aba843689b 100644 --- a/Core/MIPS/IR/IRPassSimplify.cpp +++ b/Core/MIPS/IR/IRPassSimplify.cpp @@ -10,18 +10,34 @@ void WriteInstWithConstants(const IRWriter &in, IRWriter &out, const u32 *constants, IRInst inst) { // Remap constants to the new reality const IRMeta *m = GetIRMeta(inst.op); + if (!m) { + ERROR_LOG(CPU, "Bad IR instruction %02x", (int)inst.op); + return; + } switch (m->types[0]) { case 'C': + if (!constants) { + ERROR_LOG(CPU, "Missing constant for type 0"); + return; + } inst.dest = out.AddConstant(constants[inst.dest]); break; } switch (m->types[1]) { case 'C': + if (!constants) { + ERROR_LOG(CPU, "Missing constants for type 1"); + return; + } inst.src1 = out.AddConstant(constants[inst.src1]); break; } switch (m->types[2]) { case 'C': + if (!constants) { + ERROR_LOG(CPU, "Missing constants for type 2"); + return; + } inst.src2 = out.AddConstant(constants[inst.src2]); break; } diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index bfae07fbf0..d7d7676512 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -1099,7 +1099,7 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, throughmode = (fmt & GE_VTYPE_THROUGH) != 0; numSteps_ = 0; - int biggest = 0; + biggest = 0; size = 0; tc = fmt & 0x3; @@ -1326,8 +1326,23 @@ void VertexDecoder::DecodeVerts(u8 *decodedptr, const void *verts, int indexLowe int count = indexUpperBound - indexLowerBound + 1; int stride = decFmt.stride; if (jitted_) { + // Check alignment before running the decoder, as we may crash if it's bad (as should the real PSP but doesn't always) + bool bad = false; + if (biggest == 4) { + if (((uintptr_t)verts & 3) != 0) + bad = true; + } else if (biggest == 2) { + if (((uintptr_t)verts & 1) != 0) + bad = true; + } + // We've compiled the steps into optimized machine code, so just jump! - jitted_(ptr_, decoded_, count); + if (!bad) { + jitted_(ptr_, decoded_, count); + } else { + // Not really sure what to do here... zero the verts to be safe? + memset(decodedptr, 0, count * stride); + } } else { // Interpret the decode steps for (; count; count--) { diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 57060f1fc7..b7ec77df63 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -588,6 +588,8 @@ public: u8 morphcount; u8 nweights; + u8 biggest; // in practice, alignment. + friend class VertexDecoderJitCache; }; diff --git a/ext/native/file/chunk_file.cpp b/ext/native/file/chunk_file.cpp index 94e700538a..0544417a33 100644 --- a/ext/native/file/chunk_file.cpp +++ b/ext/native/file/chunk_file.cpp @@ -72,11 +72,14 @@ int ChunkFile::readInt() { void ChunkFile::writeInt(int i) { fwrite(&i, 1, 4, file); - pos+=4; + pos += 4; } //let's get into the business bool ChunkFile::descend(uint32_t id) { + if (numLevels > 30) + return false; + id = flipID(id); if (read) { bool found = false; diff --git a/ext/native/file/chunk_file.h b/ext/native/file/chunk_file.h index 8e1a4756df..f1e9d8f3ee 100644 --- a/ext/native/file/chunk_file.h +++ b/ext/native/file/chunk_file.h @@ -56,7 +56,7 @@ private: unsigned int ID; int length; }; - ChunkInfo stack[8]; + ChunkInfo stack[32]; int numLevels; uint8_t *data; diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index d18130928f..c84e04f614 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -400,12 +400,17 @@ void DrawBuffer::MeasureTextCount(int font, const char *text, int count, float * } void DrawBuffer::MeasureTextRect(int font, const char *text, int count, const Bounds &bounds, float *w, float *h, int align) { + if (!text || (uint32_t)font >= atlas->num_fonts) { + *w = 0; + *h = 0; + return; + } + std::string toMeasure = std::string(text, count); if (align & FLAG_WRAP_TEXT) { AtlasWordWrapper wrapper(*atlas->fonts[font], fontscalex, toMeasure.c_str(), bounds.w); toMeasure = wrapper.Wrapped(); } - MeasureTextCount(font, toMeasure.c_str(), (int)toMeasure.length(), w, h); }