TextureConverter: remove WriteIncrementSampleX

This commit is contained in:
degasus 2013-11-25 17:01:35 +01:00
parent 421fd0e16e
commit 11973d31c1

View File

@ -21,7 +21,6 @@
static char text[16384];
static bool IntensityConstantAdded = false;
static int s_incrementSampleXCount = 0;
namespace TextureConversionShader
{
@ -110,7 +109,7 @@ void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
WRITE(p, " sampleUv.y = yb + xoff;\n");
}
void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYPE ApiType)
void WriteSampleColor(char*& p, const char* colorComp, const char* dest, int xoffset, API_TYPE ApiType)
{
WRITE(p, // sampleUv is the sample position in (int)gx_coords
"uv0 = float2(sampleUv + int2(%d, 0));\n" // pixel offset (if more than one pixel is samped)
@ -120,7 +119,7 @@ void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYP
"uv0 /= float2(%d, %d);\n" // normlize to [0:1]
"uv0.y = 1.0-uv0.y;\n" // ogl foo (disable this line for d3d)
"%s = texture(samp0, uv0).%s;\n",
s_incrementSampleXCount, EFB_WIDTH, EFB_HEIGHT, dest, colorComp
xoffset, EFB_WIDTH, EFB_HEIGHT, dest, colorComp
);
}
@ -135,25 +134,6 @@ void WriteColorToIntensity(char*& p, const char* src, const char* dest)
// don't add IntensityConst.a yet, because doing it later is faster and uses less instructions, due to vectorization
}
void WriteIncrementSampleX(char*& p,API_TYPE ApiType)
{
// the shader compiler apparently isn't smart or aggressive enough to recognize that:
// foo1 = lookup(x)
// x = x + increment;
// foo2 = lookup(x)
// x = x + increment;
// foo3 = lookup(x)
// can be replaced with this:
// foo1 = lookup(x + 0.0 * increment)
// foo2 = lookup(x + 1.0 * increment)
// foo3 = lookup(x + 2.0 * increment)
// which looks like the same operations but uses considerably fewer ALU instruction slots.
// thus, instead of using the former method, we only increment a counter internally here,
// and we wait until WriteSampleColor to write out the constant multiplier
// to achieve the increment as in the latter case.
s_incrementSampleXCount++;
}
void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
{
WRITE(p, " %s = floor(%s * 255.0 / exp2(8.0 - %d.0));\n", dest, src, depth);
@ -163,7 +143,6 @@ void WriteEncoderEnd(char* p, API_TYPE ApiType)
{
WRITE(p, "}\n");
IntensityConstantAdded = false;
s_incrementSampleXCount = 0;
}
void WriteI8Encoder(char* p, API_TYPE ApiType)
@ -171,19 +150,16 @@ void WriteI8Encoder(char* p, API_TYPE ApiType)
WriteSwizzler(p, GX_TF_I8, ApiType);
WRITE(p, " float3 texSample;\n");
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 0, ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.b");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 1, ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 2, ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.r");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 3, ApiType);
WriteColorToIntensity(p, "texSample", "ocol0.a");
WRITE(p, " ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity
@ -198,35 +174,28 @@ void WriteI4Encoder(char* p, API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 0, ApiType);
WriteColorToIntensity(p, "texSample", "color0.b");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 1, ApiType);
WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 2, ApiType);
WriteColorToIntensity(p, "texSample", "color0.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 3, ApiType);
WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 4, ApiType);
WriteColorToIntensity(p, "texSample", "color0.r");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 5, ApiType);
WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 6, ApiType);
WriteColorToIntensity(p, "texSample", "color0.a");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "texSample", ApiType);
WriteSampleColor(p, "rgb", "texSample", 7, ApiType);
WriteColorToIntensity(p, "texSample", "color1.a");
WRITE(p, " color0.rgba += IntensityConst.aaaa;\n");
@ -244,12 +213,11 @@ void WriteIA8Encoder(char* p,API_TYPE ApiType)
WriteSwizzler(p, GX_TF_IA8, ApiType);
WRITE(p, " float4 texSample;\n");
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 0, ApiType);
WRITE(p, " ocol0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 1, ApiType);
WRITE(p, " ocol0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "ocol0.a");
@ -265,22 +233,19 @@ void WriteIA4Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 0, ApiType);
WRITE(p, " color0.b = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.b");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 1, ApiType);
WRITE(p, " color0.g = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 2, ApiType);
WRITE(p, " color0.r = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.r");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 3, ApiType);
WRITE(p, " color0.a = texSample.a;\n");
WriteColorToIntensity(p, "texSample", "color1.a");
@ -297,9 +262,8 @@ void WriteRGB565Encoder(char* p,API_TYPE ApiType)
{
WriteSwizzler(p, GX_TF_RGB565, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1", ApiType);
WriteSampleColor(p, "rgb", "float3 texSample0", 0, ApiType);
WriteSampleColor(p, "rgb", "float3 texSample1", 1, ApiType);
WRITE(p, " float2 texRs = float2(texSample0.r, texSample1.r);\n");
WRITE(p, " float2 texGs = float2(texSample0.g, texSample1.g);\n");
WRITE(p, " float2 texBs = float2(texSample0.b, texSample1.b);\n");
@ -326,7 +290,7 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float gUpper;\n");
WRITE(p, " float gLower;\n");
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 0, ApiType);
// 0.8784 = 224 / 255 which is the maximum alpha value that can be represented in 3 bits
WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -353,9 +317,8 @@ void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
WRITE(p, "}\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 1, ApiType);
WRITE(p, "if(texSample.a > 0.878f) {\n");
@ -392,15 +355,13 @@ void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 0, ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.b");
WriteToBitDepth(p, 4, "texSample.r", "color1.b");
WriteToBitDepth(p, 4, "texSample.g", "color0.g");
WriteToBitDepth(p, 4, "texSample.b", "color1.g");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 1, ApiType);
WriteToBitDepth(p, 3, "texSample.a", "color0.r");
WriteToBitDepth(p, 4, "texSample.r", "color1.r");
WriteToBitDepth(p, 4, "texSample.g", "color0.a");
@ -421,15 +382,13 @@ void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 0, ApiType);
WRITE(p, " color0.b = texSample.a;\n");
WRITE(p, " color0.g = texSample.r;\n");
WRITE(p, " color1.b = texSample.g;\n");
WRITE(p, " color1.g = texSample.b;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "rgba", "texSample", ApiType);
WriteSampleColor(p, "rgba", "texSample", 1, ApiType);
WRITE(p, " color0.r = texSample.a;\n");
WRITE(p, " color0.a = texSample.r;\n");
WRITE(p, " color1.r = texSample.g;\n");
@ -446,28 +405,14 @@ void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "color0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color0.a", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "color1.a", ApiType);
WriteSampleColor(p, comp, "color0.b", 0, ApiType);
WriteSampleColor(p, comp, "color1.b", 1, ApiType);
WriteSampleColor(p, comp, "color0.g", 2, ApiType);
WriteSampleColor(p, comp, "color1.g", 3, ApiType);
WriteSampleColor(p, comp, "color0.r", 4, ApiType);
WriteSampleColor(p, comp, "color1.r", 5, ApiType);
WriteSampleColor(p, comp, "color0.a", 6, ApiType);
WriteSampleColor(p, comp, "color1.a", 7, ApiType);
WriteToBitDepth(p, 4, "color0", "color0");
WriteToBitDepth(p, 4, "color1", "color1");
@ -480,16 +425,10 @@ void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_R8, ApiType);
WriteSampleColor(p, comp, "ocol0.b", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.g", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.r", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.a", ApiType);
WriteSampleColor(p, comp, "ocol0.b", 0, ApiType);
WriteSampleColor(p, comp, "ocol0.g", 1, ApiType);
WriteSampleColor(p, comp, "ocol0.r", 2, ApiType);
WriteSampleColor(p, comp, "ocol0.a", 3, ApiType);
WriteEncoderEnd(p, ApiType);
}
@ -501,22 +440,19 @@ void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
WRITE(p, " float4 color0;\n");
WRITE(p, " float4 color1;\n");
WriteSampleColor(p, comp, "texSample", ApiType);
WriteSampleColor(p, comp, "texSample", 0, ApiType);
WRITE(p, " color0.b = texSample.x;\n");
WRITE(p, " color1.b = texSample.y;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WriteSampleColor(p, comp, "texSample", 1, ApiType);
WRITE(p, " color0.g = texSample.x;\n");
WRITE(p, " color1.g = texSample.y;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WriteSampleColor(p, comp, "texSample", 2, ApiType);
WRITE(p, " color0.r = texSample.x;\n");
WRITE(p, " color1.r = texSample.y;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "texSample", ApiType);
WriteSampleColor(p, comp, "texSample", 3, ApiType);
WRITE(p, " color0.a = texSample.x;\n");
WRITE(p, " color1.a = texSample.y;\n");
@ -531,10 +467,8 @@ void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_RA8, ApiType);
WriteSampleColor(p, comp, "ocol0.bg", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, comp, "ocol0.ra", ApiType);
WriteSampleColor(p, comp, "ocol0.bg", 0, ApiType);
WriteSampleColor(p, comp, "ocol0.ra", 1, ApiType);
WriteEncoderEnd(p, ApiType);
}
@ -545,19 +479,16 @@ void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
WRITE(p, " float depth;\n");
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 0, ApiType);
WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 1, ApiType);
WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 2, ApiType);
WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 3, ApiType);
WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);
WriteEncoderEnd(p, ApiType);
@ -572,7 +503,7 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
// byte order is reversed
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 0, ApiType);
WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
@ -582,9 +513,7 @@ void WriteZ16Encoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.g / 255.0;\n");
WRITE(p, " ocol0.g = expanded.r / 255.0;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 1, ApiType);
WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
@ -606,7 +535,7 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
// byte order is reversed
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 0, ApiType);
WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
@ -618,9 +547,7 @@ void WriteZ16LEncoder(char* p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.b / 255.0;\n");
WRITE(p, " ocol0.g = expanded.g / 255.0;\n");
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth", ApiType);
WriteSampleColor(p, "b", "depth", 1, ApiType);
WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
@ -646,9 +573,8 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
WRITE(p, " float3 expanded0;\n");
WRITE(p, " float3 expanded1;\n");
WriteSampleColor(p, "b", "depth0", ApiType);
WriteIncrementSampleX(p, ApiType);
WriteSampleColor(p, "b", "depth1", ApiType);
WriteSampleColor(p, "b", "depth0", 0, ApiType);
WriteSampleColor(p, "b", "depth1", 1, ApiType);
for (int i = 0; i < 2; i++)
{