mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-25 18:48:51 -04:00
Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
This commit is contained in:
111
scripts/reshade/check_fx.py
Normal file
111
scripts/reshade/check_fx.py
Normal file
@@ -0,0 +1,111 @@
|
||||
"""Build the development-only ReShade FX probe and exercise real ReShade shaders."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import zlib
|
||||
|
||||
|
||||
def main():
|
||||
probe_source = Path(__file__).resolve().parent
|
||||
root = probe_source.parents[1]
|
||||
sys.path.insert(0, str(root / "nx2"))
|
||||
from reshade_fx import write_preprocessor
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--reshade-source", default=root / "third_party" / "reshade_fx", type=Path,
|
||||
help="ReShade compiler source tree (defaults to vendored sources)")
|
||||
parser.add_argument("--shader-dir", type=Path, help="optionally test the Shaders directory of reshade-shaders")
|
||||
parser.add_argument("--spirv-headers", required=True, type=Path, help="include directory containing spirv.hpp")
|
||||
parser.add_argument("--cxx", default="clang++", help="C++ compiler (LLVM-MinGW on Windows)")
|
||||
args = parser.parse_args()
|
||||
|
||||
bridge = root / "gpu" / "vk" / "reshade"
|
||||
fx_source = args.reshade_source / "source"
|
||||
sources = [
|
||||
fx_source / f"effect_{name}.cpp"
|
||||
for name in ("codegen_spirv", "expression", "lexer", "parser_exp", "parser_stmt", "symbol_table")
|
||||
]
|
||||
|
||||
windows = os.name == "nt"
|
||||
with tempfile.TemporaryDirectory(prefix="triforce-fx-") as temp:
|
||||
tmp = Path(temp)
|
||||
sources.append(write_preprocessor(fx_source, tmp / "effect_preprocessor.cpp"))
|
||||
exe = tmp / ("fx_probe.exe" if windows else "fx_probe")
|
||||
# ReShade's FX code uses filesystem::u8string as a std::string (/Zc:char8_t- with MSVC).
|
||||
command = [args.cxx, "-std=c++20", "-O0", "-fno-char8_t"]
|
||||
if windows:
|
||||
command += ["-municode", "-static", "-include", "share.h"]
|
||||
for include in (bridge, fx_source, args.spirv_headers, root / "third_party" / "stb_image"):
|
||||
command += ["-I", str(include)]
|
||||
subprocess.run([*command, "-o", exe, probe_source / "fx_probe.cpp", bridge / "fx_compile.cpp",
|
||||
bridge / "fx_files.cpp", bridge / "fx_preset.cpp", bridge / "fx_texture.cpp", *sources], check=True)
|
||||
|
||||
fixtures = {
|
||||
"Daltonize.fx": {"technique Daltonize 1", "uniform Type", "bindings 1 1"},
|
||||
"LUT.fx": {"technique LUT 1", "uniform fLUT_AmountChroma", "texture texLUT", "bindings 2 2"},
|
||||
}
|
||||
for name, expected in fixtures.items() if args.shader_dir else ():
|
||||
result = subprocess.run([exe, args.shader_dir / name], text=True, capture_output=True, encoding="utf-8")
|
||||
if result.returncode:
|
||||
raise SystemExit(f"{name}: probe failed ({result.returncode})\n{result.stderr}")
|
||||
missing = expected.difference(result.stdout.splitlines())
|
||||
if missing:
|
||||
raise SystemExit(f"{name}: missing metadata {sorted(missing)}\n{result.stdout}")
|
||||
print(f"{name}: techniques, bindings and SPIR-V entry points verified")
|
||||
|
||||
shaders = tmp / "Shaders"
|
||||
shaders.mkdir()
|
||||
invalid = shaders / "effetto-è.fx"
|
||||
invalid.write_text('#include "missing.fxh"\n', encoding="utf-8")
|
||||
result = subprocess.run([exe, invalid], text=True, capture_output=True, encoding="utf-8")
|
||||
if result.returncode != 1 or "missing.fxh" not in result.stderr:
|
||||
raise SystemExit(f"Missing include was not reported: {result.stderr}")
|
||||
print("Missing include: diagnostic verified with a non-ASCII source path")
|
||||
|
||||
(tmp / "outside.fxh").write_text('#error OUTSIDE_SHADER_ROOT\n', encoding="utf-8")
|
||||
invalid.write_text('#define OUTSIDE "../outside.fxh"\n#include OUTSIDE\n', encoding="utf-8")
|
||||
result = subprocess.run([exe, invalid], text=True, capture_output=True, encoding="utf-8")
|
||||
if result.returncode != 1 or "could not open included file" not in result.stderr or "OUTSIDE_SHADER_ROOT" in result.stderr:
|
||||
raise SystemExit(f"Include left the shader root: {result.stderr}")
|
||||
print("Include confinement: macro-expanded traversal blocked")
|
||||
|
||||
preset = tmp / "Preset.ini"
|
||||
preset.write_text("\ufeffTechniques=A@one.fx,B@two.fx\nTechniqueSorting=B@two.fx,A@one.fx\n"
|
||||
"PreprocessorDefinitions=SWITCH=1\n[one.fx]\nPreprocessorDefinitions=SWITCH=2\n"
|
||||
"Amount=0.5\n", encoding="utf-8")
|
||||
result = subprocess.run([exe, preset], check=True, text=True, capture_output=True, encoding="utf-8")
|
||||
expected = ["B@two.fx", "A@one.fx", "SWITCH=2", "Amount=0.5"]
|
||||
if result.stdout.splitlines() != expected:
|
||||
raise SystemExit(f"Preset metadata differs: {result.stdout}")
|
||||
print("Preset INI: technique order, local definitions and uniform values verified")
|
||||
|
||||
result = subprocess.run([exe, "--builtins"], text=True, capture_output=True, encoding="utf-8")
|
||||
if result.returncode:
|
||||
raise SystemExit(f"Built-in effects failed: {result.stderr}")
|
||||
print("Built-in presets compile their fullscreen shader and supply the expected uniforms")
|
||||
|
||||
example = probe_source / "examples" / "TintedHighlights.fx"
|
||||
result = subprocess.run([exe, example], check=True, text=True, capture_output=True, encoding="utf-8")
|
||||
if "technique TintedHighlights 2" not in result.stdout.splitlines() or result.stdout.count("bindings 1 1") != 2:
|
||||
raise SystemExit(f"TintedHighlights: unexpected pass bindings:\n{result.stdout}")
|
||||
print("TintedHighlights: both graphics passes compile with their texture bindings")
|
||||
|
||||
def chunk(kind, data):
|
||||
return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data))
|
||||
|
||||
png = tmp / "LUT.png"
|
||||
png.write_bytes(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", 1, 1, 8, 6, 0, 0, 0)) +
|
||||
chunk(b"IDAT", zlib.compress(bytes([0, 17, 34, 51, 255]))) + chunk(b"IEND", b""))
|
||||
result = subprocess.run([exe, png], text=True, capture_output=True, encoding="utf-8")
|
||||
if result.returncode or result.stdout.strip() != "1x1 17 34 51 255":
|
||||
raise SystemExit(f"PNG input did not retain RGBA values: {result.stdout} {result.stderr}")
|
||||
print("PNG texture: RGBA values verified")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
44
scripts/reshade/examples/TintedHighlights.fx
Normal file
44
scripts/reshade/examples/TintedHighlights.fx
Normal file
@@ -0,0 +1,44 @@
|
||||
texture Scene : COLOR;
|
||||
texture HighlightMask {
|
||||
Width = BUFFER_WIDTH / 2;
|
||||
Height = BUFFER_HEIGHT / 2;
|
||||
Format = RGBA16F;
|
||||
};
|
||||
|
||||
sampler SceneSampler { Texture = Scene; };
|
||||
sampler MaskSampler { Texture = HighlightMask; };
|
||||
|
||||
void Fullscreen(uint id : SV_VertexID, out float4 position : SV_Position, out float2 uv : TEXCOORD0)
|
||||
{
|
||||
uv = float2((id << 1) & 2, id & 2);
|
||||
position = float4(uv * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float4 MakeMask(float4 position : SV_Position, float2 uv : TEXCOORD0) : SV_Target
|
||||
{
|
||||
float3 rgb = tex2D(SceneSampler, uv).rgb;
|
||||
float luma = dot(rgb, float3(0.2126, 0.7152, 0.0722));
|
||||
return float4(smoothstep(0.32, 0.9, luma).xxx, 1.0);
|
||||
}
|
||||
|
||||
float4 MakeTint(float4 position : SV_Position, float2 uv : TEXCOORD0) : SV_Target
|
||||
{
|
||||
return float4(float3(0.20, 0.07, 0.01) * tex2D(MaskSampler, uv).r, 0.0);
|
||||
}
|
||||
|
||||
technique TintedHighlights
|
||||
{
|
||||
pass Extract {
|
||||
VertexShader = Fullscreen;
|
||||
PixelShader = MakeMask;
|
||||
RenderTarget = HighlightMask;
|
||||
}
|
||||
pass Apply {
|
||||
VertexShader = Fullscreen;
|
||||
PixelShader = MakeTint;
|
||||
BlendEnable = true;
|
||||
SrcBlend = ONE;
|
||||
DestBlend = ONE;
|
||||
ColorWriteMask = 7;
|
||||
}
|
||||
}
|
||||
1
scripts/reshade/examples/TintedHighlights.ini
Normal file
1
scripts/reshade/examples/TintedHighlights.ini
Normal file
@@ -0,0 +1 @@
|
||||
Techniques=TintedHighlights@TintedHighlights.fx
|
||||
115
scripts/reshade/fx_probe.cpp
Normal file
115
scripts/reshade/fx_probe.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "fx_builtin.h"
|
||||
#include "fx_compile.h"
|
||||
#include "fx_preset.h"
|
||||
#include "fx_texture.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
using reshadefx::shader_type;
|
||||
static constexpr tf::reshade::FxCompileOptions options{1920, 1080, 60000, 1, 28, 8};
|
||||
|
||||
static int probe(const std::filesystem::path& path) {
|
||||
if (path == "--builtins") {
|
||||
using namespace tf::reshade;
|
||||
std::string error;
|
||||
using namespace mkwvk::reshade;
|
||||
if (clarity_presets.size() != 20 || builtin_preset(0).shader || builtin_preset(user_preset).shader ||
|
||||
builtin_preset(last_builtin_preset + 1).shader) return 1;
|
||||
if (supports_color_space(true, false, false) || !supports_color_space(true, true, false) ||
|
||||
supports_color_space(false, true, false) || !supports_color_space(false, false, false)) return 1;
|
||||
for (int i = 1; i <= last_builtin_preset; ++i) {
|
||||
if (i == user_preset) continue;
|
||||
const auto included = builtin_preset(i);
|
||||
const auto preset = parse_preset(included.ini, error);
|
||||
if (!preset || preset->techniques.size() != 1) return 1;
|
||||
const auto& tech = preset->techniques[0];
|
||||
if (!supports_color_space(true, preset->linear_hdr, true)) return 1;
|
||||
const auto validate = [&](const FxCompileOptions& target) {
|
||||
const auto fx = compile_builtin_fx(included.source(), target, error, tech.shader);
|
||||
if (!fx) {
|
||||
std::cerr << error;
|
||||
return false;
|
||||
}
|
||||
const auto technique = std::ranges::find(fx->module.techniques, tech.name, &reshadefx::technique::name);
|
||||
if (technique == fx->module.techniques.end() || technique->passes.size() != 1 || fx->shaders.size() < 2) return false;
|
||||
const auto section = preset->shader_options.find(tech.shader);
|
||||
if (section == preset->shader_options.end()) return fx->module.uniforms.empty();
|
||||
for (const auto& [name, value] : section->second) {
|
||||
const auto uniform = std::ranges::find(fx->module.uniforms, name, &reshadefx::uniform::name);
|
||||
if (uniform == fx->module.uniforms.end() || uniform->type.rows != 1 + std::ranges::count(value, ',')) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (!validate({1920, 1080, 60000, 2, 10, 16}) || (!preset->linear_hdr && !validate(options))) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (path.extension() == ".png") {
|
||||
std::string diagnostics;
|
||||
const auto pixels = tf::reshade::load_png(path.parent_path(), path.filename(), diagnostics);
|
||||
if (!pixels) {
|
||||
std::cerr << diagnostics;
|
||||
return 1;
|
||||
}
|
||||
std::cout << pixels->width << 'x' << pixels->height;
|
||||
for (auto i : pixels->rgba) std::cout << ' ' << unsigned(i);
|
||||
std::cout << '\n';
|
||||
return 0;
|
||||
}
|
||||
if (path.extension() == ".ini") {
|
||||
std::string diagnostics;
|
||||
const auto preset = tf::reshade::load_preset(path.parent_path(), path.filename(), diagnostics);
|
||||
if (!preset) {
|
||||
std::cerr << diagnostics << '\n';
|
||||
return 1;
|
||||
}
|
||||
for (const auto& t : preset->techniques) std::cout << t.name << '@' << t.shader << '\n';
|
||||
for (const auto& [key, value] : tf::reshade::preset_definitions(*preset, "one.fx"))
|
||||
std::cout << key << '=' << value << '\n';
|
||||
for (const auto& [key, value] : preset->shader_options.at("one.fx"))
|
||||
if (key != "PreprocessorDefinitions") std::cout << key << '=' << value << '\n';
|
||||
return 0;
|
||||
}
|
||||
const std::filesystem::path includes[] = {path.parent_path()};
|
||||
std::string diagnostics;
|
||||
const auto effect = tf::reshade::compile_fx(path, includes, options, diagnostics);
|
||||
std::cerr << diagnostics;
|
||||
if (!effect) return 1;
|
||||
|
||||
const auto has_shader = [&](const std::string& name, shader_type stage) {
|
||||
return std::ranges::any_of(effect->shaders, [&](const auto& shader) {
|
||||
return shader.name == name && shader.stage == stage && shader.spirv.size() > 5 &&
|
||||
shader.spirv.front() == 0x07230203;
|
||||
});
|
||||
};
|
||||
|
||||
for (const auto& technique : effect->module.techniques) {
|
||||
std::cout << "technique " << technique.name << ' ' << technique.passes.size() << '\n';
|
||||
for (const auto& pass : technique.passes) {
|
||||
const bool valid = pass.cs_entry_point.empty()
|
||||
? has_shader(pass.vs_entry_point, shader_type::vertex) && has_shader(pass.ps_entry_point, shader_type::pixel)
|
||||
: has_shader(pass.cs_entry_point, shader_type::compute);
|
||||
if (!valid) {
|
||||
std::cerr << "Missing SPIR-V entry point for " << technique.name << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "bindings " << pass.texture_bindings.size() << ' ' << pass.sampler_bindings.size() << '\n';
|
||||
}
|
||||
}
|
||||
for (const auto& uniform : effect->module.uniforms) std::cout << "uniform " << uniform.name << '\n';
|
||||
for (const auto& texture : effect->module.textures) std::cout << "texture " << texture.name << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int wmain(int argc, wchar_t** argv) {
|
||||
#else
|
||||
int main(int argc, char** argv) {
|
||||
#endif
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: fx_probe <effect.fx>\n";
|
||||
return 2;
|
||||
}
|
||||
return probe(argv[1]);
|
||||
}
|
||||
Reference in New Issue
Block a user