summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2020-12-02 15:55:15 -0800
committerGravatar GitHub2020-12-02 15:55:15 -0800
commit9abb23cd2700b57611fc25bce67581eaa6d4d3b7 (patch)
tree75a2c41fbdfab51ea44e74e84c17204da171b938 /src
parentMerge pull request #4937 from german77/multiUDP (diff)
parentLimit queue size to 10 frames (diff)
downloadyuzu-9abb23cd2700b57611fc25bce67581eaa6d4d3b7.tar.gz
yuzu-9abb23cd2700b57611fc25bce67581eaa6d4d3b7.tar.xz
yuzu-9abb23cd2700b57611fc25bce67581eaa6d4d3b7.zip
Merge pull request #5002 from ameerj/nvdec-frameskip
nvdec: Queue and display all decoded frames, cleanup decoders
Diffstat (limited to 'src')
-rw-r--r--src/video_core/command_classes/codecs/codec.cpp33
-rw-r--r--src/video_core/command_classes/codecs/codec.h11
-rw-r--r--src/video_core/command_classes/codecs/h264.cpp2
-rw-r--r--src/video_core/command_classes/codecs/h264.h4
-rw-r--r--src/video_core/command_classes/codecs/vp9.cpp333
-rw-r--r--src/video_core/command_classes/codecs/vp9.h7
-rw-r--r--src/video_core/command_classes/codecs/vp9_types.h160
-rw-r--r--src/video_core/command_classes/nvdec.cpp6
-rw-r--r--src/video_core/command_classes/nvdec.h3
-rw-r--r--src/video_core/command_classes/vic.cpp15
10 files changed, 234 insertions, 340 deletions
diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp
index 1adf3cd13..9a88f64e4 100644
--- a/src/video_core/command_classes/codecs/codec.cpp
+++ b/src/video_core/command_classes/codecs/codec.cpp
@@ -18,6 +18,11 @@ extern "C" {
18 18
19namespace Tegra { 19namespace Tegra {
20 20
21void AVFrameDeleter(AVFrame* ptr) {
22 av_frame_unref(ptr);
23 av_free(ptr);
24}
25
21Codec::Codec(GPU& gpu_) 26Codec::Codec(GPU& gpu_)
22 : gpu(gpu_), h264_decoder(std::make_unique<Decoder::H264>(gpu)), 27 : gpu(gpu_), h264_decoder(std::make_unique<Decoder::H264>(gpu)),
23 vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {} 28 vp9_decoder(std::make_unique<Decoder::VP9>(gpu)) {}
@@ -27,7 +32,9 @@ Codec::~Codec() {
27 return; 32 return;
28 } 33 }
29 // Free libav memory 34 // Free libav memory
35 AVFrame* av_frame{nullptr};
30 avcodec_send_packet(av_codec_ctx, nullptr); 36 avcodec_send_packet(av_codec_ctx, nullptr);
37 av_frame = av_frame_alloc();
31 avcodec_receive_frame(av_codec_ctx, av_frame); 38 avcodec_receive_frame(av_codec_ctx, av_frame);
32 avcodec_flush_buffers(av_codec_ctx); 39 avcodec_flush_buffers(av_codec_ctx);
33 40
@@ -60,7 +67,7 @@ void Codec::Decode() {
60 } 67 }
61 68
62 av_codec_ctx = avcodec_alloc_context3(av_codec); 69 av_codec_ctx = avcodec_alloc_context3(av_codec);
63 av_frame = av_frame_alloc(); 70 av_codec_ctx->refcounted_frames = 1;
64 av_opt_set(av_codec_ctx->priv_data, "tune", "zerolatency", 0); 71 av_opt_set(av_codec_ctx->priv_data, "tune", "zerolatency", 0);
65 72
66 // TODO(ameerj): libavcodec gpu hw acceleration 73 // TODO(ameerj): libavcodec gpu hw acceleration
@@ -68,8 +75,6 @@ void Codec::Decode() {
68 const auto av_error = avcodec_open2(av_codec_ctx, av_codec, nullptr); 75 const auto av_error = avcodec_open2(av_codec_ctx, av_codec, nullptr);
69 if (av_error < 0) { 76 if (av_error < 0) {
70 LOG_ERROR(Service_NVDRV, "avcodec_open2() Failed."); 77 LOG_ERROR(Service_NVDRV, "avcodec_open2() Failed.");
71 av_frame_unref(av_frame);
72 av_free(av_frame);
73 avcodec_close(av_codec_ctx); 78 avcodec_close(av_codec_ctx);
74 return; 79 return;
75 } 80 }
@@ -96,16 +101,26 @@ void Codec::Decode() {
96 101
97 if (!vp9_hidden_frame) { 102 if (!vp9_hidden_frame) {
98 // Only receive/store visible frames 103 // Only receive/store visible frames
99 avcodec_receive_frame(av_codec_ctx, av_frame); 104 AVFramePtr frame = AVFramePtr{av_frame_alloc(), AVFrameDeleter};
105 avcodec_receive_frame(av_codec_ctx, frame.get());
106 av_frames.push(std::move(frame));
107 // Limit queue to 10 frames. Workaround for ZLA decode and queue spam
108 if (av_frames.size() > 10) {
109 av_frames.pop();
110 }
100 } 111 }
101} 112}
102 113
103AVFrame* Codec::GetCurrentFrame() { 114AVFramePtr Codec::GetCurrentFrame() {
104 return av_frame; 115 // Sometimes VIC will request more frames than have been decoded.
105} 116 // in this case, return a nullptr and don't overwrite previous frame data
117 if (av_frames.empty()) {
118 return AVFramePtr{nullptr, AVFrameDeleter};
119 }
106 120
107const AVFrame* Codec::GetCurrentFrame() const { 121 AVFramePtr frame = std::move(av_frames.front());
108 return av_frame; 122 av_frames.pop();
123 return frame;
109} 124}
110 125
111NvdecCommon::VideoCodec Codec::GetCurrentCodec() const { 126NvdecCommon::VideoCodec Codec::GetCurrentCodec() const {
diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h
index ee5d62540..8a2a6c360 100644
--- a/src/video_core/command_classes/codecs/codec.h
+++ b/src/video_core/command_classes/codecs/codec.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <queue>
8#include "common/common_types.h" 9#include "common/common_types.h"
9#include "video_core/command_classes/nvdec_common.h" 10#include "video_core/command_classes/nvdec_common.h"
10 11
@@ -23,6 +24,9 @@ namespace Tegra {
23class GPU; 24class GPU;
24struct VicRegisters; 25struct VicRegisters;
25 26
27void AVFrameDeleter(AVFrame* ptr);
28using AVFramePtr = std::unique_ptr<AVFrame, decltype(&AVFrameDeleter)>;
29
26namespace Decoder { 30namespace Decoder {
27class H264; 31class H264;
28class VP9; 32class VP9;
@@ -42,9 +46,8 @@ public:
42 /// Call decoders to construct headers, decode AVFrame with ffmpeg 46 /// Call decoders to construct headers, decode AVFrame with ffmpeg
43 void Decode(); 47 void Decode();
44 48
45 /// Returns most recently decoded frame 49 /// Returns next decoded frame
46 [[nodiscard]] AVFrame* GetCurrentFrame(); 50 [[nodiscard]] AVFramePtr GetCurrentFrame();
47 [[nodiscard]] const AVFrame* GetCurrentFrame() const;
48 51
49 /// Returns the value of current_codec 52 /// Returns the value of current_codec
50 [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const; 53 [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const;
@@ -55,13 +58,13 @@ private:
55 58
56 AVCodec* av_codec{nullptr}; 59 AVCodec* av_codec{nullptr};
57 AVCodecContext* av_codec_ctx{nullptr}; 60 AVCodecContext* av_codec_ctx{nullptr};
58 AVFrame* av_frame{nullptr};
59 61
60 GPU& gpu; 62 GPU& gpu;
61 std::unique_ptr<Decoder::H264> h264_decoder; 63 std::unique_ptr<Decoder::H264> h264_decoder;
62 std::unique_ptr<Decoder::VP9> vp9_decoder; 64 std::unique_ptr<Decoder::VP9> vp9_decoder;
63 65
64 NvdecCommon::NvdecRegisters state{}; 66 NvdecCommon::NvdecRegisters state{};
67 std::queue<AVFramePtr> av_frames{};
65}; 68};
66 69
67} // namespace Tegra 70} // namespace Tegra
diff --git a/src/video_core/command_classes/codecs/h264.cpp b/src/video_core/command_classes/codecs/h264.cpp
index 33e063e20..65bbeac78 100644
--- a/src/video_core/command_classes/codecs/h264.cpp
+++ b/src/video_core/command_classes/codecs/h264.cpp
@@ -43,7 +43,7 @@ H264::H264(GPU& gpu_) : gpu(gpu_) {}
43 43
44H264::~H264() = default; 44H264::~H264() = default;
45 45
46const std::vector<u8>& H264::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state, 46const std::vector<u8>& H264::ComposeFrameHeader(const NvdecCommon::NvdecRegisters& state,
47 bool is_first_frame) { 47 bool is_first_frame) {
48 H264DecoderContext context{}; 48 H264DecoderContext context{};
49 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext)); 49 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext));
diff --git a/src/video_core/command_classes/codecs/h264.h b/src/video_core/command_classes/codecs/h264.h
index 273449495..0f3a1d9f3 100644
--- a/src/video_core/command_classes/codecs/h264.h
+++ b/src/video_core/command_classes/codecs/h264.h
@@ -74,8 +74,8 @@ public:
74 ~H264(); 74 ~H264();
75 75
76 /// Compose the H264 header of the frame for FFmpeg decoding 76 /// Compose the H264 header of the frame for FFmpeg decoding
77 [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state, 77 [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(
78 bool is_first_frame = false); 78 const NvdecCommon::NvdecRegisters& state, bool is_first_frame = false);
79 79
80private: 80private:
81 struct H264ParameterSet { 81 struct H264ParameterSet {
diff --git a/src/video_core/command_classes/codecs/vp9.cpp b/src/video_core/command_classes/codecs/vp9.cpp
index ab44fdc9e..b1d675cdb 100644
--- a/src/video_core/command_classes/codecs/vp9.cpp
+++ b/src/video_core/command_classes/codecs/vp9.cpp
@@ -23,122 +23,102 @@ constexpr Vp9EntropyProbs default_probs{
23 222, 34, 30, 0, 72, 16, 44, 0, 58, 32, 12, 0, 10, 7, 6, 0, 23 222, 34, 30, 0, 72, 16, 44, 0, 58, 32, 12, 0, 10, 7, 6, 0,
24 }, 24 },
25 .coef_probs{ 25 .coef_probs{
26 195, 29, 183, 0, 84, 49, 136, 0, 8, 42, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26 195, 29, 183, 84, 49, 136, 8, 42, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 0, 0, 0, 0, 31, 107, 169, 0, 35, 99, 159, 0, 17, 82, 140, 0, 8, 66, 114, 0, 27 31, 107, 169, 35, 99, 159, 17, 82, 140, 8, 66, 114, 2, 44, 76, 1, 19, 32,
28 2, 44, 76, 0, 1, 19, 32, 0, 40, 132, 201, 0, 29, 114, 187, 0, 13, 91, 157, 0, 28 40, 132, 201, 29, 114, 187, 13, 91, 157, 7, 75, 127, 3, 58, 95, 1, 28, 47,
29 7, 75, 127, 0, 3, 58, 95, 0, 1, 28, 47, 0, 69, 142, 221, 0, 42, 122, 201, 0, 29 69, 142, 221, 42, 122, 201, 15, 91, 159, 6, 67, 121, 1, 42, 77, 1, 17, 31,
30 15, 91, 159, 0, 6, 67, 121, 0, 1, 42, 77, 0, 1, 17, 31, 0, 102, 148, 228, 0, 30 102, 148, 228, 67, 117, 204, 17, 82, 154, 6, 59, 114, 2, 39, 75, 1, 15, 29,
31 67, 117, 204, 0, 17, 82, 154, 0, 6, 59, 114, 0, 2, 39, 75, 0, 1, 15, 29, 0, 31 156, 57, 233, 119, 57, 212, 58, 48, 163, 29, 40, 124, 12, 30, 81, 3, 12, 31,
32 156, 57, 233, 0, 119, 57, 212, 0, 58, 48, 163, 0, 29, 40, 124, 0, 12, 30, 81, 0, 32 191, 107, 226, 124, 117, 204, 25, 99, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0,
33 3, 12, 31, 0, 191, 107, 226, 0, 124, 117, 204, 0, 25, 99, 155, 0, 0, 0, 0, 0, 33 29, 148, 210, 37, 126, 194, 8, 93, 157, 2, 68, 118, 1, 39, 69, 1, 17, 33,
34 0, 0, 0, 0, 0, 0, 0, 0, 29, 148, 210, 0, 37, 126, 194, 0, 8, 93, 157, 0, 34 41, 151, 213, 27, 123, 193, 3, 82, 144, 1, 58, 105, 1, 32, 60, 1, 13, 26,
35 2, 68, 118, 0, 1, 39, 69, 0, 1, 17, 33, 0, 41, 151, 213, 0, 27, 123, 193, 0, 35 59, 159, 220, 23, 126, 198, 4, 88, 151, 1, 66, 114, 1, 38, 71, 1, 18, 34,
36 3, 82, 144, 0, 1, 58, 105, 0, 1, 32, 60, 0, 1, 13, 26, 0, 59, 159, 220, 0, 36 114, 136, 232, 51, 114, 207, 11, 83, 155, 3, 56, 105, 1, 33, 65, 1, 17, 34,
37 23, 126, 198, 0, 4, 88, 151, 0, 1, 66, 114, 0, 1, 38, 71, 0, 1, 18, 34, 0, 37 149, 65, 234, 121, 57, 215, 61, 49, 166, 28, 36, 114, 12, 25, 76, 3, 16, 42,
38 114, 136, 232, 0, 51, 114, 207, 0, 11, 83, 155, 0, 3, 56, 105, 0, 1, 33, 65, 0, 38 214, 49, 220, 132, 63, 188, 42, 65, 137, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 1, 17, 34, 0, 149, 65, 234, 0, 121, 57, 215, 0, 61, 49, 166, 0, 28, 36, 114, 0, 39 85, 137, 221, 104, 131, 216, 49, 111, 192, 21, 87, 155, 2, 49, 87, 1, 16, 28,
40 12, 25, 76, 0, 3, 16, 42, 0, 214, 49, 220, 0, 132, 63, 188, 0, 42, 65, 137, 0, 40 89, 163, 230, 90, 137, 220, 29, 100, 183, 10, 70, 135, 2, 42, 81, 1, 17, 33,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 137, 221, 0, 104, 131, 216, 0, 41 108, 167, 237, 55, 133, 222, 15, 97, 179, 4, 72, 135, 1, 45, 85, 1, 19, 38,
42 49, 111, 192, 0, 21, 87, 155, 0, 2, 49, 87, 0, 1, 16, 28, 0, 89, 163, 230, 0, 42 124, 146, 240, 66, 124, 224, 17, 88, 175, 4, 58, 122, 1, 36, 75, 1, 18, 37,
43 90, 137, 220, 0, 29, 100, 183, 0, 10, 70, 135, 0, 2, 42, 81, 0, 1, 17, 33, 0, 43 141, 79, 241, 126, 70, 227, 66, 58, 182, 30, 44, 136, 12, 34, 96, 2, 20, 47,
44 108, 167, 237, 0, 55, 133, 222, 0, 15, 97, 179, 0, 4, 72, 135, 0, 1, 45, 85, 0, 44 229, 99, 249, 143, 111, 235, 46, 109, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 1, 19, 38, 0, 124, 146, 240, 0, 66, 124, 224, 0, 17, 88, 175, 0, 4, 58, 122, 0, 45 82, 158, 236, 94, 146, 224, 25, 117, 191, 9, 87, 149, 3, 56, 99, 1, 33, 57,
46 1, 36, 75, 0, 1, 18, 37, 0, 141, 79, 241, 0, 126, 70, 227, 0, 66, 58, 182, 0, 46 83, 167, 237, 68, 145, 222, 10, 103, 177, 2, 72, 131, 1, 41, 79, 1, 20, 39,
47 30, 44, 136, 0, 12, 34, 96, 0, 2, 20, 47, 0, 229, 99, 249, 0, 143, 111, 235, 0, 47 99, 167, 239, 47, 141, 224, 10, 104, 178, 2, 73, 133, 1, 44, 85, 1, 22, 47,
48 46, 109, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 158, 236, 0, 48 127, 145, 243, 71, 129, 228, 17, 93, 177, 3, 61, 124, 1, 41, 84, 1, 21, 52,
49 94, 146, 224, 0, 25, 117, 191, 0, 9, 87, 149, 0, 3, 56, 99, 0, 1, 33, 57, 0, 49 157, 78, 244, 140, 72, 231, 69, 58, 184, 31, 44, 137, 14, 38, 105, 8, 23, 61,
50 83, 167, 237, 0, 68, 145, 222, 0, 10, 103, 177, 0, 2, 72, 131, 0, 1, 41, 79, 0, 50 125, 34, 187, 52, 41, 133, 6, 31, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 1, 20, 39, 0, 99, 167, 239, 0, 47, 141, 224, 0, 10, 104, 178, 0, 2, 73, 133, 0, 51 37, 109, 153, 51, 102, 147, 23, 87, 128, 8, 67, 101, 1, 41, 63, 1, 19, 29,
52 1, 44, 85, 0, 1, 22, 47, 0, 127, 145, 243, 0, 71, 129, 228, 0, 17, 93, 177, 0, 52 31, 154, 185, 17, 127, 175, 6, 96, 145, 2, 73, 114, 1, 51, 82, 1, 28, 45,
53 3, 61, 124, 0, 1, 41, 84, 0, 1, 21, 52, 0, 157, 78, 244, 0, 140, 72, 231, 0, 53 23, 163, 200, 10, 131, 185, 2, 93, 148, 1, 67, 111, 1, 41, 69, 1, 14, 24,
54 69, 58, 184, 0, 31, 44, 137, 0, 14, 38, 105, 0, 8, 23, 61, 0, 125, 34, 187, 0, 54 29, 176, 217, 12, 145, 201, 3, 101, 156, 1, 69, 111, 1, 39, 63, 1, 14, 23,
55 52, 41, 133, 0, 6, 31, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55 57, 192, 233, 25, 154, 215, 6, 109, 167, 3, 78, 118, 1, 48, 69, 1, 21, 29,
56 37, 109, 153, 0, 51, 102, 147, 0, 23, 87, 128, 0, 8, 67, 101, 0, 1, 41, 63, 0, 56 202, 105, 245, 108, 106, 216, 18, 90, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 1, 19, 29, 0, 31, 154, 185, 0, 17, 127, 175, 0, 6, 96, 145, 0, 2, 73, 114, 0, 57 33, 172, 219, 64, 149, 206, 14, 117, 177, 5, 90, 141, 2, 61, 95, 1, 37, 57,
58 1, 51, 82, 0, 1, 28, 45, 0, 23, 163, 200, 0, 10, 131, 185, 0, 2, 93, 148, 0, 58 33, 179, 220, 11, 140, 198, 1, 89, 148, 1, 60, 104, 1, 33, 57, 1, 12, 21,
59 1, 67, 111, 0, 1, 41, 69, 0, 1, 14, 24, 0, 29, 176, 217, 0, 12, 145, 201, 0, 59 30, 181, 221, 8, 141, 198, 1, 87, 145, 1, 58, 100, 1, 31, 55, 1, 12, 20,
60 3, 101, 156, 0, 1, 69, 111, 0, 1, 39, 63, 0, 1, 14, 23, 0, 57, 192, 233, 0, 60 32, 186, 224, 7, 142, 198, 1, 86, 143, 1, 58, 100, 1, 31, 55, 1, 12, 22,
61 25, 154, 215, 0, 6, 109, 167, 0, 3, 78, 118, 0, 1, 48, 69, 0, 1, 21, 29, 0, 61 57, 192, 227, 20, 143, 204, 3, 96, 154, 1, 68, 112, 1, 42, 69, 1, 19, 32,
62 202, 105, 245, 0, 108, 106, 216, 0, 18, 90, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62 212, 35, 215, 113, 47, 169, 29, 48, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 33, 172, 219, 0, 64, 149, 206, 0, 14, 117, 177, 0, 5, 90, 141, 0, 63 74, 129, 203, 106, 120, 203, 49, 107, 178, 19, 84, 144, 4, 50, 84, 1, 15, 25,
64 2, 61, 95, 0, 1, 37, 57, 0, 33, 179, 220, 0, 11, 140, 198, 0, 1, 89, 148, 0, 64 71, 172, 217, 44, 141, 209, 15, 102, 173, 6, 76, 133, 2, 51, 89, 1, 24, 42,
65 1, 60, 104, 0, 1, 33, 57, 0, 1, 12, 21, 0, 30, 181, 221, 0, 8, 141, 198, 0, 65 64, 185, 231, 31, 148, 216, 8, 103, 175, 3, 74, 131, 1, 46, 81, 1, 18, 30,
66 1, 87, 145, 0, 1, 58, 100, 0, 1, 31, 55, 0, 1, 12, 20, 0, 32, 186, 224, 0, 66 65, 196, 235, 25, 157, 221, 5, 105, 174, 1, 67, 120, 1, 38, 69, 1, 15, 30,
67 7, 142, 198, 0, 1, 86, 143, 0, 1, 58, 100, 0, 1, 31, 55, 0, 1, 12, 22, 0, 67 65, 204, 238, 30, 156, 224, 7, 107, 177, 2, 70, 124, 1, 42, 73, 1, 18, 34,
68 57, 192, 227, 0, 20, 143, 204, 0, 3, 96, 154, 0, 1, 68, 112, 0, 1, 42, 69, 0, 68 225, 86, 251, 144, 104, 235, 42, 99, 181, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 1, 19, 32, 0, 212, 35, 215, 0, 113, 47, 169, 0, 29, 48, 105, 0, 0, 0, 0, 0, 69 85, 175, 239, 112, 165, 229, 29, 136, 200, 12, 103, 162, 6, 77, 123, 2, 53, 84,
70 0, 0, 0, 0, 0, 0, 0, 0, 74, 129, 203, 0, 106, 120, 203, 0, 49, 107, 178, 0, 70 75, 183, 239, 30, 155, 221, 3, 106, 171, 1, 74, 128, 1, 44, 76, 1, 17, 28,
71 19, 84, 144, 0, 4, 50, 84, 0, 1, 15, 25, 0, 71, 172, 217, 0, 44, 141, 209, 0, 71 73, 185, 240, 27, 159, 222, 2, 107, 172, 1, 75, 127, 1, 42, 73, 1, 17, 29,
72 15, 102, 173, 0, 6, 76, 133, 0, 2, 51, 89, 0, 1, 24, 42, 0, 64, 185, 231, 0, 72 62, 190, 238, 21, 159, 222, 2, 107, 172, 1, 72, 122, 1, 40, 71, 1, 18, 32,
73 31, 148, 216, 0, 8, 103, 175, 0, 3, 74, 131, 0, 1, 46, 81, 0, 1, 18, 30, 0, 73 61, 199, 240, 27, 161, 226, 4, 113, 180, 1, 76, 129, 1, 46, 80, 1, 23, 41,
74 65, 196, 235, 0, 25, 157, 221, 0, 5, 105, 174, 0, 1, 67, 120, 0, 1, 38, 69, 0, 74 7, 27, 153, 5, 30, 95, 1, 16, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75 1, 15, 30, 0, 65, 204, 238, 0, 30, 156, 224, 0, 7, 107, 177, 0, 2, 70, 124, 0, 75 50, 75, 127, 57, 75, 124, 27, 67, 108, 10, 54, 86, 1, 33, 52, 1, 12, 18,
76 1, 42, 73, 0, 1, 18, 34, 0, 225, 86, 251, 0, 144, 104, 235, 0, 42, 99, 181, 0, 76 43, 125, 151, 26, 108, 148, 7, 83, 122, 2, 59, 89, 1, 38, 60, 1, 17, 27,
77 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 175, 239, 0, 112, 165, 229, 0, 77 23, 144, 163, 13, 112, 154, 2, 75, 117, 1, 50, 81, 1, 31, 51, 1, 14, 23,
78 29, 136, 200, 0, 12, 103, 162, 0, 6, 77, 123, 0, 2, 53, 84, 0, 75, 183, 239, 0, 78 18, 162, 185, 6, 123, 171, 1, 78, 125, 1, 51, 86, 1, 31, 54, 1, 14, 23,
79 30, 155, 221, 0, 3, 106, 171, 0, 1, 74, 128, 0, 1, 44, 76, 0, 1, 17, 28, 0, 79 15, 199, 227, 3, 150, 204, 1, 91, 146, 1, 55, 95, 1, 30, 53, 1, 11, 20,
80 73, 185, 240, 0, 27, 159, 222, 0, 2, 107, 172, 0, 1, 75, 127, 0, 1, 42, 73, 0, 80 19, 55, 240, 19, 59, 196, 3, 52, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81 1, 17, 29, 0, 62, 190, 238, 0, 21, 159, 222, 0, 2, 107, 172, 0, 1, 72, 122, 0, 81 41, 166, 207, 104, 153, 199, 31, 123, 181, 14, 101, 152, 5, 72, 106, 1, 36, 52,
82 1, 40, 71, 0, 1, 18, 32, 0, 61, 199, 240, 0, 27, 161, 226, 0, 4, 113, 180, 0, 82 35, 176, 211, 12, 131, 190, 2, 88, 144, 1, 60, 101, 1, 36, 60, 1, 16, 28,
83 1, 76, 129, 0, 1, 46, 80, 0, 1, 23, 41, 0, 7, 27, 153, 0, 5, 30, 95, 0, 83 28, 183, 213, 8, 134, 191, 1, 86, 142, 1, 56, 96, 1, 30, 53, 1, 12, 20,
84 1, 16, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 75, 127, 0, 84 20, 190, 215, 4, 135, 192, 1, 84, 139, 1, 53, 91, 1, 28, 49, 1, 11, 20,
85 57, 75, 124, 0, 27, 67, 108, 0, 10, 54, 86, 0, 1, 33, 52, 0, 1, 12, 18, 0, 85 13, 196, 216, 2, 137, 192, 1, 86, 143, 1, 57, 99, 1, 32, 56, 1, 13, 24,
86 43, 125, 151, 0, 26, 108, 148, 0, 7, 83, 122, 0, 2, 59, 89, 0, 1, 38, 60, 0, 86 211, 29, 217, 96, 47, 156, 22, 43, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 1, 17, 27, 0, 23, 144, 163, 0, 13, 112, 154, 0, 2, 75, 117, 0, 1, 50, 81, 0, 87 78, 120, 193, 111, 116, 186, 46, 102, 164, 15, 80, 128, 2, 49, 76, 1, 18, 28,
88 1, 31, 51, 0, 1, 14, 23, 0, 18, 162, 185, 0, 6, 123, 171, 0, 1, 78, 125, 0, 88 71, 161, 203, 42, 132, 192, 10, 98, 150, 3, 69, 109, 1, 44, 70, 1, 18, 29,
89 1, 51, 86, 0, 1, 31, 54, 0, 1, 14, 23, 0, 15, 199, 227, 0, 3, 150, 204, 0, 89 57, 186, 211, 30, 140, 196, 4, 93, 146, 1, 62, 102, 1, 38, 65, 1, 16, 27,
90 1, 91, 146, 0, 1, 55, 95, 0, 1, 30, 53, 0, 1, 11, 20, 0, 19, 55, 240, 0, 90 47, 199, 217, 14, 145, 196, 1, 88, 142, 1, 57, 98, 1, 36, 62, 1, 15, 26,
91 19, 59, 196, 0, 3, 52, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 91 26, 219, 229, 5, 155, 207, 1, 94, 151, 1, 60, 104, 1, 36, 62, 1, 16, 28,
92 41, 166, 207, 0, 104, 153, 199, 0, 31, 123, 181, 0, 14, 101, 152, 0, 5, 72, 106, 0, 92 233, 29, 248, 146, 47, 220, 43, 52, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 1, 36, 52, 0, 35, 176, 211, 0, 12, 131, 190, 0, 2, 88, 144, 0, 1, 60, 101, 0, 93 100, 163, 232, 179, 161, 222, 63, 142, 204, 37, 113, 174, 26, 89, 137, 18, 68, 97,
94 1, 36, 60, 0, 1, 16, 28, 0, 28, 183, 213, 0, 8, 134, 191, 0, 1, 86, 142, 0, 94 85, 181, 230, 32, 146, 209, 7, 100, 164, 3, 71, 121, 1, 45, 77, 1, 18, 30,
95 1, 56, 96, 0, 1, 30, 53, 0, 1, 12, 20, 0, 20, 190, 215, 0, 4, 135, 192, 0, 95 65, 187, 230, 20, 148, 207, 2, 97, 159, 1, 68, 116, 1, 40, 70, 1, 14, 29,
96 1, 84, 139, 0, 1, 53, 91, 0, 1, 28, 49, 0, 1, 11, 20, 0, 13, 196, 216, 0, 96 40, 194, 227, 8, 147, 204, 1, 94, 155, 1, 65, 112, 1, 39, 66, 1, 14, 26,
97 2, 137, 192, 0, 1, 86, 143, 0, 1, 57, 99, 0, 1, 32, 56, 0, 1, 13, 24, 0, 97 16, 208, 228, 3, 151, 207, 1, 98, 160, 1, 67, 117, 1, 41, 74, 1, 17, 31,
98 211, 29, 217, 0, 96, 47, 156, 0, 22, 43, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98 17, 38, 140, 7, 34, 80, 1, 17, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 78, 120, 193, 0, 111, 116, 186, 0, 46, 102, 164, 0, 15, 80, 128, 0, 99 37, 75, 128, 41, 76, 128, 26, 66, 116, 12, 52, 94, 2, 32, 55, 1, 10, 16,
100 2, 49, 76, 0, 1, 18, 28, 0, 71, 161, 203, 0, 42, 132, 192, 0, 10, 98, 150, 0, 100 50, 127, 154, 37, 109, 152, 16, 82, 121, 5, 59, 85, 1, 35, 54, 1, 13, 20,
101 3, 69, 109, 0, 1, 44, 70, 0, 1, 18, 29, 0, 57, 186, 211, 0, 30, 140, 196, 0, 101 40, 142, 167, 17, 110, 157, 2, 71, 112, 1, 44, 72, 1, 27, 45, 1, 11, 17,
102 4, 93, 146, 0, 1, 62, 102, 0, 1, 38, 65, 0, 1, 16, 27, 0, 47, 199, 217, 0, 102 30, 175, 188, 9, 124, 169, 1, 74, 116, 1, 48, 78, 1, 30, 49, 1, 11, 18,
103 14, 145, 196, 0, 1, 88, 142, 0, 1, 57, 98, 0, 1, 36, 62, 0, 1, 15, 26, 0, 103 10, 222, 223, 2, 150, 194, 1, 83, 128, 1, 48, 79, 1, 27, 45, 1, 11, 17,
104 26, 219, 229, 0, 5, 155, 207, 0, 1, 94, 151, 0, 1, 60, 104, 0, 1, 36, 62, 0, 104 36, 41, 235, 29, 36, 193, 10, 27, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 1, 16, 28, 0, 233, 29, 248, 0, 146, 47, 220, 0, 43, 52, 140, 0, 0, 0, 0, 0, 105 85, 165, 222, 177, 162, 215, 110, 135, 195, 57, 113, 168, 23, 83, 120, 10, 49, 61,
106 0, 0, 0, 0, 0, 0, 0, 0, 100, 163, 232, 0, 179, 161, 222, 0, 63, 142, 204, 0, 106 85, 190, 223, 36, 139, 200, 5, 90, 146, 1, 60, 103, 1, 38, 65, 1, 18, 30,
107 37, 113, 174, 0, 26, 89, 137, 0, 18, 68, 97, 0, 85, 181, 230, 0, 32, 146, 209, 0, 107 72, 202, 223, 23, 141, 199, 2, 86, 140, 1, 56, 97, 1, 36, 61, 1, 16, 27,
108 7, 100, 164, 0, 3, 71, 121, 0, 1, 45, 77, 0, 1, 18, 30, 0, 65, 187, 230, 0, 108 55, 218, 225, 13, 145, 200, 1, 86, 141, 1, 57, 99, 1, 35, 61, 1, 13, 22,
109 20, 148, 207, 0, 2, 97, 159, 0, 1, 68, 116, 0, 1, 40, 70, 0, 1, 14, 29, 0, 109 15, 235, 212, 1, 132, 184, 1, 84, 139, 1, 57, 97, 1, 34, 56, 1, 14, 23,
110 40, 194, 227, 0, 8, 147, 204, 0, 1, 94, 155, 0, 1, 65, 112, 0, 1, 39, 66, 0, 110 181, 21, 201, 61, 37, 123, 10, 38, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111 1, 14, 26, 0, 16, 208, 228, 0, 3, 151, 207, 0, 1, 98, 160, 0, 1, 67, 117, 0, 111 47, 106, 172, 95, 104, 173, 42, 93, 159, 18, 77, 131, 4, 50, 81, 1, 17, 23,
112 1, 41, 74, 0, 1, 17, 31, 0, 17, 38, 140, 0, 7, 34, 80, 0, 1, 17, 29, 0, 112 62, 147, 199, 44, 130, 189, 28, 102, 154, 18, 75, 115, 2, 44, 65, 1, 12, 19,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 75, 128, 0, 41, 76, 128, 0, 113 55, 153, 210, 24, 130, 194, 3, 93, 146, 1, 61, 97, 1, 31, 50, 1, 10, 16,
114 26, 66, 116, 0, 12, 52, 94, 0, 2, 32, 55, 0, 1, 10, 16, 0, 50, 127, 154, 0, 114 49, 186, 223, 17, 148, 204, 1, 96, 142, 1, 53, 83, 1, 26, 44, 1, 11, 17,
115 37, 109, 152, 0, 16, 82, 121, 0, 5, 59, 85, 0, 1, 35, 54, 0, 1, 13, 20, 0, 115 13, 217, 212, 2, 136, 180, 1, 78, 124, 1, 50, 83, 1, 29, 49, 1, 14, 23,
116 40, 142, 167, 0, 17, 110, 157, 0, 2, 71, 112, 0, 1, 44, 72, 0, 1, 27, 45, 0, 116 197, 13, 247, 82, 17, 222, 25, 17, 162, 0, 0, 0, 0, 0, 0, 0, 0, 0,
117 1, 11, 17, 0, 30, 175, 188, 0, 9, 124, 169, 0, 1, 74, 116, 0, 1, 48, 78, 0, 117 126, 186, 247, 234, 191, 243, 176, 177, 234, 104, 158, 220, 66, 128, 186, 55, 90, 137,
118 1, 30, 49, 0, 1, 11, 18, 0, 10, 222, 223, 0, 2, 150, 194, 0, 1, 83, 128, 0, 118 111, 197, 242, 46, 158, 219, 9, 104, 171, 2, 65, 125, 1, 44, 80, 1, 17, 91,
119 1, 48, 79, 0, 1, 27, 45, 0, 1, 11, 17, 0, 36, 41, 235, 0, 29, 36, 193, 0, 119 104, 208, 245, 39, 168, 224, 3, 109, 162, 1, 79, 124, 1, 50, 102, 1, 43, 102,
120 10, 27, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 165, 222, 0, 120 84, 220, 246, 31, 177, 231, 2, 115, 180, 1, 79, 134, 1, 55, 77, 1, 60, 79,
121 177, 162, 215, 0, 110, 135, 195, 0, 57, 113, 168, 0, 23, 83, 120, 0, 10, 49, 61, 0, 121 43, 243, 240, 8, 180, 217, 1, 115, 166, 1, 84, 121, 1, 51, 67, 1, 16, 6,
122 85, 190, 223, 0, 36, 139, 200, 0, 5, 90, 146, 0, 1, 60, 103, 0, 1, 38, 65, 0,
123 1, 18, 30, 0, 72, 202, 223, 0, 23, 141, 199, 0, 2, 86, 140, 0, 1, 56, 97, 0,
124 1, 36, 61, 0, 1, 16, 27, 0, 55, 218, 225, 0, 13, 145, 200, 0, 1, 86, 141, 0,
125 1, 57, 99, 0, 1, 35, 61, 0, 1, 13, 22, 0, 15, 235, 212, 0, 1, 132, 184, 0,
126 1, 84, 139, 0, 1, 57, 97, 0, 1, 34, 56, 0, 1, 14, 23, 0, 181, 21, 201, 0,
127 61, 37, 123, 0, 10, 38, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 47, 106, 172, 0, 95, 104, 173, 0, 42, 93, 159, 0, 18, 77, 131, 0, 4, 50, 81, 0,
129 1, 17, 23, 0, 62, 147, 199, 0, 44, 130, 189, 0, 28, 102, 154, 0, 18, 75, 115, 0,
130 2, 44, 65, 0, 1, 12, 19, 0, 55, 153, 210, 0, 24, 130, 194, 0, 3, 93, 146, 0,
131 1, 61, 97, 0, 1, 31, 50, 0, 1, 10, 16, 0, 49, 186, 223, 0, 17, 148, 204, 0,
132 1, 96, 142, 0, 1, 53, 83, 0, 1, 26, 44, 0, 1, 11, 17, 0, 13, 217, 212, 0,
133 2, 136, 180, 0, 1, 78, 124, 0, 1, 50, 83, 0, 1, 29, 49, 0, 1, 14, 23, 0,
134 197, 13, 247, 0, 82, 17, 222, 0, 25, 17, 162, 0, 0, 0, 0, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 126, 186, 247, 0, 234, 191, 243, 0, 176, 177, 234, 0, 104, 158, 220, 0,
136 66, 128, 186, 0, 55, 90, 137, 0, 111, 197, 242, 0, 46, 158, 219, 0, 9, 104, 171, 0,
137 2, 65, 125, 0, 1, 44, 80, 0, 1, 17, 91, 0, 104, 208, 245, 0, 39, 168, 224, 0,
138 3, 109, 162, 0, 1, 79, 124, 0, 1, 50, 102, 0, 1, 43, 102, 0, 84, 220, 246, 0,
139 31, 177, 231, 0, 2, 115, 180, 0, 1, 79, 134, 0, 1, 55, 77, 0, 1, 60, 79, 0,
140 43, 243, 240, 0, 8, 180, 217, 0, 1, 115, 166, 0, 1, 84, 121, 0, 1, 51, 67, 0,
141 1, 16, 6, 0,
142 }, 122 },
143 .switchable_interp_prob{235, 162, 36, 255, 34, 3, 149, 144}, 123 .switchable_interp_prob{235, 162, 36, 255, 34, 3, 149, 144},
144 .inter_mode_prob{ 124 .inter_mode_prob{
@@ -322,39 +302,23 @@ bool VP9::WriteLessThan(VpxRangeEncoder& writer, s32 value, s32 test) {
322} 302}
323 303
324void VP9::WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode, 304void VP9::WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode,
325 const std::array<u8, 2304>& new_prob, 305 const std::array<u8, 1728>& new_prob,
326 const std::array<u8, 2304>& old_prob) { 306 const std::array<u8, 1728>& old_prob) {
327 // Note: There's 1 byte added on each packet for alignment, 307 constexpr u32 block_bytes = 2 * 2 * 6 * 6 * 3;
328 // this byte is ignored when doing updates. 308
329 constexpr s32 block_bytes = 2 * 2 * 6 * 6 * 4; 309 const auto needs_update = [&](u32 base_index) {
330 310 return !std::equal(new_prob.begin() + base_index,
331 const auto needs_update = [&](s32 base_index) -> bool { 311 new_prob.begin() + base_index + block_bytes,
332 s32 index = base_index; 312 old_prob.begin() + base_index);
333 for (s32 i = 0; i < 2; i++) {
334 for (s32 j = 0; j < 2; j++) {
335 for (s32 k = 0; k < 6; k++) {
336 for (s32 l = 0; l < 6; l++) {
337 if (new_prob[index + 0] != old_prob[index + 0] ||
338 new_prob[index + 1] != old_prob[index + 1] ||
339 new_prob[index + 2] != old_prob[index + 2]) {
340 return true;
341 }
342
343 index += 4;
344 }
345 }
346 }
347 }
348 return false;
349 }; 313 };
350 314
351 for (s32 block_index = 0; block_index < 4; block_index++) { 315 for (u32 block_index = 0; block_index < 4; block_index++) {
352 const s32 base_index = block_index * block_bytes; 316 const u32 base_index = block_index * block_bytes;
353 const bool update = needs_update(base_index); 317 const bool update = needs_update(base_index);
354 writer.Write(update); 318 writer.Write(update);
355 319
356 if (update) { 320 if (update) {
357 s32 index = base_index; 321 u32 index = base_index;
358 for (s32 i = 0; i < 2; i++) { 322 for (s32 i = 0; i < 2; i++) {
359 for (s32 j = 0; j < 2; j++) { 323 for (s32 j = 0; j < 2; j++) {
360 for (s32 k = 0; k < 6; k++) { 324 for (s32 k = 0; k < 6; k++) {
@@ -367,14 +331,13 @@ void VP9::WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode,
367 WriteProbabilityUpdate(writer, new_prob[index + 2], 331 WriteProbabilityUpdate(writer, new_prob[index + 2],
368 old_prob[index + 2]); 332 old_prob[index + 2]);
369 } 333 }
370 index += 4; 334 index += 3;
371 } 335 }
372 } 336 }
373 } 337 }
374 } 338 }
375 } 339 }
376 340 if (block_index == static_cast<u32>(tx_mode)) {
377 if (block_index == tx_mode) {
378 break; 341 break;
379 } 342 }
380 } 343 }
@@ -392,7 +355,7 @@ void VP9::WriteMvProbabilityUpdate(VpxRangeEncoder& writer, u8 new_prob, u8 old_
392Vp9PictureInfo VP9::GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state) { 355Vp9PictureInfo VP9::GetVp9PictureInfo(const NvdecCommon::NvdecRegisters& state) {
393 PictureInfo picture_info{}; 356 PictureInfo picture_info{};
394 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo)); 357 gpu.MemoryManager().ReadBlock(state.picture_info_offset, &picture_info, sizeof(PictureInfo));
395 Vp9PictureInfo vp9_info = picture_info.Convert(); 358 Vp9PictureInfo vp9_info = std::move(picture_info.Convert());
396 359
397 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy); 360 InsertEntropy(state.vp9_entropy_probs_offset, vp9_info.entropy);
398 361
@@ -414,8 +377,7 @@ Vp9FrameContainer VP9::GetCurrentFrame(const NvdecCommon::NvdecRegisters& state)
414 Vp9FrameContainer frame{}; 377 Vp9FrameContainer frame{};
415 { 378 {
416 gpu.SyncGuestHost(); 379 gpu.SyncGuestHost();
417 frame.info = GetVp9PictureInfo(state); 380 frame.info = std::move(GetVp9PictureInfo(state));
418
419 frame.bit_stream.resize(frame.info.bitstream_size); 381 frame.bit_stream.resize(frame.info.bitstream_size);
420 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.bit_stream.data(), 382 gpu.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.bit_stream.data(),
421 frame.info.bitstream_size); 383 frame.info.bitstream_size);
@@ -423,37 +385,37 @@ Vp9FrameContainer VP9::GetCurrentFrame(const NvdecCommon::NvdecRegisters& state)
423 // Buffer two frames, saving the last show frame info 385 // Buffer two frames, saving the last show frame info
424 if (!next_next_frame.bit_stream.empty()) { 386 if (!next_next_frame.bit_stream.empty()) {
425 Vp9FrameContainer temp{ 387 Vp9FrameContainer temp{
426 .info = frame.info, 388 .info = std::move(frame.info),
427 .bit_stream = frame.bit_stream, 389 .bit_stream = std::move(frame.bit_stream),
428 }; 390 };
429 next_next_frame.info.show_frame = frame.info.last_frame_shown; 391 next_next_frame.info.show_frame = frame.info.last_frame_shown;
430 frame.info = next_next_frame.info; 392 frame.info = std::move(next_next_frame.info);
431 frame.bit_stream = next_next_frame.bit_stream; 393 frame.bit_stream = std::move(next_next_frame.bit_stream);
432 next_next_frame = std::move(temp); 394 next_next_frame = std::move(temp);
433 395
434 if (!next_frame.bit_stream.empty()) { 396 if (!next_frame.bit_stream.empty()) {
435 Vp9FrameContainer temp2{ 397 Vp9FrameContainer temp2{
436 .info = frame.info, 398 .info = std::move(frame.info),
437 .bit_stream = frame.bit_stream, 399 .bit_stream = std::move(frame.bit_stream),
438 }; 400 };
439 next_frame.info.show_frame = frame.info.last_frame_shown; 401 next_frame.info.show_frame = frame.info.last_frame_shown;
440 frame.info = next_frame.info; 402 frame.info = std::move(next_frame.info);
441 frame.bit_stream = next_frame.bit_stream; 403 frame.bit_stream = std::move(next_frame.bit_stream);
442 next_frame = std::move(temp2); 404 next_frame = std::move(temp2);
443 } else { 405 } else {
444 next_frame.info = frame.info; 406 next_frame.info = std::move(frame.info);
445 next_frame.bit_stream = frame.bit_stream; 407 next_frame.bit_stream = std::move(frame.bit_stream);
446 } 408 }
447 } else { 409 } else {
448 next_next_frame.info = frame.info; 410 next_next_frame.info = std::move(frame.info);
449 next_next_frame.bit_stream = frame.bit_stream; 411 next_next_frame.bit_stream = std::move(frame.bit_stream);
450 } 412 }
451 return frame; 413 return frame;
452} 414}
453 415
454std::vector<u8> VP9::ComposeCompressedHeader() { 416std::vector<u8> VP9::ComposeCompressedHeader() {
455 VpxRangeEncoder writer{}; 417 VpxRangeEncoder writer{};
456 418 const bool update_probs = current_frame_info.show_frame && !current_frame_info.is_key_frame;
457 if (!current_frame_info.lossless) { 419 if (!current_frame_info.lossless) {
458 if (static_cast<u32>(current_frame_info.transform_mode) >= 3) { 420 if (static_cast<u32>(current_frame_info.transform_mode) >= 3) {
459 writer.Write(3, 2); 421 writer.Write(3, 2);
@@ -471,7 +433,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
471 prev_frame_probs.tx_16x16_prob); 433 prev_frame_probs.tx_16x16_prob);
472 WriteProbabilityUpdate(writer, current_frame_info.entropy.tx_32x32_prob, 434 WriteProbabilityUpdate(writer, current_frame_info.entropy.tx_32x32_prob,
473 prev_frame_probs.tx_32x32_prob); 435 prev_frame_probs.tx_32x32_prob);
474 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 436 if (update_probs) {
475 prev_frame_probs.tx_8x8_prob = current_frame_info.entropy.tx_8x8_prob; 437 prev_frame_probs.tx_8x8_prob = current_frame_info.entropy.tx_8x8_prob;
476 prev_frame_probs.tx_16x16_prob = current_frame_info.entropy.tx_16x16_prob; 438 prev_frame_probs.tx_16x16_prob = current_frame_info.entropy.tx_16x16_prob;
477 prev_frame_probs.tx_32x32_prob = current_frame_info.entropy.tx_32x32_prob; 439 prev_frame_probs.tx_32x32_prob = current_frame_info.entropy.tx_32x32_prob;
@@ -484,7 +446,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
484 WriteProbabilityUpdate(writer, current_frame_info.entropy.skip_probs, 446 WriteProbabilityUpdate(writer, current_frame_info.entropy.skip_probs,
485 prev_frame_probs.skip_probs); 447 prev_frame_probs.skip_probs);
486 448
487 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 449 if (update_probs) {
488 prev_frame_probs.coef_probs = current_frame_info.entropy.coef_probs; 450 prev_frame_probs.coef_probs = current_frame_info.entropy.coef_probs;
489 prev_frame_probs.skip_probs = current_frame_info.entropy.skip_probs; 451 prev_frame_probs.skip_probs = current_frame_info.entropy.skip_probs;
490 } 452 }
@@ -493,15 +455,12 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
493 // read_inter_probs() in the spec 455 // read_inter_probs() in the spec
494 WriteProbabilityUpdateAligned4(writer, current_frame_info.entropy.inter_mode_prob, 456 WriteProbabilityUpdateAligned4(writer, current_frame_info.entropy.inter_mode_prob,
495 prev_frame_probs.inter_mode_prob); 457 prev_frame_probs.inter_mode_prob);
496 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) {
497 prev_frame_probs.inter_mode_prob = current_frame_info.entropy.inter_mode_prob;
498 }
499 458
500 if (current_frame_info.interp_filter == 4) { 459 if (current_frame_info.interp_filter == 4) {
501 // read_interp_filter_probs() in the spec 460 // read_interp_filter_probs() in the spec
502 WriteProbabilityUpdate(writer, current_frame_info.entropy.switchable_interp_prob, 461 WriteProbabilityUpdate(writer, current_frame_info.entropy.switchable_interp_prob,
503 prev_frame_probs.switchable_interp_prob); 462 prev_frame_probs.switchable_interp_prob);
504 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 463 if (update_probs) {
505 prev_frame_probs.switchable_interp_prob = 464 prev_frame_probs.switchable_interp_prob =
506 current_frame_info.entropy.switchable_interp_prob; 465 current_frame_info.entropy.switchable_interp_prob;
507 } 466 }
@@ -510,9 +469,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
510 // read_is_inter_probs() in the spec 469 // read_is_inter_probs() in the spec
511 WriteProbabilityUpdate(writer, current_frame_info.entropy.intra_inter_prob, 470 WriteProbabilityUpdate(writer, current_frame_info.entropy.intra_inter_prob,
512 prev_frame_probs.intra_inter_prob); 471 prev_frame_probs.intra_inter_prob);
513 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 472
514 prev_frame_probs.intra_inter_prob = current_frame_info.entropy.intra_inter_prob;
515 }
516 // frame_reference_mode() in the spec 473 // frame_reference_mode() in the spec
517 if ((current_frame_info.ref_frame_sign_bias[1] & 1) != 474 if ((current_frame_info.ref_frame_sign_bias[1] & 1) !=
518 (current_frame_info.ref_frame_sign_bias[2] & 1) || 475 (current_frame_info.ref_frame_sign_bias[2] & 1) ||
@@ -530,7 +487,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
530 if (current_frame_info.reference_mode == 2) { 487 if (current_frame_info.reference_mode == 2) {
531 WriteProbabilityUpdate(writer, current_frame_info.entropy.comp_inter_prob, 488 WriteProbabilityUpdate(writer, current_frame_info.entropy.comp_inter_prob,
532 prev_frame_probs.comp_inter_prob); 489 prev_frame_probs.comp_inter_prob);
533 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 490 if (update_probs) {
534 prev_frame_probs.comp_inter_prob = current_frame_info.entropy.comp_inter_prob; 491 prev_frame_probs.comp_inter_prob = current_frame_info.entropy.comp_inter_prob;
535 } 492 }
536 } 493 }
@@ -538,7 +495,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
538 if (current_frame_info.reference_mode != 1) { 495 if (current_frame_info.reference_mode != 1) {
539 WriteProbabilityUpdate(writer, current_frame_info.entropy.single_ref_prob, 496 WriteProbabilityUpdate(writer, current_frame_info.entropy.single_ref_prob,
540 prev_frame_probs.single_ref_prob); 497 prev_frame_probs.single_ref_prob);
541 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 498 if (update_probs) {
542 prev_frame_probs.single_ref_prob = current_frame_info.entropy.single_ref_prob; 499 prev_frame_probs.single_ref_prob = current_frame_info.entropy.single_ref_prob;
543 } 500 }
544 } 501 }
@@ -546,7 +503,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
546 if (current_frame_info.reference_mode != 0) { 503 if (current_frame_info.reference_mode != 0) {
547 WriteProbabilityUpdate(writer, current_frame_info.entropy.comp_ref_prob, 504 WriteProbabilityUpdate(writer, current_frame_info.entropy.comp_ref_prob,
548 prev_frame_probs.comp_ref_prob); 505 prev_frame_probs.comp_ref_prob);
549 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 506 if (update_probs) {
550 prev_frame_probs.comp_ref_prob = current_frame_info.entropy.comp_ref_prob; 507 prev_frame_probs.comp_ref_prob = current_frame_info.entropy.comp_ref_prob;
551 } 508 }
552 } 509 }
@@ -557,42 +514,37 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
557 WriteProbabilityUpdate(writer, current_frame_info.entropy.y_mode_prob[index], 514 WriteProbabilityUpdate(writer, current_frame_info.entropy.y_mode_prob[index],
558 prev_frame_probs.y_mode_prob[index]); 515 prev_frame_probs.y_mode_prob[index]);
559 } 516 }
560 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 517
561 prev_frame_probs.y_mode_prob = current_frame_info.entropy.y_mode_prob;
562 }
563 // read_partition_probs 518 // read_partition_probs
564 WriteProbabilityUpdateAligned4(writer, current_frame_info.entropy.partition_prob, 519 WriteProbabilityUpdateAligned4(writer, current_frame_info.entropy.partition_prob,
565 prev_frame_probs.partition_prob); 520 prev_frame_probs.partition_prob);
566 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) {
567 prev_frame_probs.partition_prob = current_frame_info.entropy.partition_prob;
568 }
569 521
570 // mv_probs 522 // mv_probs
571 for (s32 i = 0; i < 3; i++) { 523 for (s32 i = 0; i < 3; i++) {
572 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.joints[i], 524 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.joints[i],
573 prev_frame_probs.joints[i]); 525 prev_frame_probs.joints[i]);
574 } 526 }
575 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 527 if (update_probs) {
528 prev_frame_probs.inter_mode_prob = current_frame_info.entropy.inter_mode_prob;
529 prev_frame_probs.intra_inter_prob = current_frame_info.entropy.intra_inter_prob;
530 prev_frame_probs.y_mode_prob = current_frame_info.entropy.y_mode_prob;
531 prev_frame_probs.partition_prob = current_frame_info.entropy.partition_prob;
576 prev_frame_probs.joints = current_frame_info.entropy.joints; 532 prev_frame_probs.joints = current_frame_info.entropy.joints;
577 } 533 }
578 534
579 for (s32 i = 0; i < 2; i++) { 535 for (s32 i = 0; i < 2; i++) {
580 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.sign[i], 536 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.sign[i],
581 prev_frame_probs.sign[i]); 537 prev_frame_probs.sign[i]);
582
583 for (s32 j = 0; j < 10; j++) { 538 for (s32 j = 0; j < 10; j++) {
584 const int index = i * 10 + j; 539 const int index = i * 10 + j;
585
586 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.classes[index], 540 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.classes[index],
587 prev_frame_probs.classes[index]); 541 prev_frame_probs.classes[index]);
588 } 542 }
589
590 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.class_0[i], 543 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.class_0[i],
591 prev_frame_probs.class_0[i]); 544 prev_frame_probs.class_0[i]);
592 545
593 for (s32 j = 0; j < 10; j++) { 546 for (s32 j = 0; j < 10; j++) {
594 const int index = i * 10 + j; 547 const int index = i * 10 + j;
595
596 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.prob_bits[index], 548 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.prob_bits[index],
597 prev_frame_probs.prob_bits[index]); 549 prev_frame_probs.prob_bits[index]);
598 } 550 }
@@ -602,7 +554,6 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
602 for (s32 j = 0; j < 2; j++) { 554 for (s32 j = 0; j < 2; j++) {
603 for (s32 k = 0; k < 3; k++) { 555 for (s32 k = 0; k < 3; k++) {
604 const int index = i * 2 * 3 + j * 3 + k; 556 const int index = i * 2 * 3 + j * 3 + k;
605
606 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.class_0_fr[index], 557 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.class_0_fr[index],
607 prev_frame_probs.class_0_fr[index]); 558 prev_frame_probs.class_0_fr[index]);
608 } 559 }
@@ -610,7 +561,6 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
610 561
611 for (s32 j = 0; j < 3; j++) { 562 for (s32 j = 0; j < 3; j++) {
612 const int index = i * 3 + j; 563 const int index = i * 3 + j;
613
614 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.fr[index], 564 WriteMvProbabilityUpdate(writer, current_frame_info.entropy.fr[index],
615 prev_frame_probs.fr[index]); 565 prev_frame_probs.fr[index]);
616 } 566 }
@@ -626,7 +576,7 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
626 } 576 }
627 577
628 // save previous probs 578 // save previous probs
629 if (current_frame_info.show_frame && !current_frame_info.is_key_frame) { 579 if (update_probs) {
630 prev_frame_probs.sign = current_frame_info.entropy.sign; 580 prev_frame_probs.sign = current_frame_info.entropy.sign;
631 prev_frame_probs.classes = current_frame_info.entropy.classes; 581 prev_frame_probs.classes = current_frame_info.entropy.classes;
632 prev_frame_probs.class_0 = current_frame_info.entropy.class_0; 582 prev_frame_probs.class_0 = current_frame_info.entropy.class_0;
@@ -637,7 +587,6 @@ std::vector<u8> VP9::ComposeCompressedHeader() {
637 prev_frame_probs.high_precision = current_frame_info.entropy.high_precision; 587 prev_frame_probs.high_precision = current_frame_info.entropy.high_precision;
638 } 588 }
639 } 589 }
640
641 writer.End(); 590 writer.End();
642 return writer.GetBuffer(); 591 return writer.GetBuffer();
643} 592}
@@ -854,11 +803,11 @@ VpxBitStreamWriter VP9::ComposeUncompressedHeader() {
854 return uncomp_writer; 803 return uncomp_writer;
855} 804}
856 805
857const std::vector<u8>& VP9::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state) { 806const std::vector<u8>& VP9::ComposeFrameHeader(const NvdecCommon::NvdecRegisters& state) {
858 std::vector<u8> bitstream; 807 std::vector<u8> bitstream;
859 { 808 {
860 Vp9FrameContainer curr_frame = GetCurrentFrame(state); 809 Vp9FrameContainer curr_frame = std::move(GetCurrentFrame(state));
861 current_frame_info = curr_frame.info; 810 current_frame_info = std::move(curr_frame.info);
862 bitstream = std::move(curr_frame.bit_stream); 811 bitstream = std::move(curr_frame.bit_stream);
863 } 812 }
864 813
diff --git a/src/video_core/command_classes/codecs/vp9.h b/src/video_core/command_classes/codecs/vp9.h
index e2504512c..9ebbbf59e 100644
--- a/src/video_core/command_classes/codecs/vp9.h
+++ b/src/video_core/command_classes/codecs/vp9.h
@@ -119,7 +119,8 @@ public:
119 119
120 /// Composes the VP9 frame from the GPU state information. Based on the official VP9 spec 120 /// Composes the VP9 frame from the GPU state information. Based on the official VP9 spec
121 /// documentation 121 /// documentation
122 [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state); 122 [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(
123 const NvdecCommon::NvdecRegisters& state);
123 124
124 /// Returns true if the most recent frame was a hidden frame. 125 /// Returns true if the most recent frame was a hidden frame.
125 [[nodiscard]] bool WasFrameHidden() const { 126 [[nodiscard]] bool WasFrameHidden() const {
@@ -147,8 +148,8 @@ private:
147 148
148 /// Writes probability updates for the Coef probabilities 149 /// Writes probability updates for the Coef probabilities
149 void WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode, 150 void WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode,
150 const std::array<u8, 2304>& new_prob, 151 const std::array<u8, 1728>& new_prob,
151 const std::array<u8, 2304>& old_prob); 152 const std::array<u8, 1728>& old_prob);
152 153
153 /// Write probabilities for 4-byte aligned structures 154 /// Write probabilities for 4-byte aligned structures
154 template <typename T, std::size_t N> 155 template <typename T, std::size_t N>
diff --git a/src/video_core/command_classes/codecs/vp9_types.h b/src/video_core/command_classes/codecs/vp9_types.h
index 4f0b05d22..139501a1c 100644
--- a/src/video_core/command_classes/codecs/vp9_types.h
+++ b/src/video_core/command_classes/codecs/vp9_types.h
@@ -31,62 +31,6 @@ enum FrameFlags : u32 {
31 IntraOnly = 1 << 5, 31 IntraOnly = 1 << 5,
32}; 32};
33 33
34enum class MvJointType {
35 MvJointZero = 0, /* Zero vector */
36 MvJointHnzvz = 1, /* Vert zero, hor nonzero */
37 MvJointHzvnz = 2, /* Hor zero, vert nonzero */
38 MvJointHnzvnz = 3, /* Both components nonzero */
39};
40enum class MvClassType {
41 MvClass0 = 0, /* (0, 2] integer pel */
42 MvClass1 = 1, /* (2, 4] integer pel */
43 MvClass2 = 2, /* (4, 8] integer pel */
44 MvClass3 = 3, /* (8, 16] integer pel */
45 MvClass4 = 4, /* (16, 32] integer pel */
46 MvClass5 = 5, /* (32, 64] integer pel */
47 MvClass6 = 6, /* (64, 128] integer pel */
48 MvClass7 = 7, /* (128, 256] integer pel */
49 MvClass8 = 8, /* (256, 512] integer pel */
50 MvClass9 = 9, /* (512, 1024] integer pel */
51 MvClass10 = 10, /* (1024,2048] integer pel */
52};
53
54enum class BlockSize {
55 Block4x4 = 0,
56 Block4x8 = 1,
57 Block8x4 = 2,
58 Block8x8 = 3,
59 Block8x16 = 4,
60 Block16x8 = 5,
61 Block16x16 = 6,
62 Block16x32 = 7,
63 Block32x16 = 8,
64 Block32x32 = 9,
65 Block32x64 = 10,
66 Block64x32 = 11,
67 Block64x64 = 12,
68 BlockSizes = 13,
69 BlockInvalid = BlockSizes
70};
71
72enum class PredictionMode {
73 DcPred = 0, // Average of above and left pixels
74 VPred = 1, // Vertical
75 HPred = 2, // Horizontal
76 D45Pred = 3, // Directional 45 deg = round(arctan(1 / 1) * 180 / pi)
77 D135Pred = 4, // Directional 135 deg = 180 - 45
78 D117Pred = 5, // Directional 117 deg = 180 - 63
79 D153Pred = 6, // Directional 153 deg = 180 - 27
80 D207Pred = 7, // Directional 207 deg = 180 + 27
81 D63Pred = 8, // Directional 63 deg = round(arctan(2 / 1) * 180 / pi)
82 TmPred = 9, // True-motion
83 NearestMv = 10,
84 NearMv = 11,
85 ZeroMv = 12,
86 NewMv = 13,
87 MbModeCount = 14
88};
89
90enum class TxSize { 34enum class TxSize {
91 Tx4x4 = 0, // 4x4 transform 35 Tx4x4 = 0, // 4x4 transform
92 Tx8x8 = 1, // 8x8 transform 36 Tx8x8 = 1, // 8x8 transform
@@ -104,13 +48,6 @@ enum class TxMode {
104 TxModes = 5 48 TxModes = 5
105}; 49};
106 50
107enum class reference_mode {
108 SingleReference = 0,
109 CompoundReference = 1,
110 ReferenceModeSelect = 2,
111 ReferenceModes = 3
112};
113
114struct Segmentation { 51struct Segmentation {
115 u8 enabled{}; 52 u8 enabled{};
116 u8 update_map{}; 53 u8 update_map{};
@@ -131,7 +68,7 @@ static_assert(sizeof(LoopFilter) == 0x7, "LoopFilter is an invalid size");
131struct Vp9EntropyProbs { 68struct Vp9EntropyProbs {
132 std::array<u8, 36> y_mode_prob{}; 69 std::array<u8, 36> y_mode_prob{};
133 std::array<u8, 64> partition_prob{}; 70 std::array<u8, 64> partition_prob{};
134 std::array<u8, 2304> coef_probs{}; 71 std::array<u8, 1728> coef_probs{};
135 std::array<u8, 8> switchable_interp_prob{}; 72 std::array<u8, 8> switchable_interp_prob{};
136 std::array<u8, 28> inter_mode_prob{}; 73 std::array<u8, 28> inter_mode_prob{};
137 std::array<u8, 4> intra_inter_prob{}; 74 std::array<u8, 4> intra_inter_prob{};
@@ -152,7 +89,7 @@ struct Vp9EntropyProbs {
152 std::array<u8, 2> class_0_hp{}; 89 std::array<u8, 2> class_0_hp{};
153 std::array<u8, 2> high_precision{}; 90 std::array<u8, 2> high_precision{};
154}; 91};
155static_assert(sizeof(Vp9EntropyProbs) == 0x9F4, "Vp9EntropyProbs is an invalid size"); 92static_assert(sizeof(Vp9EntropyProbs) == 0x7B4, "Vp9EntropyProbs is an invalid size");
156 93
157struct Vp9PictureInfo { 94struct Vp9PictureInfo {
158 bool is_key_frame{}; 95 bool is_key_frame{};
@@ -278,72 +215,71 @@ static_assert(sizeof(PictureInfo) == 0x100, "PictureInfo is an invalid size");
278 215
279struct EntropyProbs { 216struct EntropyProbs {
280 INSERT_PADDING_BYTES(1024); 217 INSERT_PADDING_BYTES(1024);
281 std::array<std::array<u8, 4>, 7> inter_mode_prob{}; 218 std::array<u8, 28> inter_mode_prob{};
282 std::array<u8, 4> intra_inter_prob{}; 219 std::array<u8, 4> intra_inter_prob{};
283 INSERT_PADDING_BYTES(80); 220 INSERT_PADDING_BYTES(80);
284 std::array<std::array<u8, 1>, 2> tx_8x8_prob{}; 221 std::array<u8, 2> tx_8x8_prob{};
285 std::array<std::array<u8, 2>, 2> tx_16x16_prob{}; 222 std::array<u8, 4> tx_16x16_prob{};
286 std::array<std::array<u8, 3>, 2> tx_32x32_prob{}; 223 std::array<u8, 6> tx_32x32_prob{};
287 std::array<u8, 4> y_mode_prob_e8{}; 224 std::array<u8, 4> y_mode_prob_e8{};
288 std::array<std::array<u8, 8>, 4> y_mode_prob_e0e7{}; 225 std::array<std::array<u8, 8>, 4> y_mode_prob_e0e7{};
289 INSERT_PADDING_BYTES(64); 226 INSERT_PADDING_BYTES(64);
290 std::array<std::array<u8, 4>, 16> partition_prob{}; 227 std::array<u8, 64> partition_prob{};
291 INSERT_PADDING_BYTES(10); 228 INSERT_PADDING_BYTES(10);
292 std::array<std::array<u8, 2>, 4> switchable_interp_prob{}; 229 std::array<u8, 8> switchable_interp_prob{};
293 std::array<u8, 5> comp_inter_prob{}; 230 std::array<u8, 5> comp_inter_prob{};
294 std::array<u8, 4> skip_probs{}; 231 std::array<u8, 3> skip_probs{};
232 INSERT_PADDING_BYTES(1);
295 std::array<u8, 3> joints{}; 233 std::array<u8, 3> joints{};
296 std::array<u8, 2> sign{}; 234 std::array<u8, 2> sign{};
297 std::array<std::array<u8, 1>, 2> class_0{}; 235 std::array<u8, 2> class_0{};
298 std::array<std::array<u8, 3>, 2> fr{}; 236 std::array<u8, 6> fr{};
299 std::array<u8, 2> class_0_hp{}; 237 std::array<u8, 2> class_0_hp{};
300 std::array<u8, 2> high_precision{}; 238 std::array<u8, 2> high_precision{};
301 std::array<std::array<u8, 10>, 2> classes{}; 239 std::array<u8, 20> classes{};
302 std::array<std::array<std::array<u8, 3>, 2>, 2> class_0_fr{}; 240 std::array<u8, 12> class_0_fr{};
303 std::array<std::array<u8, 10>, 2> pred_bits{}; 241 std::array<u8, 20> pred_bits{};
304 std::array<std::array<u8, 2>, 5> single_ref_prob{}; 242 std::array<u8, 10> single_ref_prob{};
305 std::array<u8, 5> comp_ref_prob{}; 243 std::array<u8, 5> comp_ref_prob{};
306 INSERT_PADDING_BYTES(17); 244 INSERT_PADDING_BYTES(17);
307 std::array<std::array<std::array<std::array<std::array<std::array<u8, 4>, 6>, 6>, 2>, 2>, 4> 245 std::array<u8, 2304> coef_probs{};
308 coef_probs{};
309 246
310 void Convert(Vp9EntropyProbs& fc) { 247 void Convert(Vp9EntropyProbs& fc) {
311 std::memcpy(fc.inter_mode_prob.data(), inter_mode_prob.data(), fc.inter_mode_prob.size()); 248 fc.inter_mode_prob = inter_mode_prob;
312 249 fc.intra_inter_prob = intra_inter_prob;
313 std::memcpy(fc.intra_inter_prob.data(), intra_inter_prob.data(), 250 fc.tx_8x8_prob = tx_8x8_prob;
314 fc.intra_inter_prob.size()); 251 fc.tx_16x16_prob = tx_16x16_prob;
315 252 fc.tx_32x32_prob = tx_32x32_prob;
316 std::memcpy(fc.tx_8x8_prob.data(), tx_8x8_prob.data(), fc.tx_8x8_prob.size()); 253
317 std::memcpy(fc.tx_16x16_prob.data(), tx_16x16_prob.data(), fc.tx_16x16_prob.size()); 254 for (std::size_t i = 0; i < 4; i++) {
318 std::memcpy(fc.tx_32x32_prob.data(), tx_32x32_prob.data(), fc.tx_32x32_prob.size()); 255 for (std::size_t j = 0; j < 9; j++) {
319
320 for (s32 i = 0; i < 4; i++) {
321 for (s32 j = 0; j < 9; j++) {
322 fc.y_mode_prob[j + 9 * i] = j < 8 ? y_mode_prob_e0e7[i][j] : y_mode_prob_e8[i]; 256 fc.y_mode_prob[j + 9 * i] = j < 8 ? y_mode_prob_e0e7[i][j] : y_mode_prob_e8[i];
323 } 257 }
324 } 258 }
325 259
326 std::memcpy(fc.partition_prob.data(), partition_prob.data(), fc.partition_prob.size()); 260 fc.partition_prob = partition_prob;
327 261 fc.switchable_interp_prob = switchable_interp_prob;
328 std::memcpy(fc.switchable_interp_prob.data(), switchable_interp_prob.data(), 262 fc.comp_inter_prob = comp_inter_prob;
329 fc.switchable_interp_prob.size()); 263 fc.skip_probs = skip_probs;
330 std::memcpy(fc.comp_inter_prob.data(), comp_inter_prob.data(), fc.comp_inter_prob.size()); 264 fc.joints = joints;
331 std::memcpy(fc.skip_probs.data(), skip_probs.data(), fc.skip_probs.size()); 265 fc.sign = sign;
332 266 fc.class_0 = class_0;
333 std::memcpy(fc.joints.data(), joints.data(), fc.joints.size()); 267 fc.fr = fr;
334 268 fc.class_0_hp = class_0_hp;
335 std::memcpy(fc.sign.data(), sign.data(), fc.sign.size()); 269 fc.high_precision = high_precision;
336 std::memcpy(fc.class_0.data(), class_0.data(), fc.class_0.size()); 270 fc.classes = classes;
337 std::memcpy(fc.fr.data(), fr.data(), fc.fr.size()); 271 fc.class_0_fr = class_0_fr;
338 std::memcpy(fc.class_0_hp.data(), class_0_hp.data(), fc.class_0_hp.size()); 272 fc.prob_bits = pred_bits;
339 std::memcpy(fc.high_precision.data(), high_precision.data(), fc.high_precision.size()); 273 fc.single_ref_prob = single_ref_prob;
340 std::memcpy(fc.classes.data(), classes.data(), fc.classes.size()); 274 fc.comp_ref_prob = comp_ref_prob;
341 std::memcpy(fc.class_0_fr.data(), class_0_fr.data(), fc.class_0_fr.size()); 275
342 std::memcpy(fc.prob_bits.data(), pred_bits.data(), fc.prob_bits.size()); 276 // Skip the 4th element as it goes unused
343 std::memcpy(fc.single_ref_prob.data(), single_ref_prob.data(), fc.single_ref_prob.size()); 277 for (std::size_t i = 0; i < coef_probs.size(); i += 4) {
344 std::memcpy(fc.comp_ref_prob.data(), comp_ref_prob.data(), fc.comp_ref_prob.size()); 278 const std::size_t j = i - i / 4;
345 279 fc.coef_probs[j] = coef_probs[i];
346 std::memcpy(fc.coef_probs.data(), coef_probs.data(), fc.coef_probs.size()); 280 fc.coef_probs[j + 1] = coef_probs[i + 1];
281 fc.coef_probs[j + 2] = coef_probs[i + 2];
282 }
347 } 283 }
348}; 284};
349static_assert(sizeof(EntropyProbs) == 0xEA0, "EntropyProbs is an invalid size"); 285static_assert(sizeof(EntropyProbs) == 0xEA0, "EntropyProbs is an invalid size");
diff --git a/src/video_core/command_classes/nvdec.cpp b/src/video_core/command_classes/nvdec.cpp
index 8ca7a7b06..79e1f4e13 100644
--- a/src/video_core/command_classes/nvdec.cpp
+++ b/src/video_core/command_classes/nvdec.cpp
@@ -29,11 +29,7 @@ void Nvdec::ProcessMethod(Method method, const std::vector<u32>& arguments) {
29 } 29 }
30} 30}
31 31
32AVFrame* Nvdec::GetFrame() { 32AVFramePtr Nvdec::GetFrame() {
33 return codec->GetCurrentFrame();
34}
35
36const AVFrame* Nvdec::GetFrame() const {
37 return codec->GetCurrentFrame(); 33 return codec->GetCurrentFrame();
38} 34}
39 35
diff --git a/src/video_core/command_classes/nvdec.h b/src/video_core/command_classes/nvdec.h
index eec4443f9..e4877c533 100644
--- a/src/video_core/command_classes/nvdec.h
+++ b/src/video_core/command_classes/nvdec.h
@@ -26,8 +26,7 @@ public:
26 void ProcessMethod(Method method, const std::vector<u32>& arguments); 26 void ProcessMethod(Method method, const std::vector<u32>& arguments);
27 27
28 /// Return most recently decoded frame 28 /// Return most recently decoded frame
29 [[nodiscard]] AVFrame* GetFrame(); 29 [[nodiscard]] AVFramePtr GetFrame();
30 [[nodiscard]] const AVFrame* GetFrame() const;
31 30
32private: 31private:
33 /// Invoke codec to decode a frame 32 /// Invoke codec to decode a frame
diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp
index 5b52da277..248443027 100644
--- a/src/video_core/command_classes/vic.cpp
+++ b/src/video_core/command_classes/vic.cpp
@@ -58,17 +58,18 @@ void Vic::Execute() {
58 return; 58 return;
59 } 59 }
60 const VicConfig config{gpu.MemoryManager().Read<u64>(config_struct_address + 0x20)}; 60 const VicConfig config{gpu.MemoryManager().Read<u64>(config_struct_address + 0x20)};
61 const AVFramePtr frame_ptr = std::move(nvdec_processor->GetFrame());
62 const auto* frame = frame_ptr.get();
63 if (!frame || frame->width == 0 || frame->height == 0) {
64 return;
65 }
61 const VideoPixelFormat pixel_format = 66 const VideoPixelFormat pixel_format =
62 static_cast<VideoPixelFormat>(config.pixel_format.Value()); 67 static_cast<VideoPixelFormat>(config.pixel_format.Value());
63 switch (pixel_format) { 68 switch (pixel_format) {
64 case VideoPixelFormat::BGRA8: 69 case VideoPixelFormat::BGRA8:
65 case VideoPixelFormat::RGBA8: { 70 case VideoPixelFormat::RGBA8: {
66 LOG_TRACE(Service_NVDRV, "Writing RGB Frame"); 71 LOG_TRACE(Service_NVDRV, "Writing RGB Frame");
67 const auto* frame = nvdec_processor->GetFrame();
68 72
69 if (!frame || frame->width == 0 || frame->height == 0) {
70 return;
71 }
72 if (scaler_ctx == nullptr || frame->width != scaler_width || 73 if (scaler_ctx == nullptr || frame->width != scaler_width ||
73 frame->height != scaler_height) { 74 frame->height != scaler_height) {
74 const AVPixelFormat target_format = 75 const AVPixelFormat target_format =
@@ -121,12 +122,6 @@ void Vic::Execute() {
121 case VideoPixelFormat::Yuv420: { 122 case VideoPixelFormat::Yuv420: {
122 LOG_TRACE(Service_NVDRV, "Writing YUV420 Frame"); 123 LOG_TRACE(Service_NVDRV, "Writing YUV420 Frame");
123 124
124 const auto* frame = nvdec_processor->GetFrame();
125
126 if (!frame || frame->width == 0 || frame->height == 0) {
127 return;
128 }
129
130 const std::size_t surface_width = config.surface_width_minus1 + 1; 125 const std::size_t surface_width = config.surface_width_minus1 + 1;
131 const std::size_t surface_height = config.surface_height_minus1 + 1; 126 const std::size_t surface_height = config.surface_height_minus1 + 1;
132 const std::size_t half_width = surface_width / 2; 127 const std::size_t half_width = surface_width / 2;