nvdec_common.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "common/bit_field.h"
  5. #include "common/common_funcs.h"
  6. #include "common/common_types.h"
  7. namespace Tegra::Host1x::NvdecCommon {
  8. enum class VideoCodec : u64 {
  9. None = 0x0,
  10. H264 = 0x3,
  11. VP8 = 0x5,
  12. H265 = 0x7,
  13. VP9 = 0x9,
  14. };
  15. // NVDEC should use a 32-bit address space, but is mapped to 64-bit,
  16. // doubling the sizes here is compensating for that.
  17. struct NvdecRegisters {
  18. static constexpr std::size_t NUM_REGS = 0x178;
  19. union {
  20. struct {
  21. INSERT_PADDING_WORDS_NOINIT(256); ///< 0x0000
  22. VideoCodec set_codec_id; ///< 0x0400
  23. INSERT_PADDING_WORDS_NOINIT(126); ///< 0x0408
  24. u64 execute; ///< 0x0600
  25. INSERT_PADDING_WORDS_NOINIT(126); ///< 0x0608
  26. struct { ///< 0x0800
  27. union {
  28. BitField<0, 3, VideoCodec> codec;
  29. BitField<4, 1, u64> gp_timer_on;
  30. BitField<13, 1, u64> mb_timer_on;
  31. BitField<14, 1, u64> intra_frame_pslc;
  32. BitField<17, 1, u64> all_intra_frame;
  33. };
  34. } control_params;
  35. u64 picture_info_offset; ///< 0x0808
  36. u64 frame_bitstream_offset; ///< 0x0810
  37. u64 frame_number; ///< 0x0818
  38. u64 h264_slice_data_offsets; ///< 0x0820
  39. u64 h264_mv_dump_offset; ///< 0x0828
  40. INSERT_PADDING_WORDS_NOINIT(6); ///< 0x0830
  41. u64 frame_stats_offset; ///< 0x0848
  42. u64 h264_last_surface_luma_offset; ///< 0x0850
  43. u64 h264_last_surface_chroma_offset; ///< 0x0858
  44. std::array<u64, 17> surface_luma_offset; ///< 0x0860
  45. std::array<u64, 17> surface_chroma_offset; ///< 0x08E8
  46. INSERT_PADDING_WORDS_NOINIT(68); ///< 0x0970
  47. u64 vp8_prob_data_offset; ///< 0x0A80
  48. u64 vp8_header_partition_buf_offset; ///< 0x0A88
  49. INSERT_PADDING_WORDS_NOINIT(60); ///< 0x0A90
  50. u64 vp9_entropy_probs_offset; ///< 0x0B80
  51. u64 vp9_backward_updates_offset; ///< 0x0B88
  52. u64 vp9_last_frame_segmap_offset; ///< 0x0B90
  53. u64 vp9_curr_frame_segmap_offset; ///< 0x0B98
  54. INSERT_PADDING_WORDS_NOINIT(2); ///< 0x0BA0
  55. u64 vp9_last_frame_mvs_offset; ///< 0x0BA8
  56. u64 vp9_curr_frame_mvs_offset; ///< 0x0BB0
  57. INSERT_PADDING_WORDS_NOINIT(2); ///< 0x0BB8
  58. };
  59. std::array<u64, NUM_REGS> reg_array;
  60. };
  61. };
  62. static_assert(sizeof(NvdecRegisters) == (0xBC0), "NvdecRegisters is incorrect size");
  63. #define ASSERT_REG_POSITION(field_name, position) \
  64. static_assert(offsetof(NvdecRegisters, field_name) == position * sizeof(u64), \
  65. "Field " #field_name " has invalid position")
  66. ASSERT_REG_POSITION(set_codec_id, 0x80);
  67. ASSERT_REG_POSITION(execute, 0xC0);
  68. ASSERT_REG_POSITION(control_params, 0x100);
  69. ASSERT_REG_POSITION(picture_info_offset, 0x101);
  70. ASSERT_REG_POSITION(frame_bitstream_offset, 0x102);
  71. ASSERT_REG_POSITION(frame_number, 0x103);
  72. ASSERT_REG_POSITION(h264_slice_data_offsets, 0x104);
  73. ASSERT_REG_POSITION(frame_stats_offset, 0x109);
  74. ASSERT_REG_POSITION(h264_last_surface_luma_offset, 0x10A);
  75. ASSERT_REG_POSITION(h264_last_surface_chroma_offset, 0x10B);
  76. ASSERT_REG_POSITION(surface_luma_offset, 0x10C);
  77. ASSERT_REG_POSITION(surface_chroma_offset, 0x11D);
  78. ASSERT_REG_POSITION(vp8_prob_data_offset, 0x150);
  79. ASSERT_REG_POSITION(vp8_header_partition_buf_offset, 0x151);
  80. ASSERT_REG_POSITION(vp9_entropy_probs_offset, 0x170);
  81. ASSERT_REG_POSITION(vp9_backward_updates_offset, 0x171);
  82. ASSERT_REG_POSITION(vp9_last_frame_segmap_offset, 0x172);
  83. ASSERT_REG_POSITION(vp9_curr_frame_segmap_offset, 0x173);
  84. ASSERT_REG_POSITION(vp9_last_frame_mvs_offset, 0x175);
  85. ASSERT_REG_POSITION(vp9_curr_frame_mvs_offset, 0x176);
  86. #undef ASSERT_REG_POSITION
  87. } // namespace Tegra::Host1x::NvdecCommon