fix(shader): lower f16 NLE comparisons through swapped unordered less-than

This commit is contained in:
boykopovar
2026-10-02 21:17:18 +03:00
parent 313de1c5a3
commit a80d1fd09b
4 changed files with 15 additions and 4 deletions
@@ -228,6 +228,15 @@ int main() {
FillInput();
Run(*device);
Check();
for (std::uint32_t pairBase = 0; pairBase < HalfEdges.size() * HalfEdges.size(); pairBase += Threads) {
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
const auto pair = (pairBase + tid) % (HalfEdges.size() * HalfEdges.size());
Input[tid * Inputs + 6u] = 0xabcd0000u | HalfEdges[pair / HalfEdges.size()];
Input[tid * Inputs + 7u] = 0x12340000u | HalfEdges[pair % HalfEdges.size()];
}
Run(*device);
Check();
}
std::puts("vopc compare tests passed");
return 0;
} catch (const std::exception& error) {
@@ -116,7 +116,7 @@ private:
void emitCompareConstant(const RdnaInstruction& inst, bool value, bool scalar, bool cmpx);
void emitIntegerCompare(const RdnaInstruction& inst, IrOpcode opcode, IrType type, bool scalar, bool cmpx);
void emitInteger16Compare(const RdnaInstruction& inst, IrOpcode opcode, bool signedValue, bool cmpx);
void emitFloatCompare(const RdnaInstruction& inst, IrOpcode opcode, bool half, bool cmpx);
void emitFloatCompare(const RdnaInstruction& inst, IrOpcode opcode, bool half, bool cmpx, bool swap = false);
void emitInteger64Order(const RdnaInstruction& inst, bool signedValue, bool swap, bool negate, bool cmpx);
void emitFloatOrderedCompare(const RdnaInstruction& inst, bool ordered, bool half, bool cmpx);
void emitFloatClassCompare(const RdnaInstruction& inst, bool cmpx);
@@ -2,6 +2,7 @@
#include "Translation/TranslationContext.hpp"
#include <array>
#include <stdexcept>
#include <utility>
namespace ShaderRecompiler {
@@ -41,7 +42,7 @@ void TranslationContext::emitInteger16Compare(const RdnaInstruction& inst, IrOpc
emitCompareResult(inst, IrU1(ir.Emit(opcode, IrType::U1, {&lhs.Value(), &rhs.Value()})), false, cmpx);
}
void TranslationContext::emitFloatCompare(const RdnaInstruction& inst, IrOpcode opcode, bool half, bool cmpx) {
void TranslationContext::emitFloatCompare(const RdnaInstruction& inst, IrOpcode opcode, bool half, bool cmpx, bool swap) {
IrValue* lhs = nullptr;
IrValue* rhs = nullptr;
if (half) {
@@ -51,6 +52,7 @@ void TranslationContext::emitFloatCompare(const RdnaInstruction& inst, IrOpcode
lhs = readOperand(sourceAt(inst, 0u), IrType::F32);
rhs = readOperand(sourceAt(inst, 1u), IrType::F32);
}
if (swap) std::swap(lhs, rhs);
emitCompareResult(inst, IrU1(ir.Emit(opcode, IrType::U1, {lhs, rhs})), false, cmpx);
}
@@ -263,7 +263,7 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) {
emitFloatCompare(inst, IrOpcode::FPUnordLessThanEqual32, true, false);
return true;
case RdnaOpcode::VCmpNleF16:
emitFloatCompare(inst, IrOpcode::FPUnordGreaterThan32, true, false);
emitFloatCompare(inst, IrOpcode::FPUnordLessThan32, true, false, true);
return true;
case RdnaOpcode::VCmpNltF16:
emitFloatCompare(inst, IrOpcode::FPUnordGreaterThanEqual32, true, false);
@@ -290,7 +290,7 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) {
emitFloatCompare(inst, IrOpcode::FPUnordEqual32, true, true);
return true;
case RdnaOpcode::VCmpxNleF16:
emitFloatCompare(inst, IrOpcode::FPUnordGreaterThan32, true, true);
emitFloatCompare(inst, IrOpcode::FPUnordLessThan32, true, true, true);
return true;
case RdnaOpcode::VCmpxTruF16:
emitCompareConstant(inst, true, false, true);