2020-12-05 13:08:24 +01:00
|
|
|
#pragma once
|
2021-05-12 23:56:01 +02:00
|
|
|
#include "RSXVertexProgram.h"
|
2015-05-19 18:17:08 +02:00
|
|
|
#include <vector>
|
2018-03-20 12:14:45 +01:00
|
|
|
#include <stack>
|
2015-05-19 18:17:08 +02:00
|
|
|
#include "ShaderParam.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class is used to translate RSX Vertex program to GLSL/HLSL code
|
|
|
|
|
* Backend with text based shader can subclass this class and implement :
|
2020-12-18 08:39:54 +01:00
|
|
|
* - virtual std::string getFloatTypeName(usz elementCount) = 0;
|
2015-05-19 18:17:08 +02:00
|
|
|
* - virtual std::string getFunction(enum class FUNCTION) = 0;
|
|
|
|
|
* - virtual std::string compareFunction(enum class COMPARE, const std::string &, const std::string &) = 0;
|
|
|
|
|
* - virtual void insertHeader(std::stringstream &OS) = 0;
|
2018-04-29 08:41:51 +02:00
|
|
|
* - virtual void insertInputs(std::stringstream &OS) = 0;
|
2015-05-19 18:17:08 +02:00
|
|
|
* - virtual void insertOutputs(std::stringstream &OS) = 0;
|
|
|
|
|
* - virtual void insertConstants(std::stringstream &OS) = 0;
|
|
|
|
|
* - virtual void insertMainStart(std::stringstream &OS) = 0;
|
|
|
|
|
* - virtual void insertMainEnd(std::stringstream &OS) = 0;
|
|
|
|
|
*/
|
|
|
|
|
struct VertexProgramDecompiler
|
|
|
|
|
{
|
2015-12-21 04:35:56 +01:00
|
|
|
D0 d0;
|
|
|
|
|
D1 d1;
|
|
|
|
|
D2 d2;
|
|
|
|
|
D3 d3;
|
|
|
|
|
SRC src[3];
|
|
|
|
|
|
2018-11-20 20:41:08 +01:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
lt = 0x1,
|
|
|
|
|
eq = 0x2,
|
|
|
|
|
gt = 0x4,
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-19 18:17:08 +02:00
|
|
|
struct FuncInfo
|
|
|
|
|
{
|
|
|
|
|
u32 offset;
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Instruction
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> body;
|
|
|
|
|
int open_scopes;
|
|
|
|
|
int close_scopes;
|
|
|
|
|
int put_close_scopes;
|
|
|
|
|
int do_count;
|
|
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
|
{
|
|
|
|
|
body.clear();
|
|
|
|
|
put_close_scopes = open_scopes = close_scopes = do_count = 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-27 14:36:18 +02:00
|
|
|
Instruction m_instructions[rsx::max_vertex_program_instructions];
|
2015-05-19 18:17:08 +02:00
|
|
|
Instruction* m_cur_instr;
|
2020-12-18 08:39:54 +01:00
|
|
|
usz m_instr_count;
|
2015-05-19 18:17:08 +02:00
|
|
|
|
|
|
|
|
std::vector<std::string> m_body;
|
2018-03-20 12:14:45 +01:00
|
|
|
std::stack<u32> m_call_stack;
|
2015-05-19 18:17:08 +02:00
|
|
|
|
2018-07-01 19:37:05 +02:00
|
|
|
const RSXVertexProgram& m_prog;
|
2015-05-19 18:17:08 +02:00
|
|
|
ParamArray m_parr;
|
|
|
|
|
|
2022-03-23 21:59:42 +01:00
|
|
|
std::set<u16> m_constant_ids;
|
2022-03-23 20:53:18 +01:00
|
|
|
|
2021-04-09 21:12:47 +02:00
|
|
|
static std::string NotZeroPositive(const std::string& code);
|
|
|
|
|
std::string GetMask(bool is_sca) const;
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string GetVecMask();
|
|
|
|
|
std::string GetScaMask();
|
|
|
|
|
std::string GetDST(bool is_sca = false);
|
2019-06-08 10:07:31 +02:00
|
|
|
std::string GetSRC(u32 n);
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string GetTex();
|
2018-11-20 20:41:08 +01:00
|
|
|
std::string GetRawCond();
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string GetCond();
|
2021-04-09 21:12:47 +02:00
|
|
|
std::string GetOptionalBranchCond() const; //Conditional branch expression modified externally at runtime
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string AddAddrReg();
|
2018-03-20 12:14:45 +01:00
|
|
|
std::string AddCondReg();
|
2021-04-09 21:12:47 +02:00
|
|
|
u32 GetAddr() const;
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string Format(const std::string& code);
|
|
|
|
|
|
2019-08-31 13:31:12 +02:00
|
|
|
void AddCodeCond(const std::string& lhs, const std::string& rhs);
|
2015-05-19 18:17:08 +02:00
|
|
|
void AddCode(const std::string& code);
|
|
|
|
|
void SetDST(bool is_sca, std::string value);
|
|
|
|
|
void SetDSTVec(const std::string& code);
|
|
|
|
|
void SetDSTSca(const std::string& code);
|
|
|
|
|
std::string BuildCode();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/** returns the type name of float vectors.
|
|
|
|
|
*/
|
2020-12-18 08:39:54 +01:00
|
|
|
virtual std::string getFloatTypeName(usz elementCount) = 0;
|
2015-05-19 18:17:08 +02:00
|
|
|
|
2015-10-05 19:30:06 +02:00
|
|
|
/** returns the type name of int vectors.
|
|
|
|
|
*/
|
2020-12-18 08:39:54 +01:00
|
|
|
virtual std::string getIntTypeName(usz elementCount) = 0;
|
2015-10-05 19:30:06 +02:00
|
|
|
|
2015-05-19 18:17:08 +02:00
|
|
|
/** returns string calling function where arguments are passed via
|
|
|
|
|
* $0 $1 $2 substring.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::string getFunction(FUNCTION) = 0;
|
|
|
|
|
|
2016-07-19 13:06:01 +02:00
|
|
|
/** returns string calling comparison function on 2 args passed as strings.
|
2015-05-19 18:17:08 +02:00
|
|
|
*/
|
2018-07-06 13:50:29 +02:00
|
|
|
virtual std::string compareFunction(COMPARE, const std::string &, const std::string &, bool scalar = false) = 0;
|
2015-05-19 18:17:08 +02:00
|
|
|
|
|
|
|
|
/** Insert header of shader file (eg #version, "system constants"...)
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertHeader(std::stringstream &OS) = 0;
|
|
|
|
|
|
|
|
|
|
/** Insert vertex declaration.
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertInputs(std::stringstream &OS, const std::vector<ParamType> &inputs) = 0;
|
|
|
|
|
|
|
|
|
|
/** insert global declaration of vertex shader outputs.
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertConstants(std::stringstream &OS, const std::vector<ParamType> &constants) = 0;
|
|
|
|
|
|
|
|
|
|
/** insert declaration of shader constants.
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertOutputs(std::stringstream &OS, const std::vector<ParamType> &outputs) = 0;
|
|
|
|
|
|
|
|
|
|
/** insert beginning of main (signature, temporary declaration...)
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertMainStart(std::stringstream &OS) = 0;
|
|
|
|
|
|
|
|
|
|
/** insert end of main function (return value, output copy...)
|
|
|
|
|
*/
|
|
|
|
|
virtual void insertMainEnd(std::stringstream &OS) = 0;
|
2018-01-24 22:09:27 +01:00
|
|
|
|
2015-05-19 18:17:08 +02:00
|
|
|
public:
|
2018-01-24 22:09:27 +01:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
bool has_lit_op = false;
|
2022-03-23 20:53:18 +01:00
|
|
|
bool has_indexed_constants = false;
|
2018-01-24 22:09:27 +01:00
|
|
|
}
|
|
|
|
|
properties;
|
|
|
|
|
|
2016-01-10 20:09:56 +01:00
|
|
|
VertexProgramDecompiler(const RSXVertexProgram& prog);
|
2015-05-19 18:17:08 +02:00
|
|
|
std::string Decompile();
|
|
|
|
|
};
|