Commit graph

2027 commits

Author SHA1 Message Date
Mary 5c66a36ed6
kernel: Fix inverted condition on permission check of SetMemoryPermission syscall (#2777)
* kernel: Fix inverted condition on permission check of SetMemoryPermission syscall

* Fix condition for real..
2021-10-24 20:00:31 -03:00
gdkchan 04dfb86fde
Preserve image types for shader bindless surface instructions (.D variants) (#2779)
* Preserve image types for SULD/SUST .D variants

* Make format unknown for surface atomic if bindless and not sized
2021-10-24 19:40:20 -03:00
Mary 51fa1b2cb0
hle: Improve safety (#2778)
* timezone: Make timezone implementation safe

* hle: Do not use TrimEnd to parse ASCII strings

This adds an util that handle reading an ASCII string in a safe way.
Previously it was possible to read malformed data that could cause
various undefined behaviours in multiple services.

* hid: Remove an useless unsafe modifier on keyboard update

* Address gdkchan's comment

* Address gdkchan's comment
2021-10-24 19:13:20 -03:00
Mary b4dc33efc2
kernel: Clear pages allocated with SetHeapSize (#2776)
* kernel: Clear pages allocated with SetHeapSize

Before this commit, all new pages allocated by SetHeapSize were not
cleared by the kernel.

This would cause undefined data to be pass to the userland and possibly
resulting in weird memory corruption.

This commit also add support for custom fill heap and ipc value (that is also
supported by the official kernel)

* Remove dots at the end of KPageTableBase.MapPages new documentation

* Remove unused _stackFillValue
2021-10-24 18:52:59 -03:00
Billy Laws 8c4e4ab3b3
Fixup channel submit IOCTL syncpoint parameters (#2774)
* Fixup channel submit IOCTL syncpoint parameters

The current arguments worked by happenstance as games only ever submit
one syncpoint and request one fence back, if a game were to do something
other than this then the arguments would've been parsed entirely wrong.

* Address feedback
2021-10-24 18:34:44 -03:00
Mary 85d8d1d7ca
misc: Fix IVirtualMemoryManager.Fill ignoring value (#2775)
This fix IVirtualMemoryManager.Fill to actually use the provided fill
value instead of 0.

This have no implication at the moment as everything that use it pass 0
but it is needed for some upcoming kernel fixes.
2021-10-24 18:16:59 -03:00
Mary dc837c0042
kernel: Add resource limit related syscalls (#2773)
* kernel: Add resource limit related syscalls

This commit implements all resource limit related syscalls.

* Fix register mapping being wrong for SetResourceLimitLimitValue

* Address gdkchan's comment
2021-10-24 01:40:13 +02:00
Mary c94d47cc40
kernel: Implement SetMemoryPermission syscall (#2772)
* kernel: Implement SetMemoryPermission syscall

This commit implement the SetMemoryPermission syscall accurately.
This also fix KMemoryPermission not being an unsigned 32 bits type and
add the "DontCare" bit (used by shared memory, currently unused in
Ryujinx)

* Update MemoryPermission mask

* Address gdkchan's comments

* Fix a nit

* Address gdkchan's comment
2021-10-24 01:24:49 +02:00
Mary e7e65ccbc9
kernel: Add missing address space check in SetMemoryAttribute syscall (#2771) 2021-10-24 01:07:41 +02:00
gdkchan 0d174cbd45
EventWait should not signal the event when it returns Success (#2739)
* Fix race when EventWait is called and a wait is done on the CPU

* This is useless now

* Fix EventSignal

* Ensure the signal belongs to the current fence, to avoid stale signals
2021-10-19 17:25:32 -03:00
gdkchan 63f1663fa9
Fix shader 8-bit and 16-bit STS/STG (#2741)
* Fix 8 and 16-bit STG

* Fix 8 and 16-bit STS

* Shader cache version bump
2021-10-18 20:24:15 -03:00
riperiperi 052deebf26
Another workaround for NVIDIA driver 496.13 shader bug (#2750)
* Another workaround for NVIDIA driver 496.13 shader bug

This might work better than the other one. Give this a test to see if it fixes/doesn't fix issues with the other one.

The problem seems to be when any variable assignment happens with a negation. `temp_1 = -temp_0;` seems to trigger weird behaviour, but `temp_1 = 0.0 - temp_0;` does not. This also might to extend towards integer types?

* Update cache version

* Add disclaimer comment

* Wording
2021-10-18 20:04:06 -03:00
FICTURE7 fbf40424f4
Add an early TailMerge pass (#2721)
* Add an early `TailMerge` pass

Some translations can have a lot of guest calls and since for each guest
call there is a call guard which may return. This can produce a lot of
epilogue code for returns. This pass merges the epilogue into a single
block.

```
Using filter 'hcq'.
Using metric 'code size'.

Total diff: -1648111 (-7.19 %) (bytes):
  Base: 22913847
  Diff: 21265736

Improved: 4567, regressed: 14, unchanged: 144
```

* Set PTC version

* Address feedback

* Handle `void` returning functions

* Actually handle `void` returning functions

* Fix `RegisterToLocal` logging
2021-10-18 19:51:22 -03:00
gdkchan d512ce122c
Initial tessellation shader support (#2534)
* Initial tessellation shader support

* Nits

* Re-arrange built-in table

* This is not needed anymore

* PR feedback
2021-10-18 18:38:04 -03:00
gdkchan 7603dbe3c8
Add missing U8/S8 types from shader I2I instruction (#2740)
* Add missing U8/S8 types from shader I2I instruction

* Better names

* Fix dstIsSignedInt
2021-10-17 17:48:36 -03:00
gdkchan 25fd4ef10e
Extend bindless elimination to work with masked and shifted handles (#2727)
* Extent bindless elimination to work with masked handles

* Extend bindless elimination to catch shifted pattern, refactor handle packing/unpacking
2021-10-17 17:28:18 -03:00
gdkchan d05573bfd1
Implement SHF (funnel shift) shader instruction (#2702)
* Implement SHF shader instruction

* Shader cache version bump

* Better name
2021-10-17 17:02:20 -03:00
Caian Benedicto 1b81653478
Fix regression with foreground software keyboard (#2732) 2021-10-13 12:20:48 -03:00
gdkchan 464a92d8a7
Force index buffer update for games using Vulkan (#2726) 2021-10-12 23:46:42 +02:00
riperiperi a2c6cd5132
Enqueue frame before signalling the frame is ready. (#2722)
It seems that certain games (Link's Awakening, Xenoblade DE) had their fences reached already when posting framebuffers, so the signal that a frame was ready would go out _before_ the frame was enqueued, and the render loop would fail to dequeue anything and "skip" a frame.

This was resulting in their performance lowering dramatically after some loading transitions, as a frame signal would be consumed and presentation would be one frame behind.

It's possible this might have eventually caused deadlocks in these games or others, if it happened twice.
2021-10-12 23:29:50 +02:00
riperiperi 0bce4a074a
Don't force scaling on 2D copy sources (#2701)
Some games (GameMaker Studio) build texture atlases out of sprites during initialization, using the 2D copy method. These copies are done from textures loaded into memory, not rendered, so they are not scaled to begin with.

I had set srcTexture in these copies to force scaling, but really it only needs to scale if the texture already exists and was scaled by rendering or something else. I just set that to false, so it doesn't change if the texture is scaled or not. This will also avoid the destination being scaled if the source wasn't. The copy can handle mismatching scales just fine.

This prevents scaling artifacts in GMS games, and maybe others (not Super Mario Maker 2, that has another issue).
2021-10-12 23:12:17 +02:00
Ac_K d1604aa762
nvdec: Adding Vp8 codec support (#2707)
* first try

* second try

* working update

* Final impl

* Fixes nits

* Fix everything

* remove leftover

* Update FFmpegContext.cs

* Update Surface.cs

* Addresses gdkchan feedback

* bool not byte

* Addresses gdkchan feedback
2021-10-12 22:55:57 +02:00
gdkchan a7109c767b
Rewrite shader decoding stage (#2698)
* Rewrite shader decoding stage

* Fix P2R constant buffer encoding

* Fix PSET/PSETP

* PR feedback

* Log unimplemented shader instructions

* Implement NOP

* Remove using

* PR feedback
2021-10-12 22:35:31 +02:00
Ac_K 0510fde25a
spl: Implement IGeneralInterface GetConfig (#2705)
* spl: Implement IGeneralInterface GetConfig

This PR implement the GetConfig call of the spl service. This is currently needed for some homebrews which currently needs Ignore Missing Service to boot. Now it's fixed.
Implementation was done using Atmosphère code and REing too.

* Addresses gdkchan feedback
2021-10-12 22:15:55 +02:00
Caian Benedicto 380b95bc59
Inline software keyboard without input pop up dialog (#2180)
* Initial implementation

* Refactor dynamic text input keys out to facilitate configuration via UI

* Fix code styling

* Add per applet indirect layer handles

* Remove static functions from SoftwareKeyboardRenderer

* Remove inline keyboard reset delay

* Remove inline keyboard V2 responses

* Add inline keyboard soft-lock recovering

* Add comments

* Forward accept and cancel key names to the keyboard and add soft-lock prevention line

* Add dummy window to handle paste events

* Rework inline keyboard state machine and graphics

* Implement IHostUiHandler interfaces on headless WindowBase class

* Add inline keyboard assets

* Fix coding style

* Fix coding style

* Change mode cycling shortcut to F6

* Fix invalid calc size error in games using extended calc

* Remove unnecessary namespaces
2021-10-12 21:54:21 +02:00
FICTURE7 69093cf2d6
Optimize LSRA (#2563)
* Optimize `TryAllocateRegWithtoutSpill` a bit

* Add a fast path for when all registers are live.
* Do not query `GetOverlapPosition` if the register is already in use
  (i.e: free position is 0).

* Do not allocate child split list if not parent

* Turn `LiveRange` into a reference struct

`LiveRange` is now a reference wrapping struct like `Operand` and
`Operation`.

It has also been changed into a singly linked-list. In micro-benchmarks
traversing the linked-list was faster than binary search on `List<T>`.
Even for quite large input sizes (e.g: 1,000,000), surprisingly.

Could be because the code gen for traversing the linked-list is much
much cleaner and there is no virtual dispatch happening when checking if
intervals overlaps.

* Turn `LiveInterval` into an iterator

The LSRA allocates in forward order and never inspect previous
`LiveInterval` once they are expired. Something similar can be done for
the `LiveRange`s within the `LiveInterval`s themselves.

The `LiveInterval` is turned into a iterator which expires `LiveRange`
within it. The iterator is moved forward along with interval walking
code, i.e: AllocateInterval(context, interval, cIndex).

* Remove `LinearScanAllocator.Sources`

Local methods are less susceptible to do allocations than lambdas.

* Optimize `GetOverlapPosition(interval)` a bit

Time complexity should be in O(n+m) instead of O(nm) now.

* Optimize `NumberLocals` a bit

Use the same idea as in `HybridAllocator` to store the visited state
in the MSB of the Operand's value instead of using a `HashSet<T>`.

* Optimize `InsertSplitCopies` a bit

Avoid allocating a redundant `CopyResolver`.

* Optimize `InsertSplitCopiesAtEdges` a bit

Avoid redundant allocations of `CopyResolver`.

* Use stack allocation for `freePositions`

Avoid redundant computations.

* Add `UseList`

Replace `SortedIntegerList` with an even more specialized data
structure. It allocates memory on the arena allocators and does not
require copying use positions when splitting it.

* Turn `LiveInterval` into a reference struct

`LiveInterval` is now a reference wrapping struct like `Operand` and
`Operation`.

The rationale behind turning this in a reference wrapping struct is
because a `LiveInterval` is associated with each local variable, and
these intervals may themselves be split further. I've seen translations
having up to 8000 local variables.

To make the `LiveInterval` unmanaged, a new data structure called
`LiveIntervalList` was added to store child splits. This differs from
`SortedList<,>` because it can contain intervals with the same start
position.

Really wished we got some more of C++ template in C#. :^(

* Optimize `GetChildSplit` a bit

No need to inspect the remaining ranges if we've reached a range which
starts after position, since the split list is ordered.

* Optimize `CopyResolver` a bit

Lazily allocate the fill, spill and parallel copy structures since most
of the time only one of them is needed.

* Optimize `BitMap.Enumerator` a bit

Marking `MoveNext` as `AggressiveInlining` allows RyuJIT to promote the
`Enumerator` struct into registers completely, reducing load/store code
a lot since it does not have to store the struct on the stack for ABI
purposes.

* Use stack allocation for `use/blockedPositions`

* Optimize `AllocateWithSpill` a bit

* Address feedback

* Make `LiveInterval.AddRange(,)` more conservative

Produces no diff against master, but just for good measure.
2021-10-08 18:15:44 -03:00
C1fer c54a14d0b8
Added support for Pixel Format X8B8G8R8 (#2716)
* Added support for Pixel Format X8B8G8R8        

Fixes cutscenes on Metroid Dread.

* Removed unnecessary case execution.

* Update Ryujinx.Graphics.Vic/Image/SurfaceWriter.cs

Co-authored-by: gdkchan <gab.dark.100@gmail.com>

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-10-07 18:41:02 -03:00
riperiperi 468774578d
Merge pull request #2713 from riperiperi/fix/modified-inherit
Reregister flush actions when taking a buffer's modified range list.
2021-10-07 13:43:31 +01:00
riperiperi a4956591ec Avoid potential race 2021-10-07 01:13:51 +01:00
riperiperi c61c1ea898 Reregister flush actions when taking a buffer's modified range list.
Fixes a regression from #2663 where buffer flush would not happen after a resize. Specifically caused the world map in Yoshi's Crafted World to flash.

I have other planned changes to this class so this might change soon, but this regression could affect a lot so it couldn't wait.
2021-10-07 00:00:56 +01:00
FICTURE7 ecc64c934d
Add Operand.Label support to Assembler (#2680)
* Add `Operand.Label` support to `Assembler`

This adds label support to `Assembler` and enables branch tightening
when compiling with relocatables. Jump management and patching has been
moved to the `Assembler`.

* Move instruction table to `Assembler.Table`

* Set PTC internal version

* Rename `Assembler.Table` to `AssemblerTable`
2021-10-05 14:04:55 -03:00
gdkchan 11b437eafc
Fix DisplayInfo struct (#2708) 2021-10-05 12:38:44 -03:00
riperiperi fff48bb45a
Smaller initial size for ModifiedRangeList & directly inherit range list (#2663)
This fixes a potential regression with the new range list changes, where the cost for creating new ones would be rather large due to creating a 1024 size array. Also reduces cost for range list inheritance by using the first existing range list as a base, rather than creating a new one then adding both lists to it.

The growth size for the RangeList is now identical to its initial size. Every 32 elements was probably a little too common - now it is 1024 for most things and 8 for the buffer modified range list.

The Unmapped and SyncMethod methods have been changed to ensure that they behave properly if the range list is set null. Cleaned up a few calls to use the null-conditional operator.
2021-10-04 15:38:59 -03:00
gdkchan 75f4b1ff2d
Relax sampler pool requirement (#2703) 2021-10-04 14:35:28 -03:00
gdkchan f7aaea4300
Unref frames before decoding with FFMPEG (#2704) 2021-10-04 14:12:24 -03:00
riperiperi d92fff541b
Replace CacheResourceWrite with more general "precise" write (#2684)
* Replace CacheResourceWrite with more general "precise" write

The goal of CacheResourceWrite was to notify GPU resources when they were modified directly, by looking up the modified address/size in a structure and calling a method on each resource. The downside of this is that each resource cache has to be queried individually, they all have to implement their own way to do this, and it can only signal to resources using the same PhysicalMemory instance.

This PR adds the ability to signal a write as "precise" on the tracking, which signals a special handler (if present) which can be used to avoid unnecessary flush actions, or maybe even more. For buffers, precise writes specifically do not flush, and instead punch a hole in the modified range list to indicate that the data on GPU has been replaced.

The downside is that precise actions must ignore the page protection bits and always signal - as they need to notify the target resource to ignore the sequence number optimization.

I had to reintroduce the sequence number increment after I2M, as removing it was causing issues in rabbids kingdom battle. However - all resources modified by I2M are notified directly to lower their sequence number, so the problem is likely that another unrelated resource is not being properly updated. Thankfully, doing this does not affect performance in the games I tested.

This should fix regressions from #2624. Test any games that were broken by that. (RF4, rabbids kingdom battle)

I've also added a sequence number increment to ThreedClass.IncrementSyncpoint, as it seems to fix buffer corruption in OpenGL homebrew. (this was a regression from removing sequence number increment from constant buffer update - another unrelated resource thing)

* Add tests.

* Add XML docs for GpuRegionHandle

* Skip UpdateProtection if only precise actions were called

This allows precise actions to skip reprotection costs.
2021-09-29 02:27:03 +02:00
riperiperi b6e093b0fc
Force copy when auto-deleting a texture with dependencies (#2687)
When a texture is deleted by falling to the bottom of the AutoDeleteCache, its data is flushed to preserve any GPU writes that occurred. This ensures that the data appears in any textures recreated in the future, but didn't account for a texture that already existed with a copy dependency.

This change forces copy dependencies to complete if a texture falls out from from the AutoDeleteCache. (not removed via overlap, as that would be wasted effort)

Fixes broken lighting caused by pausing in SMO's Metro Kingdom. May fix some other issues.
2021-09-29 02:11:05 +02:00
gdkchan fd7567a6b5
Only make render target 2D textures layered if needed (#2646)
* Only make render target 2D textures layered if needed

* Shader cache version bump

* Ensure topology is updated on channel swap
2021-09-29 01:55:12 +02:00
FICTURE7 312be74861
Optimize HybridAllocator (#2637)
* Store constant `Operand`s in the `LocalInfo`

Since the spill slot and register assigned is fixed, we can just store
the `Operand` reference in the `LocalInfo` struct. This allows skipping
hitting the intern-table for a look up.

* Skip `Uses`/`Assignments` management

Since the `HybridAllocator` is the last pass and we do not care about
uses/assignments we can skip managing that when setting destinations or
sources.

* Make `GetLocalInfo` inlineable

Also fix a possible issue where with numbered locals. See or-assignment
operator in `SetVisited(local)` before patch.

* Do not run `BlockPlacement` in LCQ

With the host mapped memory manager, there is a lot less cold code to
split from hot code. So disabling this in LCQ gives some extra
throughput - where we need it.

* Address Mou-Ikkai's feedback

* Apply suggestions from code review

Co-authored-by: VocalFan <45863583+Mou-Ikkai@users.noreply.github.com>

* Move check to an assert

Co-authored-by: VocalFan <45863583+Mou-Ikkai@users.noreply.github.com>
2021-09-29 01:38:37 +02:00
riperiperi 1ae690ba2f
Use normal memory store path for DC ZVA (#2693)
Seems like this is used as an optimized way to clear memory in homebrew applications. Unfortunately, calling the software fallback method every 8 bytes was not very optimal.

The existing EmitStore is used by passing in ZR as the register to get a 0 write.
2021-09-29 01:21:30 +02:00
Ac_K 33dc4c9ce4
clkrst: Stub/Implement IClkrstManager and IClkrstSession calls (#2692)
This PR stubs and implements some clkrst call because they are used to overclock the Switch hardware and it's pointless in our case as we emulate the system.
Everything was done checked by RE.

Fixes #2686
2021-09-29 01:03:35 +02:00
gdkchan f4f496cb48
NVDEC (H264): Use separate contexts per channel and decode frames in DTS order (#2671)
* Use separate NVDEC contexts per channel (for FFMPEG)

* Remove NVDEC -> VIC frame override hack

* Add missing bottom_field_pic_order_in_frame_present_flag

* Make FFMPEG logging static

* nit: Remove empty lines

* New FFMPEG decoding approach -- call h264_decode_frame directly, trim surface cache to reduce memory usage

* Fix case

* Silence warnings

* PR feedback

* Per-decoder rather than per-codec ownership of surfaces on the cache
2021-09-29 00:43:40 +02:00
FICTURE7 0d23504e30
Fix PTC count table relocation patching (#2666)
Fix an issue introduced in #2190 where by 2 different count table entry
addresses were used for LCQ functions. E.g:

```asm
 .L1:
   mov rbp,COUNT_TABLE_0   ;; This gets an address.
   mov ebp,[rbp]
   lea esi,[rbp+1]
   mov rdi,COUNT_TABLE_1   ;; This gets another address.
   mov [rdi],esi
   cmp ebp,64h
   je near .L34
```

This caused LCQ functions to not tier up when they're loaded from the
PTC cache. This does not happen when they're freshly compiled.

This PR fixes the issue by ensuring only a single counter is created per
translation.
2021-09-29 00:28:34 +02:00
Ac_K 79c854dd2e
irs: Stub some service calls (#2665)
This PR stubs some irs service calls which are needed to get some games playable or at least bootable since we don't support IR data throught real JoyCon for now.

- Stubs `IIrSensorServer` `StopImageProcessor`, `RunMomentProcessor`, `RunClusteringProcessor`, `RunImageTransferProcessor`, `GetImageTransferProcessorState`, `RunTeraPluginProcessor`. All calls are a bit checked by RE.

Closes #2267, #2248, #2126

Night Vision and SpyAlarm are now bootable (but still unplayable due to the lack of the IR data):
2021-09-29 00:10:10 +02:00
gdkchan 83bdafccda
Share scales array for graphics and compute (#2653) 2021-09-28 23:52:27 +02:00
VocalFan 405840a24b
Quick README update for game compatibility. (#2694) 2021-09-28 23:26:45 +02:00
riperiperi 7c5ead1c19
Fast path for Inline2Memory buffer write that skips write tracking (#2624)
* Fast path for Inline2Memory buffer write

This PR adds a method to PhysicalMemory that attempts to write all cached resources directly, so that memory tracking can be avoided. The goal of this is both to avoid flushing buffer data, and to avoid raising the sequence number when data is written, which causes buffer and texture handles to be re-checked.

This currently only targets buffers, with a side check on textures that falls back to a tracked write if any exist within the target range. It's not expected to write textures from here - this is just a mechanism to protect us if someone does decide to do that. It's possible to add a fast path for this in future (and for ShaderCache, once that starts using tracking)

The forced read before inline2memory begins has been skipped, as the data is fully written when the transfer is completed anyways. This allows us to flush on read in emergency situations, but still write the new data over the flushed data.

Improves performance on Xenoblade 2 and DE, which was flushing buffer data on the GPU thread when trying to write compute data. May improve performance in other games that write SSBOs from compute, and update data in the same/nearby pages often.

Super Smash Bros Ultimate should probably be tested to make sure the vertex explosions haven't returned, as I think that's what this AdvanceSequence was for.

* ForceDirty before write, to make sure data does not flush over the new write
2021-09-19 15:09:53 +02:00
riperiperi db97b1d7d2
Implement and use an Interval Tree for the MultiRangeList (#2641)
* Implement and use an Interval Tree for the MultiRangeList

* Feedback

* Address Feedback

* Missed this somehow
2021-09-19 14:55:07 +02:00
gdkchan f08a280ade
Use shader subgroup extensions if shader ballot is not supported (#2627)
* Use shader subgroup extensions if shader ballot is not supported

* Shader cache version bump + cleanup

* The type is still required on the table
2021-09-19 14:38:39 +02:00
riperiperi 7379bc2f39
Array based RangeList that caches Address/EndAddress (#2642)
* Array based RangeList that caches Address/EndAddress

In isolation, this was more than 2x faster than the RangeList that checks using the interface. In practice I'm seeing much better results than I expected. The array is used because checking it is slightly faster than using a list, which loses time to struct copies, but I still want that data locality.

A method has been added to the list to update the cached end address, as some users of the RangeList currently modify it dynamically.

Greatly improves performance in Super Mario Odyssey, Xenoblade and any other GPU limited games.

* Address Feedback
2021-09-19 14:22:26 +02:00