committed by
ameerj
21 changed files with 437 additions and 48 deletions
-
4src/shader_recompiler/CMakeLists.txt
-
3src/shader_recompiler/backend/spirv/emit_spirv.h
-
10src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp
-
4src/shader_recompiler/backend/spirv/emit_spirv_control_flow.cpp
-
2src/shader_recompiler/environment.h
-
12src/shader_recompiler/frontend/ir/ir_emitter.cpp
-
4src/shader_recompiler/frontend/ir/ir_emitter.h
-
1src/shader_recompiler/frontend/ir/microinstruction.cpp
-
3src/shader_recompiler/frontend/ir/opcodes.inc
-
58src/shader_recompiler/frontend/maxwell/control_flow.cpp
-
7src/shader_recompiler/frontend/maxwell/control_flow.h
-
108src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.cpp
-
28src/shader_recompiler/frontend/maxwell/indirect_branch_table_track.h
-
1src/shader_recompiler/frontend/maxwell/instruction.h
-
57src/shader_recompiler/frontend/maxwell/structured_control_flow.cpp
-
36src/shader_recompiler/frontend/maxwell/translate/impl/branch_indirect.cpp
-
29src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.cpp
-
39src/shader_recompiler/frontend/maxwell/translate/impl/load_constant.h
-
8src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
-
21src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
-
50src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@ -0,0 +1,108 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include <optional>
|
||||
|
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "shader_recompiler/exception.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/decode.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/indirect_branch_table_track.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/opcodes.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/load_constant.h"
|
||||
|
|
||||
|
namespace Shader::Maxwell { |
||||
|
namespace { |
||||
|
union Encoding { |
||||
|
u64 raw; |
||||
|
BitField<0, 8, IR::Reg> dest_reg; |
||||
|
BitField<8, 8, IR::Reg> src_reg; |
||||
|
BitField<20, 19, u64> immediate; |
||||
|
BitField<56, 1, u64> is_negative; |
||||
|
BitField<20, 24, s64> brx_offset; |
||||
|
}; |
||||
|
|
||||
|
template <typename Callable> |
||||
|
std::optional<u64> Track(Environment& env, Location block_begin, Location& pos, Callable&& func) { |
||||
|
while (pos >= block_begin) { |
||||
|
const u64 insn{env.ReadInstruction(pos.Offset())}; |
||||
|
--pos; |
||||
|
if (func(insn, Decode(insn))) { |
||||
|
return insn; |
||||
|
} |
||||
|
} |
||||
|
return std::nullopt; |
||||
|
} |
||||
|
|
||||
|
std::optional<u64> TrackLDC(Environment& env, Location block_begin, Location& pos, |
||||
|
IR::Reg brx_reg) { |
||||
|
return Track(env, block_begin, pos, [brx_reg](u64 insn, Opcode opcode) { |
||||
|
const LDC::Encoding ldc{insn}; |
||||
|
return opcode == Opcode::LDC && ldc.dest_reg == brx_reg && ldc.size == LDC::Size::B32 && |
||||
|
ldc.mode == LDC::Mode::Default; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
std::optional<u64> TrackSHL(Environment& env, Location block_begin, Location& pos, |
||||
|
IR::Reg ldc_reg) { |
||||
|
return Track(env, block_begin, pos, [ldc_reg](u64 insn, Opcode opcode) { |
||||
|
const Encoding shl{insn}; |
||||
|
return opcode == Opcode::SHL_imm && shl.dest_reg == ldc_reg; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
std::optional<u64> TrackIMNMX(Environment& env, Location block_begin, Location& pos, |
||||
|
IR::Reg shl_reg) { |
||||
|
return Track(env, block_begin, pos, [shl_reg](u64 insn, Opcode opcode) { |
||||
|
const Encoding imnmx{insn}; |
||||
|
return opcode == Opcode::IMNMX_imm && imnmx.dest_reg == shl_reg; |
||||
|
}); |
||||
|
} |
||||
|
} // Anonymous namespace
|
||||
|
|
||||
|
std::optional<IndirectBranchTableInfo> TrackIndirectBranchTable(Environment& env, Location brx_pos, |
||||
|
Location block_begin) { |
||||
|
const u64 brx_insn{env.ReadInstruction(brx_pos.Offset())}; |
||||
|
const Opcode brx_opcode{Decode(brx_insn)}; |
||||
|
if (brx_opcode != Opcode::BRX && brx_opcode != Opcode::JMX) { |
||||
|
throw LogicError("Tracked instruction is not BRX or JMX"); |
||||
|
} |
||||
|
const IR::Reg brx_reg{Encoding{brx_insn}.src_reg}; |
||||
|
const s32 brx_offset{static_cast<s32>(Encoding{brx_insn}.brx_offset)}; |
||||
|
|
||||
|
Location pos{brx_pos}; |
||||
|
const std::optional<u64> ldc_insn{TrackLDC(env, block_begin, pos, brx_reg)}; |
||||
|
if (!ldc_insn) { |
||||
|
return std::nullopt; |
||||
|
} |
||||
|
const LDC::Encoding ldc{*ldc_insn}; |
||||
|
const u32 cbuf_index{static_cast<u32>(ldc.index)}; |
||||
|
const u32 cbuf_offset{static_cast<u32>(static_cast<s32>(ldc.offset.Value()))}; |
||||
|
const IR::Reg ldc_reg{ldc.src_reg}; |
||||
|
|
||||
|
const std::optional<u64> shl_insn{TrackSHL(env, block_begin, pos, ldc_reg)}; |
||||
|
if (!shl_insn) { |
||||
|
return std::nullopt; |
||||
|
} |
||||
|
const Encoding shl{*shl_insn}; |
||||
|
const IR::Reg shl_reg{shl.src_reg}; |
||||
|
|
||||
|
const std::optional<u64> imnmx_insn{TrackIMNMX(env, block_begin, pos, shl_reg)}; |
||||
|
if (!imnmx_insn) { |
||||
|
return std::nullopt; |
||||
|
} |
||||
|
const Encoding imnmx{*imnmx_insn}; |
||||
|
if (imnmx.is_negative != 0) { |
||||
|
return std::nullopt; |
||||
|
} |
||||
|
const u32 imnmx_immediate{static_cast<u32>(imnmx.immediate.Value())}; |
||||
|
return IndirectBranchTableInfo{ |
||||
|
.cbuf_index{cbuf_index}, |
||||
|
.cbuf_offset{cbuf_offset}, |
||||
|
.num_entries{imnmx_immediate + 1}, |
||||
|
.branch_offset{brx_offset}, |
||||
|
.branch_reg{brx_reg}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
} // namespace Shader::Maxwell
|
||||
@ -0,0 +1,28 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <optional> |
||||
|
|
||||
|
#include "common/bit_field.h" |
||||
|
#include "common/common_types.h" |
||||
|
#include "shader_recompiler/environment.h" |
||||
|
#include "shader_recompiler/frontend/ir/reg.h" |
||||
|
#include "shader_recompiler/frontend/maxwell/location.h" |
||||
|
|
||||
|
namespace Shader::Maxwell { |
||||
|
|
||||
|
struct IndirectBranchTableInfo { |
||||
|
u32 cbuf_index{}; |
||||
|
u32 cbuf_offset{}; |
||||
|
u32 num_entries{}; |
||||
|
s32 branch_offset{}; |
||||
|
IR::Reg branch_reg{}; |
||||
|
}; |
||||
|
|
||||
|
std::optional<IndirectBranchTableInfo> TrackIndirectBranchTable(Environment& env, Location brx_pos, |
||||
|
Location block_begin); |
||||
|
|
||||
|
} // namespace Shader::Maxwell |
||||
@ -0,0 +1,36 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#include "common/bit_field.h"
|
||||
|
#include "common/common_types.h"
|
||||
|
#include "shader_recompiler/exception.h"
|
||||
|
#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"
|
||||
|
|
||||
|
namespace Shader::Maxwell { |
||||
|
namespace { |
||||
|
void Check(u64 insn) { |
||||
|
union { |
||||
|
u64 raw; |
||||
|
BitField<5, 1, u64> cbuf_mode; |
||||
|
BitField<6, 1, u64> lmt; |
||||
|
} const encoding{insn}; |
||||
|
|
||||
|
if (encoding.cbuf_mode != 0) { |
||||
|
throw NotImplementedException("Constant buffer mode"); |
||||
|
} |
||||
|
if (encoding.lmt != 0) { |
||||
|
throw NotImplementedException("LMT"); |
||||
|
} |
||||
|
} |
||||
|
} // Anonymous namespace
|
||||
|
|
||||
|
void TranslatorVisitor::BRX(u64 insn) { |
||||
|
Check(insn); |
||||
|
} |
||||
|
|
||||
|
void TranslatorVisitor::JMX(u64 insn) { |
||||
|
Check(insn); |
||||
|
} |
||||
|
|
||||
|
} // namespace Shader::Maxwell
|
||||
@ -0,0 +1,39 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "common/bit_field.h" |
||||
|
#include "common/common_types.h" |
||||
|
#include "shader_recompiler/frontend/ir/reg.h" |
||||
|
|
||||
|
namespace Shader::Maxwell::LDC { |
||||
|
|
||||
|
enum class Mode : u64 { |
||||
|
Default, |
||||
|
IL, |
||||
|
IS, |
||||
|
ISL, |
||||
|
}; |
||||
|
|
||||
|
enum class Size : u64 { |
||||
|
U8, |
||||
|
S8, |
||||
|
U16, |
||||
|
S16, |
||||
|
B32, |
||||
|
B64, |
||||
|
}; |
||||
|
|
||||
|
union Encoding { |
||||
|
u64 raw; |
||||
|
BitField<0, 8, IR::Reg> dest_reg; |
||||
|
BitField<8, 8, IR::Reg> src_reg; |
||||
|
BitField<20, 16, s64> offset; |
||||
|
BitField<36, 5, u64> index; |
||||
|
BitField<44, 2, Mode> mode; |
||||
|
BitField<48, 3, Size> size; |
||||
|
}; |
||||
|
|
||||
|
} // namespace Shader::Maxwell::LDC |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue