Triforce v0.5.1

Hotfix for v0.5.0: crashes (NX2navi game folder refused by Setup, heap-full retries, GTX 10 series noise pass and whole VRAM mirrors, code-patch mods kept with their code, no page file warning), graphics (DLSS with frame generation, DLSS coming back, AMD storage buffer alignment, mesh index map, shared memory barrier, shader conversions, integrated GPUs' uniform snapshot, a Mesh shaders row), controls (microphone after restart, button prompts with a mod's size table, sprint vs Hide text, native mouse camera, controller after Restart now), Setup's Preparing shaders step, and the Linux link fix.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-18 12:06:48 -06:00
parent 72793f2231
commit a750a21025
54 changed files with 1806 additions and 114 deletions

View File

@@ -284,6 +284,9 @@ inline LoweredProgram LowerToMaxwellWith(std::span<const Instruction> code, u32
if (!entered)
for (u32 pc = index + 1; pc < target; ++pc) dead_instructions[pc] = true;
}
// (hookshot) A shared memory store (STS) not yet followed by a barrier: an LDS after it may read what another lane of the
// warp stored (see LDS below)
bool shared_store_pending = false;
for (u32 index = 0; index < code.size(); ++index) {
auto insn = code[index];
result.source_instruction_offsets.push_back(static_cast<u32>(result.instructions.size()));
@@ -1701,6 +1704,7 @@ inline LoweredProgram LowerToMaxwellWith(std::span<const Instruction> code, u32
case 0xb1d: // BAR.SYNC 0 (bit 80: .DEFER_BLOCKING), full workgroup.
if (insn.words[1] || (insn.words[2] & ~0x10000U) || native_predicate != 7)
return fail(index, "native workgroup barrier mode");
shared_store_pending = false;
emit(0xf0a8000000000000ULL | predicate | (u64{1} << 43) |
(u64{1} << 44) | (u64{1} << 39) | (u64{7} << 39));
break;
@@ -1757,6 +1761,23 @@ inline LoweredProgram LowerToMaxwellWith(std::span<const Instruction> code, u32
}
const bool store = opcode != 0x984;
const u32 data = store ? insn.Bits(32, 8) : static_cast<u32>(dest);
// (hookshot) A warp stores to shared memory (STS) and reads it back (LDS) with no barrier between: the Switch runs a
// warp's shared memory accesses in order, Vulkan orders another lane's store and this lane's load only through a
// barrier, and the driver's compiler may move them past each other (OoT's 4/3 gameplay network on NVIDIA's cooperative
// matrix path: 16x2 bright bars, Hookshot issue 2455). As for LDSM: a subgroup barrier before the first LDS after an
// STS, only where the LDS is not predicated (every lane of the warp reaches it). RX_VK_SHARED_NO_LDS_BARRIER=1: none, as before
// ((Triforce) both our STS forms, 0x388 and 0x988 with a uniform base, count as the store; the switch read here, as
// this file's others are: upstream's env_on is in a header we do not have)
static const bool lds_barrier = [] {
const char* e = std::getenv("RX_VK_SHARED_NO_LDS_BARRIER");
return !(e && *e && *e != '0');
}();
if (store) {
shared_store_pending = true;
} else if (shared_store_pending && lds_barrier && native_predicate == 7) {
emit(0xef98000000000000ULL | predicate | (u64{1} << 20)); // (MEMBAR, bit 20: barrier_operations.cpp)
shared_store_pending = false;
}
emit((store ? 0xef58000000000000ULL : 0xef48000000000000ULL) |
predicate | data | (u64{address} << 8) | (u64{insn.Bits(40, 24)} << 20) |
(u64{width} << 48));
@@ -1877,6 +1898,9 @@ inline LoweredProgram LowerToMaxwellWith(std::span<const Instruction> code, u32
return fail(index, "native matrix load mode");
u32 address = insn.Bits(24, 8);
const u64 offset = insn.Bits(40, 24);
// (Fritchii f130f0c50; ours had it already) An address the results overwrite is copied first, to R254: the paths below
// use R246-R253, and R253 is where each matrix's row address is shuffled to, so with the copy there matrices 1-3 of
// an .x2/.x4 read matrix 0's rows (OoT has one such LDSM.x4, gpu/vk/tests/ldsm_address_test.cpp)
if (uniform_offset) {
const u32 uniform = uniform_register(insn.Bits(32, 8));
if (uniform == ~0U) return fail(index, "native matrix load uniform offset");

View File

@@ -146,6 +146,10 @@ void TranslateF2I(TranslatorVisitor& v, u64 insn, const IR::F16F32F64& src_a) {
}()};
const bool is_signed{f2i.is_signed != 0};
const auto [max_bound, min_bound] = ClampBounds(f2i.dest_format, is_signed);
// (Fritchii eba45b151, zortos293/Lichii#1051 by myshadowww) INT32_MAX rounds up to 2^31 as an F32 bound, so an input at or
// above it reached OpConvertFToS out of range, which is undefined. The clamp stops below 2^31 and the exact INT32_MAX is
// selected after the conversion
const bool signed_f32_i32{f2i.dest_format == DestFormat::I32 && f2i.src_format == SrcFormat::F32 && is_signed};
IR::F16F32F64 intermediate;
switch (f2i.src_format) {
@@ -156,7 +160,7 @@ void TranslateF2I(TranslatorVisitor& v, u64 insn, const IR::F16F32F64& src_a) {
break;
}
case SrcFormat::F32: {
const IR::F32 max_val{v.ir.Imm32(static_cast<f32>(max_bound))};
const IR::F32 max_val{v.ir.Imm32(signed_f32_i32 ? 0x1.fffffep30f : static_cast<f32>(max_bound))};
const IR::F32 min_val{v.ir.Imm32(static_cast<f32>(min_bound))};
intermediate = v.ir.FPClamp(rounded_value, min_val, max_val);
break;
@@ -173,6 +177,10 @@ void TranslateF2I(TranslatorVisitor& v, u64 insn, const IR::F16F32F64& src_a) {
const size_t bitsize{std::max<size_t>(32, BitSize(f2i.dest_format))};
IR::U16U32U64 result{v.ir.ConvertFToI(bitsize, is_signed, intermediate)};
if (signed_f32_i32) {
result = IR::U32{v.ir.Select(v.ir.FPGreaterThanEqual(op_a, v.ir.Imm32(0x1p31f)),
v.ir.Imm32(static_cast<u32>((std::numeric_limits<s32>::max)())), result)};
}
bool handled_special_case = false;
const bool special_nan_cases =

View File

@@ -61,6 +61,20 @@ IR::U32 SmallAbs(TranslatorVisitor& v, const IR::U32& value, int bitsize) {
return IR::U32{v.ir.Select(is_least, value, absolute)};
}
// (Fritchii, zortos293 f6a8f5132) U32 -> F32 rounded toward zero. OpConvertUToF rounds to nearest whatever the IR's rounding
// asks, so an input of 2^24 or more could round up: 0xffffff80..0xffffffff became 2^32 instead of 0x4f7fffff (a hash times 2^-32
// reached 1.0). The top 24 significant bits make the float, the rest are dropped; an input below 2^24 converts exactly
IR::F32 ConvertUnsigned32ToFloatRZ(TranslatorVisitor& v, const IR::U32& source) {
auto& ir = v.ir;
const IR::U32 msb{ir.Select(ir.INotEqual(source, ir.Imm32(0)), ir.FindUMsb(source), ir.Imm32(0))};
const IR::U32 shift{ir.ISub(ir.UMax(msb, ir.Imm32(23)), ir.Imm32(23))};
const IR::U32 retained{ir.ShiftRightLogical(source, shift)};
const IR::U32 bits{ir.BitwiseOr(ir.ShiftLeftLogical(ir.IAdd(msb, ir.Imm32(127)), ir.Imm32(23)),
ir.BitwiseAnd(retained, ir.Imm32(0x7fffff)))};
const IR::F32 exact{ir.ConvertIToF(32, 32, false, ir.BitwiseAnd(source, ir.Imm32(0xffffff)))};
return IR::F32{ir.Select(ir.IGreaterThan(msb, ir.Imm32(23), false), ir.BitCast<IR::F32>(bits), exact)};
}
void I2F(TranslatorVisitor& v, u64 insn, IR::U32U64 src) {
const Encoding i2f{insn};
if (i2f.cc != 0) {
@@ -99,7 +113,12 @@ void I2F(TranslatorVisitor& v, u64 insn, IR::U32U64 src) {
.rounding = CastFpRounding(i2f.fp_rounding),
.fmz_mode = IR::FmzMode::DontCare,
};
auto value{v.ir.ConvertIToF(size_t(dst_bitsize), size_t(conversion_src_bitsize), is_signed, src, fp_control)};
IR::F16F32F64 value;
if (!is_signed && conversion_src_bitsize == 32 && dst_bitsize == 32 && i2f.fp_rounding == FpRounding::RZ) {
value = ConvertUnsigned32ToFloatRZ(v, IR::U32{src});
} else {
value = v.ir.ConvertIToF(size_t(dst_bitsize), size_t(conversion_src_bitsize), is_signed, src, fp_control);
}
if (i2f.neg != 0) {
if (i2f.abs != 0 || !is_signed) {
// We know the value is positive