[hle] constexpr handler dispatch maps, introduce version gating (#4480)

This PR primarily focuses on upbringing constexpr maps for handlers.

Each time an HLE object of a service is construed, it registers it's own handlers, over and over.
Regardless of whetever it needs them at the moment or not.
Additionally we don't require to keep track of different function pointers amongst each object.
This can be done by overriding the given function instead, as opposed to having a separate
hash map for every given object.

In other words: Remove handlers (and handlers_tipc) map for every instance
then read from a static defined per-class.

- [x] Migrate all HLE functions to new `frozen::map` constexpr time finder
- [ ] Measure if this approach actually makes better codegen

Optional:
- [x] Properly gate all functions (that have versions commented next to them)
- [x] Maybe store `HandlerFnP<>` and `const char*` separately, version gating can go in a different map as well

Information such as name can be used on debug builds, but doesn't particularly help on release as one can consult an external reference (or have an annotated IPC map)

Signed-off-by: lizzie <lizzie@eden-emu.dev>

- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions).
- [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md)
- [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability.

-------------------

Co-authored-by: Maufeat <sahyno1996@gmail.com>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4480
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
lizzie
2026-10-13 04:38:36 +02:00
committed by PavelBARABANOV
parent 989768aa46
commit 1059202c75
392 changed files with 12453 additions and 14117 deletions
+14 -39
View File
@@ -21,22 +21,15 @@ namespace Service::PTM {
class IPsmSession final : public ServiceFramework<IPsmSession> {
public:
explicit IPsmSession(Core::System& system_)
: ServiceFramework{system_, "IPsmSession"}, service_context{system_, "IPsmSession"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &IPsmSession::BindStateChangeEvent, "BindStateChangeEvent"},
{1, &IPsmSession::UnbindStateChangeEvent, "UnbindStateChangeEvent"},
{2, &IPsmSession::SetChargerTypeChangeEventEnabled, "SetChargerTypeChangeEventEnabled"},
{3, &IPsmSession::SetPowerSupplyChangeEventEnabled, "SetPowerSupplyChangeEventEnabled"},
{4, &IPsmSession::SetBatteryVoltageStateChangeEventEnabled, "SetBatteryVoltageStateChangeEventEnabled"},
};
// clang-format on
RegisterHandlers(functions);
: ServiceFramework{system_, "IPsmSession"}
, service_context{system_, "IPsmSession"} {
state_change_event = service_context.CreateEvent("IPsmSession::state_change_event");
}
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
~IPsmSession() override {
service_context.CloseEvent(state_change_event);
}
@@ -112,8 +105,15 @@ private:
rb.Push(ResultSuccess);
}
KernelHelpers::ServiceContext service_context;
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, &IPsmSession::BindStateChangeEvent, "BindStateChangeEvent"},
FunctionInfo{1, &IPsmSession::UnbindStateChangeEvent, "UnbindStateChangeEvent"},
FunctionInfo{2, &IPsmSession::SetChargerTypeChangeEventEnabled, "SetChargerTypeChangeEventEnabled"},
FunctionInfo{3, &IPsmSession::SetPowerSupplyChangeEventEnabled, "SetPowerSupplyChangeEventEnabled"},
FunctionInfo{4, &IPsmSession::SetBatteryVoltageStateChangeEventEnabled, "SetBatteryVoltageStateChangeEventEnabled"}
);
KernelHelpers::ServiceContext service_context;
bool should_signal_charger_type{};
bool should_signal_power_supply{};
bool should_signal_battery_voltage{};
@@ -122,31 +122,6 @@ private:
};
PSM::PSM(Core::System& system_) : ServiceFramework{system_, "psm"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &PSM::GetBatteryChargePercentage, "GetBatteryChargePercentage"},
{1, &PSM::GetChargerType, "GetChargerType"},
{2, nullptr, "EnableBatteryCharging"},
{3, nullptr, "DisableBatteryCharging"},
{4, nullptr, "IsBatteryChargingEnabled"},
{5, nullptr, "AcquireControllerPowerSupply"},
{6, nullptr, "ReleaseControllerPowerSupply"},
{7, &PSM::OpenSession, "OpenSession"},
{8, nullptr, "EnableEnoughPowerChargeEmulation"},
{9, nullptr, "DisableEnoughPowerChargeEmulation"},
{10, nullptr, "EnableFastBatteryCharging"},
{11, nullptr, "DisableFastBatteryCharging"},
{12, &PSM::GetBatteryVoltageState, "GetBatteryVoltageState"},
{13, nullptr, "GetRawBatteryChargePercentage"},
{14, nullptr, "IsEnoughPowerSupplied"},
{15, &PSM::GetBatteryAgePercentage, "GetBatteryAgePercentage"},
{16, nullptr, "GetBatteryChargeInfoEvent"},
{17, &PSM::GetBatteryChargeInfoFields, "GetBatteryChargeInfoFields"},
{18, nullptr, "GetBatteryChargeCalibratedEvent"},
};
// clang-format on
RegisterHandlers(functions);
}
PSM::~PSM() = default;
+25
View File
@@ -28,6 +28,31 @@ private:
void GetBatteryVoltageState(HLERequestContext& ctx);
void GetBatteryAgePercentage(HLERequestContext& ctx);
void GetBatteryChargeInfoFields(HLERequestContext& ctx);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, &PSM::GetBatteryChargePercentage, "GetBatteryChargePercentage"},
FunctionInfo{1, &PSM::GetChargerType, "GetChargerType"},
FunctionInfo{2, nullptr, "EnableBatteryCharging"},
FunctionInfo{3, nullptr, "DisableBatteryCharging"},
FunctionInfo{4, nullptr, "IsBatteryChargingEnabled"},
FunctionInfo{5, nullptr, "AcquireControllerPowerSupply"},
FunctionInfo{6, nullptr, "ReleaseControllerPowerSupply"},
FunctionInfo{7, &PSM::OpenSession, "OpenSession"},
FunctionInfo{8, nullptr, "EnableEnoughPowerChargeEmulation"},
FunctionInfo{9, nullptr, "DisableEnoughPowerChargeEmulation"},
FunctionInfo{10, nullptr, "EnableFastBatteryCharging"},
FunctionInfo{11, nullptr, "DisableFastBatteryCharging"},
FunctionInfo{12, &PSM::GetBatteryVoltageState, "GetBatteryVoltageState"},
FunctionInfo{13, nullptr, "GetRawBatteryChargePercentage"},
FunctionInfo{14, nullptr, "IsEnoughPowerSupplied"},
FunctionInfo{15, &PSM::GetBatteryAgePercentage, "GetBatteryAgePercentage"},
FunctionInfo{16, nullptr, "GetBatteryChargeInfoEvent"},
FunctionInfo{17, &PSM::GetBatteryChargeInfoFields, "GetBatteryChargeInfoFields"},
FunctionInfo{18, nullptr, "GetBatteryChargeCalibratedEvent"}
);
};
} // namespace Service::PTM
+16 -16
View File
@@ -17,28 +17,28 @@ namespace Service::PTM {
class PSM_MANU final : public ServiceFramework<PSM_MANU> {
public:
explicit PSM_MANU(Core::System& system_)
: ServiceFramework{system_, "psm:manu"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "EnableVdd50StateControl"},
{1, nullptr, "DisableVdd50StateControl"},
{2, nullptr, "SetVdd50State"},
};
// clang-format on
RegisterHandlers(functions);
: ServiceFramework{system_, "psm:manu"} {}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, nullptr, "EnableVdd50StateControl"},
FunctionInfo{1, nullptr, "DisableVdd50StateControl"},
FunctionInfo{2, nullptr, "SetVdd50State"}
);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
};
class POWCTL final : public ServiceFramework<POWCTL> {
public:
explicit POWCTL(Core::System& system_)
: ServiceFramework{system_, "powctl"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "OpenSession"},
};
// clang-format on
RegisterHandlers(functions);
: ServiceFramework{system_, "powctl"} {}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, nullptr, "OpenSession"}
);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
};
+9 -20
View File
@@ -19,16 +19,10 @@ enum class Location : u8 {
class ISession : public ServiceFramework<ISession> {
public:
explicit ISession(Core::System& system_) : ServiceFramework{system_, "ISession"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "GetTemperatureRange"},
{2, nullptr, "SetMeasurementMode"},
{4, &ISession::GetTemperature, "GetTemperature"},
};
// clang-format on
explicit ISession(Core::System& system_) : ServiceFramework{system_, "ISession"} {}
RegisterHandlers(functions);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
private:
@@ -39,20 +33,15 @@ private:
rb.Push(ResultSuccess);
rb.Push(temperature);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, nullptr, "GetTemperatureRange"},
FunctionInfo{2, nullptr, "SetMeasurementMode"},
FunctionInfo{4, &ISession::GetTemperature, "GetTemperature"}
);
};
TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "GetTemperatureRange"},
{1, &TS::GetTemperature, "GetTemperature"},
{2, nullptr, "SetMeasurementMode"},
{3, &TS::GetTemperatureMilliC, "GetTemperatureMilliC"},
{4, &TS::OpenSession, "OpenSession"},
};
// clang-format on
RegisterHandlers(functions);
}
TS::~TS() = default;
+11
View File
@@ -20,6 +20,17 @@ private:
void GetTemperature(HLERequestContext& ctx);
void GetTemperatureMilliC(HLERequestContext& ctx);
void OpenSession(HLERequestContext& ctx);
std::optional<FunctionInfoBase> FindRequest(u32 key) override {
return HandlerTableGenerateWithFind(key, functions);
}
static constexpr auto functions = CreateStaticMap(
FunctionInfo{0, nullptr, "GetTemperatureRange"},
FunctionInfo{1, &TS::GetTemperature, "GetTemperature"},
FunctionInfo{2, nullptr, "SetMeasurementMode"},
FunctionInfo{3, &TS::GetTemperatureMilliC, "GetTemperatureMilliC"},
FunctionInfo{4, &TS::OpenSession, "OpenSession"}
);
};
} // namespace Service::PTM