2015-07-23 05:25:30 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <nihstro/shader_bytecode.h>
|
|
|
|
|
2015-08-12 06:00:44 +02:00
|
|
|
#include "common/x64/emitter.h"
|
2015-07-23 05:25:30 +02:00
|
|
|
|
|
|
|
#include "video_core/pica.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "video_core/shader/shader.h"
|
2015-07-23 05:25:30 +02:00
|
|
|
|
|
|
|
using nihstro::Instruction;
|
|
|
|
using nihstro::OpCode;
|
|
|
|
using nihstro::SwizzlePattern;
|
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
namespace Shader {
|
|
|
|
|
2016-03-12 18:15:49 +01:00
|
|
|
/// Memory needed to be available to compile the next shader (otherwise, clear the cache)
|
|
|
|
constexpr size_t jit_shader_size = 1024 * 512;
|
|
|
|
/// Memory allocated for the JIT code space cache
|
|
|
|
constexpr size_t jit_cache_size = 1024 * 1024 * 8;
|
|
|
|
|
2015-08-15 22:51:32 +02:00
|
|
|
using CompiledShader = void(void* registers);
|
2015-07-23 05:25:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class implements the shader JIT compiler. It recompiles a Pica shader program into x86_64
|
|
|
|
* code that can be executed on the host machine directly.
|
|
|
|
*/
|
|
|
|
class JitCompiler : public Gen::XCodeBlock {
|
|
|
|
public:
|
|
|
|
JitCompiler();
|
|
|
|
|
|
|
|
CompiledShader* Compile();
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
void Compile_ADD(Instruction instr);
|
|
|
|
void Compile_DP3(Instruction instr);
|
|
|
|
void Compile_DP4(Instruction instr);
|
2015-08-21 12:49:21 +02:00
|
|
|
void Compile_DPH(Instruction instr);
|
2015-08-16 17:22:49 +02:00
|
|
|
void Compile_EX2(Instruction instr);
|
|
|
|
void Compile_LG2(Instruction instr);
|
2015-07-23 05:25:30 +02:00
|
|
|
void Compile_MUL(Instruction instr);
|
2015-08-19 14:23:53 +02:00
|
|
|
void Compile_SGE(Instruction instr);
|
|
|
|
void Compile_SLT(Instruction instr);
|
2015-07-23 05:25:30 +02:00
|
|
|
void Compile_FLR(Instruction instr);
|
|
|
|
void Compile_MAX(Instruction instr);
|
|
|
|
void Compile_MIN(Instruction instr);
|
|
|
|
void Compile_RCP(Instruction instr);
|
|
|
|
void Compile_RSQ(Instruction instr);
|
|
|
|
void Compile_MOVA(Instruction instr);
|
|
|
|
void Compile_MOV(Instruction instr);
|
|
|
|
void Compile_NOP(Instruction instr);
|
|
|
|
void Compile_END(Instruction instr);
|
|
|
|
void Compile_CALL(Instruction instr);
|
|
|
|
void Compile_CALLC(Instruction instr);
|
|
|
|
void Compile_CALLU(Instruction instr);
|
|
|
|
void Compile_IF(Instruction instr);
|
|
|
|
void Compile_LOOP(Instruction instr);
|
|
|
|
void Compile_JMP(Instruction instr);
|
|
|
|
void Compile_CMP(Instruction instr);
|
|
|
|
void Compile_MAD(Instruction instr);
|
|
|
|
|
|
|
|
private:
|
2016-01-24 11:10:56 +01:00
|
|
|
void Compile_Block(unsigned end);
|
2015-07-23 05:25:30 +02:00
|
|
|
void Compile_NextInstr(unsigned* offset);
|
|
|
|
|
|
|
|
void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest);
|
|
|
|
void Compile_DestEnable(Instruction instr, Gen::X64Reg dest);
|
|
|
|
|
2015-08-24 06:48:15 +02:00
|
|
|
/**
|
|
|
|
* Compiles a `MUL src1, src2` operation, properly handling the PICA semantics when multiplying
|
|
|
|
* zero by inf. Clobbers `src2` and `scratch`.
|
|
|
|
*/
|
|
|
|
void Compile_SanitizedMul(Gen::X64Reg src1, Gen::X64Reg src2, Gen::X64Reg scratch);
|
|
|
|
|
2015-07-23 05:25:30 +02:00
|
|
|
void Compile_EvaluateCondition(Instruction instr);
|
|
|
|
void Compile_UniformCondition(Instruction instr);
|
|
|
|
|
2015-08-26 09:12:14 +02:00
|
|
|
BitSet32 PersistentCallerSavedRegs();
|
2015-08-19 01:49:45 +02:00
|
|
|
|
2015-07-23 05:25:30 +02:00
|
|
|
/// Pointer to the variable that stores the current Pica code offset. Used to handle nested code blocks.
|
|
|
|
unsigned* offset_ptr = nullptr;
|
|
|
|
|
2015-08-12 06:00:44 +02:00
|
|
|
/// Set to true if currently in a loop, used to check for the existence of nested loops
|
2015-07-23 05:25:30 +02:00
|
|
|
bool looping = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Shader
|
|
|
|
|
|
|
|
} // Pica
|