Skip to content

Commit fdab5cb

Browse files
authored
Merge pull request #19563 from hrydgard/even-more-misc-fixes
Vulkan: Fix potential crash from binding old CLUT textures
2 parents ffb3e61 + ab10722 commit fdab5cb

27 files changed

+52
-56
lines changed

Common/Data/Encoding/Shiftjis.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ShiftJIS {
2020
return INVALID;
2121
}
2222
// Intentional fall-through.
23+
[[fallthrough]];
2324
case 0x9:
2425
case 0xE:
2526
row = ((j & 0x3F) << 1) - 0x01;

Common/Log/LogManager.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ void RingbufferLogListener::Log(const LogMessage &message) {
363363
#ifdef _WIN32
364364

365365
void OutputDebugStringUTF8(const char *p) {
366-
wchar_t temp[16384*4];
366+
wchar_t *temp = new wchar_t[65536];
367367

368368
int len = std::min(16383*4, (int)strlen(p));
369369
int size = (int)MultiByteToWideChar(CP_UTF8, 0, p, len, NULL, 0);
370370
MultiByteToWideChar(CP_UTF8, 0, p, len, temp, size);
371371
temp[size] = 0;
372372

373373
OutputDebugString(temp);
374+
delete[] temp;
374375
}
375376

376377
#else

Common/UI/Tween.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include <algorithm>
44
#include <cstdint>
@@ -65,7 +65,7 @@ template <typename Value>
6565
class TweenBase: public Tween {
6666
public:
6767
TweenBase(float duration, float (*curve)(float) = [](float f) { return f; })
68-
: Tween(duration, curve) {
68+
: Tween(duration, curve), from_{}, to_{} {
6969
}
7070
TweenBase(Value from, Value to, float duration, float (*curve)(float) = [](float f) { return f; })
7171
: Tween(duration, curve), from_(from), to_(to) {
@@ -77,8 +77,9 @@ class TweenBase: public Tween {
7777
void Divert(const Value &newTo, float newDuration = -1.0f) {
7878
const Value newFrom = valid_ ? Current(Position()) : newTo;
7979

80+
double now = time_now_d();
8081
// Are we already part way through another transition?
81-
if (time_now_d() < start_ + delay_ + duration_ && valid_) {
82+
if (now < start_ + delay_ + duration_ && valid_) {
8283
if (newTo == to_) {
8384
// Already on course. Don't change.
8485
return;
@@ -88,17 +89,17 @@ class TweenBase: public Tween {
8889
if (newDuration >= 0.0f) {
8990
newOffset *= newDuration / duration_;
9091
}
91-
start_ = time_now_d() - newOffset - delay_;
92-
} else if (time_now_d() <= start_ + delay_) {
92+
start_ = now - newOffset - delay_;
93+
} else if (now <= start_ + delay_) {
9394
// Start the delay over again.
94-
start_ = time_now_d();
95+
start_ = now;
9596
} else {
9697
// Since we've partially animated to the other value, skip delay.
97-
start_ = time_now_d() - delay_;
98+
start_ = now - delay_;
9899
}
99100
} else {
100101
// Already finished, so restart.
101-
start_ = time_now_d();
102+
start_ = now;
102103
finishApplied_ = false;
103104
}
104105

Core/Dialog/SavedataParam.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ std::set<std::string> SavedataParam::GetSecureFileNames(const std::string &dirPa
883883

884884
std::set<std::string> secureFileNames;
885885
for (const auto &entry : entries) {
886-
char temp[14];
886+
char temp[14]{};
887887
truncate_cpy(temp, entry.filename);
888888
secureFileNames.insert(temp);
889889
}

Core/HLE/sceFont.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ static int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCode
12081208

12091209
if (PSP_CoreParameter().compat.flags().Fontltn12Hack && requestedStyle->fontLanguage == 2) {
12101210
for (size_t j = 0; j < internalFonts.size(); j++) {
1211-
const auto tempmatchStyle = internalFonts[j]->GetFontStyle();
1211+
const auto &tempmatchStyle = internalFonts[j]->GetFontStyle();
12121212
const std::string str(tempmatchStyle.fontFileName);
12131213
if (str == "ltn12.pgf") {
12141214
optimumFont = internalFonts[j];

Core/MIPS/IR/IRInst.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class IRWriter {
379379
insts_ = w.insts_;
380380
return *this;
381381
}
382-
IRWriter &operator =(IRWriter &&w) {
382+
IRWriter &operator =(IRWriter &&w) noexcept {
383383
insts_ = std::move(w.insts_);
384384
return *this;
385385
}

Core/MIPS/IR/IRJit.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class IRBlock {
5151
IRBlock() {}
5252
IRBlock(u32 emAddr, u32 origSize, int instOffset, u32 numInstructions)
5353
: origAddr_(emAddr), origSize_(origSize), arenaOffset_(instOffset), numIRInstructions_(numInstructions) {}
54-
IRBlock(IRBlock &&b) {
54+
IRBlock(IRBlock &&b) noexcept {
5555
arenaOffset_ = b.arenaOffset_;
5656
hash_ = b.hash_;
5757
origAddr_ = b.origAddr_;

Core/MIPS/MIPS.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ void MIPSState::Init() {
207207
nextPC = 0;
208208
downcount = 0;
209209

210+
memset(vcmpResult, 0, sizeof(vcmpResult));
211+
210212
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
211213
if (PSP_CoreParameter().cpuCore == CPUCore::JIT || PSP_CoreParameter().cpuCore == CPUCore::JIT_IR) {
212214
MIPSComp::jit = MIPSComp::CreateNativeJit(this, PSP_CoreParameter().cpuCore == CPUCore::JIT_IR);

Core/MIPS/MIPSIntVFPU.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,11 @@ namespace MIPSInt
961961
case V_Triple:
962962
sz = V_Pair;
963963
// Intentional fallthrough.
964+
[[fallthrough]];
964965
case V_Pair:
965966
oz = V_Quad;
966967
// Intentional fallthrough.
968+
[[fallthrough]];
967969
case V_Single:
968970
for (int i = 0; i < GetNumVectorElements(sz); i++) {
969971
u32 value = s[i];
@@ -985,9 +987,11 @@ namespace MIPSInt
985987
case V_Triple:
986988
sz = V_Pair;
987989
// Intentional fallthrough.
990+
[[fallthrough]];
988991
case V_Pair:
989992
oz = V_Quad;
990993
// Intentional fallthrough.
994+
[[fallthrough]];
991995
case V_Single:
992996
for (int i = 0; i < GetNumVectorElements(sz); i++) {
993997
u32 value = s[i];

Core/Util/BlockAllocator.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
// Slow freaking thing but works (eventually) :)
2929

30-
BlockAllocator::BlockAllocator(int grain) : bottom_(NULL), top_(NULL), grain_(grain)
31-
{
32-
}
33-
3430
BlockAllocator::~BlockAllocator()
3531
{
3632
Shutdown();

Core/Util/BlockAllocator.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PointerWrap;
2424
class BlockAllocator
2525
{
2626
public:
27-
BlockAllocator(int grain = 16); // 16 byte granularity by default.
27+
BlockAllocator(int grain = 16) : grain_(grain) {} // 16 byte granularity by default.
2828
~BlockAllocator();
2929

3030
void Init(u32 _rangeStart, u32 _rangeSize, bool suballoc);
@@ -59,8 +59,7 @@ class BlockAllocator
5959
private:
6060
void CheckBlocks() const;
6161

62-
struct Block
63-
{
62+
struct Block {
6463
Block(u32 _start, u32 _size, bool _taken, Block *_prev, Block *_next);
6564
void SetAllocated(const char *_tag, bool suballoc);
6665
void DoState(PointerWrap &p);
@@ -72,13 +71,13 @@ class BlockAllocator
7271
Block *next;
7372
};
7473

75-
Block *bottom_;
76-
Block *top_;
77-
u32 rangeStart_;
78-
u32 rangeSize_;
74+
Block *bottom_ = nullptr;
75+
Block *top_ = nullptr;
76+
u32 rangeStart_ = 0;
77+
u32 rangeSize_ = 0;
7978

8079
u32 grain_;
81-
bool suballoc_;
80+
bool suballoc_ = false;
8281

8382
void MergeFreeBlocks(Block *fromBlock);
8483
Block *GetBlockFromAddress(u32 addr);

Core/Util/DisArm64.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static void DataProcessingRegister(uint32_t w, uint64_t addr, Instruction *instr
418418
int opcode2 = (w >> 16) & 0x1F;
419419
int opcode = (w >> 10) & 0x3F;
420420
// Data-processing (1 source)
421-
const char *opname[8] = { "rbit", "rev16", "rev32", "(unk)", "clz", "cls" };
421+
const char *opname[64] = { "rbit", "rev16", "rev32", "(unk)", "clz", "cls" };
422422
const char *op = opcode2 >= 8 ? "unk" : opname[opcode];
423423
snprintf(instr->text, sizeof(instr->text), "%s %c%d, %c%d", op, r, Rd, r, Rn);
424424
} else if (((w >> 21) & 0x2FF) == 0x0D6) {
@@ -749,7 +749,7 @@ static void FPandASIMD1(uint32_t w, uint64_t addr, Instruction *instr) {
749749
int dst_index = imm5 >> (size + 1);
750750
int src_index = imm4 >> size;
751751
int op = (w >> 29) & 1;
752-
char s;
752+
char s = '_';
753753
switch (size) {
754754
case 0x00: s = 'b'; break;
755755
case 0x01: s = 'h'; break;

Core/Util/GameDB.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class VFSInterface;
1212
struct GameDBInfo {
1313
std::string title;
1414
std::string foreignTitle;
15-
uint32_t crc;
16-
uint64_t size;
15+
uint32_t crc = 0;
16+
uint64_t size = 0;
1717
};
1818

1919
class GameDB {

GPU/Common/DrawEngineCommon.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) {
4444
transformedExpanded_ = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
4545
decoded_ = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
4646
decIndex_ = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
47+
indexGen.Setup(decIndex_);
4748
}
4849

4950
DrawEngineCommon::~DrawEngineCommon() {

GPU/Common/FramebufferManagerCommon.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,8 @@ void FramebufferManagerCommon::ResizeFramebufFBO(VirtualFramebuffer *vfb, int w,
19111911

19121912
struct CopyCandidate {
19131913
VirtualFramebuffer *vfb = nullptr;
1914-
int y;
1915-
int h;
1914+
int y = 0;
1915+
int h = 0;
19161916

19171917
std::string ToString(RasterChannel channel) const {
19181918
return StringFromFormat("%08x %s %dx%d y=%d h=%d", vfb->Address(channel), GeBufferFormatToString(vfb->Format(channel)), vfb->width, vfb->height, y, h);

GPU/Common/GPUStateUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool IsAlphaTestTriviallyTrue() {
9191
return false;
9292
}
9393
// Fallthrough on purpose
94-
94+
[[fallthrough]];
9595
case GE_COMP_GREATER:
9696
{
9797
// If the texture and vertex only use 1.0 alpha, then the ref value doesn't matter.

GPU/Common/IndexGenerator.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ const u8 IndexGenerator::indexedPrimitiveType[7] = {
4848
GE_PRIM_RECTANGLES,
4949
};
5050

51-
void IndexGenerator::Setup(u16 *inds) {
52-
this->indsBase_ = inds;
53-
Reset();
54-
}
55-
5651
void IndexGenerator::AddPrim(int prim, int vertexCount, int indexOffset, bool clockwise) {
5752
switch (prim) {
5853
case GE_PRIM_POINTS: AddPoints(vertexCount, indexOffset); break;

GPU/Common/IndexGenerator.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424

2525
class IndexGenerator {
2626
public:
27-
void Setup(u16 *indexptr);
27+
void Setup(u16 *indexptr) {
28+
indsBase_ = indexptr;
29+
inds_ = indexptr;
30+
}
2831
void Reset() {
29-
this->inds_ = indsBase_;
32+
inds_ = indsBase_;
3033
}
3134

3235
static bool PrimCompatible(int prim1, int prim2) {

GPU/Common/TextureShaderCommon.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ void TextureShaderCache::Decimate() {
194194
++tex;
195195
}
196196
}
197+
gpuStats.numClutTextures = (int)texCache_.size();
197198
}
198199

199200
Draw2DPipeline *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETextureFormat textureFormat, GEBufferFormat bufferFormat, bool smoothedDepal, u32 depthUpperBits) {

GPU/Common/TextureShaderCommon.h

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "GPU/Common/Draw2D.h"
2828
#include "GPU/Common/ShaderCommon.h"
2929

30-
3130
class ClutTexture {
3231
public:
3332
enum { MAX_RAMPS = 3 };

GPU/D3D11/DrawEngineD3D11.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,7 @@ DrawEngineD3D11::DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device,
8080
decOptions_.expandAllWeightsToFloat = true;
8181
decOptions_.expand8BitNormalsToFloat = true;
8282

83-
// Allocate nicely aligned memory. Maybe graphics drivers will
84-
// appreciate it.
85-
// All this is a LOT of memory, need to see if we can cut down somehow.
86-
indexGen.Setup(decIndex_);
87-
8883
InitDeviceObjects();
89-
90-
// Vertex pushing buffers. For uniforms we use short DISCARD buffers, but we could use
91-
// this kind of buffer there as well with D3D11.1. We might be able to use the same buffer
92-
// for both vertices and indices, and possibly all three data types.
9384
}
9485

9586
DrawEngineD3D11::~DrawEngineD3D11() {

GPU/Directx9/DrawEngineDX9.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ DrawEngineDX9::DrawEngineDX9(Draw::DrawContext *draw) : draw_(draw), vertexDeclM
8989
decOptions_.expandAllWeightsToFloat = true;
9090
decOptions_.expand8BitNormalsToFloat = true;
9191

92-
indexGen.Setup(decIndex_);
93-
9492
InitDeviceObjects();
9593

9694
tessDataTransferDX9 = new TessellationDataTransferDX9();

GPU/GLES/DrawEngineGLES.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ DrawEngineGLES::DrawEngineGLES(Draw::DrawContext *draw) : inputLayoutMap_(16), d
6767
decOptions_.expandAllWeightsToFloat = false;
6868
decOptions_.expand8BitNormalsToFloat = false;
6969

70-
indexGen.Setup(decIndex_);
71-
7270
InitDeviceObjects();
7371

7472
tessDataTransferGLES = new TessellationDataTransferGLES(render_);

GPU/GPU.h

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct GPUStatistics {
105105
numBlockTransfers = 0;
106106
numReplacerTrackedTex = 0;
107107
numCachedReplacedTextures = 0;
108+
numClutTextures = 0;
108109
msProcessingDisplayLists = 0;
109110
vertexGPUCycles = 0;
110111
otherGPUCycles = 0;
@@ -142,6 +143,7 @@ struct GPUStatistics {
142143
int numBlockTransfers;
143144
int numReplacerTrackedTex;
144145
int numCachedReplacedTextures;
146+
int numClutTextures;
145147
double msProcessingDisplayLists;
146148
int vertexGPUCycles;
147149
int otherGPUCycles;

GPU/GPUCommonHW.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
17561756
"Draw: %d (%d dec, %d culled), flushes %d, clears %d, bbox jumps %d (%d updates)\n"
17571757
"Vertices: %d dec: %d drawn: %d\n"
17581758
"FBOs active: %d (evaluations: %d)\n"
1759-
"Textures: %d, dec: %d, invalidated: %d, hashed: %d kB\n"
1759+
"Textures: %d, dec: %d, invalidated: %d, hashed: %d kB, clut %d\n"
17601760
"readbacks %d (%d non-block), upload %d (cached %d), depal %d\n"
17611761
"block transfers: %d\n"
17621762
"replacer: tracks %d references, %d unique textures\n"
@@ -1781,6 +1781,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
17811781
gpuStats.numTexturesDecoded,
17821782
gpuStats.numTextureInvalidations,
17831783
gpuStats.numTextureDataBytesHashed / 1024,
1784+
gpuStats.numClutTextures,
17841785
gpuStats.numBlockingReadbacks,
17851786
gpuStats.numReadbacks,
17861787
gpuStats.numUploads,

GPU/Vulkan/DrawEngineVulkan.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ DrawEngineVulkan::DrawEngineVulkan(Draw::DrawContext *draw)
6262
: draw_(draw) {
6363
decOptions_.expandAllWeightsToFloat = false;
6464
decOptions_.expand8BitNormalsToFloat = false;
65-
indexGen.Setup(decIndex_);
6665
}
6766

6867
void DrawEngineVulkan::InitDeviceObjects() {
@@ -167,6 +166,10 @@ void DrawEngineVulkan::DeviceRestore(Draw::DrawContext *draw) {
167166
void DrawEngineVulkan::BeginFrame() {
168167
lastPipeline_ = nullptr;
169168

169+
// These will be re-bound if needed, let's not let old bindings linger around too long.
170+
boundDepal_ = VK_NULL_HANDLE;
171+
boundSecondary_ = VK_NULL_HANDLE;
172+
170173
// pushUBO is the thin3d push pool, don't need to BeginFrame again.
171174
pushVertex_->BeginFrame();
172175
pushIndex_->BeginFrame();

ext/riscv-disas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ static void decode_inst_operands(rv_decode *dec)
22332233

22342234
static void decode_inst_decompress(rv_decode *dec, rv_isa isa)
22352235
{
2236-
int decomp_op;
2236+
int decomp_op = 0;
22372237
switch (isa) {
22382238
case rv32: decomp_op = opcode_data[dec->op].decomp_rv32; break;
22392239
case rv64: decomp_op = opcode_data[dec->op].decomp_rv64; break;

0 commit comments

Comments
 (0)