PM4 buffer handling made a virtual member of commandprocessor, place the implementation/declaration into reusable macro files. this is probably the biggest boost here. Optimized SET_CONSTANT/ LOAD_CONSTANT pm4 ops based on the register range they start writing at, this was also a nice boost Expose X64 extension flags to code outside of x64 backend, so we can detect and use things like avx512, xop, avx2, etc in normal code Add freelists for HIR structures to try to reduce the number of last level cache misses during optimization (currently disabled... fixme later) Analyzed PGO feedback and reordered branches, uninlined functions, moved code out into different functions based on info from it in the PM4 functions, this gave like a 2% boost at best. Added support for the db16cyc opcode, which is used often in xb360 spinlocks. before it was just being translated to nop, now on x64 we translate it to _mm_pause but may change that in the future to reduce cpu time wasted texture util - all our divisors were powers of 2, instead we look up a shift. this made texture scaling slightly faster, more so on intel processors which seem to be worse at int divs. GetGuestTextureLayout is now a little faster, although it is still one of the heaviest functions in the emulator when scaling is on. xe_unlikely_mutex was not a good choice for the guest clock lock, (running theory) on intel processors another thread may take a significant time to update the clock? maybe because of the uint64 division? really not sure, but switched it to xe_mutex. This fixed audio stutter that i had introduced to 1 or 2 games, fixed performance on that n64 rare game with the monkeys. Took another crack at DMA implementation, another failure. Instead of passing as a parameter, keep the ringbuffer reader as the first member of commandprocessor so it can be accessed through this Added macro for noalias Applied noalias to Memory::LookupHeap. This reduced the size of the executable by 7 kb. Reworked kernel shim template, this shaved like 100kb off the exe and eliminated the indirect calls from the shim to the actual implementation. We still unconditionally generate string representations of kernel calls though :(, unless it is kHighFrequency Add nvapi extensions support, currently unused. Will use CPUVISIBLE memory at some point Inserted prefetches in a few places based on feedback from vtune. Add native implementation of SHA int8 if all elements are the same Vectorized comparisons for SetViewport, SetScissorRect Vectorized ranged comparisons for WriteRegister Add XE_MSVC_ASSUME Move FormatInfo::name out of the structure, instead look up the name in a different table. Debug related data and critical runtime data are best kept apart Templated UpdateSystemConstantValues based on ROV/RTV and primitive_polygonal Add ArchFloatMask functions, these are for storing the results of floating point comparisons without doing costly float->int pipeline transfers (vucomiss/setb) Use floatmasks in UpdateSystemConstantValues for checking if dirty, only transfer to int at end of function. Instead of dirty |= (x == y) in UpdateSystemConstantValues, now we do dirty_u32 |= (x^y). if any of them are not equal, dirty_u32 will be nz, else if theyre all equal it will be zero. This is more friendly to register renaming and the lack of dependencies on EFLAGS lets the compiler reorder better Add PrefetchSamplerParameters to D3D12TextureCache use PrefetchSamplerParameters in UpdateBindings to eliminate cache misses that vtune detected Add PrefetchTextureBinding to D3D12TextureCache Prefetch texture bindings to get rid of more misses vtune detected (more accesses out of order with random strides) Rewrote DMAC, still terrible though and have disabled it for now. Replace tiny memcmp of 6 U64 in render_target_cache with inline loop, msvc fails to make it a loop and instead does a thunk to their memcmp function, which is optimized for larger sizes PrefetchTextureBinding in AreActiveTextureSRVKeysUpToDate Replace memcmp calls for pipelinedescription with handwritten cmp Directly write some registers that dont have special handling in PM4 functions Changed EstimateMaxY to try to eliminate mispredictions that vtune was reporting, msvc ended up turning the changed code into a series of blends in ExecutePacketType3_EVENT_WRITE_EXT, instead of writing extents to an array on the stack and then doing xe_copy_and_swap_16 of the data to its dest, pre-swap each constant and then store those. msvc manages to unroll that into wider stores stop logging XE_SWAP every time we receive XE_SWAP, stop logging the start and end of each viz query Prefetch watch nodes in FireWatches based on feedback from vtune Removed dead code from texture_info.cc NOINLINE on GpuSwap, PGO builds did it so we should too.
184 lines
5.5 KiB
C++
184 lines
5.5 KiB
C++
/**
|
|
******************************************************************************
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
******************************************************************************
|
|
* Copyright 2021 Ben Vanik. All rights reserved. *
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
******************************************************************************
|
|
*/
|
|
|
|
#ifndef XENIA_BASE_LOGGING_H_
|
|
#define XENIA_BASE_LOGGING_H_
|
|
|
|
#include <cstdarg>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include "third_party/fmt/include/fmt/format.h"
|
|
#include "xenia/base/string.h"
|
|
|
|
namespace xe {
|
|
|
|
#define XE_OPTION_ENABLE_LOGGING 1
|
|
|
|
// Log level is a general indication of the importance of a given log line.
|
|
//
|
|
// While log levels are named, they are a rough correlation of what the log line
|
|
// may be related to. These names should not be taken as fact as what a given
|
|
// log line from any log level actually is.
|
|
enum class LogLevel {
|
|
Error = 0,
|
|
Warning,
|
|
Info,
|
|
Debug,
|
|
Trace,
|
|
};
|
|
|
|
class LogSink {
|
|
public:
|
|
virtual ~LogSink() = default;
|
|
|
|
virtual void Write(const char* buf, size_t size) = 0;
|
|
virtual void Flush() = 0;
|
|
};
|
|
|
|
class FileLogSink final : public LogSink {
|
|
public:
|
|
explicit FileLogSink(FILE* file, bool own_file)
|
|
: file_(file), owns_file_(own_file) {}
|
|
~FileLogSink();
|
|
|
|
void Write(const char* buf, size_t size) override;
|
|
void Flush() override;
|
|
|
|
private:
|
|
FILE* file_;
|
|
bool owns_file_;
|
|
};
|
|
|
|
class DebugPrintLogSink final : public LogSink {
|
|
public:
|
|
DebugPrintLogSink() = default;
|
|
|
|
void Write(const char* buf, size_t size) override;
|
|
void Flush() override {}
|
|
};
|
|
|
|
// Initializes the logging system and any outputs requested.
|
|
// Must be called on startup.
|
|
void InitializeLogging(const std::string_view app_name);
|
|
void ShutdownLogging();
|
|
|
|
namespace logging {
|
|
namespace internal {
|
|
|
|
bool ShouldLog(LogLevel log_level);
|
|
std::pair<char*, size_t> GetThreadBuffer();
|
|
XE_NOALIAS
|
|
void AppendLogLine(LogLevel log_level, const char prefix_char, size_t written);
|
|
|
|
} // namespace internal
|
|
//technically, noalias is incorrect here, these functions do in fact alias global memory,
|
|
//but msvc will not optimize the calls away, and the global memory modified by the calls is limited to internal logging variables,
|
|
//so it might as well be noalias
|
|
template <typename... Args>
|
|
XE_NOALIAS
|
|
XE_NOINLINE XE_COLD static void AppendLogLineFormat_Impl(LogLevel log_level,
|
|
const char prefix_char,
|
|
const char* format,
|
|
const Args&... args) {
|
|
auto target = internal::GetThreadBuffer();
|
|
auto result = fmt::format_to_n(target.first, target.second, format, args...);
|
|
internal::AppendLogLine(log_level, prefix_char, result.size);
|
|
}
|
|
|
|
// Appends a line to the log with {fmt}-style formatting.
|
|
//chrispy: inline the initial check, outline the append. the append should happen rarely for end users
|
|
template <typename... Args>
|
|
XE_FORCEINLINE static void AppendLogLineFormat(LogLevel log_level, const char prefix_char,
|
|
const char* format, const Args&... args) {
|
|
if (!internal::ShouldLog(log_level)) {
|
|
return;
|
|
}
|
|
AppendLogLineFormat_Impl(log_level, prefix_char, format, args...);
|
|
}
|
|
|
|
// Appends a line to the log.
|
|
void AppendLogLine(LogLevel log_level, const char prefix_char,
|
|
const std::string_view str);
|
|
|
|
} // namespace logging
|
|
|
|
// Logs a fatal error and aborts the program.
|
|
[[noreturn]] void FatalError(const std::string_view str);
|
|
|
|
} // namespace xe
|
|
|
|
#if XE_OPTION_ENABLE_LOGGING
|
|
|
|
template <typename... Args>
|
|
XE_COLD void XELOGE(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Error, '!', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
XE_COLD
|
|
void XELOGW(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Warning, 'w', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGI(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'i', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGD(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'd', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGCPU(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'C', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGAPU(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'A', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGGPU(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Debug, 'G', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGKERNEL(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'K', format, args...);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void XELOGFS(const char* format, const Args&... args) {
|
|
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'F', format, args...);
|
|
}
|
|
|
|
#else
|
|
|
|
#define __XELOGDUMMY \
|
|
do { \
|
|
} while (false)
|
|
|
|
#define XELOGE(...) __XELOGDUMMY
|
|
#define XELOGW(...) __XELOGDUMMY
|
|
#define XELOGI(...) __XELOGDUMMY
|
|
#define XELOGD(...) __XELOGDUMMY
|
|
#define XELOGCPU(...) __XELOGDUMMY
|
|
#define XELOGAPU(...) __XELOGDUMMY
|
|
#define XELOGGPU(...) __XELOGDUMMY
|
|
#define XELOGKERNEL(...) __XELOGDUMMY
|
|
#define XELOGFS(...) __XELOGDUMMY
|
|
|
|
#endif // ENABLE_LOGGING
|
|
|
|
#endif // XENIA_BASE_LOGGING_H_
|