d3d12: Factorize common use functions among frag and vertex decompiler

This commit is contained in:
raven02 2015-06-07 15:19:48 +08:00 committed by Vincent Lejeune
parent e38bf8d51f
commit 1837f40ed4
6 changed files with 93 additions and 115 deletions

View File

@ -0,0 +1,71 @@
#include "stdafx.h"
#include "D3D12CommonDecompiler.h"
std::string getFloatTypeNameImp(size_t elementCount)
{
switch (elementCount)
{
default:
abort();
case 1:
return "float";
case 2:
return "float2";
case 3:
return "float3";
case 4:
return "float4";
}
}
std::string getFunctionImp(FUNCTION f)
{
switch (f)
{
default:
abort();
case FUNCTION::FUNCTION_DP2:
return "dot($0.xy, $1.xy).xxxx";
case FUNCTION::FUNCTION_DP2A:
return "(dot($0.xy, $1.xy) + $2.x).xxxx";
case FUNCTION::FUNCTION_DP3:
return "dot($0.xyz, $1.xyz).xxxx";
case FUNCTION::FUNCTION_DP4:
return "dot($0, $1).xxxx";
case FUNCTION::FUNCTION_DPH:
return "dot(float4($0.xyz, 1.0), $1).xxxx";
case FUNCTION::FUNCTION_SFL:
return "float4(0., 0., 0., 0.)";
case FUNCTION::FUNCTION_STR:
return "float4(1., 1., 1., 1.)";
case FUNCTION::FUNCTION_FRACT:
return "frac($0)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE:
return "$t.Sample($tsampler, $0.xy)";
case FUNCTION::FUNCTION_DFDX:
return "ddx($0)";
case FUNCTION::FUNCTION_DFDY:
return "ddy($0)";
}
}
std::string compareFunctionImp(COMPARE f, const std::string &Op0, const std::string &Op1)
{
switch (f)
{
default:
abort();
case COMPARE::FUNCTION_SEQ:
return "(" + Op0 + " == " + Op1 + ")";
case COMPARE::FUNCTION_SGE:
return "(" + Op0 + " >= " + Op1 + ")";
case COMPARE::FUNCTION_SGT:
return "(" + Op0 + " > " + Op1 + ")";
case COMPARE::FUNCTION_SLE:
return "(" + Op0 + " <= " + Op1 + ")";
case COMPARE::FUNCTION_SLT:
return "(" + Op0 + " < " + Op1 + ")";
case COMPARE::FUNCTION_SNE:
return "(" + Op0 + " != " + Op1 + ")";
}
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "../Common/ShaderParam.h"
std::string getFloatTypeNameImp(size_t elementCount);
std::string getFunctionImp(FUNCTION f);
std::string compareFunctionImp(COMPARE f, const std::string &Op0, const std::string &Op1);

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#if defined(DX12_SUPPORT)
#include "D3D12FragmentProgramDecompiler.h"
#include "D3D12CommonDecompiler.h"
#include "Utilities/Log.h"
#include "Emu/Memory/Memory.h"
#include "Emu/System.h"
@ -14,50 +14,12 @@ D3D12FragmentDecompiler::D3D12FragmentDecompiler(u32 addr, u32& size, u32 ctrl)
std::string D3D12FragmentDecompiler::getFloatTypeName(size_t elementCount)
{
switch (elementCount)
{
default:
abort();
case 1:
return "float";
case 2:
return "float2";
case 3:
return "float3";
case 4:
return "float4";
}
return getFloatTypeNameImp(elementCount);
}
std::string D3D12FragmentDecompiler::getFunction(enum class FUNCTION f)
{
switch (f)
{
default:
abort();
case FUNCTION::FUNCTION_DP2:
return "dot($0.xy, $1.xy).xxxx";
case FUNCTION::FUNCTION_DP2A:
return "(dot($0.xy, $1.xy) + $2.x).xxxx";
case FUNCTION::FUNCTION_DP3:
return "dot($0.xyz, $1.xyz).xxxx";
case FUNCTION::FUNCTION_DP4:
return "dot($0, $1).xxxx";
case FUNCTION::FUNCTION_DPH:
return "dot(float4($0.xyz, 1.0), $1).xxxx";
case FUNCTION::FUNCTION_SFL:
return "float4(0., 0., 0., 0.)";
case FUNCTION::FUNCTION_STR:
return "float4(1., 1., 1., 1.)";
case FUNCTION::FUNCTION_FRACT:
return "frac($0)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE:
return "$t.Sample($tsampler, $0.xy)";
case FUNCTION::FUNCTION_DFDX:
return "ddx($0)";
case FUNCTION::FUNCTION_DFDY:
return "ddy($0)";
}
return getFunctionImp(f);
}
std::string D3D12FragmentDecompiler::saturate(const std::string & code)
@ -67,23 +29,7 @@ std::string D3D12FragmentDecompiler::saturate(const std::string & code)
std::string D3D12FragmentDecompiler::compareFunction(COMPARE f, const std::string &Op0, const std::string &Op1)
{
switch (f)
{
default:
abort();
case COMPARE::FUNCTION_SEQ:
return "(" + Op0 + " == " + Op1 + ")";
case COMPARE::FUNCTION_SGE:
return "(" + Op0 + " >= " + Op1 +")";
case COMPARE::FUNCTION_SGT:
return "(" + Op0 + " > " + Op1 + ")";
case COMPARE::FUNCTION_SLE:
return "(" + Op0 + " <= " + Op1 + ")";
case COMPARE::FUNCTION_SLT:
return "(" + Op0 + " < " + Op1 + ")";
case COMPARE::FUNCTION_SNE:
return "(" + Op0 + " != " + Op1 + ")";
}
return compareFunctionImp(f, Op0, Op1);
}
void D3D12FragmentDecompiler::insertHeader(std::stringstream & OS)

View File

@ -1,77 +1,24 @@
#include "stdafx.h"
#if defined(DX12_SUPPORT)
#include "D3D12VertexProgramDecompiler.h"
#include "D3D12CommonDecompiler.h"
#include "Utilities/Log.h"
#include "Emu/System.h"
std::string D3D12VertexProgramDecompiler::getFloatTypeName(size_t elementCount)
{
switch (elementCount)
{
default:
abort();
case 1:
return "float";
case 2:
return "float2";
case 3:
return "float3";
case 4:
return "float4";
}
return getFloatTypeNameImp(elementCount);
}
std::string D3D12VertexProgramDecompiler::getFunction(enum class FUNCTION f)
{
switch (f)
{
default:
abort();
case FUNCTION::FUNCTION_DP2:
return "dot($0.xy, $1.xy).xxxx";
case FUNCTION::FUNCTION_DP2A:
return "(dot($0.xy, $1.xy) + $2.x).xxxx";
case FUNCTION::FUNCTION_DP3:
return "dot($0.xyz, $1.xyz).xxxx";
case FUNCTION::FUNCTION_DP4:
return "dot($0, $1).xxxx";
case FUNCTION::FUNCTION_DPH:
return "dot(float4($0.xyz, 1.0), $1).xxxx";
case FUNCTION::FUNCTION_SFL:
return "float4(0., 0., 0., 0.)";
case FUNCTION::FUNCTION_STR:
return "float4(1., 1., 1., 1.)";
case FUNCTION::FUNCTION_FRACT:
return "frac($0)";
case FUNCTION::FUNCTION_TEXTURE_SAMPLE:
return "$t.Sample($tsampler, $0.xy)";
case FUNCTION::FUNCTION_DFDX:
return "ddx($0)";
case FUNCTION::FUNCTION_DFDY:
return "ddy($0)";
}
return getFunctionImp(f);
}
std::string D3D12VertexProgramDecompiler::compareFunction(COMPARE f, const std::string &Op0, const std::string &Op1)
{
switch (f)
{
default:
abort();
case COMPARE::FUNCTION_SEQ:
return "(" + Op0 + " == " + Op1 + ").xxxx";
case COMPARE::FUNCTION_SGE:
return "(" + Op0 + " >= " + Op1 + ").xxxx";
case COMPARE::FUNCTION_SGT:
return "(" + Op0 + " > " + Op1 + ").xxxx";
case COMPARE::FUNCTION_SLE:
return "(" + Op0 + " <= " + Op1 + ").xxxx";
case COMPARE::FUNCTION_SLT:
return "(" + Op0 + " < " + Op1 + ").xxxx";
case COMPARE::FUNCTION_SNE:
return "(" + Op0 + " != " + Op1 + ").xxxx";
}
return compareFunctionImp(f, Op0, Op1);
}
void D3D12VertexProgramDecompiler::insertHeader(std::stringstream &OS)

View File

@ -48,6 +48,7 @@
<ClCompile Include="Emu\RSX\D3D12\D3D12RenderTargetSets.cpp" />
<ClCompile Include="Emu\RSX\D3D12\D3D12Texture.cpp" />
<ClCompile Include="Emu\RSX\D3D12\D3D12VertexProgramDecompiler.cpp" />
<ClCompile Include="Emu\RSX\D3D12\D3D12CommonDecompiler.cpp" />
<ClCompile Include="Emu\RSX\GL\GLCommonDecompiler.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sys_dbg.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sys_fs.cpp" />
@ -513,6 +514,7 @@
<ClInclude Include="Emu\RSX\D3D12\D3D12RenderTargetSets.h" />
<ClInclude Include="Emu\RSX\D3D12\D3D12Texture.h" />
<ClInclude Include="Emu\RSX\D3D12\D3D12VertexProgramDecompiler.h" />
<ClInclude Include="Emu\RSX\D3D12\D3D12CommonDecompiler.h" />
<ClInclude Include="Emu\RSX\GCM.h" />
<ClInclude Include="Emu\RSX\GL\GLBuffers.h" />
<ClInclude Include="Emu\RSX\GL\GLCommonDecompiler.h" />

View File

@ -986,6 +986,9 @@
<ClCompile Include="Emu\RSX\D3D12\D3D12VertexProgramDecompiler.cpp">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClCompile>
<ClCompile Include="Emu\RSX\D3D12\D3D12CommonDecompiler.cpp">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClCompile>
<ClCompile Include="Emu\RSX\D3D12\D3D12Texture.cpp">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClCompile>
@ -1870,6 +1873,9 @@
<ClInclude Include="Emu\RSX\D3D12\D3D12VertexProgramDecompiler.h">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClInclude>
<ClInclude Include="Emu\RSX\D3D12\D3D12CommonDecompiler.h">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClInclude>
<ClInclude Include="Emu\RSX\D3D12\D3D12Texture.h">
<Filter>Emu\GPU\RSX\D3D12</Filter>
</ClInclude>