recorder.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include <unordered_map>
  7. #include <vector>
  8. #include <boost/crc.hpp>
  9. #include "common/common_types.h"
  10. #include "core/tracer/citrace.h"
  11. namespace CiTrace {
  12. class Recorder {
  13. public:
  14. struct InitialState {
  15. std::vector<u32> gpu_registers;
  16. std::vector<u32> lcd_registers;
  17. std::vector<u32> pica_registers;
  18. std::vector<u32> default_attributes;
  19. std::vector<u32> vs_program_binary;
  20. std::vector<u32> vs_swizzle_data;
  21. std::vector<u32> vs_float_uniforms;
  22. std::vector<u32> gs_program_binary;
  23. std::vector<u32> gs_swizzle_data;
  24. std::vector<u32> gs_float_uniforms;
  25. };
  26. /**
  27. * Recorder constructor
  28. * @param initial_state Initial recorder state
  29. */
  30. Recorder(const InitialState& initial_state);
  31. /// Finish recording of this Citrace and save it using the given filename.
  32. void Finish(const std::string& filename);
  33. /// Mark end of a frame
  34. void FrameFinished();
  35. /**
  36. * Store a copy of the given memory range in the recording.
  37. * @note Use this whenever the GPU is about to access a particular memory region.
  38. * @note The implementation will make sure to minimize redundant memory updates.
  39. */
  40. void MemoryAccessed(const u8* data, u32 size, u32 physical_address);
  41. /**
  42. * Record a register write.
  43. * @note Use this whenever a GPU-related MMIO register has been written to.
  44. */
  45. template <typename T>
  46. void RegisterWritten(u32 physical_address, T value);
  47. private:
  48. // Initial state of recording start
  49. InitialState initial_state;
  50. // Command stream
  51. struct StreamElement {
  52. CTStreamElement data;
  53. /**
  54. * Extra data to store along "core" data.
  55. * This is e.g. used for data used in MemoryUpdates.
  56. */
  57. std::vector<u8> extra_data;
  58. /// Optional CRC hash (e.g. for hashing memory regions)
  59. boost::crc_32_type::value_type hash;
  60. /// If true, refer to data already written to the output file instead of extra_data
  61. bool uses_existing_data;
  62. };
  63. std::vector<StreamElement> stream;
  64. /**
  65. * Internal cache which maps hashes of memory contents to file offsets at which those memory
  66. * contents are stored.
  67. */
  68. std::unordered_map<boost::crc_32_type::value_type /*hash*/, u32 /*file_offset*/> memory_regions;
  69. };
  70. } // namespace