mirror of
				https://git.eden-emu.dev/eden-emu/eden.git
				synced 2025-10-26 12:33:22 +00:00 
			
		
		
		
	general: Use ScratchBuffer where possible
This commit is contained in:
		
							parent
							
								
									accc43e31f
								
							
						
					
					
						commit
						b8004b2472
					
				
					 14 changed files with 81 additions and 64 deletions
				
			
		|  | @ -290,7 +290,7 @@ void Codec::Decode() { | |||
|             return vp9_decoder->GetFrameBytes(); | ||||
|         default: | ||||
|             ASSERT(false); | ||||
|             return std::vector<u8>{}; | ||||
|             return std::span<const u8>{}; | ||||
|         } | ||||
|     }(); | ||||
|     AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter}; | ||||
|  |  | |||
|  | @ -29,15 +29,15 @@ H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {} | |||
| 
 | ||||
| H264::~H264() = default; | ||||
| 
 | ||||
| const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, | ||||
|                                           bool is_first_frame) { | ||||
| std::span<const u8> H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, | ||||
|                                        bool is_first_frame) { | ||||
|     H264DecoderContext context; | ||||
|     host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context, | ||||
|                                      sizeof(H264DecoderContext)); | ||||
| 
 | ||||
|     const s64 frame_number = context.h264_parameter_set.frame_number.Value(); | ||||
|     if (!is_first_frame && frame_number != 0) { | ||||
|         frame.resize(context.stream_len); | ||||
|         frame.resize_destructive(context.stream_len); | ||||
|         host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size()); | ||||
|         return frame; | ||||
|     } | ||||
|  | @ -135,14 +135,14 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist | |||
|     for (s32 index = 0; index < 6; index++) { | ||||
|         writer.WriteBit(true); | ||||
|         std::span<const u8> matrix{context.weight_scale}; | ||||
|         writer.WriteScalingList(matrix, index * 16, 16); | ||||
|         writer.WriteScalingList(scan, matrix, index * 16, 16); | ||||
|     } | ||||
| 
 | ||||
|     if (context.h264_parameter_set.transform_8x8_mode_flag) { | ||||
|         for (s32 index = 0; index < 2; index++) { | ||||
|             writer.WriteBit(true); | ||||
|             std::span<const u8> matrix{context.weight_scale_8x8}; | ||||
|             writer.WriteScalingList(matrix, index * 64, 64); | ||||
|             writer.WriteScalingList(scan, matrix, index * 64, 64); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -188,8 +188,8 @@ void H264BitWriter::WriteBit(bool state) { | |||
|     WriteBits(state ? 1 : 0, 1); | ||||
| } | ||||
| 
 | ||||
| void H264BitWriter::WriteScalingList(std::span<const u8> list, s32 start, s32 count) { | ||||
|     static Common::ScratchBuffer<u8> scan{}; | ||||
| void H264BitWriter::WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, | ||||
|                                      s32 start, s32 count) { | ||||
|     scan.resize_destructive(count); | ||||
|     if (count == 16) { | ||||
|         std::memcpy(scan.data(), zig_zag_scan.data(), scan.size()); | ||||
|  |  | |||
|  | @ -5,9 +5,11 @@ | |||
| 
 | ||||
| #include <span> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "common/bit_field.h" | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/scratch_buffer.h" | ||||
| #include "video_core/host1x/nvdec_common.h" | ||||
| 
 | ||||
| namespace Tegra { | ||||
|  | @ -37,7 +39,8 @@ public: | |||
| 
 | ||||
|     /// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification
 | ||||
|     /// Writes the scaling matrices of the sream
 | ||||
|     void WriteScalingList(std::span<const u8> list, s32 start, s32 count); | ||||
|     void WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, s32 start, | ||||
|                           s32 count); | ||||
| 
 | ||||
|     /// Return the bitstream as a vector.
 | ||||
|     [[nodiscard]] std::vector<u8>& GetByteArray(); | ||||
|  | @ -63,11 +66,12 @@ public: | |||
|     ~H264(); | ||||
| 
 | ||||
|     /// Compose the H264 frame for FFmpeg decoding
 | ||||
|     [[nodiscard]] const std::vector<u8>& ComposeFrame( | ||||
|         const Host1x::NvdecCommon::NvdecRegisters& state, bool is_first_frame = false); | ||||
|     [[nodiscard]] std::span<const u8> ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state, | ||||
|                                                    bool is_first_frame = false); | ||||
| 
 | ||||
| private: | ||||
|     std::vector<u8> frame; | ||||
|     Common::ScratchBuffer<u8> frame; | ||||
|     Common::ScratchBuffer<u8> scan; | ||||
|     Host1x::Host1x& host1x; | ||||
| 
 | ||||
|     struct H264ParameterSet { | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {} | |||
| 
 | ||||
| VP8::~VP8() = default; | ||||
| 
 | ||||
| const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { | ||||
| std::span<const u8> VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) { | ||||
|     VP8PictureInfo info; | ||||
|     host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo)); | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,10 +4,11 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include <vector> | ||||
| #include <span> | ||||
| 
 | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| #include "common/scratch_buffer.h" | ||||
| #include "video_core/host1x/nvdec_common.h" | ||||
| 
 | ||||
| namespace Tegra { | ||||
|  | @ -24,11 +25,11 @@ public: | |||
|     ~VP8(); | ||||
| 
 | ||||
|     /// Compose the VP8 frame for FFmpeg decoding
 | ||||
|     [[nodiscard]] const std::vector<u8>& ComposeFrame( | ||||
|     [[nodiscard]] std::span<const u8> ComposeFrame( | ||||
|         const Host1x::NvdecCommon::NvdecRegisters& state); | ||||
| 
 | ||||
| private: | ||||
|     std::vector<u8> frame; | ||||
|     Common::ScratchBuffer<u8> frame; | ||||
|     Host1x::Host1x& host1x; | ||||
| 
 | ||||
|     struct VP8PictureInfo { | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| 
 | ||||
| #include <algorithm> // for std::copy
 | ||||
| #include <numeric> | ||||
| 
 | ||||
| #include "common/assert.h" | ||||
| #include "video_core/host1x/codecs/vp9.h" | ||||
| #include "video_core/host1x/host1x.h" | ||||
|  |  | |||
|  | @ -4,9 +4,11 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include <span> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "common/common_types.h" | ||||
| #include "common/scratch_buffer.h" | ||||
| #include "common/stream.h" | ||||
| #include "video_core/host1x/codecs/vp9_types.h" | ||||
| #include "video_core/host1x/nvdec_common.h" | ||||
|  | @ -128,8 +130,8 @@ public: | |||
|         return !current_frame_info.show_frame; | ||||
|     } | ||||
| 
 | ||||
|     /// Returns a const reference to the composed frame data.
 | ||||
|     [[nodiscard]] const std::vector<u8>& GetFrameBytes() const { | ||||
|     /// Returns a const span to the composed frame data.
 | ||||
|     [[nodiscard]] std::span<const u8> GetFrameBytes() const { | ||||
|         return frame; | ||||
|     } | ||||
| 
 | ||||
|  | @ -181,7 +183,7 @@ private: | |||
|     [[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader(); | ||||
| 
 | ||||
|     Host1x::Host1x& host1x; | ||||
|     std::vector<u8> frame; | ||||
|     Common::ScratchBuffer<u8> frame; | ||||
| 
 | ||||
|     std::array<s8, 4> loop_filter_ref_deltas{}; | ||||
|     std::array<s8, 2> loop_filter_mode_deltas{}; | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| 
 | ||||
| #include <array> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "common/common_funcs.h" | ||||
| #include "common/common_types.h" | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Morph
						Morph