mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-01-30 03:32:55 +00:00
d3d12: Dump program parameters
This commit is contained in:
parent
3853dffce2
commit
5a1b756c14
@ -119,12 +119,12 @@ ID3D12PipelineState *PipelineStateObjectCache::getGraphicPipelineState(
|
||||
{
|
||||
LOG_WARNING(RSX, "VP not found in buffer!");
|
||||
VertexDecompiler VS(vertexShader->data);
|
||||
VS.Decompile();
|
||||
std::string shaderCode = VS.Decompile();
|
||||
m_vertex_prog.Compile(SHADER_TYPE::SHADER_TYPE_VERTEX);
|
||||
AddVertexProgram(m_vertex_prog, *vertexShader);
|
||||
|
||||
// TODO: This shouldn't use current dir
|
||||
fs::file("./VertexProgram.txt", o_write | o_create | o_trunc).write(VS.m_shader.c_str(), VS.m_shader.size());
|
||||
fs::file("./VertexProgram.txt", o_write | o_create | o_trunc).write(shaderCode.c_str(), shaderCode.size());
|
||||
}
|
||||
|
||||
if (m_fp_buf_num && m_vp_buf_num)
|
||||
|
@ -449,11 +449,6 @@ std::string VertexDecompiler::BuildCode()
|
||||
}
|
||||
|
||||
std::string p;
|
||||
|
||||
for (auto& param : m_parr.params) {
|
||||
p += param.Format();
|
||||
}
|
||||
|
||||
std::string fp;
|
||||
|
||||
for (int i = m_funcs.size() - 1; i > 0; --i)
|
||||
@ -499,15 +494,66 @@ std::string VertexDecompiler::BuildCode()
|
||||
f += fmt::Format("\nvoid %s()\n{\n%s}\n", m_funcs[i].name.c_str(), BuildFuncBody(m_funcs[i]).c_str());
|
||||
}
|
||||
|
||||
static const std::string& prot =
|
||||
"#version 420\n"
|
||||
"\n"
|
||||
"uniform mat4 scaleOffsetMat = mat4(1.0);\n"
|
||||
"%s\n"
|
||||
"%s\n"
|
||||
"%s";
|
||||
std::stringstream OS;
|
||||
insertHeader(OS);
|
||||
|
||||
return fmt::Format(prot.c_str(), p.c_str(), fp.c_str(), f.c_str());
|
||||
insertInputs(OS, m_parr.params[PARAM_IN]);
|
||||
OS << std::endl;
|
||||
insertOutputs(OS, m_parr.params[PARAM_OUT]);
|
||||
OS << std::endl;
|
||||
insertConstants(OS, m_parr.params[PARAM_UNIFORM]);
|
||||
OS << std::endl;
|
||||
|
||||
|
||||
OS << fp.c_str() << std::endl;
|
||||
OS << f.c_str() << std::endl;
|
||||
|
||||
return OS.str();
|
||||
}
|
||||
|
||||
void VertexDecompiler::insertHeader(std::stringstream &OS)
|
||||
{
|
||||
OS << "cbuffer SCALE_OFFSET : register(b0)" << std::endl;
|
||||
OS << "{" << std::endl;
|
||||
OS << " float4x4 scaleOffsetMat;" << std::endl;
|
||||
OS << "};" << std::endl;
|
||||
}
|
||||
|
||||
void VertexDecompiler::insertInputs(std::stringstream & OS, const std::vector<ParamType>& inputs)
|
||||
{
|
||||
OS << "struct VertexInput" << std::endl;
|
||||
OS << "{" << std::endl;
|
||||
for (const ParamType PT : inputs)
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
OS << " " << PT.type << " " << PI.name << ": TEXCOORD" << PI.location << ";" << std::endl;
|
||||
}
|
||||
OS << "};" << std::endl;
|
||||
}
|
||||
|
||||
void VertexDecompiler::insertConstants(std::stringstream & OS, const std::vector<ParamType> & constants)
|
||||
{
|
||||
OS << "cbuffer CONSTANT_BUFFER" << std::endl;
|
||||
OS << "{" << std::endl;
|
||||
for (const ParamType PT : constants)
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
OS << " " << PT.type << " " << PI.name << ";" << std::endl;
|
||||
}
|
||||
OS << "};" << std::endl;
|
||||
}
|
||||
|
||||
void VertexDecompiler::insertOutputs(std::stringstream & OS, const std::vector<ParamType> & outputs)
|
||||
{
|
||||
OS << "struct PixelInput" << std::endl;
|
||||
OS << "{" << std::endl;
|
||||
OS << " float4 position : SV_POSITION;" << std::endl;
|
||||
for (const ParamType PT : outputs)
|
||||
{
|
||||
for (const ParamItem &PI : PT.items)
|
||||
OS << " " << PT.type << " " << PI.name << ": TEXCOORD" << PI.location << ";" << std::endl;
|
||||
}
|
||||
OS << "};" << std::endl;
|
||||
}
|
||||
|
||||
VertexDecompiler::VertexDecompiler(std::vector<u32>& data) :
|
||||
@ -522,9 +568,10 @@ VertexDecompiler::VertexDecompiler(std::vector<u32>& data) :
|
||||
//m_cur_func->body = "\tgl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);\n";
|
||||
}
|
||||
|
||||
void VertexDecompiler::Decompile()
|
||||
std::string VertexDecompiler::Decompile()
|
||||
{
|
||||
m_parr.params.clear();
|
||||
for (unsigned i = 0; i < PARAM_COUNT; i++)
|
||||
m_parr.params[i].clear();
|
||||
m_instr_count = 0;
|
||||
|
||||
for (int i = 0; i < m_max_instr_count; ++i)
|
||||
@ -769,7 +816,7 @@ void VertexDecompiler::Decompile()
|
||||
AddCode("}");
|
||||
}
|
||||
|
||||
m_shader = BuildCode();
|
||||
std::string result = BuildCode();
|
||||
|
||||
m_jump_lvls.clear();
|
||||
m_body.clear();
|
||||
@ -777,6 +824,7 @@ void VertexDecompiler::Decompile()
|
||||
{
|
||||
m_funcs.erase(m_funcs.begin() + 2, m_funcs.end());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#if defined(DX12_SUPPORT)
|
||||
#include "Emu/RSX/RSXVertexProgram.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
enum ParamFlag
|
||||
{
|
||||
@ -11,30 +11,27 @@ enum ParamFlag
|
||||
PARAM_UNIFORM,
|
||||
PARAM_CONST,
|
||||
PARAM_NONE,
|
||||
PARAM_COUNT,
|
||||
};
|
||||
|
||||
struct GLParamItem
|
||||
struct ParamItem
|
||||
{
|
||||
std::string name;
|
||||
std::string location;
|
||||
std::string value;
|
||||
int location;
|
||||
|
||||
GLParamItem(const std::string& _name, int _location, const std::string& _value = "")
|
||||
ParamItem(const std::string& _name, int _location, const std::string& _value = "")
|
||||
: name(_name)
|
||||
, value(_value)
|
||||
{
|
||||
if (_location > -1)
|
||||
location = "layout (location = " + std::to_string(_location) + ") ";
|
||||
else
|
||||
location = "";
|
||||
}
|
||||
, value(_value),
|
||||
location(_location)
|
||||
{ }
|
||||
};
|
||||
|
||||
struct ParamType
|
||||
{
|
||||
const ParamFlag flag;
|
||||
std::string type;
|
||||
std::vector<GLParamItem> items;
|
||||
std::vector<ParamItem> items;
|
||||
|
||||
ParamType(const ParamFlag _flag, const std::string& _type)
|
||||
: flag(_flag)
|
||||
@ -51,63 +48,32 @@ struct ParamType
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Format()
|
||||
{
|
||||
std::string ret = "";
|
||||
|
||||
for (u32 n = 0; n<items.size(); ++n)
|
||||
{
|
||||
ret += items[n].location + type + " " + items[n].name;
|
||||
if (!items[n].value.empty())
|
||||
{
|
||||
ret += " = " + items[n].value;
|
||||
}
|
||||
ret += ";\n";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct ParamArray
|
||||
{
|
||||
std::vector<ParamType> params;
|
||||
std::vector<ParamType> params[PARAM_COUNT];
|
||||
|
||||
ParamType* SearchParam(const std::string& type)
|
||||
ParamType* SearchParam(const ParamFlag &flag, const std::string& type)
|
||||
{
|
||||
for (u32 i = 0; i<params.size(); ++i)
|
||||
for (u32 i = 0; i<params[flag].size(); ++i)
|
||||
{
|
||||
if (params[i].type.compare(type) == 0)
|
||||
return ¶ms[i];
|
||||
if (params[flag][i].type.compare(type) == 0)
|
||||
return ¶ms[flag][i];
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string GetParamFlag(const ParamFlag flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
case PARAM_OUT: return "out ";
|
||||
case PARAM_IN: return "in ";
|
||||
case PARAM_UNIFORM: return "uniform ";
|
||||
case PARAM_CONST: return "const ";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool HasParam(const ParamFlag flag, std::string type, const std::string& name)
|
||||
{
|
||||
type = GetParamFlag(flag) + type;
|
||||
ParamType* t = SearchParam(type);
|
||||
ParamType* t = SearchParam(flag, type);
|
||||
return t && t->SearchName(name);
|
||||
}
|
||||
|
||||
std::string AddParam(const ParamFlag flag, std::string type, const std::string& name, const std::string& value)
|
||||
{
|
||||
type = GetParamFlag(flag) + type;
|
||||
ParamType* t = SearchParam(type);
|
||||
ParamType* t = SearchParam(flag, type);
|
||||
|
||||
if (t)
|
||||
{
|
||||
@ -115,9 +81,9 @@ struct ParamArray
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 num = params.size();
|
||||
params.emplace_back(flag, type);
|
||||
params[num].items.emplace_back(name, -1, value);
|
||||
const u32 num = params[flag].size();
|
||||
params[flag].emplace_back(flag, type);
|
||||
params[flag][num].items.emplace_back(name, -1, value);
|
||||
}
|
||||
|
||||
return name;
|
||||
@ -125,8 +91,7 @@ struct ParamArray
|
||||
|
||||
std::string AddParam(const ParamFlag flag, std::string type, const std::string& name, int location = -1)
|
||||
{
|
||||
type = GetParamFlag(flag) + type;
|
||||
ParamType* t = SearchParam(type);
|
||||
ParamType* t = SearchParam(flag, type);
|
||||
|
||||
if (t)
|
||||
{
|
||||
@ -134,9 +99,9 @@ struct ParamArray
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 num = params.size();
|
||||
params.emplace_back(flag, type);
|
||||
params[num].items.emplace_back(name, location);
|
||||
const u32 num = params[flag].size();
|
||||
params[flag].emplace_back(flag, type);
|
||||
params[flag][num].items.emplace_back(name, location);
|
||||
}
|
||||
|
||||
return name;
|
||||
@ -288,9 +253,13 @@ struct VertexDecompiler
|
||||
std::string BuildFuncBody(const FuncInfo& func);
|
||||
std::string BuildCode();
|
||||
|
||||
protected:
|
||||
virtual void insertHeader(std::stringstream &OS);
|
||||
virtual void insertInputs(std::stringstream &OS, const std::vector<ParamType> &inputs);
|
||||
virtual void insertConstants(std::stringstream &OS, const std::vector<ParamType> &constants);
|
||||
virtual void insertOutputs(std::stringstream &OS, const std::vector<ParamType> &outputs);
|
||||
public:
|
||||
std::string m_shader;
|
||||
VertexDecompiler(std::vector<u32>& data);
|
||||
void Decompile();
|
||||
std::string Decompile();
|
||||
};
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user