summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service
diff options
context:
space:
mode:
authorFernando S <fsahmkow27@gmail.com>2021-07-15 15:17:50 +0200
committerGitHub <noreply@github.com>2021-07-15 15:17:50 +0200
commitda4ca4f2f94d2d685584b124106c3b344faee6e7 (patch)
treeaba358012ef82ecf200c5b8a1cec2ecd381de6db /src/core/hle/service
parentMerge pull request #6641 from Morph1984/web_browser_urls (diff)
parentvic: Fix dimension compuation of YUV frames (diff)
downloadyuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar.gz
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar.bz2
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar.lz
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar.xz
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.tar.zst
yuzu-da4ca4f2f94d2d685584b124106c3b344faee6e7.zip
Diffstat (limited to 'src/core/hle/service')
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_nvdec_common.cpp85
1 files changed, 40 insertions, 45 deletions
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 98e6296f1..1403a39d0 100644
--- 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 <typename T>
-std::size_t SpliceVectors(const std::vector<u8>& input, std::vector<T>& dst, std::size_t count,
- std::size_t offset) {
- if (!dst.empty()) {
- std::memcpy(dst.data(), input.data() + offset, count * sizeof(T));
+std::size_t SliceVectors(const std::vector<u8>& input, std::vector<T>& dst, std::size_t count,
+ std::size_t offset) {
+ 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 <typename T>
std::size_t WriteVectors(std::vector<u8>& dst, const std::vector<T>& 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<u8>& input, std::vector<u
LOG_DEBUG(Service_NVDRV, "called NVDEC Submit, cmd_buffer_count={}", params.cmd_buffer_count);
// Instantiate param buffers
- std::size_t offset = sizeof(IoctlSubmit);
std::vector<CommandBuffer> command_buffers(params.cmd_buffer_count);
std::vector<Reloc> relocs(params.relocation_count);
std::vector<u32> reloc_shifts(params.relocation_count);
@@ -70,13 +72,14 @@ NvResult nvhost_nvdec_common::Submit(const std::vector<u8>& input, std::vector<u
std::vector<SyncptIncr> wait_checks(params.syncpoint_count);
std::vector<Fence> 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);
+ // Slice input into their respective buffers
+ std::size_t offset = sizeof(IoctlSubmit);
+ offset += SliceVectors(input, command_buffers, params.cmd_buffer_count, offset);
+ offset += SliceVectors(input, relocs, params.relocation_count, offset);
+ offset += SliceVectors(input, reloc_shifts, params.relocation_count, offset);
+ offset += SliceVectors(input, syncpt_increments, params.syncpoint_count, offset);
+ offset += SliceVectors(input, wait_checks, params.syncpoint_count, offset);
+ offset += SliceVectors(input, fences, params.fence_count, offset);
auto& gpu = system.GPU();
if (gpu.UseNvdec()) {
@@ -88,35 +91,27 @@ NvResult nvhost_nvdec_common::Submit(const std::vector<u8>& input, std::vector<u
}
}
for (const auto& cmd_buffer : command_buffers) {
- auto object = nvmap_dev->GetObject(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) {
- LOG_ERROR(Service_NVDRV, "Tried to submit an invalid offset 0x{:X} dma 0x{:X}",
- object->addr, object->dma_map_addr);
- return NvResult::Success;
- }
Tegra::ChCommandHeaderList cmdlist(cmd_buffer.word_count);
- gpu.MemoryManager().ReadBlock(map->StartAddr() + cmd_buffer.offset, cmdlist.data(),
- cmdlist.size() * sizeof(u32));
+ system.Memory().ReadBlock(object->addr + cmd_buffer.offset, cmdlist.data(),
+ cmdlist.size() * sizeof(u32));
gpu.PushCommandBuffer(cmdlist);
}
if (gpu.UseNvdec()) {
-
fences[0].value = syncpoint_manager.IncreaseSyncpoint(fences[0].id, 1);
-
Tegra::ChCommandHeaderList cmdlist{{(4 << 28) | fences[0].id}};
gpu.PushCommandBuffer(cmdlist);
}
std::memcpy(output.data(), &params, sizeof(IoctlSubmit));
// Some games expect command_buffers to be written back
offset = sizeof(IoctlSubmit);
- offset = WriteVectors(output, command_buffers, offset);
- offset = WriteVectors(output, relocs, offset);
- offset = WriteVectors(output, reloc_shifts, offset);
- offset = WriteVectors(output, syncpt_increments, offset);
- offset = WriteVectors(output, wait_checks, offset);
- offset = WriteVectors(output, fences, offset);
+ offset += WriteVectors(output, command_buffers, offset);
+ offset += WriteVectors(output, relocs, offset);
+ offset += WriteVectors(output, reloc_shifts, offset);
+ offset += WriteVectors(output, syncpt_increments, offset);
+ offset += WriteVectors(output, wait_checks, offset);
+ offset += WriteVectors(output, fences, offset);
return NvResult::Success;
}
@@ -148,14 +143,14 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector<u8>& input, std::vecto
std::memcpy(&params, input.data(), sizeof(IoctlMapBuffer));
std::vector<MapBufferEntry> cmd_buffer_handles(params.num_entries);
- SpliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
+ SliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
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(), &params, output.size());
return NvResult::InvalidState;
}
@@ -170,7 +165,7 @@ NvResult nvhost_nvdec_common::MapBuffer(const std::vector<u8>& 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);
}
@@ -186,14 +181,14 @@ NvResult nvhost_nvdec_common::UnmapBuffer(const std::vector<u8>& input, std::vec
IoctlMapBuffer params{};
std::memcpy(&params, input.data(), sizeof(IoctlMapBuffer));
std::vector<MapBufferEntry> cmd_buffer_handles(params.num_entries);
- SpliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
+ SliceVectors(input, cmd_buffer_handles, params.num_entries, sizeof(IoctlMapBuffer));
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(), &params, output.size());
return NvResult::InvalidState;
}