C++17ification.

C++17ification!

- Filesystem interaction now uses std::filesystem::path.
- Usage of const char*, std::string have been changed to
  std::string_view where appropriate.
- Usage of printf-style functions changed to use fmt.
This commit is contained in:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -13,6 +13,7 @@
#include <cinttypes>
#include <cmath>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/byte_stream.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
@@ -87,11 +88,12 @@ void CommandProcessor::Shutdown() {
worker_thread_.reset();
}
void CommandProcessor::InitializeShaderStorage(const std::wstring& storage_root,
uint32_t title_id,
bool blocking) {}
void CommandProcessor::InitializeShaderStorage(
const std::filesystem::path& storage_root, uint32_t title_id,
bool blocking) {}
void CommandProcessor::RequestFrameTrace(const std::wstring& root_path) {
void CommandProcessor::RequestFrameTrace(
const std::filesystem::path& root_path) {
if (trace_state_ == TraceState::kStreaming) {
XELOGE("Streaming trace; cannot also trace frame.");
return;
@@ -104,7 +106,7 @@ void CommandProcessor::RequestFrameTrace(const std::wstring& root_path) {
trace_frame_path_ = root_path;
}
void CommandProcessor::BeginTracing(const std::wstring& root_path) {
void CommandProcessor::BeginTracing(const std::filesystem::path& root_path) {
if (trace_state_ == TraceState::kStreaming) {
XELOGE("Streaming already active; ignoring request.");
return;
@@ -440,8 +442,8 @@ uint32_t CommandProcessor::ExecutePrimaryBuffer(uint32_t read_index,
uint32_t title_id = kernel_state_->GetExecutableModule()
? kernel_state_->GetExecutableModule()->title_id()
: 0;
auto file_name = xe::format_string(L"%8X_stream.xtr", title_id);
auto path = trace_stream_path_ + file_name;
auto file_name = fmt::format("{:8X}_stream.xtr", title_id);
auto path = trace_stream_path_ / file_name;
trace_writer_.Open(path, title_id);
InitializeTrace();
}
@@ -754,8 +756,8 @@ bool CommandProcessor::ExecutePacketType3(RingBuffer* reader, uint32_t packet) {
} else if (trace_state_ == TraceState::kSingleFrame) {
// New trace request - we only start tracing at the beginning of a frame.
uint32_t title_id = kernel_state_->GetExecutableModule()->title_id();
auto file_name = xe::format_string(L"%8X_%u.xtr", title_id, counter_ - 1);
auto path = trace_frame_path_ + file_name;
auto file_name = fmt::format("{:8X}_{}.xtr", title_id, counter_ - 1);
auto path = trace_frame_path_ / file_name;
trace_writer_.Open(path, title_id);
InitializeTrace();
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -133,11 +133,12 @@ class CommandProcessor {
// May be called not only from the command processor thread when the command
// processor is paused, and the termination of this function may be explicitly
// awaited.
virtual void InitializeShaderStorage(const std::wstring& storage_root,
uint32_t title_id, bool blocking);
virtual void InitializeShaderStorage(
const std::filesystem::path& storage_root, uint32_t title_id,
bool blocking);
virtual void RequestFrameTrace(const std::wstring& root_path);
virtual void BeginTracing(const std::wstring& root_path);
virtual void RequestFrameTrace(const std::filesystem::path& root_path);
virtual void BeginTracing(const std::filesystem::path& root_path);
virtual void EndTracing();
virtual void TracePlaybackWroteMemory(uint32_t base_ptr, uint32_t length) = 0;
@@ -264,8 +265,8 @@ class CommandProcessor {
kSingleFrame,
};
TraceState trace_state_ = TraceState::kDisabled;
std::wstring trace_stream_path_;
std::wstring trace_frame_path_;
std::filesystem::path trace_stream_path_;
std::filesystem::path trace_frame_path_;
std::atomic<bool> worker_running_;
kernel::object_ref<kernel::XHostThread> worker_thread_;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -85,12 +85,14 @@ void D3D12CommandProcessor::ClearCaches() {
}
void D3D12CommandProcessor::InitializeShaderStorage(
const std::wstring& storage_root, uint32_t title_id, bool blocking) {
const std::filesystem::path& storage_root, uint32_t title_id,
bool blocking) {
CommandProcessor::InitializeShaderStorage(storage_root, title_id, blocking);
pipeline_cache_->InitializeShaderStorage(storage_root, title_id, blocking);
}
void D3D12CommandProcessor::RequestFrameTrace(const std::wstring& root_path) {
void D3D12CommandProcessor::RequestFrameTrace(
const std::filesystem::path& root_path) {
// Capture with PIX if attached.
if (GetD3D12Context()->GetD3D12Provider()->GetGraphicsAnalysis() != nullptr) {
pix_capture_requested_.store(true, std::memory_order_relaxed);
@@ -668,16 +670,16 @@ void D3D12CommandProcessor::SetExternalGraphicsPipeline(
}
}
std::wstring D3D12CommandProcessor::GetWindowTitleText() const {
std::string D3D12CommandProcessor::GetWindowTitleText() const {
if (IsROVUsedForEDRAM()) {
// Currently scaling is only supported with ROV.
if (texture_cache_ != nullptr && texture_cache_->IsResolutionScale2X()) {
return L"Direct3D 12 - ROV 2x";
return "Direct3D 12 - ROV 2x";
} else {
return L"Direct3D 12 - ROV";
return "Direct3D 12 - ROV";
}
} else {
return L"Direct3D 12 - RTV/DSV";
return "Direct3D 12 - RTV/DSV";
}
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -43,10 +43,10 @@ class D3D12CommandProcessor : public CommandProcessor {
void ClearCaches() override;
void InitializeShaderStorage(const std::wstring& storage_root,
void InitializeShaderStorage(const std::filesystem::path& storage_root,
uint32_t title_id, bool blocking) override;
void RequestFrameTrace(const std::wstring& root_path) override;
void RequestFrameTrace(const std::filesystem::path& root_path) override;
void TracePlaybackWroteMemory(uint32_t base_ptr, uint32_t length) override;
@@ -154,7 +154,7 @@ class D3D12CommandProcessor : public CommandProcessor {
bool changing_stencil_ref = false);
// Returns the text to display in the GPU backend name in the window title.
std::wstring GetWindowTitleText() const;
std::string GetWindowTitleText() const;
std::unique_ptr<xe::ui::RawImage> Capture();

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -31,13 +31,13 @@ bool D3D12GraphicsSystem::IsAvailable() {
return xe::ui::d3d12::D3D12Provider::IsD3D12APIAvailable();
}
std::wstring D3D12GraphicsSystem::name() const {
std::string D3D12GraphicsSystem::name() const {
auto d3d12_command_processor =
static_cast<D3D12CommandProcessor*>(command_processor());
if (d3d12_command_processor != nullptr) {
return d3d12_command_processor->GetWindowTitleText();
}
return L"Direct3D 12";
return "Direct3D 12";
}
X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -28,7 +28,7 @@ class D3D12GraphicsSystem : public GraphicsSystem {
static bool IsAvailable();
std::wstring name() const override;
std::string name() const override;
X_STATUS Setup(cpu::Processor* processor, kernel::KernelState* kernel_state,
ui::Window* target_window) override;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -45,7 +45,7 @@ class D3D12TraceDump : public TraceDump {
}
};
int trace_dump_main(const std::vector<std::wstring>& args) {
int trace_dump_main(const std::vector<std::string>& args) {
D3D12TraceDump trace_dump;
return trace_dump.Main(args);
}
@@ -54,6 +54,6 @@ int trace_dump_main(const std::vector<std::wstring>& args) {
} // namespace gpu
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-gpu-d3d12-trace-dump",
DEFINE_ENTRY_POINT("xenia-gpu-d3d12-trace-dump",
xe::gpu::d3d12::trace_dump_main, "some.trace",
"target_trace_file");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -47,7 +47,7 @@ class D3D12TraceViewer : public TraceViewer {
}
};
int trace_viewer_main(const std::vector<std::wstring>& args) {
int trace_viewer_main(const std::vector<std::string>& args) {
D3D12TraceViewer trace_viewer;
return trace_viewer.Main(args);
}
@@ -56,6 +56,6 @@ int trace_viewer_main(const std::vector<std::wstring>& args) {
} // namespace gpu
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-gpu-d3d12-trace-viewer",
DEFINE_ENTRY_POINT("xenia-gpu-d3d12-trace-viewer",
xe::gpu::d3d12::trace_viewer_main, "some.trace",
"target_trace_file");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -18,8 +18,8 @@
#include <mutex>
#include <utility>
#include "third_party/fmt/include/fmt/format.h"
#include "third_party/xxhash/xxhash.h"
#include "xenia/base/assert.h"
#include "xenia/base/byte_order.h"
#include "xenia/base/clock.h"
@@ -138,7 +138,7 @@ void PipelineCache::Shutdown() {
void PipelineCache::ClearCache(bool shutting_down) {
bool reinitialize_shader_storage =
!shutting_down && storage_write_thread_ != nullptr;
std::wstring shader_storage_root;
std::filesystem::path shader_storage_root;
uint32_t shader_storage_title_id = shader_storage_title_id_;
if (reinitialize_shader_storage) {
shader_storage_root = shader_storage_root_;
@@ -188,19 +188,19 @@ void PipelineCache::ClearCache(bool shutting_down) {
}
}
void PipelineCache::InitializeShaderStorage(const std::wstring& storage_root,
uint32_t title_id, bool blocking) {
void PipelineCache::InitializeShaderStorage(
const std::filesystem::path& storage_root, uint32_t title_id,
bool blocking) {
ShutdownShaderStorage();
auto shader_storage_root = xe::join_paths(storage_root, L"shaders");
auto shader_storage_root = storage_root / "shaders";
// For files that can be moved between different hosts.
// Host PSO blobs - if ever added - should be stored in shaders/local/ (they
// currently aren't used because because they may be not very practical -
// would need to invalidate them every commit likely, and additional I/O
// cost - though D3D's internal validation would possibly be enough to ensure
// they are up to date).
auto shader_storage_shareable_root =
xe::join_paths(shader_storage_root, L"shareable");
auto shader_storage_shareable_root = shader_storage_root / "shareable";
if (!xe::filesystem::CreateFolder(shader_storage_shareable_root)) {
return;
}
@@ -215,8 +215,7 @@ void PipelineCache::InitializeShaderStorage(const std::wstring& storage_root,
uint64_t shader_storage_initialization_start =
xe::Clock::QueryHostTickCount();
shader_storage_file_ = xe::filesystem::OpenFile(
xe::join_paths(shader_storage_shareable_root,
xe::format_string(L"%.8X.xsh", title_id)),
shader_storage_shareable_root / fmt::format("{:08X}.xsh", title_id),
"a+b");
if (!shader_storage_file_) {
return;
@@ -388,11 +387,11 @@ void PipelineCache::InitializeShaderStorage(const std::wstring& storage_root,
// Initialize the pipeline state storage stream.
uint64_t pipeline_state_storage_initialization_start_ =
xe::Clock::QueryHostTickCount();
pipeline_state_storage_file_ = xe::filesystem::OpenFile(
xe::join_paths(shader_storage_shareable_root,
xe::format_string(L"%.8X.%s.d3d12.xpso", title_id,
edram_rov_used_ ? L"rov" : L"rtv")),
"a+b");
pipeline_state_storage_file_ =
xe::filesystem::OpenFile(shader_storage_shareable_root /
fmt::format("{:08X}.{}.d3d12.xpso", title_id,
edram_rov_used_ ? "rov" : "rtv"),
"a+b");
if (!pipeline_state_storage_file_) {
fclose(shader_storage_file_);
shader_storage_file_ = nullptr;
@@ -1694,13 +1693,12 @@ ID3D12PipelineState* PipelineCache::CreateD3D12PipelineState(
}
std::wstring name;
if (runtime_description.pixel_shader != nullptr) {
name =
xe::format_string(L"VS %.16I64X, PS %.16I64X",
runtime_description.vertex_shader->ucode_data_hash(),
runtime_description.pixel_shader->ucode_data_hash());
name = fmt::format(L"VS {:016X}, PS {:016X}",
runtime_description.vertex_shader->ucode_data_hash(),
runtime_description.pixel_shader->ucode_data_hash());
} else {
name = xe::format_string(
L"VS %.16I64X", runtime_description.vertex_shader->ucode_data_hash());
name = fmt::format(L"VS {:016X}",
runtime_description.vertex_shader->ucode_data_hash());
}
state->SetName(name.c_str());
return state;

View File

@@ -46,7 +46,7 @@ class PipelineCache {
void Shutdown();
void ClearCache(bool shutting_down = false);
void InitializeShaderStorage(const std::wstring& storage_root,
void InitializeShaderStorage(const std::filesystem::path& storage_root,
uint32_t title_id, bool blocking);
void ShutdownShaderStorage();
@@ -262,7 +262,7 @@ class PipelineCache {
PipelineState* current_pipeline_state_ = nullptr;
// Currently open shader storage path.
std::wstring shader_storage_root_;
std::filesystem::path shader_storage_root_;
uint32_t shader_storage_title_id_ = 0;
// Shader storage output stream, for preload in the next emulator runs.

View File

@@ -7,6 +7,7 @@ project("xenia-gpu-d3d12")
kind("StaticLib")
language("C++")
links({
"fmt",
"xenia-base",
"xenia-gpu",
"xenia-ui",
@@ -27,6 +28,7 @@ project("xenia-gpu-d3d12-trace-viewer")
"aes_128",
"capstone",
"dxbc",
"fmt",
"imgui",
"libavcodec",
"libavutil",
@@ -71,6 +73,7 @@ project("xenia-gpu-d3d12-trace-dump")
"aes_128",
"capstone",
"dxbc",
"fmt",
"imgui",
"libavcodec",
"libavutil",

View File

@@ -1618,7 +1618,7 @@ void DxbcShaderTranslator::EmitInstructionDisassembly() {
return;
}
const char* source = instruction_disassembly_buffer_.GetString();
const char* source = instruction_disassembly_buffer_.buffer();
uint32_t length = uint32_t(instruction_disassembly_buffer_.length());
// Trim leading spaces and trailing new line.
while (length != 0 && source[0] == ' ') {

View File

@@ -2,21 +2,20 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2018 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/gpu/dxbc_shader_translator.h"
#include <algorithm>
#include <memory>
#include <sstream>
#include "third_party/dxbc/d3d12TokenizedProgramFormat.hpp"
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/assert.h"
#include "xenia/base/string.h"
#include "xenia/gpu/dxbc_shader_translator.h"
namespace xe {
namespace gpu {
@@ -791,9 +790,8 @@ uint32_t DxbcShaderTranslator::FindOrAddTextureSRV(uint32_t fetch_constant,
default:
dimension_name = "2d";
}
new_texture_srv.name =
xe::format_string("xe_texture%u_%s_%c", fetch_constant, dimension_name,
is_signed ? 's' : 'u');
new_texture_srv.name = fmt::format("xe_texture{}_{}_{}", fetch_constant,
dimension_name, is_signed ? 's' : 'u');
uint32_t srv_register = 1 + uint32_t(texture_srvs_.size());
texture_srvs_.emplace_back(std::move(new_texture_srv));
return srv_register;

View File

@@ -2,18 +2,18 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/gpu/gpu_flags.h"
DEFINE_string(trace_gpu_prefix, "scratch/gpu/",
"Prefix path for GPU trace files.", "GPU");
DEFINE_path(trace_gpu_prefix, "scratch/gpu/",
"Prefix path for GPU trace files.", "GPU");
DEFINE_bool(trace_gpu_stream, false, "Trace all GPU packets.", "GPU");
DEFINE_string(
DEFINE_path(
dump_shaders, "",
"For shader debugging, path to dump GPU shaders to as they are compiled.",
"GPU");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -11,10 +11,10 @@
#define XENIA_GPU_GPU_FLAGS_H_
#include "xenia/base/cvar.h"
DECLARE_string(trace_gpu_prefix);
DECLARE_path(trace_gpu_prefix);
DECLARE_bool(trace_gpu_stream);
DECLARE_string(dump_shaders);
DECLARE_path(dump_shaders);
DECLARE_bool(vsync);

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -275,8 +275,9 @@ void GraphicsSystem::ClearCaches() {
[&]() { command_processor_->ClearCaches(); });
}
void GraphicsSystem::InitializeShaderStorage(const std::wstring& storage_root,
uint32_t title_id, bool blocking) {
void GraphicsSystem::InitializeShaderStorage(
const std::filesystem::path& storage_root, uint32_t title_id,
bool blocking) {
if (!cvars::store_shaders) {
return;
}
@@ -304,12 +305,11 @@ void GraphicsSystem::InitializeShaderStorage(const std::wstring& storage_root,
}
void GraphicsSystem::RequestFrameTrace() {
command_processor_->RequestFrameTrace(
xe::to_wstring(cvars::trace_gpu_prefix));
command_processor_->RequestFrameTrace(cvars::trace_gpu_prefix);
}
void GraphicsSystem::BeginTracing() {
command_processor_->BeginTracing(xe::to_wstring(cvars::trace_gpu_prefix));
command_processor_->BeginTracing(cvars::trace_gpu_prefix);
}
void GraphicsSystem::EndTracing() { command_processor_->EndTracing(); }

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -35,7 +35,7 @@ class GraphicsSystem {
public:
virtual ~GraphicsSystem();
virtual std::wstring name() const = 0;
virtual std::string name() const = 0;
Memory* memory() const { return memory_; }
cpu::Processor* processor() const { return processor_; }
@@ -63,7 +63,7 @@ class GraphicsSystem {
virtual void ClearCaches();
void InitializeShaderStorage(const std::wstring& storage_root,
void InitializeShaderStorage(const std::filesystem::path& storage_root,
uint32_t title_id, bool blocking);
void RequestFrameTrace();

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,7 +26,7 @@ class NullGraphicsSystem : public GraphicsSystem {
static bool IsAvailable() { return true; }
std::wstring name() const override { return L"null"; }
std::string name() const override { return "null"; }
X_STATUS Setup(cpu::Processor* processor, kernel::KernelState* kernel_state,
ui::Window* target_window) override;

View File

@@ -8,6 +8,7 @@ project("xenia-gpu")
language("C++")
links({
"dxbc",
"fmt",
"glslang-spirv",
"snappy",
"spirv-tools",
@@ -32,6 +33,7 @@ project("xenia-gpu-shader-compiler")
language("C++")
links({
"dxbc",
"fmt",
"glslang-spirv",
"spirv-tools",
"xenia-base",

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -12,6 +12,7 @@
#include <cinttypes>
#include <cstring>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -40,30 +41,32 @@ std::string Shader::GetTranslatedBinaryString() const {
return result;
}
std::pair<std::string, std::string> Shader::Dump(const std::string& base_path,
const char* path_prefix) {
std::pair<std::filesystem::path, std::filesystem::path> Shader::Dump(
const std::filesystem::path& base_path, const char* path_prefix) {
// Ensure target path exists.
auto target_path = xe::to_wstring(base_path);
auto target_path = base_path;
if (!target_path.empty()) {
target_path = xe::to_absolute_path(target_path);
target_path = std::filesystem::absolute(target_path);
xe::filesystem::CreateFolder(target_path);
}
const std::string file_name_no_extension =
xe::format_string("%s/shader_%s_%.16" PRIX64, base_path.c_str(),
path_prefix, ucode_data_hash_);
std::string txt_file_name, bin_file_name;
auto base_name =
fmt::format("shader_{}_{:016X}", path_prefix, ucode_data_hash_);
std::string txt_name, bin_name;
if (shader_type_ == ShaderType::kVertex) {
txt_file_name = file_name_no_extension + ".vert";
bin_file_name = file_name_no_extension + ".bin.vert";
txt_name = base_name + ".vert";
bin_name = base_name + ".bin.vert";
} else {
txt_file_name = file_name_no_extension + ".frag";
bin_file_name = file_name_no_extension + ".bin.frag";
txt_name = base_name + ".frag";
bin_name = base_name + ".bin.frag";
}
FILE* f = fopen(txt_file_name.c_str(), "wb");
std::filesystem::path txt_path, bin_path;
txt_path = base_path / txt_name;
bin_path = base_path / bin_name;
FILE* f = filesystem::OpenFile(txt_path, "wb");
if (f) {
fwrite(translated_binary_.data(), 1, translated_binary_.size(), f);
fprintf(f, "\n\n");
@@ -81,13 +84,13 @@ std::pair<std::string, std::string> Shader::Dump(const std::string& base_path,
fclose(f);
}
f = fopen(bin_file_name.c_str(), "wb");
f = filesystem::OpenFile(bin_path, "wb");
if (f) {
fwrite(ucode_data_.data(), 4, ucode_data_.size(), f);
fclose(f);
}
return {std::move(txt_file_name), std::move(bin_file_name)};
return {std::move(txt_path), std::move(bin_path)};
}
} // namespace gpu

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -10,6 +10,7 @@
#ifndef XENIA_GPU_SHADER_H_
#define XENIA_GPU_SHADER_H_
#include <filesystem>
#include <string>
#include <vector>
@@ -685,8 +686,8 @@ class Shader {
// Both the ucode binary and disassembled and translated shader will be
// written.
// Returns the filename of the shader and the binary.
std::pair<std::string, std::string> Dump(const std::string& base_path,
const char* path_prefix);
std::pair<std::filesystem::path, std::filesystem::path> Dump(
const std::filesystem::path& base_path, const char* path_prefix);
protected:
friend class ShaderTranslator;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -27,11 +27,11 @@
#include "xenia/ui/d3d12/d3d12_api.h"
#endif // XE_PLATFORM_WIN32
DEFINE_string(shader_input, "", "Input shader binary file path.", "GPU");
DEFINE_path(shader_input, "", "Input shader binary file path.", "GPU");
DEFINE_string(shader_input_type, "",
"'vs', 'ps', or unspecified to infer from the given filename.",
"GPU");
DEFINE_string(shader_output, "", "Output shader file path.", "GPU");
DEFINE_path(shader_output, "", "Output shader file path.", "GPU");
DEFINE_string(shader_output_type, "ucode",
"Translator to use: [ucode, spirv, spirvtext, dxbc, dxbctext].",
"GPU");
@@ -48,7 +48,7 @@ DEFINE_bool(shader_output_dxbc_rov, false,
namespace xe {
namespace gpu {
int shader_compiler_main(const std::vector<std::wstring>& args) {
int shader_compiler_main(const std::vector<std::string>& args) {
ShaderType shader_type;
if (!cvars::shader_input_type.empty()) {
if (cvars::shader_input_type == "vs") {
@@ -60,13 +60,13 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
return 1;
}
} else {
auto last_dot = cvars::shader_input.find_last_of('.');
bool valid_type = false;
if (last_dot != std::string::npos) {
if (cvars::shader_input.substr(last_dot) == ".vs") {
if (cvars::shader_input.has_extension()) {
auto extension = cvars::shader_input.extension();
if (extension == ".vs") {
shader_type = ShaderType::kVertex;
valid_type = true;
} else if (cvars::shader_input.substr(last_dot) == ".ps") {
} else if (extension == ".ps") {
shader_type = ShaderType::kPixel;
valid_type = true;
}
@@ -79,9 +79,10 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
}
auto input_file = fopen(cvars::shader_input.c_str(), "rb");
auto input_file = filesystem::OpenFile(cvars::shader_input, "rb");
if (!input_file) {
XELOGE("Unable to open input file: %s", cvars::shader_input.c_str());
XELOGE("Unable to open input file: %s",
xe::path_to_utf8(cvars::shader_input).c_str());
return 1;
}
fseek(input_file, 0, SEEK_END);
@@ -92,7 +93,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
fclose(input_file);
XELOGI("Opened %s as a %s shader, %" PRId64 " words (%" PRId64 " bytes).",
cvars::shader_input.c_str(),
xe::path_to_utf8(cvars::shader_input).c_str(),
shader_type == ShaderType::kVertex ? "vertex" : "pixel",
ucode_dwords.size(), ucode_dwords.size() * 4);
@@ -153,7 +154,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
#if XE_PLATFORM_WIN32
ID3DBlob* dxbc_disasm_blob = nullptr;
if (cvars::shader_output_type == "dxbctext") {
HMODULE d3d_compiler = LoadLibrary(L"D3DCompiler_47.dll");
HMODULE d3d_compiler = LoadLibraryW(L"D3DCompiler_47.dll");
if (d3d_compiler != nullptr) {
pD3DDisassemble d3d_disassemble =
pD3DDisassemble(GetProcAddress(d3d_compiler, "D3DDisassemble"));
@@ -180,7 +181,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
#endif // XE_PLATFORM_WIN32
if (!cvars::shader_output.empty()) {
auto output_file = fopen(cvars::shader_output.c_str(), "wb");
auto output_file = filesystem::OpenFile(cvars::shader_output, "wb");
fwrite(source_data, 1, source_data_size, output_file);
fclose(output_file);
}
@@ -197,5 +198,5 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
} // namespace gpu
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-gpu-shader-compiler", xe::gpu::shader_compiler_main,
DEFINE_ENTRY_POINT("xenia-gpu-shader-compiler", xe::gpu::shader_compiler_main,
"shader.bin", "shader_input");

View File

@@ -224,7 +224,7 @@ bool ShaderTranslator::TranslateInternal(
}
void ShaderTranslator::MarkUcodeInstruction(uint32_t dword_offset) {
auto disasm = ucode_disasm_buffer_.GetString();
auto disasm = ucode_disasm_buffer_.buffer();
size_t current_offset = ucode_disasm_buffer_.length();
for (size_t i = previous_ucode_disasm_scan_offset_; i < current_offset; ++i) {
if (disasm[i] == '\n') {
@@ -568,7 +568,7 @@ bool ShaderTranslator::TranslateBlocks() {
}
std::vector<uint8_t> UcodeShaderTranslator::CompleteTranslation() {
return ucode_disasm_buffer().ToBytes();
return ucode_disasm_buffer().to_bytes();
}
void ShaderTranslator::TranslateControlFlowInstruction(

View File

@@ -46,7 +46,7 @@ void DisassembleResultOperand(const InstructionResult& result,
uses_storage_index = true;
break;
case InstructionStorageTarget::kColorTarget:
out->AppendFormat("oC");
out->Append("oC");
uses_storage_index = true;
break;
case InstructionStorageTarget::kDepth:
@@ -58,13 +58,13 @@ void DisassembleResultOperand(const InstructionResult& result,
if (uses_storage_index) {
switch (result.storage_addressing_mode) {
case InstructionStorageAddressingMode::kStatic:
out->AppendFormat("%d", result.storage_index);
out->AppendFormat("{}", result.storage_index);
break;
case InstructionStorageAddressingMode::kAddressAbsolute:
out->AppendFormat("[%d+a0]", result.storage_index);
out->AppendFormat("[{}+a0]", result.storage_index);
break;
case InstructionStorageAddressingMode::kAddressRelative:
out->AppendFormat("[%d+aL]", result.storage_index);
out->AppendFormat("[{}+aL]", result.storage_index);
break;
}
}
@@ -104,16 +104,16 @@ void DisassembleSourceOperand(const InstructionOperand& op, StringBuffer* out) {
switch (op.storage_addressing_mode) {
case InstructionStorageAddressingMode::kStatic:
if (op.is_absolute_value) {
out->AppendFormat("[%d]", op.storage_index);
out->AppendFormat("[{}]", op.storage_index);
} else {
out->AppendFormat("%d", op.storage_index);
out->AppendFormat("{}", op.storage_index);
}
break;
case InstructionStorageAddressingMode::kAddressAbsolute:
out->AppendFormat("[%d+a0]", op.storage_index);
out->AppendFormat("[{}+a0]", op.storage_index);
break;
case InstructionStorageAddressingMode::kAddressRelative:
out->AppendFormat("[%d+aL]", op.storage_index);
out->AppendFormat("[{}+aL]", op.storage_index);
break;
}
if (!op.is_standard_swizzle()) {
@@ -134,18 +134,18 @@ void DisassembleSourceOperand(const InstructionOperand& op, StringBuffer* out) {
void ParsedExecInstruction::Disassemble(StringBuffer* out) const {
switch (type) {
case Type::kUnconditional:
out->AppendFormat(" %s ", opcode_name);
out->AppendFormat(" {} ", opcode_name);
break;
case Type::kPredicated:
out->Append(condition ? " (p0) " : "(!p0) ");
out->AppendFormat("%s ", opcode_name);
out->AppendFormat("{} ", opcode_name);
break;
case Type::kConditional:
out->AppendFormat(" %s ", opcode_name);
out->AppendFormat(" {} ", opcode_name);
if (!condition) {
out->Append('!');
}
out->AppendFormat("b%u", bool_constant_index);
out->AppendFormat("b{}", bool_constant_index);
break;
}
if (is_yield) {
@@ -159,7 +159,7 @@ void ParsedExecInstruction::Disassemble(StringBuffer* out) const {
void ParsedLoopStartInstruction::Disassemble(StringBuffer* out) const {
out->Append(" loop ");
out->AppendFormat("i%u, L%u", loop_constant_index, loop_skip_address);
out->AppendFormat("i{}, L{}", loop_constant_index, loop_skip_address);
if (is_repeat) {
out->Append(", Repeat=true");
}
@@ -172,7 +172,7 @@ void ParsedLoopEndInstruction::Disassemble(StringBuffer* out) const {
} else {
out->Append(" ");
}
out->AppendFormat("endloop i%u, L%u", loop_constant_index, loop_body_address);
out->AppendFormat("endloop i{}, L{}", loop_constant_index, loop_body_address);
out->Append('\n');
}
@@ -190,10 +190,10 @@ void ParsedCallInstruction::Disassemble(StringBuffer* out) const {
if (!condition) {
out->Append('!');
}
out->AppendFormat("b%u, ", bool_constant_index);
out->AppendFormat("b{}, ", bool_constant_index);
break;
}
out->AppendFormat("L%u", target_address);
out->AppendFormat("L{}", target_address);
out->Append('\n');
}
@@ -215,10 +215,10 @@ void ParsedJumpInstruction::Disassemble(StringBuffer* out) const {
if (!condition) {
out->Append('!');
}
out->AppendFormat("b%u, ", bool_constant_index);
out->AppendFormat("b{}, ", bool_constant_index);
break;
}
out->AppendFormat("L%u", target_address);
out->AppendFormat("L{}", target_address);
out->Append('\n');
}
@@ -228,7 +228,7 @@ void ParsedAllocInstruction::Disassemble(StringBuffer* out) const {
case AllocType::kNone:
break;
case AllocType::kVsPosition:
out->AppendFormat("position");
out->Append("position");
break;
case AllocType::kVsInterpolators: // or AllocType::kPsColors
if (is_vertex_shader) {
@@ -238,7 +238,7 @@ void ParsedAllocInstruction::Disassemble(StringBuffer* out) const {
}
break;
case AllocType::kMemory:
out->AppendFormat("export = %d", count);
out->AppendFormat("export = {}", count);
break;
}
out->Append('\n');
@@ -315,32 +315,32 @@ void ParsedVertexFetchInstruction::Disassemble(StringBuffer* out) const {
} else {
out->Append(" ");
}
out->AppendFormat(opcode_name);
out->Append(opcode_name);
out->Append(' ');
DisassembleResultOperand(result, out);
if (!is_mini_fetch) {
out->Append(", ");
DisassembleSourceOperand(operands[0], out);
out->Append(", ");
out->AppendFormat("vf%d", 95 - operands[1].storage_index);
out->AppendFormat("vf{}", 95 - operands[1].storage_index);
}
if (attributes.is_index_rounded) {
out->Append(", RoundIndex=true");
}
if (attributes.exp_adjust) {
out->AppendFormat(", ExpAdjust=%d", attributes.exp_adjust);
out->AppendFormat(", ExpAdjust={}", attributes.exp_adjust);
}
if (attributes.offset) {
out->AppendFormat(", Offset=%d", attributes.offset);
out->AppendFormat(", Offset={}", attributes.offset);
}
if (attributes.data_format != VertexFormat::kUndefined) {
out->AppendFormat(
", DataFormat=%s",
kVertexFetchDataFormats[static_cast<int>(attributes.data_format)]);
", DataFormat={}",
kVertexFetchDataFormats[static_cast<int>(attributes.data_format)].name);
}
if (!is_mini_fetch && attributes.stride) {
out->AppendFormat(", Stride=%d", attributes.stride);
out->AppendFormat(", Stride={}", attributes.stride);
}
if (attributes.is_signed) {
out->Append(", Signed=true");
@@ -349,7 +349,7 @@ void ParsedVertexFetchInstruction::Disassemble(StringBuffer* out) const {
out->Append(", NumFormat=integer");
}
if (attributes.prefetch_count) {
out->AppendFormat(", PrefetchCount=%u", attributes.prefetch_count + 1);
out->AppendFormat(", PrefetchCount={}", attributes.prefetch_count + 1);
}
out->Append('\n');
@@ -388,7 +388,7 @@ void ParsedTextureFetchInstruction::Disassemble(StringBuffer* out) const {
if (needs_comma) {
out->Append(", ");
}
out->AppendFormat("tf%u", operands[1].storage_index);
out->AppendFormat("tf{}", operands[1].storage_index);
}
if (!attributes.fetch_valid_only) {
@@ -399,32 +399,32 @@ void ParsedTextureFetchInstruction::Disassemble(StringBuffer* out) const {
}
if (attributes.mag_filter != TextureFilter::kUseFetchConst) {
out->AppendFormat(
", MagFilter=%s",
", MagFilter={}",
kTextureFilterNames[static_cast<int>(attributes.mag_filter)]);
}
if (attributes.min_filter != TextureFilter::kUseFetchConst) {
out->AppendFormat(
", MinFilter=%s",
", MinFilter={}",
kTextureFilterNames[static_cast<int>(attributes.min_filter)]);
}
if (attributes.mip_filter != TextureFilter::kUseFetchConst) {
out->AppendFormat(
", MipFilter=%s",
", MipFilter={}",
kTextureFilterNames[static_cast<int>(attributes.mip_filter)]);
}
if (attributes.aniso_filter != AnisoFilter::kUseFetchConst) {
out->AppendFormat(
", AnisoFilter=%s",
", AnisoFilter={}",
kAnisoFilterNames[static_cast<int>(attributes.aniso_filter)]);
}
if (attributes.vol_mag_filter != TextureFilter::kUseFetchConst) {
out->AppendFormat(
", VolMagFilter=%s",
", VolMagFilter={}",
kTextureFilterNames[static_cast<int>(attributes.vol_mag_filter)]);
}
if (attributes.vol_min_filter != TextureFilter::kUseFetchConst) {
out->AppendFormat(
", VolMinFilter=%s",
", VolMinFilter={}",
kTextureFilterNames[static_cast<int>(attributes.vol_min_filter)]);
}
if (!attributes.use_computed_lod) {
@@ -437,17 +437,17 @@ void ParsedTextureFetchInstruction::Disassemble(StringBuffer* out) const {
out->Append(", UseRegisterGradients=true");
}
if (attributes.lod_bias != 0.0f) {
out->AppendFormat(", LODBias=%g", attributes.lod_bias);
out->AppendFormat(", LODBias={:g}", attributes.lod_bias);
}
int component_count = GetTextureDimensionComponentCount(dimension);
if (attributes.offset_x != 0.0f) {
out->AppendFormat(", OffsetX=%g", attributes.offset_x);
out->AppendFormat(", OffsetX={:g}", attributes.offset_x);
}
if (component_count > 1 && attributes.offset_y != 0.0f) {
out->AppendFormat(", OffsetY=%g", attributes.offset_y);
out->AppendFormat(", OffsetY={:g}", attributes.offset_y);
}
if (component_count > 2 && attributes.offset_z != 0.0f) {
out->AppendFormat(", OffsetZ=%g", attributes.offset_z);
out->AppendFormat(", OffsetZ={:g}", attributes.offset_z);
}
out->Append('\n');

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2017 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -15,6 +15,7 @@
#include <cstring>
#include <vector>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
@@ -232,9 +233,9 @@ void SpirvShaderTranslator::StartTranslation() {
// Create 3 texture types, all aliased on the same binding
for (int i = 0; i < 3; i++) {
tex_[i] = b.createVariable(
spv::StorageClass::StorageClassUniformConstant, tex_a_t[i],
xe::format_string("textures%dD", i + 2).c_str());
tex_[i] = b.createVariable(spv::StorageClass::StorageClassUniformConstant,
tex_a_t[i],
fmt::format("textures{}D", i + 2).c_str());
b.addDecoration(tex_[i], spv::Decoration::DecorationDescriptorSet, 1);
b.addDecoration(tex_[i], spv::Decoration::DecorationBinding, 0);
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,9 +26,8 @@
#undef _CRT_NONSTDC_NO_DEPRECATE
#include "third_party/stb/stb_image_write.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
"GPU");
DEFINE_string(trace_dump_path, "", "Output path for dumped files.", "GPU");
DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU");
DEFINE_path(trace_dump_path, "", "Output path for dumped files.", "GPU");
namespace xe {
namespace gpu {
@@ -39,21 +38,21 @@ TraceDump::TraceDump() = default;
TraceDump::~TraceDump() = default;
int TraceDump::Main(const std::vector<std::wstring>& args) {
int TraceDump::Main(const std::vector<std::string>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
std::wstring output_path;
std::filesystem::path path;
std::filesystem::path output_path;
if (!cvars::target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(cvars::target_trace_file);
path = cvars::target_trace_file;
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];
path = xe::to_path(args[1]);
if (args.size() >= 3) {
output_path = args[2];
output_path = xe::to_path(args[2]);
}
}
@@ -63,8 +62,8 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
}
// Normalize the path and make absolute.
auto abs_path = xe::to_absolute_path(path);
XELOGI("Loading trace file %ls...", abs_path.c_str());
auto abs_path = std::filesystem::absolute(path);
XELOGI("Loading trace file %s...", xe::path_to_utf8(abs_path).c_str());
if (!Setup()) {
XELOGE("Unable to setup trace dump tool");
@@ -77,21 +76,12 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
// Root file name for outputs.
if (output_path.empty()) {
base_output_path_ =
xe::fix_path_separators(xe::to_wstring(cvars::trace_dump_path));
base_output_path_ = cvars::trace_dump_path;
auto output_name = path.filename().replace_extension();
std::wstring output_name =
xe::find_name_from_path(xe::fix_path_separators(path));
// Strip the extension from the filename.
auto last_dot = output_name.find_last_of(L".");
if (last_dot != std::string::npos) {
output_name = output_name.substr(0, last_dot);
}
base_output_path_ = xe::join_paths(base_output_path_, output_name);
base_output_path_ = base_output_path_ / output_name;
} else {
base_output_path_ = xe::fix_path_separators(output_path);
base_output_path_ = output_path;
}
// Ensure output path exists.
@@ -102,7 +92,7 @@ int TraceDump::Main(const std::vector<std::wstring>& args) {
bool TraceDump::Setup() {
// Create the emulator but don't initialize so we can setup the window.
emulator_ = std::make_unique<Emulator>(L"", L"", L"");
emulator_ = std::make_unique<Emulator>("", "", "");
X_STATUS result = emulator_->Setup(
nullptr, nullptr, [this]() { return CreateGraphicsSystem(); }, nullptr);
if (XFAILED(result)) {
@@ -114,8 +104,8 @@ bool TraceDump::Setup() {
return true;
}
bool TraceDump::Load(std::wstring trace_file_path) {
trace_file_path_ = std::move(trace_file_path);
bool TraceDump::Load(const std::filesystem::path& trace_file_path) {
trace_file_path_ = trace_file_path;
if (!player_->Open(trace_file_path_)) {
XELOGE("Could not load trace file");
@@ -138,10 +128,16 @@ int TraceDump::Run() {
auto raw_image = graphics_system_->Capture();
if (raw_image) {
// Save framebuffer png.
std::string png_path = xe::to_string(base_output_path_ + L".png");
stbi_write_png(png_path.c_str(), static_cast<int>(raw_image->width),
static_cast<int>(raw_image->height), 4,
raw_image->data.data(), static_cast<int>(raw_image->stride));
auto png_path = base_output_path_.replace_extension(".png");
auto handle = filesystem::OpenFile(png_path, "wb");
auto callback = [](void* context, void* data, int size) {
fwrite(data, 1, size, (FILE*)context);
};
stbi_write_png_to_func(callback, handle, static_cast<int>(raw_image->width),
static_cast<int>(raw_image->height), 4,
raw_image->data.data(),
static_cast<int>(raw_image->stride));
fclose(handle);
} else {
result = 1;
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -36,7 +36,7 @@ class TraceDump {
public:
virtual ~TraceDump();
int Main(const std::vector<std::wstring>& args);
int Main(const std::vector<std::string>& args);
protected:
TraceDump();
@@ -52,11 +52,11 @@ class TraceDump {
private:
bool Setup();
bool Load(std::wstring trace_file_path);
bool Load(const std::filesystem::path& trace_file_path);
int Run();
std::wstring trace_file_path_;
std::wstring base_output_path_;
std::filesystem::path trace_file_path_;
std::filesystem::path base_output_path_;
};
} // namespace gpu

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -16,7 +16,7 @@ namespace xe {
namespace gpu {
// Trace file extension.
static const wchar_t kTraceExtension[] = L"xtr";
static const char kTraceExtension[] = "xtr";
// Any byte changes to the files should bump this version.
// Only builds with matching versions will work.

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -12,7 +12,7 @@
#include <cinttypes>
#include "third_party/snappy/snappy.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#include "xenia/base/mapped_memory.h"
#include "xenia/base/math.h"
@@ -23,7 +23,7 @@
namespace xe {
namespace gpu {
bool TraceReader::Open(const std::wstring& path) {
bool TraceReader::Open(const std::filesystem::path& path) {
Close();
mmap_ = MappedMemory::Open(path, MappedMemory::Mode::kRead);
@@ -45,7 +45,7 @@ bool TraceReader::Open(const std::wstring& path) {
return false;
}
auto path_str = xe::to_string(path);
auto path_str = xe::path_to_utf8(path);
XELOGI("Mapped %" PRId64 "b trace from %s", trace_size_, path_str.c_str());
XELOGI(" Version: %u", header->version);
auto commit_str = std::string(header->build_commit_sha,

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -129,7 +129,7 @@ class TraceReader {
const Frame* frame(int n) const { return &frames_[n]; }
int frame_count() const { return int(frames_.size()); }
bool Open(const std::wstring& path);
bool Open(const std::filesystem::path& path);
void Close();

View File

@@ -31,8 +31,7 @@
#include "xenia/ui/window.h"
#include "xenia/xbox.h"
DEFINE_string(target_trace_file, "", "Specifies the trace file to load.",
"GPU");
DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU");
namespace xe {
namespace gpu {
@@ -50,17 +49,17 @@ TraceViewer::TraceViewer() = default;
TraceViewer::~TraceViewer() = default;
int TraceViewer::Main(const std::vector<std::wstring>& args) {
int TraceViewer::Main(const std::vector<std::string>& args) {
// Grab path from the flag or unnamed argument.
std::wstring path;
std::filesystem::path path;
if (!cvars::target_trace_file.empty()) {
// Passed as a named argument.
// TODO(benvanik): find something better than gflags that supports
// unicode.
path = xe::to_wstring(cvars::target_trace_file);
path = cvars::target_trace_file;
} else if (args.size() >= 2) {
// Passed as an unnamed argument.
path = args[1];
path = xe::to_path(args[1]);
}
// If no path passed, ask the user.
@@ -69,10 +68,10 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
file_picker->set_type(ui::FilePicker::Type::kFile);
file_picker->set_multi_selection(false);
file_picker->set_title(L"Select Trace File");
file_picker->set_title("Select Trace File");
file_picker->set_extensions({
{L"Supported Files", L"*.xtr"},
{L"All Files (*.*)", L"*.*"},
{"Supported Files", "*.xtr"},
{"All Files (*.*)", "*.*"},
});
if (file_picker->Show()) {
auto selected_files = file_picker->selected_files();
@@ -88,7 +87,7 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
}
// Normalize the path and make absolute.
auto abs_path = xe::to_absolute_path(path);
auto abs_path = std::filesystem::absolute(path);
if (!Setup()) {
xe::FatalError("Unable to setup trace viewer");
@@ -105,7 +104,7 @@ int TraceViewer::Main(const std::vector<std::wstring>& args) {
bool TraceViewer::Setup() {
// Main display window.
loop_ = ui::Loop::Create();
window_ = xe::ui::Window::Create(loop_.get(), L"xenia-gpu-trace-viewer");
window_ = xe::ui::Window::Create(loop_.get(), "xenia-gpu-trace-viewer");
loop_->PostSynchronous([&]() {
xe::threading::set_name("Win32 Loop");
if (!window_->Initialize()) {
@@ -122,7 +121,7 @@ bool TraceViewer::Setup() {
window_->Resize(1920, 1200);
// Create the emulator but don't initialize so we can setup the window.
emulator_ = std::make_unique<Emulator>(L"", L"", L"");
emulator_ = std::make_unique<Emulator>("", "", "");
X_STATUS result = emulator_->Setup(
window_.get(), nullptr, [this]() { return CreateGraphicsSystem(); },
nullptr);
@@ -155,9 +154,9 @@ bool TraceViewer::Setup() {
return true;
}
bool TraceViewer::Load(std::wstring trace_file_path) {
auto file_name = xe::find_name_from_path(trace_file_path);
window_->set_title(std::wstring(L"Xenia GPU Trace Viewer: ") + file_name);
bool TraceViewer::Load(const std::filesystem::path& trace_file_path) {
auto file_name = trace_file_path.filename();
window_->set_title("Xenia GPU Trace Viewer: " + xe::path_to_utf8(file_name));
if (!player_->Open(trace_file_path)) {
XELOGE("Could not load trace file");
@@ -177,7 +176,7 @@ void TraceViewer::Run() {
loop_.reset();
}
void TraceViewer::DrawMultilineString(const std::string& str) {
void TraceViewer::DrawMultilineString(const std::string_view str) {
size_t i = 0;
bool done = false;
while (!done && i < str.size()) {
@@ -187,7 +186,7 @@ void TraceViewer::DrawMultilineString(const std::string& str) {
next_i = str.size() - 1;
}
auto line = str.substr(i, next_i - i);
ImGui::Text("%s", line.c_str());
ImGui::Text("%s", std::string(line).c_str());
i = next_i + 1;
}
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -36,14 +36,14 @@ class TraceViewer {
public:
virtual ~TraceViewer();
int Main(const std::vector<std::wstring>& args);
int Main(const std::vector<std::string>& args);
protected:
TraceViewer();
virtual std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem() = 0;
void DrawMultilineString(const std::string& str);
void DrawMultilineString(const std::string_view str);
virtual uintptr_t GetColorRenderTarget(uint32_t pitch, MsaaSamples samples,
uint32_t base,
@@ -74,7 +74,7 @@ class TraceViewer {
kHostDisasm,
};
bool Load(std::wstring trace_file_path);
bool Load(const std::filesystem::path& trace_file_path);
void Run();
void DrawUI();

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -27,12 +27,12 @@ TraceWriter::TraceWriter(uint8_t* membase)
TraceWriter::~TraceWriter() = default;
bool TraceWriter::Open(const std::wstring& path, uint32_t title_id) {
bool TraceWriter::Open(const std::filesystem::path& path, uint32_t title_id) {
Close();
auto canonical_path = xe::to_absolute_path(path);
auto base_path = xe::find_base_path(canonical_path);
if (!base_path.empty()) {
auto canonical_path = std::filesystem::absolute(path);
if (canonical_path.has_parent_path()) {
auto base_path = canonical_path.parent_path();
xe::filesystem::CreateFolder(base_path);
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,7 +26,7 @@ class TraceWriter {
bool is_open() const { return file_ != nullptr; }
bool Open(const std::wstring& path, uint32_t title_id);
bool Open(const std::filesystem::path& path, uint32_t title_id);
void Flush();
void Close();

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -19,7 +19,7 @@ VulkanGraphicsSystem::VulkanGraphicsSystem() {}
VulkanGraphicsSystem::~VulkanGraphicsSystem() {}
std::wstring VulkanGraphicsSystem::name() const { return L"Vulkan Prototype"; }
std::string VulkanGraphicsSystem::name() const { return "Vulkan Prototype"; }
X_STATUS VulkanGraphicsSystem::Setup(cpu::Processor* processor,
kernel::KernelState* kernel_state,

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -27,7 +27,7 @@ class VulkanGraphicsSystem : public GraphicsSystem {
static bool IsAvailable() { return true; }
std::wstring name() const override;
std::string name() const override;
X_STATUS Setup(cpu::Processor* processor, kernel::KernelState* kernel_state,
ui::Window* target_window) override;

View File

@@ -7,6 +7,7 @@ project("xenia-gpu-vulkan")
kind("StaticLib")
language("C++")
links({
"fmt",
"volk",
"xenia-base",
"xenia-gpu",
@@ -31,6 +32,7 @@ project("xenia-gpu-vulkan-trace-viewer")
links({
"aes_128",
"capstone",
"fmt",
"glslang-spirv",
"imgui",
"libavcodec",
@@ -97,6 +99,7 @@ project("xenia-gpu-vulkan-trace-dump")
links({
"aes_128",
"capstone",
"fmt",
"glslang-spirv",
"imgui",
"libavcodec",

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -11,6 +11,7 @@
#include <algorithm>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -231,10 +232,11 @@ VkResult CachedTileView::Initialize(VkCommandBuffer command_buffer) {
device_->DbgSetObjectName(
reinterpret_cast<uint64_t>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
xe::format_string("RT(d): 0x%.8X 0x%.8X(%d) 0x%.8X(%d) %d %d %d",
key.tile_offset, key.tile_width, key.tile_width,
key.tile_height, key.tile_height, key.color_or_depth,
key.msaa_samples, key.edram_format));
fmt::format("RT(d): {:#.8X} {:#.8X}({}) {:#.8X}({}) {} {} {}",
uint32_t(key.tile_offset), uint32_t(key.tile_width),
uint32_t(key.tile_width), uint32_t(key.tile_height),
uint32_t(key.tile_height), uint32_t(key.color_or_depth),
uint32_t(key.msaa_samples), uint32_t(key.edram_format)));
VkMemoryRequirements memory_requirements;
vkGetImageMemoryRequirements(*device_, image, &memory_requirements);

View File

@@ -2,16 +2,16 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/gpu/vulkan/texture_cache.h"
#include "xenia/gpu/vulkan/texture_config.h"
#include <algorithm>
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
#include "xenia/base/memory.h"
@@ -20,6 +20,7 @@
#include "xenia/gpu/sampler_info.h"
#include "xenia/gpu/texture_conversion.h"
#include "xenia/gpu/texture_info.h"
#include "xenia/gpu/vulkan/texture_config.h"
#include "xenia/gpu/vulkan/vulkan_gpu_flags.h"
#include "xenia/ui/vulkan/vulkan_mem_alloc.h"
@@ -522,8 +523,8 @@ TextureCache::Texture* TextureCache::DemandResolveTexture(
device_->DbgSetObjectName(
reinterpret_cast<uint64_t>(texture->image),
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
xe::format_string(
"RT: 0x%.8X - 0x%.8X (%s, %s)", texture_info.memory.base_address,
fmt::format(
"RT: {:#.8X} - {:#.8X} ({}, {})", texture_info.memory.base_address,
texture_info.memory.base_address + texture_info.memory.base_size,
texture_info.format_info()->name,
get_dimension_name(texture_info.dimension)));
@@ -605,8 +606,8 @@ TextureCache::Texture* TextureCache::Demand(const TextureInfo& texture_info,
device_->DbgSetObjectName(
reinterpret_cast<uint64_t>(texture->image),
VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
xe::format_string(
"T: 0x%.8X - 0x%.8X (%s, %s)", texture_info.memory.base_address,
fmt::format(
"T: {:#.8X} - {:#.8X} ({}, {})", texture_info.memory.base_address,
texture_info.memory.base_address + texture_info.memory.base_size,
texture_info.format_info()->name,
get_dimension_name(texture_info.dimension)));

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -38,7 +38,8 @@ VulkanCommandProcessor::VulkanCommandProcessor(
VulkanCommandProcessor::~VulkanCommandProcessor() = default;
void VulkanCommandProcessor::RequestFrameTrace(const std::wstring& root_path) {
void VulkanCommandProcessor::RequestFrameTrace(
const std::filesystem::path& root_path) {
// Override traces if renderdoc is attached.
if (device_->is_renderdoc_attached()) {
trace_requested_ = true;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -50,7 +50,7 @@ class VulkanCommandProcessor : public CommandProcessor {
kernel::KernelState* kernel_state);
~VulkanCommandProcessor() override;
void RequestFrameTrace(const std::wstring& root_path) override;
void RequestFrameTrace(const std::filesystem::path& root_path) override;
void TracePlaybackWroteMemory(uint32_t base_ptr, uint32_t length) override;
void RestoreEDRAMSnapshot(const void* snapshot) override;
void ClearCaches() override;

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -26,7 +26,7 @@ class VulkanGraphicsSystem : public GraphicsSystem {
static bool IsAvailable() { return true; }
std::wstring name() const override { return L"Vulkan"; }
std::string name() const override { return "Vulkan"; }
X_STATUS Setup(cpu::Processor* processor, kernel::KernelState* kernel_state,
ui::Window* target_window) override;

View File

@@ -2,13 +2,14 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2016 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "xenia/gpu/vulkan/vulkan_shader.h"
#include "third_party/fmt/include/fmt/format.h"
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/base/math.h"
@@ -54,7 +55,7 @@ bool VulkanShader::Prepare() {
: shader_type_ == ShaderType::kVertex ? 'v' : 'u';
device_->DbgSetObjectName(
uint64_t(shader_module_), VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT,
xe::format_string("S(%c): %.16llX", typeChar, ucode_data_hash()));
fmt::format("S({}): {:016X}", typeChar, ucode_data_hash()));
return status == VK_SUCCESS;
}

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -46,7 +46,7 @@ class VulkanTraceDump : public TraceDump {
}
};
int trace_dump_main(const std::vector<std::wstring>& args) {
int trace_dump_main(const std::vector<std::string>& args) {
VulkanTraceDump trace_dump;
return trace_dump.Main(args);
}
@@ -55,6 +55,6 @@ int trace_dump_main(const std::vector<std::wstring>& args) {
} // namespace gpu
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-gpu-vulkan-trace-dump",
DEFINE_ENTRY_POINT("xenia-gpu-vulkan-trace-dump",
xe::gpu::vulkan::trace_dump_main, "some.trace",
"target_trace_file");

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2019 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -62,7 +62,7 @@ class VulkanTraceViewer : public TraceViewer {
}
};
int trace_viewer_main(const std::vector<std::wstring>& args) {
int trace_viewer_main(const std::vector<std::string>& args) {
VulkanTraceViewer trace_viewer;
return trace_viewer.Main(args);
}
@@ -71,6 +71,6 @@ int trace_viewer_main(const std::vector<std::wstring>& args) {
} // namespace gpu
} // namespace xe
DEFINE_ENTRY_POINT(L"xenia-gpu-vulkan-trace-viewer",
DEFINE_ENTRY_POINT("xenia-gpu-vulkan-trace-viewer",
xe::gpu::vulkan::trace_viewer_main, "some.trace",
"target_trace_file");