Commit graph

973 commits

Author SHA1 Message Date
Fernando Sahmkow 94f2be5473 texture_cache: Optimize GetMipBlockHeight and GetMipBlockDepth 2019-06-20 21:36:12 -03:00
ReinUsesLisp 345e73f2fe video_core: Use un-shifted block sizes to avoid integer divisions
Instead of storing all block width, height and depths in their shifted
form:

block_width = 1U << block_shift;

Store them like they are provided by the emulated hardware (their
block_shift form). This way we can avoid doing the costly
Common::AlignUp operation to align texture sizes and drop CPU integer
divisions with bitwise logic (defined in Common::AlignBits).
2019-06-20 21:36:12 -03:00
Fernando Sahmkow b347543e83 Reduce amount of size calculations. 2019-06-20 21:36:12 -03:00
Lioncash 969cd6dc1d
common/hex_util: Reserve std::string memory ahead of time
Avoids potentially performing multiple reallocations (depending on the
size of the input data) by reserving the necessary amount of memory
ahead of time.

This is trivially doable, so there's no harm in it.
2019-06-12 17:54:11 -04:00
Lioncash a62088539e
common/hex_util: Combine HexVectorToString() and HexArrayToString()
These can be generified together by using a concept type to designate
them. This also has the benefit of not making copies of potentially very
large arrays.
2019-06-12 17:54:05 -04:00
ReinUsesLisp dec1cbaf7f cmake: Add missing shader hash file entries 2019-06-06 20:11:48 -03:00
Lioncash 1edf018319 common/math_util: Provide a template deduction guide for Common::Rectangle
Allows for things such as:

auto rect = Common::Rectangle{0, 0, 0, 0};

as opposed to being required to explicitly write out the underlying
type, such as:

auto rect = Common::Rectangle<int>{0, 0, 0, 0};

The only requirement for the deduction is that all constructor arguments
be the same type.
2019-05-31 04:44:02 -03:00
bunnei ed74a3cb8b
Merge pull request #1931 from DarkLordZach/mii-database-1
mii: Implement MiiManager backend and several mii service commands
2019-05-30 13:26:40 -04:00
Lioncash e7ab0e9127 common/file_util: Remove unnecessary return at end of void StripTailDirSlashes()
While we're at it, also invert the conditional into a guard clause.
2019-05-23 14:33:29 -04:00
Lioncash 11e9bee91d common/file_util: Make GetCurrentDir() return a std::optional
nullptr was being returned in the error case, which, at a glance may
seem perfectly OK... until you realize that std::string has the
invariant that it may not be constructed from a null pointer. This
means that if this error case was ever hit, then the application would
most likely crash from a thrown exception in std::string's constructor.

Instead, we can change the function to return an optional value,
indicating if a failure occurred.
2019-05-23 14:24:13 -04:00
Lioncash 943f6da1ac common/file_util: Remove duplicated documentation comments
These are already present within the header, so they don't need to be
repeated in the cpp file.
2019-05-23 14:22:12 -04:00
Lioncash 2b1fcc8a14 common/file_util: Make ReadFileToString and WriteStringToFile consistent
Makes the parameter ordering consistent, and also makes the filename
parameter a std::string. A std::string would be constructed anyways with
the previous code, as IOFile's only constructor with a filepath is one
taking a std::string.

We can also make WriteStringToFile's string parameter utilize a
std::string_view for the string, making use of our previous changes to
IOFile.
2019-05-23 13:52:43 -04:00
Lioncash e3b2539986 common/file_util: Remove unnecessary c_str() calls
The file stream open functions have supported std::string overloads
since C++11, so we don't need to use c_str() here. Same behavior, less
code.
2019-05-23 13:37:47 -04:00
Lioncash 8cd3d9be26 common/file_util: Make IOFile's WriteString take a std::string_view
We don't need to force the usage of a std::string here, and can instead
use a std::string_view, which allows writing out other forms of strings
(e.g. C-style strings) without any unnecessary heap allocations.
2019-05-23 13:35:31 -04:00
Lioncash a6f7a44aab
common/zstd_compression: Remove #pragma once directive from source file
Introduced in 72477731ed. This is only
necessary within header files.
2019-05-04 01:54:29 -04:00
Zach Hilman 1aa2b99a98 mii: Implement Delete and Destroy file 2019-04-25 08:07:57 -04:00
Zach Hilman f0db2e3ef3 mii_manager: Cleanup and optimization 2019-04-25 08:07:57 -04:00
Zach Hilman ca5638a142 common: Extract UUID to its own class
Since the Mii database uses UUIDs very similar to the Accounts database, it makes no sense to not share code between them.
2019-04-25 08:07:57 -04:00
Lioncash 4620ed47a3 common/{lz4_compression, zstd_compression}: Add missing header guards
These two files were missing the #pragma once directive.
2019-04-15 13:00:08 -04:00
bunnei b42595fa6b
Merge pull request #2391 from lioncash/scope
common/scope_exit: Replace std::move with std::forward in ScopeExit()
2019-04-12 21:52:35 -04:00
Lioncash 0d8ef2d3b9 common/swap: Improve codegen of the default swap fallbacks
Uses arithmetic that can be identified more trivially by compilers for
optimizations. e.g. Rather than shifting the halves of the value and
then swapping and combining them, we can swap them in place.

e.g. for the original swap32 code on x86-64, clang 8.0 would generate:

    mov     ecx, edi
    rol     cx, 8
    shl     ecx, 16
    shr     edi, 16
    rol     di, 8
    movzx   eax, di
    or      eax, ecx
    ret

while GCC 8.3 would generate the ideal:

    mov     eax, edi
    bswap   eax
    ret

now both generate the same optimal output.

MSVC used to generate the following with the old code:

    mov     eax, ecx
    rol     cx, 8
    shr     eax, 16
    rol     ax, 8
    movzx   ecx, cx
    movzx   eax, ax
    shl     ecx, 16
    or      eax, ecx
    ret     0

Now MSVC also generates a similar, but equally optimal result as clang/GCC:

    bswap   ecx
    mov     eax, ecx
    ret     0

====

In the swap64 case, for the original code, clang 8.0 would generate:

    mov     eax, edi
    bswap   eax
    shl     rax, 32
    shr     rdi, 32
    bswap   edi
    or      rax, rdi
    ret

(almost there, but still missing the mark)

while, again, GCC 8.3 would generate the more ideal:

    mov     rax, rdi
    bswap   rax
    ret

now clang also generates the optimal sequence for this fallback as well.

This is a case where MSVC unfortunately falls short, despite the new
code, this one still generates a doozy of an output.

    mov     r8, rcx
    mov     r9, rcx
    mov     rax, 71776119061217280
    mov     rdx, r8
    and     r9, rax
    and     edx, 65280
    mov     rax, rcx
    shr     rax, 16
    or      r9, rax
    mov     rax, rcx
    shr     r9, 16
    mov     rcx, 280375465082880
    and     rax, rcx
    mov     rcx, 1095216660480
    or      r9, rax
    mov     rax, r8
    and     rax, rcx
    shr     r9, 16
    or      r9, rax
    mov     rcx, r8
    mov     rax, r8
    shr     r9, 8
    shl     rax, 16
    and     ecx, 16711680
    or      rdx, rax
    mov     eax, -16777216
    and     rax, r8
    shl     rdx, 16
    or      rdx, rcx
    shl     rdx, 16
    or      rax, rdx
    shl     rax, 8
    or      rax, r9
    ret     0

which is pretty unfortunate.
2019-04-12 00:07:39 -04:00
Lioncash 66b73fd399 common/swap: Mark byte swapping free functions with [[nodiscard]] and noexcept
Allows the compiler to inform when the result of a swap function is
being ignored (which is 100% a bug in all usage scenarios). We also mark
them noexcept to allow other functions using them to be able to be
marked as noexcept and play nicely with things that potentially inspect
"nothrowability".
2019-04-11 20:42:44 -04:00
Lioncash 9cb4b7be40 common/swap: Simplify swap function ifdefs
Including every OS' own built-in byte swapping functions is kind of
undesirable, since it adds yet another build path to ensure compilation
succeeds on.

Given we only support clang, GCC, and MSVC for the time being, we can
utilize their built-in functions directly instead of going through the
OS's API functions.

This shrinks the overall code down to just

if (msvc)
  use msvc's functions
else if (clang or gcc)
  use clang/gcc's builtins
else
  use the slow path
2019-04-11 20:36:19 -04:00
Lioncash 598954436f common/swap: Remove 32-bit ARM path
We don't plan to support host 32-bit ARM execution environments, so this
is essentially dead code.
2019-04-11 20:15:47 -04:00
Lioncash b569641098 common/scope_exit: Replace std::move with std::forward in ScopeExit()
The template type here is actually a forwarding reference, not an rvalue
reference in this case, so it's more appropriate to use std::forward to
preserve the value category of the type being moved.
2019-04-11 20:01:33 -04:00
bunnei f14328bf0a
Merge pull request #2300 from FernandoS27/null-shader
shader_cache: Permit a Null Shader in case of a bad host_ptr.
2019-04-07 17:58:27 -04:00
bunnei 21a4e7deea
Merge pull request #2098 from FreddyFunk/disk-cache-zstd
gl_shader_disk_cache: Use Zstandard for compression
2019-04-07 17:48:33 -04:00
Fernando Sahmkow 021cd56bc9 Permit a Null Shader in case of a bad host_ptr. 2019-04-07 07:52:01 -04:00
Lioncash 93b84e9308 common/multi_level_queue: Silence truncation warning in iterator operator++ 2019-04-05 15:35:46 -04:00
Lioncash 33db37e669 common/bit_util: Make CountLeading/CountTrailing functions have the same return types
Makes the return type consistently uniform (like the intrinsics we're
wrapping). This also conveniently silences a truncation warning within
the kernel multi_level_queue.
2019-04-05 15:29:40 -04:00
Lioncash 0e2f617abc common/lz4_compression: Remove #pragma once directive from the cpp file
Introduced within 798d76f4c7, this only
really has an effect within header files.

Silences a -Wpragma-once-outside-header warning with clang.
2019-04-03 22:07:04 -04:00
bunnei d6374b2522
Merge pull request #2093 from FreddyFunk/disk-cache-better-compression
Better LZ4 compression utilization for the disk based shader cache and the yuzu build system
2019-04-03 21:50:29 -04:00
Lioncash 781ab8407b general: Use deducation guides for std::lock_guard and std::unique_lock
Since C++17, the introduction of deduction guides for locking facilities
means that we no longer need to hardcode the mutex type into the locks
themselves, making it easier to switch mutex types, should it ever be
necessary in the future.
2019-04-01 12:53:47 -04:00
bunnei a89266bc5e
Merge pull request #2303 from lioncash/thread
common/thread: Remove unused functions
2019-03-30 20:10:32 -04:00
Lioncash 394095438a common/thread: Remove unused functions
Many of these functions are carried over from Dolphin (where they aren't
used anymore). Given these have no use (and we really shouldn't be
screwing around with OS-specific thread scheduler handling from the
emulator, these can be removed.

The function for setting the thread name is left, however, since it can
have debugging utility usages.
2019-03-29 13:26:21 -04:00
unknown b4857e326f common/zstd_compression: simplify decompression interface 2019-03-29 18:22:08 +01:00
unknown 72477731ed common/zstd_compression: Add Zstandard wrapper 2019-03-29 18:22:08 +01:00
unknown ca82589350 common: Link libzstd_static 2019-03-29 18:22:07 +01:00
unknown c791192d64 Addressed feedback 2019-03-29 18:12:42 +01:00
unknown 74cee1b65d gl_shader_disk_cache: Use better compression for transferable and precompiled shader disk chache files 2019-03-29 16:42:19 +01:00
unknown 798d76f4c7 data_compression: Move LZ4 compression from video_core/gl_shader_disk_cache to common/data_compression 2019-03-29 16:42:19 +01:00
Fernando Sahmkow db42bcb306 Fixes and corrections on formatting. 2019-03-27 14:49:43 -04:00
Fernando Sahmkow f35e09fe0d Fixes to multilevelqueue's iterator. 2019-03-27 14:34:33 -04:00
Fernando Sahmkow dde0814837 Use MultiLevelQueue instead of old ThreadQueueList 2019-03-27 14:34:32 -04:00
Fernando Sahmkow 3bc815a5dc Implement intrinsics CountTrailingZeroes and test it. 2019-03-27 14:34:29 -04:00
Fernando Sahmkow 522957f9f3 Implement a MultiLevelQueue 2019-03-27 14:33:44 -04:00
bunnei e5893db3e6
Merge pull request #2256 from bunnei/gpu-vmm
gpu: Rewrite MemoryManager based on the VMManager implementation.
2019-03-22 18:41:12 -04:00
Lioncash 109b78a6d6 common/bit_util: Fix bad merge duplicating the copy constructor
Introduced as a result of #2090, we already define the copy constructor
further down below, so this isn't needed.
2019-03-20 23:48:37 -04:00
bunnei 3e930304fe
Merge pull request #2090 from FearlessTobi/port-4599
Port citra-emu/citra#4244 and citra-emu/citra#4599: Changes to BitField
2019-03-20 23:44:20 -04:00
Lioncash f2c41ba256 common/uint128: Add missing header guard 2019-03-20 22:39:00 -04:00
Lioncash b0d70096a1 common/uint128: Add missing top-file source text 2019-03-20 22:38:25 -04:00
bunnei 22d3dfbcd4 gpu: Rewrite virtual memory manager using PageTable. 2019-03-20 22:36:02 -04:00
bunnei 241563d15c gpu: Move GPUVAddr definition to common_types. 2019-03-20 22:36:02 -04:00
Lioncash 1b6adb5308 common/CMakeLists: Amend boost dependency
When #2247 was created, thread_queue_list.h was the only user of
boost-related code, however #2252 moved the page table struct into
common, which makes use of Boost.ICL, so we need to add the dependency
to the common library's link interface again.
2019-03-20 21:42:13 -04:00
bunnei e8ff8a66b0
Merge pull request #2247 from lioncash/include
common/thread_queue_list: Remove unnecessary dependency on boost
2019-03-20 21:34:12 -04:00
bunnei 93da8e0abf core: Move PageTable struct into Common. 2019-03-16 22:05:40 -04:00
bunnei 059465d496
Merge pull request #2129 from FernandoS27/cntpct
Correct CNTPCT from using CPU Cycles to using Clock Cycles
2019-03-16 21:58:59 -04:00
Lioncash f71c598907 common/thread_queue_list: Remove unnecessary dependency on boost
We really don't need to pull in several headers of boost related
machinery just to perform the erase-remove idiom (particularly with
C++20 around the corner, which adds universal container std::erase and
std::erase_if, which we can just use instead).

With this, we don't need to link in anything boost-related into common.
2019-03-16 05:01:39 -04:00
bunnei 633ce92908
Merge pull request #2147 from ReinUsesLisp/texture-clean
shader_ir: Remove "extras" from the MetaTexture
2019-03-10 17:28:36 -04:00
Lioncash e99a148628 common/bit_field: Make BitField trivially copyable
This makes the class much more flexible and doesn't make performing
copies with classes that contain a bitfield member a pain.

Given BitField instances are only intended to be used within unions, the
fact the full storage value would be copied isn't a big concern (only
sizeof(union_type) would be copied anyways).

While we're at it, provide defaulted move constructors for consistency.
2019-03-07 17:05:44 -05:00
Lioncash f8f1ff0b4f logging/backend: Make time_origin a class variable instead of a local static
Moves local global state into the Impl class itself and initializes it
at the creation of the instance instead of in the function.

This makes it nicer for weakly-ordered architectures, given the
CreateEntry() class won't need to have atomic loads executed for each
individual call to the CreateEntry class.
2019-03-02 14:44:24 -05:00
Lioncash 43c1092031 logging/backend: Move CreateEntry into the Impl class
This function is only ever used within this source file and makes it
easier to remove static state in the following change.
2019-03-02 14:44:24 -05:00
Lioncash b9238edd0d common/math_util: Move contents into the Common namespace
These types are within the common library, so they should be within the
Common namespace.
2019-02-27 03:38:39 -05:00
Lioncash 1b855efd5e common/vector_math: Move Vec[x] types into the Common namespace
These types are within the common library, so they should be using the
Common namespace.
2019-02-26 22:38:36 -05:00
Lioncash a1574aabd5 common/quaternion: Move Quaternion into the Common namespace
Quaternion is within the common library, so it should be using the
Common namespace.
2019-02-26 22:31:17 -05:00
ReinUsesLisp 48e6f77c03 shader/decode: Split memory and texture instructions decoding 2019-02-26 00:11:30 -03:00
tgsm 030814b1cb Remove GCC version checks
Citra can't be compiled using GCC <7 because of required C++17 support, so these version checks don't need to exist anymore.
2019-02-24 15:24:06 +01:00
Fernando Sahmkow a8d4927e29 Corrections, documenting and fixes. 2019-02-16 16:52:24 -04:00
Fernando Sahmkow ecccfe0337 Use u128 on Clock Cycles calculation. 2019-02-15 22:57:16 -04:00
Fernando Sahmkow 3ea48e8ebe Implement 128 bits Unsigned Integer Multiplication and Division. 2019-02-15 22:55:31 -04:00
B3n30 2195f10d15 Adressed review comments 2019-02-15 22:14:54 +01:00
B3n30 4154936568 threadsafe_queue: Add WaitIfEmpty and use it in logging 2019-02-15 22:12:54 +01:00
bunnei fcc3aa0bbf
Merge pull request #2113 from ReinUsesLisp/vulkan-base
vulkan: Add dependencies and device abstraction
2019-02-14 10:06:48 -05:00
fearlessTobi efd83570bd Make bitfield assignment operator public
This change needs to be made to get the code compiling again. It was suggested after a conversation with Lioncash.

The conversation can be seen here: https://user-images.githubusercontent.com/20753089/45064197-b6107800-b0b2-11e8-9db8-f696299fb86a.PNG
2019-02-13 21:15:15 +01:00
Lioncash 0829ef97ca threadsafe_queue: Use std::size_t for representing size
Makes it consistent with the regular standard containers in terms of
size representation. This also gets rid of dependence on our own
type aliases, removing the need for an include.
2019-02-12 22:39:53 -05:00
Lioncash f0bfb24c61 threadsafe_queue: Remove NeedSize template parameter
The necessity of this parameter is dubious at best, and in 2019 probably
offers completely negligible savings as opposed to just leaving this
enabled. This removes it and simplifies the overall interface.
2019-02-12 22:09:51 -05:00
ReinUsesLisp b12ab4d805 logging: Add Vulkan backend logging class type 2019-02-12 18:33:02 -03:00
ReinUsesLisp dfd14618f7 cmake: Fix title bar issue 2019-02-06 22:23:41 -03:00
Frederic L 8ff2ce5207 cmake: Use CMAKE_COMMAND instead of "cmake"
Co-Authored-By: ReinUsesLisp <reinuseslisp@airmail.cc>
2019-02-06 22:23:41 -03:00
ReinUsesLisp be4641c43f gl_shader_disk_cache: Invalidate shader cache changes with CMake hash 2019-02-06 22:20:57 -03:00
ReinUsesLisp 84412591c9 file_util: Add shader directory 2019-02-06 22:20:57 -03:00
Weiyi Wang 6b81ceb060 common/bitfield: make it endianness-aware 2019-02-06 17:29:39 +01:00
Weiyi Wang 71530781f3 common/swap: remove default value for swap type internal storage
This is compromise for swap type being used in union. A union has deleted default constructor if it has at least one variant member with non-trivial default constructor, and no variant member of T has a default member initializer. In the use case of Bitfield, all variant members will be the swap type on endianness mismatch, which would all have non-trivial default constructor if default value is specified, and non of them can have member initializer
2019-02-06 17:24:27 +01:00
Weiyi Wang 6734c64976 common/swap: use template and tag for LE/BE specification
The tag can be useful for other type-generic templates like BitFields to forward the endianness specification
2019-02-06 17:24:13 +01:00
Weiyi Wang 94bc48dd78 common/swap: add swap template for enum 2019-02-06 17:21:15 +01:00
bunnei 795335af0f
Merge pull request #1928 from lioncash/caps
kernel: Handle kernel capability descriptors
2018-12-27 11:15:34 -05:00
Lioncash acddf16e57 common/quaternion: Ensure that w is always initialized
Previously xyz was always being zero initialized due to its constructor,
but w wasn't. Ensures that we always have a deterministic initial state.
2018-12-21 15:25:31 -05:00
Lioncash fc8da2d5e3 common: Add basic bit manipulation utility function to Common 2018-12-21 07:04:18 -05:00
bunnei 2f2fc47af2
Merge pull request #1732 from DarkLordZach/yield-types
svc: Implement yield types 0 and -1
2018-12-15 00:28:12 -05:00
Tobias eb15711ee6
Backport review comment from citra-emu/citra#4418
Original reason:
As Windows multi-byte character codec is unspecified while we always assume std::string uses UTF-8 in our code base, this can output gibberish when the string contains non-ASCII characters. ::OutputDebugStringW combined with Common::UTF8ToUTF16W is preferred here.
2018-12-07 16:21:18 +01:00
bunnei 24dfb43ac6
Merge pull request #1773 from lioncash/thread
common/thread: Minor cleanup
2018-11-23 08:52:05 -08:00
Lioncash 1bf5a337a5 common/thread: Drop Hungarian notation on SetCurrentThreadName's parameter
This is inconsistent with our coding style.
2018-11-22 00:40:26 -05:00
Zach Hilman 820d81b9a5 scheduler: Add explanations for YieldWith and WithoutLoadBalancing 2018-11-22 00:33:53 -05:00
Lioncash 93f7677402 common/thread: Make Barrier's 'count' member non-const
While admirable as a means to ensure immutability, this has the
unfortunate downside of making the class non-movable. std::move cannot
actually perform a move operation if the provided operand has const data
members (std::move acts as an operation to "slide" resources out of an
object instance). Given Barrier contains move-only types such as
std::mutex, this can lead to confusing error messages if an object ever
contained a Barrier instance and said object was attempted to be moved.
2018-11-21 21:47:08 -05:00
Lioncash 756e773096 common/thread: Initialize class member variables where applicable
Simplifies the constructor interfaces for Barrier and Event classes.
2018-11-21 21:45:01 -05:00
Lioncash 02602afd10 common/thread: Group non-member functions together
Keeps the non-member interface in one spot instead of split into two
places, making it nicer to locate functions.
2018-11-21 21:42:33 -05:00
Lioncash d6583d68f6 common/thread: Remove SleepCurrentThread()
This is also unused and superceded by standard functionality. The
standard library provides std::this_thread::sleep_for(), which provides
a much more flexible interface, as different time units can be used with
it.
2018-11-21 21:40:11 -05:00
Lioncash 1d555fdd25 common/thread: Remove unused CurrentThreadId()
This is an old function that's no longer necessary. C++11 introduced
proper threading support to the language and a thread ID can be
retrieved via std::this_thread::get_id() if it's ever needed.
2018-11-21 21:37:11 -05:00
Lioncash 8b27e73bd7 common: Remove bit_set.h
This is an analog of BitSet from Dolphin that was introduced to allow
iterating over a set of bits. Given it's currently unused, and given
that std::bitset exists, we can remove this. If it's ever needed in the
future it can be brought back.
2018-11-21 21:30:10 -05:00
bunnei 8cdb48224d
Merge pull request #1758 from lioncash/rect
common/math_util: Minor cleanup
2018-11-21 08:05:39 -08:00