diff --git a/src/poly/logging.cc b/src/poly/logging.cc index dfbf0dcf4..a00ab61df 100644 --- a/src/poly/logging.cc +++ b/src/poly/logging.cc @@ -9,12 +9,14 @@ #include "poly/logging.h" +#include + #include -#include #include "poly/cxx_compat.h" #include "poly/main.h" #include "poly/math.h" +#include "poly/threading.h" DEFINE_bool(fast_stdout, false, "Don't lock around stdout/stderr. May introduce weirdness."); @@ -42,14 +44,18 @@ void format_log_line(char* buffer, size_t buffer_count, const char* file_path, } // Format string - add a trailing newline if required. - const char* outfmt = "%c> %s:%d: "; + const char* outfmt = "%c> %.2X %s:%d: "; buffer_ptr = buffer + snprintf(buffer, buffer_count - 1, outfmt, level_char, + poly::threading::current_thread_id(), filename, line_number); } else { buffer_ptr = buffer; *(buffer_ptr++) = level_char; *(buffer_ptr++) = '>'; *(buffer_ptr++) = ' '; + buffer_ptr += + sprintf(buffer_ptr, "%.4X", poly::threading::current_thread_id()); + *(buffer_ptr++) = ' '; } // Scribble args into the print buffer. diff --git a/src/xenia/cpu/backend/x64/x64_emitter.cc b/src/xenia/cpu/backend/x64/x64_emitter.cc index d7745459f..ff995b9b1 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.cc +++ b/src/xenia/cpu/backend/x64/x64_emitter.cc @@ -65,7 +65,10 @@ X64Emitter::X64Emitter(X64Backend* backend, XbyakAllocator* allocator) backend_(backend), code_cache_(backend->code_cache()), allocator_(allocator), - current_instr_(0) {} + current_instr_(0), + source_map_count_(0), + stack_size_(0), + trace_flags_(0) {} X64Emitter::~X64Emitter() {} diff --git a/src/xenia/gpu/gl4/gl4_graphics_system.cc b/src/xenia/gpu/gl4/gl4_graphics_system.cc index 3e2257881..c169c4112 100644 --- a/src/xenia/gpu/gl4/gl4_graphics_system.cc +++ b/src/xenia/gpu/gl4/gl4_graphics_system.cc @@ -235,6 +235,11 @@ void GL4GraphicsSystem::PlayTrace(const uint8_t* trace_data, size_t trace_size, }); } +void GL4GraphicsSystem::ClearCaches() { + command_processor_->CallInThread( + [&]() { command_processor_->texture_cache()->Clear(); }); +} + void GL4GraphicsSystem::MarkVblank() { static bool thread_name_set = false; if (!thread_name_set) { diff --git a/src/xenia/gpu/gl4/gl4_graphics_system.h b/src/xenia/gpu/gl4/gl4_graphics_system.h index fece68869..69fb022c6 100644 --- a/src/xenia/gpu/gl4/gl4_graphics_system.h +++ b/src/xenia/gpu/gl4/gl4_graphics_system.h @@ -46,6 +46,7 @@ class GL4GraphicsSystem : public GraphicsSystem { void EndTracing() override; void PlayTrace(const uint8_t* trace_data, size_t trace_size, TracePlaybackMode playback_mode) override; + void ClearCaches() override; private: void MarkVblank(); diff --git a/src/xenia/gpu/graphics_system.h b/src/xenia/gpu/graphics_system.h index e9c41bb72..6a78f5732 100644 --- a/src/xenia/gpu/graphics_system.h +++ b/src/xenia/gpu/graphics_system.h @@ -52,6 +52,7 @@ class GraphicsSystem { }; virtual void PlayTrace(const uint8_t* trace_data, size_t trace_size, TracePlaybackMode playback_mode) {} + virtual void ClearCaches() {} protected: GraphicsSystem(); diff --git a/src/xenia/gpu/trace_viewer_main.cc b/src/xenia/gpu/trace_viewer_main.cc index 5cb9c03a2..de960fc72 100644 --- a/src/xenia/gpu/trace_viewer_main.cc +++ b/src/xenia/gpu/trace_viewer_main.cc @@ -2211,10 +2211,14 @@ int trace_viewer_main(std::vector& args) { } auto control = window->child(0); - control->on_key_char.AddListener([](poly::ui::KeyEvent& e) { + control->on_key_char.AddListener([graphics_system](poly::ui::KeyEvent& e) { auto& io = ImGui::GetIO(); if (e.key_code() > 0 && e.key_code() < 0x10000) { - io.AddInputCharacter(e.key_code()); + if (e.key_code() == 0x74 /* VK_F5 */) { + graphics_system->ClearCaches(); + } else { + io.AddInputCharacter(e.key_code()); + } } e.set_handled(true); }); diff --git a/src/xenia/gpu/xenos.h b/src/xenia/gpu/xenos.h index 0a1ff3803..235795dcf 100644 --- a/src/xenia/gpu/xenos.h +++ b/src/xenia/gpu/xenos.h @@ -257,6 +257,8 @@ inline float GpuSwap(float value, Endian endianness) { inline uint32_t GpuToCpu(uint32_t p) { return p; } +inline uint32_t CpuToGpu(uint32_t p) { return p & 0x1FFFFFFF; } + // XE_GPU_REG_SQ_PROGRAM_CNTL typedef union { XEPACKEDSTRUCTANONYMOUS({ diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index c73cf38b2..94df7fce2 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -333,6 +333,15 @@ X_STATUS XThread::PlatformExit(int exit_code) { #endif // WIN32 void XThread::Execute() { + XELOGKERNEL("XThread::Execute thid %d (handle=%.8X, '%s', native=%.8X)", + thread_id_, handle(), name_.c_str(), + poly::threading::current_thread_id()); + + // All threads get a mandatory sleep. This is to deal with some buggy + // games that are assuming the 360 is so slow to create threads that they + // have time to initialize shared structures AFTER CreateThread (RR). + poly::threading::Sleep(std::chrono::milliseconds::duration(100)); + // If a XapiThreadStartup value is present, we use that as a trampoline. // Otherwise, we are a raw thread. if (creation_params_.xapi_thread_startup) { diff --git a/src/xenia/kernel/xboxkrnl_memory.cc b/src/xenia/kernel/xboxkrnl_memory.cc index fcd80f1a6..a7604c2dc 100644 --- a/src/xenia/kernel/xboxkrnl_memory.cc +++ b/src/xenia/kernel/xboxkrnl_memory.cc @@ -94,6 +94,8 @@ SHIM_CALL NtAllocateVirtualMemory_shim(PPCContext* ppc_state, return; } + XELOGD("NtAllocateVirtualMemory = %.8X", addr); + // Stash back. // Maybe set X_STATUS_ALREADY_COMMITTED if MEM_COMMIT? SHIM_SET_MEM_32(base_addr_ptr, addr); @@ -249,6 +251,7 @@ SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state, SHIM_SET_RETURN_32(0); return; } + XELOGD("MmAllocatePhysicalMemoryEx = %.8X", base_address); // Move the address into the right range. // if (protect_bits & X_MEM_LARGE_PAGES) { @@ -260,7 +263,7 @@ SHIM_CALL MmAllocatePhysicalMemoryEx_shim(PPCContext* ppc_state, //} base_address += 0xA0000000; - SHIM_SET_RETURN_32(base_address); + SHIM_SET_RETURN_64(base_address); } SHIM_CALL MmFreePhysicalMemory_shim(PPCContext* ppc_state, KernelState* state) { @@ -381,7 +384,7 @@ SHIM_CALL MmGetPhysicalAddress_shim(PPCContext* ppc_state, KernelState* state) { base_address |= 0xE0000000; }*/ - SHIM_SET_RETURN_32(base_address); + SHIM_SET_RETURN_64(base_address); } SHIM_CALL MmMapIoSpace_shim(PPCContext* ppc_state, KernelState* state) { @@ -399,7 +402,7 @@ SHIM_CALL MmMapIoSpace_shim(PPCContext* ppc_state, KernelState* state) { assert_true(size == 0x40); assert_true(flags == 0x404); - SHIM_SET_RETURN_32(src_address); + SHIM_SET_RETURN_64(src_address); } SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_state, @@ -420,7 +423,7 @@ SHIM_CALL ExAllocatePoolTypeWithTag_shim(PPCContext* ppc_state, uint32_t addr = state->memory()->SystemHeapAlloc(adjusted_size, alignment); - SHIM_SET_RETURN_32(addr); + SHIM_SET_RETURN_64(addr); } SHIM_CALL ExFreePool_shim(PPCContext* ppc_state, KernelState* state) { diff --git a/src/xenia/kernel/xboxkrnl_rtl.cc b/src/xenia/kernel/xboxkrnl_rtl.cc index d86c5c3a8..d8638c50a 100644 --- a/src/xenia/kernel/xboxkrnl_rtl.cc +++ b/src/xenia/kernel/xboxkrnl_rtl.cc @@ -565,7 +565,7 @@ spin: // All out of spin waits, create a full waiter. // TODO(benvanik): contention - do a real wait! // XELOGE("RtlEnterCriticalSection tried to really lock!"); - spin_wait_remaining = 1; // HACK: spin forever + spin_wait_remaining = 0; // HACK: spin forever Sleep(1); goto spin; } diff --git a/src/xenia/kernel/xboxkrnl_threading.cc b/src/xenia/kernel/xboxkrnl_threading.cc index bb6fc4812..99d456221 100644 --- a/src/xenia/kernel/xboxkrnl_threading.cc +++ b/src/xenia/kernel/xboxkrnl_threading.cc @@ -89,6 +89,7 @@ SHIM_CALL ExCreateThread_shim(PPCContext* ppc_state, KernelState* state) { stack_size, thread_id_ptr, xapi_thread_startup, start_address, start_context, creation_flags); + // http://jafile.com/uploads/scoop/main.cpp.txt // DWORD // LPHANDLE Handle, // DWORD StackSize, diff --git a/src/xenia/kernel/xboxkrnl_video.cc b/src/xenia/kernel/xboxkrnl_video.cc index dc0e478a2..0342316be 100644 --- a/src/xenia/kernel/xboxkrnl_video.cc +++ b/src/xenia/kernel/xboxkrnl_video.cc @@ -356,7 +356,20 @@ SHIM_CALL VdIsHSIOTrainingSucceeded_shim(PPCContext* ppc_state, } SHIM_CALL VdPersistDisplay_shim(PPCContext* ppc_state, KernelState* state) { - XELOGD("VdPersistDisplay(?)"); + uint32_t unk0 = SHIM_GET_ARG_32(0); + uint32_t unk1_ptr = SHIM_GET_ARG_32(1); + uint32_t unk2 = SHIM_GET_ARG_32(2); + uint32_t unk3 = SHIM_GET_ARG_32(3); + uint32_t unk4 = SHIM_GET_ARG_32(4); + uint32_t unk5 = SHIM_GET_ARG_32(5); + uint32_t unk6 = SHIM_GET_ARG_32(6); + uint32_t unk7 = SHIM_GET_ARG_32(7); + + XELOGD("VdPersistDisplay(%.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X)", + unk0, unk1_ptr, unk2, unk3, unk4, unk5, unk6, unk7); + + // unk1_ptr needs to be populated with a pointer passed to + // MmFreePhysicalMemory(1, *unk1_ptr). // ? SHIM_SET_RETURN_64(1); diff --git a/src/xenia/ui/main_window.cc b/src/xenia/ui/main_window.cc index ba2d9b701..4578ecce8 100644 --- a/src/xenia/ui/main_window.cc +++ b/src/xenia/ui/main_window.cc @@ -46,11 +46,22 @@ bool MainWindow::Initialize() { } Resize(1280, 720); on_key_down.AddListener([this](poly::ui::KeyEvent& e) { - if (e.key_code() == 115) { - emulator()->graphics_system()->RequestFrameTrace(); - e.set_handled(true); - return; + bool handled = true; + switch (e.key_code()) { + case 0x73: { // VK_F4 + emulator()->graphics_system()->RequestFrameTrace(); + break; + } + case 0x74: { // VK_F5 + emulator()->graphics_system()->ClearCaches(); + break; + } + default: { + handled = false; + break; + } } + e.set_handled(handled); }); return true; }