recorder.h 2.5 KB

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