summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-12-17 02:29:22 -0800
committerGravatar Yuri Kunde Schlesner2017-01-25 18:53:24 -0800
commitfa4ac279a77871f45733d43fdecf756ff1e7ece0 (patch)
tree41ded8ce22102302ca59ccb45d2af101ffd398c2 /src
parentVideoCore/Shader: Move ProduceDebugInfo to InterpreterEngine (diff)
downloadyuzu-fa4ac279a77871f45733d43fdecf756ff1e7ece0.tar.gz
yuzu-fa4ac279a77871f45733d43fdecf756ff1e7ece0.tar.xz
yuzu-fa4ac279a77871f45733d43fdecf756ff1e7ece0.zip
shader_jit_x64: Don't read program from global state
Diffstat (limited to 'src')
-rw-r--r--src/video_core/shader/shader_jit_x64.cpp2
-rw-r--r--src/video_core/shader/shader_jit_x64_compiler.cpp36
-rw-r--r--src/video_core/shader/shader_jit_x64_compiler.h6
3 files changed, 22 insertions, 22 deletions
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 6d83948e1..755ae119f 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -29,7 +29,7 @@ void JitX64Engine::SetupBatch(const ShaderSetup* setup_) {
29 cached_shader = iter->second.get(); 29 cached_shader = iter->second.get();
30 } else { 30 } else {
31 auto shader = std::make_unique<JitShader>(); 31 auto shader = std::make_unique<JitShader>();
32 shader->Compile(); 32 shader->Compile(&setup->program_code, &setup->swizzle_data);
33 cached_shader = shader.get(); 33 cached_shader = shader.get();
34 cache.emplace_hint(iter, cache_key, std::move(shader)); 34 cache.emplace_hint(iter, cache_key, std::move(shader));
35 } 35 }
diff --git a/src/video_core/shader/shader_jit_x64_compiler.cpp b/src/video_core/shader/shader_jit_x64_compiler.cpp
index 880543306..49806e8c9 100644
--- a/src/video_core/shader/shader_jit_x64_compiler.cpp
+++ b/src/video_core/shader/shader_jit_x64_compiler.cpp
@@ -151,15 +151,6 @@ static const u8 NO_SRC_REG_SWIZZLE = 0x1b;
151/// Raw constant for the destination register enable mask that indicates all components are enabled 151/// Raw constant for the destination register enable mask that indicates all components are enabled
152static const u8 NO_DEST_REG_MASK = 0xf; 152static const u8 NO_DEST_REG_MASK = 0xf;
153 153
154/**
155 * Get the vertex shader instruction for a given offset in the current shader program
156 * @param offset Offset in the current shader program of the instruction
157 * @return Instruction at the specified offset
158 */
159static Instruction GetVertexShaderInstruction(size_t offset) {
160 return {g_state.vs.program_code[offset]};
161}
162
163static void LogCritical(const char* msg) { 154static void LogCritical(const char* msg) {
164 LOG_CRITICAL(HW_GPU, "%s", msg); 155 LOG_CRITICAL(HW_GPU, "%s", msg);
165} 156}
@@ -233,7 +224,7 @@ void JitShader::Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRe
233 movaps(dest, xword[src_ptr + src_offset_disp]); 224 movaps(dest, xword[src_ptr + src_offset_disp]);
234 } 225 }
235 226
236 SwizzlePattern swiz = {g_state.vs.swizzle_data[operand_desc_id]}; 227 SwizzlePattern swiz = {(*swizzle_data)[operand_desc_id]};
237 228
238 // Generate instructions for source register swizzling as needed 229 // Generate instructions for source register swizzling as needed
239 u8 sel = swiz.GetRawSelector(src_num); 230 u8 sel = swiz.GetRawSelector(src_num);
@@ -264,7 +255,7 @@ void JitShader::Compile_DestEnable(Instruction instr, Xmm src) {
264 dest = instr.common.dest.Value(); 255 dest = instr.common.dest.Value();
265 } 256 }
266 257
267 SwizzlePattern swiz = {g_state.vs.swizzle_data[operand_desc_id]}; 258 SwizzlePattern swiz = {(*swizzle_data)[operand_desc_id]};
268 259
269 size_t dest_offset_disp = UnitState::OutputOffset(dest); 260 size_t dest_offset_disp = UnitState::OutputOffset(dest);
270 261
@@ -522,7 +513,7 @@ void JitShader::Compile_MIN(Instruction instr) {
522} 513}
523 514
524void JitShader::Compile_MOVA(Instruction instr) { 515void JitShader::Compile_MOVA(Instruction instr) {
525 SwizzlePattern swiz = {g_state.vs.swizzle_data[instr.common.operand_desc_id]}; 516 SwizzlePattern swiz = {(*swizzle_data)[instr.common.operand_desc_id]};
526 517
527 if (!swiz.DestComponentEnabled(0) && !swiz.DestComponentEnabled(1)) { 518 if (!swiz.DestComponentEnabled(0) && !swiz.DestComponentEnabled(1)) {
528 return; // NoOp 519 return; // NoOp
@@ -796,7 +787,7 @@ void JitShader::Compile_NextInstr() {
796 787
797 L(instruction_labels[program_counter]); 788 L(instruction_labels[program_counter]);
798 789
799 Instruction instr = GetVertexShaderInstruction(program_counter++); 790 Instruction instr = {(*program_code)[program_counter++]};
800 791
801 OpCode::Id opcode = instr.opcode.Value(); 792 OpCode::Id opcode = instr.opcode.Value();
802 auto instr_func = instr_table[static_cast<unsigned>(opcode)]; 793 auto instr_func = instr_table[static_cast<unsigned>(opcode)];
@@ -814,8 +805,8 @@ void JitShader::Compile_NextInstr() {
814void JitShader::FindReturnOffsets() { 805void JitShader::FindReturnOffsets() {
815 return_offsets.clear(); 806 return_offsets.clear();
816 807
817 for (size_t offset = 0; offset < g_state.vs.program_code.size(); ++offset) { 808 for (size_t offset = 0; offset < program_code->size(); ++offset) {
818 Instruction instr = GetVertexShaderInstruction(offset); 809 Instruction instr = {(*program_code)[offset]};
819 810
820 switch (instr.opcode.Value()) { 811 switch (instr.opcode.Value()) {
821 case OpCode::Id::CALL: 812 case OpCode::Id::CALL:
@@ -833,7 +824,11 @@ void JitShader::FindReturnOffsets() {
833 std::sort(return_offsets.begin(), return_offsets.end()); 824 std::sort(return_offsets.begin(), return_offsets.end());
834} 825}
835 826
836void JitShader::Compile() { 827void JitShader::Compile(const std::array<u32, 1024>* program_code_,
828 const std::array<u32, 1024>* swizzle_data_) {
829 program_code = program_code_;
830 swizzle_data = swizzle_data_;
831
837 // Reset flow control state 832 // Reset flow control state
838 program = (CompiledShader*)getCurr(); 833 program = (CompiledShader*)getCurr();
839 program_counter = 0; 834 program_counter = 0;
@@ -868,17 +863,18 @@ void JitShader::Compile() {
868 jmp(ABI_PARAM3); 863 jmp(ABI_PARAM3);
869 864
870 // Compile entire program 865 // Compile entire program
871 Compile_Block(static_cast<unsigned>(g_state.vs.program_code.size())); 866 Compile_Block(static_cast<unsigned>(program_code->size()));
872 867
873 // Free memory that's no longer needed 868 // Free memory that's no longer needed
869 program_code = nullptr;
870 swizzle_data = nullptr;
874 return_offsets.clear(); 871 return_offsets.clear();
875 return_offsets.shrink_to_fit(); 872 return_offsets.shrink_to_fit();
876 873
877 ready(); 874 ready();
878 875
879 uintptr_t size = reinterpret_cast<uintptr_t>(getCurr()) - reinterpret_cast<uintptr_t>(program); 876 ASSERT_MSG(getSize() <= MAX_SHADER_SIZE, "Compiled a shader that exceeds the allocated size!");
880 ASSERT_MSG(size <= MAX_SHADER_SIZE, "Compiled a shader that exceeds the allocated size!"); 877 LOG_DEBUG(HW_GPU, "Compiled shader size=%lu", getSize());
881 LOG_DEBUG(HW_GPU, "Compiled shader size=%lu", size);
882} 878}
883 879
884JitShader::JitShader() : Xbyak::CodeGenerator(MAX_SHADER_SIZE) {} 880JitShader::JitShader() : Xbyak::CodeGenerator(MAX_SHADER_SIZE) {}
diff --git a/src/video_core/shader/shader_jit_x64_compiler.h b/src/video_core/shader/shader_jit_x64_compiler.h
index f37548306..29e9875ea 100644
--- a/src/video_core/shader/shader_jit_x64_compiler.h
+++ b/src/video_core/shader/shader_jit_x64_compiler.h
@@ -38,7 +38,8 @@ public:
38 program(&setup, &state, instruction_labels[offset].getAddress()); 38 program(&setup, &state, instruction_labels[offset].getAddress());
39 } 39 }
40 40
41 void Compile(); 41 void Compile(const std::array<u32, 1024>* program_code,
42 const std::array<u32, 1024>* swizzle_data);
42 43
43 void Compile_ADD(Instruction instr); 44 void Compile_ADD(Instruction instr);
44 void Compile_DP3(Instruction instr); 45 void Compile_DP3(Instruction instr);
@@ -103,6 +104,9 @@ private:
103 */ 104 */
104 void FindReturnOffsets(); 105 void FindReturnOffsets();
105 106
107 const std::array<u32, 1024>* program_code = nullptr;
108 const std::array<u32, 1024>* swizzle_data = nullptr;
109
106 /// Mapping of Pica VS instructions to pointers in the emitted code 110 /// Mapping of Pica VS instructions to pointers in the emitted code
107 std::array<Xbyak::Label, 1024> instruction_labels; 111 std::array<Xbyak::Label, 1024> instruction_labels;
108 112