From be6c487b4e2108d98feec10a641d85d1474cf495 Mon Sep 17 00:00:00 2001 From: ameerj Date: Mon, 23 Nov 2020 13:25:01 -0500 Subject: nvdec cleanup --- src/video_core/command_classes/vic.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/video_core/command_classes/vic.cpp') diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp index 2b7569335c..73680d0573 100644 --- a/src/video_core/command_classes/vic.cpp +++ b/src/video_core/command_classes/vic.cpp @@ -18,7 +18,10 @@ extern "C" { namespace Tegra { Vic::Vic(GPU& gpu_, std::shared_ptr nvdec_processor_) - : gpu(gpu_), nvdec_processor(std::move(nvdec_processor_)) {} + : gpu(gpu_), + nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} + +{} Vic::~Vic() = default; void Vic::VicStateWrite(u32 offset, u32 arguments) { @@ -89,8 +92,10 @@ void Vic::Execute() { // Get Converted frame const std::size_t linear_size = frame->width * frame->height * 4; - using AVMallocPtr = std::unique_ptr; - AVMallocPtr converted_frame_buffer{static_cast(av_malloc(linear_size)), av_free}; + // Only allocate frame_buffer once per stream, as the size is not expected to change + if (!converted_frame_buffer) { + converted_frame_buffer = AVMallocPtr{static_cast(av_malloc(linear_size)), av_free}; + } const int converted_stride{frame->width * 4}; u8* const converted_frame_buf_addr{converted_frame_buffer.get()}; @@ -104,12 +109,12 @@ void Vic::Execute() { const u32 block_height = static_cast(config.block_linear_height_log2); const auto size = Tegra::Texture::CalculateSize(true, 4, frame->width, frame->height, 1, block_height, 0); - std::vector swizzled_data(size); + luma_buffer.resize(size); Tegra::Texture::SwizzleSubrect(frame->width, frame->height, frame->width * 4, - frame->width, 4, swizzled_data.data(), + frame->width, 4, luma_buffer.data(), converted_frame_buffer.get(), block_height, 0, 0); - gpu.MemoryManager().WriteBlock(output_surface_luma_address, swizzled_data.data(), size); + gpu.MemoryManager().WriteBlock(output_surface_luma_address, luma_buffer.data(), size); } else { // send pitch linear frame gpu.MemoryManager().WriteBlock(output_surface_luma_address, converted_frame_buf_addr, @@ -132,8 +137,8 @@ void Vic::Execute() { const auto stride = frame->linesize[0]; const auto half_stride = frame->linesize[1]; - std::vector luma_buffer(aligned_width * surface_height); - std::vector chroma_buffer(aligned_width * half_height); + luma_buffer.resize(aligned_width * surface_height); + chroma_buffer.resize(aligned_width * half_height); // Populate luma buffer for (std::size_t y = 0; y < surface_height - 1; ++y) { -- cgit v1.2.3 From 427eca063d73cf75be0083f148bb769908ecdd64 Mon Sep 17 00:00:00 2001 From: ameerj Date: Mon, 23 Nov 2020 15:01:40 -0500 Subject: streamline cdma_pusher/command_classes --- src/video_core/command_classes/vic.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/video_core/command_classes/vic.cpp') diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp index 73680d0573..564f9c1e8e 100644 --- a/src/video_core/command_classes/vic.cpp +++ b/src/video_core/command_classes/vic.cpp @@ -19,20 +19,13 @@ namespace Tegra { Vic::Vic(GPU& gpu_, std::shared_ptr nvdec_processor_) : gpu(gpu_), - nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} + nvdec_processor(std::move(nvdec_processor_)), converted_frame_buffer{nullptr, av_free} {} -{} Vic::~Vic() = default; -void Vic::VicStateWrite(u32 offset, u32 arguments) { - u8* const state_offset = reinterpret_cast(&vic_state) + offset * sizeof(u32); - std::memcpy(state_offset, &arguments, sizeof(u32)); -} - -void Vic::ProcessMethod(Method method, const std::vector& arguments) { - LOG_DEBUG(HW_GPU, "Vic method 0x{:X}", method); - VicStateWrite(static_cast(method), arguments[0]); - const u64 arg = static_cast(arguments[0]) << 8; +void Vic::ProcessMethod(Method method, u32 argument) { + LOG_DEBUG(HW_GPU, "Vic method 0x{:X}", static_cast(method)); + const u64 arg = static_cast(argument) << 8; switch (method) { case Method::Execute: Execute(); @@ -56,8 +49,7 @@ void Vic::ProcessMethod(Method method, const std::vector& arguments) { void Vic::Execute() { if (output_surface_luma_address == 0) { - LOG_ERROR(Service_NVDRV, "VIC Luma address not set. Received 0x{:X}", - vic_state.output_surface.luma_offset); + LOG_ERROR(Service_NVDRV, "VIC Luma address not set."); return; } const VicConfig config{gpu.MemoryManager().Read(config_struct_address + 0x20)}; -- cgit v1.2.3 From 01dec35df344367254cfa658f8a1113f9e512c9d Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Thu, 7 Jan 2021 15:56:15 -0500 Subject: rebase, fix name shadowing, more const --- src/video_core/cdma_pusher.cpp | 6 +++--- src/video_core/command_classes/vic.cpp | 10 +++++----- src/video_core/gpu.cpp | 3 +-- src/video_core/gpu_thread.cpp | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/video_core/command_classes/vic.cpp') diff --git a/src/video_core/cdma_pusher.cpp b/src/video_core/cdma_pusher.cpp index e1f00c4da5..a3fda1094a 100644 --- a/src/video_core/cdma_pusher.cpp +++ b/src/video_core/cdma_pusher.cpp @@ -145,9 +145,9 @@ void CDmaPusher::ExecuteCommand(u32 state_offset, u32 data) { } } -void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 offset, u32 argument) { - u8* const state_offset = reinterpret_cast(&state) + sizeof(u32) * offset; - std::memcpy(state_offset, &argument, sizeof(u32)); +void CDmaPusher::ThiStateWrite(ThiRegisters& state, u32 state_offset, u32 argument) { + u8* const offset_ptr = reinterpret_cast(&state) + sizeof(u32) * state_offset; + std::memcpy(offset_ptr, &argument, sizeof(u32)); } } // namespace Tegra diff --git a/src/video_core/command_classes/vic.cpp b/src/video_core/command_classes/vic.cpp index 564f9c1e8e..0a8b82f2b8 100644 --- a/src/video_core/command_classes/vic.cpp +++ b/src/video_core/command_classes/vic.cpp @@ -134,10 +134,10 @@ void Vic::Execute() { // Populate luma buffer for (std::size_t y = 0; y < surface_height - 1; ++y) { - std::size_t src = y * stride; - std::size_t dst = y * aligned_width; + const std::size_t src = y * stride; + const std::size_t dst = y * aligned_width; - std::size_t size = surface_width; + const std::size_t size = surface_width; for (std::size_t offset = 0; offset < size; ++offset) { luma_buffer[dst + offset] = luma_ptr[src + offset]; @@ -148,8 +148,8 @@ void Vic::Execute() { // Populate chroma buffer from both channels with interleaving. for (std::size_t y = 0; y < half_height; ++y) { - std::size_t src = y * half_stride; - std::size_t dst = y * aligned_width; + const std::size_t src = y * half_stride; + const std::size_t dst = y * aligned_width; for (std::size_t x = 0; x < half_width; ++x) { chroma_buffer[dst + x * 2] = chroma_b_ptr[src + x]; diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 3db33faf3c..51c63af4ae 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -493,8 +493,7 @@ void GPU::PushCommandBuffer(Tegra::ChCommandHeaderList& entries) { // TODO(ameerj): RE proper async nvdec operation // gpu_thread.SubmitCommandBuffer(std::move(entries)); - cdma_pusher->Push(std::move(entries)); - cdma_pusher->DispatchCalls(); + cdma_pusher->ProcessEntries(std::move(entries)); } void GPU::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 7644588e34..eb0e43c0cd 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -49,7 +49,7 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, } else if (auto* command_list = std::get_if(&next.data)) { // NVDEC cdma_pusher.ProcessEntries(std::move(command_list->entries)); - } else if (const auto data = std::get_if(&next.data)) { + } else if (const auto* data = std::get_if(&next.data)) { renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); } else if (std::holds_alternative(next.data)) { rasterizer->ReleaseFences(); -- cgit v1.2.3