mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.3.6
This commit is contained in:
29
nx2/build.py
29
nx2/build.py
@@ -206,6 +206,21 @@ NGX_MSVC_RT = "vk_ngx_msvc_rt.cpp"
|
||||
FSR = os.environ.get("HOOKSHOT_FSR", "") == "1"
|
||||
|
||||
|
||||
def renodx_folder(folder):
|
||||
"""HOOKSHOT_RENODX as the build takes it: the folder when it has the compiled shaders, else "" (and why, said)"""
|
||||
if folder and not os.path.isfile(os.path.join(folder, "renodx_spv.h")):
|
||||
print("build: HOOKSHOT_RENODX=%s has no renodx_spv.h (scripts/renodx_shaders.py makes it): built without RenoDX"
|
||||
% folder, flush=True)
|
||||
return ""
|
||||
return folder
|
||||
|
||||
|
||||
# HOOKSHOT_RENODX=<folder>: the Vulkan back end with RenoDX's HDR for OoT (gpu/vk/vk_renodx.cpp), from RenoDX's shaders fetched
|
||||
# and compiled into that folder's renodx_spv.h by scripts/renodx_shaders.py (never committed: they are worked from the game's
|
||||
# own shaders). Off without it (make_game.py --renodx does both); the host then keeps the game's own scene format (nn_vi.c)
|
||||
RENODX = renodx_folder(os.environ.get("HOOKSHOT_RENODX", ""))
|
||||
|
||||
|
||||
def ngx_link(sdk, mingw):
|
||||
"""What triforce_vk.dll's link adds for NVIDIA DLSS on Windows: NVIDIA's library and the registry calls it makes; with
|
||||
llvm-mingw, not Microsoft's C++ runtime it names (libcpmt: vk_ngx_msvc_rt.cpp has what it needs of it, and the other
|
||||
@@ -823,7 +838,9 @@ def main():
|
||||
host_fl + ["-I" + os.path.join(OPUS, "include")] +
|
||||
(["-I" + os.path.join(FFMPEG, "include")] if FFMPEG else []) +
|
||||
(FFMPEG_LX[0] if LINUX and FFMPEG_LX else []) +
|
||||
([stamp_def] if os.path.basename(s) == "hos_main.c" else []), host_deps) for s in host_srcs]
|
||||
([stamp_def] if os.path.basename(s) == "hos_main.c" else []) +
|
||||
# (RenoDX's HDR in this build: the scene's colour target is RGBA16F with HDR Native, hos_scene_rgba16f)
|
||||
(["-DHOOKSHOT_RENODX"] if RENODX and os.path.basename(s) == "nn_vi.c" else []), host_deps) for s in host_srcs]
|
||||
# libopus 1.5.2 (third_party/opus, from TOTKPort): nn::codec's hardware Opus decoder (host/nn_codec.c)
|
||||
# (hookshot: built for the same CPU target as the rest (CPU), so its float code can be vectorized where the target has
|
||||
# AVX2: the vendored copy has no x86 intrinsics files of its own)
|
||||
@@ -913,6 +930,12 @@ def main():
|
||||
fsr_flags = ["-DHOOKSHOT_FSR", "-I" + os.path.join(kit.HERE, "..", "third_party", "fidelityfx")] if FSR else []
|
||||
if FSR:
|
||||
print("the Vulkan back end: with AMD FSR 4 (AMD's FSR API headers, third_party/fidelityfx)", flush=True)
|
||||
# (RenoDX's HDR, a build's option too: only vk_renodx.cpp sees its compiled shaders; without them it is the stubs
|
||||
# that replace nothing)
|
||||
renodx_flags = ["-DHOOKSHOT_RENODX", "-I" + RENODX] if RENODX else []
|
||||
renodx_deps = open(os.path.join(RENODX, "renodx_spv.h"), "rb").read() if RENODX else b""
|
||||
if RENODX:
|
||||
print("the Vulkan back end: with RenoDX's HDR (its shaders compiled in %s)" % RENODX, flush=True)
|
||||
# (Eden's recompiler and sirit see only their own headers: a change to the back end's vk_*.h does not
|
||||
# rebuild their ~500 files; the back end itself depends on everything, suyu's texture decoders included)
|
||||
vk_lib_deps = tree_headers(os.path.join(vk, "eden"), os.path.join(vk, "sirit"), os.path.join(vk, "compat"),
|
||||
@@ -952,8 +975,10 @@ def main():
|
||||
([stamp_def] if os.path.basename(src) == "vk_menu.cpp" else []) +
|
||||
(ngx_flags if os.path.basename(src) == "vk_dlss.cpp" else []) +
|
||||
(imgui_flags if os.path.basename(src) in imgui_users else []) +
|
||||
(fsr_flags if os.path.basename(src) == "vk_fsr4.cpp" else []),
|
||||
(fsr_flags if os.path.basename(src) == "vk_fsr4.cpp" else []) +
|
||||
(renodx_flags if os.path.basename(src) == "vk_renodx.cpp" else []),
|
||||
vk_lib_deps if lib else vdeps + (logo_text if os.path.basename(src) == "vk_imgui.cpp" else b"") +
|
||||
(renodx_deps if os.path.basename(src) == "vk_renodx.cpp" else b"") +
|
||||
(ngx_deps if os.path.basename(src) == "vk_dlss.cpp" else b"") +
|
||||
(imgui_deps if os.path.basename(src) in imgui_users else b"")))
|
||||
if NGX_SDK and not LINUX and toolchain.mingw():
|
||||
|
||||
@@ -1272,6 +1272,40 @@ def fsr_wanted(a, out):
|
||||
return bool(getattr(a, "fsr", False)) or bool(a.update and os.path.isfile(os.path.join(out, FSR_MARK)))
|
||||
|
||||
|
||||
RENODX_MARK = ".hookshot_renodx" # (in a game folder built with RenoDX's HDR: --update builds it with RenoDX again)
|
||||
|
||||
|
||||
def renodx_wanted(a, out):
|
||||
"""RenoDX's HDR in this build. (Triforce, 11-13: every build has it, not only one that asks with --renodx; --no-renodx
|
||||
builds without. It acts only with the Insert menu's HDR set to Native.)"""
|
||||
return not getattr(a, "no_renodx", False)
|
||||
|
||||
|
||||
def prepare_renodx(work):
|
||||
"""--renodx: RenoDX's shaders fetched and compiled before the build (scripts/renodx_shaders.py), into HOOKSHOT_RENODX when
|
||||
set, else a renodx folder beside the work folder. Only what is missing or not the file expected is downloaded, and the
|
||||
shaders are compiled again only when the script's pinned sources or compiler changed. Returns the folder"""
|
||||
import importlib.util
|
||||
path = os.path.join(ROOT, "scripts", "renodx_shaders.py")
|
||||
if not os.path.isfile(path): # (the AppImage carries no scripts/: its Vulkan back end comes built, without RenoDX)
|
||||
print("RenoDX's HDR: this builder does not carry %s: built without RenoDX" % path, flush=True)
|
||||
return None
|
||||
spec = importlib.util.spec_from_file_location("renodx_shaders", path)
|
||||
renodx = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(renodx)
|
||||
folder = os.environ.get("HOOKSHOT_RENODX") or os.path.join(os.path.dirname(work), "renodx")
|
||||
print(renodx.NOTICE, flush=True)
|
||||
try:
|
||||
renodx.prepare(folder, "linux" if LINUX else "windows", say=lambda line: print(line, flush=True))
|
||||
except (OSError, ValueError) as e:
|
||||
# (Triforce, 11-13: RenoDX is in every build now, so a PC without a connection, or a download that is not the file
|
||||
# expected, must not stop the game's build: this one is made without RenoDX and says so; the next build tries again)
|
||||
print("RenoDX's shaders could not be fetched or compiled (%s): this build is made without RenoDX's HDR. The next "
|
||||
"build tries again." % e, flush=True)
|
||||
return None
|
||||
return folder
|
||||
|
||||
|
||||
def place_ngx_runtime(out):
|
||||
"""(NVIDIA DLSS) a game built with NVIDIA's SDK (HOOKSHOT_NGX_SDK, as nx2/build.py takes it) gets DLSS's runtime in its ngx
|
||||
folder, where gpu/vk/vk_dlss.cpp looks first: nvngx_dlss.dll on Windows, libnvidia-ngx-dlss.so.<version> on Linux. Never
|
||||
@@ -1318,6 +1352,11 @@ def parse_args():
|
||||
# (AMD FSR 4, off unless asked: nothing is downloaded. gpu/vk/vk_fsr4.cpp)
|
||||
p.add_argument("--fsr", action="store_true", help="build with AMD FSR 4 (AMD's DLLs are not included: see the readme)")
|
||||
p.add_argument("--no-fsr", action="store_true", help="with --update: build without AMD FSR 4 even if the folder had it")
|
||||
# (RenoDX's HDR, in every build since 11-13: its shaders and the Slang compiler are downloaded and compiled here.
|
||||
# scripts/renodx_shaders.py, gpu/vk/vk_renodx.cpp)
|
||||
p.add_argument("--renodx", action="store_true",
|
||||
help="kept for old command lines: every build has RenoDX's HDR now (its shaders and the Slang compiler are downloaded, about 60 MB)")
|
||||
p.add_argument("--no-renodx", action="store_true", help="build without RenoDX's HDR: nothing of it is downloaded")
|
||||
a = p.parse_args()
|
||||
if a.prepare: # (first: a bad --game below is said as RecompLauncher's "error" line)
|
||||
global PREPARE
|
||||
@@ -1395,6 +1434,26 @@ def main(a=None):
|
||||
os.environ.pop("HOOKSHOT_FSR", None)
|
||||
if os.path.isfile(os.path.join(out, FSR_MARK)):
|
||||
os.remove(os.path.join(out, FSR_MARK))
|
||||
# (RenoDX's HDR: its shaders made first, then the build's switch for nx2/build.py and the folder's mark for the next
|
||||
# --update)
|
||||
if renodx_wanted(a, out):
|
||||
if os.environ.get("HOOKSHOT_VK_PREBUILT"): # (the AppImage's back end, built without RenoDX)
|
||||
print("RenoDX's HDR: this build uses the prebuilt Vulkan back end (HOOKSHOT_VK_PREBUILT), which has no RenoDX: built "
|
||||
"without it", flush=True)
|
||||
os.environ.pop("HOOKSHOT_RENODX", None)
|
||||
else:
|
||||
renodx_folder = prepare_renodx(work)
|
||||
if renodx_folder:
|
||||
os.environ["HOOKSHOT_RENODX"] = renodx_folder
|
||||
open(os.path.join(out, RENODX_MARK), "w").close()
|
||||
else:
|
||||
os.environ.pop("HOOKSHOT_RENODX", None)
|
||||
if os.path.isfile(os.path.join(out, RENODX_MARK)):
|
||||
os.remove(os.path.join(out, RENODX_MARK))
|
||||
else:
|
||||
os.environ.pop("HOOKSHOT_RENODX", None)
|
||||
if os.path.isfile(os.path.join(out, RENODX_MARK)):
|
||||
os.remove(os.path.join(out, RENODX_MARK))
|
||||
exefs = os.path.join(work, "exefs")
|
||||
romfs = os.path.join(out, "romfs")
|
||||
|
||||
|
||||
@@ -442,6 +442,22 @@ def patch_text_speed(s):
|
||||
return s.replace('#include "a64.h"\n', '#include "a64.h"\n' + TEXT_DECL, 1)
|
||||
|
||||
|
||||
# (local, RenoDX port) The scene's colour target, "agl::RenderDisplay(color)": the game picks engine format 26 (R11G11B10F) or 44
|
||||
# (RGBA16F) at main+0x65234c (0x8067234c; RenoDX's addon.cpp names the place for build e0f3ccfa). RenoDX's tone mapping wants
|
||||
# RGBA16F, whose values may be negative, with HDR Native: host/nn_vi.c hos_scene_rgba16f says when. The other choice of that
|
||||
# csel is 44 already, so both become 44 then; the UNORM branch at main+0x6525b0 is left alone.
|
||||
RGBA16F_DECL = "int hos_scene_rgba16f(void);\n"
|
||||
RGBA16F_OLD = (" c->x[9] = 0x1aULL;\n c->x[9] &= 0xFFFFFFFFULL;\n"
|
||||
" { uint64_t _r = (!c->z) ? c->x[10] : c->x[9]; _r &= 0xFFFFFFFFULL; c->x[9] = _r; }\nL_80672354:;")
|
||||
RGBA16F_NEW = RGBA16F_OLD.replace("c->x[9] = 0x1aULL;", "c->x[9] = hos_scene_rgba16f() ? 0x2cULL : 0x1aULL;", 1)
|
||||
|
||||
|
||||
def patch_scene_format(s):
|
||||
if RGBA16F_OLD not in s:
|
||||
return None
|
||||
return s.replace(RGBA16F_OLD, RGBA16F_NEW, 1).replace('#include "a64.h"\n', '#include "a64.h"\n' + RGBA16F_DECL, 1)
|
||||
|
||||
|
||||
def apply(gen, *, protect_hearts=False, required=False):
|
||||
"""required: the lift of the supported build (LIFE_BUILD_ID), whole: a missing output-size edit stops it (apply_output_size).
|
||||
The other patches only warn when their place is not found once."""
|
||||
@@ -456,6 +472,7 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
done["player flight rotation"] = 0
|
||||
done["free camera"] = 0
|
||||
done["mouse camera"] = 0
|
||||
done["scene colour target format"] = 0 # (local, RenoDX port)
|
||||
step_sites, step_files = 0, [] # (the divides with the hook, and the files that have it)
|
||||
whole_sites = 0 # (the counters of WHOLE_SITES with the whole frames: patch_whole_frames)
|
||||
sound_jobs = solver_sites = 0 # (patch_sound_job, patch_solver_steps: the places found with their hooks)
|
||||
@@ -494,6 +511,11 @@ def apply(gen, *, protect_hearts=False, required=False):
|
||||
if n:
|
||||
done["fixed path's scale"] += 1
|
||||
print("oot_patches: the fixed path's scale in", os.path.basename(path))
|
||||
fmt = patch_scene_format(out) if protect_hearts else None
|
||||
if fmt is not None:
|
||||
out = fmt
|
||||
done["scene colour target format"] += 1
|
||||
print("oot_patches: the scene's colour target format in", os.path.basename(path))
|
||||
life = patch_life(out) if protect_hearts else None
|
||||
if life is not None:
|
||||
out = life
|
||||
|
||||
Reference in New Issue
Block a user