Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ target_compile_options(hydra_warnings INTERFACE
-Wno-vla-extension
-Wno-gnu-case-range
-Wno-gnu-zero-variadic-macro-arguments
-Wno-missing-designated-field-initializers
)

include_directories(externals/metal-cpp externals/dynarmic externals/stb)
Expand Down
2 changes: 1 addition & 1 deletion externals/dynarmic
2 changes: 1 addition & 1 deletion externals/hatch
2 changes: 2 additions & 0 deletions src/common/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <fstream>

#ifdef PLATFORM_APPLE
#include <CoreFoundation/CoreFoundation.h>
#endif

#include "common/log.hpp"
#include "common/platform.hpp"
Expand Down
95 changes: 53 additions & 42 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -599,38 +599,6 @@ add_library(hydra-core
hw/tegra_x1/gpu/renderer/null/texture.hpp
hw/tegra_x1/gpu/renderer/null/renderer.cpp
hw/tegra_x1/gpu/renderer/null/renderer.hpp
hw/tegra_x1/gpu/renderer/metal/const.hpp
hw/tegra_x1/gpu/renderer/metal/maxwell_to_mtl.cpp
hw/tegra_x1/gpu/renderer/metal/maxwell_to_mtl.hpp
hw/tegra_x1/gpu/renderer/metal/impl.cpp
hw/tegra_x1/gpu/renderer/metal/command_buffer.cpp
hw/tegra_x1/gpu/renderer/metal/command_buffer.hpp
hw/tegra_x1/gpu/renderer/metal/surface_compositor.cpp
hw/tegra_x1/gpu/renderer/metal/surface_compositor.hpp
hw/tegra_x1/gpu/renderer/metal/buffer.cpp
hw/tegra_x1/gpu/renderer/metal/buffer.hpp
hw/tegra_x1/gpu/renderer/metal/texture.cpp
hw/tegra_x1/gpu/renderer/metal/texture.hpp
hw/tegra_x1/gpu/renderer/metal/texture_view.cpp
hw/tegra_x1/gpu/renderer/metal/texture_view.hpp
hw/tegra_x1/gpu/renderer/metal/sampler.cpp
hw/tegra_x1/gpu/renderer/metal/sampler.hpp
hw/tegra_x1/gpu/renderer/metal/render_pass.cpp
hw/tegra_x1/gpu/renderer/metal/render_pass.hpp
hw/tegra_x1/gpu/renderer/metal/shader.cpp
hw/tegra_x1/gpu/renderer/metal/shader.hpp
hw/tegra_x1/gpu/renderer/metal/pipeline.cpp
hw/tegra_x1/gpu/renderer/metal/pipeline.hpp
hw/tegra_x1/gpu/renderer/metal/depth_stencil_state_cache.cpp
hw/tegra_x1/gpu/renderer/metal/depth_stencil_state_cache.hpp
hw/tegra_x1/gpu/renderer/metal/blit_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/blit_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/clear_color_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/clear_color_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/clear_depth_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/clear_depth_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/renderer.cpp
hw/tegra_x1/gpu/renderer/metal/renderer.hpp
input/const.hpp
input/state.hpp
input/device.hpp
Expand All @@ -642,12 +610,6 @@ add_library(hydra-core
input/device_list.hpp
input/device_manager.cpp
input/device_manager.hpp
input/apple_gc/keyboard.mm
input/apple_gc/keyboard.hpp
input/apple_gc/controller.mm
input/apple_gc/controller.hpp
input/apple_gc/device_list.mm
input/apple_gc/device_list.hpp
# TODO: only build the debugger on debug builds
debugger/const.hpp
debugger/gdb_server.cpp
Expand All @@ -663,6 +625,49 @@ add_library(hydra-core
c_api.h
)

if (APPLE)
target_sources(hydra-core PRIVATE
hw/tegra_x1/gpu/renderer/metal/const.hpp
hw/tegra_x1/gpu/renderer/metal/maxwell_to_mtl.cpp
hw/tegra_x1/gpu/renderer/metal/maxwell_to_mtl.hpp
hw/tegra_x1/gpu/renderer/metal/impl.cpp
hw/tegra_x1/gpu/renderer/metal/command_buffer.cpp
hw/tegra_x1/gpu/renderer/metal/command_buffer.hpp
hw/tegra_x1/gpu/renderer/metal/surface_compositor.cpp
hw/tegra_x1/gpu/renderer/metal/surface_compositor.hpp
hw/tegra_x1/gpu/renderer/metal/buffer.cpp
hw/tegra_x1/gpu/renderer/metal/buffer.hpp
hw/tegra_x1/gpu/renderer/metal/texture.cpp
hw/tegra_x1/gpu/renderer/metal/texture.hpp
hw/tegra_x1/gpu/renderer/metal/texture_view.cpp
hw/tegra_x1/gpu/renderer/metal/texture_view.hpp
hw/tegra_x1/gpu/renderer/metal/sampler.cpp
hw/tegra_x1/gpu/renderer/metal/sampler.hpp
hw/tegra_x1/gpu/renderer/metal/render_pass.cpp
hw/tegra_x1/gpu/renderer/metal/render_pass.hpp
hw/tegra_x1/gpu/renderer/metal/shader.cpp
hw/tegra_x1/gpu/renderer/metal/shader.hpp
hw/tegra_x1/gpu/renderer/metal/pipeline.cpp
hw/tegra_x1/gpu/renderer/metal/pipeline.hpp
hw/tegra_x1/gpu/renderer/metal/depth_stencil_state_cache.cpp
hw/tegra_x1/gpu/renderer/metal/depth_stencil_state_cache.hpp
hw/tegra_x1/gpu/renderer/metal/blit_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/blit_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/clear_color_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/clear_color_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/clear_depth_pipeline_cache.cpp
hw/tegra_x1/gpu/renderer/metal/clear_depth_pipeline_cache.hpp
hw/tegra_x1/gpu/renderer/metal/renderer.cpp
hw/tegra_x1/gpu/renderer/metal/renderer.hpp
input/apple_gc/keyboard.mm
input/apple_gc/keyboard.hpp
input/apple_gc/controller.mm
input/apple_gc/controller.hpp
input/apple_gc/device_list.mm
input/apple_gc/device_list.hpp
)
endif ()

if (HYPERVISOR_ENABLED)
target_sources(hydra-core PRIVATE
hw/tegra_x1/cpu/hypervisor/const.hpp
Expand Down Expand Up @@ -702,11 +707,17 @@ if (SDL_ENABLED)
endif ()

target_include_directories(hydra-core PRIVATE ${CMAKE_SOURCE_DIR}/externals/libyaz0/include)
# TODO: only link Apple frameworks if Apple
target_link_libraries(hydra-core PRIVATE hydra_warnings "-framework Foundation" "-framework Metal" "-framework QuartzCore" "-framework GameController" dynarmic hatch libyaz0 nx2elf date::date date::date-tz hydra-common)
target_link_libraries(hydra-core PRIVATE hydra_warnings dynarmic hatch libyaz0 nx2elf date::date date::date-tz hydra-common)

if (HYPERVISOR_ENABLED)
target_link_libraries(hydra-core PRIVATE "-framework Hypervisor")
if (LINUX)
target_link_libraries(hydra-core PRIVATE atomic)
endif ()

if (APPLE)
target_link_libraries(hydra-core PRIVATE hydra_warnings "-framework Foundation" "-framework Metal" "-framework QuartzCore" "-framework GameController")
if (HYPERVISOR_ENABLED)
target_link_libraries(hydra-core PRIVATE "-framework Hypervisor")
endif ()
endif ()

if (CUBEB_ENABLED)
Expand Down
4 changes: 4 additions & 0 deletions src/core/debugger/gdb_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#ifdef PLATFORM_LINUX
#include <fcntl.h>
#include <sys/stat.h>
#endif

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
Expand Down
2 changes: 2 additions & 0 deletions src/core/horizon/display/binder.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <condition_variable>

#include "core/horizon/kernel/kernel.hpp"
#include "core/hw/tegra_x1/gpu/const.hpp"

Expand Down
4 changes: 3 additions & 1 deletion src/core/horizon/filesystem/disk_file.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <utility>

#include "core/horizon/filesystem/file.hpp"

#define LOG_FS_ACCESS(host_path, f, ...) \
Expand All @@ -16,7 +18,7 @@ class DiskStream : public io::IostreamStream {
// as a path
DiskStream(const std::string_view path, std::ios::openmode flags)
: io::IostreamStream(stream), stream(std::string(path), flags) {
LOG_FS_ACCESS(path, "file opened (flags: {})", flags);
LOG_FS_ACCESS(path, "file opened (flags: {})", static_cast<u32>(flags));
}
~DiskStream() override {
stream.close();
Expand Down
4 changes: 2 additions & 2 deletions src/core/horizon/filesystem/romfs/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::vector<SparseFileEntry> Builder::Build() {
// Assign file offsets
u32 entry_offset = 0;
for (auto& file : files) {
data_size = align(data_size, 16ull);
data_size = align<u64>(data_size, 16ull);
file->offset = data_size;
data_size += file->size;
file->entry_offset = entry_offset;
Expand Down Expand Up @@ -166,7 +166,7 @@ std::vector<SparseFileEntry> Builder::Build() {
Header header{};
header.header_size = sizeof(Header);
header.data_offset = DATA_OFFSET;
header.directory_hash = {align(header.data_offset + data_size, 4ull),
header.directory_hash = {align<u64>(header.data_offset + data_size, 4ull),
dir_hash_table_size};
header.directory_meta = {header.directory_hash.offset +
header.directory_hash.size,
Expand Down
2 changes: 2 additions & 0 deletions src/core/horizon/kernel/thread.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <condition_variable>

#include "core/horizon/kernel/synchronization_object.hpp"

namespace hydra::horizon::kernel {
Expand Down
6 changes: 5 additions & 1 deletion src/core/horizon/services/account/internal/user_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ uuid_t UserManager::CreateUser() {
return user_id;
}

void UserManager::LoadSystemAvatars(filesystem::Filesystem& fs) {
void UserManager::LoadSystemAvatars(
[[maybe_unused]] filesystem::Filesystem& fs) {
// TODO: other platforms
#ifdef PLATFORM_APPLE
// Default avatar
const auto default_image_path =
get_bundle_resource_path("default_avatar_image.png");
Expand Down Expand Up @@ -135,6 +138,7 @@ void UserManager::LoadSystemAvatars(filesystem::Filesystem& fs) {
avatars[fmt::format(SYSTEM_AVATARS_PATH "/{}", name)] = {
static_cast<filesystem::IFile*>(entry)};
}
#endif
}

const std::vector<uchar4>& UserManager::LoadAvatarImage(std::string_view path,
Expand Down
6 changes: 3 additions & 3 deletions src/core/horizon/services/audio/audio_renderer_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IAudioRendererManager::GetWorkBufferSize(AudioRendererParameters params,
edge_matrix_buffer_sz = node_count / 8;
}
buffer_sz +=
align(node_state_buffer_sz + edge_matrix_buffer_sz, 0x10ull);
align<u64>(node_state_buffer_sz + edge_matrix_buffer_sz, 0x10ull);
}

buffer_sz += 0x20 * (params.effect_count + 4 * params.voice_count) + 0x50;
Expand All @@ -59,7 +59,7 @@ IAudioRendererManager::GetWorkBufferSize(AudioRendererParameters params,
buffer_sz += 0x20 * params.splitter_count;
buffer_sz += align(4 * params._unknown_x2c, 0x10u);
}
buffer_sz = align(buffer_sz, 0x40ull) + 0x170 * params.sink_count;
buffer_sz = align<u64>(buffer_sz, 0x40ull) + 0x170 * params.sink_count;
u64 output_sz = buffer_sz + 0x280 * params.sink_count +
0x4B0 * params.effect_count +
((params.voice_count * 256) | 0x40);
Expand All @@ -73,7 +73,7 @@ IAudioRendererManager::GetWorkBufferSize(AudioRendererParameters params,
0x40u) +
output_sz;
}
output_sz = align(output_sz + 0x1807e, 0x1000ull);
output_sz = align<u64>(output_sz + 0x1807e, 0x1000ull);

*out_size = output_sz;
LOG_INFO(Services, "Audio renderer work buffer size: 0x{:x}", *out_size);
Expand Down
8 changes: 4 additions & 4 deletions src/core/horizon/services/hid/internal/shared_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct RingLifo {
};

void Clear() {
atomic_store(&index, 0ull);
atomic_store(&count, 0ull);
atomic_store<u64>(&index, 0ull);
atomic_store<u64>(&count, 0ull);
}

T& GetCurrentStorage() { return GetCurrentAtomicStorage().data; }
Expand All @@ -26,7 +26,7 @@ struct RingLifo {
// TODO: why?
// TODO: should be max_entries - 1
if (ReadCount() < 1) {
atomic_fetch_add(&count, 1ull);
atomic_fetch_add<u64>(&count, 1ull);
}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ struct RingLifo {

AtomicStorage& GetCurrentAtomicStorage() {
const auto count_ =
std::min(ReadCount(), 1ull); // TODO: why limit to 1?
std::min<u64>(ReadCount(), 1ull); // TODO: why limit to 1?
if (count_ == 0) {
throw Error::NoStorage; // TODO: what to do?
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/horizon/services/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void IService::HandleRequest(System& system, kernel::Process* caller_process,
if (should_respond) {
// HIPC header
#define GET_ARRAY_SIZE(stream) \
static_cast<u32>(align(streams.stream.GetSeek(), 4ull) / sizeof(u32))
static_cast<u32>(align<u64>(streams.stream.GetSeek(), 4ull) / sizeof(u32))

#define WRITE_ARRAY(stream, ptr) \
if (ptr) { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void TimeZoneManager::LoadRule(std::string_view location_name,
TimeZoneRule& out_rule) const {
LOG_DEBUG(Services, "Location name: {}", location_name);

out_rule = {};

// NCA
filesystem::IFile* time_zone_archive_file;
auto res = filesystem.GetFile(FS_FIRMWARE_PATH "/TimeZoneBinary",
Expand Down
3 changes: 3 additions & 0 deletions src/core/horizon/services/timesrv/time_zone_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ result_t ITimeZoneService::ToCalendarTimeImpl(

// Get time zone name
const char* tz_name = rule.chars + info.abbreviation_list_index;
if (tz_name == nullptr) {
tz_name = "UTC";
}

// Output
out_time = {
Expand Down
2 changes: 0 additions & 2 deletions src/core/hw/tegra_x1/cpu/dynarmic/thread.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "core/hw/tegra_x1/cpu/dynarmic/thread.hpp"

#include <mach/mach_time.h>

#include <dynarmic/interface/exclusive_monitor.h>

#include "core/hw/tegra_x1/cpu/dynarmic/mmu.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/core/hw/tegra_x1/gpu/engines/3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ struct Regs3D {

// 0xd00
u32 mme_scratch[0x80];
} PACKED;
};

class ThreeD : public EngineWithRegsBase<Regs3D>, public InlineBase {
public:
Expand Down
2 changes: 2 additions & 0 deletions src/core/hw/tegra_x1/gpu/pfifo.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <condition_variable>

#include "core/hw/tegra_x1/gpu/const.hpp"
#include "core/hw/tegra_x1/gpu/gmmu.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/core/hw/tegra_x1/gpu/renderer/texture_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ u32 TextureCache::GetDataHash(const ITexture* texture) {

const auto& descriptor = texture->GetDescriptor();
u64 mem_range = descriptor.size;
u64 mem_step = std::max(mem_range / SAMPLE_COUNT, 1ull);
u64 mem_step = std::max<u64>(mem_range / SAMPLE_COUNT, 1ull);

HashCode hash;
for (u64 offset = 0; offset < mem_range; offset += mem_step)
Expand Down
2 changes: 2 additions & 0 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ System::System(horizon::ui::IHandler& ui_handler_)
System::~System() {
// TODO: set this elsewhere
LOGGER_INSTANCE.SetOutput(LogOutput::StdOut);

ForceStop();
}

void System::LoadAndStart(horizon::loader::LoaderBase* loader) {
Expand Down
16 changes: 11 additions & 5 deletions src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# TODO: set based on platform
set(NATIVE_SOURCE_FILES
native/cocoa/native.hpp
native/cocoa/native.mm
)
if (APPLE)
set(NATIVE_SOURCE_FILES
native/cocoa/native.hpp
native/cocoa/native.mm
)
endif ()

if (FRONTEND STREQUAL "SDL3")
message(STATUS "Using SDL3 frontend")
Expand All @@ -20,7 +22,11 @@ if (FRONTEND STREQUAL "SDL3")
sdl3/window.hpp
)

target_link_libraries(hydra PRIVATE hydra_warnings SDL3::SDL3 "-framework Cocoa")
target_link_libraries(hydra PRIVATE hydra_warnings SDL3::SDL3)

if (APPLE)
target_link_libraries(hydra PRIVATE "-framework Cocoa")
endif ()
elseif (FRONTEND STREQUAL "SwiftUI")
message(STATUS "Using SwiftUI frontend")

Expand Down
Loading
Loading