address more comments

This commit is contained in:
Khangaroo 2019-08-14 01:04:50 -04:00 committed by James Rowe
parent 3534ad0835
commit c2a32e942b
15 changed files with 87 additions and 56 deletions

View file

@ -8,8 +8,8 @@ add_executable(citra
default_ini.h
emu_window/emu_window_sdl2.cpp
emu_window/emu_window_sdl2.h
generic_image_interface.cpp
generic_image_interface.h
lodepng_image_interface.cpp
lodepng_image_interface.h
resource.h
)

View file

@ -20,6 +20,7 @@
#include "citra/config.h"
#include "citra/emu_window/emu_window_sdl2.h"
#include "citra/lodepng_image_interface.h"
#include "common/common_paths.h"
#include "common/detached_tasks.h"
#include "common/file_util.h"
@ -40,7 +41,6 @@
#include "core/loader/loader.h"
#include "core/movie.h"
#include "core/settings.h"
#include "generic_image_interface.h"
#include "network/network.h"
#include "video_core/video_core.h"
@ -344,7 +344,7 @@ int main(int argc, char** argv) {
Frontend::RegisterDefaultApplets();
// Register generic image interface
Core::System::GetInstance().RegisterImageInterface(std::make_shared<GenericImageInterface>());
Core::System::GetInstance().RegisterImageInterface(std::make_shared<LodePNGImageInterface>());
std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)};

View file

@ -4,9 +4,9 @@
#include <lodepng.h>
#include "common/logging/log.h"
#include "generic_image_interface.h"
#include "lodepng_image_interface.h"
bool GenericImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
bool LodePNGImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
const std::string& path) {
u32 lodepng_ret = lodepng::decode(dst, width, height, path);
if (lodepng_ret) {
@ -17,7 +17,7 @@ bool GenericImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& hei
return true;
}
bool GenericImageInterface::EncodePNG(const std::string& path, const std::vector<u8>& src,
bool LodePNGImageInterface::EncodePNG(const std::string& path, const std::vector<u8>& src,
u32 width, u32 height) {
u32 lodepng_ret = lodepng::encode(path, src, width, height);
if (lodepng_ret) {

View file

@ -6,7 +6,7 @@
#include "core/frontend/image_interface.h"
class GenericImageInterface final : public Frontend::ImageInterface {
class LodePNGImageInterface final : public Frontend::ImageInterface {
public:
bool DecodePNG(std::vector<u8>& dst, u32& width, u32& height, const std::string& path) override;
bool EncodePNG(const std::string& path, const std::vector<u8>& src, u32 width,

View file

@ -140,7 +140,7 @@
<header>configuration/configure_graphics.h</header>
<container>1</container>
</customwidget>
<customwidget>
<customwidget>
<class>ConfigureEnhancements</class>
<extends>QWidget</extends>
<header>configuration/configure_enhancements.h</header>

View file

@ -458,6 +458,9 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
QAction* open_extdata_location = context_menu.addAction(tr("Open Extra Data Location"));
QAction* open_application_location = context_menu.addAction(tr("Open Application Location"));
QAction* open_update_location = context_menu.addAction(tr("Open Update Data Location"));
QAction* open_texture_dump_location = context_menu.addAction(tr("Open Texture Dump Location"));
QAction* open_texture_load_location =
context_menu.addAction(tr("Open Custom Texture Location"));
QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry"));
const bool is_application =
@ -484,6 +487,10 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
program_id + 0xe00000000) +
"content/"));
auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id);
open_texture_dump_location->setVisible(is_application);
open_texture_load_location->setVisible(is_application);
navigate_to_gamedb_entry->setVisible(it != compatibility_list.end());
connect(open_save_location, &QAction::triggered, [this, program_id] {
@ -498,6 +505,18 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
connect(open_update_location, &QAction::triggered, [this, program_id] {
emit OpenFolderRequested(program_id, GameListOpenTarget::UPDATE_DATA);
});
connect(open_texture_dump_location, &QAction::triggered, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
program_id)))
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_DUMP);
});
connect(open_texture_load_location, &QAction::triggered, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
program_id)))
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_LOAD);
});
connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() {
emit NavigateToGamedbEntryRequested(program_id, compatibility_list);
});

View file

@ -29,7 +29,14 @@ class QTreeView;
class QToolButton;
class QVBoxLayout;
enum class GameListOpenTarget { SAVE_DATA = 0, EXT_DATA = 1, APPLICATION = 2, UPDATE_DATA = 3 };
enum class GameListOpenTarget {
SAVE_DATA = 0,
EXT_DATA = 1,
APPLICATION = 2,
UPDATE_DATA = 3,
TEXTURE_DUMP = 4,
TEXTURE_LOAD = 5
};
class GameList : public QWidget {
Q_OBJECT

View file

@ -1081,6 +1081,16 @@ void GMainWindow::OnGameListOpenFolder(u64 data_id, GameListOpenTarget target) {
path = Service::AM::GetTitlePath(Service::FS::MediaType::SDMC, data_id + 0xe00000000) +
"content/";
break;
case GameListOpenTarget::TEXTURE_DUMP:
open_target = "Dumped Textures";
path = fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), data_id);
break;
case GameListOpenTarget::TEXTURE_LOAD:
open_target = "Custom Textures";
path = fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), data_id);
break;
default:
LOG_ERROR(Frontend, "Unexpected target {}", static_cast<int>(target));
return;

View file

@ -2,12 +2,10 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <QBuffer>
#include <QImage>
#include <QString>
#include "citra_qt/qt_image_interface.h"
#include "common/logging/log.h"
#include "core/frontend/image_interface.h"
#include "qt_image_interface.h"
bool QtImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
const std::string& path) {
@ -20,16 +18,10 @@ bool QtImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
width = image.width();
height = image.height();
image = image.convertToFormat(QImage::Format_RGBA8888);
// Write RGBA8 to vector
for (int y = 0; y < image.height(); y++) {
for (int x = 0; x < image.width(); x++) {
const QColor pixel(image.pixelColor(x, y));
dst.push_back(pixel.red());
dst.push_back(pixel.green());
dst.push_back(pixel.blue());
dst.push_back(pixel.alpha());
}
}
dst = std::vector<u8>(image.constBits(), image.constBits() + (width * height * 4));
return true;
}

View file

@ -196,10 +196,11 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
}
perf_stats = std::make_unique<PerfStats>(title_id);
custom_tex_cache = std::make_unique<Core::CustomTexCache>();
if (Settings::values.custom_textures)
if (Settings::values.custom_textures) {
FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
Kernel().GetCurrentProcess()->codeset->program_id));
}
if (Settings::values.preload_textures)
PreloadCustomTextures();
status = ResultStatus::Success;

View file

@ -2,10 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <stdexcept>
#include <vector>
#include "common/common_types.h"
#include "custom_tex_cache.h"
#include "core/custom_tex_cache.h"
namespace Core {
CustomTexCache::CustomTexCache() = default;
@ -13,18 +10,18 @@ CustomTexCache::CustomTexCache() = default;
CustomTexCache::~CustomTexCache() = default;
bool CustomTexCache::IsTextureDumped(u64 hash) const {
return dumped_textures.find(hash) != dumped_textures.end();
return dumped_textures.count(hash);
}
void CustomTexCache::SetTextureDumped(const u64 hash) {
dumped_textures[hash] = true;
dumped_textures.insert(hash);
}
bool CustomTexCache::IsTextureCached(u64 hash) const {
return custom_textures.find(hash) != custom_textures.end();
return custom_textures.count(hash);
}
const CustomTexInfo& CustomTexCache::LookupTexture(u64 hash) {
const CustomTexInfo& CustomTexCache::LookupTexture(u64 hash) const {
return custom_textures.at(hash);
}

View file

@ -5,6 +5,7 @@
#pragma once
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "common/common_types.h"
@ -25,11 +26,11 @@ public:
void SetTextureDumped(u64 hash);
bool IsTextureCached(u64 hash) const;
const CustomTexInfo& LookupTexture(const u64 hash);
const CustomTexInfo& LookupTexture(u64 hash) const;
void CacheTexture(u64 hash, const std::vector<u8>& tex, u32 width, u32 height);
private:
std::unordered_map<u64, bool> dumped_textures;
std::unordered_set<u64> dumped_textures;
std::unordered_map<u64, CustomTexInfo> custom_textures;
};
} // namespace Core

View file

@ -7,7 +7,6 @@
#include <string>
#include <vector>
#include "common/common_types.h"
#include "common/logging/log.h"
namespace Frontend {

View file

@ -866,7 +866,10 @@ bool CachedSurface::LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_inf
Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id,
width, height, tex_hash, static_cast<u32>(pixel_format));
if (!custom_tex_cache.IsTextureCached(tex_hash)) {
if (custom_tex_cache.IsTextureCached(tex_hash)) {
tex_info = custom_tex_cache.LookupTexture(tex_hash);
result = true;
} else {
if (FileUtil::Exists(load_path)) {
if (image_interface->DecodePNG(tex_info.tex, tex_info.width, tex_info.height,
load_path)) {
@ -879,9 +882,6 @@ bool CachedSurface::LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_inf
LOG_CRITICAL(Render_OpenGL, "Failed to load custom texture");
}
}
} else {
tex_info = custom_tex_cache.LookupTexture(tex_hash);
result = true;
}
if (result) {
@ -915,9 +915,23 @@ std::optional<std::string> CachedSurface::GetDumpPath(u64 tex_hash) {
return {};
}
void CachedSurface::DumpTexture(GLuint target_tex, const std::string& dump_path) {
void CachedSurface::DumpTexture(GLuint target_tex, u64 tex_hash) {
// Dump texture to RGBA8 and encode as PNG
const auto& image_interface = Core::System::GetInstance().GetImageInterface();
auto& custom_tex_cache = Core::System::GetInstance().CustomTexCache();
std::string dump_path =
fmt::format("{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id);
if (!FileUtil::CreateFullPath(dump_path)) {
LOG_ERROR(Render, "Unable to create {}", dump_path);
return;
}
dump_path += fmt::format("tex1_{}x{}_{:016X}_{}.png", width, height, tex_hash,
static_cast<u32>(pixel_format));
if (!custom_tex_cache.IsTextureDumped(tex_hash) && !FileUtil::Exists(dump_path))
custom_tex_cache.SetTextureDumped(tex_hash);
LOG_INFO(Render_OpenGL, "Dumping texture to {}", dump_path);
std::vector<u8> decoded_texture;
decoded_texture.resize(width * height * 4);
@ -930,7 +944,7 @@ void CachedSurface::DumpTexture(GLuint target_tex, const std::string& dump_path)
glBindTexture(GL_TEXTURE_2D, 0);
Common::FlipRGBA8Texture(decoded_texture, width, height);
if (!image_interface->EncodePNG(dump_path, decoded_texture, width, height))
LOG_CRITICAL(Render_OpenGL, "Failed to save decoded texture");
LOG_ERROR(Render_OpenGL, "Failed to save decoded texture");
}
MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64));
@ -945,12 +959,11 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
// Read custom texture
auto& custom_tex_cache = Core::System::GetInstance().CustomTexCache();
bool dump_tex = false;
bool use_custom_tex = false;
std::string dump_path; // Has to be declared here for logging later
u64 tex_hash = 0;
Common::Rectangle custom_rect =
rect; // Required for rect to function properly with custom textures
// Required for rect to function properly with custom textures
Common::Rectangle custom_rect = rect;
if (Settings::values.dump_textures || Settings::values.custom_textures)
tex_hash = Common::ComputeHash64(gl_buffer.get(), gl_buffer_size);
@ -958,14 +971,6 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
if (Settings::values.custom_textures)
is_custom = use_custom_tex = LoadCustomTexture(tex_hash, custom_tex_info, custom_rect);
if (Settings::values.dump_textures && !use_custom_tex) {
auto temp_dump_path = GetDumpPath(tex_hash);
if (temp_dump_path.has_value()) {
dump_path = *temp_dump_path;
dump_tex = true;
}
}
// Load data from memory to the surface
GLint x0 = static_cast<GLint>(custom_rect.left);
GLint y0 = static_cast<GLint>(custom_rect.bottom);
@ -982,7 +987,7 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
y0 = 0;
unscaled_tex.Create();
if (use_custom_tex) {
if (is_custom) {
AllocateSurfaceTexture(unscaled_tex.handle, GetFormatTuple(PixelFormat::RGBA8),
custom_tex_info.width, custom_tex_info.height);
} else {
@ -1000,7 +1005,7 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
// Ensure no bad interactions with GL_UNPACK_ALIGNMENT
ASSERT(stride * GetGLBytesPerPixel(pixel_format) % 4 == 0);
if (use_custom_tex) {
if (is_custom) {
if (res_scale == 1) {
AllocateSurfaceTexture(texture.handle, GetFormatTuple(PixelFormat::RGBA8),
custom_tex_info.width, custom_tex_info.height);
@ -1023,8 +1028,8 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
if (dump_tex)
DumpTexture(target_tex, dump_path);
if (Settings::values.dump_textures)
DumpTexture(target_tex, tex_hash);
cur_state.texture_units[0].texture_2d = old_tex;
cur_state.Apply();

View file

@ -385,7 +385,7 @@ struct CachedSurface : SurfaceParams, std::enable_shared_from_this<CachedSurface
bool LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_info,
Common::Rectangle<u32>& custom_rect);
std::optional<std::string> GetDumpPath(u64 tex_hash);
void DumpTexture(GLuint target_tex, const std::string& dump_path);
void DumpTexture(GLuint target_tex, u64 tex_hash);
// Upload/Download data in gl_buffer in/to this surface's texture
void UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint read_fb_handle,