Compare commits
7 Commits
android-26
...
android-22
Author | SHA1 | Date | |
---|---|---|---|
c39bab83f1 | |||
08a843b767 | |||
d1d2531d35 | |||
6d036345dc | |||
90b2212ab2 | |||
c12137cbb7 | |||
87ff9f9f82 |
14
README.md
14
README.md
@ -1,3 +1,17 @@
|
||||
| Pull Request | Commit | Title | Author | Merged? |
|
||||
|----|----|----|----|----|
|
||||
| [12749](https://github.com/yuzu-emu/yuzu-android//pull/12749) | [`aad4b0d6f`](https://github.com/yuzu-emu/yuzu-android//pull/12749/files) | general: workarounds for SMMU syncing issues | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12761](https://github.com/yuzu-emu/yuzu-android//pull/12761) | [`2c421a704`](https://github.com/yuzu-emu/yuzu-android//pull/12761/files) | video_core: rewrite presentation for layer composition | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12845](https://github.com/yuzu-emu/yuzu-android//pull/12845) | [`41149d061`](https://github.com/yuzu-emu/yuzu-android//pull/12845/files) | notif: rewrite for new IPC | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12857](https://github.com/yuzu-emu/yuzu-android//pull/12857) | [`35e3c6802`](https://github.com/yuzu-emu/yuzu-android//pull/12857/files) | service: use const references for input raw data | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12874](https://github.com/yuzu-emu/yuzu-android//pull/12874) | [`f410cf681`](https://github.com/yuzu-emu/yuzu-android//pull/12874/files) | Revert "shader_recompiler: fix Offset operand usage for non-OpImage*Gather" | [liamwhite](https://github.com/liamwhite/) | Yes |
|
||||
| [12885](https://github.com/yuzu-emu/yuzu-android//pull/12885) | [`11a8ef664`](https://github.com/yuzu-emu/yuzu-android//pull/12885/files) | structured_control_flow: Add Samsung Proprietary Driver ID to Reorder Pass | [Moonlacer](https://github.com/Moonlacer/) | Yes |
|
||||
|
||||
|
||||
End of merge log. You can find the original README.md below the break.
|
||||
|
||||
-----
|
||||
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2018 yuzu Emulator Project
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
@ -775,6 +775,9 @@ add_library(core STATIC
|
||||
hle/service/nvnflinger/graphic_buffer_producer.h
|
||||
hle/service/nvnflinger/hos_binder_driver_server.cpp
|
||||
hle/service/nvnflinger/hos_binder_driver_server.h
|
||||
hle/service/nvnflinger/hardware_composer.cpp
|
||||
hle/service/nvnflinger/hardware_composer.h
|
||||
hle/service/nvnflinger/hwc_layer.h
|
||||
hle/service/nvnflinger/nvnflinger.cpp
|
||||
hle/service/nvnflinger/nvnflinger.h
|
||||
hle/service/nvnflinger/parcel.h
|
||||
|
@ -31,8 +31,11 @@ void LoopProcess(Core::System& system) {
|
||||
// Error Context
|
||||
server_manager->RegisterNamedService("ectx:aw", std::make_shared<ECTX_AW>(system));
|
||||
|
||||
// Notification Services for application
|
||||
server_manager->RegisterNamedService("notif:a", std::make_shared<NOTIF_A>(system));
|
||||
// Notification Services
|
||||
server_manager->RegisterNamedService(
|
||||
"notif:a", std::make_shared<INotificationServicesForApplication>(system));
|
||||
server_manager->RegisterNamedService("notif:s",
|
||||
std::make_shared<INotificationServices>(system));
|
||||
|
||||
// Time
|
||||
auto time = std::make_shared<Time::TimeManager>(system);
|
||||
|
@ -6,48 +6,31 @@
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/hle/service/cmif_serialization.h"
|
||||
#include "core/hle/service/glue/notif.h"
|
||||
#include "core/hle/service/ipc_helpers.h"
|
||||
#include "core/hle/service/kernel_helpers.h"
|
||||
|
||||
namespace Service::Glue {
|
||||
|
||||
NOTIF_A::NOTIF_A(Core::System& system_) : ServiceFramework{system_, "notif:a"} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{500, &NOTIF_A::RegisterAlarmSetting, "RegisterAlarmSetting"},
|
||||
{510, &NOTIF_A::UpdateAlarmSetting, "UpdateAlarmSetting"},
|
||||
{520, &NOTIF_A::ListAlarmSettings, "ListAlarmSettings"},
|
||||
{530, &NOTIF_A::LoadApplicationParameter, "LoadApplicationParameter"},
|
||||
{540, &NOTIF_A::DeleteAlarmSetting, "DeleteAlarmSetting"},
|
||||
{1000, &NOTIF_A::Initialize, "Initialize"},
|
||||
};
|
||||
// clang-format on
|
||||
namespace {
|
||||
|
||||
constexpr inline std::size_t MaxAlarms = 8;
|
||||
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
NOTIF_A::~NOTIF_A() = default;
|
||||
|
||||
void NOTIF_A::RegisterAlarmSetting(HLERequestContext& ctx) {
|
||||
const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0);
|
||||
const auto application_parameter_size = ctx.GetReadBufferSize(1);
|
||||
|
||||
ASSERT_MSG(alarm_setting_buffer_size == sizeof(AlarmSetting),
|
||||
"alarm_setting_buffer_size is not 0x40 bytes");
|
||||
ASSERT_MSG(application_parameter_size <= sizeof(ApplicationParameter),
|
||||
"application_parameter_size is bigger than 0x400 bytes");
|
||||
|
||||
AlarmSetting new_alarm{};
|
||||
memcpy(&new_alarm, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting));
|
||||
|
||||
// TODO: Count alarms per game id
|
||||
if (alarms.size() >= max_alarms) {
|
||||
Result NotificationServiceImpl::RegisterAlarmSetting(AlarmSettingId* out_alarm_setting_id,
|
||||
const AlarmSetting& alarm_setting,
|
||||
std::span<const u8> application_parameter) {
|
||||
if (alarms.size() > MaxAlarms) {
|
||||
LOG_ERROR(Service_NOTIF, "Alarm limit reached");
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultUnknown);
|
||||
return;
|
||||
R_THROW(ResultUnknown);
|
||||
}
|
||||
|
||||
ASSERT_MSG(application_parameter.size() <= sizeof(ApplicationParameter),
|
||||
"application_parameter_size is bigger than 0x400 bytes");
|
||||
|
||||
AlarmSetting new_alarm = alarm_setting;
|
||||
new_alarm.alarm_setting_id = last_alarm_setting_id++;
|
||||
alarms.push_back(new_alarm);
|
||||
|
||||
@ -55,100 +38,82 @@ void NOTIF_A::RegisterAlarmSetting(HLERequestContext& ctx) {
|
||||
|
||||
LOG_WARNING(Service_NOTIF,
|
||||
"(STUBBED) called, application_parameter_size={}, setting_id={}, kind={}, muted={}",
|
||||
application_parameter_size, new_alarm.alarm_setting_id, new_alarm.kind,
|
||||
application_parameter.size(), new_alarm.alarm_setting_id, new_alarm.kind,
|
||||
new_alarm.muted);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(new_alarm.alarm_setting_id);
|
||||
*out_alarm_setting_id = new_alarm.alarm_setting_id;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void NOTIF_A::UpdateAlarmSetting(HLERequestContext& ctx) {
|
||||
const auto alarm_setting_buffer_size = ctx.GetReadBufferSize(0);
|
||||
const auto application_parameter_size = ctx.GetReadBufferSize(1);
|
||||
|
||||
ASSERT_MSG(alarm_setting_buffer_size == sizeof(AlarmSetting),
|
||||
"alarm_setting_buffer_size is not 0x40 bytes");
|
||||
ASSERT_MSG(application_parameter_size <= sizeof(ApplicationParameter),
|
||||
Result NotificationServiceImpl::UpdateAlarmSetting(const AlarmSetting& alarm_setting,
|
||||
std::span<const u8> application_parameter) {
|
||||
ASSERT_MSG(application_parameter.size() <= sizeof(ApplicationParameter),
|
||||
"application_parameter_size is bigger than 0x400 bytes");
|
||||
|
||||
AlarmSetting alarm_setting{};
|
||||
memcpy(&alarm_setting, ctx.ReadBuffer(0).data(), sizeof(AlarmSetting));
|
||||
|
||||
const auto alarm_it = GetAlarmFromId(alarm_setting.alarm_setting_id);
|
||||
if (alarm_it != alarms.end()) {
|
||||
LOG_DEBUG(Service_NOTIF, "Alarm updated");
|
||||
*alarm_it = alarm_setting;
|
||||
// TODO: Save application parameter data
|
||||
}
|
||||
|
||||
LOG_WARNING(Service_NOTIF,
|
||||
"(STUBBED) called, application_parameter_size={}, setting_id={}, kind={}, muted={}",
|
||||
application_parameter_size, alarm_setting.alarm_setting_id, alarm_setting.kind,
|
||||
application_parameter.size(), alarm_setting.alarm_setting_id, alarm_setting.kind,
|
||||
alarm_setting.muted);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void NOTIF_A::ListAlarmSettings(HLERequestContext& ctx) {
|
||||
Result NotificationServiceImpl::ListAlarmSettings(s32* out_count,
|
||||
std::span<AlarmSetting> out_alarms) {
|
||||
LOG_INFO(Service_NOTIF, "called, alarm_count={}", alarms.size());
|
||||
|
||||
// TODO: Only return alarms of this game id
|
||||
ctx.WriteBuffer(alarms);
|
||||
const auto count = std::min(out_alarms.size(), alarms.size());
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
out_alarms[i] = alarms[i];
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(static_cast<u32>(alarms.size()));
|
||||
*out_count = static_cast<s32>(count);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void NOTIF_A::LoadApplicationParameter(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto alarm_setting_id{rp.Pop<AlarmSettingId>()};
|
||||
|
||||
Result NotificationServiceImpl::LoadApplicationParameter(u32* out_size,
|
||||
std::span<u8> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id) {
|
||||
const auto alarm_it = GetAlarmFromId(alarm_setting_id);
|
||||
if (alarm_it == alarms.end()) {
|
||||
LOG_ERROR(Service_NOTIF, "Invalid alarm setting id={}", alarm_setting_id);
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultUnknown);
|
||||
return;
|
||||
R_THROW(ResultUnknown);
|
||||
}
|
||||
|
||||
// TODO: Read application parameter related to this setting id
|
||||
ApplicationParameter application_parameter{};
|
||||
|
||||
LOG_WARNING(Service_NOTIF, "(STUBBED) called, alarm_setting_id={}", alarm_setting_id);
|
||||
std::memcpy(out_application_parameter.data(), application_parameter.data(),
|
||||
std::min(sizeof(application_parameter), out_application_parameter.size()));
|
||||
|
||||
ctx.WriteBuffer(application_parameter);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(static_cast<u32>(application_parameter.size()));
|
||||
*out_size = static_cast<u32>(application_parameter.size());
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void NOTIF_A::DeleteAlarmSetting(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto alarm_setting_id{rp.Pop<AlarmSettingId>()};
|
||||
|
||||
Result NotificationServiceImpl::DeleteAlarmSetting(AlarmSettingId alarm_setting_id) {
|
||||
std::erase_if(alarms, [alarm_setting_id](const AlarmSetting& alarm) {
|
||||
return alarm.alarm_setting_id == alarm_setting_id;
|
||||
});
|
||||
|
||||
LOG_INFO(Service_NOTIF, "called, alarm_setting_id={}", alarm_setting_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void NOTIF_A::Initialize(HLERequestContext& ctx) {
|
||||
Result NotificationServiceImpl::Initialize(u64 aruid) {
|
||||
// TODO: Load previous alarms from config
|
||||
|
||||
LOG_WARNING(Service_NOTIF, "(STUBBED) called");
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
std::vector<NOTIF_A::AlarmSetting>::iterator NOTIF_A::GetAlarmFromId(
|
||||
std::vector<AlarmSetting>::iterator NotificationServiceImpl::GetAlarmFromId(
|
||||
AlarmSettingId alarm_setting_id) {
|
||||
return std::find_if(alarms.begin(), alarms.end(),
|
||||
[alarm_setting_id](const AlarmSetting& alarm) {
|
||||
@ -156,4 +121,174 @@ std::vector<NOTIF_A::AlarmSetting>::iterator NOTIF_A::GetAlarmFromId(
|
||||
});
|
||||
}
|
||||
|
||||
INotificationServicesForApplication::INotificationServicesForApplication(Core::System& system_)
|
||||
: ServiceFramework{system_, "notif:a"} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{500, D<&INotificationServicesForApplication::RegisterAlarmSetting>, "RegisterAlarmSetting"},
|
||||
{510, D<&INotificationServicesForApplication::UpdateAlarmSetting>, "UpdateAlarmSetting"},
|
||||
{520, D<&INotificationServicesForApplication::ListAlarmSettings>, "ListAlarmSettings"},
|
||||
{530, D<&INotificationServicesForApplication::LoadApplicationParameter>, "LoadApplicationParameter"},
|
||||
{540, D<&INotificationServicesForApplication::DeleteAlarmSetting>, "DeleteAlarmSetting"},
|
||||
{1000, D<&INotificationServicesForApplication::Initialize>, "Initialize"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
INotificationServicesForApplication::~INotificationServicesForApplication() = default;
|
||||
|
||||
Result INotificationServicesForApplication::RegisterAlarmSetting(
|
||||
Out<AlarmSettingId> out_alarm_setting_id,
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter) {
|
||||
R_RETURN(impl.RegisterAlarmSetting(out_alarm_setting_id.Get(), *alarm_setting,
|
||||
application_parameter));
|
||||
}
|
||||
|
||||
Result INotificationServicesForApplication::UpdateAlarmSetting(
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter) {
|
||||
R_RETURN(impl.UpdateAlarmSetting(*alarm_setting, application_parameter));
|
||||
}
|
||||
|
||||
Result INotificationServicesForApplication::ListAlarmSettings(
|
||||
Out<s32> out_count, OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms) {
|
||||
R_RETURN(impl.ListAlarmSettings(out_count.Get(), out_alarms));
|
||||
}
|
||||
|
||||
Result INotificationServicesForApplication::LoadApplicationParameter(
|
||||
Out<u32> out_size, OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id) {
|
||||
R_RETURN(
|
||||
impl.LoadApplicationParameter(out_size.Get(), out_application_parameter, alarm_setting_id));
|
||||
}
|
||||
|
||||
Result INotificationServicesForApplication::DeleteAlarmSetting(AlarmSettingId alarm_setting_id) {
|
||||
R_RETURN(impl.DeleteAlarmSetting(alarm_setting_id));
|
||||
}
|
||||
|
||||
Result INotificationServicesForApplication::Initialize(ClientAppletResourceUserId aruid) {
|
||||
R_RETURN(impl.Initialize(*aruid));
|
||||
}
|
||||
|
||||
class INotificationSystemEventAccessor final
|
||||
: public ServiceFramework<INotificationSystemEventAccessor> {
|
||||
public:
|
||||
explicit INotificationSystemEventAccessor(Core::System& system_)
|
||||
: ServiceFramework{system_, "INotificationSystemEventAccessor"},
|
||||
service_context{system_, "INotificationSystemEventAccessor"} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, D<&INotificationSystemEventAccessor::GetSystemEvent>, "GetSystemEvent"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
RegisterHandlers(functions);
|
||||
|
||||
notification_event =
|
||||
service_context.CreateEvent("INotificationSystemEventAccessor:NotificationEvent");
|
||||
}
|
||||
|
||||
~INotificationSystemEventAccessor() {
|
||||
service_context.CloseEvent(notification_event);
|
||||
}
|
||||
|
||||
private:
|
||||
Result GetSystemEvent(OutCopyHandle<Kernel::KReadableEvent> out_readable_event) {
|
||||
LOG_WARNING(Service_NOTIF, "(STUBBED) called");
|
||||
|
||||
*out_readable_event = ¬ification_event->GetReadableEvent();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
Kernel::KEvent* notification_event;
|
||||
};
|
||||
|
||||
INotificationServices::INotificationServices(Core::System& system_)
|
||||
: ServiceFramework{system_, "notif:s"} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{500, D<&INotificationServices::RegisterAlarmSetting>, "RegisterAlarmSetting"},
|
||||
{510, D<&INotificationServices::UpdateAlarmSetting>, "UpdateAlarmSetting"},
|
||||
{520, D<&INotificationServices::ListAlarmSettings>, "ListAlarmSettings"},
|
||||
{530, D<&INotificationServices::LoadApplicationParameter>, "LoadApplicationParameter"},
|
||||
{540, D<&INotificationServices::DeleteAlarmSetting>, "DeleteAlarmSetting"},
|
||||
{1000, D<&INotificationServices::Initialize>, "Initialize"},
|
||||
{1010, nullptr, "ListNotifications"},
|
||||
{1020, nullptr, "DeleteNotification"},
|
||||
{1030, nullptr, "ClearNotifications"},
|
||||
{1040, D<&INotificationServices::OpenNotificationSystemEventAccessor>, "OpenNotificationSystemEventAccessor"},
|
||||
{1500, nullptr, "SetNotificationPresentationSetting"},
|
||||
{1510, D<&INotificationServices::GetNotificationPresentationSetting>, "GetNotificationPresentationSetting"},
|
||||
{2000, nullptr, "GetAlarmSetting"},
|
||||
{2001, nullptr, "GetAlarmSettingWithApplicationParameter"},
|
||||
{2010, nullptr, "MuteAlarmSetting"},
|
||||
{2020, nullptr, "IsAlarmSettingReady"},
|
||||
{8000, nullptr, "RegisterAppletResourceUserId"},
|
||||
{8010, nullptr, "UnregisterAppletResourceUserId"},
|
||||
{8999, nullptr, "GetCurrentTime"},
|
||||
{9000, nullptr, "GetAlarmSettingNextNotificationTime"},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
RegisterHandlers(functions);
|
||||
}
|
||||
|
||||
INotificationServices::~INotificationServices() = default;
|
||||
|
||||
Result INotificationServices::RegisterAlarmSetting(
|
||||
Out<AlarmSettingId> out_alarm_setting_id,
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter) {
|
||||
R_RETURN(impl.RegisterAlarmSetting(out_alarm_setting_id.Get(), *alarm_setting,
|
||||
application_parameter));
|
||||
}
|
||||
|
||||
Result INotificationServices::UpdateAlarmSetting(
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter) {
|
||||
R_RETURN(impl.UpdateAlarmSetting(*alarm_setting, application_parameter));
|
||||
}
|
||||
|
||||
Result INotificationServices::ListAlarmSettings(
|
||||
Out<s32> out_count, OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms) {
|
||||
R_RETURN(impl.ListAlarmSettings(out_count.Get(), out_alarms));
|
||||
}
|
||||
|
||||
Result INotificationServices::LoadApplicationParameter(
|
||||
Out<u32> out_size, OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id) {
|
||||
R_RETURN(
|
||||
impl.LoadApplicationParameter(out_size.Get(), out_application_parameter, alarm_setting_id));
|
||||
}
|
||||
|
||||
Result INotificationServices::DeleteAlarmSetting(AlarmSettingId alarm_setting_id) {
|
||||
R_RETURN(impl.DeleteAlarmSetting(alarm_setting_id));
|
||||
}
|
||||
|
||||
Result INotificationServices::Initialize(ClientAppletResourceUserId aruid) {
|
||||
R_RETURN(impl.Initialize(*aruid));
|
||||
}
|
||||
|
||||
Result INotificationServices::OpenNotificationSystemEventAccessor(
|
||||
Out<SharedPointer<INotificationSystemEventAccessor>> out_notification_system_event_accessor) {
|
||||
LOG_WARNING(Service_NOTIF, "(STUBBED) called");
|
||||
|
||||
*out_notification_system_event_accessor =
|
||||
std::make_shared<INotificationSystemEventAccessor>(system);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result INotificationServices::GetNotificationPresentationSetting(
|
||||
Out<NotificationPresentationSetting> out_notification_presentation_setting,
|
||||
NotificationChannel notification_channel) {
|
||||
LOG_WARNING(Service_NOTIF, "(STUBBED) called");
|
||||
|
||||
*out_notification_presentation_setting = {};
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace Service::Glue
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "common/uuid.h"
|
||||
#include "core/hle/service/cmif_types.h"
|
||||
#include "core/hle/service/service.h"
|
||||
|
||||
namespace Core {
|
||||
@ -15,58 +16,117 @@ class System;
|
||||
|
||||
namespace Service::Glue {
|
||||
|
||||
class NOTIF_A final : public ServiceFramework<NOTIF_A> {
|
||||
// This is nn::notification::AlarmSettingId
|
||||
using AlarmSettingId = u16;
|
||||
static_assert(sizeof(AlarmSettingId) == 0x2, "AlarmSettingId is an invalid size");
|
||||
|
||||
using ApplicationParameter = std::array<u8, 0x400>;
|
||||
static_assert(sizeof(ApplicationParameter) == 0x400, "ApplicationParameter is an invalid size");
|
||||
|
||||
struct DailyAlarmSetting {
|
||||
s8 hour;
|
||||
s8 minute;
|
||||
};
|
||||
static_assert(sizeof(DailyAlarmSetting) == 0x2, "DailyAlarmSetting is an invalid size");
|
||||
|
||||
struct WeeklyScheduleAlarmSetting {
|
||||
INSERT_PADDING_BYTES_NOINIT(0xA);
|
||||
std::array<DailyAlarmSetting, 0x7> day_of_week;
|
||||
};
|
||||
static_assert(sizeof(WeeklyScheduleAlarmSetting) == 0x18,
|
||||
"WeeklyScheduleAlarmSetting is an invalid size");
|
||||
|
||||
// This is nn::notification::AlarmSetting
|
||||
struct AlarmSetting {
|
||||
AlarmSettingId alarm_setting_id;
|
||||
u8 kind;
|
||||
u8 muted;
|
||||
INSERT_PADDING_BYTES_NOINIT(0x4);
|
||||
Common::UUID account_id;
|
||||
u64 application_id;
|
||||
INSERT_PADDING_BYTES_NOINIT(0x8);
|
||||
WeeklyScheduleAlarmSetting schedule;
|
||||
};
|
||||
static_assert(sizeof(AlarmSetting) == 0x40, "AlarmSetting is an invalid size");
|
||||
|
||||
enum class NotificationChannel : u8 {
|
||||
Unknown0 = 0,
|
||||
};
|
||||
|
||||
struct NotificationPresentationSetting {
|
||||
INSERT_PADDING_BYTES_NOINIT(0x10);
|
||||
};
|
||||
static_assert(sizeof(NotificationPresentationSetting) == 0x10,
|
||||
"NotificationPresentationSetting is an invalid size");
|
||||
|
||||
class NotificationServiceImpl {
|
||||
public:
|
||||
explicit NOTIF_A(Core::System& system_);
|
||||
~NOTIF_A() override;
|
||||
Result RegisterAlarmSetting(AlarmSettingId* out_alarm_setting_id,
|
||||
const AlarmSetting& alarm_setting,
|
||||
std::span<const u8> application_parameter);
|
||||
Result UpdateAlarmSetting(const AlarmSetting& alarm_setting,
|
||||
std::span<const u8> application_parameter);
|
||||
Result ListAlarmSettings(s32* out_count, std::span<AlarmSetting> out_alarms);
|
||||
Result LoadApplicationParameter(u32* out_size, std::span<u8> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id);
|
||||
Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
|
||||
Result Initialize(u64 aruid);
|
||||
|
||||
private:
|
||||
static constexpr std::size_t max_alarms = 8;
|
||||
|
||||
// This is nn::notification::AlarmSettingId
|
||||
using AlarmSettingId = u16;
|
||||
static_assert(sizeof(AlarmSettingId) == 0x2, "AlarmSettingId is an invalid size");
|
||||
|
||||
using ApplicationParameter = std::array<u8, 0x400>;
|
||||
static_assert(sizeof(ApplicationParameter) == 0x400, "ApplicationParameter is an invalid size");
|
||||
|
||||
struct DailyAlarmSetting {
|
||||
s8 hour;
|
||||
s8 minute;
|
||||
};
|
||||
static_assert(sizeof(DailyAlarmSetting) == 0x2, "DailyAlarmSetting is an invalid size");
|
||||
|
||||
struct WeeklyScheduleAlarmSetting {
|
||||
INSERT_PADDING_BYTES(0xA);
|
||||
std::array<DailyAlarmSetting, 0x7> day_of_week;
|
||||
};
|
||||
static_assert(sizeof(WeeklyScheduleAlarmSetting) == 0x18,
|
||||
"WeeklyScheduleAlarmSetting is an invalid size");
|
||||
|
||||
// This is nn::notification::AlarmSetting
|
||||
struct AlarmSetting {
|
||||
AlarmSettingId alarm_setting_id;
|
||||
u8 kind;
|
||||
u8 muted;
|
||||
INSERT_PADDING_BYTES(0x4);
|
||||
Common::UUID account_id;
|
||||
u64 application_id;
|
||||
INSERT_PADDING_BYTES(0x8);
|
||||
WeeklyScheduleAlarmSetting schedule;
|
||||
};
|
||||
static_assert(sizeof(AlarmSetting) == 0x40, "AlarmSetting is an invalid size");
|
||||
|
||||
void RegisterAlarmSetting(HLERequestContext& ctx);
|
||||
void UpdateAlarmSetting(HLERequestContext& ctx);
|
||||
void ListAlarmSettings(HLERequestContext& ctx);
|
||||
void LoadApplicationParameter(HLERequestContext& ctx);
|
||||
void DeleteAlarmSetting(HLERequestContext& ctx);
|
||||
void Initialize(HLERequestContext& ctx);
|
||||
|
||||
std::vector<AlarmSetting>::iterator GetAlarmFromId(AlarmSettingId alarm_setting_id);
|
||||
|
||||
std::vector<AlarmSetting> alarms{};
|
||||
AlarmSettingId last_alarm_setting_id{};
|
||||
};
|
||||
|
||||
class INotificationServicesForApplication final
|
||||
: public ServiceFramework<INotificationServicesForApplication> {
|
||||
public:
|
||||
explicit INotificationServicesForApplication(Core::System& system_);
|
||||
~INotificationServicesForApplication() override;
|
||||
|
||||
private:
|
||||
Result RegisterAlarmSetting(Out<AlarmSettingId> out_alarm_setting_id,
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter);
|
||||
Result UpdateAlarmSetting(InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter);
|
||||
Result ListAlarmSettings(Out<s32> out_count,
|
||||
OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms);
|
||||
Result LoadApplicationParameter(Out<u32> out_size,
|
||||
OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id);
|
||||
Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
|
||||
Result Initialize(ClientAppletResourceUserId aruid);
|
||||
|
||||
NotificationServiceImpl impl;
|
||||
};
|
||||
|
||||
class INotificationSystemEventAccessor;
|
||||
|
||||
class INotificationServices final : public ServiceFramework<INotificationServices> {
|
||||
public:
|
||||
explicit INotificationServices(Core::System& system_);
|
||||
~INotificationServices() override;
|
||||
|
||||
private:
|
||||
Result RegisterAlarmSetting(Out<AlarmSettingId> out_alarm_setting_id,
|
||||
InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter);
|
||||
Result UpdateAlarmSetting(InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
|
||||
InBuffer<BufferAttr_HipcMapAlias> application_parameter);
|
||||
Result ListAlarmSettings(Out<s32> out_count,
|
||||
OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms);
|
||||
Result LoadApplicationParameter(Out<u32> out_size,
|
||||
OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
|
||||
AlarmSettingId alarm_setting_id);
|
||||
Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
|
||||
Result Initialize(ClientAppletResourceUserId aruid);
|
||||
Result OpenNotificationSystemEventAccessor(Out<SharedPointer<INotificationSystemEventAccessor>>
|
||||
out_notification_system_event_accessor);
|
||||
Result GetNotificationPresentationSetting(
|
||||
Out<NotificationPresentationSetting> out_notification_presentation_setting,
|
||||
NotificationChannel notification_channel);
|
||||
|
||||
NotificationServiceImpl impl;
|
||||
};
|
||||
} // namespace Service::Glue
|
||||
|
@ -200,7 +200,7 @@ Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
}
|
||||
|
||||
Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(
|
||||
Out<s64> out_time, Service::PSC::Time::SystemClockContext& context) {
|
||||
Out<s64> out_time, const Service::PSC::Time::SystemClockContext& context) {
|
||||
SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time); });
|
||||
|
||||
R_RETURN(m_wrapped_service->CalculateMonotonicSystemClockBaseTimePoint(out_time, context));
|
||||
@ -216,8 +216,8 @@ Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot,
|
||||
|
||||
Result StaticService::GetClockSnapshotFromSystemClockContext(
|
||||
Service::PSC::Time::TimeType type, OutClockSnapshot out_snapshot,
|
||||
Service::PSC::Time::SystemClockContext& user_context,
|
||||
Service::PSC::Time::SystemClockContext& network_context) {
|
||||
const Service::PSC::Time::SystemClockContext& user_context,
|
||||
const Service::PSC::Time::SystemClockContext& network_context) {
|
||||
SCOPE_EXIT({
|
||||
LOG_DEBUG(Service_Time,
|
||||
"called. type={} out_snapshot={} user_context={} network_context={}", type,
|
||||
|
@ -58,12 +58,12 @@ public:
|
||||
Result GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point);
|
||||
Result CalculateMonotonicSystemClockBaseTimePoint(
|
||||
Out<s64> out_time, Service::PSC::Time::SystemClockContext& context);
|
||||
Out<s64> out_time, const Service::PSC::Time::SystemClockContext& context);
|
||||
Result GetClockSnapshot(OutClockSnapshot out_snapshot, Service::PSC::Time::TimeType type);
|
||||
Result GetClockSnapshotFromSystemClockContext(
|
||||
Service::PSC::Time::TimeType type, OutClockSnapshot out_snapshot,
|
||||
Service::PSC::Time::SystemClockContext& user_context,
|
||||
Service::PSC::Time::SystemClockContext& network_context);
|
||||
const Service::PSC::Time::SystemClockContext& user_context,
|
||||
const Service::PSC::Time::SystemClockContext& network_context);
|
||||
Result CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_difference,
|
||||
InClockSnapshot a, InClockSnapshot b);
|
||||
Result CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a, InClockSnapshot b);
|
||||
|
@ -62,7 +62,8 @@ Result TimeZoneService::GetDeviceLocationName(
|
||||
R_RETURN(m_wrapped_service->GetDeviceLocationName(out_location_name));
|
||||
}
|
||||
|
||||
Result TimeZoneService::SetDeviceLocationName(Service::PSC::Time::LocationName& location_name) {
|
||||
Result TimeZoneService::SetDeviceLocationName(
|
||||
const Service::PSC::Time::LocationName& location_name) {
|
||||
LOG_DEBUG(Service_Time, "called. location_name={}", location_name);
|
||||
|
||||
R_UNLESS(m_can_write_timezone_device_location, Service::PSC::Time::ResultPermissionDenied);
|
||||
@ -110,7 +111,8 @@ Result TimeZoneService::LoadLocationNameList(
|
||||
R_RETURN(GetTimeZoneLocationList(*out_count, out_names, out_names.size(), index));
|
||||
}
|
||||
|
||||
Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule, Service::PSC::Time::LocationName& name) {
|
||||
Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule,
|
||||
const Service::PSC::Time::LocationName& name) {
|
||||
LOG_DEBUG(Service_Time, "called. name={}", name);
|
||||
|
||||
std::scoped_lock l{m_mutex};
|
||||
@ -139,7 +141,8 @@ Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime(
|
||||
}
|
||||
|
||||
Result TimeZoneService::SetDeviceLocationNameWithTimeZoneRule(
|
||||
Service::PSC::Time::LocationName& location_name, InBuffer<BufferAttr_HipcAutoSelect> binary) {
|
||||
const Service::PSC::Time::LocationName& location_name,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> binary) {
|
||||
LOG_DEBUG(Service_Time, "called. location_name={}", location_name);
|
||||
|
||||
R_UNLESS(m_can_write_timezone_device_location, Service::PSC::Time::ResultPermissionDenied);
|
||||
|
@ -46,18 +46,20 @@ public:
|
||||
~TimeZoneService() override;
|
||||
|
||||
Result GetDeviceLocationName(Out<Service::PSC::Time::LocationName> out_location_name);
|
||||
Result SetDeviceLocationName(Service::PSC::Time::LocationName& location_name);
|
||||
Result SetDeviceLocationName(const Service::PSC::Time::LocationName& location_name);
|
||||
Result GetTotalLocationNameCount(Out<u32> out_count);
|
||||
Result LoadLocationNameList(
|
||||
Out<u32> out_count,
|
||||
OutArray<Service::PSC::Time::LocationName, BufferAttr_HipcMapAlias> out_names, u32 index);
|
||||
Result LoadTimeZoneRule(OutRule out_rule, Service::PSC::Time::LocationName& location_name);
|
||||
Result LoadTimeZoneRule(OutRule out_rule,
|
||||
const Service::PSC::Time::LocationName& location_name);
|
||||
Result GetTimeZoneRuleVersion(Out<Service::PSC::Time::RuleVersion> out_rule_version);
|
||||
Result GetDeviceLocationNameAndUpdatedTime(
|
||||
Out<Service::PSC::Time::LocationName> location_name,
|
||||
Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point);
|
||||
Result SetDeviceLocationNameWithTimeZoneRule(Service::PSC::Time::LocationName& location_name,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> binary);
|
||||
Result SetDeviceLocationNameWithTimeZoneRule(
|
||||
const Service::PSC::Time::LocationName& location_name,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> binary);
|
||||
Result ParseTimeZoneBinary(OutRule out_rule, InBuffer<BufferAttr_HipcAutoSelect> binary);
|
||||
Result GetDeviceLocationNameOperationEventReadableHandle(
|
||||
OutCopyHandle<Kernel::KReadableEvent> out_event);
|
||||
|
@ -98,7 +98,7 @@ void GetTimeZoneBinaryVersionPath(std::string& out_path) {
|
||||
out_path = "/version.txt";
|
||||
}
|
||||
|
||||
void GetTimeZoneZonePath(std::string& out_path, Service::PSC::Time::LocationName& name) {
|
||||
void GetTimeZoneZonePath(std::string& out_path, const Service::PSC::Time::LocationName& name) {
|
||||
if (g_time_zone_binary_mount_result != ResultSuccess) {
|
||||
return;
|
||||
}
|
||||
@ -106,7 +106,7 @@ void GetTimeZoneZonePath(std::string& out_path, Service::PSC::Time::LocationName
|
||||
out_path = fmt::format("/zoneinfo/{}", name.data());
|
||||
}
|
||||
|
||||
bool IsTimeZoneBinaryValid(Service::PSC::Time::LocationName& name) {
|
||||
bool IsTimeZoneBinaryValid(const Service::PSC::Time::LocationName& name) {
|
||||
std::string path{};
|
||||
GetTimeZoneZonePath(path, name);
|
||||
|
||||
@ -155,7 +155,7 @@ Result GetTimeZoneVersion(Service::PSC::Time::RuleVersion& out_rule_version) {
|
||||
}
|
||||
|
||||
Result GetTimeZoneRule(std::span<const u8>& out_rule, size_t& out_rule_size,
|
||||
Service::PSC::Time::LocationName& name) {
|
||||
const Service::PSC::Time::LocationName& name) {
|
||||
std::string path{};
|
||||
GetTimeZoneZonePath(path, name);
|
||||
|
||||
|
@ -19,12 +19,12 @@ void ResetTimeZoneBinary();
|
||||
Result MountTimeZoneBinary(Core::System& system);
|
||||
void GetTimeZoneBinaryListPath(std::string& out_path);
|
||||
void GetTimeZoneBinaryVersionPath(std::string& out_path);
|
||||
void GetTimeZoneZonePath(std::string& out_path, Service::PSC::Time::LocationName& name);
|
||||
bool IsTimeZoneBinaryValid(Service::PSC::Time::LocationName& name);
|
||||
void GetTimeZoneZonePath(std::string& out_path, const Service::PSC::Time::LocationName& name);
|
||||
bool IsTimeZoneBinaryValid(const Service::PSC::Time::LocationName& name);
|
||||
u32 GetTimeZoneCount();
|
||||
Result GetTimeZoneVersion(Service::PSC::Time::RuleVersion& out_rule_version);
|
||||
Result GetTimeZoneRule(std::span<const u8>& out_rule, size_t& out_rule_size,
|
||||
Service::PSC::Time::LocationName& name);
|
||||
const Service::PSC::Time::LocationName& name);
|
||||
Result GetTimeZoneLocationList(u32& out_count,
|
||||
std::span<Service::PSC::Time::LocationName> out_names,
|
||||
size_t max_names, u32 index);
|
||||
|
@ -126,7 +126,7 @@ public:
|
||||
R_THROW(ResultUnknown);
|
||||
}
|
||||
|
||||
Result LoadPlugin(u64 tmem_size, InCopyHandle<Kernel::KTransferMemory>& tmem,
|
||||
Result LoadPlugin(u64 tmem_size, InCopyHandle<Kernel::KTransferMemory> tmem,
|
||||
InBuffer<BufferAttr_HipcMapAlias> nrr,
|
||||
InBuffer<BufferAttr_HipcMapAlias> nro) {
|
||||
if (!tmem) {
|
||||
@ -268,9 +268,9 @@ public:
|
||||
|
||||
private:
|
||||
Result CreateJitEnvironment(Out<SharedPointer<IJitEnvironment>> out_jit_environment,
|
||||
u64 rx_size, u64 ro_size, InCopyHandle<Kernel::KProcess>& process,
|
||||
InCopyHandle<Kernel::KCodeMemory>& rx_mem,
|
||||
InCopyHandle<Kernel::KCodeMemory>& ro_mem) {
|
||||
u64 rx_size, u64 ro_size, InCopyHandle<Kernel::KProcess> process,
|
||||
InCopyHandle<Kernel::KCodeMemory> rx_mem,
|
||||
InCopyHandle<Kernel::KCodeMemory> ro_mem) {
|
||||
if (!process) {
|
||||
LOG_ERROR(Service_JIT, "process is null");
|
||||
R_THROW(ResultUnknown);
|
||||
|
@ -189,7 +189,7 @@ private:
|
||||
R_RETURN(manager->Move(metadata, new_index, create_id));
|
||||
}
|
||||
|
||||
Result AddOrReplace(StoreData& store_data) {
|
||||
Result AddOrReplace(const StoreData& store_data) {
|
||||
LOG_INFO(Service_Mii, "called");
|
||||
R_UNLESS(is_system, ResultPermissionDenied);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
@ -38,19 +40,30 @@ NvResult nvdisp_disp0::Ioctl3(DeviceFD fd, Ioctl command, std::span<const u8> in
|
||||
void nvdisp_disp0::OnOpen(NvCore::SessionId session_id, DeviceFD fd) {}
|
||||
void nvdisp_disp0::OnClose(DeviceFD fd) {}
|
||||
|
||||
void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, android::PixelFormat format, u32 width,
|
||||
u32 height, u32 stride, android::BufferTransformFlags transform,
|
||||
const Common::Rectangle<int>& crop_rect,
|
||||
std::array<Service::Nvidia::NvFence, 4>& fences, u32 num_fences) {
|
||||
const DAddr addr = nvmap.GetHandleAddress(buffer_handle);
|
||||
LOG_TRACE(Service,
|
||||
"Drawing from address {:X} offset {:08X} Width {} Height {} Stride {} Format {}",
|
||||
addr, offset, width, height, stride, format);
|
||||
void nvdisp_disp0::Composite(std::span<const Nvnflinger::HwcLayer> sorted_layers) {
|
||||
std::vector<Tegra::FramebufferConfig> output_layers;
|
||||
std::vector<Service::Nvidia::NvFence> output_fences;
|
||||
output_layers.reserve(sorted_layers.size());
|
||||
output_fences.reserve(sorted_layers.size());
|
||||
|
||||
const Tegra::FramebufferConfig framebuffer{addr, offset, width, height,
|
||||
stride, format, transform, crop_rect};
|
||||
for (auto& layer : sorted_layers) {
|
||||
output_layers.emplace_back(Tegra::FramebufferConfig{
|
||||
.address = nvmap.GetHandleAddress(layer.buffer_handle),
|
||||
.offset = layer.offset,
|
||||
.width = layer.width,
|
||||
.height = layer.height,
|
||||
.stride = layer.stride,
|
||||
.pixel_format = layer.format,
|
||||
.transform_flags = layer.transform,
|
||||
.crop_rect = layer.crop_rect,
|
||||
});
|
||||
|
||||
system.GPU().RequestSwapBuffers(&framebuffer, fences, num_fences);
|
||||
for (size_t i = 0; i < layer.acquire_fence.num_fences; i++) {
|
||||
output_fences.push_back(layer.acquire_fence.fences[i]);
|
||||
}
|
||||
}
|
||||
|
||||
system.GPU().RequestComposite(std::move(output_layers), std::move(output_fences));
|
||||
system.SpeedLimiter().DoSpeedLimiting(system.CoreTiming().GetGlobalTimeUs());
|
||||
system.GetPerfStats().EndSystemFrame();
|
||||
system.GetPerfStats().BeginSystemFrame();
|
||||
|
@ -8,8 +8,7 @@
|
||||
#include "common/common_types.h"
|
||||
#include "common/math_util.h"
|
||||
#include "core/hle/service/nvdrv/devices/nvdevice.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_transform_flags.h"
|
||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||
#include "core/hle/service/nvnflinger/hwc_layer.h"
|
||||
|
||||
namespace Service::Nvidia::NvCore {
|
||||
class Container;
|
||||
@ -35,11 +34,8 @@ public:
|
||||
void OnOpen(NvCore::SessionId session_id, DeviceFD fd) override;
|
||||
void OnClose(DeviceFD fd) override;
|
||||
|
||||
/// Performs a screen flip, drawing the buffer pointed to by the handle.
|
||||
void flip(u32 buffer_handle, u32 offset, android::PixelFormat format, u32 width, u32 height,
|
||||
u32 stride, android::BufferTransformFlags transform,
|
||||
const Common::Rectangle<int>& crop_rect,
|
||||
std::array<Service::Nvidia::NvFence, 4>& fences, u32 num_fences);
|
||||
/// Performs a screen flip, compositing each buffer.
|
||||
void Composite(std::span<const Nvnflinger::HwcLayer> sorted_layers);
|
||||
|
||||
Kernel::KEvent* QueryEvent(u32 event_id) override;
|
||||
|
||||
|
215
src/core/hle/service/nvnflinger/hardware_composer.cpp
Normal file
215
src/core/hle/service/nvnflinger/hardware_composer.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "common/microprofile.h"
|
||||
#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_item.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_item_consumer.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_queue_producer.h"
|
||||
#include "core/hle/service/nvnflinger/hardware_composer.h"
|
||||
#include "core/hle/service/nvnflinger/hwc_layer.h"
|
||||
#include "core/hle/service/nvnflinger/ui/graphic_buffer.h"
|
||||
#include "core/hle/service/vi/display/vi_display.h"
|
||||
#include "core/hle/service/vi/layer/vi_layer.h"
|
||||
|
||||
namespace Service::Nvnflinger {
|
||||
|
||||
namespace {
|
||||
|
||||
s32 NormalizeSwapInterval(f32* out_speed_scale, s32 swap_interval) {
|
||||
if (swap_interval <= 0) {
|
||||
// As an extension, treat nonpositive swap interval as speed multiplier.
|
||||
if (out_speed_scale) {
|
||||
*out_speed_scale = 2.f * static_cast<f32>(1 - swap_interval);
|
||||
}
|
||||
|
||||
swap_interval = 1;
|
||||
}
|
||||
|
||||
if (swap_interval >= 5) {
|
||||
// As an extension, treat high swap interval as precise speed control.
|
||||
if (out_speed_scale) {
|
||||
*out_speed_scale = static_cast<f32>(swap_interval) / 100.f;
|
||||
}
|
||||
|
||||
swap_interval = 1;
|
||||
}
|
||||
|
||||
return swap_interval;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
HardwareComposer::HardwareComposer() = default;
|
||||
HardwareComposer::~HardwareComposer() = default;
|
||||
|
||||
u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, VI::Display& display,
|
||||
Nvidia::Devices::nvdisp_disp0& nvdisp, u32 frame_advance) {
|
||||
boost::container::small_vector<HwcLayer, 2> composition_stack;
|
||||
|
||||
m_frame_number += frame_advance;
|
||||
|
||||
// Release any necessary framebuffers.
|
||||
for (auto& [layer_id, framebuffer] : m_framebuffers) {
|
||||
if (framebuffer.release_frame_number > m_frame_number) {
|
||||
// Not yet ready to release this framebuffer.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!framebuffer.is_acquired) {
|
||||
// Already released.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto* layer = display.FindLayer(layer_id); layer != nullptr) {
|
||||
// TODO: support release fence
|
||||
// This is needed to prevent screen tearing
|
||||
layer->GetConsumer().ReleaseBuffer(framebuffer.item, android::Fence::NoFence());
|
||||
framebuffer.is_acquired = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set default speed limit to 100%.
|
||||
*out_speed_scale = 1.0f;
|
||||
|
||||
// Determine the number of vsync periods to wait before composing again.
|
||||
std::optional<s32> swap_interval{};
|
||||
bool has_acquired_buffer{};
|
||||
|
||||
// Acquire all necessary framebuffers.
|
||||
for (size_t i = 0; i < display.GetNumLayers(); i++) {
|
||||
auto& layer = display.GetLayer(i);
|
||||
auto layer_id = layer.GetLayerId();
|
||||
|
||||
// Try to fetch the framebuffer (either new or stale).
|
||||
const auto result = this->CacheFramebufferLocked(layer, layer_id);
|
||||
|
||||
// If we failed, skip this layer.
|
||||
if (result == CacheStatus::NoBufferAvailable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we acquired a new buffer, we need to present.
|
||||
if (result == CacheStatus::BufferAcquired) {
|
||||
has_acquired_buffer = true;
|
||||
}
|
||||
|
||||
const auto& buffer = m_framebuffers[layer_id];
|
||||
const auto& item = buffer.item;
|
||||
const auto& igbp_buffer = *item.graphic_buffer;
|
||||
|
||||
// TODO: get proper Z-index from layer
|
||||
composition_stack.emplace_back(HwcLayer{
|
||||
.buffer_handle = igbp_buffer.BufferId(),
|
||||
.offset = igbp_buffer.Offset(),
|
||||
.format = igbp_buffer.ExternalFormat(),
|
||||
.width = igbp_buffer.Width(),
|
||||
.height = igbp_buffer.Height(),
|
||||
.stride = igbp_buffer.Stride(),
|
||||
.z_index = 0,
|
||||
.transform = static_cast<android::BufferTransformFlags>(item.transform),
|
||||
.crop_rect = item.crop,
|
||||
.acquire_fence = item.fence,
|
||||
});
|
||||
|
||||
// We need to compose again either before this frame is supposed to
|
||||
// be released, or exactly on the vsync period it should be released.
|
||||
const s32 item_swap_interval = NormalizeSwapInterval(out_speed_scale, item.swap_interval);
|
||||
|
||||
// TODO: handle cases where swap intervals are relatively prime. So far,
|
||||
// only swap intervals of 0, 1 and 2 have been observed, but if 3 were
|
||||
// to be introduced, this would cause an issue.
|
||||
if (swap_interval) {
|
||||
swap_interval = std::min(*swap_interval, item_swap_interval);
|
||||
} else {
|
||||
swap_interval = item_swap_interval;
|
||||
}
|
||||
}
|
||||
|
||||
// If any new buffers were acquired, we can present.
|
||||
if (has_acquired_buffer) {
|
||||
// Sort by Z-index.
|
||||
std::stable_sort(composition_stack.begin(), composition_stack.end(),
|
||||
[&](auto& l, auto& r) { return l.z_index < r.z_index; });
|
||||
|
||||
// Composite.
|
||||
nvdisp.Composite(composition_stack);
|
||||
}
|
||||
|
||||
// Render MicroProfile.
|
||||
MicroProfileFlip();
|
||||
|
||||
// Advance by at least one frame.
|
||||
return swap_interval.value_or(1);
|
||||
}
|
||||
|
||||
void HardwareComposer::RemoveLayerLocked(VI::Display& display, LayerId layer_id) {
|
||||
// Check if we are tracking a slot with this layer_id.
|
||||
const auto it = m_framebuffers.find(layer_id);
|
||||
if (it == m_framebuffers.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to release the buffer item.
|
||||
auto* const layer = display.FindLayer(layer_id);
|
||||
if (layer && it->second.is_acquired) {
|
||||
layer->GetConsumer().ReleaseBuffer(it->second.item, android::Fence::NoFence());
|
||||
}
|
||||
|
||||
// Erase the slot.
|
||||
m_framebuffers.erase(it);
|
||||
}
|
||||
|
||||
bool HardwareComposer::TryAcquireFramebufferLocked(VI::Layer& layer, Framebuffer& framebuffer) {
|
||||
// Attempt the update.
|
||||
const auto status = layer.GetConsumer().AcquireBuffer(&framebuffer.item, {}, false);
|
||||
if (status != android::Status::NoError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We succeeded, so set the new release frame info.
|
||||
framebuffer.release_frame_number =
|
||||
NormalizeSwapInterval(nullptr, framebuffer.item.swap_interval);
|
||||
framebuffer.is_acquired = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
HardwareComposer::CacheStatus HardwareComposer::CacheFramebufferLocked(VI::Layer& layer,
|
||||
LayerId layer_id) {
|
||||
// Check if this framebuffer is already present.
|
||||
const auto it = m_framebuffers.find(layer_id);
|
||||
if (it != m_framebuffers.end()) {
|
||||
// If it's currently still acquired, we are done.
|
||||
if (it->second.is_acquired) {
|
||||
return CacheStatus::CachedBufferReused;
|
||||
}
|
||||
|
||||
// Try to acquire a new item.
|
||||
if (this->TryAcquireFramebufferLocked(layer, it->second)) {
|
||||
// We got a new item.
|
||||
return CacheStatus::BufferAcquired;
|
||||
} else {
|
||||
// We didn't acquire a new item, but we can reuse the slot.
|
||||
return CacheStatus::CachedBufferReused;
|
||||
}
|
||||
}
|
||||
|
||||
// Framebuffer is not present, so try to create it.
|
||||
Framebuffer framebuffer{};
|
||||
|
||||
if (this->TryAcquireFramebufferLocked(layer, framebuffer)) {
|
||||
// Move the buffer item into a new slot.
|
||||
m_framebuffers.emplace(layer_id, std::move(framebuffer));
|
||||
|
||||
// We succeeded.
|
||||
return CacheStatus::BufferAcquired;
|
||||
}
|
||||
|
||||
// We couldn't acquire the buffer item, so don't create a slot.
|
||||
return CacheStatus::NoBufferAvailable;
|
||||
}
|
||||
|
||||
} // namespace Service::Nvnflinger
|
59
src/core/hle/service/nvnflinger/hardware_composer.h
Normal file
59
src/core/hle/service/nvnflinger/hardware_composer.h
Normal file
@ -0,0 +1,59 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
|
||||
#include "core/hle/service/nvnflinger/buffer_item.h"
|
||||
|
||||
namespace Service::Nvidia::Devices {
|
||||
class nvdisp_disp0;
|
||||
}
|
||||
|
||||
namespace Service::VI {
|
||||
class Display;
|
||||
class Layer;
|
||||
} // namespace Service::VI
|
||||
|
||||
namespace Service::Nvnflinger {
|
||||
|
||||
using LayerId = u64;
|
||||
|
||||
class HardwareComposer {
|
||||
public:
|
||||
explicit HardwareComposer();
|
||||
~HardwareComposer();
|
||||
|
||||
u32 ComposeLocked(f32* out_speed_scale, VI::Display& display,
|
||||
Nvidia::Devices::nvdisp_disp0& nvdisp, u32 frame_advance);
|
||||
void RemoveLayerLocked(VI::Display& display, LayerId layer_id);
|
||||
|
||||
private:
|
||||
// TODO: do we want to track frame number in vi instead?
|
||||
u64 m_frame_number{0};
|
||||
|
||||
private:
|
||||
using ReleaseFrameNumber = u64;
|
||||
|
||||
struct Framebuffer {
|
||||
android::BufferItem item{};
|
||||
ReleaseFrameNumber release_frame_number{};
|
||||
bool is_acquired{false};
|
||||
};
|
||||
|
||||
enum class CacheStatus : u32 {
|
||||
NoBufferAvailable,
|
||||
BufferAcquired,
|
||||
CachedBufferReused,
|
||||
};
|
||||
|
||||
boost::container::flat_map<LayerId, Framebuffer> m_framebuffers{};
|
||||
|
||||
private:
|
||||
bool TryAcquireFramebufferLocked(VI::Layer& layer, Framebuffer& framebuffer);
|
||||
CacheStatus CacheFramebufferLocked(VI::Layer& layer, LayerId layer_id);
|
||||
};
|
||||
|
||||
} // namespace Service::Nvnflinger
|
27
src/core/hle/service/nvnflinger/hwc_layer.h
Normal file
27
src/core/hle/service/nvnflinger/hwc_layer.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "core/hle/service/nvdrv/nvdata.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_transform_flags.h"
|
||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||
#include "core/hle/service/nvnflinger/ui/fence.h"
|
||||
|
||||
namespace Service::Nvnflinger {
|
||||
|
||||
struct HwcLayer {
|
||||
u32 buffer_handle;
|
||||
u32 offset;
|
||||
android::PixelFormat format;
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 stride;
|
||||
s32 z_index;
|
||||
android::BufferTransformFlags transform;
|
||||
Common::Rectangle<int> crop_rect;
|
||||
android::Fence acquire_fence;
|
||||
};
|
||||
|
||||
} // namespace Service::Nvnflinger
|
@ -18,6 +18,7 @@
|
||||
#include "core/hle/service/nvnflinger/buffer_item_consumer.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_queue_core.h"
|
||||
#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
|
||||
#include "core/hle/service/nvnflinger/hardware_composer.h"
|
||||
#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
|
||||
#include "core/hle/service/nvnflinger/nvnflinger.h"
|
||||
#include "core/hle/service/nvnflinger/ui/graphic_buffer.h"
|
||||
@ -279,45 +280,19 @@ void Nvnflinger::Compose() {
|
||||
SCOPE_EXIT({ display.SignalVSyncEvent(); });
|
||||
|
||||
// Don't do anything for displays without layers.
|
||||
if (!display.HasLayers())
|
||||
continue;
|
||||
|
||||
// TODO(Subv): Support more than 1 layer.
|
||||
VI::Layer& layer = display.GetLayer(0);
|
||||
|
||||
android::BufferItem buffer{};
|
||||
const auto status = layer.GetConsumer().AcquireBuffer(&buffer, {}, false);
|
||||
|
||||
if (status != android::Status::NoError) {
|
||||
if (!display.HasLayers()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& igbp_buffer = *buffer.graphic_buffer;
|
||||
|
||||
if (!system.IsPoweredOn()) {
|
||||
return; // We are likely shutting down
|
||||
}
|
||||
|
||||
// Now send the buffer to the GPU for drawing.
|
||||
// TODO(Subv): Support more than just disp0. The display device selection is probably based
|
||||
// on which display we're drawing (Default, Internal, External, etc)
|
||||
auto nvdisp = nvdrv->GetDevice<Nvidia::Devices::nvdisp_disp0>(disp_fd);
|
||||
ASSERT(nvdisp);
|
||||
|
||||
Common::Rectangle<int> crop_rect{
|
||||
static_cast<int>(buffer.crop.Left()), static_cast<int>(buffer.crop.Top()),
|
||||
static_cast<int>(buffer.crop.Right()), static_cast<int>(buffer.crop.Bottom())};
|
||||
|
||||
nvdisp->flip(igbp_buffer.BufferId(), igbp_buffer.Offset(), igbp_buffer.ExternalFormat(),
|
||||
igbp_buffer.Width(), igbp_buffer.Height(), igbp_buffer.Stride(),
|
||||
static_cast<android::BufferTransformFlags>(buffer.transform), crop_rect,
|
||||
buffer.fence.fences, buffer.fence.num_fences);
|
||||
|
||||
MicroProfileFlip();
|
||||
|
||||
swap_interval = buffer.swap_interval;
|
||||
|
||||
layer.GetConsumer().ReleaseBuffer(buffer, android::Fence::NoFence());
|
||||
swap_interval = display.GetComposer().ComposeLocked(&compose_speed_scale, display, *nvdisp,
|
||||
swap_interval);
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,15 +309,16 @@ s64 Nvnflinger::GetNextTicks() const {
|
||||
speed_scale = 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust by speed limit determined during composition.
|
||||
speed_scale /= compose_speed_scale;
|
||||
|
||||
if (system.GetNVDECActive() && settings.use_video_framerate.GetValue()) {
|
||||
// Run at intended presentation rate during video playback.
|
||||
speed_scale = 1.f;
|
||||
}
|
||||
|
||||
// As an extension, treat nonpositive swap interval as framerate multiplier.
|
||||
const f32 effective_fps = swap_interval <= 0 ? 120.f * static_cast<f32>(1 - swap_interval)
|
||||
: 60.f / static_cast<f32>(swap_interval);
|
||||
|
||||
const f32 effective_fps = 60.f / static_cast<f32>(swap_interval);
|
||||
return static_cast<s64>(speed_scale * (1000000000.f / effective_fps));
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ class BufferQueueProducer;
|
||||
namespace Service::Nvnflinger {
|
||||
|
||||
class FbShareBufferManager;
|
||||
class HardwareComposer;
|
||||
class HosBinderDriverServer;
|
||||
|
||||
class Nvnflinger final {
|
||||
@ -143,6 +144,7 @@ private:
|
||||
u32 next_buffer_queue_id = 1;
|
||||
|
||||
s32 swap_interval = 1;
|
||||
f32 compose_speed_scale = 1.0f;
|
||||
|
||||
bool is_abandoned = false;
|
||||
|
||||
|
@ -22,7 +22,7 @@ LocalSystemClockContextWriter::LocalSystemClockContextWriter(Core::System& syste
|
||||
SharedMemory& shared_memory)
|
||||
: m_system{system}, m_shared_memory{shared_memory} {}
|
||||
|
||||
Result LocalSystemClockContextWriter::Write(SystemClockContext& context) {
|
||||
Result LocalSystemClockContextWriter::Write(const SystemClockContext& context) {
|
||||
if (m_in_use) {
|
||||
R_SUCCEED_IF(context == m_context);
|
||||
m_context = context;
|
||||
@ -43,7 +43,7 @@ NetworkSystemClockContextWriter::NetworkSystemClockContextWriter(Core::System& s
|
||||
SystemClockCore& system_clock)
|
||||
: m_system{system}, m_shared_memory{shared_memory}, m_system_clock{system_clock} {}
|
||||
|
||||
Result NetworkSystemClockContextWriter::Write(SystemClockContext& context) {
|
||||
Result NetworkSystemClockContextWriter::Write(const SystemClockContext& context) {
|
||||
s64 time{};
|
||||
[[maybe_unused]] auto res = m_system_clock.GetCurrentTime(&time);
|
||||
|
||||
@ -66,7 +66,7 @@ EphemeralNetworkSystemClockContextWriter::EphemeralNetworkSystemClockContextWrit
|
||||
Core::System& system)
|
||||
: m_system{system} {}
|
||||
|
||||
Result EphemeralNetworkSystemClockContextWriter::Write(SystemClockContext& context) {
|
||||
Result EphemeralNetworkSystemClockContextWriter::Write(const SystemClockContext& context) {
|
||||
if (m_in_use) {
|
||||
R_SUCCEED_IF(context == m_context);
|
||||
m_context = context;
|
||||
|
@ -24,7 +24,7 @@ private:
|
||||
public:
|
||||
virtual ~ContextWriter() = default;
|
||||
|
||||
virtual Result Write(SystemClockContext& context) = 0;
|
||||
virtual Result Write(const SystemClockContext& context) = 0;
|
||||
void SignalAllNodes();
|
||||
void Link(OperationEvent& operation_event);
|
||||
|
||||
@ -37,7 +37,7 @@ class LocalSystemClockContextWriter : public ContextWriter {
|
||||
public:
|
||||
explicit LocalSystemClockContextWriter(Core::System& system, SharedMemory& shared_memory);
|
||||
|
||||
Result Write(SystemClockContext& context) override;
|
||||
Result Write(const SystemClockContext& context) override;
|
||||
|
||||
private:
|
||||
Core::System& m_system;
|
||||
@ -52,7 +52,7 @@ public:
|
||||
explicit NetworkSystemClockContextWriter(Core::System& system, SharedMemory& shared_memory,
|
||||
SystemClockCore& system_clock);
|
||||
|
||||
Result Write(SystemClockContext& context) override;
|
||||
Result Write(const SystemClockContext& context) override;
|
||||
|
||||
private:
|
||||
Core::System& m_system;
|
||||
@ -67,7 +67,7 @@ class EphemeralNetworkSystemClockContextWriter : public ContextWriter {
|
||||
public:
|
||||
EphemeralNetworkSystemClockContextWriter(Core::System& system);
|
||||
|
||||
Result Write(SystemClockContext& context) override;
|
||||
Result Write(const SystemClockContext& context) override;
|
||||
|
||||
private:
|
||||
Core::System& m_system;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Service::PSC::Time {
|
||||
|
||||
void StandardLocalSystemClockCore::Initialize(SystemClockContext& context, s64 time) {
|
||||
void StandardLocalSystemClockCore::Initialize(const SystemClockContext& context, s64 time) {
|
||||
SteadyClockTimePoint time_point{};
|
||||
if (GetCurrentTimePoint(time_point) == ResultSuccess &&
|
||||
context.steady_time_point.IdMatches(time_point)) {
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
: SystemClockCore{steady_clock} {}
|
||||
~StandardLocalSystemClockCore() override = default;
|
||||
|
||||
void Initialize(SystemClockContext& context, s64 time);
|
||||
void Initialize(const SystemClockContext& context, s64 time);
|
||||
};
|
||||
|
||||
} // namespace Service::PSC::Time
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Service::PSC::Time {
|
||||
|
||||
void StandardNetworkSystemClockCore::Initialize(SystemClockContext& context, s64 accuracy) {
|
||||
void StandardNetworkSystemClockCore::Initialize(const SystemClockContext& context, s64 accuracy) {
|
||||
if (SetContextAndWrite(context) != ResultSuccess) {
|
||||
LOG_ERROR(Service_Time, "Failed to SetContext");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
: SystemClockCore{steady_clock} {}
|
||||
~StandardNetworkSystemClockCore() override = default;
|
||||
|
||||
void Initialize(SystemClockContext& context, s64 accuracy);
|
||||
void Initialize(const SystemClockContext& context, s64 accuracy);
|
||||
bool IsAccuracySufficient();
|
||||
|
||||
private:
|
||||
|
@ -46,7 +46,7 @@ Result StandardUserSystemClockCore::GetContext(SystemClockContext& out_context)
|
||||
R_RETURN(m_local_system_clock.GetContext(out_context));
|
||||
}
|
||||
|
||||
Result StandardUserSystemClockCore::SetContext(SystemClockContext& context) {
|
||||
Result StandardUserSystemClockCore::SetContext(const SystemClockContext& context) {
|
||||
R_RETURN(ResultNotImplemented);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
Result SetAutomaticCorrection(bool automatic_correction);
|
||||
|
||||
Result GetContext(SystemClockContext& out_context) const override;
|
||||
Result SetContext(SystemClockContext& context) override;
|
||||
Result SetContext(const SystemClockContext& context) override;
|
||||
|
||||
Result GetTimePoint(SteadyClockTimePoint& out_time_point);
|
||||
void SetTimePointAndSignal(SteadyClockTimePoint& time_point);
|
||||
|
@ -51,12 +51,12 @@ Result SystemClockCore::GetContext(SystemClockContext& out_context) const {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SystemClockCore::SetContext(SystemClockContext& context) {
|
||||
Result SystemClockCore::SetContext(const SystemClockContext& context) {
|
||||
m_context = context;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SystemClockCore::SetContextAndWrite(SystemClockContext& context) {
|
||||
Result SystemClockCore::SetContextAndWrite(const SystemClockContext& context) {
|
||||
R_TRY(SetContext(context));
|
||||
|
||||
if (m_context_writer) {
|
||||
|
@ -41,8 +41,8 @@ public:
|
||||
}
|
||||
|
||||
virtual Result GetContext(SystemClockContext& out_context) const;
|
||||
virtual Result SetContext(SystemClockContext& context);
|
||||
Result SetContextAndWrite(SystemClockContext& context);
|
||||
virtual Result SetContext(const SystemClockContext& context);
|
||||
Result SetContextAndWrite(const SystemClockContext& context);
|
||||
|
||||
void LinkOperationEvent(OperationEvent& operation_event);
|
||||
|
||||
|
@ -78,8 +78,9 @@ Result ServiceManager::GetStaticServiceAsServiceManager(OutInterface<StaticServi
|
||||
}
|
||||
|
||||
Result ServiceManager::SetupStandardSteadyClockCore(bool is_rtc_reset_detected,
|
||||
Common::UUID& clock_source_id, s64 rtc_offset,
|
||||
s64 internal_offset, s64 test_offset) {
|
||||
const Common::UUID& clock_source_id,
|
||||
s64 rtc_offset, s64 internal_offset,
|
||||
s64 test_offset) {
|
||||
LOG_DEBUG(Service_Time,
|
||||
"called. is_rtc_reset_detected={} clock_source_id={} rtc_offset={} "
|
||||
"internal_offset={} test_offset={}",
|
||||
@ -102,7 +103,8 @@ Result ServiceManager::SetupStandardSteadyClockCore(bool is_rtc_reset_detected,
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ServiceManager::SetupStandardLocalSystemClockCore(SystemClockContext& context, s64 time) {
|
||||
Result ServiceManager::SetupStandardLocalSystemClockCore(const SystemClockContext& context,
|
||||
s64 time) {
|
||||
LOG_DEBUG(Service_Time,
|
||||
"called. context={} context.steady_time_point.clock_source_id={} time={}", context,
|
||||
context.steady_time_point.clock_source_id.RawString(), time);
|
||||
@ -114,7 +116,7 @@ Result ServiceManager::SetupStandardLocalSystemClockCore(SystemClockContext& con
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ServiceManager::SetupStandardNetworkSystemClockCore(SystemClockContext& context,
|
||||
Result ServiceManager::SetupStandardNetworkSystemClockCore(SystemClockContext context,
|
||||
s64 accuracy) {
|
||||
LOG_DEBUG(Service_Time, "called. context={} steady_time_point.clock_source_id={} accuracy={}",
|
||||
context, context.steady_time_point.clock_source_id.RawString(), accuracy);
|
||||
@ -131,7 +133,7 @@ Result ServiceManager::SetupStandardNetworkSystemClockCore(SystemClockContext& c
|
||||
}
|
||||
|
||||
Result ServiceManager::SetupStandardUserSystemClockCore(bool automatic_correction,
|
||||
SteadyClockTimePoint& time_point) {
|
||||
SteadyClockTimePoint time_point) {
|
||||
LOG_DEBUG(Service_Time, "called. automatic_correction={} time_point={} clock_source_id={}",
|
||||
automatic_correction, time_point, time_point.clock_source_id.RawString());
|
||||
|
||||
@ -144,9 +146,9 @@ Result ServiceManager::SetupStandardUserSystemClockCore(bool automatic_correctio
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ServiceManager::SetupTimeZoneServiceCore(LocationName& name, RuleVersion& rule_version,
|
||||
u32 location_count,
|
||||
SteadyClockTimePoint& time_point,
|
||||
Result ServiceManager::SetupTimeZoneServiceCore(const LocationName& name,
|
||||
const RuleVersion& rule_version, u32 location_count,
|
||||
const SteadyClockTimePoint& time_point,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> rule_buffer) {
|
||||
LOG_DEBUG(Service_Time,
|
||||
"called. name={} rule_version={} location_count={} time_point={} "
|
||||
|
@ -34,14 +34,15 @@ public:
|
||||
Result GetStaticServiceAsAdmin(OutInterface<StaticService> out_service);
|
||||
Result GetStaticServiceAsRepair(OutInterface<StaticService> out_service);
|
||||
Result GetStaticServiceAsServiceManager(OutInterface<StaticService> out_service);
|
||||
Result SetupStandardSteadyClockCore(bool is_rtc_reset_detected, Common::UUID& clock_source_id,
|
||||
s64 rtc_offset, s64 internal_offset, s64 test_offset);
|
||||
Result SetupStandardLocalSystemClockCore(SystemClockContext& context, s64 time);
|
||||
Result SetupStandardNetworkSystemClockCore(SystemClockContext& context, s64 accuracy);
|
||||
Result SetupStandardSteadyClockCore(bool is_rtc_reset_detected,
|
||||
const Common::UUID& clock_source_id, s64 rtc_offset,
|
||||
s64 internal_offset, s64 test_offset);
|
||||
Result SetupStandardLocalSystemClockCore(const SystemClockContext& context, s64 time);
|
||||
Result SetupStandardNetworkSystemClockCore(SystemClockContext context, s64 accuracy);
|
||||
Result SetupStandardUserSystemClockCore(bool automatic_correction,
|
||||
SteadyClockTimePoint& time_point);
|
||||
Result SetupTimeZoneServiceCore(LocationName& name, RuleVersion& rule_version,
|
||||
u32 location_count, SteadyClockTimePoint& time_point,
|
||||
SteadyClockTimePoint time_point);
|
||||
Result SetupTimeZoneServiceCore(const LocationName& name, const RuleVersion& rule_version,
|
||||
u32 location_count, const SteadyClockTimePoint& time_point,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> rule_buffer);
|
||||
Result SetupEphemeralNetworkSystemClockCore();
|
||||
Result GetStandardLocalClockOperationEvent(OutCopyHandle<Kernel::KReadableEvent> out_event);
|
||||
|
@ -51,11 +51,11 @@ SharedMemory::SharedMemory(Core::System& system)
|
||||
std::memset(m_shared_memory_ptr, 0, sizeof(*m_shared_memory_ptr));
|
||||
}
|
||||
|
||||
void SharedMemory::SetLocalSystemContext(SystemClockContext& context) {
|
||||
void SharedMemory::SetLocalSystemContext(const SystemClockContext& context) {
|
||||
WriteToLockFreeAtomicType(&m_shared_memory_ptr->local_system_clock_contexts, context);
|
||||
}
|
||||
|
||||
void SharedMemory::SetNetworkSystemContext(SystemClockContext& context) {
|
||||
void SharedMemory::SetNetworkSystemContext(const SystemClockContext& context) {
|
||||
WriteToLockFreeAtomicType(&m_shared_memory_ptr->network_system_clock_contexts, context);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ void SharedMemory::SetSteadyClockTimePoint(ClockSourceId clock_source_id, s64 ti
|
||||
{time_point, clock_source_id});
|
||||
}
|
||||
|
||||
void SharedMemory::SetContinuousAdjustment(ContinuousAdjustmentTimePoint& time_point) {
|
||||
void SharedMemory::SetContinuousAdjustment(const ContinuousAdjustmentTimePoint& time_point) {
|
||||
WriteToLockFreeAtomicType(&m_shared_memory_ptr->continuous_adjustment_time_points, time_point);
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,10 @@ public:
|
||||
return m_k_shared_memory;
|
||||
}
|
||||
|
||||
void SetLocalSystemContext(SystemClockContext& context);
|
||||
void SetNetworkSystemContext(SystemClockContext& context);
|
||||
void SetLocalSystemContext(const SystemClockContext& context);
|
||||
void SetNetworkSystemContext(const SystemClockContext& context);
|
||||
void SetSteadyClockTimePoint(ClockSourceId clock_source_id, s64 time_diff);
|
||||
void SetContinuousAdjustment(ContinuousAdjustmentTimePoint& time_point);
|
||||
void SetContinuousAdjustment(const ContinuousAdjustmentTimePoint& time_point);
|
||||
void SetAutomaticCorrection(bool automatic_correction);
|
||||
void UpdateBaseTime(s64 time);
|
||||
|
||||
|
@ -198,8 +198,8 @@ Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(Out<s64> out_time,
|
||||
SystemClockContext& context) {
|
||||
Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(
|
||||
Out<s64> out_time, const SystemClockContext& context) {
|
||||
SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time); });
|
||||
|
||||
R_UNLESS(m_time->m_standard_steady_clock.IsInitialized(), ResultClockUninitialized);
|
||||
@ -231,10 +231,9 @@ Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot, TimeType t
|
||||
R_RETURN(GetClockSnapshotImpl(out_snapshot, user_context, network_context, type));
|
||||
}
|
||||
|
||||
Result StaticService::GetClockSnapshotFromSystemClockContext(TimeType type,
|
||||
OutClockSnapshot out_snapshot,
|
||||
SystemClockContext& user_context,
|
||||
SystemClockContext& network_context) {
|
||||
Result StaticService::GetClockSnapshotFromSystemClockContext(
|
||||
TimeType type, OutClockSnapshot out_snapshot, const SystemClockContext& user_context,
|
||||
const SystemClockContext& network_context) {
|
||||
SCOPE_EXIT({
|
||||
LOG_DEBUG(Service_Time,
|
||||
"called. type={} user_context={} network_context={} out_snapshot={}", type,
|
||||
@ -294,8 +293,9 @@ Result StaticService::CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a,
|
||||
}
|
||||
|
||||
Result StaticService::GetClockSnapshotImpl(OutClockSnapshot out_snapshot,
|
||||
SystemClockContext& user_context,
|
||||
SystemClockContext& network_context, TimeType type) {
|
||||
const SystemClockContext& user_context,
|
||||
const SystemClockContext& network_context,
|
||||
TimeType type) {
|
||||
out_snapshot->user_context = user_context;
|
||||
out_snapshot->network_context = network_context;
|
||||
|
||||
|
@ -55,18 +55,19 @@ public:
|
||||
Result GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
Out<SteadyClockTimePoint> out_time_point);
|
||||
Result CalculateMonotonicSystemClockBaseTimePoint(Out<s64> out_time,
|
||||
SystemClockContext& context);
|
||||
const SystemClockContext& context);
|
||||
Result GetClockSnapshot(OutClockSnapshot out_snapshot, TimeType type);
|
||||
Result GetClockSnapshotFromSystemClockContext(TimeType type, OutClockSnapshot out_snapshot,
|
||||
SystemClockContext& user_context,
|
||||
SystemClockContext& network_context);
|
||||
const SystemClockContext& user_context,
|
||||
const SystemClockContext& network_context);
|
||||
Result CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_difference,
|
||||
InClockSnapshot a, InClockSnapshot b);
|
||||
Result CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a, InClockSnapshot b);
|
||||
|
||||
private:
|
||||
Result GetClockSnapshotImpl(OutClockSnapshot out_snapshot, SystemClockContext& user_context,
|
||||
SystemClockContext& network_context, TimeType type);
|
||||
Result GetClockSnapshotImpl(OutClockSnapshot out_snapshot,
|
||||
const SystemClockContext& user_context,
|
||||
const SystemClockContext& network_context, TimeType type);
|
||||
|
||||
Core::System& m_system;
|
||||
StaticServiceSetupInfo m_setup_info;
|
||||
|
@ -53,7 +53,7 @@ Result SystemClock::GetSystemClockContext(Out<SystemClockContext> out_context) {
|
||||
R_RETURN(m_clock_core.GetContext(*out_context));
|
||||
}
|
||||
|
||||
Result SystemClock::SetSystemClockContext(SystemClockContext& context) {
|
||||
Result SystemClock::SetSystemClockContext(const SystemClockContext& context) {
|
||||
LOG_DEBUG(Service_Time, "called. context={}", context);
|
||||
|
||||
R_UNLESS(m_can_write_clock, ResultPermissionDenied);
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
Result GetCurrentTime(Out<s64> out_time);
|
||||
Result SetCurrentTime(s64 time);
|
||||
Result GetSystemClockContext(Out<SystemClockContext> out_context);
|
||||
Result SetSystemClockContext(SystemClockContext& context);
|
||||
Result SetSystemClockContext(const SystemClockContext& context);
|
||||
Result GetOperationEventReadableHandle(OutCopyHandle<Kernel::KReadableEvent> out_event);
|
||||
|
||||
private:
|
||||
|
@ -55,7 +55,7 @@ constexpr bool GetTimeZoneTime(s64& out_time, const Tz::Rule& rule, s64 time, s3
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void TimeZone::SetTimePoint(SteadyClockTimePoint& time_point) {
|
||||
void TimeZone::SetTimePoint(const SteadyClockTimePoint& time_point) {
|
||||
std::scoped_lock l{m_mutex};
|
||||
m_steady_clock_time_point = time_point;
|
||||
}
|
||||
@ -65,7 +65,7 @@ void TimeZone::SetTotalLocationNameCount(u32 count) {
|
||||
m_total_location_name_count = count;
|
||||
}
|
||||
|
||||
void TimeZone::SetRuleVersion(RuleVersion& rule_version) {
|
||||
void TimeZone::SetRuleVersion(const RuleVersion& rule_version) {
|
||||
std::scoped_lock l{m_mutex};
|
||||
m_rule_version = rule_version;
|
||||
}
|
||||
@ -123,7 +123,7 @@ Result TimeZone::ToCalendarTimeWithMyRule(CalendarTime& calendar_time,
|
||||
R_RETURN(ToCalendarTimeImpl(calendar_time, calendar_additional, time, m_my_rule));
|
||||
}
|
||||
|
||||
Result TimeZone::ParseBinary(LocationName& name, std::span<const u8> binary) {
|
||||
Result TimeZone::ParseBinary(const LocationName& name, std::span<const u8> binary) {
|
||||
std::scoped_lock l{m_mutex};
|
||||
|
||||
Tz::Rule tmp_rule{};
|
||||
|
@ -23,9 +23,9 @@ public:
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
void SetTimePoint(SteadyClockTimePoint& time_point);
|
||||
void SetTimePoint(const SteadyClockTimePoint& time_point);
|
||||
void SetTotalLocationNameCount(u32 count);
|
||||
void SetRuleVersion(RuleVersion& rule_version);
|
||||
void SetRuleVersion(const RuleVersion& rule_version);
|
||||
Result GetLocationName(LocationName& out_name);
|
||||
Result GetTotalLocationCount(u32& out_count);
|
||||
Result GetRuleVersion(RuleVersion& out_rule_version);
|
||||
@ -36,7 +36,7 @@ public:
|
||||
const Tz::Rule& rule);
|
||||
Result ToCalendarTimeWithMyRule(CalendarTime& calendar_time,
|
||||
CalendarAdditionalInfo& calendar_additional, s64 time);
|
||||
Result ParseBinary(LocationName& name, std::span<const u8> binary);
|
||||
Result ParseBinary(const LocationName& name, std::span<const u8> binary);
|
||||
Result ParseBinaryInto(Tz::Rule& out_rule, std::span<const u8> binary);
|
||||
Result ToPosixTime(u32& out_count, std::span<s64> out_times, size_t out_times_max_count,
|
||||
const CalendarTime& calendar, const Tz::Rule& rule);
|
||||
|
@ -42,7 +42,7 @@ Result TimeZoneService::GetDeviceLocationName(Out<LocationName> out_location_nam
|
||||
R_RETURN(m_time_zone.GetLocationName(*out_location_name));
|
||||
}
|
||||
|
||||
Result TimeZoneService::SetDeviceLocationName(LocationName& location_name) {
|
||||
Result TimeZoneService::SetDeviceLocationName(const LocationName& location_name) {
|
||||
LOG_DEBUG(Service_Time, "called. This function is not implemented!");
|
||||
|
||||
R_UNLESS(m_can_write_timezone_device_location, ResultPermissionDenied);
|
||||
@ -62,7 +62,7 @@ Result TimeZoneService::LoadLocationNameList(
|
||||
R_RETURN(ResultNotImplemented);
|
||||
}
|
||||
|
||||
Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule, LocationName& location_name) {
|
||||
Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule, const LocationName& location_name) {
|
||||
LOG_DEBUG(Service_Time, "called. This function is not implemented!");
|
||||
|
||||
R_RETURN(ResultNotImplemented);
|
||||
@ -86,7 +86,7 @@ Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime(
|
||||
}
|
||||
|
||||
Result TimeZoneService::SetDeviceLocationNameWithTimeZoneRule(
|
||||
LocationName& location_name, InBuffer<BufferAttr_HipcAutoSelect> binary) {
|
||||
const LocationName& location_name, InBuffer<BufferAttr_HipcAutoSelect> binary) {
|
||||
LOG_DEBUG(Service_Time, "called. location_name={}", location_name);
|
||||
|
||||
R_UNLESS(m_can_write_timezone_device_location, ResultPermissionDenied);
|
||||
|
@ -31,16 +31,16 @@ public:
|
||||
~TimeZoneService() override = default;
|
||||
|
||||
Result GetDeviceLocationName(Out<LocationName> out_location_name);
|
||||
Result SetDeviceLocationName(LocationName& location_name);
|
||||
Result SetDeviceLocationName(const LocationName& location_name);
|
||||
Result GetTotalLocationNameCount(Out<u32> out_count);
|
||||
Result LoadLocationNameList(Out<u32> out_count,
|
||||
OutArray<LocationName, BufferAttr_HipcMapAlias> out_names,
|
||||
u32 index);
|
||||
Result LoadTimeZoneRule(OutRule out_rule, LocationName& location_name);
|
||||
Result LoadTimeZoneRule(OutRule out_rule, const LocationName& location_name);
|
||||
Result GetTimeZoneRuleVersion(Out<RuleVersion> out_rule_version);
|
||||
Result GetDeviceLocationNameAndUpdatedTime(Out<LocationName> location_name,
|
||||
Out<SteadyClockTimePoint> out_time_point);
|
||||
Result SetDeviceLocationNameWithTimeZoneRule(LocationName& location_name,
|
||||
Result SetDeviceLocationNameWithTimeZoneRule(const LocationName& location_name,
|
||||
InBuffer<BufferAttr_HipcAutoSelect> binary);
|
||||
Result ParseTimeZoneBinary(OutRule out_rule, InBuffer<BufferAttr_HipcAutoSelect> binary);
|
||||
Result GetDeviceLocationNameOperationEventReadableHandle(
|
||||
|
@ -549,13 +549,13 @@ public:
|
||||
}
|
||||
|
||||
Result RegisterProcessHandle(ClientProcessId client_pid,
|
||||
InCopyHandle<Kernel::KProcess>& process) {
|
||||
InCopyHandle<Kernel::KProcess> process) {
|
||||
// Register the process.
|
||||
R_RETURN(m_ro->RegisterProcess(std::addressof(m_context_id), process.Get(), *client_pid));
|
||||
}
|
||||
|
||||
Result RegisterProcessModuleInfo(ClientProcessId client_pid, u64 nrr_address, u64 nrr_size,
|
||||
InCopyHandle<Kernel::KProcess>& process) {
|
||||
InCopyHandle<Kernel::KProcess> process) {
|
||||
// Validate the process.
|
||||
R_TRY(m_ro->ValidateProcess(m_context_id, *client_pid));
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "core/hle/service/nvnflinger/buffer_queue_consumer.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_queue_core.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_queue_producer.h"
|
||||
#include "core/hle/service/nvnflinger/hardware_composer.h"
|
||||
#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
|
||||
#include "core/hle/service/vi/display/vi_display.h"
|
||||
#include "core/hle/service/vi/layer/vi_layer.h"
|
||||
@ -43,6 +44,7 @@ Display::Display(u64 id, std::string name_,
|
||||
KernelHelpers::ServiceContext& service_context_, Core::System& system_)
|
||||
: display_id{id}, name{std::move(name_)}, hos_binder_driver_server{hos_binder_driver_server_},
|
||||
service_context{service_context_} {
|
||||
hardware_composer = std::make_unique<Nvnflinger::HardwareComposer>();
|
||||
vsync_event = service_context.CreateEvent(fmt::format("Display VSync Event {}", id));
|
||||
}
|
||||
|
||||
@ -81,8 +83,6 @@ void Display::SignalVSyncEvent() {
|
||||
|
||||
void Display::CreateLayer(u64 layer_id, u32 binder_id,
|
||||
Service::Nvidia::NvCore::Container& nv_core) {
|
||||
ASSERT_MSG(layers.empty(), "Only one layer is supported per display at the moment");
|
||||
|
||||
auto [core, producer, consumer] = CreateBufferQueue(service_context, nv_core.GetNvMapFile());
|
||||
|
||||
auto buffer_item_consumer = std::make_shared<android::BufferItemConsumer>(std::move(consumer));
|
||||
|
@ -11,9 +11,14 @@
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KEvent;
|
||||
}
|
||||
class KReadableEvent;
|
||||
} // namespace Kernel
|
||||
|
||||
namespace Service::android {
|
||||
class BufferQueueProducer;
|
||||
@ -24,8 +29,9 @@ class ServiceContext;
|
||||
}
|
||||
|
||||
namespace Service::Nvnflinger {
|
||||
class HardwareComposer;
|
||||
class HosBinderDriverServer;
|
||||
}
|
||||
} // namespace Service::Nvnflinger
|
||||
|
||||
namespace Service::Nvidia::NvCore {
|
||||
class Container;
|
||||
@ -118,6 +124,10 @@ public:
|
||||
///
|
||||
const Layer* FindLayer(u64 layer_id) const;
|
||||
|
||||
Nvnflinger::HardwareComposer& GetComposer() const {
|
||||
return *hardware_composer;
|
||||
}
|
||||
|
||||
private:
|
||||
u64 display_id;
|
||||
std::string name;
|
||||
@ -125,6 +135,7 @@ private:
|
||||
KernelHelpers::ServiceContext& service_context;
|
||||
|
||||
std::vector<std::unique_ptr<Layer>> layers;
|
||||
std::unique_ptr<Nvnflinger::HardwareComposer> hardware_composer;
|
||||
Kernel::KEvent* vsync_event{};
|
||||
bool is_abandoned{};
|
||||
};
|
||||
|
@ -195,8 +195,9 @@ private:
|
||||
void GetSharedBufferMemoryHandleId(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const u64 buffer_id = rp.PopRaw<u64>();
|
||||
const u64 aruid = ctx.GetPID();
|
||||
|
||||
LOG_INFO(Service_VI, "called. buffer_id={:#x}", buffer_id);
|
||||
LOG_INFO(Service_VI, "called. buffer_id={:#x}, aruid={:#x}", buffer_id, aruid);
|
||||
|
||||
struct OutputParameters {
|
||||
s32 nvmap_handle;
|
||||
@ -206,7 +207,7 @@ private:
|
||||
OutputParameters out{};
|
||||
Nvnflinger::SharedMemoryPoolLayout layout{};
|
||||
const auto result = nvnflinger.GetSystemBufferManager().GetSharedBufferMemoryHandleId(
|
||||
&out.size, &out.nvmap_handle, &layout, buffer_id, 0);
|
||||
&out.size, &out.nvmap_handle, &layout, buffer_id, aruid);
|
||||
|
||||
ctx.WriteBuffer(&layout, sizeof(layout));
|
||||
|
||||
|
@ -12,11 +12,6 @@ namespace Shader::Backend::SPIRV {
|
||||
namespace {
|
||||
class ImageOperands {
|
||||
public:
|
||||
[[maybe_unused]] static constexpr bool ImageSampleOffsetAllowed = false;
|
||||
[[maybe_unused]] static constexpr bool ImageGatherOffsetAllowed = true;
|
||||
[[maybe_unused]] static constexpr bool ImageFetchOffsetAllowed = false;
|
||||
[[maybe_unused]] static constexpr bool ImageGradientOffsetAllowed = false;
|
||||
|
||||
explicit ImageOperands(EmitContext& ctx, bool has_bias, bool has_lod, bool has_lod_clamp,
|
||||
Id lod, const IR::Value& offset) {
|
||||
if (has_bias) {
|
||||
@ -27,7 +22,7 @@ public:
|
||||
const Id lod_value{has_lod_clamp ? ctx.OpCompositeExtract(ctx.F32[1], lod, 0) : lod};
|
||||
Add(spv::ImageOperandsMask::Lod, lod_value);
|
||||
}
|
||||
AddOffset(ctx, offset, ImageSampleOffsetAllowed);
|
||||
AddOffset(ctx, offset);
|
||||
if (has_lod_clamp) {
|
||||
const Id lod_clamp{has_bias ? ctx.OpCompositeExtract(ctx.F32[1], lod, 1) : lod};
|
||||
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
|
||||
@ -60,17 +55,20 @@ public:
|
||||
Add(spv::ImageOperandsMask::ConstOffsets, offsets);
|
||||
}
|
||||
|
||||
explicit ImageOperands(Id lod, Id ms) {
|
||||
explicit ImageOperands(Id offset, Id lod, Id ms) {
|
||||
if (Sirit::ValidId(lod)) {
|
||||
Add(spv::ImageOperandsMask::Lod, lod);
|
||||
}
|
||||
if (Sirit::ValidId(offset)) {
|
||||
Add(spv::ImageOperandsMask::Offset, offset);
|
||||
}
|
||||
if (Sirit::ValidId(ms)) {
|
||||
Add(spv::ImageOperandsMask::Sample, ms);
|
||||
}
|
||||
}
|
||||
|
||||
explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives,
|
||||
u32 num_derivatives, const IR::Value& offset, Id lod_clamp) {
|
||||
u32 num_derivatives, Id offset, Id lod_clamp) {
|
||||
if (!Sirit::ValidId(derivatives)) {
|
||||
throw LogicError("Derivatives must be present");
|
||||
}
|
||||
@ -85,14 +83,16 @@ public:
|
||||
const Id derivatives_Y{ctx.OpCompositeConstruct(
|
||||
ctx.F32[num_derivatives], std::span{deriv_y_accum.data(), deriv_y_accum.size()})};
|
||||
Add(spv::ImageOperandsMask::Grad, derivatives_X, derivatives_Y);
|
||||
AddOffset(ctx, offset, ImageGradientOffsetAllowed);
|
||||
if (Sirit::ValidId(offset)) {
|
||||
Add(spv::ImageOperandsMask::Offset, offset);
|
||||
}
|
||||
if (has_lod_clamp) {
|
||||
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
|
||||
}
|
||||
}
|
||||
|
||||
explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives_1, Id derivatives_2,
|
||||
const IR::Value& offset, Id lod_clamp) {
|
||||
Id offset, Id lod_clamp) {
|
||||
if (!Sirit::ValidId(derivatives_1) || !Sirit::ValidId(derivatives_2)) {
|
||||
throw LogicError("Derivatives must be present");
|
||||
}
|
||||
@ -111,7 +111,9 @@ public:
|
||||
const Id derivatives_id2{ctx.OpCompositeConstruct(
|
||||
ctx.F32[3], std::span{deriv_2_accum.data(), deriv_2_accum.size()})};
|
||||
Add(spv::ImageOperandsMask::Grad, derivatives_id1, derivatives_id2);
|
||||
AddOffset(ctx, offset, ImageGradientOffsetAllowed);
|
||||
if (Sirit::ValidId(offset)) {
|
||||
Add(spv::ImageOperandsMask::Offset, offset);
|
||||
}
|
||||
if (has_lod_clamp) {
|
||||
Add(spv::ImageOperandsMask::MinLod, lod_clamp);
|
||||
}
|
||||
@ -130,7 +132,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void AddOffset(EmitContext& ctx, const IR::Value& offset, bool runtime_offset_allowed) {
|
||||
void AddOffset(EmitContext& ctx, const IR::Value& offset) {
|
||||
if (offset.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -163,9 +165,7 @@ private:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (runtime_offset_allowed) {
|
||||
Add(spv::ImageOperandsMask::Offset, ctx.Def(offset));
|
||||
}
|
||||
Add(spv::ImageOperandsMask::Offset, ctx.Def(offset));
|
||||
}
|
||||
|
||||
void Add(spv::ImageOperandsMask new_mask, Id value) {
|
||||
@ -311,37 +311,6 @@ Id ImageGatherSubpixelOffset(EmitContext& ctx, const IR::TextureInstInfo& info,
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
|
||||
void AddOffsetToCoordinates(EmitContext& ctx, const IR::TextureInstInfo& info, Id& coords,
|
||||
Id offset) {
|
||||
if (!Sirit::ValidId(offset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Id result_type{};
|
||||
switch (info.type) {
|
||||
case TextureType::Buffer:
|
||||
case TextureType::Color1D:
|
||||
case TextureType::ColorArray1D: {
|
||||
result_type = ctx.U32[1];
|
||||
break;
|
||||
}
|
||||
case TextureType::Color2D:
|
||||
case TextureType::Color2DRect:
|
||||
case TextureType::ColorArray2D: {
|
||||
result_type = ctx.U32[2];
|
||||
break;
|
||||
}
|
||||
case TextureType::Color3D: {
|
||||
result_type = ctx.U32[3];
|
||||
break;
|
||||
}
|
||||
case TextureType::ColorCube:
|
||||
case TextureType::ColorArrayCube:
|
||||
return;
|
||||
}
|
||||
coords = ctx.OpIAdd(result_type, coords, offset);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
Id EmitBindlessImageSampleImplicitLod(EmitContext&) {
|
||||
@ -527,7 +496,6 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
||||
Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset,
|
||||
Id lod, Id ms) {
|
||||
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
||||
AddOffsetToCoordinates(ctx, info, coords, offset);
|
||||
if (info.type == TextureType::Buffer) {
|
||||
lod = Id{};
|
||||
}
|
||||
@ -535,7 +503,7 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c
|
||||
// This image is multisampled, lod must be implicit
|
||||
lod = Id{};
|
||||
}
|
||||
const ImageOperands operands(lod, ms);
|
||||
const ImageOperands operands(offset, lod, ms);
|
||||
return Emit(&EmitContext::OpImageSparseFetch, &EmitContext::OpImageFetch, ctx, inst, ctx.F32[4],
|
||||
TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span());
|
||||
}
|
||||
@ -580,13 +548,13 @@ Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, I
|
||||
}
|
||||
|
||||
Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||
Id derivatives, const IR::Value& offset, Id lod_clamp) {
|
||||
Id derivatives, Id offset, Id lod_clamp) {
|
||||
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
||||
const auto operands = info.num_derivatives == 3
|
||||
? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives,
|
||||
ctx.Def(offset), {}, lod_clamp)
|
||||
: ImageOperands(ctx, info.has_lod_clamp != 0, derivatives,
|
||||
info.num_derivatives, offset, lod_clamp);
|
||||
const auto operands =
|
||||
info.num_derivatives == 3
|
||||
? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, offset, {}, lod_clamp)
|
||||
: ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, info.num_derivatives, offset,
|
||||
lod_clamp);
|
||||
return Emit(&EmitContext::OpImageSparseSampleExplicitLod,
|
||||
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4],
|
||||
Texture(ctx, info, index), coords, operands.Mask(), operands.Span());
|
||||
|
@ -543,7 +543,7 @@ Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& i
|
||||
const IR::Value& skip_mips);
|
||||
Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
|
||||
Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||
Id derivatives, const IR::Value& offset, Id lod_clamp);
|
||||
Id derivatives, Id offset, Id lod_clamp);
|
||||
Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords);
|
||||
void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color);
|
||||
Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index);
|
||||
|
@ -55,6 +55,7 @@ add_library(video_core STATIC
|
||||
engines/maxwell_dma.h
|
||||
engines/puller.cpp
|
||||
engines/puller.h
|
||||
framebuffer_config.cpp
|
||||
framebuffer_config.h
|
||||
fsr.cpp
|
||||
fsr.h
|
||||
@ -115,8 +116,24 @@ add_library(video_core STATIC
|
||||
renderer_null/null_rasterizer.h
|
||||
renderer_null/renderer_null.cpp
|
||||
renderer_null/renderer_null.h
|
||||
renderer_opengl/present/filters.cpp
|
||||
renderer_opengl/present/filters.h
|
||||
renderer_opengl/present/fsr.cpp
|
||||
renderer_opengl/present/fsr.h
|
||||
renderer_opengl/present/fxaa.cpp
|
||||
renderer_opengl/present/fxaa.h
|
||||
renderer_opengl/present/layer.cpp
|
||||
renderer_opengl/present/layer.h
|
||||
renderer_opengl/present/present_uniforms.h
|
||||
renderer_opengl/present/smaa.cpp
|
||||
renderer_opengl/present/smaa.h
|
||||
renderer_opengl/present/util.h
|
||||
renderer_opengl/present/window_adapt_pass.cpp
|
||||
renderer_opengl/present/window_adapt_pass.h
|
||||
renderer_opengl/blit_image.cpp
|
||||
renderer_opengl/blit_image.h
|
||||
renderer_opengl/gl_blit_screen.cpp
|
||||
renderer_opengl/gl_blit_screen.h
|
||||
renderer_opengl/gl_buffer_cache_base.cpp
|
||||
renderer_opengl/gl_buffer_cache.cpp
|
||||
renderer_opengl/gl_buffer_cache.h
|
||||
@ -126,8 +143,6 @@ add_library(video_core STATIC
|
||||
renderer_opengl/gl_device.h
|
||||
renderer_opengl/gl_fence_manager.cpp
|
||||
renderer_opengl/gl_fence_manager.h
|
||||
renderer_opengl/gl_fsr.cpp
|
||||
renderer_opengl/gl_fsr.h
|
||||
renderer_opengl/gl_graphics_pipeline.cpp
|
||||
renderer_opengl/gl_graphics_pipeline.h
|
||||
renderer_opengl/gl_rasterizer.cpp
|
||||
@ -155,6 +170,22 @@ add_library(video_core STATIC
|
||||
renderer_opengl/renderer_opengl.h
|
||||
renderer_opengl/util_shaders.cpp
|
||||
renderer_opengl/util_shaders.h
|
||||
renderer_vulkan/present/anti_alias_pass.h
|
||||
renderer_vulkan/present/filters.cpp
|
||||
renderer_vulkan/present/filters.h
|
||||
renderer_vulkan/present/fsr.cpp
|
||||
renderer_vulkan/present/fsr.h
|
||||
renderer_vulkan/present/fxaa.cpp
|
||||
renderer_vulkan/present/fxaa.h
|
||||
renderer_vulkan/present/layer.cpp
|
||||
renderer_vulkan/present/layer.h
|
||||
renderer_vulkan/present/present_push_constants.h
|
||||
renderer_vulkan/present/smaa.cpp
|
||||
renderer_vulkan/present/smaa.h
|
||||
renderer_vulkan/present/util.cpp
|
||||
renderer_vulkan/present/util.h
|
||||
renderer_vulkan/present/window_adapt_pass.cpp
|
||||
renderer_vulkan/present/window_adapt_pass.h
|
||||
renderer_vulkan/blit_image.cpp
|
||||
renderer_vulkan/blit_image.h
|
||||
renderer_vulkan/fixed_pipeline_state.cpp
|
||||
@ -181,8 +212,6 @@ add_library(video_core STATIC
|
||||
renderer_vulkan/vk_descriptor_pool.h
|
||||
renderer_vulkan/vk_fence_manager.cpp
|
||||
renderer_vulkan/vk_fence_manager.h
|
||||
renderer_vulkan/vk_fsr.cpp
|
||||
renderer_vulkan/vk_fsr.h
|
||||
renderer_vulkan/vk_graphics_pipeline.cpp
|
||||
renderer_vulkan/vk_graphics_pipeline.h
|
||||
renderer_vulkan/vk_master_semaphore.cpp
|
||||
@ -203,8 +232,6 @@ add_library(video_core STATIC
|
||||
renderer_vulkan/vk_scheduler.h
|
||||
renderer_vulkan/vk_shader_util.cpp
|
||||
renderer_vulkan/vk_shader_util.h
|
||||
renderer_vulkan/vk_smaa.cpp
|
||||
renderer_vulkan/vk_smaa.h
|
||||
renderer_vulkan/vk_staging_buffer_pool.cpp
|
||||
renderer_vulkan/vk_staging_buffer_pool.h
|
||||
renderer_vulkan/vk_state_tracker.cpp
|
||||
|
@ -1546,7 +1546,10 @@ void BufferCache<P>::ImmediateUploadMemory([[maybe_unused]] Buffer& buffer,
|
||||
std::span<const u8> upload_span;
|
||||
const DAddr device_addr = buffer.CpuAddr() + copy.dst_offset;
|
||||
if (IsRangeGranular(device_addr, copy.size)) {
|
||||
upload_span = std::span(device_memory.GetPointer<u8>(device_addr), copy.size);
|
||||
auto* const ptr = device_memory.GetPointer<u8>(device_addr);
|
||||
if (ptr != nullptr) {
|
||||
upload_span = std::span(ptr, copy.size);
|
||||
}
|
||||
} else {
|
||||
if (immediate_buffer.empty()) {
|
||||
immediate_buffer = ImmediateBuffer(largest_copy);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "video_core/engines/engine_interface.h"
|
||||
|
55
src/video_core/framebuffer_config.cpp
Normal file
55
src/video_core/framebuffer_config.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "video_core/framebuffer_config.h"
|
||||
|
||||
namespace Tegra {
|
||||
|
||||
Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width,
|
||||
u32 texture_height) {
|
||||
f32 left, top, right, bottom;
|
||||
|
||||
if (!framebuffer.crop_rect.IsEmpty()) {
|
||||
// If crop rectangle is not empty, apply properties from rectangle.
|
||||
left = static_cast<f32>(framebuffer.crop_rect.left);
|
||||
top = static_cast<f32>(framebuffer.crop_rect.top);
|
||||
right = static_cast<f32>(framebuffer.crop_rect.right);
|
||||
bottom = static_cast<f32>(framebuffer.crop_rect.bottom);
|
||||
} else {
|
||||
// Otherwise, fall back to framebuffer dimensions.
|
||||
left = 0;
|
||||
top = 0;
|
||||
right = static_cast<f32>(framebuffer.width);
|
||||
bottom = static_cast<f32>(framebuffer.height);
|
||||
}
|
||||
|
||||
// Apply transformation flags.
|
||||
auto framebuffer_transform_flags = framebuffer.transform_flags;
|
||||
|
||||
if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipH)) {
|
||||
// Switch left and right.
|
||||
std::swap(left, right);
|
||||
}
|
||||
if (True(framebuffer_transform_flags & Service::android::BufferTransformFlags::FlipV)) {
|
||||
// Switch top and bottom.
|
||||
std::swap(top, bottom);
|
||||
}
|
||||
|
||||
framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipH;
|
||||
framebuffer_transform_flags &= ~Service::android::BufferTransformFlags::FlipV;
|
||||
if (True(framebuffer_transform_flags)) {
|
||||
UNIMPLEMENTED_MSG("Unsupported framebuffer_transform_flags={}",
|
||||
static_cast<u32>(framebuffer_transform_flags));
|
||||
}
|
||||
|
||||
// Normalize coordinate space.
|
||||
left /= static_cast<f32>(texture_width);
|
||||
top /= static_cast<f32>(texture_height);
|
||||
right /= static_cast<f32>(texture_width);
|
||||
bottom /= static_cast<f32>(texture_height);
|
||||
|
||||
return Common::Rectangle<f32>(left, top, right, bottom);
|
||||
}
|
||||
|
||||
} // namespace Tegra
|
@ -7,6 +7,7 @@
|
||||
#include "common/math_util.h"
|
||||
#include "core/hle/service/nvnflinger/buffer_transform_flags.h"
|
||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||
#include "core/hle/service/nvnflinger/ui/fence.h"
|
||||
|
||||
namespace Tegra {
|
||||
|
||||
@ -21,7 +22,10 @@ struct FramebufferConfig {
|
||||
u32 stride{};
|
||||
Service::android::PixelFormat pixel_format{};
|
||||
Service::android::BufferTransformFlags transform_flags{};
|
||||
Common::Rectangle<int> crop_rect;
|
||||
Common::Rectangle<int> crop_rect{};
|
||||
};
|
||||
|
||||
Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width,
|
||||
u32 texture_height);
|
||||
|
||||
} // namespace Tegra
|
||||
|
@ -274,11 +274,6 @@ struct GPU::Impl {
|
||||
}
|
||||
}
|
||||
|
||||
/// Swap buffers (render frame)
|
||||
void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
gpu_thread.SwapBuffers(framebuffer);
|
||||
}
|
||||
|
||||
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
|
||||
void FlushRegion(DAddr addr, u64 size) {
|
||||
gpu_thread.FlushRegion(addr, size);
|
||||
@ -313,8 +308,9 @@ struct GPU::Impl {
|
||||
gpu_thread.FlushAndInvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
void RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
|
||||
std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences) {
|
||||
void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
|
||||
std::vector<Service::Nvidia::NvFence>&& fences) {
|
||||
size_t num_fences{fences.size()};
|
||||
size_t current_request_counter{};
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(request_swap_mutex);
|
||||
@ -328,13 +324,12 @@ struct GPU::Impl {
|
||||
}
|
||||
}
|
||||
const auto wait_fence =
|
||||
RequestSyncOperation([this, current_request_counter, framebuffer, fences, num_fences] {
|
||||
RequestSyncOperation([this, current_request_counter, &layers, &fences, num_fences] {
|
||||
auto& syncpoint_manager = host1x.GetSyncpointManager();
|
||||
if (num_fences == 0) {
|
||||
renderer->SwapBuffers(framebuffer);
|
||||
renderer->Composite(layers);
|
||||
}
|
||||
const auto executer = [this, current_request_counter,
|
||||
framebuffer_copy = *framebuffer]() {
|
||||
const auto executer = [this, current_request_counter, layers_copy = layers]() {
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(request_swap_mutex);
|
||||
if (--request_swap_counters[current_request_counter] != 0) {
|
||||
@ -342,7 +337,7 @@ struct GPU::Impl {
|
||||
}
|
||||
free_swap_counters.push_back(current_request_counter);
|
||||
}
|
||||
renderer->SwapBuffers(&framebuffer_copy);
|
||||
renderer->Composite(layers_copy);
|
||||
};
|
||||
for (size_t i = 0; i < num_fences; i++) {
|
||||
syncpoint_manager.RegisterGuestAction(fences[i].id, fences[i].value, executer);
|
||||
@ -505,9 +500,9 @@ const VideoCore::ShaderNotify& GPU::ShaderNotify() const {
|
||||
return impl->ShaderNotify();
|
||||
}
|
||||
|
||||
void GPU::RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
|
||||
std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences) {
|
||||
impl->RequestSwapBuffers(framebuffer, fences, num_fences);
|
||||
void GPU::RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
|
||||
std::vector<Service::Nvidia::NvFence>&& fences) {
|
||||
impl->RequestComposite(std::move(layers), std::move(fences));
|
||||
}
|
||||
|
||||
u64 GPU::GetTicks() const {
|
||||
@ -554,10 +549,6 @@ void GPU::ClearCdmaInstance(u32 id) {
|
||||
impl->ClearCdmaInstance(id);
|
||||
}
|
||||
|
||||
void GPU::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
impl->SwapBuffers(framebuffer);
|
||||
}
|
||||
|
||||
VideoCore::RasterizerDownloadArea GPU::OnCPURead(PAddr addr, u64 size) {
|
||||
return impl->OnCPURead(addr, size);
|
||||
}
|
||||
|
@ -212,8 +212,8 @@ public:
|
||||
|
||||
void RendererFrameEndNotify();
|
||||
|
||||
void RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
|
||||
std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences);
|
||||
void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
|
||||
std::vector<Service::Nvidia::NvFence>&& fences);
|
||||
|
||||
/// Performs any additional setup necessary in order to begin GPU emulation.
|
||||
/// This can be used to launch any necessary threads and register any necessary
|
||||
|
@ -40,8 +40,6 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
|
||||
}
|
||||
if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) {
|
||||
scheduler.Push(submit_list->channel, std::move(submit_list->entries));
|
||||
} else if (const auto* data = std::get_if<SwapBuffersCommand>(&next.data)) {
|
||||
renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr);
|
||||
} else if (std::holds_alternative<GPUTickCommand>(next.data)) {
|
||||
system.GPU().TickWork();
|
||||
} else if (const auto* flush = std::get_if<FlushRegionCommand>(&next.data)) {
|
||||
@ -78,10 +76,6 @@ void ThreadManager::SubmitList(s32 channel, Tegra::CommandList&& entries) {
|
||||
PushCommand(SubmitListCommand(channel, std::move(entries)));
|
||||
}
|
||||
|
||||
void ThreadManager::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
PushCommand(SwapBuffersCommand(framebuffer ? std::make_optional(*framebuffer) : std::nullopt));
|
||||
}
|
||||
|
||||
void ThreadManager::FlushRegion(DAddr addr, u64 size) {
|
||||
if (!is_async) {
|
||||
// Always flush with synchronous GPU mode
|
||||
|
@ -44,14 +44,6 @@ struct SubmitListCommand final {
|
||||
Tegra::CommandList entries;
|
||||
};
|
||||
|
||||
/// Command to signal to the GPU thread that a swap buffers is pending
|
||||
struct SwapBuffersCommand final {
|
||||
explicit SwapBuffersCommand(std::optional<const Tegra::FramebufferConfig> framebuffer_)
|
||||
: framebuffer{std::move(framebuffer_)} {}
|
||||
|
||||
std::optional<Tegra::FramebufferConfig> framebuffer;
|
||||
};
|
||||
|
||||
/// Command to signal to the GPU thread to flush a region
|
||||
struct FlushRegionCommand final {
|
||||
explicit constexpr FlushRegionCommand(DAddr addr_, u64 size_) : addr{addr_}, size{size_} {}
|
||||
@ -81,8 +73,8 @@ struct FlushAndInvalidateRegionCommand final {
|
||||
struct GPUTickCommand final {};
|
||||
|
||||
using CommandData =
|
||||
std::variant<std::monostate, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand,
|
||||
InvalidateRegionCommand, FlushAndInvalidateRegionCommand, GPUTickCommand>;
|
||||
std::variant<std::monostate, SubmitListCommand, FlushRegionCommand, InvalidateRegionCommand,
|
||||
FlushAndInvalidateRegionCommand, GPUTickCommand>;
|
||||
|
||||
struct CommandDataContainer {
|
||||
CommandDataContainer() = default;
|
||||
@ -118,9 +110,6 @@ public:
|
||||
/// Push GPU command entries to be processed
|
||||
void SubmitList(s32 channel, Tegra::CommandList&& entries);
|
||||
|
||||
/// Swap buffers (render frame)
|
||||
void SwapBuffers(const Tegra::FramebufferConfig* framebuffer);
|
||||
|
||||
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
|
||||
void FlushRegion(DAddr addr, u64 size);
|
||||
|
||||
|
@ -9,7 +9,7 @@ set(FIDELITYFX_FILES
|
||||
)
|
||||
|
||||
set(GLSL_INCLUDES
|
||||
fidelityfx_fsr.comp
|
||||
fidelityfx_fsr.frag
|
||||
${FIDELITYFX_FILES}
|
||||
)
|
||||
|
||||
@ -56,10 +56,11 @@ set(SHADER_FILES
|
||||
vulkan_color_clear.frag
|
||||
vulkan_color_clear.vert
|
||||
vulkan_depthstencil_clear.frag
|
||||
vulkan_fidelityfx_fsr_easu_fp16.comp
|
||||
vulkan_fidelityfx_fsr_easu_fp32.comp
|
||||
vulkan_fidelityfx_fsr_rcas_fp16.comp
|
||||
vulkan_fidelityfx_fsr_rcas_fp32.comp
|
||||
vulkan_fidelityfx_fsr.vert
|
||||
vulkan_fidelityfx_fsr_easu_fp16.frag
|
||||
vulkan_fidelityfx_fsr_easu_fp32.frag
|
||||
vulkan_fidelityfx_fsr_rcas_fp16.frag
|
||||
vulkan_fidelityfx_fsr_rcas_fp32.frag
|
||||
vulkan_present.frag
|
||||
vulkan_present.vert
|
||||
vulkan_present_scaleforce_fp16.frag
|
||||
|
@ -34,7 +34,6 @@ layout( push_constant ) uniform constants {
|
||||
};
|
||||
|
||||
layout(set=0,binding=0) uniform sampler2D InputTexture;
|
||||
layout(set=0,binding=1,rgba16f) uniform image2D OutputTexture;
|
||||
|
||||
#define A_GPU 1
|
||||
#define A_GLSL 1
|
||||
@ -72,44 +71,40 @@ layout(set=0,binding=1,rgba16f) uniform image2D OutputTexture;
|
||||
|
||||
#include "ffx_fsr1.h"
|
||||
|
||||
void CurrFilter(AU2 pos) {
|
||||
#if USE_BILINEAR
|
||||
AF2 pp = (AF2(pos) * AF2_AU2(Const0.xy) + AF2_AU2(Const0.zw)) * AF2_AU2(Const1.xy) + AF2(0.5, -0.5) * AF2_AU2(Const1.zw);
|
||||
imageStore(OutputTexture, ASU2(pos), textureLod(InputTexture, pp, 0.0));
|
||||
#if USE_RCAS
|
||||
layout(location = 0) in vec2 frag_texcoord;
|
||||
#endif
|
||||
layout (location = 0) out vec4 frag_color;
|
||||
|
||||
void CurrFilter(AU2 pos) {
|
||||
#if USE_EASU
|
||||
#ifndef YUZU_USE_FP16
|
||||
AF3 c;
|
||||
FsrEasuF(c, pos, Const0, Const1, Const2, Const3);
|
||||
imageStore(OutputTexture, ASU2(pos), AF4(c, 1));
|
||||
frag_color = AF4(c, 1.0);
|
||||
#else
|
||||
AH3 c;
|
||||
FsrEasuH(c, pos, Const0, Const1, Const2, Const3);
|
||||
imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
|
||||
frag_color = AH4(c, 1.0);
|
||||
#endif
|
||||
#endif
|
||||
#if USE_RCAS
|
||||
#ifndef YUZU_USE_FP16
|
||||
AF3 c;
|
||||
FsrRcasF(c.r, c.g, c.b, pos, Const0);
|
||||
imageStore(OutputTexture, ASU2(pos), AF4(c, 1));
|
||||
frag_color = AF4(c, 1.0);
|
||||
#else
|
||||
AH3 c;
|
||||
FsrRcasH(c.r, c.g, c.b, pos, Const0);
|
||||
imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
|
||||
frag_color = AH4(c, 1.0);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
layout(local_size_x=64) in;
|
||||
void main() {
|
||||
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
|
||||
AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
|
||||
CurrFilter(gxy);
|
||||
gxy.x += 8u;
|
||||
CurrFilter(gxy);
|
||||
gxy.y += 8u;
|
||||
CurrFilter(gxy);
|
||||
gxy.x -= 8u;
|
||||
CurrFilter(gxy);
|
||||
#if USE_RCAS
|
||||
CurrFilter(AU2(frag_texcoord * vec2(textureSize(InputTexture, 0))));
|
||||
#else
|
||||
CurrFilter(AU2(gl_FragCoord.xy));
|
||||
#endif
|
||||
}
|
@ -7,8 +7,8 @@ out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
const vec2 vertices[4] =
|
||||
vec2[4](vec2(-1.0, 1.0), vec2(1.0, 1.0), vec2(-1.0, -1.0), vec2(1.0, -1.0));
|
||||
const vec2 vertices[3] =
|
||||
vec2[3](vec2(-1,-1), vec2(3,-1), vec2(-1, 3));
|
||||
|
||||
layout (location = 0) out vec4 posPos;
|
||||
|
||||
|
@ -26,21 +26,11 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef VULKAN
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 1
|
||||
|
||||
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 0
|
||||
|
||||
#endif
|
||||
|
||||
layout (location = 0) in vec2 tex_coord;
|
||||
|
||||
layout (location = 0) out vec4 frag_color;
|
||||
|
||||
layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D input_texture;
|
||||
layout (binding = 0) uniform sampler2D input_texture;
|
||||
|
||||
const bool ignore_alpha = true;
|
||||
|
||||
|
@ -3,22 +3,12 @@
|
||||
|
||||
#version 460 core
|
||||
|
||||
#ifdef VULKAN
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 1
|
||||
|
||||
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 0
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
layout (location = 0) in vec2 frag_tex_coord;
|
||||
|
||||
layout (location = 0) out vec4 color;
|
||||
|
||||
layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture;
|
||||
layout (binding = 0) uniform sampler2D color_texture;
|
||||
|
||||
vec4 cubic(float v) {
|
||||
vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
|
||||
|
@ -7,21 +7,11 @@
|
||||
|
||||
#version 460 core
|
||||
|
||||
#ifdef VULKAN
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 1
|
||||
|
||||
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
|
||||
|
||||
#define BINDING_COLOR_TEXTURE 0
|
||||
|
||||
#endif
|
||||
|
||||
layout(location = 0) in vec2 frag_tex_coord;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
layout(binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture;
|
||||
layout(binding = 0) uniform sampler2D color_texture;
|
||||
|
||||
const float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
|
||||
const float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
||||
|
13
src/video_core/host_shaders/vulkan_fidelityfx_fsr.vert
Normal file
13
src/video_core/host_shaders/vulkan_fidelityfx_fsr.vert
Normal file
@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec2 texcoord;
|
||||
|
||||
void main() {
|
||||
float x = float((gl_VertexIndex & 1) << 2);
|
||||
float y = float((gl_VertexIndex & 2) << 1);
|
||||
gl_Position = vec4(x - 1.0, y - 1.0, 0.0, 1.0);
|
||||
texcoord = vec2(x, y) / 2.0;
|
||||
}
|
@ -7,4 +7,4 @@
|
||||
#define YUZU_USE_FP16
|
||||
#define USE_EASU 1
|
||||
|
||||
#include "fidelityfx_fsr.comp"
|
||||
#include "fidelityfx_fsr.frag"
|
@ -6,4 +6,4 @@
|
||||
|
||||
#define USE_EASU 1
|
||||
|
||||
#include "fidelityfx_fsr.comp"
|
||||
#include "fidelityfx_fsr.frag"
|
@ -7,4 +7,4 @@
|
||||
#define YUZU_USE_FP16
|
||||
#define USE_RCAS 1
|
||||
|
||||
#include "fidelityfx_fsr.comp"
|
||||
#include "fidelityfx_fsr.frag"
|
@ -6,4 +6,4 @@
|
||||
|
||||
#define USE_RCAS 1
|
||||
|
||||
#include "fidelityfx_fsr.comp"
|
||||
#include "fidelityfx_fsr.frag"
|
@ -7,7 +7,7 @@ layout (location = 0) in vec2 frag_tex_coord;
|
||||
|
||||
layout (location = 0) out vec4 color;
|
||||
|
||||
layout (binding = 1) uniform sampler2D color_texture;
|
||||
layout (binding = 0) uniform sampler2D color_texture;
|
||||
|
||||
void main() {
|
||||
color = texture(color_texture, frag_tex_coord);
|
||||
|
@ -3,16 +3,37 @@
|
||||
|
||||
#version 460 core
|
||||
|
||||
layout (location = 0) in vec2 vert_position;
|
||||
layout (location = 1) in vec2 vert_tex_coord;
|
||||
|
||||
layout (location = 0) out vec2 frag_tex_coord;
|
||||
|
||||
layout (set = 0, binding = 0) uniform MatrixBlock {
|
||||
mat4 modelview_matrix;
|
||||
struct ScreenRectVertex {
|
||||
vec2 position;
|
||||
vec2 tex_coord;
|
||||
};
|
||||
|
||||
void main() {
|
||||
gl_Position = modelview_matrix * vec4(vert_position, 0.0, 1.0);
|
||||
frag_tex_coord = vert_tex_coord;
|
||||
layout (push_constant) uniform PushConstants {
|
||||
mat4 modelview_matrix;
|
||||
ScreenRectVertex vertices[4];
|
||||
};
|
||||
|
||||
// Vulkan spec 15.8.1:
|
||||
// Any member of a push constant block that is declared as an
|
||||
// array must only be accessed with dynamically uniform indices.
|
||||
ScreenRectVertex GetVertex(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
default:
|
||||
return vertices[0];
|
||||
case 1:
|
||||
return vertices[1];
|
||||
case 2:
|
||||
return vertices[2];
|
||||
case 3:
|
||||
return vertices[3];
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
ScreenRectVertex vertex = GetVertex(gl_VertexIndex);
|
||||
gl_Position = modelview_matrix * vec4(vertex.position, 0.0, 1.0);
|
||||
frag_tex_coord = vertex.tex_coord;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
|
||||
#define VERSION 1
|
||||
#define YUZU_USE_FP16
|
||||
|
||||
#include "opengl_present_scaleforce.frag"
|
||||
|
@ -5,4 +5,6 @@
|
||||
|
||||
#extension GL_GOOGLE_include_directive : enable
|
||||
|
||||
#define VERSION 1
|
||||
|
||||
#include "opengl_present_scaleforce.frag"
|
||||
|
@ -155,12 +155,6 @@ public:
|
||||
virtual void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||
std::span<const u8> memory) = 0;
|
||||
|
||||
/// Attempt to use a faster method to display the framebuffer to screen
|
||||
[[nodiscard]] virtual bool AccelerateDisplay(const Tegra::FramebufferConfig& config,
|
||||
DAddr framebuffer_addr, u32 pixel_stride) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Initialize disk cached resources for the game being emulated
|
||||
virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const DiskResourceLoadCallback& callback) {}
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
virtual ~RendererBase();
|
||||
|
||||
/// Finalize rendering the guest frame and draw into the presentation texture
|
||||
virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
|
||||
virtual void Composite(std::span<const Tegra::FramebufferConfig> layers) = 0;
|
||||
|
||||
[[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0;
|
||||
|
||||
|
@ -92,10 +92,6 @@ bool RasterizerNull::AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surfac
|
||||
}
|
||||
void RasterizerNull::AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||
std::span<const u8> memory) {}
|
||||
bool RasterizerNull::AccelerateDisplay(const Tegra::FramebufferConfig& config,
|
||||
DAddr framebuffer_addr, u32 pixel_stride) {
|
||||
return true;
|
||||
}
|
||||
void RasterizerNull::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) {}
|
||||
void RasterizerNull::InitializeChannel(Tegra::Control::ChannelState& channel) {
|
||||
|
@ -77,8 +77,6 @@ public:
|
||||
Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
|
||||
void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||
std::span<const u8> memory) override;
|
||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, DAddr framebuffer_addr,
|
||||
u32 pixel_stride) override;
|
||||
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||
void InitializeChannel(Tegra::Control::ChannelState& channel) override;
|
||||
|
@ -13,8 +13,8 @@ RendererNull::RendererNull(Core::Frontend::EmuWindow& emu_window, Tegra::GPU& gp
|
||||
|
||||
RendererNull::~RendererNull() = default;
|
||||
|
||||
void RendererNull::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||
if (!framebuffer) {
|
||||
void RendererNull::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
|
||||
if (framebuffers.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
std::unique_ptr<Core::Frontend::GraphicsContext> context);
|
||||
~RendererNull() override;
|
||||
|
||||
void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override;
|
||||
void Composite(std::span<const Tegra::FramebufferConfig> framebuffer) override;
|
||||
|
||||
VideoCore::RasterizerInterface* ReadRasterizer() override {
|
||||
return &m_rasterizer;
|
||||
|
96
src/video_core/renderer_opengl/gl_blit_screen.cpp
Normal file
96
src/video_core/renderer_opengl/gl_blit_screen.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "video_core/renderer_opengl/gl_blit_screen.h"
|
||||
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
||||
#include "video_core/renderer_opengl/present/filters.h"
|
||||
#include "video_core/renderer_opengl/present/layer.h"
|
||||
#include "video_core/renderer_opengl/present/window_adapt_pass.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
BlitScreen::BlitScreen(RasterizerOpenGL& rasterizer_,
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
StateTracker& state_tracker_, ProgramManager& program_manager_,
|
||||
Device& device_)
|
||||
: rasterizer(rasterizer_), device_memory(device_memory_), state_tracker(state_tracker_),
|
||||
program_manager(program_manager_), device(device_) {}
|
||||
|
||||
BlitScreen::~BlitScreen() = default;
|
||||
|
||||
void BlitScreen::DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers,
|
||||
const Layout::FramebufferLayout& layout) {
|
||||
// TODO: Signal state tracker about these changes
|
||||
state_tracker.NotifyScreenDrawVertexArray();
|
||||
state_tracker.NotifyPolygonModes();
|
||||
state_tracker.NotifyViewport0();
|
||||
state_tracker.NotifyScissor0();
|
||||
state_tracker.NotifyColorMask(0);
|
||||
state_tracker.NotifyBlend0();
|
||||
state_tracker.NotifyFramebuffer();
|
||||
state_tracker.NotifyFrontFace();
|
||||
state_tracker.NotifyCullTest();
|
||||
state_tracker.NotifyDepthTest();
|
||||
state_tracker.NotifyStencilTest();
|
||||
state_tracker.NotifyPolygonOffset();
|
||||
state_tracker.NotifyRasterizeEnable();
|
||||
state_tracker.NotifyFramebufferSRGB();
|
||||
state_tracker.NotifyLogicOp();
|
||||
state_tracker.NotifyClipControl();
|
||||
state_tracker.NotifyAlphaTest();
|
||||
state_tracker.ClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glDisable(GL_RASTERIZER_DISCARD);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDisablei(GL_BLEND, 0);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glCullFace(GL_BACK);
|
||||
glFrontFace(GL_CW);
|
||||
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glDepthRangeIndexed(0, 0.0, 0.0);
|
||||
|
||||
while (layers.size() < framebuffers.size()) {
|
||||
layers.emplace_back(rasterizer, device_memory);
|
||||
}
|
||||
|
||||
CreateWindowAdapt();
|
||||
window_adapt->DrawToFramebuffer(program_manager, layers, framebuffers, layout);
|
||||
|
||||
// TODO
|
||||
// program_manager.RestoreGuestPipeline();
|
||||
}
|
||||
|
||||
void BlitScreen::CreateWindowAdapt() {
|
||||
if (window_adapt && Settings::values.scaling_filter.GetValue() == current_window_adapt) {
|
||||
return;
|
||||
}
|
||||
|
||||
current_window_adapt = Settings::values.scaling_filter.GetValue();
|
||||
switch (current_window_adapt) {
|
||||
case Settings::ScalingFilter::NearestNeighbor:
|
||||
window_adapt = MakeNearestNeighbor(device);
|
||||
break;
|
||||
case Settings::ScalingFilter::Bicubic:
|
||||
window_adapt = MakeBicubic(device);
|
||||
break;
|
||||
case Settings::ScalingFilter::Gaussian:
|
||||
window_adapt = MakeGaussian(device);
|
||||
break;
|
||||
case Settings::ScalingFilter::ScaleForce:
|
||||
window_adapt = MakeScaleForce(device);
|
||||
break;
|
||||
case Settings::ScalingFilter::Fsr:
|
||||
case Settings::ScalingFilter::Bilinear:
|
||||
default:
|
||||
window_adapt = MakeBilinear(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
71
src/video_core/renderer_opengl/gl_blit_screen.h
Normal file
71
src/video_core/renderer_opengl/gl_blit_screen.h
Normal file
@ -0,0 +1,71 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
|
||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||
#include "video_core/host1x/gpu_device_memory_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace Layout {
|
||||
struct FramebufferLayout;
|
||||
}
|
||||
|
||||
namespace Tegra {
|
||||
struct FramebufferConfig;
|
||||
}
|
||||
|
||||
namespace Settings {
|
||||
enum class ScalingFilter : u32;
|
||||
}
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class Device;
|
||||
class Layer;
|
||||
class ProgramManager;
|
||||
class RasterizerOpenGL;
|
||||
class StateTracker;
|
||||
class WindowAdaptPass;
|
||||
|
||||
/// Structure used for storing information about the display target for the Switch screen
|
||||
struct FramebufferTextureInfo {
|
||||
GLuint display_texture{};
|
||||
u32 width;
|
||||
u32 height;
|
||||
u32 scaled_width;
|
||||
u32 scaled_height;
|
||||
};
|
||||
|
||||
class BlitScreen {
|
||||
public:
|
||||
explicit BlitScreen(RasterizerOpenGL& rasterizer,
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory,
|
||||
StateTracker& state_tracker, ProgramManager& program_manager,
|
||||
Device& device);
|
||||
~BlitScreen();
|
||||
|
||||
/// Draws the emulated screens to the emulator window.
|
||||
void DrawScreen(std::span<const Tegra::FramebufferConfig> framebuffers,
|
||||
const Layout::FramebufferLayout& layout);
|
||||
|
||||
private:
|
||||
void CreateWindowAdapt();
|
||||
|
||||
RasterizerOpenGL& rasterizer;
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||
StateTracker& state_tracker;
|
||||
ProgramManager& program_manager;
|
||||
Device& device;
|
||||
|
||||
Settings::ScalingFilter current_window_adapt{};
|
||||
std::unique_ptr<WindowAdaptPass> window_adapt;
|
||||
|
||||
std::list<Layer> layers;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
@ -1,101 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/renderer_opengl/gl_fsr.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
|
||||
namespace OpenGL {
|
||||
using namespace FSR;
|
||||
|
||||
using FsrConstants = std::array<u32, 4 * 4>;
|
||||
|
||||
FSR::FSR(std::string_view fsr_vertex_source, std::string_view fsr_easu_source,
|
||||
std::string_view fsr_rcas_source)
|
||||
: fsr_vertex{CreateProgram(fsr_vertex_source, GL_VERTEX_SHADER)},
|
||||
fsr_easu_frag{CreateProgram(fsr_easu_source, GL_FRAGMENT_SHADER)},
|
||||
fsr_rcas_frag{CreateProgram(fsr_rcas_source, GL_FRAGMENT_SHADER)} {
|
||||
glProgramUniform2f(fsr_vertex.handle, 0, 1.0f, 1.0f);
|
||||
glProgramUniform2f(fsr_vertex.handle, 1, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
FSR::~FSR() = default;
|
||||
|
||||
void FSR::Draw(ProgramManager& program_manager, const Common::Rectangle<u32>& screen,
|
||||
u32 input_image_width, u32 input_image_height,
|
||||
const Common::Rectangle<int>& crop_rect) {
|
||||
|
||||
const auto output_image_width = screen.GetWidth();
|
||||
const auto output_image_height = screen.GetHeight();
|
||||
|
||||
if (fsr_intermediate_tex.handle) {
|
||||
GLint fsr_tex_width, fsr_tex_height;
|
||||
glGetTextureLevelParameteriv(fsr_intermediate_tex.handle, 0, GL_TEXTURE_WIDTH,
|
||||
&fsr_tex_width);
|
||||
glGetTextureLevelParameteriv(fsr_intermediate_tex.handle, 0, GL_TEXTURE_HEIGHT,
|
||||
&fsr_tex_height);
|
||||
if (static_cast<u32>(fsr_tex_width) != output_image_width ||
|
||||
static_cast<u32>(fsr_tex_height) != output_image_height) {
|
||||
fsr_intermediate_tex.Release();
|
||||
}
|
||||
}
|
||||
if (!fsr_intermediate_tex.handle) {
|
||||
fsr_intermediate_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(fsr_intermediate_tex.handle, 1, GL_RGB16F, output_image_width,
|
||||
output_image_height);
|
||||
glNamedFramebufferTexture(fsr_framebuffer.handle, GL_COLOR_ATTACHMENT0,
|
||||
fsr_intermediate_tex.handle, 0);
|
||||
}
|
||||
|
||||
GLint old_draw_fb;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb);
|
||||
|
||||
glFrontFace(GL_CW);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fsr_framebuffer.handle);
|
||||
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(output_image_width),
|
||||
static_cast<GLfloat>(output_image_height));
|
||||
|
||||
FsrConstants constants;
|
||||
FsrEasuConOffset(
|
||||
constants.data() + 0, constants.data() + 4, constants.data() + 8, constants.data() + 12,
|
||||
|
||||
static_cast<f32>(crop_rect.GetWidth()), static_cast<f32>(crop_rect.GetHeight()),
|
||||
static_cast<f32>(input_image_width), static_cast<f32>(input_image_height),
|
||||
static_cast<f32>(output_image_width), static_cast<f32>(output_image_height),
|
||||
static_cast<f32>(crop_rect.left), static_cast<f32>(crop_rect.top));
|
||||
|
||||
glProgramUniform4uiv(fsr_easu_frag.handle, 0, sizeof(constants), std::data(constants));
|
||||
|
||||
program_manager.BindPresentPrograms(fsr_vertex.handle, fsr_easu_frag.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
|
||||
glBindTextureUnit(0, fsr_intermediate_tex.handle);
|
||||
|
||||
const float sharpening =
|
||||
static_cast<float>(Settings::values.fsr_sharpening_slider.GetValue()) / 100.0f;
|
||||
|
||||
FsrRcasCon(constants.data(), sharpening);
|
||||
glProgramUniform4uiv(fsr_rcas_frag.handle, 0, sizeof(constants), std::data(constants));
|
||||
}
|
||||
|
||||
void FSR::InitBuffers() {
|
||||
fsr_framebuffer.Create();
|
||||
}
|
||||
|
||||
void FSR::ReleaseBuffers() {
|
||||
fsr_framebuffer.Release();
|
||||
fsr_intermediate_tex.Release();
|
||||
}
|
||||
|
||||
const OGLProgram& FSR::GetPresentFragmentProgram() const noexcept {
|
||||
return fsr_rcas_frag;
|
||||
}
|
||||
|
||||
bool FSR::AreBuffersInitialized() const noexcept {
|
||||
return fsr_framebuffer.handle;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
@ -1,43 +0,0 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class ProgramManager;
|
||||
|
||||
class FSR {
|
||||
public:
|
||||
explicit FSR(std::string_view fsr_vertex_source, std::string_view fsr_easu_source,
|
||||
std::string_view fsr_rcas_source);
|
||||
~FSR();
|
||||
|
||||
void Draw(ProgramManager& program_manager, const Common::Rectangle<u32>& screen,
|
||||
u32 input_image_width, u32 input_image_height,
|
||||
const Common::Rectangle<int>& crop_rect);
|
||||
|
||||
void InitBuffers();
|
||||
|
||||
void ReleaseBuffers();
|
||||
|
||||
[[nodiscard]] const OGLProgram& GetPresentFragmentProgram() const noexcept;
|
||||
|
||||
[[nodiscard]] bool AreBuffersInitialized() const noexcept;
|
||||
|
||||
private:
|
||||
OGLFramebuffer fsr_framebuffer;
|
||||
OGLProgram fsr_vertex;
|
||||
OGLProgram fsr_easu_frag;
|
||||
OGLProgram fsr_rcas_frag;
|
||||
OGLTexture fsr_intermediate_tex;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
@ -71,10 +71,10 @@ std::optional<VideoCore::QueryType> MaxwellToVideoCoreQuery(VideoCommon::QueryTy
|
||||
|
||||
RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
const Device& device_, ScreenInfo& screen_info_,
|
||||
ProgramManager& program_manager_, StateTracker& state_tracker_)
|
||||
: gpu(gpu_), device_memory(device_memory_), device(device_), screen_info(screen_info_),
|
||||
program_manager(program_manager_), state_tracker(state_tracker_),
|
||||
const Device& device_, ProgramManager& program_manager_,
|
||||
StateTracker& state_tracker_)
|
||||
: gpu(gpu_), device_memory(device_memory_), device(device_), program_manager(program_manager_),
|
||||
state_tracker(state_tracker_),
|
||||
texture_cache_runtime(device, program_manager, state_tracker, staging_buffer_pool),
|
||||
texture_cache(texture_cache_runtime, device_memory_),
|
||||
buffer_cache_runtime(device, staging_buffer_pool),
|
||||
@ -739,27 +739,29 @@ void RasterizerOpenGL::AccelerateInlineToMemory(GPUVAddr address, size_t copy_si
|
||||
query_cache.InvalidateRegion(*cpu_addr, copy_size);
|
||||
}
|
||||
|
||||
bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
|
||||
DAddr framebuffer_addr, u32 pixel_stride) {
|
||||
std::optional<FramebufferTextureInfo> RasterizerOpenGL::AccelerateDisplay(
|
||||
const Tegra::FramebufferConfig& config, DAddr framebuffer_addr, u32 pixel_stride) {
|
||||
if (framebuffer_addr == 0) {
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
||||
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
ImageView* const image_view{
|
||||
texture_cache.TryFindFramebufferImageView(config, framebuffer_addr)};
|
||||
const auto [image_view, scaled] =
|
||||
texture_cache.TryFindFramebufferImageView(config, framebuffer_addr);
|
||||
if (!image_view) {
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
// Verify that the cached surface is the same size and format as the requested framebuffer
|
||||
// ASSERT_MSG(image_view->size.width == config.width, "Framebuffer width is different");
|
||||
// ASSERT_MSG(image_view->size.height == config.height, "Framebuffer height is different");
|
||||
|
||||
screen_info.texture.width = image_view->size.width;
|
||||
screen_info.texture.height = image_view->size.height;
|
||||
screen_info.display_texture = image_view->Handle(Shader::TextureType::Color2D);
|
||||
return true;
|
||||
const auto& resolution = Settings::values.resolution_info;
|
||||
|
||||
FramebufferTextureInfo info{};
|
||||
info.display_texture = image_view->Handle(Shader::TextureType::Color2D);
|
||||
info.width = image_view->size.width;
|
||||
info.height = image_view->size.height;
|
||||
info.scaled_width = scaled ? resolution.ScaleUp(info.width) : info.width;
|
||||
info.scaled_height = scaled ? resolution.ScaleUp(info.height) : info.height;
|
||||
return info;
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::SyncState() {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "video_core/engines/maxwell_dma.h"
|
||||
#include "video_core/rasterizer_interface.h"
|
||||
#include "video_core/renderer_opengl/blit_image.h"
|
||||
#include "video_core/renderer_opengl/gl_blit_screen.h"
|
||||
#include "video_core/renderer_opengl/gl_buffer_cache.h"
|
||||
#include "video_core/renderer_opengl/gl_device.h"
|
||||
#include "video_core/renderer_opengl/gl_fence_manager.h"
|
||||
@ -37,7 +38,7 @@ class MemoryManager;
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
struct ScreenInfo;
|
||||
struct FramebufferTextureInfo;
|
||||
struct ShaderEntries;
|
||||
|
||||
struct BindlessSSBO {
|
||||
@ -76,8 +77,8 @@ class RasterizerOpenGL : public VideoCore::RasterizerInterface,
|
||||
public:
|
||||
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory_,
|
||||
const Device& device_, ScreenInfo& screen_info_,
|
||||
ProgramManager& program_manager_, StateTracker& state_tracker_);
|
||||
const Device& device_, ProgramManager& program_manager_,
|
||||
StateTracker& state_tracker_);
|
||||
~RasterizerOpenGL() override;
|
||||
|
||||
void Draw(bool is_indexed, u32 instance_count) override;
|
||||
@ -122,8 +123,6 @@ public:
|
||||
Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
|
||||
void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
|
||||
std::span<const u8> memory) override;
|
||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, DAddr framebuffer_addr,
|
||||
u32 pixel_stride) override;
|
||||
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||
|
||||
@ -144,6 +143,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<FramebufferTextureInfo> AccelerateDisplay(const Tegra::FramebufferConfig& config,
|
||||
VAddr framebuffer_addr,
|
||||
u32 pixel_stride);
|
||||
|
||||
private:
|
||||
static constexpr size_t MAX_TEXTURES = 192;
|
||||
static constexpr size_t MAX_IMAGES = 48;
|
||||
@ -237,7 +240,6 @@ private:
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||
|
||||
const Device& device;
|
||||
ScreenInfo& screen_info;
|
||||
ProgramManager& program_manager;
|
||||
StateTracker& state_tracker;
|
||||
|
||||
|
@ -1051,6 +1051,10 @@ void Image::Scale(bool up_scale) {
|
||||
state_tracker.NotifyScissor0();
|
||||
}
|
||||
|
||||
bool Image::IsRescaled() const {
|
||||
return True(flags & ImageFlagBits::Rescaled);
|
||||
}
|
||||
|
||||
bool Image::ScaleUp(bool ignore) {
|
||||
const auto& resolution = runtime->resolution;
|
||||
if (!resolution.active) {
|
||||
|
@ -217,6 +217,8 @@ public:
|
||||
return gl_type;
|
||||
}
|
||||
|
||||
bool IsRescaled() const;
|
||||
|
||||
bool ScaleUp(bool ignore = false);
|
||||
|
||||
bool ScaleDown(bool ignore = false);
|
||||
|
39
src/video_core/renderer_opengl/present/filters.cpp
Normal file
39
src/video_core/renderer_opengl/present/filters.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/host_shaders/opengl_present_frag.h"
|
||||
#include "video_core/host_shaders/opengl_present_scaleforce_frag.h"
|
||||
#include "video_core/host_shaders/present_bicubic_frag.h"
|
||||
#include "video_core/host_shaders/present_gaussian_frag.h"
|
||||
#include "video_core/renderer_opengl/present/filters.h"
|
||||
#include "video_core/renderer_opengl/present/util.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeNearestNeighbor(const Device& device) {
|
||||
return std::make_unique<WindowAdaptPass>(device, CreateNearestNeighborSampler(),
|
||||
HostShaders::OPENGL_PRESENT_FRAG);
|
||||
}
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeBilinear(const Device& device) {
|
||||
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
|
||||
HostShaders::OPENGL_PRESENT_FRAG);
|
||||
}
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device) {
|
||||
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
|
||||
HostShaders::PRESENT_BICUBIC_FRAG);
|
||||
}
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device) {
|
||||
return std::make_unique<WindowAdaptPass>(device, CreateBilinearSampler(),
|
||||
HostShaders::PRESENT_GAUSSIAN_FRAG);
|
||||
}
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeScaleForce(const Device& device) {
|
||||
return std::make_unique<WindowAdaptPass>(
|
||||
device, CreateBilinearSampler(),
|
||||
fmt::format("#version 460\n{}", HostShaders::OPENGL_PRESENT_SCALEFORCE_FRAG));
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
17
src/video_core/renderer_opengl/present/filters.h
Normal file
17
src/video_core/renderer_opengl/present/filters.h
Normal file
@ -0,0 +1,17 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "video_core/renderer_opengl/present/window_adapt_pass.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
std::unique_ptr<WindowAdaptPass> MakeNearestNeighbor(const Device& device);
|
||||
std::unique_ptr<WindowAdaptPass> MakeBilinear(const Device& device);
|
||||
std::unique_ptr<WindowAdaptPass> MakeBicubic(const Device& device);
|
||||
std::unique_ptr<WindowAdaptPass> MakeGaussian(const Device& device);
|
||||
std::unique_ptr<WindowAdaptPass> MakeScaleForce(const Device& device);
|
||||
|
||||
} // namespace OpenGL
|
98
src/video_core/renderer_opengl/present/fsr.cpp
Normal file
98
src/video_core/renderer_opengl/present/fsr.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/host_shaders/ffx_a_h.h"
|
||||
#include "video_core/host_shaders/ffx_fsr1_h.h"
|
||||
#include "video_core/host_shaders/full_screen_triangle_vert.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/present/fsr.h"
|
||||
#include "video_core/renderer_opengl/present/util.h"
|
||||
|
||||
namespace OpenGL {
|
||||
using namespace FSR;
|
||||
|
||||
using FsrConstants = std::array<u32, 4 * 4>;
|
||||
|
||||
FSR::FSR(u32 output_width_, u32 output_height_) : width(output_width_), height(output_height_) {
|
||||
std::string fsr_source{HostShaders::OPENGL_FIDELITYFX_FSR_FRAG};
|
||||
ReplaceInclude(fsr_source, "ffx_a.h", HostShaders::FFX_A_H);
|
||||
ReplaceInclude(fsr_source, "ffx_fsr1.h", HostShaders::FFX_FSR1_H);
|
||||
|
||||
std::string fsr_easu_source{HostShaders::OPENGL_FIDELITYFX_FSR_EASU_FRAG};
|
||||
std::string fsr_rcas_source{HostShaders::OPENGL_FIDELITYFX_FSR_RCAS_FRAG};
|
||||
ReplaceInclude(fsr_easu_source, "opengl_fidelityfx_fsr.frag", fsr_source);
|
||||
ReplaceInclude(fsr_rcas_source, "opengl_fidelityfx_fsr.frag", fsr_source);
|
||||
|
||||
vert = CreateProgram(HostShaders::FULL_SCREEN_TRIANGLE_VERT, GL_VERTEX_SHADER);
|
||||
easu_frag = CreateProgram(fsr_easu_source, GL_FRAGMENT_SHADER);
|
||||
rcas_frag = CreateProgram(fsr_rcas_source, GL_FRAGMENT_SHADER);
|
||||
|
||||
glProgramUniform2f(vert.handle, 0, 1.0f, -1.0f);
|
||||
glProgramUniform2f(vert.handle, 1, 0.0f, 1.0f);
|
||||
|
||||
sampler = CreateBilinearSampler();
|
||||
framebuffer.Create();
|
||||
|
||||
easu_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(easu_tex.handle, 1, GL_RGBA16F, width, height);
|
||||
|
||||
rcas_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(rcas_tex.handle, 1, GL_RGBA16F, width, height);
|
||||
}
|
||||
|
||||
FSR::~FSR() = default;
|
||||
|
||||
GLuint FSR::Draw(ProgramManager& program_manager, GLuint texture, u32 input_image_width,
|
||||
u32 input_image_height, const Common::Rectangle<f32>& crop_rect) {
|
||||
const f32 input_width = static_cast<f32>(input_image_width);
|
||||
const f32 input_height = static_cast<f32>(input_image_height);
|
||||
const f32 output_width = static_cast<f32>(width);
|
||||
const f32 output_height = static_cast<f32>(height);
|
||||
const f32 viewport_width = (crop_rect.right - crop_rect.left) * input_width;
|
||||
const f32 viewport_x = crop_rect.left * input_width;
|
||||
const f32 viewport_height = (crop_rect.bottom - crop_rect.top) * input_height;
|
||||
const f32 viewport_y = crop_rect.top * input_height;
|
||||
|
||||
FsrConstants easu_con{};
|
||||
FsrConstants rcas_con{};
|
||||
|
||||
FsrEasuConOffset(easu_con.data() + 0, easu_con.data() + 4, easu_con.data() + 8,
|
||||
easu_con.data() + 12, viewport_width, viewport_height, input_width,
|
||||
input_height, output_width, output_height, viewport_x, viewport_y);
|
||||
|
||||
const float sharpening =
|
||||
static_cast<float>(Settings::values.fsr_sharpening_slider.GetValue()) / 100.0f;
|
||||
|
||||
FsrRcasCon(rcas_con.data(), sharpening);
|
||||
|
||||
glProgramUniform4uiv(easu_frag.handle, 0, sizeof(easu_con), easu_con.data());
|
||||
glProgramUniform4uiv(rcas_frag.handle, 0, sizeof(rcas_con), rcas_con.data());
|
||||
|
||||
glFrontFace(GL_CW);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, easu_tex.handle, 0);
|
||||
glViewportIndexedf(0, 0.0f, 0.0f, output_width, output_height);
|
||||
program_manager.BindPresentPrograms(vert.handle, easu_frag.handle);
|
||||
glBindTextureUnit(0, texture);
|
||||
glBindSampler(0, sampler.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, rcas_tex.handle, 0);
|
||||
program_manager.BindPresentPrograms(vert.handle, rcas_frag.handle);
|
||||
glBindTextureUnit(0, easu_tex.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
return rcas_tex.handle;
|
||||
}
|
||||
|
||||
bool FSR::NeedsRecreation(const Common::Rectangle<u32>& screen) {
|
||||
return screen.GetWidth() != width || screen.GetHeight() != height;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
39
src/video_core/renderer_opengl/present/fsr.h
Normal file
39
src/video_core/renderer_opengl/present/fsr.h
Normal file
@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class ProgramManager;
|
||||
|
||||
class FSR {
|
||||
public:
|
||||
explicit FSR(u32 output_width, u32 output_height);
|
||||
~FSR();
|
||||
|
||||
GLuint Draw(ProgramManager& program_manager, GLuint texture, u32 input_image_width,
|
||||
u32 input_image_height, const Common::Rectangle<f32>& crop_rect);
|
||||
|
||||
bool NeedsRecreation(const Common::Rectangle<u32>& screen);
|
||||
|
||||
private:
|
||||
const u32 width;
|
||||
const u32 height;
|
||||
OGLFramebuffer framebuffer;
|
||||
OGLSampler sampler;
|
||||
OGLProgram vert;
|
||||
OGLProgram easu_frag;
|
||||
OGLProgram rcas_frag;
|
||||
OGLTexture easu_tex;
|
||||
OGLTexture rcas_tex;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
41
src/video_core/renderer_opengl/present/fxaa.cpp
Normal file
41
src/video_core/renderer_opengl/present/fxaa.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/host_shaders/fxaa_frag.h"
|
||||
#include "video_core/host_shaders/fxaa_vert.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/present/fxaa.h"
|
||||
#include "video_core/renderer_opengl/present/util.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
FXAA::FXAA(u32 width, u32 height) {
|
||||
vert_shader = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER);
|
||||
frag_shader = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER);
|
||||
|
||||
sampler = CreateBilinearSampler();
|
||||
|
||||
framebuffer.Create();
|
||||
|
||||
texture.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(texture.handle, 1, GL_RGBA16F, width, height);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
|
||||
}
|
||||
|
||||
FXAA::~FXAA() = default;
|
||||
|
||||
GLuint FXAA::Draw(ProgramManager& program_manager, GLuint input_texture) {
|
||||
glFrontFace(GL_CCW);
|
||||
|
||||
program_manager.BindPresentPrograms(vert_shader.handle, frag_shader.handle);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
||||
glBindTextureUnit(0, input_texture);
|
||||
glBindSampler(0, sampler.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
return texture.handle;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
27
src/video_core/renderer_opengl/present/fxaa.h
Normal file
27
src/video_core/renderer_opengl/present/fxaa.h
Normal file
@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class ProgramManager;
|
||||
|
||||
class FXAA {
|
||||
public:
|
||||
explicit FXAA(u32 width, u32 height);
|
||||
~FXAA();
|
||||
|
||||
GLuint Draw(ProgramManager& program_manager, GLuint input_texture);
|
||||
|
||||
private:
|
||||
OGLProgram vert_shader;
|
||||
OGLProgram frag_shader;
|
||||
OGLSampler sampler;
|
||||
OGLFramebuffer framebuffer;
|
||||
OGLTexture texture;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
215
src/video_core/renderer_opengl/present/layer.cpp
Normal file
215
src/video_core/renderer_opengl/present/layer.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/framebuffer_config.h"
|
||||
#include "video_core/renderer_opengl/gl_blit_screen.h"
|
||||
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
||||
#include "video_core/renderer_opengl/present/fsr.h"
|
||||
#include "video_core/renderer_opengl/present/fxaa.h"
|
||||
#include "video_core/renderer_opengl/present/layer.h"
|
||||
#include "video_core/renderer_opengl/present/present_uniforms.h"
|
||||
#include "video_core/renderer_opengl/present/smaa.h"
|
||||
#include "video_core/surface.h"
|
||||
#include "video_core/textures/decoders.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
Layer::Layer(RasterizerOpenGL& rasterizer_, Tegra::MaxwellDeviceMemoryManager& device_memory_)
|
||||
: rasterizer(rasterizer_), device_memory(device_memory_) {
|
||||
// Allocate textures for the screen
|
||||
framebuffer_texture.resource.Create(GL_TEXTURE_2D);
|
||||
|
||||
const GLuint texture = framebuffer_texture.resource.handle;
|
||||
glTextureStorage2D(texture, 1, GL_RGBA8, 1, 1);
|
||||
|
||||
// Clear screen to black
|
||||
const u8 framebuffer_data[4] = {0, 0, 0, 0};
|
||||
glClearTexImage(framebuffer_texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
framebuffer_data);
|
||||
}
|
||||
|
||||
Layer::~Layer() = default;
|
||||
|
||||
GLuint Layer::ConfigureDraw(std::array<GLfloat, 3 * 2>& out_matrix,
|
||||
std::array<ScreenRectVertex, 4>& out_vertices,
|
||||
ProgramManager& program_manager,
|
||||
const Tegra::FramebufferConfig& framebuffer,
|
||||
const Layout::FramebufferLayout& layout) {
|
||||
FramebufferTextureInfo info = PrepareRenderTarget(framebuffer);
|
||||
auto crop = Tegra::NormalizeCrop(framebuffer, info.width, info.height);
|
||||
GLuint texture = info.display_texture;
|
||||
|
||||
auto anti_aliasing = Settings::values.anti_aliasing.GetValue();
|
||||
if (anti_aliasing != Settings::AntiAliasing::None) {
|
||||
glEnablei(GL_SCISSOR_TEST, 0);
|
||||
auto viewport_width = Settings::values.resolution_info.ScaleUp(framebuffer_texture.width);
|
||||
auto viewport_height = Settings::values.resolution_info.ScaleUp(framebuffer_texture.height);
|
||||
|
||||
glScissorIndexed(0, 0, 0, viewport_width, viewport_height);
|
||||
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(viewport_width),
|
||||
static_cast<GLfloat>(viewport_height));
|
||||
|
||||
switch (anti_aliasing) {
|
||||
case Settings::AntiAliasing::Fxaa:
|
||||
CreateFXAA();
|
||||
texture = fxaa->Draw(program_manager, info.display_texture);
|
||||
break;
|
||||
case Settings::AntiAliasing::Smaa:
|
||||
default:
|
||||
CreateSMAA();
|
||||
texture = smaa->Draw(program_manager, info.display_texture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
glDisablei(GL_SCISSOR_TEST, 0);
|
||||
|
||||
if (Settings::values.scaling_filter.GetValue() == Settings::ScalingFilter::Fsr) {
|
||||
if (!fsr || fsr->NeedsRecreation(layout.screen)) {
|
||||
fsr = std::make_unique<FSR>(layout.screen.GetWidth(), layout.screen.GetHeight());
|
||||
}
|
||||
|
||||
texture = fsr->Draw(program_manager, texture, info.scaled_width, info.scaled_height, crop);
|
||||
crop = {0, 0, 1, 1};
|
||||
}
|
||||
|
||||
out_matrix =
|
||||
MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
|
||||
|
||||
// Map the coordinates to the screen.
|
||||
const auto& screen = layout.screen;
|
||||
const auto x = screen.left;
|
||||
const auto y = screen.top;
|
||||
const auto w = screen.GetWidth();
|
||||
const auto h = screen.GetHeight();
|
||||
|
||||
out_vertices[0] = ScreenRectVertex(x, y, crop.left, crop.top);
|
||||
out_vertices[1] = ScreenRectVertex(x + w, y, crop.right, crop.top);
|
||||
out_vertices[2] = ScreenRectVertex(x, y + h, crop.left, crop.bottom);
|
||||
out_vertices[3] = ScreenRectVertex(x + w, y + h, crop.right, crop.bottom);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
FramebufferTextureInfo Layer::PrepareRenderTarget(const Tegra::FramebufferConfig& framebuffer) {
|
||||
// If framebuffer is provided, reload it from memory to a texture
|
||||
if (framebuffer_texture.width != static_cast<GLsizei>(framebuffer.width) ||
|
||||
framebuffer_texture.height != static_cast<GLsizei>(framebuffer.height) ||
|
||||
framebuffer_texture.pixel_format != framebuffer.pixel_format ||
|
||||
gl_framebuffer_data.empty()) {
|
||||
// Reallocate texture if the framebuffer size has changed.
|
||||
// This is expected to not happen very often and hence should not be a
|
||||
// performance problem.
|
||||
ConfigureFramebufferTexture(framebuffer);
|
||||
}
|
||||
|
||||
// Load the framebuffer from memory if needed
|
||||
return LoadFBToScreenInfo(framebuffer);
|
||||
}
|
||||
|
||||
FramebufferTextureInfo Layer::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) {
|
||||
const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset};
|
||||
const auto accelerated_info =
|
||||
rasterizer.AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride);
|
||||
if (accelerated_info) {
|
||||
return *accelerated_info;
|
||||
}
|
||||
|
||||
// Reset the screen info's display texture to its own permanent texture
|
||||
FramebufferTextureInfo info{};
|
||||
info.display_texture = framebuffer_texture.resource.handle;
|
||||
info.width = framebuffer.width;
|
||||
info.height = framebuffer.height;
|
||||
info.scaled_width = framebuffer.width;
|
||||
info.scaled_height = framebuffer.height;
|
||||
|
||||
// TODO(Rodrigo): Read this from HLE
|
||||
constexpr u32 block_height_log2 = 4;
|
||||
const auto pixel_format{
|
||||
VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
|
||||
const u32 bytes_per_pixel{VideoCore::Surface::BytesPerBlock(pixel_format)};
|
||||
const u64 size_in_bytes{Tegra::Texture::CalculateSize(
|
||||
true, bytes_per_pixel, framebuffer.stride, framebuffer.height, 1, block_height_log2, 0)};
|
||||
const u8* const host_ptr{device_memory.GetPointer<u8>(framebuffer_addr)};
|
||||
const std::span<const u8> input_data(host_ptr, size_in_bytes);
|
||||
Tegra::Texture::UnswizzleTexture(gl_framebuffer_data, input_data, bytes_per_pixel,
|
||||
framebuffer.width, framebuffer.height, 1, block_height_log2,
|
||||
0);
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(framebuffer.stride));
|
||||
|
||||
// Update existing texture
|
||||
// TODO: Test what happens on hardware when you change the framebuffer dimensions so that
|
||||
// they differ from the LCD resolution.
|
||||
// TODO: Applications could theoretically crash yuzu here by specifying too large
|
||||
// framebuffer sizes. We should make sure that this cannot happen.
|
||||
glTextureSubImage2D(framebuffer_texture.resource.handle, 0, 0, 0, framebuffer.width,
|
||||
framebuffer.height, framebuffer_texture.gl_format,
|
||||
framebuffer_texture.gl_type, gl_framebuffer_data.data());
|
||||
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void Layer::ConfigureFramebufferTexture(const Tegra::FramebufferConfig& framebuffer) {
|
||||
framebuffer_texture.width = framebuffer.width;
|
||||
framebuffer_texture.height = framebuffer.height;
|
||||
framebuffer_texture.pixel_format = framebuffer.pixel_format;
|
||||
|
||||
const auto pixel_format{
|
||||
VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
|
||||
const u32 bytes_per_pixel{VideoCore::Surface::BytesPerBlock(pixel_format)};
|
||||
gl_framebuffer_data.resize(framebuffer_texture.width * framebuffer_texture.height *
|
||||
bytes_per_pixel);
|
||||
|
||||
GLint internal_format;
|
||||
switch (framebuffer.pixel_format) {
|
||||
case Service::android::PixelFormat::Rgba8888:
|
||||
internal_format = GL_RGBA8;
|
||||
framebuffer_texture.gl_format = GL_RGBA;
|
||||
framebuffer_texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
break;
|
||||
case Service::android::PixelFormat::Rgb565:
|
||||
internal_format = GL_RGB565;
|
||||
framebuffer_texture.gl_format = GL_RGB;
|
||||
framebuffer_texture.gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
||||
break;
|
||||
default:
|
||||
internal_format = GL_RGBA8;
|
||||
framebuffer_texture.gl_format = GL_RGBA;
|
||||
framebuffer_texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
||||
// UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}",
|
||||
// static_cast<u32>(framebuffer.pixel_format));
|
||||
break;
|
||||
}
|
||||
|
||||
framebuffer_texture.resource.Release();
|
||||
framebuffer_texture.resource.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(framebuffer_texture.resource.handle, 1, internal_format,
|
||||
framebuffer_texture.width, framebuffer_texture.height);
|
||||
|
||||
fxaa.reset();
|
||||
smaa.reset();
|
||||
}
|
||||
|
||||
void Layer::CreateFXAA() {
|
||||
smaa.reset();
|
||||
if (!fxaa) {
|
||||
fxaa = std::make_unique<FXAA>(
|
||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
||||
}
|
||||
}
|
||||
|
||||
void Layer::CreateSMAA() {
|
||||
fxaa.reset();
|
||||
if (!smaa) {
|
||||
smaa = std::make_unique<SMAA>(
|
||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.width),
|
||||
Settings::values.resolution_info.ScaleUp(framebuffer_texture.height));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
80
src/video_core/renderer_opengl/present/layer.h
Normal file
80
src/video_core/renderer_opengl/present/layer.h
Normal file
@ -0,0 +1,80 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "video_core/host1x/gpu_device_memory_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace Layout {
|
||||
struct FramebufferLayout;
|
||||
}
|
||||
|
||||
namespace Service::android {
|
||||
enum class PixelFormat : u32;
|
||||
};
|
||||
|
||||
namespace Tegra {
|
||||
struct FramebufferConfig;
|
||||
}
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
struct FramebufferTextureInfo;
|
||||
class FSR;
|
||||
class FXAA;
|
||||
class ProgramManager;
|
||||
class RasterizerOpenGL;
|
||||
class SMAA;
|
||||
|
||||
/// Structure used for storing information about the textures for the Switch screen
|
||||
struct TextureInfo {
|
||||
OGLTexture resource;
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
GLenum gl_format;
|
||||
GLenum gl_type;
|
||||
Service::android::PixelFormat pixel_format;
|
||||
};
|
||||
|
||||
struct ScreenRectVertex;
|
||||
|
||||
class Layer {
|
||||
public:
|
||||
explicit Layer(RasterizerOpenGL& rasterizer, Tegra::MaxwellDeviceMemoryManager& device_memory);
|
||||
~Layer();
|
||||
|
||||
GLuint ConfigureDraw(std::array<GLfloat, 3 * 2>& out_matrix,
|
||||
std::array<ScreenRectVertex, 4>& out_vertices,
|
||||
ProgramManager& program_manager,
|
||||
const Tegra::FramebufferConfig& framebuffer,
|
||||
const Layout::FramebufferLayout& layout);
|
||||
|
||||
private:
|
||||
/// Loads framebuffer from emulated memory into the active OpenGL texture.
|
||||
FramebufferTextureInfo LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer);
|
||||
FramebufferTextureInfo PrepareRenderTarget(const Tegra::FramebufferConfig& framebuffer);
|
||||
void ConfigureFramebufferTexture(const Tegra::FramebufferConfig& framebuffer);
|
||||
|
||||
void CreateFXAA();
|
||||
void CreateSMAA();
|
||||
|
||||
private:
|
||||
RasterizerOpenGL& rasterizer;
|
||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||
|
||||
/// OpenGL framebuffer data
|
||||
std::vector<u8> gl_framebuffer_data;
|
||||
|
||||
/// Display information for Switch screen
|
||||
TextureInfo framebuffer_texture;
|
||||
|
||||
std::unique_ptr<FSR> fsr;
|
||||
std::unique_ptr<FXAA> fxaa;
|
||||
std::unique_ptr<SMAA> smaa;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
43
src/video_core/renderer_opengl/present/present_uniforms.h
Normal file
43
src/video_core/renderer_opengl/present/present_uniforms.h
Normal file
@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
constexpr GLint PositionLocation = 0;
|
||||
constexpr GLint TexCoordLocation = 1;
|
||||
constexpr GLint ModelViewMatrixLocation = 0;
|
||||
|
||||
struct ScreenRectVertex {
|
||||
constexpr ScreenRectVertex() = default;
|
||||
|
||||
constexpr ScreenRectVertex(u32 x, u32 y, GLfloat u, GLfloat v)
|
||||
: position{{static_cast<GLfloat>(x), static_cast<GLfloat>(y)}}, tex_coord{{u, v}} {}
|
||||
|
||||
std::array<GLfloat, 2> position{};
|
||||
std::array<GLfloat, 2> tex_coord{};
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines a 1:1 pixel orthographic projection matrix with (0,0) on the top-left
|
||||
* corner and (width, height) on the lower-bottom.
|
||||
*
|
||||
* The projection part of the matrix is trivial, hence these operations are represented
|
||||
* by a 3x2 matrix.
|
||||
*/
|
||||
static inline std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(float width, float height) {
|
||||
std::array<GLfloat, 3 * 2> matrix; // Laid out in column-major order
|
||||
|
||||
// clang-format off
|
||||
matrix[0] = 2.f / width; matrix[2] = 0.f; matrix[4] = -1.f;
|
||||
matrix[1] = 0.f; matrix[3] = -2.f / height; matrix[5] = 1.f;
|
||||
// Last matrix row is implicitly assumed to be [0, 0, 1].
|
||||
// clang-format on
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
102
src/video_core/renderer_opengl/present/smaa.cpp
Normal file
102
src/video_core/renderer_opengl/present/smaa.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/host_shaders/opengl_smaa_glsl.h"
|
||||
#include "video_core/host_shaders/smaa_blending_weight_calculation_frag.h"
|
||||
#include "video_core/host_shaders/smaa_blending_weight_calculation_vert.h"
|
||||
#include "video_core/host_shaders/smaa_edge_detection_frag.h"
|
||||
#include "video_core/host_shaders/smaa_edge_detection_vert.h"
|
||||
#include "video_core/host_shaders/smaa_neighborhood_blending_frag.h"
|
||||
#include "video_core/host_shaders/smaa_neighborhood_blending_vert.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/present/smaa.h"
|
||||
#include "video_core/renderer_opengl/present/util.h"
|
||||
#include "video_core/smaa_area_tex.h"
|
||||
#include "video_core/smaa_search_tex.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
SMAA::SMAA(u32 width, u32 height) {
|
||||
const auto SmaaShader = [&](std::string_view specialized_source, GLenum stage) {
|
||||
std::string shader_source{specialized_source};
|
||||
ReplaceInclude(shader_source, "opengl_smaa.glsl", HostShaders::OPENGL_SMAA_GLSL);
|
||||
return CreateProgram(shader_source, stage);
|
||||
};
|
||||
|
||||
edge_detection_vert = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_VERT, GL_VERTEX_SHADER);
|
||||
edge_detection_frag = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_FRAG, GL_FRAGMENT_SHADER);
|
||||
blending_weight_calculation_vert =
|
||||
SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_VERT, GL_VERTEX_SHADER);
|
||||
blending_weight_calculation_frag =
|
||||
SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_FRAG, GL_FRAGMENT_SHADER);
|
||||
neighborhood_blending_vert =
|
||||
SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_VERT, GL_VERTEX_SHADER);
|
||||
neighborhood_blending_frag =
|
||||
SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_FRAG, GL_FRAGMENT_SHADER);
|
||||
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
|
||||
area_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(area_tex.handle, 1, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT);
|
||||
glTextureSubImage2D(area_tex.handle, 0, 0, 0, AREATEX_WIDTH, AREATEX_HEIGHT, GL_RG,
|
||||
GL_UNSIGNED_BYTE, areaTexBytes);
|
||||
search_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(search_tex.handle, 1, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT);
|
||||
glTextureSubImage2D(search_tex.handle, 0, 0, 0, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GL_RED,
|
||||
GL_UNSIGNED_BYTE, searchTexBytes);
|
||||
|
||||
edges_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(edges_tex.handle, 1, GL_RG16F, width, height);
|
||||
|
||||
blend_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(blend_tex.handle, 1, GL_RGBA16F, width, height);
|
||||
|
||||
sampler = CreateBilinearSampler();
|
||||
|
||||
framebuffer.Create();
|
||||
|
||||
texture.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(texture.handle, 1, GL_RGBA16F, width, height);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
|
||||
}
|
||||
|
||||
SMAA::~SMAA() = default;
|
||||
|
||||
GLuint SMAA::Draw(ProgramManager& program_manager, GLuint input_texture) {
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glFrontFace(GL_CCW);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
||||
glBindSampler(0, sampler.handle);
|
||||
glBindSampler(1, sampler.handle);
|
||||
glBindSampler(2, sampler.handle);
|
||||
|
||||
glBindTextureUnit(0, input_texture);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, edges_tex.handle, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
program_manager.BindPresentPrograms(edge_detection_vert.handle, edge_detection_frag.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glBindTextureUnit(0, edges_tex.handle);
|
||||
glBindTextureUnit(1, area_tex.handle);
|
||||
glBindTextureUnit(2, search_tex.handle);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, blend_tex.handle, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
program_manager.BindPresentPrograms(blending_weight_calculation_vert.handle,
|
||||
blending_weight_calculation_frag.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glBindTextureUnit(0, input_texture);
|
||||
glBindTextureUnit(1, blend_tex.handle);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, texture.handle, 0);
|
||||
program_manager.BindPresentPrograms(neighborhood_blending_vert.handle,
|
||||
neighborhood_blending_frag.handle);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
return texture.handle;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
35
src/video_core/renderer_opengl/present/smaa.h
Normal file
35
src/video_core/renderer_opengl/present/smaa.h
Normal file
@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class ProgramManager;
|
||||
|
||||
class SMAA {
|
||||
public:
|
||||
explicit SMAA(u32 width, u32 height);
|
||||
~SMAA();
|
||||
|
||||
GLuint Draw(ProgramManager& program_manager, GLuint input_texture);
|
||||
|
||||
private:
|
||||
OGLProgram edge_detection_vert;
|
||||
OGLProgram blending_weight_calculation_vert;
|
||||
OGLProgram neighborhood_blending_vert;
|
||||
OGLProgram edge_detection_frag;
|
||||
OGLProgram blending_weight_calculation_frag;
|
||||
OGLProgram neighborhood_blending_frag;
|
||||
OGLTexture area_tex;
|
||||
OGLTexture search_tex;
|
||||
OGLTexture edges_tex;
|
||||
OGLTexture blend_tex;
|
||||
OGLSampler sampler;
|
||||
OGLFramebuffer framebuffer;
|
||||
OGLTexture texture;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
43
src/video_core/renderer_opengl/present/util.h
Normal file
43
src/video_core/renderer_opengl/present/util.h
Normal file
@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
static inline void ReplaceInclude(std::string& shader_source, std::string_view include_name,
|
||||
std::string_view include_content) {
|
||||
const std::string include_string = fmt::format("#include \"{}\"", include_name);
|
||||
const std::size_t pos = shader_source.find(include_string);
|
||||
ASSERT(pos != std::string::npos);
|
||||
shader_source.replace(pos, include_string.size(), include_content);
|
||||
};
|
||||
|
||||
static inline OGLSampler CreateBilinearSampler() {
|
||||
OGLSampler sampler;
|
||||
sampler.Create();
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
return sampler;
|
||||
}
|
||||
|
||||
static inline OGLSampler CreateNearestNeighborSampler() {
|
||||
OGLSampler sampler;
|
||||
sampler.Create();
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glSamplerParameteri(sampler.handle, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
return sampler;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
103
src/video_core/renderer_opengl/present/window_adapt_pass.cpp
Normal file
103
src/video_core/renderer_opengl/present/window_adapt_pass.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "video_core/framebuffer_config.h"
|
||||
#include "video_core/host_shaders/opengl_present_vert.h"
|
||||
#include "video_core/renderer_opengl/gl_device.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/present/layer.h"
|
||||
#include "video_core/renderer_opengl/present/present_uniforms.h"
|
||||
#include "video_core/renderer_opengl/present/window_adapt_pass.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
WindowAdaptPass::WindowAdaptPass(const Device& device_, OGLSampler&& sampler_,
|
||||
std::string_view frag_source)
|
||||
: device(device_), sampler(std::move(sampler_)) {
|
||||
vert = CreateProgram(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER);
|
||||
frag = CreateProgram(frag_source, GL_FRAGMENT_SHADER);
|
||||
|
||||
// Generate VBO handle for drawing
|
||||
vertex_buffer.Create();
|
||||
|
||||
// Attach vertex data to VAO
|
||||
glNamedBufferData(vertex_buffer.handle, sizeof(ScreenRectVertex) * 4, nullptr, GL_STREAM_DRAW);
|
||||
|
||||
// Query vertex buffer address when the driver supports unified vertex attributes
|
||||
if (device.HasVertexBufferUnifiedMemory()) {
|
||||
glMakeNamedBufferResidentNV(vertex_buffer.handle, GL_READ_ONLY);
|
||||
glGetNamedBufferParameterui64vNV(vertex_buffer.handle, GL_BUFFER_GPU_ADDRESS_NV,
|
||||
&vertex_buffer_address);
|
||||
}
|
||||
}
|
||||
|
||||
WindowAdaptPass::~WindowAdaptPass() = default;
|
||||
|
||||
void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers,
|
||||
std::span<const Tegra::FramebufferConfig> framebuffers,
|
||||
const Layout::FramebufferLayout& layout) {
|
||||
GLint old_read_fb;
|
||||
GLint old_draw_fb;
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb);
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb);
|
||||
|
||||
const size_t layer_count = framebuffers.size();
|
||||
std::vector<GLuint> textures(layer_count);
|
||||
std::vector<std::array<GLfloat, 3 * 2>> matrices(layer_count);
|
||||
std::vector<std::array<ScreenRectVertex, 4>> vertices(layer_count);
|
||||
|
||||
auto layer_it = layers.begin();
|
||||
for (size_t i = 0; i < layer_count; i++) {
|
||||
textures[i] = layer_it->ConfigureDraw(matrices[i], vertices[i], program_manager,
|
||||
framebuffers[i], layout);
|
||||
layer_it++;
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
|
||||
|
||||
program_manager.BindPresentPrograms(vert.handle, frag.handle);
|
||||
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(layout.width),
|
||||
static_cast<GLfloat>(layout.height));
|
||||
|
||||
glEnableVertexAttribArray(PositionLocation);
|
||||
glEnableVertexAttribArray(TexCoordLocation);
|
||||
glVertexAttribDivisor(PositionLocation, 0);
|
||||
glVertexAttribDivisor(TexCoordLocation, 0);
|
||||
glVertexAttribFormat(PositionLocation, 2, GL_FLOAT, GL_FALSE,
|
||||
offsetof(ScreenRectVertex, position));
|
||||
glVertexAttribFormat(TexCoordLocation, 2, GL_FLOAT, GL_FALSE,
|
||||
offsetof(ScreenRectVertex, tex_coord));
|
||||
glVertexAttribBinding(PositionLocation, 0);
|
||||
glVertexAttribBinding(TexCoordLocation, 0);
|
||||
if (device.HasVertexBufferUnifiedMemory()) {
|
||||
glBindVertexBuffer(0, 0, 0, sizeof(ScreenRectVertex));
|
||||
glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, 0, vertex_buffer_address,
|
||||
sizeof(decltype(vertices)::value_type));
|
||||
} else {
|
||||
glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
|
||||
}
|
||||
|
||||
glBindSampler(0, sampler.handle);
|
||||
|
||||
// Update background color before drawing
|
||||
glClearColor(Settings::values.bg_red.GetValue() / 255.0f,
|
||||
Settings::values.bg_green.GetValue() / 255.0f,
|
||||
Settings::values.bg_blue.GetValue() / 255.0f, 1.0f);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
for (size_t i = 0; i < layer_count; i++) {
|
||||
glBindTextureUnit(0, textures[i]);
|
||||
glProgramUniformMatrix3x2fv(vert.handle, ModelViewMatrixLocation, 1, GL_FALSE,
|
||||
matrices[i].data());
|
||||
glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices[i]), std::data(vertices[i]));
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
47
src/video_core/renderer_opengl/present/window_adapt_pass.h
Normal file
47
src/video_core/renderer_opengl/present/window_adapt_pass.h
Normal file
@ -0,0 +1,47 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <span>
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace Layout {
|
||||
struct FramebufferLayout;
|
||||
}
|
||||
|
||||
namespace Tegra {
|
||||
struct FramebufferConfig;
|
||||
}
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class Device;
|
||||
class Layer;
|
||||
class ProgramManager;
|
||||
|
||||
class WindowAdaptPass final {
|
||||
public:
|
||||
explicit WindowAdaptPass(const Device& device, OGLSampler&& sampler,
|
||||
std::string_view frag_source);
|
||||
~WindowAdaptPass();
|
||||
|
||||
void DrawToFramebuffer(ProgramManager& program_manager, std::list<Layer>& layers,
|
||||
std::span<const Tegra::FramebufferConfig> framebuffers,
|
||||
const Layout::FramebufferLayout& layout);
|
||||
|
||||
private:
|
||||
const Device& device;
|
||||
OGLSampler sampler;
|
||||
OGLProgram vert;
|
||||
OGLProgram frag;
|
||||
OGLBuffer vertex_buffer;
|
||||
|
||||
// GPU address of the vertex buffer
|
||||
GLuint64EXT vertex_buffer_address = 0;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user