mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-22 03:46:53 +02:00
refactor(shader): compact paired 64-bit lowering
This commit is contained in:
@@ -170,6 +170,10 @@ bool FoldCompositeExtract(Inst& inst, ValueOpcode construct, size_t components)
|
||||
}
|
||||
const auto component = index.U32();
|
||||
const auto* producer = composite.TryInstruction();
|
||||
if (IsImmediate(composite, Type::U64)) {
|
||||
Replace(inst, Value(static_cast<uint32_t>(composite.U64() >> (component * 32u))));
|
||||
return true;
|
||||
}
|
||||
if (producer != nullptr && producer->GetOpcode() == construct) {
|
||||
Replace(inst, producer->Arg(component));
|
||||
return true;
|
||||
@@ -185,14 +189,6 @@ bool FoldCompositeExtract(Inst& inst, ValueOpcode construct, size_t components)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (component < 2u && producer != nullptr &&
|
||||
producer->GetOpcode() == ValueOpcode::UnpackUint2x32) {
|
||||
const auto packed = producer->Arg(0).Resolve();
|
||||
if (IsImmediate(packed, Type::U64)) {
|
||||
Replace(inst, Value(static_cast<uint32_t>(packed.U64() >> (component * 32u))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -284,6 +280,9 @@ void FoldInstruction(Inst& inst) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
case ValueOpcode::CompositeExtractU64:
|
||||
FoldCompositeExtract(inst, ValueOpcode::CompositeConstructU64, 2);
|
||||
return;
|
||||
case ValueOpcode::CompositeExtractU32x2:
|
||||
FoldCompositeExtract(inst, ValueOpcode::CompositeConstructU32x2, 2);
|
||||
return;
|
||||
@@ -293,27 +292,12 @@ void FoldInstruction(Inst& inst) {
|
||||
case ValueOpcode::CompositeExtractU32x4:
|
||||
FoldCompositeExtract(inst, ValueOpcode::CompositeConstructU32x4, 4);
|
||||
return;
|
||||
case ValueOpcode::PackUint2x32: {
|
||||
const auto value = Arg(inst, 0);
|
||||
const auto* producer = value.TryInstruction();
|
||||
if (producer != nullptr && producer->GetOpcode() == ValueOpcode::UnpackUint2x32) {
|
||||
Replace(inst, producer->Arg(0));
|
||||
} else if (producer != nullptr &&
|
||||
producer->GetOpcode() == ValueOpcode::CompositeConstructU32x2) {
|
||||
const auto low = producer->Arg(0).Resolve();
|
||||
const auto high = producer->Arg(1).Resolve();
|
||||
if (IsImmediate(low, Type::U32) && IsImmediate(high, Type::U32)) {
|
||||
Replace(inst, Value(static_cast<uint64_t>(low.U32()) |
|
||||
(static_cast<uint64_t>(high.U32()) << 32u)));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
case ValueOpcode::UnpackUint2x32: {
|
||||
const auto value = Arg(inst, 0);
|
||||
const auto* producer = value.TryInstruction();
|
||||
if (producer != nullptr && producer->GetOpcode() == ValueOpcode::PackUint2x32) {
|
||||
Replace(inst, producer->Arg(0));
|
||||
case ValueOpcode::CompositeConstructU64: {
|
||||
const auto low = Arg(inst, 0);
|
||||
const auto high = Arg(inst, 1);
|
||||
if (IsImmediate(low, Type::U32) && IsImmediate(high, Type::U32)) {
|
||||
Replace(inst, Value(static_cast<uint64_t>(low.U32()) |
|
||||
(static_cast<uint64_t>(high.U32()) << 32u)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -367,8 +351,8 @@ void FoldInstruction(Inst& inst) {
|
||||
};
|
||||
const auto low = expand(static_cast<uint32_t>(value.U64()));
|
||||
const auto high = expand(static_cast<uint32_t>(value.U64() >> 32u));
|
||||
Replace(inst, Value(static_cast<uint64_t>(low) |
|
||||
(static_cast<uint64_t>(high) << 32u)));
|
||||
Replace(inst,
|
||||
Value(static_cast<uint64_t>(low) | (static_cast<uint64_t>(high) << 32u)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -461,11 +445,6 @@ void FoldInstruction(Inst& inst) {
|
||||
ReplaceBinaryIdentity(inst, Type::U32, 0u);
|
||||
}
|
||||
return;
|
||||
case ValueOpcode::BitwiseOr64:
|
||||
if (!FoldU64(inst, [](uint64_t a, uint64_t b) { return a | b; })) {
|
||||
ReplaceBinaryIdentity(inst, Type::U64, 0u);
|
||||
}
|
||||
return;
|
||||
case ValueOpcode::BitwiseNot32: {
|
||||
const auto value = Arg(inst, 0);
|
||||
if (IsImmediate(value, Type::U32)) {
|
||||
|
||||
@@ -76,10 +76,10 @@ bool IsDescriptorHandle(ValueOpcode opcode) {
|
||||
|
||||
bool IsRuntimeIntegerOp(ValueOpcode op) {
|
||||
switch (op) {
|
||||
case ValueOpcode::CompositeConstructU64:
|
||||
case ValueOpcode::CompositeExtractU64:
|
||||
case ValueOpcode::CompositeConstructU32x2:
|
||||
case ValueOpcode::CompositeExtractU32x2:
|
||||
case ValueOpcode::PackUint2x32:
|
||||
case ValueOpcode::UnpackUint2x32:
|
||||
case ValueOpcode::BitFieldInsert:
|
||||
case ValueOpcode::BitFieldUExtract:
|
||||
case ValueOpcode::BitFieldSExtract:
|
||||
@@ -100,7 +100,6 @@ bool IsRuntimeIntegerOp(ValueOpcode op) {
|
||||
case ValueOpcode::BitwiseAnd32:
|
||||
case ValueOpcode::BitwiseAnd64:
|
||||
case ValueOpcode::BitwiseOr32:
|
||||
case ValueOpcode::BitwiseOr64:
|
||||
case ValueOpcode::BitwiseXor32:
|
||||
case ValueOpcode::BitwiseNot32:
|
||||
case ValueOpcode::SelectU1:
|
||||
@@ -211,10 +210,10 @@ private:
|
||||
reason = fmt::format("contains a non-scalar {}", ValueOpcodeName(op));
|
||||
return finish(false);
|
||||
}
|
||||
} else if (op == ValueOpcode::PackUint2x32) {
|
||||
const auto* pair = inst->NumArgs() == 1 ? inst->Arg(0).ResolveInstruction() : nullptr;
|
||||
if (pair == nullptr || pair->GetOpcode() != ValueOpcode::CompositeConstructU32x2) {
|
||||
reason = "contains an unsupported packed runtime value";
|
||||
} else if (op == ValueOpcode::CompositeExtractU64) {
|
||||
const auto index = inst->NumArgs() == 2 ? inst->Arg(1).Resolve() : Value {};
|
||||
if (!index.IsImmediate() || index.GetType() != Type::U32 || index.U32() >= 2u) {
|
||||
reason = "contains an invalid U64 component index";
|
||||
return finish(false);
|
||||
}
|
||||
} else if (op == ValueOpcode::CompositeExtractU32x2) {
|
||||
@@ -223,7 +222,6 @@ private:
|
||||
if (source == nullptr || !index.IsImmediate() || index.GetType() != Type::U32 ||
|
||||
index.U32() >= 2u ||
|
||||
(source->GetOpcode() != ValueOpcode::CompositeConstructU32x2 &&
|
||||
source->GetOpcode() != ValueOpcode::UnpackUint2x32 &&
|
||||
source->GetOpcode() != ValueOpcode::IAddCarry32)) {
|
||||
reason = "contains an unsupported composite runtime source";
|
||||
return finish(false);
|
||||
@@ -484,22 +482,25 @@ private:
|
||||
if (!index.IsImmediate() || index.GetType() != Type::U32) {
|
||||
return Fail(error, "dynamic composite extract in runtime expression");
|
||||
}
|
||||
const auto component = index.U32();
|
||||
const auto* source = inst.Arg(0).ResolveInstruction();
|
||||
if (source == nullptr || component >= 2u) {
|
||||
const auto component = index.U32();
|
||||
if (component >= 2u) {
|
||||
return Fail(error, "unsupported composite runtime source");
|
||||
}
|
||||
if (source->GetOpcode() == ValueOpcode::CompositeConstructU32x2) {
|
||||
return EvaluateWide(source->Arg(component), result, error);
|
||||
}
|
||||
if (source->GetOpcode() == ValueOpcode::UnpackUint2x32) {
|
||||
if (inst.GetOpcode() == ValueOpcode::CompositeExtractU64) {
|
||||
uint64_t packed = 0;
|
||||
if (!Arg(*source, 0, packed, error)) {
|
||||
if (!Arg(inst, 0, packed, error)) {
|
||||
return false;
|
||||
}
|
||||
result = static_cast<uint32_t>(packed >> (component * 32u));
|
||||
return true;
|
||||
}
|
||||
const auto* source = inst.Arg(0).ResolveInstruction();
|
||||
if (source == nullptr) {
|
||||
return Fail(error, "unsupported composite runtime source");
|
||||
}
|
||||
if (source->GetOpcode() == ValueOpcode::CompositeConstructU32x2) {
|
||||
return EvaluateWide(source->Arg(component), result, error);
|
||||
}
|
||||
if (source->GetOpcode() == ValueOpcode::IAddCarry32) {
|
||||
uint64_t lhs = 0;
|
||||
uint64_t rhs = 0;
|
||||
@@ -596,17 +597,15 @@ private:
|
||||
}
|
||||
case ValueOpcode::GetShaderBase: result = m_runtime.shader_base; return true;
|
||||
case ValueOpcode::Phi: return EvaluatePhi(inst, result, error);
|
||||
case ValueOpcode::CompositeExtractU64:
|
||||
case ValueOpcode::CompositeExtractU32x2: return EvaluateExtract(inst, result, error);
|
||||
case ValueOpcode::PackUint2x32: {
|
||||
const auto* pair = inst.Arg(0).ResolveInstruction();
|
||||
if (pair == nullptr || pair->GetOpcode() != ValueOpcode::CompositeConstructU32x2 ||
|
||||
!Arg(*pair, 0, a, error) || !Arg(*pair, 1, b, error)) {
|
||||
return Fail(error, "unsupported packed runtime value");
|
||||
case ValueOpcode::CompositeConstructU64:
|
||||
if (!binary()) {
|
||||
return false;
|
||||
}
|
||||
result = static_cast<uint32_t>(a) |
|
||||
(static_cast<uint64_t>(static_cast<uint32_t>(b)) << 32u);
|
||||
return true;
|
||||
}
|
||||
case ValueOpcode::ReadConst: {
|
||||
const auto slot = inst.Arg(1).Resolve();
|
||||
if (!slot.IsImmediate() || slot.GetType() != Type::U32 ||
|
||||
@@ -687,12 +686,6 @@ private:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case ValueOpcode::BitwiseOr64:
|
||||
if (binary()) {
|
||||
result = a | b;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case ValueOpcode::BitwiseXor32:
|
||||
if (binary()) {
|
||||
result = static_cast<uint32_t>(a ^ b);
|
||||
|
||||
Reference in New Issue
Block a user