Skip to content

Commit

Permalink
Merge branch 'master' into feature_openxr_vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
lvonasek committed Sep 14, 2022
2 parents d8fbc7c + e2768b9 commit f98381f
Show file tree
Hide file tree
Showing 31 changed files with 201 additions and 171 deletions.
4 changes: 2 additions & 2 deletions Common/Data/Collections/TinySet.h
Expand Up @@ -47,12 +47,12 @@ struct TinySet {
size_t otherSize = other.size();
if (size() + otherSize <= MaxFastSize) {
// Fast case
for (int i = 0; i < otherSize; i++) {
for (size_t i = 0; i < otherSize; i++) {
fastLookup_[fastCount + i] = other.fastLookup_[i];
}
fastCount += other.fastCount;
} else {
for (int i = 0; i < otherSize; i++) {
for (size_t i = 0; i < otherSize; i++) {
push_back(other[i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/OpenGL/thin3d_gl.cpp
Expand Up @@ -1219,7 +1219,7 @@ bool OpenGLPipeline::LinkShaders() {
}
std::vector<GLRProgram::Initializer> initialize;
for (int i = 0; i < MAX_TEXTURE_SLOTS; ++i) {
if (i < samplers_.size()) {
if (i < (int)samplers_.size()) {
initialize.push_back({ &samplerLocs_[i], 0, i });
} else {
samplerLocs_[i] = -1;
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/thin3d_vulkan.cpp
Expand Up @@ -1086,7 +1086,7 @@ Pipeline *VKContext::CreateGraphicsPipeline(const PipelineDesc &desc, const char
_dbg_assert_((int)input->attributes.size() == (int)input->visc.vertexAttributeDescriptionCount);

gDesc.ibd = input->bindings[0];
for (int i = 0; i < input->attributes.size(); i++) {
for (size_t i = 0; i < input->attributes.size(); i++) {
gDesc.attrs[i] = input->attributes[i];
}
gDesc.vis.vertexAttributeDescriptionCount = input->visc.vertexAttributeDescriptionCount;
Expand Down
4 changes: 3 additions & 1 deletion Core/Dialog/PSPSaveDialog.cpp
Expand Up @@ -1149,7 +1149,9 @@ void PSPSaveDialog::ExecuteNotVisibleIOAction() {
case SCE_UTILITY_SAVEDATA_TYPE_READDATA:
case SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE:
result = param.Load(param.GetPspParam(), GetSelectedSaveDirName(), currentSelectedSave, param.GetPspParam()->mode == SCE_UTILITY_SAVEDATA_TYPE_READDATASECURE);
if(result == SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA)
if (result == SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN)
result = SCE_UTILITY_SAVEDATA_ERROR_RW_DATA_BROKEN;
if (result == SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA)
result = SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA;
break;
case SCE_UTILITY_SAVEDATA_TYPE_ERASE:
Expand Down
52 changes: 32 additions & 20 deletions Core/Dialog/SavedataParam.cpp
Expand Up @@ -589,15 +589,22 @@ int SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &saveD
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_NO_DATA : SCE_UTILITY_SAVEDATA_ERROR_LOAD_NO_DATA;
}

if (fileName != "" && !pspFileSystem.GetFileInfo(filePath).exists) {
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND : SCE_UTILITY_SAVEDATA_ERROR_LOAD_FILE_NOT_FOUND;
}

// If it wasn't zero, force to zero before loading and especially in case of error.
// This isn't reset if the path doesn't even exist.
param->dataSize = 0;
int result = LoadSaveData(param, saveDirName, dirPath, secureMode);
if (result != 0)
return result;

// Load sfo
if (!LoadSFO(param, dirPath)) {
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_DATA_BROKEN : SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN;
}

if (fileName != "" && !pspFileSystem.GetFileInfo(filePath).exists) {
return isRWMode ? SCE_UTILITY_SAVEDATA_ERROR_RW_FILE_NOT_FOUND : SCE_UTILITY_SAVEDATA_ERROR_LOAD_FILE_NOT_FOUND;
}

// Don't know what it is, but PSP always respond this and this unlock some game
param->bind = 1021;

Expand All @@ -612,15 +619,6 @@ int SavedataParam::Load(SceUtilitySavedataParam *param, const std::string &saveD
// Load SND0.AT3
LoadFile(dirPath, SND0_FILENAME, &param->snd0FileData);

if (fileName == "") {
// Don't load savedata but return success.
return 0;
}

int result = LoadSaveData(param, saveDirName, dirPath, secureMode);
if (result != 0)
return result;

return 0;
}

Expand All @@ -638,6 +636,10 @@ int SavedataParam::LoadSaveData(SceUtilitySavedataParam *param, const std::strin

std::string filename = GetFileName(param);
std::string filePath = dirPath + "/" + filename;
// Blank filename always means success, if secureVersion was correct.
if (filename == "")
return 0;

s64 readSize;
INFO_LOG(SCEUTILITY, "Loading file with size %u in %s", param->dataBufSize, filePath.c_str());
u8 *saveData = nullptr;
Expand Down Expand Up @@ -667,14 +669,18 @@ int SavedataParam::LoadSaveData(SceUtilitySavedataParam *param, const std::strin
if (!saveDone) {
loadedSize = LoadNotCryptedSave(param, param->dataBuf, saveData, saveSize);
}
param->dataSize = (SceSize)saveSize;
delete[] saveData;

if (loadedSize != 0) {
// Ignore error codes.
if (loadedSize != 0 && (loadedSize & 0x80000000) == 0) {
std::string tag = "LoadSaveData/" + filePath;
NotifyMemInfo(MemBlockFlags::WRITE, param->dataBuf.ptr, loadedSize, tag.c_str(), tag.size());
}

if ((loadedSize & 0x80000000) != 0)
return loadedSize;

param->dataSize = (SceSize)saveSize;
return 0;
}

Expand Down Expand Up @@ -760,8 +766,12 @@ u32 SavedataParam::LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, con
u32 sz = 0;
if (err == 0) {
if (param->dataBuf.IsValid()) {
sz = std::min((u32)saveSize, (u32)param->dataBufSize);
memcpy(data, data_base, sz);
if ((u32)saveSize > param->dataBufSize || !Memory::IsValidRange(param->dataBuf.ptr, saveSize)) {
sz = SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN;
} else {
sz = (u32)saveSize;
memcpy(data, data_base, sz);
}
}
saveDone = true;
}
Expand All @@ -773,9 +783,11 @@ u32 SavedataParam::LoadCryptedSave(SceUtilitySavedataParam *param, u8 *data, con

u32 SavedataParam::LoadNotCryptedSave(SceUtilitySavedataParam *param, u8 *data, u8 *saveData, int &saveSize) {
if (param->dataBuf.IsValid()) {
u32 sz = std::min((u32)saveSize, (u32)param->dataBufSize);
memcpy(data, saveData, sz);
return sz;
if ((u32)saveSize > param->dataBufSize || !Memory::IsValidRange(param->dataBuf.ptr, saveSize)) {
return SCE_UTILITY_SAVEDATA_ERROR_LOAD_DATA_BROKEN;
}
memcpy(data, saveData, saveSize);
return saveSize;
}
return 0;
}
Expand Down
19 changes: 5 additions & 14 deletions GPU/Common/DepalettizeShaderCommon.cpp
Expand Up @@ -132,10 +132,7 @@ void GenerateDepalShader300(ShaderWriter &writer, const DepalConfig &config) {
break;
}

float texturePixels = 256.0f;
if (config.clutFormat != GE_CMODE_32BIT_ABGR8888) {
texturePixels = 512.0f;
}
float texturePixels = 512.0f;

if (shift) {
writer.F(" index = (int(uint(index) >> uint(%d)) & 0x%02x)", shift, mask);
Expand Down Expand Up @@ -278,11 +275,9 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) {
break;
}

float texturePixels = 256.f;
if (config.clutFormat != GE_CMODE_32BIT_ABGR8888) {
texturePixels = 512.f;
index_multiplier *= 0.5f;
}
// We always use 512-sized textures now.
float texturePixels = 512.f;
index_multiplier *= 0.5f;

// Adjust index_multiplier, similar to the use of 15.99 instead of 16 in the ES 3 path.
// index_multiplier -= 0.01f / texturePixels;
Expand Down Expand Up @@ -326,11 +321,7 @@ void GenerateDepalSmoothed(ShaderWriter &writer, const DepalConfig &config) {
}

writer.C(" float index = ").SampleTexture2D("tex", "v_texcoord").F(".%s * %0.1f;\n", sourceChannel, indexMultiplier);
float texturePixels = 256.f;
if (config.clutFormat != GE_CMODE_32BIT_ABGR8888) {
texturePixels = 512.f;
}

float texturePixels = 512.f;
writer.F(" float coord = (index + 0.5) * %f;\n", 1.0 / texturePixels);
writer.C(" vec4 outColor = ").SampleTexture2D("pal", "vec2(coord, 0.0)").C(";\n");
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/FragmentShaderGenerator.cpp
Expand Up @@ -640,7 +640,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
p.C(" if (depalShift == 5u) { index0 = t.g; }\n");
p.C(" else if (depalShift == 10u) { index0 = t.b; }\n");
p.C(" }\n");
p.F(" t = ").SampleTexture2D("pal", "vec2(index0 * factor, 0.0)").C(";\n");
p.F(" t = ").SampleTexture2D("pal", "vec2(index0 * factor * 0.5, 0.0)").C(";\n"); // 0.5 for 512-entry CLUT.
break;
case ShaderDepalMode::NORMAL:
if (doTextureProjection) {
Expand Down
52 changes: 32 additions & 20 deletions GPU/Common/FramebufferManagerCommon.cpp
Expand Up @@ -666,6 +666,10 @@ static const char *reinterpretStrings[4][4] = {

// Call this after the target has been bound for rendering. For color, raster is probably always going to win over blits/copies.
void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dst) {
if (!useBufferedRendering_) {
return;
}

std::vector<CopySource> sources;
for (auto src : vfbs_) {
// Discard old and equal potential inputs.
Expand Down Expand Up @@ -773,30 +777,17 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra
WARN_LOG_ONCE(bta, G3D, "WARNING: Reinterpret encountered with BlueToAlpha on");
}

if (IsBufferFormat16Bit(src->fb_format) && !IsBufferFormat16Bit(dst->fb_format)) {
// We halve the X coordinates in the destination framebuffer.
// The shader will collect two pixels worth of input data and merge into one.
dstX1 *= 0.5f;
dstX2 *= 0.5f;
} else if (!IsBufferFormat16Bit(src->fb_format) && IsBufferFormat16Bit(dst->fb_format)) {
// We double the X coordinates in the destination framebuffer.
// The shader will sample and depending on the X coordinate & 1, use the upper or lower bits.
dstX1 *= 2.0f;
dstX2 *= 2.0f;
}

// Reinterpret!
WARN_LOG_N_TIMES(reint, 5, G3D, "Reinterpret detected from %08x_%s to %08x_%s",
src->fb_address, GeBufferFormatToString(src->fb_format),
dst->fb_address, GeBufferFormatToString(dst->fb_format));
pipeline = reinterpretFromTo_[(int)src->fb_format][(int)dst->fb_format];

float scaleFactorX = 1.0f;
pipeline = GetReinterpretPipeline(src->fb_format, dst->fb_format, &scaleFactorX);
dstX1 *= scaleFactorX;
dstX2 *= scaleFactorX;

pass_name = reinterpretStrings[(int)src->fb_format][(int)dst->fb_format];
if (!pipeline) {
pipeline = draw2D_.Create2DPipeline([=](ShaderWriter &shaderWriter) -> Draw2DPipelineInfo {
return GenerateReinterpretFragmentShader(shaderWriter, src->fb_format, dst->fb_format);
});
reinterpretFromTo_[(int)src->fb_format][(int)dst->fb_format] = pipeline;
}

gpuStats.numReinterpretCopies++;
}
Expand All @@ -819,6 +810,27 @@ void FramebufferManagerCommon::CopyToColorFromOverlappingFramebuffers(VirtualFra
textureCache_->ForgetLastTexture();
}

Draw2DPipeline *FramebufferManagerCommon::GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX) {
if (IsBufferFormat16Bit(from) && !IsBufferFormat16Bit(to)) {
// We halve the X coordinates in the destination framebuffer.
// The shader will collect two pixels worth of input data and merge into one.
*scaleFactorX = 0.5f;
} else if (!IsBufferFormat16Bit(from) && IsBufferFormat16Bit(to)) {
// We double the X coordinates in the destination framebuffer.
// The shader will sample and depending on the X coordinate & 1, use the upper or lower bits.
*scaleFactorX = 2.0f;
}

Draw2DPipeline *pipeline = reinterpretFromTo_[(int)from][(int)to];
if (!pipeline) {
pipeline = draw2D_.Create2DPipeline([=](ShaderWriter &shaderWriter) -> Draw2DPipelineInfo {
return GenerateReinterpretFragmentShader(shaderWriter, from, to);
});
reinterpretFromTo_[(int)from][(int)to] = pipeline;
}
return pipeline;
}

void FramebufferManagerCommon::DestroyFramebuf(VirtualFramebuffer *v) {
// Notify the texture cache of both the color and depth buffers.
textureCache_->NotifyFramebuffer(v, NOTIFY_FB_DESTROYED);
Expand Down Expand Up @@ -1069,7 +1081,7 @@ bool FramebufferManagerCommon::BindFramebufferAsColorTexture(int stage, VirtualF

// currentRenderVfb_ will always be set when this is called, except from the GE debugger.
// Let's just not bother with the copy in that case.
bool skipCopy = !(flags & BINDFBCOLOR_MAY_COPY) || GPUStepping::IsStepping();
bool skipCopy = !(flags & BINDFBCOLOR_MAY_COPY);

// Currently rendering to this framebuffer. Need to make a copy.
if (!skipCopy && framebuffer == currentRenderVfb_) {
Expand Down
5 changes: 3 additions & 2 deletions GPU/Common/FramebufferManagerCommon.h
Expand Up @@ -421,14 +421,15 @@ class FramebufferManagerCommon {
// Returns the resolved framebuffer.
VirtualFramebuffer *ResolveFramebufferColorToFormat(VirtualFramebuffer *vfb, GEBufferFormat newFormat);

Draw2DPipeline *Get2DPipeline(Draw2DShader shader);
Draw2DPipeline *GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX);

protected:
virtual void PackFramebufferSync(VirtualFramebuffer *vfb, int x, int y, int w, int h, RasterChannel channel);
void SetViewport2D(int x, int y, int w, int h);
Draw::Texture *MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);
void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags);

Draw2DPipeline *Get2DPipeline(Draw2DShader shader);

void CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dest);
void CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest);

Expand Down

0 comments on commit f98381f

Please sign in to comment.