diff options
Diffstat (limited to 'src/video_core/control')
| -rw-r--r-- | src/video_core/control/channel_state_cache.cpp | 8 | ||||
| -rw-r--r-- | src/video_core/control/channel_state_cache.h | 28 | ||||
| -rw-r--r-- | src/video_core/control/channel_state_cache.inc | 23 |
3 files changed, 49 insertions, 10 deletions
diff --git a/src/video_core/control/channel_state_cache.cpp b/src/video_core/control/channel_state_cache.cpp index f72a97b2f..ec7ba907c 100644 --- a/src/video_core/control/channel_state_cache.cpp +++ b/src/video_core/control/channel_state_cache.cpp | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | #include "video_core/control/channel_state_cache.inc" | 1 | #include "video_core/control/channel_state_cache.inc" |
| 2 | 2 | ||
| 3 | namespace VideoCommon { | 3 | namespace VideoCommon { |
| 4 | |||
| 5 | ChannelInfo::ChannelInfo(Tegra::Control::ChannelState& channel_state) | ||
| 6 | : maxwell3d{*channel_state.maxwell_3d}, kepler_compute{*channel_state.kepler_compute}, | ||
| 7 | gpu_memory{*channel_state.memory_manager} {} | ||
| 8 | |||
| 4 | template class VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo>; | 9 | template class VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo>; |
| 5 | } | 10 | |
| 11 | } // namespace VideoCommon | ||
diff --git a/src/video_core/control/channel_state_cache.h b/src/video_core/control/channel_state_cache.h index c8298c003..c51040c83 100644 --- a/src/video_core/control/channel_state_cache.h +++ b/src/video_core/control/channel_state_cache.h | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | #include <deque> | 3 | #include <deque> |
| 4 | #include <limits> | 4 | #include <limits> |
| 5 | #include <mutex> | ||
| 5 | #include <unordered_map> | 6 | #include <unordered_map> |
| 6 | 7 | ||
| 7 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| @@ -41,9 +42,10 @@ template <class P> | |||
| 41 | class ChannelSetupCaches { | 42 | class ChannelSetupCaches { |
| 42 | public: | 43 | public: |
| 43 | /// Operations for seting the channel of execution. | 44 | /// Operations for seting the channel of execution. |
| 45 | virtual ~ChannelSetupCaches(); | ||
| 44 | 46 | ||
| 45 | /// Create channel state. | 47 | /// Create channel state. |
| 46 | void CreateChannel(Tegra::Control::ChannelState& channel); | 48 | virtual void CreateChannel(Tegra::Control::ChannelState& channel); |
| 47 | 49 | ||
| 48 | /// Bind a channel for execution. | 50 | /// Bind a channel for execution. |
| 49 | void BindToChannel(s32 id); | 51 | void BindToChannel(s32 id); |
| @@ -51,18 +53,34 @@ public: | |||
| 51 | /// Erase channel's state. | 53 | /// Erase channel's state. |
| 52 | void EraseChannel(s32 id); | 54 | void EraseChannel(s32 id); |
| 53 | 55 | ||
| 56 | Tegra::MemoryManager* GetFromID(size_t id) const { | ||
| 57 | std::unique_lock<std::mutex> lk(config_mutex); | ||
| 58 | const auto ref = address_spaces.find(id); | ||
| 59 | return ref->second.gpu_memory; | ||
| 60 | } | ||
| 61 | |||
| 54 | protected: | 62 | protected: |
| 55 | static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()}; | 63 | static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()}; |
| 56 | 64 | ||
| 57 | std::deque<P> channel_storage; | ||
| 58 | std::deque<size_t> free_channel_ids; | ||
| 59 | std::unordered_map<s32, size_t> channel_map; | ||
| 60 | |||
| 61 | P* channel_state; | 65 | P* channel_state; |
| 62 | size_t current_channel_id{UNSET_CHANNEL}; | 66 | size_t current_channel_id{UNSET_CHANNEL}; |
| 67 | size_t current_address_space{}; | ||
| 63 | Tegra::Engines::Maxwell3D* maxwell3d; | 68 | Tegra::Engines::Maxwell3D* maxwell3d; |
| 64 | Tegra::Engines::KeplerCompute* kepler_compute; | 69 | Tegra::Engines::KeplerCompute* kepler_compute; |
| 65 | Tegra::MemoryManager* gpu_memory; | 70 | Tegra::MemoryManager* gpu_memory; |
| 71 | |||
| 72 | std::deque<P> channel_storage; | ||
| 73 | std::deque<size_t> free_channel_ids; | ||
| 74 | std::unordered_map<s32, size_t> channel_map; | ||
| 75 | struct AddresSpaceRef { | ||
| 76 | size_t ref_count; | ||
| 77 | size_t storage_id; | ||
| 78 | Tegra::MemoryManager* gpu_memory; | ||
| 79 | }; | ||
| 80 | std::unordered_map<size_t, AddresSpaceRef> address_spaces; | ||
| 81 | mutable std::mutex config_mutex; | ||
| 82 | |||
| 83 | virtual void OnGPUASRegister([[maybe_unused]] size_t map_id) {} | ||
| 66 | }; | 84 | }; |
| 67 | 85 | ||
| 68 | } // namespace VideoCommon | 86 | } // namespace VideoCommon |
diff --git a/src/video_core/control/channel_state_cache.inc b/src/video_core/control/channel_state_cache.inc index 3eb73af9f..185eabc35 100644 --- a/src/video_core/control/channel_state_cache.inc +++ b/src/video_core/control/channel_state_cache.inc | |||
| @@ -6,18 +6,18 @@ | |||
| 6 | 6 | ||
| 7 | namespace VideoCommon { | 7 | namespace VideoCommon { |
| 8 | 8 | ||
| 9 | ChannelInfo::ChannelInfo(Tegra::Control::ChannelState& channel_state) | 9 | template <class P> |
| 10 | : maxwell3d{*channel_state.maxwell_3d}, kepler_compute{*channel_state.kepler_compute}, | 10 | ChannelSetupCaches<P>::~ChannelSetupCaches() = default; |
| 11 | gpu_memory{*channel_state.memory_manager} {} | ||
| 12 | 11 | ||
| 13 | template <class P> | 12 | template <class P> |
| 14 | void ChannelSetupCaches<P>::CreateChannel(struct Tegra::Control::ChannelState& channel) { | 13 | void ChannelSetupCaches<P>::CreateChannel(struct Tegra::Control::ChannelState& channel) { |
| 14 | std::unique_lock<std::mutex> lk(config_mutex); | ||
| 15 | ASSERT(channel_map.find(channel.bind_id) == channel_map.end() && channel.bind_id >= 0); | 15 | ASSERT(channel_map.find(channel.bind_id) == channel_map.end() && channel.bind_id >= 0); |
| 16 | auto new_id = [this, &channel]() { | 16 | auto new_id = [this, &channel]() { |
| 17 | if (!free_channel_ids.empty()) { | 17 | if (!free_channel_ids.empty()) { |
| 18 | auto id = free_channel_ids.front(); | 18 | auto id = free_channel_ids.front(); |
| 19 | free_channel_ids.pop_front(); | 19 | free_channel_ids.pop_front(); |
| 20 | new (&channel_storage[id]) ChannelInfo(channel); | 20 | new (&channel_storage[id]) P(channel); |
| 21 | return id; | 21 | return id; |
| 22 | } | 22 | } |
| 23 | channel_storage.emplace_back(channel); | 23 | channel_storage.emplace_back(channel); |
| @@ -27,11 +27,24 @@ void ChannelSetupCaches<P>::CreateChannel(struct Tegra::Control::ChannelState& c | |||
| 27 | if (current_channel_id != UNSET_CHANNEL) { | 27 | if (current_channel_id != UNSET_CHANNEL) { |
| 28 | channel_state = &channel_storage[current_channel_id]; | 28 | channel_state = &channel_storage[current_channel_id]; |
| 29 | } | 29 | } |
| 30 | auto as_it = address_spaces.find(channel.memory_manager->GetID()); | ||
| 31 | if (as_it != address_spaces.end()) { | ||
| 32 | as_it->second.ref_count++; | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | AddresSpaceRef new_gpu_mem_ref{ | ||
| 36 | .ref_count = 1, | ||
| 37 | .storage_id = address_spaces.size(), | ||
| 38 | .gpu_memory = channel.memory_manager.get(), | ||
| 39 | }; | ||
| 40 | address_spaces.emplace(channel.memory_manager->GetID(), new_gpu_mem_ref); | ||
| 41 | OnGPUASRegister(channel.memory_manager->GetID()); | ||
| 30 | } | 42 | } |
| 31 | 43 | ||
| 32 | /// Bind a channel for execution. | 44 | /// Bind a channel for execution. |
| 33 | template <class P> | 45 | template <class P> |
| 34 | void ChannelSetupCaches<P>::BindToChannel(s32 id) { | 46 | void ChannelSetupCaches<P>::BindToChannel(s32 id) { |
| 47 | std::unique_lock<std::mutex> lk(config_mutex); | ||
| 35 | auto it = channel_map.find(id); | 48 | auto it = channel_map.find(id); |
| 36 | ASSERT(it != channel_map.end() && id >= 0); | 49 | ASSERT(it != channel_map.end() && id >= 0); |
| 37 | current_channel_id = it->second; | 50 | current_channel_id = it->second; |
| @@ -39,11 +52,13 @@ void ChannelSetupCaches<P>::BindToChannel(s32 id) { | |||
| 39 | maxwell3d = &channel_state->maxwell3d; | 52 | maxwell3d = &channel_state->maxwell3d; |
| 40 | kepler_compute = &channel_state->kepler_compute; | 53 | kepler_compute = &channel_state->kepler_compute; |
| 41 | gpu_memory = &channel_state->gpu_memory; | 54 | gpu_memory = &channel_state->gpu_memory; |
| 55 | current_address_space = gpu_memory->GetID(); | ||
| 42 | } | 56 | } |
| 43 | 57 | ||
| 44 | /// Erase channel's channel_state. | 58 | /// Erase channel's channel_state. |
| 45 | template <class P> | 59 | template <class P> |
| 46 | void ChannelSetupCaches<P>::EraseChannel(s32 id) { | 60 | void ChannelSetupCaches<P>::EraseChannel(s32 id) { |
| 61 | std::unique_lock<std::mutex> lk(config_mutex); | ||
| 47 | const auto it = channel_map.find(id); | 62 | const auto it = channel_map.find(id); |
| 48 | ASSERT(it != channel_map.end() && id >= 0); | 63 | ASSERT(it != channel_map.end() && id >= 0); |
| 49 | const auto this_id = it->second; | 64 | const auto this_id = it->second; |