Some code clean up

This commit is contained in:
N3xoX1 2026-02-16 18:34:02 +10:30
parent 8c8ab9358b
commit f43b464b24
6 changed files with 120 additions and 77 deletions

View File

@ -50,62 +50,74 @@ std::size_t WriteVectors(std::span<u8> dst, const std::vector<T>& src, std::size
}
} // Anonymous namespace
nvhost_nvdec_common::nvhost_nvdec_common(Core::System& system_, NvCore::Container& core_,
NvCore::ChannelType channel_type_)
: nvdevice{system_}, core{core_}, syncpoint_manager{core.GetSyncpointManager()},
nvmap{core.GetNvMapFile()}, channel_type{channel_type_} {
nvhost_nvdec_common::nvhost_nvdec_common(Core::System& system_, NvCore::Container& core_, NvCore::ChannelType channel_type_) :
nvdevice{system_},
core{core_},
syncpoint_manager{core.GetSyncpointManager()},
nvmap{core.GetNvMapFile()},
channel_type{channel_type_}
{
auto& syncpts_accumulated = core.Host1xDeviceFile().syncpts_accumulated;
if (syncpts_accumulated.empty()) {
if (syncpts_accumulated.empty())
{
channel_syncpoint = syncpoint_manager.AllocateSyncpoint(false);
} else {
}
else
{
channel_syncpoint = syncpts_accumulated.front();
syncpts_accumulated.pop_front();
}
}
nvhost_nvdec_common::~nvhost_nvdec_common() {
nvhost_nvdec_common::~nvhost_nvdec_common()
{
core.Host1xDeviceFile().syncpts_accumulated.push_back(channel_syncpoint);
}
NvResult nvhost_nvdec_common::SetNVMAPfd(IoctlSetNvmapFD& params) {
NvResult nvhost_nvdec_common::SetNVMAPfd(IoctlSetNvmapFD& params)
{
LOG_DEBUG(Service_NVDRV, "called, fd={}", params.nvmap_fd);
nvmap_fd = params.nvmap_fd;
return NvResult::Success;
}
NvResult nvhost_nvdec_common::Submit(IoctlSubmit& params, std::span<u8> data, DeviceFD fd) {
NvResult nvhost_nvdec_common::Submit(IoctlSubmit& params, std::span<u8> data, DeviceFD fd)
{
UNIMPLEMENTED();
return NvResult::Success;
}
NvResult nvhost_nvdec_common::GetSyncpoint(IoctlGetSyncpoint& params) {
NvResult nvhost_nvdec_common::GetSyncpoint(IoctlGetSyncpoint& params)
{
LOG_DEBUG(Service_NVDRV, "called GetSyncpoint, id={}", params.param);
params.value = channel_syncpoint;
return NvResult::Success;
}
NvResult nvhost_nvdec_common::GetWaitbase(IoctlGetWaitbase& params) {
NvResult nvhost_nvdec_common::GetWaitbase(IoctlGetWaitbase& params)
{
LOG_CRITICAL(Service_NVDRV, "called WAITBASE");
params.value = 0; // Seems to be hard coded at 0
return NvResult::Success;
}
NvResult nvhost_nvdec_common::MapBuffer(IoctlMapBuffer& params, std::span<MapBufferEntry> entries,
DeviceFD fd) {
NvResult nvhost_nvdec_common::MapBuffer(IoctlMapBuffer& params, std::span<MapBufferEntry> entries, DeviceFD fd)
{
const size_t num_entries = std::min(params.num_entries, static_cast<u32>(entries.size()));
for (size_t i = 0; i < num_entries; i++) {
for (size_t i = 0; i < num_entries; i++)
{
DAddr pin_address = nvmap.PinHandle(entries[i].map_handle, true);
entries[i].map_address = static_cast<u32>(pin_address);
}
return NvResult::Success;
}
NvResult nvhost_nvdec_common::UnmapBuffer(IoctlMapBuffer& params,
std::span<MapBufferEntry> entries) {
NvResult nvhost_nvdec_common::UnmapBuffer(IoctlMapBuffer& params, std::span<MapBufferEntry> entries)
{
const size_t num_entries = std::min(params.num_entries, static_cast<u32>(entries.size()));
for (size_t i = 0; i < num_entries; i++) {
for (size_t i = 0; i < num_entries; i++)
{
nvmap.UnpinHandle(entries[i].map_handle);
entries[i] = {};
}
@ -114,12 +126,14 @@ NvResult nvhost_nvdec_common::UnmapBuffer(IoctlMapBuffer& params,
return NvResult::Success;
}
NvResult nvhost_nvdec_common::SetSubmitTimeout(u32 timeout) {
NvResult nvhost_nvdec_common::SetSubmitTimeout(u32 timeout)
{
LOG_WARNING(Service_NVDRV, "(STUBBED) called");
return NvResult::Success;
}
Kernel::KEvent* nvhost_nvdec_common::QueryEvent(u32 event_id) {
Kernel::KEvent* nvhost_nvdec_common::QueryEvent(u32 event_id)
{
LOG_CRITICAL(Service_NVDRV, "Unknown HOSTX1 Event {}", event_id);
return nullptr;
}

View File

@ -59,31 +59,34 @@ void ServiceFrameworkBase::RegisterHandlersBaseTipc(const FunctionInfoBase* func
}
}
void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx,
const FunctionInfoBase* info) {
void ServiceFrameworkBase::ReportUnimplementedFunction(HLERequestContext& ctx, const FunctionInfoBase* info)
{
auto cmd_buf = ctx.CommandBuffer();
std::string function_name = info == nullptr ? fmt::format("{}", ctx.GetCommand()) : info->name;
fmt::memory_buffer buf;
fmt::format_to(std::back_inserter(buf), "function '{}': port='{}' cmd_buf={{[0]=0x{:X}",
function_name, service_name, cmd_buf[0]);
for (int i = 1; i <= 8; ++i) {
fmt::format_to(std::back_inserter(buf), "function '{}': port='{}' cmd_buf={{[0]=0x{:X}", function_name, service_name, cmd_buf[0]);
for (int i = 1; i <= 8; ++i)
{
fmt::format_to(std::back_inserter(buf), ", [{}]=0x{:X}", i, cmd_buf[i]);
}
buf.push_back('}');
UNIMPLEMENTED_MSG("Unknown / unimplemented {}", fmt::to_string(buf));
if (Settings::values.use_auto_stub) {
if (Settings::values.use_auto_stub)
{
LOG_WARNING(Service, "Using auto stub fallback!");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
}
}
void ServiceFrameworkBase::InvokeRequest(HLERequestContext& ctx) {
void ServiceFrameworkBase::InvokeRequest(HLERequestContext& ctx)
{
auto itr = handlers.find(ctx.GetCommand());
const FunctionInfoBase* info = itr == handlers.end() ? nullptr : &itr->second;
if (info == nullptr || info->handler_callback == nullptr) {
if (info == nullptr || info->handler_callback == nullptr)
{
return ReportUnimplementedFunction(ctx, info);
}
@ -91,13 +94,15 @@ void ServiceFrameworkBase::InvokeRequest(HLERequestContext& ctx) {
handler_invoker(this, info->handler_callback, ctx);
}
void ServiceFrameworkBase::InvokeRequestTipc(HLERequestContext& ctx) {
void ServiceFrameworkBase::InvokeRequestTipc(HLERequestContext& ctx)
{
boost::container::flat_map<u32, FunctionInfoBase>::iterator itr;
itr = handlers_tipc.find(ctx.GetCommand());
const FunctionInfoBase* info = itr == handlers_tipc.end() ? nullptr : &itr->second;
if (info == nullptr || info->handler_callback == nullptr) {
if (info == nullptr || info->handler_callback == nullptr)
{
return ReportUnimplementedFunction(ctx, info);
}

View File

@ -13,7 +13,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace Service
namespace Core {
namespace Core
{
class System;
}
@ -75,7 +76,7 @@ protected:
}
/// System context that the service operates under.
Core::System& system;
Core::System & system;
/// Identifier string used to connect to the service.
std::string service_name;
@ -93,8 +94,7 @@ private:
using InvokerFn = void(ServiceFrameworkBase* object, HandlerFnP<ServiceFrameworkBase> member,
HLERequestContext& ctx);
explicit ServiceFrameworkBase(Core::System& system_, const char* service_name_,
u32 max_sessions_, InvokerFn* handler_invoker_);
explicit ServiceFrameworkBase(Core::System & system_, const char * service_name_, u32 max_sessions_, InvokerFn* handler_invoker_);
~ServiceFrameworkBase() override;
void RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n);
@ -163,9 +163,10 @@ protected:
* @param max_sessions_ Maximum number of sessions that can be connected to this service at the
* same time.
*/
explicit ServiceFramework(Core::System& system_, const char* service_name_,
u32 max_sessions_ = ServerSessionCountMax)
: ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker) {}
explicit ServiceFramework(Core::System & system_, const char * service_name_, u32 max_sessions_ = ServerSessionCountMax) :
ServiceFrameworkBase(system_, service_name_, max_sessions_, Invoker)
{
}
/// Registers handlers in the service.
template <typename T = Self, std::size_t N>

View File

@ -13,17 +13,23 @@
#include "yuzu_video_core/memory_manager.h"
namespace Tegra {
CDmaPusher::CDmaPusher(Host1x::Host1x& host1x_)
: host1x{host1x_}, nvdec_processor(std::make_shared<Host1x::Nvdec>(host1x)),
vic_processor(std::make_unique<Host1x::Vic>(host1x, nvdec_processor)),
host1x_processor(std::make_unique<Host1x::Control>(host1x)),
sync_manager(std::make_unique<Host1x::SyncptIncrManager>(host1x)) {}
CDmaPusher::CDmaPusher(Host1x::Host1x& host1x_) :
host1x{host1x_},
nvdec_processor(std::make_shared<Host1x::Nvdec>(host1x)),
vic_processor(std::make_unique<Host1x::Vic>(host1x, nvdec_processor)),
host1x_processor(std::make_unique<Host1x::Control>(host1x)),
sync_manager(std::make_unique<Host1x::SyncptIncrManager>(host1x))
{
}
CDmaPusher::~CDmaPusher() = default;
void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
for (const auto& value : entries) {
if (mask != 0) {
void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries)
{
for (const auto& value : entries)
{
if (mask != 0)
{
const auto lbs = static_cast<u32>(std::countr_zero(mask));
mask &= ~(1U << lbs);
ExecuteCommand(offset + lbs, value.raw);
@ -67,26 +73,30 @@ void CDmaPusher::ProcessEntries(ChCommandHeaderList&& entries) {
}
}
void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
switch (current_class) {
void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data)
{
switch (current_class)
{
case ChClassId::NvDec:
ThiStateWrite(nvdec_thi_state, offset, data);
switch (static_cast<ThiMethod>(offset)) {
switch (static_cast<ThiMethod>(offset))
{
case ThiMethod::IncSyncpt: {
LOG_DEBUG(Service_NVDRV, "NVDEC Class IncSyncpt Method");
const auto syncpoint_id = static_cast<u32>(data & 0xFF);
const auto cond = static_cast<u32>((data >> 8) & 0xFF);
if (cond == 0) {
if (cond == 0)
{
sync_manager->Increment(syncpoint_id);
} else {
sync_manager->SignalDone(
sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
}
else
{
sync_manager->SignalDone(sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
}
break;
}
case ThiMethod::SetMethod1:
LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}",
static_cast<u32>(nvdec_thi_state.method_0));
LOG_DEBUG(Service_NVDRV, "NVDEC method 0x{:X}", static_cast<u32>(nvdec_thi_state.method_0));
nvdec_processor->ProcessMethod(nvdec_thi_state.method_0, data);
break;
default:
@ -100,19 +110,19 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
LOG_DEBUG(Service_NVDRV, "VIC Class IncSyncpt Method");
const auto syncpoint_id = static_cast<u32>(data & 0xFF);
const auto cond = static_cast<u32>((data >> 8) & 0xFF);
if (cond == 0) {
if (cond == 0)
{
sync_manager->Increment(syncpoint_id);
} else {
sync_manager->SignalDone(
sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
}
else
{
sync_manager->SignalDone(sync_manager->IncrementWhenDone(static_cast<u32>(current_class), syncpoint_id));
}
break;
}
case ThiMethod::SetMethod1:
LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})",
static_cast<u32>(vic_thi_state.method_0), data);
vic_processor->ProcessMethod(static_cast<Host1x::Vic::Method>(vic_thi_state.method_0),
data);
LOG_DEBUG(Service_NVDRV, "VIC method 0x{:X}, Args=({})", static_cast<u32>(vic_thi_state.method_0), data);
vic_processor->ProcessMethod(static_cast<Host1x::Vic::Method>(vic_thi_state.method_0), data);
break;
default:
break;
@ -129,8 +139,9 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) {
}
}
void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument) {
u8* const offset_ptr = reinterpret_cast<u8*>(&state) + sizeof(u32) * state_offset;
void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument)
{
u8 * const offset_ptr = reinterpret_cast<u8 *>(&state) + sizeof(u32) * state_offset;
std::memcpy(offset_ptr, &argument, sizeof(u32));
}

View File

@ -12,31 +12,41 @@
namespace Tegra {
Codec::Codec(Host1x::Host1x& host1x_, const Host1x::NvdecCommon::NvdecRegisters& regs)
: host1x(host1x_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(host1x)),
vp8_decoder(std::make_unique<Decoder::VP8>(host1x)),
vp9_decoder(std::make_unique<Decoder::VP9>(host1x)) {}
Codec::Codec(Host1x::Host1x& host1x_, const Host1x::NvdecCommon::NvdecRegisters& regs) :
host1x(host1x_),
state{regs},
h264_decoder(std::make_unique<Decoder::H264>(host1x)),
vp8_decoder(std::make_unique<Decoder::VP8>(host1x)),
vp9_decoder(std::make_unique<Decoder::VP9>(host1x))
{
}
Codec::~Codec() = default;
void Codec::Initialize() {
void Codec::Initialize()
{
UNIMPLEMENTED();
initialized = false; // decode_api.Initialize(current_codec);
}
void Codec::SetTargetCodec(Host1x::NvdecCommon::VideoCodec codec) {
if (current_codec != codec) {
void Codec::SetTargetCodec(Host1x::NvdecCommon::VideoCodec codec)
{
if (current_codec != codec)
{
current_codec = codec;
LOG_INFO(Service_NVDRV, "NVDEC video codec initialized to {}", GetCurrentCodecName());
}
}
Host1x::NvdecCommon::VideoCodec Codec::GetCurrentCodec() const {
Host1x::NvdecCommon::VideoCodec Codec::GetCurrentCodec() const
{
return current_codec;
}
std::string_view Codec::GetCurrentCodecName() const {
switch (current_codec) {
std::string_view Codec::GetCurrentCodecName() const
{
switch (current_codec)
{
case Host1x::NvdecCommon::VideoCodec::None:
return "None";
case Host1x::NvdecCommon::VideoCodec::H264:

View File

@ -48,9 +48,11 @@ union VicConfig {
BitField<46, 14, u64_le> surface_height_minus1;
};
Vic::Vic(Host1x& host1x_, std::shared_ptr<Nvdec> nvdec_processor_)
: host1x(host1x_),
nvdec_processor(std::move(nvdec_processor_)) {}
Vic::Vic(Host1x& host1x_, std::shared_ptr<Nvdec> nvdec_processor_) :
host1x(host1x_),
nvdec_processor(std::move(nvdec_processor_))
{
}
Vic::~Vic() = default;