2012-11-15 00:39:56 +01:00
|
|
|
#pragma once
|
2013-11-09 22:29:49 +01:00
|
|
|
#include "GLShaderParam.h"
|
|
|
|
|
#include "Emu/GS/RSXFragmentProgram.h"
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-09 22:29:49 +01:00
|
|
|
struct GLFragmentDecompilerThread : public ThreadBase
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
|
|
|
|
union OPDEST
|
|
|
|
|
{
|
|
|
|
|
u32 HEX;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u32 end : 1;
|
|
|
|
|
u32 dest_reg : 6;
|
|
|
|
|
u32 fp16 : 1;
|
|
|
|
|
u32 set_cond : 1;
|
|
|
|
|
u32 mask_x : 1;
|
|
|
|
|
u32 mask_y : 1;
|
|
|
|
|
u32 mask_z : 1;
|
|
|
|
|
u32 mask_w : 1;
|
|
|
|
|
u32 src_attr_reg_num : 4;
|
|
|
|
|
u32 tex_num : 4;
|
|
|
|
|
u32 exp_tex : 1;
|
|
|
|
|
u32 prec : 2;
|
|
|
|
|
u32 opcode : 6;
|
|
|
|
|
u32 no_dest : 1;
|
|
|
|
|
u32 saturate : 1;
|
|
|
|
|
};
|
|
|
|
|
} dst;
|
|
|
|
|
|
|
|
|
|
union SRC0
|
|
|
|
|
{
|
|
|
|
|
u32 HEX;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
2013-08-26 16:18:59 +02:00
|
|
|
u32 reg_type : 2;
|
|
|
|
|
u32 tmp_reg_index : 6;
|
|
|
|
|
u32 fp16 : 1;
|
|
|
|
|
u32 swizzle_x : 2;
|
|
|
|
|
u32 swizzle_y : 2;
|
|
|
|
|
u32 swizzle_z : 2;
|
|
|
|
|
u32 swizzle_w : 2;
|
|
|
|
|
u32 neg : 1;
|
|
|
|
|
u32 exec_if_lt : 1;
|
|
|
|
|
u32 exec_if_eq : 1;
|
|
|
|
|
u32 exec_if_gr : 1;
|
|
|
|
|
u32 cond_swizzle_x : 2;
|
|
|
|
|
u32 cond_swizzle_y : 2;
|
|
|
|
|
u32 cond_swizzle_z : 2;
|
|
|
|
|
u32 cond_swizzle_w : 2;
|
|
|
|
|
u32 abs : 1;
|
|
|
|
|
u32 cond_mod_reg_index : 1;
|
|
|
|
|
u32 cond_reg_index : 1;
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
} src0;
|
|
|
|
|
|
|
|
|
|
union SRC1
|
|
|
|
|
{
|
|
|
|
|
u32 HEX;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u32 reg_type : 2;
|
|
|
|
|
u32 tmp_reg_index : 6;
|
|
|
|
|
u32 fp16 : 1;
|
|
|
|
|
u32 swizzle_x : 2;
|
|
|
|
|
u32 swizzle_y : 2;
|
|
|
|
|
u32 swizzle_z : 2;
|
|
|
|
|
u32 swizzle_w : 2;
|
|
|
|
|
u32 neg : 1;
|
|
|
|
|
u32 abs : 1;
|
2013-08-26 16:18:59 +02:00
|
|
|
u32 input_mod_src0 : 3;
|
|
|
|
|
u32 : 6;
|
2012-11-15 00:39:56 +01:00
|
|
|
u32 scale : 3;
|
|
|
|
|
u32 opcode_is_branch : 1;
|
|
|
|
|
};
|
|
|
|
|
} src1;
|
|
|
|
|
|
|
|
|
|
union SRC2
|
|
|
|
|
{
|
|
|
|
|
u32 HEX;
|
|
|
|
|
|
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
u32 reg_type : 2;
|
|
|
|
|
u32 tmp_reg_index : 6;
|
|
|
|
|
u32 fp16 : 1;
|
|
|
|
|
u32 swizzle_x : 2;
|
|
|
|
|
u32 swizzle_y : 2;
|
|
|
|
|
u32 swizzle_z : 2;
|
|
|
|
|
u32 swizzle_w : 2;
|
|
|
|
|
u32 neg : 1;
|
|
|
|
|
u32 abs : 1;
|
|
|
|
|
u32 addr_reg : 11;
|
|
|
|
|
u32 use_index_reg : 1;
|
2013-08-26 16:18:59 +02:00
|
|
|
u32 perspective_corr: 1;
|
2012-11-15 00:39:56 +01:00
|
|
|
};
|
|
|
|
|
} src2;
|
|
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
std::string main;
|
|
|
|
|
std::string& m_shader;
|
2013-11-09 22:29:49 +01:00
|
|
|
GLParamArray& m_parr;
|
2012-11-15 00:39:56 +01:00
|
|
|
u32 m_addr;
|
|
|
|
|
u32& m_size;
|
2013-06-30 10:46:29 +02:00
|
|
|
u32 m_const_index;
|
2013-08-10 23:56:24 +02:00
|
|
|
u32 m_offset;
|
2013-11-03 20:23:16 +01:00
|
|
|
u32 m_location;
|
2013-11-26 05:34:19 +01:00
|
|
|
u32 m_ctrl;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
GLFragmentDecompilerThread(std::string& shader, GLParamArray& parr, u32 addr, u32& size, u32 ctrl)
|
2014-01-31 19:40:18 +01:00
|
|
|
: ThreadBase("Fragment Shader Decompiler Thread")
|
2012-11-15 00:39:56 +01:00
|
|
|
, m_shader(shader)
|
|
|
|
|
, m_parr(parr)
|
|
|
|
|
, m_addr(addr)
|
|
|
|
|
, m_size(size)
|
2013-06-30 10:46:29 +02:00
|
|
|
, m_const_index(0)
|
2013-11-03 20:23:16 +01:00
|
|
|
, m_location(0)
|
2013-11-26 05:34:19 +01:00
|
|
|
, m_ctrl(ctrl)
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-06-30 10:46:29 +02:00
|
|
|
m_size = 0;
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
std::string GetMask();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
void AddCode(std::string code, bool append_mask = true);
|
|
|
|
|
std::string AddReg(u32 index, int fp16);
|
2013-08-26 16:18:59 +02:00
|
|
|
bool HasReg(u32 index, int fp16);
|
2013-11-27 20:16:19 +01:00
|
|
|
std::string AddCond(int fp16);
|
|
|
|
|
std::string AddConst();
|
|
|
|
|
std::string AddTex();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
template<typename T> std::string GetSRC(T src);
|
|
|
|
|
std::string BuildCode();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
virtual void Task();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
u32 GetData(const u32 d) const { return d << 16 | d >> 16; }
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-09 22:29:49 +01:00
|
|
|
struct GLShaderProgram
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2013-11-09 22:29:49 +01:00
|
|
|
GLShaderProgram();
|
|
|
|
|
~GLShaderProgram();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-09 22:29:49 +01:00
|
|
|
GLFragmentDecompilerThread* m_decompiler_thread;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-09 22:29:49 +01:00
|
|
|
GLParamArray parr;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2013-11-27 20:16:19 +01:00
|
|
|
std::string shader;
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
u32 id;
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
void Wait()
|
|
|
|
|
{
|
|
|
|
|
if(m_decompiler_thread && m_decompiler_thread->IsAlive())
|
|
|
|
|
{
|
2014-01-31 19:40:18 +01:00
|
|
|
m_decompiler_thread->Join();
|
2013-06-30 10:46:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-09 22:29:49 +01:00
|
|
|
void Decompile(RSXShaderProgram& prog);
|
2012-11-15 00:39:56 +01:00
|
|
|
void Compile();
|
|
|
|
|
|
|
|
|
|
void Delete();
|
|
|
|
|
};
|