diff options
| author | 2023-06-24 21:58:23 -0400 | |
|---|---|---|
| committer | 2023-06-30 21:49:59 -0400 | |
| commit | 310b6cf4af940fa07666400426bbcca815c5375c (patch) | |
| tree | d3de4ddab952c5404be38035ece48773c0be41ac /src/video_core/host1x | |
| parent | ring_buffer: Fix const usage on std::span (diff) | |
| download | yuzu-310b6cf4af940fa07666400426bbcca815c5375c.tar.gz yuzu-310b6cf4af940fa07666400426bbcca815c5375c.tar.xz yuzu-310b6cf4af940fa07666400426bbcca815c5375c.zip | |
general: Use ScratchBuffer where possible
Diffstat (limited to 'src/video_core/host1x')
| -rw-r--r-- | src/video_core/host1x/codecs/codec.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/h264.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/h264.h | 12 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/vp8.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/vp8.h | 7 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/vp9.cpp | 1 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/vp9.h | 8 | ||||
| -rw-r--r-- | src/video_core/host1x/codecs/vp9_types.h | 1 |
8 files changed, 28 insertions, 19 deletions
diff --git a/src/video_core/host1x/codecs/codec.cpp b/src/video_core/host1x/codecs/codec.cpp index cd6a3a9b8..da07a556f 100644 --- a/src/video_core/host1x/codecs/codec.cpp +++ b/src/video_core/host1x/codecs/codec.cpp | |||
| @@ -290,7 +290,7 @@ void Codec::Decode() { | |||
| 290 | return vp9_decoder->GetFrameBytes(); | 290 | return vp9_decoder->GetFrameBytes(); |
| 291 | default: | 291 | default: |
| 292 | ASSERT(false); | 292 | ASSERT(false); |
| 293 | return std::vector<u8>{}; | 293 | return std::span<const u8>{}; |
| 294 | } | 294 | } |
| 295 | }(); | 295 | }(); |
| 296 | AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter}; | 296 | AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter}; |
diff --git a/src/video_core/host1x/codecs/h264.cpp b/src/video_core/host1x/codecs/h264.cpp index ce827eb6c..862904e39 100644 --- a/src/video_core/host1x/codecs/h264.cpp +++ b/src/video_core/host1x/codecs/h264.cpp | |||
| @@ -29,15 +29,15 @@ H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {} | |||
| 29 | 29 | ||
| 30 | H264::~H264() = default; | 30 | H264::~H264() = default; |
| 31 | 31 | ||
| 32 | const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, | 32 | std::span<const u8> H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, |
| 33 | bool is_first_frame) { | 33 | bool is_first_frame) { |
| 34 | H264DecoderContext context; | 34 | H264DecoderContext context; |
| 35 | host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context, | 35 | host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context, |
| 36 | sizeof(H264DecoderContext)); | 36 | sizeof(H264DecoderContext)); |
| 37 | 37 | ||
| 38 | const s64 frame_number = context.h264_parameter_set.frame_number.Value(); | 38 | const s64 frame_number = context.h264_parameter_set.frame_number.Value(); |
| 39 | if (!is_first_frame && frame_number != 0) { | 39 | if (!is_first_frame && frame_number != 0) { |
| 40 | frame.resize(context.stream_len); | 40 | frame.resize_destructive(context.stream_len); |
| 41 | host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); | 41 | host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); |
| 42 | return frame; | 42 | return frame; |
| 43 | } | 43 | } |
| @@ -135,14 +135,14 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist | |||
| 135 | for (s32 index = 0; index < 6; index++) { | 135 | for (s32 index = 0; index < 6; index++) { |
| 136 | writer.WriteBit(true); | 136 | writer.WriteBit(true); |
| 137 | std::span<const u8> matrix{context.weight_scale}; | 137 | std::span<const u8> matrix{context.weight_scale}; |
| 138 | writer.WriteScalingList(matrix, index * 16, 16); | 138 | writer.WriteScalingList(scan, matrix, index * 16, 16); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | if (context.h264_parameter_set.transform_8x8_mode_flag) { | 141 | if (context.h264_parameter_set.transform_8x8_mode_flag) { |
| 142 | for (s32 index = 0; index < 2; index++) { | 142 | for (s32 index = 0; index < 2; index++) { |
| 143 | writer.WriteBit(true); | 143 | writer.WriteBit(true); |
| 144 | std::span<const u8> matrix{context.weight_scale_8x8}; | 144 | std::span<const u8> matrix{context.weight_scale_8x8}; |
| 145 | writer.WriteScalingList(matrix, index * 64, 64); | 145 | writer.WriteScalingList(scan, matrix, index * 64, 64); |
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | 148 | ||
| @@ -188,8 +188,8 @@ void H264BitWriter::WriteBit(bool state) { | |||
| 188 | WriteBits(state ? 1 : 0, 1); | 188 | WriteBits(state ? 1 : 0, 1); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | void H264BitWriter::WriteScalingList(std::span<const u8> list, s32 start, s32 count) { | 191 | void H264BitWriter::WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, |
| 192 | static Common::ScratchBuffer<u8> scan{}; | 192 | s32 start, s32 count) { |
| 193 | scan.resize_destructive(count); | 193 | scan.resize_destructive(count); |
| 194 | if (count == 16) { | 194 | if (count == 16) { |
| 195 | std::memcpy(scan.data(), zig_zag_scan.data(), scan.size()); | 195 | std::memcpy(scan.data(), zig_zag_scan.data(), scan.size()); |
diff --git a/src/video_core/host1x/codecs/h264.h b/src/video_core/host1x/codecs/h264.h index 5cc86454e..d6b556322 100644 --- a/src/video_core/host1x/codecs/h264.h +++ b/src/video_core/host1x/codecs/h264.h | |||
| @@ -5,9 +5,11 @@ | |||
| 5 | 5 | ||
| 6 | #include <span> | 6 | #include <span> |
| 7 | #include <vector> | 7 | #include <vector> |
| 8 | |||
| 8 | #include "common/bit_field.h" | 9 | #include "common/bit_field.h" |
| 9 | #include "common/common_funcs.h" | 10 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "common/scratch_buffer.h" | ||
| 11 | #include "video_core/host1x/nvdec_common.h" | 13 | #include "video_core/host1x/nvdec_common.h" |
| 12 | 14 | ||
| 13 | namespace Tegra { | 15 | namespace Tegra { |
| @@ -37,7 +39,8 @@ public: | |||
| 37 | 39 | ||
| 38 | /// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification | 40 | /// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification |
| 39 | /// Writes the scaling matrices of the sream | 41 | /// Writes the scaling matrices of the sream |
| 40 | void WriteScalingList(std::span<const u8> list, s32 start, s32 count); | 42 | void WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, s32 start, |
| 43 | s32 count); | ||
| 41 | 44 | ||
| 42 | /// Return the bitstream as a vector. | 45 | /// Return the bitstream as a vector. |
| 43 | [[nodiscard]] std::vector<u8>& GetByteArray(); | 46 | [[nodiscard]] std::vector<u8>& GetByteArray(); |
| @@ -63,11 +66,12 @@ public: | |||
| 63 | ~H264(); | 66 | ~H264(); |
| 64 | 67 | ||
| 65 | /// Compose the H264 frame for FFmpeg decoding | 68 | /// Compose the H264 frame for FFmpeg decoding |
| 66 | [[nodiscard]] const std::vector<u8>& ComposeFrame( | 69 | [[nodiscard]] std::span<const u8> ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, |
| 67 | const Host1x::NvdecCommon::NvdecRegisters& state, bool is_first_frame = false); | 70 | bool is_first_frame = false); |
| 68 | 71 | ||
| 69 | private: | 72 | private: |
| 70 | std::vector<u8> frame; | 73 | Common::ScratchBuffer<u8> frame; |
| 74 | Common::ScratchBuffer<u8> scan; | ||
| 71 | Host1x::Host1x& host1x; | 75 | Host1x::Host1x& host1x; |
| 72 | 76 | ||
| 73 | struct H264ParameterSet { | 77 | struct H264ParameterSet { |
diff --git a/src/video_core/host1x/codecs/vp8.cpp b/src/video_core/host1x/codecs/vp8.cpp index 28fb12cb8..ee6392ff9 100644 --- a/src/video_core/host1x/codecs/vp8.cpp +++ b/src/video_core/host1x/codecs/vp8.cpp | |||
| @@ -12,7 +12,7 @@ VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {} | |||
| 12 | 12 | ||
| 13 | VP8::~VP8() = default; | 13 | VP8::~VP8() = default; |
| 14 | 14 | ||
| 15 | const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { | 15 | std::span<const u8> VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { |
| 16 | VP8PictureInfo info; | 16 | VP8PictureInfo info; |
| 17 | host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); | 17 | host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); |
| 18 | 18 | ||
diff --git a/src/video_core/host1x/codecs/vp8.h b/src/video_core/host1x/codecs/vp8.h index 5bf07ecab..7926b73f3 100644 --- a/src/video_core/host1x/codecs/vp8.h +++ b/src/video_core/host1x/codecs/vp8.h | |||
| @@ -4,10 +4,11 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <vector> | 7 | #include <span> |
| 8 | 8 | ||
| 9 | #include "common/common_funcs.h" | 9 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/scratch_buffer.h" | ||
| 11 | #include "video_core/host1x/nvdec_common.h" | 12 | #include "video_core/host1x/nvdec_common.h" |
| 12 | 13 | ||
| 13 | namespace Tegra { | 14 | namespace Tegra { |
| @@ -24,11 +25,11 @@ public: | |||
| 24 | ~VP8(); | 25 | ~VP8(); |
| 25 | 26 | ||
| 26 | /// Compose the VP8 frame for FFmpeg decoding | 27 | /// Compose the VP8 frame for FFmpeg decoding |
| 27 | [[nodiscard]] const std::vector<u8>& ComposeFrame( | 28 | [[nodiscard]] std::span<const u8> ComposeFrame( |
| 28 | const Host1x::NvdecCommon::NvdecRegisters& state); | 29 | const Host1x::NvdecCommon::NvdecRegisters& state); |
| 29 | 30 | ||
| 30 | private: | 31 | private: |
| 31 | std::vector<u8> frame; | 32 | Common::ScratchBuffer<u8> frame; |
| 32 | Host1x::Host1x& host1x; | 33 | Host1x::Host1x& host1x; |
| 33 | 34 | ||
| 34 | struct VP8PictureInfo { | 35 | struct VP8PictureInfo { |
diff --git a/src/video_core/host1x/codecs/vp9.cpp b/src/video_core/host1x/codecs/vp9.cpp index cf40c9012..306c3d0e8 100644 --- a/src/video_core/host1x/codecs/vp9.cpp +++ b/src/video_core/host1x/codecs/vp9.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include <algorithm> // for std::copy | 4 | #include <algorithm> // for std::copy |
| 5 | #include <numeric> | 5 | #include <numeric> |
| 6 | |||
| 6 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 7 | #include "video_core/host1x/codecs/vp9.h" | 8 | #include "video_core/host1x/codecs/vp9.h" |
| 8 | #include "video_core/host1x/host1x.h" | 9 | #include "video_core/host1x/host1x.h" |
diff --git a/src/video_core/host1x/codecs/vp9.h b/src/video_core/host1x/codecs/vp9.h index d4083e8d3..f1ed19508 100644 --- a/src/video_core/host1x/codecs/vp9.h +++ b/src/video_core/host1x/codecs/vp9.h | |||
| @@ -4,9 +4,11 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <span> | ||
| 7 | #include <vector> | 8 | #include <vector> |
| 8 | 9 | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/scratch_buffer.h" | ||
| 10 | #include "common/stream.h" | 12 | #include "common/stream.h" |
| 11 | #include "video_core/host1x/codecs/vp9_types.h" | 13 | #include "video_core/host1x/codecs/vp9_types.h" |
| 12 | #include "video_core/host1x/nvdec_common.h" | 14 | #include "video_core/host1x/nvdec_common.h" |
| @@ -128,8 +130,8 @@ public: | |||
| 128 | return !current_frame_info.show_frame; | 130 | return !current_frame_info.show_frame; |
| 129 | } | 131 | } |
| 130 | 132 | ||
| 131 | /// Returns a const reference to the composed frame data. | 133 | /// Returns a const span to the composed frame data. |
| 132 | [[nodiscard]] const std::vector<u8>& GetFrameBytes() const { | 134 | [[nodiscard]] std::span<const u8> GetFrameBytes() const { |
| 133 | return frame; | 135 | return frame; |
| 134 | } | 136 | } |
| 135 | 137 | ||
| @@ -181,7 +183,7 @@ private: | |||
| 181 | [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); | 183 | [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); |
| 182 | 184 | ||
| 183 | Host1x::Host1x& host1x; | 185 | Host1x::Host1x& host1x; |
| 184 | std::vector<u8> frame; | 186 | Common::ScratchBuffer<u8> frame; |
| 185 | 187 | ||
| 186 | std::array<s8, 4> loop_filter_ref_deltas{}; | 188 | std::array<s8, 4> loop_filter_ref_deltas{}; |
| 187 | std::array<s8, 2> loop_filter_mode_deltas{}; | 189 | std::array<s8, 2> loop_filter_mode_deltas{}; |
diff --git a/src/video_core/host1x/codecs/vp9_types.h b/src/video_core/host1x/codecs/vp9_types.h index adad8ed7e..cc9b25690 100644 --- a/src/video_core/host1x/codecs/vp9_types.h +++ b/src/video_core/host1x/codecs/vp9_types.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <vector> | 7 | #include <vector> |
| 8 | |||
| 8 | #include "common/common_funcs.h" | 9 | #include "common/common_funcs.h" |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 10 | 11 | ||