2009-04-03 14:35:49 +00:00
|
|
|
// Copyright (C) 2003-2000 Dolphin Project.
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
|
2009-09-03 19:24:16 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2009-10-14 01:58:39 +00:00
|
|
|
#include <locale.h>
|
2009-09-03 19:24:16 +00:00
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
#include "TextureConversionShader.h"
|
|
|
|
#include "TextureDecoder.h"
|
|
|
|
#include "PixelShaderManager.h"
|
|
|
|
#include "PixelShaderGen.h"
|
2009-06-22 09:31:30 +00:00
|
|
|
#include "BPMemory.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "RenderBase.h"
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
#define WRITE p+=sprintf
|
|
|
|
|
|
|
|
static char text[16384];
|
2009-10-25 02:35:21 +00:00
|
|
|
static bool IntensityConstantAdded = false;
|
2010-12-19 21:05:41 +00:00
|
|
|
static int s_incrementSampleXCount = 0;
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
namespace TextureConversionShader
|
|
|
|
{
|
|
|
|
|
|
|
|
u16 GetEncodedSampleCount(u32 format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GX_TF_I4: return 8;
|
|
|
|
case GX_TF_I8: return 4;
|
|
|
|
case GX_TF_IA4: return 4;
|
|
|
|
case GX_TF_IA8: return 2;
|
|
|
|
case GX_TF_RGB565: return 2;
|
|
|
|
case GX_TF_RGB5A3: return 2;
|
|
|
|
case GX_TF_RGBA8: return 1;
|
|
|
|
case GX_CTF_R4: return 8;
|
|
|
|
case GX_CTF_RA4: return 4;
|
|
|
|
case GX_CTF_RA8: return 2;
|
|
|
|
case GX_CTF_A8: return 4;
|
|
|
|
case GX_CTF_R8: return 4;
|
|
|
|
case GX_CTF_G8: return 4;
|
|
|
|
case GX_CTF_B8: return 4;
|
|
|
|
case GX_CTF_RG8: return 2;
|
|
|
|
case GX_CTF_GB8: return 2;
|
|
|
|
case GX_TF_Z8: return 4;
|
|
|
|
case GX_TF_Z16: return 2;
|
|
|
|
case GX_TF_Z24X8: return 1;
|
|
|
|
case GX_CTF_Z4: return 8;
|
|
|
|
case GX_CTF_Z8M: return 4;
|
|
|
|
case GX_CTF_Z8L: return 4;
|
|
|
|
case GX_CTF_Z16L: return 2;
|
|
|
|
default: return 1;
|
|
|
|
}
|
|
|
|
}
|
2011-12-03 01:04:37 +00:00
|
|
|
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
|
|
|
|
{
|
|
|
|
if(ApiType == API_GLSL)
|
|
|
|
return ""; // Once we switch to GLSL 1.3 we can do something here
|
|
|
|
static char result[64];
|
|
|
|
sprintf(result, " : register(%s%d)", prefix, num);
|
|
|
|
return result;
|
|
|
|
}
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2009-03-22 09:00:43 +00:00
|
|
|
// block dimensions : widthStride, heightStride
|
2009-02-23 06:15:48 +00:00
|
|
|
// texture dims : width, height, x offset, y offset
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteSwizzler(char*& p, u32 format, API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
// [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
|
|
|
|
WRITE(p, "uniform float4 "I_COLORS"[2] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
|
2009-03-22 09:00:43 +00:00
|
|
|
|
2009-08-11 20:36:13 +00:00
|
|
|
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
|
|
|
|
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
|
2009-03-22 09:00:43 +00:00
|
|
|
float samples = (float)GetEncodedSampleCount(format);
|
2011-12-03 01:04:37 +00:00
|
|
|
if (ApiType == API_OPENGL)
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
|
|
|
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
|
|
|
|
}
|
2011-12-03 01:04:37 +00:00
|
|
|
else if (ApiType == API_GLSL)
|
|
|
|
{
|
|
|
|
WRITE(p, "uniform sampler2DRect samp0;\n");
|
|
|
|
}
|
2011-06-10 19:16:09 +00:00
|
|
|
else if (ApiType & API_D3D9)
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
WRITE(p,"uniform sampler samp0 : register(s0);\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
else
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
|
|
|
WRITE(p,"sampler samp0 : register(s0);\n");
|
|
|
|
WRITE(p, "Texture2D Tex0 : register(t0);\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
if(ApiType == API_GLSL)
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " float4 ocol0;\n");
|
|
|
|
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
|
|
|
|
WRITE(p, "void main()\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p,"void main(\n");
|
|
|
|
if(ApiType != API_D3D11)
|
|
|
|
{
|
|
|
|
WRITE(p," out float4 ocol0 : COLOR0,\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WRITE(p," out float4 ocol0 : SV_Target,\n");
|
|
|
|
}
|
|
|
|
WRITE(p," in float2 uv0 : TEXCOORD0)\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:47:13 +00:00
|
|
|
WRITE(p, "{\n"
|
2009-03-22 09:00:43 +00:00
|
|
|
" float2 sampleUv;\n"
|
|
|
|
" float2 uv1 = floor(uv0);\n");
|
|
|
|
|
|
|
|
WRITE(p, " uv1.x = uv1.x * %f;\n", samples);
|
|
|
|
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
WRITE(p, " float xl = floor(uv1.x / %f);\n", blkW);
|
2009-03-22 09:00:43 +00:00
|
|
|
WRITE(p, " float xib = uv1.x - (xl * %f);\n", blkW);
|
|
|
|
WRITE(p, " float yl = floor(uv1.y / %f);\n", blkH);
|
|
|
|
WRITE(p, " float yb = yl * %f;\n", blkH);
|
|
|
|
WRITE(p, " float yoff = uv1.y - yb;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " float xp = uv1.x + (yoff * "I_COLORS"[1].x);\n");
|
2009-03-22 09:00:43 +00:00
|
|
|
WRITE(p, " float xel = floor(xp / %f);\n", blkW);
|
|
|
|
WRITE(p, " float xb = floor(xel / %f);\n", blkH);
|
|
|
|
WRITE(p, " float xoff = xel - (xb * %f);\n", blkH);
|
|
|
|
|
|
|
|
WRITE(p, " sampleUv.x = xib + (xb * %f);\n", blkW);
|
|
|
|
WRITE(p, " sampleUv.y = yb + xoff;\n");
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
if(ApiType == API_OPENGL)
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
|
2009-12-07 18:48:31 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
if(ApiType != API_OPENGL)
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
{
|
2010-06-05 00:01:18 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
|
2010-05-22 21:58:43 +00:00
|
|
|
}
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 02:39:55 +00:00
|
|
|
// block dimensions : widthStride, heightStride
|
|
|
|
// texture dims : width, height, x offset, y offset
|
2010-07-12 19:30:25 +00:00
|
|
|
void Write32BitSwizzler(char*& p, u32 format, API_TYPE ApiType)
|
2011-12-03 01:04:37 +00:00
|
|
|
{
|
|
|
|
// [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
|
|
|
|
WRITE(p, "uniform float4 "I_COLORS"[2] %s;\n", WriteRegister(ApiType, "c", C_COLORS));
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2009-08-11 20:36:13 +00:00
|
|
|
float blkW = (float)TexDecoder_GetBlockWidthInTexels(format);
|
|
|
|
float blkH = (float)TexDecoder_GetBlockHeightInTexels(format);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
|
|
|
// 32 bit textures (RGBA8 and Z24) are store in 2 cache line increments
|
2010-07-12 19:30:25 +00:00
|
|
|
if(ApiType == API_OPENGL)
|
|
|
|
{
|
|
|
|
WRITE(p,"uniform samplerRECT samp0 : register(s0);\n");
|
|
|
|
}
|
2011-12-03 01:04:37 +00:00
|
|
|
else if (ApiType == API_GLSL)
|
|
|
|
{
|
|
|
|
WRITE(p, "uniform sampler2DRect samp0;\n");
|
|
|
|
}
|
2011-06-10 19:16:09 +00:00
|
|
|
else if (ApiType & API_D3D9)
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
WRITE(p,"uniform sampler samp0 : register(s0);\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
else
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
|
|
|
WRITE(p,"sampler samp0 : register(s0);\n");
|
|
|
|
WRITE(p, "Texture2D Tex0 : register(t0);\n");
|
|
|
|
}
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
if(ApiType == API_GLSL)
|
2010-07-12 19:30:25 +00:00
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " float4 ocol0;\n");
|
|
|
|
WRITE(p, " float2 uv0 = gl_TexCoord[0].xy;\n");
|
|
|
|
WRITE(p, "void main()\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p,"void main(\n");
|
|
|
|
if(ApiType != API_D3D11)
|
|
|
|
{
|
|
|
|
WRITE(p," out float4 ocol0 : COLOR0,\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WRITE(p," out float4 ocol0 : SV_Target,\n");
|
|
|
|
}
|
|
|
|
WRITE(p," in float2 uv0 : TEXCOORD0)\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
|
2011-12-08 05:01:14 +00:00
|
|
|
WRITE(p, "{\n"
|
2009-05-15 02:39:55 +00:00
|
|
|
" float2 sampleUv;\n"
|
|
|
|
" float2 uv1 = floor(uv0);\n");
|
|
|
|
|
|
|
|
WRITE(p, " float yl = floor(uv1.y / %f);\n", blkH);
|
|
|
|
WRITE(p, " float yb = yl * %f;\n", blkH);
|
|
|
|
WRITE(p, " float yoff = uv1.y - yb;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " float xp = uv1.x + (yoff * "I_COLORS"[1].x);\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, " float xel = floor(xp / 2);\n");
|
|
|
|
WRITE(p, " float xb = floor(xel / %f);\n", blkH);
|
|
|
|
WRITE(p, " float xoff = xel - (xb * %f);\n", blkH);
|
|
|
|
|
|
|
|
WRITE(p, " float x2 = uv1.x * 2;\n");
|
|
|
|
WRITE(p, " float xl = floor(x2 / %f);\n", blkW);
|
|
|
|
WRITE(p, " float xib = x2 - (xl * %f);\n", blkW);
|
|
|
|
WRITE(p, " float halfxb = floor(xb / 2);\n");
|
|
|
|
|
|
|
|
|
|
|
|
WRITE(p, " sampleUv.x = xib + (halfxb * %f);\n", blkW);
|
|
|
|
WRITE(p, " sampleUv.y = yb + xoff;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv * "I_COLORS"[0].xy;\n");
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
if(ApiType == API_OPENGL)
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p," sampleUv.y = "I_COLORS"[1].y - sampleUv.y;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv + "I_COLORS"[1].zw;\n");
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
if(ApiType != API_OPENGL)
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
{
|
2010-06-05 00:01:18 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv + float2(0.0f,1.0f);\n");// still to determine the reason for this
|
2011-12-03 01:04:37 +00:00
|
|
|
WRITE(p, " sampleUv = sampleUv / "I_COLORS"[0].zw;\n");
|
2010-05-22 21:58:43 +00:00
|
|
|
}
|
2009-05-15 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
void WriteSampleColor(char*& p, const char* colorComp, const char* dest, API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-12-19 21:05:41 +00:00
|
|
|
const char* texSampleOpName;
|
2011-06-10 19:16:09 +00:00
|
|
|
if (ApiType & API_D3D9)
|
2010-12-19 21:05:41 +00:00
|
|
|
texSampleOpName = "tex2D";
|
2010-07-12 19:30:25 +00:00
|
|
|
else if (ApiType == API_D3D11)
|
2010-12-19 21:05:41 +00:00
|
|
|
texSampleOpName = "tex0.Sample";
|
2011-12-03 01:04:37 +00:00
|
|
|
else if (ApiType == API_GLSL)
|
|
|
|
texSampleOpName = "texture2DRect";
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
else
|
2010-12-19 21:05:41 +00:00
|
|
|
texSampleOpName = "texRECT";
|
|
|
|
|
|
|
|
// the increment of sampleUv.x is delayed, so we perform it here. see WriteIncrementSampleX.
|
|
|
|
const char* texSampleIncrementUnit;
|
|
|
|
if(ApiType != API_OPENGL)
|
2011-12-03 01:04:37 +00:00
|
|
|
texSampleIncrementUnit = I_COLORS"[0].x / "I_COLORS"[0].z";
|
2010-12-19 21:05:41 +00:00
|
|
|
else
|
2011-12-03 01:04:37 +00:00
|
|
|
texSampleIncrementUnit = I_COLORS"[0].x";
|
2010-12-19 21:05:41 +00:00
|
|
|
|
|
|
|
WRITE(p, " %s = %s(samp0, sampleUv + float2(%d * (%s), 0)).%s;\n",
|
|
|
|
dest, texSampleOpName, s_incrementSampleXCount, texSampleIncrementUnit, colorComp);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteColorToIntensity(char*& p, const char* src, const char* dest)
|
|
|
|
{
|
2009-10-25 02:35:21 +00:00
|
|
|
if(!IntensityConstantAdded)
|
|
|
|
{
|
|
|
|
WRITE(p, " float4 IntensityConst = float4(0.257f,0.504f,0.098f,0.0625f);\n");
|
|
|
|
IntensityConstantAdded = true;
|
|
|
|
}
|
2010-12-19 21:05:41 +00:00
|
|
|
WRITE(p, " %s = dot(IntensityConst.rgb, %s.rgb);\n", dest, src);
|
|
|
|
// don't add IntensityConst.a yet, because doing it later is faster and uses less instructions, due to vectorization
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteIncrementSampleX(char*& p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-12-19 21:05:41 +00:00
|
|
|
// 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++;
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteToBitDepth(char*& p, u8 depth, const char* src, const char* dest)
|
|
|
|
{
|
2012-05-05 01:21:05 +00:00
|
|
|
float result = 255 / pow(2.0f, (8 - depth));
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " %s = floor(%s * %ff);\n", dest, src, result);
|
|
|
|
}
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
void WriteEncoderEnd(char* p, API_TYPE ApiType)
|
2009-10-25 02:35:21 +00:00
|
|
|
{
|
2011-12-03 01:04:37 +00:00
|
|
|
if(ApiType == API_GLSL)
|
|
|
|
WRITE(p, "gl_FragData[0] = ocol0;\n");
|
2009-10-25 02:35:21 +00:00
|
|
|
WRITE(p, "}\n");
|
|
|
|
IntensityConstantAdded = false;
|
2010-12-19 21:05:41 +00:00
|
|
|
s_incrementSampleXCount = 0;
|
2009-10-25 02:35:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteI8Encoder(char* p, API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_I8,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float3 texSample;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.b");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.g");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.r");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.a");
|
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
WRITE(p, " ocol0.rgba += IntensityConst.aaaa;\n"); // see WriteColorToIntensity
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteI4Encoder(char* p, API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_I4,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float3 texSample;\n");
|
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color0.b");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color1.b");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color0.g");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color1.g");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color0.r");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color1.r");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color0.a");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgb", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color1.a");
|
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
WRITE(p, " color0.rgba += IntensityConst.aaaa;\n");
|
|
|
|
WRITE(p, " color1.rgba += IntensityConst.aaaa;\n");
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteToBitDepth(p, 4, "color0", "color0");
|
|
|
|
WriteToBitDepth(p, 4, "color1", "color1");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteIA8Encoder(char* p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_IA8,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float4 texSample;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " ocol0.b = texSample.a;\n");
|
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.g");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " ocol0.r = texSample.a;\n");
|
|
|
|
WriteColorToIntensity(p, "texSample", "ocol0.a");
|
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
WRITE(p, " ocol0.ga += IntensityConst.aa;\n");
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteIA4Encoder(char* p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_IA4,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float4 texSample;\n");
|
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.b = texSample.a;\n");
|
|
|
|
WriteColorToIntensity(p, "texSample", "color1.b");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.g = texSample.a;\n");
|
|
|
|
WriteColorToIntensity(p, "texSample", "color1.g");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.r = texSample.a;\n");
|
|
|
|
WriteColorToIntensity(p, "texSample", "color1.r");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.a = texSample.a;\n");
|
2009-03-22 09:00:43 +00:00
|
|
|
WriteColorToIntensity(p, "texSample", "color1.a");
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
WRITE(p, " color1.rgba += IntensityConst.aaaa;\n");
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteToBitDepth(p, 4, "color0", "color0");
|
|
|
|
WriteToBitDepth(p, 4, "color1", "color1");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteRGB565Encoder(char* p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_RGB565,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-12-19 21:05:41 +00:00
|
|
|
WriteSampleColor(p, "rgb", "float3 texSample0",ApiType);
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2010-12-19 21:05:41 +00:00
|
|
|
WriteSampleColor(p, "rgb", "float3 texSample1",ApiType);
|
2011-12-08 04:47:13 +00:00
|
|
|
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");
|
2010-12-19 21:05:41 +00:00
|
|
|
|
|
|
|
WriteToBitDepth(p, 6, "texGs", "float2 gInt");
|
|
|
|
WRITE(p, " float2 gUpper = floor(gInt / 8.0f);\n");
|
|
|
|
WRITE(p, " float2 gLower = gInt - gUpper * 8.0f;\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 5, "texRs", "ocol0.br");
|
|
|
|
WRITE(p, " ocol0.br = ocol0.br * 8.0f + gUpper;\n");
|
|
|
|
WriteToBitDepth(p, 5, "texBs", "ocol0.ga");
|
|
|
|
WRITE(p, " ocol0.ga = ocol0.ga + gLower * 32.0f;\n");
|
2009-03-22 03:25:59 +00:00
|
|
|
|
|
|
|
WRITE(p, " ocol0 = ocol0 / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-03-22 03:25:59 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteRGB5A3Encoder(char* p,API_TYPE ApiType)
|
2009-03-22 03:25:59 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_RGB5A3,ApiType);
|
2009-03-22 03:25:59 +00:00
|
|
|
|
|
|
|
WRITE(p, " float4 texSample;\n");
|
|
|
|
WRITE(p, " float color0;\n");
|
|
|
|
WRITE(p, " float gUpper;\n");
|
|
|
|
WRITE(p, " float gLower;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-03-22 03:25:59 +00:00
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 5, "texSample.g", "color0");
|
|
|
|
WRITE(p, " gUpper = floor(color0 / 8.0f);\n");
|
|
|
|
WRITE(p, " gLower = color0 - gUpper * 8.0f;\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 5, "texSample.r", "ocol0.b");
|
|
|
|
WRITE(p, " ocol0.b = ocol0.b * 4.0f + gUpper + 128.0f;\n");
|
|
|
|
WriteToBitDepth(p, 5, "texSample.b", "ocol0.g");
|
|
|
|
WRITE(p, " ocol0.g = ocol0.g + gLower * 32.0f;\n");
|
|
|
|
|
|
|
|
WRITE(p, "} else {\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 4, "texSample.r", "ocol0.b");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.b", "ocol0.g");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 3, "texSample.a", "color0");
|
|
|
|
WRITE(p, "ocol0.b = ocol0.b + color0 * 16.0f;\n");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.g", "color0");
|
|
|
|
WRITE(p, "ocol0.g = ocol0.g + color0 * 16.0f;\n");
|
|
|
|
|
|
|
|
WRITE(p, "}\n");
|
|
|
|
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-03-22 03:25:59 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-03-22 03:25:59 +00:00
|
|
|
|
|
|
|
WRITE(p, "if(texSample.a > 0.878f) {\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 5, "texSample.g", "color0");
|
|
|
|
WRITE(p, " gUpper = floor(color0 / 8.0f);\n");
|
|
|
|
WRITE(p, " gLower = color0 - gUpper * 8.0f;\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 5, "texSample.r", "ocol0.r");
|
|
|
|
WRITE(p, " ocol0.r = ocol0.r * 4.0f + gUpper + 128.0f;\n");
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteToBitDepth(p, 5, "texSample.b", "ocol0.a");
|
|
|
|
WRITE(p, " ocol0.a = ocol0.a + gLower * 32.0f;\n");
|
|
|
|
|
2009-03-22 03:25:59 +00:00
|
|
|
WRITE(p, "} else {\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 4, "texSample.r", "ocol0.r");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.b", "ocol0.a");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 3, "texSample.a", "color0");
|
|
|
|
WRITE(p, "ocol0.r = ocol0.r + color0 * 16.0f;\n");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.g", "color0");
|
|
|
|
WRITE(p, "ocol0.a = ocol0.a + color0 * 16.0f;\n");
|
|
|
|
|
|
|
|
WRITE(p, "}\n");
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " ocol0 = ocol0 / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteRGBA4443Encoder(char* p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_RGB5A3,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
WRITE(p, " float4 texSample;\n");
|
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
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");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WriteToBitDepth(p, 3, "texSample.a", "color0.r");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.r", "color1.r");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.g", "color0.a");
|
|
|
|
WriteToBitDepth(p, 4, "texSample.b", "color1.a");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteRGBA8Encoder(char* p,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
Write32BitSwizzler(p, GX_TF_RGBA8,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
WRITE(p, " float cl1 = xb - (halfxb * 2);\n");
|
|
|
|
WRITE(p, " float cl0 = 1.0f - cl1;\n");
|
|
|
|
|
|
|
|
WRITE(p, " float4 texSample;\n");
|
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, " color0.b = texSample.a;\n");
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.g = texSample.r;\n");
|
|
|
|
WRITE(p, " color1.b = texSample.g;\n");
|
|
|
|
WRITE(p, " color1.g = texSample.b;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "rgba", "texSample",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, " color0.r = texSample.a;\n");
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.a = texSample.r;\n");
|
|
|
|
WRITE(p, " color1.r = texSample.g;\n");
|
|
|
|
WRITE(p, " color1.a = texSample.b;\n");
|
|
|
|
|
2009-03-22 09:00:43 +00:00
|
|
|
WRITE(p, " ocol0 = (cl0 * color0) + (cl1 * color1);\n");
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteC4Encoder(char* p, const char* comp,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_R4,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color0.b",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color1.b",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color0.g",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color1.g",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color0.r",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color1.r",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color0.a",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "color1.a",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
|
|
|
WriteToBitDepth(p, 4, "color0", "color0");
|
|
|
|
WriteToBitDepth(p, 4, "color1", "color1");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteC8Encoder(char* p, const char* comp,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_R8,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.b",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.g",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.r",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.a",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteCC4Encoder(char* p, const char* comp,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_RA4,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " float2 texSample;\n");
|
|
|
|
WRITE(p, " float4 color0;\n");
|
|
|
|
WRITE(p, " float4 color1;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.b = texSample.x;\n");
|
|
|
|
WRITE(p, " color1.b = texSample.y;\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.g = texSample.x;\n");
|
|
|
|
WRITE(p, " color1.g = texSample.y;\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.r = texSample.x;\n");
|
|
|
|
WRITE(p, " color1.r = texSample.y;\n");
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "texSample",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
WRITE(p, " color0.a = texSample.x;\n");
|
|
|
|
WRITE(p, " color1.a = texSample.y;\n");
|
|
|
|
|
|
|
|
WriteToBitDepth(p, 4, "color0", "color0");
|
|
|
|
WriteToBitDepth(p, 4, "color1", "color1");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0 = (color0 * 16.0f + color1) / 255.0f;\n");
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteCC8Encoder(char* p, const char* comp, API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_RA8,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.bg",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, comp, "ocol0.ra",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteZ8Encoder(char* p, const char* multiplier,API_TYPE ApiType)
|
2009-05-15 02:39:55 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_Z8M,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
|
|
|
WRITE(p, " float depth;\n");
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteZ16Encoder(char* p,API_TYPE ApiType)
|
2009-05-15 02:39:55 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_TF_Z16,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " float depth;\n");
|
|
|
|
WRITE(p, " float3 expanded;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
|
|
|
// byte order is reversed
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-12-02 04:17:18 +00:00
|
|
|
|
|
|
|
WRITE(p, " depth *= 16777215.0f;\n");
|
|
|
|
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
|
|
|
|
WRITE(p, " depth -= expanded.r * 256 * 256;\n");
|
|
|
|
WRITE(p, " expanded.g = floor(depth / 256);\n");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0.b = expanded.g / 255;\n");
|
|
|
|
WRITE(p, " ocol0.g = expanded.r / 255;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-12-02 04:17:18 +00:00
|
|
|
|
|
|
|
WRITE(p, " depth *= 16777215.0f;\n");
|
|
|
|
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
|
|
|
|
WRITE(p, " depth -= expanded.r * 256 * 256;\n");
|
|
|
|
WRITE(p, " expanded.g = floor(depth / 256);\n");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0.r = expanded.g / 255;\n");
|
|
|
|
WRITE(p, " ocol0.a = expanded.r / 255;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteZ16LEncoder(char* p,API_TYPE ApiType)
|
2009-05-15 02:39:55 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSwizzler(p, GX_CTF_Z16L,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " float depth;\n");
|
|
|
|
WRITE(p, " float3 expanded;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
|
|
|
// byte order is reversed
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-12-02 04:17:18 +00:00
|
|
|
|
|
|
|
WRITE(p, " depth *= 16777215.0f;\n");
|
|
|
|
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
|
|
|
|
WRITE(p, " depth -= expanded.r * 256 * 256;\n");
|
|
|
|
WRITE(p, " expanded.g = floor(depth / 256);\n");
|
|
|
|
WRITE(p, " depth -= expanded.g * 256;\n");
|
|
|
|
WRITE(p, " expanded.b = depth;\n");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0.b = expanded.b / 255;\n");
|
|
|
|
WRITE(p, " ocol0.g = expanded.g / 255;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIncrementSampleX(p,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth",ApiType);
|
2009-12-02 04:17:18 +00:00
|
|
|
|
|
|
|
WRITE(p, " depth *= 16777215.0f;\n");
|
|
|
|
WRITE(p, " expanded.r = floor(depth / (256 * 256));\n");
|
|
|
|
WRITE(p, " depth -= expanded.r * 256 * 256;\n");
|
|
|
|
WRITE(p, " expanded.g = floor(depth / 256);\n");
|
|
|
|
WRITE(p, " depth -= expanded.g * 256;\n");
|
|
|
|
WRITE(p, " expanded.b = depth;\n");
|
|
|
|
|
|
|
|
WRITE(p, " ocol0.r = expanded.b;\n");
|
|
|
|
WRITE(p, " ocol0.a = expanded.g;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
void WriteZ24Encoder(char* p, API_TYPE ApiType)
|
2009-05-15 02:39:55 +00:00
|
|
|
{
|
2010-07-12 19:30:25 +00:00
|
|
|
Write32BitSwizzler(p, GX_TF_Z24X8,ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
|
|
|
WRITE(p, " float cl = xb - (halfxb * 2);\n");
|
|
|
|
|
|
|
|
WRITE(p, " float depth0;\n");
|
|
|
|
WRITE(p, " float depth1;\n");
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " float3 expanded0;\n");
|
|
|
|
WRITE(p, " float3 expanded1;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteSampleColor(p, "b", "depth0",ApiType);
|
|
|
|
WriteIncrementSampleX(p,ApiType);
|
|
|
|
WriteSampleColor(p, "b", "depth1",ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
|
2009-12-02 04:17:18 +00:00
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
WRITE(p, " depth%i *= 16777215.0f;\n", i);
|
|
|
|
|
|
|
|
WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i);
|
|
|
|
WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i);
|
|
|
|
WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i);
|
|
|
|
WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i);
|
|
|
|
WRITE(p, " expanded%i.b = depth%i;\n", i, i);
|
|
|
|
}
|
|
|
|
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, " if(cl > 0.5f) {\n");
|
|
|
|
// upper 16
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " ocol0.b = expanded0.g / 255;\n");
|
|
|
|
WRITE(p, " ocol0.g = expanded0.b / 255;\n");
|
|
|
|
WRITE(p, " ocol0.r = expanded1.g / 255;\n");
|
|
|
|
WRITE(p, " ocol0.a = expanded1.b / 255;\n");
|
2009-05-15 02:39:55 +00:00
|
|
|
WRITE(p, " } else {\n");
|
|
|
|
// lower 8
|
|
|
|
WRITE(p, " ocol0.b = 1.0f;\n");
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " ocol0.g = expanded0.r / 255;\n");
|
2009-09-14 06:25:00 +00:00
|
|
|
WRITE(p, " ocol0.r = 1.0f;\n");
|
2009-12-02 04:17:18 +00:00
|
|
|
WRITE(p, " ocol0.a = expanded1.r / 255;\n");
|
2009-10-25 02:35:21 +00:00
|
|
|
WRITE(p, " }\n");
|
2009-12-02 04:17:18 +00:00
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
WriteEncoderEnd(p, ApiType);
|
2009-05-15 02:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 19:30:25 +00:00
|
|
|
const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2009-10-14 01:58:39 +00:00
|
|
|
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
2009-02-23 06:15:48 +00:00
|
|
|
text[sizeof(text) - 1] = 0x7C; // canary
|
|
|
|
|
|
|
|
char *p = text;
|
|
|
|
|
2011-12-03 01:04:37 +00:00
|
|
|
if(ApiType == API_GLSL)
|
|
|
|
{
|
|
|
|
// A few required defines and ones that will make our lives a lot easier
|
|
|
|
WRITE(p, "#version 120\n");
|
|
|
|
// Silly differences
|
|
|
|
WRITE(p, "#define float2 vec2\n");
|
|
|
|
WRITE(p, "#define float3 vec3\n");
|
|
|
|
WRITE(p, "#define float4 vec4\n");
|
|
|
|
|
|
|
|
// cg to glsl function translation
|
|
|
|
WRITE(p, "#define frac(x) fract(x)\n");
|
|
|
|
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
|
|
|
|
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
|
|
|
|
|
|
|
|
// We require this here
|
|
|
|
WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n");
|
|
|
|
}
|
|
|
|
|
2009-02-23 06:15:48 +00:00
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case GX_TF_I4:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteI4Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_I8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteI8Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_IA4:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIA4Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_IA8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteIA8Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_RGB565:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteRGB565Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_RGB5A3:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteRGB5A3Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_RGBA8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteRGBA8Encoder(p,ApiType);
|
2009-03-22 09:00:43 +00:00
|
|
|
break;
|
2009-02-23 06:15:48 +00:00
|
|
|
case GX_CTF_R4:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC4Encoder(p, "r",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_RA4:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteCC4Encoder(p, "ar",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_RA8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteCC8Encoder(p, "ar",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_A8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC8Encoder(p, "a",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_R8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC8Encoder(p, "r",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_G8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC8Encoder(p, "g",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_B8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC8Encoder(p, "b",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_RG8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteCC8Encoder(p, "rg",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_GB8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteCC8Encoder(p, "gb",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_Z8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC8Encoder(p, "b",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_Z16:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteZ16Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_TF_Z24X8:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteZ24Encoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_Z4:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteC4Encoder(p, "b",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_Z8M:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteZ8Encoder(p, "256.0f",ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_Z8L:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteZ8Encoder(p, "65536.0f" ,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
|
|
|
case GX_CTF_Z16L:
|
2010-07-12 19:30:25 +00:00
|
|
|
WriteZ16LEncoder(p,ApiType);
|
2009-02-23 06:15:48 +00:00
|
|
|
break;
|
2009-03-22 09:00:43 +00:00
|
|
|
default:
|
2009-02-23 06:15:48 +00:00
|
|
|
PanicAlert("Unknown texture copy format: 0x%x\n", format);
|
2009-03-22 09:00:43 +00:00
|
|
|
break;
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (text[sizeof(text) - 1] != 0x7C)
|
|
|
|
PanicAlert("TextureConversionShader generator - buffer too small, canary has been eaten!");
|
|
|
|
|
2009-10-14 01:58:39 +00:00
|
|
|
setlocale(LC_NUMERIC, ""); // restore locale
|
2009-02-23 06:15:48 +00:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
void SetShaderParameters(float width, float height, float offsetX, float offsetY, float widthStride, float heightStride,float buffW,float buffH)
|
2009-02-23 06:15:48 +00:00
|
|
|
{
|
2011-01-31 01:28:32 +00:00
|
|
|
g_renderer->SetPSConstant4f(C_COLORMATRIX, widthStride, heightStride, buffW, buffH);
|
|
|
|
g_renderer->SetPSConstant4f(C_COLORMATRIX + 1, width, (height - 1), offsetX, offsetY);
|
2009-02-23 06:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|