From 24d73467bcbe9b340c3a2d2d22243e3565197fe0 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Wed, 16 Mar 2022 03:11:22 +0100 Subject: [PATCH] early-access version 2552 --- README.md | 2 +- .../spirv/emit_spirv_context_get_set.cpp | 53 +++++++++++++++---- .../ir_opt/collect_shader_info_pass.cpp | 35 +++++++++--- src/yuzu_cmd/default_ini.h | 6 ++- 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 29237c876..f5d642b29 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2551. +This is the source code for early-access 2552. ## Legal Notice 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 8ea730c80..1cfe1d49f 100755 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp @@ -124,25 +124,56 @@ std::optional OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { Id GetCbuf(EmitContext& ctx, Id result_type, Id UniformDefinitions::*member_ptr, u32 element_size, const IR::Value& binding, const IR::Value& offset) { - if (!binding.IsImmediate()) { - throw NotImplementedException("Constant buffer indexing"); - } - const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; + std::array indexes; + const Id uniform_type{ctx.uniform_types.*member_ptr}; - if (!offset.IsImmediate()) { + if (offset.IsImmediate()) { + // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) + const Id imm_offset{ctx.Const(offset.U32() / element_size)}; + indexes = {ctx.u32_zero_value, imm_offset}; + } else { Id index{ctx.Def(offset)}; if (element_size > 1) { const u32 log2_element_size{static_cast(std::countr_zero(element_size))}; const Id shift{ctx.Const(log2_element_size)}; index = ctx.OpShiftRightArithmetic(ctx.U32[1], ctx.Def(offset), shift); } - const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, index)}; - return ctx.OpLoad(result_type, access_chain); + indexes = {ctx.u32_zero_value, index}; + } + + if (binding.IsImmediate()) { + const Id cbuf{ctx.cbufs[binding.U32()].*member_ptr}; + const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, indexes)}; + return ctx.OpLoad(result_type, access_chain); + } else { + const Id index{ctx.Def(binding)}; + const Id ptr{ctx.TypePointer(spv::StorageClass::Function, result_type)}; + const Id value{ctx.AddLocalVariable(ptr, spv::StorageClass::Function)}; + const Id merge_label = ctx.OpLabel(); + + std::array buf_labels; + std::array buf_literals; + for (u32 i = 0; i < Info::MAX_CBUFS; i++) { + buf_labels[i] = ctx.OpLabel(); + buf_literals[i] = Sirit::Literal{i}; + } + + ctx.OpSelectionMerge(merge_label, spv::SelectionControlMask::MaskNone); + ctx.OpSwitch(index, buf_labels[0], buf_literals, buf_labels); + + for (u32 i = 0; i < Info::MAX_CBUFS; i++) { + ctx.AddLabel(buf_labels[i]); + const Id cbuf{ctx.cbufs[i].*member_ptr}; + const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, indexes)}; + const Id result = ctx.OpLoad(result_type, access_chain); + ctx.OpStore(value, result); + ctx.OpBranch(merge_label); + } + + ctx.AddLabel(merge_label); + + return ctx.OpLoad(result_type, value); } - // Hardware been proved to read the aligned offset (e.g. LDC.U32 at 6 will read offset 4) - const Id imm_offset{ctx.Const(offset.U32() / element_size)}; - const Id access_chain{ctx.OpAccessChain(uniform_type, cbuf, ctx.u32_zero_value, imm_offset)}; - return ctx.OpLoad(result_type, access_chain); } Id GetCbufU32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset) { 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 bfd2ae650..1a50dd382 100755 --- a/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp +++ b/src/shader_recompiler/ir_opt/collect_shader_info_pass.cpp @@ -29,6 +29,20 @@ void AddConstantBufferDescriptor(Info& info, u32 index, u32 count) { }); } +void AddRegisterIndexedLdc(Info& info) { + // The shader can use any possible constant buffer + info.constant_buffer_mask = (1 << Info::MAX_CBUFS) - 1; + + auto& cbufs{info.constant_buffer_descriptors}; + cbufs.clear(); + for (u32 i = 0; i < Info::MAX_CBUFS; i++) { + cbufs.push_back(ConstantBufferDescriptor{.index = i, .count = 1}); + + // The shader can use any possible access size + info.constant_buffer_used_sizes[i] = 0x10'000; + } +} + void GetPatch(Info& info, IR::Patch patch) { if (!IR::IsGeneric(patch)) { throw NotImplementedException("Reading non-generic patch {}", patch); @@ -463,10 +477,12 @@ void VisitUsages(Info& info, IR::Inst& inst) { case IR::Opcode::GetCbufU32x2: { const IR::Value index{inst.Arg(0)}; const IR::Value offset{inst.Arg(1)}; - if (!index.IsImmediate()) { - throw NotImplementedException("Constant buffer with non-immediate index"); + if (index.IsImmediate()) { + AddConstantBufferDescriptor(info, index.U32(), 1); + } else { + AddRegisterIndexedLdc(info); } - AddConstantBufferDescriptor(info, index.U32(), 1); + u32 element_size{}; switch (inst.GetOpcode()) { case IR::Opcode::GetCbufU8: @@ -494,11 +510,14 @@ void VisitUsages(Info& info, IR::Inst& inst) { default: break; } - u32& size{info.constant_buffer_used_sizes[index.U32()]}; - if (offset.IsImmediate()) { - size = Common::AlignUp(std::max(size, offset.U32() + element_size), 16u); - } else { - size = 0x10'000; + + if (index.IsImmediate()) { + u32& size{info.constant_buffer_used_sizes[index.U32()]}; + if (offset.IsImmediate()) { + size = Common::AlignUp(std::max(size, offset.U32() + element_size), 16u); + } else { + size = 0x10'000; + } } break; } diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 3ac1440c9..34782c378 100755 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -124,7 +124,11 @@ keyboard_enabled = [Core] # Whether to use multi-core for CPU emulation # 0: Disabled, 1 (default): Enabled -use_multi_core= +use_multi_core = + +# Enable extended guest system memory layout (6GB DRAM) +# 0 (default): Disabled, 1: Enabled +use_extended_memory_layout = [Cpu] # Adjusts various optimizations.