mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 12:25:56 +00:00
tools/make_release_linux.py assembles the Linux release folder and packs it with the static type-2 AppImage runtime: python-build-standalone 3.14 with tkinter, LLVM 23.1.4 (clang, lld, llvm-ar) and the part of the Steam Runtime 3 sniper SDK sysroot a game build reads, so the game, hostcheck, hactool and the translator need no newer glibc than 2.31 and run on SteamOS. The game it builds needs only glibc, the system's Vulkan loader and the libSDL3.so.0 beside it; Opus, libvpx, zstd and libstdc++ are linked in. --prove builds generated/v121 with the folder alone and runs the probes. The installer runs on Linux: release and dev layouts, temp under the XDG cache (the AppImage mount is read-only), cancel through the CLI's process group, language from LANG, xdg-open and a PNG icon, texts that name the right executable, and a warning on kernels older than 6.7. hostcheck reads x86-64-v3 from CPUID, since clang's __builtin_cpu_supports reads it from libgcc, which before GCC 12 has no level bits. build_game.py takes --sysroot, build_hactool.py --cc and build_xlate.py --llvm/--sysroot; linux.c carries the Linux 6.7 write-watch definitions for older headers. Also: shader_census.py and package_build.py use the Linux executable names, and probe-shader writes its shader path with forward slashes.
84 lines
3.9 KiB
C
84 lines
3.9 KiB
C
// Host check of the installer's first step, compiled with the bundled clang at install time: does the CPU run
|
|
// -march=x86-64-v3 code, and does a Vulkan 1.3 device exist. Prints one JSON object on stdout.
|
|
// The Vulkan loader is opened at run time, so a machine without one gets "loader": false instead of a failed start.
|
|
#include <cpuid.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <vulkan/vulkan.h>
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#define open_lib() LoadLibraryA("vulkan-1.dll")
|
|
#define lib_sym(l, n) ((void *)GetProcAddress((l), (n)))
|
|
#else
|
|
#include <dlfcn.h>
|
|
#define open_lib() dlopen("libvulkan.so.1", RTLD_NOW)
|
|
#define lib_sym(l, n) dlsym((l), (n))
|
|
#endif
|
|
|
|
static void json_string(const char *s) {
|
|
putchar('"');
|
|
for (; *s; s++) {
|
|
if (*s == '"' || *s == '\\') printf("\\%c", *s);
|
|
else if ((unsigned char)*s < 0x20) printf("\\u%04x", *s);
|
|
else putchar(*s);
|
|
}
|
|
putchar('"');
|
|
}
|
|
|
|
// The x86-64-v3 level from CPUID: AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT and MOVBE, with the OS saving the YMM state.
|
|
// Not __builtin_cpu_supports("x86-64-v3"): clang reads that from the C runtime's CPU model, and libgcc before GCC 12
|
|
// (the Linux release's sysroot has GCC 10) has no level bits, so it answers false on every CPU.
|
|
static int x86_64_v3(void) {
|
|
unsigned a, b, c, d;
|
|
if (!__get_cpuid(1, &a, &b, &c, &d)) return 0;
|
|
const unsigned fma = 1u << 12, movbe = 1u << 22, osxsave = 1u << 27, avx = 1u << 28, f16c = 1u << 29;
|
|
if ((c & (fma | movbe | osxsave | avx | f16c)) != (fma | movbe | osxsave | avx | f16c)) return 0;
|
|
unsigned lo, hi;
|
|
__asm__("xgetbv" : "=a"(lo), "=d"(hi) : "c"(0));
|
|
if ((lo & 6) != 6) return 0; // XMM and YMM state enabled by the OS
|
|
if (!__get_cpuid_count(7, 0, &a, &b, &c, &d)) return 0;
|
|
const unsigned bmi1 = 1u << 3, avx2 = 1u << 5, bmi2 = 1u << 8;
|
|
if ((b & (bmi1 | avx2 | bmi2)) != (bmi1 | avx2 | bmi2)) return 0;
|
|
if (!__get_cpuid(0x80000001, &a, &b, &c, &d)) return 0;
|
|
return (c & (1u << 5)) != 0; // LZCNT (ABM)
|
|
}
|
|
|
|
int main(void) {
|
|
printf("{\"x86_64_v3\": %s, ", x86_64_v3() ? "true" : "false");
|
|
void *lib = open_lib();
|
|
PFN_vkGetInstanceProcAddr gipa = lib ? (PFN_vkGetInstanceProcAddr)lib_sym(lib, "vkGetInstanceProcAddr") : NULL;
|
|
if (!gipa) {
|
|
printf("\"loader\": false, \"devices\": []}\n");
|
|
return 0;
|
|
}
|
|
printf("\"loader\": true, ");
|
|
PFN_vkCreateInstance create = (PFN_vkCreateInstance)gipa(NULL, "vkCreateInstance");
|
|
VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pApplicationName = "totk-install",
|
|
.apiVersion = VK_API_VERSION_1_3};
|
|
VkInstanceCreateInfo ci = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app};
|
|
VkInstance inst = VK_NULL_HANDLE;
|
|
VkResult r = create ? create(&ci, NULL, &inst) : VK_ERROR_INITIALIZATION_FAILED;
|
|
if (r != VK_SUCCESS) {
|
|
printf("\"instance\": %d, \"devices\": []}\n", (int)r);
|
|
return 0;
|
|
}
|
|
PFN_vkEnumeratePhysicalDevices enumerate = (PFN_vkEnumeratePhysicalDevices)gipa(inst, "vkEnumeratePhysicalDevices");
|
|
PFN_vkGetPhysicalDeviceProperties props = (PFN_vkGetPhysicalDeviceProperties)gipa(inst, "vkGetPhysicalDeviceProperties");
|
|
PFN_vkDestroyInstance destroy = (PFN_vkDestroyInstance)gipa(inst, "vkDestroyInstance");
|
|
VkPhysicalDevice devs[16];
|
|
uint32_t n = 16;
|
|
if (enumerate(inst, &n, devs) < 0) n = 0;
|
|
printf("\"instance\": 0, \"devices\": [");
|
|
for (uint32_t i = 0; i < n; i++) {
|
|
VkPhysicalDeviceProperties p;
|
|
props(devs[i], &p);
|
|
printf("%s{\"name\": ", i ? ", " : "");
|
|
json_string(p.deviceName);
|
|
printf(", \"api\": [%u, %u, %u], \"type\": %d}", VK_API_VERSION_MAJOR(p.apiVersion),
|
|
VK_API_VERSION_MINOR(p.apiVersion), VK_API_VERSION_PATCH(p.apiVersion), (int)p.deviceType);
|
|
}
|
|
printf("]}\n");
|
|
destroy(inst, NULL);
|
|
return 0;
|
|
}
|