Merge pull request #2693 from ReinUsesLisp/hsetp2

shader/half_set_predicate: Implement missing HSETP2 variants
This commit is contained in:
Fernando Sahmkow 2019-07-20 17:25:08 -04:00 committed by GitHub
commit 0a67416971
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 61 deletions

View file

@ -931,8 +931,6 @@ union Instruction {
} csetp; } csetp;
union { union {
BitField<35, 4, PredCondition> cond;
BitField<49, 1, u64> h_and;
BitField<6, 1, u64> ftz; BitField<6, 1, u64> ftz;
BitField<45, 2, PredOperation> op; BitField<45, 2, PredOperation> op;
BitField<3, 3, u64> pred3; BitField<3, 3, u64> pred3;
@ -940,9 +938,21 @@ union Instruction {
BitField<43, 1, u64> negate_a; BitField<43, 1, u64> negate_a;
BitField<44, 1, u64> abs_a; BitField<44, 1, u64> abs_a;
BitField<47, 2, HalfType> type_a; BitField<47, 2, HalfType> type_a;
BitField<31, 1, u64> negate_b; union {
BitField<30, 1, u64> abs_b; BitField<35, 4, PredCondition> cond;
BitField<28, 2, HalfType> type_b; BitField<49, 1, u64> h_and;
BitField<31, 1, u64> negate_b;
BitField<30, 1, u64> abs_b;
BitField<28, 2, HalfType> type_b;
} reg;
union {
BitField<56, 1, u64> negate_b;
BitField<54, 1, u64> abs_b;
} cbuf;
union {
BitField<49, 4, PredCondition> cond;
BitField<53, 1, u64> h_and;
} cbuf_and_imm;
BitField<42, 1, u64> neg_pred; BitField<42, 1, u64> neg_pred;
BitField<39, 3, u64> pred39; BitField<39, 3, u64> pred39;
} hsetp2; } hsetp2;
@ -1548,7 +1558,9 @@ public:
HFMA2_RC, HFMA2_RC,
HFMA2_RR, HFMA2_RR,
HFMA2_IMM_R, HFMA2_IMM_R,
HSETP2_C,
HSETP2_R, HSETP2_R,
HSETP2_IMM,
HSET2_R, HSET2_R,
POPC_C, POPC_C,
POPC_R, POPC_R,
@ -1831,7 +1843,9 @@ private:
INST("01100---1-------", Id::HFMA2_RC, Type::Hfma2, "HFMA2_RC"), INST("01100---1-------", Id::HFMA2_RC, Type::Hfma2, "HFMA2_RC"),
INST("0101110100000---", Id::HFMA2_RR, Type::Hfma2, "HFMA2_RR"), INST("0101110100000---", Id::HFMA2_RR, Type::Hfma2, "HFMA2_RR"),
INST("01110---0-------", Id::HFMA2_IMM_R, Type::Hfma2, "HFMA2_R_IMM"), INST("01110---0-------", Id::HFMA2_IMM_R, Type::Hfma2, "HFMA2_R_IMM"),
INST("0101110100100---", Id::HSETP2_R, Type::HalfSetPredicate, "HSETP_R"), INST("0111111-1-------", Id::HSETP2_C, Type::HalfSetPredicate, "HSETP2_C"),
INST("0101110100100---", Id::HSETP2_R, Type::HalfSetPredicate, "HSETP2_R"),
INST("0111111-0-------", Id::HSETP2_IMM, Type::HalfSetPredicate, "HSETP2_IMM"),
INST("0101110100011---", Id::HSET2_R, Type::HalfSet, "HSET2_R"), INST("0101110100011---", Id::HSET2_R, Type::HalfSet, "HSET2_R"),
INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"), INST("0101000010000---", Id::MUFU, Type::Arithmetic, "MUFU"),
INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"), INST("0100110010010---", Id::RRO_C, Type::Arithmetic, "RRO_C"),

View file

@ -254,10 +254,6 @@ public:
} }
private: private:
using OperationDecompilerFn = std::string (GLSLDecompiler::*)(Operation);
using OperationDecompilersArray =
std::array<OperationDecompilerFn, static_cast<std::size_t>(OperationCode::Amount)>;
void DeclareVertex() { void DeclareVertex() {
if (stage != ShaderStage::Vertex) if (stage != ShaderStage::Vertex)
return; return;
@ -1400,14 +1396,10 @@ private:
return fmt::format("{}[{}]", pair, VisitOperand(operation, 1, Type::Uint)); return fmt::format("{}[{}]", pair, VisitOperand(operation, 1, Type::Uint));
} }
std::string LogicalAll2(Operation operation) { std::string LogicalAnd2(Operation operation) {
return GenerateUnary(operation, "all", Type::Bool, Type::Bool2); return GenerateUnary(operation, "all", Type::Bool, Type::Bool2);
} }
std::string LogicalAny2(Operation operation) {
return GenerateUnary(operation, "any", Type::Bool, Type::Bool2);
}
template <bool with_nan> template <bool with_nan>
std::string GenerateHalfComparison(Operation operation, const std::string& compare_op) { std::string GenerateHalfComparison(Operation operation, const std::string& compare_op) {
const std::string comparison{GenerateBinaryCall(operation, compare_op, Type::Bool2, const std::string comparison{GenerateBinaryCall(operation, compare_op, Type::Bool2,
@ -1714,7 +1706,7 @@ private:
return "utof(gl_WorkGroupID"s + GetSwizzle(element) + ')'; return "utof(gl_WorkGroupID"s + GetSwizzle(element) + ')';
} }
static constexpr OperationDecompilersArray operation_decompilers = { static constexpr std::array operation_decompilers = {
&GLSLDecompiler::Assign, &GLSLDecompiler::Assign,
&GLSLDecompiler::Select, &GLSLDecompiler::Select,
@ -1798,8 +1790,7 @@ private:
&GLSLDecompiler::LogicalXor, &GLSLDecompiler::LogicalXor,
&GLSLDecompiler::LogicalNegate, &GLSLDecompiler::LogicalNegate,
&GLSLDecompiler::LogicalPick2, &GLSLDecompiler::LogicalPick2,
&GLSLDecompiler::LogicalAll2, &GLSLDecompiler::LogicalAnd2,
&GLSLDecompiler::LogicalAny2,
&GLSLDecompiler::LogicalLessThan<Type::Float>, &GLSLDecompiler::LogicalLessThan<Type::Float>,
&GLSLDecompiler::LogicalEqual<Type::Float>, &GLSLDecompiler::LogicalEqual<Type::Float>,
@ -1863,6 +1854,7 @@ private:
&GLSLDecompiler::WorkGroupId<1>, &GLSLDecompiler::WorkGroupId<1>,
&GLSLDecompiler::WorkGroupId<2>, &GLSLDecompiler::WorkGroupId<2>,
}; };
static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount));
std::string GetRegister(u32 index) const { std::string GetRegister(u32 index) const {
return GetDeclarationWithSuffix(index, "gpr"); return GetDeclarationWithSuffix(index, "gpr");

View file

@ -205,10 +205,6 @@ public:
} }
private: private:
using OperationDecompilerFn = Id (SPIRVDecompiler::*)(Operation);
using OperationDecompilersArray =
std::array<OperationDecompilerFn, static_cast<std::size_t>(OperationCode::Amount)>;
static constexpr auto INTERNAL_FLAGS_COUNT = static_cast<std::size_t>(InternalFlag::Amount); static constexpr auto INTERNAL_FLAGS_COUNT = static_cast<std::size_t>(InternalFlag::Amount);
void AllocateBindings() { void AllocateBindings() {
@ -804,12 +800,7 @@ private:
return {}; return {};
} }
Id LogicalAll2(Operation operation) { Id LogicalAnd2(Operation operation) {
UNIMPLEMENTED();
return {};
}
Id LogicalAny2(Operation operation) {
UNIMPLEMENTED(); UNIMPLEMENTED();
return {}; return {};
} }
@ -1206,7 +1197,7 @@ private:
return {}; return {};
} }
static constexpr OperationDecompilersArray operation_decompilers = { static constexpr std::array operation_decompilers = {
&SPIRVDecompiler::Assign, &SPIRVDecompiler::Assign,
&SPIRVDecompiler::Ternary<&Module::OpSelect, Type::Float, Type::Bool, Type::Float, &SPIRVDecompiler::Ternary<&Module::OpSelect, Type::Float, Type::Bool, Type::Float,
@ -1291,8 +1282,7 @@ private:
&SPIRVDecompiler::Binary<&Module::OpLogicalNotEqual, Type::Bool>, &SPIRVDecompiler::Binary<&Module::OpLogicalNotEqual, Type::Bool>,
&SPIRVDecompiler::Unary<&Module::OpLogicalNot, Type::Bool>, &SPIRVDecompiler::Unary<&Module::OpLogicalNot, Type::Bool>,
&SPIRVDecompiler::LogicalPick2, &SPIRVDecompiler::LogicalPick2,
&SPIRVDecompiler::LogicalAll2, &SPIRVDecompiler::LogicalAnd2,
&SPIRVDecompiler::LogicalAny2,
&SPIRVDecompiler::Binary<&Module::OpFOrdLessThan, Type::Bool, Type::Float>, &SPIRVDecompiler::Binary<&Module::OpFOrdLessThan, Type::Bool, Type::Float>,
&SPIRVDecompiler::Binary<&Module::OpFOrdEqual, Type::Bool, Type::Float>, &SPIRVDecompiler::Binary<&Module::OpFOrdEqual, Type::Bool, Type::Float>,
@ -1357,6 +1347,7 @@ private:
&SPIRVDecompiler::WorkGroupId<1>, &SPIRVDecompiler::WorkGroupId<1>,
&SPIRVDecompiler::WorkGroupId<2>, &SPIRVDecompiler::WorkGroupId<2>,
}; };
static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount));
const VKDevice& device; const VKDevice& device;
const ShaderIR& ir; const ShaderIR& ir;

View file

@ -23,38 +23,51 @@ u32 ShaderIR::DecodeHalfSetPredicate(NodeBlock& bb, u32 pc) {
Node op_a = UnpackHalfFloat(GetRegister(instr.gpr8), instr.hsetp2.type_a); Node op_a = UnpackHalfFloat(GetRegister(instr.gpr8), instr.hsetp2.type_a);
op_a = GetOperandAbsNegHalf(op_a, instr.hsetp2.abs_a, instr.hsetp2.negate_a); op_a = GetOperandAbsNegHalf(op_a, instr.hsetp2.abs_a, instr.hsetp2.negate_a);
Node op_b = [&]() { Tegra::Shader::PredCondition cond{};
switch (opcode->get().GetId()) { bool h_and{};
case OpCode::Id::HSETP2_R: Node op_b{};
return GetOperandAbsNegHalf(GetRegister(instr.gpr20), instr.hsetp2.abs_a, switch (opcode->get().GetId()) {
instr.hsetp2.negate_b); case OpCode::Id::HSETP2_C:
default: cond = instr.hsetp2.cbuf_and_imm.cond;
UNREACHABLE(); h_and = instr.hsetp2.cbuf_and_imm.h_and;
return Immediate(0); op_b = GetOperandAbsNegHalf(GetConstBuffer(instr.cbuf34.index, instr.cbuf34.offset),
} instr.hsetp2.cbuf.abs_b, instr.hsetp2.cbuf.negate_b);
}(); break;
op_b = UnpackHalfFloat(op_b, instr.hsetp2.type_b); case OpCode::Id::HSETP2_IMM:
cond = instr.hsetp2.cbuf_and_imm.cond;
// We can't use the constant predicate as destination. h_and = instr.hsetp2.cbuf_and_imm.h_and;
ASSERT(instr.hsetp2.pred3 != static_cast<u64>(Pred::UnusedIndex)); op_b = UnpackHalfImmediate(instr, true);
break;
const Node second_pred = GetPredicate(instr.hsetp2.pred39, instr.hsetp2.neg_pred != 0); case OpCode::Id::HSETP2_R:
cond = instr.hsetp2.reg.cond;
h_and = instr.hsetp2.reg.h_and;
op_b =
UnpackHalfFloat(GetOperandAbsNegHalf(GetRegister(instr.gpr20), instr.hsetp2.reg.abs_b,
instr.hsetp2.reg.negate_b),
instr.hsetp2.reg.type_b);
break;
default:
UNREACHABLE();
op_b = Immediate(0);
}
const OperationCode combiner = GetPredicateCombiner(instr.hsetp2.op); const OperationCode combiner = GetPredicateCombiner(instr.hsetp2.op);
const OperationCode pair_combiner = const Node pred39 = GetPredicate(instr.hsetp2.pred39, instr.hsetp2.neg_pred);
instr.hsetp2.h_and ? OperationCode::LogicalAll2 : OperationCode::LogicalAny2;
const Node comparison = GetPredicateComparisonHalf(instr.hsetp2.cond, op_a, op_b); const auto Write = [&](u64 dest, Node src) {
const Node first_pred = Operation(pair_combiner, comparison); SetPredicate(bb, dest, Operation(combiner, std::move(src), pred39));
};
// Set the primary predicate to the result of Predicate OP SecondPredicate const Node comparison = GetPredicateComparisonHalf(cond, op_a, op_b);
const Node value = Operation(combiner, first_pred, second_pred); const u64 first = instr.hsetp2.pred0;
SetPredicate(bb, instr.hsetp2.pred3, value); const u64 second = instr.hsetp2.pred3;
if (h_and) {
if (instr.hsetp2.pred0 != static_cast<u64>(Pred::UnusedIndex)) { const Node joined = Operation(OperationCode::LogicalAnd2, comparison);
// Set the secondary predicate to the result of !Predicate OP SecondPredicate, if enabled Write(first, joined);
const Node negated_pred = Operation(OperationCode::LogicalNegate, first_pred); Write(second, Operation(OperationCode::LogicalNegate, joined));
SetPredicate(bb, instr.hsetp2.pred0, Operation(combiner, negated_pred, second_pred)); } else {
Write(first, Operation(OperationCode::LogicalPick2, comparison, Immediate(0u)));
Write(second, Operation(OperationCode::LogicalPick2, comparison, Immediate(1u)));
} }
return pc; return pc;

View file

@ -101,8 +101,7 @@ enum class OperationCode {
LogicalXor, /// (bool a, bool b) -> bool LogicalXor, /// (bool a, bool b) -> bool
LogicalNegate, /// (bool a) -> bool LogicalNegate, /// (bool a) -> bool
LogicalPick2, /// (bool2 pair, uint index) -> bool LogicalPick2, /// (bool2 pair, uint index) -> bool
LogicalAll2, /// (bool2 a) -> bool LogicalAnd2, /// (bool2 a) -> bool
LogicalAny2, /// (bool2 a) -> bool
LogicalFLessThan, /// (float a, float b) -> bool LogicalFLessThan, /// (float a, float b) -> bool
LogicalFEqual, /// (float a, float b) -> bool LogicalFEqual, /// (float a, float b) -> bool