Compare commits
65 Commits
__refs_pul
...
__refs_pul
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b417b8562e | ||
|
|
45ea712d39 | ||
|
|
f463ef7dae | ||
|
|
95c5b715b1 | ||
|
|
8bf46f48f8 | ||
|
|
9d7671ec3b | ||
|
|
5d0a051abb | ||
|
|
4c84bce171 | ||
|
|
d8eb37fbec | ||
|
|
ef7d44e243 | ||
|
|
f71140fbd9 | ||
|
|
0792139a5f | ||
|
|
4467fd9993 | ||
|
|
1462db4694 | ||
|
|
44af2e32a4 | ||
|
|
3c88547c74 | ||
|
|
1fe003113e | ||
|
|
cef7aaa8ec | ||
|
|
005f0eb083 | ||
|
|
b41006004b | ||
|
|
408a9cd50d | ||
|
|
d2b62ae401 | ||
|
|
9cd698e8ad | ||
|
|
68f6f2671b | ||
|
|
95ceae40e6 | ||
|
|
5e3695ecaa | ||
|
|
daaf03942f | ||
|
|
c3fbc8d2fe | ||
|
|
657ab0287d | ||
|
|
eaa62aee98 | ||
|
|
87080e71c5 | ||
|
|
b7c7768e0a | ||
|
|
ad1946b893 | ||
|
|
34c448bad4 | ||
|
|
146769f44e | ||
|
|
ae7e9b5469 | ||
|
|
971b89b979 | ||
|
|
7f5ccd0151 | ||
|
|
595d55d485 | ||
|
|
aa89ec9214 | ||
|
|
b94e576653 | ||
|
|
1e3b2328a6 | ||
|
|
272916eeaf | ||
|
|
95cefaf993 | ||
|
|
e146a00345 | ||
|
|
8857911216 | ||
|
|
1a46823ec5 | ||
|
|
5a09fa5012 | ||
|
|
310b6cf4af | ||
|
|
da8df6488d | ||
|
|
14ea16e499 | ||
|
|
22263787e3 | ||
|
|
ff6d35f2c7 | ||
|
|
fbd85417ff | ||
|
|
b8c906f9d1 | ||
|
|
11991fbd7f | ||
|
|
ea8d5ef5e8 | ||
|
|
ddcd89afd4 | ||
|
|
dfa040502a | ||
|
|
0e6b559c98 | ||
|
|
3f407417c1 | ||
|
|
a1dd5dfba5 | ||
|
|
da440da9f5 | ||
|
|
47d0d292d5 | ||
|
|
edd54abee4 |
@@ -35,7 +35,7 @@ DESTDIR="$PWD/AppDir" ninja install
|
||||
rm -vf AppDir/usr/bin/yuzu-cmd AppDir/usr/bin/yuzu-tester
|
||||
|
||||
# Download tools needed to build an AppImage
|
||||
wget -nc https://raw.githubusercontent.com/yuzu-emu/ext-linux-bin/main/gcc/deploy-linux.sh
|
||||
wget -nc https://raw.githubusercontent.com/yuzu-emu/ext-linux-bin/main/appimage/deploy-linux.sh
|
||||
wget -nc https://raw.githubusercontent.com/yuzu-emu/AppImageKit-checkrt/old/AppRun.sh
|
||||
wget -nc https://github.com/yuzu-emu/ext-linux-bin/raw/main/appimage/exec-x86_64.so
|
||||
# Set executable bit
|
||||
|
||||
79
.github/workflows/android-build.yml
vendored
Normal file
79
.github/workflows/android-build.yml
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
name: 'yuzu-android-build'
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: [ "*" ]
|
||||
|
||||
jobs:
|
||||
android:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
- name: Set up cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
~/.gradle/caches
|
||||
~/.gradle/wrapper
|
||||
~/.ccache
|
||||
key: ${{ runner.os }}-android-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-android-
|
||||
- name: Query tag name
|
||||
uses: olegtarasov/get-tag@v2.1.2
|
||||
id: tagName
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ccache apksigner glslang-dev glslang-tools
|
||||
- name: Build
|
||||
run: ./.ci/scripts/android/build.sh
|
||||
- name: Copy and sign artifacts
|
||||
env:
|
||||
ANDROID_KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
|
||||
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
|
||||
ANDROID_KEYSTORE_PASS: ${{ secrets.ANDROID_KEYSTORE_PASS }}
|
||||
run: ./.ci/scripts/android/upload.sh
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: android
|
||||
path: artifacts/
|
||||
# release steps
|
||||
release-android:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [android]
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/') }}
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
- name: Query tag name
|
||||
uses: olegtarasov/get-tag@v2.1.2
|
||||
id: tagName
|
||||
- name: Create release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.tagName.outputs.tag }}
|
||||
release_name: ${{ steps.tagName.outputs.tag }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Upload artifacts
|
||||
uses: alexellis/upload-assets@0.2.3
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
asset_paths: '["./**/*.apk","./**/*.aab"]'
|
||||
218
.github/workflows/android-merge.js
vendored
Normal file
218
.github/workflows/android-merge.js
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
// Note: This is a GitHub Actions script
|
||||
// It is not meant to be executed directly on your machine without modifications
|
||||
|
||||
const fs = require("fs");
|
||||
// which label to check for changes
|
||||
const CHANGE_LABEL = 'android-merge';
|
||||
// how far back in time should we consider the changes are "recent"? (default: 24 hours)
|
||||
const DETECTION_TIME_FRAME = (parseInt(process.env.DETECTION_TIME_FRAME)) || (24 * 3600 * 1000);
|
||||
|
||||
async function checkBaseChanges(github, context) {
|
||||
// query the commit date of the latest commit on this branch
|
||||
const query = `query($owner:String!, $name:String!, $ref:String!) {
|
||||
repository(name:$name, owner:$owner) {
|
||||
ref(qualifiedName:$ref) {
|
||||
target {
|
||||
... on Commit { id pushedDate oid }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = {
|
||||
owner: context.repo.owner,
|
||||
name: context.repo.repo,
|
||||
ref: 'refs/heads/master',
|
||||
};
|
||||
const result = await github.graphql(query, variables);
|
||||
const pushedAt = result.repository.ref.target.pushedDate;
|
||||
console.log(`Last commit pushed at ${pushedAt}.`);
|
||||
const delta = new Date() - new Date(pushedAt);
|
||||
if (delta <= DETECTION_TIME_FRAME) {
|
||||
console.info('New changes detected, triggering a new build.');
|
||||
return true;
|
||||
}
|
||||
console.info('No new changes detected.');
|
||||
return false;
|
||||
}
|
||||
|
||||
async function checkAndroidChanges(github, context) {
|
||||
if (checkBaseChanges(github, context)) return true;
|
||||
const query = `query($owner:String!, $name:String!, $label:String!) {
|
||||
repository(name:$name, owner:$owner) {
|
||||
pullRequests(labels: [$label], states: OPEN, first: 100) {
|
||||
nodes { number headRepository { pushedAt } }
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = {
|
||||
owner: context.repo.owner,
|
||||
name: context.repo.repo,
|
||||
label: CHANGE_LABEL,
|
||||
};
|
||||
const result = await github.graphql(query, variables);
|
||||
const pulls = result.repository.pullRequests.nodes;
|
||||
for (let i = 0; i < pulls.length; i++) {
|
||||
let pull = pulls[i];
|
||||
if (new Date() - new Date(pull.headRepository.pushedAt) <= DETECTION_TIME_FRAME) {
|
||||
console.info(`${pull.number} updated at ${pull.headRepository.pushedAt}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
console.info("No changes detected in any tagged pull requests.");
|
||||
return false;
|
||||
}
|
||||
|
||||
async function tagAndPush(github, owner, repo, execa, commit=false) {
|
||||
let altToken = process.env.ALT_GITHUB_TOKEN;
|
||||
if (!altToken) {
|
||||
throw `Please set ALT_GITHUB_TOKEN environment variable. This token should have write access to ${owner}/${repo}.`;
|
||||
}
|
||||
const query = `query ($owner:String!, $name:String!) {
|
||||
repository(name:$name, owner:$owner) {
|
||||
refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 10) {
|
||||
nodes { name }
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = {
|
||||
owner: owner,
|
||||
name: repo,
|
||||
};
|
||||
const tags = await github.graphql(query, variables);
|
||||
const tagList = tags.repository.refs.nodes;
|
||||
const lastTag = tagList[0] ? tagList[0].name : 'dummy-0';
|
||||
const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0;
|
||||
const channel = repo.split('-')[1];
|
||||
const newTag = `${channel}-${tagNumber + 1}`;
|
||||
console.log(`New tag: ${newTag}`);
|
||||
if (commit) {
|
||||
let channelName = channel[0].toUpperCase() + channel.slice(1);
|
||||
console.info(`Committing pending commit as ${channelName} #${tagNumber + 1}`);
|
||||
await execa("git", ['commit', '-m', `${channelName} #${tagNumber + 1}`]);
|
||||
}
|
||||
console.info('Pushing tags to GitHub ...');
|
||||
await execa("git", ['tag', newTag]);
|
||||
await execa("git", ['remote', 'add', 'target', `https://${altToken}@github.com/${owner}/${repo}.git`]);
|
||||
await execa("git", ['push', 'target', 'master', '-f']);
|
||||
await execa("git", ['push', 'target', 'master', '--tags']);
|
||||
console.info('Successfully pushed new changes.');
|
||||
}
|
||||
|
||||
async function generateReadme(pulls, context, mergeResults, execa) {
|
||||
let baseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/`;
|
||||
let output =
|
||||
"| Pull Request | Commit | Title | Author | Merged? |\n|----|----|----|----|----|\n";
|
||||
for (let pull of pulls) {
|
||||
let pr = pull.number;
|
||||
let result = mergeResults[pr];
|
||||
output += `| [${pr}](${baseUrl}/pull/${pr}) | [\`${result.rev || "N/A"}\`](${baseUrl}/pull/${pr}/files) | ${pull.title} | [${pull.author.login}](https://github.com/${pull.author.login}/) | ${result.success ? "Yes" : "No"} |\n`;
|
||||
}
|
||||
output +=
|
||||
"\n\nEnd of merge log. You can find the original README.md below the break.\n\n-----\n\n";
|
||||
output += fs.readFileSync("./README.md");
|
||||
fs.writeFileSync("./README.md", output);
|
||||
await execa("git", ["add", "README.md"]);
|
||||
}
|
||||
|
||||
async function fetchPullRequests(pulls, repoUrl, execa) {
|
||||
console.log("::group::Fetch pull requests");
|
||||
for (let pull of pulls) {
|
||||
let pr = pull.number;
|
||||
console.info(`Fetching PR ${pr} ...`);
|
||||
await execa("git", [
|
||||
"fetch",
|
||||
"-f",
|
||||
"--no-recurse-submodules",
|
||||
repoUrl,
|
||||
`pull/${pr}/head:pr-${pr}`,
|
||||
]);
|
||||
}
|
||||
console.log("::endgroup::");
|
||||
}
|
||||
|
||||
async function mergePullRequests(pulls, execa) {
|
||||
let mergeResults = {};
|
||||
console.log("::group::Merge pull requests");
|
||||
await execa("git", ["config", "--global", "user.name", "yuzubot"]);
|
||||
await execa("git", [
|
||||
"config",
|
||||
"--global",
|
||||
"user.email",
|
||||
"yuzu\x40yuzu-emu\x2eorg", // prevent email harvesters from scraping the address
|
||||
]);
|
||||
let hasFailed = false;
|
||||
for (let pull of pulls) {
|
||||
let pr = pull.number;
|
||||
console.info(`Merging PR ${pr} ...`);
|
||||
try {
|
||||
const process1 = execa("git", [
|
||||
"merge",
|
||||
"--squash",
|
||||
"--no-edit",
|
||||
`pr-${pr}`,
|
||||
]);
|
||||
process1.stdout.pipe(process.stdout);
|
||||
await process1;
|
||||
|
||||
const process2 = execa("git", ["commit", "-m", `Merge PR ${pr}`]);
|
||||
process2.stdout.pipe(process.stdout);
|
||||
await process2;
|
||||
|
||||
const process3 = await execa("git", ["rev-parse", "--short", `pr-${pr}`]);
|
||||
mergeResults[pr] = {
|
||||
success: true,
|
||||
rev: process3.stdout,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log(
|
||||
`::error title=#${pr} not merged::Failed to merge pull request: ${pr}: ${err}`
|
||||
);
|
||||
mergeResults[pr] = { success: false };
|
||||
hasFailed = true;
|
||||
await execa("git", ["reset", "--hard"]);
|
||||
}
|
||||
}
|
||||
console.log("::endgroup::");
|
||||
if (hasFailed) {
|
||||
throw 'There are merge failures. Aborting!';
|
||||
}
|
||||
return mergeResults;
|
||||
}
|
||||
|
||||
async function mergebot(github, context, execa) {
|
||||
const query = `query ($owner:String!, $name:String!, $label:String!) {
|
||||
repository(name:$name, owner:$owner) {
|
||||
pullRequests(labels: [$label], states: OPEN, first: 100) {
|
||||
nodes {
|
||||
number title author { login }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = {
|
||||
owner: context.repo.owner,
|
||||
name: context.repo.repo,
|
||||
label: CHANGE_LABEL,
|
||||
};
|
||||
const result = await github.graphql(query, variables);
|
||||
const pulls = result.repository.pullRequests.nodes;
|
||||
let displayList = [];
|
||||
for (let i = 0; i < pulls.length; i++) {
|
||||
let pull = pulls[i];
|
||||
displayList.push({ PR: pull.number, Title: pull.title });
|
||||
}
|
||||
console.info("The following pull requests will be merged:");
|
||||
console.table(displayList);
|
||||
await fetchPullRequests(pulls, "https://github.com/yuzu-emu/yuzu", execa);
|
||||
const mergeResults = await mergePullRequests(pulls, execa);
|
||||
await generateReadme(pulls, context, mergeResults, execa);
|
||||
await tagAndPush(github, context.repo.owner, `${context.repo.repo}-android`, execa, true);
|
||||
}
|
||||
|
||||
module.exports.mergebot = mergebot;
|
||||
module.exports.checkAndroidChanges = checkAndroidChanges;
|
||||
module.exports.tagAndPush = tagAndPush;
|
||||
module.exports.checkBaseChanges = checkBaseChanges;
|
||||
57
.github/workflows/android-publish.yml
vendored
Normal file
57
.github/workflows/android-publish.yml
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
name: yuzu-android-publish
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '37 0 * * *'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
android:
|
||||
description: 'Whether to trigger an Android build (true/false/auto)'
|
||||
required: false
|
||||
default: 'true'
|
||||
|
||||
jobs:
|
||||
android:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.inputs.android != 'false' && github.repository == 'yuzu-emu/yuzu' }}
|
||||
steps:
|
||||
# this checkout is required to make sure the GitHub Actions scripts are available
|
||||
- uses: actions/checkout@v3
|
||||
name: Pre-checkout
|
||||
with:
|
||||
submodules: false
|
||||
- uses: actions/github-script@v6
|
||||
id: check-changes
|
||||
name: 'Check for new changes'
|
||||
env:
|
||||
# 24 hours
|
||||
DETECTION_TIME_FRAME: 86400000
|
||||
with:
|
||||
script: |
|
||||
if (context.payload.inputs && context.payload.inputs.android === 'true') return true;
|
||||
const checkAndroidChanges = require('./.github/workflows/android-merge.js').checkAndroidChanges;
|
||||
return checkAndroidChanges(github, context);
|
||||
- run: npm install execa@5
|
||||
if: ${{ steps.check-changes.outputs.result == 'true' }}
|
||||
- uses: actions/checkout@v3
|
||||
name: Checkout
|
||||
if: ${{ steps.check-changes.outputs.result == 'true' }}
|
||||
with:
|
||||
path: 'yuzu-merge'
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
token: ${{ secrets.ALT_GITHUB_TOKEN }}
|
||||
- uses: actions/github-script@v5
|
||||
name: 'Check and merge Android changes'
|
||||
if: ${{ steps.check-changes.outputs.result == 'true' }}
|
||||
env:
|
||||
ALT_GITHUB_TOKEN: ${{ secrets.ALT_GITHUB_TOKEN }}
|
||||
with:
|
||||
script: |
|
||||
const execa = require("execa");
|
||||
const mergebot = require('./.github/workflows/android-merge.js').mergebot;
|
||||
process.chdir('${{ github.workspace }}/yuzu-merge');
|
||||
mergebot(github, context, execa);
|
||||
4
.github/workflows/verify.yml
vendored
4
.github/workflows/verify.yml
vendored
@@ -129,11 +129,12 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
- name: set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'adopt'
|
||||
distribution: 'temurin'
|
||||
- name: Set up cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
@@ -151,7 +152,6 @@ jobs:
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ccache apksigner glslang-dev glslang-tools
|
||||
git -C ./externals/vcpkg/ fetch --all --unshallow
|
||||
- name: Build
|
||||
run: ./.ci/scripts/android/build.sh
|
||||
- name: Copy and sign artifacts
|
||||
|
||||
@@ -489,7 +489,7 @@ if (ENABLE_SDL2)
|
||||
if (YUZU_USE_BUNDLED_SDL2)
|
||||
# Detect toolchain and platform
|
||||
if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
|
||||
set(SDL2_VER "SDL2-2.28.0")
|
||||
set(SDL2_VER "SDL2-2.28.1")
|
||||
else()
|
||||
message(FATAL_ERROR "No bundled SDL2 binaries for your toolchain. Disable YUZU_USE_BUNDLED_SDL2 and provide your own.")
|
||||
endif()
|
||||
|
||||
2
externals/SDL
vendored
2
externals/SDL
vendored
Submodule externals/SDL updated: 491fba1d06...116a5344ff
@@ -54,6 +54,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
<activity
|
||||
android:name="org.yuzu.yuzu_emu.activities.EmulationActivity"
|
||||
android:theme="@style/Theme.Yuzu.Main"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="userLandscape"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode"
|
||||
|
||||
@@ -34,11 +34,14 @@ import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.yuzu.yuzu_emu.NativeLibrary
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding
|
||||
import org.yuzu.yuzu_emu.features.settings.model.BooleanSetting
|
||||
import org.yuzu.yuzu_emu.features.settings.model.IntSetting
|
||||
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
||||
import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel
|
||||
import org.yuzu.yuzu_emu.model.Game
|
||||
import org.yuzu.yuzu_emu.utils.ControllerMappingHelper
|
||||
@@ -47,6 +50,7 @@ import org.yuzu.yuzu_emu.utils.InputHandler
|
||||
import org.yuzu.yuzu_emu.utils.MemoryUtil
|
||||
import org.yuzu.yuzu_emu.utils.NfcReader
|
||||
import org.yuzu.yuzu_emu.utils.ThemeHelper
|
||||
import java.text.NumberFormat
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
||||
@@ -106,17 +110,26 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
||||
inputHandler = InputHandler()
|
||||
inputHandler.initialize()
|
||||
|
||||
val memoryUtil = MemoryUtil(this)
|
||||
if (memoryUtil.isLessThan(8, MemoryUtil.Gb)) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(
|
||||
R.string.device_memory_inadequate,
|
||||
memoryUtil.getDeviceRAM(),
|
||||
"8 ${getString(R.string.memory_gigabyte)}"
|
||||
),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||
if (!preferences.getBoolean(Settings.PREF_MEMORY_WARNING_SHOWN, false)) {
|
||||
if (MemoryUtil.isLessThan(MemoryUtil.REQUIRED_MEMORY, MemoryUtil.Gb)) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(
|
||||
R.string.device_memory_inadequate,
|
||||
MemoryUtil.getDeviceRAM(),
|
||||
getString(
|
||||
R.string.memory_formatted,
|
||||
NumberFormat.getInstance().format(MemoryUtil.REQUIRED_MEMORY),
|
||||
getString(R.string.memory_gigabyte)
|
||||
)
|
||||
),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
preferences.edit()
|
||||
.putBoolean(Settings.PREF_MEMORY_WARNING_SHOWN, true)
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
|
||||
// Start a foreground service to prevent the app from getting killed in the background
|
||||
|
||||
@@ -110,25 +110,38 @@ class Settings {
|
||||
const val SECTION_THEME = "Theme"
|
||||
const val SECTION_DEBUG = "Debug"
|
||||
|
||||
const val PREF_OVERLAY_INIT = "OverlayInit"
|
||||
const val PREF_MEMORY_WARNING_SHOWN = "MemoryWarningShown"
|
||||
|
||||
const val PREF_OVERLAY_VERSION = "OverlayVersion"
|
||||
const val PREF_LANDSCAPE_OVERLAY_VERSION = "LandscapeOverlayVersion"
|
||||
const val PREF_PORTRAIT_OVERLAY_VERSION = "PortraitOverlayVersion"
|
||||
const val PREF_FOLDABLE_OVERLAY_VERSION = "FoldableOverlayVersion"
|
||||
val overlayLayoutPrefs = listOf(
|
||||
PREF_LANDSCAPE_OVERLAY_VERSION,
|
||||
PREF_PORTRAIT_OVERLAY_VERSION,
|
||||
PREF_FOLDABLE_OVERLAY_VERSION
|
||||
)
|
||||
|
||||
const val PREF_CONTROL_SCALE = "controlScale"
|
||||
const val PREF_CONTROL_OPACITY = "controlOpacity"
|
||||
const val PREF_TOUCH_ENABLED = "isTouchEnabled"
|
||||
const val PREF_BUTTON_TOGGLE_0 = "buttonToggle0"
|
||||
const val PREF_BUTTON_TOGGLE_1 = "buttonToggle1"
|
||||
const val PREF_BUTTON_TOGGLE_2 = "buttonToggle2"
|
||||
const val PREF_BUTTON_TOGGLE_3 = "buttonToggle3"
|
||||
const val PREF_BUTTON_TOGGLE_4 = "buttonToggle4"
|
||||
const val PREF_BUTTON_TOGGLE_5 = "buttonToggle5"
|
||||
const val PREF_BUTTON_TOGGLE_6 = "buttonToggle6"
|
||||
const val PREF_BUTTON_TOGGLE_7 = "buttonToggle7"
|
||||
const val PREF_BUTTON_TOGGLE_8 = "buttonToggle8"
|
||||
const val PREF_BUTTON_TOGGLE_9 = "buttonToggle9"
|
||||
const val PREF_BUTTON_TOGGLE_10 = "buttonToggle10"
|
||||
const val PREF_BUTTON_TOGGLE_11 = "buttonToggle11"
|
||||
const val PREF_BUTTON_TOGGLE_12 = "buttonToggle12"
|
||||
const val PREF_BUTTON_TOGGLE_13 = "buttonToggle13"
|
||||
const val PREF_BUTTON_TOGGLE_14 = "buttonToggle14"
|
||||
const val PREF_BUTTON_A = "buttonToggle0"
|
||||
const val PREF_BUTTON_B = "buttonToggle1"
|
||||
const val PREF_BUTTON_X = "buttonToggle2"
|
||||
const val PREF_BUTTON_Y = "buttonToggle3"
|
||||
const val PREF_BUTTON_L = "buttonToggle4"
|
||||
const val PREF_BUTTON_R = "buttonToggle5"
|
||||
const val PREF_BUTTON_ZL = "buttonToggle6"
|
||||
const val PREF_BUTTON_ZR = "buttonToggle7"
|
||||
const val PREF_BUTTON_PLUS = "buttonToggle8"
|
||||
const val PREF_BUTTON_MINUS = "buttonToggle9"
|
||||
const val PREF_BUTTON_DPAD = "buttonToggle10"
|
||||
const val PREF_STICK_L = "buttonToggle11"
|
||||
const val PREF_STICK_R = "buttonToggle12"
|
||||
const val PREF_BUTTON_STICK_L = "buttonToggle13"
|
||||
const val PREF_BUTTON_STICK_R = "buttonToggle14"
|
||||
const val PREF_BUTTON_HOME = "buttonToggle15"
|
||||
const val PREF_BUTTON_SCREENSHOT = "buttonToggle16"
|
||||
|
||||
const val PREF_MENU_SETTINGS_JOYSTICK_REL_CENTER = "EmulationMenuSettings_JoystickRelCenter"
|
||||
const val PREF_MENU_SETTINGS_DPAD_SLIDE = "EmulationMenuSettings_DpadSlideEnable"
|
||||
@@ -143,6 +156,30 @@ class Settings {
|
||||
|
||||
private val configFileSectionsMap: MutableMap<String, List<String>> = HashMap()
|
||||
|
||||
val overlayPreferences = listOf(
|
||||
PREF_OVERLAY_VERSION,
|
||||
PREF_CONTROL_SCALE,
|
||||
PREF_CONTROL_OPACITY,
|
||||
PREF_TOUCH_ENABLED,
|
||||
PREF_BUTTON_A,
|
||||
PREF_BUTTON_B,
|
||||
PREF_BUTTON_X,
|
||||
PREF_BUTTON_Y,
|
||||
PREF_BUTTON_L,
|
||||
PREF_BUTTON_R,
|
||||
PREF_BUTTON_ZL,
|
||||
PREF_BUTTON_ZR,
|
||||
PREF_BUTTON_PLUS,
|
||||
PREF_BUTTON_MINUS,
|
||||
PREF_BUTTON_DPAD,
|
||||
PREF_STICK_L,
|
||||
PREF_STICK_R,
|
||||
PREF_BUTTON_HOME,
|
||||
PREF_BUTTON_SCREENSHOT,
|
||||
PREF_BUTTON_STICK_L,
|
||||
PREF_BUTTON_STICK_R
|
||||
)
|
||||
|
||||
const val LayoutOption_Unspecified = 0
|
||||
const val LayoutOption_MobilePortrait = 4
|
||||
const val LayoutOption_MobileLandscape = 5
|
||||
|
||||
@@ -212,9 +212,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
}
|
||||
if (!isInFoldableLayout) {
|
||||
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
binding.surfaceInputOverlay.orientation = InputOverlay.PORTRAIT
|
||||
binding.surfaceInputOverlay.layout = InputOverlay.PORTRAIT
|
||||
} else {
|
||||
binding.surfaceInputOverlay.orientation = InputOverlay.LANDSCAPE
|
||||
binding.surfaceInputOverlay.layout = InputOverlay.LANDSCAPE
|
||||
}
|
||||
}
|
||||
if (!binding.surfaceInputOverlay.isInEditMode) {
|
||||
@@ -260,7 +260,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
.remove(Settings.PREF_CONTROL_SCALE)
|
||||
.remove(Settings.PREF_CONTROL_OPACITY)
|
||||
.apply()
|
||||
binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.resetButtonPlacement() }
|
||||
binding.surfaceInputOverlay.post {
|
||||
binding.surfaceInputOverlay.resetLayoutVisibilityAndPlacement()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateShowFpsOverlay() {
|
||||
@@ -337,7 +339,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
binding.inGameMenu.layoutParams.height = it.bounds.bottom
|
||||
|
||||
isInFoldableLayout = true
|
||||
binding.surfaceInputOverlay.orientation = InputOverlay.FOLDABLE
|
||||
binding.surfaceInputOverlay.layout = InputOverlay.FOLDABLE
|
||||
refreshInputOverlay()
|
||||
}
|
||||
}
|
||||
@@ -410,9 +412,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
R.id.menu_toggle_controls -> {
|
||||
val preferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||
val optionsArray = BooleanArray(15)
|
||||
for (i in 0..14) {
|
||||
optionsArray[i] = preferences.getBoolean("buttonToggle$i", i < 13)
|
||||
val optionsArray = BooleanArray(Settings.overlayPreferences.size)
|
||||
Settings.overlayPreferences.forEachIndexed { i, _ ->
|
||||
optionsArray[i] = preferences.getBoolean("buttonToggle$i", i < 15)
|
||||
}
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(requireContext())
|
||||
@@ -436,7 +438,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
.setOnClickListener {
|
||||
val isChecked = !optionsArray[0]
|
||||
for (i in 0..14) {
|
||||
Settings.overlayPreferences.forEachIndexed { i, _ ->
|
||||
optionsArray[i] = isChecked
|
||||
dialog.listView.setItemChecked(i, isChecked)
|
||||
preferences.edit()
|
||||
|
||||
@@ -51,15 +51,23 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
|
||||
private lateinit var windowInsets: WindowInsets
|
||||
|
||||
var orientation = LANDSCAPE
|
||||
var layout = LANDSCAPE
|
||||
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
super.onLayout(changed, left, top, right, bottom)
|
||||
|
||||
windowInsets = rootWindowInsets
|
||||
|
||||
if (!preferences.getBoolean("${Settings.PREF_OVERLAY_INIT}$orientation", false)) {
|
||||
defaultOverlay()
|
||||
val overlayVersion = preferences.getInt(Settings.PREF_OVERLAY_VERSION, 0)
|
||||
if (overlayVersion != OVERLAY_VERSION) {
|
||||
resetAllLayouts()
|
||||
} else {
|
||||
val layoutIndex = overlayLayouts.indexOf(layout)
|
||||
val currentLayoutVersion =
|
||||
preferences.getInt(Settings.overlayLayoutPrefs[layoutIndex], 0)
|
||||
if (currentLayoutVersion != overlayLayoutVersions[layoutIndex]) {
|
||||
resetCurrentLayout()
|
||||
}
|
||||
}
|
||||
|
||||
// Load the controls.
|
||||
@@ -266,10 +274,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
MotionEvent.ACTION_POINTER_UP -> if (buttonBeingConfigured === button) {
|
||||
// Persist button position by saving new place.
|
||||
saveControlPosition(
|
||||
buttonBeingConfigured!!.buttonId,
|
||||
buttonBeingConfigured!!.prefId,
|
||||
buttonBeingConfigured!!.bounds.centerX(),
|
||||
buttonBeingConfigured!!.bounds.centerY(),
|
||||
orientation
|
||||
layout
|
||||
)
|
||||
buttonBeingConfigured = null
|
||||
}
|
||||
@@ -299,10 +307,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
MotionEvent.ACTION_POINTER_UP -> if (dpadBeingConfigured === dpad) {
|
||||
// Persist button position by saving new place.
|
||||
saveControlPosition(
|
||||
dpadBeingConfigured!!.upId,
|
||||
Settings.PREF_BUTTON_DPAD,
|
||||
dpadBeingConfigured!!.bounds.centerX(),
|
||||
dpadBeingConfigured!!.bounds.centerY(),
|
||||
orientation
|
||||
layout
|
||||
)
|
||||
dpadBeingConfigured = null
|
||||
}
|
||||
@@ -330,10 +338,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
MotionEvent.ACTION_UP,
|
||||
MotionEvent.ACTION_POINTER_UP -> if (joystickBeingConfigured != null) {
|
||||
saveControlPosition(
|
||||
joystickBeingConfigured!!.buttonId,
|
||||
joystickBeingConfigured!!.prefId,
|
||||
joystickBeingConfigured!!.bounds.centerX(),
|
||||
joystickBeingConfigured!!.bounds.centerY(),
|
||||
orientation
|
||||
layout
|
||||
)
|
||||
joystickBeingConfigured = null
|
||||
}
|
||||
@@ -343,9 +351,9 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
return true
|
||||
}
|
||||
|
||||
private fun addOverlayControls(orientation: String) {
|
||||
private fun addOverlayControls(layout: String) {
|
||||
val windowSize = getSafeScreenSize(context)
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_0, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_A, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -353,11 +361,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_a,
|
||||
R.drawable.facebutton_a_depressed,
|
||||
ButtonType.BUTTON_A,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_A,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_1, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_B, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -365,11 +374,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_b,
|
||||
R.drawable.facebutton_b_depressed,
|
||||
ButtonType.BUTTON_B,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_B,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_2, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_X, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -377,11 +387,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_x,
|
||||
R.drawable.facebutton_x_depressed,
|
||||
ButtonType.BUTTON_X,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_X,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_3, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_Y, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -389,11 +400,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_y,
|
||||
R.drawable.facebutton_y_depressed,
|
||||
ButtonType.BUTTON_Y,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_Y,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_4, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_L, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -401,11 +413,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.l_shoulder,
|
||||
R.drawable.l_shoulder_depressed,
|
||||
ButtonType.TRIGGER_L,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_L,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_5, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_R, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -413,11 +426,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.r_shoulder,
|
||||
R.drawable.r_shoulder_depressed,
|
||||
ButtonType.TRIGGER_R,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_R,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_6, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_ZL, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -425,11 +439,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.zl_trigger,
|
||||
R.drawable.zl_trigger_depressed,
|
||||
ButtonType.TRIGGER_ZL,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_ZL,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_7, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_ZR, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -437,11 +452,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.zr_trigger,
|
||||
R.drawable.zr_trigger_depressed,
|
||||
ButtonType.TRIGGER_ZR,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_ZR,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_8, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_PLUS, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -449,11 +465,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_plus,
|
||||
R.drawable.facebutton_plus_depressed,
|
||||
ButtonType.BUTTON_PLUS,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_PLUS,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_9, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_MINUS, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -461,11 +478,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_minus,
|
||||
R.drawable.facebutton_minus_depressed,
|
||||
ButtonType.BUTTON_MINUS,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_MINUS,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_10, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_DPAD, true)) {
|
||||
overlayDpads.add(
|
||||
initializeOverlayDpad(
|
||||
context,
|
||||
@@ -473,11 +491,11 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.dpad_standard,
|
||||
R.drawable.dpad_standard_cardinal_depressed,
|
||||
R.drawable.dpad_standard_diagonal_depressed,
|
||||
orientation
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_11, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_STICK_L, true)) {
|
||||
overlayJoysticks.add(
|
||||
initializeOverlayJoystick(
|
||||
context,
|
||||
@@ -487,11 +505,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.joystick_depressed,
|
||||
StickType.STICK_L,
|
||||
ButtonType.STICK_L,
|
||||
orientation
|
||||
Settings.PREF_STICK_L,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_12, true)) {
|
||||
if (preferences.getBoolean(Settings.PREF_STICK_R, true)) {
|
||||
overlayJoysticks.add(
|
||||
initializeOverlayJoystick(
|
||||
context,
|
||||
@@ -501,11 +520,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.joystick_depressed,
|
||||
StickType.STICK_R,
|
||||
ButtonType.STICK_R,
|
||||
orientation
|
||||
Settings.PREF_STICK_R,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_13, false)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_HOME, false)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -513,11 +533,12 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_home,
|
||||
R.drawable.facebutton_home_depressed,
|
||||
ButtonType.BUTTON_HOME,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_HOME,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_14, false)) {
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_SCREENSHOT, false)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
@@ -525,7 +546,34 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.drawable.facebutton_screenshot,
|
||||
R.drawable.facebutton_screenshot_depressed,
|
||||
ButtonType.BUTTON_CAPTURE,
|
||||
orientation
|
||||
Settings.PREF_BUTTON_SCREENSHOT,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_STICK_L, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
windowSize,
|
||||
R.drawable.button_l3,
|
||||
R.drawable.button_l3_depressed,
|
||||
ButtonType.STICK_L,
|
||||
Settings.PREF_BUTTON_STICK_L,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
if (preferences.getBoolean(Settings.PREF_BUTTON_STICK_R, true)) {
|
||||
overlayButtons.add(
|
||||
initializeOverlayButton(
|
||||
context,
|
||||
windowSize,
|
||||
R.drawable.button_r3,
|
||||
R.drawable.button_r3_depressed,
|
||||
ButtonType.STICK_R,
|
||||
Settings.PREF_BUTTON_STICK_R,
|
||||
layout
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -539,18 +587,18 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
|
||||
// Add all the enabled overlay items back to the HashSet.
|
||||
if (EmulationMenuSettings.showOverlay) {
|
||||
addOverlayControls(orientation)
|
||||
addOverlayControls(layout)
|
||||
}
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private fun saveControlPosition(sharedPrefsId: Int, x: Int, y: Int, orientation: String) {
|
||||
private fun saveControlPosition(prefId: String, x: Int, y: Int, layout: String) {
|
||||
val windowSize = getSafeScreenSize(context)
|
||||
val min = windowSize.first
|
||||
val max = windowSize.second
|
||||
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).edit()
|
||||
.putFloat("$sharedPrefsId-X$orientation", (x - min.x).toFloat() / max.x)
|
||||
.putFloat("$sharedPrefsId-Y$orientation", (y - min.y).toFloat() / max.y)
|
||||
.putFloat("$prefId-X$layout", (x - min.x).toFloat() / max.x)
|
||||
.putFloat("$prefId-Y$layout", (y - min.y).toFloat() / max.y)
|
||||
.apply()
|
||||
}
|
||||
|
||||
@@ -558,19 +606,31 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
inEditMode = editMode
|
||||
}
|
||||
|
||||
private fun defaultOverlay() {
|
||||
if (!preferences.getBoolean("${Settings.PREF_OVERLAY_INIT}$orientation", false)) {
|
||||
defaultOverlayByLayout(orientation)
|
||||
}
|
||||
|
||||
resetButtonPlacement()
|
||||
private fun resetCurrentLayout() {
|
||||
defaultOverlayByLayout(layout)
|
||||
val layoutIndex = overlayLayouts.indexOf(layout)
|
||||
preferences.edit()
|
||||
.putBoolean("${Settings.PREF_OVERLAY_INIT}$orientation", true)
|
||||
.putInt(Settings.overlayLayoutPrefs[layoutIndex], overlayLayoutVersions[layoutIndex])
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun resetButtonPlacement() {
|
||||
defaultOverlayByLayout(orientation)
|
||||
private fun resetAllLayouts() {
|
||||
val editor = preferences.edit()
|
||||
overlayLayouts.forEachIndexed { i, layout ->
|
||||
defaultOverlayByLayout(layout)
|
||||
editor.putInt(Settings.overlayLayoutPrefs[i], overlayLayoutVersions[i])
|
||||
}
|
||||
editor.putInt(Settings.PREF_OVERLAY_VERSION, OVERLAY_VERSION)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun resetLayoutVisibilityAndPlacement() {
|
||||
defaultOverlayByLayout(layout)
|
||||
val editor = preferences.edit()
|
||||
Settings.overlayPreferences.forEachIndexed { _, pref ->
|
||||
editor.remove(pref)
|
||||
}
|
||||
editor.apply()
|
||||
refreshControls()
|
||||
}
|
||||
|
||||
@@ -604,7 +664,11 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.integer.SWITCH_STICK_R_X,
|
||||
R.integer.SWITCH_STICK_R_Y,
|
||||
R.integer.SWITCH_STICK_L_X,
|
||||
R.integer.SWITCH_STICK_L_Y
|
||||
R.integer.SWITCH_STICK_L_Y,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_X,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_Y,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_X,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_Y
|
||||
)
|
||||
|
||||
private val portraitResources = arrayOf(
|
||||
@@ -637,7 +701,11 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.integer.SWITCH_STICK_R_X_PORTRAIT,
|
||||
R.integer.SWITCH_STICK_R_Y_PORTRAIT,
|
||||
R.integer.SWITCH_STICK_L_X_PORTRAIT,
|
||||
R.integer.SWITCH_STICK_L_Y_PORTRAIT
|
||||
R.integer.SWITCH_STICK_L_Y_PORTRAIT,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_X_PORTRAIT,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_Y_PORTRAIT,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_X_PORTRAIT,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_Y_PORTRAIT
|
||||
)
|
||||
|
||||
private val foldableResources = arrayOf(
|
||||
@@ -670,139 +738,159 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
R.integer.SWITCH_STICK_R_X_FOLDABLE,
|
||||
R.integer.SWITCH_STICK_R_Y_FOLDABLE,
|
||||
R.integer.SWITCH_STICK_L_X_FOLDABLE,
|
||||
R.integer.SWITCH_STICK_L_Y_FOLDABLE
|
||||
R.integer.SWITCH_STICK_L_Y_FOLDABLE,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_X_FOLDABLE,
|
||||
R.integer.SWITCH_BUTTON_STICK_L_Y_FOLDABLE,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_X_FOLDABLE,
|
||||
R.integer.SWITCH_BUTTON_STICK_R_Y_FOLDABLE
|
||||
)
|
||||
|
||||
private fun getResourceValue(orientation: String, position: Int): Float {
|
||||
return when (orientation) {
|
||||
private fun getResourceValue(layout: String, position: Int): Float {
|
||||
return when (layout) {
|
||||
PORTRAIT -> resources.getInteger(portraitResources[position]).toFloat() / 1000
|
||||
FOLDABLE -> resources.getInteger(foldableResources[position]).toFloat() / 1000
|
||||
else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000
|
||||
}
|
||||
}
|
||||
|
||||
private fun defaultOverlayByLayout(orientation: String) {
|
||||
private fun defaultOverlayByLayout(layout: String) {
|
||||
// Each value represents the position of the button in relation to the screen size without insets.
|
||||
preferences.edit()
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_A.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 0)
|
||||
"${Settings.PREF_BUTTON_A}-X$layout",
|
||||
getResourceValue(layout, 0)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_A.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 1)
|
||||
"${Settings.PREF_BUTTON_A}-Y$layout",
|
||||
getResourceValue(layout, 1)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_B.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 2)
|
||||
"${Settings.PREF_BUTTON_B}-X$layout",
|
||||
getResourceValue(layout, 2)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_B.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 3)
|
||||
"${Settings.PREF_BUTTON_B}-Y$layout",
|
||||
getResourceValue(layout, 3)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_X.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 4)
|
||||
"${Settings.PREF_BUTTON_X}-X$layout",
|
||||
getResourceValue(layout, 4)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_X.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 5)
|
||||
"${Settings.PREF_BUTTON_X}-Y$layout",
|
||||
getResourceValue(layout, 5)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_Y.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 6)
|
||||
"${Settings.PREF_BUTTON_Y}-X$layout",
|
||||
getResourceValue(layout, 6)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_Y.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 7)
|
||||
"${Settings.PREF_BUTTON_Y}-Y$layout",
|
||||
getResourceValue(layout, 7)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_ZL.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 8)
|
||||
"${Settings.PREF_BUTTON_ZL}-X$layout",
|
||||
getResourceValue(layout, 8)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_ZL.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 9)
|
||||
"${Settings.PREF_BUTTON_ZL}-Y$layout",
|
||||
getResourceValue(layout, 9)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_ZR.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 10)
|
||||
"${Settings.PREF_BUTTON_ZR}-X$layout",
|
||||
getResourceValue(layout, 10)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_ZR.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 11)
|
||||
"${Settings.PREF_BUTTON_ZR}-Y$layout",
|
||||
getResourceValue(layout, 11)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.DPAD_UP.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 12)
|
||||
"${Settings.PREF_BUTTON_DPAD}-X$layout",
|
||||
getResourceValue(layout, 12)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.DPAD_UP.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 13)
|
||||
"${Settings.PREF_BUTTON_DPAD}-Y$layout",
|
||||
getResourceValue(layout, 13)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_L.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 14)
|
||||
"${Settings.PREF_BUTTON_L}-X$layout",
|
||||
getResourceValue(layout, 14)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_L.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 15)
|
||||
"${Settings.PREF_BUTTON_L}-Y$layout",
|
||||
getResourceValue(layout, 15)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_R.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 16)
|
||||
"${Settings.PREF_BUTTON_R}-X$layout",
|
||||
getResourceValue(layout, 16)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.TRIGGER_R.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 17)
|
||||
"${Settings.PREF_BUTTON_R}-Y$layout",
|
||||
getResourceValue(layout, 17)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_PLUS.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 18)
|
||||
"${Settings.PREF_BUTTON_PLUS}-X$layout",
|
||||
getResourceValue(layout, 18)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_PLUS.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 19)
|
||||
"${Settings.PREF_BUTTON_PLUS}-Y$layout",
|
||||
getResourceValue(layout, 19)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_MINUS.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 20)
|
||||
"${Settings.PREF_BUTTON_MINUS}-X$layout",
|
||||
getResourceValue(layout, 20)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_MINUS.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 21)
|
||||
"${Settings.PREF_BUTTON_MINUS}-Y$layout",
|
||||
getResourceValue(layout, 21)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_HOME.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 22)
|
||||
"${Settings.PREF_BUTTON_HOME}-X$layout",
|
||||
getResourceValue(layout, 22)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_HOME.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 23)
|
||||
"${Settings.PREF_BUTTON_HOME}-Y$layout",
|
||||
getResourceValue(layout, 23)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_CAPTURE.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 24)
|
||||
"${Settings.PREF_BUTTON_SCREENSHOT}-X$layout",
|
||||
getResourceValue(layout, 24)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.BUTTON_CAPTURE.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 25)
|
||||
"${Settings.PREF_BUTTON_SCREENSHOT}-Y$layout",
|
||||
getResourceValue(layout, 25)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.STICK_R.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 26)
|
||||
"${Settings.PREF_STICK_R}-X$layout",
|
||||
getResourceValue(layout, 26)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.STICK_R.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 27)
|
||||
"${Settings.PREF_STICK_R}-Y$layout",
|
||||
getResourceValue(layout, 27)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.STICK_L.toString() + "-X$orientation",
|
||||
getResourceValue(orientation, 28)
|
||||
"${Settings.PREF_STICK_L}-X$layout",
|
||||
getResourceValue(layout, 28)
|
||||
)
|
||||
.putFloat(
|
||||
ButtonType.STICK_L.toString() + "-Y$orientation",
|
||||
getResourceValue(orientation, 29)
|
||||
"${Settings.PREF_STICK_L}-Y$layout",
|
||||
getResourceValue(layout, 29)
|
||||
)
|
||||
.putFloat(
|
||||
"${Settings.PREF_BUTTON_STICK_L}-X$layout",
|
||||
getResourceValue(layout, 30)
|
||||
)
|
||||
.putFloat(
|
||||
"${Settings.PREF_BUTTON_STICK_L}-Y$layout",
|
||||
getResourceValue(layout, 31)
|
||||
)
|
||||
.putFloat(
|
||||
"${Settings.PREF_BUTTON_STICK_R}-X$layout",
|
||||
getResourceValue(layout, 32)
|
||||
)
|
||||
.putFloat(
|
||||
"${Settings.PREF_BUTTON_STICK_R}-Y$layout",
|
||||
getResourceValue(layout, 33)
|
||||
)
|
||||
.apply()
|
||||
}
|
||||
@@ -812,12 +900,30 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Increase this number every time there is a breaking change to every overlay layout
|
||||
const val OVERLAY_VERSION = 1
|
||||
|
||||
// Increase the corresponding layout version number whenever that layout has a breaking change
|
||||
private const val LANDSCAPE_OVERLAY_VERSION = 1
|
||||
private const val PORTRAIT_OVERLAY_VERSION = 1
|
||||
private const val FOLDABLE_OVERLAY_VERSION = 1
|
||||
val overlayLayoutVersions = listOf(
|
||||
LANDSCAPE_OVERLAY_VERSION,
|
||||
PORTRAIT_OVERLAY_VERSION,
|
||||
FOLDABLE_OVERLAY_VERSION
|
||||
)
|
||||
|
||||
private val preferences: SharedPreferences =
|
||||
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||
|
||||
const val LANDSCAPE = ""
|
||||
const val LANDSCAPE = "_Landscape"
|
||||
const val PORTRAIT = "_Portrait"
|
||||
const val FOLDABLE = "_Foldable"
|
||||
val overlayLayouts = listOf(
|
||||
LANDSCAPE,
|
||||
PORTRAIT,
|
||||
FOLDABLE
|
||||
)
|
||||
|
||||
/**
|
||||
* Resizes a [Bitmap] by a given scale factor
|
||||
@@ -948,6 +1054,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
* @param defaultResId The resource ID of the [Drawable] to get the [Bitmap] of (Default State).
|
||||
* @param pressedResId The resource ID of the [Drawable] to get the [Bitmap] of (Pressed State).
|
||||
* @param buttonId Identifier for determining what type of button the initialized InputOverlayDrawableButton represents.
|
||||
* @param prefId Identifier for determining where a button appears on screen.
|
||||
* @param layout The current screen layout as determined by [LANDSCAPE], [PORTRAIT], or [FOLDABLE].
|
||||
* @return An [InputOverlayDrawableButton] with the correct drawing bounds set.
|
||||
*/
|
||||
private fun initializeOverlayButton(
|
||||
@@ -956,7 +1064,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
defaultResId: Int,
|
||||
pressedResId: Int,
|
||||
buttonId: Int,
|
||||
orientation: String
|
||||
prefId: String,
|
||||
layout: String
|
||||
): InputOverlayDrawableButton {
|
||||
// Resources handle for fetching the initial Drawable resource.
|
||||
val res = context.resources
|
||||
@@ -964,17 +1073,20 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
|
||||
val sPrefs = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||
|
||||
// Decide scale based on button ID and user preference
|
||||
var scale: Float = when (buttonId) {
|
||||
ButtonType.BUTTON_HOME,
|
||||
ButtonType.BUTTON_CAPTURE,
|
||||
ButtonType.BUTTON_PLUS,
|
||||
ButtonType.BUTTON_MINUS -> 0.07f
|
||||
// Decide scale based on button preference ID and user preference
|
||||
var scale: Float = when (prefId) {
|
||||
Settings.PREF_BUTTON_HOME,
|
||||
Settings.PREF_BUTTON_SCREENSHOT,
|
||||
Settings.PREF_BUTTON_PLUS,
|
||||
Settings.PREF_BUTTON_MINUS -> 0.07f
|
||||
|
||||
ButtonType.TRIGGER_L,
|
||||
ButtonType.TRIGGER_R,
|
||||
ButtonType.TRIGGER_ZL,
|
||||
ButtonType.TRIGGER_ZR -> 0.26f
|
||||
Settings.PREF_BUTTON_L,
|
||||
Settings.PREF_BUTTON_R,
|
||||
Settings.PREF_BUTTON_ZL,
|
||||
Settings.PREF_BUTTON_ZR -> 0.26f
|
||||
|
||||
Settings.PREF_BUTTON_STICK_L,
|
||||
Settings.PREF_BUTTON_STICK_R -> 0.155f
|
||||
|
||||
else -> 0.11f
|
||||
}
|
||||
@@ -984,8 +1096,13 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
// Initialize the InputOverlayDrawableButton.
|
||||
val defaultStateBitmap = getBitmap(context, defaultResId, scale)
|
||||
val pressedStateBitmap = getBitmap(context, pressedResId, scale)
|
||||
val overlayDrawable =
|
||||
InputOverlayDrawableButton(res, defaultStateBitmap, pressedStateBitmap, buttonId)
|
||||
val overlayDrawable = InputOverlayDrawableButton(
|
||||
res,
|
||||
defaultStateBitmap,
|
||||
pressedStateBitmap,
|
||||
buttonId,
|
||||
prefId
|
||||
)
|
||||
|
||||
// Get the minimum and maximum coordinates of the screen where the button can be placed.
|
||||
val min = windowSize.first
|
||||
@@ -993,8 +1110,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
|
||||
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
|
||||
// These were set in the input overlay configuration menu.
|
||||
val xKey = "$buttonId-X$orientation"
|
||||
val yKey = "$buttonId-Y$orientation"
|
||||
val xKey = "$prefId-X$layout"
|
||||
val yKey = "$prefId-Y$layout"
|
||||
val drawableXPercent = sPrefs.getFloat(xKey, 0f)
|
||||
val drawableYPercent = sPrefs.getFloat(yKey, 0f)
|
||||
val drawableX = (drawableXPercent * max.x + min.x).toInt()
|
||||
@@ -1029,7 +1146,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
* @param defaultResId The [Bitmap] resource ID of the default state.
|
||||
* @param pressedOneDirectionResId The [Bitmap] resource ID of the pressed state in one direction.
|
||||
* @param pressedTwoDirectionsResId The [Bitmap] resource ID of the pressed state in two directions.
|
||||
* @return the initialized [InputOverlayDrawableDpad]
|
||||
* @param layout The current screen layout as determined by [LANDSCAPE], [PORTRAIT], or [FOLDABLE].
|
||||
* @return The initialized [InputOverlayDrawableDpad]
|
||||
*/
|
||||
private fun initializeOverlayDpad(
|
||||
context: Context,
|
||||
@@ -1037,7 +1155,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
defaultResId: Int,
|
||||
pressedOneDirectionResId: Int,
|
||||
pressedTwoDirectionsResId: Int,
|
||||
orientation: String
|
||||
layout: String
|
||||
): InputOverlayDrawableDpad {
|
||||
// Resources handle for fetching the initial Drawable resource.
|
||||
val res = context.resources
|
||||
@@ -1074,8 +1192,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
|
||||
// The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay.
|
||||
// These were set in the input overlay configuration menu.
|
||||
val drawableXPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}-X$orientation", 0f)
|
||||
val drawableYPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}-Y$orientation", 0f)
|
||||
val drawableXPercent = sPrefs.getFloat("${Settings.PREF_BUTTON_DPAD}-X$layout", 0f)
|
||||
val drawableYPercent = sPrefs.getFloat("${Settings.PREF_BUTTON_DPAD}-Y$layout", 0f)
|
||||
val drawableX = (drawableXPercent * max.x + min.x).toInt()
|
||||
val drawableY = (drawableYPercent * max.y + min.y).toInt()
|
||||
val width = overlayDrawable.width
|
||||
@@ -1107,7 +1225,9 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
* @param pressedResInner Resource ID for the pressed inner image of the joystick.
|
||||
* @param joystick Identifier for which joystick this is.
|
||||
* @param button Identifier for which joystick button this is.
|
||||
* @return the initialized [InputOverlayDrawableJoystick].
|
||||
* @param prefId Identifier for determining where a button appears on screen.
|
||||
* @param layout The current screen layout as determined by [LANDSCAPE], [PORTRAIT], or [FOLDABLE].
|
||||
* @return The initialized [InputOverlayDrawableJoystick].
|
||||
*/
|
||||
private fun initializeOverlayJoystick(
|
||||
context: Context,
|
||||
@@ -1117,7 +1237,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
pressedResInner: Int,
|
||||
joystick: Int,
|
||||
button: Int,
|
||||
orientation: String
|
||||
prefId: String,
|
||||
layout: String
|
||||
): InputOverlayDrawableJoystick {
|
||||
// Resources handle for fetching the initial Drawable resource.
|
||||
val res = context.resources
|
||||
@@ -1141,8 +1262,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
|
||||
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
|
||||
// These were set in the input overlay configuration menu.
|
||||
val drawableXPercent = sPrefs.getFloat("$button-X$orientation", 0f)
|
||||
val drawableYPercent = sPrefs.getFloat("$button-Y$orientation", 0f)
|
||||
val drawableXPercent = sPrefs.getFloat("$prefId-X$layout", 0f)
|
||||
val drawableYPercent = sPrefs.getFloat("$prefId-Y$layout", 0f)
|
||||
val drawableX = (drawableXPercent * max.x + min.x).toInt()
|
||||
val drawableY = (drawableYPercent * max.y + min.y).toInt()
|
||||
val outerScale = 1.66f
|
||||
@@ -1168,7 +1289,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) :
|
||||
outerRect,
|
||||
innerRect,
|
||||
joystick,
|
||||
button
|
||||
button,
|
||||
prefId
|
||||
)
|
||||
|
||||
// Need to set the image's position
|
||||
|
||||
@@ -24,7 +24,8 @@ class InputOverlayDrawableButton(
|
||||
res: Resources,
|
||||
defaultStateBitmap: Bitmap,
|
||||
pressedStateBitmap: Bitmap,
|
||||
val buttonId: Int
|
||||
val buttonId: Int,
|
||||
val prefId: String
|
||||
) {
|
||||
// The ID value what motion event is tracking
|
||||
var trackId: Int
|
||||
|
||||
@@ -37,7 +37,8 @@ class InputOverlayDrawableJoystick(
|
||||
rectOuter: Rect,
|
||||
rectInner: Rect,
|
||||
val joystickId: Int,
|
||||
val buttonId: Int
|
||||
val buttonId: Int,
|
||||
val prefId: String
|
||||
) {
|
||||
// The ID value what motion event is tracking
|
||||
var trackId = -1
|
||||
|
||||
@@ -5,35 +5,101 @@ package org.yuzu.yuzu_emu.utils
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.YuzuApplication
|
||||
import java.util.Locale
|
||||
import kotlin.math.ceil
|
||||
|
||||
class MemoryUtil(val context: Context) {
|
||||
object MemoryUtil {
|
||||
private val context get() = YuzuApplication.appContext
|
||||
|
||||
private val Long.floatForm: String
|
||||
get() = String.format(Locale.ROOT, "%.2f", this.toDouble())
|
||||
private val Float.hundredths: String
|
||||
get() = String.format(Locale.ROOT, "%.2f", this)
|
||||
|
||||
private fun bytesToSizeUnit(size: Long): String {
|
||||
return when {
|
||||
size < Kb -> "${size.floatForm} ${context.getString(R.string.memory_byte)}"
|
||||
size < Mb -> "${(size / Kb).floatForm} ${context.getString(R.string.memory_kilobyte)}"
|
||||
size < Gb -> "${(size / Mb).floatForm} ${context.getString(R.string.memory_megabyte)}"
|
||||
size < Tb -> "${(size / Gb).floatForm} ${context.getString(R.string.memory_gigabyte)}"
|
||||
size < Pb -> "${(size / Tb).floatForm} ${context.getString(R.string.memory_terabyte)}"
|
||||
size < Eb -> "${(size / Pb).floatForm} ${context.getString(R.string.memory_petabyte)}"
|
||||
else -> "${(size / Eb).floatForm} ${context.getString(R.string.memory_exabyte)}"
|
||||
// Required total system memory
|
||||
const val REQUIRED_MEMORY = 8
|
||||
|
||||
const val Kb: Float = 1024F
|
||||
const val Mb = Kb * 1024
|
||||
const val Gb = Mb * 1024
|
||||
const val Tb = Gb * 1024
|
||||
const val Pb = Tb * 1024
|
||||
const val Eb = Pb * 1024
|
||||
|
||||
private fun bytesToSizeUnit(size: Float): String =
|
||||
when {
|
||||
size < Kb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
size.hundredths,
|
||||
context.getString(R.string.memory_byte)
|
||||
)
|
||||
}
|
||||
size < Mb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Kb).hundredths,
|
||||
context.getString(R.string.memory_kilobyte)
|
||||
)
|
||||
}
|
||||
size < Gb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Mb).hundredths,
|
||||
context.getString(R.string.memory_megabyte)
|
||||
)
|
||||
}
|
||||
size < Tb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Gb).hundredths,
|
||||
context.getString(R.string.memory_gigabyte)
|
||||
)
|
||||
}
|
||||
size < Pb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Tb).hundredths,
|
||||
context.getString(R.string.memory_terabyte)
|
||||
)
|
||||
}
|
||||
size < Eb -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Pb).hundredths,
|
||||
context.getString(R.string.memory_petabyte)
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
context.getString(
|
||||
R.string.memory_formatted,
|
||||
(size / Eb).hundredths,
|
||||
context.getString(R.string.memory_exabyte)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val totalMemory =
|
||||
with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) {
|
||||
// Devices are unlikely to have 0.5GB increments of memory so we'll just round up to account for
|
||||
// the potential error created by memInfo.totalMem
|
||||
private val totalMemory: Float
|
||||
get() {
|
||||
val memInfo = ActivityManager.MemoryInfo()
|
||||
getMemoryInfo(memInfo)
|
||||
memInfo.totalMem
|
||||
with(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) {
|
||||
getMemoryInfo(memInfo)
|
||||
}
|
||||
|
||||
return ceil(
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
memInfo.advertisedMem.toFloat()
|
||||
} else {
|
||||
memInfo.totalMem.toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun isLessThan(minimum: Int, size: Long): Boolean {
|
||||
return when (size) {
|
||||
fun isLessThan(minimum: Int, size: Float): Boolean =
|
||||
when (size) {
|
||||
Kb -> totalMemory < Mb && totalMemory < minimum
|
||||
Mb -> totalMemory < Gb && (totalMemory / Mb) < minimum
|
||||
Gb -> totalMemory < Tb && (totalMemory / Gb) < minimum
|
||||
@@ -42,18 +108,6 @@ class MemoryUtil(val context: Context) {
|
||||
Eb -> totalMemory / Eb < minimum
|
||||
else -> totalMemory < Kb && totalMemory < minimum
|
||||
}
|
||||
}
|
||||
|
||||
fun getDeviceRAM(): String {
|
||||
return bytesToSizeUnit(totalMemory)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val Kb: Long = 1024
|
||||
const val Mb = Kb * 1024
|
||||
const val Gb = Mb * 1024
|
||||
const val Tb = Gb * 1024
|
||||
const val Pb = Tb * 1024
|
||||
const val Eb = Pb * 1024
|
||||
}
|
||||
fun getDeviceRAM(): String = bytesToSizeUnit(totalMemory)
|
||||
}
|
||||
|
||||
128
src/android/app/src/main/res/drawable/button_l3.xml
Normal file
128
src/android/app/src/main/res/drawable/button_l3.xml
Normal file
@@ -0,0 +1,128 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="34.963dp"
|
||||
android:height="37.265dp"
|
||||
android:viewportWidth="34.963"
|
||||
android:viewportHeight="37.265">
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="M19.451,19.024A3.498,3.498 0,0 0,21.165 19.508c1.336,0 1.749,-0.852 1.738,-1.49 0,-1.077 -0.982,-1.537 -1.987,-1.537L20.327,16.481L20.327,15.7L20.901,15.7c0.757,0 1.714,-0.392 1.714,-1.302C22.621,13.785 22.224,13.229 21.271,13.229a2.834,2.834 0,0 0,-1.537 0.529l-0.265,-0.757a3.662,3.662 0,0 1,2.008 -0.59c1.513,0 2.201,0.897 2.201,1.834 0,0.794 -0.474,1.466 -1.421,1.807l0,0.024c0.947,0.19 1.714,0.9 1.714,1.976C23.967,19.27 23.017,20.346 21.165,20.346a3.929,3.929 135,0 1,-1.998 -0.529z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="21.568"
|
||||
android:endY="33.938"
|
||||
android:startX="21.568"
|
||||
android:startY="16.14"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="M16.062,9.353 L9.624,3.405A1.963,1.963 0,0 1,10.955 0l12.88,0a1.963,1.963 135,0 1,1.323 3.405L18.726,9.353a1.961,1.961 135,0 1,-2.664 0z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="17.395"
|
||||
android:endY="18.74"
|
||||
android:startX="17.395"
|
||||
android:startY="-1.296"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="m25.79,5.657l0,0a2.09,2.09 45,0 0,0.23 3.262c3.522,2.402 4.762,5.927 4.741,10.52A13.279,13.279 135,0 1,4.206 19.365c0,-4.516 0.931,-7.71 4.374,-10.107a2.098,2.098 0,0 0,0.233 -3.265l0,0a2.101,2.101 135,0 0,-2.646 -0.169C1.433,9.133 -0.266,13.941 0.033,20.233a17.468,17.468 0,0 0,34.925 -0.868c0,-6.006 -1.971,-10.771 -6.585,-13.917a2.088,2.088 45,0 0,-2.582 0.209z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:centerX="17.477"
|
||||
android:centerY="19.92"
|
||||
android:gradientRadius="17.201"
|
||||
android:type="radial">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0.58" />
|
||||
<item
|
||||
android:color="#FFC6C6C6"
|
||||
android:offset="0.84" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.88" />
|
||||
<item
|
||||
android:color="#FFC2C2C2"
|
||||
android:offset="0.91" />
|
||||
<item
|
||||
android:color="#FFB5B5B5"
|
||||
android:offset="0.94" />
|
||||
<item
|
||||
android:color="#FF9E9E9E"
|
||||
android:offset="0.98" />
|
||||
<item
|
||||
android:color="#FF8F8F8F"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="m12.516,12.729l2,0l0,13.822l6.615,0l0,1.68L12.516,28.231Z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="16.829"
|
||||
android:endY="46.882"
|
||||
android:startX="16.829"
|
||||
android:startY="20.479"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
||||
@@ -0,0 +1,75 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="34.963dp"
|
||||
android:height="37.265dp"
|
||||
android:viewportWidth="34.963"
|
||||
android:viewportHeight="37.265">
|
||||
<path
|
||||
android:fillAlpha="0.3"
|
||||
android:fillColor="#151515"
|
||||
android:pathData="M16.062,9.353 L9.624,3.405A1.963,1.963 0,0 1,10.955 0l12.88,0a1.963,1.963 135,0 1,1.323 3.405L18.726,9.353a1.961,1.961 135,0 1,-2.664 0z"
|
||||
android:strokeAlpha="0.3" />
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:fillColor="#151515"
|
||||
android:pathData="m25.79,5.657l0,0a2.09,2.09 45,0 0,0.23 3.262c3.522,2.402 4.762,5.927 4.741,10.52A13.279,13.279 135,0 1,4.206 19.365c0,-4.516 0.931,-7.71 4.374,-10.107a2.098,2.098 0,0 0,0.233 -3.265l0,0a2.101,2.101 135,0 0,-2.646 -0.169C1.433,9.133 -0.266,13.941 0.033,20.233a17.468,17.468 0,0 0,34.925 -0.868c0,-6.006 -1.971,-10.771 -6.585,-13.917a2.088,2.088 45,0 0,-2.582 0.209z"
|
||||
android:strokeAlpha="0.6" />
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:pathData="M19.451,19.024A3.498,3.498 0,0 0,21.165 19.508c1.336,0 1.749,-0.852 1.738,-1.49 0,-1.077 -0.982,-1.537 -1.987,-1.537L20.327,16.481L20.327,15.7L20.901,15.7c0.757,0 1.714,-0.392 1.714,-1.302C22.621,13.785 22.224,13.229 21.271,13.229a2.834,2.834 0,0 0,-1.537 0.529l-0.265,-0.757a3.662,3.662 0,0 1,2.008 -0.59c1.513,0 2.201,0.897 2.201,1.834 0,0.794 -0.474,1.466 -1.421,1.807l0,0.024c0.947,0.19 1.714,0.9 1.714,1.976C23.967,19.27 23.017,20.346 21.165,20.346a3.929,3.929 135,0 1,-1.998 -0.529z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="21.568"
|
||||
android:endY="33.938"
|
||||
android:startX="21.568"
|
||||
android:startY="16.14"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:pathData="m12.516,12.729l2,0l0,13.822l6.615,0l0,1.68L12.516,28.231Z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="16.829"
|
||||
android:endY="46.882"
|
||||
android:startX="16.829"
|
||||
android:startY="20.479"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
||||
128
src/android/app/src/main/res/drawable/button_r3.xml
Normal file
128
src/android/app/src/main/res/drawable/button_r3.xml
Normal file
@@ -0,0 +1,128 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="34.963dp"
|
||||
android:height="37.265dp"
|
||||
android:viewportWidth="34.963"
|
||||
android:viewportHeight="37.265">
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="m10.781,12.65a19.579,19.579 0,0 1,3.596 -0.302c2.003,0 3.294,0.368 4.199,1.185a3.622,3.622 0,0 1,1.14 2.757c0,1.916 -1.206,3.175 -2.733,3.704l0,0.063c1.119,0.386 1.786,1.421 2.117,2.929 0.474,2.024 0.818,3.424 1.119,3.982l-1.924,0c-0.238,-0.407 -0.561,-1.656 -0.968,-3.466 -0.431,-2.003 -1.206,-2.757 -2.91,-2.82l-1.762,0l0,6.286l-1.873,0zM12.654,19.264l1.916,0c2.003,0 3.273,-1.098 3.273,-2.757 0,-1.873 -1.357,-2.691 -3.336,-2.712a7.649,7.649 0,0 0,-1.852 0.172z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="15.506"
|
||||
android:endY="48.977"
|
||||
android:startX="15.506"
|
||||
android:startY="19.659"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="M16.062,9.353 L9.624,3.405A1.963,1.963 0,0 1,10.955 0l12.88,0a1.963,1.963 135,0 1,1.323 3.405L18.726,9.353a1.961,1.961 135,0 1,-2.664 0z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="17.395"
|
||||
android:endY="18.74"
|
||||
android:startX="17.395"
|
||||
android:startY="-1.296"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="m25.79,5.657l0,0a2.09,2.09 45,0 0,0.23 3.262c3.522,2.402 4.762,5.927 4.741,10.52A13.279,13.279 135,0 1,4.206 19.365c0,-4.516 0.931,-7.71 4.374,-10.107a2.098,2.098 0,0 0,0.233 -3.265l0,0a2.101,2.101 135,0 0,-2.646 -0.169C1.433,9.133 -0.266,13.941 0.033,20.233a17.468,17.468 0,0 0,34.925 -0.868c0,-6.006 -1.971,-10.771 -6.585,-13.917a2.088,2.088 45,0 0,-2.582 0.209z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:centerX="17.477"
|
||||
android:centerY="19.92"
|
||||
android:gradientRadius="17.201"
|
||||
android:type="radial">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0.58" />
|
||||
<item
|
||||
android:color="#FFC6C6C6"
|
||||
android:offset="0.84" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.88" />
|
||||
<item
|
||||
android:color="#FFC2C2C2"
|
||||
android:offset="0.91" />
|
||||
<item
|
||||
android:color="#FFB5B5B5"
|
||||
android:offset="0.94" />
|
||||
<item
|
||||
android:color="#FF9E9E9E"
|
||||
android:offset="0.98" />
|
||||
<item
|
||||
android:color="#FF8F8F8F"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.5"
|
||||
android:pathData="M21.832,19.024A3.498,3.498 0,0 0,23.547 19.508c1.336,0 1.749,-0.852 1.738,-1.49 0,-1.077 -0.982,-1.537 -1.987,-1.537L22.708,16.481L22.708,15.7L23.282,15.7c0.757,0 1.714,-0.392 1.714,-1.302C25.002,13.785 24.605,13.229 23.652,13.229a2.834,2.834 0,0 0,-1.537 0.529l-0.265,-0.757a3.662,3.662 0,0 1,2.008 -0.59c1.513,0 2.201,0.897 2.201,1.834 0,0.794 -0.474,1.466 -1.421,1.807l0,0.024c0.947,0.19 1.714,0.9 1.714,1.976C26.349,19.27 25.399,20.346 23.547,20.346a3.929,3.929 135,0 1,-1.998 -0.529z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="23.949"
|
||||
android:endY="33.938"
|
||||
android:startX="23.949"
|
||||
android:startY="16.14"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
||||
@@ -0,0 +1,75 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="34.963dp"
|
||||
android:height="37.265dp"
|
||||
android:viewportWidth="34.963"
|
||||
android:viewportHeight="37.265">
|
||||
<path
|
||||
android:fillAlpha="0.3"
|
||||
android:fillColor="#151515"
|
||||
android:pathData="M16.062,9.353 L9.624,3.405A1.963,1.963 0,0 1,10.955 0l12.88,0a1.963,1.963 135,0 1,1.323 3.405L18.726,9.353a1.961,1.961 135,0 1,-2.664 0z"
|
||||
android:strokeAlpha="0.3" />
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:fillColor="#151515"
|
||||
android:pathData="m25.79,5.657l0,0a2.09,2.09 45,0 0,0.23 3.262c3.522,2.402 4.762,5.927 4.741,10.52A13.279,13.279 135,0 1,4.206 19.365c0,-4.516 0.931,-7.71 4.374,-10.107a2.098,2.098 0,0 0,0.233 -3.265l0,0a2.101,2.101 135,0 0,-2.646 -0.169C1.433,9.133 -0.266,13.941 0.033,20.233a17.468,17.468 0,0 0,34.925 -0.868c0,-6.006 -1.971,-10.771 -6.585,-13.917a2.088,2.088 45,0 0,-2.582 0.209z"
|
||||
android:strokeAlpha="0.6" />
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:pathData="m10.781,12.65a19.579,19.579 0,0 1,3.596 -0.302c2.003,0 3.294,0.368 4.199,1.185a3.622,3.622 0,0 1,1.14 2.757c0,1.916 -1.206,3.175 -2.733,3.704l0,0.063c1.119,0.386 1.786,1.421 2.117,2.929 0.474,2.024 0.818,3.424 1.119,3.982l-1.924,0c-0.238,-0.407 -0.561,-1.656 -0.968,-3.466 -0.431,-2.003 -1.206,-2.757 -2.91,-2.82l-1.762,0l0,6.286l-1.873,0zM12.654,19.264l1.916,0c2.003,0 3.273,-1.098 3.273,-2.757 0,-1.873 -1.357,-2.691 -3.336,-2.712a7.649,7.649 0,0 0,-1.852 0.172z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="15.506"
|
||||
android:endY="48.977"
|
||||
android:startX="15.506"
|
||||
android:startY="19.659"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillAlpha="0.6"
|
||||
android:pathData="M21.832,19.024A3.498,3.498 0,0 0,23.547 19.508c1.336,0 1.749,-0.852 1.738,-1.49 0,-1.077 -0.982,-1.537 -1.987,-1.537L22.708,16.481L22.708,15.7L23.282,15.7c0.757,0 1.714,-0.392 1.714,-1.302C25.002,13.785 24.605,13.229 23.652,13.229a2.834,2.834 0,0 0,-1.537 0.529l-0.265,-0.757a3.662,3.662 0,0 1,2.008 -0.59c1.513,0 2.201,0.897 2.201,1.834 0,0.794 -0.474,1.466 -1.421,1.807l0,0.024c0.947,0.19 1.714,0.9 1.714,1.976C26.349,19.27 25.399,20.346 23.547,20.346a3.929,3.929 135,0 1,-1.998 -0.529z"
|
||||
android:strokeAlpha="0.6">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="23.949"
|
||||
android:endY="33.938"
|
||||
android:startX="23.949"
|
||||
android:startY="16.14"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#FFC3C4C5"
|
||||
android:offset="0" />
|
||||
<item
|
||||
android:color="#FFC5C6C6"
|
||||
android:offset="0.03" />
|
||||
<item
|
||||
android:color="#FFC7C7C7"
|
||||
android:offset="0.19" />
|
||||
<item
|
||||
android:color="#DBB5B5B5"
|
||||
android:offset="0.44" />
|
||||
<item
|
||||
android:color="#7F878787"
|
||||
android:offset="1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
||||
@@ -205,6 +205,8 @@
|
||||
<item>@string/gamepad_d_pad</item>
|
||||
<item>@string/gamepad_left_stick</item>
|
||||
<item>@string/gamepad_right_stick</item>
|
||||
<item>L3</item>
|
||||
<item>R3</item>
|
||||
<item>@string/gamepad_home</item>
|
||||
<item>@string/gamepad_screenshot</item>
|
||||
</string-array>
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_X">260</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_Y">790</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_X">870</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_Y">400</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_X">960</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_Y">430</integer>
|
||||
|
||||
<!-- Default SWITCH portrait layout -->
|
||||
<integer name="SWITCH_BUTTON_A_X_PORTRAIT">840</integer>
|
||||
@@ -65,6 +69,10 @@
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_Y_PORTRAIT">950</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_X_PORTRAIT">240</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_Y_PORTRAIT">840</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_X_PORTRAIT">730</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_Y_PORTRAIT">510</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_X_PORTRAIT">900</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_Y_PORTRAIT">540</integer>
|
||||
|
||||
<!-- Default SWITCH foldable layout -->
|
||||
<integer name="SWITCH_BUTTON_A_X_FOLDABLE">840</integer>
|
||||
@@ -97,5 +105,9 @@
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_Y_FOLDABLE">470</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_X_FOLDABLE">240</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_Y_FOLDABLE">390</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_X_FOLDABLE">550</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_L_Y_FOLDABLE">210</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_X_FOLDABLE">550</integer>
|
||||
<integer name="SWITCH_BUTTON_STICK_R_Y_FOLDABLE">280</integer>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -273,6 +273,7 @@
|
||||
<string name="fatal_error_message">A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs.</string>
|
||||
<string name="performance_warning">Turning off this setting will significantly reduce emulation performance! For the best experience, it is recommended that you leave this setting enabled.</string>
|
||||
<string name="device_memory_inadequate">Device RAM: %1$s\nRecommended: %2$s</string>
|
||||
<string name="memory_formatted">%1$s %2$s</string>
|
||||
|
||||
<!-- Region Names -->
|
||||
<string name="region_japan">Japan</string>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "audio_core/sink/sink_stream.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/fixed_point.h"
|
||||
#include "common/scope_exit.h"
|
||||
#include "common/settings.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
@@ -19,9 +20,12 @@
|
||||
namespace AudioCore::Sink {
|
||||
|
||||
void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
if (type == StreamType::In) {
|
||||
SCOPE_EXIT({
|
||||
queue.enqueue(buffer);
|
||||
queued_buffers++;
|
||||
++queued_buffers;
|
||||
});
|
||||
|
||||
if (type == StreamType::In) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,16 +70,17 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
static_cast<s16>(std::clamp(right_sample, min, max));
|
||||
}
|
||||
|
||||
samples = samples.subspan(0, samples.size() / system_channels * device_channels);
|
||||
samples_buffer.Push(samples.subspan(0, samples.size() / system_channels * device_channels));
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (system_channels == 2 && device_channels == 6) {
|
||||
if (system_channels == 2 && device_channels == 6) {
|
||||
// We need moar samples! Not all games will provide 6 channel audio.
|
||||
// TODO: Implement some upmixing here. Currently just passthrough, with other
|
||||
// channels left as silence.
|
||||
auto new_size = samples.size() / system_channels * device_channels;
|
||||
tmp_samples.resize_destructive(new_size);
|
||||
std::vector<s16> new_samples(samples.size() / system_channels * device_channels);
|
||||
|
||||
for (u32 read_index = 0, write_index = 0; read_index < new_size;
|
||||
for (u32 read_index = 0, write_index = 0; read_index < samples.size();
|
||||
read_index += system_channels, write_index += device_channels) {
|
||||
const auto left_sample{static_cast<s16>(std::clamp(
|
||||
static_cast<s32>(
|
||||
@@ -83,7 +88,7 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
volume),
|
||||
min, max))};
|
||||
|
||||
tmp_samples[write_index + static_cast<u32>(Channels::FrontLeft)] = left_sample;
|
||||
new_samples[write_index + static_cast<u32>(Channels::FrontLeft)] = left_sample;
|
||||
|
||||
const auto right_sample{static_cast<s16>(std::clamp(
|
||||
static_cast<s32>(
|
||||
@@ -91,20 +96,21 @@ void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
|
||||
volume),
|
||||
min, max))};
|
||||
|
||||
tmp_samples[write_index + static_cast<u32>(Channels::FrontRight)] = right_sample;
|
||||
new_samples[write_index + static_cast<u32>(Channels::FrontRight)] = right_sample;
|
||||
}
|
||||
samples = std::span<s16>(tmp_samples);
|
||||
|
||||
} else if (volume != 1.0f) {
|
||||
for (u32 i = 0; i < samples.size(); i++) {
|
||||
samples_buffer.Push(new_samples);
|
||||
return;
|
||||
}
|
||||
|
||||
if (volume != 1.0f) {
|
||||
for (u32 i = 0; i < samples.size(); ++i) {
|
||||
samples[i] = static_cast<s16>(
|
||||
std::clamp(static_cast<s32>(static_cast<f32>(samples[i]) * volume), min, max));
|
||||
}
|
||||
}
|
||||
|
||||
samples_buffer.Push(samples);
|
||||
queue.enqueue(buffer);
|
||||
queued_buffers++;
|
||||
}
|
||||
|
||||
std::vector<s16> SinkStream::ReleaseBuffer(u64 num_samples) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/reader_writer_queue.h"
|
||||
#include "common/ring_buffer.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
namespace Core {
|
||||
@@ -256,8 +255,6 @@ private:
|
||||
/// Signalled when ring buffer entries are consumed
|
||||
std::condition_variable_any release_cv;
|
||||
std::mutex release_mutex;
|
||||
/// Temporary buffer for appending samples when upmixing
|
||||
Common::ScratchBuffer<s16> tmp_samples{};
|
||||
};
|
||||
|
||||
using SinkStreamPtr = std::unique_ptr<SinkStream>;
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
return push_count;
|
||||
}
|
||||
|
||||
std::size_t Push(const std::span<T> input) {
|
||||
std::size_t Push(std::span<const T> input) {
|
||||
return Push(input.data(), input.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "common/concepts.h"
|
||||
#include "common/make_unique_for_overwrite.h"
|
||||
|
||||
namespace Common {
|
||||
@@ -19,15 +18,22 @@ namespace Common {
|
||||
template <typename T>
|
||||
class ScratchBuffer {
|
||||
public:
|
||||
using iterator = T*;
|
||||
using const_iterator = const T*;
|
||||
using value_type = T;
|
||||
using element_type = T;
|
||||
using iterator_category = std::contiguous_iterator_tag;
|
||||
using value_type = T;
|
||||
using size_type = size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
using reference = T&;
|
||||
using const_reference = const T&;
|
||||
using iterator = pointer;
|
||||
using const_iterator = const_pointer;
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using iterator_concept = std::contiguous_iterator_tag;
|
||||
|
||||
ScratchBuffer() = default;
|
||||
|
||||
explicit ScratchBuffer(size_t initial_capacity)
|
||||
explicit ScratchBuffer(size_type initial_capacity)
|
||||
: last_requested_size{initial_capacity}, buffer_capacity{initial_capacity},
|
||||
buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {}
|
||||
|
||||
@@ -39,7 +45,7 @@ public:
|
||||
|
||||
/// This will only grow the buffer's capacity if size is greater than the current capacity.
|
||||
/// The previously held data will remain intact.
|
||||
void resize(size_t size) {
|
||||
void resize(size_type size) {
|
||||
if (size > buffer_capacity) {
|
||||
auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
|
||||
std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get());
|
||||
@@ -51,7 +57,7 @@ public:
|
||||
|
||||
/// This will only grow the buffer's capacity if size is greater than the current capacity.
|
||||
/// The previously held data will be destroyed if a reallocation occurs.
|
||||
void resize_destructive(size_t size) {
|
||||
void resize_destructive(size_type size) {
|
||||
if (size > buffer_capacity) {
|
||||
buffer_capacity = size;
|
||||
buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity);
|
||||
@@ -59,43 +65,43 @@ public:
|
||||
last_requested_size = size;
|
||||
}
|
||||
|
||||
[[nodiscard]] T* data() noexcept {
|
||||
[[nodiscard]] pointer data() noexcept {
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* data() const noexcept {
|
||||
[[nodiscard]] const_pointer data() const noexcept {
|
||||
return buffer.get();
|
||||
}
|
||||
|
||||
[[nodiscard]] T* begin() noexcept {
|
||||
[[nodiscard]] iterator begin() noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* begin() const noexcept {
|
||||
[[nodiscard]] const_iterator begin() const noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
[[nodiscard]] T* end() noexcept {
|
||||
[[nodiscard]] iterator end() noexcept {
|
||||
return data() + last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* end() const noexcept {
|
||||
[[nodiscard]] const_iterator end() const noexcept {
|
||||
return data() + last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] T& operator[](size_t i) {
|
||||
[[nodiscard]] reference operator[](size_type i) {
|
||||
return buffer[i];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& operator[](size_t i) const {
|
||||
[[nodiscard]] const_reference operator[](size_type i) const {
|
||||
return buffer[i];
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t size() const noexcept {
|
||||
[[nodiscard]] size_type size() const noexcept {
|
||||
return last_requested_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t capacity() const noexcept {
|
||||
[[nodiscard]] size_type capacity() const noexcept {
|
||||
return buffer_capacity;
|
||||
}
|
||||
|
||||
@@ -106,8 +112,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
size_t last_requested_size{};
|
||||
size_t buffer_capacity{};
|
||||
size_type last_requested_size{};
|
||||
size_type buffer_capacity{};
|
||||
std::unique_ptr<T[]> buffer{};
|
||||
};
|
||||
|
||||
|
||||
@@ -527,12 +527,10 @@ struct Values {
|
||||
Setting<bool> mouse_panning{false, "mouse_panning"};
|
||||
Setting<u8, true> mouse_panning_x_sensitivity{50, 1, 100, "mouse_panning_x_sensitivity"};
|
||||
Setting<u8, true> mouse_panning_y_sensitivity{50, 1, 100, "mouse_panning_y_sensitivity"};
|
||||
Setting<u8, true> mouse_panning_deadzone_x_counterweight{
|
||||
0, 0, 100, "mouse_panning_deadzone_x_counterweight"};
|
||||
Setting<u8, true> mouse_panning_deadzone_y_counterweight{
|
||||
0, 0, 100, "mouse_panning_deadzone_y_counterweight"};
|
||||
Setting<u8, true> mouse_panning_decay_strength{22, 0, 100, "mouse_panning_decay_strength"};
|
||||
Setting<u8, true> mouse_panning_min_decay{5, 0, 100, "mouse_panning_min_decay"};
|
||||
Setting<u8, true> mouse_panning_deadzone_counterweight{20, 0, 100,
|
||||
"mouse_panning_deadzone_counterweight"};
|
||||
Setting<u8, true> mouse_panning_decay_strength{18, 0, 100, "mouse_panning_decay_strength"};
|
||||
Setting<u8, true> mouse_panning_min_decay{6, 0, 100, "mouse_panning_min_decay"};
|
||||
|
||||
Setting<bool> mouse_enabled{false, "mouse_enabled"};
|
||||
Setting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"};
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/vfs_concat.h"
|
||||
#include "core/file_sys/vfs_real.h"
|
||||
#include "core/gpu_dirty_memory_manager.h"
|
||||
#include "core/hid/hid_core.h"
|
||||
#include "core/hle/kernel/k_memory_manager.h"
|
||||
#include "core/hle/kernel/k_process.h"
|
||||
@@ -130,7 +131,10 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||
struct System::Impl {
|
||||
explicit Impl(System& system)
|
||||
: kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
|
||||
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {}
|
||||
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system},
|
||||
gpu_dirty_memory_write_manager{} {
|
||||
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
|
||||
}
|
||||
|
||||
void Initialize(System& system) {
|
||||
device_memory = std::make_unique<Core::DeviceMemory>();
|
||||
@@ -234,6 +238,8 @@ struct System::Impl {
|
||||
// Setting changes may require a full system reinitialization (e.g., disabling multicore).
|
||||
ReinitializeIfNecessary(system);
|
||||
|
||||
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
|
||||
|
||||
kernel.Initialize();
|
||||
cpu_manager.Initialize();
|
||||
|
||||
@@ -540,6 +546,9 @@ struct System::Impl {
|
||||
|
||||
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
|
||||
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{};
|
||||
|
||||
std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES>
|
||||
gpu_dirty_memory_write_manager{};
|
||||
};
|
||||
|
||||
System::System() : impl{std::make_unique<Impl>(*this)} {}
|
||||
@@ -629,10 +638,31 @@ void System::PrepareReschedule(const u32 core_index) {
|
||||
impl->kernel.PrepareReschedule(core_index);
|
||||
}
|
||||
|
||||
Core::GPUDirtyMemoryManager& System::CurrentGPUDirtyMemoryManager() {
|
||||
const std::size_t core = impl->kernel.GetCurrentHostThreadID();
|
||||
return impl->gpu_dirty_memory_write_manager[core < Core::Hardware::NUM_CPU_CORES
|
||||
? core
|
||||
: Core::Hardware::NUM_CPU_CORES - 1];
|
||||
}
|
||||
|
||||
/// Provides a constant reference to the current gou dirty memory manager.
|
||||
const Core::GPUDirtyMemoryManager& System::CurrentGPUDirtyMemoryManager() const {
|
||||
const std::size_t core = impl->kernel.GetCurrentHostThreadID();
|
||||
return impl->gpu_dirty_memory_write_manager[core < Core::Hardware::NUM_CPU_CORES
|
||||
? core
|
||||
: Core::Hardware::NUM_CPU_CORES - 1];
|
||||
}
|
||||
|
||||
size_t System::GetCurrentHostThreadID() const {
|
||||
return impl->kernel.GetCurrentHostThreadID();
|
||||
}
|
||||
|
||||
void System::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) {
|
||||
for (auto& manager : impl->gpu_dirty_memory_write_manager) {
|
||||
manager.Gather(callback);
|
||||
}
|
||||
}
|
||||
|
||||
PerfStatsResults System::GetAndResetPerfStats() {
|
||||
return impl->GetAndResetPerfStats();
|
||||
}
|
||||
|
||||
@@ -108,9 +108,10 @@ class CpuManager;
|
||||
class Debugger;
|
||||
class DeviceMemory;
|
||||
class ExclusiveMonitor;
|
||||
class SpeedLimiter;
|
||||
class GPUDirtyMemoryManager;
|
||||
class PerfStats;
|
||||
class Reporter;
|
||||
class SpeedLimiter;
|
||||
class TelemetrySession;
|
||||
|
||||
struct PerfStatsResults;
|
||||
@@ -225,6 +226,14 @@ public:
|
||||
/// Prepare the core emulation for a reschedule
|
||||
void PrepareReschedule(u32 core_index);
|
||||
|
||||
/// Provides a reference to the gou dirty memory manager.
|
||||
[[nodiscard]] Core::GPUDirtyMemoryManager& CurrentGPUDirtyMemoryManager();
|
||||
|
||||
/// Provides a constant reference to the current gou dirty memory manager.
|
||||
[[nodiscard]] const Core::GPUDirtyMemoryManager& CurrentGPUDirtyMemoryManager() const;
|
||||
|
||||
void GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback);
|
||||
|
||||
[[nodiscard]] size_t GetCurrentHostThreadID() const;
|
||||
|
||||
/// Gets and resets core performance statistics
|
||||
|
||||
@@ -253,9 +253,6 @@ void CoreTiming::ThreadLoop() {
|
||||
auto wait_time = *next_time - GetGlobalTimeNs().count();
|
||||
if (wait_time > 0) {
|
||||
#ifdef _WIN32
|
||||
const auto timer_resolution_ns =
|
||||
Common::Windows::GetCurrentTimerResolution().count();
|
||||
|
||||
while (!paused && !event.IsSet() && wait_time > 0) {
|
||||
wait_time = *next_time - GetGlobalTimeNs().count();
|
||||
|
||||
@@ -316,4 +313,10 @@ std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
|
||||
return std::chrono::microseconds{Common::WallClock::CPUTickToUS(cpu_ticks)};
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void CoreTiming::SetTimerResolutionNs(std::chrono::nanoseconds ns) {
|
||||
timer_resolution_ns = ns.count();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Core::Timing
|
||||
|
||||
@@ -131,6 +131,10 @@ public:
|
||||
/// Checks for events manually and returns time in nanoseconds for next event, threadsafe.
|
||||
std::optional<s64> Advance();
|
||||
|
||||
#ifdef _WIN32
|
||||
void SetTimerResolutionNs(std::chrono::nanoseconds ns);
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct Event;
|
||||
|
||||
@@ -143,6 +147,10 @@ private:
|
||||
|
||||
s64 global_timer = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
s64 timer_resolution_ns;
|
||||
#endif
|
||||
|
||||
// The queue is a min-heap using std::make_heap/push_heap/pop_heap.
|
||||
// We don't use std::priority_queue because we need to be able to serialize, unserialize and
|
||||
// erase arbitrary events (RemoveEvent()) regardless of the queue order. These aren't
|
||||
|
||||
@@ -105,19 +105,11 @@ static u64 romfs_get_hash_table_count(u64 num_entries) {
|
||||
return count;
|
||||
}
|
||||
|
||||
void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir,
|
||||
void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir,
|
||||
std::shared_ptr<RomFSBuildDirectoryContext> parent) {
|
||||
std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs;
|
||||
|
||||
VirtualDir dir;
|
||||
|
||||
if (parent->path_len == 0) {
|
||||
dir = root_romfs;
|
||||
} else {
|
||||
dir = root_romfs->GetDirectoryRelative(parent->path);
|
||||
}
|
||||
|
||||
const auto entries = dir->GetEntries();
|
||||
const auto entries = romfs_dir->GetEntries();
|
||||
|
||||
for (const auto& kv : entries) {
|
||||
if (kv.second == VfsEntryType::Directory) {
|
||||
@@ -127,7 +119,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir
|
||||
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size());
|
||||
child->path = parent->path + "/" + kv.first;
|
||||
|
||||
if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) {
|
||||
if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -144,17 +136,17 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir
|
||||
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size());
|
||||
child->path = parent->path + "/" + kv.first;
|
||||
|
||||
if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) {
|
||||
if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanity check on path_len
|
||||
ASSERT(child->path_len < FS_MAX_PATH);
|
||||
|
||||
child->source = root_romfs->GetFileRelative(child->path);
|
||||
child->source = romfs_dir->GetFile(kv.first);
|
||||
|
||||
if (ext_dir != nullptr) {
|
||||
if (const auto ips = ext_dir->GetFileRelative(child->path + ".ips")) {
|
||||
if (const auto ips = ext_dir->GetFile(kv.first + ".ips")) {
|
||||
if (auto patched = PatchIPS(child->source, ips)) {
|
||||
child->source = std::move(patched);
|
||||
}
|
||||
@@ -168,23 +160,27 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir
|
||||
}
|
||||
|
||||
for (auto& child : child_dirs) {
|
||||
this->VisitDirectory(root_romfs, ext_dir, child);
|
||||
auto subdir_name = std::string_view(child->path).substr(child->cur_path_ofs);
|
||||
auto child_romfs_dir = romfs_dir->GetSubdirectory(subdir_name);
|
||||
auto child_ext_dir = ext_dir != nullptr ? ext_dir->GetSubdirectory(subdir_name) : nullptr;
|
||||
this->VisitDirectory(child_romfs_dir, child_ext_dir, child);
|
||||
}
|
||||
}
|
||||
|
||||
bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx,
|
||||
std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx) {
|
||||
// Check whether it's already in the known directories.
|
||||
const auto existing = directories.find(dir_ctx->path);
|
||||
if (existing != directories.end())
|
||||
const auto [it, is_new] = directories.emplace(dir_ctx->path, nullptr);
|
||||
if (!is_new) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add a new directory.
|
||||
num_dirs++;
|
||||
dir_table_size +=
|
||||
sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4);
|
||||
dir_ctx->parent = parent_dir_ctx;
|
||||
directories.emplace(dir_ctx->path, dir_ctx);
|
||||
it->second = dir_ctx;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -192,8 +188,8 @@ bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext>
|
||||
bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx,
|
||||
std::shared_ptr<RomFSBuildFileContext> file_ctx) {
|
||||
// Check whether it's already in the known files.
|
||||
const auto existing = files.find(file_ctx->path);
|
||||
if (existing != files.end()) {
|
||||
const auto [it, is_new] = files.emplace(file_ctx->path, nullptr);
|
||||
if (!is_new) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -202,7 +198,7 @@ bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> pare
|
||||
file_table_size +=
|
||||
sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4);
|
||||
file_ctx->parent = parent_dir_ctx;
|
||||
files.emplace(file_ctx->path, file_ctx);
|
||||
it->second = file_ctx;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,8 @@ std::size_t RealVfsFile::GetSize() const {
|
||||
if (size) {
|
||||
return *size;
|
||||
}
|
||||
return FS::GetSize(path);
|
||||
auto lk = base.RefreshReference(path, perms, *reference);
|
||||
return reference->file ? reference->file->GetSize() : 0;
|
||||
}
|
||||
|
||||
bool RealVfsFile::Resize(std::size_t new_size) {
|
||||
|
||||
122
src/core/gpu_dirty_memory_manager.h
Normal file
122
src/core/gpu_dirty_memory_manager.h
Normal file
@@ -0,0 +1,122 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <bit>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace Core {
|
||||
|
||||
class GPUDirtyMemoryManager {
|
||||
public:
|
||||
GPUDirtyMemoryManager() : current{default_transform} {
|
||||
back_buffer.reserve(256);
|
||||
front_buffer.reserve(256);
|
||||
}
|
||||
|
||||
~GPUDirtyMemoryManager() = default;
|
||||
|
||||
void Collect(VAddr address, size_t size) {
|
||||
TransformAddress t = BuildTransform(address, size);
|
||||
TransformAddress tmp, original;
|
||||
do {
|
||||
tmp = current.load(std::memory_order_acquire);
|
||||
original = tmp;
|
||||
if (tmp.address != t.address) {
|
||||
if (IsValid(tmp.address)) {
|
||||
std::scoped_lock lk(guard);
|
||||
back_buffer.emplace_back(tmp);
|
||||
current.exchange(t, std::memory_order_relaxed);
|
||||
return;
|
||||
}
|
||||
tmp.address = t.address;
|
||||
tmp.mask = 0;
|
||||
}
|
||||
if ((tmp.mask | t.mask) == tmp.mask) {
|
||||
return;
|
||||
}
|
||||
tmp.mask |= t.mask;
|
||||
} while (!current.compare_exchange_weak(original, tmp, std::memory_order_release,
|
||||
std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
void Gather(std::function<void(VAddr, size_t)>& callback) {
|
||||
{
|
||||
std::scoped_lock lk(guard);
|
||||
TransformAddress t = current.exchange(default_transform, std::memory_order_relaxed);
|
||||
front_buffer.swap(back_buffer);
|
||||
if (IsValid(t.address)) {
|
||||
front_buffer.emplace_back(t);
|
||||
}
|
||||
}
|
||||
for (auto& transform : front_buffer) {
|
||||
size_t offset = 0;
|
||||
u64 mask = transform.mask;
|
||||
while (mask != 0) {
|
||||
const size_t empty_bits = std::countr_zero(mask);
|
||||
offset += empty_bits << align_bits;
|
||||
mask = mask >> empty_bits;
|
||||
|
||||
const size_t continuous_bits = std::countr_one(mask);
|
||||
callback((static_cast<VAddr>(transform.address) << page_bits) + offset,
|
||||
continuous_bits << align_bits);
|
||||
mask = continuous_bits < align_size ? (mask >> continuous_bits) : 0;
|
||||
offset += continuous_bits << align_bits;
|
||||
}
|
||||
}
|
||||
front_buffer.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
struct alignas(8) TransformAddress {
|
||||
u32 address;
|
||||
u32 mask;
|
||||
};
|
||||
|
||||
constexpr static size_t page_bits = Memory::YUZU_PAGEBITS - 1;
|
||||
constexpr static size_t page_size = 1ULL << page_bits;
|
||||
constexpr static size_t page_mask = page_size - 1;
|
||||
|
||||
constexpr static size_t align_bits = 6U;
|
||||
constexpr static size_t align_size = 1U << align_bits;
|
||||
constexpr static size_t align_mask = align_size - 1;
|
||||
constexpr static TransformAddress default_transform = {.address = ~0U, .mask = 0U};
|
||||
|
||||
bool IsValid(VAddr address) {
|
||||
return address < (1ULL << 39);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T CreateMask(size_t top_bit, size_t minor_bit) {
|
||||
T mask = ~T(0);
|
||||
mask <<= (sizeof(T) * 8 - top_bit);
|
||||
mask >>= (sizeof(T) * 8 - top_bit);
|
||||
mask >>= minor_bit;
|
||||
mask <<= minor_bit;
|
||||
return mask;
|
||||
}
|
||||
|
||||
TransformAddress BuildTransform(VAddr address, size_t size) {
|
||||
const size_t minor_address = address & page_mask;
|
||||
const size_t minor_bit = minor_address >> align_bits;
|
||||
const size_t top_bit = (minor_address + size + align_mask) >> align_bits;
|
||||
TransformAddress result{};
|
||||
result.address = static_cast<u32>(address >> page_bits);
|
||||
result.mask = CreateMask<u32>(top_bit, minor_bit);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::atomic<TransformAddress> current{};
|
||||
std::mutex guard;
|
||||
std::vector<TransformAddress> back_buffer;
|
||||
std::vector<TransformAddress> front_buffer;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
@@ -1243,10 +1243,12 @@ Common::Input::DriverResult EmulatedController::SetPollingMode(
|
||||
auto& nfc_output_device = output_devices[3];
|
||||
|
||||
if (device_index == EmulatedDeviceIndex::LeftIndex) {
|
||||
controller.left_polling_mode = polling_mode;
|
||||
return left_output_device->SetPollingMode(polling_mode);
|
||||
}
|
||||
|
||||
if (device_index == EmulatedDeviceIndex::RightIndex) {
|
||||
controller.right_polling_mode = polling_mode;
|
||||
const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode);
|
||||
const auto mapped_nfc_result = right_output_device->SetPollingMode(polling_mode);
|
||||
|
||||
@@ -1261,12 +1263,22 @@ Common::Input::DriverResult EmulatedController::SetPollingMode(
|
||||
return mapped_nfc_result;
|
||||
}
|
||||
|
||||
controller.left_polling_mode = polling_mode;
|
||||
controller.right_polling_mode = polling_mode;
|
||||
left_output_device->SetPollingMode(polling_mode);
|
||||
right_output_device->SetPollingMode(polling_mode);
|
||||
nfc_output_device->SetPollingMode(polling_mode);
|
||||
return Common::Input::DriverResult::Success;
|
||||
}
|
||||
|
||||
Common::Input::PollingMode EmulatedController::GetPollingMode(
|
||||
EmulatedDeviceIndex device_index) const {
|
||||
if (device_index == EmulatedDeviceIndex::LeftIndex) {
|
||||
return controller.left_polling_mode;
|
||||
}
|
||||
return controller.right_polling_mode;
|
||||
}
|
||||
|
||||
bool EmulatedController::SetCameraFormat(
|
||||
Core::IrSensor::ImageTransferProcessorFormat camera_format) {
|
||||
LOG_INFO(Service_HID, "Set camera format {}", camera_format);
|
||||
|
||||
@@ -143,6 +143,8 @@ struct ControllerStatus {
|
||||
CameraState camera_state{};
|
||||
RingSensorForce ring_analog_state{};
|
||||
NfcState nfc_state{};
|
||||
Common::Input::PollingMode left_polling_mode{};
|
||||
Common::Input::PollingMode right_polling_mode{};
|
||||
};
|
||||
|
||||
enum class ControllerTriggerType {
|
||||
@@ -370,6 +372,12 @@ public:
|
||||
*/
|
||||
Common::Input::DriverResult SetPollingMode(EmulatedDeviceIndex device_index,
|
||||
Common::Input::PollingMode polling_mode);
|
||||
/**
|
||||
* Get the current polling mode from a controller
|
||||
* @param device_index index of the controller to set the polling mode
|
||||
* @return current polling mode
|
||||
*/
|
||||
Common::Input::PollingMode GetPollingMode(EmulatedDeviceIndex device_index) const;
|
||||
|
||||
/**
|
||||
* Sets the desired camera format to be polled from a controller
|
||||
|
||||
@@ -338,6 +338,15 @@ public:
|
||||
return m_parent != nullptr;
|
||||
}
|
||||
|
||||
std::span<KSynchronizationObject*> GetSynchronizationObjectBuffer() {
|
||||
return m_sync_object_buffer.sync_objects;
|
||||
}
|
||||
|
||||
std::span<Handle> GetHandleBuffer() {
|
||||
return {m_sync_object_buffer.handles.data() + Svc::ArgumentHandleCountMax,
|
||||
Svc::ArgumentHandleCountMax};
|
||||
}
|
||||
|
||||
u16 GetUserDisableCount() const;
|
||||
void SetInterruptFlag();
|
||||
void ClearInterruptFlag();
|
||||
@@ -855,6 +864,7 @@ private:
|
||||
u32* m_light_ipc_data{};
|
||||
KProcessAddress m_tls_address{};
|
||||
KLightLock m_activity_pause_lock;
|
||||
SyncObjectBuffer m_sync_object_buffer{};
|
||||
s64 m_schedule_count{};
|
||||
s64 m_last_scheduled_tick{};
|
||||
std::array<QueueEntry, Core::Hardware::NUM_CPU_CORES> m_per_core_priority_queue_entry{};
|
||||
|
||||
@@ -38,22 +38,31 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
|
||||
|
||||
Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles,
|
||||
Handle reply_target, s64 timeout_ns) {
|
||||
// Ensure number of handles is valid.
|
||||
R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange);
|
||||
|
||||
// Get the synchronization context.
|
||||
auto& kernel = system.Kernel();
|
||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
||||
auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer();
|
||||
auto handles = GetCurrentThread(kernel).GetHandleBuffer();
|
||||
|
||||
R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange);
|
||||
R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange(
|
||||
handles_addr, static_cast<u64>(sizeof(Handle) * num_handles)),
|
||||
ResultInvalidPointer);
|
||||
// Copy user handles.
|
||||
if (num_handles > 0) {
|
||||
// Ensure we can try to get the handles.
|
||||
R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange(
|
||||
handles_addr, static_cast<u64>(sizeof(Handle) * num_handles)),
|
||||
ResultInvalidPointer);
|
||||
|
||||
std::array<Handle, Svc::ArgumentHandleCountMax> handles;
|
||||
GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(), sizeof(Handle) * num_handles);
|
||||
// Get the handles.
|
||||
GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(),
|
||||
sizeof(Handle) * num_handles);
|
||||
|
||||
// Convert handle list to object table.
|
||||
std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> objs;
|
||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles.data(),
|
||||
num_handles),
|
||||
ResultInvalidHandle);
|
||||
// Convert the handles to objects.
|
||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(
|
||||
objs.data(), handles.data(), num_handles),
|
||||
ResultInvalidHandle);
|
||||
}
|
||||
|
||||
// Ensure handles are closed when we're done.
|
||||
SCOPE_EXIT({
|
||||
|
||||
@@ -47,21 +47,35 @@ Result ResetSignal(Core::System& system, Handle handle) {
|
||||
R_THROW(ResultInvalidHandle);
|
||||
}
|
||||
|
||||
static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles,
|
||||
int32_t num_handles, int64_t timeout_ns) {
|
||||
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
|
||||
Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_handles,
|
||||
int32_t num_handles, int64_t timeout_ns) {
|
||||
LOG_TRACE(Kernel_SVC, "called user_handles={:#x}, num_handles={}, timeout_ns={}", user_handles,
|
||||
num_handles, timeout_ns);
|
||||
|
||||
// Ensure number of handles is valid.
|
||||
R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange);
|
||||
|
||||
// Get the synchronization context.
|
||||
auto& kernel = system.Kernel();
|
||||
auto& handle_table = GetCurrentProcess(kernel).GetHandleTable();
|
||||
std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> objs;
|
||||
auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer();
|
||||
auto handles = GetCurrentThread(kernel).GetHandleBuffer();
|
||||
|
||||
// Copy user handles.
|
||||
if (num_handles > 0) {
|
||||
// Ensure we can try to get the handles.
|
||||
R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange(
|
||||
user_handles, static_cast<u64>(sizeof(Handle) * num_handles)),
|
||||
ResultInvalidPointer);
|
||||
|
||||
// Get the handles.
|
||||
GetCurrentMemory(kernel).ReadBlock(user_handles, handles.data(),
|
||||
sizeof(Handle) * num_handles);
|
||||
|
||||
// Convert the handles to objects.
|
||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles,
|
||||
num_handles),
|
||||
R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(
|
||||
objs.data(), handles.data(), num_handles),
|
||||
ResultInvalidHandle);
|
||||
}
|
||||
|
||||
@@ -80,23 +94,6 @@ static Result WaitSynchronization(Core::System& system, int32_t* out_index, cons
|
||||
R_RETURN(res);
|
||||
}
|
||||
|
||||
/// Wait for the given handles to synchronize, timeout after the specified nanoseconds
|
||||
Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_handles,
|
||||
int32_t num_handles, int64_t timeout_ns) {
|
||||
LOG_TRACE(Kernel_SVC, "called user_handles={:#x}, num_handles={}, timeout_ns={}", user_handles,
|
||||
num_handles, timeout_ns);
|
||||
|
||||
// Ensure number of handles is valid.
|
||||
R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange);
|
||||
std::array<Handle, Svc::ArgumentHandleCountMax> handles;
|
||||
if (num_handles > 0) {
|
||||
GetCurrentMemory(system.Kernel())
|
||||
.ReadBlock(user_handles, handles.data(), num_handles * sizeof(Handle));
|
||||
}
|
||||
|
||||
R_RETURN(WaitSynchronization(system, out_index, handles.data(), num_handles, timeout_ns));
|
||||
}
|
||||
|
||||
/// Resumes a thread waiting on WaitSynchronization
|
||||
Result CancelSynchronization(Core::System& system, Handle handle) {
|
||||
LOG_TRACE(Kernel_SVC, "called handle=0x{:X}", handle);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "audio_core/renderer/audio_device.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/settings.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
@@ -124,12 +124,15 @@ private:
|
||||
|
||||
void GetReleasedAudioInBuffer(HLERequestContext& ctx) {
|
||||
const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>();
|
||||
tmp_buffer.resize_destructive(write_buffer_size);
|
||||
tmp_buffer[0] = 0;
|
||||
released_buffer.resize_destructive(write_buffer_size);
|
||||
released_buffer[0] = 0;
|
||||
|
||||
const auto count = impl->GetReleasedBuffers(tmp_buffer);
|
||||
const auto count = impl->GetReleasedBuffers(released_buffer);
|
||||
|
||||
ctx.WriteBuffer(tmp_buffer);
|
||||
LOG_TRACE(Service_Audio, "called. Session {} released {} buffers",
|
||||
impl->GetSystem().GetSessionId(), count);
|
||||
|
||||
ctx.WriteBuffer(released_buffer);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
@@ -155,7 +158,6 @@ private:
|
||||
LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(buffer_count);
|
||||
}
|
||||
@@ -195,7 +197,7 @@ private:
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
Kernel::KEvent* event;
|
||||
std::shared_ptr<AudioCore::AudioIn::In> impl;
|
||||
Common::ScratchBuffer<u64> tmp_buffer;
|
||||
Common::ScratchBuffer<u64> released_buffer;
|
||||
};
|
||||
|
||||
AudInU::AudInU(Core::System& system_)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "audio_core/renderer/audio_device.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/string_util.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/core.h"
|
||||
@@ -102,8 +103,8 @@ private:
|
||||
AudioOutBuffer buffer{};
|
||||
std::memcpy(&buffer, in_buffer.data(), sizeof(AudioOutBuffer));
|
||||
|
||||
[[maybe_unused]] auto sessionid{impl->GetSystem().GetSessionId()};
|
||||
LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}", sessionid, tag);
|
||||
LOG_TRACE(Service_Audio, "called. Session {} Appending buffer {:08X}",
|
||||
impl->GetSystem().GetSessionId(), tag);
|
||||
|
||||
auto result = impl->AppendBuffer(buffer, tag);
|
||||
|
||||
@@ -123,12 +124,15 @@ private:
|
||||
|
||||
void GetReleasedAudioOutBuffers(HLERequestContext& ctx) {
|
||||
const auto write_buffer_size = ctx.GetWriteBufferNumElements<u64>();
|
||||
tmp_buffer.resize_destructive(write_buffer_size);
|
||||
tmp_buffer[0] = 0;
|
||||
released_buffer.resize_destructive(write_buffer_size);
|
||||
released_buffer[0] = 0;
|
||||
|
||||
const auto count = impl->GetReleasedBuffers(tmp_buffer);
|
||||
const auto count = impl->GetReleasedBuffers(released_buffer);
|
||||
|
||||
ctx.WriteBuffer(tmp_buffer);
|
||||
ctx.WriteBuffer(released_buffer);
|
||||
|
||||
LOG_TRACE(Service_Audio, "called. Session {} released {} buffers",
|
||||
impl->GetSystem().GetSessionId(), count);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(ResultSuccess);
|
||||
@@ -154,7 +158,6 @@ private:
|
||||
LOG_DEBUG(Service_Audio, "called. Buffer count={}", buffer_count);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(buffer_count);
|
||||
}
|
||||
@@ -165,7 +168,6 @@ private:
|
||||
LOG_DEBUG(Service_Audio, "called. Played samples={}", samples_played);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 4};
|
||||
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(samples_played);
|
||||
}
|
||||
@@ -205,7 +207,7 @@ private:
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
Kernel::KEvent* event;
|
||||
std::shared_ptr<AudioCore::AudioOut::Out> impl;
|
||||
Common::ScratchBuffer<u64> tmp_buffer;
|
||||
Common::ScratchBuffer<u64> released_buffer;
|
||||
};
|
||||
|
||||
AudOutU::AudOutU(Core::System& system_)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
@@ -119,23 +120,23 @@ private:
|
||||
auto is_buffer_b{ctx.BufferDescriptorB()[0].Size() != 0};
|
||||
if (is_buffer_b) {
|
||||
const auto buffersB{ctx.BufferDescriptorB()};
|
||||
tmp_output.resize_destructive(buffersB[0].Size());
|
||||
tmp_performance.resize_destructive(buffersB[1].Size());
|
||||
output_buffer.resize_destructive(buffersB[0].Size());
|
||||
performance_buffer.resize_destructive(buffersB[1].Size());
|
||||
} else {
|
||||
const auto buffersC{ctx.BufferDescriptorC()};
|
||||
tmp_output.resize_destructive(buffersC[0].Size());
|
||||
tmp_performance.resize_destructive(buffersC[1].Size());
|
||||
output_buffer.resize_destructive(buffersC[0].Size());
|
||||
performance_buffer.resize_destructive(buffersC[1].Size());
|
||||
}
|
||||
|
||||
auto result = impl->RequestUpdate(input, tmp_performance, tmp_output);
|
||||
auto result = impl->RequestUpdate(input, performance_buffer, output_buffer);
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
if (is_buffer_b) {
|
||||
ctx.WriteBufferB(tmp_output.data(), tmp_output.size(), 0);
|
||||
ctx.WriteBufferB(tmp_performance.data(), tmp_performance.size(), 1);
|
||||
ctx.WriteBufferB(output_buffer.data(), output_buffer.size(), 0);
|
||||
ctx.WriteBufferB(performance_buffer.data(), performance_buffer.size(), 1);
|
||||
} else {
|
||||
ctx.WriteBufferC(tmp_output.data(), tmp_output.size(), 0);
|
||||
ctx.WriteBufferC(tmp_performance.data(), tmp_performance.size(), 1);
|
||||
ctx.WriteBufferC(output_buffer.data(), output_buffer.size(), 0);
|
||||
ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1);
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description);
|
||||
@@ -233,8 +234,8 @@ private:
|
||||
Kernel::KEvent* rendered_event;
|
||||
Manager& manager;
|
||||
std::unique_ptr<Renderer> impl;
|
||||
Common::ScratchBuffer<u8> tmp_output;
|
||||
Common::ScratchBuffer<u8> tmp_performance;
|
||||
Common::ScratchBuffer<u8> output_buffer;
|
||||
Common::ScratchBuffer<u8> performance_buffer;
|
||||
};
|
||||
|
||||
class IAudioDevice final : public ServiceFramework<IAudioDevice> {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "core/hle/service/audio/hwopus.h"
|
||||
#include "core/hle/service/ipc_helpers.h"
|
||||
|
||||
@@ -68,13 +69,13 @@ private:
|
||||
ExtraBehavior extra_behavior) {
|
||||
u32 consumed = 0;
|
||||
u32 sample_count = 0;
|
||||
tmp_samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>());
|
||||
samples.resize_destructive(ctx.GetWriteBufferNumElements<opus_int16>());
|
||||
|
||||
if (extra_behavior == ExtraBehavior::ResetContext) {
|
||||
ResetDecoderContext();
|
||||
}
|
||||
|
||||
if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), tmp_samples, performance)) {
|
||||
if (!DecodeOpusData(consumed, sample_count, ctx.ReadBuffer(), samples, performance)) {
|
||||
LOG_ERROR(Audio, "Failed to decode opus data");
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
// TODO(ogniK): Use correct error code
|
||||
@@ -90,7 +91,7 @@ private:
|
||||
if (performance) {
|
||||
rb.Push<u64>(*performance);
|
||||
}
|
||||
ctx.WriteBuffer(tmp_samples);
|
||||
ctx.WriteBuffer(samples);
|
||||
}
|
||||
|
||||
bool DecodeOpusData(u32& consumed, u32& sample_count, std::span<const u8> input,
|
||||
@@ -154,7 +155,7 @@ private:
|
||||
OpusDecoderPtr decoder;
|
||||
u32 sample_rate;
|
||||
u32 channel_count;
|
||||
Common::ScratchBuffer<opus_int16> tmp_samples;
|
||||
Common::ScratchBuffer<opus_int16> samples;
|
||||
};
|
||||
|
||||
class IHardwareOpusDecoderManager final : public ServiceFramework<IHardwareOpusDecoderManager> {
|
||||
|
||||
@@ -66,10 +66,6 @@ NfcDevice::~NfcDevice() {
|
||||
};
|
||||
|
||||
void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
|
||||
if (!is_initalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == Core::HID::ControllerTriggerType::Connected) {
|
||||
Initialize();
|
||||
availability_change_event->Signal();
|
||||
@@ -77,12 +73,12 @@ void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
|
||||
}
|
||||
|
||||
if (type == Core::HID::ControllerTriggerType::Disconnected) {
|
||||
device_state = DeviceState::Unavailable;
|
||||
Finalize();
|
||||
availability_change_event->Signal();
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != Core::HID::ControllerTriggerType::Nfc) {
|
||||
if (!is_initalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,6 +86,17 @@ void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure nfc mode is always active
|
||||
if (npad_device->GetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex) ==
|
||||
Common::Input::PollingMode::Active) {
|
||||
npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
|
||||
Common::Input::PollingMode::NFC);
|
||||
}
|
||||
|
||||
if (type != Core::HID::ControllerTriggerType::Nfc) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto nfc_status = npad_device->GetNfc();
|
||||
switch (nfc_status.state) {
|
||||
case Common::Input::NfcState::NewAmiibo:
|
||||
@@ -207,11 +214,14 @@ void NfcDevice::Initialize() {
|
||||
}
|
||||
|
||||
void NfcDevice::Finalize() {
|
||||
if (device_state == DeviceState::TagMounted) {
|
||||
Unmount();
|
||||
}
|
||||
if (device_state == DeviceState::SearchingForTag || device_state == DeviceState::TagRemoved) {
|
||||
StopDetection();
|
||||
if (npad_device->IsConnected()) {
|
||||
if (device_state == DeviceState::TagMounted) {
|
||||
Unmount();
|
||||
}
|
||||
if (device_state == DeviceState::SearchingForTag ||
|
||||
device_state == DeviceState::TagRemoved) {
|
||||
StopDetection();
|
||||
}
|
||||
}
|
||||
|
||||
if (device_state != DeviceState::Unavailable) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// SPDX-FileCopyrightText: 2021 Skyline Team and Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <cinttypes>
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
@@ -63,12 +62,12 @@ void NVDRV::Ioctl1(HLERequestContext& ctx) {
|
||||
}
|
||||
|
||||
// Check device
|
||||
tmp_output.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
const auto input_buffer = ctx.ReadBuffer(0);
|
||||
|
||||
const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, tmp_output);
|
||||
const auto nv_result = nvdrv->Ioctl1(fd, command, input_buffer, output_buffer);
|
||||
if (command.is_out != 0) {
|
||||
ctx.WriteBuffer(tmp_output);
|
||||
ctx.WriteBuffer(output_buffer);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
@@ -90,12 +89,12 @@ void NVDRV::Ioctl2(HLERequestContext& ctx) {
|
||||
|
||||
const auto input_buffer = ctx.ReadBuffer(0);
|
||||
const auto input_inlined_buffer = ctx.ReadBuffer(1);
|
||||
tmp_output.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
|
||||
const auto nv_result =
|
||||
nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, tmp_output);
|
||||
nvdrv->Ioctl2(fd, command, input_buffer, input_inlined_buffer, output_buffer);
|
||||
if (command.is_out != 0) {
|
||||
ctx.WriteBuffer(tmp_output);
|
||||
ctx.WriteBuffer(output_buffer);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
@@ -116,12 +115,14 @@ void NVDRV::Ioctl3(HLERequestContext& ctx) {
|
||||
}
|
||||
|
||||
const auto input_buffer = ctx.ReadBuffer(0);
|
||||
tmp_output.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
tmp_output_inline.resize_destructive(ctx.GetWriteBufferSize(1));
|
||||
const auto nv_result = nvdrv->Ioctl3(fd, command, input_buffer, tmp_output, tmp_output_inline);
|
||||
output_buffer.resize_destructive(ctx.GetWriteBufferSize(0));
|
||||
inline_output_buffer.resize_destructive(ctx.GetWriteBufferSize(1));
|
||||
|
||||
const auto nv_result =
|
||||
nvdrv->Ioctl3(fd, command, input_buffer, output_buffer, inline_output_buffer);
|
||||
if (command.is_out != 0) {
|
||||
ctx.WriteBuffer(tmp_output, 0);
|
||||
ctx.WriteBuffer(tmp_output_inline, 1);
|
||||
ctx.WriteBuffer(output_buffer, 0);
|
||||
ctx.WriteBuffer(inline_output_buffer, 1);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "core/hle/service/nvdrv/nvdrv.h"
|
||||
#include "core/hle/service/service.h"
|
||||
@@ -34,8 +35,8 @@ private:
|
||||
|
||||
u64 pid{};
|
||||
bool is_initialized{};
|
||||
Common::ScratchBuffer<u8> tmp_output;
|
||||
Common::ScratchBuffer<u8> tmp_output_inline;
|
||||
Common::ScratchBuffer<u8> output_buffer;
|
||||
Common::ScratchBuffer<u8> inline_output_buffer;
|
||||
};
|
||||
|
||||
} // namespace Service::Nvidia
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
#include "common/alignment.h"
|
||||
@@ -148,9 +149,9 @@ public:
|
||||
this->WriteImpl(0U, m_object_buffer);
|
||||
}
|
||||
|
||||
std::vector<u8> Serialize() const {
|
||||
std::vector<u8> output_buffer(sizeof(ParcelHeader) + m_data_buffer.size() +
|
||||
m_object_buffer.size());
|
||||
std::span<u8> Serialize() {
|
||||
m_output_buffer.resize(sizeof(ParcelHeader) + m_data_buffer.size() +
|
||||
m_object_buffer.size());
|
||||
|
||||
ParcelHeader header{};
|
||||
header.data_size = static_cast<u32>(m_data_buffer.size());
|
||||
@@ -158,17 +159,17 @@ public:
|
||||
header.objects_size = static_cast<u32>(m_object_buffer.size());
|
||||
header.objects_offset = header.data_offset + header.data_size;
|
||||
|
||||
std::memcpy(output_buffer.data(), &header, sizeof(header));
|
||||
std::ranges::copy(m_data_buffer, output_buffer.data() + header.data_offset);
|
||||
std::ranges::copy(m_object_buffer, output_buffer.data() + header.objects_offset);
|
||||
std::memcpy(m_output_buffer.data(), &header, sizeof(ParcelHeader));
|
||||
std::ranges::copy(m_data_buffer, m_output_buffer.data() + header.data_offset);
|
||||
std::ranges::copy(m_object_buffer, m_output_buffer.data() + header.objects_offset);
|
||||
|
||||
return output_buffer;
|
||||
return m_output_buffer;
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
template <typename T, size_t BufferSize>
|
||||
requires(std::is_trivially_copyable_v<T>)
|
||||
void WriteImpl(const T& val, boost::container::small_vector<u8, 0x200>& buffer) {
|
||||
void WriteImpl(const T& val, boost::container::small_vector<u8, BufferSize>& buffer) {
|
||||
const size_t aligned_size = Common::AlignUp(sizeof(T), 4);
|
||||
const size_t old_size = buffer.size();
|
||||
buffer.resize(old_size + aligned_size);
|
||||
@@ -177,8 +178,9 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
boost::container::small_vector<u8, 0x200> m_data_buffer;
|
||||
boost::container::small_vector<u8, 0x200> m_object_buffer;
|
||||
boost::container::small_vector<u8, 0x1B0> m_data_buffer;
|
||||
boost::container::small_vector<u8, 0x40> m_object_buffer;
|
||||
boost::container::small_vector<u8, 0x200> m_output_buffer;
|
||||
};
|
||||
|
||||
} // namespace Service::android
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <span>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/atomic_ops.h"
|
||||
@@ -13,6 +14,7 @@
|
||||
#include "common/swap.h"
|
||||
#include "core/core.h"
|
||||
#include "core/device_memory.h"
|
||||
#include "core/gpu_dirty_memory_manager.h"
|
||||
#include "core/hardware_properties.h"
|
||||
#include "core/hle/kernel/k_page_table.h"
|
||||
#include "core/hle/kernel/k_process.h"
|
||||
@@ -678,7 +680,7 @@ struct Memory::Impl {
|
||||
LOG_ERROR(HW_Memory, "Unmapped Write{} @ 0x{:016X} = 0x{:016X}", sizeof(T) * 8,
|
||||
GetInteger(vaddr), static_cast<u64>(data));
|
||||
},
|
||||
[&]() { system.GPU().InvalidateRegion(GetInteger(vaddr), sizeof(T)); });
|
||||
[&]() { HandleRasterizerWrite(GetInteger(vaddr), sizeof(T)); });
|
||||
if (ptr) {
|
||||
std::memcpy(ptr, &data, sizeof(T));
|
||||
}
|
||||
@@ -692,7 +694,7 @@ struct Memory::Impl {
|
||||
LOG_ERROR(HW_Memory, "Unmapped WriteExclusive{} @ 0x{:016X} = 0x{:016X}",
|
||||
sizeof(T) * 8, GetInteger(vaddr), static_cast<u64>(data));
|
||||
},
|
||||
[&]() { system.GPU().InvalidateRegion(GetInteger(vaddr), sizeof(T)); });
|
||||
[&]() { HandleRasterizerWrite(GetInteger(vaddr), sizeof(T)); });
|
||||
if (ptr) {
|
||||
const auto volatile_pointer = reinterpret_cast<volatile T*>(ptr);
|
||||
return Common::AtomicCompareAndSwap(volatile_pointer, data, expected);
|
||||
@@ -707,7 +709,7 @@ struct Memory::Impl {
|
||||
LOG_ERROR(HW_Memory, "Unmapped WriteExclusive128 @ 0x{:016X} = 0x{:016X}{:016X}",
|
||||
GetInteger(vaddr), static_cast<u64>(data[1]), static_cast<u64>(data[0]));
|
||||
},
|
||||
[&]() { system.GPU().InvalidateRegion(GetInteger(vaddr), sizeof(u128)); });
|
||||
[&]() { HandleRasterizerWrite(GetInteger(vaddr), sizeof(u128)); });
|
||||
if (ptr) {
|
||||
const auto volatile_pointer = reinterpret_cast<volatile u64*>(ptr);
|
||||
return Common::AtomicCompareAndSwap(volatile_pointer, data, expected);
|
||||
@@ -717,7 +719,7 @@ struct Memory::Impl {
|
||||
|
||||
void HandleRasterizerDownload(VAddr address, size_t size) {
|
||||
const size_t core = system.GetCurrentHostThreadID();
|
||||
auto& current_area = rasterizer_areas[core];
|
||||
auto& current_area = rasterizer_read_areas[core];
|
||||
const VAddr end_address = address + size;
|
||||
if (current_area.start_address <= address && end_address <= current_area.end_address)
|
||||
[[likely]] {
|
||||
@@ -726,9 +728,31 @@ struct Memory::Impl {
|
||||
current_area = system.GPU().OnCPURead(address, size);
|
||||
}
|
||||
|
||||
Common::PageTable* current_page_table = nullptr;
|
||||
std::array<VideoCore::RasterizerDownloadArea, Core::Hardware::NUM_CPU_CORES> rasterizer_areas{};
|
||||
void HandleRasterizerWrite(VAddr address, size_t size) {
|
||||
const size_t core = system.GetCurrentHostThreadID();
|
||||
auto& current_area = rasterizer_write_areas[core];
|
||||
VAddr subaddress = address >> YUZU_PAGEBITS;
|
||||
bool do_collection = current_area.last_address == subaddress;
|
||||
if (!do_collection) [[unlikely]] {
|
||||
do_collection = system.GPU().OnCPUWrite(address, size);
|
||||
if (!do_collection) {
|
||||
return;
|
||||
}
|
||||
current_area.last_address = subaddress;
|
||||
}
|
||||
gpu_dirty_managers[core].Collect(address, size);
|
||||
}
|
||||
|
||||
struct GPUDirtyState {
|
||||
VAddr last_address;
|
||||
};
|
||||
|
||||
Core::System& system;
|
||||
Common::PageTable* current_page_table = nullptr;
|
||||
std::array<VideoCore::RasterizerDownloadArea, Core::Hardware::NUM_CPU_CORES>
|
||||
rasterizer_read_areas{};
|
||||
std::array<GPUDirtyState, Core::Hardware::NUM_CPU_CORES> rasterizer_write_areas{};
|
||||
std::span<Core::GPUDirtyMemoryManager> gpu_dirty_managers;
|
||||
};
|
||||
|
||||
Memory::Memory(Core::System& system_) : system{system_} {
|
||||
@@ -876,6 +900,10 @@ void Memory::ZeroBlock(Common::ProcessAddress dest_addr, const std::size_t size)
|
||||
impl->ZeroBlock(*system.ApplicationProcess(), dest_addr, size);
|
||||
}
|
||||
|
||||
void Memory::SetGPUDirtyManagers(std::span<Core::GPUDirtyMemoryManager> managers) {
|
||||
impl->gpu_dirty_managers = managers;
|
||||
}
|
||||
|
||||
Result Memory::InvalidateDataCache(Common::ProcessAddress dest_addr, const std::size_t size) {
|
||||
return impl->InvalidateDataCache(*system.ApplicationProcess(), dest_addr, size);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include "common/typed_address.h"
|
||||
#include "core/hle/result.h"
|
||||
@@ -15,7 +16,8 @@ struct PageTable;
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
class GPUDirtyMemoryManager;
|
||||
} // namespace Core
|
||||
|
||||
namespace Kernel {
|
||||
class PhysicalMemory;
|
||||
@@ -458,6 +460,8 @@ public:
|
||||
*/
|
||||
void MarkRegionDebug(Common::ProcessAddress vaddr, u64 size, bool debug);
|
||||
|
||||
void SetGPUDirtyManagers(std::span<Core::GPUDirtyMemoryManager> managers);
|
||||
|
||||
private:
|
||||
Core::System& system;
|
||||
|
||||
|
||||
@@ -12,9 +12,13 @@
|
||||
|
||||
namespace InputCommon {
|
||||
constexpr int update_time = 10;
|
||||
constexpr float default_stick_sensitivity = 0.0044f;
|
||||
constexpr float default_motion_sensitivity = 0.0003f;
|
||||
constexpr float default_panning_sensitivity = 0.0010f;
|
||||
constexpr float default_stick_sensitivity = 0.0006f;
|
||||
constexpr float default_deadzone_counterweight = 0.01f;
|
||||
constexpr float default_motion_panning_sensitivity = 2.5f;
|
||||
constexpr float default_motion_sensitivity = 0.416f;
|
||||
constexpr float maximum_rotation_speed = 2.0f;
|
||||
constexpr float maximum_stick_range = 1.5f;
|
||||
constexpr int mouse_axis_x = 0;
|
||||
constexpr int mouse_axis_y = 1;
|
||||
constexpr int wheel_axis_x = 2;
|
||||
@@ -81,7 +85,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
|
||||
}
|
||||
|
||||
void Mouse::UpdateStickInput() {
|
||||
if (!Settings::values.mouse_panning) {
|
||||
if (!IsMousePanningEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,26 +93,13 @@ void Mouse::UpdateStickInput() {
|
||||
|
||||
// Prevent input from exceeding the max range (1.0f) too much,
|
||||
// but allow some room to make it easier to sustain
|
||||
if (length > 1.2f) {
|
||||
if (length > maximum_stick_range) {
|
||||
last_mouse_change /= length;
|
||||
last_mouse_change *= 1.2f;
|
||||
last_mouse_change *= maximum_stick_range;
|
||||
}
|
||||
|
||||
auto mouse_change = last_mouse_change;
|
||||
|
||||
// Bind the mouse change to [0 <= deadzone_counterweight <= 1,1]
|
||||
if (length < 1.0f) {
|
||||
const float deadzone_h_counterweight =
|
||||
Settings::values.mouse_panning_deadzone_x_counterweight.GetValue();
|
||||
const float deadzone_v_counterweight =
|
||||
Settings::values.mouse_panning_deadzone_y_counterweight.GetValue();
|
||||
mouse_change /= length;
|
||||
mouse_change.x *= length + (1 - length) * deadzone_h_counterweight * 0.01f;
|
||||
mouse_change.y *= length + (1 - length) * deadzone_v_counterweight * 0.01f;
|
||||
}
|
||||
|
||||
SetAxis(identifier, mouse_axis_x, mouse_change.x);
|
||||
SetAxis(identifier, mouse_axis_y, -mouse_change.y);
|
||||
SetAxis(identifier, mouse_axis_x, last_mouse_change.x);
|
||||
SetAxis(identifier, mouse_axis_y, -last_mouse_change.y);
|
||||
|
||||
// Decay input over time
|
||||
const float clamped_length = std::min(1.0f, length);
|
||||
@@ -120,14 +111,13 @@ void Mouse::UpdateStickInput() {
|
||||
}
|
||||
|
||||
void Mouse::UpdateMotionInput() {
|
||||
// This may need its own sensitivity instead of using the average
|
||||
const float sensitivity = (Settings::values.mouse_panning_x_sensitivity.GetValue() +
|
||||
Settings::values.mouse_panning_y_sensitivity.GetValue()) /
|
||||
2.0f * default_motion_sensitivity;
|
||||
const float sensitivity =
|
||||
IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
|
||||
|
||||
const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x +
|
||||
last_motion_change.y * last_motion_change.y);
|
||||
|
||||
// Clamp rotation speed
|
||||
if (rotation_velocity > maximum_rotation_speed / sensitivity) {
|
||||
const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity;
|
||||
last_motion_change.x = last_motion_change.x * multiplier;
|
||||
@@ -144,7 +134,7 @@ void Mouse::UpdateMotionInput() {
|
||||
.delta_timestamp = update_time * 1000,
|
||||
};
|
||||
|
||||
if (Settings::values.mouse_panning) {
|
||||
if (IsMousePanningEnabled()) {
|
||||
last_motion_change.x = 0;
|
||||
last_motion_change.y = 0;
|
||||
}
|
||||
@@ -154,33 +144,43 @@ void Mouse::UpdateMotionInput() {
|
||||
}
|
||||
|
||||
void Mouse::Move(int x, int y, int center_x, int center_y) {
|
||||
if (Settings::values.mouse_panning) {
|
||||
if (IsMousePanningEnabled()) {
|
||||
const auto mouse_change =
|
||||
(Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
|
||||
const float x_sensitivity =
|
||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
|
||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
const float y_sensitivity =
|
||||
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity;
|
||||
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
|
||||
const float deadzone_counterweight =
|
||||
Settings::values.mouse_panning_deadzone_counterweight.GetValue() *
|
||||
default_deadzone_counterweight;
|
||||
|
||||
last_motion_change += {-mouse_change.y, -mouse_change.x, 0};
|
||||
last_mouse_change.x += mouse_change.x * x_sensitivity * 0.09f;
|
||||
last_mouse_change.y += mouse_change.y * y_sensitivity * 0.09f;
|
||||
last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0};
|
||||
last_mouse_change.x += mouse_change.x * x_sensitivity;
|
||||
last_mouse_change.y += mouse_change.y * y_sensitivity;
|
||||
|
||||
// Bind the mouse change to [0 <= deadzone_counterweight <= 1.0]
|
||||
const float length = last_mouse_change.Length();
|
||||
if (length < deadzone_counterweight && length != 0.0f) {
|
||||
last_mouse_change /= length;
|
||||
last_mouse_change *= deadzone_counterweight;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (button_pressed) {
|
||||
const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin;
|
||||
const float x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue();
|
||||
const float y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue();
|
||||
SetAxis(identifier, mouse_axis_x,
|
||||
static_cast<float>(mouse_move.x) * x_sensitivity * 0.0012f);
|
||||
SetAxis(identifier, mouse_axis_y,
|
||||
static_cast<float>(-mouse_move.y) * y_sensitivity * 0.0012f);
|
||||
const float x_sensitivity =
|
||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
|
||||
const float y_sensitivity =
|
||||
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity;
|
||||
SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * x_sensitivity);
|
||||
SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * y_sensitivity);
|
||||
|
||||
last_motion_change = {
|
||||
static_cast<float>(-mouse_move.y) / 50.0f,
|
||||
static_cast<float>(-mouse_move.x) / 50.0f,
|
||||
static_cast<float>(-mouse_move.y) * x_sensitivity,
|
||||
static_cast<float>(-mouse_move.x) * y_sensitivity,
|
||||
last_motion_change.z,
|
||||
};
|
||||
}
|
||||
@@ -220,7 +220,7 @@ void Mouse::ReleaseButton(MouseButton button) {
|
||||
SetButton(real_mouse_identifier, static_cast<int>(button), false);
|
||||
SetButton(touch_identifier, static_cast<int>(button), false);
|
||||
|
||||
if (!Settings::values.mouse_panning) {
|
||||
if (!IsMousePanningEnabled()) {
|
||||
SetAxis(identifier, mouse_axis_x, 0);
|
||||
SetAxis(identifier, mouse_axis_y, 0);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ void Mouse::ReleaseButton(MouseButton button) {
|
||||
void Mouse::MouseWheelChange(int x, int y) {
|
||||
wheel_position.x += x;
|
||||
wheel_position.y += y;
|
||||
last_motion_change.z += static_cast<f32>(y) / 100.0f;
|
||||
last_motion_change.z += static_cast<f32>(y);
|
||||
SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x));
|
||||
SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y));
|
||||
}
|
||||
@@ -244,6 +244,11 @@ void Mouse::ReleaseAllButtons() {
|
||||
button_pressed = false;
|
||||
}
|
||||
|
||||
bool Mouse::IsMousePanningEnabled() {
|
||||
// Disable mouse panning when a real mouse is connected
|
||||
return Settings::values.mouse_panning && !Settings::values.mouse_enabled;
|
||||
}
|
||||
|
||||
std::vector<Common::ParamPackage> Mouse::GetInputDevices() const {
|
||||
std::vector<Common::ParamPackage> devices;
|
||||
devices.emplace_back(Common::ParamPackage{
|
||||
|
||||
@@ -99,6 +99,8 @@ private:
|
||||
void UpdateStickInput();
|
||||
void UpdateMotionInput();
|
||||
|
||||
bool IsMousePanningEnabled();
|
||||
|
||||
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
|
||||
|
||||
Common::Vec2<int> mouse_origin;
|
||||
|
||||
@@ -115,7 +115,34 @@ void BufferCache<P>::WriteMemory(VAddr cpu_addr, u64 size) {
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::CachedWriteMemory(VAddr cpu_addr, u64 size) {
|
||||
memory_tracker.CachedCpuWrite(cpu_addr, size);
|
||||
const bool is_dirty = IsRegionRegistered(cpu_addr, size);
|
||||
if (!is_dirty) {
|
||||
return;
|
||||
}
|
||||
VAddr aligned_start = Common::AlignDown(cpu_addr, YUZU_PAGESIZE);
|
||||
VAddr aligned_end = Common::AlignUp(cpu_addr + size, YUZU_PAGESIZE);
|
||||
if (!IsRegionGpuModified(aligned_start, aligned_end - aligned_start)) {
|
||||
WriteMemory(cpu_addr, size);
|
||||
return;
|
||||
}
|
||||
|
||||
tmp_buffer.resize_destructive(size);
|
||||
cpu_memory.ReadBlockUnsafe(cpu_addr, tmp_buffer.data(), size);
|
||||
|
||||
InlineMemoryImplementation(cpu_addr, size, tmp_buffer);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
bool BufferCache<P>::OnCPUWrite(VAddr cpu_addr, u64 size) {
|
||||
const bool is_dirty = IsRegionRegistered(cpu_addr, size);
|
||||
if (!is_dirty) {
|
||||
return false;
|
||||
}
|
||||
if (memory_tracker.IsRegionGpuModified(cpu_addr, size)) {
|
||||
return true;
|
||||
}
|
||||
WriteMemory(cpu_addr, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
@@ -1553,6 +1580,14 @@ bool BufferCache<P>::InlineMemory(VAddr dest_address, size_t copy_size,
|
||||
return false;
|
||||
}
|
||||
|
||||
InlineMemoryImplementation(dest_address, copy_size, inlined_buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::InlineMemoryImplementation(VAddr dest_address, size_t copy_size,
|
||||
std::span<const u8> inlined_buffer) {
|
||||
const IntervalType subtract_interval{dest_address, dest_address + copy_size};
|
||||
ClearDownload(subtract_interval);
|
||||
common_ranges.subtract(subtract_interval);
|
||||
@@ -1574,8 +1609,6 @@ bool BufferCache<P>::InlineMemory(VAddr dest_address, size_t copy_size,
|
||||
} else {
|
||||
buffer.ImmediateUpload(buffer.Offset(dest_address), inlined_buffer.first(copy_size));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
||||
@@ -245,6 +245,8 @@ public:
|
||||
|
||||
void CachedWriteMemory(VAddr cpu_addr, u64 size);
|
||||
|
||||
bool OnCPUWrite(VAddr cpu_addr, u64 size);
|
||||
|
||||
void DownloadMemory(VAddr cpu_addr, u64 size);
|
||||
|
||||
std::optional<VideoCore::RasterizerDownloadArea> GetFlushArea(VAddr cpu_addr, u64 size);
|
||||
@@ -543,6 +545,9 @@ private:
|
||||
|
||||
void ClearDownload(IntervalType subtract_interval);
|
||||
|
||||
void InlineMemoryImplementation(VAddr dest_address, size_t copy_size,
|
||||
std::span<const u8> inlined_buffer);
|
||||
|
||||
VideoCore::RasterizerInterface& rasterizer;
|
||||
Core::Memory::Memory& cpu_memory;
|
||||
|
||||
|
||||
@@ -272,6 +272,9 @@ constexpr Table MakeNonNativeBgrCopyTable() {
|
||||
|
||||
bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_views,
|
||||
bool native_bgr) {
|
||||
if (format_a == format_b) {
|
||||
return true;
|
||||
}
|
||||
if (broken_views) {
|
||||
// If format views are broken, only accept formats that are identical.
|
||||
return format_a == format_b;
|
||||
@@ -282,6 +285,9 @@ bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_vi
|
||||
}
|
||||
|
||||
bool IsCopyCompatible(PixelFormat format_a, PixelFormat format_b, bool native_bgr) {
|
||||
if (format_a == format_b) {
|
||||
return true;
|
||||
}
|
||||
static constexpr Table BGR_TABLE = MakeNativeBgrCopyTable();
|
||||
static constexpr Table NO_BGR_TABLE = MakeNonNativeBgrCopyTable();
|
||||
return IsSupported(native_bgr ? BGR_TABLE : NO_BGR_TABLE, format_a, format_b);
|
||||
|
||||
@@ -174,8 +174,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
|
||||
src_operand.address = regs.offset_in;
|
||||
|
||||
DMA::BufferOperand dst_operand;
|
||||
u32 abs_pitch_out = std::abs(static_cast<s32>(regs.pitch_out));
|
||||
dst_operand.pitch = abs_pitch_out;
|
||||
dst_operand.pitch = static_cast<u32>(std::abs(regs.pitch_out));
|
||||
dst_operand.width = regs.line_length_in;
|
||||
dst_operand.height = regs.line_count;
|
||||
dst_operand.address = regs.offset_out;
|
||||
@@ -222,7 +221,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
|
||||
const size_t src_size =
|
||||
CalculateSize(true, bytes_per_pixel, width, height, depth, block_height, block_depth);
|
||||
|
||||
const size_t dst_size = static_cast<size_t>(abs_pitch_out) * regs.line_count;
|
||||
const size_t dst_size = dst_operand.pitch * regs.line_count;
|
||||
read_buffer.resize_destructive(src_size);
|
||||
write_buffer.resize_destructive(dst_size);
|
||||
|
||||
@@ -231,7 +230,7 @@ void MaxwellDMA::CopyBlockLinearToPitch() {
|
||||
|
||||
UnswizzleSubrect(write_buffer, read_buffer, bytes_per_pixel, width, height, depth, x_offset,
|
||||
src_params.origin.y, x_elements, regs.line_count, block_height, block_depth,
|
||||
abs_pitch_out);
|
||||
dst_operand.pitch);
|
||||
|
||||
memory_manager.WriteBlockCached(regs.offset_out, write_buffer.data(), dst_size);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ public:
|
||||
}
|
||||
|
||||
void SignalFence(std::function<void()>&& func) {
|
||||
rasterizer.InvalidateGPUCache();
|
||||
bool delay_fence = Settings::IsGPULevelHigh();
|
||||
if constexpr (!can_async_check) {
|
||||
TryReleasePendingFences<false>();
|
||||
@@ -96,6 +95,7 @@ public:
|
||||
guard.unlock();
|
||||
cv.notify_all();
|
||||
}
|
||||
rasterizer.InvalidateGPUCache();
|
||||
}
|
||||
|
||||
void SignalSyncPoint(u32 value) {
|
||||
|
||||
@@ -95,7 +95,9 @@ struct GPU::Impl {
|
||||
|
||||
/// Synchronizes CPU writes with Host GPU memory.
|
||||
void InvalidateGPUCache() {
|
||||
rasterizer->InvalidateGPUCache();
|
||||
std::function<void(VAddr, size_t)> callback_writes(
|
||||
[this](VAddr address, size_t size) { rasterizer->OnCacheInvalidation(address, size); });
|
||||
system.GatherGPUDirtyMemory(callback_writes);
|
||||
}
|
||||
|
||||
/// Signal the ending of command list.
|
||||
@@ -299,6 +301,10 @@ struct GPU::Impl {
|
||||
gpu_thread.InvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
bool OnCPUWrite(VAddr addr, u64 size) {
|
||||
return rasterizer->OnCPUWrite(addr, size);
|
||||
}
|
||||
|
||||
/// Notify rasterizer that any caches of the specified region should be flushed and invalidated
|
||||
void FlushAndInvalidateRegion(VAddr addr, u64 size) {
|
||||
gpu_thread.FlushAndInvalidateRegion(addr, size);
|
||||
@@ -561,6 +567,10 @@ void GPU::InvalidateRegion(VAddr addr, u64 size) {
|
||||
impl->InvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
bool GPU::OnCPUWrite(VAddr addr, u64 size) {
|
||||
return impl->OnCPUWrite(addr, size);
|
||||
}
|
||||
|
||||
void GPU::FlushAndInvalidateRegion(VAddr addr, u64 size) {
|
||||
impl->FlushAndInvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
@@ -250,6 +250,10 @@ public:
|
||||
/// Notify rasterizer that any caches of the specified region should be invalidated
|
||||
void InvalidateRegion(VAddr addr, u64 size);
|
||||
|
||||
/// Notify rasterizer that CPU is trying to write this area. It returns true if the area is
|
||||
/// sensible, false otherwise
|
||||
bool OnCPUWrite(VAddr addr, u64 size);
|
||||
|
||||
/// Notify rasterizer that any caches of the specified region should be flushed and invalidated
|
||||
void FlushAndInvalidateRegion(VAddr addr, u64 size);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
|
||||
} else if (const auto* flush = std::get_if<FlushRegionCommand>(&next.data)) {
|
||||
rasterizer->FlushRegion(flush->addr, flush->size);
|
||||
} else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) {
|
||||
rasterizer->OnCPUWrite(invalidate->addr, invalidate->size);
|
||||
rasterizer->OnCacheInvalidation(invalidate->addr, invalidate->size);
|
||||
} else {
|
||||
ASSERT(false);
|
||||
}
|
||||
@@ -102,12 +102,12 @@ void ThreadManager::TickGPU() {
|
||||
}
|
||||
|
||||
void ThreadManager::InvalidateRegion(VAddr addr, u64 size) {
|
||||
rasterizer->OnCPUWrite(addr, size);
|
||||
rasterizer->OnCacheInvalidation(addr, size);
|
||||
}
|
||||
|
||||
void ThreadManager::FlushAndInvalidateRegion(VAddr addr, u64 size) {
|
||||
// Skip flush on asynch mode, as FlushAndInvalidateRegion is not used for anything too important
|
||||
rasterizer->OnCPUWrite(addr, size);
|
||||
rasterizer->OnCacheInvalidation(addr, size);
|
||||
}
|
||||
|
||||
u64 ThreadManager::PushCommand(CommandData&& command_data, bool block) {
|
||||
|
||||
@@ -290,7 +290,7 @@ void Codec::Decode() {
|
||||
return vp9_decoder->GetFrameBytes();
|
||||
default:
|
||||
ASSERT(false);
|
||||
return std::vector<u8>{};
|
||||
return std::span<const u8>{};
|
||||
}
|
||||
}();
|
||||
AVPacketPtr packet{av_packet_alloc(), AVPacketDeleter};
|
||||
|
||||
@@ -29,15 +29,15 @@ H264::H264(Host1x::Host1x& host1x_) : host1x{host1x_} {}
|
||||
|
||||
H264::~H264() = default;
|
||||
|
||||
const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
|
||||
bool is_first_frame) {
|
||||
std::span<const u8> H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
|
||||
bool is_first_frame) {
|
||||
H264DecoderContext context;
|
||||
host1x.MemoryManager().ReadBlock(state.picture_info_offset, &context,
|
||||
sizeof(H264DecoderContext));
|
||||
|
||||
const s64 frame_number = context.h264_parameter_set.frame_number.Value();
|
||||
if (!is_first_frame && frame_number != 0) {
|
||||
frame.resize(context.stream_len);
|
||||
frame.resize_destructive(context.stream_len);
|
||||
host1x.MemoryManager().ReadBlock(state.frame_bitstream_offset, frame.data(), frame.size());
|
||||
return frame;
|
||||
}
|
||||
@@ -135,14 +135,14 @@ const std::vector<u8>& H264::ComposeFrame(const Host1x::NvdecCommon::NvdecRegist
|
||||
for (s32 index = 0; index < 6; index++) {
|
||||
writer.WriteBit(true);
|
||||
std::span<const u8> matrix{context.weight_scale};
|
||||
writer.WriteScalingList(matrix, index * 16, 16);
|
||||
writer.WriteScalingList(scan, matrix, index * 16, 16);
|
||||
}
|
||||
|
||||
if (context.h264_parameter_set.transform_8x8_mode_flag) {
|
||||
for (s32 index = 0; index < 2; index++) {
|
||||
writer.WriteBit(true);
|
||||
std::span<const u8> matrix{context.weight_scale_8x8};
|
||||
writer.WriteScalingList(matrix, index * 64, 64);
|
||||
writer.WriteScalingList(scan, matrix, index * 64, 64);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ void H264BitWriter::WriteBit(bool state) {
|
||||
WriteBits(state ? 1 : 0, 1);
|
||||
}
|
||||
|
||||
void H264BitWriter::WriteScalingList(std::span<const u8> list, s32 start, s32 count) {
|
||||
static Common::ScratchBuffer<u8> scan{};
|
||||
void H264BitWriter::WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list,
|
||||
s32 start, s32 count) {
|
||||
scan.resize_destructive(count);
|
||||
if (count == 16) {
|
||||
std::memcpy(scan.data(), zig_zag_scan.data(), scan.size());
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include "common/bit_field.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "video_core/host1x/nvdec_common.h"
|
||||
|
||||
namespace Tegra {
|
||||
@@ -37,7 +39,8 @@ public:
|
||||
|
||||
/// Based on section 7.3.2.1.1.1 and Table 7-4 in the H.264 specification
|
||||
/// Writes the scaling matrices of the sream
|
||||
void WriteScalingList(std::span<const u8> list, s32 start, s32 count);
|
||||
void WriteScalingList(Common::ScratchBuffer<u8>& scan, std::span<const u8> list, s32 start,
|
||||
s32 count);
|
||||
|
||||
/// Return the bitstream as a vector.
|
||||
[[nodiscard]] std::vector<u8>& GetByteArray();
|
||||
@@ -63,11 +66,12 @@ public:
|
||||
~H264();
|
||||
|
||||
/// Compose the H264 frame for FFmpeg decoding
|
||||
[[nodiscard]] const std::vector<u8>& ComposeFrame(
|
||||
const Host1x::NvdecCommon::NvdecRegisters& state, bool is_first_frame = false);
|
||||
[[nodiscard]] std::span<const u8> ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state,
|
||||
bool is_first_frame = false);
|
||||
|
||||
private:
|
||||
std::vector<u8> frame;
|
||||
Common::ScratchBuffer<u8> frame;
|
||||
Common::ScratchBuffer<u8> scan;
|
||||
Host1x::Host1x& host1x;
|
||||
|
||||
struct H264ParameterSet {
|
||||
|
||||
@@ -12,7 +12,7 @@ VP8::VP8(Host1x::Host1x& host1x_) : host1x{host1x_} {}
|
||||
|
||||
VP8::~VP8() = default;
|
||||
|
||||
const std::vector<u8>& VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
|
||||
std::span<const u8> VP8::ComposeFrame(const Host1x::NvdecCommon::NvdecRegisters& state) {
|
||||
VP8PictureInfo info;
|
||||
host1x.MemoryManager().ReadBlock(state.picture_info_offset, &info, sizeof(VP8PictureInfo));
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <span>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "video_core/host1x/nvdec_common.h"
|
||||
|
||||
namespace Tegra {
|
||||
@@ -24,11 +25,11 @@ public:
|
||||
~VP8();
|
||||
|
||||
/// Compose the VP8 frame for FFmpeg decoding
|
||||
[[nodiscard]] const std::vector<u8>& ComposeFrame(
|
||||
[[nodiscard]] std::span<const u8> ComposeFrame(
|
||||
const Host1x::NvdecCommon::NvdecRegisters& state);
|
||||
|
||||
private:
|
||||
std::vector<u8> frame;
|
||||
Common::ScratchBuffer<u8> frame;
|
||||
Host1x::Host1x& host1x;
|
||||
|
||||
struct VP8PictureInfo {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <algorithm> // for std::copy
|
||||
#include <numeric>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "video_core/host1x/codecs/vp9.h"
|
||||
#include "video_core/host1x/host1x.h"
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/scratch_buffer.h"
|
||||
#include "common/stream.h"
|
||||
#include "video_core/host1x/codecs/vp9_types.h"
|
||||
#include "video_core/host1x/nvdec_common.h"
|
||||
@@ -128,8 +130,8 @@ public:
|
||||
return !current_frame_info.show_frame;
|
||||
}
|
||||
|
||||
/// Returns a const reference to the composed frame data.
|
||||
[[nodiscard]] const std::vector<u8>& GetFrameBytes() const {
|
||||
/// Returns a const span to the composed frame data.
|
||||
[[nodiscard]] std::span<const u8> GetFrameBytes() const {
|
||||
return frame;
|
||||
}
|
||||
|
||||
@@ -181,7 +183,7 @@ private:
|
||||
[[nodiscard]] VpxBitStreamWriter ComposeUncompressedHeader();
|
||||
|
||||
Host1x::Host1x& host1x;
|
||||
std::vector<u8> frame;
|
||||
Common::ScratchBuffer<u8> frame;
|
||||
|
||||
std::array<s8, 4> loop_filter_ref_deltas{};
|
||||
std::array<s8, 2> loop_filter_mode_deltas{};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
|
||||
@@ -109,7 +109,9 @@ public:
|
||||
}
|
||||
|
||||
/// Notify rasterizer that any caches of the specified region are desync with guest
|
||||
virtual void OnCPUWrite(VAddr addr, u64 size) = 0;
|
||||
virtual void OnCacheInvalidation(VAddr addr, u64 size) = 0;
|
||||
|
||||
virtual bool OnCPUWrite(VAddr addr, u64 size) = 0;
|
||||
|
||||
/// Sync memory between guest and host.
|
||||
virtual void InvalidateGPUCache() = 0;
|
||||
|
||||
@@ -47,7 +47,10 @@ bool RasterizerNull::MustFlushRegion(VAddr addr, u64 size, VideoCommon::CacheTyp
|
||||
return false;
|
||||
}
|
||||
void RasterizerNull::InvalidateRegion(VAddr addr, u64 size, VideoCommon::CacheType) {}
|
||||
void RasterizerNull::OnCPUWrite(VAddr addr, u64 size) {}
|
||||
bool RasterizerNull::OnCPUWrite(VAddr addr, u64 size) {
|
||||
return false;
|
||||
}
|
||||
void RasterizerNull::OnCacheInvalidation(VAddr addr, u64 size) {}
|
||||
VideoCore::RasterizerDownloadArea RasterizerNull::GetFlushArea(VAddr addr, u64 size) {
|
||||
VideoCore::RasterizerDownloadArea new_area{
|
||||
.start_address = Common::AlignDown(addr, Core::Memory::YUZU_PAGESIZE),
|
||||
|
||||
@@ -53,7 +53,8 @@ public:
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
void InvalidateRegion(VAddr addr, u64 size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
void OnCPUWrite(VAddr addr, u64 size) override;
|
||||
void OnCacheInvalidation(VAddr addr, u64 size) override;
|
||||
bool OnCPUWrite(VAddr addr, u64 size) override;
|
||||
VideoCore::RasterizerDownloadArea GetFlushArea(VAddr addr, u64 size) override;
|
||||
void InvalidateGPUCache() override;
|
||||
void UnmapMemory(VAddr addr, u64 size) override;
|
||||
|
||||
@@ -485,12 +485,33 @@ void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size, VideoCommon::Cache
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::OnCPUWrite(VAddr addr, u64 size) {
|
||||
bool RasterizerOpenGL::OnCPUWrite(VAddr addr, u64 size) {
|
||||
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
||||
if (addr == 0 || size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
if (buffer_cache.OnCPUWrite(addr, size)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.WriteMemory(addr, size);
|
||||
}
|
||||
|
||||
shader_cache.InvalidateRegion(addr, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::OnCacheInvalidation(VAddr addr, u64 size) {
|
||||
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
||||
if (addr == 0 || size == 0) {
|
||||
return;
|
||||
}
|
||||
shader_cache.OnCPUWrite(addr, size);
|
||||
{
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.WriteMemory(addr, size);
|
||||
@@ -499,15 +520,11 @@ void RasterizerOpenGL::OnCPUWrite(VAddr addr, u64 size) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.CachedWriteMemory(addr, size);
|
||||
}
|
||||
shader_cache.InvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::InvalidateGPUCache() {
|
||||
MICROPROFILE_SCOPE(OpenGL_CacheManagement);
|
||||
shader_cache.SyncGuestHost();
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.FlushCachedWrites();
|
||||
}
|
||||
gpu.InvalidateGPUCache();
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::UnmapMemory(VAddr addr, u64 size) {
|
||||
@@ -519,7 +536,7 @@ void RasterizerOpenGL::UnmapMemory(VAddr addr, u64 size) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.WriteMemory(addr, size);
|
||||
}
|
||||
shader_cache.OnCPUWrite(addr, size);
|
||||
shader_cache.OnCacheInvalidation(addr, size);
|
||||
}
|
||||
|
||||
void RasterizerOpenGL::ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) {
|
||||
|
||||
@@ -98,7 +98,8 @@ public:
|
||||
VideoCore::RasterizerDownloadArea GetFlushArea(VAddr addr, u64 size) override;
|
||||
void InvalidateRegion(VAddr addr, u64 size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
void OnCPUWrite(VAddr addr, u64 size) override;
|
||||
void OnCacheInvalidation(VAddr addr, u64 size) override;
|
||||
bool OnCPUWrite(VAddr addr, u64 size) override;
|
||||
void InvalidateGPUCache() override;
|
||||
void UnmapMemory(VAddr addr, u64 size) override;
|
||||
void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) override;
|
||||
|
||||
@@ -591,7 +591,7 @@ void BufferCacheRuntime::ReserveNullBuffer() {
|
||||
.flags = 0,
|
||||
.size = 4,
|
||||
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT,
|
||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||
.queueFamilyIndexCount = 0,
|
||||
.pQueueFamilyIndices = nullptr,
|
||||
@@ -599,7 +599,6 @@ void BufferCacheRuntime::ReserveNullBuffer() {
|
||||
if (device.IsExtTransformFeedbackSupported()) {
|
||||
create_info.usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
|
||||
}
|
||||
create_info.usage |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT;
|
||||
null_buffer = memory_allocator.CreateBuffer(create_info, MemoryUsage::DeviceLocal);
|
||||
if (device.HasDebuggingToolAttached()) {
|
||||
null_buffer.SetObjectNameEXT("Null buffer");
|
||||
|
||||
@@ -566,11 +566,32 @@ void RasterizerVulkan::InnerInvalidation(std::span<const std::pair<VAddr, std::s
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerVulkan::OnCPUWrite(VAddr addr, u64 size) {
|
||||
bool RasterizerVulkan::OnCPUWrite(VAddr addr, u64 size) {
|
||||
if (addr == 0 || size == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
if (buffer_cache.OnCPUWrite(addr, size)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.WriteMemory(addr, size);
|
||||
}
|
||||
|
||||
pipeline_cache.InvalidateRegion(addr, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
void RasterizerVulkan::OnCacheInvalidation(VAddr addr, u64 size) {
|
||||
if (addr == 0 || size == 0) {
|
||||
return;
|
||||
}
|
||||
pipeline_cache.OnCPUWrite(addr, size);
|
||||
|
||||
{
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
texture_cache.WriteMemory(addr, size);
|
||||
@@ -579,14 +600,11 @@ void RasterizerVulkan::OnCPUWrite(VAddr addr, u64 size) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.CachedWriteMemory(addr, size);
|
||||
}
|
||||
pipeline_cache.InvalidateRegion(addr, size);
|
||||
}
|
||||
|
||||
void RasterizerVulkan::InvalidateGPUCache() {
|
||||
pipeline_cache.SyncGuestHost();
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.FlushCachedWrites();
|
||||
}
|
||||
gpu.InvalidateGPUCache();
|
||||
}
|
||||
|
||||
void RasterizerVulkan::UnmapMemory(VAddr addr, u64 size) {
|
||||
@@ -598,7 +616,7 @@ void RasterizerVulkan::UnmapMemory(VAddr addr, u64 size) {
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
buffer_cache.WriteMemory(addr, size);
|
||||
}
|
||||
pipeline_cache.OnCPUWrite(addr, size);
|
||||
pipeline_cache.OnCacheInvalidation(addr, size);
|
||||
}
|
||||
|
||||
void RasterizerVulkan::ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) {
|
||||
|
||||
@@ -96,7 +96,8 @@ public:
|
||||
void InvalidateRegion(VAddr addr, u64 size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
void InnerInvalidation(std::span<const std::pair<VAddr, std::size_t>> sequences) override;
|
||||
void OnCPUWrite(VAddr addr, u64 size) override;
|
||||
void OnCacheInvalidation(VAddr addr, u64 size) override;
|
||||
bool OnCPUWrite(VAddr addr, u64 size) override;
|
||||
void InvalidateGPUCache() override;
|
||||
void UnmapMemory(VAddr addr, u64 size) override;
|
||||
void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) override;
|
||||
|
||||
@@ -36,8 +36,10 @@ using VideoCommon::ImageFlagBits;
|
||||
using VideoCommon::ImageInfo;
|
||||
using VideoCommon::ImageType;
|
||||
using VideoCommon::SubresourceRange;
|
||||
using VideoCore::Surface::BytesPerBlock;
|
||||
using VideoCore::Surface::IsPixelFormatASTC;
|
||||
using VideoCore::Surface::IsPixelFormatInteger;
|
||||
using VideoCore::Surface::SurfaceType;
|
||||
|
||||
namespace {
|
||||
constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) {
|
||||
@@ -130,7 +132,7 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) {
|
||||
[[nodiscard]] VkImageCreateInfo MakeImageCreateInfo(const Device& device, const ImageInfo& info) {
|
||||
const PixelFormat format = StorageFormat(info.format);
|
||||
const auto format_info = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, false, format);
|
||||
VkImageCreateFlags flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||
VkImageCreateFlags flags{};
|
||||
if (info.type == ImageType::e2D && info.resources.layers >= 6 &&
|
||||
info.size.width == info.size.height && !device.HasBrokenCubeImageCompability()) {
|
||||
flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
||||
@@ -163,11 +165,24 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) {
|
||||
}
|
||||
|
||||
[[nodiscard]] vk::Image MakeImage(const Device& device, const MemoryAllocator& allocator,
|
||||
const ImageInfo& info) {
|
||||
const ImageInfo& info, std::span<const VkFormat> view_formats) {
|
||||
if (info.type == ImageType::Buffer) {
|
||||
return vk::Image{};
|
||||
}
|
||||
return allocator.CreateImage(MakeImageCreateInfo(device, info));
|
||||
VkImageCreateInfo image_ci = MakeImageCreateInfo(device, info);
|
||||
const VkImageFormatListCreateInfo image_format_list = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.viewFormatCount = static_cast<u32>(view_formats.size()),
|
||||
.pViewFormats = view_formats.data(),
|
||||
};
|
||||
if (view_formats.size() > 1) {
|
||||
image_ci.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||
if (device.IsKhrImageFormatListSupported()) {
|
||||
image_ci.pNext = &image_format_list;
|
||||
}
|
||||
}
|
||||
return allocator.CreateImage(image_ci);
|
||||
}
|
||||
|
||||
[[nodiscard]] VkImageAspectFlags ImageAspectMask(PixelFormat format) {
|
||||
@@ -806,6 +821,23 @@ TextureCacheRuntime::TextureCacheRuntime(const Device& device_, Scheduler& sched
|
||||
astc_decoder_pass.emplace(device, scheduler, descriptor_pool, staging_buffer_pool,
|
||||
compute_pass_descriptor_queue, memory_allocator);
|
||||
}
|
||||
if (!device.IsKhrImageFormatListSupported()) {
|
||||
return;
|
||||
}
|
||||
for (size_t index_a = 0; index_a < VideoCore::Surface::MaxPixelFormat; index_a++) {
|
||||
const auto image_format = static_cast<PixelFormat>(index_a);
|
||||
if (IsPixelFormatASTC(image_format) && !device.IsOptimalAstcSupported()) {
|
||||
view_formats[index_a].push_back(VK_FORMAT_A8B8G8R8_UNORM_PACK32);
|
||||
}
|
||||
for (size_t index_b = 0; index_b < VideoCore::Surface::MaxPixelFormat; index_b++) {
|
||||
const auto view_format = static_cast<PixelFormat>(index_b);
|
||||
if (VideoCore::Surface::IsViewCompatible(image_format, view_format, false, true)) {
|
||||
const auto view_info =
|
||||
MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, view_format);
|
||||
view_formats[index_a].push_back(view_info.format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextureCacheRuntime::Finish() {
|
||||
@@ -1265,8 +1297,8 @@ void TextureCacheRuntime::TickFrame() {}
|
||||
Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_,
|
||||
VAddr cpu_addr_)
|
||||
: VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler},
|
||||
runtime{&runtime_},
|
||||
original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info)),
|
||||
runtime{&runtime_}, original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info,
|
||||
runtime->ViewFormats(info.format))),
|
||||
aspect_mask(ImageAspectMask(info.format)) {
|
||||
if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) {
|
||||
if (Settings::values.async_astc.GetValue()) {
|
||||
@@ -1471,7 +1503,8 @@ bool Image::ScaleUp(bool ignore) {
|
||||
auto scaled_info = info;
|
||||
scaled_info.size.width = scaled_width;
|
||||
scaled_info.size.height = scaled_height;
|
||||
scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info);
|
||||
scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info,
|
||||
runtime->ViewFormats(info.format));
|
||||
ignore = false;
|
||||
}
|
||||
current_image = *scaled_image;
|
||||
|
||||
@@ -103,6 +103,10 @@ public:
|
||||
|
||||
[[nodiscard]] VkBuffer GetTemporaryBuffer(size_t needed_size);
|
||||
|
||||
std::span<const VkFormat> ViewFormats(PixelFormat format) {
|
||||
return view_formats[static_cast<std::size_t>(format)];
|
||||
}
|
||||
|
||||
void BarrierFeedbackLoop();
|
||||
|
||||
const Device& device;
|
||||
@@ -113,6 +117,7 @@ public:
|
||||
RenderPassCache& render_pass_cache;
|
||||
std::optional<ASTCDecoderPass> astc_decoder_pass;
|
||||
const Settings::ResolutionScalingInfo& resolution;
|
||||
std::array<std::vector<VkFormat>, VideoCore::Surface::MaxPixelFormat> view_formats;
|
||||
|
||||
static constexpr size_t indexing_slots = 8 * sizeof(size_t);
|
||||
std::array<vk::Buffer, indexing_slots> buffers{};
|
||||
|
||||
@@ -24,7 +24,7 @@ void ShaderCache::InvalidateRegion(VAddr addr, size_t size) {
|
||||
RemovePendingShaders();
|
||||
}
|
||||
|
||||
void ShaderCache::OnCPUWrite(VAddr addr, size_t size) {
|
||||
void ShaderCache::OnCacheInvalidation(VAddr addr, size_t size) {
|
||||
std::scoped_lock lock{invalidation_mutex};
|
||||
InvalidatePagesInRegion(addr, size);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
/// @brief Unmarks a memory region as cached and marks it for removal
|
||||
/// @param addr Start address of the CPU write operation
|
||||
/// @param size Number of bytes of the CPU write operation
|
||||
void OnCPUWrite(VAddr addr, size_t size);
|
||||
void OnCacheInvalidation(VAddr addr, size_t size);
|
||||
|
||||
/// @brief Flushes delayed removal operations
|
||||
void SyncGuestHost();
|
||||
|
||||
@@ -598,6 +598,10 @@ void TextureCache<P>::UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t siz
|
||||
[&](ImageId id, Image&) { deleted_images.push_back(id); });
|
||||
for (const ImageId id : deleted_images) {
|
||||
Image& image = slot_images[id];
|
||||
if (True(image.flags & ImageFlagBits::CpuModified)) {
|
||||
continue;
|
||||
}
|
||||
image.flags |= ImageFlagBits::CpuModified;
|
||||
if (True(image.flags & ImageFlagBits::Remapped)) {
|
||||
continue;
|
||||
}
|
||||
@@ -865,11 +869,15 @@ void TextureCache<P>::PopAsyncFlushes() {
|
||||
template <class P>
|
||||
ImageId TextureCache<P>::DmaImageId(const Tegra::DMA::ImageOperand& operand, bool is_upload) {
|
||||
const ImageInfo dst_info(operand);
|
||||
const ImageId image_id = FindDMAImage(dst_info, operand.address);
|
||||
if (!image_id) {
|
||||
const ImageId dst_id = FindDMAImage(dst_info, operand.address);
|
||||
if (!dst_id) {
|
||||
return NULL_IMAGE_ID;
|
||||
}
|
||||
auto& image = slot_images[dst_id];
|
||||
if (False(image.flags & ImageFlagBits::GpuModified)) {
|
||||
// No need to waste time on an image that's synced with guest
|
||||
return NULL_IMAGE_ID;
|
||||
}
|
||||
auto& image = slot_images[image_id];
|
||||
if (image.info.type == ImageType::e3D) {
|
||||
// Don't accelerate 3D images.
|
||||
return NULL_IMAGE_ID;
|
||||
@@ -883,7 +891,7 @@ ImageId TextureCache<P>::DmaImageId(const Tegra::DMA::ImageOperand& operand, boo
|
||||
if (!base) {
|
||||
return NULL_IMAGE_ID;
|
||||
}
|
||||
return image_id;
|
||||
return dst_id;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
|
||||
@@ -54,7 +54,6 @@ enum class RelaxedOptions : u32 {
|
||||
Format = 1 << 1,
|
||||
Samples = 1 << 2,
|
||||
ForceBrokenViews = 1 << 3,
|
||||
FormatBpp = 1 << 4,
|
||||
};
|
||||
DECLARE_ENUM_FLAG_OPERATORS(RelaxedOptions)
|
||||
|
||||
|
||||
@@ -1201,8 +1201,7 @@ std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const
|
||||
// Format checking is relaxed, but we still have to check for matching bytes per block.
|
||||
// This avoids creating a view for blits on UE4 titles where formats with different bytes
|
||||
// per block are aliased.
|
||||
if (BytesPerBlock(existing.format) != BytesPerBlock(candidate.format) &&
|
||||
False(options & RelaxedOptions::FormatBpp)) {
|
||||
if (BytesPerBlock(existing.format) != BytesPerBlock(candidate.format)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
} else {
|
||||
@@ -1233,11 +1232,7 @@ std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const
|
||||
}
|
||||
const bool strict_size = False(options & RelaxedOptions::Size);
|
||||
if (!IsBlockLinearSizeCompatible(existing, candidate, base->level, 0, strict_size)) {
|
||||
if (False(options & RelaxedOptions::FormatBpp)) {
|
||||
return std::nullopt;
|
||||
} else if (!IsBlockLinearSizeCompatibleBPPRelaxed(existing, candidate, base->level, 0)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
// TODO: compare block sizes
|
||||
return base;
|
||||
|
||||
@@ -485,7 +485,7 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
||||
loaded_extensions.erase(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
|
||||
}
|
||||
}
|
||||
if (extensions.extended_dynamic_state2 && (is_radv || is_qualcomm)) {
|
||||
if (extensions.extended_dynamic_state2 && is_radv) {
|
||||
const u32 version = (properties.properties.driverVersion << 3) >> 3;
|
||||
if (version < VK_MAKE_API_VERSION(0, 22, 3, 1)) {
|
||||
LOG_WARNING(
|
||||
@@ -498,6 +498,20 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
||||
loaded_extensions.erase(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
|
||||
}
|
||||
}
|
||||
if (extensions.extended_dynamic_state2 && is_qualcomm) {
|
||||
const u32 version = (properties.properties.driverVersion << 3) >> 3;
|
||||
if (version >= VK_MAKE_API_VERSION(0, 0, 676, 0) &&
|
||||
version < VK_MAKE_API_VERSION(0, 0, 680, 0)) {
|
||||
// Qualcomm Adreno 7xx drivers do not properly support extended_dynamic_state2.
|
||||
LOG_WARNING(Render_Vulkan,
|
||||
"Qualcomm Adreno 7xx drivers have broken VK_EXT_extended_dynamic_state2");
|
||||
features.extended_dynamic_state2.extendedDynamicState2 = false;
|
||||
features.extended_dynamic_state2.extendedDynamicState2LogicOp = false;
|
||||
features.extended_dynamic_state2.extendedDynamicState2PatchControlPoints = false;
|
||||
extensions.extended_dynamic_state2 = false;
|
||||
loaded_extensions.erase(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME);
|
||||
}
|
||||
}
|
||||
if (extensions.extended_dynamic_state3 && is_radv) {
|
||||
LOG_WARNING(Render_Vulkan, "RADV has broken extendedDynamicState3ColorBlendEquation");
|
||||
features.extended_dynamic_state3.extendedDynamicState3ColorBlendEnable = false;
|
||||
@@ -512,8 +526,7 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
||||
dynamic_state3_enables = false;
|
||||
}
|
||||
}
|
||||
if (extensions.vertex_input_dynamic_state && (is_radv || is_qualcomm)) {
|
||||
// Qualcomm S8gen2 drivers do not properly support vertex_input_dynamic_state.
|
||||
if (extensions.vertex_input_dynamic_state && is_radv) {
|
||||
// TODO(ameerj): Blacklist only offending driver versions
|
||||
// TODO(ameerj): Confirm if RDNA1 is affected
|
||||
const bool is_rdna2 =
|
||||
@@ -526,6 +539,19 @@ Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR
|
||||
loaded_extensions.erase(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
|
||||
}
|
||||
}
|
||||
if (extensions.vertex_input_dynamic_state && is_qualcomm) {
|
||||
const u32 version = (properties.properties.driverVersion << 3) >> 3;
|
||||
if (version >= VK_MAKE_API_VERSION(0, 0, 676, 0) &&
|
||||
version < VK_MAKE_API_VERSION(0, 0, 680, 0)) {
|
||||
// Qualcomm Adreno 7xx drivers do not properly support vertex_input_dynamic_state.
|
||||
LOG_WARNING(
|
||||
Render_Vulkan,
|
||||
"Qualcomm Adreno 7xx drivers have broken VK_EXT_vertex_input_dynamic_state");
|
||||
features.vertex_input_dynamic_state.vertexInputDynamicState = false;
|
||||
extensions.vertex_input_dynamic_state = false;
|
||||
loaded_extensions.erase(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
sets_per_pool = 64;
|
||||
if (extensions.extended_dynamic_state3 && is_amd_driver &&
|
||||
@@ -774,6 +800,17 @@ bool Device::ShouldBoostClocks() const {
|
||||
return validated_driver && !is_steam_deck && !is_debugging;
|
||||
}
|
||||
|
||||
bool Device::HasTimelineSemaphore() const {
|
||||
if (GetDriverID() == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||
GetDriverID() == VK_DRIVER_ID_MESA_TURNIP) {
|
||||
// Timeline semaphores do not work properly on all Qualcomm drivers.
|
||||
// They generally work properly with Turnip drivers, but are problematic on some devices
|
||||
// (e.g. ZTE handsets with Snapdragon 870).
|
||||
return false;
|
||||
}
|
||||
return features.timeline_semaphore.timelineSemaphore;
|
||||
}
|
||||
|
||||
bool Device::GetSuitability(bool requires_swapchain) {
|
||||
// Assume we will be suitable.
|
||||
bool suitable = true;
|
||||
|
||||
@@ -77,6 +77,7 @@ VK_DEFINE_HANDLE(VmaAllocator)
|
||||
EXTENSION(KHR, SPIRV_1_4, spirv_1_4) \
|
||||
EXTENSION(KHR, SWAPCHAIN, swapchain) \
|
||||
EXTENSION(KHR, SWAPCHAIN_MUTABLE_FORMAT, swapchain_mutable_format) \
|
||||
EXTENSION(KHR, IMAGE_FORMAT_LIST, image_format_list) \
|
||||
EXTENSION(NV, DEVICE_DIAGNOSTICS_CONFIG, device_diagnostics_config) \
|
||||
EXTENSION(NV, GEOMETRY_SHADER_PASSTHROUGH, geometry_shader_passthrough) \
|
||||
EXTENSION(NV, VIEWPORT_ARRAY2, viewport_array2) \
|
||||
@@ -408,6 +409,11 @@ public:
|
||||
return extensions.workgroup_memory_explicit_layout;
|
||||
}
|
||||
|
||||
/// Returns true if the device supports VK_KHR_image_format_list.
|
||||
bool IsKhrImageFormatListSupported() const {
|
||||
return extensions.image_format_list || instance_version >= VK_API_VERSION_1_2;
|
||||
}
|
||||
|
||||
/// Returns true if the device supports VK_EXT_primitive_topology_list_restart.
|
||||
bool IsTopologyListPrimitiveRestartSupported() const {
|
||||
return features.primitive_topology_list_restart.primitiveTopologyListRestart;
|
||||
@@ -522,13 +528,7 @@ public:
|
||||
return extensions.shader_atomic_int64;
|
||||
}
|
||||
|
||||
bool HasTimelineSemaphore() const {
|
||||
if (GetDriverID() == VK_DRIVER_ID_QUALCOMM_PROPRIETARY) {
|
||||
// Timeline semaphores do not work properly on all Qualcomm drivers.
|
||||
return false;
|
||||
}
|
||||
return features.timeline_semaphore.timelineSemaphore;
|
||||
}
|
||||
bool HasTimelineSemaphore() const;
|
||||
|
||||
/// Returns the minimum supported version of SPIR-V.
|
||||
u32 SupportedSpirvVersion() const {
|
||||
|
||||
@@ -19,11 +19,9 @@
|
||||
#include <windows.h>
|
||||
// ensure include order
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <vulkan/vulkan_macos.h>
|
||||
#elif defined(__ANDROID__)
|
||||
#include <vulkan/vulkan_android.h>
|
||||
#else
|
||||
#elif !defined(__APPLE__)
|
||||
#include <X11/Xlib.h>
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
#include <vulkan/vulkan_xlib.h>
|
||||
@@ -68,7 +66,7 @@ namespace {
|
||||
break;
|
||||
#elif defined(__APPLE__)
|
||||
case Core::Frontend::WindowSystemType::Cocoa:
|
||||
extensions.push_back(VK_MVK_MACOS_SURFACE_EXTENSION_NAME);
|
||||
extensions.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME);
|
||||
break;
|
||||
#elif defined(__ANDROID__)
|
||||
case Core::Frontend::WindowSystemType::Android:
|
||||
|
||||
@@ -221,8 +221,8 @@ vk::Image MemoryAllocator::CreateImage(const VkImageCreateInfo& ci) const {
|
||||
const VmaAllocationCreateInfo alloc_ci = {
|
||||
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
.preferredFlags = 0,
|
||||
.requiredFlags = 0,
|
||||
.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
.memoryTypeBits = 0,
|
||||
.pool = VK_NULL_HANDLE,
|
||||
.pUserData = nullptr,
|
||||
|
||||
@@ -11,11 +11,9 @@
|
||||
#include <windows.h>
|
||||
// ensure include order
|
||||
#include <vulkan/vulkan_win32.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <vulkan/vulkan_macos.h>
|
||||
#elif defined(__ANDROID__)
|
||||
#include <vulkan/vulkan_android.h>
|
||||
#else
|
||||
#elif !defined(__APPLE__)
|
||||
#include <X11/Xlib.h>
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
#include <vulkan/vulkan_xlib.h>
|
||||
@@ -44,12 +42,13 @@ vk::SurfaceKHR CreateSurface(
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
if (window_info.type == Core::Frontend::WindowSystemType::Cocoa) {
|
||||
const VkMacOSSurfaceCreateInfoMVK mvk_ci{VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK,
|
||||
nullptr, 0, window_info.render_surface};
|
||||
const auto vkCreateMacOSSurfaceMVK = reinterpret_cast<PFN_vkCreateMacOSSurfaceMVK>(
|
||||
dld.vkGetInstanceProcAddr(*instance, "vkCreateMacOSSurfaceMVK"));
|
||||
if (!vkCreateMacOSSurfaceMVK ||
|
||||
vkCreateMacOSSurfaceMVK(*instance, &mvk_ci, nullptr, &unsafe_surface) != VK_SUCCESS) {
|
||||
const VkMetalSurfaceCreateInfoEXT macos_ci = {
|
||||
.pLayer = static_cast<const CAMetalLayer*>(window_info.render_surface),
|
||||
};
|
||||
const auto vkCreateMetalSurfaceEXT = reinterpret_cast<PFN_vkCreateMetalSurfaceEXT>(
|
||||
dld.vkGetInstanceProcAddr(*instance, "vkCreateMetalSurfaceEXT"));
|
||||
if (!vkCreateMetalSurfaceEXT ||
|
||||
vkCreateMetalSurfaceEXT(*instance, &macos_ci, nullptr, &unsafe_surface) != VK_SUCCESS) {
|
||||
LOG_ERROR(Render_Vulkan, "Failed to initialize Metal surface");
|
||||
throw vk::Exception(VK_ERROR_INITIALIZATION_FAILED);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#define VK_NO_PROTOTYPES
|
||||
#ifdef _WIN32
|
||||
#define VK_USE_PLATFORM_WIN32_KHR
|
||||
#elif defined(__APPLE__)
|
||||
#define VK_USE_PLATFORM_METAL_EXT
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
||||
@@ -503,8 +503,7 @@ void Config::ReadMousePanningValues() {
|
||||
ReadBasicSetting(Settings::values.mouse_panning);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_x_sensitivity);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_y_sensitivity);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_deadzone_x_counterweight);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_deadzone_y_counterweight);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_deadzone_counterweight);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_decay_strength);
|
||||
ReadBasicSetting(Settings::values.mouse_panning_min_decay);
|
||||
}
|
||||
@@ -1122,8 +1121,7 @@ void Config::SaveMousePanningValues() {
|
||||
// Don't overwrite values.mouse_panning
|
||||
WriteBasicSetting(Settings::values.mouse_panning_x_sensitivity);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_y_sensitivity);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_deadzone_x_counterweight);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_deadzone_y_counterweight);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_deadzone_counterweight);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_decay_strength);
|
||||
WriteBasicSetting(Settings::values.mouse_panning_min_decay);
|
||||
}
|
||||
|
||||
@@ -3105,21 +3105,6 @@
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mousePanningButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>68</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>68</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">min-width: 68px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Configure</string>
|
||||
</property>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "common/settings.h"
|
||||
#include "ui_configure_mouse_panning.h"
|
||||
@@ -27,31 +28,34 @@ void ConfigureMousePanning::SetConfiguration(float right_stick_deadzone, float r
|
||||
ui->enable->setChecked(Settings::values.mouse_panning.GetValue());
|
||||
ui->x_sensitivity->setValue(Settings::values.mouse_panning_x_sensitivity.GetValue());
|
||||
ui->y_sensitivity->setValue(Settings::values.mouse_panning_y_sensitivity.GetValue());
|
||||
ui->deadzone_x_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_x_counterweight.GetValue());
|
||||
ui->deadzone_y_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_y_counterweight.GetValue());
|
||||
ui->deadzone_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_counterweight.GetValue());
|
||||
ui->decay_strength->setValue(Settings::values.mouse_panning_decay_strength.GetValue());
|
||||
ui->min_decay->setValue(Settings::values.mouse_panning_min_decay.GetValue());
|
||||
|
||||
if (right_stick_deadzone > 0.0f || right_stick_range != 1.0f) {
|
||||
ui->warning_label->setText(QString::fromStdString(
|
||||
"Mouse panning works better with a deadzone of 0% and a range of 100%.\n"
|
||||
"Current values are " +
|
||||
std::to_string(static_cast<int>(right_stick_deadzone * 100.0f)) + "% and " +
|
||||
std::to_string(static_cast<int>(right_stick_range * 100.0f)) + "% respectively."));
|
||||
} else {
|
||||
ui->warning_label->hide();
|
||||
const QString right_stick_deadzone_str =
|
||||
QString::fromStdString(std::to_string(static_cast<int>(right_stick_deadzone * 100.0f)));
|
||||
const QString right_stick_range_str =
|
||||
QString::fromStdString(std::to_string(static_cast<int>(right_stick_range * 100.0f)));
|
||||
|
||||
ui->warning_label->setText(
|
||||
tr("Mouse panning works better with a deadzone of 0% and a range of 100%.\nCurrent "
|
||||
"values are %1% and %2% respectively.")
|
||||
.arg(right_stick_deadzone_str, right_stick_range_str));
|
||||
}
|
||||
|
||||
if (Settings::values.mouse_enabled) {
|
||||
ui->warning_label->setText(
|
||||
tr("Emulated mouse is enabled. This is incompatible with mouse panning."));
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigureMousePanning::SetDefaultConfiguration() {
|
||||
ui->x_sensitivity->setValue(Settings::values.mouse_panning_x_sensitivity.GetDefault());
|
||||
ui->y_sensitivity->setValue(Settings::values.mouse_panning_y_sensitivity.GetDefault());
|
||||
ui->deadzone_x_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_x_counterweight.GetDefault());
|
||||
ui->deadzone_y_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_y_counterweight.GetDefault());
|
||||
ui->deadzone_counterweight->setValue(
|
||||
Settings::values.mouse_panning_deadzone_counterweight.GetDefault());
|
||||
ui->decay_strength->setValue(Settings::values.mouse_panning_decay_strength.GetDefault());
|
||||
ui->min_decay->setValue(Settings::values.mouse_panning_min_decay.GetDefault());
|
||||
}
|
||||
@@ -68,12 +72,19 @@ void ConfigureMousePanning::ApplyConfiguration() {
|
||||
Settings::values.mouse_panning = ui->enable->isChecked();
|
||||
Settings::values.mouse_panning_x_sensitivity = static_cast<float>(ui->x_sensitivity->value());
|
||||
Settings::values.mouse_panning_y_sensitivity = static_cast<float>(ui->y_sensitivity->value());
|
||||
Settings::values.mouse_panning_deadzone_x_counterweight =
|
||||
static_cast<float>(ui->deadzone_x_counterweight->value());
|
||||
Settings::values.mouse_panning_deadzone_y_counterweight =
|
||||
static_cast<float>(ui->deadzone_y_counterweight->value());
|
||||
Settings::values.mouse_panning_deadzone_counterweight =
|
||||
static_cast<float>(ui->deadzone_counterweight->value());
|
||||
Settings::values.mouse_panning_decay_strength = static_cast<float>(ui->decay_strength->value());
|
||||
Settings::values.mouse_panning_min_decay = static_cast<float>(ui->min_decay->value());
|
||||
|
||||
if (Settings::values.mouse_enabled && Settings::values.mouse_panning) {
|
||||
Settings::values.mouse_panning = false;
|
||||
QMessageBox::critical(
|
||||
this, tr("Emulated mouse is enabled"),
|
||||
tr("Real mouse input and mouse panning are incompatible. Please disable the "
|
||||
"emulated mouse in input advanced settings to allow mouse panning."));
|
||||
return;
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enable">
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
<string>Enable mouse panning</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Can be toggled via a hotkey</string>
|
||||
<string>Can be toggled via a hotkey. Default hotkey is Ctrl + F9</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -89,40 +89,14 @@
|
||||
</property>
|
||||
<layout class="QGridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="deadzone_x_counterweight_label">
|
||||
<widget class="QLabel" name="deadzone_counterweight_label">
|
||||
<property name="text">
|
||||
<string>Horizontal</string>
|
||||
<string>Deadzone</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="deadzone_x_counterweight">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>%</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="deadzone_y_counterweight_label">
|
||||
<property name="text">
|
||||
<string>Vertical</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="deadzone_y_counterweight">
|
||||
<widget class="QSpinBox" name="deadzone_counterweight">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
|
||||
@@ -101,6 +101,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
|
||||
#include "common/settings.h"
|
||||
#include "common/telemetry.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/crypto/key_manager.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/common_funcs.h"
|
||||
@@ -177,6 +178,8 @@ constexpr int default_mouse_hide_timeout = 2500;
|
||||
constexpr int default_mouse_center_timeout = 10;
|
||||
constexpr int default_input_update_timeout = 1;
|
||||
|
||||
constexpr size_t CopyBufferSize = 1_MiB;
|
||||
|
||||
/**
|
||||
* "Callouts" are one-time instructional messages shown to the user. In the config settings, there
|
||||
* is a bitfield "callout_flags" options, used to track if a message has already been shown to the
|
||||
@@ -389,6 +392,7 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan
|
||||
std::chrono::duration_cast<std::chrono::duration<f64, std::milli>>(
|
||||
Common::Windows::SetCurrentTimerResolutionToMaximum())
|
||||
.count());
|
||||
system->CoreTiming().SetTimerResolutionNs(Common::Windows::GetCurrentTimerResolution());
|
||||
#endif
|
||||
UpdateWindowTitle();
|
||||
|
||||
@@ -452,7 +456,7 @@ GMainWindow::GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan
|
||||
// the user through their desktop environment.
|
||||
//: TRANSLATORS: This string is shown to the user to explain why yuzu needs to prevent the
|
||||
//: computer from sleeping
|
||||
QByteArray wakelock_reason = tr("Running a game").toLatin1();
|
||||
QByteArray wakelock_reason = tr("Running a game").toUtf8();
|
||||
SDL_SetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME, wakelock_reason.data());
|
||||
|
||||
// SDL disables the screen saver by default, and setting the hint
|
||||
@@ -2927,10 +2931,10 @@ void GMainWindow::OnMenuInstallToNAND() {
|
||||
|
||||
int remaining = filenames.size();
|
||||
|
||||
// This would only overflow above 2^43 bytes (8.796 TB)
|
||||
// This would only overflow above 2^51 bytes (2.252 PB)
|
||||
int total_size = 0;
|
||||
for (const QString& file : files) {
|
||||
total_size += static_cast<int>(QFile(file).size() / 0x1000);
|
||||
total_size += static_cast<int>(QFile(file).size() / CopyBufferSize);
|
||||
}
|
||||
if (total_size < 0) {
|
||||
LOG_CRITICAL(Frontend, "Attempting to install too many files, aborting.");
|
||||
@@ -3030,7 +3034,7 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<u8> buffer(1_MiB);
|
||||
std::vector<u8> buffer(CopyBufferSize);
|
||||
|
||||
for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
|
||||
if (install_progress->wasCanceled()) {
|
||||
@@ -3086,7 +3090,7 @@ InstallResult GMainWindow::InstallNCA(const QString& filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::array<u8, 0x1000> buffer{};
|
||||
std::vector<u8> buffer(CopyBufferSize);
|
||||
|
||||
for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
|
||||
if (install_progress->wasCanceled()) {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#if !defined(WIN32) && !defined(__APPLE__)
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <objc/message.h>
|
||||
#endif
|
||||
|
||||
namespace QtCommon {
|
||||
@@ -37,9 +39,12 @@ Core::Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window)
|
||||
Core::Frontend::EmuWindow::WindowSystemInfo wsi;
|
||||
wsi.type = GetWindowSystemType();
|
||||
|
||||
#if defined(WIN32)
|
||||
// Our Win32 Qt external doesn't have the private API.
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
|
||||
wsi.render_surface = reinterpret_cast<void*>(window->winId());
|
||||
#elif defined(__APPLE__)
|
||||
wsi.render_surface = reinterpret_cast<void* (*)(id, SEL)>(objc_msgSend)(
|
||||
reinterpret_cast<id>(window->winId()), sel_registerName("layer"));
|
||||
#else
|
||||
QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
|
||||
wsi.display_connection = pni->nativeResourceForWindow("display", window);
|
||||
|
||||
@@ -26,7 +26,10 @@ Record::~Record() = default;
|
||||
void PopulateRecords(std::vector<Record>& records, QWindow* window) try {
|
||||
using namespace Vulkan;
|
||||
|
||||
auto wsi = QtCommon::GetWindowSystemInfo(window);
|
||||
// Create a test window with a Vulkan surface type for checking present modes.
|
||||
QWindow test_window(window);
|
||||
test_window.setSurfaceType(QWindow::VulkanSurface);
|
||||
auto wsi = QtCommon::GetWindowSystemInfo(&test_window);
|
||||
|
||||
vk::InstanceDispatch dld;
|
||||
const auto library = OpenLibrary();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "common/string_util.h"
|
||||
#include "common/telemetry.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/cpu_manager.h"
|
||||
#include "core/crypto/key_manager.h"
|
||||
#include "core/file_sys/registered_cache.h"
|
||||
@@ -316,8 +317,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
#ifdef _WIN32
|
||||
LocalFree(argv_w);
|
||||
|
||||
Common::Windows::SetCurrentTimerResolutionToMaximum();
|
||||
#endif
|
||||
|
||||
MicroProfileOnThreadCreate("EmuThread");
|
||||
@@ -351,6 +350,11 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
Common::Windows::SetCurrentTimerResolutionToMaximum();
|
||||
system.CoreTiming().SetTimerResolutionNs(Common::Windows::GetCurrentTimerResolution());
|
||||
#endif
|
||||
|
||||
system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>());
|
||||
system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>());
|
||||
system.GetFileSystemController().CreateFactories(*system.GetFilesystem());
|
||||
|
||||
Reference in New Issue
Block a user