channel_state_cache.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include <deque>
  3. #include <limits>
  4. #include <mutex>
  5. #include <unordered_map>
  6. #include "common/common_types.h"
  7. namespace Tegra {
  8. namespace Engines {
  9. class Maxwell3D;
  10. class KeplerCompute;
  11. } // namespace Engines
  12. class MemoryManager;
  13. namespace Control {
  14. struct ChannelState;
  15. }
  16. } // namespace Tegra
  17. namespace VideoCommon {
  18. class ChannelInfo {
  19. public:
  20. ChannelInfo() = delete;
  21. ChannelInfo(Tegra::Control::ChannelState& state);
  22. ChannelInfo(const ChannelInfo& state) = delete;
  23. ChannelInfo& operator=(const ChannelInfo&) = delete;
  24. ChannelInfo(ChannelInfo&& other) = default;
  25. ChannelInfo& operator=(ChannelInfo&& other) = default;
  26. Tegra::Engines::Maxwell3D& maxwell3d;
  27. Tegra::Engines::KeplerCompute& kepler_compute;
  28. Tegra::MemoryManager& gpu_memory;
  29. };
  30. template <class P>
  31. class ChannelSetupCaches {
  32. public:
  33. /// Operations for seting the channel of execution.
  34. virtual ~ChannelSetupCaches();
  35. /// Create channel state.
  36. virtual void CreateChannel(Tegra::Control::ChannelState& channel);
  37. /// Bind a channel for execution.
  38. void BindToChannel(s32 id);
  39. /// Erase channel's state.
  40. void EraseChannel(s32 id);
  41. Tegra::MemoryManager* GetFromID(size_t id) const {
  42. std::unique_lock<std::mutex> lk(config_mutex);
  43. const auto ref = address_spaces.find(id);
  44. return ref->second.gpu_memory;
  45. }
  46. protected:
  47. static constexpr size_t UNSET_CHANNEL{std::numeric_limits<size_t>::max()};
  48. P* channel_state;
  49. size_t current_channel_id{UNSET_CHANNEL};
  50. size_t current_address_space{};
  51. Tegra::Engines::Maxwell3D* maxwell3d;
  52. Tegra::Engines::KeplerCompute* kepler_compute;
  53. Tegra::MemoryManager* gpu_memory;
  54. std::deque<P> channel_storage;
  55. std::deque<size_t> free_channel_ids;
  56. std::unordered_map<s32, size_t> channel_map;
  57. std::vector<size_t> active_channel_ids;
  58. struct AddresSpaceRef {
  59. size_t ref_count;
  60. size_t storage_id;
  61. Tegra::MemoryManager* gpu_memory;
  62. };
  63. std::unordered_map<size_t, AddresSpaceRef> address_spaces;
  64. mutable std::mutex config_mutex;
  65. virtual void OnGPUASRegister([[maybe_unused]] size_t map_id) {}
  66. };
  67. } // namespace VideoCommon