diff options
Diffstat (limited to 'src')
57 files changed, 638 insertions, 417 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt index b3b3fc209..6aba69dbe 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt | |||
| @@ -73,7 +73,7 @@ abstract class SettingsItem( | |||
| 73 | R.string.frame_limit_slider, | 73 | R.string.frame_limit_slider, |
| 74 | R.string.frame_limit_slider_description, | 74 | R.string.frame_limit_slider_description, |
| 75 | 1, | 75 | 1, |
| 76 | 200, | 76 | 400, |
| 77 | "%" | 77 | "%" |
| 78 | ) | 78 | ) |
| 79 | ) | 79 | ) |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/InstallableFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/InstallableFragment.kt index ec116ab62..6940fc757 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/InstallableFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/InstallableFragment.kt | |||
| @@ -21,6 +21,8 @@ import org.yuzu.yuzu_emu.databinding.FragmentInstallablesBinding | |||
| 21 | import org.yuzu.yuzu_emu.model.HomeViewModel | 21 | import org.yuzu.yuzu_emu.model.HomeViewModel |
| 22 | import org.yuzu.yuzu_emu.model.Installable | 22 | import org.yuzu.yuzu_emu.model.Installable |
| 23 | import org.yuzu.yuzu_emu.ui.main.MainActivity | 23 | import org.yuzu.yuzu_emu.ui.main.MainActivity |
| 24 | import java.time.LocalDateTime | ||
| 25 | import java.time.format.DateTimeFormatter | ||
| 24 | 26 | ||
| 25 | class InstallableFragment : Fragment() { | 27 | class InstallableFragment : Fragment() { |
| 26 | private var _binding: FragmentInstallablesBinding? = null | 28 | private var _binding: FragmentInstallablesBinding? = null |
| @@ -78,7 +80,15 @@ class InstallableFragment : Fragment() { | |||
| 78 | R.string.manage_save_data, | 80 | R.string.manage_save_data, |
| 79 | R.string.import_export_saves_description, | 81 | R.string.import_export_saves_description, |
| 80 | install = { mainActivity.importSaves.launch(arrayOf("application/zip")) }, | 82 | install = { mainActivity.importSaves.launch(arrayOf("application/zip")) }, |
| 81 | export = { mainActivity.exportSave() } | 83 | export = { |
| 84 | mainActivity.exportSaves.launch( | ||
| 85 | "yuzu saves - ${ | ||
| 86 | LocalDateTime.now().format( | ||
| 87 | DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm") | ||
| 88 | ) | ||
| 89 | }.zip" | ||
| 90 | ) | ||
| 91 | } | ||
| 82 | ) | 92 | ) |
| 83 | } else { | 93 | } else { |
| 84 | Installable( | 94 | Installable( |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt index de84b2adb..2fa3ab31b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.kt | |||
| @@ -18,8 +18,8 @@ class Game( | |||
| 18 | val version: String = "", | 18 | val version: String = "", |
| 19 | val isHomebrew: Boolean = false | 19 | val isHomebrew: Boolean = false |
| 20 | ) : Parcelable { | 20 | ) : Parcelable { |
| 21 | val keyAddedToLibraryTime get() = "${programId}_AddedToLibraryTime" | 21 | val keyAddedToLibraryTime get() = "${path}_AddedToLibraryTime" |
| 22 | val keyLastPlayedTime get() = "${programId}_LastPlayed" | 22 | val keyLastPlayedTime get() = "${path}_LastPlayed" |
| 23 | 23 | ||
| 24 | override fun equals(other: Any?): Boolean { | 24 | override fun equals(other: Any?): Boolean { |
| 25 | if (other !is Game) { | 25 | if (other !is Game) { |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index 211b7cf69..ace5dddea 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt | |||
| @@ -6,7 +6,6 @@ package org.yuzu.yuzu_emu.ui.main | |||
| 6 | import android.content.Intent | 6 | import android.content.Intent |
| 7 | import android.net.Uri | 7 | import android.net.Uri |
| 8 | import android.os.Bundle | 8 | import android.os.Bundle |
| 9 | import android.provider.DocumentsContract | ||
| 10 | import android.view.View | 9 | import android.view.View |
| 11 | import android.view.ViewGroup.MarginLayoutParams | 10 | import android.view.ViewGroup.MarginLayoutParams |
| 12 | import android.view.WindowManager | 11 | import android.view.WindowManager |
| @@ -20,7 +19,6 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | |||
| 20 | import androidx.core.view.ViewCompat | 19 | import androidx.core.view.ViewCompat |
| 21 | import androidx.core.view.WindowCompat | 20 | import androidx.core.view.WindowCompat |
| 22 | import androidx.core.view.WindowInsetsCompat | 21 | import androidx.core.view.WindowInsetsCompat |
| 23 | import androidx.documentfile.provider.DocumentFile | ||
| 24 | import androidx.lifecycle.Lifecycle | 22 | import androidx.lifecycle.Lifecycle |
| 25 | import androidx.lifecycle.lifecycleScope | 23 | import androidx.lifecycle.lifecycleScope |
| 26 | import androidx.lifecycle.repeatOnLifecycle | 24 | import androidx.lifecycle.repeatOnLifecycle |
| @@ -41,7 +39,6 @@ import org.yuzu.yuzu_emu.NativeLibrary | |||
| 41 | import org.yuzu.yuzu_emu.R | 39 | import org.yuzu.yuzu_emu.R |
| 42 | import org.yuzu.yuzu_emu.activities.EmulationActivity | 40 | import org.yuzu.yuzu_emu.activities.EmulationActivity |
| 43 | import org.yuzu.yuzu_emu.databinding.ActivityMainBinding | 41 | import org.yuzu.yuzu_emu.databinding.ActivityMainBinding |
| 44 | import org.yuzu.yuzu_emu.features.DocumentProvider | ||
| 45 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 42 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 46 | import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment | 43 | import org.yuzu.yuzu_emu.fragments.IndeterminateProgressDialogFragment |
| 47 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment | 44 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment |
| @@ -53,9 +50,6 @@ import org.yuzu.yuzu_emu.model.TaskViewModel | |||
| 53 | import org.yuzu.yuzu_emu.utils.* | 50 | import org.yuzu.yuzu_emu.utils.* |
| 54 | import java.io.BufferedInputStream | 51 | import java.io.BufferedInputStream |
| 55 | import java.io.BufferedOutputStream | 52 | import java.io.BufferedOutputStream |
| 56 | import java.io.FileOutputStream | ||
| 57 | import java.time.LocalDateTime | ||
| 58 | import java.time.format.DateTimeFormatter | ||
| 59 | import java.util.zip.ZipEntry | 53 | import java.util.zip.ZipEntry |
| 60 | import java.util.zip.ZipInputStream | 54 | import java.util.zip.ZipInputStream |
| 61 | 55 | ||
| @@ -73,7 +67,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider { | |||
| 73 | 67 | ||
| 74 | // Get first subfolder in saves folder (should be the user folder) | 68 | // Get first subfolder in saves folder (should be the user folder) |
| 75 | val savesFolderRoot get() = File(savesFolder).listFiles()?.firstOrNull()?.canonicalPath ?: "" | 69 | val savesFolderRoot get() = File(savesFolder).listFiles()?.firstOrNull()?.canonicalPath ?: "" |
| 76 | private var lastZipCreated: File? = null | ||
| 77 | 70 | ||
| 78 | override fun onCreate(savedInstanceState: Bundle?) { | 71 | override fun onCreate(savedInstanceState: Bundle?) { |
| 79 | val splashScreen = installSplashScreen() | 72 | val splashScreen = installSplashScreen() |
| @@ -657,74 +650,30 @@ class MainActivity : AppCompatActivity(), ThemeProvider { | |||
| 657 | } | 650 | } |
| 658 | 651 | ||
| 659 | /** | 652 | /** |
| 660 | * Zips the save files located in the given folder path and creates a new zip file with the current date and time. | ||
| 661 | * @return true if the zip file is successfully created, false otherwise. | ||
| 662 | */ | ||
| 663 | private fun zipSave(): Boolean { | ||
| 664 | try { | ||
| 665 | val tempFolder = File(getPublicFilesDir().canonicalPath, "temp") | ||
| 666 | tempFolder.mkdirs() | ||
| 667 | val saveFolder = File(savesFolderRoot) | ||
| 668 | val outputZipFile = File( | ||
| 669 | tempFolder, | ||
| 670 | "yuzu saves - ${ | ||
| 671 | LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")) | ||
| 672 | }.zip" | ||
| 673 | ) | ||
| 674 | outputZipFile.createNewFile() | ||
| 675 | val result = FileUtil.zipFromInternalStorage( | ||
| 676 | saveFolder, | ||
| 677 | savesFolderRoot, | ||
| 678 | BufferedOutputStream(FileOutputStream(outputZipFile)) | ||
| 679 | ) | ||
| 680 | if (result == TaskState.Failed) { | ||
| 681 | return false | ||
| 682 | } | ||
| 683 | lastZipCreated = outputZipFile | ||
| 684 | } catch (e: Exception) { | ||
| 685 | return false | ||
| 686 | } | ||
| 687 | return true | ||
| 688 | } | ||
| 689 | |||
| 690 | /** | ||
| 691 | * Exports the save file located in the given folder path by creating a zip file and sharing it via intent. | 653 | * Exports the save file located in the given folder path by creating a zip file and sharing it via intent. |
| 692 | */ | 654 | */ |
| 693 | fun exportSave() { | 655 | val exportSaves = registerForActivityResult( |
| 694 | CoroutineScope(Dispatchers.IO).launch { | 656 | ActivityResultContracts.CreateDocument("application/zip") |
| 695 | val wasZipCreated = zipSave() | 657 | ) { result -> |
| 696 | val lastZipFile = lastZipCreated | 658 | if (result == null) { |
| 697 | if (!wasZipCreated || lastZipFile == null) { | 659 | return@registerForActivityResult |
| 698 | withContext(Dispatchers.Main) { | 660 | } |
| 699 | Toast.makeText( | ||
| 700 | this@MainActivity, | ||
| 701 | getString(R.string.export_save_failed), | ||
| 702 | Toast.LENGTH_LONG | ||
| 703 | ).show() | ||
| 704 | } | ||
| 705 | return@launch | ||
| 706 | } | ||
| 707 | 661 | ||
| 708 | withContext(Dispatchers.Main) { | 662 | IndeterminateProgressDialogFragment.newInstance( |
| 709 | val file = DocumentFile.fromSingleUri( | 663 | this, |
| 710 | this@MainActivity, | 664 | R.string.save_files_exporting, |
| 711 | DocumentsContract.buildDocumentUri( | 665 | false |
| 712 | DocumentProvider.AUTHORITY, | 666 | ) { |
| 713 | "${DocumentProvider.ROOT_ID}/temp/${lastZipFile.name}" | 667 | val zipResult = FileUtil.zipFromInternalStorage( |
| 714 | ) | 668 | File(savesFolderRoot), |
| 715 | )!! | 669 | savesFolderRoot, |
| 716 | val intent = Intent(Intent.ACTION_SEND) | 670 | BufferedOutputStream(contentResolver.openOutputStream(result)) |
| 717 | .setDataAndType(file.uri, "application/zip") | 671 | ) |
| 718 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | 672 | return@newInstance when (zipResult) { |
| 719 | .putExtra(Intent.EXTRA_STREAM, file.uri) | 673 | TaskState.Completed -> getString(R.string.export_success) |
| 720 | startForResultExportSave.launch( | 674 | TaskState.Cancelled, TaskState.Failed -> getString(R.string.export_failed) |
| 721 | Intent.createChooser( | ||
| 722 | intent, | ||
| 723 | getString(R.string.share_save_file) | ||
| 724 | ) | ||
| 725 | ) | ||
| 726 | } | 675 | } |
| 727 | } | 676 | }.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG) |
| 728 | } | 677 | } |
| 729 | 678 | ||
| 730 | private val startForResultExportSave = | 679 | private val startForResultExportSave = |
diff --git a/src/android/app/src/main/res/layout/fragment_search.xml b/src/android/app/src/main/res/layout/fragment_search.xml index b8d54d947..efdfd7047 100644 --- a/src/android/app/src/main/res/layout/fragment_search.xml +++ b/src/android/app/src/main/res/layout/fragment_search.xml | |||
| @@ -127,6 +127,7 @@ | |||
| 127 | android:layout_height="wrap_content" | 127 | android:layout_height="wrap_content" |
| 128 | android:clipToPadding="false" | 128 | android:clipToPadding="false" |
| 129 | android:paddingVertical="4dp" | 129 | android:paddingVertical="4dp" |
| 130 | app:checkedChip="@id/chip_recently_played" | ||
| 130 | app:chipSpacingHorizontal="12dp" | 131 | app:chipSpacingHorizontal="12dp" |
| 131 | app:singleLine="true" | 132 | app:singleLine="true" |
| 132 | app:singleSelection="true"> | 133 | app:singleSelection="true"> |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 98c3f20f8..471af8795 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -91,6 +91,7 @@ | |||
| 91 | <string name="manage_save_data">Manage save data</string> | 91 | <string name="manage_save_data">Manage save data</string> |
| 92 | <string name="manage_save_data_description">Save data found. Please select an option below.</string> | 92 | <string name="manage_save_data_description">Save data found. Please select an option below.</string> |
| 93 | <string name="import_export_saves_description">Import or export save files</string> | 93 | <string name="import_export_saves_description">Import or export save files</string> |
| 94 | <string name="save_files_exporting">Exporting save files…</string> | ||
| 94 | <string name="save_file_imported_success">Imported successfully</string> | 95 | <string name="save_file_imported_success">Imported successfully</string> |
| 95 | <string name="save_file_invalid_zip_structure">Invalid save directory structure</string> | 96 | <string name="save_file_invalid_zip_structure">Invalid save directory structure</string> |
| 96 | <string name="save_file_invalid_zip_structure_description">The first subfolder name must be the title ID of the game.</string> | 97 | <string name="save_file_invalid_zip_structure_description">The first subfolder name must be the title ID of the game.</string> |
| @@ -256,6 +257,7 @@ | |||
| 256 | <string name="cancelling">Cancelling</string> | 257 | <string name="cancelling">Cancelling</string> |
| 257 | <string name="install">Install</string> | 258 | <string name="install">Install</string> |
| 258 | <string name="delete">Delete</string> | 259 | <string name="delete">Delete</string> |
| 260 | <string name="export_success">Exported successfully</string> | ||
| 259 | 261 | ||
| 260 | <!-- GPU driver installation --> | 262 | <!-- GPU driver installation --> |
| 261 | <string name="select_gpu_driver">Select GPU driver</string> | 263 | <string name="select_gpu_driver">Select GPU driver</string> |
diff --git a/src/audio_core/adsp/apps/opus/opus_multistream_decode_object.cpp b/src/audio_core/adsp/apps/opus/opus_multistream_decode_object.cpp index 7f1ed0450..05cf3975d 100644 --- a/src/audio_core/adsp/apps/opus/opus_multistream_decode_object.cpp +++ b/src/audio_core/adsp/apps/opus/opus_multistream_decode_object.cpp | |||
| @@ -12,7 +12,7 @@ bool IsValidChannelCount(u32 channel_count) { | |||
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | bool IsValidStreamCounts(u32 total_stream_count, u32 stereo_stream_count) { | 14 | bool IsValidStreamCounts(u32 total_stream_count, u32 stereo_stream_count) { |
| 15 | return total_stream_count > 0 && stereo_stream_count > 0 && | 15 | return total_stream_count > 0 && static_cast<s32>(stereo_stream_count) >= 0 && |
| 16 | stereo_stream_count <= total_stream_count && IsValidChannelCount(total_stream_count); | 16 | stereo_stream_count <= total_stream_count && IsValidChannelCount(total_stream_count); |
| 17 | } | 17 | } |
| 18 | } // namespace | 18 | } // namespace |
diff --git a/src/audio_core/opus/decoder.cpp b/src/audio_core/opus/decoder.cpp index c6fd45f47..b7fed5304 100644 --- a/src/audio_core/opus/decoder.cpp +++ b/src/audio_core/opus/decoder.cpp | |||
| @@ -148,7 +148,7 @@ Result OpusDecoder::DecodeInterleavedForMultiStream(u32* out_data_size, u64* out | |||
| 148 | auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())}; | 148 | auto* header_p{reinterpret_cast<const OpusPacketHeader*>(input_data.data())}; |
| 149 | OpusPacketHeader header{ReverseHeader(*header_p)}; | 149 | OpusPacketHeader header{ReverseHeader(*header_p)}; |
| 150 | 150 | ||
| 151 | LOG_ERROR(Service_Audio, "header size 0x{:X} input data size 0x{:X} in_data size 0x{:X}", | 151 | LOG_TRACE(Service_Audio, "header size 0x{:X} input data size 0x{:X} in_data size 0x{:X}", |
| 152 | header.size, input_data.size_bytes(), in_data.size_bytes()); | 152 | header.size, input_data.size_bytes(), in_data.size_bytes()); |
| 153 | 153 | ||
| 154 | R_UNLESS(in_data.size_bytes() >= header.size && | 154 | R_UNLESS(in_data.size_bytes() >= header.size && |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 555807e19..597890655 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -725,6 +725,7 @@ add_library(core STATIC | |||
| 725 | hle/service/nvnflinger/producer_listener.h | 725 | hle/service/nvnflinger/producer_listener.h |
| 726 | hle/service/nvnflinger/status.h | 726 | hle/service/nvnflinger/status.h |
| 727 | hle/service/nvnflinger/ui/fence.h | 727 | hle/service/nvnflinger/ui/fence.h |
| 728 | hle/service/nvnflinger/ui/graphic_buffer.cpp | ||
| 728 | hle/service/nvnflinger/ui/graphic_buffer.h | 729 | hle/service/nvnflinger/ui/graphic_buffer.h |
| 729 | hle/service/nvnflinger/window.h | 730 | hle/service/nvnflinger/window.h |
| 730 | hle/service/olsc/olsc.cpp | 731 | hle/service/olsc/olsc.cpp |
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 56f26a14a..9caed6541 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp | |||
| @@ -1563,7 +1563,7 @@ void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { | |||
| 1563 | 1563 | ||
| 1564 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1564 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1565 | rb.Push(ResultSuccess); | 1565 | rb.Push(ResultSuccess); |
| 1566 | rb.PushIpcInterface<IActiveVibrationDeviceList>(system, resource_manager); | 1566 | rb.PushIpcInterface<IActiveVibrationDeviceList>(system, GetResourceManager()); |
| 1567 | } | 1567 | } |
| 1568 | 1568 | ||
| 1569 | void IHidServer::PermitVibration(HLERequestContext& ctx) { | 1569 | void IHidServer::PermitVibration(HLERequestContext& ctx) { |
diff --git a/src/core/hle/service/nvnflinger/buffer_item.h b/src/core/hle/service/nvnflinger/buffer_item.h index 3da8cc3aa..7fd808f54 100644 --- a/src/core/hle/service/nvnflinger/buffer_item.h +++ b/src/core/hle/service/nvnflinger/buffer_item.h | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | namespace Service::android { | 16 | namespace Service::android { |
| 17 | 17 | ||
| 18 | struct GraphicBuffer; | 18 | class GraphicBuffer; |
| 19 | 19 | ||
| 20 | class BufferItem final { | 20 | class BufferItem final { |
| 21 | public: | 21 | public: |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp index 51291539d..d91886bed 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferQueueConsumer.cpp | 5 | // https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/libs/gui/BufferQueueConsumer.cpp |
| 6 | 6 | ||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 9 | #include "core/hle/service/nvnflinger/buffer_item.h" | 8 | #include "core/hle/service/nvnflinger/buffer_item.h" |
| 10 | #include "core/hle/service/nvnflinger/buffer_queue_consumer.h" | 9 | #include "core/hle/service/nvnflinger/buffer_queue_consumer.h" |
| 11 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" | 10 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" |
| @@ -14,9 +13,8 @@ | |||
| 14 | 13 | ||
| 15 | namespace Service::android { | 14 | namespace Service::android { |
| 16 | 15 | ||
| 17 | BufferQueueConsumer::BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_, | 16 | BufferQueueConsumer::BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_) |
| 18 | Service::Nvidia::NvCore::NvMap& nvmap_) | 17 | : core{std::move(core_)}, slots{core->slots} {} |
| 19 | : core{std::move(core_)}, slots{core->slots}, nvmap(nvmap_) {} | ||
| 20 | 18 | ||
| 21 | BufferQueueConsumer::~BufferQueueConsumer() = default; | 19 | BufferQueueConsumer::~BufferQueueConsumer() = default; |
| 22 | 20 | ||
| @@ -136,8 +134,6 @@ Status BufferQueueConsumer::ReleaseBuffer(s32 slot, u64 frame_number, const Fenc | |||
| 136 | 134 | ||
| 137 | slots[slot].buffer_state = BufferState::Free; | 135 | slots[slot].buffer_state = BufferState::Free; |
| 138 | 136 | ||
| 139 | nvmap.FreeHandle(slots[slot].graphic_buffer->BufferId(), true); | ||
| 140 | |||
| 141 | listener = core->connected_producer_listener; | 137 | listener = core->connected_producer_listener; |
| 142 | 138 | ||
| 143 | LOG_DEBUG(Service_Nvnflinger, "releasing slot {}", slot); | 139 | LOG_DEBUG(Service_Nvnflinger, "releasing slot {}", slot); |
| @@ -175,6 +171,25 @@ Status BufferQueueConsumer::Connect(std::shared_ptr<IConsumerListener> consumer_ | |||
| 175 | return Status::NoError; | 171 | return Status::NoError; |
| 176 | } | 172 | } |
| 177 | 173 | ||
| 174 | Status BufferQueueConsumer::Disconnect() { | ||
| 175 | LOG_DEBUG(Service_Nvnflinger, "called"); | ||
| 176 | |||
| 177 | std::scoped_lock lock{core->mutex}; | ||
| 178 | |||
| 179 | if (core->consumer_listener == nullptr) { | ||
| 180 | LOG_ERROR(Service_Nvnflinger, "no consumer is connected"); | ||
| 181 | return Status::BadValue; | ||
| 182 | } | ||
| 183 | |||
| 184 | core->is_abandoned = true; | ||
| 185 | core->consumer_listener = nullptr; | ||
| 186 | core->queue.clear(); | ||
| 187 | core->FreeAllBuffersLocked(); | ||
| 188 | core->SignalDequeueCondition(); | ||
| 189 | |||
| 190 | return Status::NoError; | ||
| 191 | } | ||
| 192 | |||
| 178 | Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { | 193 | Status BufferQueueConsumer::GetReleasedBuffers(u64* out_slot_mask) { |
| 179 | if (out_slot_mask == nullptr) { | 194 | if (out_slot_mask == nullptr) { |
| 180 | LOG_ERROR(Service_Nvnflinger, "out_slot_mask may not be nullptr"); | 195 | LOG_ERROR(Service_Nvnflinger, "out_slot_mask may not be nullptr"); |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_consumer.h b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h index 50ed0bb5f..0a61e8dbd 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_consumer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_consumer.h | |||
| @@ -13,10 +13,6 @@ | |||
| 13 | #include "core/hle/service/nvnflinger/buffer_queue_defs.h" | 13 | #include "core/hle/service/nvnflinger/buffer_queue_defs.h" |
| 14 | #include "core/hle/service/nvnflinger/status.h" | 14 | #include "core/hle/service/nvnflinger/status.h" |
| 15 | 15 | ||
| 16 | namespace Service::Nvidia::NvCore { | ||
| 17 | class NvMap; | ||
| 18 | } // namespace Service::Nvidia::NvCore | ||
| 19 | |||
| 20 | namespace Service::android { | 16 | namespace Service::android { |
| 21 | 17 | ||
| 22 | class BufferItem; | 18 | class BufferItem; |
| @@ -25,19 +21,18 @@ class IConsumerListener; | |||
| 25 | 21 | ||
| 26 | class BufferQueueConsumer final { | 22 | class BufferQueueConsumer final { |
| 27 | public: | 23 | public: |
| 28 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_, | 24 | explicit BufferQueueConsumer(std::shared_ptr<BufferQueueCore> core_); |
| 29 | Service::Nvidia::NvCore::NvMap& nvmap_); | ||
| 30 | ~BufferQueueConsumer(); | 25 | ~BufferQueueConsumer(); |
| 31 | 26 | ||
| 32 | Status AcquireBuffer(BufferItem* out_buffer, std::chrono::nanoseconds expected_present); | 27 | Status AcquireBuffer(BufferItem* out_buffer, std::chrono::nanoseconds expected_present); |
| 33 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); | 28 | Status ReleaseBuffer(s32 slot, u64 frame_number, const Fence& release_fence); |
| 34 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); | 29 | Status Connect(std::shared_ptr<IConsumerListener> consumer_listener, bool controlled_by_app); |
| 30 | Status Disconnect(); | ||
| 35 | Status GetReleasedBuffers(u64* out_slot_mask); | 31 | Status GetReleasedBuffers(u64* out_slot_mask); |
| 36 | 32 | ||
| 37 | private: | 33 | private: |
| 38 | std::shared_ptr<BufferQueueCore> core; | 34 | std::shared_ptr<BufferQueueCore> core; |
| 39 | BufferQueueDefs::SlotsType& slots; | 35 | BufferQueueDefs::SlotsType& slots; |
| 40 | Service::Nvidia::NvCore::NvMap& nvmap; | ||
| 41 | }; | 36 | }; |
| 42 | 37 | ||
| 43 | } // namespace Service::android | 38 | } // namespace Service::android |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_core.cpp b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp index ed66f6f5b..4ed5e5978 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_core.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.cpp | |||
| @@ -14,24 +14,12 @@ BufferQueueCore::BufferQueueCore() = default; | |||
| 14 | 14 | ||
| 15 | BufferQueueCore::~BufferQueueCore() = default; | 15 | BufferQueueCore::~BufferQueueCore() = default; |
| 16 | 16 | ||
| 17 | void BufferQueueCore::NotifyShutdown() { | ||
| 18 | std::scoped_lock lock{mutex}; | ||
| 19 | |||
| 20 | is_shutting_down = true; | ||
| 21 | |||
| 22 | SignalDequeueCondition(); | ||
| 23 | } | ||
| 24 | |||
| 25 | void BufferQueueCore::SignalDequeueCondition() { | 17 | void BufferQueueCore::SignalDequeueCondition() { |
| 26 | dequeue_possible.store(true); | 18 | dequeue_possible.store(true); |
| 27 | dequeue_condition.notify_all(); | 19 | dequeue_condition.notify_all(); |
| 28 | } | 20 | } |
| 29 | 21 | ||
| 30 | bool BufferQueueCore::WaitForDequeueCondition(std::unique_lock<std::mutex>& lk) { | 22 | bool BufferQueueCore::WaitForDequeueCondition(std::unique_lock<std::mutex>& lk) { |
| 31 | if (is_shutting_down) { | ||
| 32 | return false; | ||
| 33 | } | ||
| 34 | |||
| 35 | dequeue_condition.wait(lk, [&] { return dequeue_possible.load(); }); | 23 | dequeue_condition.wait(lk, [&] { return dequeue_possible.load(); }); |
| 36 | dequeue_possible.store(false); | 24 | dequeue_possible.store(false); |
| 37 | 25 | ||
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_core.h b/src/core/hle/service/nvnflinger/buffer_queue_core.h index 9164f08a0..e513d183b 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_core.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_core.h | |||
| @@ -34,8 +34,6 @@ public: | |||
| 34 | BufferQueueCore(); | 34 | BufferQueueCore(); |
| 35 | ~BufferQueueCore(); | 35 | ~BufferQueueCore(); |
| 36 | 36 | ||
| 37 | void NotifyShutdown(); | ||
| 38 | |||
| 39 | private: | 37 | private: |
| 40 | void SignalDequeueCondition(); | 38 | void SignalDequeueCondition(); |
| 41 | bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk); | 39 | bool WaitForDequeueCondition(std::unique_lock<std::mutex>& lk); |
| @@ -74,7 +72,6 @@ private: | |||
| 74 | u32 transform_hint{}; | 72 | u32 transform_hint{}; |
| 75 | bool is_allocating{}; | 73 | bool is_allocating{}; |
| 76 | mutable std::condition_variable_any is_allocating_condition; | 74 | mutable std::condition_variable_any is_allocating_condition; |
| 77 | bool is_shutting_down{}; | ||
| 78 | }; | 75 | }; |
| 79 | 76 | ||
| 80 | } // namespace Service::android | 77 | } // namespace Service::android |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp index 6e7a49658..5d8762d25 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.cpp | |||
| @@ -13,7 +13,6 @@ | |||
| 13 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 14 | #include "core/hle/service/hle_ipc.h" | 14 | #include "core/hle/service/hle_ipc.h" |
| 15 | #include "core/hle/service/kernel_helpers.h" | 15 | #include "core/hle/service/kernel_helpers.h" |
| 16 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 17 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" | 16 | #include "core/hle/service/nvnflinger/buffer_queue_core.h" |
| 18 | #include "core/hle/service/nvnflinger/buffer_queue_producer.h" | 17 | #include "core/hle/service/nvnflinger/buffer_queue_producer.h" |
| 19 | #include "core/hle/service/nvnflinger/consumer_listener.h" | 18 | #include "core/hle/service/nvnflinger/consumer_listener.h" |
| @@ -533,8 +532,6 @@ Status BufferQueueProducer::QueueBuffer(s32 slot, const QueueBufferInput& input, | |||
| 533 | item.is_droppable = core->dequeue_buffer_cannot_block || async; | 532 | item.is_droppable = core->dequeue_buffer_cannot_block || async; |
| 534 | item.swap_interval = swap_interval; | 533 | item.swap_interval = swap_interval; |
| 535 | 534 | ||
| 536 | nvmap.DuplicateHandle(item.graphic_buffer->BufferId(), true); | ||
| 537 | |||
| 538 | sticky_transform = sticky_transform_; | 535 | sticky_transform = sticky_transform_; |
| 539 | 536 | ||
| 540 | if (core->queue.empty()) { | 537 | if (core->queue.empty()) { |
| @@ -744,19 +741,13 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { | |||
| 744 | return Status::NoError; | 741 | return Status::NoError; |
| 745 | } | 742 | } |
| 746 | 743 | ||
| 747 | // HACK: We are not Android. Remove handle for items in queue, and clear queue. | ||
| 748 | // Allows synchronous destruction of nvmap handles. | ||
| 749 | for (auto& item : core->queue) { | ||
| 750 | nvmap.FreeHandle(item.graphic_buffer->BufferId(), true); | ||
| 751 | } | ||
| 752 | core->queue.clear(); | ||
| 753 | |||
| 754 | switch (api) { | 744 | switch (api) { |
| 755 | case NativeWindowApi::Egl: | 745 | case NativeWindowApi::Egl: |
| 756 | case NativeWindowApi::Cpu: | 746 | case NativeWindowApi::Cpu: |
| 757 | case NativeWindowApi::Media: | 747 | case NativeWindowApi::Media: |
| 758 | case NativeWindowApi::Camera: | 748 | case NativeWindowApi::Camera: |
| 759 | if (core->connected_api == api) { | 749 | if (core->connected_api == api) { |
| 750 | core->queue.clear(); | ||
| 760 | core->FreeAllBuffersLocked(); | 751 | core->FreeAllBuffersLocked(); |
| 761 | core->connected_producer_listener = nullptr; | 752 | core->connected_producer_listener = nullptr; |
| 762 | core->connected_api = NativeWindowApi::NoConnectedApi; | 753 | core->connected_api = NativeWindowApi::NoConnectedApi; |
| @@ -785,7 +776,7 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) { | |||
| 785 | } | 776 | } |
| 786 | 777 | ||
| 787 | Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, | 778 | Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, |
| 788 | const std::shared_ptr<GraphicBuffer>& buffer) { | 779 | const std::shared_ptr<NvGraphicBuffer>& buffer) { |
| 789 | LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); | 780 | LOG_DEBUG(Service_Nvnflinger, "slot {}", slot); |
| 790 | 781 | ||
| 791 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { | 782 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { |
| @@ -796,7 +787,7 @@ Status BufferQueueProducer::SetPreallocatedBuffer(s32 slot, | |||
| 796 | 787 | ||
| 797 | slots[slot] = {}; | 788 | slots[slot] = {}; |
| 798 | slots[slot].fence = Fence::NoFence(); | 789 | slots[slot].fence = Fence::NoFence(); |
| 799 | slots[slot].graphic_buffer = buffer; | 790 | slots[slot].graphic_buffer = std::make_shared<GraphicBuffer>(nvmap, buffer); |
| 800 | slots[slot].frame_number = 0; | 791 | slots[slot].frame_number = 0; |
| 801 | 792 | ||
| 802 | // Most games preallocate a buffer and pass a valid buffer here. However, it is possible for | 793 | // Most games preallocate a buffer and pass a valid buffer here. However, it is possible for |
| @@ -839,7 +830,7 @@ void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u | |||
| 839 | } | 830 | } |
| 840 | case TransactionId::SetPreallocatedBuffer: { | 831 | case TransactionId::SetPreallocatedBuffer: { |
| 841 | const auto slot = parcel_in.Read<s32>(); | 832 | const auto slot = parcel_in.Read<s32>(); |
| 842 | const auto buffer = parcel_in.ReadObject<GraphicBuffer>(); | 833 | const auto buffer = parcel_in.ReadObject<NvGraphicBuffer>(); |
| 843 | 834 | ||
| 844 | status = SetPreallocatedBuffer(slot, buffer); | 835 | status = SetPreallocatedBuffer(slot, buffer); |
| 845 | break; | 836 | break; |
| @@ -867,7 +858,7 @@ void BufferQueueProducer::Transact(HLERequestContext& ctx, TransactionId code, u | |||
| 867 | 858 | ||
| 868 | status = RequestBuffer(slot, &buf); | 859 | status = RequestBuffer(slot, &buf); |
| 869 | 860 | ||
| 870 | parcel_out.WriteFlattenedObject(buf); | 861 | parcel_out.WriteFlattenedObject<NvGraphicBuffer>(buf.get()); |
| 871 | break; | 862 | break; |
| 872 | } | 863 | } |
| 873 | case TransactionId::QueueBuffer: { | 864 | case TransactionId::QueueBuffer: { |
diff --git a/src/core/hle/service/nvnflinger/buffer_queue_producer.h b/src/core/hle/service/nvnflinger/buffer_queue_producer.h index d4201c104..64c17d56c 100644 --- a/src/core/hle/service/nvnflinger/buffer_queue_producer.h +++ b/src/core/hle/service/nvnflinger/buffer_queue_producer.h | |||
| @@ -38,6 +38,7 @@ namespace Service::android { | |||
| 38 | 38 | ||
| 39 | class BufferQueueCore; | 39 | class BufferQueueCore; |
| 40 | class IProducerListener; | 40 | class IProducerListener; |
| 41 | struct NvGraphicBuffer; | ||
| 41 | 42 | ||
| 42 | class BufferQueueProducer final : public IBinder { | 43 | class BufferQueueProducer final : public IBinder { |
| 43 | public: | 44 | public: |
| @@ -65,7 +66,7 @@ public: | |||
| 65 | bool producer_controlled_by_app, QueueBufferOutput* output); | 66 | bool producer_controlled_by_app, QueueBufferOutput* output); |
| 66 | 67 | ||
| 67 | Status Disconnect(NativeWindowApi api); | 68 | Status Disconnect(NativeWindowApi api); |
| 68 | Status SetPreallocatedBuffer(s32 slot, const std::shared_ptr<GraphicBuffer>& buffer); | 69 | Status SetPreallocatedBuffer(s32 slot, const std::shared_ptr<NvGraphicBuffer>& buffer); |
| 69 | 70 | ||
| 70 | private: | 71 | private: |
| 71 | BufferQueueProducer(const BufferQueueProducer&) = delete; | 72 | BufferQueueProducer(const BufferQueueProducer&) = delete; |
diff --git a/src/core/hle/service/nvnflinger/buffer_slot.h b/src/core/hle/service/nvnflinger/buffer_slot.h index d8c9dec3b..d25bca049 100644 --- a/src/core/hle/service/nvnflinger/buffer_slot.h +++ b/src/core/hle/service/nvnflinger/buffer_slot.h | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | namespace Service::android { | 14 | namespace Service::android { |
| 15 | 15 | ||
| 16 | struct GraphicBuffer; | 16 | class GraphicBuffer; |
| 17 | 17 | ||
| 18 | enum class BufferState : u32 { | 18 | enum class BufferState : u32 { |
| 19 | Free = 0, | 19 | Free = 0, |
diff --git a/src/core/hle/service/nvnflinger/consumer_base.cpp b/src/core/hle/service/nvnflinger/consumer_base.cpp index 4dcda8dac..1059e72bf 100644 --- a/src/core/hle/service/nvnflinger/consumer_base.cpp +++ b/src/core/hle/service/nvnflinger/consumer_base.cpp | |||
| @@ -27,6 +27,26 @@ void ConsumerBase::Connect(bool controlled_by_app) { | |||
| 27 | consumer->Connect(shared_from_this(), controlled_by_app); | 27 | consumer->Connect(shared_from_this(), controlled_by_app); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | void ConsumerBase::Abandon() { | ||
| 31 | LOG_DEBUG(Service_Nvnflinger, "called"); | ||
| 32 | |||
| 33 | std::scoped_lock lock{mutex}; | ||
| 34 | |||
| 35 | if (!is_abandoned) { | ||
| 36 | this->AbandonLocked(); | ||
| 37 | is_abandoned = true; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | void ConsumerBase::AbandonLocked() { | ||
| 42 | for (int i = 0; i < BufferQueueDefs::NUM_BUFFER_SLOTS; i++) { | ||
| 43 | this->FreeBufferLocked(i); | ||
| 44 | } | ||
| 45 | // disconnect from the BufferQueue | ||
| 46 | consumer->Disconnect(); | ||
| 47 | consumer = nullptr; | ||
| 48 | } | ||
| 49 | |||
| 30 | void ConsumerBase::FreeBufferLocked(s32 slot_index) { | 50 | void ConsumerBase::FreeBufferLocked(s32 slot_index) { |
| 31 | LOG_DEBUG(Service_Nvnflinger, "slot_index={}", slot_index); | 51 | LOG_DEBUG(Service_Nvnflinger, "slot_index={}", slot_index); |
| 32 | 52 | ||
diff --git a/src/core/hle/service/nvnflinger/consumer_base.h b/src/core/hle/service/nvnflinger/consumer_base.h index 264829414..ea3e9e97a 100644 --- a/src/core/hle/service/nvnflinger/consumer_base.h +++ b/src/core/hle/service/nvnflinger/consumer_base.h | |||
| @@ -24,6 +24,7 @@ class BufferQueueConsumer; | |||
| 24 | class ConsumerBase : public IConsumerListener, public std::enable_shared_from_this<ConsumerBase> { | 24 | class ConsumerBase : public IConsumerListener, public std::enable_shared_from_this<ConsumerBase> { |
| 25 | public: | 25 | public: |
| 26 | void Connect(bool controlled_by_app); | 26 | void Connect(bool controlled_by_app); |
| 27 | void Abandon(); | ||
| 27 | 28 | ||
| 28 | protected: | 29 | protected: |
| 29 | explicit ConsumerBase(std::unique_ptr<BufferQueueConsumer> consumer_); | 30 | explicit ConsumerBase(std::unique_ptr<BufferQueueConsumer> consumer_); |
| @@ -34,6 +35,7 @@ protected: | |||
| 34 | void OnBuffersReleased() override; | 35 | void OnBuffersReleased() override; |
| 35 | void OnSidebandStreamChanged() override; | 36 | void OnSidebandStreamChanged() override; |
| 36 | 37 | ||
| 38 | void AbandonLocked(); | ||
| 37 | void FreeBufferLocked(s32 slot_index); | 39 | void FreeBufferLocked(s32 slot_index); |
| 38 | Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when); | 40 | Status AcquireBufferLocked(BufferItem* item, std::chrono::nanoseconds present_when); |
| 39 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer); | 41 | Status ReleaseBufferLocked(s32 slot, const std::shared_ptr<GraphicBuffer>& graphic_buffer); |
diff --git a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp index 6dc327b8b..d7db24f42 100644 --- a/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp +++ b/src/core/hle/service/nvnflinger/fb_share_buffer_manager.cpp | |||
| @@ -166,7 +166,7 @@ constexpr SharedMemoryPoolLayout SharedBufferPoolLayout = [] { | |||
| 166 | }(); | 166 | }(); |
| 167 | 167 | ||
| 168 | void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 handle) { | 168 | void MakeGraphicBuffer(android::BufferQueueProducer& producer, u32 slot, u32 handle) { |
| 169 | auto buffer = std::make_shared<android::GraphicBuffer>(); | 169 | auto buffer = std::make_shared<android::NvGraphicBuffer>(); |
| 170 | buffer->width = SharedBufferWidth; | 170 | buffer->width = SharedBufferWidth; |
| 171 | buffer->height = SharedBufferHeight; | 171 | buffer->height = SharedBufferHeight; |
| 172 | buffer->stride = SharedBufferBlockLinearStride; | 172 | buffer->stride = SharedBufferBlockLinearStride; |
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index bebb45eae..0745434c5 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp | |||
| @@ -47,7 +47,10 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) { | |||
| 47 | vsync_signal.Wait(); | 47 | vsync_signal.Wait(); |
| 48 | 48 | ||
| 49 | const auto lock_guard = Lock(); | 49 | const auto lock_guard = Lock(); |
| 50 | Compose(); | 50 | |
| 51 | if (!is_abandoned) { | ||
| 52 | Compose(); | ||
| 53 | } | ||
| 51 | } | 54 | } |
| 52 | } | 55 | } |
| 53 | 56 | ||
| @@ -98,7 +101,6 @@ Nvnflinger::~Nvnflinger() { | |||
| 98 | } | 101 | } |
| 99 | 102 | ||
| 100 | ShutdownLayers(); | 103 | ShutdownLayers(); |
| 101 | vsync_thread = {}; | ||
| 102 | 104 | ||
| 103 | if (nvdrv) { | 105 | if (nvdrv) { |
| 104 | nvdrv->Close(disp_fd); | 106 | nvdrv->Close(disp_fd); |
| @@ -106,12 +108,20 @@ Nvnflinger::~Nvnflinger() { | |||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | void Nvnflinger::ShutdownLayers() { | 110 | void Nvnflinger::ShutdownLayers() { |
| 109 | const auto lock_guard = Lock(); | 111 | // Abandon consumers. |
| 110 | for (auto& display : displays) { | 112 | { |
| 111 | for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { | 113 | const auto lock_guard = Lock(); |
| 112 | display.GetLayer(layer).Core().NotifyShutdown(); | 114 | for (auto& display : displays) { |
| 115 | for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { | ||
| 116 | display.GetLayer(layer).GetConsumer().Abandon(); | ||
| 117 | } | ||
| 113 | } | 118 | } |
| 119 | |||
| 120 | is_abandoned = true; | ||
| 114 | } | 121 | } |
| 122 | |||
| 123 | // Join the vsync thread, if it exists. | ||
| 124 | vsync_thread = {}; | ||
| 115 | } | 125 | } |
| 116 | 126 | ||
| 117 | void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { | 127 | void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { |
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index 959d8b46b..f5d73acdb 100644 --- a/src/core/hle/service/nvnflinger/nvnflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h | |||
| @@ -140,6 +140,8 @@ private: | |||
| 140 | 140 | ||
| 141 | s32 swap_interval = 1; | 141 | s32 swap_interval = 1; |
| 142 | 142 | ||
| 143 | bool is_abandoned = false; | ||
| 144 | |||
| 143 | /// Event that handles screen composition. | 145 | /// Event that handles screen composition. |
| 144 | std::shared_ptr<Core::Timing::EventType> multi_composition_event; | 146 | std::shared_ptr<Core::Timing::EventType> multi_composition_event; |
| 145 | std::shared_ptr<Core::Timing::EventType> single_composition_event; | 147 | std::shared_ptr<Core::Timing::EventType> single_composition_event; |
diff --git a/src/core/hle/service/nvnflinger/status.h b/src/core/hle/service/nvnflinger/status.h index 7af166c40..3fa0fe15b 100644 --- a/src/core/hle/service/nvnflinger/status.h +++ b/src/core/hle/service/nvnflinger/status.h | |||
| @@ -19,7 +19,7 @@ enum class Status : s32 { | |||
| 19 | Busy = -16, | 19 | Busy = -16, |
| 20 | NoInit = -19, | 20 | NoInit = -19, |
| 21 | BadValue = -22, | 21 | BadValue = -22, |
| 22 | InvalidOperation = -37, | 22 | InvalidOperation = -38, |
| 23 | BufferNeedsReallocation = 1, | 23 | BufferNeedsReallocation = 1, |
| 24 | ReleaseAllBuffers = 2, | 24 | ReleaseAllBuffers = 2, |
| 25 | }; | 25 | }; |
diff --git a/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp b/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp new file mode 100644 index 000000000..ce70946ec --- /dev/null +++ b/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "core/hle/service/nvdrv/core/nvmap.h" | ||
| 5 | #include "core/hle/service/nvnflinger/ui/graphic_buffer.h" | ||
| 6 | |||
| 7 | namespace Service::android { | ||
| 8 | |||
| 9 | static NvGraphicBuffer GetBuffer(std::shared_ptr<NvGraphicBuffer>& buffer) { | ||
| 10 | if (buffer) { | ||
| 11 | return *buffer; | ||
| 12 | } else { | ||
| 13 | return {}; | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | GraphicBuffer::GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) | ||
| 18 | : NvGraphicBuffer(width_, height_, format_, usage_), m_nvmap(nullptr) {} | ||
| 19 | |||
| 20 | GraphicBuffer::GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap, | ||
| 21 | std::shared_ptr<NvGraphicBuffer> buffer) | ||
| 22 | : NvGraphicBuffer(GetBuffer(buffer)), m_nvmap(std::addressof(nvmap)) { | ||
| 23 | if (this->BufferId() > 0) { | ||
| 24 | m_nvmap->DuplicateHandle(this->BufferId(), true); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | GraphicBuffer::~GraphicBuffer() { | ||
| 29 | if (m_nvmap != nullptr && this->BufferId() > 0) { | ||
| 30 | m_nvmap->FreeHandle(this->BufferId(), true); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | } // namespace Service::android | ||
diff --git a/src/core/hle/service/nvnflinger/ui/graphic_buffer.h b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h index 3eac5cedd..da430aa75 100644 --- a/src/core/hle/service/nvnflinger/ui/graphic_buffer.h +++ b/src/core/hle/service/nvnflinger/ui/graphic_buffer.h | |||
| @@ -6,16 +6,22 @@ | |||
| 6 | 6 | ||
| 7 | #pragma once | 7 | #pragma once |
| 8 | 8 | ||
| 9 | #include <memory> | ||
| 10 | |||
| 9 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "core/hle/service/nvnflinger/pixel_format.h" | 13 | #include "core/hle/service/nvnflinger/pixel_format.h" |
| 12 | 14 | ||
| 15 | namespace Service::Nvidia::NvCore { | ||
| 16 | class NvMap; | ||
| 17 | } // namespace Service::Nvidia::NvCore | ||
| 18 | |||
| 13 | namespace Service::android { | 19 | namespace Service::android { |
| 14 | 20 | ||
| 15 | struct GraphicBuffer final { | 21 | struct NvGraphicBuffer { |
| 16 | constexpr GraphicBuffer() = default; | 22 | constexpr NvGraphicBuffer() = default; |
| 17 | 23 | ||
| 18 | constexpr GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) | 24 | constexpr NvGraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_) |
| 19 | : width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_}, | 25 | : width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_}, |
| 20 | usage{static_cast<s32>(usage_)} {} | 26 | usage{static_cast<s32>(usage_)} {} |
| 21 | 27 | ||
| @@ -93,6 +99,17 @@ struct GraphicBuffer final { | |||
| 93 | u32 offset{}; | 99 | u32 offset{}; |
| 94 | INSERT_PADDING_WORDS(60); | 100 | INSERT_PADDING_WORDS(60); |
| 95 | }; | 101 | }; |
| 96 | static_assert(sizeof(GraphicBuffer) == 0x16C, "GraphicBuffer has wrong size"); | 102 | static_assert(sizeof(NvGraphicBuffer) == 0x16C, "NvGraphicBuffer has wrong size"); |
| 103 | |||
| 104 | class GraphicBuffer final : public NvGraphicBuffer { | ||
| 105 | public: | ||
| 106 | explicit GraphicBuffer(u32 width, u32 height, PixelFormat format, u32 usage); | ||
| 107 | explicit GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap, | ||
| 108 | std::shared_ptr<NvGraphicBuffer> buffer); | ||
| 109 | ~GraphicBuffer(); | ||
| 110 | |||
| 111 | private: | ||
| 112 | Service::Nvidia::NvCore::NvMap* m_nvmap{}; | ||
| 113 | }; | ||
| 97 | 114 | ||
| 98 | } // namespace Service::android | 115 | } // namespace Service::android |
diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index f0b5eff8a..d30f49877 100644 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp | |||
| @@ -35,7 +35,7 @@ static BufferQueue CreateBufferQueue(KernelHelpers::ServiceContext& service_cont | |||
| 35 | return { | 35 | return { |
| 36 | buffer_queue_core, | 36 | buffer_queue_core, |
| 37 | std::make_unique<android::BufferQueueProducer>(service_context, buffer_queue_core, nvmap), | 37 | std::make_unique<android::BufferQueueProducer>(service_context, buffer_queue_core, nvmap), |
| 38 | std::make_unique<android::BufferQueueConsumer>(buffer_queue_core, nvmap)}; | 38 | std::make_unique<android::BufferQueueConsumer>(buffer_queue_core)}; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | Display::Display(u64 id, std::string name_, | 41 | Display::Display(u64 id, std::string name_, |
diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index 83b763447..19db17c6d 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt | |||
| @@ -231,6 +231,7 @@ add_library(shader_recompiler STATIC | |||
| 231 | ir_opt/rescaling_pass.cpp | 231 | ir_opt/rescaling_pass.cpp |
| 232 | ir_opt/ssa_rewrite_pass.cpp | 232 | ir_opt/ssa_rewrite_pass.cpp |
| 233 | ir_opt/texture_pass.cpp | 233 | ir_opt/texture_pass.cpp |
| 234 | ir_opt/vendor_workaround_pass.cpp | ||
| 234 | ir_opt/verification_pass.cpp | 235 | ir_opt/verification_pass.cpp |
| 235 | object_pool.h | 236 | object_pool.h |
| 236 | precompiled_headers.h | 237 | precompiled_headers.h |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp index d0e308124..64e7bad75 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | |||
| @@ -559,12 +559,12 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 559 | const IR::Value& offset, const IR::Value& lod_clamp) { | 559 | const IR::Value& offset, const IR::Value& lod_clamp) { |
| 560 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 560 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 561 | ScopedRegister dpdx, dpdy, coords; | 561 | ScopedRegister dpdx, dpdy, coords; |
| 562 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; | 562 | const bool multi_component{info.num_derivatives > 1 || info.has_lod_clamp}; |
| 563 | if (multi_component) { | 563 | if (multi_component) { |
| 564 | // Allocate this early to avoid aliasing other registers | 564 | // Allocate this early to avoid aliasing other registers |
| 565 | dpdx = ScopedRegister{ctx.reg_alloc}; | 565 | dpdx = ScopedRegister{ctx.reg_alloc}; |
| 566 | dpdy = ScopedRegister{ctx.reg_alloc}; | 566 | dpdy = ScopedRegister{ctx.reg_alloc}; |
| 567 | if (info.num_derivates >= 3) { | 567 | if (info.num_derivatives >= 3) { |
| 568 | coords = ScopedRegister{ctx.reg_alloc}; | 568 | coords = ScopedRegister{ctx.reg_alloc}; |
| 569 | } | 569 | } |
| 570 | } | 570 | } |
| @@ -584,7 +584,7 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 584 | dpdx.reg, derivatives_vec, dpdx.reg, derivatives_vec, dpdy.reg, derivatives_vec, | 584 | dpdx.reg, derivatives_vec, dpdx.reg, derivatives_vec, dpdy.reg, derivatives_vec, |
| 585 | dpdy.reg, derivatives_vec); | 585 | dpdy.reg, derivatives_vec); |
| 586 | Register final_coord; | 586 | Register final_coord; |
| 587 | if (info.num_derivates >= 3) { | 587 | if (info.num_derivatives >= 3) { |
| 588 | ctx.Add("MOV.F {}.z,{}.x;" | 588 | ctx.Add("MOV.F {}.z,{}.x;" |
| 589 | "MOV.F {}.z,{}.y;", | 589 | "MOV.F {}.z,{}.y;", |
| 590 | dpdx.reg, coord_vec, dpdy.reg, coord_vec); | 590 | dpdx.reg, coord_vec, dpdy.reg, coord_vec); |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp index d9872ecc2..6e940bd5a 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |||
| @@ -548,15 +548,15 @@ void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 548 | if (sparse_inst) { | 548 | if (sparse_inst) { |
| 549 | throw NotImplementedException("EmitImageGradient Sparse"); | 549 | throw NotImplementedException("EmitImageGradient Sparse"); |
| 550 | } | 550 | } |
| 551 | if (!offset.IsEmpty() && info.num_derivates <= 2) { | 551 | if (!offset.IsEmpty() && info.num_derivatives <= 2) { |
| 552 | throw NotImplementedException("EmitImageGradient offset"); | 552 | throw NotImplementedException("EmitImageGradient offset"); |
| 553 | } | 553 | } |
| 554 | const auto texture{Texture(ctx, info, index)}; | 554 | const auto texture{Texture(ctx, info, index)}; |
| 555 | const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)}; | 555 | const auto texel{ctx.var_alloc.Define(inst, GlslVarType::F32x4)}; |
| 556 | const bool multi_component{info.num_derivates > 1 || info.has_lod_clamp}; | 556 | const bool multi_component{info.num_derivatives > 1 || info.has_lod_clamp}; |
| 557 | const auto derivatives_vec{ctx.var_alloc.Consume(derivatives)}; | 557 | const auto derivatives_vec{ctx.var_alloc.Consume(derivatives)}; |
| 558 | if (multi_component) { | 558 | if (multi_component) { |
| 559 | if (info.num_derivates >= 3) { | 559 | if (info.num_derivatives >= 3) { |
| 560 | const auto offset_vec{ctx.var_alloc.Consume(offset)}; | 560 | const auto offset_vec{ctx.var_alloc.Consume(offset)}; |
| 561 | ctx.Add("{}=textureGrad({},{},vec3({}.xz, {}.x),vec3({}.yw, {}.y));", texel, texture, | 561 | ctx.Add("{}=textureGrad({},{},vec3({}.xz, {}.x),vec3({}.yw, {}.y));", texel, texture, |
| 562 | coords, derivatives_vec, offset_vec, derivatives_vec, offset_vec); | 562 | coords, derivatives_vec, offset_vec, derivatives_vec, offset_vec); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.cpp b/src/shader_recompiler/backend/spirv/emit_spirv.cpp index 34592a01f..0031fa5fb 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv.cpp | |||
| @@ -407,7 +407,7 @@ void SetupCapabilities(const Profile& profile, const Info& info, EmitContext& ct | |||
| 407 | } | 407 | } |
| 408 | ctx.AddCapability(spv::Capability::DemoteToHelperInvocation); | 408 | ctx.AddCapability(spv::Capability::DemoteToHelperInvocation); |
| 409 | } | 409 | } |
| 410 | if (info.stores[IR::Attribute::ViewportIndex]) { | 410 | if (info.stores[IR::Attribute::ViewportIndex] && profile.support_multi_viewport) { |
| 411 | ctx.AddCapability(spv::Capability::MultiViewport); | 411 | ctx.AddCapability(spv::Capability::MultiViewport); |
| 412 | } | 412 | } |
| 413 | if (info.stores[IR::Attribute::ViewportMask] && profile.support_viewport_mask) { | 413 | if (info.stores[IR::Attribute::ViewportMask] && profile.support_viewport_mask) { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 1d77426e0..e5a78a914 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -84,6 +84,10 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 84 | } | 84 | } |
| 85 | return std::nullopt; | 85 | return std::nullopt; |
| 86 | case IR::Attribute::ViewportIndex: | 86 | case IR::Attribute::ViewportIndex: |
| 87 | if (!ctx.profile.support_multi_viewport) { | ||
| 88 | LOG_WARNING(Shader, "Ignoring viewport index store on non-supporting driver"); | ||
| 89 | return std::nullopt; | ||
| 90 | } | ||
| 87 | if (ctx.profile.support_viewport_index_layer_non_geometry || | 91 | if (ctx.profile.support_viewport_index_layer_non_geometry || |
| 88 | ctx.stage == Shader::Stage::Geometry) { | 92 | ctx.stage == Shader::Stage::Geometry) { |
| 89 | return OutAttr{ctx.viewport_index, ctx.U32[1]}; | 93 | return OutAttr{ctx.viewport_index, ctx.U32[1]}; |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index 8decdf399..22ceca19c 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |||
| @@ -67,22 +67,22 @@ public: | |||
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivates, u32 num_derivates, | 70 | explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives, |
| 71 | Id offset, Id lod_clamp) { | 71 | u32 num_derivatives, Id offset, Id lod_clamp) { |
| 72 | if (!Sirit::ValidId(derivates)) { | 72 | if (!Sirit::ValidId(derivatives)) { |
| 73 | throw LogicError("Derivates must be present"); | 73 | throw LogicError("Derivatives must be present"); |
| 74 | } | 74 | } |
| 75 | boost::container::static_vector<Id, 3> deriv_x_accum; | 75 | boost::container::static_vector<Id, 3> deriv_x_accum; |
| 76 | boost::container::static_vector<Id, 3> deriv_y_accum; | 76 | boost::container::static_vector<Id, 3> deriv_y_accum; |
| 77 | for (u32 i = 0; i < num_derivates; ++i) { | 77 | for (u32 i = 0; i < num_derivatives; ++i) { |
| 78 | deriv_x_accum.push_back(ctx.OpCompositeExtract(ctx.F32[1], derivates, i * 2)); | 78 | deriv_x_accum.push_back(ctx.OpCompositeExtract(ctx.F32[1], derivatives, i * 2)); |
| 79 | deriv_y_accum.push_back(ctx.OpCompositeExtract(ctx.F32[1], derivates, i * 2 + 1)); | 79 | deriv_y_accum.push_back(ctx.OpCompositeExtract(ctx.F32[1], derivatives, i * 2 + 1)); |
| 80 | } | 80 | } |
| 81 | const Id derivates_X{ctx.OpCompositeConstruct( | 81 | const Id derivatives_X{ctx.OpCompositeConstruct( |
| 82 | ctx.F32[num_derivates], std::span{deriv_x_accum.data(), deriv_x_accum.size()})}; | 82 | ctx.F32[num_derivatives], std::span{deriv_x_accum.data(), deriv_x_accum.size()})}; |
| 83 | const Id derivates_Y{ctx.OpCompositeConstruct( | 83 | const Id derivatives_Y{ctx.OpCompositeConstruct( |
| 84 | ctx.F32[num_derivates], std::span{deriv_y_accum.data(), deriv_y_accum.size()})}; | 84 | ctx.F32[num_derivatives], std::span{deriv_y_accum.data(), deriv_y_accum.size()})}; |
| 85 | Add(spv::ImageOperandsMask::Grad, derivates_X, derivates_Y); | 85 | Add(spv::ImageOperandsMask::Grad, derivatives_X, derivatives_Y); |
| 86 | if (Sirit::ValidId(offset)) { | 86 | if (Sirit::ValidId(offset)) { |
| 87 | Add(spv::ImageOperandsMask::Offset, offset); | 87 | Add(spv::ImageOperandsMask::Offset, offset); |
| 88 | } | 88 | } |
| @@ -91,26 +91,26 @@ public: | |||
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivates_1, Id derivates_2, | 94 | explicit ImageOperands(EmitContext& ctx, bool has_lod_clamp, Id derivatives_1, Id derivatives_2, |
| 95 | Id offset, Id lod_clamp) { | 95 | Id offset, Id lod_clamp) { |
| 96 | if (!Sirit::ValidId(derivates_1) || !Sirit::ValidId(derivates_2)) { | 96 | if (!Sirit::ValidId(derivatives_1) || !Sirit::ValidId(derivatives_2)) { |
| 97 | throw LogicError("Derivates must be present"); | 97 | throw LogicError("Derivatives must be present"); |
| 98 | } | 98 | } |
| 99 | boost::container::static_vector<Id, 3> deriv_1_accum{ | 99 | boost::container::static_vector<Id, 3> deriv_1_accum{ |
| 100 | ctx.OpCompositeExtract(ctx.F32[1], derivates_1, 0), | 100 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_1, 0), |
| 101 | ctx.OpCompositeExtract(ctx.F32[1], derivates_1, 2), | 101 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_1, 2), |
| 102 | ctx.OpCompositeExtract(ctx.F32[1], derivates_2, 0), | 102 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_2, 0), |
| 103 | }; | 103 | }; |
| 104 | boost::container::static_vector<Id, 3> deriv_2_accum{ | 104 | boost::container::static_vector<Id, 3> deriv_2_accum{ |
| 105 | ctx.OpCompositeExtract(ctx.F32[1], derivates_1, 1), | 105 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_1, 1), |
| 106 | ctx.OpCompositeExtract(ctx.F32[1], derivates_1, 3), | 106 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_1, 3), |
| 107 | ctx.OpCompositeExtract(ctx.F32[1], derivates_2, 1), | 107 | ctx.OpCompositeExtract(ctx.F32[1], derivatives_2, 1), |
| 108 | }; | 108 | }; |
| 109 | const Id derivates_id1{ctx.OpCompositeConstruct( | 109 | const Id derivatives_id1{ctx.OpCompositeConstruct( |
| 110 | ctx.F32[3], std::span{deriv_1_accum.data(), deriv_1_accum.size()})}; | 110 | ctx.F32[3], std::span{deriv_1_accum.data(), deriv_1_accum.size()})}; |
| 111 | const Id derivates_id2{ctx.OpCompositeConstruct( | 111 | const Id derivatives_id2{ctx.OpCompositeConstruct( |
| 112 | ctx.F32[3], std::span{deriv_2_accum.data(), deriv_2_accum.size()})}; | 112 | ctx.F32[3], std::span{deriv_2_accum.data(), deriv_2_accum.size()})}; |
| 113 | Add(spv::ImageOperandsMask::Grad, derivates_id1, derivates_id2); | 113 | Add(spv::ImageOperandsMask::Grad, derivatives_id1, derivatives_id2); |
| 114 | if (Sirit::ValidId(offset)) { | 114 | if (Sirit::ValidId(offset)) { |
| 115 | Add(spv::ImageOperandsMask::Offset, offset); | 115 | Add(spv::ImageOperandsMask::Offset, offset); |
| 116 | } | 116 | } |
| @@ -548,12 +548,12 @@ Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, I | |||
| 548 | } | 548 | } |
| 549 | 549 | ||
| 550 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, | 550 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
| 551 | Id derivates, Id offset, Id lod_clamp) { | 551 | Id derivatives, Id offset, Id lod_clamp) { |
| 552 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 552 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 553 | const auto operands = | 553 | const auto operands = |
| 554 | info.num_derivates == 3 | 554 | info.num_derivatives == 3 |
| 555 | ? ImageOperands(ctx, info.has_lod_clamp != 0, derivates, offset, {}, lod_clamp) | 555 | ? ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, offset, {}, lod_clamp) |
| 556 | : ImageOperands(ctx, info.has_lod_clamp != 0, derivates, info.num_derivates, offset, | 556 | : ImageOperands(ctx, info.has_lod_clamp != 0, derivatives, info.num_derivatives, offset, |
| 557 | lod_clamp); | 557 | lod_clamp); |
| 558 | return Emit(&EmitContext::OpImageSparseSampleExplicitLod, | 558 | return Emit(&EmitContext::OpImageSparseSampleExplicitLod, |
| 559 | &EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4], | 559 | &EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4], |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index a440b557d..7d34575c8 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h | |||
| @@ -543,7 +543,7 @@ Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& i | |||
| 543 | const IR::Value& skip_mips); | 543 | const IR::Value& skip_mips); |
| 544 | Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); | 544 | Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); |
| 545 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, | 545 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
| 546 | Id derivates, Id offset, Id lod_clamp); | 546 | Id derivatives, Id offset, Id lod_clamp); |
| 547 | Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); | 547 | Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); |
| 548 | void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color); | 548 | void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color); |
| 549 | Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index); | 549 | Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index); |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index b7caa4246..49171c470 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -1864,11 +1864,11 @@ Value IREmitter::ImageQueryLod(const Value& handle, const Value& coords, Texture | |||
| 1864 | return Inst(op, Flags{info}, handle, coords); | 1864 | return Inst(op, Flags{info}, handle, coords); |
| 1865 | } | 1865 | } |
| 1866 | 1866 | ||
| 1867 | Value IREmitter::ImageGradient(const Value& handle, const Value& coords, const Value& derivates, | 1867 | Value IREmitter::ImageGradient(const Value& handle, const Value& coords, const Value& derivatives, |
| 1868 | const Value& offset, const F32& lod_clamp, TextureInstInfo info) { | 1868 | const Value& offset, const F32& lod_clamp, TextureInstInfo info) { |
| 1869 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageGradient | 1869 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageGradient |
| 1870 | : Opcode::BindlessImageGradient}; | 1870 | : Opcode::BindlessImageGradient}; |
| 1871 | return Inst(op, Flags{info}, handle, coords, derivates, offset, lod_clamp); | 1871 | return Inst(op, Flags{info}, handle, coords, derivatives, offset, lod_clamp); |
| 1872 | } | 1872 | } |
| 1873 | 1873 | ||
| 1874 | Value IREmitter::ImageRead(const Value& handle, const Value& coords, TextureInstInfo info) { | 1874 | Value IREmitter::ImageRead(const Value& handle, const Value& coords, TextureInstInfo info) { |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index f3c81dbe1..6c30897f4 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -335,7 +335,7 @@ public: | |||
| 335 | [[nodiscard]] Value ImageFetch(const Value& handle, const Value& coords, const Value& offset, | 335 | [[nodiscard]] Value ImageFetch(const Value& handle, const Value& coords, const Value& offset, |
| 336 | const U32& lod, const U32& multisampling, TextureInstInfo info); | 336 | const U32& lod, const U32& multisampling, TextureInstInfo info); |
| 337 | [[nodiscard]] Value ImageGradient(const Value& handle, const Value& coords, | 337 | [[nodiscard]] Value ImageGradient(const Value& handle, const Value& coords, |
| 338 | const Value& derivates, const Value& offset, | 338 | const Value& derivatives, const Value& offset, |
| 339 | const F32& lod_clamp, TextureInstInfo info); | 339 | const F32& lod_clamp, TextureInstInfo info); |
| 340 | [[nodiscard]] Value ImageRead(const Value& handle, const Value& coords, TextureInstInfo info); | 340 | [[nodiscard]] Value ImageRead(const Value& handle, const Value& coords, TextureInstInfo info); |
| 341 | void ImageWrite(const Value& handle, const Value& coords, const Value& color, | 341 | void ImageWrite(const Value& handle, const Value& coords, const Value& color, |
diff --git a/src/shader_recompiler/frontend/ir/modifiers.h b/src/shader_recompiler/frontend/ir/modifiers.h index 1e9e8c8f5..c20c2401f 100644 --- a/src/shader_recompiler/frontend/ir/modifiers.h +++ b/src/shader_recompiler/frontend/ir/modifiers.h | |||
| @@ -40,7 +40,7 @@ union TextureInstInfo { | |||
| 40 | BitField<21, 1, u32> has_lod_clamp; | 40 | BitField<21, 1, u32> has_lod_clamp; |
| 41 | BitField<22, 1, u32> relaxed_precision; | 41 | BitField<22, 1, u32> relaxed_precision; |
| 42 | BitField<23, 2, u32> gather_component; | 42 | BitField<23, 2, u32> gather_component; |
| 43 | BitField<25, 2, u32> num_derivates; | 43 | BitField<25, 2, u32> num_derivatives; |
| 44 | BitField<27, 3, ImageFormat> image_format; | 44 | BitField<27, 3, ImageFormat> image_format; |
| 45 | BitField<30, 1, u32> ndv_is_active; | 45 | BitField<30, 1, u32> ndv_is_active; |
| 46 | }; | 46 | }; |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp index dd34507bc..4ce3dd0cd 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp | |||
| @@ -59,7 +59,7 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 59 | BitField<51, 3, IR::Pred> sparse_pred; | 59 | BitField<51, 3, IR::Pred> sparse_pred; |
| 60 | BitField<0, 8, IR::Reg> dest_reg; | 60 | BitField<0, 8, IR::Reg> dest_reg; |
| 61 | BitField<8, 8, IR::Reg> coord_reg; | 61 | BitField<8, 8, IR::Reg> coord_reg; |
| 62 | BitField<20, 8, IR::Reg> derivate_reg; | 62 | BitField<20, 8, IR::Reg> derivative_reg; |
| 63 | BitField<28, 3, TextureType> type; | 63 | BitField<28, 3, TextureType> type; |
| 64 | BitField<31, 4, u64> mask; | 64 | BitField<31, 4, u64> mask; |
| 65 | BitField<36, 13, u64> cbuf_offset; | 65 | BitField<36, 13, u64> cbuf_offset; |
| @@ -71,7 +71,7 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | IR::Value coords; | 73 | IR::Value coords; |
| 74 | u32 num_derivates{}; | 74 | u32 num_derivatives{}; |
| 75 | IR::Reg base_reg{txd.coord_reg}; | 75 | IR::Reg base_reg{txd.coord_reg}; |
| 76 | IR::Reg last_reg; | 76 | IR::Reg last_reg; |
| 77 | IR::Value handle; | 77 | IR::Value handle; |
| @@ -90,42 +90,42 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 90 | switch (txd.type) { | 90 | switch (txd.type) { |
| 91 | case TextureType::_1D: { | 91 | case TextureType::_1D: { |
| 92 | coords = v.F(base_reg); | 92 | coords = v.F(base_reg); |
| 93 | num_derivates = 1; | 93 | num_derivatives = 1; |
| 94 | last_reg = base_reg + 1; | 94 | last_reg = base_reg + 1; |
| 95 | break; | 95 | break; |
| 96 | } | 96 | } |
| 97 | case TextureType::ARRAY_1D: { | 97 | case TextureType::ARRAY_1D: { |
| 98 | last_reg = base_reg + 1; | 98 | last_reg = base_reg + 1; |
| 99 | coords = v.ir.CompositeConstruct(v.F(base_reg), read_array()); | 99 | coords = v.ir.CompositeConstruct(v.F(base_reg), read_array()); |
| 100 | num_derivates = 1; | 100 | num_derivatives = 1; |
| 101 | break; | 101 | break; |
| 102 | } | 102 | } |
| 103 | case TextureType::_2D: { | 103 | case TextureType::_2D: { |
| 104 | last_reg = base_reg + 2; | 104 | last_reg = base_reg + 2; |
| 105 | coords = v.ir.CompositeConstruct(v.F(base_reg), v.F(base_reg + 1)); | 105 | coords = v.ir.CompositeConstruct(v.F(base_reg), v.F(base_reg + 1)); |
| 106 | num_derivates = 2; | 106 | num_derivatives = 2; |
| 107 | break; | 107 | break; |
| 108 | } | 108 | } |
| 109 | case TextureType::ARRAY_2D: { | 109 | case TextureType::ARRAY_2D: { |
| 110 | last_reg = base_reg + 2; | 110 | last_reg = base_reg + 2; |
| 111 | coords = v.ir.CompositeConstruct(v.F(base_reg), v.F(base_reg + 1), read_array()); | 111 | coords = v.ir.CompositeConstruct(v.F(base_reg), v.F(base_reg + 1), read_array()); |
| 112 | num_derivates = 2; | 112 | num_derivatives = 2; |
| 113 | break; | 113 | break; |
| 114 | } | 114 | } |
| 115 | default: | 115 | default: |
| 116 | throw NotImplementedException("Invalid texture type"); | 116 | throw NotImplementedException("Invalid texture type"); |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | const IR::Reg derivate_reg{txd.derivate_reg}; | 119 | const IR::Reg derivative_reg{txd.derivative_reg}; |
| 120 | IR::Value derivates; | 120 | IR::Value derivatives; |
| 121 | switch (num_derivates) { | 121 | switch (num_derivatives) { |
| 122 | case 1: { | 122 | case 1: { |
| 123 | derivates = v.ir.CompositeConstruct(v.F(derivate_reg), v.F(derivate_reg + 1)); | 123 | derivatives = v.ir.CompositeConstruct(v.F(derivative_reg), v.F(derivative_reg + 1)); |
| 124 | break; | 124 | break; |
| 125 | } | 125 | } |
| 126 | case 2: { | 126 | case 2: { |
| 127 | derivates = v.ir.CompositeConstruct(v.F(derivate_reg), v.F(derivate_reg + 1), | 127 | derivatives = v.ir.CompositeConstruct(v.F(derivative_reg), v.F(derivative_reg + 1), |
| 128 | v.F(derivate_reg + 2), v.F(derivate_reg + 3)); | 128 | v.F(derivative_reg + 2), v.F(derivative_reg + 3)); |
| 129 | break; | 129 | break; |
| 130 | } | 130 | } |
| 131 | default: | 131 | default: |
| @@ -150,9 +150,10 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) { | |||
| 150 | 150 | ||
| 151 | IR::TextureInstInfo info{}; | 151 | IR::TextureInstInfo info{}; |
| 152 | info.type.Assign(GetType(txd.type)); | 152 | info.type.Assign(GetType(txd.type)); |
| 153 | info.num_derivates.Assign(num_derivates); | 153 | info.num_derivatives.Assign(num_derivatives); |
| 154 | info.has_lod_clamp.Assign(has_lod_clamp ? 1 : 0); | 154 | info.has_lod_clamp.Assign(has_lod_clamp ? 1 : 0); |
| 155 | const IR::Value sample{v.ir.ImageGradient(handle, coords, derivates, offset, lod_clamp, info)}; | 155 | const IR::Value sample{ |
| 156 | v.ir.ImageGradient(handle, coords, derivatives, offset, lod_clamp, info)}; | ||
| 156 | 157 | ||
| 157 | IR::Reg dest_reg{txd.dest_reg}; | 158 | IR::Reg dest_reg{txd.dest_reg}; |
| 158 | for (size_t element = 0; element < 4; ++element) { | 159 | for (size_t element = 0; element < 4; ++element) { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index 928b35561..8fac6bad3 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -310,6 +310,7 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo | |||
| 310 | } | 310 | } |
| 311 | Optimization::CollectShaderInfoPass(env, program); | 311 | Optimization::CollectShaderInfoPass(env, program); |
| 312 | Optimization::LayerPass(program, host_info); | 312 | Optimization::LayerPass(program, host_info); |
| 313 | Optimization::VendorWorkaroundPass(program); | ||
| 313 | 314 | ||
| 314 | CollectInterpolationInfo(env, program); | 315 | CollectInterpolationInfo(env, program); |
| 315 | AddNVNStorageBuffers(program); | 316 | AddNVNStorageBuffers(program); |
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index f46e55122..ec12c843a 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -428,7 +428,7 @@ void FoldFPAdd32(IR::Inst& inst) { | |||
| 428 | } | 428 | } |
| 429 | } | 429 | } |
| 430 | 430 | ||
| 431 | bool FoldDerivateYFromCorrection(IR::Inst& inst) { | 431 | bool FoldDerivativeYFromCorrection(IR::Inst& inst) { |
| 432 | const IR::Value lhs_value{inst.Arg(0)}; | 432 | const IR::Value lhs_value{inst.Arg(0)}; |
| 433 | const IR::Value rhs_value{inst.Arg(1)}; | 433 | const IR::Value rhs_value{inst.Arg(1)}; |
| 434 | IR::Inst* const lhs_op{lhs_value.InstRecursive()}; | 434 | IR::Inst* const lhs_op{lhs_value.InstRecursive()}; |
| @@ -464,7 +464,7 @@ void FoldFPMul32(IR::Inst& inst) { | |||
| 464 | if (lhs_value.IsImmediate() || rhs_value.IsImmediate()) { | 464 | if (lhs_value.IsImmediate() || rhs_value.IsImmediate()) { |
| 465 | return; | 465 | return; |
| 466 | } | 466 | } |
| 467 | if (FoldDerivateYFromCorrection(inst)) { | 467 | if (FoldDerivativeYFromCorrection(inst)) { |
| 468 | return; | 468 | return; |
| 469 | } | 469 | } |
| 470 | IR::Inst* const lhs_op{lhs_value.InstRecursive()}; | 470 | IR::Inst* const lhs_op{lhs_value.InstRecursive()}; |
| @@ -699,7 +699,7 @@ void FoldFSwizzleAdd(IR::Block& block, IR::Inst& inst) { | |||
| 699 | } | 699 | } |
| 700 | } | 700 | } |
| 701 | 701 | ||
| 702 | bool FindGradient3DDerivates(std::array<IR::Value, 3>& results, IR::Value coord) { | 702 | bool FindGradient3DDerivatives(std::array<IR::Value, 3>& results, IR::Value coord) { |
| 703 | if (coord.IsImmediate()) { | 703 | if (coord.IsImmediate()) { |
| 704 | return false; | 704 | return false; |
| 705 | } | 705 | } |
| @@ -834,7 +834,7 @@ void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | |||
| 834 | IR::Inst* const inst2 = coords.InstRecursive(); | 834 | IR::Inst* const inst2 = coords.InstRecursive(); |
| 835 | std::array<std::array<IR::Value, 3>, 3> results_matrix; | 835 | std::array<std::array<IR::Value, 3>, 3> results_matrix; |
| 836 | for (size_t i = 0; i < 3; i++) { | 836 | for (size_t i = 0; i < 3; i++) { |
| 837 | if (!FindGradient3DDerivates(results_matrix[i], inst2->Arg(i).Resolve())) { | 837 | if (!FindGradient3DDerivatives(results_matrix[i], inst2->Arg(i).Resolve())) { |
| 838 | return; | 838 | return; |
| 839 | } | 839 | } |
| 840 | } | 840 | } |
| @@ -852,7 +852,7 @@ void FoldImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | |||
| 852 | IR::Value derivatives_1 = ir.CompositeConstruct(results_matrix[0][1], results_matrix[0][2], | 852 | IR::Value derivatives_1 = ir.CompositeConstruct(results_matrix[0][1], results_matrix[0][2], |
| 853 | results_matrix[1][1], results_matrix[1][2]); | 853 | results_matrix[1][1], results_matrix[1][2]); |
| 854 | IR::Value derivatives_2 = ir.CompositeConstruct(results_matrix[2][1], results_matrix[2][2]); | 854 | IR::Value derivatives_2 = ir.CompositeConstruct(results_matrix[2][1], results_matrix[2][2]); |
| 855 | info.num_derivates.Assign(3); | 855 | info.num_derivatives.Assign(3); |
| 856 | IR::Value new_gradient_instruction = | 856 | IR::Value new_gradient_instruction = |
| 857 | ir.ImageGradient(handle, new_coords, derivatives_1, derivatives_2, lod_clamp, info); | 857 | ir.ImageGradient(handle, new_coords, derivatives_1, derivatives_2, lod_clamp, info); |
| 858 | IR::Inst* const new_inst = new_gradient_instruction.InstRecursive(); | 858 | IR::Inst* const new_inst = new_gradient_instruction.InstRecursive(); |
diff --git a/src/shader_recompiler/ir_opt/passes.h b/src/shader_recompiler/ir_opt/passes.h index 629d18fa1..d4d5285e5 100644 --- a/src/shader_recompiler/ir_opt/passes.h +++ b/src/shader_recompiler/ir_opt/passes.h | |||
| @@ -26,6 +26,7 @@ void SsaRewritePass(IR::Program& program); | |||
| 26 | void PositionPass(Environment& env, IR::Program& program); | 26 | void PositionPass(Environment& env, IR::Program& program); |
| 27 | void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo& host_info); | 27 | void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo& host_info); |
| 28 | void LayerPass(IR::Program& program, const HostTranslateInfo& host_info); | 28 | void LayerPass(IR::Program& program, const HostTranslateInfo& host_info); |
| 29 | void VendorWorkaroundPass(IR::Program& program); | ||
| 29 | void VerificationPass(const IR::Program& program); | 30 | void VerificationPass(const IR::Program& program); |
| 30 | 31 | ||
| 31 | // Dual Vertex | 32 | // Dual Vertex |
diff --git a/src/shader_recompiler/ir_opt/vendor_workaround_pass.cpp b/src/shader_recompiler/ir_opt/vendor_workaround_pass.cpp new file mode 100644 index 000000000..08c658cb8 --- /dev/null +++ b/src/shader_recompiler/ir_opt/vendor_workaround_pass.cpp | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 5 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | ||
| 6 | #include "shader_recompiler/frontend/ir/value.h" | ||
| 7 | #include "shader_recompiler/ir_opt/passes.h" | ||
| 8 | |||
| 9 | namespace Shader::Optimization { | ||
| 10 | |||
| 11 | namespace { | ||
| 12 | void AddingByteSwapsWorkaround(IR::Block& block, IR::Inst& inst) { | ||
| 13 | /* | ||
| 14 | * Workaround for an NVIDIA bug seen in Super Mario RPG | ||
| 15 | * | ||
| 16 | * We are looking for this pattern: | ||
| 17 | * %lhs_bfe = BitFieldUExtract %factor_a, #0, #16 | ||
| 18 | * %lhs_mul = IMul32 %lhs_bfe, %factor_b // potentially optional? | ||
| 19 | * %lhs_shl = ShiftLeftLogical32 %lhs_mul, #16 | ||
| 20 | * %rhs_bfe = BitFieldUExtract %factor_a, #16, #16 | ||
| 21 | * %result = IAdd32 %lhs_shl, %rhs_bfe | ||
| 22 | * | ||
| 23 | * And replacing the IAdd32 with a BitwiseOr32 | ||
| 24 | * %result = BitwiseOr32 %lhs_shl, %rhs_bfe | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | IR::Inst* const lhs_shl{inst.Arg(0).TryInstRecursive()}; | ||
| 28 | IR::Inst* const rhs_bfe{inst.Arg(1).TryInstRecursive()}; | ||
| 29 | if (!lhs_shl || !rhs_bfe) { | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | if (lhs_shl->GetOpcode() != IR::Opcode::ShiftLeftLogical32 || | ||
| 33 | lhs_shl->Arg(1) != IR::Value{16U}) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | if (rhs_bfe->GetOpcode() != IR::Opcode::BitFieldUExtract || rhs_bfe->Arg(1) != IR::Value{16U} || | ||
| 37 | rhs_bfe->Arg(2) != IR::Value{16U}) { | ||
| 38 | return; | ||
| 39 | } | ||
| 40 | IR::Inst* const lhs_mul{lhs_shl->Arg(0).TryInstRecursive()}; | ||
| 41 | if (!lhs_mul) { | ||
| 42 | return; | ||
| 43 | } | ||
| 44 | const bool lhs_mul_optional{lhs_mul->GetOpcode() == IR::Opcode::BitFieldUExtract}; | ||
| 45 | if (lhs_mul->GetOpcode() != IR::Opcode::IMul32 && | ||
| 46 | lhs_mul->GetOpcode() != IR::Opcode::BitFieldUExtract) { | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | IR::Inst* const lhs_bfe{lhs_mul_optional ? lhs_mul : lhs_mul->Arg(0).TryInstRecursive()}; | ||
| 50 | if (!lhs_bfe) { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | if (lhs_bfe->GetOpcode() != IR::Opcode::BitFieldUExtract) { | ||
| 54 | return; | ||
| 55 | } | ||
| 56 | if (lhs_bfe->Arg(1) != IR::Value{0U} || lhs_bfe->Arg(2) != IR::Value{16U}) { | ||
| 57 | return; | ||
| 58 | } | ||
| 59 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | ||
| 60 | inst.ReplaceUsesWith(ir.BitwiseOr(IR::U32{inst.Arg(0)}, IR::U32{inst.Arg(1)})); | ||
| 61 | } | ||
| 62 | |||
| 63 | } // Anonymous namespace | ||
| 64 | |||
| 65 | void VendorWorkaroundPass(IR::Program& program) { | ||
| 66 | for (IR::Block* const block : program.post_order_blocks) { | ||
| 67 | for (IR::Inst& inst : block->Instructions()) { | ||
| 68 | switch (inst.GetOpcode()) { | ||
| 69 | case IR::Opcode::IAdd32: | ||
| 70 | AddingByteSwapsWorkaround(*block, inst); | ||
| 71 | break; | ||
| 72 | default: | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | } // namespace Shader::Optimization | ||
diff --git a/src/shader_recompiler/profile.h b/src/shader_recompiler/profile.h index 38d820db2..a9de9f4a9 100644 --- a/src/shader_recompiler/profile.h +++ b/src/shader_recompiler/profile.h | |||
| @@ -43,6 +43,7 @@ struct Profile { | |||
| 43 | bool support_gl_sparse_textures{}; | 43 | bool support_gl_sparse_textures{}; |
| 44 | bool support_gl_derivative_control{}; | 44 | bool support_gl_derivative_control{}; |
| 45 | bool support_scaled_attributes{}; | 45 | bool support_scaled_attributes{}; |
| 46 | bool support_multi_viewport{}; | ||
| 46 | 47 | ||
| 47 | bool warp_size_potentially_larger_than_guest{}; | 48 | bool warp_size_potentially_larger_than_guest{}; |
| 48 | 49 | ||
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 081a574e8..f5b10411b 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -1192,11 +1192,6 @@ void BufferCache<P>::UpdateDrawIndirect() { | |||
| 1192 | .size = static_cast<u32>(size), | 1192 | .size = static_cast<u32>(size), |
| 1193 | .buffer_id = FindBuffer(*cpu_addr, static_cast<u32>(size)), | 1193 | .buffer_id = FindBuffer(*cpu_addr, static_cast<u32>(size)), |
| 1194 | }; | 1194 | }; |
| 1195 | VAddr cpu_addr_start = Common::AlignDown(*cpu_addr, 64); | ||
| 1196 | VAddr cpu_addr_end = Common::AlignUp(*cpu_addr + size, 64); | ||
| 1197 | IntervalType interval{cpu_addr_start, cpu_addr_end}; | ||
| 1198 | ClearDownload(interval); | ||
| 1199 | common_ranges.subtract(interval); | ||
| 1200 | }; | 1195 | }; |
| 1201 | if (current_draw_indirect->include_count) { | 1196 | if (current_draw_indirect->include_count) { |
| 1202 | update(current_draw_indirect->count_start_address, sizeof(u32), | 1197 | update(current_draw_indirect->count_start_address, sizeof(u32), |
diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp index 02e161270..91f10aec2 100644 --- a/src/video_core/engines/fermi_2d.cpp +++ b/src/video_core/engines/fermi_2d.cpp | |||
| @@ -72,7 +72,7 @@ void Fermi2D::Blit() { | |||
| 72 | UNIMPLEMENTED_IF_MSG(regs.clip_enable != 0, "Clipped blit enabled"); | 72 | UNIMPLEMENTED_IF_MSG(regs.clip_enable != 0, "Clipped blit enabled"); |
| 73 | 73 | ||
| 74 | const auto& args = regs.pixels_from_memory; | 74 | const auto& args = regs.pixels_from_memory; |
| 75 | constexpr s64 null_derivate = 1ULL << 32; | 75 | constexpr s64 null_derivative = 1ULL << 32; |
| 76 | Surface src = regs.src; | 76 | Surface src = regs.src; |
| 77 | const auto bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format)); | 77 | const auto bytes_per_pixel = BytesPerBlock(PixelFormatFromRenderTargetFormat(src.format)); |
| 78 | const bool delegate_to_gpu = src.width > 512 && src.height > 512 && bytes_per_pixel <= 8 && | 78 | const bool delegate_to_gpu = src.width > 512 && src.height > 512 && bytes_per_pixel <= 8 && |
| @@ -89,7 +89,7 @@ void Fermi2D::Blit() { | |||
| 89 | .operation = regs.operation, | 89 | .operation = regs.operation, |
| 90 | .filter = args.sample_mode.filter, | 90 | .filter = args.sample_mode.filter, |
| 91 | .must_accelerate = | 91 | .must_accelerate = |
| 92 | args.du_dx != null_derivate || args.dv_dy != null_derivate || delegate_to_gpu, | 92 | args.du_dx != null_derivative || args.dv_dy != null_derivative || delegate_to_gpu, |
| 93 | .dst_x0 = args.dst_x0, | 93 | .dst_x0 = args.dst_x0, |
| 94 | .dst_y0 = args.dst_y0, | 94 | .dst_y0 = args.dst_y0, |
| 95 | .dst_x1 = args.dst_x0 + args.dst_width, | 95 | .dst_x1 = args.dst_x0 + args.dst_width, |
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 32d767d85..592c28ba3 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -268,7 +268,7 @@ size_t Maxwell3D::EstimateIndexBufferSize() { | |||
| 268 | std::numeric_limits<u32>::max()}; | 268 | std::numeric_limits<u32>::max()}; |
| 269 | const size_t byte_size = regs.index_buffer.FormatSizeInBytes(); | 269 | const size_t byte_size = regs.index_buffer.FormatSizeInBytes(); |
| 270 | const size_t log2_byte_size = Common::Log2Ceil64(byte_size); | 270 | const size_t log2_byte_size = Common::Log2Ceil64(byte_size); |
| 271 | const size_t cap{GetMaxCurrentVertices() * 3 * byte_size}; | 271 | const size_t cap{GetMaxCurrentVertices() * 4 * byte_size}; |
| 272 | const size_t lower_cap = | 272 | const size_t lower_cap = |
| 273 | std::min<size_t>(static_cast<size_t>(end_address - start_address), cap); | 273 | std::min<size_t>(static_cast<size_t>(end_address - start_address), cap); |
| 274 | return std::min<size_t>( | 274 | return std::min<size_t>( |
diff --git a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp index 44a771d65..af0a453ee 100644 --- a/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp +++ b/src/video_core/renderer_opengl/gl_graphics_pipeline.cpp | |||
| @@ -559,7 +559,9 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 559 | } | 559 | } |
| 560 | 560 | ||
| 561 | void GraphicsPipeline::ConfigureTransformFeedbackImpl() const { | 561 | void GraphicsPipeline::ConfigureTransformFeedbackImpl() const { |
| 562 | glTransformFeedbackAttribsNV(num_xfb_attribs, xfb_attribs.data(), GL_SEPARATE_ATTRIBS); | 562 | const GLenum buffer_mode = |
| 563 | num_xfb_buffers_active == 1 ? GL_INTERLEAVED_ATTRIBS : GL_SEPARATE_ATTRIBS; | ||
| 564 | glTransformFeedbackAttribsNV(num_xfb_attribs, xfb_attribs.data(), buffer_mode); | ||
| 563 | } | 565 | } |
| 564 | 566 | ||
| 565 | void GraphicsPipeline::GenerateTransformFeedbackState() { | 567 | void GraphicsPipeline::GenerateTransformFeedbackState() { |
| @@ -567,12 +569,14 @@ void GraphicsPipeline::GenerateTransformFeedbackState() { | |||
| 567 | // when this is required. | 569 | // when this is required. |
| 568 | GLint* cursor{xfb_attribs.data()}; | 570 | GLint* cursor{xfb_attribs.data()}; |
| 569 | 571 | ||
| 572 | num_xfb_buffers_active = 0; | ||
| 570 | for (size_t feedback = 0; feedback < Maxwell::NumTransformFeedbackBuffers; ++feedback) { | 573 | for (size_t feedback = 0; feedback < Maxwell::NumTransformFeedbackBuffers; ++feedback) { |
| 571 | const auto& layout = key.xfb_state.layouts[feedback]; | 574 | const auto& layout = key.xfb_state.layouts[feedback]; |
| 572 | UNIMPLEMENTED_IF_MSG(layout.stride != layout.varying_count * 4, "Stride padding"); | 575 | UNIMPLEMENTED_IF_MSG(layout.stride != layout.varying_count * 4, "Stride padding"); |
| 573 | if (layout.varying_count == 0) { | 576 | if (layout.varying_count == 0) { |
| 574 | continue; | 577 | continue; |
| 575 | } | 578 | } |
| 579 | num_xfb_buffers_active++; | ||
| 576 | 580 | ||
| 577 | const auto& locations = key.xfb_state.varyings[feedback]; | 581 | const auto& locations = key.xfb_state.varyings[feedback]; |
| 578 | std::optional<u32> current_index; | 582 | std::optional<u32> current_index; |
diff --git a/src/video_core/renderer_opengl/gl_graphics_pipeline.h b/src/video_core/renderer_opengl/gl_graphics_pipeline.h index 74fc9cc3d..2f70c1ae9 100644 --- a/src/video_core/renderer_opengl/gl_graphics_pipeline.h +++ b/src/video_core/renderer_opengl/gl_graphics_pipeline.h | |||
| @@ -154,6 +154,7 @@ private: | |||
| 154 | 154 | ||
| 155 | static constexpr std::size_t XFB_ENTRY_STRIDE = 3; | 155 | static constexpr std::size_t XFB_ENTRY_STRIDE = 3; |
| 156 | GLsizei num_xfb_attribs{}; | 156 | GLsizei num_xfb_attribs{}; |
| 157 | u32 num_xfb_buffers_active{}; | ||
| 157 | std::array<GLint, 128 * XFB_ENTRY_STRIDE * Maxwell::NumTransformFeedbackBuffers> xfb_attribs{}; | 158 | std::array<GLint, 128 * XFB_ENTRY_STRIDE * Maxwell::NumTransformFeedbackBuffers> xfb_attribs{}; |
| 158 | 159 | ||
| 159 | std::mutex built_mutex; | 160 | std::mutex built_mutex; |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 22bf8cc77..89b455bff 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -263,6 +263,22 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span<const Shader::IR::Program> program | |||
| 263 | info.y_negate = key.state.y_negate != 0; | 263 | info.y_negate = key.state.y_negate != 0; |
| 264 | return info; | 264 | return info; |
| 265 | } | 265 | } |
| 266 | |||
| 267 | size_t GetTotalPipelineWorkers() { | ||
| 268 | const size_t max_core_threads = | ||
| 269 | std::max<size_t>(static_cast<size_t>(std::thread::hardware_concurrency()), 2ULL) - 1ULL; | ||
| 270 | #ifdef ANDROID | ||
| 271 | // Leave at least a few cores free in android | ||
| 272 | constexpr size_t free_cores = 3ULL; | ||
| 273 | if (max_core_threads <= free_cores) { | ||
| 274 | return 1ULL; | ||
| 275 | } | ||
| 276 | return max_core_threads - free_cores; | ||
| 277 | #else | ||
| 278 | return max_core_threads; | ||
| 279 | #endif | ||
| 280 | } | ||
| 281 | |||
| 266 | } // Anonymous namespace | 282 | } // Anonymous namespace |
| 267 | 283 | ||
| 268 | size_t ComputePipelineCacheKey::Hash() const noexcept { | 284 | size_t ComputePipelineCacheKey::Hash() const noexcept { |
| @@ -294,11 +310,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device | |||
| 294 | texture_cache{texture_cache_}, shader_notify{shader_notify_}, | 310 | texture_cache{texture_cache_}, shader_notify{shader_notify_}, |
| 295 | use_asynchronous_shaders{Settings::values.use_asynchronous_shaders.GetValue()}, | 311 | use_asynchronous_shaders{Settings::values.use_asynchronous_shaders.GetValue()}, |
| 296 | use_vulkan_pipeline_cache{Settings::values.use_vulkan_driver_pipeline_cache.GetValue()}, | 312 | use_vulkan_pipeline_cache{Settings::values.use_vulkan_driver_pipeline_cache.GetValue()}, |
| 297 | #ifdef ANDROID | 313 | workers(device.HasBrokenParallelShaderCompiling() ? 1ULL : GetTotalPipelineWorkers(), |
| 298 | workers(1, "VkPipelineBuilder"), | 314 | "VkPipelineBuilder"), |
| 299 | #else | ||
| 300 | workers(std::max(std::thread::hardware_concurrency(), 2U) - 1, "VkPipelineBuilder"), | ||
| 301 | #endif | ||
| 302 | serialization_thread(1, "VkPipelineSerialization") { | 315 | serialization_thread(1, "VkPipelineSerialization") { |
| 303 | const auto& float_control{device.FloatControlProperties()}; | 316 | const auto& float_control{device.FloatControlProperties()}; |
| 304 | const VkDriverId driver_id{device.GetDriverID()}; | 317 | const VkDriverId driver_id{device.GetDriverID()}; |
| @@ -338,6 +351,7 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device | |||
| 338 | .support_geometry_shader_passthrough = device.IsNvGeometryShaderPassthroughSupported(), | 351 | .support_geometry_shader_passthrough = device.IsNvGeometryShaderPassthroughSupported(), |
| 339 | .support_native_ndc = device.IsExtDepthClipControlSupported(), | 352 | .support_native_ndc = device.IsExtDepthClipControlSupported(), |
| 340 | .support_scaled_attributes = !device.MustEmulateScaledFormats(), | 353 | .support_scaled_attributes = !device.MustEmulateScaledFormats(), |
| 354 | .support_multi_viewport = device.SupportsMultiViewport(), | ||
| 341 | 355 | ||
| 342 | .warp_size_potentially_larger_than_guest = device.IsWarpSizePotentiallyBiggerThanGuest(), | 356 | .warp_size_potentially_larger_than_guest = device.IsWarpSizePotentiallyBiggerThanGuest(), |
| 343 | 357 | ||
diff --git a/src/video_core/renderer_vulkan/vk_query_cache.cpp b/src/video_core/renderer_vulkan/vk_query_cache.cpp index 66c03bf17..078777cdd 100644 --- a/src/video_core/renderer_vulkan/vk_query_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_query_cache.cpp | |||
| @@ -211,6 +211,13 @@ public: | |||
| 211 | return; | 211 | return; |
| 212 | } | 212 | } |
| 213 | PauseCounter(); | 213 | PauseCounter(); |
| 214 | const auto driver_id = device.GetDriverID(); | ||
| 215 | if (driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY || | ||
| 216 | driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) { | ||
| 217 | pending_sync.clear(); | ||
| 218 | sync_values_stash.clear(); | ||
| 219 | return; | ||
| 220 | } | ||
| 214 | sync_values_stash.clear(); | 221 | sync_values_stash.clear(); |
| 215 | sync_values_stash.emplace_back(); | 222 | sync_values_stash.emplace_back(); |
| 216 | std::vector<HostSyncValues>* sync_values = &sync_values_stash.back(); | 223 | std::vector<HostSyncValues>* sync_values = &sync_values_stash.back(); |
| @@ -1378,6 +1385,12 @@ bool QueryCacheRuntime::HostConditionalRenderingCompareValues(VideoCommon::Looku | |||
| 1378 | return true; | 1385 | return true; |
| 1379 | } | 1386 | } |
| 1380 | 1387 | ||
| 1388 | auto driver_id = impl->device.GetDriverID(); | ||
| 1389 | if (driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY || | ||
| 1390 | driver_id == VK_DRIVER_ID_ARM_PROPRIETARY || driver_id == VK_DRIVER_ID_MESA_TURNIP) { | ||
| 1391 | return true; | ||
| 1392 | } | ||
| 1393 | |||
| 1381 | for (size_t i = 0; i < 2; i++) { | 1394 | for (size_t i = 0; i < 2; i++) { |
| 1382 | is_null[i] = !is_in_ac[i] && check_value(objects[i]->address); | 1395 | is_null[i] = !is_in_ac[i] && check_value(objects[i]->address); |
| 1383 | } | 1396 | } |
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp index e518756d2..6900b8ffa 100644 --- a/src/video_core/vulkan_common/vulkan_device.cpp +++ b/src/video_core/vulkan_common/vulkan_device.cpp | |||
| @@ -635,6 +635,12 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR | |||
| 635 | has_broken_cube_compatibility = true; | 635 | has_broken_cube_compatibility = true; |
| 636 | } | 636 | } |
| 637 | } | 637 | } |
| 638 | if (is_qualcomm) { | ||
| 639 | const u32 version = (properties.properties.driverVersion << 3) >> 3; | ||
| 640 | if (version < VK_MAKE_API_VERSION(0, 255, 615, 512)) { | ||
| 641 | has_broken_parallel_compiling = true; | ||
| 642 | } | ||
| 643 | } | ||
| 638 | if (extensions.sampler_filter_minmax && is_amd) { | 644 | if (extensions.sampler_filter_minmax && is_amd) { |
| 639 | // Disable ext_sampler_filter_minmax on AMD GCN4 and lower as it is broken. | 645 | // Disable ext_sampler_filter_minmax on AMD GCN4 and lower as it is broken. |
| 640 | if (!features.shader_float16_int8.shaderFloat16) { | 646 | if (!features.shader_float16_int8.shaderFloat16) { |
diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index b213ed7dd..4f3846345 100644 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h | |||
| @@ -102,6 +102,7 @@ VK_DEFINE_HANDLE(VmaAllocator) | |||
| 102 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) \ | 102 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME) \ |
| 103 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME) \ | 103 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME) \ |
| 104 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME) \ | 104 | EXTENSION_NAME(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME) \ |
| 105 | EXTENSION_NAME(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME) \ | ||
| 105 | EXTENSION_NAME(VK_EXT_4444_FORMATS_EXTENSION_NAME) \ | 106 | EXTENSION_NAME(VK_EXT_4444_FORMATS_EXTENSION_NAME) \ |
| 106 | EXTENSION_NAME(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME) \ | 107 | EXTENSION_NAME(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME) \ |
| 107 | EXTENSION_NAME(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) \ | 108 | EXTENSION_NAME(VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) \ |
| @@ -599,6 +600,11 @@ public: | |||
| 599 | return has_broken_cube_compatibility; | 600 | return has_broken_cube_compatibility; |
| 600 | } | 601 | } |
| 601 | 602 | ||
| 603 | /// Returns true if parallel shader compiling has issues with the current driver. | ||
| 604 | bool HasBrokenParallelShaderCompiling() const { | ||
| 605 | return has_broken_parallel_compiling; | ||
| 606 | } | ||
| 607 | |||
| 602 | /// Returns the vendor name reported from Vulkan. | 608 | /// Returns the vendor name reported from Vulkan. |
| 603 | std::string_view GetVendorName() const { | 609 | std::string_view GetVendorName() const { |
| 604 | return properties.driver.driverName; | 610 | return properties.driver.driverName; |
| @@ -663,6 +669,10 @@ public: | |||
| 663 | return supports_conditional_barriers; | 669 | return supports_conditional_barriers; |
| 664 | } | 670 | } |
| 665 | 671 | ||
| 672 | bool SupportsMultiViewport() const { | ||
| 673 | return features2.features.multiViewport; | ||
| 674 | } | ||
| 675 | |||
| 666 | [[nodiscard]] static constexpr bool CheckBrokenCompute(VkDriverId driver_id, | 676 | [[nodiscard]] static constexpr bool CheckBrokenCompute(VkDriverId driver_id, |
| 667 | u32 driver_version) { | 677 | u32 driver_version) { |
| 668 | if (driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) { | 678 | if (driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) { |
| @@ -794,6 +804,7 @@ private: | |||
| 794 | bool is_non_gpu{}; ///< Is SoftwareRasterizer, FPGA, non-GPU device. | 804 | bool is_non_gpu{}; ///< Is SoftwareRasterizer, FPGA, non-GPU device. |
| 795 | bool has_broken_compute{}; ///< Compute shaders can cause crashes | 805 | bool has_broken_compute{}; ///< Compute shaders can cause crashes |
| 796 | bool has_broken_cube_compatibility{}; ///< Has broken cube compatibility bit | 806 | bool has_broken_cube_compatibility{}; ///< Has broken cube compatibility bit |
| 807 | bool has_broken_parallel_compiling{}; ///< Has broken parallel shader compiling. | ||
| 797 | bool has_renderdoc{}; ///< Has RenderDoc attached | 808 | bool has_renderdoc{}; ///< Has RenderDoc attached |
| 798 | bool has_nsight_graphics{}; ///< Has Nsight Graphics attached | 809 | bool has_nsight_graphics{}; ///< Has Nsight Graphics attached |
| 799 | bool supports_d24_depth{}; ///< Supports D24 depth buffers. | 810 | bool supports_d24_depth{}; ///< Supports D24 depth buffers. |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 7e7d8e252..f294dc23d 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -567,9 +567,10 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 567 | QAction* verify_integrity = context_menu.addAction(tr("Verify Integrity")); | 567 | QAction* verify_integrity = context_menu.addAction(tr("Verify Integrity")); |
| 568 | QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard")); | 568 | QAction* copy_tid = context_menu.addAction(tr("Copy Title ID to Clipboard")); |
| 569 | QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry")); | 569 | QAction* navigate_to_gamedb_entry = context_menu.addAction(tr("Navigate to GameDB entry")); |
| 570 | // TODO: Implement shortcut creation for macOS | ||
| 571 | #if !defined(__APPLE__) | ||
| 570 | QMenu* shortcut_menu = context_menu.addMenu(tr("Create Shortcut")); | 572 | QMenu* shortcut_menu = context_menu.addMenu(tr("Create Shortcut")); |
| 571 | QAction* create_desktop_shortcut = shortcut_menu->addAction(tr("Add to Desktop")); | 573 | QAction* create_desktop_shortcut = shortcut_menu->addAction(tr("Add to Desktop")); |
| 572 | #ifndef WIN32 | ||
| 573 | QAction* create_applications_menu_shortcut = | 574 | QAction* create_applications_menu_shortcut = |
| 574 | shortcut_menu->addAction(tr("Add to Applications Menu")); | 575 | shortcut_menu->addAction(tr("Add to Applications Menu")); |
| 575 | #endif | 576 | #endif |
| @@ -647,10 +648,11 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri | |||
| 647 | connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() { | 648 | connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() { |
| 648 | emit NavigateToGamedbEntryRequested(program_id, compatibility_list); | 649 | emit NavigateToGamedbEntryRequested(program_id, compatibility_list); |
| 649 | }); | 650 | }); |
| 651 | // TODO: Implement shortcut creation for macOS | ||
| 652 | #if !defined(__APPLE__) | ||
| 650 | connect(create_desktop_shortcut, &QAction::triggered, [this, program_id, path]() { | 653 | connect(create_desktop_shortcut, &QAction::triggered, [this, program_id, path]() { |
| 651 | emit CreateShortcut(program_id, path, GameListShortcutTarget::Desktop); | 654 | emit CreateShortcut(program_id, path, GameListShortcutTarget::Desktop); |
| 652 | }); | 655 | }); |
| 653 | #ifndef WIN32 | ||
| 654 | connect(create_applications_menu_shortcut, &QAction::triggered, [this, program_id, path]() { | 656 | connect(create_applications_menu_shortcut, &QAction::triggered, [this, program_id, path]() { |
| 655 | emit CreateShortcut(program_id, path, GameListShortcutTarget::Applications); | 657 | emit CreateShortcut(program_id, path, GameListShortcutTarget::Applications); |
| 656 | }); | 658 | }); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index b0e995c52..f22db233b 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include <thread> | 10 | #include <thread> |
| 11 | #include "core/loader/nca.h" | 11 | #include "core/loader/nca.h" |
| 12 | #include "core/tools/renderdoc.h" | 12 | #include "core/tools/renderdoc.h" |
| 13 | |||
| 13 | #ifdef __APPLE__ | 14 | #ifdef __APPLE__ |
| 14 | #include <unistd.h> // for chdir | 15 | #include <unistd.h> // for chdir |
| 15 | #endif | 16 | #endif |
| @@ -2847,170 +2848,259 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id, | |||
| 2847 | QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory)); | 2848 | QDesktopServices::openUrl(QUrl(QStringLiteral("https://yuzu-emu.org/game/") + directory)); |
| 2848 | } | 2849 | } |
| 2849 | 2850 | ||
| 2850 | void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path, | 2851 | bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, |
| 2851 | GameListShortcutTarget target) { | 2852 | const std::string& comment, |
| 2852 | // Get path to yuzu executable | 2853 | const std::filesystem::path& icon_path, |
| 2853 | const QStringList args = QApplication::arguments(); | 2854 | const std::filesystem::path& command, |
| 2854 | std::filesystem::path yuzu_command = args[0].toStdString(); | 2855 | const std::string& arguments, const std::string& categories, |
| 2855 | 2856 | const std::string& keywords, const std::string& name) try { | |
| 2856 | // If relative path, make it an absolute path | 2857 | #if defined(__linux__) || defined(__FreeBSD__) // Linux and FreeBSD |
| 2857 | if (yuzu_command.c_str()[0] == '.') { | 2858 | std::filesystem::path shortcut_path_full = shortcut_path / (name + ".desktop"); |
| 2858 | yuzu_command = Common::FS::GetCurrentDir() / yuzu_command; | 2859 | std::ofstream shortcut_stream(shortcut_path_full, std::ios::binary | std::ios::trunc); |
| 2860 | if (!shortcut_stream.is_open()) { | ||
| 2861 | LOG_ERROR(Frontend, "Failed to create shortcut"); | ||
| 2862 | return false; | ||
| 2859 | } | 2863 | } |
| 2860 | 2864 | // TODO: Migrate fmt::print to std::print in futures STD C++ 23. | |
| 2861 | #if defined(__linux__) | 2865 | fmt::print(shortcut_stream, "[Desktop Entry]\n"); |
| 2862 | // Warn once if we are making a shortcut to a volatile AppImage | 2866 | fmt::print(shortcut_stream, "Type=Application\n"); |
| 2863 | const std::string appimage_ending = | 2867 | fmt::print(shortcut_stream, "Version=1.0\n"); |
| 2864 | std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage"); | 2868 | fmt::print(shortcut_stream, "Name={}\n", name); |
| 2865 | if (yuzu_command.string().ends_with(appimage_ending) && | 2869 | if (!comment.empty()) { |
| 2866 | !UISettings::values.shortcut_already_warned) { | 2870 | fmt::print(shortcut_stream, "Comment={}\n", comment); |
| 2867 | if (QMessageBox::warning(this, tr("Create Shortcut"), | 2871 | } |
| 2868 | tr("This will create a shortcut to the current AppImage. This may " | 2872 | if (std::filesystem::is_regular_file(icon_path)) { |
| 2869 | "not work well if you update. Continue?"), | 2873 | fmt::print(shortcut_stream, "Icon={}\n", icon_path.string()); |
| 2870 | QMessageBox::StandardButton::Ok | | 2874 | } |
| 2871 | QMessageBox::StandardButton::Cancel) == | 2875 | fmt::print(shortcut_stream, "TryExec={}\n", command.string()); |
| 2872 | QMessageBox::StandardButton::Cancel) { | 2876 | fmt::print(shortcut_stream, "Exec={} {}\n", command.string(), arguments); |
| 2873 | return; | 2877 | if (!categories.empty()) { |
| 2878 | fmt::print(shortcut_stream, "Categories={}\n", categories); | ||
| 2879 | } | ||
| 2880 | if (!keywords.empty()) { | ||
| 2881 | fmt::print(shortcut_stream, "Keywords={}\n", keywords); | ||
| 2882 | } | ||
| 2883 | return true; | ||
| 2884 | #elif defined(_WIN32) // Windows | ||
| 2885 | HRESULT hr = CoInitialize(nullptr); | ||
| 2886 | if (FAILED(hr)) { | ||
| 2887 | LOG_ERROR(Frontend, "CoInitialize failed"); | ||
| 2888 | return false; | ||
| 2889 | } | ||
| 2890 | SCOPE_EXIT({ CoUninitialize(); }); | ||
| 2891 | IShellLinkW* ps1 = nullptr; | ||
| 2892 | IPersistFile* persist_file = nullptr; | ||
| 2893 | SCOPE_EXIT({ | ||
| 2894 | if (persist_file != nullptr) { | ||
| 2895 | persist_file->Release(); | ||
| 2874 | } | 2896 | } |
| 2875 | UISettings::values.shortcut_already_warned = true; | 2897 | if (ps1 != nullptr) { |
| 2898 | ps1->Release(); | ||
| 2899 | } | ||
| 2900 | }); | ||
| 2901 | HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLinkW, | ||
| 2902 | reinterpret_cast<void**>(&ps1)); | ||
| 2903 | if (FAILED(hres)) { | ||
| 2904 | LOG_ERROR(Frontend, "Failed to create IShellLinkW instance"); | ||
| 2905 | return false; | ||
| 2876 | } | 2906 | } |
| 2877 | #endif // __linux__ | 2907 | hres = ps1->SetPath(command.c_str()); |
| 2878 | 2908 | if (FAILED(hres)) { | |
| 2879 | std::filesystem::path target_directory{}; | 2909 | LOG_ERROR(Frontend, "Failed to set path"); |
| 2880 | 2910 | return false; | |
| 2881 | switch (target) { | ||
| 2882 | case GameListShortcutTarget::Desktop: { | ||
| 2883 | const QString desktop_path = | ||
| 2884 | QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); | ||
| 2885 | target_directory = desktop_path.toUtf8().toStdString(); | ||
| 2886 | break; | ||
| 2887 | } | 2911 | } |
| 2888 | case GameListShortcutTarget::Applications: { | 2912 | if (!arguments.empty()) { |
| 2889 | const QString applications_path = | 2913 | hres = ps1->SetArguments(Common::UTF8ToUTF16W(arguments).data()); |
| 2890 | QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); | 2914 | if (FAILED(hres)) { |
| 2891 | if (applications_path.isEmpty()) { | 2915 | LOG_ERROR(Frontend, "Failed to set arguments"); |
| 2892 | const char* home = std::getenv("HOME"); | 2916 | return false; |
| 2893 | if (home != nullptr) { | ||
| 2894 | target_directory = std::filesystem::path(home) / ".local/share/applications"; | ||
| 2895 | } | ||
| 2896 | } else { | ||
| 2897 | target_directory = applications_path.toUtf8().toStdString(); | ||
| 2898 | } | 2917 | } |
| 2899 | break; | ||
| 2900 | } | 2918 | } |
| 2901 | default: | 2919 | if (!comment.empty()) { |
| 2902 | return; | 2920 | hres = ps1->SetDescription(Common::UTF8ToUTF16W(comment).data()); |
| 2921 | if (FAILED(hres)) { | ||
| 2922 | LOG_ERROR(Frontend, "Failed to set description"); | ||
| 2923 | return false; | ||
| 2924 | } | ||
| 2903 | } | 2925 | } |
| 2904 | 2926 | if (std::filesystem::is_regular_file(icon_path)) { | |
| 2905 | const QDir dir(QString::fromStdString(target_directory.generic_string())); | 2927 | hres = ps1->SetIconLocation(icon_path.c_str(), 0); |
| 2906 | if (!dir.exists()) { | 2928 | if (FAILED(hres)) { |
| 2907 | QMessageBox::critical(this, tr("Create Shortcut"), | 2929 | LOG_ERROR(Frontend, "Failed to set icon location"); |
| 2908 | tr("Cannot create shortcut. Path \"%1\" does not exist.") | 2930 | return false; |
| 2909 | .arg(QString::fromStdString(target_directory.generic_string())), | 2931 | } |
| 2910 | QMessageBox::StandardButton::Ok); | ||
| 2911 | return; | ||
| 2912 | } | 2932 | } |
| 2933 | hres = ps1->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&persist_file)); | ||
| 2934 | if (FAILED(hres)) { | ||
| 2935 | LOG_ERROR(Frontend, "Failed to get IPersistFile interface"); | ||
| 2936 | return false; | ||
| 2937 | } | ||
| 2938 | hres = persist_file->Save(std::filesystem::path{shortcut_path / (name + ".lnk")}.c_str(), TRUE); | ||
| 2939 | if (FAILED(hres)) { | ||
| 2940 | LOG_ERROR(Frontend, "Failed to save shortcut"); | ||
| 2941 | return false; | ||
| 2942 | } | ||
| 2943 | return true; | ||
| 2944 | #else // Unsupported platform | ||
| 2945 | return false; | ||
| 2946 | #endif | ||
| 2947 | } catch (const std::exception& e) { | ||
| 2948 | LOG_ERROR(Frontend, "Failed to create shortcut: {}", e.what()); | ||
| 2949 | return false; | ||
| 2950 | } | ||
| 2951 | // Messages in pre-defined message boxes for less code spaghetti | ||
| 2952 | bool GMainWindow::CreateShortcutMessagesGUI(QWidget* parent, int imsg, const QString& game_title) { | ||
| 2953 | int result = 0; | ||
| 2954 | QMessageBox::StandardButtons buttons; | ||
| 2955 | switch (imsg) { | ||
| 2956 | case GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES: | ||
| 2957 | buttons = QMessageBox::Yes | QMessageBox::No; | ||
| 2958 | result = | ||
| 2959 | QMessageBox::information(parent, tr("Create Shortcut"), | ||
| 2960 | tr("Do you want to launch the game in fullscreen?"), buttons); | ||
| 2961 | return result == QMessageBox::Yes; | ||
| 2962 | case GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS: | ||
| 2963 | QMessageBox::information(parent, tr("Create Shortcut"), | ||
| 2964 | tr("Successfully created a shortcut to %1").arg(game_title)); | ||
| 2965 | return false; | ||
| 2966 | case GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING: | ||
| 2967 | buttons = QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel; | ||
| 2968 | result = | ||
| 2969 | QMessageBox::warning(this, tr("Create Shortcut"), | ||
| 2970 | tr("This will create a shortcut to the current AppImage. This may " | ||
| 2971 | "not work well if you update. Continue?"), | ||
| 2972 | buttons); | ||
| 2973 | return result == QMessageBox::Ok; | ||
| 2974 | default: | ||
| 2975 | buttons = QMessageBox::Ok; | ||
| 2976 | QMessageBox::critical(parent, tr("Create Shortcut"), | ||
| 2977 | tr("Failed to create a shortcut to %1").arg(game_title), buttons); | ||
| 2978 | return false; | ||
| 2979 | } | ||
| 2980 | } | ||
| 2913 | 2981 | ||
| 2914 | const std::string game_file_name = std::filesystem::path(game_path).filename().string(); | 2982 | bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name, |
| 2915 | // Determine full paths for icon and shortcut | 2983 | std::filesystem::path& out_icon_path) { |
| 2916 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) | 2984 | // Get path to Yuzu icons directory & icon extension |
| 2917 | const char* home = std::getenv("HOME"); | 2985 | std::string ico_extension = "png"; |
| 2918 | const std::filesystem::path home_path = (home == nullptr ? "~" : home); | 2986 | #if defined(_WIN32) |
| 2919 | const char* xdg_data_home = std::getenv("XDG_DATA_HOME"); | 2987 | out_icon_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::IconsDir); |
| 2920 | 2988 | ico_extension = "ico"; | |
| 2921 | std::filesystem::path system_icons_path = | 2989 | #elif defined(__linux__) || defined(__FreeBSD__) |
| 2922 | (xdg_data_home == nullptr ? home_path / ".local/share/" | 2990 | out_icon_path = Common::FS::GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256"; |
| 2923 | : std::filesystem::path(xdg_data_home)) / | 2991 | #endif |
| 2924 | "icons/hicolor/256x256"; | 2992 | // Create icons directory if it doesn't exist |
| 2925 | if (!Common::FS::CreateDirs(system_icons_path)) { | 2993 | if (!Common::FS::CreateDirs(out_icon_path)) { |
| 2926 | QMessageBox::critical( | 2994 | QMessageBox::critical( |
| 2927 | this, tr("Create Icon"), | 2995 | this, tr("Create Icon"), |
| 2928 | tr("Cannot create icon file. Path \"%1\" does not exist and cannot be created.") | 2996 | tr("Cannot create icon file. Path \"%1\" does not exist and cannot be created.") |
| 2929 | .arg(QString::fromStdString(system_icons_path)), | 2997 | .arg(QString::fromStdString(out_icon_path.string())), |
| 2930 | QMessageBox::StandardButton::Ok); | 2998 | QMessageBox::StandardButton::Ok); |
| 2931 | return; | 2999 | out_icon_path.clear(); |
| 3000 | return false; | ||
| 2932 | } | 3001 | } |
| 2933 | std::filesystem::path icon_path = | ||
| 2934 | system_icons_path / (program_id == 0 ? fmt::format("yuzu-{}.png", game_file_name) | ||
| 2935 | : fmt::format("yuzu-{:016X}.png", program_id)); | ||
| 2936 | const std::filesystem::path shortcut_path = | ||
| 2937 | target_directory / (program_id == 0 ? fmt::format("yuzu-{}.desktop", game_file_name) | ||
| 2938 | : fmt::format("yuzu-{:016X}.desktop", program_id)); | ||
| 2939 | #elif defined(WIN32) | ||
| 2940 | std::filesystem::path icons_path = | ||
| 2941 | Common::FS::GetYuzuPathString(Common::FS::YuzuPath::IconsDir); | ||
| 2942 | std::filesystem::path icon_path = | ||
| 2943 | icons_path / ((program_id == 0 ? fmt::format("yuzu-{}.ico", game_file_name) | ||
| 2944 | : fmt::format("yuzu-{:016X}.ico", program_id))); | ||
| 2945 | #else | ||
| 2946 | std::string icon_extension; | ||
| 2947 | #endif | ||
| 2948 | |||
| 2949 | // Get title from game file | ||
| 2950 | const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), | ||
| 2951 | system->GetContentProvider()}; | ||
| 2952 | const auto control = pm.GetControlMetadata(); | ||
| 2953 | const auto loader = Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); | ||
| 2954 | 3002 | ||
| 2955 | std::string title{fmt::format("{:016X}", program_id)}; | 3003 | // Create icon file path |
| 2956 | 3004 | out_icon_path /= (program_id == 0 ? fmt::format("yuzu-{}.{}", game_file_name, ico_extension) | |
| 2957 | if (control.first != nullptr) { | 3005 | : fmt::format("yuzu-{:016X}.{}", program_id, ico_extension)); |
| 2958 | title = control.first->GetApplicationName(); | 3006 | return true; |
| 2959 | } else { | 3007 | } |
| 2960 | loader->ReadTitle(title); | ||
| 2961 | } | ||
| 2962 | 3008 | ||
| 2963 | // Get icon from game file | 3009 | void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& game_path, |
| 2964 | std::vector<u8> icon_image_file{}; | 3010 | GameListShortcutTarget target) { |
| 2965 | if (control.second != nullptr) { | 3011 | std::string game_title; |
| 2966 | icon_image_file = control.second->ReadAllBytes(); | 3012 | QString qt_game_title; |
| 2967 | } else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) { | 3013 | std::filesystem::path out_icon_path; |
| 2968 | LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); | 3014 | // Get path to yuzu executable |
| 3015 | const QStringList args = QApplication::arguments(); | ||
| 3016 | std::filesystem::path yuzu_command = args[0].toStdString(); | ||
| 3017 | // If relative path, make it an absolute path | ||
| 3018 | if (yuzu_command.c_str()[0] == '.') { | ||
| 3019 | yuzu_command = Common::FS::GetCurrentDir() / yuzu_command; | ||
| 2969 | } | 3020 | } |
| 2970 | 3021 | // Shortcut path | |
| 2971 | QImage icon_data = | 3022 | std::filesystem::path shortcut_path{}; |
| 2972 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); | 3023 | if (target == GameListShortcutTarget::Desktop) { |
| 2973 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) | 3024 | shortcut_path = |
| 2974 | // Convert and write the icon as a PNG | 3025 | QStandardPaths::writableLocation(QStandardPaths::DesktopLocation).toStdString(); |
| 2975 | if (!icon_data.save(QString::fromStdString(icon_path.string()))) { | 3026 | } else if (target == GameListShortcutTarget::Applications) { |
| 2976 | LOG_ERROR(Frontend, "Could not write icon as PNG to file"); | 3027 | shortcut_path = |
| 3028 | QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation).toStdString(); | ||
| 3029 | } | ||
| 3030 | // Icon path and title | ||
| 3031 | if (std::filesystem::exists(shortcut_path)) { | ||
| 3032 | // Get title from game file | ||
| 3033 | const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), | ||
| 3034 | system->GetContentProvider()}; | ||
| 3035 | const auto control = pm.GetControlMetadata(); | ||
| 3036 | const auto loader = | ||
| 3037 | Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read)); | ||
| 3038 | game_title = fmt::format("{:016X}", program_id); | ||
| 3039 | if (control.first != nullptr) { | ||
| 3040 | game_title = control.first->GetApplicationName(); | ||
| 3041 | } else { | ||
| 3042 | loader->ReadTitle(game_title); | ||
| 3043 | } | ||
| 3044 | // Delete illegal characters from title | ||
| 3045 | const std::string illegal_chars = "<>:\"/\\|?*."; | ||
| 3046 | for (auto it = game_title.rbegin(); it != game_title.rend(); ++it) { | ||
| 3047 | if (illegal_chars.find(*it) != std::string::npos) { | ||
| 3048 | game_title.erase(it.base() - 1); | ||
| 3049 | } | ||
| 3050 | } | ||
| 3051 | qt_game_title = QString::fromStdString(game_title); | ||
| 3052 | // Get icon from game file | ||
| 3053 | std::vector<u8> icon_image_file{}; | ||
| 3054 | if (control.second != nullptr) { | ||
| 3055 | icon_image_file = control.second->ReadAllBytes(); | ||
| 3056 | } else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) { | ||
| 3057 | LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path); | ||
| 3058 | } | ||
| 3059 | QImage icon_data = | ||
| 3060 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); | ||
| 3061 | if (GMainWindow::MakeShortcutIcoPath(program_id, game_title, out_icon_path)) { | ||
| 3062 | if (!SaveIconToFile(out_icon_path, icon_data)) { | ||
| 3063 | LOG_ERROR(Frontend, "Could not write icon to file"); | ||
| 3064 | } | ||
| 3065 | } | ||
| 2977 | } else { | 3066 | } else { |
| 2978 | LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string()); | 3067 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, |
| 2979 | } | 3068 | qt_game_title); |
| 2980 | #elif defined(WIN32) | 3069 | LOG_ERROR(Frontend, "Invalid shortcut target"); |
| 2981 | if (!SaveIconToFile(icon_path.string(), icon_data)) { | ||
| 2982 | LOG_ERROR(Frontend, "Could not write icon to file"); | ||
| 2983 | return; | 3070 | return; |
| 2984 | } | 3071 | } |
| 3072 | #if defined(__linux__) | ||
| 3073 | // Special case for AppImages | ||
| 3074 | // Warn once if we are making a shortcut to a volatile AppImage | ||
| 3075 | const std::string appimage_ending = | ||
| 3076 | std::string(Common::g_scm_rev).substr(0, 9).append(".AppImage"); | ||
| 3077 | if (yuzu_command.string().ends_with(appimage_ending) && | ||
| 3078 | !UISettings::values.shortcut_already_warned) { | ||
| 3079 | if (GMainWindow::CreateShortcutMessagesGUI( | ||
| 3080 | this, GMainWindow::CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING, qt_game_title)) { | ||
| 3081 | return; | ||
| 3082 | } | ||
| 3083 | UISettings::values.shortcut_already_warned = true; | ||
| 3084 | } | ||
| 2985 | #endif // __linux__ | 3085 | #endif // __linux__ |
| 2986 | 3086 | // Create shortcut | |
| 2987 | #ifdef _WIN32 | 3087 | std::string arguments = fmt::format("-g \"{:s}\"", game_path); |
| 2988 | // Replace characters that are illegal in Windows filenames by a dash | 3088 | if (GMainWindow::CreateShortcutMessagesGUI( |
| 2989 | const std::string illegal_chars = "<>:\"/\\|?*"; | 3089 | this, GMainWindow::CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, qt_game_title)) { |
| 2990 | for (char c : illegal_chars) { | 3090 | arguments = "-f " + arguments; |
| 2991 | std::replace(title.begin(), title.end(), c, '_'); | ||
| 2992 | } | 3091 | } |
| 2993 | const std::filesystem::path shortcut_path = target_directory / (title + ".lnk").c_str(); | 3092 | const std::string comment = fmt::format("Start {:s} with the yuzu Emulator", game_title); |
| 2994 | #endif | ||
| 2995 | |||
| 2996 | const std::string comment = | ||
| 2997 | tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString(); | ||
| 2998 | const std::string arguments = fmt::format("-g \"{:s}\"", game_path); | ||
| 2999 | const std::string categories = "Game;Emulator;Qt;"; | 3093 | const std::string categories = "Game;Emulator;Qt;"; |
| 3000 | const std::string keywords = "Switch;Nintendo;"; | 3094 | const std::string keywords = "Switch;Nintendo;"; |
| 3001 | 3095 | ||
| 3002 | if (!CreateShortcut(shortcut_path.string(), title, comment, icon_path.string(), | 3096 | if (GMainWindow::CreateShortcutLink(shortcut_path, comment, out_icon_path, yuzu_command, |
| 3003 | yuzu_command.string(), arguments, categories, keywords)) { | 3097 | arguments, categories, keywords, game_title)) { |
| 3004 | QMessageBox::critical(this, tr("Create Shortcut"), | 3098 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_SUCCESS, |
| 3005 | tr("Failed to create a shortcut at %1") | 3099 | qt_game_title); |
| 3006 | .arg(QString::fromStdString(shortcut_path.string()))); | ||
| 3007 | return; | 3100 | return; |
| 3008 | } | 3101 | } |
| 3009 | 3102 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, | |
| 3010 | LOG_INFO(Frontend, "Wrote a shortcut to {}", shortcut_path.string()); | 3103 | qt_game_title); |
| 3011 | QMessageBox::information( | ||
| 3012 | this, tr("Create Shortcut"), | ||
| 3013 | tr("Successfully created a shortcut to %1").arg(QString::fromStdString(title))); | ||
| 3014 | } | 3104 | } |
| 3015 | 3105 | ||
| 3016 | void GMainWindow::OnGameListOpenDirectory(const QString& directory) { | 3106 | void GMainWindow::OnGameListOpenDirectory(const QString& directory) { |
| @@ -4005,66 +4095,6 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file | |||
| 4005 | } | 4095 | } |
| 4006 | } | 4096 | } |
| 4007 | 4097 | ||
| 4008 | bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::string& title, | ||
| 4009 | const std::string& comment, const std::string& icon_path, | ||
| 4010 | const std::string& command, const std::string& arguments, | ||
| 4011 | const std::string& categories, const std::string& keywords) { | ||
| 4012 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) | ||
| 4013 | // This desktop file template was writing referencing | ||
| 4014 | // https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html | ||
| 4015 | std::string shortcut_contents{}; | ||
| 4016 | shortcut_contents.append("[Desktop Entry]\n"); | ||
| 4017 | shortcut_contents.append("Type=Application\n"); | ||
| 4018 | shortcut_contents.append("Version=1.0\n"); | ||
| 4019 | shortcut_contents.append(fmt::format("Name={:s}\n", title)); | ||
| 4020 | shortcut_contents.append(fmt::format("Comment={:s}\n", comment)); | ||
| 4021 | shortcut_contents.append(fmt::format("Icon={:s}\n", icon_path)); | ||
| 4022 | shortcut_contents.append(fmt::format("TryExec={:s}\n", command)); | ||
| 4023 | shortcut_contents.append(fmt::format("Exec={:s} {:s}\n", command, arguments)); | ||
| 4024 | shortcut_contents.append(fmt::format("Categories={:s}\n", categories)); | ||
| 4025 | shortcut_contents.append(fmt::format("Keywords={:s}\n", keywords)); | ||
| 4026 | |||
| 4027 | std::ofstream shortcut_stream(shortcut_path); | ||
| 4028 | if (!shortcut_stream.is_open()) { | ||
| 4029 | LOG_WARNING(Common, "Failed to create file {:s}", shortcut_path); | ||
| 4030 | return false; | ||
| 4031 | } | ||
| 4032 | shortcut_stream << shortcut_contents; | ||
| 4033 | shortcut_stream.close(); | ||
| 4034 | |||
| 4035 | return true; | ||
| 4036 | #elif defined(WIN32) | ||
| 4037 | IShellLinkW* shell_link; | ||
| 4038 | auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, | ||
| 4039 | (void**)&shell_link); | ||
| 4040 | if (FAILED(hres)) { | ||
| 4041 | return false; | ||
| 4042 | } | ||
| 4043 | shell_link->SetPath( | ||
| 4044 | Common::UTF8ToUTF16W(command).data()); // Path to the object we are referring to | ||
| 4045 | shell_link->SetArguments(Common::UTF8ToUTF16W(arguments).data()); | ||
| 4046 | shell_link->SetDescription(Common::UTF8ToUTF16W(comment).data()); | ||
| 4047 | shell_link->SetIconLocation(Common::UTF8ToUTF16W(icon_path).data(), 0); | ||
| 4048 | |||
| 4049 | IPersistFile* persist_file; | ||
| 4050 | hres = shell_link->QueryInterface(IID_IPersistFile, (void**)&persist_file); | ||
| 4051 | if (FAILED(hres)) { | ||
| 4052 | return false; | ||
| 4053 | } | ||
| 4054 | |||
| 4055 | hres = persist_file->Save(Common::UTF8ToUTF16W(shortcut_path).data(), TRUE); | ||
| 4056 | if (FAILED(hres)) { | ||
| 4057 | return false; | ||
| 4058 | } | ||
| 4059 | |||
| 4060 | persist_file->Release(); | ||
| 4061 | shell_link->Release(); | ||
| 4062 | |||
| 4063 | return true; | ||
| 4064 | #endif | ||
| 4065 | return false; | ||
| 4066 | } | ||
| 4067 | |||
| 4068 | void GMainWindow::OnLoadAmiibo() { | 4098 | void GMainWindow::OnLoadAmiibo() { |
| 4069 | if (emu_thread == nullptr || !emu_thread->IsRunning()) { | 4099 | if (emu_thread == nullptr || !emu_thread->IsRunning()) { |
| 4070 | return; | 4100 | return; |
| @@ -4103,7 +4133,6 @@ void GMainWindow::OnLoadAmiibo() { | |||
| 4103 | bool GMainWindow::question(QWidget* parent, const QString& title, const QString& text, | 4133 | bool GMainWindow::question(QWidget* parent, const QString& title, const QString& text, |
| 4104 | QMessageBox::StandardButtons buttons, | 4134 | QMessageBox::StandardButtons buttons, |
| 4105 | QMessageBox::StandardButton defaultButton) { | 4135 | QMessageBox::StandardButton defaultButton) { |
| 4106 | |||
| 4107 | QMessageBox* box_dialog = new QMessageBox(parent); | 4136 | QMessageBox* box_dialog = new QMessageBox(parent); |
| 4108 | box_dialog->setWindowTitle(title); | 4137 | box_dialog->setWindowTitle(title); |
| 4109 | box_dialog->setText(text); | 4138 | box_dialog->setText(text); |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 19740cc52..49ee1e1d2 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <optional> | 7 | #include <optional> |
| 8 | 8 | ||
| 9 | #include <filesystem> | ||
| 9 | #include <QMainWindow> | 10 | #include <QMainWindow> |
| 10 | #include <QMessageBox> | 11 | #include <QMessageBox> |
| 11 | #include <QPushButton> | 12 | #include <QPushButton> |
| @@ -174,6 +175,13 @@ class GMainWindow : public QMainWindow { | |||
| 174 | UI_EMU_STOPPING, | 175 | UI_EMU_STOPPING, |
| 175 | }; | 176 | }; |
| 176 | 177 | ||
| 178 | enum { | ||
| 179 | CREATE_SHORTCUT_MSGBOX_FULLSCREEN_YES, | ||
| 180 | CREATE_SHORTCUT_MSGBOX_SUCCESS, | ||
| 181 | CREATE_SHORTCUT_MSGBOX_ERROR, | ||
| 182 | CREATE_SHORTCUT_MSGBOX_APPVOLATILE_WARNING, | ||
| 183 | }; | ||
| 184 | |||
| 177 | public: | 185 | public: |
| 178 | void filterBarSetChecked(bool state); | 186 | void filterBarSetChecked(bool state); |
| 179 | void UpdateUITheme(); | 187 | void UpdateUITheme(); |
| @@ -457,11 +465,14 @@ private: | |||
| 457 | bool ConfirmShutdownGame(); | 465 | bool ConfirmShutdownGame(); |
| 458 | 466 | ||
| 459 | QString GetTasStateDescription() const; | 467 | QString GetTasStateDescription() const; |
| 460 | bool CreateShortcut(const std::string& shortcut_path, const std::string& title, | 468 | bool CreateShortcutMessagesGUI(QWidget* parent, int imsg, const QString& game_title); |
| 461 | const std::string& comment, const std::string& icon_path, | 469 | bool MakeShortcutIcoPath(const u64 program_id, const std::string_view game_file_name, |
| 462 | const std::string& command, const std::string& arguments, | 470 | std::filesystem::path& out_icon_path); |
| 463 | const std::string& categories, const std::string& keywords); | 471 | bool CreateShortcutLink(const std::filesystem::path& shortcut_path, const std::string& comment, |
| 464 | 472 | const std::filesystem::path& icon_path, | |
| 473 | const std::filesystem::path& command, const std::string& arguments, | ||
| 474 | const std::string& categories, const std::string& keywords, | ||
| 475 | const std::string& name); | ||
| 465 | /** | 476 | /** |
| 466 | * Mimic the behavior of QMessageBox::question but link controller navigation to the dialog | 477 | * Mimic the behavior of QMessageBox::question but link controller navigation to the dialog |
| 467 | * The only difference is that it returns a boolean. | 478 | * The only difference is that it returns a boolean. |
diff --git a/src/yuzu/util/util.cpp b/src/yuzu/util/util.cpp index f2854c8ec..e22cf84bf 100644 --- a/src/yuzu/util/util.cpp +++ b/src/yuzu/util/util.cpp | |||
| @@ -4,7 +4,10 @@ | |||
| 4 | #include <array> | 4 | #include <array> |
| 5 | #include <cmath> | 5 | #include <cmath> |
| 6 | #include <QPainter> | 6 | #include <QPainter> |
| 7 | |||
| 8 | #include "common/logging/log.h" | ||
| 7 | #include "yuzu/util/util.h" | 9 | #include "yuzu/util/util.h" |
| 10 | |||
| 8 | #ifdef _WIN32 | 11 | #ifdef _WIN32 |
| 9 | #include <windows.h> | 12 | #include <windows.h> |
| 10 | #include "common/fs/file.h" | 13 | #include "common/fs/file.h" |
| @@ -42,7 +45,7 @@ QPixmap CreateCirclePixmapFromColor(const QColor& color) { | |||
| 42 | return circle_pixmap; | 45 | return circle_pixmap; |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | bool SaveIconToFile(const std::string_view path, const QImage& image) { | 48 | bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image) { |
| 46 | #if defined(WIN32) | 49 | #if defined(WIN32) |
| 47 | #pragma pack(push, 2) | 50 | #pragma pack(push, 2) |
| 48 | struct IconDir { | 51 | struct IconDir { |
| @@ -73,7 +76,7 @@ bool SaveIconToFile(const std::string_view path, const QImage& image) { | |||
| 73 | .id_count = static_cast<WORD>(scale_sizes.size()), | 76 | .id_count = static_cast<WORD>(scale_sizes.size()), |
| 74 | }; | 77 | }; |
| 75 | 78 | ||
| 76 | Common::FS::IOFile icon_file(path, Common::FS::FileAccessMode::Write, | 79 | Common::FS::IOFile icon_file(icon_path.string(), Common::FS::FileAccessMode::Write, |
| 77 | Common::FS::FileType::BinaryFile); | 80 | Common::FS::FileType::BinaryFile); |
| 78 | if (!icon_file.IsOpen()) { | 81 | if (!icon_file.IsOpen()) { |
| 79 | return false; | 82 | return false; |
| @@ -135,6 +138,14 @@ bool SaveIconToFile(const std::string_view path, const QImage& image) { | |||
| 135 | icon_file.Close(); | 138 | icon_file.Close(); |
| 136 | 139 | ||
| 137 | return true; | 140 | return true; |
| 141 | #elif defined(__linux__) || defined(__FreeBSD__) | ||
| 142 | // Convert and write the icon as a PNG | ||
| 143 | if (!image.save(QString::fromStdString(icon_path.string()))) { | ||
| 144 | LOG_ERROR(Frontend, "Could not write icon as PNG to file"); | ||
| 145 | } else { | ||
| 146 | LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string()); | ||
| 147 | } | ||
| 148 | return true; | ||
| 138 | #else | 149 | #else |
| 139 | return false; | 150 | return false; |
| 140 | #endif | 151 | #endif |
diff --git a/src/yuzu/util/util.h b/src/yuzu/util/util.h index 09c14ce3f..4094cf6c2 100644 --- a/src/yuzu/util/util.h +++ b/src/yuzu/util/util.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <filesystem> | ||
| 6 | #include <QFont> | 7 | #include <QFont> |
| 7 | #include <QString> | 8 | #include <QString> |
| 8 | 9 | ||
| @@ -25,4 +26,4 @@ | |||
| 25 | * @param image The image to save | 26 | * @param image The image to save |
| 26 | * @return bool If the operation succeeded | 27 | * @return bool If the operation succeeded |
| 27 | */ | 28 | */ |
| 28 | [[nodiscard]] bool SaveIconToFile(const std::string_view path, const QImage& image); | 29 | [[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image); |