Skip to content

Commit

Permalink
Merge branch 'shadps4-emu:main' into lto
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorP93 authored Dec 2, 2024
2 parents f6dcba6 + fda4f06 commit c1baee6
Show file tree
Hide file tree
Showing 30 changed files with 660 additions and 115 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later

cmake_minimum_required(VERSION 3.16.3)
# Version 3.24 needed for FetchContent OVERRIDE_FIND_PACKAGE
cmake_minimum_required(VERSION 3.24)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Expand Down Expand Up @@ -110,7 +111,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp.in" "${CMAKE_
find_package(Boost 1.84.0 CONFIG)
find_package(FFmpeg 5.1.2 MODULE)
find_package(fmt 10.2.0 CONFIG)
find_package(glslang 14.2.0 CONFIG)
find_package(glslang 15 CONFIG)
find_package(half 1.12.0 MODULE)
find_package(magic_enum 0.9.6 CONFIG)
find_package(PNG 1.6 MODULE)
Expand Down Expand Up @@ -373,6 +374,8 @@ set(JPEG_LIB src/core/libraries/jpeg/jpeg_error.h

set(PLAYGO_LIB src/core/libraries/playgo/playgo.cpp
src/core/libraries/playgo/playgo.h
src/core/libraries/playgo/playgo_dialog.cpp
src/core/libraries/playgo/playgo_dialog.h
src/core/libraries/playgo/playgo_types.h
)

Expand Down Expand Up @@ -432,10 +435,14 @@ set(DEV_TOOLS src/core/devtools/layer.cpp
src/core/devtools/widget/frame_graph.cpp
src/core/devtools/widget/frame_graph.h
src/core/devtools/widget/imgui_memory_editor.h
src/core/devtools/widget/memory_map.cpp
src/core/devtools/widget/memory_map.h
src/core/devtools/widget/reg_popup.cpp
src/core/devtools/widget/reg_popup.h
src/core/devtools/widget/reg_view.cpp
src/core/devtools/widget/reg_view.h
src/core/devtools/widget/shader_list.cpp
src/core/devtools/widget/shader_list.h
src/core/devtools/widget/text_editor.cpp
src/core/devtools/widget/text_editor.h
)
Expand Down
5 changes: 4 additions & 1 deletion externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ else()
set(CRYPTOPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cryptopp/)
add_subdirectory(cryptopp-cmake)
file(COPY cryptopp DESTINATION cryptopp FILES_MATCHING PATTERN "*.h")
target_include_directories(cryptopp INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/cryptopp")
# remove externals/cryptopp from include directories because it contains a conflicting zlib.h file
set_target_properties(cryptopp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/cryptopp")
endif()
endif()

Expand Down Expand Up @@ -67,6 +68,8 @@ if (NOT TARGET ZLIB::ZLIB)
)
FetchContent_MakeAvailable(ZLIB)
add_library(ZLIB::ZLIB ALIAS zlib)
# libpng expects this variable to exist after its find_package(ZLIB)
set(ZLIB_INCLUDE_DIRS "${FETCHCONTENT_BASE_DIR}/zlib-build")
endif()

# SDL3
Expand Down
12 changes: 12 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static std::string backButtonBehavior = "left";
static bool useSpecialPad = false;
static int specialPadClass = 1;
static bool isDebugDump = false;
static bool isShaderDebug = false;
static bool isShowSplash = false;
static bool isAutoUpdate = false;
static bool isNullGpu = false;
Expand Down Expand Up @@ -159,6 +160,10 @@ bool debugDump() {
return isDebugDump;
}

bool collectShadersForDebug() {
return isShaderDebug;
}

bool showSplash() {
return isShowSplash;
}
Expand Down Expand Up @@ -235,6 +240,10 @@ void setDebugDump(bool enable) {
isDebugDump = enable;
}

void setCollectShaderForDebug(bool enable) {
isShaderDebug = enable;
}

void setShowSplash(bool enable) {
isShowSplash = enable;
}
Expand Down Expand Up @@ -571,6 +580,7 @@ void load(const std::filesystem::path& path) {
const toml::value& debug = data.at("Debug");

isDebugDump = toml::find_or<bool>(debug, "DebugDump", false);
isShaderDebug = toml::find_or<bool>(debug, "CollectShader", false);
}

if (data.contains("GUI")) {
Expand Down Expand Up @@ -662,6 +672,7 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["rdocMarkersEnable"] = vkMarkers;
data["Vulkan"]["crashDiagnostic"] = vkCrashDiagnostic;
data["Debug"]["DebugDump"] = isDebugDump;
data["Debug"]["CollectShader"] = isShaderDebug;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;
Expand Down Expand Up @@ -717,6 +728,7 @@ void setDefaultValues() {
useSpecialPad = false;
specialPadClass = 1;
isDebugDump = false;
isShaderDebug = false;
isShowSplash = false;
isAutoUpdate = false;
isNullGpu = false;
Expand Down
2 changes: 2 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ u32 getScreenHeight();
s32 getGpuId();

bool debugDump();
bool collectShadersForDebug();
bool showSplash();
bool autoUpdate();
bool nullGpu();
Expand All @@ -47,6 +48,7 @@ bool isRdocEnabled();
u32 vblankDiv();

void setDebugDump(bool enable);
void setCollectShaderForDebug(bool enable);
void setShowSplash(bool enable);
void setAutoUpdate(bool enable);
void setNullGpu(bool enable);
Expand Down
1 change: 1 addition & 0 deletions src/common/logging/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
SUB(Lib, Png) \
SUB(Lib, Jpeg) \
SUB(Lib, PlayGo) \
SUB(Lib, PlayGoDialog) \
SUB(Lib, Random) \
SUB(Lib, Usbd) \
SUB(Lib, Ajm) \
Expand Down
1 change: 1 addition & 0 deletions src/common/logging/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum class Class : u8 {
Lib_Png, ///< The LibScePng implementation.
Lib_Jpeg, ///< The LibSceJpeg implementation.
Lib_PlayGo, ///< The LibScePlayGo implementation.
Lib_PlayGoDialog, ///< The LibScePlayGoDialog implementation.
Lib_Random, ///< The libSceRandom implementation.
Lib_Usbd, ///< The LibSceUsbd implementation.
Lib_Ajm, ///< The LibSceAjm implementation.
Expand Down
11 changes: 9 additions & 2 deletions src/core/debug_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void DebugStateImpl::PushRegsDump(uintptr_t base_addr, uintptr_t header_addr,
if (is_compute) {
dump.is_compute = true;
const auto& cs = dump.regs.cs_program;
dump.cs_data = ComputerShaderDump{
dump.cs_data = PipelineComputerProgramDump{
.cs_program = cs,
.code = std::vector<u32>{cs.Code().begin(), cs.Code().end()},
};
Expand All @@ -167,7 +167,7 @@ void DebugStateImpl::PushRegsDump(uintptr_t base_addr, uintptr_t header_addr,
auto stage = regs.ProgramForStage(i);
if (stage->address_lo != 0) {
auto code = stage->Code();
dump.stages[i] = ShaderDump{
dump.stages[i] = PipelineShaderProgramDump{
.user_data = *stage,
.code = std::vector<u32>{code.begin(), code.end()},
};
Expand All @@ -176,3 +176,10 @@ void DebugStateImpl::PushRegsDump(uintptr_t base_addr, uintptr_t header_addr,
}
}
}

void DebugStateImpl::CollectShader(const std::string& name, std::span<const u32> spv,
std::span<const u32> raw_code) {
shader_dump_list.emplace_back(name, std::vector<u32>{spv.begin(), spv.end()},
std::vector<u32>{raw_code.begin(), raw_code.end()});
std::ranges::sort(shader_dump_list, {}, &ShaderDump::name);
}
48 changes: 42 additions & 6 deletions src/core/debug_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace Core::Devtools {
class Layer;
namespace Widget {
class FrameGraph;
}
class ShaderList;
} // namespace Widget
} // namespace Core::Devtools

namespace DebugStateType {
Expand All @@ -49,12 +50,12 @@ struct QueueDump {
uintptr_t base_addr;
};

struct ShaderDump {
struct PipelineShaderProgramDump {
Vulkan::Liverpool::ShaderProgram user_data{};
std::vector<u32> code{};
};

struct ComputerShaderDump {
struct PipelineComputerProgramDump {
Vulkan::Liverpool::ComputeProgram cs_program{};
std::vector<u32> code{};
};
Expand All @@ -63,8 +64,8 @@ struct RegDump {
bool is_compute{false};
static constexpr size_t MaxShaderStages = 5;
Vulkan::Liverpool::Regs regs{};
std::array<ShaderDump, MaxShaderStages> stages{};
ComputerShaderDump cs_data{};
std::array<PipelineShaderProgramDump, MaxShaderStages> stages{};
PipelineComputerProgramDump cs_data{};
};

struct FrameDump {
Expand All @@ -73,9 +74,41 @@ struct FrameDump {
std::unordered_map<uintptr_t, RegDump> regs; // address -> reg dump
};

struct ShaderDump {
std::string name;
std::vector<u32> spv;
std::vector<u32> raw_code;

std::string cache_spv_disasm{};
std::string cache_raw_disasm{};

ShaderDump(std::string name, std::vector<u32> spv, std::vector<u32> raw_code)
: name(std::move(name)), spv(std::move(spv)), raw_code(std::move(raw_code)) {}

ShaderDump(const ShaderDump& other) = delete;
ShaderDump(ShaderDump&& other) noexcept
: name{std::move(other.name)}, spv{std::move(other.spv)},
raw_code{std::move(other.raw_code)}, cache_spv_disasm{std::move(other.cache_spv_disasm)},
cache_raw_disasm{std::move(other.cache_raw_disasm)} {}
ShaderDump& operator=(const ShaderDump& other) = delete;
ShaderDump& operator=(ShaderDump&& other) noexcept {
if (this == &other)
return *this;
name = std::move(other.name);
spv = std::move(other.spv);
raw_code = std::move(other.raw_code);
cache_spv_disasm = std::move(other.cache_spv_disasm);
cache_raw_disasm = std::move(other.cache_raw_disasm);
return *this;
}
};

class DebugStateImpl {
friend class Core::Devtools::Layer;
friend class Core::Devtools::Widget::FrameGraph;
friend class Core::Devtools::Widget::ShaderList;

std::queue<std::string> debug_message_popup;

std::mutex guest_threads_mutex{};
std::vector<ThreadID> guest_threads{};
Expand All @@ -94,7 +127,7 @@ class DebugStateImpl {
std::shared_mutex frame_dump_list_mutex;
std::vector<FrameDump> frame_dump_list{};

std::queue<std::string> debug_message_popup;
std::vector<ShaderDump> shader_dump_list{};

public:
void ShowDebugMessage(std::string message) {
Expand Down Expand Up @@ -152,6 +185,9 @@ class DebugStateImpl {

void PushRegsDump(uintptr_t base_addr, uintptr_t header_addr,
const AmdGpu::Liverpool::Regs& regs, bool is_compute = false);

void CollectShader(const std::string& name, std::span<const u32> spv,
std::span<const u32> raw_code);
};
} // namespace DebugStateType

Expand Down
10 changes: 10 additions & 0 deletions src/core/devtools/gcn/gcn_context_regs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ const char* GetContextRegName(u32 reg_offset) {
return "mmSPI_PS_INPUT_CNTL_2";
case mmSPI_PS_INPUT_CNTL_3:
return "mmSPI_PS_INPUT_CNTL_3";
case mmPA_SU_POLY_OFFSET_FRONT_SCALE:
return "mmPA_SU_POLY_OFFSET_FRONT_SCALE";
case mmPA_SU_POLY_OFFSET_FRONT_OFFSET:
return "mmPA_SU_POLY_OFFSET_FRONT_OFFSET";
case mmPA_SU_POLY_OFFSET_BACK_SCALE:
return "mmPA_SU_POLY_OFFSET_BACK_SCALE";
case mmPA_SU_POLY_OFFSET_BACK_OFFSET:
return "mmPA_SU_POLY_OFFSET_BACK_OFFSET";
case mmPA_SU_POLY_OFFSET_CLAMP:
return "mmPA_SU_POLY_OFFSET_CLAMP";
default:
break;
}
Expand Down
Loading

0 comments on commit c1baee6

Please sign in to comment.