mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-23 20:05:01 +00:00
shader_recompiler: Fix image write swizzles. (#2236)
This commit is contained in:
parent
56f4b8a2b8
commit
a51c8c17e0
2 changed files with 29 additions and 6 deletions
|
@ -569,7 +569,7 @@ void PatchTextureBufferArgs(IR::Block& block, IR::Inst& inst, Info& info) {
|
||||||
inst.SetArg(1, CalculateBufferAddress(ir, inst, info, buffer, 1U));
|
inst.SetArg(1, CalculateBufferAddress(ir, inst, info, buffer, 1U));
|
||||||
|
|
||||||
if (inst.GetOpcode() == IR::Opcode::StoreBufferFormatF32) {
|
if (inst.GetOpcode() == IR::Opcode::StoreBufferFormatF32) {
|
||||||
const auto swizzled = ApplySwizzle(ir, inst.Arg(2), buffer.DstSelect());
|
const auto swizzled = ApplySwizzle(ir, inst.Arg(2), buffer.DstSelect().Inverse());
|
||||||
const auto converted =
|
const auto converted =
|
||||||
ApplyWriteNumberConversionVec4(ir, swizzled, buffer.GetNumberConversion());
|
ApplyWriteNumberConversionVec4(ir, swizzled, buffer.GetNumberConversion());
|
||||||
inst.SetArg(2, converted);
|
inst.SetArg(2, converted);
|
||||||
|
@ -829,7 +829,7 @@ void PatchImageArgs(IR::Block& block, IR::Inst& inst, Info& info) {
|
||||||
auto texel = inst.Arg(4);
|
auto texel = inst.Arg(4);
|
||||||
if (is_storage) {
|
if (is_storage) {
|
||||||
// Storage image requires shader swizzle.
|
// Storage image requires shader swizzle.
|
||||||
texel = ApplySwizzle(ir, texel, image.DstSelect());
|
texel = ApplySwizzle(ir, texel, image.DstSelect().Inverse());
|
||||||
}
|
}
|
||||||
const auto converted =
|
const auto converted =
|
||||||
ApplyWriteNumberConversionVec4(ir, texel, image.GetNumberConversion());
|
ApplyWriteNumberConversionVec4(ir, texel, image.GetNumberConversion());
|
||||||
|
|
|
@ -200,10 +200,10 @@ enum class NumberConversion : u32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompMapping {
|
struct CompMapping {
|
||||||
CompSwizzle r : 3;
|
CompSwizzle r;
|
||||||
CompSwizzle g : 3;
|
CompSwizzle g;
|
||||||
CompSwizzle b : 3;
|
CompSwizzle b;
|
||||||
CompSwizzle a : 3;
|
CompSwizzle a;
|
||||||
|
|
||||||
auto operator<=>(const CompMapping& other) const = default;
|
auto operator<=>(const CompMapping& other) const = default;
|
||||||
|
|
||||||
|
@ -217,6 +217,15 @@ struct CompMapping {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] CompMapping Inverse() const {
|
||||||
|
CompMapping result{};
|
||||||
|
InverseSingle(result.r, CompSwizzle::Red);
|
||||||
|
InverseSingle(result.g, CompSwizzle::Green);
|
||||||
|
InverseSingle(result.b, CompSwizzle::Blue);
|
||||||
|
InverseSingle(result.a, CompSwizzle::Alpha);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T ApplySingle(const std::array<T, 4>& data, const CompSwizzle swizzle) const {
|
T ApplySingle(const std::array<T, 4>& data, const CompSwizzle swizzle) const {
|
||||||
|
@ -237,6 +246,20 @@ private:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InverseSingle(CompSwizzle& dst, const CompSwizzle target) const {
|
||||||
|
if (r == target) {
|
||||||
|
dst = CompSwizzle::Red;
|
||||||
|
} else if (g == target) {
|
||||||
|
dst = CompSwizzle::Green;
|
||||||
|
} else if (b == target) {
|
||||||
|
dst = CompSwizzle::Blue;
|
||||||
|
} else if (a == target) {
|
||||||
|
dst = CompSwizzle::Alpha;
|
||||||
|
} else {
|
||||||
|
dst = CompSwizzle::Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DataFormat RemapDataFormat(const DataFormat format) {
|
inline DataFormat RemapDataFormat(const DataFormat format) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue