Files
Xenia-Canary/src/xenia/gpu/trace_writer.h
chss95cs@gmail.com cb85fe401c Huge set of performance improvements, combined with an architecture specific build and clang-cl users have reported absurd gains over master for some gains, in the range 50%-90%
But for normal msvc builds i would put it at around 30-50%
Added per-xexmodule caching of information per instruction, can be used to remember what code needs compiling at start up
Record what guest addresses wrote mmio and backpropagate that to future runs, eliminating dependence on exception trapping. this makes many games like h3 actually tolerable to run under a debugger
fixed a number of errors where temporaries were being passed by reference/pointer
Can now be compiled with clang-cl 14.0.1, requires -Werror off though and some other solution/project changes.
Added macros wrapping compiler extensions like noinline, forceinline, __expect, and cold.
Removed the "global lock" in guest code completely. It does not properly emulate the behavior of mfmsrd/mtmsr and it seriously cripples amd cpus. Removing this yielded around a 3x speedup in Halo Reach for me.
Disabled the microprofiler for now. The microprofiler has a huge performance cost associated with it. Developers can re-enable it in the base/profiling header if they really need it
Disable the trace writer in release builds. despite just returning after checking if the file was open the trace functions were consuming about 0.60% cpu time total
Add IsValidReg, GetRegisterInfo is a huge (about 45k) branching function and using that to check if a register was valid consumed a significant chunk of time
Optimized RingBuffer::ReadAndSwap and RingBuffer::read_count. This gave us the largest overall boost in performance. The memcpies were unnecessary and one of them was always a no-op
Added simplification rules for multiplicative patterns like (x+x), (x<<1)+x
For the most frequently called win32 functions i added code to call their underlying NT implementations, which lets us skip a lot of MS code we don't care about/isnt relevant to our usecases
^this can be toggled off in the platform_win header
handle indirect call true with constant function pointer, was occurring in h3
lookup host format swizzle in denser array
by default, don't check if a gpu register is unknown, instead just check if its out of range. controlled by a cvar
^looking up whether its known or not took approx 0.3% cpu time
Changed some things in /cpu to make the project UNITYBUILD friendly
The timer thread was spinning way too much and consuming a ton of cpu, changed it to use a blocking wait instead
tagged some conditions as XE_UNLIKELY/LIKELY based on profiler feedback (will only affect clang builds)
Shifted around some code in CommandProcessor::WriteRegister based on how frequently it was executed
added support for docdecaduple precision floating point so that we can represent our performance gains numerically
tons of other stuff im probably forgetting
2022-08-13 12:59:00 -07:00

124 lines
4.9 KiB
C++

/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_GPU_TRACE_WRITER_H_
#define XENIA_GPU_TRACE_WRITER_H_
#include <filesystem>
#include <set>
#include <string>
#include "xenia/gpu/registers.h"
#include "xenia/gpu/trace_protocol.h"
// only enable trace writer in debug builds, measured hit from the trace
// function calls (even if they just immediately return) is 0.40-0.60% cpu time
// total. with inlining they just bloat the caller and negatively impact
// register allocation for the caller
#ifdef NDEBUG
#define XE_ENABLE_TRACE_WRITER_INSTRUMENTATION 0
#else
#define XE_ENABLE_TRACE_WRITER_INSTRUMENTATION 1
#endif
namespace xe {
namespace gpu {
class TraceWriter {
public:
#if XE_ENABLE_TRACE_WRITER_INSTRUMENTATION == 1
explicit TraceWriter(uint8_t* membase);
~TraceWriter();
bool is_open() const { return file_ != nullptr; }
bool Open(const std::filesystem::path& path, uint32_t title_id);
void Flush();
void Close();
void WritePrimaryBufferStart(uint32_t base_ptr, uint32_t count);
void WritePrimaryBufferEnd();
void WriteIndirectBufferStart(uint32_t base_ptr, uint32_t count);
void WriteIndirectBufferEnd();
void WritePacketStart(uint32_t base_ptr, uint32_t count);
void WritePacketEnd();
void WriteMemoryRead(uint32_t base_ptr, size_t length,
const void* host_ptr = nullptr);
void WriteMemoryReadCached(uint32_t base_ptr, size_t length);
void WriteMemoryReadCachedNop(uint32_t base_ptr, size_t length);
void WriteMemoryWrite(uint32_t base_ptr, size_t length,
const void* host_ptr = nullptr);
void WriteEdramSnapshot(const void* snapshot);
void WriteEvent(EventCommand::Type event_type);
void WriteRegisters(uint32_t first_register, const uint32_t* register_values,
uint32_t register_count, bool execute_callbacks_on_play);
void WriteGammaRamp(const reg::DC_LUT_30_COLOR* gamma_ramp_256_entry_table,
const reg::DC_LUT_PWL_DATA* gamma_ramp_pwl_rgb,
uint32_t gamma_ramp_rw_component);
private:
void WriteMemoryCommand(TraceCommandType type, uint32_t base_ptr,
size_t length, const void* host_ptr = nullptr);
std::set<uint64_t> cached_memory_reads_;
uint8_t* membase_;
FILE* file_;
bool compress_output_ = true;
size_t compression_threshold_ = 1024; // Min. number of bytes to compress.
#else
// this could be annoying to maintain if new methods are added or the
// signatures change
constexpr explicit TraceWriter(uint8_t* membase) {}
static constexpr bool is_open() { return false; }
static constexpr bool Open(const std::filesystem::path& path,
uint32_t title_id) {
return false;
}
static constexpr void Flush() {}
static constexpr void Close() {}
static constexpr void WritePrimaryBufferStart(uint32_t base_ptr,
uint32_t count) {}
static constexpr void WritePrimaryBufferEnd() {}
static constexpr void WriteIndirectBufferStart(uint32_t base_ptr,
uint32_t count) {}
static constexpr void WriteIndirectBufferEnd() {}
static constexpr void WritePacketStart(uint32_t base_ptr, uint32_t count) {}
static constexpr void WritePacketEnd() {}
static constexpr void WriteMemoryRead(uint32_t base_ptr, size_t length,
const void* host_ptr = nullptr) {}
static constexpr void WriteMemoryReadCached(uint32_t base_ptr,
size_t length) {}
static constexpr void WriteMemoryReadCachedNop(uint32_t base_ptr,
size_t length) {}
static constexpr void WriteMemoryWrite(uint32_t base_ptr, size_t length,
const void* host_ptr = nullptr) {}
static constexpr void WriteEdramSnapshot(const void* snapshot) {}
static constexpr void WriteEvent(EventCommand::Type event_type) {}
static constexpr void WriteRegisters(uint32_t first_register,
const uint32_t* register_values,
uint32_t register_count,
bool execute_callbacks_on_play) {}
static constexpr void WriteGammaRamp(
const reg::DC_LUT_30_COLOR* gamma_ramp_256_entry_table,
const reg::DC_LUT_PWL_DATA* gamma_ramp_pwl_rgb,
uint32_t gamma_ramp_rw_component) {}
#endif
};
} // namespace gpu
} // namespace xe
#endif // XENIA_GPU_TRACE_WRITER_H_