From 230a0aa491925b3b78790ef782408a0e9dff091a Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Fri, 25 Jun 2021 07:57:02 +0200 Subject: [PATCH] early-access version 1826 --- README.md | 2 +- .../nvdrv/devices/nvhost_nvdec_common.cpp | 65 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index fd9356c56..6bfee0c15 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1825. +This is the source code for early-access 1826. ## Legal Notice diff --git a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp index 1375689e7..e57074b0f 100755 --- a/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp @@ -19,26 +19,29 @@ namespace Service::Nvidia::Devices { namespace { -// Splice vectors will copy count amount of type T from the input vector into the dst vector. +// Copies count amount of type T from the input vector into the dst vector. +// Returns the number of bytes written into dst. template std::size_t SpliceVectors(const std::vector& input, std::vector& dst, std::size_t count, std::size_t offset) { - if (!dst.empty()) { - std::memcpy(dst.data(), input.data() + offset, count * sizeof(T)); + if (dst.empty()) { + return 0; } - return 0; + const size_t bytes_copied = count * sizeof(T); + std::memcpy(dst.data(), input.data() + offset, bytes_copied); + return bytes_copied; } -// Write vectors will write data to the output buffer +// Writes the data in src to an offset into the dst vector. The offset is specified in bytes +// Returns the number of bytes written into dst. template std::size_t WriteVectors(std::vector& dst, const std::vector& src, std::size_t offset) { if (src.empty()) { return 0; - } else { - std::memcpy(dst.data() + offset, src.data(), src.size() * sizeof(T)); - offset += src.size() * sizeof(T); - return offset; } + const size_t bytes_copied = src.size() * sizeof(T); + std::memcpy(dst.data() + offset, src.data(), bytes_copied); + return bytes_copied; } } // Anonymous namespace @@ -62,7 +65,6 @@ NvResult nvhost_nvdec_common::Submit(const std::vector& input, std::vector command_buffers(params.cmd_buffer_count); std::vector relocs(params.relocation_count); std::vector reloc_shifts(params.relocation_count); @@ -71,12 +73,13 @@ NvResult nvhost_nvdec_common::Submit(const std::vector& input, std::vector fences(params.fence_count); // Splice input into their respective buffers - offset = SpliceVectors(input, command_buffers, params.cmd_buffer_count, offset); - offset = SpliceVectors(input, relocs, params.relocation_count, offset); - offset = SpliceVectors(input, reloc_shifts, params.relocation_count, offset); - offset = SpliceVectors(input, syncpt_increments, params.syncpoint_count, offset); - offset = SpliceVectors(input, wait_checks, params.syncpoint_count, offset); - offset = SpliceVectors(input, fences, params.fence_count, offset); + std::size_t offset = sizeof(IoctlSubmit); + offset += SpliceVectors(input, command_buffers, params.cmd_buffer_count, offset); + offset += SpliceVectors(input, relocs, params.relocation_count, offset); + offset += SpliceVectors(input, reloc_shifts, params.relocation_count, offset); + offset += SpliceVectors(input, syncpt_increments, params.syncpoint_count, offset); + offset += SpliceVectors(input, wait_checks, params.syncpoint_count, offset); + offset += SpliceVectors(input, fences, params.fence_count, offset); auto& gpu = system.GPU(); if (gpu.UseNvdec()) { @@ -88,7 +91,7 @@ NvResult nvhost_nvdec_common::Submit(const std::vector& input, std::vectorGetObject(cmd_buffer.memory_id); + const auto object = nvmap_dev->GetObject(cmd_buffer.memory_id); ASSERT_OR_EXECUTE(object, return NvResult::InvalidState;); const auto map = FindBufferMap(object->dma_map_addr); if (!map) { @@ -102,21 +105,19 @@ NvResult nvhost_nvdec_common::Submit(const std::vector& input, std::vector& input, std::vecto auto& gpu = system.GPU(); - for (auto& cmf_buff : cmd_buffer_handles) { - auto object{nvmap_dev->GetObject(cmf_buff.map_handle)}; + for (auto& cmd_buffer : cmd_buffer_handles) { + auto object{nvmap_dev->GetObject(cmd_buffer.map_handle)}; if (!object) { - LOG_ERROR(Service_NVDRV, "invalid cmd_buffer nvmap_handle={:X}", cmf_buff.map_handle); + LOG_ERROR(Service_NVDRV, "invalid cmd_buffer nvmap_handle={:X}", cmd_buffer.map_handle); std::memcpy(output.data(), ¶ms, output.size()); return NvResult::InvalidState; } @@ -170,7 +171,7 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector& input, std::vecto if (!object->dma_map_addr) { LOG_ERROR(Service_NVDRV, "failed to map size={}", object->size); } else { - cmf_buff.map_address = object->dma_map_addr; + cmd_buffer.map_address = object->dma_map_addr; AddBufferMap(object->dma_map_addr, object->size, object->addr, object->status == nvmap::Object::Status::Allocated); } @@ -190,10 +191,10 @@ NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector& input, std::vec auto& gpu = system.GPU(); - for (auto& cmf_buff : cmd_buffer_handles) { - const auto object{nvmap_dev->GetObject(cmf_buff.map_handle)}; + for (auto& cmd_buffer : cmd_buffer_handles) { + const auto object{nvmap_dev->GetObject(cmd_buffer.map_handle)}; if (!object) { - LOG_ERROR(Service_NVDRV, "invalid cmd_buffer nvmap_handle={:X}", cmf_buff.map_handle); + LOG_ERROR(Service_NVDRV, "invalid cmd_buffer nvmap_handle={:X}", cmd_buffer.map_handle); std::memcpy(output.data(), ¶ms, output.size()); return NvResult::InvalidState; }