Skip to content

Commit c8720f4

Browse files
committed
Readbacks proof of concept shadps4-emu#2668
1 parent 4e9a1a2 commit c8720f4

File tree

14 files changed

+413
-201
lines changed

14 files changed

+413
-201
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
891891
src/video_core/buffer_cache/buffer.h
892892
src/video_core/buffer_cache/buffer_cache.cpp
893893
src/video_core/buffer_cache/buffer_cache.h
894-
src/video_core/buffer_cache/memory_tracker_base.h
894+
src/video_core/buffer_cache/memory_tracker.h
895895
src/video_core/buffer_cache/range_set.h
896896
src/video_core/buffer_cache/word_manager.h
897897
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
{
@@ -636,9 +637,8 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
636637
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
637638
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
638639
dma_data->dst_sel == DmaDataDst::Gds) {
639-
rasterizer->InlineData(dma_data->dst_addr_lo,
640-
dma_data->SrcAddress<const void*>(),
641-
dma_data->NumBytes(), true);
640+
rasterizer->CopyBuffer(dma_data->dst_addr_lo, dma_data->SrcAddress<VAddr>(),
641+
dma_data->NumBytes(), true, false);
642642
} else if (dma_data->src_sel == DmaDataSrc::Data &&
643643
(dma_data->dst_sel == DmaDataDst::Memory ||
644644
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
@@ -647,14 +647,15 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
647647
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
648648
(dma_data->dst_sel == DmaDataDst::Memory ||
649649
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
650-
// LOG_WARNING(Render_Vulkan, "GDS memory read");
650+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->src_addr_lo,
651+
dma_data->NumBytes(), false, true);
651652
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
652653
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
653654
(dma_data->dst_sel == DmaDataDst::Memory ||
654655
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
655-
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
656-
dma_data->SrcAddress<const void*>(),
657-
dma_data->NumBytes(), false);
656+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(),
657+
dma_data->SrcAddress<VAddr>(), dma_data->NumBytes(),
658+
false, false);
658659
} else {
659660
UNREACHABLE_MSG("WriteData src_sel = {}, dst_sel = {}",
660661
u32(dma_data->src_sel.Value()), u32(dma_data->dst_sel.Value()));
@@ -690,6 +691,9 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
690691
break;
691692
}
692693
case PM4ItOpcode::Rewind: {
694+
if (!rasterizer) {
695+
break;
696+
}
693697
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
694698
while (!rewind->Valid()) {
695699
YIELD_GFX();
@@ -836,8 +840,8 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
836840
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
837841
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
838842
dma_data->dst_sel == DmaDataDst::Gds) {
839-
rasterizer->InlineData(dma_data->dst_addr_lo, dma_data->SrcAddress<const void*>(),
840-
dma_data->NumBytes(), true);
843+
rasterizer->CopyBuffer(dma_data->dst_addr_lo, dma_data->SrcAddress<VAddr>(),
844+
dma_data->NumBytes(), true, false);
841845
} else if (dma_data->src_sel == DmaDataSrc::Data &&
842846
(dma_data->dst_sel == DmaDataDst::Memory ||
843847
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
@@ -846,14 +850,14 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
846850
} else if (dma_data->src_sel == DmaDataSrc::Gds &&
847851
(dma_data->dst_sel == DmaDataDst::Memory ||
848852
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
849-
// LOG_WARNING(Render_Vulkan, "GDS memory read");
853+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->src_addr_lo,
854+
dma_data->NumBytes(), false, true);
850855
} else if ((dma_data->src_sel == DmaDataSrc::Memory ||
851856
dma_data->src_sel == DmaDataSrc::MemoryUsingL2) &&
852857
(dma_data->dst_sel == DmaDataDst::Memory ||
853858
dma_data->dst_sel == DmaDataDst::MemoryUsingL2)) {
854-
rasterizer->InlineData(dma_data->DstAddress<VAddr>(),
855-
dma_data->SrcAddress<const void*>(), dma_data->NumBytes(),
856-
false);
859+
rasterizer->CopyBuffer(dma_data->DstAddress<VAddr>(), dma_data->SrcAddress<VAddr>(),
860+
dma_data->NumBytes(), false, false);
857861
} else {
858862
UNREACHABLE_MSG("WriteData src_sel = {}, dst_sel = {}",
859863
u32(dma_data->src_sel.Value()), u32(dma_data->dst_sel.Value()));
@@ -864,6 +868,9 @@ Liverpool::Task Liverpool::ProcessCompute(const u32* acb, u32 acb_dwords, u32 vq
864868
break;
865869
}
866870
case PM4ItOpcode::Rewind: {
871+
if (!rasterizer) {
872+
break;
873+
}
867874
const PM4CmdRewind* rewind = reinterpret_cast<const PM4CmdRewind*>(header);
868875
while (!rewind->Valid()) {
869876
YIELD_ASC(vqid);

src/video_core/amdgpu/liverpool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ struct Liverpool {
15221522
u32 tmp_dwords;
15231523
};
15241524
Common::SlotVector<AscQueueInfo> asc_queues{};
1525+
std::thread::id gpu_id;
15251526

15261527
private:
15271528
struct Task {

0 commit comments

Comments
 (0)