Skip to content

Commit 5bba437

Browse files
committed
1 parent 3ab1188 commit 5bba437

File tree

6 files changed

+49
-69
lines changed

6 files changed

+49
-69
lines changed

src/shader_recompiler/frontend/translate/export.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ void Translator::EmitExport(const GcnInst& inst) {
1313

1414
const auto& exp = inst.control.exp;
1515
const IR::Attribute attrib{exp.target};
16-
if (attrib == IR::Attribute::Depth && exp.en != 0 && exp.en != 1) {
17-
LOG_WARNING(Render_Vulkan, "Unsupported depth export");
18-
return;
19-
}
20-
2116
const std::array vsrc = {
2217
IR::VectorReg(inst.src[0].code),
2318
IR::VectorReg(inst.src[1].code),

src/shader_recompiler/ir/passes/resource_tracking_pass.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -128,35 +128,6 @@ bool IsImageInstruction(const IR::Inst& inst) {
128128
}
129129
}
130130

131-
IR::Value SwizzleVector(IR::IREmitter& ir, auto sharp, IR::Value texel) {
132-
boost::container::static_vector<IR::Value, 4> comps;
133-
for (u32 i = 0; i < 4; i++) {
134-
switch (sharp.GetSwizzle(i)) {
135-
case AmdGpu::CompSwizzle::Zero:
136-
comps.emplace_back(ir.Imm32(0.f));
137-
break;
138-
case AmdGpu::CompSwizzle::One:
139-
comps.emplace_back(ir.Imm32(1.f));
140-
break;
141-
case AmdGpu::CompSwizzle::Red:
142-
comps.emplace_back(ir.CompositeExtract(texel, 0));
143-
break;
144-
case AmdGpu::CompSwizzle::Green:
145-
comps.emplace_back(ir.CompositeExtract(texel, 1));
146-
break;
147-
case AmdGpu::CompSwizzle::Blue:
148-
comps.emplace_back(ir.CompositeExtract(texel, 2));
149-
break;
150-
case AmdGpu::CompSwizzle::Alpha:
151-
comps.emplace_back(ir.CompositeExtract(texel, 3));
152-
break;
153-
default:
154-
UNREACHABLE();
155-
}
156-
}
157-
return ir.CompositeConstruct(comps[0], comps[1], comps[2], comps[3]);
158-
};
159-
160131
class Descriptors {
161132
public:
162133
explicit Descriptors(Info& info_)
@@ -409,15 +380,6 @@ void PatchTextureBufferInstruction(IR::Block& block, IR::Inst& inst, Info& info,
409380
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
410381
inst.SetArg(0, ir.Imm32(binding));
411382
ASSERT(!buffer.swizzle_enable && !buffer.add_tid_enable);
412-
413-
// Apply dst_sel swizzle on formatted buffer instructions
414-
if (inst.GetOpcode() == IR::Opcode::StoreBufferFormatF32) {
415-
inst.SetArg(2, SwizzleVector(ir, buffer, inst.Arg(2)));
416-
} else {
417-
const auto inst_info = inst.Flags<IR::BufferInstInfo>();
418-
const auto texel = ir.LoadBufferFormat(inst.Arg(0), inst.Arg(1), inst_info);
419-
inst.ReplaceUsesWith(SwizzleVector(ir, buffer, texel));
420-
}
421383
}
422384

423385
IR::Value PatchCubeCoord(IR::IREmitter& ir, const IR::Value& s, const IR::Value& t,
@@ -765,10 +727,6 @@ void PatchImageInstruction(IR::Block& block, IR::Inst& inst, Info& info, Descrip
765727
}();
766728
inst.SetArg(1, coords);
767729

768-
if (inst.GetOpcode() == IR::Opcode::ImageWrite) {
769-
inst.SetArg(4, SwizzleVector(ir, image, inst.Arg(4)));
770-
}
771-
772730
if (inst_info.has_lod) {
773731
ASSERT(inst.GetOpcode() == IR::Opcode::ImageRead ||
774732
inst.GetOpcode() == IR::Opcode::ImageWrite);

src/shader_recompiler/specialization.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ struct BufferSpecialization {
3131

3232
struct TextureBufferSpecialization {
3333
bool is_integer = false;
34-
u32 dst_select = 0;
3534

3635
auto operator<=>(const TextureBufferSpecialization&) const = default;
3736
};
3837

3938
struct ImageSpecialization {
4039
AmdGpu::ImageType type = AmdGpu::ImageType::Color2D;
4140
bool is_integer = false;
42-
bool is_storage = false;
43-
u32 dst_select = 0;
4441

45-
bool operator==(const ImageSpecialization& other) const {
46-
return type == other.type && is_integer == other.is_integer &&
47-
is_storage == other.is_storage &&
48-
(dst_select != 0 ? dst_select == other.dst_select : true);
49-
}
42+
auto operator<=>(const ImageSpecialization&) const = default;
5043
};
5144

5245
struct FMaskSpecialization {
@@ -110,16 +103,11 @@ struct StageSpecialization {
110103
ForEachSharp(binding, tex_buffers, info->texture_buffers,
111104
[](auto& spec, const auto& desc, AmdGpu::Buffer sharp) {
112105
spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt());
113-
spec.dst_select = sharp.DstSelect();
114106
});
115107
ForEachSharp(binding, images, info->images,
116108
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {
117109
spec.type = sharp.GetBoundType();
118110
spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt());
119-
spec.is_storage = desc.IsStorage(sharp);
120-
if (spec.is_storage) {
121-
spec.dst_select = sharp.DstSelect();
122-
}
123111
});
124112
ForEachSharp(binding, fmasks, info->fmasks,
125113
[](auto& spec, const auto& desc, AmdGpu::Image sharp) {

src/video_core/amdgpu/resource.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ struct Buffer {
5252
return std::memcmp(this, &other, sizeof(Buffer)) == 0;
5353
}
5454

55-
u32 DstSelect() const {
56-
return dst_sel_x | (dst_sel_y << 3) | (dst_sel_z << 6) | (dst_sel_w << 9);
57-
}
58-
5955
CompSwizzle GetSwizzle(u32 comp) const noexcept {
6056
const std::array select{dst_sel_x, dst_sel_y, dst_sel_z, dst_sel_w};
6157
return static_cast<CompSwizzle>(select[comp]);
@@ -211,11 +207,6 @@ struct Image {
211207
return dst_sel_x | (dst_sel_y << 3) | (dst_sel_z << 6) | (dst_sel_w << 9);
212208
}
213209

214-
CompSwizzle GetSwizzle(u32 comp) const noexcept {
215-
const std::array select{dst_sel_x, dst_sel_y, dst_sel_z, dst_sel_w};
216-
return static_cast<CompSwizzle>(select[comp]);
217-
}
218-
219210
static char SelectComp(u32 sel) {
220211
switch (sel) {
221212
case 0:

src/video_core/renderer_vulkan/liverpool_to_vk.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,15 @@ vk::Format AdjustColorBufferFormat(vk::Format base_format,
700700
default:
701701
break;
702702
}
703+
} else if (comp_swap_reverse) {
704+
switch (base_format) {
705+
case vk::Format::eR8G8B8A8Unorm:
706+
return vk::Format::eA8B8G8R8UnormPack32;
707+
case vk::Format::eR8G8B8A8Srgb:
708+
return vk::Format::eA8B8G8R8SrgbPack32;
709+
default:
710+
break;
711+
}
703712
}
704713
return base_format;
705714
}

src/video_core/texture_cache/image_view.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ vk::ComponentSwizzle ConvertComponentSwizzle(u32 dst_sel) {
5050
}
5151
}
5252

53+
bool IsIdentityMapping(u32 dst_sel, u32 num_components) {
54+
return (num_components == 1 && dst_sel == 0b001'000'000'100) ||
55+
(num_components == 2 && dst_sel == 0b001'000'101'100) ||
56+
(num_components == 3 && dst_sel == 0b001'110'101'100) ||
57+
(num_components == 4 && dst_sel == 0b111'110'101'100);
58+
}
59+
60+
vk::Format TrySwizzleFormat(vk::Format format, u32 dst_sel) {
61+
// BGRA
62+
if (dst_sel == 0b111100101110) {
63+
switch (format) {
64+
case vk::Format::eR8G8B8A8Unorm:
65+
return vk::Format::eB8G8R8A8Unorm;
66+
case vk::Format::eR8G8B8A8Snorm:
67+
return vk::Format::eB8G8R8A8Snorm;
68+
case vk::Format::eR8G8B8A8Uint:
69+
return vk::Format::eB8G8R8A8Uint;
70+
case vk::Format::eR8G8B8A8Sint:
71+
return vk::Format::eB8G8R8A8Sint;
72+
case vk::Format::eR8G8B8A8Srgb:
73+
return vk::Format::eB8G8R8A8Srgb;
74+
default:
75+
break;
76+
}
77+
}
78+
return format;
79+
}
80+
5381
ImageViewInfo::ImageViewInfo(const AmdGpu::Image& image, const Shader::ImageResource& desc) noexcept
5482
: is_storage{desc.IsStorage(image)} {
5583
const auto dfmt = image.GetDataFmt();
@@ -92,6 +120,17 @@ ImageViewInfo::ImageViewInfo(const AmdGpu::Image& image, const Shader::ImageReso
92120
mapping.b = ConvertComponentSwizzle(image.dst_sel_z);
93121
mapping.a = ConvertComponentSwizzle(image.dst_sel_w);
94122
}
123+
// Check for unfortunate case of storage images being swizzled
124+
const u32 num_comps = AmdGpu::NumComponents(image.GetDataFmt());
125+
const u32 dst_sel = image.DstSelect();
126+
if (is_storage && !IsIdentityMapping(dst_sel, num_comps)) {
127+
if (auto new_format = TrySwizzleFormat(format, dst_sel); new_format != format) {
128+
format = new_format;
129+
return;
130+
}
131+
LOG_ERROR(Render_Vulkan, "Storage image (num_comps = {}) requires swizzling {}", num_comps,
132+
image.DstSelectName());
133+
}
95134
}
96135

97136
ImageViewInfo::ImageViewInfo(const AmdGpu::Liverpool::ColorBuffer& col_buffer) noexcept {

0 commit comments

Comments
 (0)