Bit more cleanup from removing Nvidia CG

This commit is contained in:
Ryan Houdek 2012-12-27 22:46:29 -06:00
parent d7f43c7a68
commit 7d93834cd8
7 changed files with 47 additions and 57 deletions

View File

@ -507,7 +507,7 @@ static void BuildSwapModeTable()
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
return ""; // Nothing to do here
static char result[64];
sprintf(result, " : register(%s%d)", prefix, num);
@ -516,7 +516,7 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
const char* WriteBinding(API_TYPE ApiType, const u32 num)
{
if (ApiType != API_GLSL || !g_ActiveConfig.backend_info.bSupportsGLSLBinding)
if (!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
return "";
static char result[64];
sprintf(result, "layout(binding = %d) ", num);
@ -525,7 +525,7 @@ const char* WriteBinding(API_TYPE ApiType, const u32 num)
const char *WriteLocation(API_TYPE ApiType)
{
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return "";
static char result[64];
sprintf(result, "uniform ");
@ -557,7 +557,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
DepthTextureEnable = (bpmem.ztex2.op != ZTEXTURE_DISABLE && !bpmem.zcontrol.zcomploc && bpmem.zmode.testenable && bpmem.zmode.updateenable) || g_ActiveConfig.bEnablePerPixelDepth ;
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -640,7 +640,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
}
WRITE(p, "\n");
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform PSBlock {\n");
WRITE(p, "%sfloat4 " I_COLORS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
@ -656,10 +656,10 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "%sfloat4 " I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS));
WRITE(p, "%sfloat4 " I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS));
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
if (ApiType != API_GLSL)
if (ApiType != API_OPENGL)
{
WRITE(p, "void main(\n");
if (ApiType != API_D3D11)
@ -788,7 +788,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "depth = 1.f;\n");
if(dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = 0;\n");
if(ApiType == API_GLSL && dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
if(ApiType == API_OPENGL && dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "gl_FragData[0] = ocol0;\n");
if(ApiType != API_D3D11)
WRITE(p, "return;\n");
@ -921,7 +921,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
WRITE(p, "depth = 1.f;\n");
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
WRITE(p, "ocol1 = float4(0.0f,0.0f,0.0f,0.0f);\n");
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
// Once we switch to GLSL 1.3 and bind variables, we won't need to do this
if (dstAlphaMode != DSTALPHA_DUAL_SOURCE_BLEND)
@ -975,7 +975,7 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
// ...and the alpha from ocol0 will be written to the framebuffer.
WRITE(p, " ocol0.a = " I_ALPHA"[0].a;\n");
}
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
if (DepthTextureEnable)
WRITE(p, "gl_FragDepth = depth;\n");
@ -1350,7 +1350,7 @@ void SampleTexture(char *&p, const char *destination, const char *texcoords, con
if (ApiType == API_D3D11)
WRITE(p, "%s=Tex%d.Sample(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, texmap,texmap, texcoords, texmap, texswap);
else
WRITE(p, "%s=%s(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, ApiType == API_GLSL ? "texture2D" : "tex2D", texmap, texcoords, texmap, texswap);
WRITE(p, "%s=%s(samp%d,%s.xy * " I_TEXDIMS"[%d].xy).%s;\n", destination, ApiType == API_OPENGL ? "texture2D" : "tex2D", texmap, texcoords, texmap, texswap);
}
static const char *tevAlphaFuncsTable[] =

View File

@ -69,7 +69,7 @@ u16 GetEncodedSampleCount(u32 format)
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
return ""; // Once we switch to GLSL 1.3 we can do something here
static char result[64];
sprintf(result, " : register(%s%d)", prefix, num);
@ -78,7 +78,7 @@ const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
const char *WriteLocation(API_TYPE ApiType)
{
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
return "";
static char result[64];
sprintf(result, "uniform ");
@ -92,22 +92,18 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 " I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
float samples = (float)GetEncodedSampleCount(format);
if (ApiType == API_OPENGL)
{
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
}
else if (ApiType == API_GLSL)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "layout(binding = 0) ");
@ -124,7 +120,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
}
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -165,12 +161,12 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " sampleUv = sampleUv * " I_COLORS"[0].xy;\n");
if (ApiType == API_OPENGL || ApiType == API_GLSL)
if (ApiType == API_OPENGL)
WRITE(p," sampleUv.y = " I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + " I_COLORS"[1].zw;\n");
if (ApiType != API_OPENGL && ApiType != API_GLSL)
if (ApiType != API_OPENGL)
{
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / " I_COLORS"[0].zw;\n");
@ -184,10 +180,10 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// [0] left, top, right, bottom of source rectangle within source texture
// [1] width and height of destination texture in pixels
// Two were merged for GLSL
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140%s) uniform PSBlock {\n", g_ActiveConfig.backend_info.bSupportsGLSLBinding ? ", binding = 1" : "");
WRITE(p, "%sfloat4 " I_COLORS"[2] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_COLORS));
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
@ -195,10 +191,6 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
// 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
if (ApiType == API_OPENGL)
{
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
}
else if (ApiType == API_GLSL)
{
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
WRITE(p, "layout(binding = 0) ");
@ -214,7 +206,7 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, "Texture2D Tex0 : register(t0);\n");
}
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
WRITE(p, " float4 ocol0;\n");
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
@ -256,12 +248,12 @@ void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " sampleUv.y = yb + xoff;\n");
WRITE(p, " sampleUv = sampleUv * " I_COLORS"[0].xy;\n");
if (ApiType == API_OPENGL || ApiType == API_GLSL)
if (ApiType == API_OPENGL)
WRITE(p," sampleUv.y = " I_COLORS"[1].y - sampleUv.y;\n");
WRITE(p, " sampleUv = sampleUv + " I_COLORS"[1].zw;\n");
if (ApiType != API_OPENGL && ApiType != API_GLSL)
if (ApiType != API_OPENGL)
{
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
WRITE(p, " sampleUv = sampleUv / " I_COLORS"[0].zw;\n");
@ -275,14 +267,12 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
texSampleOpName = "tex2D";
else if (ApiType == API_D3D11)
texSampleOpName = "tex0.Sample";
else if (ApiType == API_GLSL)
texSampleOpName = "texture2DRect";
else
texSampleOpName = "texRECT";
texSampleOpName = "texture2DRect";
// the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX.
const char* texSampleIncrementUnit;
if (ApiType != API_OPENGL && ApiType != API_GLSL)
if (ApiType != API_OPENGL)
texSampleIncrementUnit = I_COLORS"[0].x / " I_COLORS"[0].z";
else
texSampleIncrementUnit = I_COLORS"[0].x";
@ -329,7 +319,7 @@ void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
void WriteEncoderEnd(char* p, API_TYPE ApiType)
{
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
WRITE(p, "gl_FragData[0] = ocol0;\n");
WRITE(p, "}\n");
IntensityConstantAdded = false;
@ -855,7 +845,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
char *p = text;
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)

View File

@ -132,30 +132,30 @@ static char text[16384];
char* GenerateVSOutputStruct(char* p, u32 components, API_TYPE ApiType)
{
// This turned a bit ugly with GLSL
// Will be less ugly with GLSL 1.3...hopefully
// GLSL makes this ugly
// TODO: Make pretty
WRITE(p, "struct VS_OUTPUT {\n");
WRITE(p, " float4 pos %s POSITION;\n", ApiType == API_GLSL ? ";//" : ":");
WRITE(p, " float4 colors_0 %s COLOR0;\n", ApiType == API_GLSL ? ";//" : ":");
WRITE(p, " float4 colors_1 %s COLOR1;\n", ApiType == API_GLSL ? ";//" : ":");
WRITE(p, " float4 pos %s POSITION;\n", ApiType == API_OPENGL ? ";//" : ":");
WRITE(p, " float4 colors_0 %s COLOR0;\n", ApiType == API_OPENGL ? ";//" : ":");
WRITE(p, " float4 colors_1 %s COLOR1;\n", ApiType == API_OPENGL ? ";//" : ":");
if (xfregs.numTexGen.numTexGens < 7) {
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " float3 tex%d %s TEXCOORD%d;\n", i, ApiType == API_GLSL ? ";//" : ":", i);
WRITE(p, " float4 clipPos %s TEXCOORD%d;\n", ApiType == API_GLSL ? ";//" : ":", xfregs.numTexGen.numTexGens);
WRITE(p, " float3 tex%d %s TEXCOORD%d;\n", i, ApiType == API_OPENGL ? ";//" : ":", i);
WRITE(p, " float4 clipPos %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens);
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
WRITE(p, " float4 Normal %s TEXCOORD%d;\n", ApiType == API_GLSL ? ";//" : ":", xfregs.numTexGen.numTexGens + 1);
WRITE(p, " float4 Normal %s TEXCOORD%d;\n", ApiType == API_OPENGL ? ";//" : ":", xfregs.numTexGen.numTexGens + 1);
} else {
// clip position is in w of first 4 texcoords
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{
for (int i = 0; i < 8; ++i)
WRITE(p, " float4 tex%d %s TEXCOORD%d;\n", i, ApiType == API_GLSL ? ";//" : ":", i);
WRITE(p, " float4 tex%d %s TEXCOORD%d;\n", i, ApiType == API_OPENGL? ";//" : ":", i);
}
else
{
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i)
WRITE(p, " float%d tex%d %s TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, ApiType == API_GLSL ? ";//" : ":", i);
WRITE(p, " float%d tex%d %s TEXCOORD%d;\n", i < 4 ? 4 : 3 , i, ApiType == API_OPENGL ? ";//" : ":", i);
}
}
WRITE(p, "};\n");
@ -185,7 +185,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
char *p = text;
WRITE(p, "//Vertex Shader: comp:%x, \n", components);
if (ApiType == API_GLSL)
if (ApiType == API_OPENGL)
{
// A few required defines and ones that will make our lives a lot easier
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding || g_ActiveConfig.backend_info.bSupportsGLSLUBO)
@ -222,7 +222,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
}
// uniforms
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "layout(std140) uniform VSBlock {\n");
WRITE(p, "%sfloat4 " I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
@ -235,13 +235,13 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "%sfloat4 " I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
WRITE(p, "%sfloat4 " I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
if (ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
WRITE(p, "};\n");
p = GenerateVSOutputStruct(p, components, ApiType);
if(ApiType == API_GLSL)
if(ApiType == API_OPENGL)
{
if (components & VB_HAS_NRM0)
WRITE(p, " float3 rawnorm0 = gl_Normal; // NORMAL0,\n");
@ -603,9 +603,10 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
WRITE(p, "o.pos = o.pos + float4(" I_DEPTHPARAMS".z, " I_DEPTHPARAMS".w, 0.f, 0.f);\n");
}
if(ApiType == API_GLSL)
if(ApiType == API_OPENGL)
{
// Bit ugly here
// TODO: Make pretty
// Will look better when we bind uniforms in GLSL 1.3
// clipPos/w needs to be done in pixel shader, not here

View File

@ -105,8 +105,7 @@ typedef enum
API_D3D9_SM20 = 4,
API_D3D9 = 6,
API_D3D11 = 8,
API_GLSL = 16,
API_NONE = 32
API_NONE = 16
} API_TYPE;
inline u32 RGBA8ToRGBA6ToRGBA8(u32 src)

View File

@ -194,7 +194,7 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
// Make an entry in the table
PSCacheEntry& newentry = PixelShaders[uid];
last_entry = &newentry;
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_GLSL, components);
const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components);
if (g_ActiveConfig.bEnableShaderDebugging && code)
{

View File

@ -179,7 +179,7 @@ FRAGMENTSHADER &GetOrCreateEncodingShader(u32 format)
if (s_encodingPrograms[format].glprogid == 0)
{
const char* shader = TextureConversionShader::GenerateEncodingShader(format, API_GLSL);
const char* shader = TextureConversionShader::GenerateEncodingShader(format, API_OPENGL);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && shader)

View File

@ -89,7 +89,7 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
// Make an entry in the table
VSCacheEntry& entry = vshaders[uid];
last_entry = &entry;
const char *code = GenerateVertexShaderCode(components, API_GLSL);
const char *code = GenerateVertexShaderCode(components, API_OPENGL);
GetSafeVertexShaderId(&entry.safe_uid, components);
#if defined(_DEBUG) || defined(DEBUGFAST)