summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------externals/cubeb0
m---------externals/dynarmic0
m---------externals/sirit0
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.cpp7
-rw-r--r--src/core/arm/unicorn/arm_unicorn.cpp5
-rw-r--r--src/core/arm/unicorn/arm_unicorn.h7
-rw-r--r--src/core/hle/kernel/physical_core.cpp4
-rw-r--r--src/core/hle/kernel/svc.cpp4
-rw-r--r--src/core/hle/service/am/am.cpp40
-rw-r--r--src/core/hle/service/am/am.h3
-rw-r--r--src/core/hle/service/caps/caps_su.cpp3
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp4
-rw-r--r--src/core/hle/service/glue/errors.h8
-rw-r--r--src/core/hle/service/nim/nim.cpp70
-rw-r--r--src/core/hle/service/ns/ns.cpp8
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h5
-rw-r--r--src/core/hle/service/ptm/psm.cpp21
-rw-r--r--src/core/hle/service/set/set.cpp1
-rw-r--r--src/core/hle/service/sm/sm.cpp12
-rw-r--r--src/core/hle/service/vi/vi.cpp9
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/engines/maxwell_3d.h1
-rw-r--r--src/video_core/engines/shader_bytecode.h4
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp55
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp82
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp10
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.cpp2
-rw-r--r--src/video_core/renderer_vulkan/fixed_pipeline_state.h2
-rw-r--r--src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp2
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp69
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.h8
-rw-r--r--src/video_core/renderer_vulkan/vk_rasterizer.cpp4
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_decompiler.cpp11
-rw-r--r--src/video_core/shader/control_flow.cpp12
-rw-r--r--src/video_core/shader/decode.cpp12
-rw-r--r--src/video_core/shader/decode/arithmetic_integer.cpp31
-rw-r--r--src/video_core/shader/decode/register_set_predicate.cpp52
-rw-r--r--src/video_core/shader/memory_util.cpp77
-rw-r--r--src/video_core/shader/memory_util.h47
-rw-r--r--src/video_core/shader/node.h2
-rw-r--r--src/video_core/shader/shader_ir.h3
-rw-r--r--src/video_core/shader/track.cpp20
-rw-r--r--src/video_core/texture_cache/texture_cache.h66
-rw-r--r--src/yuzu/main.cpp4
45 files changed, 493 insertions, 299 deletions
diff --git a/externals/cubeb b/externals/cubeb
Subproject 6f2420de8f155b10330cf973900ac7bdbfee589 Subproject 616d773441b5355800ce64197a699e6cd6b3617
diff --git a/externals/dynarmic b/externals/dynarmic
Subproject a3cd05577c9b6c51f0f345d0e915b6feab68fe1 Subproject e7166e8ba74d7b9c85e87afc0aaf667e7e84cfe
diff --git a/externals/sirit b/externals/sirit
Subproject a712959f1e373a33b48042b5934e288a243d595 Subproject 414fc4dbd28d8fe48f735a0c389db8a234f733c
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
index 65cbfe5e6..337b97be9 100644
--- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp
@@ -185,10 +185,9 @@ void ARM_Dynarmic_64::Step() {
185 185
186ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, ExclusiveMonitor& exclusive_monitor, 186ARM_Dynarmic_64::ARM_Dynarmic_64(System& system, ExclusiveMonitor& exclusive_monitor,
187 std::size_t core_index) 187 std::size_t core_index)
188 : ARM_Interface{system}, 188 : ARM_Interface{system}, cb(std::make_unique<DynarmicCallbacks64>(*this)),
189 cb(std::make_unique<DynarmicCallbacks64>(*this)), inner_unicorn{system}, 189 inner_unicorn{system, ARM_Unicorn::Arch::AArch64}, core_index{core_index},
190 core_index{core_index}, exclusive_monitor{ 190 exclusive_monitor{dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {}
191 dynamic_cast<DynarmicExclusiveMonitor&>(exclusive_monitor)} {}
192 191
193ARM_Dynarmic_64::~ARM_Dynarmic_64() = default; 192ARM_Dynarmic_64::~ARM_Dynarmic_64() = default;
194 193
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp
index b96583123..e40e9626a 100644
--- a/src/core/arm/unicorn/arm_unicorn.cpp
+++ b/src/core/arm/unicorn/arm_unicorn.cpp
@@ -62,8 +62,9 @@ static bool UnmappedMemoryHook(uc_engine* uc, uc_mem_type type, u64 addr, int si
62 return false; 62 return false;
63} 63}
64 64
65ARM_Unicorn::ARM_Unicorn(System& system) : ARM_Interface{system} { 65ARM_Unicorn::ARM_Unicorn(System& system, Arch architecture) : ARM_Interface{system} {
66 CHECKED(uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc)); 66 const auto arch = architecture == Arch::AArch32 ? UC_ARCH_ARM : UC_ARCH_ARM64;
67 CHECKED(uc_open(arch, UC_MODE_ARM, &uc));
67 68
68 auto fpv = 3 << 20; 69 auto fpv = 3 << 20;
69 CHECKED(uc_reg_write(uc, UC_ARM64_REG_CPACR_EL1, &fpv)); 70 CHECKED(uc_reg_write(uc, UC_ARM64_REG_CPACR_EL1, &fpv));
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h
index f30d13cb6..725c65085 100644
--- a/src/core/arm/unicorn/arm_unicorn.h
+++ b/src/core/arm/unicorn/arm_unicorn.h
@@ -15,7 +15,12 @@ class System;
15 15
16class ARM_Unicorn final : public ARM_Interface { 16class ARM_Unicorn final : public ARM_Interface {
17public: 17public:
18 explicit ARM_Unicorn(System& system); 18 enum class Arch {
19 AArch32, // 32-bit ARM
20 AArch64, // 64-bit ARM
21 };
22
23 explicit ARM_Unicorn(System& system, Arch architecture);
19 ~ARM_Unicorn() override; 24 ~ARM_Unicorn() override;
20 25
21 void SetPC(u64 pc) override; 26 void SetPC(u64 pc) override;
diff --git a/src/core/hle/kernel/physical_core.cpp b/src/core/hle/kernel/physical_core.cpp
index aa2787467..a15011076 100644
--- a/src/core/hle/kernel/physical_core.cpp
+++ b/src/core/hle/kernel/physical_core.cpp
@@ -27,7 +27,9 @@ PhysicalCore::PhysicalCore(Core::System& system, std::size_t id,
27 std::make_unique<Core::ARM_Dynarmic_64>(system, exclusive_monitor, core_index); 27 std::make_unique<Core::ARM_Dynarmic_64>(system, exclusive_monitor, core_index);
28 28
29#else 29#else
30 arm_interface = std::make_shared<Core::ARM_Unicorn>(system); 30 using Core::ARM_Unicorn;
31 arm_interface_32 = std::make_unique<ARM_Unicorn>(system, ARM_Unicorn::Arch::AArch32);
32 arm_interface_64 = std::make_unique<ARM_Unicorn>(system, ARM_Unicorn::Arch::AArch64);
31 LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available"); 33 LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
32#endif 34#endif
33 35
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 25b4a23b4..41ef2caf6 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -773,7 +773,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
773 break; 773 break;
774 } 774 }
775 775
776 LOG_WARNING(Kernel_SVC, "(STUBBED) Unimplemented svcGetInfo id=0x{:016X}", info_id); 776 LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
777 return ERR_INVALID_ENUM_VALUE; 777 return ERR_INVALID_ENUM_VALUE;
778 } 778 }
779 779
@@ -866,7 +866,7 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
866 } 866 }
867 867
868 default: 868 default:
869 LOG_WARNING(Kernel_SVC, "(STUBBED) Unimplemented svcGetInfo id=0x{:016X}", info_id); 869 LOG_ERROR(Kernel_SVC, "Unimplemented svcGetInfo id=0x{:016X}", info_id);
870 return ERR_INVALID_ENUM_VALUE; 870 return ERR_INVALID_ENUM_VALUE;
871 } 871 }
872} 872}
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index bee4a9d3f..9450de6e9 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -43,20 +43,15 @@
43 43
44namespace Service::AM { 44namespace Service::AM {
45 45
46constexpr ResultCode ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 0x2}; 46constexpr ResultCode ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 2};
47constexpr ResultCode ERR_NO_MESSAGES{ErrorModule::AM, 0x3}; 47constexpr ResultCode ERR_NO_MESSAGES{ErrorModule::AM, 3};
48constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 0x1F7}; 48constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 503};
49 49
50enum class LaunchParameterKind : u32 { 50enum class LaunchParameterKind : u32 {
51 ApplicationSpecific = 1, 51 ApplicationSpecific = 1,
52 AccountPreselectedUser = 2, 52 AccountPreselectedUser = 2,
53}; 53};
54 54
55enum class VrMode : u8 {
56 Disabled = 0,
57 Enabled = 1,
58};
59
60constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA; 55constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA;
61 56
62struct LaunchParameterAccountPreselectedUser { 57struct LaunchParameterAccountPreselectedUser {
@@ -685,27 +680,21 @@ void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) {
685} 680}
686 681
687void ICommonStateGetter::IsVrModeEnabled(Kernel::HLERequestContext& ctx) { 682void ICommonStateGetter::IsVrModeEnabled(Kernel::HLERequestContext& ctx) {
688 LOG_WARNING(Service_AM, "(STUBBED) called"); 683 LOG_DEBUG(Service_AM, "called");
689 684
690 IPC::ResponseBuilder rb{ctx, 3}; 685 IPC::ResponseBuilder rb{ctx, 3};
691 rb.Push(RESULT_SUCCESS); 686 rb.Push(RESULT_SUCCESS);
692 rb.PushEnum(VrMode::Disabled); 687 rb.Push(vr_mode_state);
693} 688}
694 689
695void ICommonStateGetter::SetVrModeEnabled(Kernel::HLERequestContext& ctx) { 690void ICommonStateGetter::SetVrModeEnabled(Kernel::HLERequestContext& ctx) {
696 IPC::RequestParser rp{ctx}; 691 IPC::RequestParser rp{ctx};
697 const auto is_vr_mode_enabled = rp.Pop<bool>(); 692 vr_mode_state = rp.Pop<bool>();
698 693
699 LOG_WARNING(Service_AM, "(STUBBED) called. is_vr_mode_enabled={}", is_vr_mode_enabled); 694 LOG_WARNING(Service_AM, "VR Mode is {}", vr_mode_state ? "on" : "off");
700 695
701 IPC::ResponseBuilder rb{ctx, 2}; 696 IPC::ResponseBuilder rb{ctx, 2};
702 if (!is_vr_mode_enabled) { 697 rb.Push(RESULT_SUCCESS);
703 rb.Push(RESULT_SUCCESS);
704 } else {
705 // TODO: Find better error code for this
706 UNIMPLEMENTED_MSG("is_vr_mode_enabled={}", is_vr_mode_enabled);
707 rb.Push(RESULT_UNKNOWN);
708 }
709} 698}
710 699
711void ICommonStateGetter::SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx) { 700void ICommonStateGetter::SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx) {
@@ -1169,7 +1158,7 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1169 {121, nullptr, "ClearUserChannel"}, 1158 {121, nullptr, "ClearUserChannel"},
1170 {122, nullptr, "UnpopToUserChannel"}, 1159 {122, nullptr, "UnpopToUserChannel"},
1171 {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"}, 1160 {130, &IApplicationFunctions::GetGpuErrorDetectedSystemEvent, "GetGpuErrorDetectedSystemEvent"},
1172 {140, nullptr, "GetFriendInvitationStorageChannelEvent"}, 1161 {140, &IApplicationFunctions::GetFriendInvitationStorageChannelEvent, "GetFriendInvitationStorageChannelEvent"},
1173 {141, nullptr, "TryPopFromFriendInvitationStorageChannel"}, 1162 {141, nullptr, "TryPopFromFriendInvitationStorageChannel"},
1174 {150, nullptr, "GetNotificationStorageChannelEvent"}, 1163 {150, nullptr, "GetNotificationStorageChannelEvent"},
1175 {151, nullptr, "TryPopFromNotificationStorageChannel"}, 1164 {151, nullptr, "TryPopFromNotificationStorageChannel"},
@@ -1186,6 +1175,9 @@ IApplicationFunctions::IApplicationFunctions(Core::System& system_)
1186 auto& kernel = system.Kernel(); 1175 auto& kernel = system.Kernel();
1187 gpu_error_detected_event = Kernel::WritableEvent::CreateEventPair( 1176 gpu_error_detected_event = Kernel::WritableEvent::CreateEventPair(
1188 kernel, "IApplicationFunctions:GpuErrorDetectedSystemEvent"); 1177 kernel, "IApplicationFunctions:GpuErrorDetectedSystemEvent");
1178
1179 friend_invitation_storage_channel_event = Kernel::WritableEvent::CreateEventPair(
1180 kernel, "IApplicationFunctions:FriendInvitationStorageChannelEvent");
1189} 1181}
1190 1182
1191IApplicationFunctions::~IApplicationFunctions() = default; 1183IApplicationFunctions::~IApplicationFunctions() = default;
@@ -1500,6 +1492,14 @@ void IApplicationFunctions::GetGpuErrorDetectedSystemEvent(Kernel::HLERequestCon
1500 rb.PushCopyObjects(gpu_error_detected_event.readable); 1492 rb.PushCopyObjects(gpu_error_detected_event.readable);
1501} 1493}
1502 1494
1495void IApplicationFunctions::GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx) {
1496 LOG_DEBUG(Service_AM, "called");
1497
1498 IPC::ResponseBuilder rb{ctx, 2, 1};
1499 rb.Push(RESULT_SUCCESS);
1500 rb.PushCopyObjects(friend_invitation_storage_channel_event.readable);
1501}
1502
1503void InstallInterfaces(SM::ServiceManager& service_manager, 1503void InstallInterfaces(SM::ServiceManager& service_manager,
1504 std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system) { 1504 std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system) {
1505 auto message_queue = std::make_shared<AppletMessageQueue>(system.Kernel()); 1505 auto message_queue = std::make_shared<AppletMessageQueue>(system.Kernel());
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index 53cfce10f..dfa701d73 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -191,6 +191,7 @@ private:
191 191
192 Core::System& system; 192 Core::System& system;
193 std::shared_ptr<AppletMessageQueue> msg_queue; 193 std::shared_ptr<AppletMessageQueue> msg_queue;
194 bool vr_mode_state{};
194}; 195};
195 196
196class IStorageImpl { 197class IStorageImpl {
@@ -280,10 +281,12 @@ private:
280 void QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx); 281 void QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx);
281 void QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx); 282 void QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx);
282 void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx); 283 void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx);
284 void GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx);
283 285
284 bool launch_popped_application_specific = false; 286 bool launch_popped_application_specific = false;
285 bool launch_popped_account_preselect = false; 287 bool launch_popped_account_preselect = false;
286 Kernel::EventPair gpu_error_detected_event; 288 Kernel::EventPair gpu_error_detected_event;
289 Kernel::EventPair friend_invitation_storage_channel_event;
287 Core::System& system; 290 Core::System& system;
288}; 291};
289 292
diff --git a/src/core/hle/service/caps/caps_su.cpp b/src/core/hle/service/caps/caps_su.cpp
index 2b4c2d808..b4d9355ef 100644
--- a/src/core/hle/service/caps/caps_su.cpp
+++ b/src/core/hle/service/caps/caps_su.cpp
@@ -9,8 +9,11 @@ namespace Service::Capture {
9CAPS_SU::CAPS_SU() : ServiceFramework("caps:su") { 9CAPS_SU::CAPS_SU() : ServiceFramework("caps:su") {
10 // clang-format off 10 // clang-format off
11 static const FunctionInfo functions[] = { 11 static const FunctionInfo functions[] = {
12 {32, nullptr, "SetShimLibraryVersion"},
12 {201, nullptr, "SaveScreenShot"}, 13 {201, nullptr, "SaveScreenShot"},
13 {203, nullptr, "SaveScreenShotEx0"}, 14 {203, nullptr, "SaveScreenShotEx0"},
15 {205, nullptr, "SaveScreenShotEx1"},
16 {210, nullptr, "SaveScreenShotEx2"},
14 }; 17 };
15 // clang-format on 18 // clang-format on
16 19
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 6b9b4f3b9..f6503fe2f 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -316,8 +316,8 @@ public:
316 {8, &IFileSystem::OpenFile, "OpenFile"}, 316 {8, &IFileSystem::OpenFile, "OpenFile"},
317 {9, &IFileSystem::OpenDirectory, "OpenDirectory"}, 317 {9, &IFileSystem::OpenDirectory, "OpenDirectory"},
318 {10, &IFileSystem::Commit, "Commit"}, 318 {10, &IFileSystem::Commit, "Commit"},
319 {11, nullptr, "GetFreeSpaceSize"}, 319 {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"},
320 {12, nullptr, "GetTotalSpaceSize"}, 320 {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"},
321 {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, 321 {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"},
322 {14, nullptr, "GetFileTimeStampRaw"}, 322 {14, nullptr, "GetFileTimeStampRaw"},
323 {15, nullptr, "QueryEntry"}, 323 {15, nullptr, "QueryEntry"},
diff --git a/src/core/hle/service/glue/errors.h b/src/core/hle/service/glue/errors.h
index c2874c585..f6647f724 100644
--- a/src/core/hle/service/glue/errors.h
+++ b/src/core/hle/service/glue/errors.h
@@ -8,9 +8,9 @@
8 8
9namespace Service::Glue { 9namespace Service::Glue {
10 10
11constexpr ResultCode ERR_INVALID_RESOURCE{ErrorModule::ARP, 0x1E}; 11constexpr ResultCode ERR_INVALID_RESOURCE{ErrorModule::ARP, 30};
12constexpr ResultCode ERR_INVALID_PROCESS_ID{ErrorModule::ARP, 0x1F}; 12constexpr ResultCode ERR_INVALID_PROCESS_ID{ErrorModule::ARP, 31};
13constexpr ResultCode ERR_INVALID_ACCESS{ErrorModule::ARP, 0x2A}; 13constexpr ResultCode ERR_INVALID_ACCESS{ErrorModule::ARP, 42};
14constexpr ResultCode ERR_NOT_REGISTERED{ErrorModule::ARP, 0x66}; 14constexpr ResultCode ERR_NOT_REGISTERED{ErrorModule::ARP, 102};
15 15
16} // namespace Service::Glue 16} // namespace Service::Glue
diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp
index e85f123e2..f19affce7 100644
--- a/src/core/hle/service/nim/nim.cpp
+++ b/src/core/hle/service/nim/nim.cpp
@@ -15,6 +15,66 @@
15 15
16namespace Service::NIM { 16namespace Service::NIM {
17 17
18class IShopServiceAsync final : public ServiceFramework<IShopServiceAsync> {
19public:
20 IShopServiceAsync() : ServiceFramework("IShopServiceAsync") {
21 // clang-format off
22 static const FunctionInfo functions[] = {
23 {0, nullptr, "Cancel"},
24 {1, nullptr, "GetSize"},
25 {2, nullptr, "Read"},
26 {3, nullptr, "GetErrorCode"},
27 {4, nullptr, "Request"},
28 {5, nullptr, "Prepare"},
29 };
30 // clang-format on
31
32 RegisterHandlers(functions);
33 }
34};
35
36class IShopServiceAccessor final : public ServiceFramework<IShopServiceAccessor> {
37public:
38 IShopServiceAccessor() : ServiceFramework("IShopServiceAccessor") {
39 // clang-format off
40 static const FunctionInfo functions[] = {
41 {0, &IShopServiceAccessor::CreateAsyncInterface, "CreateAsyncInterface"},
42 };
43 // clang-format on
44
45 RegisterHandlers(functions);
46 }
47
48private:
49 void CreateAsyncInterface(Kernel::HLERequestContext& ctx) {
50 LOG_WARNING(Service_NIM, "(STUBBED) called");
51 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
52 rb.Push(RESULT_SUCCESS);
53 rb.PushIpcInterface<IShopServiceAsync>();
54 }
55};
56
57class IShopServiceAccessServer final : public ServiceFramework<IShopServiceAccessServer> {
58public:
59 IShopServiceAccessServer() : ServiceFramework("IShopServiceAccessServer") {
60 // clang-format off
61 static const FunctionInfo functions[] = {
62 {0, &IShopServiceAccessServer::CreateAccessorInterface, "CreateAccessorInterface"},
63 };
64 // clang-format on
65
66 RegisterHandlers(functions);
67 }
68
69private:
70 void CreateAccessorInterface(Kernel::HLERequestContext& ctx) {
71 LOG_WARNING(Service_NIM, "(STUBBED) called");
72 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
73 rb.Push(RESULT_SUCCESS);
74 rb.PushIpcInterface<IShopServiceAccessor>();
75 }
76};
77
18class NIM final : public ServiceFramework<NIM> { 78class NIM final : public ServiceFramework<NIM> {
19public: 79public:
20 explicit NIM() : ServiceFramework{"nim"} { 80 explicit NIM() : ServiceFramework{"nim"} {
@@ -78,7 +138,7 @@ public:
78 explicit NIM_ECA() : ServiceFramework{"nim:eca"} { 138 explicit NIM_ECA() : ServiceFramework{"nim:eca"} {
79 // clang-format off 139 // clang-format off
80 static const FunctionInfo functions[] = { 140 static const FunctionInfo functions[] = {
81 {0, nullptr, "CreateServerInterface"}, 141 {0, &NIM_ECA::CreateServerInterface, "CreateServerInterface"},
82 {1, nullptr, "RefreshDebugAvailability"}, 142 {1, nullptr, "RefreshDebugAvailability"},
83 {2, nullptr, "ClearDebugResponse"}, 143 {2, nullptr, "ClearDebugResponse"},
84 {3, nullptr, "RegisterDebugResponse"}, 144 {3, nullptr, "RegisterDebugResponse"},
@@ -87,6 +147,14 @@ public:
87 147
88 RegisterHandlers(functions); 148 RegisterHandlers(functions);
89 } 149 }
150
151private:
152 void CreateServerInterface(Kernel::HLERequestContext& ctx) {
153 LOG_WARNING(Service_NIM, "(STUBBED) called");
154 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
155 rb.Push(RESULT_SUCCESS);
156 rb.PushIpcInterface<IShopServiceAccessServer>();
157 }
90}; 158};
91 159
92class NIM_SHP final : public ServiceFramework<NIM_SHP> { 160class NIM_SHP final : public ServiceFramework<NIM_SHP> {
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp
index 8fb88990e..7e5ceccdb 100644
--- a/src/core/hle/service/ns/ns.cpp
+++ b/src/core/hle/service/ns/ns.cpp
@@ -371,10 +371,15 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage(
371 // Convert to application language, get priority list 371 // Convert to application language, get priority list
372 const auto application_language = ConvertToApplicationLanguage(language_code); 372 const auto application_language = ConvertToApplicationLanguage(language_code);
373 if (application_language == std::nullopt) { 373 if (application_language == std::nullopt) {
374 LOG_ERROR(Service_NS, "Could not convert application language! language_code={}",
375 language_code);
374 return ERR_APPLICATION_LANGUAGE_NOT_FOUND; 376 return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
375 } 377 }
376 const auto priority_list = GetApplicationLanguagePriorityList(*application_language); 378 const auto priority_list = GetApplicationLanguagePriorityList(*application_language);
377 if (!priority_list) { 379 if (!priority_list) {
380 LOG_ERROR(Service_NS,
381 "Could not find application language priorities! application_language={}",
382 *application_language);
378 return ERR_APPLICATION_LANGUAGE_NOT_FOUND; 383 return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
379 } 384 }
380 385
@@ -386,6 +391,8 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage(
386 } 391 }
387 } 392 }
388 393
394 LOG_ERROR(Service_NS, "Could not find a valid language! supported_languages={:08X}",
395 supported_languages);
389 return ERR_APPLICATION_LANGUAGE_NOT_FOUND; 396 return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
390} 397}
391 398
@@ -410,6 +417,7 @@ ResultVal<u64> IApplicationManagerInterface::ConvertApplicationLanguageToLanguag
410 const auto language_code = 417 const auto language_code =
411 ConvertToLanguageCode(static_cast<ApplicationLanguage>(application_language)); 418 ConvertToLanguageCode(static_cast<ApplicationLanguage>(application_language));
412 if (language_code == std::nullopt) { 419 if (language_code == std::nullopt) {
420 LOG_ERROR(Service_NS, "Language not found! application_language={}", application_language);
413 return ERR_APPLICATION_LANGUAGE_NOT_FOUND; 421 return ERR_APPLICATION_LANGUAGE_NOT_FOUND;
414 } 422 }
415 423
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
index 642b0a2cb..07b644ec5 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h
@@ -159,9 +159,10 @@ private:
159 static_assert(sizeof(IoctlFlushL2) == 8, "IoctlFlushL2 is incorrect size"); 159 static_assert(sizeof(IoctlFlushL2) == 8, "IoctlFlushL2 is incorrect size");
160 160
161 struct IoctlGetGpuTime { 161 struct IoctlGetGpuTime {
162 u64_le gpu_time; 162 u64_le gpu_time{};
163 INSERT_PADDING_WORDS(2);
163 }; 164 };
164 static_assert(sizeof(IoctlGetGpuTime) == 8, "IoctlGetGpuTime is incorrect size"); 165 static_assert(sizeof(IoctlGetGpuTime) == 0x10, "IoctlGetGpuTime is incorrect size");
165 166
166 u32 GetCharacteristics(const std::vector<u8>& input, std::vector<u8>& output, 167 u32 GetCharacteristics(const std::vector<u8>& input, std::vector<u8>& output,
167 std::vector<u8>& output2, IoctlVersion version); 168 std::vector<u8>& output2, IoctlVersion version);
diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp
index c2d5fda94..12d154ecf 100644
--- a/src/core/hle/service/ptm/psm.cpp
+++ b/src/core/hle/service/ptm/psm.cpp
@@ -12,9 +12,6 @@
12 12
13namespace Service::PSM { 13namespace Service::PSM {
14 14
15constexpr u32 BATTERY_FULLY_CHARGED = 100; // 100% Full
16constexpr u32 BATTERY_CURRENTLY_CHARGING = 1; // Plugged into an official dock
17
18class PSM final : public ServiceFramework<PSM> { 15class PSM final : public ServiceFramework<PSM> {
19public: 16public:
20 explicit PSM() : ServiceFramework{"psm"} { 17 explicit PSM() : ServiceFramework{"psm"} {
@@ -48,20 +45,30 @@ public:
48 45
49private: 46private:
50 void GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) { 47 void GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) {
51 LOG_WARNING(Service_PSM, "(STUBBED) called"); 48 LOG_DEBUG(Service_PSM, "called");
52 49
53 IPC::ResponseBuilder rb{ctx, 3}; 50 IPC::ResponseBuilder rb{ctx, 3};
54 rb.Push(RESULT_SUCCESS); 51 rb.Push(RESULT_SUCCESS);
55 rb.Push<u32>(BATTERY_FULLY_CHARGED); 52 rb.Push<u32>(battery_charge_percentage);
56 } 53 }
57 54
58 void GetChargerType(Kernel::HLERequestContext& ctx) { 55 void GetChargerType(Kernel::HLERequestContext& ctx) {
59 LOG_WARNING(Service_PSM, "(STUBBED) called"); 56 LOG_DEBUG(Service_PSM, "called");
60 57
61 IPC::ResponseBuilder rb{ctx, 3}; 58 IPC::ResponseBuilder rb{ctx, 3};
62 rb.Push(RESULT_SUCCESS); 59 rb.Push(RESULT_SUCCESS);
63 rb.Push<u32>(BATTERY_CURRENTLY_CHARGING); 60 rb.PushEnum(charger_type);
64 } 61 }
62
63 enum class ChargerType : u32 {
64 Unplugged = 0,
65 RegularCharger = 1,
66 LowPowerCharger = 2,
67 Unknown = 3,
68 };
69
70 u32 battery_charge_percentage{100}; // 100%
71 ChargerType charger_type{ChargerType::RegularCharger};
65}; 72};
66 73
67void InstallInterfaces(SM::ServiceManager& sm) { 74void InstallInterfaces(SM::ServiceManager& sm) {
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp
index 9e12c76fc..f3b4b286c 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -67,6 +67,7 @@ void SET::MakeLanguageCode(Kernel::HLERequestContext& ctx) {
67 const auto index = rp.Pop<u32>(); 67 const auto index = rp.Pop<u32>();
68 68
69 if (index >= available_language_codes.size()) { 69 if (index >= available_language_codes.size()) {
70 LOG_ERROR(Service_SET, "Invalid language code index! index={}", index);
70 IPC::ResponseBuilder rb{ctx, 2}; 71 IPC::ResponseBuilder rb{ctx, 2};
71 rb.Push(ERR_INVALID_LANGUAGE); 72 rb.Push(ERR_INVALID_LANGUAGE);
72 return; 73 return;
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 88909504d..6ada13be4 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -28,9 +28,11 @@ void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
28 28
29static ResultCode ValidateServiceName(const std::string& name) { 29static ResultCode ValidateServiceName(const std::string& name) {
30 if (name.size() <= 0 || name.size() > 8) { 30 if (name.size() <= 0 || name.size() > 8) {
31 LOG_ERROR(Service_SM, "Invalid service name! service={}", name);
31 return ERR_INVALID_NAME; 32 return ERR_INVALID_NAME;
32 } 33 }
33 if (name.find('\0') != std::string::npos) { 34 if (name.find('\0') != std::string::npos) {
35 LOG_ERROR(Service_SM, "A non null terminated service was passed");
34 return ERR_INVALID_NAME; 36 return ERR_INVALID_NAME;
35 } 37 }
36 return RESULT_SUCCESS; 38 return RESULT_SUCCESS;
@@ -51,8 +53,10 @@ ResultVal<std::shared_ptr<Kernel::ServerPort>> ServiceManager::RegisterService(
51 53
52 CASCADE_CODE(ValidateServiceName(name)); 54 CASCADE_CODE(ValidateServiceName(name));
53 55
54 if (registered_services.find(name) != registered_services.end()) 56 if (registered_services.find(name) != registered_services.end()) {
57 LOG_ERROR(Service_SM, "Service is already registered! service={}", name);
55 return ERR_ALREADY_REGISTERED; 58 return ERR_ALREADY_REGISTERED;
59 }
56 60
57 auto& kernel = Core::System::GetInstance().Kernel(); 61 auto& kernel = Core::System::GetInstance().Kernel();
58 auto [server_port, client_port] = 62 auto [server_port, client_port] =
@@ -66,9 +70,10 @@ ResultCode ServiceManager::UnregisterService(const std::string& name) {
66 CASCADE_CODE(ValidateServiceName(name)); 70 CASCADE_CODE(ValidateServiceName(name));
67 71
68 const auto iter = registered_services.find(name); 72 const auto iter = registered_services.find(name);
69 if (iter == registered_services.end()) 73 if (iter == registered_services.end()) {
74 LOG_ERROR(Service_SM, "Server is not registered! service={}", name);
70 return ERR_SERVICE_NOT_REGISTERED; 75 return ERR_SERVICE_NOT_REGISTERED;
71 76 }
72 registered_services.erase(iter); 77 registered_services.erase(iter);
73 return RESULT_SUCCESS; 78 return RESULT_SUCCESS;
74} 79}
@@ -79,6 +84,7 @@ ResultVal<std::shared_ptr<Kernel::ClientPort>> ServiceManager::GetServicePort(
79 CASCADE_CODE(ValidateServiceName(name)); 84 CASCADE_CODE(ValidateServiceName(name));
80 auto it = registered_services.find(name); 85 auto it = registered_services.find(name);
81 if (it == registered_services.end()) { 86 if (it == registered_services.end()) {
87 LOG_ERROR(Service_SM, "Server is not registered! service={}", name);
82 return ERR_SERVICE_NOT_REGISTERED; 88 return ERR_SERVICE_NOT_REGISTERED;
83 } 89 }
84 90
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 9390ca83d..46e14c2a3 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -867,6 +867,7 @@ private:
867 867
868 const auto layer_id = nv_flinger->CreateLayer(display); 868 const auto layer_id = nv_flinger->CreateLayer(display);
869 if (!layer_id) { 869 if (!layer_id) {
870 LOG_ERROR(Service_VI, "Layer not found! display=0x{:016X}", display);
870 IPC::ResponseBuilder rb{ctx, 2}; 871 IPC::ResponseBuilder rb{ctx, 2};
871 rb.Push(ERR_NOT_FOUND); 872 rb.Push(ERR_NOT_FOUND);
872 return; 873 return;
@@ -983,6 +984,7 @@ private:
983 984
984 const auto display_id = nv_flinger->OpenDisplay(name); 985 const auto display_id = nv_flinger->OpenDisplay(name);
985 if (!display_id) { 986 if (!display_id) {
987 LOG_ERROR(Service_VI, "Display not found! display_name={}", name);
986 IPC::ResponseBuilder rb{ctx, 2}; 988 IPC::ResponseBuilder rb{ctx, 2};
987 rb.Push(ERR_NOT_FOUND); 989 rb.Push(ERR_NOT_FOUND);
988 return; 990 return;
@@ -1082,6 +1084,7 @@ private:
1082 1084
1083 const auto display_id = nv_flinger->OpenDisplay(display_name); 1085 const auto display_id = nv_flinger->OpenDisplay(display_name);
1084 if (!display_id) { 1086 if (!display_id) {
1087 LOG_ERROR(Service_VI, "Layer not found! layer_id={}", layer_id);
1085 IPC::ResponseBuilder rb{ctx, 2}; 1088 IPC::ResponseBuilder rb{ctx, 2};
1086 rb.Push(ERR_NOT_FOUND); 1089 rb.Push(ERR_NOT_FOUND);
1087 return; 1090 return;
@@ -1089,6 +1092,7 @@ private:
1089 1092
1090 const auto buffer_queue_id = nv_flinger->FindBufferQueueId(*display_id, layer_id); 1093 const auto buffer_queue_id = nv_flinger->FindBufferQueueId(*display_id, layer_id);
1091 if (!buffer_queue_id) { 1094 if (!buffer_queue_id) {
1095 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", *display_id);
1092 IPC::ResponseBuilder rb{ctx, 2}; 1096 IPC::ResponseBuilder rb{ctx, 2};
1093 rb.Push(ERR_NOT_FOUND); 1097 rb.Push(ERR_NOT_FOUND);
1094 return; 1098 return;
@@ -1124,6 +1128,7 @@ private:
1124 1128
1125 const auto layer_id = nv_flinger->CreateLayer(display_id); 1129 const auto layer_id = nv_flinger->CreateLayer(display_id);
1126 if (!layer_id) { 1130 if (!layer_id) {
1131 LOG_ERROR(Service_VI, "Layer not found! layer_id={}", *layer_id);
1127 IPC::ResponseBuilder rb{ctx, 2}; 1132 IPC::ResponseBuilder rb{ctx, 2};
1128 rb.Push(ERR_NOT_FOUND); 1133 rb.Push(ERR_NOT_FOUND);
1129 return; 1134 return;
@@ -1131,6 +1136,7 @@ private:
1131 1136
1132 const auto buffer_queue_id = nv_flinger->FindBufferQueueId(display_id, *layer_id); 1137 const auto buffer_queue_id = nv_flinger->FindBufferQueueId(display_id, *layer_id);
1133 if (!buffer_queue_id) { 1138 if (!buffer_queue_id) {
1139 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", display_id);
1134 IPC::ResponseBuilder rb{ctx, 2}; 1140 IPC::ResponseBuilder rb{ctx, 2};
1135 rb.Push(ERR_NOT_FOUND); 1141 rb.Push(ERR_NOT_FOUND);
1136 return; 1142 return;
@@ -1161,6 +1167,7 @@ private:
1161 1167
1162 const auto vsync_event = nv_flinger->FindVsyncEvent(display_id); 1168 const auto vsync_event = nv_flinger->FindVsyncEvent(display_id);
1163 if (!vsync_event) { 1169 if (!vsync_event) {
1170 LOG_ERROR(Service_VI, "Vsync event was not found for display_id={}", display_id);
1164 IPC::ResponseBuilder rb{ctx, 2}; 1171 IPC::ResponseBuilder rb{ctx, 2};
1165 rb.Push(ERR_NOT_FOUND); 1172 rb.Push(ERR_NOT_FOUND);
1166 return; 1173 return;
@@ -1201,6 +1208,7 @@ private:
1201 case NintendoScaleMode::PreserveAspectRatio: 1208 case NintendoScaleMode::PreserveAspectRatio:
1202 return MakeResult(ConvertedScaleMode::PreserveAspectRatio); 1209 return MakeResult(ConvertedScaleMode::PreserveAspectRatio);
1203 default: 1210 default:
1211 LOG_ERROR(Service_VI, "Invalid scaling mode specified, mode={}", mode);
1204 return ERR_OPERATION_FAILED; 1212 return ERR_OPERATION_FAILED;
1205 } 1213 }
1206 } 1214 }
@@ -1257,6 +1265,7 @@ void detail::GetDisplayServiceImpl(Kernel::HLERequestContext& ctx,
1257 const auto policy = rp.PopEnum<Policy>(); 1265 const auto policy = rp.PopEnum<Policy>();
1258 1266
1259 if (!IsValidServiceAccess(permission, policy)) { 1267 if (!IsValidServiceAccess(permission, policy)) {
1268 LOG_ERROR(Service_VI, "Permission denied for policy {}", static_cast<u32>(policy));
1260 IPC::ResponseBuilder rb{ctx, 2}; 1269 IPC::ResponseBuilder rb{ctx, 2};
1261 rb.Push(ERR_PERMISSION_DENIED); 1270 rb.Push(ERR_PERMISSION_DENIED);
1262 return; 1271 return;
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 8ede4ba9b..ff53282c9 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -124,6 +124,8 @@ add_library(video_core STATIC
124 shader/decode.cpp 124 shader/decode.cpp
125 shader/expr.cpp 125 shader/expr.cpp
126 shader/expr.h 126 shader/expr.h
127 shader/memory_util.cpp
128 shader/memory_util.h
127 shader/node_helper.cpp 129 shader/node_helper.cpp
128 shader/node_helper.h 130 shader/node_helper.h
129 shader/node.h 131 shader/node.h
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 3dfba8197..5e522e0d2 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -1179,6 +1179,7 @@ public:
1179 BitField<0, 1, u32> depth_range_0_1; 1179 BitField<0, 1, u32> depth_range_0_1;
1180 BitField<3, 1, u32> depth_clamp_near; 1180 BitField<3, 1, u32> depth_clamp_near;
1181 BitField<4, 1, u32> depth_clamp_far; 1181 BitField<4, 1, u32> depth_clamp_far;
1182 BitField<11, 1, u32> depth_clamp_disabled;
1182 } view_volume_clip_control; 1183 } view_volume_clip_control;
1183 1184
1184 INSERT_UNION_PADDING_WORDS(0x1F); 1185 INSERT_UNION_PADDING_WORDS(0x1F);
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index cde3a26b9..8dae754d4 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -814,6 +814,10 @@ union Instruction {
814 } alu_integer; 814 } alu_integer;
815 815
816 union { 816 union {
817 BitField<43, 1, u64> x;
818 } iadd;
819
820 union {
817 BitField<39, 1, u64> ftz; 821 BitField<39, 1, u64> ftz;
818 BitField<32, 1, u64> saturate; 822 BitField<32, 1, u64> saturate;
819 BitField<49, 2, HalfMerge> merge; 823 BitField<49, 2, HalfMerge> merge;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 6fe155bcc..f33c4a8f9 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -348,7 +348,7 @@ void RasterizerOpenGL::ConfigureFramebuffers() {
348 348
349 texture_cache.GuardRenderTargets(true); 349 texture_cache.GuardRenderTargets(true);
350 350
351 View depth_surface = texture_cache.GetDepthBufferSurface(); 351 View depth_surface = texture_cache.GetDepthBufferSurface(true);
352 352
353 const auto& regs = gpu.regs; 353 const auto& regs = gpu.regs;
354 UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0); 354 UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0);
@@ -357,7 +357,7 @@ void RasterizerOpenGL::ConfigureFramebuffers() {
357 FramebufferCacheKey key; 357 FramebufferCacheKey key;
358 const auto colors_count = static_cast<std::size_t>(regs.rt_control.count); 358 const auto colors_count = static_cast<std::size_t>(regs.rt_control.count);
359 for (std::size_t index = 0; index < colors_count; ++index) { 359 for (std::size_t index = 0; index < colors_count; ++index) {
360 View color_surface{texture_cache.GetColorBufferSurface(index)}; 360 View color_surface{texture_cache.GetColorBufferSurface(index, true)};
361 if (!color_surface) { 361 if (!color_surface) {
362 continue; 362 continue;
363 } 363 }
@@ -381,28 +381,52 @@ void RasterizerOpenGL::ConfigureFramebuffers() {
381 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cache.GetFramebuffer(key)); 381 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cache.GetFramebuffer(key));
382} 382}
383 383
384void RasterizerOpenGL::ConfigureClearFramebuffer(bool using_color_fb, bool using_depth_fb, 384void RasterizerOpenGL::ConfigureClearFramebuffer(bool using_color, bool using_depth_stencil) {
385 bool using_stencil_fb) {
386 auto& gpu = system.GPU().Maxwell3D(); 385 auto& gpu = system.GPU().Maxwell3D();
387 const auto& regs = gpu.regs; 386 const auto& regs = gpu.regs;
388 387
389 texture_cache.GuardRenderTargets(true); 388 texture_cache.GuardRenderTargets(true);
390 View color_surface; 389 View color_surface;
391 if (using_color_fb) { 390
391 if (using_color) {
392 // Determine if we have to preserve the contents.
393 // First we have to make sure all clear masks are enabled.
394 bool preserve_contents = !regs.clear_buffers.R || !regs.clear_buffers.G ||
395 !regs.clear_buffers.B || !regs.clear_buffers.A;
392 const std::size_t index = regs.clear_buffers.RT; 396 const std::size_t index = regs.clear_buffers.RT;
393 color_surface = texture_cache.GetColorBufferSurface(index); 397 if (regs.clear_flags.scissor) {
398 // Then we have to confirm scissor testing clears the whole image.
399 const auto& scissor = regs.scissor_test[0];
400 preserve_contents |= scissor.min_x > 0;
401 preserve_contents |= scissor.min_y > 0;
402 preserve_contents |= scissor.max_x < regs.rt[index].width;
403 preserve_contents |= scissor.max_y < regs.rt[index].height;
404 }
405
406 color_surface = texture_cache.GetColorBufferSurface(index, preserve_contents);
394 texture_cache.MarkColorBufferInUse(index); 407 texture_cache.MarkColorBufferInUse(index);
395 } 408 }
409
396 View depth_surface; 410 View depth_surface;
397 if (using_depth_fb || using_stencil_fb) { 411 if (using_depth_stencil) {
398 depth_surface = texture_cache.GetDepthBufferSurface(); 412 bool preserve_contents = false;
413 if (regs.clear_flags.scissor) {
414 // For depth stencil clears we only have to confirm scissor test covers the whole image.
415 const auto& scissor = regs.scissor_test[0];
416 preserve_contents |= scissor.min_x > 0;
417 preserve_contents |= scissor.min_y > 0;
418 preserve_contents |= scissor.max_x < regs.zeta_width;
419 preserve_contents |= scissor.max_y < regs.zeta_height;
420 }
421
422 depth_surface = texture_cache.GetDepthBufferSurface(preserve_contents);
399 texture_cache.MarkDepthBufferInUse(); 423 texture_cache.MarkDepthBufferInUse();
400 } 424 }
401 texture_cache.GuardRenderTargets(false); 425 texture_cache.GuardRenderTargets(false);
402 426
403 FramebufferCacheKey key; 427 FramebufferCacheKey key;
404 key.colors[0] = color_surface; 428 key.colors[0] = std::move(color_surface);
405 key.zeta = depth_surface; 429 key.zeta = std::move(depth_surface);
406 430
407 state_tracker.NotifyFramebuffer(); 431 state_tracker.NotifyFramebuffer();
408 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cache.GetFramebuffer(key)); 432 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cache.GetFramebuffer(key));
@@ -422,8 +446,7 @@ void RasterizerOpenGL::Clear() {
422 if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B || 446 if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B ||
423 regs.clear_buffers.A) { 447 regs.clear_buffers.A) {
424 use_color = true; 448 use_color = true;
425 } 449
426 if (use_color) {
427 state_tracker.NotifyColorMask0(); 450 state_tracker.NotifyColorMask0();
428 glColorMaski(0, regs.clear_buffers.R != 0, regs.clear_buffers.G != 0, 451 glColorMaski(0, regs.clear_buffers.R != 0, regs.clear_buffers.G != 0,
429 regs.clear_buffers.B != 0, regs.clear_buffers.A != 0); 452 regs.clear_buffers.B != 0, regs.clear_buffers.A != 0);
@@ -461,7 +484,7 @@ void RasterizerOpenGL::Clear() {
461 484
462 UNIMPLEMENTED_IF(regs.clear_flags.viewport); 485 UNIMPLEMENTED_IF(regs.clear_flags.viewport);
463 486
464 ConfigureClearFramebuffer(use_color, use_depth, use_stencil); 487 ConfigureClearFramebuffer(use_color, use_depth || use_stencil);
465 488
466 if (use_color) { 489 if (use_color) {
467 glClearBufferfv(GL_COLOR, 0, regs.clear_color); 490 glClearBufferfv(GL_COLOR, 0, regs.clear_color);
@@ -999,11 +1022,7 @@ void RasterizerOpenGL::SyncDepthClamp() {
999 } 1022 }
1000 flags[Dirty::DepthClampEnabled] = false; 1023 flags[Dirty::DepthClampEnabled] = false;
1001 1024
1002 const auto& state = gpu.regs.view_volume_clip_control; 1025 oglEnable(GL_DEPTH_CLAMP, gpu.regs.view_volume_clip_control.depth_clamp_disabled == 0);
1003 UNIMPLEMENTED_IF_MSG(state.depth_clamp_far != state.depth_clamp_near,
1004 "Unimplemented depth clamp separation!");
1005
1006 oglEnable(GL_DEPTH_CLAMP, state.depth_clamp_far || state.depth_clamp_near);
1007} 1026}
1008 1027
1009void RasterizerOpenGL::SyncClipEnabled(u32 clip_mask) { 1028void RasterizerOpenGL::SyncClipEnabled(u32 clip_mask) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index ebd2173eb..87249fb6f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -95,7 +95,8 @@ private:
95 /// Configures the color and depth framebuffer states. 95 /// Configures the color and depth framebuffer states.
96 void ConfigureFramebuffers(); 96 void ConfigureFramebuffers();
97 97
98 void ConfigureClearFramebuffer(bool using_color_fb, bool using_depth_fb, bool using_stencil_fb); 98 /// Configures the color and depth framebuffer for clearing.
99 void ConfigureClearFramebuffer(bool using_color, bool using_depth_stencil);
99 100
100 /// Configures the current constbuffers to use for the draw command. 101 /// Configures the current constbuffers to use for the draw command.
101 void SetupDrawConstBuffers(std::size_t stage_index, const Shader& shader); 102 void SetupDrawConstBuffers(std::size_t stage_index, const Shader& shader);
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index f63156b8d..9759a7078 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -10,8 +10,6 @@
10#include <thread> 10#include <thread>
11#include <unordered_set> 11#include <unordered_set>
12 12
13#include <boost/functional/hash.hpp>
14
15#include "common/alignment.h" 13#include "common/alignment.h"
16#include "common/assert.h" 14#include "common/assert.h"
17#include "common/logging/log.h" 15#include "common/logging/log.h"
@@ -28,76 +26,26 @@
28#include "video_core/renderer_opengl/gl_shader_disk_cache.h" 26#include "video_core/renderer_opengl/gl_shader_disk_cache.h"
29#include "video_core/renderer_opengl/gl_state_tracker.h" 27#include "video_core/renderer_opengl/gl_state_tracker.h"
30#include "video_core/renderer_opengl/utils.h" 28#include "video_core/renderer_opengl/utils.h"
29#include "video_core/shader/memory_util.h"
31#include "video_core/shader/registry.h" 30#include "video_core/shader/registry.h"
32#include "video_core/shader/shader_ir.h" 31#include "video_core/shader/shader_ir.h"
33 32
34namespace OpenGL { 33namespace OpenGL {
35 34
36using Tegra::Engines::ShaderType; 35using Tegra::Engines::ShaderType;
36using VideoCommon::Shader::GetShaderAddress;
37using VideoCommon::Shader::GetShaderCode;
38using VideoCommon::Shader::GetUniqueIdentifier;
39using VideoCommon::Shader::KERNEL_MAIN_OFFSET;
37using VideoCommon::Shader::ProgramCode; 40using VideoCommon::Shader::ProgramCode;
38using VideoCommon::Shader::Registry; 41using VideoCommon::Shader::Registry;
39using VideoCommon::Shader::ShaderIR; 42using VideoCommon::Shader::ShaderIR;
43using VideoCommon::Shader::STAGE_MAIN_OFFSET;
40 44
41namespace { 45namespace {
42 46
43constexpr u32 STAGE_MAIN_OFFSET = 10;
44constexpr u32 KERNEL_MAIN_OFFSET = 0;
45
46constexpr VideoCommon::Shader::CompilerSettings COMPILER_SETTINGS{}; 47constexpr VideoCommon::Shader::CompilerSettings COMPILER_SETTINGS{};
47 48
48/// Gets the address for the specified shader stage program
49GPUVAddr GetShaderAddress(Core::System& system, Maxwell::ShaderProgram program) {
50 const auto& gpu{system.GPU().Maxwell3D()};
51 const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]};
52 return gpu.regs.code_address.CodeAddress() + shader_config.offset;
53}
54
55/// Gets if the current instruction offset is a scheduler instruction
56constexpr bool IsSchedInstruction(std::size_t offset, std::size_t main_offset) {
57 // Sched instructions appear once every 4 instructions.
58 constexpr std::size_t SchedPeriod = 4;
59 const std::size_t absolute_offset = offset - main_offset;
60 return (absolute_offset % SchedPeriod) == 0;
61}
62
63/// Calculates the size of a program stream
64std::size_t CalculateProgramSize(const ProgramCode& program) {
65 constexpr std::size_t start_offset = 10;
66 // This is the encoded version of BRA that jumps to itself. All Nvidia
67 // shaders end with one.
68 constexpr u64 self_jumping_branch = 0xE2400FFFFF07000FULL;
69 constexpr u64 mask = 0xFFFFFFFFFF7FFFFFULL;
70 std::size_t offset = start_offset;
71 while (offset < program.size()) {
72 const u64 instruction = program[offset];
73 if (!IsSchedInstruction(offset, start_offset)) {
74 if ((instruction & mask) == self_jumping_branch) {
75 // End on Maxwell's "nop" instruction
76 break;
77 }
78 if (instruction == 0) {
79 break;
80 }
81 }
82 offset++;
83 }
84 // The last instruction is included in the program size
85 return std::min(offset + 1, program.size());
86}
87
88/// Gets the shader program code from memory for the specified address
89ProgramCode GetShaderCode(Tegra::MemoryManager& memory_manager, const GPUVAddr gpu_addr,
90 const u8* host_ptr) {
91 ProgramCode code(VideoCommon::Shader::MAX_PROGRAM_LENGTH);
92 ASSERT_OR_EXECUTE(host_ptr != nullptr, {
93 std::fill(code.begin(), code.end(), 0);
94 return code;
95 });
96 memory_manager.ReadBlockUnsafe(gpu_addr, code.data(), code.size() * sizeof(u64));
97 code.resize(CalculateProgramSize(code));
98 return code;
99}
100
101/// Gets the shader type from a Maxwell program type 49/// Gets the shader type from a Maxwell program type
102constexpr GLenum GetGLShaderType(ShaderType shader_type) { 50constexpr GLenum GetGLShaderType(ShaderType shader_type) {
103 switch (shader_type) { 51 switch (shader_type) {
@@ -114,17 +62,6 @@ constexpr GLenum GetGLShaderType(ShaderType shader_type) {
114 } 62 }
115} 63}
116 64
117/// Hashes one (or two) program streams
118u64 GetUniqueIdentifier(ShaderType shader_type, bool is_a, const ProgramCode& code,
119 const ProgramCode& code_b = {}) {
120 u64 unique_identifier = boost::hash_value(code);
121 if (is_a) {
122 // VertexA programs include two programs
123 boost::hash_combine(unique_identifier, boost::hash_value(code_b));
124 }
125 return unique_identifier;
126}
127
128constexpr const char* GetShaderTypeName(ShaderType shader_type) { 65constexpr const char* GetShaderTypeName(ShaderType shader_type) {
129 switch (shader_type) { 66 switch (shader_type) {
130 case ShaderType::Vertex: 67 case ShaderType::Vertex:
@@ -456,11 +393,12 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
456 const auto host_ptr{memory_manager.GetPointer(address)}; 393 const auto host_ptr{memory_manager.GetPointer(address)};
457 394
458 // No shader found - create a new one 395 // No shader found - create a new one
459 ProgramCode code{GetShaderCode(memory_manager, address, host_ptr)}; 396 ProgramCode code{GetShaderCode(memory_manager, address, host_ptr, false)};
460 ProgramCode code_b; 397 ProgramCode code_b;
461 if (program == Maxwell::ShaderProgram::VertexA) { 398 if (program == Maxwell::ShaderProgram::VertexA) {
462 const GPUVAddr address_b{GetShaderAddress(system, Maxwell::ShaderProgram::VertexB)}; 399 const GPUVAddr address_b{GetShaderAddress(system, Maxwell::ShaderProgram::VertexB)};
463 code_b = GetShaderCode(memory_manager, address_b, memory_manager.GetPointer(address_b)); 400 const u8* host_ptr_b = memory_manager.GetPointer(address_b);
401 code_b = GetShaderCode(memory_manager, address_b, host_ptr_b, false);
464 } 402 }
465 403
466 const auto unique_identifier = GetUniqueIdentifier( 404 const auto unique_identifier = GetUniqueIdentifier(
@@ -498,7 +436,7 @@ Shader ShaderCacheOpenGL::GetComputeKernel(GPUVAddr code_addr) {
498 436
499 const auto host_ptr{memory_manager.GetPointer(code_addr)}; 437 const auto host_ptr{memory_manager.GetPointer(code_addr)};
500 // No kernel found, create a new one 438 // No kernel found, create a new one
501 auto code{GetShaderCode(memory_manager, code_addr, host_ptr)}; 439 auto code{GetShaderCode(memory_manager, code_addr, host_ptr, true)};
502 const auto unique_identifier{GetUniqueIdentifier(ShaderType::Compute, false, code)}; 440 const auto unique_identifier{GetUniqueIdentifier(ShaderType::Compute, false, code)};
503 441
504 const ShaderParameters params{system, disk_cache, device, 442 const ShaderParameters params{system, disk_cache, device,
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 0cd3ad7e1..3803a6f3a 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -1870,6 +1870,14 @@ private:
1870 return GenerateBinaryInfix(operation, ">=", Type::Bool, type, type); 1870 return GenerateBinaryInfix(operation, ">=", Type::Bool, type, type);
1871 } 1871 }
1872 1872
1873 Expression LogicalAddCarry(Operation operation) {
1874 const std::string carry = code.GenerateTemporary();
1875 code.AddLine("uint {};", carry);
1876 code.AddLine("uaddCarry({}, {}, {});", VisitOperand(operation, 0).AsUint(),
1877 VisitOperand(operation, 1).AsUint(), carry);
1878 return {fmt::format("({} != 0)", carry), Type::Bool};
1879 }
1880
1873 Expression LogicalFIsNan(Operation operation) { 1881 Expression LogicalFIsNan(Operation operation) {
1874 return GenerateUnary(operation, "isnan", Type::Bool, Type::Float); 1882 return GenerateUnary(operation, "isnan", Type::Bool, Type::Float);
1875 } 1883 }
@@ -2441,6 +2449,8 @@ private:
2441 &GLSLDecompiler::LogicalNotEqual<Type::Uint>, 2449 &GLSLDecompiler::LogicalNotEqual<Type::Uint>,
2442 &GLSLDecompiler::LogicalGreaterEqual<Type::Uint>, 2450 &GLSLDecompiler::LogicalGreaterEqual<Type::Uint>,
2443 2451
2452 &GLSLDecompiler::LogicalAddCarry,
2453
2444 &GLSLDecompiler::Logical2HLessThan<false>, 2454 &GLSLDecompiler::Logical2HLessThan<false>,
2445 &GLSLDecompiler::Logical2HEqual<false>, 2455 &GLSLDecompiler::Logical2HEqual<false>,
2446 &GLSLDecompiler::Logical2HLessEqual<false>, 2456 &GLSLDecompiler::Logical2HLessEqual<false>,
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
index a7f256ff9..648b1e71b 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp
@@ -81,7 +81,7 @@ void FixedPipelineState::Rasterizer::Fill(const Maxwell& regs) noexcept {
81 primitive_restart_enable.Assign(regs.primitive_restart.enabled != 0 ? 1 : 0); 81 primitive_restart_enable.Assign(regs.primitive_restart.enabled != 0 ? 1 : 0);
82 cull_enable.Assign(regs.cull_test_enabled != 0 ? 1 : 0); 82 cull_enable.Assign(regs.cull_test_enabled != 0 ? 1 : 0);
83 depth_bias_enable.Assign(enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]] != 0 ? 1 : 0); 83 depth_bias_enable.Assign(enabled_lut[POLYGON_OFFSET_ENABLE_LUT[topology_index]] != 0 ? 1 : 0);
84 depth_clamp_enable.Assign(clip.depth_clamp_near == 1 || clip.depth_clamp_far == 1 ? 1 : 0); 84 depth_clamp_disabled.Assign(regs.view_volume_clip_control.depth_clamp_disabled.Value());
85 ndc_minus_one_to_one.Assign(regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1 : 0); 85 ndc_minus_one_to_one.Assign(regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1 : 0);
86 cull_face.Assign(PackCullFace(regs.cull_face)); 86 cull_face.Assign(PackCullFace(regs.cull_face));
87 front_face.Assign(packed_front_face); 87 front_face.Assign(packed_front_face);
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.h b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
index 77188b862..8652067a7 100644
--- a/src/video_core/renderer_vulkan/fixed_pipeline_state.h
+++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.h
@@ -153,7 +153,7 @@ struct FixedPipelineState {
153 BitField<4, 1, u32> primitive_restart_enable; 153 BitField<4, 1, u32> primitive_restart_enable;
154 BitField<5, 1, u32> cull_enable; 154 BitField<5, 1, u32> cull_enable;
155 BitField<6, 1, u32> depth_bias_enable; 155 BitField<6, 1, u32> depth_bias_enable;
156 BitField<7, 1, u32> depth_clamp_enable; 156 BitField<7, 1, u32> depth_clamp_disabled;
157 BitField<8, 1, u32> ndc_minus_one_to_one; 157 BitField<8, 1, u32> ndc_minus_one_to_one;
158 BitField<9, 2, u32> cull_face; 158 BitField<9, 2, u32> cull_face;
159 BitField<11, 1, u32> front_face; 159 BitField<11, 1, u32> front_face;
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
index 45bd1fc6c..852a17a70 100644
--- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
+++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp
@@ -249,7 +249,7 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
249 rasterization_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; 249 rasterization_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
250 rasterization_ci.pNext = nullptr; 250 rasterization_ci.pNext = nullptr;
251 rasterization_ci.flags = 0; 251 rasterization_ci.flags = 0;
252 rasterization_ci.depthClampEnable = rs.depth_clamp_enable; 252 rasterization_ci.depthClampEnable = rs.depth_clamp_disabled == 0 ? VK_TRUE : VK_FALSE;
253 rasterization_ci.rasterizerDiscardEnable = VK_FALSE; 253 rasterization_ci.rasterizerDiscardEnable = VK_FALSE;
254 rasterization_ci.polygonMode = VK_POLYGON_MODE_FILL; 254 rasterization_ci.polygonMode = VK_POLYGON_MODE_FILL;
255 rasterization_ci.cullMode = 255 rasterization_ci.cullMode =
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
index e6d4adc92..9b703a2f0 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@@ -27,12 +27,18 @@
27#include "video_core/renderer_vulkan/vk_update_descriptor.h" 27#include "video_core/renderer_vulkan/vk_update_descriptor.h"
28#include "video_core/renderer_vulkan/wrapper.h" 28#include "video_core/renderer_vulkan/wrapper.h"
29#include "video_core/shader/compiler_settings.h" 29#include "video_core/shader/compiler_settings.h"
30#include "video_core/shader/memory_util.h"
30 31
31namespace Vulkan { 32namespace Vulkan {
32 33
33MICROPROFILE_DECLARE(Vulkan_PipelineCache); 34MICROPROFILE_DECLARE(Vulkan_PipelineCache);
34 35
35using Tegra::Engines::ShaderType; 36using Tegra::Engines::ShaderType;
37using VideoCommon::Shader::GetShaderAddress;
38using VideoCommon::Shader::GetShaderCode;
39using VideoCommon::Shader::KERNEL_MAIN_OFFSET;
40using VideoCommon::Shader::ProgramCode;
41using VideoCommon::Shader::STAGE_MAIN_OFFSET;
36 42
37namespace { 43namespace {
38 44
@@ -45,60 +51,6 @@ constexpr VkDescriptorType STORAGE_IMAGE = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
45constexpr VideoCommon::Shader::CompilerSettings compiler_settings{ 51constexpr VideoCommon::Shader::CompilerSettings compiler_settings{
46 VideoCommon::Shader::CompileDepth::FullDecompile}; 52 VideoCommon::Shader::CompileDepth::FullDecompile};
47 53
48/// Gets the address for the specified shader stage program
49GPUVAddr GetShaderAddress(Core::System& system, Maxwell::ShaderProgram program) {
50 const auto& gpu{system.GPU().Maxwell3D()};
51 const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]};
52 return gpu.regs.code_address.CodeAddress() + shader_config.offset;
53}
54
55/// Gets if the current instruction offset is a scheduler instruction
56constexpr bool IsSchedInstruction(std::size_t offset, std::size_t main_offset) {
57 // Sched instructions appear once every 4 instructions.
58 constexpr std::size_t SchedPeriod = 4;
59 const std::size_t absolute_offset = offset - main_offset;
60 return (absolute_offset % SchedPeriod) == 0;
61}
62
63/// Calculates the size of a program stream
64std::size_t CalculateProgramSize(const ProgramCode& program, bool is_compute) {
65 const std::size_t start_offset = is_compute ? 0 : 10;
66 // This is the encoded version of BRA that jumps to itself. All Nvidia
67 // shaders end with one.
68 constexpr u64 self_jumping_branch = 0xE2400FFFFF07000FULL;
69 constexpr u64 mask = 0xFFFFFFFFFF7FFFFFULL;
70 std::size_t offset = start_offset;
71 while (offset < program.size()) {
72 const u64 instruction = program[offset];
73 if (!IsSchedInstruction(offset, start_offset)) {
74 if ((instruction & mask) == self_jumping_branch) {
75 // End on Maxwell's "nop" instruction
76 break;
77 }
78 if (instruction == 0) {
79 break;
80 }
81 }
82 ++offset;
83 }
84 // The last instruction is included in the program size
85 return std::min(offset + 1, program.size());
86}
87
88/// Gets the shader program code from memory for the specified address
89ProgramCode GetShaderCode(Tegra::MemoryManager& memory_manager, const GPUVAddr gpu_addr,
90 const u8* host_ptr, bool is_compute) {
91 ProgramCode program_code(VideoCommon::Shader::MAX_PROGRAM_LENGTH);
92 ASSERT_OR_EXECUTE(host_ptr != nullptr, {
93 std::fill(program_code.begin(), program_code.end(), 0);
94 return program_code;
95 });
96 memory_manager.ReadBlockUnsafe(gpu_addr, program_code.data(),
97 program_code.size() * sizeof(u64));
98 program_code.resize(CalculateProgramSize(program_code, is_compute));
99 return program_code;
100}
101
102constexpr std::size_t GetStageFromProgram(std::size_t program) { 54constexpr std::size_t GetStageFromProgram(std::size_t program) {
103 return program == 0 ? 0 : program - 1; 55 return program == 0 ? 0 : program - 1;
104} 56}
@@ -230,9 +182,9 @@ std::array<Shader, Maxwell::MaxShaderProgram> VKPipelineCache::GetShaders() {
230 const auto host_ptr{memory_manager.GetPointer(program_addr)}; 182 const auto host_ptr{memory_manager.GetPointer(program_addr)};
231 183
232 // No shader found - create a new one 184 // No shader found - create a new one
233 constexpr u32 stage_offset = 10; 185 constexpr u32 stage_offset = STAGE_MAIN_OFFSET;
234 const auto stage = static_cast<Tegra::Engines::ShaderType>(index == 0 ? 0 : index - 1); 186 const auto stage = static_cast<Tegra::Engines::ShaderType>(index == 0 ? 0 : index - 1);
235 auto code = GetShaderCode(memory_manager, program_addr, host_ptr, false); 187 ProgramCode code = GetShaderCode(memory_manager, program_addr, host_ptr, false);
236 188
237 shader = std::make_shared<CachedShader>(system, stage, program_addr, *cpu_addr, 189 shader = std::make_shared<CachedShader>(system, stage, program_addr, *cpu_addr,
238 std::move(code), stage_offset); 190 std::move(code), stage_offset);
@@ -288,11 +240,10 @@ VKComputePipeline& VKPipelineCache::GetComputePipeline(const ComputePipelineCach
288 // No shader found - create a new one 240 // No shader found - create a new one
289 const auto host_ptr = memory_manager.GetPointer(program_addr); 241 const auto host_ptr = memory_manager.GetPointer(program_addr);
290 242
291 auto code = GetShaderCode(memory_manager, program_addr, host_ptr, true); 243 ProgramCode code = GetShaderCode(memory_manager, program_addr, host_ptr, true);
292 constexpr u32 kernel_main_offset = 0;
293 shader = std::make_shared<CachedShader>(system, Tegra::Engines::ShaderType::Compute, 244 shader = std::make_shared<CachedShader>(system, Tegra::Engines::ShaderType::Compute,
294 program_addr, *cpu_addr, std::move(code), 245 program_addr, *cpu_addr, std::move(code),
295 kernel_main_offset); 246 KERNEL_MAIN_OFFSET);
296 if (cpu_addr) { 247 if (cpu_addr) {
297 Register(shader); 248 Register(shader);
298 } else { 249 } else {
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.h b/src/video_core/renderer_vulkan/vk_pipeline_cache.h
index 84d26b822..ebddafb73 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.h
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.h
@@ -24,6 +24,7 @@
24#include "video_core/renderer_vulkan/vk_resource_manager.h" 24#include "video_core/renderer_vulkan/vk_resource_manager.h"
25#include "video_core/renderer_vulkan/vk_shader_decompiler.h" 25#include "video_core/renderer_vulkan/vk_shader_decompiler.h"
26#include "video_core/renderer_vulkan/wrapper.h" 26#include "video_core/renderer_vulkan/wrapper.h"
27#include "video_core/shader/memory_util.h"
27#include "video_core/shader/registry.h" 28#include "video_core/shader/registry.h"
28#include "video_core/shader/shader_ir.h" 29#include "video_core/shader/shader_ir.h"
29#include "video_core/surface.h" 30#include "video_core/surface.h"
@@ -46,8 +47,6 @@ class CachedShader;
46using Shader = std::shared_ptr<CachedShader>; 47using Shader = std::shared_ptr<CachedShader>;
47using Maxwell = Tegra::Engines::Maxwell3D::Regs; 48using Maxwell = Tegra::Engines::Maxwell3D::Regs;
48 49
49using ProgramCode = std::vector<u64>;
50
51struct GraphicsPipelineCacheKey { 50struct GraphicsPipelineCacheKey {
52 FixedPipelineState fixed_state; 51 FixedPipelineState fixed_state;
53 RenderPassParams renderpass_params; 52 RenderPassParams renderpass_params;
@@ -108,7 +107,8 @@ namespace Vulkan {
108class CachedShader final : public RasterizerCacheObject { 107class CachedShader final : public RasterizerCacheObject {
109public: 108public:
110 explicit CachedShader(Core::System& system, Tegra::Engines::ShaderType stage, GPUVAddr gpu_addr, 109 explicit CachedShader(Core::System& system, Tegra::Engines::ShaderType stage, GPUVAddr gpu_addr,
111 VAddr cpu_addr, ProgramCode program_code, u32 main_offset); 110 VAddr cpu_addr, VideoCommon::Shader::ProgramCode program_code,
111 u32 main_offset);
112 ~CachedShader(); 112 ~CachedShader();
113 113
114 GPUVAddr GetGpuAddr() const { 114 GPUVAddr GetGpuAddr() const {
@@ -140,7 +140,7 @@ private:
140 Tegra::Engines::ShaderType stage); 140 Tegra::Engines::ShaderType stage);
141 141
142 GPUVAddr gpu_addr{}; 142 GPUVAddr gpu_addr{};
143 ProgramCode program_code; 143 VideoCommon::Shader::ProgramCode program_code;
144 VideoCommon::Shader::Registry registry; 144 VideoCommon::Shader::Registry registry;
145 VideoCommon::Shader::ShaderIR shader_ir; 145 VideoCommon::Shader::ShaderIR shader_ir;
146 ShaderEntries entries; 146 ShaderEntries entries;
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index c821b1229..776053de5 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -656,7 +656,7 @@ RasterizerVulkan::Texceptions RasterizerVulkan::UpdateAttachments() {
656 Texceptions texceptions; 656 Texceptions texceptions;
657 for (std::size_t rt = 0; rt < Maxwell::NumRenderTargets; ++rt) { 657 for (std::size_t rt = 0; rt < Maxwell::NumRenderTargets; ++rt) {
658 if (update_rendertargets) { 658 if (update_rendertargets) {
659 color_attachments[rt] = texture_cache.GetColorBufferSurface(rt); 659 color_attachments[rt] = texture_cache.GetColorBufferSurface(rt, true);
660 } 660 }
661 if (color_attachments[rt] && WalkAttachmentOverlaps(*color_attachments[rt])) { 661 if (color_attachments[rt] && WalkAttachmentOverlaps(*color_attachments[rt])) {
662 texceptions[rt] = true; 662 texceptions[rt] = true;
@@ -664,7 +664,7 @@ RasterizerVulkan::Texceptions RasterizerVulkan::UpdateAttachments() {
664 } 664 }
665 665
666 if (update_rendertargets) { 666 if (update_rendertargets) {
667 zeta_attachment = texture_cache.GetDepthBufferSurface(); 667 zeta_attachment = texture_cache.GetDepthBufferSurface(true);
668 } 668 }
669 if (zeta_attachment && WalkAttachmentOverlaps(*zeta_attachment)) { 669 if (zeta_attachment && WalkAttachmentOverlaps(*zeta_attachment)) {
670 texceptions[ZETA_TEXCEPTION_INDEX] = true; 670 texceptions[ZETA_TEXCEPTION_INDEX] = true;
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
index aaa138f52..20b6ca0ad 100644
--- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
+++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
@@ -1584,6 +1584,15 @@ private:
1584 return {OpCompositeConstruct(t_half, low, high), Type::HalfFloat}; 1584 return {OpCompositeConstruct(t_half, low, high), Type::HalfFloat};
1585 } 1585 }
1586 1586
1587 Expression LogicalAddCarry(Operation operation) {
1588 const Id op_a = AsUint(Visit(operation[0]));
1589 const Id op_b = AsUint(Visit(operation[1]));
1590
1591 const Id result = OpIAddCarry(TypeStruct({t_uint, t_uint}), op_a, op_b);
1592 const Id carry = OpCompositeExtract(t_uint, result, 1);
1593 return {OpINotEqual(t_bool, carry, Constant(t_uint, 0)), Type::Bool};
1594 }
1595
1587 Expression LogicalAssign(Operation operation) { 1596 Expression LogicalAssign(Operation operation) {
1588 const Node& dest = operation[0]; 1597 const Node& dest = operation[0];
1589 const Node& src = operation[1]; 1598 const Node& src = operation[1];
@@ -2518,6 +2527,8 @@ private:
2518 &SPIRVDecompiler::Binary<&Module::OpINotEqual, Type::Bool, Type::Uint>, 2527 &SPIRVDecompiler::Binary<&Module::OpINotEqual, Type::Bool, Type::Uint>,
2519 &SPIRVDecompiler::Binary<&Module::OpUGreaterThanEqual, Type::Bool, Type::Uint>, 2528 &SPIRVDecompiler::Binary<&Module::OpUGreaterThanEqual, Type::Bool, Type::Uint>,
2520 2529
2530 &SPIRVDecompiler::LogicalAddCarry,
2531
2521 &SPIRVDecompiler::Binary<&Module::OpFOrdLessThan, Type::Bool2, Type::HalfFloat>, 2532 &SPIRVDecompiler::Binary<&Module::OpFOrdLessThan, Type::Bool2, Type::HalfFloat>,
2522 &SPIRVDecompiler::Binary<&Module::OpFOrdEqual, Type::Bool2, Type::HalfFloat>, 2533 &SPIRVDecompiler::Binary<&Module::OpFOrdEqual, Type::Bool2, Type::HalfFloat>,
2523 &SPIRVDecompiler::Binary<&Module::OpFOrdLessThanEqual, Type::Bool2, Type::HalfFloat>, 2534 &SPIRVDecompiler::Binary<&Module::OpFOrdLessThanEqual, Type::Bool2, Type::HalfFloat>,
diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp
index e00a3fb70..8d86020f6 100644
--- a/src/video_core/shader/control_flow.cpp
+++ b/src/video_core/shader/control_flow.cpp
@@ -13,6 +13,7 @@
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "video_core/shader/ast.h" 14#include "video_core/shader/ast.h"
15#include "video_core/shader/control_flow.h" 15#include "video_core/shader/control_flow.h"
16#include "video_core/shader/memory_util.h"
16#include "video_core/shader/registry.h" 17#include "video_core/shader/registry.h"
17#include "video_core/shader/shader_ir.h" 18#include "video_core/shader/shader_ir.h"
18 19
@@ -115,17 +116,6 @@ Pred GetPredicate(u32 index, bool negated) {
115 return static_cast<Pred>(static_cast<u64>(index) + (negated ? 8ULL : 0ULL)); 116 return static_cast<Pred>(static_cast<u64>(index) + (negated ? 8ULL : 0ULL));
116} 117}
117 118
118/**
119 * Returns whether the instruction at the specified offset is a 'sched' instruction.
120 * Sched instructions always appear before a sequence of 3 instructions.
121 */
122constexpr bool IsSchedInstruction(u32 offset, u32 main_offset) {
123 constexpr u32 SchedPeriod = 4;
124 u32 absolute_offset = offset - main_offset;
125
126 return (absolute_offset % SchedPeriod) == 0;
127}
128
129enum class ParseResult : u32 { 119enum class ParseResult : u32 {
130 ControlCaught, 120 ControlCaught,
131 BlockEnd, 121 BlockEnd,
diff --git a/src/video_core/shader/decode.cpp b/src/video_core/shader/decode.cpp
index 87ac9ac6c..1167ff4ec 100644
--- a/src/video_core/shader/decode.cpp
+++ b/src/video_core/shader/decode.cpp
@@ -13,6 +13,7 @@
13#include "video_core/engines/shader_bytecode.h" 13#include "video_core/engines/shader_bytecode.h"
14#include "video_core/engines/shader_header.h" 14#include "video_core/engines/shader_header.h"
15#include "video_core/shader/control_flow.h" 15#include "video_core/shader/control_flow.h"
16#include "video_core/shader/memory_util.h"
16#include "video_core/shader/node_helper.h" 17#include "video_core/shader/node_helper.h"
17#include "video_core/shader/shader_ir.h" 18#include "video_core/shader/shader_ir.h"
18 19
@@ -23,17 +24,6 @@ using Tegra::Shader::OpCode;
23 24
24namespace { 25namespace {
25 26
26/**
27 * Returns whether the instruction at the specified offset is a 'sched' instruction.
28 * Sched instructions always appear before a sequence of 3 instructions.
29 */
30constexpr bool IsSchedInstruction(u32 offset, u32 main_offset) {
31 constexpr u32 SchedPeriod = 4;
32 u32 absolute_offset = offset - main_offset;
33
34 return (absolute_offset % SchedPeriod) == 0;
35}
36
37void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile& gpu_driver, 27void DeduceTextureHandlerSize(VideoCore::GuestDriverProfile& gpu_driver,
38 const std::list<Sampler>& used_samplers) { 28 const std::list<Sampler>& used_samplers) {
39 if (gpu_driver.IsTextureHandlerSizeKnown() || used_samplers.size() <= 1) { 29 if (gpu_driver.IsTextureHandlerSizeKnown() || used_samplers.size() <= 1) {
diff --git a/src/video_core/shader/decode/arithmetic_integer.cpp b/src/video_core/shader/decode/arithmetic_integer.cpp
index 9af8c606d..a041519b7 100644
--- a/src/video_core/shader/decode/arithmetic_integer.cpp
+++ b/src/video_core/shader/decode/arithmetic_integer.cpp
@@ -35,15 +35,38 @@ u32 ShaderIR::DecodeArithmeticInteger(NodeBlock& bb, u32 pc) {
35 case OpCode::Id::IADD_C: 35 case OpCode::Id::IADD_C:
36 case OpCode::Id::IADD_R: 36 case OpCode::Id::IADD_R:
37 case OpCode::Id::IADD_IMM: { 37 case OpCode::Id::IADD_IMM: {
38 UNIMPLEMENTED_IF_MSG(instr.alu.saturate_d, "IADD saturation not implemented"); 38 UNIMPLEMENTED_IF_MSG(instr.alu.saturate_d, "IADD.SAT");
39 UNIMPLEMENTED_IF_MSG(instr.iadd.x && instr.generates_cc, "IADD.X Rd.CC");
39 40
40 op_a = GetOperandAbsNegInteger(op_a, false, instr.alu_integer.negate_a, true); 41 op_a = GetOperandAbsNegInteger(op_a, false, instr.alu_integer.negate_a, true);
41 op_b = GetOperandAbsNegInteger(op_b, false, instr.alu_integer.negate_b, true); 42 op_b = GetOperandAbsNegInteger(op_b, false, instr.alu_integer.negate_b, true);
42 43
43 const Node value = Operation(OperationCode::IAdd, PRECISE, op_a, op_b); 44 Node value = Operation(OperationCode::UAdd, op_a, op_b);
44 45
45 SetInternalFlagsFromInteger(bb, value, instr.generates_cc); 46 if (instr.iadd.x) {
46 SetRegister(bb, instr.gpr0, value); 47 Node carry = GetInternalFlag(InternalFlag::Carry);
48 Node x = Operation(OperationCode::Select, std::move(carry), Immediate(1), Immediate(0));
49 value = Operation(OperationCode::UAdd, std::move(value), std::move(x));
50 }
51
52 if (instr.generates_cc) {
53 const Node i0 = Immediate(0);
54
55 Node zero = Operation(OperationCode::LogicalIEqual, value, i0);
56 Node sign = Operation(OperationCode::LogicalILessThan, value, i0);
57 Node carry = Operation(OperationCode::LogicalAddCarry, op_a, op_b);
58
59 Node pos_a = Operation(OperationCode::LogicalIGreaterThan, op_a, i0);
60 Node pos_b = Operation(OperationCode::LogicalIGreaterThan, op_b, i0);
61 Node pos = Operation(OperationCode::LogicalAnd, std::move(pos_a), std::move(pos_b));
62 Node overflow = Operation(OperationCode::LogicalAnd, pos, sign);
63
64 SetInternalFlag(bb, InternalFlag::Zero, std::move(zero));
65 SetInternalFlag(bb, InternalFlag::Sign, std::move(sign));
66 SetInternalFlag(bb, InternalFlag::Carry, std::move(carry));
67 SetInternalFlag(bb, InternalFlag::Overflow, std::move(overflow));
68 }
69 SetRegister(bb, instr.gpr0, std::move(value));
47 break; 70 break;
48 } 71 }
49 case OpCode::Id::IADD3_C: 72 case OpCode::Id::IADD3_C:
diff --git a/src/video_core/shader/decode/register_set_predicate.cpp b/src/video_core/shader/decode/register_set_predicate.cpp
index 8d54cce34..6116c31aa 100644
--- a/src/video_core/shader/decode/register_set_predicate.cpp
+++ b/src/video_core/shader/decode/register_set_predicate.cpp
@@ -2,6 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <utility>
6
5#include "common/assert.h" 7#include "common/assert.h"
6#include "common/common_types.h" 8#include "common/common_types.h"
7#include "video_core/engines/shader_bytecode.h" 9#include "video_core/engines/shader_bytecode.h"
@@ -10,20 +12,20 @@
10 12
11namespace VideoCommon::Shader { 13namespace VideoCommon::Shader {
12 14
15using std::move;
13using Tegra::Shader::Instruction; 16using Tegra::Shader::Instruction;
14using Tegra::Shader::OpCode; 17using Tegra::Shader::OpCode;
15 18
16namespace { 19namespace {
17constexpr u64 NUM_PROGRAMMABLE_PREDICATES = 7; 20constexpr u64 NUM_CONDITION_CODES = 4;
18} 21constexpr u64 NUM_PREDICATES = 7;
22} // namespace
19 23
20u32 ShaderIR::DecodeRegisterSetPredicate(NodeBlock& bb, u32 pc) { 24u32 ShaderIR::DecodeRegisterSetPredicate(NodeBlock& bb, u32 pc) {
21 const Instruction instr = {program_code[pc]}; 25 const Instruction instr = {program_code[pc]};
22 const auto opcode = OpCode::Decode(instr); 26 const auto opcode = OpCode::Decode(instr);
23 27
24 UNIMPLEMENTED_IF(instr.p2r_r2p.mode != Tegra::Shader::R2pMode::Pr); 28 Node apply_mask = [this, opcode, instr] {
25
26 const Node apply_mask = [&] {
27 switch (opcode->get().GetId()) { 29 switch (opcode->get().GetId()) {
28 case OpCode::Id::R2P_IMM: 30 case OpCode::Id::R2P_IMM:
29 case OpCode::Id::P2R_IMM: 31 case OpCode::Id::P2R_IMM:
@@ -34,39 +36,43 @@ u32 ShaderIR::DecodeRegisterSetPredicate(NodeBlock& bb, u32 pc) {
34 } 36 }
35 }(); 37 }();
36 38
37 const auto offset = static_cast<u32>(instr.p2r_r2p.byte) * 8; 39 const u32 offset = static_cast<u32>(instr.p2r_r2p.byte) * 8;
40
41 const bool cc = instr.p2r_r2p.mode == Tegra::Shader::R2pMode::Cc;
42 const u64 num_entries = cc ? NUM_CONDITION_CODES : NUM_PREDICATES;
43 const auto get_entry = [this, cc](u64 entry) {
44 return cc ? GetInternalFlag(static_cast<InternalFlag>(entry)) : GetPredicate(entry);
45 };
38 46
39 switch (opcode->get().GetId()) { 47 switch (opcode->get().GetId()) {
40 case OpCode::Id::R2P_IMM: { 48 case OpCode::Id::R2P_IMM: {
41 const Node mask = GetRegister(instr.gpr8); 49 Node mask = GetRegister(instr.gpr8);
42 50
43 for (u64 pred = 0; pred < NUM_PROGRAMMABLE_PREDICATES; ++pred) { 51 for (u64 entry = 0; entry < num_entries; ++entry) {
44 const auto shift = static_cast<u32>(pred); 52 const u32 shift = static_cast<u32>(entry);
45 53
46 const Node apply_compare = BitfieldExtract(apply_mask, shift, 1); 54 Node apply = BitfieldExtract(apply_mask, shift, 1);
47 const Node condition = 55 Node condition = Operation(OperationCode::LogicalUNotEqual, apply, Immediate(0));
48 Operation(OperationCode::LogicalUNotEqual, apply_compare, Immediate(0));
49 56
50 const Node value_compare = BitfieldExtract(mask, offset + shift, 1); 57 Node compare = BitfieldExtract(mask, offset + shift, 1);
51 const Node value = 58 Node value = Operation(OperationCode::LogicalUNotEqual, move(compare), Immediate(0));
52 Operation(OperationCode::LogicalUNotEqual, value_compare, Immediate(0));
53 59
54 const Node code = Operation(OperationCode::LogicalAssign, GetPredicate(pred), value); 60 Node code = Operation(OperationCode::LogicalAssign, get_entry(entry), move(value));
55 bb.push_back(Conditional(condition, {code})); 61 bb.push_back(Conditional(condition, {move(code)}));
56 } 62 }
57 break; 63 break;
58 } 64 }
59 case OpCode::Id::P2R_IMM: { 65 case OpCode::Id::P2R_IMM: {
60 Node value = Immediate(0); 66 Node value = Immediate(0);
61 for (u64 pred = 0; pred < NUM_PROGRAMMABLE_PREDICATES; ++pred) { 67 for (u64 entry = 0; entry < num_entries; ++entry) {
62 Node bit = Operation(OperationCode::Select, GetPredicate(pred), Immediate(1U << pred), 68 Node bit = Operation(OperationCode::Select, get_entry(entry), Immediate(1U << entry),
63 Immediate(0)); 69 Immediate(0));
64 value = Operation(OperationCode::UBitwiseOr, std::move(value), std::move(bit)); 70 value = Operation(OperationCode::UBitwiseOr, move(value), move(bit));
65 } 71 }
66 value = Operation(OperationCode::UBitwiseAnd, std::move(value), apply_mask); 72 value = Operation(OperationCode::UBitwiseAnd, move(value), apply_mask);
67 value = BitfieldInsert(GetRegister(instr.gpr8), std::move(value), offset, 8); 73 value = BitfieldInsert(GetRegister(instr.gpr8), move(value), offset, 8);
68 74
69 SetRegister(bb, instr.gpr0, std::move(value)); 75 SetRegister(bb, instr.gpr0, move(value));
70 break; 76 break;
71 } 77 }
72 default: 78 default:
diff --git a/src/video_core/shader/memory_util.cpp b/src/video_core/shader/memory_util.cpp
new file mode 100644
index 000000000..074f21691
--- /dev/null
+++ b/src/video_core/shader/memory_util.cpp
@@ -0,0 +1,77 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <cstddef>
7
8#include <boost/container_hash/hash.hpp>
9
10#include "common/common_types.h"
11#include "core/core.h"
12#include "video_core/engines/maxwell_3d.h"
13#include "video_core/memory_manager.h"
14#include "video_core/shader/memory_util.h"
15#include "video_core/shader/shader_ir.h"
16
17namespace VideoCommon::Shader {
18
19GPUVAddr GetShaderAddress(Core::System& system,
20 Tegra::Engines::Maxwell3D::Regs::ShaderProgram program) {
21 const auto& gpu{system.GPU().Maxwell3D()};
22 const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]};
23 return gpu.regs.code_address.CodeAddress() + shader_config.offset;
24}
25
26bool IsSchedInstruction(std::size_t offset, std::size_t main_offset) {
27 // Sched instructions appear once every 4 instructions.
28 constexpr std::size_t SchedPeriod = 4;
29 const std::size_t absolute_offset = offset - main_offset;
30 return (absolute_offset % SchedPeriod) == 0;
31}
32
33std::size_t CalculateProgramSize(const ProgramCode& program, bool is_compute) {
34 // This is the encoded version of BRA that jumps to itself. All Nvidia
35 // shaders end with one.
36 static constexpr u64 SELF_JUMPING_BRANCH = 0xE2400FFFFF07000FULL;
37 static constexpr u64 MASK = 0xFFFFFFFFFF7FFFFFULL;
38
39 const std::size_t start_offset = is_compute ? KERNEL_MAIN_OFFSET : STAGE_MAIN_OFFSET;
40 std::size_t offset = start_offset;
41 while (offset < program.size()) {
42 const u64 instruction = program[offset];
43 if (!IsSchedInstruction(offset, start_offset)) {
44 if ((instruction & MASK) == SELF_JUMPING_BRANCH) {
45 // End on Maxwell's "nop" instruction
46 break;
47 }
48 if (instruction == 0) {
49 break;
50 }
51 }
52 ++offset;
53 }
54 // The last instruction is included in the program size
55 return std::min(offset + 1, program.size());
56}
57
58ProgramCode GetShaderCode(Tegra::MemoryManager& memory_manager, GPUVAddr gpu_addr,
59 const u8* host_ptr, bool is_compute) {
60 ProgramCode code(VideoCommon::Shader::MAX_PROGRAM_LENGTH);
61 ASSERT_OR_EXECUTE(host_ptr != nullptr, { return code; });
62 memory_manager.ReadBlockUnsafe(gpu_addr, code.data(), code.size() * sizeof(u64));
63 code.resize(CalculateProgramSize(code, is_compute));
64 return code;
65}
66
67u64 GetUniqueIdentifier(Tegra::Engines::ShaderType shader_type, bool is_a, const ProgramCode& code,
68 const ProgramCode& code_b) {
69 u64 unique_identifier = boost::hash_value(code);
70 if (is_a) {
71 // VertexA programs include two programs
72 boost::hash_combine(unique_identifier, boost::hash_value(code_b));
73 }
74 return unique_identifier;
75}
76
77} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/memory_util.h b/src/video_core/shader/memory_util.h
new file mode 100644
index 000000000..be90d24fd
--- /dev/null
+++ b/src/video_core/shader/memory_util.h
@@ -0,0 +1,47 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <cstddef>
8#include <vector>
9
10#include "common/common_types.h"
11#include "video_core/engines/maxwell_3d.h"
12#include "video_core/engines/shader_type.h"
13
14namespace Core {
15class System;
16}
17
18namespace Tegra {
19class MemoryManager;
20}
21
22namespace VideoCommon::Shader {
23
24using ProgramCode = std::vector<u64>;
25
26constexpr u32 STAGE_MAIN_OFFSET = 10;
27constexpr u32 KERNEL_MAIN_OFFSET = 0;
28
29/// Gets the address for the specified shader stage program
30GPUVAddr GetShaderAddress(Core::System& system,
31 Tegra::Engines::Maxwell3D::Regs::ShaderProgram program);
32
33/// Gets if the current instruction offset is a scheduler instruction
34bool IsSchedInstruction(std::size_t offset, std::size_t main_offset);
35
36/// Calculates the size of a program stream
37std::size_t CalculateProgramSize(const ProgramCode& program, bool is_compute);
38
39/// Gets the shader program code from memory for the specified address
40ProgramCode GetShaderCode(Tegra::MemoryManager& memory_manager, GPUVAddr gpu_addr,
41 const u8* host_ptr, bool is_compute);
42
43/// Hashes one (or two) program streams
44u64 GetUniqueIdentifier(Tegra::Engines::ShaderType shader_type, bool is_a, const ProgramCode& code,
45 const ProgramCode& code_b = {});
46
47} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h
index 3eee961f5..3f5a7bc7a 100644
--- a/src/video_core/shader/node.h
+++ b/src/video_core/shader/node.h
@@ -132,6 +132,8 @@ enum class OperationCode {
132 LogicalUNotEqual, /// (uint a, uint b) -> bool 132 LogicalUNotEqual, /// (uint a, uint b) -> bool
133 LogicalUGreaterEqual, /// (uint a, uint b) -> bool 133 LogicalUGreaterEqual, /// (uint a, uint b) -> bool
134 134
135 LogicalAddCarry, /// (uint a, uint b) -> bool
136
135 Logical2HLessThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2 137 Logical2HLessThan, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
136 Logical2HEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2 138 Logical2HEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
137 Logical2HLessEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2 139 Logical2HLessEqual, /// (MetaHalfArithmetic, f16vec2 a, f16vec2) -> bool2
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index c6e7bdf50..69de5e68b 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -18,6 +18,7 @@
18#include "video_core/engines/shader_header.h" 18#include "video_core/engines/shader_header.h"
19#include "video_core/shader/ast.h" 19#include "video_core/shader/ast.h"
20#include "video_core/shader/compiler_settings.h" 20#include "video_core/shader/compiler_settings.h"
21#include "video_core/shader/memory_util.h"
21#include "video_core/shader/node.h" 22#include "video_core/shader/node.h"
22#include "video_core/shader/registry.h" 23#include "video_core/shader/registry.h"
23 24
@@ -25,8 +26,6 @@ namespace VideoCommon::Shader {
25 26
26struct ShaderBlock; 27struct ShaderBlock;
27 28
28using ProgramCode = std::vector<u64>;
29
30constexpr u32 MAX_PROGRAM_LENGTH = 0x1000; 29constexpr u32 MAX_PROGRAM_LENGTH = 0x1000;
31 30
32class ConstBuffer { 31class ConstBuffer {
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp
index 513e9bf49..eb97bfd41 100644
--- a/src/video_core/shader/track.cpp
+++ b/src/video_core/shader/track.cpp
@@ -153,21 +153,13 @@ std::tuple<Node, u32, u32> ShaderIR::TrackCbuf(Node tracked, const NodeBlock& co
153 if (gpr->GetIndex() == Tegra::Shader::Register::ZeroIndex) { 153 if (gpr->GetIndex() == Tegra::Shader::Register::ZeroIndex) {
154 return {}; 154 return {};
155 } 155 }
156 s64 current_cursor = cursor; 156 // Reduce the cursor in one to avoid infinite loops when the instruction sets the same
157 while (current_cursor > 0) { 157 // register that it uses as operand
158 // Reduce the cursor in one to avoid infinite loops when the instruction sets the same 158 const auto [source, new_cursor] = TrackRegister(gpr, code, cursor - 1);
159 // register that it uses as operand 159 if (!source) {
160 const auto [source, new_cursor] = TrackRegister(gpr, code, current_cursor - 1); 160 return {};
161 current_cursor = new_cursor;
162 if (!source) {
163 continue;
164 }
165 const auto [base_address, index, offset] = TrackCbuf(source, code, current_cursor);
166 if (base_address != nullptr) {
167 return {base_address, index, offset};
168 }
169 } 161 }
170 return {}; 162 return TrackCbuf(source, code, new_cursor);
171 } 163 }
172 if (const auto operation = std::get_if<OperationNode>(&*tracked)) { 164 if (const auto operation = std::get_if<OperationNode>(&*tracked)) {
173 for (std::size_t i = operation->GetOperandsCount(); i > 0; --i) { 165 for (std::size_t i = operation->GetOperandsCount(); i > 0; --i) {
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index cf6bd005a..d2d2846e6 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -143,7 +143,7 @@ public:
143 } 143 }
144 144
145 const auto params{SurfaceParams::CreateForTexture(format_lookup_table, tic, entry)}; 145 const auto params{SurfaceParams::CreateForTexture(format_lookup_table, tic, entry)};
146 const auto [surface, view] = GetSurface(gpu_addr, *cpu_addr, params, false); 146 const auto [surface, view] = GetSurface(gpu_addr, *cpu_addr, params, true, false);
147 if (guard_samplers) { 147 if (guard_samplers) {
148 sampled_textures.push_back(surface); 148 sampled_textures.push_back(surface);
149 } 149 }
@@ -163,7 +163,7 @@ public:
163 return GetNullSurface(SurfaceParams::ExpectedTarget(entry)); 163 return GetNullSurface(SurfaceParams::ExpectedTarget(entry));
164 } 164 }
165 const auto params{SurfaceParams::CreateForImage(format_lookup_table, tic, entry)}; 165 const auto params{SurfaceParams::CreateForImage(format_lookup_table, tic, entry)};
166 const auto [surface, view] = GetSurface(gpu_addr, *cpu_addr, params, false); 166 const auto [surface, view] = GetSurface(gpu_addr, *cpu_addr, params, true, false);
167 if (guard_samplers) { 167 if (guard_samplers) {
168 sampled_textures.push_back(surface); 168 sampled_textures.push_back(surface);
169 } 169 }
@@ -178,7 +178,7 @@ public:
178 return any_rt; 178 return any_rt;
179 } 179 }
180 180
181 TView GetDepthBufferSurface() { 181 TView GetDepthBufferSurface(bool preserve_contents) {
182 std::lock_guard lock{mutex}; 182 std::lock_guard lock{mutex};
183 auto& maxwell3d = system.GPU().Maxwell3D(); 183 auto& maxwell3d = system.GPU().Maxwell3D();
184 if (!maxwell3d.dirty.flags[VideoCommon::Dirty::ZetaBuffer]) { 184 if (!maxwell3d.dirty.flags[VideoCommon::Dirty::ZetaBuffer]) {
@@ -199,7 +199,7 @@ public:
199 return {}; 199 return {};
200 } 200 }
201 const auto depth_params{SurfaceParams::CreateForDepthBuffer(system)}; 201 const auto depth_params{SurfaceParams::CreateForDepthBuffer(system)};
202 auto surface_view = GetSurface(gpu_addr, *cpu_addr, depth_params, true); 202 auto surface_view = GetSurface(gpu_addr, *cpu_addr, depth_params, preserve_contents, true);
203 if (depth_buffer.target) 203 if (depth_buffer.target)
204 depth_buffer.target->MarkAsRenderTarget(false, NO_RT); 204 depth_buffer.target->MarkAsRenderTarget(false, NO_RT);
205 depth_buffer.target = surface_view.first; 205 depth_buffer.target = surface_view.first;
@@ -209,7 +209,7 @@ public:
209 return surface_view.second; 209 return surface_view.second;
210 } 210 }
211 211
212 TView GetColorBufferSurface(std::size_t index) { 212 TView GetColorBufferSurface(std::size_t index, bool preserve_contents) {
213 std::lock_guard lock{mutex}; 213 std::lock_guard lock{mutex};
214 ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets); 214 ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets);
215 auto& maxwell3d = system.GPU().Maxwell3D(); 215 auto& maxwell3d = system.GPU().Maxwell3D();
@@ -239,8 +239,9 @@ public:
239 return {}; 239 return {};
240 } 240 }
241 241
242 auto surface_view = GetSurface(gpu_addr, *cpu_addr, 242 auto surface_view =
243 SurfaceParams::CreateForFramebuffer(system, index), true); 243 GetSurface(gpu_addr, *cpu_addr, SurfaceParams::CreateForFramebuffer(system, index),
244 preserve_contents, true);
244 if (render_targets[index].target) { 245 if (render_targets[index].target) {
245 auto& surface = render_targets[index].target; 246 auto& surface = render_targets[index].target;
246 surface->MarkAsRenderTarget(false, NO_RT); 247 surface->MarkAsRenderTarget(false, NO_RT);
@@ -300,9 +301,9 @@ public:
300 const std::optional<VAddr> src_cpu_addr = 301 const std::optional<VAddr> src_cpu_addr =
301 system.GPU().MemoryManager().GpuToCpuAddress(src_gpu_addr); 302 system.GPU().MemoryManager().GpuToCpuAddress(src_gpu_addr);
302 std::pair<TSurface, TView> dst_surface = 303 std::pair<TSurface, TView> dst_surface =
303 GetSurface(dst_gpu_addr, *dst_cpu_addr, dst_params, false); 304 GetSurface(dst_gpu_addr, *dst_cpu_addr, dst_params, true, false);
304 std::pair<TSurface, TView> src_surface = 305 std::pair<TSurface, TView> src_surface =
305 GetSurface(src_gpu_addr, *src_cpu_addr, src_params, false); 306 GetSurface(src_gpu_addr, *src_cpu_addr, src_params, true, false);
306 ImageBlit(src_surface.second, dst_surface.second, copy_config); 307 ImageBlit(src_surface.second, dst_surface.second, copy_config);
307 dst_surface.first->MarkAsModified(true, Tick()); 308 dst_surface.first->MarkAsModified(true, Tick());
308 } 309 }
@@ -532,18 +533,22 @@ private:
532 * @param overlaps The overlapping surfaces registered in the cache. 533 * @param overlaps The overlapping surfaces registered in the cache.
533 * @param params The parameters for the new surface. 534 * @param params The parameters for the new surface.
534 * @param gpu_addr The starting address of the new surface. 535 * @param gpu_addr The starting address of the new surface.
536 * @param preserve_contents Indicates that the new surface should be loaded from memory or left
537 * blank.
535 * @param untopological Indicates to the recycler that the texture has no way to match the 538 * @param untopological Indicates to the recycler that the texture has no way to match the
536 * overlaps due to topological reasons. 539 * overlaps due to topological reasons.
537 **/ 540 **/
538 std::pair<TSurface, TView> RecycleSurface(std::vector<TSurface>& overlaps, 541 std::pair<TSurface, TView> RecycleSurface(std::vector<TSurface>& overlaps,
539 const SurfaceParams& params, const GPUVAddr gpu_addr, 542 const SurfaceParams& params, const GPUVAddr gpu_addr,
543 const bool preserve_contents,
540 const MatchTopologyResult untopological) { 544 const MatchTopologyResult untopological) {
545 const bool do_load = preserve_contents && Settings::IsGPULevelExtreme();
541 for (auto& surface : overlaps) { 546 for (auto& surface : overlaps) {
542 Unregister(surface); 547 Unregister(surface);
543 } 548 }
544 switch (PickStrategy(overlaps, params, gpu_addr, untopological)) { 549 switch (PickStrategy(overlaps, params, gpu_addr, untopological)) {
545 case RecycleStrategy::Ignore: { 550 case RecycleStrategy::Ignore: {
546 return InitializeSurface(gpu_addr, params, Settings::IsGPULevelExtreme()); 551 return InitializeSurface(gpu_addr, params, do_load);
547 } 552 }
548 case RecycleStrategy::Flush: { 553 case RecycleStrategy::Flush: {
549 std::sort(overlaps.begin(), overlaps.end(), 554 std::sort(overlaps.begin(), overlaps.end(),
@@ -553,7 +558,7 @@ private:
553 for (auto& surface : overlaps) { 558 for (auto& surface : overlaps) {
554 FlushSurface(surface); 559 FlushSurface(surface);
555 } 560 }
556 return InitializeSurface(gpu_addr, params); 561 return InitializeSurface(gpu_addr, params, preserve_contents);
557 } 562 }
558 case RecycleStrategy::BufferCopy: { 563 case RecycleStrategy::BufferCopy: {
559 auto new_surface = GetUncachedSurface(gpu_addr, params); 564 auto new_surface = GetUncachedSurface(gpu_addr, params);
@@ -562,7 +567,7 @@ private:
562 } 567 }
563 default: { 568 default: {
564 UNIMPLEMENTED_MSG("Unimplemented Texture Cache Recycling Strategy!"); 569 UNIMPLEMENTED_MSG("Unimplemented Texture Cache Recycling Strategy!");
565 return InitializeSurface(gpu_addr, params); 570 return InitializeSurface(gpu_addr, params, do_load);
566 } 571 }
567 } 572 }
568 } 573 }
@@ -700,11 +705,14 @@ private:
700 * @param params The parameters on the new surface. 705 * @param params The parameters on the new surface.
701 * @param gpu_addr The starting address of the new surface. 706 * @param gpu_addr The starting address of the new surface.
702 * @param cpu_addr The starting address of the new surface on physical memory. 707 * @param cpu_addr The starting address of the new surface on physical memory.
708 * @param preserve_contents Indicates that the new surface should be loaded from memory or
709 * left blank.
703 */ 710 */
704 std::optional<std::pair<TSurface, TView>> Manage3DSurfaces(std::vector<TSurface>& overlaps, 711 std::optional<std::pair<TSurface, TView>> Manage3DSurfaces(std::vector<TSurface>& overlaps,
705 const SurfaceParams& params, 712 const SurfaceParams& params,
706 const GPUVAddr gpu_addr, 713 const GPUVAddr gpu_addr,
707 const VAddr cpu_addr) { 714 const VAddr cpu_addr,
715 bool preserve_contents) {
708 if (params.target == SurfaceTarget::Texture3D) { 716 if (params.target == SurfaceTarget::Texture3D) {
709 bool failed = false; 717 bool failed = false;
710 if (params.num_levels > 1) { 718 if (params.num_levels > 1) {
@@ -754,7 +762,7 @@ private:
754 return std::nullopt; 762 return std::nullopt;
755 } 763 }
756 Unregister(surface); 764 Unregister(surface);
757 return InitializeSurface(gpu_addr, params); 765 return InitializeSurface(gpu_addr, params, preserve_contents);
758 } 766 }
759 return std::nullopt; 767 return std::nullopt;
760 } 768 }
@@ -765,7 +773,7 @@ private:
765 return {{surface, surface->GetMainView()}}; 773 return {{surface, surface->GetMainView()}};
766 } 774 }
767 } 775 }
768 return InitializeSurface(gpu_addr, params); 776 return InitializeSurface(gpu_addr, params, preserve_contents);
769 } 777 }
770 } 778 }
771 779
@@ -788,10 +796,13 @@ private:
788 * 796 *
789 * @param gpu_addr The starting address of the candidate surface. 797 * @param gpu_addr The starting address of the candidate surface.
790 * @param params The parameters on the candidate surface. 798 * @param params The parameters on the candidate surface.
799 * @param preserve_contents Indicates that the new surface should be loaded from memory or
800 * left blank.
791 * @param is_render Whether or not the surface is a render target. 801 * @param is_render Whether or not the surface is a render target.
792 **/ 802 **/
793 std::pair<TSurface, TView> GetSurface(const GPUVAddr gpu_addr, const VAddr cpu_addr, 803 std::pair<TSurface, TView> GetSurface(const GPUVAddr gpu_addr, const VAddr cpu_addr,
794 const SurfaceParams& params, bool is_render) { 804 const SurfaceParams& params, bool preserve_contents,
805 bool is_render) {
795 // Step 1 806 // Step 1
796 // Check Level 1 Cache for a fast structural match. If candidate surface 807 // Check Level 1 Cache for a fast structural match. If candidate surface
797 // matches at certain level we are pretty much done. 808 // matches at certain level we are pretty much done.
@@ -800,7 +811,8 @@ private:
800 const auto topological_result = current_surface->MatchesTopology(params); 811 const auto topological_result = current_surface->MatchesTopology(params);
801 if (topological_result != MatchTopologyResult::FullMatch) { 812 if (topological_result != MatchTopologyResult::FullMatch) {
802 std::vector<TSurface> overlaps{current_surface}; 813 std::vector<TSurface> overlaps{current_surface};
803 return RecycleSurface(overlaps, params, gpu_addr, topological_result); 814 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
815 topological_result);
804 } 816 }
805 817
806 const auto struct_result = current_surface->MatchesStructure(params); 818 const auto struct_result = current_surface->MatchesStructure(params);
@@ -825,7 +837,7 @@ private:
825 837
826 // If none are found, we are done. we just load the surface and create it. 838 // If none are found, we are done. we just load the surface and create it.
827 if (overlaps.empty()) { 839 if (overlaps.empty()) {
828 return InitializeSurface(gpu_addr, params); 840 return InitializeSurface(gpu_addr, params, preserve_contents);
829 } 841 }
830 842
831 // Step 3 843 // Step 3
@@ -835,13 +847,15 @@ private:
835 for (const auto& surface : overlaps) { 847 for (const auto& surface : overlaps) {
836 const auto topological_result = surface->MatchesTopology(params); 848 const auto topological_result = surface->MatchesTopology(params);
837 if (topological_result != MatchTopologyResult::FullMatch) { 849 if (topological_result != MatchTopologyResult::FullMatch) {
838 return RecycleSurface(overlaps, params, gpu_addr, topological_result); 850 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
851 topological_result);
839 } 852 }
840 } 853 }
841 854
842 // Check if it's a 3D texture 855 // Check if it's a 3D texture
843 if (params.block_depth > 0) { 856 if (params.block_depth > 0) {
844 auto surface = Manage3DSurfaces(overlaps, params, gpu_addr, cpu_addr); 857 auto surface =
858 Manage3DSurfaces(overlaps, params, gpu_addr, cpu_addr, preserve_contents);
845 if (surface) { 859 if (surface) {
846 return *surface; 860 return *surface;
847 } 861 }
@@ -861,7 +875,8 @@ private:
861 return *view; 875 return *view;
862 } 876 }
863 } 877 }
864 return RecycleSurface(overlaps, params, gpu_addr, MatchTopologyResult::FullMatch); 878 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
879 MatchTopologyResult::FullMatch);
865 } 880 }
866 // Now we check if the candidate is a mipmap/layer of the overlap 881 // Now we check if the candidate is a mipmap/layer of the overlap
867 std::optional<TView> view = 882 std::optional<TView> view =
@@ -885,7 +900,7 @@ private:
885 pair.first->EmplaceView(params, gpu_addr, candidate_size); 900 pair.first->EmplaceView(params, gpu_addr, candidate_size);
886 if (mirage_view) 901 if (mirage_view)
887 return {pair.first, *mirage_view}; 902 return {pair.first, *mirage_view};
888 return RecycleSurface(overlaps, params, gpu_addr, 903 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
889 MatchTopologyResult::FullMatch); 904 MatchTopologyResult::FullMatch);
890 } 905 }
891 return {current_surface, *view}; 906 return {current_surface, *view};
@@ -901,7 +916,8 @@ private:
901 } 916 }
902 } 917 }
903 // We failed all the tests, recycle the overlaps into a new texture. 918 // We failed all the tests, recycle the overlaps into a new texture.
904 return RecycleSurface(overlaps, params, gpu_addr, MatchTopologyResult::FullMatch); 919 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
920 MatchTopologyResult::FullMatch);
905 } 921 }
906 922
907 /** 923 /**
@@ -1059,10 +1075,10 @@ private:
1059 } 1075 }
1060 1076
1061 std::pair<TSurface, TView> InitializeSurface(GPUVAddr gpu_addr, const SurfaceParams& params, 1077 std::pair<TSurface, TView> InitializeSurface(GPUVAddr gpu_addr, const SurfaceParams& params,
1062 bool do_load = true) { 1078 bool preserve_contents) {
1063 auto new_surface{GetUncachedSurface(gpu_addr, params)}; 1079 auto new_surface{GetUncachedSurface(gpu_addr, params)};
1064 Register(new_surface); 1080 Register(new_surface);
1065 if (do_load) { 1081 if (preserve_contents) {
1066 LoadSurface(new_surface); 1082 LoadSurface(new_surface);
1067 } 1083 }
1068 return {new_surface, new_surface->GetMainView()}; 1084 return {new_surface, new_surface->GetMainView()};
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 05baec7e1..b44b4276c 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1304,7 +1304,9 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
1304 FileSys::VirtualFile romfs; 1304 FileSys::VirtualFile romfs;
1305 1305
1306 if (*romfs_title_id == program_id) { 1306 if (*romfs_title_id == program_id) {
1307 romfs = file; 1307 const u64 ivfc_offset = loader->ReadRomFSIVFCOffset();
1308 FileSys::PatchManager pm{program_id};
1309 romfs = pm.PatchRomFS(file, ivfc_offset, FileSys::ContentRecordType::Program);
1308 } else { 1310 } else {
1309 romfs = installed.GetEntry(*romfs_title_id, FileSys::ContentRecordType::Data)->GetRomFS(); 1311 romfs = installed.GetEntry(*romfs_title_id, FileSys::ContentRecordType::Data)->GetRomFS();
1310 } 1312 }