Skip to content

Commit a51c8c1

Browse files
authored
shader_recompiler: Fix image write swizzles. (#2236)
1 parent 56f4b8a commit a51c8c1

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/shader_recompiler/ir/passes/resource_tracking_pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void PatchTextureBufferArgs(IR::Block& block, IR::Inst& inst, Info& info) {
569569
inst.SetArg(1, CalculateBufferAddress(ir, inst, info, buffer, 1U));
570570

571571
if (inst.GetOpcode() == IR::Opcode::StoreBufferFormatF32) {
572-
const auto swizzled = ApplySwizzle(ir, inst.Arg(2), buffer.DstSelect());
572+
const auto swizzled = ApplySwizzle(ir, inst.Arg(2), buffer.DstSelect().Inverse());
573573
const auto converted =
574574
ApplyWriteNumberConversionVec4(ir, swizzled, buffer.GetNumberConversion());
575575
inst.SetArg(2, converted);
@@ -829,7 +829,7 @@ void PatchImageArgs(IR::Block& block, IR::Inst& inst, Info& info) {
829829
auto texel = inst.Arg(4);
830830
if (is_storage) {
831831
// Storage image requires shader swizzle.
832-
texel = ApplySwizzle(ir, texel, image.DstSelect());
832+
texel = ApplySwizzle(ir, texel, image.DstSelect().Inverse());
833833
}
834834
const auto converted =
835835
ApplyWriteNumberConversionVec4(ir, texel, image.GetNumberConversion());

src/video_core/amdgpu/types.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ enum class NumberConversion : u32 {
200200
};
201201

202202
struct CompMapping {
203-
CompSwizzle r : 3;
204-
CompSwizzle g : 3;
205-
CompSwizzle b : 3;
206-
CompSwizzle a : 3;
203+
CompSwizzle r;
204+
CompSwizzle g;
205+
CompSwizzle b;
206+
CompSwizzle a;
207207

208208
auto operator<=>(const CompMapping& other) const = default;
209209

@@ -217,6 +217,15 @@ struct CompMapping {
217217
};
218218
}
219219

220+
[[nodiscard]] CompMapping Inverse() const {
221+
CompMapping result{};
222+
InverseSingle(result.r, CompSwizzle::Red);
223+
InverseSingle(result.g, CompSwizzle::Green);
224+
InverseSingle(result.b, CompSwizzle::Blue);
225+
InverseSingle(result.a, CompSwizzle::Alpha);
226+
return result;
227+
}
228+
220229
private:
221230
template <typename T>
222231
T ApplySingle(const std::array<T, 4>& data, const CompSwizzle swizzle) const {
@@ -237,6 +246,20 @@ struct CompMapping {
237246
UNREACHABLE();
238247
}
239248
}
249+
250+
void InverseSingle(CompSwizzle& dst, const CompSwizzle target) const {
251+
if (r == target) {
252+
dst = CompSwizzle::Red;
253+
} else if (g == target) {
254+
dst = CompSwizzle::Green;
255+
} else if (b == target) {
256+
dst = CompSwizzle::Blue;
257+
} else if (a == target) {
258+
dst = CompSwizzle::Alpha;
259+
} else {
260+
dst = CompSwizzle::Zero;
261+
}
262+
}
240263
};
241264

242265
inline DataFormat RemapDataFormat(const DataFormat format) {

0 commit comments

Comments
 (0)