Skip to content

Commit b0f36ca

Browse files
author
N3xoX1
committed
add HandleRasterizerDownload
1 parent 26846be commit b0f36ca

19 files changed

Lines changed: 77 additions & 54 deletions

File tree

src/nxemu-module-spec/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
enum
1818
{
1919
MODULE_LOADER_SPECS_VERSION = 0x0106,
20-
MODULE_VIDEO_SPECS_VERSION = 0x0106,
20+
MODULE_VIDEO_SPECS_VERSION = 0x0107,
2121
MODULE_CPU_SPECS_VERSION = 0x0102,
2222
MODULE_OPERATING_SYSTEM_SPECS_VERSION = 0x0106,
2323
};

src/nxemu-module-spec/video.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct VideoNvFence
2626
uint32_t value;
2727
};
2828

29+
struct RasterizerDownloadArea
30+
{
31+
uint64_t startAddress;
32+
uint64_t endAddress;
33+
bool preemtive;
34+
};
35+
2936
__interface IChannelState
3037
{
3138
bool Initialized() const = 0;
@@ -52,6 +59,7 @@ __interface IVideo
5259
IChannelState * AllocateChannel() = 0;
5360
void PushGPUEntries(int32_t bindId, const uint64_t * commandList, uint32_t commandListSize, const uint32_t * prefetchCommandlist, uint32_t prefetchCommandlistSize) = 0;
5461
void ApplyOpOnDeviceMemoryPointer(const uint8_t * pointer, uint32_t * scratchBuffer, size_t scratchBufferSize, DeviceMemoryOperation operation, void * userData) = 0;
62+
RasterizerDownloadArea OnCPURead(uint64_t addr, uint64_t size) = 0;
5563
bool OnCPUWrite(uint64_t addr, uint64_t size) = 0;
5664
uint32_t HostSyncpointValue(uint32_t id) = 0;
5765
uint32_t HostSyncpointRegisterAction(uint32_t fence_id, uint32_t target_value, HostActionCallback operation, uint32_t slot, void * userData) = 0;

src/nxemu-os/core/memory.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,33 @@ struct Memory::Impl {
797797
return true;
798798
}
799799

800+
struct RasterizerDownloadContext {
801+
Impl * impl;
802+
RasterizerDownloadArea * current_area;
803+
size_t core;
804+
size_t size;
805+
};
806+
807+
static void HandleRasterizerDownloadCallback(uint64_t address, void * user_data)
808+
{
809+
RasterizerDownloadContext & context = *((RasterizerDownloadContext *)user_data);
810+
const DAddr end_address = address + context.size;
811+
if (context.current_area->startAddress <= address && end_address <= context.current_area->endAddress)
812+
[[likely]] {
813+
return;
814+
}
815+
*(context.current_area) = context.impl->system.GetVideo().OnCPURead(address, context.size);
816+
}
817+
800818
void HandleRasterizerDownload(VAddr v_address, size_t size) {
801-
UNIMPLEMENTED();
819+
const auto* p = GetPointerImpl(
820+
v_address, []() {}, []() {});
821+
RasterizerDownloadContext context;
822+
context.impl = this;
823+
context.core = system.GetCurrentHostThreadID();
824+
context.current_area = &rasterizer_read_areas[context.core];
825+
context.size = size;
826+
system.GetVideo().ApplyOpOnDeviceMemoryPointer(p, scratch_buffers[context.core].data(), scratch_buffers[context.core].size(), HandleRasterizerDownloadCallback, &context);
802827
}
803828

804829
struct RasterizerWriteContext {
@@ -858,6 +883,7 @@ struct Memory::Impl {
858883

859884
Core::System& system;
860885
Common::PageTable* current_page_table = nullptr;
886+
std::array<RasterizerDownloadArea, Core::Hardware::NUM_CPU_CORES> rasterizer_read_areas{};
861887
std::array<GPUDirtyState, Core::Hardware::NUM_CPU_CORES> rasterizer_write_areas{};
862888
std::array<Common::ScratchBuffer<u32>, Core::Hardware::NUM_CPU_CORES> scratch_buffers{};
863889
std::span<Core::GPUDirtyMemoryManager> gpu_dirty_managers;

src/nxemu-video/video_manager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void VideoManager::MemoryMap(uint64_t address, uint64_t virtualAddress, uint64_t
137137
impl->m_host1x->MemoryManager().Map(address, virtualAddress, size, Core::Asid{asid}, track);
138138
}
139139

140-
void VideoManager::ApplyOpOnDeviceMemoryPointer(const uint8_t* pointer, uint32_t * scratchBuffer, size_t scratchBufferSize, DeviceMemoryOperation operation, void* userData)
140+
void VideoManager::ApplyOpOnDeviceMemoryPointer(const uint8_t * pointer, uint32_t * scratchBuffer, size_t scratchBufferSize, DeviceMemoryOperation operation, void * userData)
141141
{
142142
Common::ScratchBuffer<u32> tempBuffer;
143143
tempBuffer.resize(scratchBufferSize);
@@ -149,6 +149,11 @@ void VideoManager::ApplyOpOnDeviceMemoryPointer(const uint8_t* pointer, uint32_t
149149
std::memcpy(scratchBuffer, tempBuffer.data(), tempBuffer.size() * sizeof(uint32_t));
150150
}
151151

152+
RasterizerDownloadArea VideoManager::OnCPURead(uint64_t addr, uint64_t size)
153+
{
154+
return impl->m_gpuCore->OnCPURead(addr, size);
155+
}
156+
152157
bool VideoManager::OnCPUWrite(uint64_t addr, uint64_t size)
153158
{
154159
return impl->m_gpuCore->OnCPUWrite(addr, size);

src/nxemu-video/video_manager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class VideoManager :
2828
void UpdateFramebufferLayout(uint32_t width, uint32_t height) override;
2929
IChannelState * AllocateChannel() override;
3030
void PushGPUEntries(int32_t bindId, const uint64_t * commandList, uint32_t commandListSize, const uint32_t * prefetchCommandlist, uint32_t prefetchCommandlistSize);
31-
void ApplyOpOnDeviceMemoryPointer(const uint8_t* pointer, uint32_t* scratchBuffer, size_t scratchBufferSize, DeviceMemoryOperation operation, void* userData) override;
31+
void ApplyOpOnDeviceMemoryPointer(const uint8_t * pointer, uint32_t* scratchBuffer, size_t scratchBufferSize, DeviceMemoryOperation operation, void* userData) override;
32+
RasterizerDownloadArea OnCPURead(uint64_t addr, uint64_t size) override;
3233
bool OnCPUWrite(uint64_t addr, uint64_t size) override;
3334
uint32_t HostSyncpointValue(uint32_t id) override;
3435
uint32_t HostSyncpointRegisterAction(uint32_t fence_id, uint32_t target_value, HostActionCallback operation, uint32_t slot, void * userData) override;

src/yuzu_video_core/buffer_cache/buffer_cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ bool BufferCache<P>::OnCPUWrite(DAddr device_addr, u64 size) {
148148
}
149149

150150
template <class P>
151-
std::optional<VideoCore::RasterizerDownloadArea> BufferCache<P>::GetFlushArea(DAddr device_addr,
151+
std::optional<RasterizerDownloadArea> BufferCache<P>::GetFlushArea(DAddr device_addr,
152152
u64 size) {
153-
std::optional<VideoCore::RasterizerDownloadArea> area{};
153+
std::optional<RasterizerDownloadArea> area{};
154154
area.emplace();
155155
DAddr device_addr_start_aligned = Common::AlignDown(device_addr, Core::DEVICE_PAGESIZE);
156156
DAddr device_addr_end_aligned = Common::AlignUp(device_addr + size, Core::DEVICE_PAGESIZE);
157-
area->start_address = device_addr_start_aligned;
158-
area->end_address = device_addr_end_aligned;
157+
area->startAddress = device_addr_start_aligned;
158+
area->endAddress = device_addr_end_aligned;
159159
if (memory_tracker.IsRegionPreflushable(device_addr, size)) {
160160
area->preemtive = true;
161161
return area;

src/yuzu_video_core/buffer_cache/buffer_cache_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class BufferCache : public VideoCommon::ChannelSetupCaches<BufferCacheChannelInf
207207

208208
void DownloadMemory(DAddr device_addr, u64 size);
209209

210-
std::optional<VideoCore::RasterizerDownloadArea> GetFlushArea(DAddr device_addr, u64 size);
210+
std::optional<RasterizerDownloadArea> GetFlushArea(DAddr device_addr, u64 size);
211211

212212
bool InlineMemory(DAddr dest_address, size_t copy_size, std::span<const u8> inlined_buffer);
213213

src/yuzu_video_core/gpu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ struct GPU::Impl :
274274
gpu_thread.FlushRegion(addr, size);
275275
}
276276

277-
VideoCore::RasterizerDownloadArea OnCPURead(DAddr addr, u64 size) {
277+
RasterizerDownloadArea OnCPURead(DAddr addr, u64 size) {
278278
auto raster_area = rasterizer->GetFlushArea(addr, size);
279279
if (raster_area.preemtive) {
280280
return raster_area;
281281
}
282282
raster_area.preemtive = true;
283283
const u64 fence = RequestSyncOperation([this, &raster_area]() {
284-
rasterizer->FlushRegion(raster_area.start_address,
285-
raster_area.end_address - raster_area.start_address);
284+
rasterizer->FlushRegion(raster_area.startAddress,
285+
raster_area.endAddress - raster_area.startAddress);
286286
});
287287
gpu_thread.TickGPU();
288288
WaitForSyncOperation(fence);
@@ -564,7 +564,7 @@ void GPU::ClearCdmaInstance(u32 id) {
564564
impl->ClearCdmaInstance(id);
565565
}
566566

567-
VideoCore::RasterizerDownloadArea GPU::OnCPURead(PAddr addr, u64 size) {
567+
RasterizerDownloadArea GPU::OnCPURead(PAddr addr, u64 size) {
568568
return impl->OnCPURead(addr, size);
569569
}
570570

src/yuzu_video_core/gpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "yuzu_common/nvdata.h"
1111
#include "yuzu_video_core/cdma_pusher.h"
1212
#include "yuzu_video_core/framebuffer_config.h"
13-
#include "yuzu_video_core/rasterizer_download_area.h"
1413
#include <nxemu-module-spec/operating_system.h>
14+
#include <nxemu-module-spec/video.h>
1515

1616
namespace Core {
1717
class System;
@@ -245,7 +245,7 @@ class GPU final {
245245
void SwapBuffers(const Tegra::FramebufferConfig* framebuffer);
246246

247247
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
248-
[[nodiscard]] VideoCore::RasterizerDownloadArea OnCPURead(DAddr addr, u64 size);
248+
[[nodiscard]] RasterizerDownloadArea OnCPURead(DAddr addr, u64 size);
249249

250250
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
251251
void FlushRegion(DAddr addr, u64 size);

src/yuzu_video_core/rasterizer_download_area.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)