summaryrefslogtreecommitdiff
path: root/src/video_core/host1x/codecs
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2022-01-30 22:26:01 +0100
committerGravatar Fernando Sahmkow2022-10-06 21:00:52 +0200
commit2931101e6f5aa755566ef40f6e6dc71909fd3e92 (patch)
tree76e847786e355e24a136562d42177b895a03315e /src/video_core/host1x/codecs
parentVideoCore: Refactor syncing. (diff)
downloadyuzu-2931101e6f5aa755566ef40f6e6dc71909fd3e92.tar.gz
yuzu-2931101e6f5aa755566ef40f6e6dc71909fd3e92.tar.xz
yuzu-2931101e6f5aa755566ef40f6e6dc71909fd3e92.zip
NVDRV: Refactor Host1x
Diffstat (limited to 'src/video_core/host1x/codecs')
-rw-r--r--src/video_core/host1x/codecs/codec.cpp10
-rw-r--r--src/video_core/host1x/codecs/codec.h9
-rw-r--r--src/video_core/host1x/codecs/h264.cpp13
-rw-r--r--src/video_core/host1x/codecs/h264.h10
-rw-r--r--src/video_core/host1x/codecs/vp8.cpp8
-rw-r--r--src/video_core/host1x/codecs/vp8.h10
-rw-r--r--src/video_core/host1x/codecs/vp9.cpp12
-rw-r--r--src/video_core/host1x/codecs/vp9.h10
-rw-r--r--src/video_core/host1x/codecs/vp9_types.h1
9 files changed, 49 insertions, 34 deletions
diff --git a/src/video_core/host1x/codecs/codec.cpp b/src/video_core/host1x/codecs/codec.cpp
index 70c47ae03..42e7d6e4f 100644
--- a/src/video_core/host1x/codecs/codec.cpp
+++ b/src/video_core/host1x/codecs/codec.cpp
@@ -6,11 +6,11 @@
6#include <vector> 6#include <vector>
7#include "common/assert.h" 7#include "common/assert.h"
8#include "common/settings.h" 8#include "common/settings.h"
9#include "video_core/gpu.h"
10#include "video_core/host1x/codecs/codec.h" 9#include "video_core/host1x/codecs/codec.h"
11#include "video_core/host1x/codecs/h264.h" 10#include "video_core/host1x/codecs/h264.h"
12#include "video_core/host1x/codecs/vp8.h" 11#include "video_core/host1x/codecs/vp8.h"
13#include "video_core/host1x/codecs/vp9.h" 12#include "video_core/host1x/codecs/vp9.h"
13#include "video_core/host1x/host1x.h"
14#include "video_core/memory_manager.h" 14#include "video_core/memory_manager.h"
15 15
16extern "C" { 16extern "C" {
@@ -73,10 +73,10 @@ void AVFrameDeleter(AVFrame* ptr) {
73 av_frame_free(&ptr); 73 av_frame_free(&ptr);
74} 74}
75 75
76Codec::Codec(GPU& gpu_, const Host1x::NvdecCommon::NvdecRegisters& regs) 76Codec::Codec(Host1x::Host1x& host1x_, const Host1x::NvdecCommon::NvdecRegisters& regs)
77 : gpu(gpu_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(gpu)), 77 : host1x(host1x_), state{regs}, h264_decoder(std::make_unique<Decoder::H264>(host1x)),
78 vp8_decoder(std::make_unique<Decoder::VP8>(gpu)), 78 vp8_decoder(std::make_unique<Decoder::VP8>(host1x)),
79 vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {} 79 vp9_decoder(std::make_unique<Decoder::VP9>(host1x)) {}
80 80
81Codec::~Codec() { 81Codec::~Codec() {
82 if (!initialized) { 82 if (!initialized) {
diff --git a/src/video_core/host1x/codecs/codec.h b/src/video_core/host1x/codecs/codec.h
index 117cb3ccd..0d45fb7fe 100644
--- a/src/video_core/host1x/codecs/codec.h
+++ b/src/video_core/host1x/codecs/codec.h
@@ -21,7 +21,6 @@ extern "C" {
21} 21}
22 22
23namespace Tegra { 23namespace Tegra {
24class GPU;
25 24
26void AVFrameDeleter(AVFrame* ptr); 25void AVFrameDeleter(AVFrame* ptr);
27using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>; 26using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>;
@@ -32,9 +31,13 @@ class VP8;
32class VP9; 31class VP9;
33} // namespace Decoder 32} // namespace Decoder
34 33
34namespace Host1x {
35class Host1x;
36} // namespace Host1x
37
35class Codec { 38class Codec {
36public: 39public:
37 explicit Codec(GPU& gpu, const Host1x::NvdecCommon::NvdecRegisters& regs); 40 explicit Codec(Host1x::Host1x& host1x, const Host1x::NvdecCommon::NvdecRegisters& regs);
38 ~Codec(); 41 ~Codec();
39 42
40 /// Initialize the codec, returning success or failure 43 /// Initialize the codec, returning success or failure
@@ -69,7 +72,7 @@ private:
69 AVCodecContext* av_codec_ctx{nullptr}; 72 AVCodecContext* av_codec_ctx{nullptr};
70 AVBufferRef* av_gpu_decoder{nullptr}; 73 AVBufferRef* av_gpu_decoder{nullptr};
71 74
72 GPU& gpu; 75 Host1x::Host1x& host1x;
73 const Host1x::NvdecCommon::NvdecRegisters& state; 76 const Host1x::NvdecCommon::NvdecRegisters& state;
74 std::unique_ptr<Decoder::H264> h264_decoder; 77 std::unique_ptr<Decoder::H264> h264_decoder;
75 std::unique_ptr<Decoder::VP8> vp8_decoder; 78 std::unique_ptr<Decoder::VP8> vp8_decoder;
diff --git a/src/video_core/host1x/codecs/h264.cpp b/src/video_core/host1x/codecs/h264.cpp
index 95534bc85..e87bd65fa 100644
--- a/src/video_core/host1x/codecs/h264.cpp
+++ b/src/video_core/host1x/codecs/h264.cpp
@@ -5,8 +5,8 @@
5#include <bit> 5#include <bit>
6 6
7#include "common/settings.h" 7#include "common/settings.h"
8#include "video_core/gpu.h"
9#include "video_core/host1x/codecs/h264.h" 8#include "video_core/host1x/codecs/h264.h"
9#include "video_core/host1x/host1x.h"
10#include "video_core/memory_manager.h" 10#include "video_core/memory_manager.h"
11 11
12namespace Tegra::Decoder { 12namespace Tegra::Decoder {
@@ -24,19 +24,20 @@ constexpr std::array<u8, 16> zig_zag_scan{
24}; 24};
25} // Anonymous namespace 25} // Anonymous namespace
26 26
27H264::H264(GPU& gpu_) : gpu(gpu_) {} 27H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {}
28 28
29H264::~H264() = default; 29H264::~H264() = default;
30 30
31const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, 31const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
32 bool is_first_frame) { 32 bool is_first_frame) {
33 H264DecoderContext context; 33 H264DecoderContext context;
34 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext)); 34 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context,
35 sizeof(H264DecoderContext));
35 36
36 const s64 frame_number = context.h264_parameter_set.frame_number.Value(); 37 const s64 frame_number = context.h264_parameter_set.frame_number.Value();
37 if (!is_first_frame && frame_number != 0) { 38 if (!is_first_frame && frame_number != 0) {
38 frame.resize(context.stream_len); 39 frame.resize(context.stream_len);
39 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); 40 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size());
40 return frame; 41 return frame;
41 } 42 }
42 43
@@ -155,8 +156,8 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist
155 frame.resize(encoded_header.size() + context.stream_len); 156 frame.resize(encoded_header.size() + context.stream_len);
156 std::memcpy(frame.data(), encoded_header.data(), encoded_header.size()); 157 std::memcpy(frame.data(), encoded_header.data(), encoded_header.size());
157 158
158 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, 159 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset,
159 frame.data() + encoded_header.size(), context.stream_len); 160 frame.data() + encoded_header.size(), context.stream_len);
160 161
161 return frame; 162 return frame;
162} 163}
diff --git a/src/video_core/host1x/codecs/h264.h b/src/video_core/host1x/codecs/h264.h
index a98730474..5cc86454e 100644
--- a/src/video_core/host1x/codecs/h264.h
+++ b/src/video_core/host1x/codecs/h264.h
@@ -11,7 +11,11 @@
11#include "video_core/host1x/nvdec_common.h" 11#include "video_core/host1x/nvdec_common.h"
12 12
13namespace Tegra { 13namespace Tegra {
14class GPU; 14
15namespace Host1x {
16class Host1x;
17} // namespace Host1x
18
15namespace Decoder { 19namespace Decoder {
16 20
17class H264BitWriter { 21class H264BitWriter {
@@ -55,7 +59,7 @@ private:
55 59
56class H264 { 60class H264 {
57public: 61public:
58 explicit H264(GPU& gpu); 62 explicit H264(Host1x::Host1x& host1x);
59 ~H264(); 63 ~H264();
60 64
61 /// Compose the H264 frame for FFmpeg decoding 65 /// Compose the H264 frame for FFmpeg decoding
@@ -64,7 +68,7 @@ public:
64 68
65private: 69private:
66 std::vector<u8> frame; 70 std::vector<u8> frame;
67 GPU& gpu; 71 Host1x::Host1x& host1x;
68 72
69 struct H264ParameterSet { 73 struct H264ParameterSet {
70 s32 log2_max_pic_order_cnt_lsb_minus4; ///< 0x00 74 s32 log2_max_pic_order_cnt_lsb_minus4; ///< 0x00
diff --git a/src/video_core/host1x/codecs/vp8.cpp b/src/video_core/host1x/codecs/vp8.cpp
index aac026e17..28fb12cb8 100644
--- a/src/video_core/host1x/codecs/vp8.cpp
+++ b/src/video_core/host1x/codecs/vp8.cpp
@@ -3,18 +3,18 @@
3 3
4#include <vector> 4#include <vector>
5 5
6#include "video_core/gpu.h"
7#include "video_core/host1x/codecs/vp8.h" 6#include "video_core/host1x/codecs/vp8.h"
7#include "video_core/host1x/host1x.h"
8#include "video_core/memory_manager.h" 8#include "video_core/memory_manager.h"
9 9
10namespace Tegra::Decoder { 10namespace Tegra::Decoder {
11VP8::VP8(GPU& gpu_) : gpu(gpu_) {} 11VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {}
12 12
13VP8::~VP8() = default; 13VP8::~VP8() = default;
14 14
15const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { 15const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
16 VP8PictureInfo info; 16 VP8PictureInfo info;
17 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); 17 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo));
18 18
19 const bool is_key_frame = info.key_frame == 1u; 19 const bool is_key_frame = info.key_frame == 1u;
20 const auto bitstream_size = static_cast<size_t>(info.vld_buffer_size); 20 const auto bitstream_size = static_cast<size_t>(info.vld_buffer_size);
@@ -45,7 +45,7 @@ const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegiste
45 frame[9] = static_cast<u8>(((info.frame_height >> 8) & 0x3f)); 45 frame[9] = static_cast<u8>(((info.frame_height >> 8) & 0x3f));
46 } 46 }
47 const u64 bitstream_offset = state.frame_bitstream_offset; 47 const u64 bitstream_offset = state.frame_bitstream_offset;
48 gpu.MemoryManager().ReadBlock(bitstream_offset, frame.data() + header_size, bitstream_size); 48 host1x.MemoryManager().ReadBlock(bitstream_offset, frame.data() + header_size, bitstream_size);
49 49
50 return frame; 50 return frame;
51} 51}
diff --git a/src/video_core/host1x/codecs/vp8.h b/src/video_core/host1x/codecs/vp8.h
index a1dfa5f03..5bf07ecab 100644
--- a/src/video_core/host1x/codecs/vp8.h
+++ b/src/video_core/host1x/codecs/vp8.h
@@ -11,12 +11,16 @@
11#include "video_core/host1x/nvdec_common.h" 11#include "video_core/host1x/nvdec_common.h"
12 12
13namespace Tegra { 13namespace Tegra {
14class GPU; 14
15namespace Host1x {
16class Host1x;
17} // namespace Host1x
18
15namespace Decoder { 19namespace Decoder {
16 20
17class VP8 { 21class VP8 {
18public: 22public:
19 explicit VP8(GPU& gpu); 23 explicit VP8(Host1x::Host1x& host1x);
20 ~VP8(); 24 ~VP8();
21 25
22 /// Compose the VP8 frame for FFmpeg decoding 26 /// Compose the VP8 frame for FFmpeg decoding
@@ -25,7 +29,7 @@ public:
25 29
26private: 30private:
27 std::vector<u8> frame; 31 std::vector<u8> frame;
28 GPU& gpu; 32 Host1x::Host1x& host1x;
29 33
30 struct VP8PictureInfo { 34 struct VP8PictureInfo {
31 INSERT_PADDING_WORDS_NOINIT(14); 35 INSERT_PADDING_WORDS_NOINIT(14);
diff --git a/src/video_core/host1x/codecs/vp9.cpp b/src/video_core/host1x/codecs/vp9.cpp
index bc50c6ba4..667aadc6a 100644
--- a/src/video_core/host1x/codecs/vp9.cpp
+++ b/src/video_core/host1x/codecs/vp9.cpp
@@ -4,8 +4,8 @@
4#include <algorithm> // for std::copy 4#include <algorithm> // for std::copy
5#include <numeric> 5#include <numeric>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "video_core/gpu.h"
8#include "video_core/host1x/codecs/vp9.h" 7#include "video_core/host1x/codecs/vp9.h"
8#include "video_core/host1x/host1x.h"
9#include "video_core/memory_manager.h" 9#include "video_core/memory_manager.h"
10 10
11namespace Tegra::Decoder { 11namespace Tegra::Decoder {
@@ -236,7 +236,7 @@ constexpr std::array<u8, 254> map_lut{
236} 236}
237} // Anonymous namespace 237} // Anonymous namespace
238 238
239VP9::VP9(GPU& gpu_) : gpu{gpu_} {} 239VP9::VP9(Host1x::Host1x& host1x_) : host1x{host1x_} {}
240 240
241VP9::~VP9() = default; 241VP9::~VP9() = default;
242 242
@@ -357,7 +357,7 @@ void VP9::WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_
357 357
358Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters& state) { 358Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters& state) {
359 PictureInfo picture_info; 359 PictureInfo picture_info;
360 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo)); 360 host1x.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo));
361 Vp9PictureInfo vp9_info = picture_info.Convert(); 361 Vp9PictureInfo vp9_info = picture_info.Convert();
362 362
363 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy); 363 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy);
@@ -372,17 +372,17 @@ Vp9PictureInfo VP9::GetVp9PictureInfo(const Host1x::NvdecCommon::NvdecRegisters&
372 372
373void VP9::InsertEntropy(u64 offset, Vp9EntropyProbs& dst) { 373void VP9::InsertEntropy(u64 offset, Vp9EntropyProbs& dst) {
374 EntropyProbs entropy; 374 EntropyProbs entropy;
375 gpu.MemoryManager().ReadBlock(offset, &entropy, sizeof(EntropyProbs)); 375 host1x.MemoryManager().ReadBlock(offset, &entropy, sizeof(EntropyProbs));
376 entropy.Convert(dst); 376 entropy.Convert(dst);
377} 377}
378 378
379Vp9FrameContainer VP9::GetCurrentFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { 379Vp9FrameContainer VP9::GetCurrentFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
380 Vp9FrameContainer current_frame{}; 380 Vp9FrameContainer current_frame{};
381 { 381 {
382 gpu.SyncGuestHost(); 382 // gpu.SyncGuestHost(); epic, why?
383 current_frame.info = GetVp9PictureInfo(state); 383 current_frame.info = GetVp9PictureInfo(state);
384 current_frame.bit_stream.resize(current_frame.info.bitstream_size); 384 current_frame.bit_stream.resize(current_frame.info.bitstream_size);
385 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, current_frame.bit_stream.data(), 385 host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, current_frame.bit_stream.data(),
386 current_frame.info.bitstream_size); 386 current_frame.info.bitstream_size);
387 } 387 }
388 if (!next_frame.bit_stream.empty()) { 388 if (!next_frame.bit_stream.empty()) {
diff --git a/src/video_core/host1x/codecs/vp9.h b/src/video_core/host1x/codecs/vp9.h
index a425c0fa4..d4083e8d3 100644
--- a/src/video_core/host1x/codecs/vp9.h
+++ b/src/video_core/host1x/codecs/vp9.h
@@ -12,7 +12,11 @@
12#include "video_core/host1x/nvdec_common.h" 12#include "video_core/host1x/nvdec_common.h"
13 13
14namespace Tegra { 14namespace Tegra {
15class GPU; 15
16namespace Host1x {
17class Host1x;
18} // namespace Host1x
19
16namespace Decoder { 20namespace Decoder {
17 21
18/// The VpxRangeEncoder, and VpxBitStreamWriter classes are used to compose the 22/// The VpxRangeEncoder, and VpxBitStreamWriter classes are used to compose the
@@ -106,7 +110,7 @@ private:
106 110
107class VP9 { 111class VP9 {
108public: 112public:
109 explicit VP9(GPU& gpu_); 113 explicit VP9(Host1x::Host1x& host1x);
110 ~VP9(); 114 ~VP9();
111 115
112 VP9(const VP9&) = delete; 116 VP9(const VP9&) = delete;
@@ -176,7 +180,7 @@ private:
176 [[nodiscard]] std::vector<u8> ComposeCompressedHeader(); 180 [[nodiscard]] std::vector<u8> ComposeCompressedHeader();
177 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); 181 [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader();
178 182
179 GPU& gpu; 183 Host1x::Host1x& host1x;
180 std::vector<u8> frame; 184 std::vector<u8> frame;
181 185
182 std::array<s8, 4> loop_filter_ref_deltas{}; 186 std::array<s8, 4> loop_filter_ref_deltas{};
diff --git a/src/video_core/host1x/codecs/vp9_types.h b/src/video_core/host1x/codecs/vp9_types.h
index bb3d8df6e..adad8ed7e 100644
--- a/src/video_core/host1x/codecs/vp9_types.h
+++ b/src/video_core/host1x/codecs/vp9_types.h
@@ -9,7 +9,6 @@
9#include "common/common_types.h" 9#include "common/common_types.h"
10 10
11namespace Tegra { 11namespace Tegra {
12class GPU;
13 12
14namespace Decoder { 13namespace Decoder {
15struct Vp9FrameDimensions { 14struct Vp9FrameDimensions {