summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-05-18 02:35:01 -0300
committerGravatar ReinUsesLisp2019-05-20 22:38:59 -0300
commitf78ef617b66e81b6095156fa0ff435cf8307aef7 (patch)
treec822e8d45e7b33bd36f8778bff56f67a8e461fec
parentMerge pull request #2455 from lioncash/config (diff)
downloadyuzu-f78ef617b66e81b6095156fa0ff435cf8307aef7.tar.gz
yuzu-f78ef617b66e81b6095156fa0ff435cf8307aef7.tar.xz
yuzu-f78ef617b66e81b6095156fa0ff435cf8307aef7.zip
shader/memory: Implement LD (generic memory)
-rw-r--r--src/video_core/engines/shader_bytecode.h19
-rw-r--r--src/video_core/shader/decode/memory.cpp28
-rw-r--r--src/video_core/shader/shader_ir.h6
3 files changed, 38 insertions, 15 deletions
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 7bbc556da..073b622ef 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -530,6 +530,11 @@ union Instruction {
530 BitField<48, 16, u64> opcode; 530 BitField<48, 16, u64> opcode;
531 531
532 union { 532 union {
533 BitField<8, 8, Register> gpr;
534 BitField<20, 24, s64> offset;
535 } gmem;
536
537 union {
533 BitField<20, 16, u64> imm20_16; 538 BitField<20, 16, u64> imm20_16;
534 BitField<20, 19, u64> imm20_19; 539 BitField<20, 19, u64> imm20_19;
535 BitField<20, 32, s64> imm20_32; 540 BitField<20, 32, s64> imm20_32;
@@ -812,13 +817,11 @@ union Instruction {
812 union { 817 union {
813 BitField<48, 3, UniformType> type; 818 BitField<48, 3, UniformType> type;
814 BitField<46, 2, u64> cache_mode; 819 BitField<46, 2, u64> cache_mode;
815 BitField<20, 24, s64> immediate_offset;
816 } ldg; 820 } ldg;
817 821
818 union { 822 union {
819 BitField<48, 3, UniformType> type; 823 BitField<48, 3, UniformType> type;
820 BitField<46, 2, u64> cache_mode; 824 BitField<46, 2, u64> cache_mode;
821 BitField<20, 24, s64> immediate_offset;
822 } stg; 825 } stg;
823 826
824 union { 827 union {
@@ -828,6 +831,11 @@ union Instruction {
828 } al2p; 831 } al2p;
829 832
830 union { 833 union {
834 BitField<53, 3, UniformType> type;
835 BitField<52, 1, u64> extended;
836 } generic;
837
838 union {
831 BitField<0, 3, u64> pred0; 839 BitField<0, 3, u64> pred0;
832 BitField<3, 3, u64> pred3; 840 BitField<3, 3, u64> pred3;
833 BitField<7, 1, u64> abs_a; 841 BitField<7, 1, u64> abs_a;
@@ -1387,10 +1395,12 @@ public:
1387 LD_L, 1395 LD_L,
1388 LD_S, 1396 LD_S,
1389 LD_C, 1397 LD_C,
1398 LD, // Load from generic memory
1399 LDG, // Load from global memory
1390 ST_A, 1400 ST_A,
1391 ST_L, 1401 ST_L,
1392 ST_S, 1402 ST_S,
1393 LDG, // Load from global memory 1403 ST, // Store in generic memory
1394 STG, // Store in global memory 1404 STG, // Store in global memory
1395 AL2P, // Transforms attribute memory into physical memory 1405 AL2P, // Transforms attribute memory into physical memory
1396 TEX, 1406 TEX,
@@ -1658,10 +1668,11 @@ private:
1658 INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"), 1668 INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"),
1659 INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"), 1669 INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"),
1660 INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"), 1670 INST("1110111110010---", Id::LD_C, Type::Memory, "LD_C"),
1671 INST("100-------------", Id::LD, Type::Memory, "LD"),
1672 INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
1661 INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"), 1673 INST("1110111111110---", Id::ST_A, Type::Memory, "ST_A"),
1662 INST("1110111101011---", Id::ST_S, Type::Memory, "ST_S"), 1674 INST("1110111101011---", Id::ST_S, Type::Memory, "ST_S"),
1663 INST("1110111101010---", Id::ST_L, Type::Memory, "ST_L"), 1675 INST("1110111101010---", Id::ST_L, Type::Memory, "ST_L"),
1664 INST("1110111011010---", Id::LDG, Type::Memory, "LDG"),
1665 INST("1110111011011---", Id::STG, Type::Memory, "STG"), 1676 INST("1110111011011---", Id::STG, Type::Memory, "STG"),
1666 INST("1110111110100---", Id::AL2P, Type::Memory, "AL2P"), 1677 INST("1110111110100---", Id::AL2P, Type::Memory, "AL2P"),
1667 INST("110000----111---", Id::TEX, Type::Texture, "TEX"), 1678 INST("110000----111---", Id::TEX, Type::Texture, "TEX"),
diff --git a/src/video_core/shader/decode/memory.cpp b/src/video_core/shader/decode/memory.cpp
index 6a992c543..8ac2fd4ac 100644
--- a/src/video_core/shader/decode/memory.cpp
+++ b/src/video_core/shader/decode/memory.cpp
@@ -148,12 +148,25 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
148 } 148 }
149 break; 149 break;
150 } 150 }
151 case OpCode::Id::LD:
151 case OpCode::Id::LDG: { 152 case OpCode::Id::LDG: {
153 const auto type = [instr, &opcode]() -> Tegra::Shader::UniformType {
154 switch (opcode->get().GetId()) {
155 case OpCode::Id::LD:
156 UNIMPLEMENTED_IF_MSG(!instr.generic.extended, "Unextended LD is not implemented");
157 return instr.generic.type;
158 case OpCode::Id::LDG:
159 return instr.ldg.type;
160 default:
161 UNREACHABLE();
162 return {};
163 }
164 }();
165
152 const auto [real_address_base, base_address, descriptor] = 166 const auto [real_address_base, base_address, descriptor] =
153 TrackAndGetGlobalMemory(bb, GetRegister(instr.gpr8), 167 TrackAndGetGlobalMemory(bb, instr, false);
154 static_cast<u32>(instr.ldg.immediate_offset.Value()), false);
155 168
156 const u32 count = GetUniformTypeElementsCount(instr.ldg.type); 169 const u32 count = GetUniformTypeElementsCount(type);
157 for (u32 i = 0; i < count; ++i) { 170 for (u32 i = 0; i < count; ++i) {
158 const Node it_offset = Immediate(i * 4); 171 const Node it_offset = Immediate(i * 4);
159 const Node real_address = 172 const Node real_address =
@@ -169,8 +182,7 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
169 } 182 }
170 case OpCode::Id::STG: { 183 case OpCode::Id::STG: {
171 const auto [real_address_base, base_address, descriptor] = 184 const auto [real_address_base, base_address, descriptor] =
172 TrackAndGetGlobalMemory(bb, GetRegister(instr.gpr8), 185 TrackAndGetGlobalMemory(bb, instr, true);
173 static_cast<u32>(instr.stg.immediate_offset.Value()), true);
174 186
175 // Encode in temporary registers like this: real_base_address, {registers_to_be_written...} 187 // Encode in temporary registers like this: real_base_address, {registers_to_be_written...}
176 SetTemporal(bb, 0, real_address_base); 188 SetTemporal(bb, 0, real_address_base);
@@ -267,9 +279,11 @@ u32 ShaderIR::DecodeMemory(NodeBlock& bb, u32 pc) {
267} 279}
268 280
269std::tuple<Node, Node, GlobalMemoryBase> ShaderIR::TrackAndGetGlobalMemory(NodeBlock& bb, 281std::tuple<Node, Node, GlobalMemoryBase> ShaderIR::TrackAndGetGlobalMemory(NodeBlock& bb,
270 Node addr_register, 282 Instruction instr,
271 u32 immediate_offset,
272 bool is_write) { 283 bool is_write) {
284 const auto addr_register{GetRegister(instr.gmem.gpr)};
285 const auto immediate_offset{static_cast<u32>(instr.gmem.offset)};
286
273 const Node base_address{ 287 const Node base_address{
274 TrackCbuf(addr_register, global_code, static_cast<s64>(global_code.size()))}; 288 TrackCbuf(addr_register, global_code, static_cast<s64>(global_code.size()))};
275 const auto cbuf = std::get_if<CbufNode>(base_address); 289 const auto cbuf = std::get_if<CbufNode>(base_address);
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index 0bf124252..0f769ed8d 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -818,10 +818,8 @@ private:
818 std::pair<Node, s64> TrackRegister(const GprNode* tracked, const NodeBlock& code, 818 std::pair<Node, s64> TrackRegister(const GprNode* tracked, const NodeBlock& code,
819 s64 cursor) const; 819 s64 cursor) const;
820 820
821 std::tuple<Node, Node, GlobalMemoryBase> TrackAndGetGlobalMemory(NodeBlock& bb, 821 std::tuple<Node, Node, GlobalMemoryBase> TrackAndGetGlobalMemory(
822 Node addr_register, 822 NodeBlock& bb, Tegra::Shader::Instruction instr, bool is_write);
823 u32 immediate_offset,
824 bool is_write);
825 823
826 template <typename... T> 824 template <typename... T>
827 Node Operation(OperationCode code, const T*... operands) { 825 Node Operation(OperationCode code, const T*... operands) {