initial commit
This commit is contained in:
commit
93b04b1b2b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build
|
||||||
15
asset-packer/dub.json
Normal file
15
asset-packer/dub.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "asset-packer",
|
||||||
|
"targetName": "Packer",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"targetType": "executable",
|
||||||
|
"targetPath": "../build",
|
||||||
|
"platforms": ["linux", "windows"],
|
||||||
|
"importPaths": ["./", "../src"],
|
||||||
|
"sourceFiles-linux": ["../src/util.d", "../build/libxxhash.a"],
|
||||||
|
"sourcePaths": ["./"],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
asset-packer/includes.c
Normal file
1
asset-packer/includes.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "../external/xxhash/xxhash.h"
|
||||||
7
asset-packer/main.d
Normal file
7
asset-packer/main.d
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import std.stdio;
|
||||||
|
import util;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Log("Hello, World!");
|
||||||
|
}
|
||||||
36
build-vma.sh
Executable file
36
build-vma.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc";
|
||||||
|
elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang";
|
||||||
|
else echo "Unable to find c++ cpp_compiler"; exit -1; fi;
|
||||||
|
|
||||||
|
if [ -x "$(command -v mold)" ]; then linker_cmd="-fuse-ld=mold";
|
||||||
|
elif [ -x "$(command -v lld)" ]; then linker_cmd="-fuse-ld=lld";
|
||||||
|
elif [ -x "$(command -v ld)" ]; then linker_cmd="-fuse-ld=ld";
|
||||||
|
else echo "Unable to find c/c++ linker"; exit -1; fi;
|
||||||
|
|
||||||
|
# VMA
|
||||||
|
src="external/vma/vma.cpp"
|
||||||
|
flags="-std=c++20 -D_USE_MATH_DEFINES -Iexternal/vma -c -Wno-everything -static"
|
||||||
|
out="-o"
|
||||||
|
obj="build/vma.o"
|
||||||
|
lib="build/libvma.a"
|
||||||
|
|
||||||
|
if ! [ -f build/libvma.a ]; then
|
||||||
|
$cpp_compiler $flags $src $out $obj
|
||||||
|
ar rcs $lib $obj
|
||||||
|
rm $obj
|
||||||
|
fi
|
||||||
|
|
||||||
|
# XXHASH
|
||||||
|
src="external/xxhash/xxhash.c"
|
||||||
|
flags="-std=c99 -Wno-everything -Iexternal/xxhash -c -static"
|
||||||
|
obj="build/xxhash.o"
|
||||||
|
lib="build/libxxhash.a"
|
||||||
|
|
||||||
|
if ! [ -f build/libxxhash.a ]; then
|
||||||
|
$c_compiler $flags $src $out $obj
|
||||||
|
ar rcs $lib $obj
|
||||||
|
rm $obj
|
||||||
|
fi
|
||||||
31
dub.json
Normal file
31
dub.json
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "main",
|
||||||
|
"targetType": "none",
|
||||||
|
"subPackages": [
|
||||||
|
{
|
||||||
|
"name": "gears",
|
||||||
|
"targetType": "executable",
|
||||||
|
"targetName": "Gears",
|
||||||
|
"targetPath": "build",
|
||||||
|
"platforms": ["linux", "windows"],
|
||||||
|
"sourceFiles-linux": ["build/libvma.a", "build/libxxhash.a"],
|
||||||
|
"sourceFiles-windows": [],
|
||||||
|
"importPaths": ["src"],
|
||||||
|
"sourcePaths": ["src"],
|
||||||
|
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"],
|
||||||
|
"libs-windows": [],
|
||||||
|
"preGenerateCommands-linux": ["./build-vma.sh"],
|
||||||
|
"preGenerateCommands-windows": [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "packer",
|
||||||
|
"targetType": "executable",
|
||||||
|
"targetPath": "build",
|
||||||
|
"targetName": "Packer",
|
||||||
|
"platforms": ["linux", "windows"],
|
||||||
|
"importPaths": ["src", "asset-packer"],
|
||||||
|
"sourceFiles-linux": ["src/util.d", "build/libxxhash.a"],
|
||||||
|
"sourcePaths": ["asset-packer"],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
19112
external/vma/vk_mem_alloc.h
vendored
Normal file
19112
external/vma/vk_mem_alloc.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
external/vma/vma.cpp
vendored
Normal file
14
external/vma/vma.cpp
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#define VMA_IMPLEMENTATION
|
||||||
|
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||||
|
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
|
||||||
|
#define VMA_VULKAN_VERSION 1003000
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#define VK_USE_PLATFORM_XCB_KHR
|
||||||
|
#elif _WIN32
|
||||||
|
#define VK_USE_PLATFORM_WIN32_KHR
|
||||||
|
#else
|
||||||
|
#error not yet implemented
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "vk_mem_alloc.h"
|
||||||
26
external/xxhash/LICENSE
vendored
Normal file
26
external/xxhash/LICENSE
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
xxHash Library
|
||||||
|
Copyright (c) 2012-2021 Yann Collet
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
274
external/xxhash/README.md
vendored
Normal file
274
external/xxhash/README.md
vendored
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
|
||||||
|
xxHash - Extremely fast hash algorithm
|
||||||
|
======================================
|
||||||
|
|
||||||
|
xxHash is an Extremely fast Hash algorithm, processing at RAM speed limits.
|
||||||
|
Code is highly portable, and produces hashes identical across all platforms (little / big endian).
|
||||||
|
The library includes the following algorithms :
|
||||||
|
- XXH32 : generates 32-bit hashes, using 32-bit arithmetic
|
||||||
|
- XXH64 : generates 64-bit hashes, using 64-bit arithmetic
|
||||||
|
- XXH3 (since `v0.8.0`): generates 64 or 128-bit hashes, using vectorized arithmetic.
|
||||||
|
The 128-bit variant is called XXH128.
|
||||||
|
|
||||||
|
All variants successfully complete the [SMHasher](https://code.google.com/p/smhasher/wiki/SMHasher) test suite
|
||||||
|
which evaluates the quality of hash functions (collision, dispersion and randomness).
|
||||||
|
Additional tests, which evaluate more thoroughly speed and collision properties of 64-bit hashes, [are also provided](https://github.com/Cyan4973/xxHash/tree/dev/tests).
|
||||||
|
|
||||||
|
|Branch |Status |
|
||||||
|
|------------|---------|
|
||||||
|
|release | [](https://github.com/Cyan4973/xxHash/actions?query=branch%3Arelease+) |
|
||||||
|
|dev | [](https://github.com/Cyan4973/xxHash/actions?query=branch%3Adev+) |
|
||||||
|
|
||||||
|
|
||||||
|
Benchmarks
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
The benchmarked reference system uses an Intel i7-9700K cpu, and runs Ubuntu x64 20.04.
|
||||||
|
The [open source benchmark program] is compiled with `clang` v10.0 using `-O3` flag.
|
||||||
|
|
||||||
|
| Hash Name | Width | Bandwidth (GB/s) | Small Data Velocity | Quality | Comment |
|
||||||
|
| --------- | ----- | ---------------- | ----- | --- | --- |
|
||||||
|
| __XXH3__ (SSE2) | 64 | 31.5 GB/s | 133.1 | 10
|
||||||
|
| __XXH128__ (SSE2) | 128 | 29.6 GB/s | 118.1 | 10
|
||||||
|
| _RAM sequential read_ | N/A | 28.0 GB/s | N/A | N/A | _for reference_
|
||||||
|
| City64 | 64 | 22.0 GB/s | 76.6 | 10
|
||||||
|
| T1ha2 | 64 | 22.0 GB/s | 99.0 | 9 | Slightly worse [collisions]
|
||||||
|
| City128 | 128 | 21.7 GB/s | 57.7 | 10
|
||||||
|
| __XXH64__ | 64 | 19.4 GB/s | 71.0 | 10
|
||||||
|
| SpookyHash | 64 | 19.3 GB/s | 53.2 | 10
|
||||||
|
| Mum | 64 | 18.0 GB/s | 67.0 | 9 | Slightly worse [collisions]
|
||||||
|
| __XXH32__ | 32 | 9.7 GB/s | 71.9 | 10
|
||||||
|
| City32 | 32 | 9.1 GB/s | 66.0 | 10
|
||||||
|
| Murmur3 | 32 | 3.9 GB/s | 56.1 | 10
|
||||||
|
| SipHash | 64 | 3.0 GB/s | 43.2 | 10
|
||||||
|
| FNV64 | 64 | 1.2 GB/s | 62.7 | 5 | Poor avalanche properties
|
||||||
|
| Blake2 | 256 | 1.1 GB/s | 5.1 | 10 | Cryptographic
|
||||||
|
| SHA1 | 160 | 0.8 GB/s | 5.6 | 10 | Cryptographic but broken
|
||||||
|
| MD5 | 128 | 0.6 GB/s | 7.8 | 10 | Cryptographic but broken
|
||||||
|
|
||||||
|
[open source benchmark program]: https://github.com/Cyan4973/xxHash/tree/release/tests/bench
|
||||||
|
[collisions]: https://github.com/Cyan4973/xxHash/wiki/Collision-ratio-comparison#collision-study
|
||||||
|
|
||||||
|
note 1: Small data velocity is a _rough_ evaluation of algorithm's efficiency on small data. For more detailed analysis, please refer to next paragraph.
|
||||||
|
|
||||||
|
note 2: some algorithms feature _faster than RAM_ speed. In which case, they can only reach their full speed potential when input is already in CPU cache (L3 or better). Otherwise, they max out on RAM speed limit.
|
||||||
|
|
||||||
|
### Small data
|
||||||
|
|
||||||
|
Performance on large data is only one part of the picture.
|
||||||
|
Hashing is also very useful in constructions like hash tables and bloom filters.
|
||||||
|
In these use cases, it's frequent to hash a lot of small data (starting at a few bytes).
|
||||||
|
Algorithm's performance can be very different for such scenarios, since parts of the algorithm,
|
||||||
|
such as initialization or finalization, become fixed cost.
|
||||||
|
The impact of branch mis-prediction also becomes much more present.
|
||||||
|
|
||||||
|
XXH3 has been designed for excellent performance on both long and small inputs,
|
||||||
|
which can be observed in the following graph:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
For a more detailed analysis, please visit the wiki :
|
||||||
|
https://github.com/Cyan4973/xxHash/wiki/Performance-comparison#benchmarks-concentrating-on-small-data-
|
||||||
|
|
||||||
|
Quality
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Speed is not the only property that matters.
|
||||||
|
Produced hash values must respect excellent dispersion and randomness properties,
|
||||||
|
so that any sub-section of it can be used to maximally spread out a table or index,
|
||||||
|
as well as reduce the amount of collisions to the minimal theoretical level, following the [birthday paradox].
|
||||||
|
|
||||||
|
`xxHash` has been tested with Austin Appleby's excellent SMHasher test suite,
|
||||||
|
and passes all tests, ensuring reasonable quality levels.
|
||||||
|
It also passes extended tests from [newer forks of SMHasher], featuring additional scenarios and conditions.
|
||||||
|
|
||||||
|
Finally, xxHash provides its own [massive collision tester](https://github.com/Cyan4973/xxHash/tree/dev/tests/collisions),
|
||||||
|
able to generate and compare billions of hashes to test the limits of 64-bit hash algorithms.
|
||||||
|
On this front too, xxHash features good results, in line with the [birthday paradox].
|
||||||
|
A more detailed analysis is documented [in the wiki](https://github.com/Cyan4973/xxHash/wiki/Collision-ratio-comparison).
|
||||||
|
|
||||||
|
[birthday paradox]: https://en.wikipedia.org/wiki/Birthday_problem
|
||||||
|
[newer forks of SMHasher]: https://github.com/rurban/smhasher
|
||||||
|
|
||||||
|
|
||||||
|
### Build modifiers
|
||||||
|
|
||||||
|
The following macros can be set at compilation time to modify `libxxhash`'s behavior. They are generally disabled by default.
|
||||||
|
|
||||||
|
- `XXH_INLINE_ALL`: Make all functions `inline`, implementation is directly included within `xxhash.h`.
|
||||||
|
Inlining functions is beneficial for speed, notably for small keys.
|
||||||
|
It's _extremely effective_ when key's length is expressed as _a compile time constant_,
|
||||||
|
with performance improvements observed in the +200% range .
|
||||||
|
See [this article](https://fastcompression.blogspot.com/2018/03/xxhash-for-small-keys-impressive-power.html) for details.
|
||||||
|
- `XXH_PRIVATE_API`: same outcome as `XXH_INLINE_ALL`. Still available for legacy support.
|
||||||
|
The name underlines that `XXH_*` symbol names will not be exported.
|
||||||
|
- `XXH_STATIC_LINKING_ONLY`: gives access to internal state declaration, required for static allocation.
|
||||||
|
Incompatible with dynamic linking, due to risks of ABI changes.
|
||||||
|
- `XXH_NAMESPACE`: Prefixes all symbols with the value of `XXH_NAMESPACE`.
|
||||||
|
This macro can only use compilable character set.
|
||||||
|
Useful to evade symbol naming collisions,
|
||||||
|
in case of multiple inclusions of xxHash's source code.
|
||||||
|
Client applications still use the regular function names,
|
||||||
|
as symbols are automatically translated through `xxhash.h`.
|
||||||
|
- `XXH_FORCE_ALIGN_CHECK`: Use a faster direct read path when input is aligned.
|
||||||
|
This option can result in dramatic performance improvement on architectures unable to load memory from unaligned addresses
|
||||||
|
when input to hash happens to be aligned on 32 or 64-bit boundaries.
|
||||||
|
It is (slightly) detrimental on platform with good unaligned memory access performance (same instruction for both aligned and unaligned accesses).
|
||||||
|
This option is automatically disabled on `x86`, `x64` and `aarch64`, and enabled on all other platforms.
|
||||||
|
- `XXH_FORCE_MEMORY_ACCESS`: The default method `0` uses a portable `memcpy()` notation.
|
||||||
|
Method `1` uses a gcc-specific `packed` attribute, which can provide better performance for some targets.
|
||||||
|
Method `2` forces unaligned reads, which is not standard compliant, but might sometimes be the only way to extract better read performance.
|
||||||
|
Method `3` uses a byteshift operation, which is best for old compilers which don't inline `memcpy()` or big-endian systems without a byteswap instruction.
|
||||||
|
- `XXH_CPU_LITTLE_ENDIAN`: By default, endianness is determined by a runtime test resolved at compile time.
|
||||||
|
If, for some reason, the compiler cannot simplify the runtime test, it can cost performance.
|
||||||
|
It's possible to skip auto-detection and simply state that the architecture is little-endian by setting this macro to 1.
|
||||||
|
Setting it to 0 states big-endian.
|
||||||
|
- `XXH_ENABLE_AUTOVECTORIZE`: Auto-vectorization may be triggered for XXH32 and XXH64, depending on cpu vector capabilities and compiler version.
|
||||||
|
Note: auto-vectorization tends to be triggered more easily with recent versions of `clang`.
|
||||||
|
For XXH32, SSE4.1 or equivalent (NEON) is enough, while XXH64 requires AVX512.
|
||||||
|
Unfortunately, auto-vectorization is generally detrimental to XXH performance.
|
||||||
|
For this reason, the xxhash source code tries to prevent auto-vectorization by default.
|
||||||
|
That being said, systems evolve, and this conclusion is not forthcoming.
|
||||||
|
For example, it has been reported that recent Zen4 cpus are more likely to improve performance with vectorization.
|
||||||
|
Therefore, should you prefer or want to test vectorized code, you can enable this flag:
|
||||||
|
it will remove the no-vectorization protection code, thus making it more likely for XXH32 and XXH64 to be auto-vectorized.
|
||||||
|
- `XXH32_ENDJMP`: Switch multi-branch finalization stage of XXH32 by a single jump.
|
||||||
|
This is generally undesirable for performance, especially when hashing inputs of random sizes.
|
||||||
|
But depending on exact architecture and compiler, a jump might provide slightly better performance on small inputs. Disabled by default.
|
||||||
|
- `XXH_IMPORT`: MSVC specific: should only be defined for dynamic linking, as it prevents linkage errors.
|
||||||
|
- `XXH_NO_STDLIB`: Disable invocation of `<stdlib.h>` functions, notably `malloc()` and `free()`.
|
||||||
|
`libxxhash`'s `XXH*_createState()` will always fail and return `NULL`.
|
||||||
|
But one-shot hashing (like `XXH32()`) or streaming using statically allocated states
|
||||||
|
still work as expected.
|
||||||
|
This build flag is useful for embedded environments without dynamic allocation.
|
||||||
|
- `XXH_memcpy`, `XXH_memset`, `XXH_memcmp` : redirect `memcpy()`, `memset()` and `memcmp()` to some user-selected symbol at compile time.
|
||||||
|
Redirecting all 3 removes the need to include `<string.h>` standard library.
|
||||||
|
- `XXH_NO_EXTERNC_GUARD`: When `xxhash.h` is compiled in C++ mode, removes the `extern "C" { .. }` block guard.
|
||||||
|
- `XXH_DEBUGLEVEL` : When set to any value >= 1, enables `assert()` statements.
|
||||||
|
This (slightly) slows down execution, but may help finding bugs during debugging sessions.
|
||||||
|
|
||||||
|
#### Binary size control
|
||||||
|
- `XXH_NO_XXH3` : removes symbols related to `XXH3` (both 64 & 128 bits) from generated binary.
|
||||||
|
`XXH3` is by far the largest contributor to `libxxhash` size,
|
||||||
|
so it's useful to reduce binary size for applications which do not employ `XXH3`.
|
||||||
|
- `XXH_NO_LONG_LONG`: removes compilation of algorithms relying on 64-bit `long long` types
|
||||||
|
which include `XXH3` and `XXH64`.
|
||||||
|
Only `XXH32` will be compiled.
|
||||||
|
Useful for targets (architectures and compilers) without 64-bit support.
|
||||||
|
- `XXH_NO_STREAM`: Disables the streaming API, limiting the library to single shot variants only.
|
||||||
|
- `XXH_NO_INLINE_HINTS`: By default, xxHash uses `__attribute__((always_inline))` and `__forceinline` to improve performance at the cost of code size.
|
||||||
|
Defining this macro to 1 will mark all internal functions as `static`, allowing the compiler to decide whether to inline a function or not.
|
||||||
|
This is very useful when optimizing for smallest binary size,
|
||||||
|
and is automatically defined when compiling with `-O0`, `-Os`, `-Oz`, or `-fno-inline` on GCC and Clang.
|
||||||
|
It may also be required to successfully compile using `-Og`, depending on compiler version.
|
||||||
|
- `XXH_SIZE_OPT`: `0`: default, optimize for speed
|
||||||
|
`1`: default for `-Os` and `-Oz`: disables some speed hacks for size optimization
|
||||||
|
`2`: makes code as small as possible, performance may cry
|
||||||
|
|
||||||
|
#### Build modifiers specific for XXH3
|
||||||
|
- `XXH_VECTOR` : manually select a vector instruction set (default: auto-selected at compilation time). Available instruction sets are `XXH_SCALAR`, `XXH_SSE2`, `XXH_AVX2`, `XXH_AVX512`, `XXH_NEON` and `XXH_VSX`. Compiler may require additional flags to ensure proper support (for example, `gcc` on x86_64 requires `-mavx2` for `AVX2`, or `-mavx512f` for `AVX512`).
|
||||||
|
- `XXH_PREFETCH_DIST` : select prefetching distance. For close-to-metal adaptation to specific hardware platforms. XXH3 only.
|
||||||
|
- `XXH_NO_PREFETCH` : disable prefetching. Some platforms or situations may perform better without prefetching. XXH3 only.
|
||||||
|
|
||||||
|
#### Makefile variables
|
||||||
|
When compiling the Command Line Interface `xxhsum` using `make`, the following environment variables can also be set :
|
||||||
|
- `DISPATCH=1` : use `xxh_x86dispatch.c`, select at runtime between `scalar`, `sse2`, `avx2` or `avx512` instruction set. This option is only valid for `x86`/`x64` systems. It is enabled by default when target `x86`/`x64` is detected. It can be forcefully turned off using `DISPATCH=0`.
|
||||||
|
- `LIBXXH_DISPATCH=1` : same idea, implemented a runtime vector extension detector, but within `libxxhash`. This parameter is disabled by default. When enabled (only valid for `x86`/`x64` systems), new symbols published in `xxh_x86dispatch.h` become accessible. At the time of this writing, it's required to include `xxh_x86dispatch.h` in order to access the symbols with runtime vector extension detection.
|
||||||
|
- `XXH_1ST_SPEED_TARGET` : select an initial speed target, expressed in MB/s, for the first speed test in benchmark mode. Benchmark will adjust the target at subsequent iterations, but the first test is made "blindly" by targeting this speed. Currently conservatively set to 10 MB/s, to support very slow (emulated) platforms.
|
||||||
|
- `NODE_JS=1` : When compiling `xxhsum` for Node.js with Emscripten, this links the `NODERAWFS` library for unrestricted filesystem access and patches `isatty` to make the command line utility correctly detect the terminal. This does make the binary specific to Node.js.
|
||||||
|
|
||||||
|
### Building xxHash - Using vcpkg
|
||||||
|
|
||||||
|
You can download and install xxHash using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||||
|
|
||||||
|
git clone https://github.com/Microsoft/vcpkg.git
|
||||||
|
cd vcpkg
|
||||||
|
./bootstrap-vcpkg.sh
|
||||||
|
./vcpkg integrate install
|
||||||
|
./vcpkg install xxhash
|
||||||
|
|
||||||
|
The xxHash port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
The simplest example calls xxhash 64-bit variant as a one-shot function
|
||||||
|
generating a hash value from a single buffer, and invoked from a C/C++ program:
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include "xxhash.h"
|
||||||
|
|
||||||
|
(...)
|
||||||
|
XXH64_hash_t hash = XXH64(buffer, size, seed);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Streaming variant is more involved, but makes it possible to provide data incrementally:
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include "stdlib.h" /* abort() */
|
||||||
|
#include "xxhash.h"
|
||||||
|
|
||||||
|
|
||||||
|
XXH64_hash_t calcul_hash_streaming(FileHandler fh)
|
||||||
|
{
|
||||||
|
/* create a hash state */
|
||||||
|
XXH64_state_t* const state = XXH64_createState();
|
||||||
|
if (state==NULL) abort();
|
||||||
|
|
||||||
|
size_t const bufferSize = SOME_SIZE;
|
||||||
|
void* const buffer = malloc(bufferSize);
|
||||||
|
if (buffer==NULL) abort();
|
||||||
|
|
||||||
|
/* Initialize state with selected seed */
|
||||||
|
XXH64_hash_t const seed = 0; /* or any other value */
|
||||||
|
if (XXH64_reset(state, seed) == XXH_ERROR) abort();
|
||||||
|
|
||||||
|
/* Feed the state with input data, any size, any number of times */
|
||||||
|
(...)
|
||||||
|
while ( /* some data left */ ) {
|
||||||
|
size_t const length = get_more_data(buffer, bufferSize, fh);
|
||||||
|
if (XXH64_update(state, buffer, length) == XXH_ERROR) abort();
|
||||||
|
(...)
|
||||||
|
}
|
||||||
|
(...)
|
||||||
|
|
||||||
|
/* Produce the final hash value */
|
||||||
|
XXH64_hash_t const hash = XXH64_digest(state);
|
||||||
|
|
||||||
|
/* State could be re-used; but in this example, it is simply freed */
|
||||||
|
free(buffer);
|
||||||
|
XXH64_freeState(state);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### License
|
||||||
|
|
||||||
|
The library files `xxhash.c` and `xxhash.h` are BSD licensed.
|
||||||
|
The utility `xxhsum` is GPL licensed.
|
||||||
|
|
||||||
|
|
||||||
|
### Other programming languages
|
||||||
|
|
||||||
|
Beyond the C reference version,
|
||||||
|
xxHash is also available from many different programming languages,
|
||||||
|
thanks to great contributors.
|
||||||
|
They are [listed here](http://www.xxhash.com/#other-languages).
|
||||||
|
|
||||||
|
|
||||||
|
### Packaging status
|
||||||
|
|
||||||
|
Many distributions bundle a package manager
|
||||||
|
which allows easy xxhash installation as both a `libxxhash` library
|
||||||
|
and `xxhsum` command line interface.
|
||||||
|
|
||||||
|
[](https://repology.org/project/xxhash/versions)
|
||||||
|
|
||||||
|
|
||||||
|
### Special Thanks
|
||||||
|
|
||||||
|
- Takayuki Matsuoka, aka @t-mat, for creating `xxhsum -c` and great support during early xxh releases
|
||||||
|
- Mathias Westerdahl, aka @JCash, for introducing the first version of `XXH64`
|
||||||
|
- Devin Hussey, aka @easyaspi314, for incredible low-level optimizations on `XXH3` and `XXH128`
|
||||||
13
external/xxhash/SECURITY.md
vendored
Normal file
13
external/xxhash/SECURITY.md
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Security updates are applied only to the latest release.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
|
||||||
|
|
||||||
|
Please disclose it at [security advisory](https://github.com/Cyan4973/xxHash/security/advisories/new).
|
||||||
|
|
||||||
|
This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
|
||||||
55
external/xxhash/xxh3.h
vendored
Normal file
55
external/xxhash/xxh3.h
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* xxHash - Extremely Fast Hash algorithm
|
||||||
|
* Development source file for `xxh3`
|
||||||
|
* Copyright (C) 2019-2021 Yann Collet
|
||||||
|
*
|
||||||
|
* BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - xxHash homepage: https://www.xxhash.com
|
||||||
|
* - xxHash source repository: https://github.com/Cyan4973/xxHash
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note: This file used to host the source code of XXH3_* variants.
|
||||||
|
* during the development period.
|
||||||
|
* The source code is now properly integrated within xxhash.h.
|
||||||
|
*
|
||||||
|
* xxh3.h is no longer useful,
|
||||||
|
* but it is still provided for compatibility with source code
|
||||||
|
* which used to include it directly.
|
||||||
|
*
|
||||||
|
* Programs are now highly discouraged to include xxh3.h.
|
||||||
|
* Include `xxhash.h` instead, which is the officially supported interface.
|
||||||
|
*
|
||||||
|
* In the future, xxh3.h will start to generate warnings, then errors,
|
||||||
|
* then it will be removed from source package and from include directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Simulate the same impact as including the old xxh3.h source file */
|
||||||
|
|
||||||
|
#define XXH_INLINE_ALL
|
||||||
|
#include "xxhash.h"
|
||||||
821
external/xxhash/xxh_x86dispatch.c
vendored
Normal file
821
external/xxhash/xxh_x86dispatch.c
vendored
Normal file
@ -0,0 +1,821 @@
|
|||||||
|
/*
|
||||||
|
* xxHash - Extremely Fast Hash algorithm
|
||||||
|
* Copyright (C) 2020-2021 Yann Collet
|
||||||
|
*
|
||||||
|
* BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - xxHash homepage: https://www.xxhash.com
|
||||||
|
* - xxHash source repository: https://github.com/Cyan4973/xxHash
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @file xxh_x86dispatch.c
|
||||||
|
*
|
||||||
|
* Automatic dispatcher code for the @ref XXH3_family on x86-based targets.
|
||||||
|
*
|
||||||
|
* Optional add-on.
|
||||||
|
*
|
||||||
|
* **Compile this file with the default flags for your target.**
|
||||||
|
* Note that compiling with flags like `-mavx*`, `-march=native`, or `/arch:AVX*`
|
||||||
|
* will make the resulting binary incompatible with cpus not supporting the requested instruction set.
|
||||||
|
*
|
||||||
|
* @defgroup dispatch x86 Dispatcher
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !(defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64))
|
||||||
|
# error "Dispatching is currently only supported on x86 and x86_64."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#ifndef XXH_HAS_INCLUDE
|
||||||
|
# ifdef __has_include
|
||||||
|
/*
|
||||||
|
* Not defined as XXH_HAS_INCLUDE(x) (function-like) because
|
||||||
|
* this causes segfaults in Apple Clang 4.2 (on Mac OS X 10.7 Lion)
|
||||||
|
*/
|
||||||
|
# define XXH_HAS_INCLUDE __has_include
|
||||||
|
# else
|
||||||
|
# define XXH_HAS_INCLUDE(x) 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def XXH_DISPATCH_SCALAR
|
||||||
|
* @brief Enables/dispatching the scalar code path.
|
||||||
|
*
|
||||||
|
* If this is defined to 0, SSE2 support is assumed. This reduces code size
|
||||||
|
* when the scalar path is not needed.
|
||||||
|
*
|
||||||
|
* This is automatically defined to 0 when...
|
||||||
|
* - SSE2 support is enabled in the compiler
|
||||||
|
* - Targeting x86_64
|
||||||
|
* - Targeting Android x86
|
||||||
|
* - Targeting macOS
|
||||||
|
*/
|
||||||
|
#ifndef XXH_DISPATCH_SCALAR
|
||||||
|
# if defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) /* SSE2 on by default */ \
|
||||||
|
|| defined(__x86_64__) || defined(_M_X64) /* x86_64 */ \
|
||||||
|
|| defined(__ANDROID__) || defined(__APPLE__) /* Android or macOS */
|
||||||
|
# define XXH_DISPATCH_SCALAR 0 /* disable */
|
||||||
|
# else
|
||||||
|
# define XXH_DISPATCH_SCALAR 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
/*!
|
||||||
|
* @def XXH_DISPATCH_AVX2
|
||||||
|
* @brief Enables/disables dispatching for AVX2.
|
||||||
|
*
|
||||||
|
* This is automatically detected if it is not defined.
|
||||||
|
* - GCC 4.7 and later are known to support AVX2, but >4.9 is required for
|
||||||
|
* to get the AVX2 intrinsics and typedefs without -mavx -mavx2.
|
||||||
|
* - Visual Studio 2013 Update 2 and later are known to support AVX2.
|
||||||
|
* - The GCC/Clang internal header `<avx2intrin.h>` is detected. While this is
|
||||||
|
* not allowed to be included directly, it still appears in the builtin
|
||||||
|
* include path and is detectable with `__has_include`.
|
||||||
|
*
|
||||||
|
* @see XXH_AVX2
|
||||||
|
*/
|
||||||
|
#ifndef XXH_DISPATCH_AVX2
|
||||||
|
# if (defined(__GNUC__) && (__GNUC__ > 4)) /* GCC 5.0+ */ \
|
||||||
|
|| (defined(_MSC_VER) && _MSC_VER >= 1900) /* VS 2015+ */ \
|
||||||
|
|| (defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180030501) /* VS 2013 Update 2 */ \
|
||||||
|
|| XXH_HAS_INCLUDE(<avx2intrin.h>) /* GCC/Clang internal header */
|
||||||
|
# define XXH_DISPATCH_AVX2 1 /* enable dispatch towards AVX2 */
|
||||||
|
# else
|
||||||
|
# define XXH_DISPATCH_AVX2 0
|
||||||
|
# endif
|
||||||
|
#endif /* XXH_DISPATCH_AVX2 */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def XXH_DISPATCH_AVX512
|
||||||
|
* @brief Enables/disables dispatching for AVX512.
|
||||||
|
*
|
||||||
|
* Automatically detected if one of the following conditions is met:
|
||||||
|
* - GCC 4.9 and later are known to support AVX512.
|
||||||
|
* - Visual Studio 2017 and later are known to support AVX2.
|
||||||
|
* - The GCC/Clang internal header `<avx512fintrin.h>` is detected. While this
|
||||||
|
* is not allowed to be included directly, it still appears in the builtin
|
||||||
|
* include path and is detectable with `__has_include`.
|
||||||
|
*
|
||||||
|
* @see XXH_AVX512
|
||||||
|
*/
|
||||||
|
#ifndef XXH_DISPATCH_AVX512
|
||||||
|
# if (defined(__GNUC__) \
|
||||||
|
&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) /* GCC 4.9+ */ \
|
||||||
|
|| (defined(_MSC_VER) && _MSC_VER >= 1910) /* VS 2017+ */ \
|
||||||
|
|| XXH_HAS_INCLUDE(<avx512fintrin.h>) /* GCC/Clang internal header */
|
||||||
|
# define XXH_DISPATCH_AVX512 1 /* enable dispatch towards AVX512 */
|
||||||
|
# else
|
||||||
|
# define XXH_DISPATCH_AVX512 0
|
||||||
|
# endif
|
||||||
|
#endif /* XXH_DISPATCH_AVX512 */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def XXH_TARGET_SSE2
|
||||||
|
* @brief Allows a function to be compiled with SSE2 intrinsics.
|
||||||
|
*
|
||||||
|
* Uses `__attribute__((__target__("sse2")))` on GCC to allow SSE2 to be used
|
||||||
|
* even with `-mno-sse2`.
|
||||||
|
*
|
||||||
|
* @def XXH_TARGET_AVX2
|
||||||
|
* @brief Like @ref XXH_TARGET_SSE2, but for AVX2.
|
||||||
|
*
|
||||||
|
* @def XXH_TARGET_AVX512
|
||||||
|
* @brief Like @ref XXH_TARGET_SSE2, but for AVX512.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
# include <emmintrin.h> /* SSE2 */
|
||||||
|
# if XXH_DISPATCH_AVX2 || XXH_DISPATCH_AVX512
|
||||||
|
# include <immintrin.h> /* AVX2, AVX512F */
|
||||||
|
# endif
|
||||||
|
# define XXH_TARGET_SSE2 __attribute__((__target__("sse2")))
|
||||||
|
# define XXH_TARGET_AVX2 __attribute__((__target__("avx2")))
|
||||||
|
# define XXH_TARGET_AVX512 __attribute__((__target__("avx512f")))
|
||||||
|
#elif defined(__clang__) && defined(_MSC_VER) /* clang-cl.exe */
|
||||||
|
# include <emmintrin.h> /* SSE2 */
|
||||||
|
# if XXH_DISPATCH_AVX2 || XXH_DISPATCH_AVX512
|
||||||
|
# include <immintrin.h> /* AVX2, AVX512F */
|
||||||
|
# include <smmintrin.h>
|
||||||
|
# include <avxintrin.h>
|
||||||
|
# include <avx2intrin.h>
|
||||||
|
# include <avx512fintrin.h>
|
||||||
|
# endif
|
||||||
|
# define XXH_TARGET_SSE2 __attribute__((__target__("sse2")))
|
||||||
|
# define XXH_TARGET_AVX2 __attribute__((__target__("avx2")))
|
||||||
|
# define XXH_TARGET_AVX512 __attribute__((__target__("avx512f")))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
# include <intrin.h>
|
||||||
|
# define XXH_TARGET_SSE2
|
||||||
|
# define XXH_TARGET_AVX2
|
||||||
|
# define XXH_TARGET_AVX512
|
||||||
|
#else
|
||||||
|
# error "Dispatching is currently not supported for your compiler."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#ifdef XXH_DISPATCH_DEBUG
|
||||||
|
/* debug logging */
|
||||||
|
# include <stdio.h>
|
||||||
|
# define XXH_debugPrint(str) { fprintf(stderr, "DEBUG: xxHash dispatch: %s \n", str); fflush(NULL); }
|
||||||
|
#else
|
||||||
|
# define XXH_debugPrint(str) ((void)0)
|
||||||
|
# undef NDEBUG /* avoid redefinition */
|
||||||
|
# define NDEBUG
|
||||||
|
#endif
|
||||||
|
/*! @endcond */
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifndef XXH_DOXYGEN
|
||||||
|
#define XXH_INLINE_ALL
|
||||||
|
#define XXH_X86DISPATCH
|
||||||
|
#include "xxhash.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#ifndef XXH_HAS_ATTRIBUTE
|
||||||
|
# ifdef __has_attribute
|
||||||
|
# define XXH_HAS_ATTRIBUTE(...) __has_attribute(__VA_ARGS__)
|
||||||
|
# else
|
||||||
|
# define XXH_HAS_ATTRIBUTE(...) 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#if XXH_HAS_ATTRIBUTE(constructor)
|
||||||
|
# define XXH_CONSTRUCTOR __attribute__((constructor))
|
||||||
|
# define XXH_DISPATCH_MAYBE_NULL 0
|
||||||
|
#else
|
||||||
|
# define XXH_CONSTRUCTOR
|
||||||
|
# define XXH_DISPATCH_MAYBE_NULL 1
|
||||||
|
#endif
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
/*
|
||||||
|
* Support both AT&T and Intel dialects
|
||||||
|
*
|
||||||
|
* GCC doesn't convert AT&T syntax to Intel syntax, and will error out if
|
||||||
|
* compiled with -masm=intel. Instead, it supports dialect switching with
|
||||||
|
* curly braces: { AT&T syntax | Intel syntax }
|
||||||
|
*
|
||||||
|
* Clang's integrated assembler automatically converts AT&T syntax to Intel if
|
||||||
|
* needed, making the dialect switching useless (it isn't even supported).
|
||||||
|
*
|
||||||
|
* Note: Comments are written in the inline assembly itself.
|
||||||
|
*/
|
||||||
|
#ifdef __clang__
|
||||||
|
# define XXH_I_ATT(intel, att) att "\n\t"
|
||||||
|
#else
|
||||||
|
# define XXH_I_ATT(intel, att) "{" att "|" intel "}\n\t"
|
||||||
|
#endif
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Runs CPUID.
|
||||||
|
*
|
||||||
|
* @param eax , ecx The parameters to pass to CPUID, %eax and %ecx respectively.
|
||||||
|
* @param abcd The array to store the result in, `{ eax, ebx, ecx, edx }`
|
||||||
|
*/
|
||||||
|
static void XXH_cpuid(xxh_u32 eax, xxh_u32 ecx, xxh_u32* abcd)
|
||||||
|
{
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
__cpuidex((int*)abcd, eax, ecx);
|
||||||
|
#else
|
||||||
|
xxh_u32 ebx, edx;
|
||||||
|
# if defined(__i386__) && defined(__PIC__)
|
||||||
|
__asm__(
|
||||||
|
"# Call CPUID\n\t"
|
||||||
|
"#\n\t"
|
||||||
|
"# On 32-bit x86 with PIC enabled, we are not allowed to overwrite\n\t"
|
||||||
|
"# EBX, so we use EDI instead.\n\t"
|
||||||
|
XXH_I_ATT("mov edi, ebx", "movl %%ebx, %%edi")
|
||||||
|
XXH_I_ATT("cpuid", "cpuid" )
|
||||||
|
XXH_I_ATT("xchg edi, ebx", "xchgl %%ebx, %%edi")
|
||||||
|
: "=D" (ebx),
|
||||||
|
# else
|
||||||
|
__asm__(
|
||||||
|
"# Call CPUID\n\t"
|
||||||
|
XXH_I_ATT("cpuid", "cpuid")
|
||||||
|
: "=b" (ebx),
|
||||||
|
# endif
|
||||||
|
"+a" (eax), "+c" (ecx), "=d" (edx));
|
||||||
|
abcd[0] = eax;
|
||||||
|
abcd[1] = ebx;
|
||||||
|
abcd[2] = ecx;
|
||||||
|
abcd[3] = edx;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modified version of Intel's guide
|
||||||
|
* https://software.intel.com/en-us/articles/how-to-detect-new-instruction-support-in-the-4th-generation-intel-core-processor-family
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if XXH_DISPATCH_AVX2 || XXH_DISPATCH_AVX512
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Runs `XGETBV`.
|
||||||
|
*
|
||||||
|
* While the CPU may support AVX2, the operating system might not properly save
|
||||||
|
* the full YMM/ZMM registers.
|
||||||
|
*
|
||||||
|
* xgetbv is used for detecting this: Any compliant operating system will define
|
||||||
|
* a set of flags in the xcr0 register indicating how it saves the AVX registers.
|
||||||
|
*
|
||||||
|
* You can manually disable this flag on Windows by running, as admin:
|
||||||
|
*
|
||||||
|
* bcdedit.exe /set xsavedisable 1
|
||||||
|
*
|
||||||
|
* and rebooting. Run the same command with 0 to re-enable it.
|
||||||
|
*/
|
||||||
|
static xxh_u64 XXH_xgetbv(void)
|
||||||
|
{
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
return _xgetbv(0); /* min VS2010 SP1 compiler is required */
|
||||||
|
#else
|
||||||
|
xxh_u32 xcr0_lo, xcr0_hi;
|
||||||
|
__asm__(
|
||||||
|
"# Call XGETBV\n\t"
|
||||||
|
"#\n\t"
|
||||||
|
"# Older assemblers (e.g. macOS's ancient GAS version) don't support\n\t"
|
||||||
|
"# the XGETBV opcode, so we encode it by hand instead.\n\t"
|
||||||
|
"# See <https://github.com/asmjit/asmjit/issues/78> for details.\n\t"
|
||||||
|
".byte 0x0f, 0x01, 0xd0\n\t"
|
||||||
|
: "=a" (xcr0_lo), "=d" (xcr0_hi) : "c" (0));
|
||||||
|
return xcr0_lo | ((xxh_u64)xcr0_hi << 32);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#define XXH_SSE2_CPUID_MASK (1 << 26)
|
||||||
|
#define XXH_OSXSAVE_CPUID_MASK ((1 << 26) | (1 << 27))
|
||||||
|
#define XXH_AVX2_CPUID_MASK (1 << 5)
|
||||||
|
#define XXH_AVX2_XGETBV_MASK ((1 << 2) | (1 << 1))
|
||||||
|
#define XXH_AVX512F_CPUID_MASK (1 << 16)
|
||||||
|
#define XXH_AVX512F_XGETBV_MASK ((7 << 5) | (1 << 2) | (1 << 1))
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Returns the best XXH3 implementation.
|
||||||
|
*
|
||||||
|
* Runs various CPUID/XGETBV tests to try and determine the best implementation.
|
||||||
|
*
|
||||||
|
* @return The best @ref XXH_VECTOR implementation.
|
||||||
|
* @see XXH_VECTOR_TYPES
|
||||||
|
*/
|
||||||
|
int XXH_featureTest(void)
|
||||||
|
{
|
||||||
|
xxh_u32 abcd[4];
|
||||||
|
xxh_u32 max_leaves;
|
||||||
|
int best = XXH_SCALAR;
|
||||||
|
#if XXH_DISPATCH_AVX2 || XXH_DISPATCH_AVX512
|
||||||
|
xxh_u64 xgetbv_val;
|
||||||
|
#endif
|
||||||
|
#if defined(__GNUC__) && defined(__i386__)
|
||||||
|
xxh_u32 cpuid_supported;
|
||||||
|
__asm__(
|
||||||
|
"# For the sake of ruthless backwards compatibility, check if CPUID\n\t"
|
||||||
|
"# is supported in the EFLAGS on i386.\n\t"
|
||||||
|
"# This is not necessary on x86_64 - CPUID is mandatory.\n\t"
|
||||||
|
"# The ID flag (bit 21) in the EFLAGS register indicates support\n\t"
|
||||||
|
"# for the CPUID instruction. If a software procedure can set and\n\t"
|
||||||
|
"# clear this flag, the processor executing the procedure supports\n\t"
|
||||||
|
"# the CPUID instruction.\n\t"
|
||||||
|
"# <https://c9x.me/x86/html/file_module_x86_id_45.html>\n\t"
|
||||||
|
"#\n\t"
|
||||||
|
"# Routine is from <https://wiki.osdev.org/CPUID>.\n\t"
|
||||||
|
|
||||||
|
"# Save EFLAGS\n\t"
|
||||||
|
XXH_I_ATT("pushfd", "pushfl" )
|
||||||
|
"# Store EFLAGS\n\t"
|
||||||
|
XXH_I_ATT("pushfd", "pushfl" )
|
||||||
|
"# Invert the ID bit in stored EFLAGS\n\t"
|
||||||
|
XXH_I_ATT("xor dword ptr[esp], 0x200000", "xorl $0x200000, (%%esp)")
|
||||||
|
"# Load stored EFLAGS (with ID bit inverted)\n\t"
|
||||||
|
XXH_I_ATT("popfd", "popfl" )
|
||||||
|
"# Store EFLAGS again (ID bit may or not be inverted)\n\t"
|
||||||
|
XXH_I_ATT("pushfd", "pushfl" )
|
||||||
|
"# eax = modified EFLAGS (ID bit may or may not be inverted)\n\t"
|
||||||
|
XXH_I_ATT("pop eax", "popl %%eax" )
|
||||||
|
"# eax = whichever bits were changed\n\t"
|
||||||
|
XXH_I_ATT("xor eax, dword ptr[esp]", "xorl (%%esp), %%eax" )
|
||||||
|
"# Restore original EFLAGS\n\t"
|
||||||
|
XXH_I_ATT("popfd", "popfl" )
|
||||||
|
"# eax = zero if ID bit can't be changed, else non-zero\n\t"
|
||||||
|
XXH_I_ATT("and eax, 0x200000", "andl $0x200000, %%eax" )
|
||||||
|
: "=a" (cpuid_supported) :: "cc");
|
||||||
|
|
||||||
|
if (XXH_unlikely(!cpuid_supported)) {
|
||||||
|
XXH_debugPrint("CPUID support is not detected!");
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/* Check how many CPUID pages we have */
|
||||||
|
XXH_cpuid(0, 0, abcd);
|
||||||
|
max_leaves = abcd[0];
|
||||||
|
|
||||||
|
/* Shouldn't happen on hardware, but happens on some QEMU configs. */
|
||||||
|
if (XXH_unlikely(max_leaves == 0)) {
|
||||||
|
XXH_debugPrint("Max CPUID leaves == 0!");
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for SSE2, OSXSAVE and xgetbv */
|
||||||
|
XXH_cpuid(1, 0, abcd);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test for SSE2. The check is redundant on x86_64, but it doesn't hurt.
|
||||||
|
*/
|
||||||
|
if (XXH_unlikely((abcd[3] & XXH_SSE2_CPUID_MASK) != XXH_SSE2_CPUID_MASK))
|
||||||
|
return best;
|
||||||
|
|
||||||
|
XXH_debugPrint("SSE2 support detected.");
|
||||||
|
|
||||||
|
best = XXH_SSE2;
|
||||||
|
#if XXH_DISPATCH_AVX2 || XXH_DISPATCH_AVX512
|
||||||
|
/* Make sure we have enough leaves */
|
||||||
|
if (XXH_unlikely(max_leaves < 7))
|
||||||
|
return best;
|
||||||
|
|
||||||
|
/* Test for OSXSAVE and XGETBV */
|
||||||
|
if ((abcd[2] & XXH_OSXSAVE_CPUID_MASK) != XXH_OSXSAVE_CPUID_MASK)
|
||||||
|
return best;
|
||||||
|
|
||||||
|
/* CPUID check for AVX features */
|
||||||
|
XXH_cpuid(7, 0, abcd);
|
||||||
|
|
||||||
|
xgetbv_val = XXH_xgetbv();
|
||||||
|
#if XXH_DISPATCH_AVX2
|
||||||
|
/* Validate that AVX2 is supported by the CPU */
|
||||||
|
if ((abcd[1] & XXH_AVX2_CPUID_MASK) != XXH_AVX2_CPUID_MASK)
|
||||||
|
return best;
|
||||||
|
|
||||||
|
/* Validate that the OS supports YMM registers */
|
||||||
|
if ((xgetbv_val & XXH_AVX2_XGETBV_MASK) != XXH_AVX2_XGETBV_MASK) {
|
||||||
|
XXH_debugPrint("AVX2 supported by the CPU, but not the OS.");
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* AVX2 supported */
|
||||||
|
XXH_debugPrint("AVX2 support detected.");
|
||||||
|
best = XXH_AVX2;
|
||||||
|
#endif
|
||||||
|
#if XXH_DISPATCH_AVX512
|
||||||
|
/* Check if AVX512F is supported by the CPU */
|
||||||
|
if ((abcd[1] & XXH_AVX512F_CPUID_MASK) != XXH_AVX512F_CPUID_MASK) {
|
||||||
|
XXH_debugPrint("AVX512F not supported by CPU");
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate that the OS supports ZMM registers */
|
||||||
|
if ((xgetbv_val & XXH_AVX512F_XGETBV_MASK) != XXH_AVX512F_XGETBV_MASK) {
|
||||||
|
XXH_debugPrint("AVX512F supported by the CPU, but not the OS.");
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* AVX512F supported */
|
||||||
|
XXH_debugPrint("AVX512F support detected.");
|
||||||
|
best = XXH_AVX512;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* === Vector implementations === */
|
||||||
|
|
||||||
|
/*! @cond PRIVATE */
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Defines the various dispatch functions.
|
||||||
|
*
|
||||||
|
* TODO: Consolidate?
|
||||||
|
*
|
||||||
|
* @param suffix The suffix for the functions, e.g. sse2 or scalar
|
||||||
|
* @param target XXH_TARGET_* or empty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define XXH_DEFINE_DISPATCH_FUNCS(suffix, target) \
|
||||||
|
\
|
||||||
|
/* === XXH3, default variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH64_hash_t \
|
||||||
|
XXHL64_default_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, \
|
||||||
|
size_t len) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_64b_internal( \
|
||||||
|
input, len, XXH3_kSecret, sizeof(XXH3_kSecret), \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH3, Seeded variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH64_hash_t \
|
||||||
|
XXHL64_seed_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, size_t len, \
|
||||||
|
XXH64_hash_t seed) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_64b_withSeed_internal( \
|
||||||
|
input, len, seed, XXH3_accumulate_##suffix, \
|
||||||
|
XXH3_scrambleAcc_##suffix, XXH3_initCustomSecret_##suffix \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH3, Secret variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH64_hash_t \
|
||||||
|
XXHL64_secret_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, \
|
||||||
|
size_t len, XXH_NOESCAPE const void* secret, \
|
||||||
|
size_t secretLen) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_64b_internal( \
|
||||||
|
input, len, secret, secretLen, \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH3 update variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH_errorcode \
|
||||||
|
XXH3_update_##suffix(XXH_NOESCAPE XXH3_state_t* state, \
|
||||||
|
XXH_NOESCAPE const void* input, size_t len) \
|
||||||
|
{ \
|
||||||
|
return XXH3_update(state, (const xxh_u8*)input, len, \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH128 default variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH128_hash_t \
|
||||||
|
XXHL128_default_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, \
|
||||||
|
size_t len) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_128b_internal( \
|
||||||
|
input, len, XXH3_kSecret, sizeof(XXH3_kSecret), \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH128 Secret variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH128_hash_t \
|
||||||
|
XXHL128_secret_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, \
|
||||||
|
size_t len, \
|
||||||
|
XXH_NOESCAPE const void* XXH_RESTRICT secret, \
|
||||||
|
size_t secretLen) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_128b_internal( \
|
||||||
|
input, len, (const xxh_u8*)secret, secretLen, \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
/* === XXH128 Seeded variants === */ \
|
||||||
|
\
|
||||||
|
XXH_NO_INLINE target XXH128_hash_t \
|
||||||
|
XXHL128_seed_##suffix(XXH_NOESCAPE const void* XXH_RESTRICT input, size_t len,\
|
||||||
|
XXH64_hash_t seed) \
|
||||||
|
{ \
|
||||||
|
return XXH3_hashLong_128b_withSeed_internal(input, len, seed, \
|
||||||
|
XXH3_accumulate_##suffix, XXH3_scrambleAcc_##suffix, \
|
||||||
|
XXH3_initCustomSecret_##suffix); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @endcond */
|
||||||
|
/* End XXH_DEFINE_DISPATCH_FUNCS */
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
#if XXH_DISPATCH_SCALAR
|
||||||
|
XXH_DEFINE_DISPATCH_FUNCS(scalar, /* nothing */)
|
||||||
|
#endif
|
||||||
|
XXH_DEFINE_DISPATCH_FUNCS(sse2, XXH_TARGET_SSE2)
|
||||||
|
#if XXH_DISPATCH_AVX2
|
||||||
|
XXH_DEFINE_DISPATCH_FUNCS(avx2, XXH_TARGET_AVX2)
|
||||||
|
#endif
|
||||||
|
#if XXH_DISPATCH_AVX512
|
||||||
|
XXH_DEFINE_DISPATCH_FUNCS(avx512, XXH_TARGET_AVX512)
|
||||||
|
#endif
|
||||||
|
#undef XXH_DEFINE_DISPATCH_FUNCS
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/* ==== Dispatchers ==== */
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
typedef XXH64_hash_t (*XXH3_dispatchx86_hashLong64_default)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t);
|
||||||
|
|
||||||
|
typedef XXH64_hash_t (*XXH3_dispatchx86_hashLong64_withSeed)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH64_hash_t);
|
||||||
|
|
||||||
|
typedef XXH64_hash_t (*XXH3_dispatchx86_hashLong64_withSecret)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH_NOESCAPE const void* XXH_RESTRICT, size_t);
|
||||||
|
|
||||||
|
typedef XXH_errorcode (*XXH3_dispatchx86_update)(XXH_NOESCAPE XXH3_state_t*, XXH_NOESCAPE const void*, size_t);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
XXH3_dispatchx86_hashLong64_default hashLong64_default;
|
||||||
|
XXH3_dispatchx86_hashLong64_withSeed hashLong64_seed;
|
||||||
|
XXH3_dispatchx86_hashLong64_withSecret hashLong64_secret;
|
||||||
|
XXH3_dispatchx86_update update;
|
||||||
|
} XXH_dispatchFunctions_s;
|
||||||
|
|
||||||
|
#define XXH_NB_DISPATCHES 4
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Table of dispatchers for @ref XXH3_64bits().
|
||||||
|
*
|
||||||
|
* @pre The indices must match @ref XXH_VECTOR_TYPE.
|
||||||
|
*/
|
||||||
|
static const XXH_dispatchFunctions_s XXH_kDispatch[XXH_NB_DISPATCHES] = {
|
||||||
|
#if XXH_DISPATCH_SCALAR
|
||||||
|
/* Scalar */ { XXHL64_default_scalar, XXHL64_seed_scalar, XXHL64_secret_scalar, XXH3_update_scalar },
|
||||||
|
#else
|
||||||
|
/* Scalar */ { NULL, NULL, NULL, NULL },
|
||||||
|
#endif
|
||||||
|
/* SSE2 */ { XXHL64_default_sse2, XXHL64_seed_sse2, XXHL64_secret_sse2, XXH3_update_sse2 },
|
||||||
|
#if XXH_DISPATCH_AVX2
|
||||||
|
/* AVX2 */ { XXHL64_default_avx2, XXHL64_seed_avx2, XXHL64_secret_avx2, XXH3_update_avx2 },
|
||||||
|
#else
|
||||||
|
/* AVX2 */ { NULL, NULL, NULL, NULL },
|
||||||
|
#endif
|
||||||
|
#if XXH_DISPATCH_AVX512
|
||||||
|
/* AVX512 */ { XXHL64_default_avx512, XXHL64_seed_avx512, XXHL64_secret_avx512, XXH3_update_avx512 }
|
||||||
|
#else
|
||||||
|
/* AVX512 */ { NULL, NULL, NULL, NULL }
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief The selected dispatch table for @ref XXH3_64bits().
|
||||||
|
*/
|
||||||
|
static XXH_dispatchFunctions_s XXH_g_dispatch = { NULL, NULL, NULL, NULL };
|
||||||
|
|
||||||
|
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_default)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t);
|
||||||
|
|
||||||
|
typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_withSeed)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH64_hash_t);
|
||||||
|
|
||||||
|
typedef XXH128_hash_t (*XXH3_dispatchx86_hashLong128_withSecret)(XXH_NOESCAPE const void* XXH_RESTRICT, size_t, XXH_NOESCAPE const void* XXH_RESTRICT, size_t);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
XXH3_dispatchx86_hashLong128_default hashLong128_default;
|
||||||
|
XXH3_dispatchx86_hashLong128_withSeed hashLong128_seed;
|
||||||
|
XXH3_dispatchx86_hashLong128_withSecret hashLong128_secret;
|
||||||
|
XXH3_dispatchx86_update update;
|
||||||
|
} XXH_dispatch128Functions_s;
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Table of dispatchers for @ref XXH3_128bits().
|
||||||
|
*
|
||||||
|
* @pre The indices must match @ref XXH_VECTOR_TYPE.
|
||||||
|
*/
|
||||||
|
static const XXH_dispatch128Functions_s XXH_kDispatch128[XXH_NB_DISPATCHES] = {
|
||||||
|
#if XXH_DISPATCH_SCALAR
|
||||||
|
/* Scalar */ { XXHL128_default_scalar, XXHL128_seed_scalar, XXHL128_secret_scalar, XXH3_update_scalar },
|
||||||
|
#else
|
||||||
|
/* Scalar */ { NULL, NULL, NULL, NULL },
|
||||||
|
#endif
|
||||||
|
/* SSE2 */ { XXHL128_default_sse2, XXHL128_seed_sse2, XXHL128_secret_sse2, XXH3_update_sse2 },
|
||||||
|
#if XXH_DISPATCH_AVX2
|
||||||
|
/* AVX2 */ { XXHL128_default_avx2, XXHL128_seed_avx2, XXHL128_secret_avx2, XXH3_update_avx2 },
|
||||||
|
#else
|
||||||
|
/* AVX2 */ { NULL, NULL, NULL, NULL },
|
||||||
|
#endif
|
||||||
|
#if XXH_DISPATCH_AVX512
|
||||||
|
/* AVX512 */ { XXHL128_default_avx512, XXHL128_seed_avx512, XXHL128_secret_avx512, XXH3_update_avx512 }
|
||||||
|
#else
|
||||||
|
/* AVX512 */ { NULL, NULL, NULL, NULL }
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief The selected dispatch table for @ref XXH3_64bits().
|
||||||
|
*/
|
||||||
|
static XXH_dispatch128Functions_s XXH_g_dispatch128 = { NULL, NULL, NULL, NULL };
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @private
|
||||||
|
* @brief Runs a CPUID check and sets the correct dispatch tables.
|
||||||
|
*/
|
||||||
|
static XXH_CONSTRUCTOR void XXH_setDispatch(void)
|
||||||
|
{
|
||||||
|
int vecID = XXH_featureTest();
|
||||||
|
XXH_STATIC_ASSERT(XXH_AVX512 == XXH_NB_DISPATCHES-1);
|
||||||
|
assert(XXH_SCALAR <= vecID && vecID <= XXH_AVX512);
|
||||||
|
#if !XXH_DISPATCH_SCALAR
|
||||||
|
assert(vecID != XXH_SCALAR);
|
||||||
|
#endif
|
||||||
|
#if !XXH_DISPATCH_AVX512
|
||||||
|
assert(vecID != XXH_AVX512);
|
||||||
|
#endif
|
||||||
|
#if !XXH_DISPATCH_AVX2
|
||||||
|
assert(vecID != XXH_AVX2);
|
||||||
|
#endif
|
||||||
|
XXH_g_dispatch = XXH_kDispatch[vecID];
|
||||||
|
XXH_g_dispatch128 = XXH_kDispatch128[vecID];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ==== XXH3 public functions ==== */
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
|
||||||
|
static XXH64_hash_t
|
||||||
|
XXH3_hashLong_64b_defaultSecret_selection(const void* XXH_RESTRICT input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)seed64; (void)secret; (void)secretLen;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch.hashLong64_default == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch.hashLong64_default(input, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH64_hash_t XXH3_64bits_dispatch(XXH_NOESCAPE const void* input, size_t len)
|
||||||
|
{
|
||||||
|
return XXH3_64bits_internal(input, len, 0, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_64b_defaultSecret_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static XXH64_hash_t
|
||||||
|
XXH3_hashLong_64b_withSeed_selection(const void* XXH_RESTRICT input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)secret; (void)secretLen;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch.hashLong64_seed == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch.hashLong64_seed(input, len, seed64);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH64_hash_t XXH3_64bits_withSeed_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH64_hash_t seed)
|
||||||
|
{
|
||||||
|
return XXH3_64bits_internal(input, len, seed, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_64b_withSeed_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static XXH64_hash_t
|
||||||
|
XXH3_hashLong_64b_withSecret_selection(const void* XXH_RESTRICT input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const xxh_u8* XXH_RESTRICT secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)seed64;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch.hashLong64_secret == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch.hashLong64_secret(input, len, secret, secretLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH64_hash_t XXH3_64bits_withSecret_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH_NOESCAPE const void* secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
return XXH3_64bits_internal(input, len, 0, secret, secretLen, XXH3_hashLong_64b_withSecret_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH_errorcode
|
||||||
|
XXH3_64bits_update_dispatch(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
|
||||||
|
{
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch.update == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
|
||||||
|
return XXH_g_dispatch.update(state, (const xxh_u8*)input, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
|
||||||
|
/* ==== XXH128 public functions ==== */
|
||||||
|
/*! @cond Doxygen ignores this part */
|
||||||
|
|
||||||
|
static XXH128_hash_t
|
||||||
|
XXH3_hashLong_128b_defaultSecret_selection(const void* input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const void* secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)seed64; (void)secret; (void)secretLen;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch128.hashLong128_default == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch128.hashLong128_default(input, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH128_hash_t XXH3_128bits_dispatch(XXH_NOESCAPE const void* input, size_t len)
|
||||||
|
{
|
||||||
|
return XXH3_128bits_internal(input, len, 0, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_128b_defaultSecret_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static XXH128_hash_t
|
||||||
|
XXH3_hashLong_128b_withSeed_selection(const void* input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const void* secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)secret; (void)secretLen;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch128.hashLong128_seed == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch128.hashLong128_seed(input, len, seed64);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH128_hash_t XXH3_128bits_withSeed_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH64_hash_t seed)
|
||||||
|
{
|
||||||
|
return XXH3_128bits_internal(input, len, seed, XXH3_kSecret, sizeof(XXH3_kSecret), XXH3_hashLong_128b_withSeed_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static XXH128_hash_t
|
||||||
|
XXH3_hashLong_128b_withSecret_selection(const void* input, size_t len,
|
||||||
|
XXH64_hash_t seed64, const void* secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
(void)seed64;
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch128.hashLong128_secret == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch128.hashLong128_secret(input, len, secret, secretLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH128_hash_t XXH3_128bits_withSecret_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH_NOESCAPE const void* secret, size_t secretLen)
|
||||||
|
{
|
||||||
|
return XXH3_128bits_internal(input, len, 0, secret, secretLen, XXH3_hashLong_128b_withSecret_selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
XXH_errorcode
|
||||||
|
XXH3_128bits_update_dispatch(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len)
|
||||||
|
{
|
||||||
|
if (XXH_DISPATCH_MAYBE_NULL && XXH_g_dispatch128.update == NULL)
|
||||||
|
XXH_setDispatch();
|
||||||
|
return XXH_g_dispatch128.update(state, (const xxh_u8*)input, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @endcond */
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/*! @} */
|
||||||
93
external/xxhash/xxh_x86dispatch.h
vendored
Normal file
93
external/xxhash/xxh_x86dispatch.h
vendored
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* xxHash - XXH3 Dispatcher for x86-based targets
|
||||||
|
* Copyright (C) 2020-2024 Yann Collet
|
||||||
|
*
|
||||||
|
* BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - xxHash homepage: https://www.xxhash.com
|
||||||
|
* - xxHash source repository: https://github.com/Cyan4973/xxHash
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XXH_X86DISPATCH_H_13563687684
|
||||||
|
#define XXH_X86DISPATCH_H_13563687684
|
||||||
|
|
||||||
|
#include "xxhash.h" /* XXH64_hash_t, XXH3_state_t */
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the best XXH3 implementation for x86
|
||||||
|
*
|
||||||
|
* @return The best @ref XXH_VECTOR implementation.
|
||||||
|
* @see XXH_VECTOR_TYPES
|
||||||
|
*/
|
||||||
|
XXH_PUBLIC_API int XXH_featureTest(void);
|
||||||
|
|
||||||
|
XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_dispatch(XXH_NOESCAPE const void* input, size_t len);
|
||||||
|
XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSeed_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH64_hash_t seed);
|
||||||
|
XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSecret_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH_NOESCAPE const void* secret, size_t secretLen);
|
||||||
|
XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update_dispatch(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len);
|
||||||
|
|
||||||
|
XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_dispatch(XXH_NOESCAPE const void* input, size_t len);
|
||||||
|
XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSeed_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH64_hash_t seed);
|
||||||
|
XXH_PUBLIC_API XXH128_hash_t XXH3_128bits_withSecret_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH_NOESCAPE const void* secret, size_t secretLen);
|
||||||
|
XXH_PUBLIC_API XXH_errorcode XXH3_128bits_update_dispatch(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len);
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* automatic replacement of XXH3 functions.
|
||||||
|
* can be disabled by setting XXH_DISPATCH_DISABLE_REPLACE */
|
||||||
|
#ifndef XXH_DISPATCH_DISABLE_REPLACE
|
||||||
|
|
||||||
|
# undef XXH3_64bits
|
||||||
|
# define XXH3_64bits XXH3_64bits_dispatch
|
||||||
|
# undef XXH3_64bits_withSeed
|
||||||
|
# define XXH3_64bits_withSeed XXH3_64bits_withSeed_dispatch
|
||||||
|
# undef XXH3_64bits_withSecret
|
||||||
|
# define XXH3_64bits_withSecret XXH3_64bits_withSecret_dispatch
|
||||||
|
# undef XXH3_64bits_update
|
||||||
|
# define XXH3_64bits_update XXH3_64bits_update_dispatch
|
||||||
|
|
||||||
|
# undef XXH128
|
||||||
|
# define XXH128 XXH3_128bits_withSeed_dispatch
|
||||||
|
# undef XXH3_128bits
|
||||||
|
# define XXH3_128bits XXH3_128bits_dispatch
|
||||||
|
# undef XXH3_128bits_withSeed
|
||||||
|
# define XXH3_128bits_withSeed XXH3_128bits_withSeed_dispatch
|
||||||
|
# undef XXH3_128bits_withSecret
|
||||||
|
# define XXH3_128bits_withSecret XXH3_128bits_withSecret_dispatch
|
||||||
|
# undef XXH3_128bits_update
|
||||||
|
# define XXH3_128bits_update XXH3_128bits_update_dispatch
|
||||||
|
|
||||||
|
#endif /* XXH_DISPATCH_DISABLE_REPLACE */
|
||||||
|
|
||||||
|
#endif /* XXH_X86DISPATCH_H_13563687684 */
|
||||||
42
external/xxhash/xxhash.c
vendored
Normal file
42
external/xxhash/xxhash.c
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* xxHash - Extremely Fast Hash algorithm
|
||||||
|
* Copyright (C) 2012-2023 Yann Collet
|
||||||
|
*
|
||||||
|
* BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - xxHash homepage: https://www.xxhash.com
|
||||||
|
* - xxHash source repository: https://github.com/Cyan4973/xxHash
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* xxhash.c instantiates functions defined in xxhash.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
|
||||||
|
#define XXH_IMPLEMENTATION /* access definitions */
|
||||||
|
|
||||||
|
#include "xxhash.h"
|
||||||
7343
external/xxhash/xxhash.h
vendored
Normal file
7343
external/xxhash/xxhash.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
33
src/aliases.d
Normal file
33
src/aliases.d
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import core.memory;
|
||||||
|
import std.stdint;
|
||||||
|
|
||||||
|
debug
|
||||||
|
{
|
||||||
|
const BUILD_DEBUG = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const BUILD_DEBUG = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
alias i8 = byte;
|
||||||
|
alias i16 = short;
|
||||||
|
alias i32 = int;
|
||||||
|
alias i64 = long;
|
||||||
|
|
||||||
|
alias u8 = ubyte;
|
||||||
|
alias u16 = ushort;
|
||||||
|
alias u32 = uint;
|
||||||
|
alias u64 = ulong;
|
||||||
|
|
||||||
|
alias f32 = float;
|
||||||
|
alias f64 = double;
|
||||||
|
|
||||||
|
alias b32 = uint;
|
||||||
|
|
||||||
|
alias intptr = intptr_t;
|
||||||
|
alias uintptr = uintptr_t;
|
||||||
|
|
||||||
|
alias free = pureFree;
|
||||||
|
alias malloc = pureMalloc;
|
||||||
|
alias realloc = pureRealloc;
|
||||||
94
src/alloc.d
Normal file
94
src/alloc.d
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import aliases;
|
||||||
|
import m = math;
|
||||||
|
import std.stdio;
|
||||||
|
import core.stdc.string : memset;
|
||||||
|
|
||||||
|
const DEFAULT_ALIGNMENT = (void *).sizeof * 2;
|
||||||
|
|
||||||
|
struct Arena
|
||||||
|
{
|
||||||
|
u8* mem;
|
||||||
|
u64 length;
|
||||||
|
u64 pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
T*
|
||||||
|
Alloc(T)()
|
||||||
|
{
|
||||||
|
void* mem = malloc(T.sizeof);
|
||||||
|
memset(mem, 0, T.sizeof);
|
||||||
|
return (cast(T*)mem);
|
||||||
|
}
|
||||||
|
|
||||||
|
T[]
|
||||||
|
AllocArray(T)(u64 count)
|
||||||
|
{
|
||||||
|
void* mem = malloc(T.sizeof * count);
|
||||||
|
memset(mem, 0, T.sizeof * count);
|
||||||
|
return (cast(T*)mem)[0 .. count];
|
||||||
|
}
|
||||||
|
|
||||||
|
Arena
|
||||||
|
CreateArena(u64 size)
|
||||||
|
{
|
||||||
|
Arena arena = {
|
||||||
|
mem: cast(u8 *)malloc(size),
|
||||||
|
length: size,
|
||||||
|
pos: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(arena.mem != null, "Unable to allocate memory for arena");
|
||||||
|
|
||||||
|
return arena;
|
||||||
|
};
|
||||||
|
|
||||||
|
T[]
|
||||||
|
AllocArray(T)(Arena* arena, u64 count)
|
||||||
|
{
|
||||||
|
void* mem = AllocAlign(arena, T.sizeof * count, DEFAULT_ALIGNMENT);
|
||||||
|
memset(mem, 0, T.sizeof * count);
|
||||||
|
return (cast(T*)mem)[0 .. count];
|
||||||
|
}
|
||||||
|
|
||||||
|
T*
|
||||||
|
Alloc(T)(Arena* arena)
|
||||||
|
{
|
||||||
|
void* mem = AllocAlign(arena, T.sizeof, DEFAULT_ALIGNMENT);
|
||||||
|
memset(mem, 0, T.sizeof);
|
||||||
|
return cast(T*)mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
void*
|
||||||
|
AllocAlign(Arena* arena, u64 size, u64 alignment)
|
||||||
|
{
|
||||||
|
void* ptr = null;
|
||||||
|
|
||||||
|
uintptr mem_pos = cast(uintptr)arena.mem;
|
||||||
|
uintptr current = mem_pos + arena.pos;
|
||||||
|
uintptr offset = m.AlignPow2(current, alignment) - mem_pos;
|
||||||
|
|
||||||
|
if (offset+size <= arena.length)
|
||||||
|
{
|
||||||
|
ptr = &arena.mem[offset];
|
||||||
|
arena.pos = offset+size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
writefln("AllocAlign failure: out of memory, size requested: %llu", size);
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
Reset(Arena* arena)
|
||||||
|
{
|
||||||
|
arena.pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Free(Arena* arena)
|
||||||
|
{
|
||||||
|
free(arena.mem);
|
||||||
|
}
|
||||||
0
src/assets.d
Normal file
0
src/assets.d
Normal file
20
src/dub.json
Normal file
20
src/dub.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "gears",
|
||||||
|
"targetName": "Gears",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"targetType": "executable",
|
||||||
|
"targetPath": "../build",
|
||||||
|
"platforms": ["linux", "windows"],
|
||||||
|
"sourceFiles-linux": ["../build/libvma.a", "../build/libxxhash.a"],
|
||||||
|
"sourceFiles-windows": [],
|
||||||
|
"importPaths": ["./"],
|
||||||
|
"sourcePaths": ["./"],
|
||||||
|
"libs-linux": ["xcb", "X11", "X11-xcb", "vulkan", "stdc++"],
|
||||||
|
"libs-windows": [],
|
||||||
|
"preGenerateCommands-linux": ["../build-vma.sh"],
|
||||||
|
"preGenerateCommands-windows": [],
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
25
src/includes.c
Normal file
25
src/includes.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifdef __linux__
|
||||||
|
# include <xcb/xcb.h>
|
||||||
|
# include <X11/XKBlib.h>
|
||||||
|
# include <X11/Xlib-xcb.h>
|
||||||
|
# include <X11/Xlib.h>
|
||||||
|
# include <X11/keysym.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __linux__
|
||||||
|
# define VK_USE_PLATFORM_XCB_KHR
|
||||||
|
#elif _WIN32
|
||||||
|
# define VK_USE_PLATFORM_WIN32_KHR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define VK_NO_PROTOTYPES
|
||||||
|
|
||||||
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
|
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||||
|
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
|
||||||
|
#define VMA_VULKAN_VERSION 1003000
|
||||||
|
|
||||||
|
#include "../external/vma/vk_mem_alloc.h"
|
||||||
|
|
||||||
|
#include "../external/xxhash/xxhash.h"
|
||||||
18
src/main.d
Normal file
18
src/main.d
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
public import includes;
|
||||||
|
import std.stdio;
|
||||||
|
import aliases;
|
||||||
|
import core.memory;
|
||||||
|
import u = util : Result;
|
||||||
|
import p = platform;
|
||||||
|
import a = alloc;
|
||||||
|
import vk = vulkan : Vulkan;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
p.Window window = p.CreateWindow("Video Game", 1920, 1080);
|
||||||
|
|
||||||
|
Result!(Vulkan) result = vk.Init(&window, u.MB(24), u.MB(32));
|
||||||
|
Vulkan vulkan = result.value;
|
||||||
|
|
||||||
|
vk.Destroy(&vulkan);
|
||||||
|
}
|
||||||
BIN
src/main.o
Normal file
BIN
src/main.o
Normal file
Binary file not shown.
6
src/math.d
Normal file
6
src/math.d
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import aliases;
|
||||||
|
|
||||||
|
T AlignPow2(T)(T v, T a)
|
||||||
|
{
|
||||||
|
return (v + a - 1) & ~(a - 1);
|
||||||
|
};
|
||||||
174
src/platform.d
Normal file
174
src/platform.d
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
import aliases;
|
||||||
|
import includes;
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
version(linux)
|
||||||
|
{
|
||||||
|
import core.sys.posix.dlfcn;
|
||||||
|
|
||||||
|
struct Window
|
||||||
|
{
|
||||||
|
Display *display;
|
||||||
|
xcb_connection_t *conn;
|
||||||
|
xcb_window_t window;
|
||||||
|
xcb_atom_t close_event;
|
||||||
|
xcb_atom_t minimize_event;
|
||||||
|
u16 w;
|
||||||
|
u16 h;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Library
|
||||||
|
{
|
||||||
|
void* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Function
|
||||||
|
{
|
||||||
|
void* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void CheckErr(Window *window, xcb_void_cookie_t *cookie, xcb_generic_error_t *err, string msg)
|
||||||
|
{
|
||||||
|
assert(err == null, msg);
|
||||||
|
free(err);
|
||||||
|
};
|
||||||
|
|
||||||
|
Window CreateWindow(string name, u16 width, u16 height)
|
||||||
|
{
|
||||||
|
Window window = {
|
||||||
|
w: width,
|
||||||
|
h: height,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert(width > 0 && height > 0, "CreateWindow error: width and height must be above 0");
|
||||||
|
|
||||||
|
window.display = XOpenDisplay(null);
|
||||||
|
assert(window.display != null, "XOpenDisplay failure");
|
||||||
|
|
||||||
|
window.conn = XGetXCBConnection(window.display);
|
||||||
|
assert(window.conn != null, "XGetXCBConnection failure");
|
||||||
|
|
||||||
|
xcb_void_cookie_t cookie;
|
||||||
|
xcb_generic_error_t *error;
|
||||||
|
|
||||||
|
xcb_setup_t *setup = xcb_get_setup(window.conn);
|
||||||
|
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
|
||||||
|
xcb_screen_t *screen = iter.data;
|
||||||
|
|
||||||
|
i32 event_mask = XCB_EVENT_MASK_EXPOSURE |
|
||||||
|
XCB_EVENT_MASK_KEY_PRESS |
|
||||||
|
XCB_EVENT_MASK_KEY_RELEASE |
|
||||||
|
XCB_EVENT_MASK_BUTTON_PRESS |
|
||||||
|
XCB_EVENT_MASK_BUTTON_RELEASE |
|
||||||
|
XCB_EVENT_MASK_POINTER_MOTION |
|
||||||
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY;
|
||||||
|
|
||||||
|
i32[] val_win = [screen.black_pixel, event_mask];
|
||||||
|
i32 val_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
|
||||||
|
|
||||||
|
window.window = xcb_generate_id(window.conn);
|
||||||
|
|
||||||
|
cookie = xcb_create_window_checked(
|
||||||
|
window.conn,
|
||||||
|
XCB_COPY_FROM_PARENT,
|
||||||
|
window.window,
|
||||||
|
screen.root,
|
||||||
|
0, // x pos
|
||||||
|
0, // y pos
|
||||||
|
window.w, // width
|
||||||
|
window.h, // height
|
||||||
|
0,
|
||||||
|
XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
||||||
|
screen.root_visual,
|
||||||
|
val_mask,
|
||||||
|
val_win.ptr
|
||||||
|
);
|
||||||
|
error = xcb_request_check(window.conn, cookie);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_create_window failure");
|
||||||
|
|
||||||
|
cookie = xcb_map_window_checked(window.conn, window.window);
|
||||||
|
error = xcb_request_check(window.conn, cookie);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_map_window_checked failure");
|
||||||
|
|
||||||
|
cookie = xcb_change_property_checked(
|
||||||
|
window.conn,
|
||||||
|
XCB_PROP_MODE_REPLACE,
|
||||||
|
window.window,
|
||||||
|
XCB_ATOM_WM_NAME,
|
||||||
|
XCB_ATOM_STRING,
|
||||||
|
8,
|
||||||
|
cast(u32)name.length,
|
||||||
|
name.ptr
|
||||||
|
);
|
||||||
|
error = xcb_request_check(window.conn, cookie);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_change_property_checked failure");
|
||||||
|
|
||||||
|
xcb_intern_atom_cookie_t c_proto = xcb_intern_atom(window.conn, 1, 12, "WM_PROTOCOLS");
|
||||||
|
xcb_intern_atom_reply_t *r_proto = xcb_intern_atom_reply(window.conn, c_proto, &error);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_intern_atom WM_PROTOCOLS failure");
|
||||||
|
|
||||||
|
xcb_intern_atom_cookie_t c_close = xcb_intern_atom(window.conn, 0, 16, "WM_DELETE_WINDOW");
|
||||||
|
xcb_intern_atom_reply_t *r_close = xcb_intern_atom_reply(window.conn, c_close, &error);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_intern_atom WM_DELETE_WINDOW failure");
|
||||||
|
|
||||||
|
xcb_intern_atom_cookie_t c_minimize = xcb_intern_atom(window.conn, 0, 20, "_NET_WM_STATE_HIDDEN");
|
||||||
|
xcb_intern_atom_reply_t *r_minimize = xcb_intern_atom_reply(window.conn, c_minimize, &error);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_intern_atom _NET_WM_STATE_HIDDEN failure");
|
||||||
|
|
||||||
|
|
||||||
|
cookie = xcb_change_property_checked(
|
||||||
|
window.conn,
|
||||||
|
XCB_PROP_MODE_REPLACE,
|
||||||
|
window.window,
|
||||||
|
r_proto.atom,
|
||||||
|
XCB_ATOM_ATOM,
|
||||||
|
32,
|
||||||
|
1,
|
||||||
|
&r_close.atom
|
||||||
|
);
|
||||||
|
error = xcb_request_check(window.conn, cookie);
|
||||||
|
CheckErr(&window, &cookie, error, "xcb_change_property_checked failure");
|
||||||
|
|
||||||
|
window.close_event = r_close.atom;
|
||||||
|
window.minimize_event = r_minimize.atom;
|
||||||
|
|
||||||
|
free(r_proto);
|
||||||
|
free(r_close);
|
||||||
|
free(r_minimize);
|
||||||
|
|
||||||
|
xcb_map_window(window.conn, window.window);
|
||||||
|
|
||||||
|
i32 stream_result = xcb_flush(window.conn);
|
||||||
|
assert(stream_result > 0, "xcb_flush failure");
|
||||||
|
|
||||||
|
return window;
|
||||||
|
};
|
||||||
|
|
||||||
|
Library LoadLibrary(string name)
|
||||||
|
{
|
||||||
|
Library lib = {
|
||||||
|
ptr: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
lib.ptr = dlopen(name.ptr, RTLD_NOW);
|
||||||
|
|
||||||
|
return lib;
|
||||||
|
};
|
||||||
|
|
||||||
|
Function LoadFunction(Library lib, string name)
|
||||||
|
{
|
||||||
|
Function fn = {
|
||||||
|
ptr: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn.ptr = dlsym(lib.ptr, name.ptr);
|
||||||
|
|
||||||
|
return fn;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
version(Windows)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
4
src/renderer.d
Normal file
4
src/renderer.d
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import aliases;
|
||||||
|
import includes;
|
||||||
|
|
||||||
|
alias Shader = VkShaderModule;
|
||||||
25
src/tests.d
Normal file
25
src/tests.d
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import aliases;
|
||||||
|
import u = util;
|
||||||
|
|
||||||
|
void
|
||||||
|
RunTests()
|
||||||
|
{
|
||||||
|
TestHashTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestHashTable()
|
||||||
|
{
|
||||||
|
auto ht = u.CreateHashTable!(u64, u64)(8);
|
||||||
|
|
||||||
|
u64 value = 55;
|
||||||
|
ht[3] = value;
|
||||||
|
auto res = ht[3];
|
||||||
|
assert(res.ok && value == res.value, "hash table failure");
|
||||||
|
|
||||||
|
res = ~ht[3];
|
||||||
|
assert(res.ok && res.value == value, "hash table delete failure");
|
||||||
|
|
||||||
|
res = ~ht[3];
|
||||||
|
assert(!res.ok, "value not deleted from hash table");
|
||||||
|
}
|
||||||
314
src/util.d
Normal file
314
src/util.d
Normal file
@ -0,0 +1,314 @@
|
|||||||
|
import aliases;
|
||||||
|
import includes;
|
||||||
|
import std.stdio;
|
||||||
|
import core.stdc.string : memset;
|
||||||
|
import a = alloc;
|
||||||
|
|
||||||
|
void
|
||||||
|
Logf(Args...)(string fmt, Args args)
|
||||||
|
{
|
||||||
|
writefln(fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Log(string str)
|
||||||
|
{
|
||||||
|
writeln(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Log(char* str)
|
||||||
|
{
|
||||||
|
writeln(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
u64
|
||||||
|
KB(u64 v)
|
||||||
|
{
|
||||||
|
return v * 1024;
|
||||||
|
};
|
||||||
|
|
||||||
|
u64
|
||||||
|
MB(u64 v)
|
||||||
|
{
|
||||||
|
return KB(v) * 1024;
|
||||||
|
};
|
||||||
|
|
||||||
|
u64
|
||||||
|
GB(u64 v)
|
||||||
|
{
|
||||||
|
return MB(v) * 1024;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool
|
||||||
|
BitEq(u64 l, u64 r)
|
||||||
|
{
|
||||||
|
return (l & r) == r;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Node(T)
|
||||||
|
{
|
||||||
|
Node!(T)* next;
|
||||||
|
T value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SLList(T)
|
||||||
|
{
|
||||||
|
Node!(T)* first;
|
||||||
|
Node!(T)* last;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): bool
|
||||||
|
CheckNil(T)(Node!(T)* nil, Node!(T)* node)
|
||||||
|
{
|
||||||
|
return node == null || node == nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): void
|
||||||
|
ConcatInPlace(T)(SLList!(T)* list, SLList!(T)* to_concat)
|
||||||
|
{
|
||||||
|
if (to_concat.first)
|
||||||
|
{
|
||||||
|
if (list.first)
|
||||||
|
{
|
||||||
|
list.last.next = to_concat.first;
|
||||||
|
list.last = to_concat.last;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list.first = to_concat.first;
|
||||||
|
list.last = to_concat.last;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(to_concat, 0, SLList!(T).sizeof);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): Node!(T)*
|
||||||
|
Pop(T)(SLList!(T)*list, Node!(T)* nil)
|
||||||
|
{
|
||||||
|
Node!(T)* node = list.first;
|
||||||
|
|
||||||
|
if (list.first == list.last)
|
||||||
|
{
|
||||||
|
list.first = list.last = nil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list.first = list.first.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): void
|
||||||
|
PushFront(T)(SLList!(T)*list, Node!(T)* node, Node!(T)* nil)
|
||||||
|
{
|
||||||
|
if (CheckNil(nil, list.first))
|
||||||
|
{
|
||||||
|
list.first = list.last = node;
|
||||||
|
node.next = nil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node.next = list.first;
|
||||||
|
list.first = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): void
|
||||||
|
Push(T)(SLList!(T)*list, Node!(T)* node, Node!(T)* nil)
|
||||||
|
{
|
||||||
|
if (CheckNil(nil, list.first))
|
||||||
|
{
|
||||||
|
list.first = list.last = node;
|
||||||
|
node.next = nil;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list.last.next = node;
|
||||||
|
list.last = node;
|
||||||
|
node.next = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct KVPair(K, V)
|
||||||
|
{
|
||||||
|
K key;
|
||||||
|
V value;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Result(V)
|
||||||
|
{
|
||||||
|
V value;
|
||||||
|
bool ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct HashTable(K, V)
|
||||||
|
{
|
||||||
|
alias P = KVPair!(K, V);
|
||||||
|
|
||||||
|
SLList!(P) free_lists;
|
||||||
|
SLList!(P)[] lists;
|
||||||
|
Node!(P)* nil;
|
||||||
|
u64 node_count;
|
||||||
|
u64 list_count;
|
||||||
|
|
||||||
|
void opIndexAssign(V value, K key)
|
||||||
|
{
|
||||||
|
Push(&this, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result!(V) opIndex(K key)
|
||||||
|
{
|
||||||
|
P* pair = Search(&this, key);
|
||||||
|
assert(pair != null, "HashTable key index failure: Result must be present");
|
||||||
|
|
||||||
|
Result!(V) result = { ok: false };
|
||||||
|
if (pair != null)
|
||||||
|
{
|
||||||
|
result.value = pair.value;
|
||||||
|
result.ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result!(V) opIndexUnary(string s: "~")(K key)
|
||||||
|
{
|
||||||
|
return Delete(&this, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HashTable!(K, V)
|
||||||
|
CreateHashTable(K, V)(u64 size)
|
||||||
|
{
|
||||||
|
auto nil = a.Alloc!(Node!(KVPair!(K, V)));
|
||||||
|
auto lists = a.AllocArray!(SLList!(KVPair!(K, V)))(size);
|
||||||
|
|
||||||
|
HashTable!(K, V) table = {
|
||||||
|
lists: lists,
|
||||||
|
list_count: size,
|
||||||
|
nil: nil,
|
||||||
|
free_lists: {
|
||||||
|
first: nil,
|
||||||
|
last: nil,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach(list; table.lists)
|
||||||
|
{
|
||||||
|
list.first = nil;
|
||||||
|
list.last = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): void
|
||||||
|
Clear(K, V)(HashTable!(K, V)* ht)
|
||||||
|
{
|
||||||
|
table.count = 0;
|
||||||
|
foreach(i, list; ht.lists)
|
||||||
|
{
|
||||||
|
ConcatInPlace(&ht.free_lists, ht.lists.ptr + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): Node!(KVPair!(K, V))*
|
||||||
|
Push(K, V)(HashTable!(K, V)* ht, K key, V value)
|
||||||
|
{
|
||||||
|
alias P = KVPair!(K, V);
|
||||||
|
alias N = Node!(P);
|
||||||
|
|
||||||
|
N* node = ht.nil;
|
||||||
|
|
||||||
|
if (ht.free_lists.first != ht.nil)
|
||||||
|
{
|
||||||
|
node = Pop(&ht.free_lists, ht.nil);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node = a.Alloc!(N);
|
||||||
|
}
|
||||||
|
|
||||||
|
node.next = ht.nil;
|
||||||
|
node.value.key = key;
|
||||||
|
node.value.value = value;
|
||||||
|
|
||||||
|
Push(GetList(ht, key), node, ht.nil);
|
||||||
|
|
||||||
|
ht.node_count += 1;
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): KVPair!(K, V)*
|
||||||
|
Search(K, V)(HashTable!(K, V)* ht, K key)
|
||||||
|
{
|
||||||
|
KVPair!(K, V)* result = null;
|
||||||
|
|
||||||
|
auto list = GetList(ht, key);
|
||||||
|
for(auto node = list.first; node != ht.nil; node = node.next)
|
||||||
|
{
|
||||||
|
if (node.value.key == key)
|
||||||
|
{
|
||||||
|
result = &node.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): SLList!(KVPair!(K, V))*
|
||||||
|
GetList(K, V)(HashTable!(K, V)* ht, K key)
|
||||||
|
{
|
||||||
|
u64 hash = Hash(&key);
|
||||||
|
u64 index = hash % ht.list_count;
|
||||||
|
return ht.lists.ptr + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): Result!(V)
|
||||||
|
Delete(K, V)(HashTable!(K, V)* ht, K key)
|
||||||
|
{
|
||||||
|
Result!(V) result = { ok: false };
|
||||||
|
|
||||||
|
auto list = GetList(ht, key);
|
||||||
|
auto prev = ht.nil;
|
||||||
|
for(auto node = list.first; node != ht.nil; node = node.next)
|
||||||
|
{
|
||||||
|
if (node.value.key == key)
|
||||||
|
{
|
||||||
|
if (prev != ht.nil)
|
||||||
|
{
|
||||||
|
prev.next = node.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.ok = true;
|
||||||
|
result.value = node.value.value;
|
||||||
|
|
||||||
|
memset(&node.value, 0, node.value.sizeof);
|
||||||
|
|
||||||
|
Push(&ht.free_lists, node, ht.nil);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u64 HASH_SEED = 5995;
|
||||||
|
|
||||||
|
pragma(inline): u64
|
||||||
|
Hash(T)(T* value)
|
||||||
|
{
|
||||||
|
return XXH3_64bits_withSeed(value, T.sizeof / u8.sizeof, HASH_SEED);
|
||||||
|
}
|
||||||
|
|
||||||
|
pragma(inline): u64
|
||||||
|
Hash(string str)
|
||||||
|
{
|
||||||
|
return XXH3_64bits_withSeed(str.ptr, str.length, HASH_SEED);
|
||||||
|
}
|
||||||
1457
src/vulkan.d
Normal file
1457
src/vulkan.d
Normal file
File diff suppressed because it is too large
Load Diff
246
src/vulkan_funcs.d
Normal file
246
src/vulkan_funcs.d
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
public import includes;
|
||||||
|
import p = platform;
|
||||||
|
import vulkan : Vulkan, VULKAN_LIBS;
|
||||||
|
|
||||||
|
// Global Functions
|
||||||
|
|
||||||
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = null;
|
||||||
|
PFN_vkCreateInstance vkCreateInstance = null;
|
||||||
|
PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties = null;
|
||||||
|
|
||||||
|
// Instance Functions
|
||||||
|
|
||||||
|
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices = null;
|
||||||
|
PFN_vkCreateDevice vkCreateDevice = null;
|
||||||
|
PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties = null;
|
||||||
|
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR = null;
|
||||||
|
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties = null;
|
||||||
|
PFN_vkGetPhysicalDeviceFeatures2 vkGetPhysicalDeviceFeatures2 = null;
|
||||||
|
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties = null;
|
||||||
|
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR = null;
|
||||||
|
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR = null;
|
||||||
|
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR = null;
|
||||||
|
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties = null;
|
||||||
|
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr = null;
|
||||||
|
PFN_vkDestroyInstance vkDestroyInstance = null;
|
||||||
|
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR = null;
|
||||||
|
|
||||||
|
debug
|
||||||
|
{
|
||||||
|
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT = null;
|
||||||
|
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Platform Functions
|
||||||
|
|
||||||
|
version(linux)
|
||||||
|
{
|
||||||
|
PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
version(Windows)
|
||||||
|
{
|
||||||
|
PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Device Functions
|
||||||
|
|
||||||
|
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR = null;
|
||||||
|
PFN_vkCreateImage vkCreateImage = null;
|
||||||
|
PFN_vkCreateImageView vkCreateImageView = null;
|
||||||
|
PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR = null;
|
||||||
|
PFN_vkGetDeviceQueue vkGetDeviceQueue = null;
|
||||||
|
PFN_vkCreateSemaphore vkCreateSemaphore = null;
|
||||||
|
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers = null;
|
||||||
|
PFN_vkCreateCommandPool vkCreateCommandPool = null;
|
||||||
|
PFN_vkCreateFence vkCreateFence = null;
|
||||||
|
PFN_vkCreateDescriptorPool vkCreateDescriptorPool = null;
|
||||||
|
PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout = null;
|
||||||
|
PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets = null;
|
||||||
|
PFN_vkCreatePipelineLayout vkCreatePipelineLayout = null;
|
||||||
|
PFN_vkResetDescriptorPool vkResetDescriptorPool = null;
|
||||||
|
PFN_vkCreateShaderModule vkCreateShaderModule = null;
|
||||||
|
PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines = null;
|
||||||
|
PFN_vkCreateComputePipelines vkCreateComputePipelines = null;
|
||||||
|
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets = null;
|
||||||
|
PFN_vkDestroyDevice vkDestroyDevice = null;
|
||||||
|
PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool = null;
|
||||||
|
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR = null;
|
||||||
|
PFN_vkDestroyImage vkDestroyImage = null;
|
||||||
|
PFN_vkDestroyImageView vkDestroyImageView = null;
|
||||||
|
PFN_vkDestroyCommandPool vkDestroyCommandPool = null;
|
||||||
|
PFN_vkDestroySemaphore vkDestroySemaphore = null;
|
||||||
|
PFN_vkDestroyFence vkDestroyFence = null;
|
||||||
|
PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout = null;
|
||||||
|
PFN_vkDestroyPipeline vkDestroyPipeline = null;
|
||||||
|
PFN_vkWaitForFences vkWaitForFences = null;
|
||||||
|
PFN_vkBeginCommandBuffer vkBeginCommandBuffer = null;
|
||||||
|
PFN_vkEndCommandBuffer vkEndCommandBuffer = null;
|
||||||
|
PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR = null;
|
||||||
|
PFN_vkCmdBindPipeline vkCmdBindPipeline = null;
|
||||||
|
PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets = null;
|
||||||
|
PFN_vkCmdDispatch vkCmdDispatch = null;
|
||||||
|
PFN_vkCmdBeginRendering vkCmdBeginRendering = null;
|
||||||
|
PFN_vkCmdEndRendering vkCmdEndRendering = null;
|
||||||
|
PFN_vkCmdSetViewport vkCmdSetViewport = null;
|
||||||
|
PFN_vkCmdSetScissor vkCmdSetScissor = null;
|
||||||
|
PFN_vkCmdPushConstants vkCmdPushConstants = null;
|
||||||
|
PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer = null;
|
||||||
|
PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers = null;
|
||||||
|
PFN_vkCmdDrawIndexed vkCmdDrawIndexed = null;
|
||||||
|
PFN_vkCmdBlitImage2 vkCmdBlitImage2 = null;
|
||||||
|
PFN_vkCmdPipelineBarrier2 vkCmdPipelineBarrier2 = null;
|
||||||
|
PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage = null;
|
||||||
|
PFN_vkCmdCopyBuffer vkCmdCopyBuffer = null;
|
||||||
|
PFN_vkQueueSubmit2 vkQueueSubmit2 = null;
|
||||||
|
PFN_vkResetFences vkResetFences = null;
|
||||||
|
PFN_vkResetCommandBuffer vkResetCommandBuffer = null;
|
||||||
|
PFN_vkFreeCommandBuffers vkFreeCommandBuffers = null;
|
||||||
|
PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout = null;
|
||||||
|
PFN_vkDestroyShaderModule vkDestroyShaderModule = null;
|
||||||
|
PFN_vkQueuePresentKHR vkQueuePresentKHR = null;
|
||||||
|
PFN_vkCmdDraw vkCmdDraw = null;
|
||||||
|
PFN_vkDeviceWaitIdle vkDeviceWaitIdle = null;
|
||||||
|
PFN_vkCmdClearColorImage vkCmdClearColorImage = null;
|
||||||
|
PFN_vkCreateSampler vkCreateSampler = null;
|
||||||
|
PFN_vkDestroySampler vkDestroySampler = null;
|
||||||
|
PFN_vkGetBufferDeviceAddress vkGetBufferDeviceAddress = null;
|
||||||
|
PFN_vkWaitSemaphores vkWaitSemaphores = null;
|
||||||
|
PFN_vkQueueWaitIdle vkQueueWaitIdle = null;
|
||||||
|
|
||||||
|
bool
|
||||||
|
LoadGlobalFunctions()
|
||||||
|
{
|
||||||
|
p.Library lib;
|
||||||
|
p.Function fn;
|
||||||
|
foreach(name; VULKAN_LIBS)
|
||||||
|
{
|
||||||
|
lib = p.LoadLibrary(name);
|
||||||
|
if (lib.ptr)
|
||||||
|
{
|
||||||
|
fn = p.LoadFunction(lib, "vkGetInstanceProcAddr");
|
||||||
|
vkGetInstanceProcAddr = cast(PFN_vkGetInstanceProcAddr)fn.ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fn.ptr)
|
||||||
|
{
|
||||||
|
vkGetInstanceProcAddr = cast(PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr(null, "vkGetInstanceProcAddr");
|
||||||
|
assert(vkGetInstanceProcAddr != null, "LoadGlobalFunctions failure: Unable to load vkGetInstanceProcAddr");
|
||||||
|
|
||||||
|
vkCreateInstance = cast(PFN_vkCreateInstance)vkGetInstanceProcAddr(null, "vkCreateInstance");
|
||||||
|
assert(vkCreateInstance != null, "LoadGlobalFunctions failure: Unable to load VkCreateInstance");
|
||||||
|
|
||||||
|
vkEnumerateInstanceLayerProperties = cast(PFN_vkEnumerateInstanceLayerProperties)vkGetInstanceProcAddr(null, "vkEnumerateInstanceLayerProperties");
|
||||||
|
assert(vkEnumerateInstanceLayerProperties != null, "LoadGlobalFunctions failure: Unable to load vkEnumerateInstanceLayerProperties");
|
||||||
|
}
|
||||||
|
|
||||||
|
return fn.ptr != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LoadDeviceFunctions(Vulkan* vk)
|
||||||
|
{
|
||||||
|
vkCreateSwapchainKHR = cast(PFN_vkCreateSwapchainKHR)vkGetDeviceProcAddr(vk.device, "vkCreateSwapchainKHR");
|
||||||
|
vkCreateImage = cast(PFN_vkCreateImage)vkGetDeviceProcAddr(vk.device, "vkCreateImage");
|
||||||
|
vkCreateImageView = cast(PFN_vkCreateImageView)vkGetDeviceProcAddr(vk.device, "vkCreateImageView");
|
||||||
|
vkGetSwapchainImagesKHR = cast(PFN_vkGetSwapchainImagesKHR)vkGetDeviceProcAddr(vk.device, "vkGetSwapchainImagesKHR");
|
||||||
|
vkGetDeviceQueue = cast(PFN_vkGetDeviceQueue)vkGetDeviceProcAddr(vk.device, "vkGetDeviceQueue");
|
||||||
|
vkCreateSemaphore = cast(PFN_vkCreateSemaphore)vkGetDeviceProcAddr(vk.device, "vkCreateSemaphore");
|
||||||
|
vkAllocateCommandBuffers = cast(PFN_vkAllocateCommandBuffers)vkGetDeviceProcAddr(vk.device, "vkAllocateCommandBuffers");
|
||||||
|
vkCreateCommandPool = cast(PFN_vkCreateCommandPool)vkGetDeviceProcAddr(vk.device, "vkCreateCommandPool");
|
||||||
|
vkCreateFence = cast(PFN_vkCreateFence)vkGetDeviceProcAddr(vk.device, "vkCreateFence");
|
||||||
|
vkCreateDescriptorPool = cast(PFN_vkCreateDescriptorPool)vkGetDeviceProcAddr(vk.device, "vkCreateDescriptorPool");
|
||||||
|
vkCreateDescriptorSetLayout = cast(PFN_vkCreateDescriptorSetLayout)vkGetDeviceProcAddr(vk.device, "vkCreateDescriptorSetLayout");
|
||||||
|
vkAllocateDescriptorSets = cast(PFN_vkAllocateDescriptorSets)vkGetDeviceProcAddr(vk.device, "vkAllocateDescriptorSets");
|
||||||
|
vkCreatePipelineLayout = cast(PFN_vkCreatePipelineLayout)vkGetDeviceProcAddr(vk.device, "vkCreatePipelineLayout");
|
||||||
|
vkResetDescriptorPool = cast(PFN_vkResetDescriptorPool)vkGetDeviceProcAddr(vk.device, "vkResetDescriptorPool");
|
||||||
|
vkCreateShaderModule = cast(PFN_vkCreateShaderModule)vkGetDeviceProcAddr(vk.device, "vkCreateShaderModule");
|
||||||
|
vkCreateGraphicsPipelines = cast(PFN_vkCreateGraphicsPipelines)vkGetDeviceProcAddr(vk.device, "vkCreateGraphicsPipelines");
|
||||||
|
vkCreateComputePipelines = cast(PFN_vkCreateComputePipelines)vkGetDeviceProcAddr(vk.device, "vkCreateComputePipelines");
|
||||||
|
vkUpdateDescriptorSets = cast(PFN_vkUpdateDescriptorSets)vkGetDeviceProcAddr(vk.device, "vkUpdateDescriptorSets");
|
||||||
|
vkDestroyDevice = cast(PFN_vkDestroyDevice)vkGetDeviceProcAddr(vk.device, "vkDestroyDevice");
|
||||||
|
vkDestroyDescriptorPool = cast(PFN_vkDestroyDescriptorPool)vkGetDeviceProcAddr(vk.device, "vkDestroyDescriptorPool");
|
||||||
|
vkDestroySwapchainKHR = cast(PFN_vkDestroySwapchainKHR)vkGetDeviceProcAddr(vk.device, "vkDestroySwapchainKHR");
|
||||||
|
vkDestroyImage = cast(PFN_vkDestroyImage)vkGetDeviceProcAddr(vk.device, "vkDestroyImage");
|
||||||
|
vkDestroyImageView = cast(PFN_vkDestroyImageView)vkGetDeviceProcAddr(vk.device, "vkDestroyImageView");
|
||||||
|
vkDestroyCommandPool = cast(PFN_vkDestroyCommandPool)vkGetDeviceProcAddr(vk.device, "vkDestroyCommandPool");
|
||||||
|
vkDestroySemaphore = cast(PFN_vkDestroySemaphore)vkGetDeviceProcAddr(vk.device, "vkDestroySemaphore");
|
||||||
|
vkDestroyFence = cast(PFN_vkDestroyFence)vkGetDeviceProcAddr(vk.device, "vkDestroyFence");
|
||||||
|
vkDestroyPipelineLayout = cast(PFN_vkDestroyPipelineLayout)vkGetDeviceProcAddr(vk.device, "vkDestroyPipelineLayout");
|
||||||
|
vkDestroyPipeline = cast(PFN_vkDestroyPipeline)vkGetDeviceProcAddr(vk.device, "vkDestroyPipeline");
|
||||||
|
vkWaitForFences = cast(PFN_vkWaitForFences)vkGetDeviceProcAddr(vk.device, "vkWaitForFences");
|
||||||
|
vkBeginCommandBuffer = cast(PFN_vkBeginCommandBuffer)vkGetDeviceProcAddr(vk.device, "vkBeginCommandBuffer");
|
||||||
|
vkEndCommandBuffer = cast(PFN_vkEndCommandBuffer)vkGetDeviceProcAddr(vk.device, "vkEndCommandBuffer");
|
||||||
|
vkAcquireNextImageKHR = cast(PFN_vkAcquireNextImageKHR)vkGetDeviceProcAddr(vk.device, "vkAcquireNextImageKHR");
|
||||||
|
vkCmdBindPipeline = cast(PFN_vkCmdBindPipeline)vkGetDeviceProcAddr(vk.device, "vkCmdBindPipeline");
|
||||||
|
vkCmdBindDescriptorSets = cast(PFN_vkCmdBindDescriptorSets)vkGetDeviceProcAddr(vk.device, "vkCmdBindDescriptorSets");
|
||||||
|
vkCmdDispatch = cast(PFN_vkCmdDispatch)vkGetDeviceProcAddr(vk.device, "vkCmdDispatch");
|
||||||
|
vkCmdBeginRendering = cast(PFN_vkCmdBeginRendering)vkGetDeviceProcAddr(vk.device, "vkCmdBeginRendering");
|
||||||
|
vkCmdEndRendering = cast(PFN_vkCmdEndRendering)vkGetDeviceProcAddr(vk.device, "vkCmdEndRendering");
|
||||||
|
vkCmdSetViewport = cast(PFN_vkCmdSetViewport)vkGetDeviceProcAddr(vk.device, "vkCmdSetViewport");
|
||||||
|
vkCmdSetScissor = cast(PFN_vkCmdSetScissor)vkGetDeviceProcAddr(vk.device, "vkCmdSetScissor");
|
||||||
|
vkCmdPushConstants = cast(PFN_vkCmdPushConstants)vkGetDeviceProcAddr(vk.device, "vkCmdPushConstants");
|
||||||
|
vkCmdBindIndexBuffer = cast(PFN_vkCmdBindIndexBuffer)vkGetDeviceProcAddr(vk.device, "vkCmdBindIndexBuffer");
|
||||||
|
vkCmdBindVertexBuffers = cast(PFN_vkCmdBindVertexBuffers)vkGetDeviceProcAddr(vk.device, "vkCmdBindVertexBuffers");
|
||||||
|
vkCmdDrawIndexed = cast(PFN_vkCmdDrawIndexed)vkGetDeviceProcAddr(vk.device, "vkCmdDrawIndexed");
|
||||||
|
vkCmdBlitImage2 = cast(PFN_vkCmdBlitImage2)vkGetDeviceProcAddr(vk.device, "vkCmdBlitImage2");
|
||||||
|
vkCmdPipelineBarrier2 = cast(PFN_vkCmdPipelineBarrier2)vkGetDeviceProcAddr(vk.device, "vkCmdPipelineBarrier2");
|
||||||
|
vkCmdCopyBufferToImage = cast(PFN_vkCmdCopyBufferToImage)vkGetDeviceProcAddr(vk.device, "vkCmdCopyBufferToImage");
|
||||||
|
vkCmdCopyBuffer = cast(PFN_vkCmdCopyBuffer)vkGetDeviceProcAddr(vk.device, "vkCmdCopyBuffer");
|
||||||
|
vkQueueSubmit2 = cast(PFN_vkQueueSubmit2)vkGetDeviceProcAddr(vk.device, "vkQueueSubmit2");
|
||||||
|
vkResetFences = cast(PFN_vkResetFences)vkGetDeviceProcAddr(vk.device, "vkResetFences");
|
||||||
|
vkResetCommandBuffer = cast(PFN_vkResetCommandBuffer)vkGetDeviceProcAddr(vk.device, "vkResetCommandBuffer");
|
||||||
|
vkFreeCommandBuffers = cast(PFN_vkFreeCommandBuffers)vkGetDeviceProcAddr(vk.device, "vkFreeCommandBuffers");
|
||||||
|
vkDestroyDescriptorSetLayout = cast(PFN_vkDestroyDescriptorSetLayout)vkGetDeviceProcAddr(vk.device, "vkDestroyDescriptorSetLayout");
|
||||||
|
vkDestroyShaderModule = cast(PFN_vkDestroyShaderModule)vkGetDeviceProcAddr(vk.device, "vkDestroyShaderModule");
|
||||||
|
vkQueuePresentKHR = cast(PFN_vkQueuePresentKHR)vkGetDeviceProcAddr(vk.device, "vkQueuePresentKHR");
|
||||||
|
vkCmdDraw = cast(PFN_vkCmdDraw)vkGetDeviceProcAddr(vk.device, "vkCmdDraw");
|
||||||
|
vkDeviceWaitIdle = cast(PFN_vkDeviceWaitIdle)vkGetDeviceProcAddr(vk.device, "vkDeviceWaitIdle");
|
||||||
|
vkCmdClearColorImage = cast(PFN_vkCmdClearColorImage)vkGetDeviceProcAddr(vk.device, "vkCmdClearColorImage");
|
||||||
|
vkCreateSampler = cast(PFN_vkCreateSampler)vkGetDeviceProcAddr(vk.device, "vkCreateSampler");
|
||||||
|
vkDestroySampler = cast(PFN_vkDestroySampler)vkGetDeviceProcAddr(vk.device, "vkDestroySampler");
|
||||||
|
vkGetBufferDeviceAddress = cast(PFN_vkGetBufferDeviceAddress)vkGetDeviceProcAddr(vk.device, "vkGetBufferDeviceAddress");
|
||||||
|
vkWaitSemaphores = cast(PFN_vkWaitSemaphores)vkGetDeviceProcAddr(vk.device, "vkWaitSemaphores");
|
||||||
|
vkQueueWaitIdle = cast(PFN_vkQueueWaitIdle)vkGetDeviceProcAddr(vk.device, "vkQueueWaitIdle");
|
||||||
|
|
||||||
|
assert(vkCreateSwapchainKHR != null, "LoadDeviceFunctions failure: function pointer is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LoadInstanceFunctions(Vulkan* vk)
|
||||||
|
{
|
||||||
|
vkEnumeratePhysicalDevices = cast(PFN_vkEnumeratePhysicalDevices)vkGetInstanceProcAddr(vk.instance, "vkEnumeratePhysicalDevices");
|
||||||
|
vkDestroySurfaceKHR = cast(PFN_vkDestroySurfaceKHR)vkGetInstanceProcAddr(vk.instance, "vkDestroySurfaceKHR");
|
||||||
|
vkDestroyInstance = cast(PFN_vkDestroyInstance)vkGetInstanceProcAddr(vk.instance, "vkDestroyInstance");
|
||||||
|
vkCreateDevice = cast(PFN_vkCreateDevice)vkGetInstanceProcAddr(vk.instance, "vkCreateDevice");
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties = cast(PFN_vkGetPhysicalDeviceQueueFamilyProperties)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceQueueFamilyProperties");
|
||||||
|
vkGetPhysicalDeviceSurfaceSupportKHR = cast(PFN_vkGetPhysicalDeviceSurfaceSupportKHR)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
|
||||||
|
vkGetPhysicalDeviceProperties = cast(PFN_vkGetPhysicalDeviceProperties)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceProperties");
|
||||||
|
vkGetPhysicalDeviceFeatures2 = cast(PFN_vkGetPhysicalDeviceFeatures2)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceFeatures2");
|
||||||
|
vkEnumerateDeviceExtensionProperties = cast(PFN_vkEnumerateDeviceExtensionProperties)vkGetInstanceProcAddr(vk.instance, "vkEnumerateDeviceExtensionProperties");
|
||||||
|
vkGetPhysicalDeviceSurfacePresentModesKHR = cast(PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceSurfacePresentModesKHR");
|
||||||
|
vkGetPhysicalDeviceSurfaceFormatsKHR = cast(PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceSurfaceFormatsKHR");
|
||||||
|
vkGetPhysicalDeviceSurfaceCapabilitiesKHR = cast(PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
|
||||||
|
vkGetPhysicalDeviceImageFormatProperties = cast(PFN_vkGetPhysicalDeviceImageFormatProperties)vkGetInstanceProcAddr(vk.instance, "vkGetPhysicalDeviceImageFormatProperties");
|
||||||
|
vkGetDeviceProcAddr = cast(PFN_vkGetDeviceProcAddr)vkGetInstanceProcAddr(vk.instance, "vkGetDeviceProcAddr");
|
||||||
|
|
||||||
|
version(linux)
|
||||||
|
{
|
||||||
|
vkCreateXcbSurfaceKHR = cast(PFN_vkCreateXcbSurfaceKHR)vkGetInstanceProcAddr(vk.instance, "vkCreateXcbSurfaceKHR");
|
||||||
|
}
|
||||||
|
|
||||||
|
version(Windows)
|
||||||
|
{
|
||||||
|
vkCreateWin32SurfaceKHR = cast(PFN_vkCreateWin32SurfaceKHR)vkGetInstanceProcAddr(vk.instance, "vkCreateWin32SurfaceKHR");
|
||||||
|
}
|
||||||
|
|
||||||
|
debug
|
||||||
|
{
|
||||||
|
vkCreateDebugUtilsMessengerEXT = cast(PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk.instance, "vkCreateDebugUtilsMessengerEXT");
|
||||||
|
vkDestroyDebugUtilsMessengerEXT = cast(PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(vk.instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(vkEnumeratePhysicalDevices != null, "LoadInstanceFunctions failure: failed to load function");
|
||||||
|
}
|
||||||
153
src/vulkan_logging.d
Normal file
153
src/vulkan_logging.d
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
public import includes;
|
||||||
|
import std.stdio;
|
||||||
|
import vulkan : Vulkan;
|
||||||
|
|
||||||
|
VkBool32
|
||||||
|
DebugCallback(
|
||||||
|
VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
|
||||||
|
VkDebugUtilsMessageTypeFlagsEXT message_type,
|
||||||
|
const VkDebugUtilsMessengerCallbackDataEXT* callback_data,
|
||||||
|
void* user_data
|
||||||
|
)
|
||||||
|
{
|
||||||
|
string ms, mt;
|
||||||
|
|
||||||
|
switch (message_severity) {
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
|
||||||
|
ms = "VERBOSE";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
|
||||||
|
ms = "INFO";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT:
|
||||||
|
ms = "WARNING";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT:
|
||||||
|
ms = "ERROR";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ms = "UNKNOWN";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (message_type) {
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT:
|
||||||
|
mt = "General";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT:
|
||||||
|
mt = "Validation";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT:
|
||||||
|
mt = "Validation | General";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT:
|
||||||
|
mt = "Performance";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT:
|
||||||
|
mt = "General | Performance";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT:
|
||||||
|
mt = "Validation | Performance";
|
||||||
|
break;
|
||||||
|
case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT:
|
||||||
|
mt = "General | Validation | Performance";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mt = "Unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
writefln("[%s: %s]\n%s\n", ms, mt, callback_data.pMessage);
|
||||||
|
|
||||||
|
return VK_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
VkResultStr(VkResult result)
|
||||||
|
{
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case VK_SUCCESS:
|
||||||
|
return "VK_SUCCESS";
|
||||||
|
case VK_NOT_READY:
|
||||||
|
return "VK_NOT_READY";
|
||||||
|
case VK_TIMEOUT:
|
||||||
|
return "VK_TIMEOUT";
|
||||||
|
case VK_EVENT_SET:
|
||||||
|
return "VK_EVENT_SET";
|
||||||
|
case VK_EVENT_RESET:
|
||||||
|
return "VK_EVENT_RESET";
|
||||||
|
case VK_INCOMPLETE:
|
||||||
|
return "VK_INCOMPLETE";
|
||||||
|
case VK_ERROR_OUT_OF_HOST_MEMORY:
|
||||||
|
return "VK_ERROR_OUT_OF_HOST_MEMORY";
|
||||||
|
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
|
||||||
|
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
|
||||||
|
case VK_ERROR_INITIALIZATION_FAILED:
|
||||||
|
return "VK_ERROR_INITIALIZATION_FAILED";
|
||||||
|
case VK_ERROR_DEVICE_LOST:
|
||||||
|
return "VK_ERROR_DEVICE_LOST";
|
||||||
|
case VK_ERROR_MEMORY_MAP_FAILED:
|
||||||
|
return "VK_ERROR_MEMORY_MAP_FAILED";
|
||||||
|
case VK_ERROR_LAYER_NOT_PRESENT:
|
||||||
|
return "VK_ERROR_LAYER_NOT_PRESENT";
|
||||||
|
case VK_ERROR_EXTENSION_NOT_PRESENT:
|
||||||
|
return "VK_ERROR_EXTENSION_NOT_PRESENT";
|
||||||
|
case VK_ERROR_FEATURE_NOT_PRESENT:
|
||||||
|
return "VK_ERROR_FEATURE_NOT_PRESENT";
|
||||||
|
case VK_ERROR_INCOMPATIBLE_DRIVER:
|
||||||
|
return "VK_ERROR_INCOMPATIBLE_DRIVER";
|
||||||
|
case VK_ERROR_TOO_MANY_OBJECTS:
|
||||||
|
return "VK_ERROR_TOO_MANY_OBJECTS";
|
||||||
|
case VK_ERROR_FORMAT_NOT_SUPPORTED:
|
||||||
|
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
|
||||||
|
case VK_ERROR_FRAGMENTED_POOL:
|
||||||
|
return "VK_ERROR_FRAGMENTED_POOL";
|
||||||
|
case VK_ERROR_UNKNOWN:
|
||||||
|
return "VK_ERROR_UNKNOWN";
|
||||||
|
case VK_ERROR_OUT_OF_POOL_MEMORY:
|
||||||
|
return "VK_ERROR_OUT_OF_POOL_MEMORY";
|
||||||
|
case VK_ERROR_INVALID_EXTERNAL_HANDLE:
|
||||||
|
return "VK_ERROR_INVALID_EXTERNAL_HANDLE";
|
||||||
|
case VK_ERROR_FRAGMENTATION:
|
||||||
|
return "VK_ERROR_FRAGMENTATION";
|
||||||
|
case VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS:
|
||||||
|
return "VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS";
|
||||||
|
case VK_PIPELINE_COMPILE_REQUIRED:
|
||||||
|
return "VK_PIPELINE_COMPILE_REQUIRED";
|
||||||
|
case VK_ERROR_SURFACE_LOST_KHR:
|
||||||
|
return "VK_ERROR_SURFACE_LOST_KHR";
|
||||||
|
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
|
||||||
|
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
|
||||||
|
case VK_SUBOPTIMAL_KHR:
|
||||||
|
return "VK_SUBOPTIMAL_KHR";
|
||||||
|
case VK_ERROR_OUT_OF_DATE_KHR:
|
||||||
|
return "VK_ERROR_OUT_OF_DATE_KHR";
|
||||||
|
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
|
||||||
|
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
|
||||||
|
case VK_ERROR_VALIDATION_FAILED_EXT:
|
||||||
|
return "VK_ERROR_VALIDATION_FAILED_EXT";
|
||||||
|
case VK_ERROR_INVALID_SHADER_NV:
|
||||||
|
return "VK_ERROR_INVALID_SHADER_NV";
|
||||||
|
case VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT:
|
||||||
|
return "VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT";
|
||||||
|
case VK_ERROR_NOT_PERMITTED_KHR:
|
||||||
|
return "VK_ERROR_NOT_PERMITTED_KHR";
|
||||||
|
case VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:
|
||||||
|
return "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT";
|
||||||
|
case VK_THREAD_IDLE_KHR:
|
||||||
|
return "VK_THREAD_IDLE_KHR";
|
||||||
|
case VK_THREAD_DONE_KHR:
|
||||||
|
return "VK_THREAD_DONE_KHR";
|
||||||
|
case VK_OPERATION_DEFERRED_KHR:
|
||||||
|
return "VK_OPERATION_DEFERRED_KHR";
|
||||||
|
case VK_OPERATION_NOT_DEFERRED_KHR:
|
||||||
|
return "VK_OPERATION_NOT_DEFERRED_KHR";
|
||||||
|
case VK_ERROR_COMPRESSION_EXHAUSTED_EXT:
|
||||||
|
return "VK_ERROR_COMPRESSION_EXHAUSTED_EXT";
|
||||||
|
case VK_RESULT_MAX_ENUM:
|
||||||
|
return "VK_RESULT_MAX_ENUM";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user