mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): support V_PERM_B32 byte selection
This commit is contained in:
@@ -284,6 +284,7 @@ enum class RdnaOpcode : std::uint16_t {
|
||||
VAdd3U32,
|
||||
VLshlAddU32,
|
||||
VAddLshlU32,
|
||||
VPermB32,
|
||||
VXadU32,
|
||||
VLshlOrB32,
|
||||
VAndOrB32,
|
||||
|
||||
@@ -257,6 +257,7 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) {
|
||||
case RdnaOpcode::VAdd3U32:
|
||||
case RdnaOpcode::VLshlAddU32:
|
||||
case RdnaOpcode::VAddLshlU32:
|
||||
case RdnaOpcode::VPermB32:
|
||||
case RdnaOpcode::VXadU32:
|
||||
case RdnaOpcode::VLshlOrB32:
|
||||
case RdnaOpcode::VAndOrB32:
|
||||
|
||||
@@ -355,6 +355,7 @@ constexpr VectorOpcodeInfo vop3Opcodes[] = {
|
||||
{0x311u, RdnaOpcode::VPackB32F16},
|
||||
{0x314u, RdnaOpcode::VLshlrevB16},
|
||||
{0x319u, RdnaOpcode::VSubrevI32},
|
||||
{0x344u, RdnaOpcode::VPermB32},
|
||||
{0x345u, RdnaOpcode::VXadU32},
|
||||
{0x346u, RdnaOpcode::VLshlAddU32},
|
||||
{0x347u, RdnaOpcode::VAddLshlU32},
|
||||
|
||||
@@ -186,6 +186,7 @@ private:
|
||||
bool vAlignbyteB32(const RdnaInstruction& inst);
|
||||
bool vLshlAddU32(const RdnaInstruction& inst);
|
||||
bool vAddLshlU32(const RdnaInstruction& inst);
|
||||
bool vPermB32(const RdnaInstruction& inst);
|
||||
bool vXadU32(const RdnaInstruction& inst);
|
||||
bool vLshlOrB32(const RdnaInstruction& inst);
|
||||
bool vCndmaskB32(const RdnaInstruction& inst);
|
||||
|
||||
@@ -532,6 +532,28 @@ bool TranslationContext::vAddLshlU32(const RdnaInstruction& inst) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TranslationContext::vPermB32(const RdnaInstruction& inst) {
|
||||
const IrU32 high = readU32(sourceAt(inst, 0u));
|
||||
const IrU32 low = readU32(sourceAt(inst, 1u));
|
||||
const IrU32 selectors = readU32(sourceAt(inst, 2u));
|
||||
IrValue* result = &ir.Constant(0u);
|
||||
for (std::uint32_t byte = 0u; byte < 4u; ++byte) {
|
||||
IrValue& selector = ir.BitwiseAnd(ir.ShiftRightLogical(selectors.Value(), ir.Constant(byte * 8u)), ir.Constant(255u));
|
||||
IrValue& signIndex = ir.IAdd(ir.IMul(ir.BitwiseAnd(selector, ir.Constant(3u)), ir.Constant(2u)), ir.Constant(1u));
|
||||
IrValue& index = ir.Select(ir.ULessThan(selector, ir.Constant(8u)), selector, signIndex);
|
||||
IrValue& word = ir.Select(ir.ULessThan(index, ir.Constant(4u)), low.Value(), high.Value());
|
||||
IrValue& shift = ir.IMul(ir.BitwiseAnd(index, ir.Constant(3u)), ir.Constant(8u));
|
||||
IrValue& value = ir.BitwiseAnd(ir.ShiftRightLogical(word, shift), ir.Constant(255u));
|
||||
IrValue& sign = ir.Select(ir.UGreaterThan(value, ir.Constant(127u)), ir.Constant(255u), ir.Constant(0u));
|
||||
IrValue& selected = ir.Select(ir.ULessThan(selector, ir.Constant(8u)), value, sign);
|
||||
IrValue& fill = ir.Select(ir.IEqual(selector, ir.Constant(12u)), ir.Constant(0u), ir.Constant(255u));
|
||||
IrValue& output = ir.Select(ir.ULessThan(selector, ir.Constant(12u)), selected, fill);
|
||||
result = &ir.BitwiseOr(*result, ir.ShiftLeftLogical(output, ir.Constant(byte * 8u)));
|
||||
}
|
||||
writeOperand(inst.destination, result);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TranslationContext::vXadU32(const RdnaInstruction& inst) {
|
||||
const IrU32 lhs = readU32(sourceAt(inst, 0u));
|
||||
const IrU32 rhs = readU32(sourceAt(inst, 1u));
|
||||
|
||||
@@ -673,6 +673,8 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) {
|
||||
return vLshlAddU32(inst);
|
||||
case RdnaOpcode::VAddLshlU32:
|
||||
return vAddLshlU32(inst);
|
||||
case RdnaOpcode::VPermB32:
|
||||
return vPermB32(inst);
|
||||
case RdnaOpcode::VXadU32:
|
||||
return vXadU32(inst);
|
||||
case RdnaOpcode::VLshlOrB32:
|
||||
|
||||
Reference in New Issue
Block a user