Merge pull request #19563 from hrydgard/even-more-misc-fixes

Vulkan: Fix potential crash from binding old CLUT textures
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2024-10-29 09:04:12 +01:00
commit fdab5cb7bd
27 files changed
+52 -56

No files matched your search

+1
View File
@@ -20,6 +20,7 @@ struct ShiftJIS {
return INVALID;
}
// Intentional fall-through.
[[fallthrough]];
case 0x9:
case 0xE:
row = ((j & 0x3F) << 1) - 0x01;
+2 -1
View File
@@ -363,7 +363,7 @@ 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);
@@ -371,6 +371,7 @@ void OutputDebugStringUTF8(const char *p) {
temp[size] = 0;
OutputDebugString(temp);
delete[] temp;
}
#else
+9 -8
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <algorithm>
#include <cstdint>
@@ -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) {
@@ -77,8 +77,9 @@ public:
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;
@@ -88,17 +89,17 @@ public:
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;
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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];
+1 -1
View File
@@ -379,7 +379,7 @@ public:
insts_ = w.insts_;
return *this;
}
IRWriter &operator =(IRWriter &&w) {
IRWriter &operator =(IRWriter &&w) noexcept {
insts_ = std::move(w.insts_);
return *this;
}
+1 -1
View File
@@ -51,7 +51,7 @@ public:
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_;
+2
View File
@@ -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);
+4
View File
@@ -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];
@@ -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];
-4
View File
@@ -27,10 +27,6 @@
// Slow freaking thing but works (eventually) :)
BlockAllocator::BlockAllocator(int grain) : bottom_(NULL), top_(NULL), grain_(grain)
{
}
BlockAllocator::~BlockAllocator()
{
Shutdown();
+7 -8
View File
@@ -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);
@@ -59,8 +59,7 @@ public:
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);
@@ -72,13 +71,13 @@ private:
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);
+2 -2
View File
@@ -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) {
@@ -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;
+2 -2
View File
@@ -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 {
+1
View File
@@ -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() {
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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.
-5
View File
@@ -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;
+5 -2
View File
@@ -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) {
+1
View File
@@ -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) {
-1
View File
@@ -27,7 +27,6 @@
#include "GPU/Common/Draw2D.h"
#include "GPU/Common/ShaderCommon.h"
class ClutTexture {
public:
enum { MAX_RAMPS = 3 };
-9
View File
@@ -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() {
-2
View File
@@ -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();
-2
View File
@@ -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_);
+2
View File
@@ -105,6 +105,7 @@ struct GPUStatistics {
numBlockTransfers = 0;
numReplacerTrackedTex = 0;
numCachedReplacedTextures = 0;
numClutTextures = 0;
msProcessingDisplayLists = 0;
vertexGPUCycles = 0;
otherGPUCycles = 0;
@@ -142,6 +143,7 @@ struct GPUStatistics {
int numBlockTransfers;
int numReplacerTrackedTex;
int numCachedReplacedTextures;
int numClutTextures;
double msProcessingDisplayLists;
int vertexGPUCycles;
int otherGPUCycles;
+2 -1
View File
@@ -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"
@@ -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,
+4 -1
View File
@@ -62,7 +62,6 @@ DrawEngineVulkan::DrawEngineVulkan(Draw::DrawContext *draw)
: draw_(draw) {
decOptions_.expandAllWeightsToFloat = false;
decOptions_.expand8BitNormalsToFloat = false;
indexGen.Setup(decIndex_);
}
void DrawEngineVulkan::InitDeviceObjects() {
@@ -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();
+1 -1
View File
@@ -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;