Skip to content

Commit

Permalink
Merge branch 'master' into TemporaryHackishBranch
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaMoo committed Mar 29, 2018
2 parents 12691ee + 170b600 commit 65ba116
Show file tree
Hide file tree
Showing 31 changed files with 249 additions and 92 deletions.
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ if(LIBRETRO)
endif()

if(ANDROID)
set(CoreLibName ppsspp_jni)
set(CoreLinkType SHARED)
set(MOBILE_DEVICE ON)
set(USING_GLES2 ON)
endif()

if(ANDROID AND NOT LIBRETRO)
set(CoreLibName ppsspp_jni)
set(CoreLinkType SHARED)
else()
set(CoreLibName Core)
set(CoreLinkType STATIC)
Expand Down
4 changes: 3 additions & 1 deletion GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ void TextureCacheCommon::SetTexture(bool force) {

// Before we go reading the texture from memory, let's check for render-to-texture.
// We must do this early so we have the right w/h.
entry->framebuffer = 0;
entry->framebuffer = nullptr;
for (size_t i = 0, n = fbCache_.size(); i < n; ++i) {
auto framebuffer = fbCache_[i];
AttachFramebuffer(entry, framebuffer->fb_address, framebuffer);
Expand Down Expand Up @@ -685,6 +685,7 @@ void TextureCacheCommon::AttachFramebufferValid(TexCacheEntry *entry, VirtualFra
if (entry->framebuffer == nullptr) {
cacheSizeEstimate_ -= EstimateTexMemoryUsage(entry);
}
ReleaseTexture(entry, true);
entry->framebuffer = framebuffer;
entry->invalidHint = 0;
entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE;
Expand All @@ -704,6 +705,7 @@ void TextureCacheCommon::AttachFramebufferInvalid(TexCacheEntry *entry, VirtualF
if (entry->framebuffer == nullptr) {
cacheSizeEstimate_ -= EstimateTexMemoryUsage(entry);
}
ReleaseTexture(entry, true);
entry->framebuffer = framebuffer;
entry->invalidHint = -1;
entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE;
Expand Down
8 changes: 4 additions & 4 deletions GPU/GLES/TextureCacheGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferH

minFilt &= 1; // framebuffers can't mipmap.

float aniso = 0.0f;
render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);

// Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case.
// This happens whether we have OES_texture_npot or not.
int w = gstate.getTextureWidth(0);
int h = gstate.getTextureHeight(0);
if (w != bufferWidth || h != bufferHeight) {
return;
sClamp = true;
tClamp = true;
}
float aniso = 0.0f;
render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);
}

static void ConvertColors(void *dstBuf, const void *srcBuf, GLuint dstFmt, int numPixels) {
Expand Down
7 changes: 2 additions & 5 deletions GPU/Vulkan/GPU_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ void GPU_Vulkan::LoadCache(std::string filename) {
// it can just memcpy the finished shader binaries out of the pipeline cache file.
bool result = shaderManagerVulkan_->LoadCache(f);
if (result) {
VkRenderPass renderPass = g_Config.iRenderingMode == FB_BUFFERED_MODE ?
(VkRenderPass)draw_->GetNativeObject(Draw::NativeObject::FRAMEBUFFER_RENDERPASS) :
(VkRenderPass)draw_->GetNativeObject(Draw::NativeObject::BACKBUFFER_RENDERPASS);
result = pipelineManager_->LoadCache(f, false, shaderManagerVulkan_, &drawEngine_, drawEngine_.GetPipelineLayout(), renderPass);
result = pipelineManager_->LoadCache(f, false, shaderManagerVulkan_, draw_, drawEngine_.GetPipelineLayout());
}
fclose(f);
if (!result) {
Expand All @@ -148,7 +145,7 @@ void GPU_Vulkan::SaveCache(std::string filename) {
if (!f)
return;
shaderManagerVulkan_->SaveCache(f);
pipelineManager_->SaveCache(f, false, shaderManagerVulkan_);
pipelineManager_->SaveCache(f, false, shaderManagerVulkan_, draw_);
INFO_LOG(G3D, "Saved Vulkan pipeline cache");
fclose(f);
}
Expand Down
47 changes: 44 additions & 3 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "GPU/Vulkan/PipelineManagerVulkan.h"
#include "GPU/Vulkan/ShaderManagerVulkan.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "ext/native/thin3d/thin3d.h"
#include "ext/native/thin3d/VulkanRenderManager.h"
#include "ext/native/thin3d/VulkanQueueRunner.h"

PipelineManagerVulkan::PipelineManagerVulkan(VulkanContext *vulkan) : vulkan_(vulkan), pipelines_(256) {
// The pipeline cache is created on demand (or explicitly through Load).
Expand Down Expand Up @@ -540,7 +543,25 @@ struct VkPipelineCacheHeader {
uint8_t uuid[VK_UUID_SIZE];
};

void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager) {
struct StoredVulkanPipelineKey {
VulkanPipelineRasterStateKey raster;
VShaderID vShaderID;
FShaderID fShaderID;
uint32_t vtxFmtId;
bool useHWTransform;
bool backbufferPass;
VulkanQueueRunner::RPKey renderPassKey;

// For std::set. Better zero-initialize the struct properly for this to work.
bool operator < (const StoredVulkanPipelineKey &other) const {
return memcmp(this, &other, sizeof(*this)) < 0;
}
};

void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext) {
VulkanRenderManager *rm = (VulkanRenderManager *)drawContext->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
VulkanQueueRunner *queueRunner = rm->GetQueueRunner();

size_t dataSize = 0;
uint32_t size;

Expand Down Expand Up @@ -569,6 +590,7 @@ void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, Sha
// Make sure the set of pipelines we write is "unique".
std::set<StoredVulkanPipelineKey> keys;

// TODO: Use derivative pipelines when possible, helps Mali driver pipeline creation speed at least.
pipelines_.Iterate([&](const VulkanPipelineKey &pkey, VulkanPipeline *value) {
if (failed)
return;
Expand All @@ -587,6 +609,14 @@ void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, Sha
// NOTE: This is not a vtype, but a decoded vertex format.
key.vtxFmtId = pkey.vtxFmtId;
}
// Figure out what kind of renderpass this pipeline uses.
if (pkey.renderPass == queueRunner->GetBackbufferRenderPass()) {
key.backbufferPass = true;
key.renderPassKey = {};
} else {
key.backbufferPass = false;
queueRunner->GetRenderPassKey(pkey.renderPass, &key.renderPassKey);
}
keys.insert(key);
});

Expand All @@ -610,7 +640,10 @@ void PipelineManagerVulkan::SaveCache(FILE *file, bool saveRawPipelineCache, Sha
NOTICE_LOG(G3D, "Saved Vulkan pipeline ID cache (%d unique pipelines/%d).", (int)keys.size(), (int)pipelines_.size());
}

bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, DrawEngineCommon *drawEngine, VkPipelineLayout layout, VkRenderPass renderPass) {
bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VkPipelineLayout layout) {
VulkanRenderManager *rm = (VulkanRenderManager *)drawContext->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
VulkanQueueRunner *queueRunner = rm->GetQueueRunner();

uint32_t size = 0;
if (loadRawPipelineCache) {
fread(&size, sizeof(size), 1, file);
Expand Down Expand Up @@ -673,9 +706,17 @@ bool PipelineManagerVulkan::LoadCache(FILE *file, bool loadRawPipelineCache, Sha
ERROR_LOG(G3D, "Failed to find vs or fs in of pipeline %d in cache", (int)i);
continue;
}

VkRenderPass rp;
if (key.backbufferPass) {
rp = queueRunner->GetBackbufferRenderPass();
} else {
rp = queueRunner->GetRenderPass(key.renderPassKey);
}

DecVtxFormat fmt;
fmt.InitializeFromID(key.vtxFmtId);
GetOrCreatePipeline(layout, renderPass, key.raster,
GetOrCreatePipeline(layout, rp, key.raster,
key.useHWTransform ? &fmt : 0,
vs, fs, key.useHWTransform);
}
Expand Down
17 changes: 2 additions & 15 deletions GPU/Vulkan/PipelineManagerVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ struct VulkanPipelineKey {
std::string GetDescription(DebugShaderStringType stringType) const;
};

struct StoredVulkanPipelineKey {
VulkanPipelineRasterStateKey raster;
VShaderID vShaderID;
FShaderID fShaderID;
uint32_t vtxFmtId;
bool useHWTransform;

// For std::set. Better zero-initialize the struct properly for this to work.
bool operator < (const StoredVulkanPipelineKey &other) const {
return memcmp(this, &other, sizeof(*this)) < 0;
}
};

enum PipelineFlags {
PIPELINE_FLAG_USES_LINES = (1 << 2),
PIPELINE_FLAG_USES_BLEND_CONSTANT = (1 << 3),
Expand Down Expand Up @@ -109,8 +96,8 @@ class PipelineManagerVulkan {
std::vector<std::string> DebugGetObjectIDs(DebugShaderType type);

// Saves data for faster creation next time.
void SaveCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager);
bool LoadCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, DrawEngineCommon *drawEngine, VkPipelineLayout layout, VkRenderPass renderPass);
void SaveCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext);
bool LoadCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VkPipelineLayout layout);

private:
DenseHashMap<VulkanPipelineKey, VulkanPipeline *, nullptr> pipelines_;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Vulkan/ShaderManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ VulkanFragmentShader *ShaderManagerVulkan::GetFragmentShaderFromModule(VkShaderM
// instantaneous.

#define CACHE_HEADER_MAGIC 0xff51f420
#define CACHE_VERSION 6
#define CACHE_VERSION 9
struct VulkanCacheHeader {
uint32_t magic;
uint32_t version;
Expand Down
4 changes: 4 additions & 0 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ class GameInfoWorkItem : public PrioritizedWorkQueueItem {
if (File::Exists(screenshotPath)) {
if (readFileToString(false, screenshotPath.c_str(), info_->icon.data)) {
info_->icon.dataLoaded = true;
} else {
ERROR_LOG(G3D, "Error loading screenshot data: '%s'", screenshotPath.c_str());
}
}
break;
Expand Down Expand Up @@ -795,6 +797,8 @@ void GameInfoCache::SetupTexture(std::shared_ptr<GameInfo> &info, Draw::DrawCont
tex.texture = CreateTextureFromFileData(thin3d, (const uint8_t *)tex.data.data(), (int)tex.data.size(), ImageFileType::DETECT);
if (tex.texture) {
tex.timeLoaded = time_now_d();
} else {
ERROR_LOG(G3D, "Failed creating texture");
}
}
if ((info->wantFlags & GAMEINFO_WANTBGDATA) == 0) {
Expand Down
2 changes: 2 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static std::string PostShaderTranslateName(const char *value) {
const ShaderInfo *info = GetPostShaderInfo(value);
if (info) {
return ps->T(value, info ? info->name.c_str() : value);
} else {
return value;
}
}

Expand Down
3 changes: 3 additions & 0 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
screenManager->setUIContext(uiContext);
screenManager->setDrawContext(g_draw);
screenManager->setPostRenderCallback(&RenderOverlays, nullptr);
screenManager->deviceRestored();

#ifdef _WIN32
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
Expand All @@ -702,6 +703,8 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
}

void NativeShutdownGraphics() {
screenManager->deviceLost();

if (gpu)
gpu->DeviceLost();

Expand Down
14 changes: 12 additions & 2 deletions UI/PauseScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ AsyncImageFileView::AsyncImageFileView(const std::string &filename, UI::ImageSiz
AsyncImageFileView::~AsyncImageFileView() {}

void AsyncImageFileView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
if (texture_) {
if (texture_ && texture_->GetTexture()) {
float texw = (float)texture_->Width();
float texh = (float)texture_->Height();
switch (sizeMode_) {
Expand Down Expand Up @@ -77,6 +77,16 @@ void AsyncImageFileView::SetFilename(std::string filename) {
}
}

void AsyncImageFileView::DeviceLost() {
if (texture_.get())
texture_->DeviceLost();
}

void AsyncImageFileView::DeviceRestored(Draw::DrawContext *draw) {
if (texture_.get())
texture_->DeviceRestored(draw);
}

void AsyncImageFileView::Draw(UIContext &dc) {
using namespace Draw;
if (!texture_ && !textureFailed_ && !filename_.empty()) {
Expand All @@ -90,7 +100,7 @@ void AsyncImageFileView::Draw(UIContext &dc) {
}

// TODO: involve sizemode
if (texture_) {
if (texture_ && texture_->GetTexture()) {
dc.Flush();
dc.GetDrawContext()->BindTexture(0, texture_->GetTexture());
dc.Draw()->Rect(bounds_.x, bounds_.y, bounds_.w, bounds_.h, color_);
Expand Down
7 changes: 5 additions & 2 deletions UI/PauseScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class GamePauseScreen : public UIDialogScreenWithGameBackground {

class PrioritizedWorkQueue;

// TextureView takes a texture that is assumed to be alive during the lifetime
// of the view. TODO: Actually make async using the task.
// AsyncImageFileView loads a texture from a file, and reloads it as necessary.
// TODO: Actually make async, doh.
class AsyncImageFileView : public UI::Clickable {
public:
AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams = 0);
Expand All @@ -70,6 +70,9 @@ class AsyncImageFileView : public UI::Clickable {
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;

void DeviceLost() override;
void DeviceRestored(Draw::DrawContext *draw) override;

void SetFilename(std::string filename);
void SetColor(uint32_t color) { color_ = color; }
void SetOverlayText(std::string text) { text_ = text; }
Expand Down
4 changes: 1 addition & 3 deletions UI/SavedataScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ void SavedataBrowser::Refresh() {
if (!isState && File::Exists(path_ + fileInfo[i].name + "/PARAM.SFO"))
isSaveData = true;

if (isSaveData) {
savedataButtons.push_back(new SavedataButton(fileInfo[i].fullName, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::WRAP_CONTENT)));
} else if (isState) {
if (isSaveData || isState) {
savedataButtons.push_back(new SavedataButton(fileInfo[i].fullName, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::WRAP_CONTENT)));
}
}
Expand Down
Loading

0 comments on commit 65ba116

Please sign in to comment.