Compare commits

..

27 Commits

Author SHA1 Message Date
868919e101 misc: Update GtkSharp.Dependencies and speed up initial Windows build (#3128)
Update GtkSharp.Dependencies to fix between menu flickering and enable
the SkipInstallGtk in csproj to avoid downloading unused GTK3 install
locally.
2022-02-17 22:10:48 +01:00
9ca040c0ff Use ReadOnlySpan<byte> compiler optimization for static data (#3130) 2022-02-17 21:38:50 +01:00
7e9011673b Use a basic cubic interpolation for the audren upsampler (#3129)
Before, it was selecting nearest neighbour, which sounded terrible. This is likely temporary til the upsampling algorithm used by the switch is reversed.

Fixes bad audio in Skyward Sword HD.
2022-02-17 20:19:29 +01:00
741db8e43d amadeus: Fix PCMFloat datasource command v1 (#3127)
Really simple copy pasta error here.

Shouldn't affect anything as float support was added at the same REV as
datasource command v2.
2022-02-16 23:55:40 +01:00
3bd357045f Do not allow render targets not explicitly written by the fragment shader to be modified (#3063)
* Do not allow render targets not explicitly written by the fragment shader to be modified

* Shader cache version bump

* Remove blank lines

* Avoid redundant color mask updates

* HostShaderCacheEntry can be null

* Avoid more redundant glColorMask calls

* nit: Mask -> Masks

* Fix currentComponentMask

* More efficient way to update _currentComponentMasks
2022-02-16 23:15:39 +01:00
ab5d77c0c4 amadeus: Fix limiter correctness (#3126)
This fixes missing audio on Nintendo Switch Sports Online Play Test.
2022-02-16 21:38:45 +01:00
7bfb5f79b8 When copying linear textures, DMA should ignore region X/Y (#3121) 2022-02-16 11:13:45 +01:00
8cc2479825 Adjusting how deadzones are calculated (#3079)
* Making deadzones feel nice and smooth + adding rider files to .gitignore

* removing unnecessary parentheses and fixing possibility of divide by 0

* formatting :)

* fixing up ClampAxis

* fixing up ClampAxis
2022-02-16 11:06:52 +01:00
8f35345729 Use Enum and Delegate.CreateDelegate generic overloads (#3111)
* Use Enum generic overloads

* Remove EnumExtensions.cs

* Use Delegate.CreateDelegate generic overloads
2022-02-13 10:50:07 -03:00
ce71f9144e InstEmitMemory32: Literal loads always have word-aligned PC (#3104) 2022-02-11 17:51:03 -03:00
f861f0bca2 Fix missing geometry shader passthrough inputs (#3106)
* Fix missing geometry shader passthrough inputs

* Shader cache version bump
2022-02-11 19:52:20 +01:00
571496d243 Ship SoundIO library only for the specified runtime (#3103)
* Add RuntimeIdentifers properties

For Linux, Windows and OS X x86-64
This ensures that the SoundIO project gets this property when built as a subproject

* Address gdkchan's nit

Merge tags into one
2022-02-11 00:15:13 +01:00
c3c3914ed3 Add a limit on the number of uses a constant may have (#3097) 2022-02-09 17:42:47 -03:00
6dffe0fad4 misc: Make PID unsigned long instead of long (#3043) 2022-02-09 17:18:07 -03:00
86b37d0ff7 ARMeilleure: A32: Implement SHSUB8 and UHSUB8 (#3089)
* ARMeilleure: A32: Implement UHSUB8

* ARMeilleure: A32: Implement SHSUB8
2022-02-08 10:46:42 +01:00
863c581190 fix headless sdl2 option string (#3093) 2022-02-07 11:50:51 +01:00
5c3112aaeb Convert the bool to a lowercase string (#3080)
mesa_glthread doesn't accept PascalCase input
2022-02-06 12:52:39 -03:00
88d3ffb97c ARMeilleure: A32: Implement SHADD8 (#3086) 2022-02-06 12:25:45 -03:00
222b1ad7da ARMeilleure: OpCodeTable: Add CMN (RsReg) (#3087) 2022-02-06 02:01:05 +01:00
d317cfd639 Try to ensure save data always has a valid owner ID (#3057)
- Run the extra data fix in FixExtraData on non-system saves that have no owner ID.
- Set the owner ID in the dummy application control property if an application doesn't have a proper one available.
2022-02-02 14:49:49 -07:00
76b9041adf Fix the pronunciation of Ryujinx (#3059) 2022-01-31 18:34:21 +01:00
b944941733 Fix bug that could cause depth buffer to be missing after clear (#3067) 2022-01-31 00:11:43 -03:00
0dddcd012c Remove Appveyor from Readme and SLN (#3026)
* Replace Appveyor with Github badge.

* Delete appveyor.yml

* Remove Appveyor from SLN
2022-01-30 16:41:22 +01:00
bd412afb9f Fix small precision error on CPU reciprocal estimate instructions (#3061)
* Fix small precision error on CPU reciprocal estimate instructions

* PPTC version bump
2022-01-29 23:59:34 +01:00
20ce37dee6 kernel: A bit of refactoring and fix GetThreadContext3 correctness (#3042)
* Start refactoring kernel a bit and import some changes from kernel decoupling PR

* kernel: Put output always at the start in Syscall functions

* kernel: Rewrite GetThreadContext3 to use a structure and to be accurate

* kernel: make KernelTransfer use generic types and simplify

* Fix some warning and do not use getters on MemoryInfo

* Address gdkchan's comment

* GetThreadContext3: use correct pause flag
2022-01-29 22:18:03 +01:00
c52158b733 Add timestamp to 16-byte/4-word semaphore releases. (#3049)
* Add timestamp to 16-byte semaphore releases.

BOTW was reading a ulong 8 bytes after a semaphore return. Turns out this is the timestamp it was trying to do performance calculation with, so I've made it write when necessary.

This mode was also added to the DMA semaphore I added recently, as it is required by a few games. (i think quake?)

The timestamp code has been moved to GPU context. Check other games with an unusually low framerate cap or dynamic resolution to see if they have improved.

* Cast dma semaphore payload to ulong to fill the space

* Write timestamp first

Might be just worrying too much, but we don't want the applcation reading timestamp if it sees the payload before timestamp is written.
2022-01-27 22:50:32 +01:00
fd6d3ec88f Fix res scale parameters not being updated in vertex shader (#3046)
This fixes an issue where the render scale array would not be updated when technically the scales on the flat array were the same, but the start index for the vertex scales was different.
2022-01-27 14:17:13 -03:00
126 changed files with 1053 additions and 749 deletions

3
.gitignore vendored
View File

@ -74,6 +74,9 @@ _TeamCity*
# DotCover is a Code Coverage Tool # DotCover is a Code Coverage Tool
*.dotCover *.dotCover
# Rider is a Visual Studio alternative
.idea/*
# NCrunch # NCrunch
*.ncrunch* *.ncrunch*
.*crunch*.local.xml .*crunch*.local.xml

View File

@ -9,13 +9,17 @@ namespace ARMeilleure.CodeGen.X86
{ {
static class X86Optimizer static class X86Optimizer
{ {
private const int MaxConstantUses = 10000;
public static void RunPass(ControlFlowGraph cfg) public static void RunPass(ControlFlowGraph cfg)
{ {
var constants = new Dictionary<ulong, Operand>(); var constants = new Dictionary<ulong, Operand>();
Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source) Operand GetConstantCopy(BasicBlock block, Operation operation, Operand source)
{ {
if (!constants.TryGetValue(source.Value, out var constant)) // If the constant has many uses, we also force a new constant mov to be added, in order
// to avoid overflow of the counts field (that is limited to 16 bits).
if (!constants.TryGetValue(source.Value, out var constant) || constant.UsesCount > MaxConstantUses)
{ {
constant = Local(source.Type); constant = Local(source.Type);
@ -23,7 +27,7 @@ namespace ARMeilleure.CodeGen.X86
block.Operations.AddBefore(operation, copyOp); block.Operations.AddBefore(operation, copyOp);
constants.Add(source.Value, constant); constants[source.Value] = constant;
} }
return constant; return constant;

View File

@ -654,6 +654,7 @@ namespace ARMeilleure.Decoders
SetA32("<<<<000101101111xxxx11110001xxxx", InstName.Clz, InstEmit32.Clz, OpCode32AluReg.Create); SetA32("<<<<000101101111xxxx11110001xxxx", InstName.Clz, InstEmit32.Clz, OpCode32AluReg.Create);
SetA32("<<<<00110111xxxx0000xxxxxxxxxxxx", InstName.Cmn, InstEmit32.Cmn, OpCode32AluImm.Create); SetA32("<<<<00110111xxxx0000xxxxxxxxxxxx", InstName.Cmn, InstEmit32.Cmn, OpCode32AluImm.Create);
SetA32("<<<<00010111xxxx0000xxxxxxx0xxxx", InstName.Cmn, InstEmit32.Cmn, OpCode32AluRsImm.Create); SetA32("<<<<00010111xxxx0000xxxxxxx0xxxx", InstName.Cmn, InstEmit32.Cmn, OpCode32AluRsImm.Create);
SetA32("<<<<00010111xxxx0000xxxx0xx1xxxx", InstName.Cmn, InstEmit32.Cmn, OpCode32AluRsReg.Create);
SetA32("<<<<00110101xxxx0000xxxxxxxxxxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluImm.Create); SetA32("<<<<00110101xxxx0000xxxxxxxxxxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluImm.Create);
SetA32("<<<<00010101xxxx0000xxxxxxx0xxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluRsImm.Create); SetA32("<<<<00010101xxxx0000xxxxxxx0xxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluRsImm.Create);
SetA32("<<<<00010101xxxx0000xxxx0xx1xxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluRsReg.Create); SetA32("<<<<00010101xxxx0000xxxx0xx1xxxx", InstName.Cmp, InstEmit32.Cmp, OpCode32AluRsReg.Create);
@ -732,6 +733,8 @@ namespace ARMeilleure.Decoders
SetA32("<<<<0000110xxxxxxxxxxxxx0xx1xxxx", InstName.Sbc, InstEmit32.Sbc, OpCode32AluRsReg.Create); SetA32("<<<<0000110xxxxxxxxxxxxx0xx1xxxx", InstName.Sbc, InstEmit32.Sbc, OpCode32AluRsReg.Create);
SetA32("<<<<0111101xxxxxxxxxxxxxx101xxxx", InstName.Sbfx, InstEmit32.Sbfx, OpCode32AluBf.Create); SetA32("<<<<0111101xxxxxxxxxxxxxx101xxxx", InstName.Sbfx, InstEmit32.Sbfx, OpCode32AluBf.Create);
SetA32("<<<<01110001xxxx1111xxxx0001xxxx", InstName.Sdiv, InstEmit32.Sdiv, OpCode32AluMla.Create); SetA32("<<<<01110001xxxx1111xxxx0001xxxx", InstName.Sdiv, InstEmit32.Sdiv, OpCode32AluMla.Create);
SetA32("<<<<01100011xxxxxxxx11111001xxxx", InstName.Shadd8, InstEmit32.Shadd8, OpCode32AluReg.Create);
SetA32("<<<<01100011xxxxxxxx11111111xxxx", InstName.Shsub8, InstEmit32.Shsub8, OpCode32AluReg.Create);
SetA32("<<<<00010000xxxxxxxxxxxx1xx0xxxx", InstName.Smla__, InstEmit32.Smla__, OpCode32AluMla.Create); SetA32("<<<<00010000xxxxxxxxxxxx1xx0xxxx", InstName.Smla__, InstEmit32.Smla__, OpCode32AluMla.Create);
SetA32("<<<<0000111xxxxxxxxxxxxx1001xxxx", InstName.Smlal, InstEmit32.Smlal, OpCode32AluUmull.Create); SetA32("<<<<0000111xxxxxxxxxxxxx1001xxxx", InstName.Smlal, InstEmit32.Smlal, OpCode32AluUmull.Create);
SetA32("<<<<00010100xxxxxxxxxxxx1xx0xxxx", InstName.Smlal__, InstEmit32.Smlal__, OpCode32AluUmull.Create); SetA32("<<<<00010100xxxxxxxxxxxx1xx0xxxx", InstName.Smlal__, InstEmit32.Smlal__, OpCode32AluUmull.Create);
@ -780,6 +783,7 @@ namespace ARMeilleure.Decoders
SetA32("<<<<0111111xxxxxxxxxxxxxx101xxxx", InstName.Ubfx, InstEmit32.Ubfx, OpCode32AluBf.Create); SetA32("<<<<0111111xxxxxxxxxxxxxx101xxxx", InstName.Ubfx, InstEmit32.Ubfx, OpCode32AluBf.Create);
SetA32("<<<<01110011xxxx1111xxxx0001xxxx", InstName.Udiv, InstEmit32.Udiv, OpCode32AluMla.Create); SetA32("<<<<01110011xxxx1111xxxx0001xxxx", InstName.Udiv, InstEmit32.Udiv, OpCode32AluMla.Create);
SetA32("<<<<01100111xxxxxxxx11111001xxxx", InstName.Uhadd8, InstEmit32.Uhadd8, OpCode32AluReg.Create); SetA32("<<<<01100111xxxxxxxx11111001xxxx", InstName.Uhadd8, InstEmit32.Uhadd8, OpCode32AluReg.Create);
SetA32("<<<<01100111xxxxxxxx11111111xxxx", InstName.Uhsub8, InstEmit32.Uhsub8, OpCode32AluReg.Create);
SetA32("<<<<00000100xxxxxxxxxxxx1001xxxx", InstName.Umaal, InstEmit32.Umaal, OpCode32AluUmull.Create); SetA32("<<<<00000100xxxxxxxxxxxx1001xxxx", InstName.Umaal, InstEmit32.Umaal, OpCode32AluUmull.Create);
SetA32("<<<<0000101xxxxxxxxxxxxx1001xxxx", InstName.Umlal, InstEmit32.Umlal, OpCode32AluUmull.Create); SetA32("<<<<0000101xxxxxxxxxxxxx1001xxxx", InstName.Umlal, InstEmit32.Umlal, OpCode32AluUmull.Create);
SetA32("<<<<0000100xxxxxxxxxxxxx1001xxxx", InstName.Umull, InstEmit32.Umull, OpCode32AluUmull.Create); SetA32("<<<<0000100xxxxxxxxxxxxx1001xxxx", InstName.Umull, InstEmit32.Umull, OpCode32AluUmull.Create);

View File

@ -1,13 +1,14 @@
// https://www.intel.com/content/dam/doc/white-paper/advanced-encryption-standard-new-instructions-set-paper.pdf // https://www.intel.com/content/dam/doc/white-paper/advanced-encryption-standard-new-instructions-set-paper.pdf
using ARMeilleure.State; using ARMeilleure.State;
using System;
namespace ARMeilleure.Instructions namespace ARMeilleure.Instructions
{ {
static class CryptoHelper static class CryptoHelper
{ {
#region "LookUp Tables" #region "LookUp Tables"
private static readonly byte[] _sBox = new byte[] private static ReadOnlySpan<byte> _sBox => new byte[]
{ {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
@ -27,7 +28,7 @@ namespace ARMeilleure.Instructions
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
}; };
private static readonly byte[] _invSBox = new byte[] private static ReadOnlySpan<byte> _invSBox => new byte[]
{ {
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
@ -47,7 +48,7 @@ namespace ARMeilleure.Instructions
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
}; };
private static readonly byte[] _gfMul02 = new byte[] private static ReadOnlySpan<byte> _gfMul02 => new byte[]
{ {
0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
@ -67,7 +68,7 @@ namespace ARMeilleure.Instructions
0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5 0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
}; };
private static readonly byte[] _gfMul03 = new byte[] private static ReadOnlySpan<byte> _gfMul03 => new byte[]
{ {
0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11, 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21, 0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
@ -87,7 +88,7 @@ namespace ARMeilleure.Instructions
0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
}; };
private static readonly byte[] _gfMul09 = new byte[] private static ReadOnlySpan<byte> _gfMul09 => new byte[]
{ {
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77, 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, 0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77,
0x90, 0x99, 0x82, 0x8b, 0xb4, 0xbd, 0xa6, 0xaf, 0xd8, 0xd1, 0xca, 0xc3, 0xfc, 0xf5, 0xee, 0xe7, 0x90, 0x99, 0x82, 0x8b, 0xb4, 0xbd, 0xa6, 0xaf, 0xd8, 0xd1, 0xca, 0xc3, 0xfc, 0xf5, 0xee, 0xe7,
@ -107,7 +108,7 @@ namespace ARMeilleure.Instructions
0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 0x07, 0x0e, 0x79, 0x70, 0x6b, 0x62, 0x5d, 0x54, 0x4f, 0x46 0x31, 0x38, 0x23, 0x2a, 0x15, 0x1c, 0x07, 0x0e, 0x79, 0x70, 0x6b, 0x62, 0x5d, 0x54, 0x4f, 0x46
}; };
private static readonly byte[] _gfMul0B = new byte[] private static ReadOnlySpan<byte> _gfMul0B => new byte[]
{ {
0x00, 0x0b, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45, 0x74, 0x7f, 0x62, 0x69, 0x00, 0x0b, 0x16, 0x1d, 0x2c, 0x27, 0x3a, 0x31, 0x58, 0x53, 0x4e, 0x45, 0x74, 0x7f, 0x62, 0x69,
0xb0, 0xbb, 0xa6, 0xad, 0x9c, 0x97, 0x8a, 0x81, 0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 0xd2, 0xd9, 0xb0, 0xbb, 0xa6, 0xad, 0x9c, 0x97, 0x8a, 0x81, 0xe8, 0xe3, 0xfe, 0xf5, 0xc4, 0xcf, 0xd2, 0xd9,
@ -127,7 +128,7 @@ namespace ARMeilleure.Instructions
0xca, 0xc1, 0xdc, 0xd7, 0xe6, 0xed, 0xf0, 0xfb, 0x92, 0x99, 0x84, 0x8f, 0xbe, 0xb5, 0xa8, 0xa3 0xca, 0xc1, 0xdc, 0xd7, 0xe6, 0xed, 0xf0, 0xfb, 0x92, 0x99, 0x84, 0x8f, 0xbe, 0xb5, 0xa8, 0xa3
}; };
private static readonly byte[] _gfMul0D = new byte[] private static ReadOnlySpan<byte> _gfMul0D => new byte[]
{ {
0x00, 0x0d, 0x1a, 0x17, 0x34, 0x39, 0x2e, 0x23, 0x68, 0x65, 0x72, 0x7f, 0x5c, 0x51, 0x46, 0x4b, 0x00, 0x0d, 0x1a, 0x17, 0x34, 0x39, 0x2e, 0x23, 0x68, 0x65, 0x72, 0x7f, 0x5c, 0x51, 0x46, 0x4b,
0xd0, 0xdd, 0xca, 0xc7, 0xe4, 0xe9, 0xfe, 0xf3, 0xb8, 0xb5, 0xa2, 0xaf, 0x8c, 0x81, 0x96, 0x9b, 0xd0, 0xdd, 0xca, 0xc7, 0xe4, 0xe9, 0xfe, 0xf3, 0xb8, 0xb5, 0xa2, 0xaf, 0x8c, 0x81, 0x96, 0x9b,
@ -147,7 +148,7 @@ namespace ARMeilleure.Instructions
0xdc, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, 0xff, 0xb4, 0xb9, 0xae, 0xa3, 0x80, 0x8d, 0x9a, 0x97 0xdc, 0xd1, 0xc6, 0xcb, 0xe8, 0xe5, 0xf2, 0xff, 0xb4, 0xb9, 0xae, 0xa3, 0x80, 0x8d, 0x9a, 0x97
}; };
private static readonly byte[] _gfMul0E = new byte[] private static ReadOnlySpan<byte> _gfMul0E => new byte[]
{ {
0x00, 0x0e, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62, 0x48, 0x46, 0x54, 0x5a, 0x00, 0x0e, 0x1c, 0x12, 0x38, 0x36, 0x24, 0x2a, 0x70, 0x7e, 0x6c, 0x62, 0x48, 0x46, 0x54, 0x5a,
0xe0, 0xee, 0xfc, 0xf2, 0xd8, 0xd6, 0xc4, 0xca, 0x90, 0x9e, 0x8c, 0x82, 0xa8, 0xa6, 0xb4, 0xba, 0xe0, 0xee, 0xfc, 0xf2, 0xd8, 0xd6, 0xc4, 0xca, 0x90, 0x9e, 0x8c, 0x82, 0xa8, 0xa6, 0xb4, 0xba,
@ -167,12 +168,12 @@ namespace ARMeilleure.Instructions
0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, 0xfd, 0xa7, 0xa9, 0xbb, 0xb5, 0x9f, 0x91, 0x83, 0x8d 0xd7, 0xd9, 0xcb, 0xc5, 0xef, 0xe1, 0xf3, 0xfd, 0xa7, 0xa9, 0xbb, 0xb5, 0x9f, 0x91, 0x83, 0x8d
}; };
private static readonly byte[] _srPerm = new byte[] private static ReadOnlySpan<byte> _srPerm => new byte[]
{ {
0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3 0, 13, 10, 7, 4, 1, 14, 11, 8, 5, 2, 15, 12, 9, 6, 3
}; };
private static readonly byte[] _isrPerm = new byte[] private static ReadOnlySpan<byte> _isrPerm => new byte[]
{ {
0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11
}; };

View File

@ -387,6 +387,16 @@ namespace ARMeilleure.Instructions
EmitDiv(context, false); EmitDiv(context, false);
} }
public static void Shadd8(ArmEmitterContext context)
{
EmitHadd8(context, false);
}
public static void Shsub8(ArmEmitterContext context)
{
EmitHsub8(context, false);
}
public static void Ssat(ArmEmitterContext context) public static void Ssat(ArmEmitterContext context)
{ {
OpCode32Sat op = (OpCode32Sat)context.CurrOp; OpCode32Sat op = (OpCode32Sat)context.CurrOp;
@ -474,20 +484,12 @@ namespace ARMeilleure.Instructions
public static void Uhadd8(ArmEmitterContext context) public static void Uhadd8(ArmEmitterContext context)
{ {
OpCode32AluReg op = (OpCode32AluReg)context.CurrOp; EmitHadd8(context, true);
}
Operand m = GetIntA32(context, op.Rm); public static void Uhsub8(ArmEmitterContext context)
Operand n = GetIntA32(context, op.Rn); {
EmitHsub8(context, true);
Operand xor, res;
res = context.BitwiseAnd(m, n);
xor = context.BitwiseExclusiveOr(m, n);
xor = context.ShiftRightUI(xor, Const(1));
xor = context.BitwiseAnd(xor, Const(0x7F7F7F7Fu));
res = context.Add(res, xor);
SetIntA32(context, op.Rd, res);
} }
public static void Usat(ArmEmitterContext context) public static void Usat(ArmEmitterContext context)
@ -659,6 +661,71 @@ namespace ARMeilleure.Instructions
context.MarkLabel(lblEnd); context.MarkLabel(lblEnd);
} }
private static void EmitHadd8(ArmEmitterContext context, bool unsigned)
{
OpCode32AluReg op = (OpCode32AluReg)context.CurrOp;
Operand m = GetIntA32(context, op.Rm);
Operand n = GetIntA32(context, op.Rn);
Operand xor, res, carry;
// This relies on the equality x+y == ((x&y) << 1) + (x^y).
// Note that x^y always contains the LSB of the result.
// Since we want to calculate (x+y)/2, we can instead calculate (x&y) + ((x^y)>>1).
// We mask by 0x7F to remove the LSB so that it doesn't leak into the field below.
res = context.BitwiseAnd(m, n);
carry = context.BitwiseExclusiveOr(m, n);
xor = context.ShiftRightUI(carry, Const(1));
xor = context.BitwiseAnd(xor, Const(0x7F7F7F7Fu));
res = context.Add(res, xor);
if (!unsigned)
{
// Propagates the sign bit from (x^y)>>1 upwards by one.
carry = context.BitwiseAnd(carry, Const(0x80808080u));
res = context.BitwiseExclusiveOr(res, carry);
}
SetIntA32(context, op.Rd, res);
}
private static void EmitHsub8(ArmEmitterContext context, bool unsigned)
{
OpCode32AluReg op = (OpCode32AluReg)context.CurrOp;
Operand m = GetIntA32(context, op.Rm);
Operand n = GetIntA32(context, op.Rn);
Operand left, right, carry, res;
// This relies on the equality x-y == (x^y) - (((x^y)&y) << 1).
// Note that x^y always contains the LSB of the result.
// Since we want to calculate (x+y)/2, we can instead calculate ((x^y)>>1) - ((x^y)&y).
carry = context.BitwiseExclusiveOr(m, n);
left = context.ShiftRightUI(carry, Const(1));
right = context.BitwiseAnd(carry, m);
// We must now perform a partitioned subtraction.
// We can do this because minuend contains 7 bit fields.
// We use the extra bit in minuend as a bit to borrow from; we set this bit.
// We invert this bit at the end as this tells us if that bit was borrowed from.
res = context.BitwiseOr(left, Const(0x80808080));
res = context.Subtract(res, right);
res = context.BitwiseExclusiveOr(res, Const(0x80808080));
if (!unsigned)
{
// We then sign extend the result into this bit.
carry = context.BitwiseAnd(carry, Const(0x80808080));
res = context.BitwiseExclusiveOr(res, carry);
}
SetIntA32(context, op.Rd, res);
}
private static void EmitSat(ArmEmitterContext context, int intMin, int intMax) private static void EmitSat(ArmEmitterContext context, int intMin, int intMax)
{ {
OpCode32Sat op = (OpCode32Sat)context.CurrOp; OpCode32Sat op = (OpCode32Sat)context.CurrOp;
@ -772,4 +839,4 @@ namespace ARMeilleure.Instructions
EmitGenericAluStoreA32(context, op.Rd, op.SetFlags, value); EmitGenericAluStoreA32(context, op.Rd, op.SetFlags, value);
} }
} }
} }

View File

@ -47,6 +47,20 @@ namespace ARMeilleure.Instructions
} }
} }
public static Operand GetIntA32AlignedPC(ArmEmitterContext context, int regIndex)
{
if (regIndex == RegisterAlias.Aarch32Pc)
{
OpCode32 op = (OpCode32)context.CurrOp;
return Const((int)(op.GetPc() & 0xfffffffc));
}
else
{
return Register(GetRegisterAlias(context.Mode, regIndex), RegisterType.Integer, OperandType.I32);
}
}
public static Operand GetVecA32(int regIndex) public static Operand GetVecA32(int regIndex)
{ {
return Register(regIndex, RegisterType.Vector, OperandType.V128); return Register(regIndex, RegisterType.Vector, OperandType.V128);

View File

@ -153,7 +153,7 @@ namespace ARMeilleure.Instructions
{ {
OpCode32Mem op = (OpCode32Mem)context.CurrOp; OpCode32Mem op = (OpCode32Mem)context.CurrOp;
Operand n = context.Copy(GetIntA32(context, op.Rn)); Operand n = context.Copy(GetIntA32AlignedPC(context, op.Rn));
Operand m = GetMemM(context, setCarry: false); Operand m = GetMemM(context, setCarry: false);
Operand temp = default; Operand temp = default;

View File

@ -3613,7 +3613,7 @@ namespace ARMeilleure.Instructions
Operand masked = context.AddIntrinsic(Intrinsic.X86Pand, value, expMask); Operand masked = context.AddIntrinsic(Intrinsic.X86Pand, value, expMask);
Operand isNaNInf = context.AddIntrinsic(Intrinsic.X86Pcmpeqd, masked, expMask); Operand isNaNInf = context.AddIntrinsic(Intrinsic.X86Pcmpeqd, masked, expMask);
value = context.AddIntrinsic(Intrinsic.X86Paddw, value, roundMask); value = context.AddIntrinsic(Intrinsic.X86Paddd, value, roundMask);
value = context.AddIntrinsic(Intrinsic.X86Pand, value, truncMask); value = context.AddIntrinsic(Intrinsic.X86Pand, value, truncMask);
return context.AddIntrinsic(Intrinsic.X86Blendvps, value, oValue, isNaNInf); return context.AddIntrinsic(Intrinsic.X86Blendvps, value, oValue, isNaNInf);

View File

@ -80,6 +80,7 @@ namespace ARMeilleure.Instructions
Sbcs, Sbcs,
Sbfm, Sbfm,
Sdiv, Sdiv,
Shsub8,
Smaddl, Smaddl,
Smsubl, Smsubl,
Smulh, Smulh,
@ -516,6 +517,7 @@ namespace ARMeilleure.Instructions
Rsb, Rsb,
Rsc, Rsc,
Sbfx, Sbfx,
Shadd8,
Smla__, Smla__,
Smlal, Smlal,
Smlal__, Smlal__,
@ -545,6 +547,7 @@ namespace ARMeilleure.Instructions
Tst, Tst,
Ubfx, Ubfx,
Uhadd8, Uhadd8,
Uhsub8,
Umaal, Umaal,
Umlal, Umlal,
Umull, Umull,

View File

@ -824,7 +824,7 @@ namespace ARMeilleure.Instructions
return (ulong)(size - 1); return (ulong)(size - 1);
} }
private static readonly byte[] ClzNibbleTbl = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; private static ReadOnlySpan<byte> ClzNibbleTbl => new byte[] { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
public static ulong CountLeadingZeros(ulong value, int size) // size is 8, 16, 32 or 64 (SIMD&FP or Base Inst.). public static ulong CountLeadingZeros(ulong value, int size) // size is 8, 16, 32 or 64 (SIMD&FP or Base Inst.).
{ {

View File

@ -27,7 +27,7 @@ namespace ARMeilleure.Translation.PTC
private const string OuterHeaderMagicString = "PTCohd\0\0"; private const string OuterHeaderMagicString = "PTCohd\0\0";
private const string InnerHeaderMagicString = "PTCihd\0\0"; private const string InnerHeaderMagicString = "PTCihd\0\0";
private const uint InternalVersion = 3034; //! To be incremented manually for each change to the ARMeilleure project. private const uint InternalVersion = 3061; //! To be incremented manually for each change to the ARMeilleure project.
private const string ActualDir = "0"; private const string ActualDir = "0";
private const string BackupDir = "1"; private const string BackupDir = "1";

View File

@ -5,7 +5,7 @@
<br> <br>
<b>Ryujinx</b> <b>Ryujinx</b>
<br> <br>
<sub><sup><b>(REE-YOU-JI-NX)</b></sup></sub> <sub><sup><b>(REE-YOU-JINX)</b></sup></sub>
<br> <br>
</h1> </h1>
@ -17,8 +17,8 @@
</p> </p>
<p align="center"> <p align="center">
<a href="https://ci.appveyor.com/project/gdkchan/ryujinx?branch=master"> <a href="https://github.com/Ryujinx/Ryujinx/actions/workflows/release.yml">
<img src="https://ci.appveyor.com/api/projects/status/ssg4jwu6ve3k594s/branch/master?svg=true" <img src="https://github.com/Ryujinx/Ryujinx/actions/workflows/release.yml/badge.svg"
alt=""> alt="">
</a> </a>
<a href="https://discord.com/invite/VkQYXAZ"> <a href="https://discord.com/invite/VkQYXAZ">

View File

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -100,9 +100,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {
for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++) for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++)
{ {
float inputSample = *((float*)inputBuffers[channelIndex] + sampleIndex); float rawInputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);
float sampleInputMax = Math.Abs(inputSample * Parameter.InputGain); float inputSample = (rawInputSample / short.MaxValue) * Parameter.InputGain;
float sampleInputMax = Math.Abs(inputSample);
float inputCoefficient = Parameter.ReleaseCoefficient; float inputCoefficient = Parameter.ReleaseCoefficient;
@ -131,7 +133,9 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]]; ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]];
*((float*)outputBuffers[channelIndex] + sampleIndex) = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain; float outputSample = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
*((float*)outputBuffers[channelIndex] + sampleIndex) = outputSample * short.MaxValue;
delayedSample = inputSample; delayedSample = inputSample;

View File

@ -111,9 +111,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {
for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++) for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++)
{ {
float inputSample = *((float*)inputBuffers[channelIndex] + sampleIndex); float rawInputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);
float sampleInputMax = Math.Abs(inputSample * Parameter.InputGain); float inputSample = (rawInputSample / short.MaxValue) * Parameter.InputGain;
float sampleInputMax = Math.Abs(inputSample);
float inputCoefficient = Parameter.ReleaseCoefficient; float inputCoefficient = Parameter.ReleaseCoefficient;
@ -142,7 +144,9 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]]; ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]];
*((float*)outputBuffers[channelIndex] + sampleIndex) = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain; float outputSample = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
*((float*)outputBuffers[channelIndex] + sampleIndex) = outputSample * short.MaxValue;
delayedSample = inputSample; delayedSample = inputSample;

View File

@ -76,7 +76,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation
{ {
SourceSampleRate = SampleRate, SourceSampleRate = SampleRate,
SampleFormat = SampleFormat.PcmInt16, SampleFormat = SampleFormat.PcmFloat,
Pitch = Pitch, Pitch = Pitch,
DecodingBehaviour = DecodingBehaviour, DecodingBehaviour = DecodingBehaviour,
ExtraParameter = 0, ExtraParameter = 0,

View File

@ -600,19 +600,42 @@ namespace Ryujinx.Audio.Renderer.Dsp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ResampleForUpsampler(Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, float ratio, ref float fraction, int sampleCount) public static void ResampleForUpsampler(Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, float ratio, ref float fraction, int sampleCount)
{ {
// TODO: use a bandwidth filter to have better resampling. // Currently a simple cubic interpolation, assuming duplicated values at edges.
// TODO: Discover and use algorithm that the switch uses.
int inputBufferIndex = 0; int inputBufferIndex = 0;
int maxIndex = inputBuffer.Length - 1;
int cubicEnd = inputBuffer.Length - 3;
for (int i = 0; i < sampleCount; i++) for (int i = 0; i < sampleCount; i++)
{ {
float outputData = inputBuffer[inputBufferIndex]; float s0, s1, s2, s3;
if (fraction > 1.0f) s1 = inputBuffer[inputBufferIndex];
if (inputBufferIndex == 0 || inputBufferIndex > cubicEnd)
{ {
outputData = inputBuffer[inputBufferIndex + 1]; // Clamp interplation values at the ends of the input buffer.
s0 = inputBuffer[Math.Max(0, inputBufferIndex - 1)];
s2 = inputBuffer[Math.Min(maxIndex, inputBufferIndex + 1)];
s3 = inputBuffer[Math.Min(maxIndex, inputBufferIndex + 2)];
}
else
{
s0 = inputBuffer[inputBufferIndex - 1];
s2 = inputBuffer[inputBufferIndex + 1];
s3 = inputBuffer[inputBufferIndex + 2];
} }
outputBuffer[i] = outputData; float a = s3 - s2 - s0 + s1;
float b = s0 - s1 - a;
float c = s2 - s0;
float d = s1;
float f2 = fraction * fraction;
float f3 = f2 * fraction;
outputBuffer[i] = a * f3 + b * f2 + c * fraction + d;
fraction += ratio; fraction += ratio;
inputBufferIndex += (int)MathF.Truncate(fraction); inputBufferIndex += (int)MathF.Truncate(fraction);

View File

@ -37,6 +37,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State
DectectorAverage.AsSpan().Fill(0.0f); DectectorAverage.AsSpan().Fill(0.0f);
CompressionGain.AsSpan().Fill(1.0f); CompressionGain.AsSpan().Fill(1.0f);
DelayedSampleBufferPosition.AsSpan().Fill(0); DelayedSampleBufferPosition.AsSpan().Fill(0);
DelayedSampleBuffer.AsSpan().Fill(0.0f);
UpdateParameter(ref parameter); UpdateParameter(ref parameter);
} }

View File

@ -558,7 +558,16 @@ namespace Ryujinx.Audio.Renderer.Server
if (_rendererContext.BehaviourContext.IsEffectInfoVersion2Supported()) if (_rendererContext.BehaviourContext.IsEffectInfoVersion2Supported())
{ {
Memory<EffectResultState> dspResultState = _effectContext.GetDspStateMemory(effectId); Memory<EffectResultState> dspResultState;
if (effect.Parameter.StatisticsEnabled)
{
dspResultState = _effectContext.GetDspStateMemory(effectId);
}
else
{
dspResultState = Memory<EffectResultState>.Empty;
}
_commandBuffer.GenerateLimiterEffectVersion2(bufferOffset, effect.Parameter, effect.State, dspResultState, effect.IsEnabled, workBuffer, nodeId); _commandBuffer.GenerateLimiterEffectVersion2(bufferOffset, effect.Parameter, effect.State, dspResultState, effect.IsEnabled, workBuffer, nodeId);
} }

View File

@ -1,12 +0,0 @@
using System;
namespace Ryujinx.Common
{
public static class EnumExtensions
{
public static T[] GetValues<T>()
{
return (T[])Enum.GetValues(typeof(T));
}
}
}

View File

@ -6,7 +6,7 @@ namespace Ryujinx.Common.GraphicsDriver
{ {
public static void ToggleOGLThreading(bool enabled) public static void ToggleOGLThreading(bool enabled)
{ {
Environment.SetEnvironmentVariable("mesa_glthread", enabled.ToString()); Environment.SetEnvironmentVariable("mesa_glthread", enabled.ToString().ToLower());
Environment.SetEnvironmentVariable("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0"); Environment.SetEnvironmentVariable("__GL_THREADED_OPTIMIZATIONS", enabled ? "1" : "0");
try try

View File

@ -94,7 +94,7 @@ namespace Ryujinx.Common.Logging
static Logger() static Logger()
{ {
m_EnabledClasses = new bool[Enum.GetNames(typeof(LogClass)).Length]; m_EnabledClasses = new bool[Enum.GetNames<LogClass>().Length];
for (int index = 0; index < m_EnabledClasses.Length; index++) for (int index = 0; index < m_EnabledClasses.Length; index++)
{ {

View File

@ -1,8 +1,10 @@
using System;
namespace Ryujinx.Common namespace Ryujinx.Common
{ {
public static class BitUtils public static class BitUtils
{ {
private static readonly byte[] ClzNibbleTbl = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; private static ReadOnlySpan<byte> ClzNibbleTbl => new byte[] { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
public static uint AlignUp(uint value, int size) public static uint AlignUp(uint value, int size)
{ {

View File

@ -43,7 +43,7 @@ namespace Ryujinx.Common
Prime32_1 Prime32_1
}; };
private static readonly byte[] Xxh3KSecret = new byte[] private static ReadOnlySpan<byte> Xxh3KSecret => new byte[]
{ {
0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c, 0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f, 0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,

View File

@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.GAL
BufferHandle CreateBuffer(int size); BufferHandle CreateBuffer(int size);
IProgram CreateProgram(IShader[] shaders); IProgram CreateProgram(IShader[] shaders, ShaderInfo info);
ISampler CreateSampler(SamplerCreateInfo info); ISampler CreateSampler(SamplerCreateInfo info);
ITexture CreateTexture(TextureCreateInfo info, float scale); ITexture CreateTexture(TextureCreateInfo info, float scale);
@ -33,7 +33,7 @@ namespace Ryujinx.Graphics.GAL
Capabilities GetCapabilities(); Capabilities GetCapabilities();
IProgram LoadProgramBinary(byte[] programBinary); IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info);
void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data); void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data);

View File

@ -5,17 +5,21 @@
public ThreadedProgram Threaded { get; set; } public ThreadedProgram Threaded { get; set; }
private byte[] _data; private byte[] _data;
private bool _hasFragmentShader;
private ShaderInfo _info;
public BinaryProgramRequest(ThreadedProgram program, byte[] data) public BinaryProgramRequest(ThreadedProgram program, byte[] data, bool hasFragmentShader, ShaderInfo info)
{ {
Threaded = program; Threaded = program;
_data = data; _data = data;
_hasFragmentShader = hasFragmentShader;
_info = info;
} }
public IProgram Create(IRenderer renderer) public IProgram Create(IRenderer renderer)
{ {
return renderer.LoadProgramBinary(_data); return renderer.LoadProgramBinary(_data, _hasFragmentShader, _info);
} }
} }
} }

View File

@ -7,12 +7,14 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources.Programs
public ThreadedProgram Threaded { get; set; } public ThreadedProgram Threaded { get; set; }
private IShader[] _shaders; private IShader[] _shaders;
private ShaderInfo _info;
public SourceProgramRequest(ThreadedProgram program, IShader[] shaders) public SourceProgramRequest(ThreadedProgram program, IShader[] shaders, ShaderInfo info)
{ {
Threaded = program; Threaded = program;
_shaders = shaders; _shaders = shaders;
_info = info;
} }
public IProgram Create(IRenderer renderer) public IProgram Create(IRenderer renderer)
@ -24,7 +26,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources.Programs
return threaded?.Base; return threaded?.Base;
}).ToArray(); }).ToArray();
return renderer.CreateProgram(shaders); return renderer.CreateProgram(shaders, _info);
} }
} }
} }

View File

@ -268,10 +268,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading
return handle; return handle;
} }
public IProgram CreateProgram(IShader[] shaders) public IProgram CreateProgram(IShader[] shaders, ShaderInfo info)
{ {
var program = new ThreadedProgram(this); var program = new ThreadedProgram(this);
SourceProgramRequest request = new SourceProgramRequest(program, shaders); SourceProgramRequest request = new SourceProgramRequest(program, shaders, info);
Programs.Add(request); Programs.Add(request);
New<CreateProgramCommand>().Set(Ref((IProgramRequest)request)); New<CreateProgramCommand>().Set(Ref((IProgramRequest)request));
@ -355,11 +355,11 @@ namespace Ryujinx.Graphics.GAL.Multithreading
_baseRenderer.Initialize(logLevel); _baseRenderer.Initialize(logLevel);
} }
public IProgram LoadProgramBinary(byte[] programBinary) public IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info)
{ {
var program = new ThreadedProgram(this); var program = new ThreadedProgram(this);
BinaryProgramRequest request = new BinaryProgramRequest(program, programBinary); BinaryProgramRequest request = new BinaryProgramRequest(program, programBinary, hasFragmentShader, info);
Programs.Add(request); Programs.Add(request);
New<CreateProgramCommand>().Set(Ref((IProgramRequest)request)); New<CreateProgramCommand>().Set(Ref((IProgramRequest)request));

View File

@ -0,0 +1,12 @@
namespace Ryujinx.Graphics.GAL
{
public struct ShaderInfo
{
public int FragmentOutputMap { get; }
public ShaderInfo(int fragmentOutputMap)
{
FragmentOutputMap = fragmentOutputMap;
}
}
}

View File

@ -85,9 +85,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
} }
int alignWidth = Constants.StrideAlignment / bpp; int alignWidth = Constants.StrideAlignment / bpp;
return tex.RegionX == 0 && return stride / bpp == BitUtils.AlignUp(xCount, alignWidth);
tex.RegionY == 0 &&
stride / bpp == BitUtils.AlignUp(xCount, alignWidth);
} }
else else
{ {
@ -115,7 +113,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
} }
else /* if (type == LaunchDmaSemaphoreType.ReleaseFourWordSemaphore) */ else /* if (type == LaunchDmaSemaphoreType.ReleaseFourWordSemaphore) */
{ {
Logger.Warning?.Print(LogClass.Gpu, "DMA semaphore type ReleaseFourWordSemaphore was used, but is not currently implemented."); _channel.MemoryManager.Write(address + 8, _context.GetTimestamp());
_channel.MemoryManager.Write(address, (ulong)_state.State.SetSemaphorePayload);
} }
} }
} }
@ -160,6 +159,20 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
var dst = Unsafe.As<uint, DmaTexture>(ref _state.State.SetDstBlockSize); var dst = Unsafe.As<uint, DmaTexture>(ref _state.State.SetDstBlockSize);
var src = Unsafe.As<uint, DmaTexture>(ref _state.State.SetSrcBlockSize); var src = Unsafe.As<uint, DmaTexture>(ref _state.State.SetSrcBlockSize);
int srcRegionX = 0, srcRegionY = 0, dstRegionX = 0, dstRegionY = 0;
if (!srcLinear)
{
srcRegionX = src.RegionX;
srcRegionY = src.RegionY;
}
if (!dstLinear)
{
dstRegionX = dst.RegionX;
dstRegionY = dst.RegionY;
}
int srcStride = (int)_state.State.PitchIn; int srcStride = (int)_state.State.PitchIn;
int dstStride = (int)_state.State.PitchOut; int dstStride = (int)_state.State.PitchOut;
@ -181,8 +194,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
dst.MemoryLayout.UnpackGobBlocksInZ(), dst.MemoryLayout.UnpackGobBlocksInZ(),
dstBpp); dstBpp);
(int srcBaseOffset, int srcSize) = srcCalculator.GetRectangleRange(src.RegionX, src.RegionY, xCount, yCount); (int srcBaseOffset, int srcSize) = srcCalculator.GetRectangleRange(srcRegionX, srcRegionY, xCount, yCount);
(int dstBaseOffset, int dstSize) = dstCalculator.GetRectangleRange(dst.RegionX, dst.RegionY, xCount, yCount); (int dstBaseOffset, int dstSize) = dstCalculator.GetRectangleRange(dstRegionX, dstRegionY, xCount, yCount);
if (srcLinear && srcStride < 0) if (srcLinear && srcStride < 0)
{ {
@ -271,13 +284,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
for (int y = 0; y < yCount; y++) for (int y = 0; y < yCount; y++)
{ {
srcCalculator.SetY(src.RegionY + y); srcCalculator.SetY(srcRegionY + y);
dstCalculator.SetY(dst.RegionY + y); dstCalculator.SetY(dstRegionY + y);
for (int x = 0; x < xCount; x++) for (int x = 0; x < xCount; x++)
{ {
int srcOffset = srcCalculator.GetOffset(src.RegionX + x); int srcOffset = srcCalculator.GetOffset(srcRegionX + x);
int dstOffset = dstCalculator.GetOffset(dst.RegionX + x); int dstOffset = dstCalculator.GetOffset(dstRegionX + x);
*(T*)(dstBase + dstOffset) = *(T*)(srcBase + srcOffset); *(T*)(dstBase + dstOffset) = *(T*)(srcBase + srcOffset);
} }

View File

@ -75,6 +75,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
SemaphoredOperation operation = _state.State.SemaphoredOperation; SemaphoredOperation operation = _state.State.SemaphoredOperation;
if (_state.State.SemaphoredReleaseSize == SemaphoredReleaseSize.SixteenBytes)
{
_parent.MemoryManager.Write(address + 4, 0);
_parent.MemoryManager.Write(address + 8, _context.GetTimestamp());
}
// TODO: Acquire operations (Wait), interrupts for invalid combinations. // TODO: Acquire operations (Wait), interrupts for invalid combinations.
if (operation == SemaphoredOperation.Release) if (operation == SemaphoredOperation.Release)
{ {

View File

@ -112,7 +112,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
_ilGen.Emit(OpCodes.Ret); _ilGen.Emit(OpCodes.Ret);
} }
return (MacroExecute)_meth.CreateDelegate(typeof(MacroExecute)); return _meth.CreateDelegate<MacroExecute>();
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,4 @@
using Ryujinx.Common; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Gpu.Engine.Threed namespace Ryujinx.Graphics.Gpu.Engine.Threed
{ {
@ -9,9 +7,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary> /// </summary>
class SemaphoreUpdater class SemaphoreUpdater
{ {
private const int NsToTicksFractionNumerator = 384;
private const int NsToTicksFractionDenominator = 625;
/// <summary> /// <summary>
/// GPU semaphore operation. /// GPU semaphore operation.
/// </summary> /// </summary>
@ -154,14 +149,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{ {
ulong gpuVa = _state.State.SemaphoreAddress.Pack(); ulong gpuVa = _state.State.SemaphoreAddress.Pack();
ulong ticks = ConvertNanosecondsToTicks((ulong)PerformanceCounter.ElapsedNanoseconds); ulong ticks = _context.GetTimestamp();
if (GraphicsConfig.FastGpuTime)
{
// Divide by some amount to report time as if operations were performed faster than they really are.
// This can prevent some games from switching to a lower resolution because rendering is too slow.
ticks /= 256;
}
ICounterEvent counter = null; ICounterEvent counter = null;
@ -197,27 +185,5 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
_channel.MemoryManager.CounterCache.AddOrUpdate(gpuVa, counter); _channel.MemoryManager.CounterCache.AddOrUpdate(gpuVa, counter);
} }
/// <summary>
/// Converts a nanoseconds timestamp value to Maxwell time ticks.
/// </summary>
/// <remarks>
/// The frequency is 614400000 Hz.
/// </remarks>
/// <param name="nanoseconds">Timestamp in nanoseconds</param>
/// <returns>Maxwell ticks</returns>
private static ulong ConvertNanosecondsToTicks(ulong nanoseconds)
{
// We need to divide first to avoid overflows.
// We fix up the result later by calculating the difference and adding
// that to the result.
ulong divided = nanoseconds / NsToTicksFractionDenominator;
ulong rounded = divided * NsToTicksFractionDenominator;
ulong errorBias = (nanoseconds - rounded) * NsToTicksFractionNumerator / NsToTicksFractionDenominator;
return divided * NsToTicksFractionNumerator + errorBias;
}
} }
} }

View File

@ -369,14 +369,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (color != null) if (color != null)
{ {
if (clipRegionWidth > color.Width) if (clipRegionWidth > color.Width / samplesInX)
{ {
clipRegionWidth = color.Width; clipRegionWidth = color.Width / samplesInX;
} }
if (clipRegionHeight > color.Height) if (clipRegionHeight > color.Height / samplesInY)
{ {
clipRegionHeight = color.Height; clipRegionHeight = color.Height / samplesInY;
} }
} }
} }
@ -400,14 +400,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
if (depthStencil != null) if (depthStencil != null)
{ {
if (clipRegionWidth > depthStencil.Width) if (clipRegionWidth > depthStencil.Width / samplesInX)
{ {
clipRegionWidth = depthStencil.Width; clipRegionWidth = depthStencil.Width / samplesInX;
} }
if (clipRegionHeight > depthStencil.Height) if (clipRegionHeight > depthStencil.Height / samplesInY)
{ {
clipRegionHeight = depthStencil.Height; clipRegionHeight = depthStencil.Height / samplesInY;
} }
} }
} }

View File

@ -1,3 +1,4 @@
using Ryujinx.Common;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.GPFifo; using Ryujinx.Graphics.Gpu.Engine.GPFifo;
using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Memory;
@ -15,6 +16,9 @@ namespace Ryujinx.Graphics.Gpu
/// </summary> /// </summary>
public sealed class GpuContext : IDisposable public sealed class GpuContext : IDisposable
{ {
private const int NsToTicksFractionNumerator = 384;
private const int NsToTicksFractionDenominator = 625;
/// <summary> /// <summary>
/// Event signaled when the host emulation context is ready to be used by the gpu context. /// Event signaled when the host emulation context is ready to be used by the gpu context.
/// </summary> /// </summary>
@ -73,7 +77,7 @@ namespace Ryujinx.Graphics.Gpu
/// <summary> /// <summary>
/// Registry with physical memories that can be used with this GPU context, keyed by owner process ID. /// Registry with physical memories that can be used with this GPU context, keyed by owner process ID.
/// </summary> /// </summary>
internal ConcurrentDictionary<long, PhysicalMemory> PhysicalMemoryRegistry { get; } internal ConcurrentDictionary<ulong, PhysicalMemory> PhysicalMemoryRegistry { get; }
/// <summary> /// <summary>
/// Host hardware capabilities. /// Host hardware capabilities.
@ -122,7 +126,7 @@ namespace Ryujinx.Graphics.Gpu
DeferredActions = new Queue<Action>(); DeferredActions = new Queue<Action>();
PhysicalMemoryRegistry = new ConcurrentDictionary<long, PhysicalMemory>(); PhysicalMemoryRegistry = new ConcurrentDictionary<ulong, PhysicalMemory>();
} }
/// <summary> /// <summary>
@ -140,7 +144,7 @@ namespace Ryujinx.Graphics.Gpu
/// <param name="pid">ID of the process that owns the memory manager</param> /// <param name="pid">ID of the process that owns the memory manager</param>
/// <returns>The memory manager</returns> /// <returns>The memory manager</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
public MemoryManager CreateMemoryManager(long pid) public MemoryManager CreateMemoryManager(ulong pid)
{ {
if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory)) if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory))
{ {
@ -156,7 +160,7 @@ namespace Ryujinx.Graphics.Gpu
/// <param name="pid">ID of the process that owns <paramref name="cpuMemory"/></param> /// <param name="pid">ID of the process that owns <paramref name="cpuMemory"/></param>
/// <param name="cpuMemory">Virtual memory owned by the process</param> /// <param name="cpuMemory">Virtual memory owned by the process</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="pid"/> was already registered</exception> /// <exception cref="ArgumentException">Thrown if <paramref name="pid"/> was already registered</exception>
public void RegisterProcess(long pid, Cpu.IVirtualMemoryManagerTracked cpuMemory) public void RegisterProcess(ulong pid, Cpu.IVirtualMemoryManagerTracked cpuMemory)
{ {
var physicalMemory = new PhysicalMemory(this, cpuMemory); var physicalMemory = new PhysicalMemory(this, cpuMemory);
if (!PhysicalMemoryRegistry.TryAdd(pid, physicalMemory)) if (!PhysicalMemoryRegistry.TryAdd(pid, physicalMemory))
@ -171,7 +175,7 @@ namespace Ryujinx.Graphics.Gpu
/// Unregisters a process, indicating that its memory will no longer be used, and that caches can be freed. /// Unregisters a process, indicating that its memory will no longer be used, and that caches can be freed.
/// </summary> /// </summary>
/// <param name="pid">ID of the process</param> /// <param name="pid">ID of the process</param>
public void UnregisterProcess(long pid) public void UnregisterProcess(ulong pid)
{ {
if (PhysicalMemoryRegistry.TryRemove(pid, out var physicalMemory)) if (PhysicalMemoryRegistry.TryRemove(pid, out var physicalMemory))
{ {
@ -180,6 +184,46 @@ namespace Ryujinx.Graphics.Gpu
} }
} }
/// <summary>
/// Converts a nanoseconds timestamp value to Maxwell time ticks.
/// </summary>
/// <remarks>
/// The frequency is 614400000 Hz.
/// </remarks>
/// <param name="nanoseconds">Timestamp in nanoseconds</param>
/// <returns>Maxwell ticks</returns>
private static ulong ConvertNanosecondsToTicks(ulong nanoseconds)
{
// We need to divide first to avoid overflows.
// We fix up the result later by calculating the difference and adding
// that to the result.
ulong divided = nanoseconds / NsToTicksFractionDenominator;
ulong rounded = divided * NsToTicksFractionDenominator;
ulong errorBias = (nanoseconds - rounded) * NsToTicksFractionNumerator / NsToTicksFractionDenominator;
return divided * NsToTicksFractionNumerator + errorBias;
}
/// <summary>
/// Gets the value of the GPU timer.
/// </summary>
/// <returns>The current GPU timestamp</returns>
public ulong GetTimestamp()
{
ulong ticks = ConvertNanosecondsToTicks((ulong)PerformanceCounter.ElapsedNanoseconds);
if (GraphicsConfig.FastGpuTime)
{
// Divide by some amount to report time as if operations were performed faster than they really are.
// This can prevent some games from switching to a lower resolution because rendering is too slow.
ticks /= 256;
}
return ticks;
}
/// <summary> /// <summary>
/// Shader cache state update handler. /// Shader cache state update handler.
/// </summary> /// </summary>

View File

@ -49,6 +49,7 @@ namespace Ryujinx.Graphics.Gpu.Image
private readonly float[] _scales; private readonly float[] _scales;
private bool _scaleChanged; private bool _scaleChanged;
private int _lastFragmentTotal;
/// <summary> /// <summary>
/// Constructs a new instance of the texture bindings manager. /// Constructs a new instance of the texture bindings manager.
@ -288,26 +289,30 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary> /// </summary>
private void CommitRenderScale() private void CommitRenderScale()
{ {
// Stage 0 total: Compute or Vertex.
int total = _textureBindingsCount[0] + _imageBindingsCount[0];
int fragmentIndex = (int)ShaderStage.Fragment - 1;
int fragmentTotal = _isCompute ? 0 : (_textureBindingsCount[fragmentIndex] + _imageBindingsCount[fragmentIndex]);
if (total != 0 && fragmentTotal != _lastFragmentTotal)
{
// Must update scales in the support buffer if:
// - Vertex stage has bindings.
// - Fragment stage binding count has been updated since last render scale update.
_scaleChanged = true;
}
if (_scaleChanged) if (_scaleChanged)
{ {
int fragmentTotal = 0;
int total;
if (!_isCompute) if (!_isCompute)
{ {
int fragmentIndex = (int)ShaderStage.Fragment - 1; total += fragmentTotal; // Add the fragment bindings to the total.
fragmentTotal = _textureBindingsCount[fragmentIndex] + _imageBindingsCount[fragmentIndex];
int vertexIndex = (int)ShaderStage.Vertex - 1;
int vertexTotal = _textureBindingsCount[vertexIndex] + _imageBindingsCount[vertexIndex];
total = fragmentTotal + vertexTotal;
}
else
{
total = _textureBindingsCount[0] + _imageBindingsCount[0];
} }
_lastFragmentTotal = fragmentTotal;
_context.Renderer.Pipeline.UpdateRenderScale(_scales, total, fragmentTotal); _context.Renderer.Pipeline.UpdateRenderScale(_scales, total, fragmentTotal);
_scaleChanged = false; _scaleChanged = false;

View File

@ -434,6 +434,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{ {
new Span<ITexture>(_rtHostColors).Fill(null); new Span<ITexture>(_rtHostColors).Fill(null);
_rtHostColors[index] = _rtColors[index]?.HostTexture; _rtHostColors[index] = _rtColors[index]?.HostTexture;
_rtHostDs = null;
_context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, null); _context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, null);
} }

View File

@ -77,7 +77,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
programInfo.Images.Count, programInfo.Images.Count,
programInfo.UsesInstanceId, programInfo.UsesInstanceId,
programInfo.UsesRtLayer, programInfo.UsesRtLayer,
programInfo.ClipDistancesWritten); programInfo.ClipDistancesWritten,
programInfo.FragmentOutputMap);
CBuffers = programInfo.CBuffers.ToArray(); CBuffers = programInfo.CBuffers.ToArray();
SBuffers = programInfo.SBuffers.ToArray(); SBuffers = programInfo.SBuffers.ToArray();
Textures = programInfo.Textures.ToArray(); Textures = programInfo.Textures.ToArray();
@ -97,7 +98,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
Images, Images,
Header.UseFlags.HasFlag(UseFlags.InstanceId), Header.UseFlags.HasFlag(UseFlags.InstanceId),
Header.UseFlags.HasFlag(UseFlags.RtLayer), Header.UseFlags.HasFlag(UseFlags.RtLayer),
Header.ClipDistancesWritten); Header.ClipDistancesWritten,
Header.FragmentOutputMap);
} }
/// <summary> /// <summary>

View File

@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
/// <summary> /// <summary>
/// Host shader entry header used for binding information. /// Host shader entry header used for binding information.
/// </summary> /// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x14)] [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x18)]
struct HostShaderCacheEntryHeader struct HostShaderCacheEntryHeader
{ {
/// <summary> /// <summary>
@ -70,6 +70,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
/// </summary> /// </summary>
public byte Reserved; public byte Reserved;
/// <summary>
/// Mask of components written by the fragment shader stage.
/// </summary>
public int FragmentOutputMap;
/// <summary> /// <summary>
/// Create a new host shader cache entry header. /// Create a new host shader cache entry header.
/// </summary> /// </summary>
@ -78,6 +83,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
/// <param name="texturesCount">Count of texture descriptors</param> /// <param name="texturesCount">Count of texture descriptors</param>
/// <param name="imagesCount">Count of image descriptors</param> /// <param name="imagesCount">Count of image descriptors</param>
/// <param name="usesInstanceId">Set to true if the shader uses instance id</param> /// <param name="usesInstanceId">Set to true if the shader uses instance id</param>
/// <param name="clipDistancesWritten">Mask of clip distances that are written to on the shader</param>
/// <param name="fragmentOutputMap">Mask of components written by the fragment shader stage</param>
public HostShaderCacheEntryHeader( public HostShaderCacheEntryHeader(
int cBuffersCount, int cBuffersCount,
int sBuffersCount, int sBuffersCount,
@ -85,13 +92,15 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
int imagesCount, int imagesCount,
bool usesInstanceId, bool usesInstanceId,
bool usesRtLayer, bool usesRtLayer,
byte clipDistancesWritten) : this() byte clipDistancesWritten,
int fragmentOutputMap) : this()
{ {
CBuffersCount = cBuffersCount; CBuffersCount = cBuffersCount;
SBuffersCount = sBuffersCount; SBuffersCount = sBuffersCount;
TexturesCount = texturesCount; TexturesCount = texturesCount;
ImagesCount = imagesCount; ImagesCount = imagesCount;
ClipDistancesWritten = clipDistancesWritten; ClipDistancesWritten = clipDistancesWritten;
FragmentOutputMap = fragmentOutputMap;
InUse = true; InUse = true;
UseFlags = usesInstanceId ? UseFlags.InstanceId : UseFlags.None; UseFlags = usesInstanceId ? UseFlags.InstanceId : UseFlags.None;

View File

@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary> /// <summary>
/// Version of the codegen (to be changed when codegen or guest format change). /// Version of the codegen (to be changed when codegen or guest format change).
/// </summary> /// </summary>
private const ulong ShaderCodeGenVersion = 3012; private const ulong ShaderCodeGenVersion = 3063;
// Progress reporting helpers // Progress reporting helpers
private volatile int _shaderCount; private volatile int _shaderCount;
@ -188,7 +188,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
{ {
hostShaderEntries = HostShaderCacheEntry.Parse(hostProgramBinary, out ReadOnlySpan<byte> hostProgramBinarySpan); hostShaderEntries = HostShaderCacheEntry.Parse(hostProgramBinary, out ReadOnlySpan<byte> hostProgramBinarySpan);
hostProgramBinary = hostProgramBinarySpan.ToArray(); hostProgramBinary = hostProgramBinarySpan.ToArray();
hostProgram = _context.Renderer.LoadProgramBinary(hostProgramBinary); hostProgram = _context.Renderer.LoadProgramBinary(hostProgramBinary, false, new ShaderInfo(-1));
} }
ShaderCompileTask task = new ShaderCompileTask(taskDoneEvent); ShaderCompileTask task = new ShaderCompileTask(taskDoneEvent);
@ -252,7 +252,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
// Compile shader and create program as the shader program binary got invalidated. // Compile shader and create program as the shader program binary got invalidated.
shader.HostShader = _context.Renderer.CompileShader(ShaderStage.Compute, program.Code); shader.HostShader = _context.Renderer.CompileShader(ShaderStage.Compute, program.Code);
hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader }); hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader }, new ShaderInfo(-1));
task.OnCompiled(hostProgram, (bool isNewProgramValid, ShaderCompileTask task) => task.OnCompiled(hostProgram, (bool isNewProgramValid, ShaderCompileTask task) =>
{ {
@ -303,7 +303,18 @@ namespace Ryujinx.Graphics.Gpu.Shader
{ {
hostShaderEntries = HostShaderCacheEntry.Parse(hostProgramBinary, out ReadOnlySpan<byte> hostProgramBinarySpan); hostShaderEntries = HostShaderCacheEntry.Parse(hostProgramBinary, out ReadOnlySpan<byte> hostProgramBinarySpan);
hostProgramBinary = hostProgramBinarySpan.ToArray(); hostProgramBinary = hostProgramBinarySpan.ToArray();
hostProgram = _context.Renderer.LoadProgramBinary(hostProgramBinary);
bool hasFragmentShader = false;
int fragmentOutputMap = -1;
int fragmentIndex = (int)ShaderStage.Fragment - 1;
if (hostShaderEntries[fragmentIndex] != null && hostShaderEntries[fragmentIndex].Header.InUse)
{
hasFragmentShader = true;
fragmentOutputMap = hostShaderEntries[fragmentIndex].Header.FragmentOutputMap;
}
hostProgram = _context.Renderer.LoadProgramBinary(hostProgramBinary, hasFragmentShader, new ShaderInfo(fragmentOutputMap));
} }
ShaderCompileTask task = new ShaderCompileTask(taskDoneEvent); ShaderCompileTask task = new ShaderCompileTask(taskDoneEvent);
@ -426,7 +437,15 @@ namespace Ryujinx.Graphics.Gpu.Shader
hostShaders.Add(hostShader); hostShaders.Add(hostShader);
} }
hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray()); int fragmentIndex = (int)ShaderStage.Fragment - 1;
int fragmentOutputMap = -1;
if (shaders[fragmentIndex] != null)
{
fragmentOutputMap = shaders[fragmentIndex].Info.FragmentOutputMap;
}
hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray(), new ShaderInfo(fragmentOutputMap));
task.OnCompiled(hostProgram, (bool isNewProgramValid, ShaderCompileTask task) => task.OnCompiled(hostProgram, (bool isNewProgramValid, ShaderCompileTask task) =>
{ {
@ -617,7 +636,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
shader.HostShader = _context.Renderer.CompileShader(ShaderStage.Compute, shader.Program.Code); shader.HostShader = _context.Renderer.CompileShader(ShaderStage.Compute, shader.Program.Code);
IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader }); IProgram hostProgram = _context.Renderer.CreateProgram(new IShader[] { shader.HostShader }, new ShaderInfo(-1));
cpShader = new ShaderBundle(hostProgram, shader); cpShader = new ShaderBundle(hostProgram, shader);
@ -755,7 +774,15 @@ namespace Ryujinx.Graphics.Gpu.Shader
hostShaders.Add(hostShader); hostShaders.Add(hostShader);
} }
IProgram hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray()); int fragmentIndex = (int)ShaderStage.Fragment - 1;
int fragmentOutputMap = -1;
if (shaders[fragmentIndex] != null)
{
fragmentOutputMap = shaders[fragmentIndex].Info.FragmentOutputMap;
}
IProgram hostProgram = _context.Renderer.CreateProgram(hostShaders.ToArray(), new ShaderInfo(fragmentOutputMap));
gpShaders = new ShaderBundle(hostProgram, shaders); gpShaders = new ShaderBundle(hostProgram, shaders);

View File

@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Gpu
/// <param name="userObj">User defined object passed to the release callback</param> /// <param name="userObj">User defined object passed to the release callback</param>
/// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
public void EnqueueFrameThreadSafe( public void EnqueueFrameThreadSafe(
long pid, ulong pid,
ulong address, ulong address,
int width, int width,
int height, int height,

View File

@ -118,7 +118,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
} }
// ZigZag LUTs from libavcodec. // ZigZag LUTs from libavcodec.
private static readonly byte[] ZigZagDirect = new byte[] private static ReadOnlySpan<byte> ZigZagDirect => new byte[]
{ {
0, 1, 8, 16, 9, 2, 3, 10, 0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5, 17, 24, 32, 25, 18, 11, 4, 5,
@ -130,7 +130,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
53, 60, 61, 54, 47, 55, 62, 63 53, 60, 61, 54, 47, 55, 62, 63
}; };
private static readonly byte[] ZigZagScan = new byte[] private static ReadOnlySpan<byte> ZigZagScan => new byte[]
{ {
0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4, 0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4,
1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4, 1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4,
@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
private static void WriteScalingList(ref H264BitStreamWriter writer, IArray<byte> list) private static void WriteScalingList(ref H264BitStreamWriter writer, IArray<byte> list)
{ {
byte[] scan = list.Length == 16 ? ZigZagScan : ZigZagDirect; ReadOnlySpan<byte> scan = list.Length == 16 ? ZigZagScan : ZigZagDirect;
int lastScale = 8; int lastScale = 8;

View File

@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
public ISurface CreateSurface(int width, int height) => new Surface(width, height); public ISurface CreateSurface(int width, int height) => new Surface(width, height);
private static readonly byte[] LiteralToFilter = new byte[] private static ReadOnlySpan<byte> LiteralToFilter => new byte[]
{ {
Constants.EightTapSmooth, Constants.EightTapSmooth,
Constants.EightTap, Constants.EightTap,

View File

@ -1,5 +1,6 @@
using Ryujinx.Graphics.Nvdec.Vp9.Common; using Ryujinx.Graphics.Nvdec.Vp9.Common;
using Ryujinx.Graphics.Nvdec.Vp9.Types; using Ryujinx.Graphics.Nvdec.Vp9.Types;
using System;
using static Ryujinx.Graphics.Nvdec.Vp9.Dsp.IntraPred; using static Ryujinx.Graphics.Nvdec.Vp9.Dsp.IntraPred;
namespace Ryujinx.Graphics.Nvdec.Vp9 namespace Ryujinx.Graphics.Nvdec.Vp9
@ -24,7 +25,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
private const int NeedAbove = 1 << 2; private const int NeedAbove = 1 << 2;
private const int NeedAboveRight = 1 << 3; private const int NeedAboveRight = 1 << 3;
private static readonly byte[] ExtendModes = new byte[] private static ReadOnlySpan<byte> ExtendModes => new byte[]
{ {
NeedAbove | NeedLeft, // DC NeedAbove | NeedLeft, // DC
NeedAbove, // V NeedAbove, // V

View File

@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9.Types
public short Row; public short Row;
public short Col; public short Col;
private static readonly byte[] LogInBase2 = new byte[] private static ReadOnlySpan<byte> LogInBase2 => new byte[]
{ {
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,

View File

@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.OpenGL
static FormatTable() static FormatTable()
{ {
int tableSize = Enum.GetNames(typeof(Format)).Length; int tableSize = Enum.GetNames<Format>().Length;
Table = new FormatInfo[tableSize]; Table = new FormatInfo[tableSize];
TableImage = new SizedInternalFormat[tableSize]; TableImage = new SizedInternalFormat[tableSize];

View File

@ -53,7 +53,9 @@ namespace Ryujinx.Graphics.OpenGL
private ClipOrigin _clipOrigin; private ClipOrigin _clipOrigin;
private ClipDepthMode _clipDepthMode; private ClipDepthMode _clipDepthMode;
private readonly uint[] _componentMasks; private uint _fragmentOutputMap;
private uint _componentMasks;
private uint _currentComponentMasks;
private uint _scissorEnables; private uint _scissorEnables;
@ -73,12 +75,8 @@ namespace Ryujinx.Graphics.OpenGL
_clipOrigin = ClipOrigin.LowerLeft; _clipOrigin = ClipOrigin.LowerLeft;
_clipDepthMode = ClipDepthMode.NegativeOneToOne; _clipDepthMode = ClipDepthMode.NegativeOneToOne;
_componentMasks = new uint[Constants.MaxRenderTargets]; _fragmentOutputMap = uint.MaxValue;
_componentMasks = uint.MaxValue;
for (int index = 0; index < Constants.MaxRenderTargets; index++)
{
_componentMasks[index] = 0xf;
}
var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f }; var defaultScale = new Vector4<float> { X = 1f, Y = 0f, Z = 0f, W = 0f };
new Span<Vector4<float>>(_renderScale).Fill(defaultScale); new Span<Vector4<float>>(_renderScale).Fill(defaultScale);
@ -1001,18 +999,30 @@ namespace Ryujinx.Graphics.OpenGL
public void SetProgram(IProgram program) public void SetProgram(IProgram program)
{ {
_program = (Program)program; Program prg = (Program)program;
if (_tfEnabled) if (_tfEnabled)
{ {
GL.EndTransformFeedback(); GL.EndTransformFeedback();
_program.Bind(); prg.Bind();
GL.BeginTransformFeedback(_tfTopology); GL.BeginTransformFeedback(_tfTopology);
} }
else else
{ {
_program.Bind(); prg.Bind();
} }
if (prg.HasFragmentShader && _fragmentOutputMap != (uint)prg.FragmentOutputMap)
{
_fragmentOutputMap = (uint)prg.FragmentOutputMap;
for (int index = 0; index < Constants.MaxRenderTargets; index++)
{
RestoreComponentMask(index, force: false);
}
}
_program = prg;
} }
public void SetRasterizerDiscard(bool discard) public void SetRasterizerDiscard(bool discard)
@ -1037,11 +1047,13 @@ namespace Ryujinx.Graphics.OpenGL
public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks) public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks)
{ {
_componentMasks = 0;
for (int index = 0; index < componentMasks.Length; index++) for (int index = 0; index < componentMasks.Length; index++)
{ {
_componentMasks[index] = componentMasks[index]; _componentMasks |= componentMasks[index] << (index * 4);
RestoreComponentMask(index); RestoreComponentMask(index, force: false);
} }
} }
@ -1436,18 +1448,34 @@ namespace Ryujinx.Graphics.OpenGL
} }
} }
public void RestoreComponentMask(int index) public void RestoreComponentMask(int index, bool force = true)
{ {
// If the bound render target is bgra, swap the red and blue masks. // If the bound render target is bgra, swap the red and blue masks.
uint redMask = _fpIsBgra[index].X == 0 ? 1u : 4u; uint redMask = _fpIsBgra[index].X == 0 ? 1u : 4u;
uint blueMask = _fpIsBgra[index].X == 0 ? 4u : 1u; uint blueMask = _fpIsBgra[index].X == 0 ? 4u : 1u;
int shift = index * 4;
uint componentMask = _componentMasks & _fragmentOutputMap;
uint checkMask = 0xfu << shift;
uint componentMaskAtIndex = componentMask & checkMask;
if (!force && componentMaskAtIndex == (_currentComponentMasks & checkMask))
{
return;
}
componentMask >>= shift;
componentMask &= 0xfu;
GL.ColorMask( GL.ColorMask(
index, index,
(_componentMasks[index] & redMask) != 0, (componentMask & redMask) != 0,
(_componentMasks[index] & 2u) != 0, (componentMask & 2u) != 0,
(_componentMasks[index] & blueMask) != 0, (componentMask & blueMask) != 0,
(_componentMasks[index] & 8u) != 0); (componentMask & 8u) != 0);
_currentComponentMasks &= ~checkMask;
_currentComponentMasks |= componentMaskAtIndex;
} }
public void RestoreScissor0Enable() public void RestoreScissor0Enable()

View File

@ -1,11 +1,8 @@
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader.CodeGen.Glsl;
using System; using System;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.Generic;
using System.Linq;
namespace Ryujinx.Graphics.OpenGL namespace Ryujinx.Graphics.OpenGL
{ {
@ -29,7 +26,10 @@ namespace Ryujinx.Graphics.OpenGL
private ProgramLinkStatus _status = ProgramLinkStatus.Incomplete; private ProgramLinkStatus _status = ProgramLinkStatus.Incomplete;
private IShader[] _shaders; private IShader[] _shaders;
public Program(IShader[] shaders) public bool HasFragmentShader;
public int FragmentOutputMap { get; }
public Program(IShader[] shaders, int fragmentOutputMap)
{ {
Handle = GL.CreateProgram(); Handle = GL.CreateProgram();
@ -37,17 +37,23 @@ namespace Ryujinx.Graphics.OpenGL
for (int index = 0; index < shaders.Length; index++) for (int index = 0; index < shaders.Length; index++)
{ {
int shaderHandle = ((Shader)shaders[index]).Handle; Shader shader = (Shader)shaders[index];
GL.AttachShader(Handle, shaderHandle); if (shader.IsFragment)
{
HasFragmentShader = true;
}
GL.AttachShader(Handle, shader.Handle);
} }
GL.LinkProgram(Handle); GL.LinkProgram(Handle);
_shaders = shaders; _shaders = shaders;
FragmentOutputMap = fragmentOutputMap;
} }
public Program(ReadOnlySpan<byte> code) public Program(ReadOnlySpan<byte> code, bool hasFragmentShader, int fragmentOutputMap)
{ {
BinaryFormat binaryFormat = (BinaryFormat)BinaryPrimitives.ReadInt32LittleEndian(code.Slice(code.Length - 4, 4)); BinaryFormat binaryFormat = (BinaryFormat)BinaryPrimitives.ReadInt32LittleEndian(code.Slice(code.Length - 4, 4));
@ -60,6 +66,9 @@ namespace Ryujinx.Graphics.OpenGL
GL.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4); GL.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4);
} }
} }
HasFragmentShader = hasFragmentShader;
FragmentOutputMap = fragmentOutputMap;
} }
public void Bind() public void Bind()

View File

@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public Counters() public Counters()
{ {
int count = Enum.GetNames(typeof(CounterType)).Length; int count = Enum.GetNames<CounterType>().Length;
_counterQueues = new CounterQueue[count]; _counterQueues = new CounterQueue[count];
} }

View File

@ -66,9 +66,9 @@ namespace Ryujinx.Graphics.OpenGL
return Buffer.Create(size); return Buffer.Create(size);
} }
public IProgram CreateProgram(IShader[] shaders) public IProgram CreateProgram(IShader[] shaders, ShaderInfo info)
{ {
return new Program(shaders); return new Program(shaders, info.FragmentOutputMap);
} }
public ISampler CreateSampler(SamplerCreateInfo info) public ISampler CreateSampler(SamplerCreateInfo info)
@ -202,9 +202,9 @@ namespace Ryujinx.Graphics.OpenGL
_sync.Dispose(); _sync.Dispose();
} }
public IProgram LoadProgramBinary(byte[] programBinary) public IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info)
{ {
return new Program(programBinary); return new Program(programBinary, hasFragmentShader, info.FragmentOutputMap);
} }
public void CreateSync(ulong id) public void CreateSync(ulong id)

View File

@ -7,6 +7,7 @@ namespace Ryujinx.Graphics.OpenGL
class Shader : IShader class Shader : IShader
{ {
public int Handle { get; private set; } public int Handle { get; private set; }
public bool IsFragment { get; }
public Shader(ShaderStage stage, string code) public Shader(ShaderStage stage, string code)
{ {
@ -22,6 +23,7 @@ namespace Ryujinx.Graphics.OpenGL
}; };
Handle = GL.CreateShader(type); Handle = GL.CreateShader(type);
IsFragment = stage == ShaderStage.Fragment;
GL.ShaderSource(Handle, code); GL.ShaderSource(Handle, code);
GL.CompileShader(Handle); GL.CompileShader(Handle);

View File

@ -490,7 +490,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
} }
else else
{ {
int usedAttributes = context.Config.UsedInputAttributes; int usedAttributes = context.Config.UsedInputAttributes | context.Config.PassthroughAttributes;
while (usedAttributes != 0) while (usedAttributes != 0)
{ {
int index = BitOperations.TrailingZeroCount(usedAttributes); int index = BitOperations.TrailingZeroCount(usedAttributes);

View File

@ -5,32 +5,35 @@ namespace Ryujinx.Graphics.Shader
{ {
public class ShaderProgramInfo public class ShaderProgramInfo
{ {
public ReadOnlyCollection<BufferDescriptor> CBuffers { get; } public ReadOnlyCollection<BufferDescriptor> CBuffers { get; }
public ReadOnlyCollection<BufferDescriptor> SBuffers { get; } public ReadOnlyCollection<BufferDescriptor> SBuffers { get; }
public ReadOnlyCollection<TextureDescriptor> Textures { get; } public ReadOnlyCollection<TextureDescriptor> Textures { get; }
public ReadOnlyCollection<TextureDescriptor> Images { get; } public ReadOnlyCollection<TextureDescriptor> Images { get; }
public bool UsesInstanceId { get; } public bool UsesInstanceId { get; }
public bool UsesRtLayer { get; } public bool UsesRtLayer { get; }
public byte ClipDistancesWritten { get; } public byte ClipDistancesWritten { get; }
public int FragmentOutputMap { get; }
public ShaderProgramInfo( public ShaderProgramInfo(
BufferDescriptor[] cBuffers, BufferDescriptor[] cBuffers,
BufferDescriptor[] sBuffers, BufferDescriptor[] sBuffers,
TextureDescriptor[] textures, TextureDescriptor[] textures,
TextureDescriptor[] images, TextureDescriptor[] images,
bool usesInstanceId, bool usesInstanceId,
bool usesRtLayer, bool usesRtLayer,
byte clipDistancesWritten) byte clipDistancesWritten,
int fragmentOutputMap)
{ {
CBuffers = Array.AsReadOnly(cBuffers); CBuffers = Array.AsReadOnly(cBuffers);
SBuffers = Array.AsReadOnly(sBuffers); SBuffers = Array.AsReadOnly(sBuffers);
Textures = Array.AsReadOnly(textures); Textures = Array.AsReadOnly(textures);
Images = Array.AsReadOnly(images); Images = Array.AsReadOnly(images);
UsesInstanceId = usesInstanceId; UsesInstanceId = usesInstanceId;
UsesRtLayer = usesRtLayer; UsesRtLayer = usesRtLayer;
ClipDistancesWritten = clipDistancesWritten; ClipDistancesWritten = clipDistancesWritten;
FragmentOutputMap = fragmentOutputMap;
} }
} }
} }

View File

@ -172,11 +172,10 @@ namespace Ryujinx.Graphics.Shader.Translation
for (int rtIndex = 0; rtIndex < 8; rtIndex++) for (int rtIndex = 0; rtIndex < 8; rtIndex++)
{ {
OmapTarget target = Config.OmapTargets[rtIndex];
for (int component = 0; component < 4; component++) for (int component = 0; component < 4; component++)
{ {
if (!target.ComponentEnabled(component)) bool componentEnabled = (Config.OmapTargets & (1 << (rtIndex * 4 + component))) != 0;
if (!componentEnabled)
{ {
continue; continue;
} }
@ -210,7 +209,8 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
} }
if (target.Enabled) bool targetEnabled = (Config.OmapTargets & (0xf << (rtIndex * 4))) != 0;
if (targetEnabled)
{ {
Config.SetOutputUserAttribute(rtIndex, perPatch: false); Config.SetOutputUserAttribute(rtIndex, perPatch: false);
regIndexBase += 4; regIndexBase += 4;

View File

@ -25,9 +25,9 @@ namespace Ryujinx.Graphics.Shader.Translation
public ImapPixelType[] ImapTypes { get; } public ImapPixelType[] ImapTypes { get; }
public OmapTarget[] OmapTargets { get; } public int OmapTargets { get; }
public bool OmapSampleMask { get; } public bool OmapSampleMask { get; }
public bool OmapDepth { get; } public bool OmapDepth { get; }
public IGpuAccessor GpuAccessor { get; } public IGpuAccessor GpuAccessor { get; }
@ -135,21 +135,8 @@ namespace Ryujinx.Graphics.Shader.Translation
public int GetDepthRegister() public int GetDepthRegister()
{ {
int count = 0;
for (int index = 0; index < OmapTargets.Length; index++)
{
for (int component = 0; component < 4; component++)
{
if (OmapTargets[index].ComponentEnabled(component))
{
count++;
}
}
}
// The depth register is always two registers after the last color output. // The depth register is always two registers after the last color output.
return count + 1; return BitOperations.PopCount((uint)OmapTargets) + 1;
} }
public TextureFormat GetTextureFormat(int handle, int cbufSlot = -1) public TextureFormat GetTextureFormat(int handle, int cbufSlot = -1)

View File

@ -36,37 +36,6 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
} }
struct OmapTarget
{
public bool Red { get; }
public bool Green { get; }
public bool Blue { get; }
public bool Alpha { get; }
public bool Enabled => Red || Green || Blue || Alpha;
public OmapTarget(bool red, bool green, bool blue, bool alpha)
{
Red = red;
Green = green;
Blue = blue;
Alpha = alpha;
}
public bool ComponentEnabled(int component)
{
switch (component)
{
case 0: return Red;
case 1: return Green;
case 2: return Blue;
case 3: return Alpha;
}
throw new ArgumentOutOfRangeException(nameof(component));
}
}
class ShaderHeader class ShaderHeader
{ {
public int SphType { get; } public int SphType { get; }
@ -85,7 +54,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public bool GpPassthrough { get; } public bool GpPassthrough { get; }
public bool DoesLoadOrStore { get; } public bool DoesLoadOrStore { get; }
public bool DoesFp64 { get; } public bool DoesFp64 { get; }
public int StreamOutMask { get; } public int StreamOutMask { get; }
@ -104,13 +73,13 @@ namespace Ryujinx.Graphics.Shader.Translation
public int MaxOutputVertexCount { get; } public int MaxOutputVertexCount { get; }
public int StoreReqStart { get; } public int StoreReqStart { get; }
public int StoreReqEnd { get; } public int StoreReqEnd { get; }
public ImapPixelType[] ImapTypes { get; } public ImapPixelType[] ImapTypes { get; }
public OmapTarget[] OmapTargets { get; } public int OmapTargets { get; }
public bool OmapSampleMask { get; } public bool OmapSampleMask { get; }
public bool OmapDepth { get; } public bool OmapDepth { get; }
public ShaderHeader(IGpuAccessor gpuAccessor, ulong address) public ShaderHeader(IGpuAccessor gpuAccessor, ulong address)
{ {
@ -144,7 +113,7 @@ namespace Ryujinx.Graphics.Shader.Translation
GpPassthrough = commonWord0.Extract(24); GpPassthrough = commonWord0.Extract(24);
DoesLoadOrStore = commonWord0.Extract(26); DoesLoadOrStore = commonWord0.Extract(26);
DoesFp64 = commonWord0.Extract(27); DoesFp64 = commonWord0.Extract(27);
StreamOutMask = commonWord0.Extract(28, 4); StreamOutMask = commonWord0.Extract(28, 4);
@ -163,7 +132,7 @@ namespace Ryujinx.Graphics.Shader.Translation
MaxOutputVertexCount = commonWord4.Extract(0, 12); MaxOutputVertexCount = commonWord4.Extract(0, 12);
StoreReqStart = commonWord4.Extract(12, 8); StoreReqStart = commonWord4.Extract(12, 8);
StoreReqEnd = commonWord4.Extract(24, 8); StoreReqEnd = commonWord4.Extract(24, 8);
ImapTypes = new ImapPixelType[32]; ImapTypes = new ImapPixelType[32];
@ -179,21 +148,11 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
int type2OmapTarget = header[18]; int type2OmapTarget = header[18];
int type2Omap = header[19]; int type2Omap = header[19];
OmapTargets = new OmapTarget[8];
for (int offset = 0; offset < OmapTargets.Length * 4; offset += 4)
{
OmapTargets[offset >> 2] = new OmapTarget(
type2OmapTarget.Extract(offset + 0),
type2OmapTarget.Extract(offset + 1),
type2OmapTarget.Extract(offset + 2),
type2OmapTarget.Extract(offset + 3));
}
OmapTargets = type2OmapTarget;
OmapSampleMask = type2Omap.Extract(0); OmapSampleMask = type2Omap.Extract(0);
OmapDepth = type2Omap.Extract(1); OmapDepth = type2Omap.Extract(1);
} }
} }
} }

View File

@ -105,7 +105,8 @@ namespace Ryujinx.Graphics.Shader.Translation
config.GetImageDescriptors(), config.GetImageDescriptors(),
config.UsedFeatures.HasFlag(FeatureFlags.InstanceId), config.UsedFeatures.HasFlag(FeatureFlags.InstanceId),
config.UsedFeatures.HasFlag(FeatureFlags.RtLayer), config.UsedFeatures.HasFlag(FeatureFlags.RtLayer),
config.ClipDistancesWritten); config.ClipDistancesWritten,
config.OmapTargets);
return program; return program;
} }

View File

@ -102,7 +102,7 @@ namespace Ryujinx.HLE.FileSystem.Content
_contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>(); _contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>();
_locationEntries = new Dictionary<StorageId, LinkedList<LocationEntry>>(); _locationEntries = new Dictionary<StorageId, LinkedList<LocationEntry>>();
foreach (StorageId storageId in Enum.GetValues(typeof(StorageId))) foreach (StorageId storageId in Enum.GetValues<StorageId>())
{ {
string contentDirectory = null; string contentDirectory = null;
string contentPathString = null; string contentPathString = null;

View File

@ -505,7 +505,9 @@ namespace Ryujinx.HLE.FileSystem
bool canFixBySaveDataId = extraData.Attribute.StaticSaveDataId == 0 && info.StaticSaveDataId != 0; bool canFixBySaveDataId = extraData.Attribute.StaticSaveDataId == 0 && info.StaticSaveDataId != 0;
if (!canFixByProgramId && !canFixBySaveDataId) bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != LibHac.Fs.SaveDataType.System;
if (!canFixByProgramId && !canFixBySaveDataId && !hasEmptyOwnerId)
{ {
wasFixNeeded = false; wasFixNeeded = false;
return Result.Success; return Result.Success;

View File

@ -776,6 +776,7 @@ namespace Ryujinx.HLE.HOS
// The set sizes don't actually matter as long as they're non-zero because we use directory savedata. // The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
control.UserAccountSaveDataSize = 0x4000; control.UserAccountSaveDataSize = 0x4000;
control.UserAccountSaveDataJournalSize = 0x4000; control.UserAccountSaveDataJournalSize = 0x4000;
control.SaveDataOwnerId = applicationId;
Logger.Warning?.Print(LogClass.Application, Logger.Warning?.Print(LogClass.Application,
"No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games."); "No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");

View File

@ -9,14 +9,14 @@ namespace Ryujinx.HLE.HOS
{ {
class ArmProcessContext<T> : IProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager class ArmProcessContext<T> : IProcessContext where T : class, IVirtualMemoryManagerTracked, IMemoryManager
{ {
private readonly long _pid; private readonly ulong _pid;
private readonly GpuContext _gpuContext; private readonly GpuContext _gpuContext;
private readonly CpuContext _cpuContext; private readonly CpuContext _cpuContext;
private T _memoryManager; private T _memoryManager;
public IVirtualMemoryManager AddressSpace => _memoryManager; public IVirtualMemoryManager AddressSpace => _memoryManager;
public ArmProcessContext(long pid, GpuContext gpuContext, T memoryManager, bool for64Bit) public ArmProcessContext(ulong pid, GpuContext gpuContext, T memoryManager, bool for64Bit)
{ {
if (memoryManager is IRefCounted rc) if (memoryManager is IRefCounted rc)
{ {

View File

@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS
_gpu = gpu; _gpu = gpu;
} }
public IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit) public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
{ {
MemoryManagerMode mode = context.Device.Configuration.MemoryManagerMode; MemoryManagerMode mode = context.Device.Configuration.MemoryManagerMode;

View File

@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Ipc
{ {
public bool HasPId { get; private set; } public bool HasPId { get; private set; }
public long PId { get; private set; } public ulong PId { get; private set; }
public int[] ToCopy { get; private set; } public int[] ToCopy { get; private set; }
public int[] ToMove { get; private set; } public int[] ToMove { get; private set; }
@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Ipc
ToCopy = new int[(word >> 1) & 0xf]; ToCopy = new int[(word >> 1) & 0xf];
ToMove = new int[(word >> 5) & 0xf]; ToMove = new int[(word >> 5) & 0xf];
PId = HasPId ? reader.ReadInt64() : 0; PId = HasPId ? reader.ReadUInt64() : 0;
for (int index = 0; index < ToCopy.Length; index++) for (int index = 0; index < ToCopy.Length; index++)
{ {
@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Ipc
ToMove = move ?? throw new ArgumentNullException(nameof(move)); ToMove = move ?? throw new ArgumentNullException(nameof(move));
} }
public IpcHandleDesc(int[] copy, int[] move, long pId) : this(copy, move) public IpcHandleDesc(int[] copy, int[] move, ulong pId) : this(copy, move)
{ {
PId = pId; PId = pId;

View File

@ -1,54 +1,50 @@
using Ryujinx.Cpu; using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Process; using Ryujinx.HLE.HOS.Kernel.Process;
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Kernel.Common namespace Ryujinx.HLE.HOS.Kernel.Common
{ {
static class KernelTransfer static class KernelTransfer
{ {
public static bool UserToKernelInt32(KernelContext context, ulong address, out int value) public static bool UserToKernel<T>(out T value, ulong address) where T : unmanaged
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) && if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
currentProcess.CpuMemory.IsMapped(address + 3))
{ {
value = currentProcess.CpuMemory.Read<int>(address); value = currentProcess.CpuMemory.Read<T>(address);
return true; return true;
} }
value = 0; value = default;
return false; return false;
} }
public static bool UserToKernelInt32Array(KernelContext context, ulong address, Span<int> values) public static bool UserToKernelArray<T>(ulong address, Span<T> values) where T : unmanaged
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
for (int index = 0; index < values.Length; index++, address += 4) Span<byte> data = MemoryMarshal.Cast<T, byte>(values);
if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)data.Length))
{ {
if (currentProcess.CpuMemory.IsMapped(address) && currentProcess.CpuMemory.Read(address, data);
currentProcess.CpuMemory.IsMapped(address + 3))
{ return true;
values[index]= currentProcess.CpuMemory.Read<int>(address);
}
else
{
return false;
}
} }
return true; return false;
} }
public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value) public static bool UserToKernelString(out string value, ulong address, uint size)
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) && if (currentProcess.CpuMemory.IsRangeMapped(address, size))
currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
{ {
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size); value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size);
@ -60,27 +56,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
return false; return false;
} }
public static bool KernelToUserInt32(KernelContext context, ulong address, int value) public static bool KernelToUser<T>(ulong address, T value) where T: unmanaged
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) && if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
currentProcess.CpuMemory.IsMapped(address + 3))
{
currentProcess.CpuMemory.Write(address, value);
return true;
}
return false;
}
public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 7))
{ {
currentProcess.CpuMemory.Write(address, value); currentProcess.CpuMemory.Write(address, value);

View File

@ -42,14 +42,14 @@ namespace Ryujinx.HLE.HOS.Kernel
public KSynchronization Synchronization { get; } public KSynchronization Synchronization { get; }
public KContextIdManager ContextIdManager { get; } public KContextIdManager ContextIdManager { get; }
public ConcurrentDictionary<long, KProcess> Processes { get; } public ConcurrentDictionary<ulong, KProcess> Processes { get; }
public ConcurrentDictionary<string, KAutoObject> AutoObjectNames { get; } public ConcurrentDictionary<string, KAutoObject> AutoObjectNames { get; }
public bool ThreadReselectionRequested { get; set; } public bool ThreadReselectionRequested { get; set; }
private long _kipId; private ulong _kipId;
private long _processId; private ulong _processId;
private long _threadUid; private ulong _threadUid;
public KernelContext( public KernelContext(
Switch device, Switch device,
@ -98,7 +98,7 @@ namespace Ryujinx.HLE.HOS.Kernel
KernelInitialized = true; KernelInitialized = true;
Processes = new ConcurrentDictionary<long, KProcess>(); Processes = new ConcurrentDictionary<ulong, KProcess>();
AutoObjectNames = new ConcurrentDictionary<string, KAutoObject>(); AutoObjectNames = new ConcurrentDictionary<string, KAutoObject>();
_kipId = KernelConstants.InitialKipId; _kipId = KernelConstants.InitialKipId;
@ -115,17 +115,17 @@ namespace Ryujinx.HLE.HOS.Kernel
new Thread(PreemptionThreadStart) { Name = "HLE.PreemptionThread" }.Start(); new Thread(PreemptionThreadStart) { Name = "HLE.PreemptionThread" }.Start();
} }
public long NewThreadUid() public ulong NewThreadUid()
{ {
return Interlocked.Increment(ref _threadUid) - 1; return Interlocked.Increment(ref _threadUid) - 1;
} }
public long NewKipId() public ulong NewKipId()
{ {
return Interlocked.Increment(ref _kipId) - 1; return Interlocked.Increment(ref _kipId) - 1;
} }
public long NewProcessId() public ulong NewProcessId()
{ {
return Interlocked.Increment(ref _processId) - 1; return Interlocked.Increment(ref _processId) - 1;
} }

View File

@ -2682,7 +2682,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return Context.MemoryManager.MemoryRegions[(int)_memRegion]; return Context.MemoryManager.MemoryRegions[(int)_memRegion];
} }
public long GetMmUsedPages() public ulong GetMmUsedPages()
{ {
lock (_blockManager) lock (_blockManager)
{ {
@ -2690,9 +2690,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
} }
} }
private long GetMmUsedSize() private ulong GetMmUsedSize()
{ {
return _blockManager.BlocksCount * KMemoryBlockSize; return (ulong)(_blockManager.BlocksCount * KMemoryBlockSize);
} }
public bool IsInvalidRegion(ulong address, ulong size) public bool IsInvalidRegion(ulong address, ulong size)

View File

@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{ {
private readonly SharedMemoryStorage _storage; private readonly SharedMemoryStorage _storage;
private readonly long _ownerPid; private readonly ulong _ownerPid;
private readonly KMemoryPermission _ownerPermission; private readonly KMemoryPermission _ownerPermission;
private readonly KMemoryPermission _userPermission; private readonly KMemoryPermission _userPermission;
@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public KSharedMemory( public KSharedMemory(
KernelContext context, KernelContext context,
SharedMemoryStorage storage, SharedMemoryStorage storage,
long ownerPid, ulong ownerPid,
KMemoryPermission ownerPermission, KMemoryPermission ownerPermission,
KMemoryPermission userPermission) : base(context) KMemoryPermission userPermission) : base(context)
{ {

View File

@ -5,8 +5,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
[Flags] [Flags]
enum KMemoryPermission : uint enum KMemoryPermission : uint
{ {
None = 0, None = 0,
Mask = uint.MaxValue, UserMask = Read | Write | Execute,
Mask = uint.MaxValue,
Read = 1 << 0, Read = 1 << 0,
Write = 1 << 1, Write = 1 << 1,

View File

@ -26,6 +26,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
KernelStack = 0x00002013, KernelStack = 0x00002013,
CodeReadOnly = 0x00402214, CodeReadOnly = 0x00402214,
CodeWritable = 0x00402015, CodeWritable = 0x00402015,
UserMask = 0xff,
Mask = 0xffffffff, Mask = 0xffffffff,
PermissionChangeAllowed = 1 << 8, PermissionChangeAllowed = 1 << 8,

View File

@ -4,6 +4,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{ {
interface IProcessContextFactory interface IProcessContextFactory
{ {
IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit); IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit);
} }
} }

View File

@ -45,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public KAddressArbiter AddressArbiter { get; private set; } public KAddressArbiter AddressArbiter { get; private set; }
public long[] RandomEntropy { get; private set; } public ulong[] RandomEntropy { get; private set; }
public KThread[] PinnedThreads { get; private set; } public KThread[] PinnedThreads { get; private set; }
private bool _signaled; private bool _signaled;
@ -62,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public ulong TitleId { get; private set; } public ulong TitleId { get; private set; }
public bool IsApplication { get; private set; } public bool IsApplication { get; private set; }
public long Pid { get; private set; } public ulong Pid { get; private set; }
private long _creationTimestamp; private long _creationTimestamp;
private ulong _entrypoint; private ulong _entrypoint;
@ -102,7 +102,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Capabilities = new KProcessCapabilities(); Capabilities = new KProcessCapabilities();
RandomEntropy = new long[KScheduler.CpuCoresCount]; RandomEntropy = new ulong[KScheduler.CpuCoresCount];
PinnedThreads = new KThread[KScheduler.CpuCoresCount]; PinnedThreads = new KThread[KScheduler.CpuCoresCount];
// TODO: Remove once we no longer need to initialize it externally. // TODO: Remove once we no longer need to initialize it externally.
@ -131,7 +131,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Pid = KernelContext.NewKipId(); Pid = KernelContext.NewKipId();
if (Pid == 0 || (ulong)Pid >= KernelConstants.InitialProcessId) if (Pid == 0 || Pid >= KernelConstants.InitialProcessId)
{ {
throw new InvalidOperationException($"Invalid KIP Id {Pid}."); throw new InvalidOperationException($"Invalid KIP Id {Pid}.");
} }
@ -239,7 +239,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Pid = KernelContext.NewProcessId(); Pid = KernelContext.NewProcessId();
if (Pid == -1 || (ulong)Pid < KernelConstants.InitialProcessId) if (Pid == ulong.MaxValue || Pid < KernelConstants.InitialProcessId)
{ {
throw new InvalidOperationException($"Invalid Process Id {Pid}."); throw new InvalidOperationException($"Invalid Process Id {Pid}.");
} }
@ -868,12 +868,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public bool IsCpuCoreAllowed(int core) public bool IsCpuCoreAllowed(int core)
{ {
return (Capabilities.AllowedCpuCoresMask & (1L << core)) != 0; return (Capabilities.AllowedCpuCoresMask & (1UL << core)) != 0;
} }
public bool IsPriorityAllowed(int priority) public bool IsPriorityAllowed(int priority)
{ {
return (Capabilities.AllowedThreadPriosMask & (1L << priority)) != 0; return (Capabilities.AllowedThreadPriosMask & (1UL << priority)) != 0;
} }
public override bool IsSignaled() public override bool IsSignaled()

View File

@ -11,8 +11,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public byte[] SvcAccessMask { get; private set; } public byte[] SvcAccessMask { get; private set; }
public byte[] IrqAccessMask { get; private set; } public byte[] IrqAccessMask { get; private set; }
public long AllowedCpuCoresMask { get; private set; } public ulong AllowedCpuCoresMask { get; private set; }
public long AllowedThreadPriosMask { get; private set; } public ulong AllowedThreadPriosMask { get; private set; }
public int DebuggingFlags { get; private set; } public int DebuggingFlags { get; private set; }
public int HandleTableSize { get; private set; } public int HandleTableSize { get; private set; }
@ -28,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public KernelResult InitializeForKernel(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager) public KernelResult InitializeForKernel(ReadOnlySpan<int> capabilities, KPageTableBase memoryManager)
{ {
AllowedCpuCoresMask = 0xf; AllowedCpuCoresMask = 0xf;
AllowedThreadPriosMask = -1; AllowedThreadPriosMask = ulong.MaxValue;
DebuggingFlags &= ~3; DebuggingFlags &= ~3;
KernelReleaseVersion = KProcess.KernelVersionPacked; KernelReleaseVersion = KProcess.KernelVersionPacked;
@ -303,16 +303,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return KernelResult.Success; return KernelResult.Success;
} }
private static long GetMaskFromMinMax(int min, int max) private static ulong GetMaskFromMinMax(int min, int max)
{ {
int range = max - min + 1; int range = max - min + 1;
if (range == 64) if (range == 64)
{ {
return -1L; return ulong.MaxValue;
} }
long mask = (1L << range) - 1; ulong mask = (1UL << range) - 1;
return mask << min; return mask << min;
} }

View File

@ -4,7 +4,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{ {
class ProcessContextFactory : IProcessContextFactory class ProcessContextFactory : IProcessContextFactory
{ {
public IProcessContext Create(KernelContext context, long pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit) public IProcessContext Create(KernelContext context, ulong pid, ulong addressSpaceSize, InvalidAccessHandler invalidAccessHandler, bool for64Bit)
{ {
return new ProcessContext(new AddressSpaceManager(addressSpaceSize)); return new ProcessContext(new AddressSpaceManager(addressSpaceSize));
} }

View File

@ -2,7 +2,7 @@ using System;
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
public class InvalidSvcException : Exception class InvalidSvcException : Exception
{ {
public InvalidSvcException(string message) : base(message) { } public InvalidSvcException(string message) : base(message) { }
} }

View File

@ -0,0 +1,37 @@
using Ryujinx.HLE.HOS.Kernel.Memory;
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{
struct MemoryInfo
{
public ulong Address;
public ulong Size;
public MemoryState State;
public MemoryAttribute Attribute;
public KMemoryPermission Permission;
public int IpcRefCount;
public int DeviceRefCount;
#pragma warning disable CS0414
private int _padding;
#pragma warning restore CS0414
public MemoryInfo(
ulong address,
ulong size,
MemoryState state,
MemoryAttribute attribute,
KMemoryPermission permission,
int ipcRefCount,
int deviceRefCount)
{
Address = address;
Size = size;
State = state;
Attribute = attribute;
Permission = permission;
IpcRefCount = ipcRefCount;
DeviceRefCount = deviceRefCount;
_padding = 0;
}
}
}

View File

@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
// Process // Process
public KernelResult GetProcessId(int handle, out long pid) public KernelResult GetProcessId(out ulong pid, int handle)
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
@ -50,9 +50,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult CreateProcess( public KernelResult CreateProcess(
out int handle,
ProcessCreationInfo info, ProcessCreationInfo info,
ReadOnlySpan<int> capabilities, ReadOnlySpan<int> capabilities,
out int handle,
IProcessContextFactory contextFactory, IProcessContextFactory contextFactory,
ThreadStart customThreadStart = null) ThreadStart customThreadStart = null)
{ {
@ -170,19 +170,19 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
// IPC // IPC
public KernelResult ConnectToNamedPort(ulong namePtr, out int handle) public KernelResult ConnectToNamedPort(out int handle, ulong namePtr)
{ {
handle = 0; handle = 0;
if (!KernelTransfer.UserToKernelString(_context, namePtr, 12, out string name)) if (!KernelTransfer.UserToKernelString(out string name, namePtr, 12))
{ {
return KernelResult.UserCopyFailed; return KernelResult.UserCopyFailed;
} }
return ConnectToNamedPort(name, out handle); return ConnectToNamedPort(out handle, name);
} }
public KernelResult ConnectToNamedPort(string name, out int handle) public KernelResult ConnectToNamedPort(out int handle, string name)
{ {
handle = 0; handle = 0;
@ -193,7 +193,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
KAutoObject autoObj = KAutoObject.FindNamedObject(_context, name); KAutoObject autoObj = KAutoObject.FindNamedObject(_context, name);
if (!(autoObj is KClientPort clientPort)) if (autoObj is not KClientPort clientPort)
{ {
return KernelResult.NotFound; return KernelResult.NotFound;
} }
@ -284,7 +284,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return result; return result;
} }
public KernelResult SendAsyncRequestWithUserBuffer(ulong messagePtr, ulong messageSize, int handle, out int doneEventHandle) public KernelResult SendAsyncRequestWithUserBuffer(out int doneEventHandle, ulong messagePtr, ulong messageSize, int handle)
{ {
doneEventHandle = 0; doneEventHandle = 0;
@ -355,10 +355,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult CreateSession( public KernelResult CreateSession(
bool isLight,
ulong namePtr,
out int serverSessionHandle, out int serverSessionHandle,
out int clientSessionHandle) out int clientSessionHandle,
bool isLight,
ulong namePtr)
{ {
serverSessionHandle = 0; serverSessionHandle = 0;
clientSessionHandle = 0; clientSessionHandle = 0;
@ -420,7 +420,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return result; return result;
} }
public KernelResult AcceptSession(int portHandle, out int sessionHandle) public KernelResult AcceptSession(out int sessionHandle, int portHandle)
{ {
sessionHandle = 0; sessionHandle = 0;
@ -472,11 +472,11 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult ReplyAndReceive( public KernelResult ReplyAndReceive(
out int handleIndex,
ulong handlesPtr, ulong handlesPtr,
int handlesCount, int handlesCount,
int replyTargetHandle, int replyTargetHandle,
long timeout, long timeout)
out int handleIndex)
{ {
handleIndex = 0; handleIndex = 0;
@ -501,7 +501,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
int[] handles = new int[handlesCount]; int[] handles = new int[handlesCount];
if (!KernelTransfer.UserToKernelInt32Array(_context, handlesPtr, handles)) if (!KernelTransfer.UserToKernelArray<int>(handlesPtr, handles))
{ {
return KernelResult.UserCopyFailed; return KernelResult.UserCopyFailed;
} }
@ -511,10 +511,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
timeout += KTimeManager.DefaultTimeIncrementNanoseconds; timeout += KTimeManager.DefaultTimeIncrementNanoseconds;
} }
return ReplyAndReceive(handles, replyTargetHandle, timeout, out handleIndex); return ReplyAndReceive(out handleIndex, handles, replyTargetHandle, timeout);
} }
public KernelResult ReplyAndReceive(ReadOnlySpan<int> handles, int replyTargetHandle, long timeout, out int handleIndex) public KernelResult ReplyAndReceive(out int handleIndex, ReadOnlySpan<int> handles, int replyTargetHandle, long timeout)
{ {
handleIndex = 0; handleIndex = 0;
@ -577,13 +577,13 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult ReplyAndReceiveWithUserBuffer( public KernelResult ReplyAndReceiveWithUserBuffer(
out int handleIndex,
ulong handlesPtr, ulong handlesPtr,
ulong messagePtr, ulong messagePtr,
ulong messageSize, ulong messageSize,
int handlesCount, int handlesCount,
int replyTargetHandle, int replyTargetHandle,
long timeout, long timeout)
out int handleIndex)
{ {
handleIndex = 0; handleIndex = 0;
@ -615,7 +615,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
int[] handles = new int[handlesCount]; int[] handles = new int[handlesCount];
if (!KernelTransfer.UserToKernelInt32Array(_context, handlesPtr, handles)) if (!KernelTransfer.UserToKernelArray<int>(handlesPtr, handles))
{ {
currentProcess.MemoryManager.UnborrowIpcBuffer(messagePtr, messageSize); currentProcess.MemoryManager.UnborrowIpcBuffer(messagePtr, messageSize);
@ -681,11 +681,11 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult CreatePort( public KernelResult CreatePort(
out int serverPortHandle,
out int clientPortHandle,
int maxSessions, int maxSessions,
bool isLight, bool isLight,
ulong namePtr, ulong namePtr)
out int serverPortHandle,
out int clientPortHandle)
{ {
serverPortHandle = clientPortHandle = 0; serverPortHandle = clientPortHandle = 0;
@ -715,11 +715,11 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return result; return result;
} }
public KernelResult ManageNamedPort(ulong namePtr, int maxSessions, out int handle) public KernelResult ManageNamedPort(out int handle, ulong namePtr, int maxSessions)
{ {
handle = 0; handle = 0;
if (!KernelTransfer.UserToKernelString(_context, namePtr, 12, out string name)) if (!KernelTransfer.UserToKernelString(out string name, namePtr, 12))
{ {
return KernelResult.UserCopyFailed; return KernelResult.UserCopyFailed;
} }
@ -729,10 +729,10 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.MaximumExceeded; return KernelResult.MaximumExceeded;
} }
return ManageNamedPort(name, maxSessions, out handle); return ManageNamedPort(out handle, name, maxSessions);
} }
public KernelResult ManageNamedPort(string name, int maxSessions, out int handle) public KernelResult ManageNamedPort(out int handle, string name, int maxSessions)
{ {
handle = 0; handle = 0;
@ -767,7 +767,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return result; return result;
} }
public KernelResult ConnectToPort(int clientPortHandle, out int clientSessionHandle) public KernelResult ConnectToPort(out int clientSessionHandle, int clientPortHandle)
{ {
clientSessionHandle = 0; clientSessionHandle = 0;
@ -820,18 +820,18 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
// Memory // Memory
public KernelResult SetHeapSize(ulong size, out ulong position) public KernelResult SetHeapSize(out ulong address, ulong size)
{ {
if ((size & 0xfffffffe001fffff) != 0) if ((size & 0xfffffffe001fffff) != 0)
{ {
position = 0; address = 0;
return KernelResult.InvalidSize; return KernelResult.InvalidSize;
} }
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
return process.MemoryManager.SetHeapSize(size, out position); return process.MemoryManager.SetHeapSize(size, out address);
} }
public KernelResult SetMemoryPermission(ulong address, ulong size, KMemoryPermission permission) public KernelResult SetMemoryPermission(ulong address, ulong size, KMemoryPermission permission)
@ -867,12 +867,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
public KernelResult SetMemoryAttribute( public KernelResult SetMemoryAttribute(
ulong position, ulong address,
ulong size, ulong size,
MemoryAttribute attributeMask, MemoryAttribute attributeMask,
MemoryAttribute attributeValue) MemoryAttribute attributeValue)
{ {
if (!PageAligned(position)) if (!PageAligned(address))
{ {
return KernelResult.InvalidAddress; return KernelResult.InvalidAddress;
} }
@ -892,13 +892,13 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
if (!process.MemoryManager.InsideAddrSpace(position, size)) if (!process.MemoryManager.InsideAddrSpace(address, size))
{ {
return KernelResult.InvalidMemState; return KernelResult.InvalidMemState;
} }
KernelResult result = process.MemoryManager.SetMemoryAttribute( KernelResult result = process.MemoryManager.SetMemoryAttribute(
position, address,
size, size,
attributeMask, attributeMask,
attributeValue); attributeValue);
@ -978,20 +978,34 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return process.MemoryManager.Unmap(dst, src, size); return process.MemoryManager.Unmap(dst, src, size);
} }
public KernelResult QueryMemory(ulong infoPtr, ulong position, out ulong pageInfo) public KernelResult QueryMemory(ulong infoPtr, out ulong pageInfo, ulong address)
{
KernelResult result = QueryMemory(out MemoryInfo info, out pageInfo, address);
if (result == KernelResult.Success)
{
return KernelTransfer.KernelToUser(infoPtr, info)
? KernelResult.Success
: KernelResult.InvalidMemState;
}
return result;
}
public KernelResult QueryMemory(out MemoryInfo info, out ulong pageInfo, ulong address)
{ {
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
KMemoryInfo blkInfo = process.MemoryManager.QueryMemory(position); KMemoryInfo blockInfo = process.MemoryManager.QueryMemory(address);
process.CpuMemory.Write(infoPtr + 0x00, blkInfo.Address); info = new MemoryInfo(
process.CpuMemory.Write(infoPtr + 0x08, blkInfo.Size); blockInfo.Address,
process.CpuMemory.Write(infoPtr + 0x10, (int)blkInfo.State & 0xff); blockInfo.Size,
process.CpuMemory.Write(infoPtr + 0x14, (int)blkInfo.Attribute); blockInfo.State & MemoryState.UserMask,
process.CpuMemory.Write(infoPtr + 0x18, (int)blkInfo.Permission); blockInfo.Attribute,
process.CpuMemory.Write(infoPtr + 0x1c, blkInfo.IpcRefCount); blockInfo.Permission & KMemoryPermission.UserMask,
process.CpuMemory.Write(infoPtr + 0x20, blkInfo.DeviceRefCount); blockInfo.IpcRefCount,
process.CpuMemory.Write(infoPtr + 0x24, 0); blockInfo.DeviceRefCount);
pageInfo = 0; pageInfo = 0;
@ -1084,7 +1098,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
currentProcess); currentProcess);
} }
public KernelResult CreateTransferMemory(ulong address, ulong size, KMemoryPermission permission, out int handle) public KernelResult CreateTransferMemory(out int handle, ulong address, ulong size, KMemoryPermission permission)
{ {
handle = 0; handle = 0;
@ -1414,9 +1428,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return targetProcess.MemoryManager.SetProcessMemoryPermission(src, size, permission); return targetProcess.MemoryManager.SetProcessMemoryPermission(src, size, permission);
} }
private static bool PageAligned(ulong position) private static bool PageAligned(ulong address)
{ {
return (position & (KPageTableBase.PageSize - 1)) == 0; return (address & (KPageTableBase.PageSize - 1)) == 0;
} }
// System // System
@ -1575,7 +1589,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
Logger.Warning?.Print(LogClass.KernelSvc, str); Logger.Warning?.Print(LogClass.KernelSvc, str);
} }
public KernelResult GetInfo(InfoType id, int handle, long subId, out long value) public KernelResult GetInfo(out ulong value, InfoType id, int handle, long subId)
{ {
value = 0; value = 0;
@ -1621,30 +1635,30 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
case InfoType.CoreMask: value = process.Capabilities.AllowedCpuCoresMask; break; case InfoType.CoreMask: value = process.Capabilities.AllowedCpuCoresMask; break;
case InfoType.PriorityMask: value = process.Capabilities.AllowedThreadPriosMask; break; case InfoType.PriorityMask: value = process.Capabilities.AllowedThreadPriosMask; break;
case InfoType.AliasRegionAddress: value = (long)process.MemoryManager.AliasRegionStart; break; case InfoType.AliasRegionAddress: value = process.MemoryManager.AliasRegionStart; break;
case InfoType.AliasRegionSize: case InfoType.AliasRegionSize:
value = (long)(process.MemoryManager.AliasRegionEnd - value = (process.MemoryManager.AliasRegionEnd -
process.MemoryManager.AliasRegionStart); break; process.MemoryManager.AliasRegionStart); break;
case InfoType.HeapRegionAddress: value = (long)process.MemoryManager.HeapRegionStart; break; case InfoType.HeapRegionAddress: value = process.MemoryManager.HeapRegionStart; break;
case InfoType.HeapRegionSize: case InfoType.HeapRegionSize:
value = (long)(process.MemoryManager.HeapRegionEnd - value = (process.MemoryManager.HeapRegionEnd -
process.MemoryManager.HeapRegionStart); break; process.MemoryManager.HeapRegionStart); break;
case InfoType.TotalMemorySize: value = (long)process.GetMemoryCapacity(); break; case InfoType.TotalMemorySize: value = process.GetMemoryCapacity(); break;
case InfoType.UsedMemorySize: value = (long)process.GetMemoryUsage(); break; case InfoType.UsedMemorySize: value = process.GetMemoryUsage(); break;
case InfoType.AslrRegionAddress: value = (long)process.MemoryManager.GetAddrSpaceBaseAddr(); break; case InfoType.AslrRegionAddress: value = process.MemoryManager.GetAddrSpaceBaseAddr(); break;
case InfoType.AslrRegionSize: value = (long)process.MemoryManager.GetAddrSpaceSize(); break; case InfoType.AslrRegionSize: value = process.MemoryManager.GetAddrSpaceSize(); break;
case InfoType.StackRegionAddress: value = (long)process.MemoryManager.StackRegionStart; break; case InfoType.StackRegionAddress: value = process.MemoryManager.StackRegionStart; break;
case InfoType.StackRegionSize: case InfoType.StackRegionSize:
value = (long)(process.MemoryManager.StackRegionEnd - value = (process.MemoryManager.StackRegionEnd -
process.MemoryManager.StackRegionStart); break; process.MemoryManager.StackRegionStart); break;
case InfoType.SystemResourceSizeTotal: value = (long)process.PersonalMmHeapPagesCount * KPageTableBase.PageSize; break; case InfoType.SystemResourceSizeTotal: value = process.PersonalMmHeapPagesCount * KPageTableBase.PageSize; break;
case InfoType.SystemResourceSizeUsed: case InfoType.SystemResourceSizeUsed:
if (process.PersonalMmHeapPagesCount != 0) if (process.PersonalMmHeapPagesCount != 0)
@ -1654,20 +1668,21 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
break; break;
case InfoType.ProgramId: value = (long)process.TitleId; break; case InfoType.ProgramId: value = process.TitleId; break;
case InfoType.UserExceptionContextAddress: value = (long)process.UserExceptionContextAddress; break; case InfoType.UserExceptionContextAddress: value = process.UserExceptionContextAddress; break;
case InfoType.TotalNonSystemMemorySize: value = (long)process.GetMemoryCapacityWithoutPersonalMmHeap(); break; case InfoType.TotalNonSystemMemorySize: value = process.GetMemoryCapacityWithoutPersonalMmHeap(); break;
case InfoType.UsedNonSystemMemorySize: value = (long)process.GetMemoryUsageWithoutPersonalMmHeap(); break; case InfoType.UsedNonSystemMemorySize: value = process.GetMemoryUsageWithoutPersonalMmHeap(); break;
case InfoType.IsApplication: value = process.IsApplication ? 1 : 0; break; case InfoType.IsApplication: value = process.IsApplication ? 1UL : 0UL; break;
case InfoType.FreeThreadCount: case InfoType.FreeThreadCount:
if (process.ResourceLimit != null) if (process.ResourceLimit != null)
{ {
value = process.ResourceLimit.GetLimitValue(LimitableResource.Thread) - process.ResourceLimit.GetCurrentValue(LimitableResource.Thread); value = (ulong)(process.ResourceLimit.GetLimitValue(LimitableResource.Thread) -
process.ResourceLimit.GetCurrentValue(LimitableResource.Thread));
} }
else else
{ {
@ -1692,7 +1707,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidCombination; return KernelResult.InvalidCombination;
} }
value = KernelStatic.GetCurrentProcess().Debug ? 1 : 0; value = KernelStatic.GetCurrentProcess().Debug ? 1UL : 0UL;
break; break;
} }
@ -1743,7 +1758,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidCombination; return KernelResult.InvalidCombination;
} }
value = KTimeManager.ConvertHostTicksToTicks(_context.Schedulers[currentCore].TotalIdleTimeTicks); value = (ulong)KTimeManager.ConvertHostTicksToTicks(_context.Schedulers[currentCore].TotalIdleTimeTicks);
break; break;
} }
@ -1796,7 +1811,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
if (subId != -1) if (subId != -1)
{ {
value = KTimeManager.ConvertHostTicksToTicks(timeDelta); value = (ulong)KTimeManager.ConvertHostTicksToTicks(timeDelta);
} }
else else
{ {
@ -1807,7 +1822,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
totalTimeRunning += timeDelta; totalTimeRunning += timeDelta;
} }
value = KTimeManager.ConvertHostTicksToTicks(totalTimeRunning); value = (ulong)KTimeManager.ConvertHostTicksToTicks(totalTimeRunning);
} }
break; break;
@ -1844,7 +1859,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return result; return result;
} }
public KernelResult GetProcessList(ulong address, int maxCount, out int count) public KernelResult GetProcessList(out int count, ulong address, int maxCount)
{ {
count = 0; count = 0;
@ -1878,7 +1893,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
if (copyCount < maxCount) if (copyCount < maxCount)
{ {
if (!KernelTransfer.KernelToUserInt64(_context, address + (ulong)copyCount * 8, process.Pid)) if (!KernelTransfer.KernelToUser(address + (ulong)copyCount * 8, process.Pid))
{ {
return KernelResult.UserCopyFailed; return KernelResult.UserCopyFailed;
} }
@ -1893,7 +1908,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.Success; return KernelResult.Success;
} }
public KernelResult GetSystemInfo(uint id, int handle, long subId, out long value) public KernelResult GetSystemInfo(out long value, uint id, int handle, long subId)
{ {
value = 0; value = 0;
@ -1949,7 +1964,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.Success; return KernelResult.Success;
} }
public KernelResult GetResourceLimitLimitValue(int handle, LimitableResource resource, out long limitValue) public KernelResult GetResourceLimitLimitValue(out long limitValue, int handle, LimitableResource resource)
{ {
limitValue = 0; limitValue = 0;
@ -1970,7 +1985,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.Success; return KernelResult.Success;
} }
public KernelResult GetResourceLimitCurrentValue(int handle, LimitableResource resource, out long limitValue) public KernelResult GetResourceLimitCurrentValue(out long limitValue, int handle, LimitableResource resource)
{ {
limitValue = 0; limitValue = 0;
@ -1991,7 +2006,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.Success; return KernelResult.Success;
} }
public KernelResult GetResourceLimitPeakValue(int handle, LimitableResource resource, out long peak) public KernelResult GetResourceLimitPeakValue(out long peak, int handle, LimitableResource resource)
{ {
peak = 0; peak = 0;
@ -2041,12 +2056,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
// Thread // Thread
public KernelResult CreateThread( public KernelResult CreateThread(
out int handle,
ulong entrypoint, ulong entrypoint,
ulong argsPtr, ulong argsPtr,
ulong stackTop, ulong stackTop,
int priority, int priority,
int cpuCore, int cpuCore)
out int handle)
{ {
handle = 0; handle = 0;
@ -2152,7 +2167,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
} }
public KernelResult GetThreadPriority(int handle, out int priority) public KernelResult GetThreadPriority(out int priority, int handle)
{ {
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
@ -2190,7 +2205,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.Success; return KernelResult.Success;
} }
public KernelResult GetThreadCoreMask(int handle, out int preferredCore, out long affinityMask) public KernelResult GetThreadCoreMask(out int preferredCore, out ulong affinityMask, int handle)
{ {
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
@ -2212,7 +2227,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
} }
} }
public KernelResult SetThreadCoreMask(int handle, int preferredCore, long affinityMask) public KernelResult SetThreadCoreMask(int handle, int preferredCore, ulong affinityMask)
{ {
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
@ -2220,7 +2235,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
preferredCore = currentProcess.DefaultCpuCore; preferredCore = currentProcess.DefaultCpuCore;
affinityMask = 1 << preferredCore; affinityMask = 1UL << preferredCore;
} }
else else
{ {
@ -2242,7 +2257,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidCpuCore; return KernelResult.InvalidCpuCore;
} }
} }
else if ((affinityMask & (1 << preferredCore)) == 0) else if ((affinityMask & (1UL << preferredCore)) == 0)
{ {
return KernelResult.InvalidCombination; return KernelResult.InvalidCombination;
} }
@ -2265,7 +2280,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelStatic.GetCurrentThread().CurrentCore; return KernelStatic.GetCurrentThread().CurrentCore;
} }
public KernelResult GetThreadId(int handle, out long threadUid) public KernelResult GetThreadId(out ulong threadUid, int handle)
{ {
KProcess process = KernelStatic.GetCurrentProcess(); KProcess process = KernelStatic.GetCurrentProcess();
@ -2331,96 +2346,21 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidThread; return KernelResult.InvalidThread;
} }
IVirtualMemoryManager memory = currentProcess.CpuMemory; KernelResult result = thread.GetThreadContext3(out ThreadContext context);
memory.Write(address + 0x0, thread.Context.GetX(0)); if (result == KernelResult.Success)
memory.Write(address + 0x8, thread.Context.GetX(1)); {
memory.Write(address + 0x10, thread.Context.GetX(2)); return KernelTransfer.KernelToUser(address, context)
memory.Write(address + 0x18, thread.Context.GetX(3)); ? KernelResult.Success
memory.Write(address + 0x20, thread.Context.GetX(4)); : KernelResult.InvalidMemState;
memory.Write(address + 0x28, thread.Context.GetX(5)); }
memory.Write(address + 0x30, thread.Context.GetX(6));
memory.Write(address + 0x38, thread.Context.GetX(7));
memory.Write(address + 0x40, thread.Context.GetX(8));
memory.Write(address + 0x48, thread.Context.GetX(9));
memory.Write(address + 0x50, thread.Context.GetX(10));
memory.Write(address + 0x58, thread.Context.GetX(11));
memory.Write(address + 0x60, thread.Context.GetX(12));
memory.Write(address + 0x68, thread.Context.GetX(13));
memory.Write(address + 0x70, thread.Context.GetX(14));
memory.Write(address + 0x78, thread.Context.GetX(15));
memory.Write(address + 0x80, thread.Context.GetX(16));
memory.Write(address + 0x88, thread.Context.GetX(17));
memory.Write(address + 0x90, thread.Context.GetX(18));
memory.Write(address + 0x98, thread.Context.GetX(19));
memory.Write(address + 0xa0, thread.Context.GetX(20));
memory.Write(address + 0xa8, thread.Context.GetX(21));
memory.Write(address + 0xb0, thread.Context.GetX(22));
memory.Write(address + 0xb8, thread.Context.GetX(23));
memory.Write(address + 0xc0, thread.Context.GetX(24));
memory.Write(address + 0xc8, thread.Context.GetX(25));
memory.Write(address + 0xd0, thread.Context.GetX(26));
memory.Write(address + 0xd8, thread.Context.GetX(27));
memory.Write(address + 0xe0, thread.Context.GetX(28));
memory.Write(address + 0xe8, thread.Context.GetX(29));
memory.Write(address + 0xf0, thread.Context.GetX(30));
memory.Write(address + 0xf8, thread.Context.GetX(31));
memory.Write(address + 0x100, thread.LastPc); return result;
memory.Write(address + 0x108, (ulong)GetPsr(thread.Context));
memory.Write(address + 0x110, thread.Context.GetV(0));
memory.Write(address + 0x120, thread.Context.GetV(1));
memory.Write(address + 0x130, thread.Context.GetV(2));
memory.Write(address + 0x140, thread.Context.GetV(3));
memory.Write(address + 0x150, thread.Context.GetV(4));
memory.Write(address + 0x160, thread.Context.GetV(5));
memory.Write(address + 0x170, thread.Context.GetV(6));
memory.Write(address + 0x180, thread.Context.GetV(7));
memory.Write(address + 0x190, thread.Context.GetV(8));
memory.Write(address + 0x1a0, thread.Context.GetV(9));
memory.Write(address + 0x1b0, thread.Context.GetV(10));
memory.Write(address + 0x1c0, thread.Context.GetV(11));
memory.Write(address + 0x1d0, thread.Context.GetV(12));
memory.Write(address + 0x1e0, thread.Context.GetV(13));
memory.Write(address + 0x1f0, thread.Context.GetV(14));
memory.Write(address + 0x200, thread.Context.GetV(15));
memory.Write(address + 0x210, thread.Context.GetV(16));
memory.Write(address + 0x220, thread.Context.GetV(17));
memory.Write(address + 0x230, thread.Context.GetV(18));
memory.Write(address + 0x240, thread.Context.GetV(19));
memory.Write(address + 0x250, thread.Context.GetV(20));
memory.Write(address + 0x260, thread.Context.GetV(21));
memory.Write(address + 0x270, thread.Context.GetV(22));
memory.Write(address + 0x280, thread.Context.GetV(23));
memory.Write(address + 0x290, thread.Context.GetV(24));
memory.Write(address + 0x2a0, thread.Context.GetV(25));
memory.Write(address + 0x2b0, thread.Context.GetV(26));
memory.Write(address + 0x2c0, thread.Context.GetV(27));
memory.Write(address + 0x2d0, thread.Context.GetV(28));
memory.Write(address + 0x2e0, thread.Context.GetV(29));
memory.Write(address + 0x2f0, thread.Context.GetV(30));
memory.Write(address + 0x300, thread.Context.GetV(31));
memory.Write(address + 0x310, (int)thread.Context.Fpcr);
memory.Write(address + 0x314, (int)thread.Context.Fpsr);
memory.Write(address + 0x318, thread.Context.Tpidr);
return KernelResult.Success;
}
private static int GetPsr(ARMeilleure.State.ExecutionContext context)
{
return (context.GetPstateFlag(ARMeilleure.State.PState.NFlag) ? (1 << (int)ARMeilleure.State.PState.NFlag) : 0) |
(context.GetPstateFlag(ARMeilleure.State.PState.ZFlag) ? (1 << (int)ARMeilleure.State.PState.ZFlag) : 0) |
(context.GetPstateFlag(ARMeilleure.State.PState.CFlag) ? (1 << (int)ARMeilleure.State.PState.CFlag) : 0) |
(context.GetPstateFlag(ARMeilleure.State.PState.VFlag) ? (1 << (int)ARMeilleure.State.PState.VFlag) : 0);
} }
// Thread synchronization // Thread synchronization
public KernelResult WaitSynchronization(ulong handlesPtr, int handlesCount, long timeout, out int handleIndex) public KernelResult WaitSynchronization(out int handleIndex, ulong handlesPtr, int handlesCount, long timeout)
{ {
handleIndex = 0; handleIndex = 0;
@ -2456,7 +2396,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
Span<int> handles = new Span<int>(currentThread.WaitSyncHandles).Slice(0, handlesCount); Span<int> handles = new Span<int>(currentThread.WaitSyncHandles).Slice(0, handlesCount);
if (!KernelTransfer.UserToKernelInt32Array(_context, handlesPtr, handles)) if (!KernelTransfer.UserToKernelArray(handlesPtr, handles))
{ {
return KernelResult.UserCopyFailed; return KernelResult.UserCopyFailed;
} }

View File

@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult ConnectToNamedPort32([R(1)] uint namePtr, [R(1)] out int handle) public KernelResult ConnectToNamedPort32([R(1)] uint namePtr, [R(1)] out int handle)
{ {
return _syscall.ConnectToNamedPort(namePtr, out handle); return _syscall.ConnectToNamedPort(out handle, namePtr);
} }
public KernelResult SendSyncRequest32([R(0)] int handle) public KernelResult SendSyncRequest32([R(0)] int handle)
@ -36,17 +36,17 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(1)] out int serverSessionHandle, [R(1)] out int serverSessionHandle,
[R(2)] out int clientSessionHandle) [R(2)] out int clientSessionHandle)
{ {
return _syscall.CreateSession(isLight, namePtr, out serverSessionHandle, out clientSessionHandle); return _syscall.CreateSession(out serverSessionHandle, out clientSessionHandle, isLight, namePtr);
} }
public KernelResult AcceptSession32([R(1)] int portHandle, [R(1)] out int sessionHandle) public KernelResult AcceptSession32([R(1)] int portHandle, [R(1)] out int sessionHandle)
{ {
return _syscall.AcceptSession(portHandle, out sessionHandle); return _syscall.AcceptSession(out sessionHandle, portHandle);
} }
public KernelResult ReplyAndReceive32( public KernelResult ReplyAndReceive32(
[R(0)] uint timeoutLow, [R(0)] uint timeoutLow,
[R(1)] ulong handlesPtr, [R(1)] uint handlesPtr,
[R(2)] int handlesCount, [R(2)] int handlesCount,
[R(3)] int replyTargetHandle, [R(3)] int replyTargetHandle,
[R(4)] uint timeoutHigh, [R(4)] uint timeoutHigh,
@ -54,7 +54,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
long timeout = (long)(timeoutLow | ((ulong)timeoutHigh << 32)); long timeout = (long)(timeoutLow | ((ulong)timeoutHigh << 32));
return _syscall.ReplyAndReceive(handlesPtr, handlesCount, replyTargetHandle, timeout, out handleIndex); return _syscall.ReplyAndReceive(out handleIndex, handlesPtr, handlesCount, replyTargetHandle, timeout);
} }
public KernelResult CreatePort32( public KernelResult CreatePort32(
@ -64,45 +64,45 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(1)] out int serverPortHandle, [R(1)] out int serverPortHandle,
[R(2)] out int clientPortHandle) [R(2)] out int clientPortHandle)
{ {
return _syscall.CreatePort(maxSessions, isLight, namePtr, out serverPortHandle, out clientPortHandle); return _syscall.CreatePort(out serverPortHandle, out clientPortHandle, maxSessions, isLight, namePtr);
} }
public KernelResult ManageNamedPort32([R(1)] uint namePtr, [R(2)] int maxSessions, [R(1)] out int handle) public KernelResult ManageNamedPort32([R(1)] uint namePtr, [R(2)] int maxSessions, [R(1)] out int handle)
{ {
return _syscall.ManageNamedPort(namePtr, maxSessions, out handle); return _syscall.ManageNamedPort(out handle, namePtr, maxSessions);
} }
public KernelResult ConnectToPort32([R(1)] int clientPortHandle, [R(1)] out int clientSessionHandle) public KernelResult ConnectToPort32([R(1)] int clientPortHandle, [R(1)] out int clientSessionHandle)
{ {
return _syscall.ConnectToPort(clientPortHandle, out clientSessionHandle); return _syscall.ConnectToPort(out clientSessionHandle, clientPortHandle);
} }
// Memory // Memory
public KernelResult SetHeapSize32([R(1)] uint size, [R(1)] out uint position) public KernelResult SetHeapSize32([R(1)] uint size, [R(1)] out uint address)
{ {
KernelResult result = _syscall.SetHeapSize(size, out ulong temporaryPosition); KernelResult result = _syscall.SetHeapSize(out ulong address64, size);
position = (uint)temporaryPosition; address = (uint)address64;
return result; return result;
} }
public KernelResult SetMemoryPermission32( public KernelResult SetMemoryPermission32(
[R(0)] ulong position, [R(0)] uint address,
[R(1)] ulong size, [R(1)] uint size,
[R(2)] KMemoryPermission permission) [R(2)] KMemoryPermission permission)
{ {
return _syscall.SetMemoryPermission(position, size, permission); return _syscall.SetMemoryPermission(address, size, permission);
} }
public KernelResult SetMemoryAttribute32( public KernelResult SetMemoryAttribute32(
[R(0)] uint position, [R(0)] uint address,
[R(1)] uint size, [R(1)] uint size,
[R(2)] MemoryAttribute attributeMask, [R(2)] MemoryAttribute attributeMask,
[R(3)] MemoryAttribute attributeValue) [R(3)] MemoryAttribute attributeValue)
{ {
return _syscall.SetMemoryAttribute(position, size, attributeMask, attributeValue); return _syscall.SetMemoryAttribute(address, size, attributeMask, attributeValue);
} }
public KernelResult MapMemory32([R(0)] uint dst, [R(1)] uint src, [R(2)] uint size) public KernelResult MapMemory32([R(0)] uint dst, [R(1)] uint src, [R(2)] uint size)
@ -115,9 +115,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.UnmapMemory(dst, src, size); return _syscall.UnmapMemory(dst, src, size);
} }
public KernelResult QueryMemory32([R(0)] uint infoPtr, [R(1)] uint r1, [R(2)] uint position, [R(1)] out uint pageInfo) public KernelResult QueryMemory32([R(0)] uint infoPtr, [R(1)] uint r1, [R(2)] uint address, [R(1)] out uint pageInfo)
{ {
KernelResult result = _syscall.QueryMemory(infoPtr, position, out ulong pageInfo64); KernelResult result = _syscall.QueryMemory(infoPtr, out ulong pageInfo64, address);
pageInfo = (uint)pageInfo64; pageInfo = (uint)pageInfo64;
@ -140,7 +140,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(3)] KMemoryPermission permission, [R(3)] KMemoryPermission permission,
[R(1)] out int handle) [R(1)] out int handle)
{ {
return _syscall.CreateTransferMemory(address, size, permission, out handle); return _syscall.CreateTransferMemory(out handle, address, size, permission);
} }
public KernelResult MapTransferMemory32([R(0)] int handle, [R(1)] uint address, [R(2)] uint size, [R(3)] KMemoryPermission permission) public KernelResult MapTransferMemory32([R(0)] int handle, [R(1)] uint address, [R(2)] uint size, [R(3)] KMemoryPermission permission)
@ -235,12 +235,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
resultHigh = (uint)(result >> 32); resultHigh = (uint)(result >> 32);
} }
public KernelResult GetProcessId32([R(1)] int handle, [R(1)] out int pidLow, [R(2)] out int pidHigh) public KernelResult GetProcessId32([R(1)] int handle, [R(1)] out uint pidLow, [R(2)] out uint pidHigh)
{ {
KernelResult result = _syscall.GetProcessId(handle, out long pid); KernelResult result = _syscall.GetProcessId(out ulong pid, handle);
pidLow = (int)(pid & uint.MaxValue); pidLow = (uint)(pid & uint.MaxValue);
pidHigh = (int)(pid >> 32); pidHigh = (uint)(pid >> 32);
return result; return result;
} }
@ -265,7 +265,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
long subId = (long)(subIdLow | ((ulong)subIdHigh << 32)); long subId = (long)(subIdLow | ((ulong)subIdHigh << 32));
KernelResult result = _syscall.GetInfo(id, handle, subId, out long value); KernelResult result = _syscall.GetInfo(out ulong value, id, handle, subId);
valueHigh = (uint)(value >> 32); valueHigh = (uint)(value >> 32);
valueLow = (uint)(value & uint.MaxValue); valueLow = (uint)(value & uint.MaxValue);
@ -280,14 +280,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetProcessList32([R(1)] ulong address, [R(2)] int maxCount, [R(1)] out int count) public KernelResult GetProcessList32([R(1)] ulong address, [R(2)] int maxCount, [R(1)] out int count)
{ {
return _syscall.GetProcessList(address, maxCount, out count); return _syscall.GetProcessList(out count, address, maxCount);
} }
public KernelResult GetSystemInfo32([R(1)] uint subIdLow, [R(2)] uint id, [R(3)] int handle, [R(3)] uint subIdHigh, [R(1)] out int valueLow, [R(2)] out int valueHigh) public KernelResult GetSystemInfo32([R(1)] uint subIdLow, [R(2)] uint id, [R(3)] int handle, [R(3)] uint subIdHigh, [R(1)] out int valueLow, [R(2)] out int valueHigh)
{ {
long subId = (long)(subIdLow | ((ulong)subIdHigh << 32)); long subId = (long)(subIdLow | ((ulong)subIdHigh << 32));
KernelResult result = _syscall.GetSystemInfo(id, handle, subId, out long value); KernelResult result = _syscall.GetSystemInfo(out long value, id, handle, subId);
valueHigh = (int)(value >> 32); valueHigh = (int)(value >> 32);
valueLow = (int)(value & uint.MaxValue); valueLow = (int)(value & uint.MaxValue);
@ -297,7 +297,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetResourceLimitLimitValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int limitValueLow, [R(2)] out int limitValueHigh) public KernelResult GetResourceLimitLimitValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int limitValueLow, [R(2)] out int limitValueHigh)
{ {
KernelResult result = _syscall.GetResourceLimitLimitValue(handle, resource, out long limitValue); KernelResult result = _syscall.GetResourceLimitLimitValue(out long limitValue, handle, resource);
limitValueHigh = (int)(limitValue >> 32); limitValueHigh = (int)(limitValue >> 32);
limitValueLow = (int)(limitValue & uint.MaxValue); limitValueLow = (int)(limitValue & uint.MaxValue);
@ -307,7 +307,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetResourceLimitCurrentValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int limitValueLow, [R(2)] out int limitValueHigh) public KernelResult GetResourceLimitCurrentValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int limitValueLow, [R(2)] out int limitValueHigh)
{ {
KernelResult result = _syscall.GetResourceLimitCurrentValue(handle, resource, out long limitValue); KernelResult result = _syscall.GetResourceLimitCurrentValue(out long limitValue, handle, resource);
limitValueHigh = (int)(limitValue >> 32); limitValueHigh = (int)(limitValue >> 32);
limitValueLow = (int)(limitValue & uint.MaxValue); limitValueLow = (int)(limitValue & uint.MaxValue);
@ -317,7 +317,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetResourceLimitPeakValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int peakLow, [R(2)] out int peakHigh) public KernelResult GetResourceLimitPeakValue32([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out int peakLow, [R(2)] out int peakHigh)
{ {
KernelResult result = _syscall.GetResourceLimitPeakValue(handle, resource, out long peak); KernelResult result = _syscall.GetResourceLimitPeakValue(out long peak, handle, resource);
peakHigh = (int)(peak >> 32); peakHigh = (int)(peak >> 32);
peakLow = (int)(peak & uint.MaxValue); peakLow = (int)(peak & uint.MaxValue);
@ -359,7 +359,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(4)] int cpuCore, [R(4)] int cpuCore,
[R(1)] out int handle) [R(1)] out int handle)
{ {
return _syscall.CreateThread(entrypoint, argsPtr, stackTop, priority, cpuCore, out handle); return _syscall.CreateThread(out handle, entrypoint, argsPtr, stackTop, priority, cpuCore);
} }
public KernelResult StartThread32([R(0)] int handle) public KernelResult StartThread32([R(0)] int handle)
@ -381,7 +381,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetThreadPriority32([R(1)] int handle, [R(1)] out int priority) public KernelResult GetThreadPriority32([R(1)] int handle, [R(1)] out int priority)
{ {
return _syscall.GetThreadPriority(handle, out priority); return _syscall.GetThreadPriority(out priority, handle);
} }
public KernelResult SetThreadPriority32([R(0)] int handle, [R(1)] int priority) public KernelResult SetThreadPriority32([R(0)] int handle, [R(1)] int priority)
@ -389,19 +389,19 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.SetThreadPriority(handle, priority); return _syscall.SetThreadPriority(handle, priority);
} }
public KernelResult GetThreadCoreMask32([R(2)] int handle, [R(1)] out int preferredCore, [R(2)] out int affinityMaskLow, [R(3)] out int affinityMaskHigh) public KernelResult GetThreadCoreMask32([R(2)] int handle, [R(1)] out int preferredCore, [R(2)] out uint affinityMaskLow, [R(3)] out uint affinityMaskHigh)
{ {
KernelResult result = _syscall.GetThreadCoreMask(handle, out preferredCore, out long affinityMask); KernelResult result = _syscall.GetThreadCoreMask(out preferredCore, out ulong affinityMask, handle);
affinityMaskLow = (int)(affinityMask & uint.MaxValue); affinityMaskLow = (uint)(affinityMask & uint.MaxValue);
affinityMaskHigh = (int)(affinityMask >> 32); affinityMaskHigh = (uint)(affinityMask >> 32);
return result; return result;
} }
public KernelResult SetThreadCoreMask32([R(0)] int handle, [R(1)] int preferredCore, [R(2)] uint affinityMaskLow, [R(3)] uint affinityMaskHigh) public KernelResult SetThreadCoreMask32([R(0)] int handle, [R(1)] int preferredCore, [R(2)] uint affinityMaskLow, [R(3)] uint affinityMaskHigh)
{ {
long affinityMask = (long)(affinityMaskLow | ((ulong)affinityMaskHigh << 32)); ulong affinityMask = affinityMaskLow | ((ulong)affinityMaskHigh << 32);
return _syscall.SetThreadCoreMask(handle, preferredCore, affinityMask); return _syscall.SetThreadCoreMask(handle, preferredCore, affinityMask);
} }
@ -413,9 +413,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetThreadId32([R(1)] int handle, [R(1)] out uint threadUidLow, [R(2)] out uint threadUidHigh) public KernelResult GetThreadId32([R(1)] int handle, [R(1)] out uint threadUidLow, [R(2)] out uint threadUidHigh)
{ {
long threadUid; ulong threadUid;
KernelResult result = _syscall.GetThreadId(handle, out threadUid); KernelResult result = _syscall.GetThreadId(out threadUid, handle);
threadUidLow = (uint)(threadUid >> 32); threadUidLow = (uint)(threadUid >> 32);
threadUidHigh = (uint)(threadUid & uint.MaxValue); threadUidHigh = (uint)(threadUid & uint.MaxValue);
@ -444,7 +444,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{ {
long timeout = (long)(timeoutLow | ((ulong)timeoutHigh << 32)); long timeout = (long)(timeoutLow | ((ulong)timeoutHigh << 32));
return _syscall.WaitSynchronization(handlesPtr, handlesCount, timeout, out handleIndex); return _syscall.WaitSynchronization(out handleIndex, handlesPtr, handlesCount, timeout);
} }
public KernelResult CancelSynchronization32([R(0)] int handle) public KernelResult CancelSynchronization32([R(0)] int handle)

View File

@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult ConnectToNamedPort64([R(1)] ulong namePtr, [R(1)] out int handle) public KernelResult ConnectToNamedPort64([R(1)] ulong namePtr, [R(1)] out int handle)
{ {
return _syscall.ConnectToNamedPort(namePtr, out handle); return _syscall.ConnectToNamedPort(out handle, namePtr);
} }
public KernelResult SendSyncRequest64([R(0)] int handle) public KernelResult SendSyncRequest64([R(0)] int handle)
@ -36,7 +36,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(3)] int handle, [R(3)] int handle,
[R(1)] out int doneEventHandle) [R(1)] out int doneEventHandle)
{ {
return _syscall.SendAsyncRequestWithUserBuffer(messagePtr, messageSize, handle, out doneEventHandle); return _syscall.SendAsyncRequestWithUserBuffer(out doneEventHandle, messagePtr, messageSize, handle);
} }
public KernelResult CreateSession64( public KernelResult CreateSession64(
@ -45,12 +45,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(1)] out int serverSessionHandle, [R(1)] out int serverSessionHandle,
[R(2)] out int clientSessionHandle) [R(2)] out int clientSessionHandle)
{ {
return _syscall.CreateSession(isLight, namePtr, out serverSessionHandle, out clientSessionHandle); return _syscall.CreateSession(out serverSessionHandle, out clientSessionHandle, isLight, namePtr);
} }
public KernelResult AcceptSession64([R(1)] int portHandle, [R(1)] out int sessionHandle) public KernelResult AcceptSession64([R(1)] int portHandle, [R(1)] out int sessionHandle)
{ {
return _syscall.AcceptSession(portHandle, out sessionHandle); return _syscall.AcceptSession(out sessionHandle, portHandle);
} }
public KernelResult ReplyAndReceive64( public KernelResult ReplyAndReceive64(
@ -60,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(4)] long timeout, [R(4)] long timeout,
[R(1)] out int handleIndex) [R(1)] out int handleIndex)
{ {
return _syscall.ReplyAndReceive(handlesPtr, handlesCount, replyTargetHandle, timeout, out handleIndex); return _syscall.ReplyAndReceive(out handleIndex, handlesPtr, handlesCount, replyTargetHandle, timeout);
} }
public KernelResult ReplyAndReceiveWithUserBuffer64( public KernelResult ReplyAndReceiveWithUserBuffer64(
@ -73,13 +73,13 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(1)] out int handleIndex) [R(1)] out int handleIndex)
{ {
return _syscall.ReplyAndReceiveWithUserBuffer( return _syscall.ReplyAndReceiveWithUserBuffer(
out handleIndex,
handlesPtr, handlesPtr,
messagePtr, messagePtr,
messageSize, messageSize,
handlesCount, handlesCount,
replyTargetHandle, replyTargetHandle,
timeout, timeout);
out handleIndex);
} }
public KernelResult CreatePort64( public KernelResult CreatePort64(
@ -89,41 +89,41 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(1)] out int serverPortHandle, [R(1)] out int serverPortHandle,
[R(2)] out int clientPortHandle) [R(2)] out int clientPortHandle)
{ {
return _syscall.CreatePort(maxSessions, isLight, namePtr, out serverPortHandle, out clientPortHandle); return _syscall.CreatePort(out serverPortHandle, out clientPortHandle, maxSessions, isLight, namePtr);
} }
public KernelResult ManageNamedPort64([R(1)] ulong namePtr, [R(2)] int maxSessions, [R(1)] out int handle) public KernelResult ManageNamedPort64([R(1)] ulong namePtr, [R(2)] int maxSessions, [R(1)] out int handle)
{ {
return _syscall.ManageNamedPort(namePtr, maxSessions, out handle); return _syscall.ManageNamedPort(out handle, namePtr, maxSessions);
} }
public KernelResult ConnectToPort64([R(1)] int clientPortHandle, [R(1)] out int clientSessionHandle) public KernelResult ConnectToPort64([R(1)] int clientPortHandle, [R(1)] out int clientSessionHandle)
{ {
return _syscall.ConnectToPort(clientPortHandle, out clientSessionHandle); return _syscall.ConnectToPort(out clientSessionHandle, clientPortHandle);
} }
// Memory // Memory
public KernelResult SetHeapSize64([R(1)] ulong size, [R(1)] out ulong position) public KernelResult SetHeapSize64([R(1)] ulong size, [R(1)] out ulong address)
{ {
return _syscall.SetHeapSize(size, out position); return _syscall.SetHeapSize(out address, size);
} }
public KernelResult SetMemoryPermission64( public KernelResult SetMemoryPermission64(
[R(0)] ulong position, [R(0)] ulong address,
[R(1)] ulong size, [R(1)] ulong size,
[R(2)] KMemoryPermission permission) [R(2)] KMemoryPermission permission)
{ {
return _syscall.SetMemoryPermission(position, size, permission); return _syscall.SetMemoryPermission(address, size, permission);
} }
public KernelResult SetMemoryAttribute64( public KernelResult SetMemoryAttribute64(
[R(0)] ulong position, [R(0)] ulong address,
[R(1)] ulong size, [R(1)] ulong size,
[R(2)] MemoryAttribute attributeMask, [R(2)] MemoryAttribute attributeMask,
[R(3)] MemoryAttribute attributeValue) [R(3)] MemoryAttribute attributeValue)
{ {
return _syscall.SetMemoryAttribute(position, size, attributeMask, attributeValue); return _syscall.SetMemoryAttribute(address, size, attributeMask, attributeValue);
} }
public KernelResult MapMemory64([R(0)] ulong dst, [R(1)] ulong src, [R(2)] ulong size) public KernelResult MapMemory64([R(0)] ulong dst, [R(1)] ulong src, [R(2)] ulong size)
@ -136,9 +136,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.UnmapMemory(dst, src, size); return _syscall.UnmapMemory(dst, src, size);
} }
public KernelResult QueryMemory64([R(0)] ulong infoPtr, [R(2)] ulong position, [R(1)] out ulong pageInfo) public KernelResult QueryMemory64([R(0)] ulong infoPtr, [R(2)] ulong address, [R(1)] out ulong pageInfo)
{ {
return _syscall.QueryMemory(infoPtr, position, out pageInfo); return _syscall.QueryMemory(infoPtr, out pageInfo, address);
} }
public KernelResult MapSharedMemory64([R(0)] int handle, [R(1)] ulong address, [R(2)] ulong size, [R(3)] KMemoryPermission permission) public KernelResult MapSharedMemory64([R(0)] int handle, [R(1)] ulong address, [R(2)] ulong size, [R(3)] KMemoryPermission permission)
@ -157,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(3)] KMemoryPermission permission, [R(3)] KMemoryPermission permission,
[R(1)] out int handle) [R(1)] out int handle)
{ {
return _syscall.CreateTransferMemory(address, size, permission, out handle); return _syscall.CreateTransferMemory(out handle, address, size, permission);
} }
public KernelResult MapTransferMemory64([R(0)] int handle, [R(1)] ulong address, [R(2)] ulong size, [R(3)] KMemoryPermission permission) public KernelResult MapTransferMemory64([R(0)] int handle, [R(1)] ulong address, [R(2)] ulong size, [R(3)] KMemoryPermission permission)
@ -232,9 +232,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.GetSystemTick(); return _syscall.GetSystemTick();
} }
public KernelResult GetProcessId64([R(1)] int handle, [R(1)] out long pid) public KernelResult GetProcessId64([R(1)] int handle, [R(1)] out ulong pid)
{ {
return _syscall.GetProcessId(handle, out pid); return _syscall.GetProcessId(out pid, handle);
} }
public void Break64([R(0)] ulong reason, [R(1)] ulong x1, [R(2)] ulong info) public void Break64([R(0)] ulong reason, [R(1)] ulong x1, [R(2)] ulong info)
@ -247,9 +247,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
_syscall.OutputDebugString(strPtr, size); _syscall.OutputDebugString(strPtr, size);
} }
public KernelResult GetInfo64([R(1)] InfoType id, [R(2)] int handle, [R(3)] long subId, [R(1)] out long value) public KernelResult GetInfo64([R(1)] InfoType id, [R(2)] int handle, [R(3)] long subId, [R(1)] out ulong value)
{ {
return _syscall.GetInfo(id, handle, subId, out value); return _syscall.GetInfo(out value, id, handle, subId);
} }
public KernelResult CreateEvent64([R(1)] out int wEventHandle, [R(2)] out int rEventHandle) public KernelResult CreateEvent64([R(1)] out int wEventHandle, [R(2)] out int rEventHandle)
@ -259,27 +259,27 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetProcessList64([R(1)] ulong address, [R(2)] int maxCount, [R(1)] out int count) public KernelResult GetProcessList64([R(1)] ulong address, [R(2)] int maxCount, [R(1)] out int count)
{ {
return _syscall.GetProcessList(address, maxCount, out count); return _syscall.GetProcessList(out count, address, maxCount);
} }
public KernelResult GetSystemInfo64([R(1)] uint id, [R(2)] int handle, [R(3)] long subId, [R(1)] out long value) public KernelResult GetSystemInfo64([R(1)] uint id, [R(2)] int handle, [R(3)] long subId, [R(1)] out long value)
{ {
return _syscall.GetSystemInfo(id, handle, subId, out value); return _syscall.GetSystemInfo(out value, id, handle, subId);
} }
public KernelResult GetResourceLimitLimitValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long limitValue) public KernelResult GetResourceLimitLimitValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long limitValue)
{ {
return _syscall.GetResourceLimitLimitValue(handle, resource, out limitValue); return _syscall.GetResourceLimitLimitValue(out limitValue, handle, resource);
} }
public KernelResult GetResourceLimitCurrentValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long limitValue) public KernelResult GetResourceLimitCurrentValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long limitValue)
{ {
return _syscall.GetResourceLimitCurrentValue(handle, resource, out limitValue); return _syscall.GetResourceLimitCurrentValue(out limitValue, handle, resource);
} }
public KernelResult GetResourceLimitPeakValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long peak) public KernelResult GetResourceLimitPeakValue64([R(1)] int handle, [R(2)] LimitableResource resource, [R(1)] out long peak)
{ {
return _syscall.GetResourceLimitPeakValue(handle, resource, out peak); return _syscall.GetResourceLimitPeakValue(out peak, handle, resource);
} }
public KernelResult CreateResourceLimit64([R(1)] out int handle) public KernelResult CreateResourceLimit64([R(1)] out int handle)
@ -302,7 +302,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
[R(5)] int cpuCore, [R(5)] int cpuCore,
[R(1)] out int handle) [R(1)] out int handle)
{ {
return _syscall.CreateThread(entrypoint, argsPtr, stackTop, priority, cpuCore, out handle); return _syscall.CreateThread(out handle, entrypoint, argsPtr, stackTop, priority, cpuCore);
} }
public KernelResult StartThread64([R(0)] int handle) public KernelResult StartThread64([R(0)] int handle)
@ -322,7 +322,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult GetThreadPriority64([R(1)] int handle, [R(1)] out int priority) public KernelResult GetThreadPriority64([R(1)] int handle, [R(1)] out int priority)
{ {
return _syscall.GetThreadPriority(handle, out priority); return _syscall.GetThreadPriority(out priority, handle);
} }
public KernelResult SetThreadPriority64([R(0)] int handle, [R(1)] int priority) public KernelResult SetThreadPriority64([R(0)] int handle, [R(1)] int priority)
@ -330,12 +330,12 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.SetThreadPriority(handle, priority); return _syscall.SetThreadPriority(handle, priority);
} }
public KernelResult GetThreadCoreMask64([R(2)] int handle, [R(1)] out int preferredCore, [R(2)] out long affinityMask) public KernelResult GetThreadCoreMask64([R(2)] int handle, [R(1)] out int preferredCore, [R(2)] out ulong affinityMask)
{ {
return _syscall.GetThreadCoreMask(handle, out preferredCore, out affinityMask); return _syscall.GetThreadCoreMask(out preferredCore, out affinityMask, handle);
} }
public KernelResult SetThreadCoreMask64([R(0)] int handle, [R(1)] int preferredCore, [R(2)] long affinityMask) public KernelResult SetThreadCoreMask64([R(0)] int handle, [R(1)] int preferredCore, [R(2)] ulong affinityMask)
{ {
return _syscall.SetThreadCoreMask(handle, preferredCore, affinityMask); return _syscall.SetThreadCoreMask(handle, preferredCore, affinityMask);
} }
@ -345,9 +345,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return _syscall.GetCurrentProcessorNumber(); return _syscall.GetCurrentProcessorNumber();
} }
public KernelResult GetThreadId64([R(1)] int handle, [R(1)] out long threadUid) public KernelResult GetThreadId64([R(1)] int handle, [R(1)] out ulong threadUid)
{ {
return _syscall.GetThreadId(handle, out threadUid); return _syscall.GetThreadId(out threadUid, handle);
} }
public KernelResult SetThreadActivity64([R(0)] int handle, [R(1)] bool pause) public KernelResult SetThreadActivity64([R(0)] int handle, [R(1)] bool pause)
@ -364,7 +364,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
public KernelResult WaitSynchronization64([R(1)] ulong handlesPtr, [R(2)] int handlesCount, [R(3)] long timeout, [R(1)] out int handleIndex) public KernelResult WaitSynchronization64([R(1)] ulong handlesPtr, [R(2)] int handlesCount, [R(3)] long timeout, [R(1)] out int handleIndex)
{ {
return _syscall.WaitSynchronization(handlesPtr, handlesCount, timeout, out handleIndex); return _syscall.WaitSynchronization(out handleIndex, handlesPtr, handlesCount, timeout);
} }
public KernelResult CancelSynchronization64([R(0)] int handle) public KernelResult CancelSynchronization64([R(0)] int handle)

View File

@ -433,7 +433,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
generator.Emit(OpCodes.Ret); generator.Emit(OpCodes.Ret);
return (Action<T, ExecutionContext>)method.CreateDelegate(typeof(Action<T, ExecutionContext>)); return method.CreateDelegate<Action<T, ExecutionContext>>();
} }
private static void CheckIfTypeIsSupported(Type type, string svcName) private static void CheckIfTypeIsSupported(Type type, string svcName)

View File

@ -0,0 +1,22 @@
using ARMeilleure.State;
using Ryujinx.Common.Memory;
namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{
struct ThreadContext
{
public Array29<ulong> Registers;
public ulong Fp;
public ulong Lr;
public ulong Sp;
public ulong Pc;
public uint Pstate;
#pragma warning disable CS0169
private uint _padding;
#pragma warning restore CS0169
public Array32<V128> FpuRegisters;
public uint Fpcr;
public uint Fpsr;
public ulong Tpidr;
}
}

View File

@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (!KernelTransfer.UserToKernelInt32(_context, mutexAddress, out int mutexValue)) if (!KernelTransfer.UserToKernel(out int mutexValue, mutexAddress))
{ {
_context.CriticalSection.Leave(); _context.CriticalSection.Leave();
@ -88,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelResult result = KernelResult.Success; KernelResult result = KernelResult.Success;
if (!KernelTransfer.KernelToUserInt32(_context, mutexAddress, mutexValue)) if (!KernelTransfer.KernelToUser(mutexAddress, mutexValue))
{ {
result = KernelResult.InvalidMemState; result = KernelResult.InvalidMemState;
} }
@ -123,9 +123,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
(int mutexValue, _) = MutexUnlock(currentThread, mutexAddress); (int mutexValue, _) = MutexUnlock(currentThread, mutexAddress);
KernelTransfer.KernelToUserInt32(_context, condVarAddress, 1); KernelTransfer.KernelToUser(condVarAddress, 1);
if (!KernelTransfer.KernelToUserInt32(_context, mutexAddress, mutexValue)) if (!KernelTransfer.KernelToUser(mutexAddress, mutexValue))
{ {
_context.CriticalSection.Leave(); _context.CriticalSection.Leave();
@ -201,7 +201,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (!_condVarThreads.Any(x => x.CondVarAddress == address)) if (!_condVarThreads.Any(x => x.CondVarAddress == address))
{ {
KernelTransfer.KernelToUserInt32(_context, address, 0); KernelTransfer.KernelToUser(address, 0);
} }
_context.CriticalSection.Leave(); _context.CriticalSection.Leave();
@ -290,7 +290,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
currentThread.SignaledObj = null; currentThread.SignaledObj = null;
currentThread.ObjSyncResult = KernelResult.TimedOut; currentThread.ObjSyncResult = KernelResult.TimedOut;
if (!KernelTransfer.UserToKernelInt32(_context, address, out int currentValue)) if (!KernelTransfer.UserToKernel(out int currentValue, address))
{ {
_context.CriticalSection.Leave(); _context.CriticalSection.Leave();
@ -363,7 +363,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KProcess currentProcess = KernelStatic.GetCurrentProcess(); KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (!KernelTransfer.UserToKernelInt32(_context, address, out int currentValue)) if (!KernelTransfer.UserToKernel(out int currentValue, address))
{ {
_context.CriticalSection.Leave(); _context.CriticalSection.Leave();

View File

@ -2,6 +2,7 @@ using Ryujinx.Common.Logging;
using Ryujinx.Cpu; using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common; using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process; using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.SupervisorCall;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
@ -27,9 +28,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
public KThreadContext ThreadContext { get; private set; } public KThreadContext ThreadContext { get; private set; }
public int DynamicPriority { get; set; } public int DynamicPriority { get; set; }
public long AffinityMask { get; set; } public ulong AffinityMask { get; set; }
public long ThreadUid { get; private set; } public ulong ThreadUid { get; private set; }
private long _totalTimeRunning; private long _totalTimeRunning;
@ -88,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
public bool IsPinned { get; private set; } public bool IsPinned { get; private set; }
private long _originalAffinityMask; private ulong _originalAffinityMask;
private int _originalPreferredCore; private int _originalPreferredCore;
private int _originalBasePriority; private int _originalBasePriority;
private int _coreMigrationDisableCount; private int _coreMigrationDisableCount;
@ -147,7 +148,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
ThreadContext = new KThreadContext(); ThreadContext = new KThreadContext();
PreferredCore = cpuCore; PreferredCore = cpuCore;
AffinityMask |= 1L << cpuCore; AffinityMask |= 1UL << cpuCore;
SchedFlags = type == ThreadType.Dummy SchedFlags = type == ThreadType.Dummy
? ThreadSchedState.Running ? ThreadSchedState.Running
@ -629,6 +630,89 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
} }
} }
public KernelResult GetThreadContext3(out ThreadContext context)
{
context = default;
lock (ActivityOperationLock)
{
KernelContext.CriticalSection.Enter();
if ((_forcePauseFlags & ThreadSchedState.ThreadPauseFlag) == 0)
{
KernelContext.CriticalSection.Leave();
return KernelResult.InvalidState;
}
if (!TerminationRequested)
{
context = GetCurrentContext();
}
KernelContext.CriticalSection.Leave();
}
return KernelResult.Success;
}
private static uint GetPsr(ARMeilleure.State.ExecutionContext context)
{
return (context.GetPstateFlag(ARMeilleure.State.PState.NFlag) ? (1U << (int)ARMeilleure.State.PState.NFlag) : 0U) |
(context.GetPstateFlag(ARMeilleure.State.PState.ZFlag) ? (1U << (int)ARMeilleure.State.PState.ZFlag) : 0U) |
(context.GetPstateFlag(ARMeilleure.State.PState.CFlag) ? (1U << (int)ARMeilleure.State.PState.CFlag) : 0U) |
(context.GetPstateFlag(ARMeilleure.State.PState.VFlag) ? (1U << (int)ARMeilleure.State.PState.VFlag) : 0U);
}
private ThreadContext GetCurrentContext()
{
const int MaxRegistersAArch32 = 15;
const int MaxFpuRegistersAArch32 = 16;
ThreadContext context = new ThreadContext();
if (Owner.Flags.HasFlag(ProcessCreationFlags.Is64Bit))
{
for (int i = 0; i < context.Registers.Length; i++)
{
context.Registers[i] = Context.GetX(i);
}
for (int i = 0; i < context.FpuRegisters.Length; i++)
{
context.FpuRegisters[i] = Context.GetV(i);
}
context.Fp = Context.GetX(29);
context.Lr = Context.GetX(30);
context.Sp = Context.GetX(31);
context.Pc = (ulong)LastPc;
context.Pstate = GetPsr(Context);
context.Tpidr = (ulong)Context.Tpidr;
}
else
{
for (int i = 0; i < MaxRegistersAArch32; i++)
{
context.Registers[i] = (uint)Context.GetX(i);
}
for (int i = 0; i < MaxFpuRegistersAArch32; i++)
{
context.FpuRegisters[i] = Context.GetV(i);
}
context.Pc = (uint)LastPc;
context.Pstate = GetPsr(Context);
context.Tpidr = (uint)Context.Tpidr;
}
context.Fpcr = (uint)Context.Fpcr;
context.Fpsr = (uint)Context.Fpsr;
return context;
}
public void CancelSynchronization() public void CancelSynchronization()
{ {
KernelContext.CriticalSection.Enter(); KernelContext.CriticalSection.Enter();
@ -660,7 +744,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.CriticalSection.Leave(); KernelContext.CriticalSection.Leave();
} }
public KernelResult SetCoreAndAffinityMask(int newCore, long newAffinityMask) public KernelResult SetCoreAndAffinityMask(int newCore, ulong newAffinityMask)
{ {
lock (ActivityOperationLock) lock (ActivityOperationLock)
{ {
@ -673,7 +757,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{ {
newCore = isCoreMigrationDisabled ? _originalPreferredCore : PreferredCore; newCore = isCoreMigrationDisabled ? _originalPreferredCore : PreferredCore;
if ((newAffinityMask & (1 << newCore)) == 0) if ((newAffinityMask & (1UL << newCore)) == 0)
{ {
KernelContext.CriticalSection.Leave(); KernelContext.CriticalSection.Leave();
@ -688,7 +772,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
} }
else else
{ {
long oldAffinityMask = AffinityMask; ulong oldAffinityMask = AffinityMask;
PreferredCore = newCore; PreferredCore = newCore;
AffinityMask = newAffinityMask; AffinityMask = newAffinityMask;
@ -701,7 +785,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
{ {
if (PreferredCore < 0) if (PreferredCore < 0)
{ {
ActiveCore = sizeof(ulong) * 8 - 1 - BitOperations.LeadingZeroCount((ulong)AffinityMask); ActiveCore = sizeof(ulong) * 8 - 1 - BitOperations.LeadingZeroCount(AffinityMask);
} }
else else
{ {
@ -733,7 +817,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
int coreNumber = GetEffectiveRunningCore(); int coreNumber = GetEffectiveRunningCore();
bool isPinnedThreadCurrentlyRunning = coreNumber >= 0; bool isPinnedThreadCurrentlyRunning = coreNumber >= 0;
if (isPinnedThreadCurrentlyRunning && ((1 << coreNumber) & AffinityMask) == 0) if (isPinnedThreadCurrentlyRunning && ((1UL << coreNumber) & AffinityMask) == 0)
{ {
if (IsPinned) if (IsPinned)
{ {
@ -1077,7 +1161,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KernelContext.ThreadReselectionRequested = true; KernelContext.ThreadReselectionRequested = true;
} }
private void AdjustSchedulingForNewAffinity(long oldAffinityMask, int oldCore) private void AdjustSchedulingForNewAffinity(ulong oldAffinityMask, int oldCore)
{ {
if (SchedFlags != ThreadSchedState.Running || DynamicPriority >= KScheduler.PrioritiesCount || !IsSchedulable) if (SchedFlags != ThreadSchedState.Running || DynamicPriority >= KScheduler.PrioritiesCount || !IsSchedulable)
{ {
@ -1259,7 +1343,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
ActiveCore = CurrentCore; ActiveCore = CurrentCore;
PreferredCore = CurrentCore; PreferredCore = CurrentCore;
AffinityMask = 1 << CurrentCore; AffinityMask = 1UL << CurrentCore;
if (activeCore != CurrentCore || _originalAffinityMask != AffinityMask) if (activeCore != CurrentCore || _originalAffinityMask != AffinityMask)
{ {
@ -1282,7 +1366,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
IsPinned = false; IsPinned = false;
_coreMigrationDisableCount--; _coreMigrationDisableCount--;
long affinityMask = AffinityMask; ulong affinityMask = AffinityMask;
int activeCore = ActiveCore; int activeCore = ActiveCore;
PreferredCore = _originalPreferredCore; PreferredCore = _originalPreferredCore;
@ -1290,7 +1374,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (AffinityMask != affinityMask) if (AffinityMask != affinityMask)
{ {
if ((AffinityMask & 1 << ActiveCore) != 0) if ((AffinityMask & 1UL << ActiveCore) != 0)
{ {
if (PreferredCore >= 0) if (PreferredCore >= 0)
{ {

View File

@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService
{ {
class ILibraryAppletProxy : IpcService class ILibraryAppletProxy : IpcService
{ {
private readonly long _pid; private readonly ulong _pid;
public ILibraryAppletProxy(long pid) public ILibraryAppletProxy(ulong pid)
{ {
_pid = pid; _pid = pid;
} }

View File

@ -4,9 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService
{ {
class ISystemAppletProxy : IpcService class ISystemAppletProxy : IpcService
{ {
private readonly long _pid; private readonly ulong _pid;
public ISystemAppletProxy(long pid) public ISystemAppletProxy(ulong pid)
{ {
_pid = pid; _pid = pid;
} }

View File

@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
{ {
class ISelfController : IpcService class ISelfController : IpcService
{ {
private readonly long _pid; private readonly ulong _pid;
private KEvent _libraryAppletLaunchableEvent; private KEvent _libraryAppletLaunchableEvent;
private int _libraryAppletLaunchableEventHandle; private int _libraryAppletLaunchableEventHandle;
@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
private uint _screenShotImageOrientation = 0; private uint _screenShotImageOrientation = 0;
private uint _idleTimeDetectionExtension = 0; private uint _idleTimeDetectionExtension = 0;
public ISelfController(ServiceCtx context, long pid) public ISelfController(ServiceCtx context, ulong pid)
{ {
_libraryAppletLaunchableEvent = new KEvent(context.Device.System.KernelContext); _libraryAppletLaunchableEvent = new KEvent(context.Device.System.KernelContext);
_pid = pid; _pid = pid;

View File

@ -4,9 +4,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
{ {
class IWindowController : IpcService class IWindowController : IpcService
{ {
private readonly long _pid; private readonly ulong _pid;
public IWindowController(long pid) public IWindowController(ulong pid)
{ {
_pid = pid; _pid = pid;
} }

View File

@ -5,9 +5,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService
{ {
class IApplicationProxy : IpcService class IApplicationProxy : IpcService
{ {
private readonly long _pid; private readonly ulong _pid;
public IApplicationProxy(long pid) public IApplicationProxy(ulong pid)
{ {
_pid = pid; _pid = pid;
} }

View File

@ -318,7 +318,7 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
// Pid placeholder // Pid placeholder
context.RequestData.ReadInt64(); context.RequestData.ReadInt64();
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
ulong playHistoryRegistrationKeyPosition = context.Request.PtrBuff[0].Position; ulong playHistoryRegistrationKeyPosition = context.Request.PtrBuff[0].Position;
ulong PlayHistoryRegistrationKeySize = context.Request.PtrBuff[0].Size; ulong PlayHistoryRegistrationKeySize = context.Request.PtrBuff[0].Size;

View File

@ -1021,7 +1021,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
HidVibrationDeviceType vibrationDeviceType = HidVibrationDeviceType.None; HidVibrationDeviceType vibrationDeviceType = HidVibrationDeviceType.None;
if (Enum.IsDefined(typeof(NpadStyleIndex), deviceType)) if (Enum.IsDefined<NpadStyleIndex>(deviceType))
{ {
vibrationDeviceType = HidVibrationDeviceType.LinearResonantActuator; vibrationDeviceType = HidVibrationDeviceType.LinearResonantActuator;
} }

View File

@ -210,7 +210,7 @@ namespace Ryujinx.HLE.HOS.Services
} }
else else
{ {
context.Device.System.KernelContext.Syscall.CreateSession(false, 0, out int serverSessionHandle, out int clientSessionHandle); context.Device.System.KernelContext.Syscall.CreateSession(out int serverSessionHandle, out int clientSessionHandle, false, 0);
obj.Server.AddSessionObj(serverSessionHandle, obj); obj.Server.AddSessionObj(serverSessionHandle, obj);

View File

@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// CountAddOnContent(pid) -> u32 // CountAddOnContent(pid) -> u32
public ResultCode CountAddOnContent(ServiceCtx context) public ResultCode CountAddOnContent(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// ListAddOnContent(u32 start_index, u32 buffer_size, pid) -> (u32 count, buffer<u32>) // ListAddOnContent(u32 start_index, u32 buffer_size, pid) -> (u32 count, buffer<u32>)
public ResultCode ListAddOnContent(ServiceCtx context) public ResultCode ListAddOnContent(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -75,7 +75,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// GetAddOnContentBaseId(pid) -> u64 // GetAddOnContentBaseId(pid) -> u64
public ResultCode GetAddOnContentBaseId(ServiceCtx context) public ResultCode GetAddOnContentBaseId(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// PrepareAddOnContent(u32 index, pid) // PrepareAddOnContent(u32 index, pid)
public ResultCode PrepareAddOnContent(ServiceCtx context) public ResultCode PrepareAddOnContent(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -123,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// GetAddOnContentListChangedEventWithProcessId(pid) -> handle<copy> // GetAddOnContentListChangedEventWithProcessId(pid) -> handle<copy>
public ResultCode GetAddOnContentListChangedEventWithProcessId(ServiceCtx context) public ResultCode GetAddOnContentListChangedEventWithProcessId(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -142,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// NotifyMountAddOnContent(pid, u64 title_id) // NotifyMountAddOnContent(pid, u64 title_id)
public ResultCode NotifyMountAddOnContent(ServiceCtx context) public ResultCode NotifyMountAddOnContent(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -160,7 +160,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// NotifyUnmountAddOnContent(pid, u64 title_id) // NotifyUnmountAddOnContent(pid, u64 title_id)
public ResultCode NotifyUnmountAddOnContent(ServiceCtx context) public ResultCode NotifyUnmountAddOnContent(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
@ -175,7 +175,7 @@ namespace Ryujinx.HLE.HOS.Services.Ns.Aoc
// CheckAddOnContentMountStatus(pid) // CheckAddOnContentMountStatus(pid)
public ResultCode CheckAddOnContentMountStatus(ServiceCtx context) public ResultCode CheckAddOnContentMountStatus(ServiceCtx context)
{ {
long pid = context.Request.HandleDesc.PId; ulong pid = context.Request.HandleDesc.PId;
// NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId. // NOTE: Service call arp:r GetApplicationLaunchProperty to get TitleId using the PId.
// Then it does some internal checks and returns InvalidBufferSize if they fail. // Then it does some internal checks and returns InvalidBufferSize if they fail.

View File

@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
public NvMemoryAllocator MemoryAllocator { get; } public NvMemoryAllocator MemoryAllocator { get; }
public Host1xDevice Host1x { get;} public Host1xDevice Host1x { get;}
public Host1xContext(GpuContext gpu, long pid) public Host1xContext(GpuContext gpu, ulong pid)
{ {
MemoryAllocator = new NvMemoryAllocator(); MemoryAllocator = new NvMemoryAllocator();
Host1x = new Host1xDevice(gpu.Synchronization); Host1x = new Host1xDevice(gpu.Synchronization);

View File

@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
public static IdDictionary DeviceFileIdRegistry = new IdDictionary(); public static IdDictionary DeviceFileIdRegistry = new IdDictionary();
private IVirtualMemoryManager _clientMemory; private IVirtualMemoryManager _clientMemory;
private long _owner; private ulong _owner;
private bool _transferMemInitialized = false; private bool _transferMemInitialized = false;
@ -53,7 +53,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
{ {
if (_deviceFileRegistry.TryGetValue(path, out Type deviceFileClass)) if (_deviceFileRegistry.TryGetValue(path, out Type deviceFileClass))
{ {
ConstructorInfo constructor = deviceFileClass.GetConstructor(new Type[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(long) }); ConstructorInfo constructor = deviceFileClass.GetConstructor(new Type[] { typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(ulong) });
NvDeviceFile deviceFile = (NvDeviceFile)constructor.Invoke(new object[] { context, _clientMemory, _owner }); NvDeviceFile deviceFile = (NvDeviceFile)constructor.Invoke(new object[] { context, _clientMemory, _owner });
@ -323,7 +323,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
_clientMemory = context.Process.HandleTable.GetKProcess(clientHandle).CpuMemory; _clientMemory = context.Process.HandleTable.GetKProcess(clientHandle).CpuMemory;
context.Device.System.KernelContext.Syscall.GetProcessId(clientHandle, out _owner); context.Device.System.KernelContext.Syscall.GetProcessId(out _owner, clientHandle);
context.ResponseData.Write((uint)NvResult.Success); context.ResponseData.Write((uint)NvResult.Success);

View File

@ -11,11 +11,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices
abstract class NvDeviceFile abstract class NvDeviceFile
{ {
public readonly ServiceCtx Context; public readonly ServiceCtx Context;
public readonly long Owner; public readonly ulong Owner;
public string Path; public string Path;
public NvDeviceFile(ServiceCtx context, long owner) public NvDeviceFile(ServiceCtx context, ulong owner)
{ {
Context = context; Context = context;
Owner = owner; Owner = owner;

View File

@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
private readonly AddressSpaceContext _asContext; private readonly AddressSpaceContext _asContext;
private readonly NvMemoryAllocator _memoryAllocator; private readonly NvMemoryAllocator _memoryAllocator;
public NvHostAsGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) public NvHostAsGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{ {
_asContext = new AddressSpaceContext(context.Device.Gpu.CreateMemoryManager(owner)); _asContext = new AddressSpaceContext(context.Device.Gpu.CreateMemoryManager(owner));
_memoryAllocator = new NvMemoryAllocator(); _memoryAllocator = new NvMemoryAllocator();

View File

@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
{ {
class NvHostChannelDeviceFile : NvDeviceFile class NvHostChannelDeviceFile : NvDeviceFile
{ {
private static readonly ConcurrentDictionary<long, Host1xContext> _host1xContextRegistry = new(); private static readonly ConcurrentDictionary<ulong, Host1xContext> _host1xContextRegistry = new();
private const uint MaxModuleSyncpoint = 16; private const uint MaxModuleSyncpoint = 16;
@ -45,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
private NvFence _channelSyncpoint; private NvFence _channelSyncpoint;
public NvHostChannelDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) public NvHostChannelDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{ {
_device = context.Device; _device = context.Device;
_memory = memory; _memory = memory;
@ -556,9 +556,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
_channelSyncpoint.Id = 0; _channelSyncpoint.Id = 0;
} }
private static Host1xContext GetHost1XContext(GpuContext gpu, long pid) private static Host1xContext GetHost1XContext(GpuContext gpu, ulong pid)
{ {
return _host1xContextRegistry.GetOrAdd(pid, (long key) => new Host1xContext(gpu, key)); return _host1xContextRegistry.GetOrAdd(pid, (ulong key) => new Host1xContext(gpu, key));
} }
public static void Destroy() public static void Destroy()

View File

@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
private int _smExceptionBptPauseReportEventHandle; private int _smExceptionBptPauseReportEventHandle;
private int _errorNotifierEventHandle; private int _errorNotifierEventHandle;
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner) public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, memory, owner)
{ {
_smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle); _smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle);
_smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle); _smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle);

View File

@ -20,7 +20,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
private Switch _device; private Switch _device;
private NvHostEvent[] _events; private NvHostEvent[] _events;
public NvHostCtrlDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) public NvHostCtrlDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{ {
if (NxSettings.Settings.TryGetValue("nv!rmos_set_production_mode", out object productionModeSetting)) if (NxSettings.Settings.TryGetValue("nv!rmos_set_production_mode", out object productionModeSetting))
{ {

View File

@ -16,7 +16,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu
private KEvent _errorEvent; private KEvent _errorEvent;
private KEvent _unknownEvent; private KEvent _unknownEvent;
public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) public NvHostCtrlGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{ {
_errorEvent = new KEvent(context.Device.System.KernelContext); _errorEvent = new KEvent(context.Device.System.KernelContext);
_unknownEvent = new KEvent(context.Device.System.KernelContext); _unknownEvent = new KEvent(context.Device.System.KernelContext);

View File

@ -11,9 +11,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
{ {
private const int FlagNotFreedYet = 1; private const int FlagNotFreedYet = 1;
private static ConcurrentDictionary<long, IdDictionary> _maps = new ConcurrentDictionary<long, IdDictionary>(); private static ConcurrentDictionary<ulong, IdDictionary> _maps = new ConcurrentDictionary<ulong, IdDictionary>();
public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, owner) public NvMapDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, ulong owner) : base(context, owner)
{ {
IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary()); IdDictionary dict = _maps.GetOrAdd(Owner, (key) => new IdDictionary());
@ -237,7 +237,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
return dict.Add(map); return dict.Add(map);
} }
private static bool DeleteMapWithHandle(long pid, int handle) private static bool DeleteMapWithHandle(ulong pid, int handle)
{ {
if (_maps.TryGetValue(pid, out IdDictionary dict)) if (_maps.TryGetValue(pid, out IdDictionary dict))
{ {
@ -247,12 +247,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
return false; return false;
} }
public static void IncrementMapRefCount(long pid, int handle) public static void IncrementMapRefCount(ulong pid, int handle)
{ {
GetMapFromHandle(pid, handle)?.IncrementRefCount(); GetMapFromHandle(pid, handle)?.IncrementRefCount();
} }
public static bool DecrementMapRefCount(long pid, int handle) public static bool DecrementMapRefCount(ulong pid, int handle)
{ {
NvMapHandle map = GetMapFromHandle(pid, handle); NvMapHandle map = GetMapFromHandle(pid, handle);
@ -275,7 +275,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
} }
} }
public static NvMapHandle GetMapFromHandle(long pid, int handle) public static NvMapHandle GetMapFromHandle(ulong pid, int handle)
{ {
if (_maps.TryGetValue(pid, out IdDictionary dict)) if (_maps.TryGetValue(pid, out IdDictionary dict))
{ {

Some files were not shown because too many files have changed in this diff Show More