Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Fix potential crash from binding old CLUT textures #19563

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/Data/Encoding/Shiftjis.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ShiftJIS {
return INVALID;
}
// Intentional fall-through.
[[fallthrough]];
case 0x9:
case 0xE:
row = ((j & 0x3F) << 1) - 0x01;
Expand Down
3 changes: 2 additions & 1 deletion Common/Log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,15 @@ void RingbufferLogListener::Log(const LogMessage &message) {
#ifdef _WIN32

void OutputDebugStringUTF8(const char *p) {
wchar_t temp[16384*4];
wchar_t *temp = new wchar_t[65536];

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

OutputDebugString(temp);
delete[] temp;
}

#else
Expand Down
17 changes: 9 additions & 8 deletions Common/UI/Tween.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <algorithm>
#include <cstdint>
Expand Down Expand Up @@ -65,7 +65,7 @@ template <typename Value>
class TweenBase: public Tween {
public:
TweenBase(float duration, float (*curve)(float) = [](float f) { return f; })
: Tween(duration, curve) {
: Tween(duration, curve), from_{}, to_{} {
}
TweenBase(Value from, Value to, float duration, float (*curve)(float) = [](float f) { return f; })
: Tween(duration, curve), from_(from), to_(to) {
Expand All @@ -77,8 +77,9 @@ class TweenBase: public Tween {
void Divert(const Value &newTo, float newDuration = -1.0f) {
const Value newFrom = valid_ ? Current(Position()) : newTo;

double now = time_now_d();
// Are we already part way through another transition?
if (time_now_d() < start_ + delay_ + duration_ && valid_) {
if (now < start_ + delay_ + duration_ && valid_) {
if (newTo == to_) {
// Already on course. Don't change.
return;
Expand All @@ -88,17 +89,17 @@ class TweenBase: public Tween {
if (newDuration >= 0.0f) {
newOffset *= newDuration / duration_;
}
start_ = time_now_d() - newOffset - delay_;
} else if (time_now_d() <= start_ + delay_) {
start_ = now - newOffset - delay_;
} else if (now <= start_ + delay_) {
// Start the delay over again.
start_ = time_now_d();
start_ = now;
} else {
// Since we've partially animated to the other value, skip delay.
start_ = time_now_d() - delay_;
start_ = now - delay_;
}
} else {
// Already finished, so restart.
start_ = time_now_d();
start_ = now;
finishApplied_ = false;
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ std::set<std::string> SavedataParam::GetSecureFileNames(const std::string &dirPa

std::set<std::string> secureFileNames;
for (const auto &entry : entries) {
char temp[14];
char temp[14]{};
truncate_cpy(temp, entry.filename);
secureFileNames.insert(temp);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ static int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCode

if (PSP_CoreParameter().compat.flags().Fontltn12Hack && requestedStyle->fontLanguage == 2) {
for (size_t j = 0; j < internalFonts.size(); j++) {
const auto tempmatchStyle = internalFonts[j]->GetFontStyle();
const auto &tempmatchStyle = internalFonts[j]->GetFontStyle();
const std::string str(tempmatchStyle.fontFileName);
if (str == "ltn12.pgf") {
optimumFont = internalFonts[j];
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class IRWriter {
insts_ = w.insts_;
return *this;
}
IRWriter &operator =(IRWriter &&w) {
IRWriter &operator =(IRWriter &&w) noexcept {
insts_ = std::move(w.insts_);
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRJit.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IRBlock {
IRBlock() {}
IRBlock(u32 emAddr, u32 origSize, int instOffset, u32 numInstructions)
: origAddr_(emAddr), origSize_(origSize), arenaOffset_(instOffset), numIRInstructions_(numInstructions) {}
IRBlock(IRBlock &&b) {
IRBlock(IRBlock &&b) noexcept {
arenaOffset_ = b.arenaOffset_;
hash_ = b.hash_;
origAddr_ = b.origAddr_;
Expand Down
2 changes: 2 additions & 0 deletions Core/MIPS/MIPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ void MIPSState::Init() {
nextPC = 0;
downcount = 0;

memset(vcmpResult, 0, sizeof(vcmpResult));

std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
if (PSP_CoreParameter().cpuCore == CPUCore::JIT || PSP_CoreParameter().cpuCore == CPUCore::JIT_IR) {
MIPSComp::jit = MIPSComp::CreateNativeJit(this, PSP_CoreParameter().cpuCore == CPUCore::JIT_IR);
Expand Down
4 changes: 4 additions & 0 deletions Core/MIPS/MIPSIntVFPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,9 +961,11 @@ namespace MIPSInt
case V_Triple:
sz = V_Pair;
// Intentional fallthrough.
[[fallthrough]];
case V_Pair:
oz = V_Quad;
// Intentional fallthrough.
[[fallthrough]];
case V_Single:
for (int i = 0; i < GetNumVectorElements(sz); i++) {
u32 value = s[i];
Expand All @@ -985,9 +987,11 @@ namespace MIPSInt
case V_Triple:
sz = V_Pair;
// Intentional fallthrough.
[[fallthrough]];
case V_Pair:
oz = V_Quad;
// Intentional fallthrough.
[[fallthrough]];
case V_Single:
for (int i = 0; i < GetNumVectorElements(sz); i++) {
u32 value = s[i];
Expand Down
4 changes: 0 additions & 4 deletions Core/Util/BlockAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

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

BlockAllocator::BlockAllocator(int grain) : bottom_(NULL), top_(NULL), grain_(grain)
{
}

BlockAllocator::~BlockAllocator()
{
Shutdown();
Expand Down
15 changes: 7 additions & 8 deletions Core/Util/BlockAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PointerWrap;
class BlockAllocator
{
public:
BlockAllocator(int grain = 16); // 16 byte granularity by default.
BlockAllocator(int grain = 16) : grain_(grain) {} // 16 byte granularity by default.
~BlockAllocator();

void Init(u32 _rangeStart, u32 _rangeSize, bool suballoc);
Expand Down Expand Up @@ -59,8 +59,7 @@ class BlockAllocator
private:
void CheckBlocks() const;

struct Block
{
struct Block {
Block(u32 _start, u32 _size, bool _taken, Block *_prev, Block *_next);
void SetAllocated(const char *_tag, bool suballoc);
void DoState(PointerWrap &p);
Expand All @@ -72,13 +71,13 @@ class BlockAllocator
Block *next;
};

Block *bottom_;
Block *top_;
u32 rangeStart_;
u32 rangeSize_;
Block *bottom_ = nullptr;
Block *top_ = nullptr;
u32 rangeStart_ = 0;
u32 rangeSize_ = 0;

u32 grain_;
bool suballoc_;
bool suballoc_ = false;

void MergeFreeBlocks(Block *fromBlock);
Block *GetBlockFromAddress(u32 addr);
Expand Down
4 changes: 2 additions & 2 deletions Core/Util/DisArm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static void DataProcessingRegister(uint32_t w, uint64_t addr, Instruction *instr
int opcode2 = (w >> 16) & 0x1F;
int opcode = (w >> 10) & 0x3F;
// Data-processing (1 source)
const char *opname[8] = { "rbit", "rev16", "rev32", "(unk)", "clz", "cls" };
const char *opname[64] = { "rbit", "rev16", "rev32", "(unk)", "clz", "cls" };
const char *op = opcode2 >= 8 ? "unk" : opname[opcode];
snprintf(instr->text, sizeof(instr->text), "%s %c%d, %c%d", op, r, Rd, r, Rn);
} else if (((w >> 21) & 0x2FF) == 0x0D6) {
Expand Down Expand Up @@ -749,7 +749,7 @@ static void FPandASIMD1(uint32_t w, uint64_t addr, Instruction *instr) {
int dst_index = imm5 >> (size + 1);
int src_index = imm4 >> size;
int op = (w >> 29) & 1;
char s;
char s = '_';
switch (size) {
case 0x00: s = 'b'; break;
case 0x01: s = 'h'; break;
Expand Down
4 changes: 2 additions & 2 deletions Core/Util/GameDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class VFSInterface;
struct GameDBInfo {
std::string title;
std::string foreignTitle;
uint32_t crc;
uint64_t size;
uint32_t crc = 0;
uint64_t size = 0;
};

class GameDB {
Expand Down
1 change: 1 addition & 0 deletions GPU/Common/DrawEngineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) {
transformedExpanded_ = (TransformedVertex *)AllocateMemoryPages(3 * TRANSFORMED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
decoded_ = (u8 *)AllocateMemoryPages(DECODED_VERTEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
decIndex_ = (u16 *)AllocateMemoryPages(DECODED_INDEX_BUFFER_SIZE, MEM_PROT_READ | MEM_PROT_WRITE);
indexGen.Setup(decIndex_);
}

DrawEngineCommon::~DrawEngineCommon() {
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,8 +1911,8 @@ void FramebufferManagerCommon::ResizeFramebufFBO(VirtualFramebuffer *vfb, int w,

struct CopyCandidate {
VirtualFramebuffer *vfb = nullptr;
int y;
int h;
int y = 0;
int h = 0;

std::string ToString(RasterChannel channel) const {
return StringFromFormat("%08x %s %dx%d y=%d h=%d", vfb->Address(channel), GeBufferFormatToString(vfb->Format(channel)), vfb->width, vfb->height, y, h);
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/GPUStateUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool IsAlphaTestTriviallyTrue() {
return false;
}
// Fallthrough on purpose

[[fallthrough]];
case GE_COMP_GREATER:
{
// If the texture and vertex only use 1.0 alpha, then the ref value doesn't matter.
Expand Down
5 changes: 0 additions & 5 deletions GPU/Common/IndexGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ const u8 IndexGenerator::indexedPrimitiveType[7] = {
GE_PRIM_RECTANGLES,
};

void IndexGenerator::Setup(u16 *inds) {
this->indsBase_ = inds;
Reset();
}

void IndexGenerator::AddPrim(int prim, int vertexCount, int indexOffset, bool clockwise) {
switch (prim) {
case GE_PRIM_POINTS: AddPoints(vertexCount, indexOffset); break;
Expand Down
7 changes: 5 additions & 2 deletions GPU/Common/IndexGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

class IndexGenerator {
public:
void Setup(u16 *indexptr);
void Setup(u16 *indexptr) {
indsBase_ = indexptr;
inds_ = indexptr;
}
void Reset() {
this->inds_ = indsBase_;
inds_ = indsBase_;
}

static bool PrimCompatible(int prim1, int prim2) {
Expand Down
1 change: 1 addition & 0 deletions GPU/Common/TextureShaderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void TextureShaderCache::Decimate() {
++tex;
}
}
gpuStats.numClutTextures = (int)texCache_.size();
}

Draw2DPipeline *TextureShaderCache::GetDepalettizeShader(uint32_t clutMode, GETextureFormat textureFormat, GEBufferFormat bufferFormat, bool smoothedDepal, u32 depthUpperBits) {
Expand Down
1 change: 0 additions & 1 deletion GPU/Common/TextureShaderCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "GPU/Common/Draw2D.h"
#include "GPU/Common/ShaderCommon.h"


class ClutTexture {
public:
enum { MAX_RAMPS = 3 };
Expand Down
9 changes: 0 additions & 9 deletions GPU/D3D11/DrawEngineD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ DrawEngineD3D11::DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device,
decOptions_.expandAllWeightsToFloat = true;
decOptions_.expand8BitNormalsToFloat = true;

// Allocate nicely aligned memory. Maybe graphics drivers will
// appreciate it.
// All this is a LOT of memory, need to see if we can cut down somehow.
indexGen.Setup(decIndex_);

InitDeviceObjects();

// Vertex pushing buffers. For uniforms we use short DISCARD buffers, but we could use
// this kind of buffer there as well with D3D11.1. We might be able to use the same buffer
// for both vertices and indices, and possibly all three data types.
}

DrawEngineD3D11::~DrawEngineD3D11() {
Expand Down
2 changes: 0 additions & 2 deletions GPU/Directx9/DrawEngineDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ DrawEngineDX9::DrawEngineDX9(Draw::DrawContext *draw) : draw_(draw), vertexDeclM
decOptions_.expandAllWeightsToFloat = true;
decOptions_.expand8BitNormalsToFloat = true;

indexGen.Setup(decIndex_);

InitDeviceObjects();

tessDataTransferDX9 = new TessellationDataTransferDX9();
Expand Down
2 changes: 0 additions & 2 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ DrawEngineGLES::DrawEngineGLES(Draw::DrawContext *draw) : inputLayoutMap_(16), d
decOptions_.expandAllWeightsToFloat = false;
decOptions_.expand8BitNormalsToFloat = false;

indexGen.Setup(decIndex_);

InitDeviceObjects();

tessDataTransferGLES = new TessellationDataTransferGLES(render_);
Expand Down
2 changes: 2 additions & 0 deletions GPU/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct GPUStatistics {
numBlockTransfers = 0;
numReplacerTrackedTex = 0;
numCachedReplacedTextures = 0;
numClutTextures = 0;
msProcessingDisplayLists = 0;
vertexGPUCycles = 0;
otherGPUCycles = 0;
Expand Down Expand Up @@ -142,6 +143,7 @@ struct GPUStatistics {
int numBlockTransfers;
int numReplacerTrackedTex;
int numCachedReplacedTextures;
int numClutTextures;
double msProcessingDisplayLists;
int vertexGPUCycles;
int otherGPUCycles;
Expand Down
3 changes: 2 additions & 1 deletion GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
"Draw: %d (%d dec, %d culled), flushes %d, clears %d, bbox jumps %d (%d updates)\n"
"Vertices: %d dec: %d drawn: %d\n"
"FBOs active: %d (evaluations: %d)\n"
"Textures: %d, dec: %d, invalidated: %d, hashed: %d kB\n"
"Textures: %d, dec: %d, invalidated: %d, hashed: %d kB, clut %d\n"
"readbacks %d (%d non-block), upload %d (cached %d), depal %d\n"
"block transfers: %d\n"
"replacer: tracks %d references, %d unique textures\n"
Expand All @@ -1781,6 +1781,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) {
gpuStats.numTexturesDecoded,
gpuStats.numTextureInvalidations,
gpuStats.numTextureDataBytesHashed / 1024,
gpuStats.numClutTextures,
gpuStats.numBlockingReadbacks,
gpuStats.numReadbacks,
gpuStats.numUploads,
Expand Down
5 changes: 4 additions & 1 deletion GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ DrawEngineVulkan::DrawEngineVulkan(Draw::DrawContext *draw)
: draw_(draw) {
decOptions_.expandAllWeightsToFloat = false;
decOptions_.expand8BitNormalsToFloat = false;
indexGen.Setup(decIndex_);
}

void DrawEngineVulkan::InitDeviceObjects() {
Expand Down Expand Up @@ -167,6 +166,10 @@ void DrawEngineVulkan::DeviceRestore(Draw::DrawContext *draw) {
void DrawEngineVulkan::BeginFrame() {
lastPipeline_ = nullptr;

// These will be re-bound if needed, let's not let old bindings linger around too long.
boundDepal_ = VK_NULL_HANDLE;
boundSecondary_ = VK_NULL_HANDLE;

// pushUBO is the thin3d push pool, don't need to BeginFrame again.
pushVertex_->BeginFrame();
pushIndex_->BeginFrame();
Expand Down
2 changes: 1 addition & 1 deletion ext/riscv-disas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ static void decode_inst_operands(rv_decode *dec)

static void decode_inst_decompress(rv_decode *dec, rv_isa isa)
{
int decomp_op;
int decomp_op = 0;
switch (isa) {
case rv32: decomp_op = opcode_data[dec->op].decomp_rv32; break;
case rv64: decomp_op = opcode_data[dec->op].decomp_rv64; break;
Expand Down
Loading