diff options
| author | 2021-04-04 02:31:09 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:26 -0400 | |
| commit | 3f594dd86bd1ee1b178109132482c7d6b43e66dd (patch) | |
| tree | 7de68eba744644121f3409f2de8c2e7a0bd5c125 | |
| parent | vk_compute_pass: Fix compute passes (diff) | |
| download | yuzu-3f594dd86bd1ee1b178109132482c7d6b43e66dd.tar.gz yuzu-3f594dd86bd1ee1b178109132482c7d6b43e66dd.tar.xz yuzu-3f594dd86bd1ee1b178109132482c7d6b43e66dd.zip | |
shader: Reimplement GetCbufU64 as GetCbufU32x2
It may generate better code on some compilers and it's easier to handle.
Diffstat (limited to '')
9 files changed, 21 insertions, 22 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 32f679f2a..e70b78a28 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -308,8 +308,8 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) { | |||
| 308 | if (True(info.used_constant_buffer_types & IR::Type::F32)) { | 308 | if (True(info.used_constant_buffer_types & IR::Type::F32)) { |
| 309 | DefineConstantBuffers(info, &UniformDefinitions::F32, binding, F32[1], 'f', sizeof(f32)); | 309 | DefineConstantBuffers(info, &UniformDefinitions::F32, binding, F32[1], 'f', sizeof(f32)); |
| 310 | } | 310 | } |
| 311 | if (True(info.used_constant_buffer_types & IR::Type::U64)) { | 311 | if (True(info.used_constant_buffer_types & IR::Type::U32x2)) { |
| 312 | DefineConstantBuffers(info, &UniformDefinitions::U64, binding, U64, 'u', sizeof(u64)); | 312 | DefineConstantBuffers(info, &UniformDefinitions::U32x2, binding, U32[2], 'u', sizeof(u64)); |
| 313 | } | 313 | } |
| 314 | for (const ConstantBufferDescriptor& desc : info.constant_buffer_descriptors) { | 314 | for (const ConstantBufferDescriptor& desc : info.constant_buffer_descriptors) { |
| 315 | binding += desc.count; | 315 | binding += desc.count; |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index f4715a709..3a686a78c 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -42,7 +42,7 @@ struct UniformDefinitions { | |||
| 42 | Id S16{}; | 42 | Id S16{}; |
| 43 | Id U32{}; | 43 | Id U32{}; |
| 44 | Id F32{}; | 44 | Id F32{}; |
| 45 | Id U64{}; | 45 | Id U32x2{}; |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | class EmitContext final : public Sirit::Module { | 48 | class EmitContext final : public Sirit::Module { |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h index 5d0f16b3a..e066ba87d 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv.h | |||
| @@ -47,7 +47,7 @@ Id EmitGetCbufU16(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 47 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 47 | Id EmitGetCbufS16(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); |
| 48 | Id EmitGetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 48 | Id EmitGetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); |
| 49 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 49 | Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); |
| 50 | Id EmitGetCbufU64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); | 50 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset); |
| 51 | Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr); | 51 | Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr); |
| 52 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, Id value); | 52 | void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, Id value); |
| 53 | void EmitGetAttributeIndexed(EmitContext& ctx); | 53 | void EmitGetAttributeIndexed(EmitContext& ctx); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index caab9aa12..1bfc60294 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -153,8 +153,8 @@ Id EmitGetCbufF32(EmitContext& ctx, const IR::Value& binding, const IR::Value& o | |||
| 153 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset); | 153 | return GetCbuf(ctx, ctx.F32[1], &UniformDefinitions::F32, sizeof(f32), binding, offset); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | Id EmitGetCbufU64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { | 156 | Id EmitGetCbufU32x2(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { |
| 157 | return GetCbuf(ctx, ctx.U64, &UniformDefinitions::U64, sizeof(u64), binding, offset); | 157 | return GetCbuf(ctx, ctx.U32[2], &UniformDefinitions::U32x2, sizeof(u32[2]), binding, offset); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr) { | 160 | Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr) { |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index dbfc670b0..dbd38a28b 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -162,8 +162,8 @@ U32 IREmitter::GetCbuf(const U32& binding, const U32& byte_offset) { | |||
| 162 | return Inst<U32>(Opcode::GetCbufU32, binding, byte_offset); | 162 | return Inst<U32>(Opcode::GetCbufU32, binding, byte_offset); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | UAny IREmitter::GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsize, | 165 | Value IREmitter::GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsize, |
| 166 | bool is_signed) { | 166 | bool is_signed) { |
| 167 | switch (bitsize) { | 167 | switch (bitsize) { |
| 168 | case 8: | 168 | case 8: |
| 169 | return Inst<U32>(is_signed ? Opcode::GetCbufS8 : Opcode::GetCbufU8, binding, byte_offset); | 169 | return Inst<U32>(is_signed ? Opcode::GetCbufS8 : Opcode::GetCbufU8, binding, byte_offset); |
| @@ -172,7 +172,7 @@ UAny IREmitter::GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsi | |||
| 172 | case 32: | 172 | case 32: |
| 173 | return Inst<U32>(Opcode::GetCbufU32, binding, byte_offset); | 173 | return Inst<U32>(Opcode::GetCbufU32, binding, byte_offset); |
| 174 | case 64: | 174 | case 64: |
| 175 | return Inst<U64>(Opcode::GetCbufU64, binding, byte_offset); | 175 | return Inst(Opcode::GetCbufU32x2, binding, byte_offset); |
| 176 | default: | 176 | default: |
| 177 | throw InvalidArgument("Invalid bit size {}", bitsize); | 177 | throw InvalidArgument("Invalid bit size {}", bitsize); |
| 178 | } | 178 | } |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index 14b743975..81a57fefe 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -56,8 +56,8 @@ public: | |||
| 56 | void SetIndirectBranchVariable(const U32& value); | 56 | void SetIndirectBranchVariable(const U32& value); |
| 57 | 57 | ||
| 58 | [[nodiscard]] U32 GetCbuf(const U32& binding, const U32& byte_offset); | 58 | [[nodiscard]] U32 GetCbuf(const U32& binding, const U32& byte_offset); |
| 59 | [[nodiscard]] UAny GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsize, | 59 | [[nodiscard]] Value GetCbuf(const U32& binding, const U32& byte_offset, size_t bitsize, |
| 60 | bool is_signed); | 60 | bool is_signed); |
| 61 | [[nodiscard]] F32 GetFloatCbuf(const U32& binding, const U32& byte_offset); | 61 | [[nodiscard]] F32 GetFloatCbuf(const U32& binding, const U32& byte_offset); |
| 62 | 62 | ||
| 63 | [[nodiscard]] U1 GetZFlag(); | 63 | [[nodiscard]] U1 GetZFlag(); |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 3640a5d24..734f5328b 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -40,7 +40,7 @@ OPCODE(GetCbufU16, U32, U32, | |||
| 40 | OPCODE(GetCbufS16, U32, U32, U32, ) | 40 | OPCODE(GetCbufS16, U32, U32, U32, ) |
| 41 | OPCODE(GetCbufU32, U32, U32, U32, ) | 41 | OPCODE(GetCbufU32, U32, U32, U32, ) |
| 42 | OPCODE(GetCbufF32, F32, U32, U32, ) | 42 | OPCODE(GetCbufF32, F32, U32, U32, ) |
| 43 | OPCODE(GetCbufU64, U64, U32, U32, ) | 43 | OPCODE(GetCbufU32x2, U32x2, U32, U32, ) |
| 44 | OPCODE(GetAttribute, F32, Attribute, ) | 44 | OPCODE(GetAttribute, F32, Attribute, ) |
| 45 | OPCODE(SetAttribute, Void, Attribute, F32, ) | 45 | OPCODE(SetAttribute, Void, Attribute, F32, ) |
| 46 | OPCODE(GetAttributeIndexed, F32, U32, ) | 46 | OPCODE(GetAttributeIndexed, F32, U32, ) |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp index 49ccb7d62..ae3ecea32 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp | |||
| @@ -30,25 +30,25 @@ void TranslatorVisitor::LDC(u64 insn) { | |||
| 30 | const auto [index, offset]{Slot(ir, ldc.mode, imm_index, reg, imm)}; | 30 | const auto [index, offset]{Slot(ir, ldc.mode, imm_index, reg, imm)}; |
| 31 | switch (ldc.size) { | 31 | switch (ldc.size) { |
| 32 | case Size::U8: | 32 | case Size::U8: |
| 33 | X(ldc.dest_reg, ir.GetCbuf(index, offset, 8, false)); | 33 | X(ldc.dest_reg, IR::U32{ir.GetCbuf(index, offset, 8, false)}); |
| 34 | break; | 34 | break; |
| 35 | case Size::S8: | 35 | case Size::S8: |
| 36 | X(ldc.dest_reg, ir.GetCbuf(index, offset, 8, true)); | 36 | X(ldc.dest_reg, IR::U32{ir.GetCbuf(index, offset, 8, true)}); |
| 37 | break; | 37 | break; |
| 38 | case Size::U16: | 38 | case Size::U16: |
| 39 | X(ldc.dest_reg, ir.GetCbuf(index, offset, 16, false)); | 39 | X(ldc.dest_reg, IR::U32{ir.GetCbuf(index, offset, 16, false)}); |
| 40 | break; | 40 | break; |
| 41 | case Size::S16: | 41 | case Size::S16: |
| 42 | X(ldc.dest_reg, ir.GetCbuf(index, offset, 16, true)); | 42 | X(ldc.dest_reg, IR::U32{ir.GetCbuf(index, offset, 16, true)}); |
| 43 | break; | 43 | break; |
| 44 | case Size::B32: | 44 | case Size::B32: |
| 45 | X(ldc.dest_reg, ir.GetCbuf(index, offset, 32, false)); | 45 | X(ldc.dest_reg, IR::U32{ir.GetCbuf(index, offset, 32, false)}); |
| 46 | break; | 46 | break; |
| 47 | case Size::B64: { | 47 | case Size::B64: { |
| 48 | if (!IR::IsAligned(ldc.dest_reg, 2)) { | 48 | if (!IR::IsAligned(ldc.dest_reg, 2)) { |
| 49 | throw NotImplementedException("Unaligned destination register"); | 49 | throw NotImplementedException("Unaligned destination register"); |
| 50 | } | 50 | } |
| 51 | const IR::Value vector{ir.UnpackUint2x32(ir.GetCbuf(index, offset, 64, false))}; | 51 | const IR::Value vector{ir.GetCbuf(index, offset, 64, false)}; |
| 52 | for (int i = 0; i < 2; ++i) { | 52 | for (int i = 0; i < 2; ++i) { |
| 53 | X(ldc.dest_reg + i, IR::U32{ir.CompositeExtract(vector, i)}); | 53 | X(ldc.dest_reg + i, IR::U32{ir.CompositeExtract(vector, i)}); |
| 54 | } | 54 | } |
diff --git a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp index 5c1b81638..07f031ea6 100644 --- a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp +++ b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp | |||
| @@ -271,7 +271,6 @@ void VisitUsages(Info& info, IR::Inst& inst) { | |||
| 271 | break; | 271 | break; |
| 272 | } | 272 | } |
| 273 | switch (inst.Opcode()) { | 273 | switch (inst.Opcode()) { |
| 274 | case IR::Opcode::GetCbufU64: | ||
| 275 | case IR::Opcode::UndefU64: | 274 | case IR::Opcode::UndefU64: |
| 276 | case IR::Opcode::LoadGlobalU8: | 275 | case IR::Opcode::LoadGlobalU8: |
| 277 | case IR::Opcode::LoadGlobalS8: | 276 | case IR::Opcode::LoadGlobalS8: |
| @@ -349,7 +348,7 @@ void VisitUsages(Info& info, IR::Inst& inst) { | |||
| 349 | case IR::Opcode::GetCbufS16: | 348 | case IR::Opcode::GetCbufS16: |
| 350 | case IR::Opcode::GetCbufU32: | 349 | case IR::Opcode::GetCbufU32: |
| 351 | case IR::Opcode::GetCbufF32: | 350 | case IR::Opcode::GetCbufF32: |
| 352 | case IR::Opcode::GetCbufU64: { | 351 | case IR::Opcode::GetCbufU32x2: { |
| 353 | if (const IR::Value index{inst.Arg(0)}; index.IsImmediate()) { | 352 | if (const IR::Value index{inst.Arg(0)}; index.IsImmediate()) { |
| 354 | AddConstantBufferDescriptor(info, index.U32(), 1); | 353 | AddConstantBufferDescriptor(info, index.U32(), 1); |
| 355 | } else { | 354 | } else { |
| @@ -370,8 +369,8 @@ void VisitUsages(Info& info, IR::Inst& inst) { | |||
| 370 | case IR::Opcode::GetCbufF32: | 369 | case IR::Opcode::GetCbufF32: |
| 371 | info.used_constant_buffer_types |= IR::Type::F32; | 370 | info.used_constant_buffer_types |= IR::Type::F32; |
| 372 | break; | 371 | break; |
| 373 | case IR::Opcode::GetCbufU64: | 372 | case IR::Opcode::GetCbufU32x2: |
| 374 | info.used_constant_buffer_types |= IR::Type::U64; | 373 | info.used_constant_buffer_types |= IR::Type::U32x2; |
| 375 | break; | 374 | break; |
| 376 | default: | 375 | default: |
| 377 | break; | 376 | break; |