ShaderGen: Small optimization.
This commit is contained in:
parent
cdddb26bba
commit
248d56d930
|
@ -26,7 +26,7 @@
|
|||
|
||||
// uid_data needs to have a struct named lighting_uid
|
||||
template<class T,class UidDataT>
|
||||
void GenerateLightShader(T& object, UidDataT& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
|
||||
static void GenerateLightShader(T& object, UidDataT& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
|
||||
{
|
||||
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
|
||||
const char* swizzle = "xyzw";
|
||||
|
@ -94,7 +94,7 @@ void GenerateLightShader(T& object, UidDataT& uid_data, int index, int litchan_i
|
|||
// inColorName is color in vs and colors_ in ps
|
||||
// dest is o.colors_ in vs and colors_ in ps
|
||||
template<class T, class UidDataT>
|
||||
void GenerateLightingShader(T& object, UidDataT& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
||||
static void GenerateLightingShader(T& object, UidDataT& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
||||
{
|
||||
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
|
||||
{
|
||||
|
|
|
@ -21,10 +21,11 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "CommonTypes.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "CommonTypes.h"
|
||||
#include "VideoCommon.h"
|
||||
|
||||
class ShaderGeneratorInterface
|
||||
{
|
||||
public:
|
||||
|
@ -125,4 +126,31 @@ private:
|
|||
std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here?
|
||||
};
|
||||
|
||||
template<class T>
|
||||
static void WriteRegister(T& object, API_TYPE ApiType, const char *prefix, const u32 num)
|
||||
{
|
||||
if (ApiType == API_OPENGL)
|
||||
return; // Nothing to do here
|
||||
|
||||
object.Write(" : register(%s%d)", prefix, num);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void WriteLocation(T& object, API_TYPE ApiType, bool using_ubos)
|
||||
{
|
||||
if (using_ubos)
|
||||
return;
|
||||
|
||||
object.Write("uniform ");
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void DeclareUniform(T& object, API_TYPE api_type, bool using_ubos, const u32 num, const char* type, const char* name)
|
||||
{
|
||||
WriteLocation(object, api_type, using_ubos);
|
||||
object.Write("%s %s ", type, name);
|
||||
WriteRegister(object, api_type, "c", num);
|
||||
object.Write(";\n");
|
||||
}
|
||||
|
||||
#endif // _SHADERGENCOMMON_H
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
static char text[16768];
|
||||
|
||||
template<class T>
|
||||
void DefineVSOutputStructMember(T& object, API_TYPE api_type, const char* type, const char* name, int var_index, const char* semantic, int semantic_index = -1)
|
||||
static void DefineVSOutputStructMember(T& object, API_TYPE api_type, const char* type, const char* name, int var_index, const char* semantic, int semantic_index = -1)
|
||||
{
|
||||
object.Write(" %s %s", type, name);
|
||||
if (var_index != -1)
|
||||
|
@ -48,7 +48,7 @@ void DefineVSOutputStructMember(T& object, API_TYPE api_type, const char* type,
|
|||
|
||||
// TODO: Check if something goes wrong if the cached shaders used pixel lighting but it's disabled later??
|
||||
template<class T>
|
||||
void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type)
|
||||
static void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type)
|
||||
{
|
||||
object.Write("struct VS_OUTPUT {\n");
|
||||
DefineVSOutputStructMember(object, api_type, "float4", "pos", -1, "POSITION");
|
||||
|
@ -76,12 +76,8 @@ void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type)
|
|||
object.Write("};\n");
|
||||
}
|
||||
|
||||
// TODO: Seriously? -.-
|
||||
extern const char *WriteRegister(API_TYPE api_type, const char *prefix, const u32 num);
|
||||
extern const char *WriteLocation(API_TYPE api_type);
|
||||
|
||||
template<class T>
|
||||
void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||
static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||
{
|
||||
// Non-uid template parameters will write to the dummy data (=> gets optimized out)
|
||||
vertex_shader_uid_data dummy_data;
|
||||
|
@ -108,16 +104,16 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
|||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
out.Write("layout(std140) uniform VSBlock {\n");
|
||||
|
||||
out.Write("%sfloat4 " I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_POSNORMALMATRIX));
|
||||
out.Write("%sfloat4 " I_PROJECTION"[4] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_PROJECTION));
|
||||
out.Write("%sfloat4 " I_MATERIALS"[4] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_MATERIALS));
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PROJECTION, "float4", I_PROJECTION"[4]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_MATERIALS, "float4", I_MATERIALS"[4]");
|
||||
out.Write("struct Light { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; };\n");
|
||||
out.Write("%sLight " I_LIGHTS"[8] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_LIGHTS));
|
||||
out.Write("%sfloat4 " I_TEXMATRICES"[24] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_TEXMATRICES)); // also using tex matrices
|
||||
out.Write("%sfloat4 " I_TRANSFORMMATRICES"[64] %s;\n", WriteLocation(api_type),WriteRegister(api_type, "c", C_TRANSFORMMATRICES));
|
||||
out.Write("%sfloat4 " I_NORMALMATRICES"[32] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_NORMALMATRICES));
|
||||
out.Write("%sfloat4 " I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_POSTTRANSFORMMATRICES));
|
||||
out.Write("%sfloat4 " I_DEPTHPARAMS" %s;\n", WriteLocation(api_type), WriteRegister(api_type, "c", C_DEPTHPARAMS));
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_LIGHTS, "Light", I_LIGHTS"[8]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TRANSFORMMATRICES, "float4", I_TRANSFORMMATRICES"[64]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_NORMALMATRICES, "float4", I_NORMALMATRICES"[32]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSTTRANSFORMMATRICES, "float4", I_POSTTRANSFORMMATRICES"[64]");
|
||||
DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_DEPTHPARAMS, "float4", I_DEPTHPARAMS);
|
||||
|
||||
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||
out.Write("};\n");
|
||||
|
|
|
@ -76,7 +76,8 @@ const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
|||
{I_DEPTHPARAMS, C_DEPTHPARAMS, 1 },
|
||||
};
|
||||
|
||||
// TODO: Need packing?
|
||||
#pragma pack(4)
|
||||
|
||||
struct vertex_shader_uid_data
|
||||
|
||||
{
|
||||
|
@ -108,6 +109,7 @@ struct vertex_shader_uid_data
|
|||
u32 light_mask : 8;
|
||||
} lit_chans[4];
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
typedef ShaderUid<vertex_shader_uid_data> VertexShaderUid;
|
||||
typedef ShaderCode VertexShaderCode; // TODO: Obsolete..
|
||||
|
|
Loading…
Reference in New Issue