2022-06-30 01:27:49 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2022-01-30 10:31:13 +01:00
|
|
|
|
2021-11-05 15:52:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <limits>
|
2021-12-17 16:45:06 +01:00
|
|
|
#include <mutex>
|
2022-01-01 22:03:37 +01:00
|
|
|
#include <optional>
|
2021-11-05 15:52:31 +01:00
|
|
|
#include <unordered_map>
|
2022-06-16 02:12:21 +02:00
|
|
|
#include <vector>
|
2021-11-05 15:52:31 +01:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
|
|
namespace Tegra {
|
|
|
|
|
|
|
|
namespace Engines {
|
|
|
|
class Maxwell3D;
|
|
|
|
class KeplerCompute;
|
|
|
|
} // namespace Engines
|
|
|
|
|
|
|
|
class MemoryManager;
|
|
|
|
|
|
|
|
namespace Control {
|
|
|
|
struct ChannelState;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tegra
|
|
|
|
|
|
|
|
namespace VideoCommon {
|
|
|
|
|
|
|
|
class ChannelInfo {
|
|
|
|
public:
|
|
|
|
ChannelInfo() = delete;
|
2022-09-01 05:45:22 +02:00
|
|
|
explicit ChannelInfo(Tegra::Control::ChannelState& state);
|
2021-11-05 15:52:31 +01:00
|
|
|
ChannelInfo(const ChannelInfo& state) = delete;
|
|
|
|
ChannelInfo& operator=(const ChannelInfo&) = delete;
|
|
|
|
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d;
|
|
|
|
Tegra::Engines::KeplerCompute& kepler_compute;
|
|
|
|
Tegra::MemoryManager& gpu_memory;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class P>
|
|
|
|
class ChannelSetupCaches {
|
|
|
|
public:
|
2023-03-12 04:10:38 +01:00
|
|
|
/// Operations for setting the channel of execution.
|
2021-12-17 16:45:06 +01:00
|
|
|
virtual ~ChannelSetupCaches();
|
2021-11-05 15:52:31 +01:00
|
|
|
|
|
|
|
/// Create channel state.
|
2021-12-17 16:45:06 +01:00
|
|
|
virtual void CreateChannel(Tegra::Control::ChannelState& channel);
|
2021-11-05 15:52:31 +01:00
|
|
|
|
|
|
|
/// Bind a channel for execution.
|
|
|
|
void BindToChannel(s32 id);
|
|
|
|
|
|
|
|
/// Erase channel's state.
|
|
|
|
void EraseChannel(s32 id);
|
|
|
|
|
2021-12-17 16:45:06 +01:00
|
|
|
Tegra::MemoryManager* GetFromID(size_t id) const {
|
|
|
|
std::unique_lock<std::mutex> lk(config_mutex);
|
|
|
|
const auto ref = address_spaces.find(id);
|
|
|
|
return ref->second.gpu_memory;
|
|
|
|
}
|
|
|
|
|
2022-01-01 22:03:37 +01:00
|
|
|
std::optional<size_t> getStorageID(size_t id) const {
|
|
|
|
std::unique_lock<std::mutex> lk(config_mutex);
|
|
|
|
const auto ref = address_spaces.find(id);
|
|
|
|
if (ref == address_spaces.end()) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return ref->second.storage_id;
|
|
|
|
}
|
|
|
|
|
2021-11-05 15:52:31 +01:00
|
|
|
protected:
|
|
|
|
static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()};
|
|
|
|
|
|
|
|
P* channel_state;
|
|
|
|
size_t current_channel_id{UNSET_CHANNEL};
|
2021-12-17 16:45:06 +01:00
|
|
|
size_t current_address_space{};
|
2021-11-05 15:52:31 +01:00
|
|
|
Tegra::Engines::Maxwell3D* maxwell3d;
|
|
|
|
Tegra::Engines::KeplerCompute* kepler_compute;
|
|
|
|
Tegra::MemoryManager* gpu_memory;
|
2021-12-17 16:45:06 +01:00
|
|
|
|
|
|
|
std::deque<P> channel_storage;
|
|
|
|
std::deque<size_t> free_channel_ids;
|
|
|
|
std::unordered_map<s32, size_t> channel_map;
|
2021-12-23 01:40:45 +01:00
|
|
|
std::vector<size_t> active_channel_ids;
|
2021-12-17 16:45:06 +01:00
|
|
|
struct AddresSpaceRef {
|
|
|
|
size_t ref_count;
|
|
|
|
size_t storage_id;
|
|
|
|
Tegra::MemoryManager* gpu_memory;
|
|
|
|
};
|
|
|
|
std::unordered_map<size_t, AddresSpaceRef> address_spaces;
|
|
|
|
mutable std::mutex config_mutex;
|
|
|
|
|
|
|
|
virtual void OnGPUASRegister([[maybe_unused]] size_t map_id) {}
|
2021-11-05 15:52:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace VideoCommon
|