From 4bc2d821300354e0d178c520b4b3520afbf8ff20 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sun, 18 Dec 2022 18:09:59 -0500 Subject: [PATCH] video_core: Add usages of ScratchBuffer --- src/video_core/engines/engine_upload.h | 7 +++--- src/video_core/engines/maxwell_dma.cpp | 32 +++++++------------------- src/video_core/engines/maxwell_dma.h | 8 ++++--- src/video_core/host1x/vic.h | 7 +++--- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/video_core/engines/engine_upload.h b/src/video_core/engines/engine_upload.h index 94fafd9dce..7242d25292 100644 --- a/src/video_core/engines/engine_upload.h +++ b/src/video_core/engines/engine_upload.h @@ -4,9 +4,10 @@ #pragma once #include -#include + #include "common/bit_field.h" #include "common/common_types.h" +#include "common/scratch_buffer.h" namespace Tegra { class MemoryManager; @@ -73,8 +74,8 @@ private: u32 write_offset = 0; u32 copy_size = 0; - std::vector inner_buffer; - std::vector tmp_buffer; + Common::ScratchBuffer inner_buffer; + Common::ScratchBuffer tmp_buffer; bool is_linear = false; Registers& regs; MemoryManager& memory_manager; diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index a189e60ae2..dc873732eb 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp @@ -184,12 +184,8 @@ void MaxwellDMA::CopyBlockLinearToPitch() { const size_t src_size = CalculateSize(true, bytes_per_pixel, width, height, depth, block_height, block_depth); - if (read_buffer.size() < src_size) { - read_buffer.resize(src_size); - } - if (write_buffer.size() < dst_size) { - write_buffer.resize(dst_size); - } + read_buffer.resize(src_size); + write_buffer.resize(dst_size); memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); @@ -235,12 +231,8 @@ void MaxwellDMA::CopyPitchToBlockLinear() { CalculateSize(true, bytes_per_pixel, width, height, depth, block_height, block_depth); const size_t src_size = static_cast(regs.pitch_in) * regs.line_count; - if (read_buffer.size() < src_size) { - read_buffer.resize(src_size); - } - if (write_buffer.size() < dst_size) { - write_buffer.resize(dst_size); - } + read_buffer.resize(src_size); + write_buffer.resize(dst_size); memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); if (Settings::IsGPULevelExtreme()) { @@ -269,12 +261,8 @@ void MaxwellDMA::FastCopyBlockLinearToPitch() { pos_x = pos_x % x_in_gob; pos_y = pos_y % 8; - if (read_buffer.size() < src_size) { - read_buffer.resize(src_size); - } - if (write_buffer.size() < dst_size) { - write_buffer.resize(dst_size); - } + read_buffer.resize(src_size); + write_buffer.resize(dst_size); if (Settings::IsGPULevelExtreme()) { memory_manager.ReadBlock(regs.offset_in + offset, read_buffer.data(), src_size); @@ -333,12 +321,8 @@ void MaxwellDMA::CopyBlockLinearToBlockLinear() { const u32 pitch = x_elements * bytes_per_pixel; const size_t mid_buffer_size = pitch * regs.line_count; - if (read_buffer.size() < src_size) { - read_buffer.resize(src_size); - } - if (write_buffer.size() < dst_size) { - write_buffer.resize(dst_size); - } + read_buffer.resize(src_size); + write_buffer.resize(dst_size); intermediate_buffer.resize(mid_buffer_size); diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h index d40d3d3022..c88191a613 100644 --- a/src/video_core/engines/maxwell_dma.h +++ b/src/video_core/engines/maxwell_dma.h @@ -6,8 +6,10 @@ #include #include #include + #include "common/bit_field.h" #include "common/common_types.h" +#include "common/scratch_buffer.h" #include "video_core/engines/engine_interface.h" namespace Core { @@ -234,9 +236,9 @@ private: MemoryManager& memory_manager; VideoCore::RasterizerInterface* rasterizer = nullptr; - std::vector read_buffer; - std::vector write_buffer; - std::vector intermediate_buffer; + Common::ScratchBuffer read_buffer; + Common::ScratchBuffer write_buffer; + Common::ScratchBuffer intermediate_buffer; static constexpr std::size_t NUM_REGS = 0x800; struct Regs { diff --git a/src/video_core/host1x/vic.h b/src/video_core/host1x/vic.h index 2b78786e85..3d9753047b 100644 --- a/src/video_core/host1x/vic.h +++ b/src/video_core/host1x/vic.h @@ -4,8 +4,9 @@ #pragma once #include -#include + #include "common/common_types.h" +#include "common/scratch_buffer.h" struct SwsContext; @@ -49,8 +50,8 @@ private: /// size does not change during a stream using AVMallocPtr = std::unique_ptr; AVMallocPtr converted_frame_buffer; - std::vector luma_buffer; - std::vector chroma_buffer; + Common::ScratchBuffer luma_buffer; + Common::ScratchBuffer chroma_buffer; GPUVAddr config_struct_address{}; GPUVAddr output_surface_luma_address{};