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

host/config: LOG_IMPORTS, LOG_EXPORTS, LOG_ACTIVE_SHADERS, LOG_UNIFORMS converted to Config settings #339

Merged
merged 4 commits into from Oct 11, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/emulator/host/include/host/config.h
Expand Up @@ -33,14 +33,18 @@ struct Config {
optional<std::string> vpk_path;
optional<std::string> run_title_id;
optional<int> log_level;
bool log_imports = false;
bool log_exports = false;
bool log_active_shaders = false;
bool log_uniforms = false;
std::vector<std::string> lle_modules;
};

namespace config {

/**
* \brief Initializes config system, parsing command-line args and handling some basic ones:
* --help, --version, -log-level
* --help, --version, --log-level
* \param cfg Config options are returend via this parameter.
* \return True on success, false on error.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/emulator/host/src/app.cpp
Expand Up @@ -233,7 +233,7 @@ bool load_app_impl(Ptr<const void> &entry_point, HostState &host, const std::wst
Ptr<const void> lib_entry_point;

if (vfs::read_app_file(module_buffer, host.pref_path, host.io.title_id, module_path)) {
SceUID module_id = load_self(lib_entry_point, host.kernel, host.mem, module_buffer.data(), std::string("app0:") + module_path);
SceUID module_id = load_self(lib_entry_point, host.kernel, host.mem, module_buffer.data(), std::string("app0:") + module_path, host.cfg);
if (module_id >= 0) {
const auto module = host.kernel.loaded_modules[module_id];
const auto module_name = module->module_name;
Expand All @@ -248,7 +248,7 @@ bool load_app_impl(Ptr<const void> &entry_point, HostState &host, const std::wst
// Load main executable (eboot.bin)
vfs::FileBuffer eboot_buffer;
if (vfs::read_app_file(eboot_buffer, host.pref_path, host.io.title_id, EBOOT_PATH)) {
SceUID module_id = load_self(entry_point, host.kernel, host.mem, eboot_buffer.data(), EBOOT_PATH_ABS);
SceUID module_id = load_self(entry_point, host.kernel, host.mem, eboot_buffer.data(), EBOOT_PATH_ABS, host.cfg);
if (module_id >= 0) {
const auto module = host.kernel.loaded_modules[module_id];
const auto module_name = module->module_name;
Expand Down
6 changes: 5 additions & 1 deletion src/emulator/host/src/config.cpp
Expand Up @@ -51,7 +51,11 @@ ExitCode init(Config &cfg, int argc, char **argv) {
po::options_description config_desc("Configuration");
config_desc.add_options()
("lle-modules,m", po::value<std::string>(), "Load given (decrypted) OS modules from disk. Separate by commas to specify multiple modules (no spaces). Full path and extension should not be included, the following are assumed: vs0:sys/external/<name>.suprx\nExample: --lle-modules libscemp4,libngs")
("log-level,l", po::value(&cfg.log_level)->default_value(spdlog::level::trace), "logging level:\nTRACE = 0\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nCRITICAL = 5\nOFF = 6");
("log-level,l", po::value(&cfg.log_level)->default_value(spdlog::level::trace), "logging level:\nTRACE = 0\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nCRITICAL = 5\nOFF = 6")
("log-imports,I", po::bool_switch(&cfg.log_imports), "Log Imports")
("log-exports,E", po::bool_switch(&cfg.log_exports), "Log Exports")
("log-active-shaders,S", po::bool_switch(&cfg.log_active_shaders), "Log Active Shaders")
("log-uniforms,U", po::bool_switch(&cfg.log_uniforms), "Log Uniforms");
// clang-format on

// Positional args
Expand Down
3 changes: 2 additions & 1 deletion src/emulator/kernel/include/kernel/load_self.h
Expand Up @@ -18,8 +18,9 @@
#pragma once
#include "kernel/state.h"
#include "psp2/types.h"
struct Config;
struct MemState;
template <class T>
class Ptr;

SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &mem, const void *self, const std::string &path);
SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &mem, const void *self, const std::string &path, const Config &cfg);
45 changes: 22 additions & 23 deletions src/emulator/kernel/src/load_self.cpp
Expand Up @@ -20,6 +20,7 @@
#include <kernel/state.h>
#include <kernel/types.h>
#include <mem/mem.h>
#include <host/config.h>

#include <nids/functions.h>
#include <util/log.h>
Expand Down Expand Up @@ -53,11 +54,9 @@ using namespace ELFIO;
namespace fs = boost::filesystem;

static constexpr bool LOG_MODULE_LOADING = false;
static constexpr bool LOG_IMPORTS = false;
static constexpr bool LOG_EXPORTS = false;
static constexpr bool DUMP_SEGMENTS = false;

static bool load_var_imports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, const SegmentInfosForReloc &segments, KernelState &kernel, MemState &mem) {
static bool load_var_imports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, const SegmentInfosForReloc &segments, KernelState &kernel, MemState &mem, const Config &cfg) {
struct VarImportsHeader {
uint8_t unk; // seems to always be 0x40
uint8_t reloc_count;
Expand All @@ -68,7 +67,7 @@ static bool load_var_imports(const uint32_t *nids, const Ptr<uint32_t> *entries,
const uint32_t nid = nids[i];
const Ptr<uint32_t> entry = entries[i];

if (LOG_IMPORTS) {
if (cfg.log_imports) {
const char *const name = import_name(nid);
LOG_DEBUG("\tNID {} ({}). entry: {}, *entry: {}", log_hex(nid), name, log_hex(entry.address()), log_hex(*entry.get(mem)));
}
Expand Down Expand Up @@ -134,12 +133,12 @@ static uint32_t encode_arm_inst(uint8_t type, uint16_t immed, uint16_t reg) {
}
}

static bool load_func_imports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel, const MemState &mem) {
static bool load_func_imports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel, const MemState &mem, const Config &cfg) {
for (size_t i = 0; i < count; ++i) {
const uint32_t nid = nids[i];
const Ptr<uint32_t> entry = entries[i];

if (LOG_IMPORTS) {
if (cfg.log_imports) {
const char *const name = import_name(nid);
LOG_DEBUG("\tNID {} ({}) at {}", log_hex(nid), name, log_hex(entry.address()));
}
Expand All @@ -162,7 +161,7 @@ static bool load_func_imports(const uint32_t *nids, const Ptr<uint32_t> *entries
return true;
}

static bool load_imports(const sce_module_info_raw &module, Ptr<const void> segment_address, const SegmentInfosForReloc &segments, KernelState &kernel, MemState &mem) {
static bool load_imports(const sce_module_info_raw &module, Ptr<const void> segment_address, const SegmentInfosForReloc &segments, KernelState &kernel, MemState &mem, const Config &cfg) {
const uint8_t *const base = segment_address.cast<const uint8_t>().get(mem);
const sce_module_imports_raw *const imports_begin = reinterpret_cast<const sce_module_imports_raw *>(base + module.import_top);
const sce_module_imports_raw *const imports_end = reinterpret_cast<const sce_module_imports_raw *>(base + module.import_end);
Expand Down Expand Up @@ -193,7 +192,7 @@ static bool load_imports(const sce_module_info_raw &module, Ptr<const void> segm
}

std::string lib_name;
if (LOG_IMPORTS) {
if (cfg.log_imports) {
lib_name = Ptr<const char>(module_name).get(mem);
LOG_INFO("Loading func imports from {}", lib_name);
}
Expand All @@ -202,7 +201,7 @@ static bool load_imports(const sce_module_info_raw &module, Ptr<const void> segm
const Ptr<uint32_t> *const entries = Ptr<Ptr<uint32_t>>(func_entry_table).get(mem);

const size_t num_syms_funcs = imports->num_syms_funcs;
if (!load_func_imports(nids, entries, num_syms_funcs, kernel, mem)) {
if (!load_func_imports(nids, entries, num_syms_funcs, kernel, mem, cfg)) {
return false;
}

Expand All @@ -211,19 +210,19 @@ static bool load_imports(const sce_module_info_raw &module, Ptr<const void> segm

const auto var_count = imports->num_syms_vars;

if (LOG_IMPORTS && var_count > 0) {
if (cfg.log_imports && var_count > 0) {
LOG_INFO("Loading var imports from {}", lib_name);
}

if (!load_var_imports(var_nids, var_entries, var_count, segments, kernel, mem)) {
if (!load_var_imports(var_nids, var_entries, var_count, segments, kernel, mem, cfg)) {
return false;
}
}

return true;
}

static bool load_func_exports(Ptr<const void> &entry_point, const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel) {
static bool load_func_exports(Ptr<const void> &entry_point, const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel, const Config &cfg) {
for (size_t i = 0; i < count; ++i) {
const uint32_t nid = nids[i];
const Ptr<uint32_t> entry = entries[i];
Expand All @@ -238,7 +237,7 @@ static bool load_func_exports(Ptr<const void> &entry_point, const uint32_t *nids

kernel.export_nids.emplace(nid, entry.address());

if (LOG_EXPORTS) {
if (cfg.log_exports) {
const char *const name = import_name(nid);

LOG_DEBUG("\tNID {} ({}) at {}", log_hex(nid), name, log_hex(entry.address()));
Expand All @@ -248,7 +247,7 @@ static bool load_func_exports(Ptr<const void> &entry_point, const uint32_t *nids
return true;
}

static bool load_var_exports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel) {
static bool load_var_exports(const uint32_t *nids, const Ptr<uint32_t> *entries, size_t count, KernelState &kernel, const Config &cfg) {
for (size_t i = 0; i < count; ++i) {
const uint32_t nid = nids[i];
const Ptr<uint32_t> entry = entries[i];
Expand All @@ -269,7 +268,7 @@ static bool load_var_exports(const uint32_t *nids, const Ptr<uint32_t> *entries,
continue;
}

if (LOG_EXPORTS) {
if (cfg.log_exports) {
const char *const name = import_name(nid);

LOG_DEBUG("\tNID {} ({}) at {}", log_hex(nid), name, log_hex(entry.address()));
Expand All @@ -281,31 +280,31 @@ static bool load_var_exports(const uint32_t *nids, const Ptr<uint32_t> *entries,
return true;
}

static bool load_exports(Ptr<const void> &entry_point, const sce_module_info_raw &module, Ptr<const void> segment_address, KernelState &kernel, const MemState &mem) {
static bool load_exports(Ptr<const void> &entry_point, const sce_module_info_raw &module, Ptr<const void> segment_address, KernelState &kernel, const MemState &mem, const Config &cfg) {
const uint8_t *const base = segment_address.cast<const uint8_t>().get(mem);
const sce_module_exports_raw *const exports_begin = reinterpret_cast<const sce_module_exports_raw *>(base + module.export_top);
const sce_module_exports_raw *const exports_end = reinterpret_cast<const sce_module_exports_raw *>(base + module.export_end);

for (const sce_module_exports_raw *exports = exports_begin; exports < exports_end; exports = reinterpret_cast<const sce_module_exports_raw *>(reinterpret_cast<const uint8_t *>(exports) + exports->size)) {
const char *const lib_name = Ptr<const char>(exports->module_name).get(mem);

if (LOG_EXPORTS) {
if (cfg.log_exports) {
LOG_INFO("Loading func exports from {}", lib_name ? lib_name : "unknown");
}

const uint32_t *const nids = Ptr<const uint32_t>(exports->nid_table).get(mem);
const Ptr<uint32_t> *const entries = Ptr<Ptr<uint32_t>>(exports->entry_table).get(mem);
if (!load_func_exports(entry_point, nids, entries, exports->num_syms_funcs, kernel)) {
if (!load_func_exports(entry_point, nids, entries, exports->num_syms_funcs, kernel, cfg)) {
return false;
}

const auto var_count = exports->num_syms_vars;

if (LOG_EXPORTS && var_count > 0) {
if (cfg.log_exports && var_count > 0) {
LOG_INFO("Loading var exports from {}", lib_name ? lib_name : "unknown");
}

if (!load_var_exports(&nids[exports->num_syms_funcs], &entries[exports->num_syms_funcs], var_count, kernel)) {
if (!load_var_exports(&nids[exports->num_syms_funcs], &entries[exports->num_syms_funcs], var_count, kernel, cfg)) {
return false;
}
}
Expand All @@ -316,7 +315,7 @@ static bool load_exports(Ptr<const void> &entry_point, const sce_module_info_raw
/**
* \return Negative on failure
*/
SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &mem, const void *self, const std::string &self_path) {
SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &mem, const void *self, const std::string &self_path, const Config &cfg) {
const uint8_t *const self_bytes = static_cast<const uint8_t *>(self);
const SCE_header &self_header = *static_cast<const SCE_header *>(self);

Expand Down Expand Up @@ -460,11 +459,11 @@ SceUID load_self(Ptr<const void> &entry_point, KernelState &kernel, MemState &me

LOG_INFO("Loading symbols for SELF: {}", self_path);

if (!load_exports(entry_point, *module_info, module_info_segment_address, kernel, mem)) {
if (!load_exports(entry_point, *module_info, module_info_segment_address, kernel, mem, cfg)) {
return -1;
}

if (!load_imports(*module_info, module_info_segment_address, segment_reloc_info, kernel, mem)) {
if (!load_imports(*module_info, module_info_segment_address, segment_reloc_info, kernel, mem, cfg)) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/emulator/modules/SceGxm/SceGxm.cpp
Expand Up @@ -413,7 +413,7 @@ EXPORT(int, sceGxmDraw, SceGxmContext *context, SceGxmPrimitiveType primType, Sc
context->state.fragment_last_reserve_status = SceGxmLastReserveStatus::Available;
}

if (!renderer::sync_state(context->renderer, context->state, host.mem, host.gui.texture_cache)) {
if (!renderer::sync_state(context->renderer, context->state, host.mem, host.gui.texture_cache, host.cfg.log_active_shaders, host.cfg.log_uniforms)) {
return RET_ERROR(SCE_GXM_ERROR_DRIVER);
}

Expand Down
2 changes: 1 addition & 1 deletion src/emulator/modules/SceLibKernel/SceLibKernel.cpp
Expand Up @@ -1081,7 +1081,7 @@ bool load_module(SceUID &mod_id, Ptr<const void> &entry_point, SceKernelModuleIn
return false;
}

mod_id = load_self(entry_point, host.kernel, host.mem, data, path);
mod_id = load_self(entry_point, host.kernel, host.mem, data, path, host.cfg);

close_file(host.io, file, export_name);
delete[] data;
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/modules/SceSysmodule/SceSysmodule.cpp
Expand Up @@ -164,7 +164,7 @@ bool load_module(HostState &host, SceSysmoduleModuleId module_id) {
Ptr<const void> lib_entry_point;

if (vfs::read_file(VitaIoDevice::VS0, module_buffer, host.pref_path, module_path)) {
SceUID loaded_module_uid = load_self(lib_entry_point, host.kernel, host.mem, module_buffer.data(), module_path);
SceUID loaded_module_uid = load_self(lib_entry_point, host.kernel, host.mem, module_buffer.data(), module_path, host.cfg);
const auto module = host.kernel.loaded_modules[loaded_module_uid];
const auto module_name = module->module_name;

Expand Down
2 changes: 1 addition & 1 deletion src/emulator/renderer/include/renderer/functions.h
Expand Up @@ -23,7 +23,7 @@ bool create(FragmentProgram &fp, State &state, const SceGxmProgram &program, con
bool create(VertexProgram &vp, State &state, const SceGxmProgram &program, const char *base_path);
void begin_scene(const RenderTarget &rt);
void end_scene(Context &context, SceGxmSyncObject *sync_object, size_t width, size_t height, size_t stride_in_pixels, uint32_t *pixels);
bool sync_state(Context &context, const GxmContextState &state, const MemState &mem, bool enable_texture_cache);
bool sync_state(Context &context, const GxmContextState &state, const MemState &mem, bool enable_texture_cache, bool log_active_shaders, bool log_uniforms);
bsinky marked this conversation as resolved.
Show resolved Hide resolved
void draw(Context &context, const GxmContextState &state, SceGxmPrimitiveType type, SceGxmIndexFormat format, const void *indices, size_t count, const MemState &mem);
void finish(Context &context);
void wait_sync_object(SceGxmSyncObject *sync_object);
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/renderer/src/functions.h
Expand Up @@ -59,5 +59,5 @@ void cache_and_bind_texture(TextureCacheState &cache, const SceGxmTexture &gxm_t
} // namespace texture

// Uniforms.
void set_uniforms(GLuint program, const GxmContextState &state, const MemState &mem);
void set_uniforms(GLuint program, const GxmContextState &state, const MemState &mem, bool log_uniforms);
} // namespace renderer
7 changes: 3 additions & 4 deletions src/emulator/renderer/src/sync_state.cpp
Expand Up @@ -12,7 +12,6 @@
#include <cmath>

namespace renderer {
static constexpr bool LOG_ACTIVE_SHADERS = false;

static GLenum translate_depth_func(SceGxmDepthFunc depth_func) {
R_PROFILE(__func__);
Expand Down Expand Up @@ -98,7 +97,7 @@ static void set_stencil_state(GLenum face, const GxmStencilState &state) {
glStencilMaskSeparate(face, state.write_mask);
}

bool sync_state(Context &context, const GxmContextState &state, const MemState &mem, bool enable_texture_cache) {
bool sync_state(Context &context, const GxmContextState &state, const MemState &mem, bool enable_texture_cache, bool log_active_shaders, bool log_uniforms) {
R_PROFILE(__func__);

// TODO Use some kind of caching to avoid setting every draw call?
Expand All @@ -108,7 +107,7 @@ bool sync_state(Context &context, const GxmContextState &state, const MemState &
}
glUseProgram(program->get());

if (LOG_ACTIVE_SHADERS) {
if (log_active_shaders) {
const SceGxmProgram &fragment_gxp_program = *state.fragment_program.get(mem)->program.get(mem);
const SceGxmProgram &vertex_gxp_program = *state.vertex_program.get(mem)->program.get(mem);

Expand Down Expand Up @@ -262,7 +261,7 @@ bool sync_state(Context &context, const GxmContextState &state, const MemState &
glActiveTexture(GL_TEXTURE0);

// Uniforms.
set_uniforms(program->get(), state, mem);
set_uniforms(program->get(), state, mem, log_uniforms);

// Vertex attributes.
const SceGxmVertexProgram &vertex_program = *state.vertex_program.get(mem);
Expand Down