Skip to content

Commit af405c8

Browse files
committed
Readbacks proof of concept shadps4-emu#2668
1 parent 9f914db commit af405c8

File tree

14 files changed

+424
-208
lines changed

14 files changed

+424
-208
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
894894
src/video_core/buffer_cache/buffer.h
895895
src/video_core/buffer_cache/buffer_cache.cpp
896896
src/video_core/buffer_cache/buffer_cache.h
897-
src/video_core/buffer_cache/memory_tracker_base.h
897+
src/video_core/buffer_cache/memory_tracker.h
898898
src/video_core/buffer_cache/range_set.h
899899
src/video_core/buffer_cache/word_manager.h
900900
src/video_core/renderer_vulkan/liverpool_to_vk.cpp

src/core/address_space.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,15 @@ struct AddressSpace::Impl {
302302
new_flags = PAGE_READWRITE;
303303
} else if (read && !write) {
304304
new_flags = PAGE_READONLY;
305-
} else if (execute && !read && not write) {
305+
} else if (execute && !read && !write) {
306306
new_flags = PAGE_EXECUTE;
307307
} else if (!read && !write && !execute) {
308308
new_flags = PAGE_NOACCESS;
309309
} else {
310310
LOG_CRITICAL(Common_Memory,
311-
"Unsupported protection flag combination for address {:#x}, size {}",
312-
virtual_addr, size);
311+
"Unsupported protection flag combination for address {:#x}, size {}, "
312+
"read={}, write={}, execute={}",
313+
virtual_addr, size, read, write, execute);
313314
return;
314315
}
315316

src/core/address_space.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Core {
1212

1313
enum class MemoryPermission : u32 {
14+
None = 0,
1415
Read = 1 << 0,
1516
Write = 1 << 1,
1617
ReadWrite = Read | Write,

src/video_core/amdgpu/liverpool.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Liverpool::~Liverpool() {
7474

7575
void Liverpool::Process(std::stop_token stoken) {
7676
Common::SetCurrentThreadName("shadPS4:GpuCommandProcessor");
77+
gpu_id = std::this_thread::get_id();
7778

7879
while (!stoken.stop_requested()) {
7980
{
@@ -628,9 +629,8 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
628629
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
629630
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
630631
dma_data->dst_sel == DmaDataDst::Gds) {
631-
rasterizer->InlineData(dma_data->dst_addr_lo,
632-
dma_data->SrcAddress<const void*>(),
633-
dma_data->NumBytes(), true);
632+
rasterizer->CopyBuffer(dma_data->dst_addr_lo, dma_data->SrcAddress<VAddr>(),
633+
dma_data->NumBytes(), true, false);
634634
} else if (dma_data->src_sel == DmaDataSrc::Data &&
635635
(dma_data->dst_sel == DmaDataDst::Memory ||
636636
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
@@ -639,14 +639,15 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
639639
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
640640
(dma_data->dst_sel == DmaDataDst::Memory ||
641641
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
642-
// LOG_WARNING(Render_Vulkan, "GDS memory read");
642+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->src_addr_lo,
643+
dma_data->NumBytes(), false, true);
643644
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
644645
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
645646
(dma_data->dst_sel == DmaDataDst::Memory ||
646647
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
647-
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
648-
dma_data->SrcAddress<const void*>(),
649-
dma_data->NumBytes(), false);
648+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(),
649+
dma_data->SrcAddress<VAddr>(), dma_data->NumBytes(),
650+
false, false);
650651
} else {
651652
UNREACHABLE_MSG("WriteData src_sel = {}, dst_sel = {}",
652653
u32(dma_data->src_sel.Value()), u32(dma_data->dst_sel.Value()));
@@ -682,6 +683,9 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
682683
break;
683684
}
684685
case PM4ItOpcode::Rewind: {
686+
if (!rasterizer) {
687+
break;
688+
}
685689
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
686690
while (!rewind->Valid()) {
687691
YIELD_GFX();
@@ -818,8 +822,8 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
818822
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
819823
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
820824
dma_data->dst_sel == DmaDataDst::Gds) {
821-
rasterizer->InlineData(dma_data->dst_addr_lo, dma_data->SrcAddress<const void*>(),
822-
dma_data->NumBytes(), true);
825+
rasterizer->CopyBuffer(dma_data->dst_addr_lo, dma_data->SrcAddress<VAddr>(),
826+
dma_data->NumBytes(), true, false);
823827
} else if (dma_data->src_sel == DmaDataSrc::Data &&
824828
(dma_data->dst_sel == DmaDataDst::Memory ||
825829
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
@@ -828,14 +832,14 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
828832
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
829833
(dma_data->dst_sel == DmaDataDst::Memory ||
830834
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
831-
// LOG_WARNING(Render_Vulkan, "GDS memory read");
835+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->src_addr_lo,
836+
dma_data->NumBytes(), false, true);
832837
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
833838
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
834839
(dma_data->dst_sel == DmaDataDst::Memory ||
835840
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
836-
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
837-
dma_data->SrcAddress<const void*>(), dma_data->NumBytes(),
838-
false);
841+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->SrcAddress<VAddr>(),
842+
dma_data->NumBytes(), false, false);
839843
} else {
840844
UNREACHABLE_MSG("WriteData src_sel = {}, dst_sel = {}",
841845
u32(dma_data->src_sel.Value()), u32(dma_data->dst_sel.Value()));
@@ -846,6 +850,9 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
846850
break;
847851
}
848852
case PM4ItOpcode::Rewind: {
853+
if (!rasterizer) {
854+
break;
855+
}
849856
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
850857
while (!rewind->Valid()) {
851858
YIELD_ASC(vqid);

src/video_core/amdgpu/liverpool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ struct Liverpool {
15121512
u32 tmp_dwords;
15131513
};
15141514
Common::SlotVector<AscQueueInfo> asc_queues{};
1515+
std::thread::id gpu_id;
15151516

15161517
private:
15171518
struct Task {

0 commit comments

Comments
 (0)