* Fix context code for the common shader and set the indices for the uniform... (will fix most of GLSL-related  black screen issue)
* some memory improvements were not merged from zzogl-dev branch


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5252 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-06-01 08:21:31 +00:00
parent ca6b638303
commit 85bfc2ed66
5 changed files with 153 additions and 68 deletions

View File

@ -158,6 +158,9 @@ enum PSM_value{
// This code returns the same value on Z-textures, so texel storage mode is (BITMODE and !ISZTEX).
inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
template <int psm>
inline int PSM_BITMODE() {return (psm & 0x7);}
inline int PSMT_BITS_NUM(int psm)
{
// Treat these as 32 bit.
@ -186,36 +189,49 @@ inline int PSMT_BITS_NUM(int psm)
// Used for PSMT8, PSMT8H, PSMT4, PSMT4HH, PSMT4HL textures
inline bool PSMT_ISCLUT(int psm) { return (PSMT_BITMODE(psm) > 2);}
// Check to see if it is 32 bits. According to code comments, anyways.
// I'll have to look closer at it, because it'd seem like it'd return true for 24 bits.
// Note: the function only works for clut format. Clut PSM is 4 bits only. The possible value are PSMCT32, PSMCT16, PSMCT16S
inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
// PSMCT16, PSMCT16S, PSMT16Z, PSMT16SZ is 16-bit targets and usually there is
// two of them in each 32-bit word.
inline bool PSMT_IS16BIT(int psm) { return (PSMT_BITMODE(psm) == 2);}
template <int psm>
inline bool PSM_IS16BIT() { return ((psm & 0x7) == 2);}
// PSM16Z and PSMT16SZ use -1 offset to z-buff. Need to check this thesis.
inline bool PSMT_IS16Z(int psm) {return ((psm & 0x32) == 0x32);}
// PSMT32Z, PSMT24Z, PSMT16Z, PSMT16SZ is Z-buffer textures
inline bool PSMT_ISZTEX(int psm) {return ((psm & 0x30) == 0x30);}
// PSMCT16, PSMCT16S, PSMT8, PSMT8H, PSMT16Z and PSMT16SZ use only half 16 bit per pixel.
inline bool PSMT_ISHALF(int psm) {return ((psm & 2) == 2);}
template <int psm>
inline bool PSM_ISHALF() {return (psm & 2);}
// PSMT8 and PSMT8H use IDTEX8 CLUT, PSMT4H, PSMT4HL, PSMT4HH -- IDTEX4.
// Don't use it on non clut entries, please!
inline bool PSMT_IS8CLUT(int psm) {return ((psm & 3) == 3);}
// PSM16Z and PSMT16SZ use -1 offset to z-buff. Need to check this thesis.
inline bool PSMT_IS16Z(int psm) {return ((psm & 0x32) == 0x32);}
// Check to see if it is 32 bits. According to code comments, anyways.
// I'll have to look closer at it, because it'd seem like it'd return true for 24 bits.
// Note: the function only works for clut format. Clut PSM is 4 bits only. The possible value are PSMCT32, PSMCT16, PSMCT16S
inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
// When color format is RGB24 (PSMCT24) or RGBA16 (PSMCT16 & 16S) alpha value expanded, based on
// TEXA register and AEM status.
inline int PSMT_ALPHAEXP(int psm) {return (psm == PSMCT24 || psm == PSMCT16 || psm == PSMCT16S);}
// Check, how many pixels would be stored in side. So 32 and 24 is 32-bit's (1 pixel),
// 16, 16S -- 16 bit's (2 pixels), 8 and 8H -- 4 pixels, and 4 -- 8 pixels.
inline int PSMT_BITCOUNT(int psm) {return (PSMT_BITMODE(psm) == 0) ? 1 : 1 << (PSMT_BITMODE(psm) - 1); }
template <int psm>
inline int PSM_BITCOUNT() {return (PSM_BITMODE<psm>() == 0) ? 1 : 1 << (PSM_BITMODE<psm>() - 1); }
// This function updates the 6th and 5th bit of psm
// 00 or 11 -> 00 ; 01 -> 10 ; 10 -> 01
inline int Switch_Top_Bytes (int X) {
inline int Switch_Top_Bytes (int X)
{
if ( ( X & 0x30 ) == 0 )
return X;
else
@ -235,6 +251,61 @@ inline int PIXELS_PER_WORD(int psm)
return 1;
}
template <int psm>
inline int PSM_PIXELS_PER_WORD()
{
if (psm == PSMT8)
return 4;
if (psm == PSMT4)
return 8;
if (PSM_IS16BIT<psm>())
return 2;
return 1;
}
// Some psm does not have all pixels in memory.
template <int psm>
inline bool PSM_NON_FULL_WORD()
{
return ((psm == PSMCT24) || (psm == PSMT24Z) || (psm == PSMT8H) || (psm == PSMT4HL) || (psm == PSMT4HH));
}
inline bool PSM_NON_FULL_WORD(int psm)
{
return ((psm == PSMCT24) || (psm == PSMT24Z) || (psm == PSMT8H) || (psm == PSMT4HL) || (psm == PSMT4HH));
}
template <int psm>
inline int PSM_PIXEL_SHIFT()
{
if (!PSM_NON_FULL_WORD<psm>())
return 0;
switch (psm) {
case PSMCT24:
case PSMT24Z:
return 0;
case PSMT8H:
case PSMT4HL:
return 24;
case PSMT4HH:
return 28;
default: return 0;
}
}
template <int psm>
inline int PSM_BITS_PER_PIXEL()
{
switch (psm & 0x7) {
case 0: return 32;
case 1: return 24;
case 2: return 16;
case 3: return 8;
case 4: return 4;
default: return 0;
}
}
// Some storage formats could share the same memory block (2 textures in 1 format). This include following combinations:
// PSMT24(24Z) with either 8H, 4HL, 4HH and PSMT4HL with PSMT4HH.
// We use slightly different versions of this function on comparison with GSDX, Storage format XOR 0x30 made Z-textures
@ -247,6 +318,33 @@ inline bool PSMT_HAS_SHARED_BITS (int fpsm, int tpsm) {
// If a clut is in 32-bit color, its size is 4 bytes, and 16-bit clut has a 2 byte size.
inline int CLUT_PIXEL_SIZE(int cpsm) {return ((cpsm <= 1) ? 4 : 2); }
inline void PSMT_SET_BLOCK_SIZE (int psm, int& W, int&H, int& ppw) {
switch (PIXELS_PER_WORD(psm)) {
case 8:
W = 128; H = 128; ppw = 8;
case 4:
W = 128; H = 64; ppw = 4;
case 2:
W = 64; H = 64; ppw = 2;
default:
W = 32; H = 64; ppw = 1;
}
}
template <int psm>
inline int PSM_PIXELS_STORED_PER_WORD()
{
return 32 / PSM_BITS_PER_PIXEL<psm>();
}
template <int psm>
inline int PSM_BYTS_LOAD_PER_WRITE()
{
if (psm == PSMCT24 || psm == PSMT24Z) return 3;
return 4;
}
//----------------------- Data from registers -----------------------
typedef union

View File

@ -1325,6 +1325,9 @@ void Flush(int context)
FUNCLOG
VB& curvb = vb[context];
const pixTest curtest = curvb.test;
#ifdef GLSL4_API
g_cs.set_context(context);
#endif
if (FlushInitialTest(curvb, curtest, context)) return;

View File

@ -64,6 +64,10 @@ inline bool ZZshActiveParameter(ZZshParameter param) {return (param !=NULL); }
#include "GSVertexArrayOGL.h"
#endif
// GLSL only
// Set it to 0 to diable context usage, 1 -- to enable. FFX-1 have a strange issue with ClampExt.
#define NOCONTEXT 0
#ifdef GLSL_API
enum ZZshPARAMTYPE {
@ -329,7 +333,7 @@ struct FRAGMENTSHADER
#else
const GLenum g_texture_target[11] = {GL_TEXTURE_RECTANGLE, GL_TEXTURE_RECTANGLE, GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_RECTANGLE, GL_TEXTURE_RECTANGLE, GL_TEXTURE_RECTANGLE, GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE};
extern int g_current_texture_bind[11];
extern uint g_current_texture_bind[11];
struct SamplerParam {
int unit;
GLuint texid;
@ -463,6 +467,8 @@ struct FRAGMENTSHADER
for (uint i = 0; i < 7 ; i++)
samplers[i].release_texture();
}
void set_context(uint new_context) { context = new_context * NOCONTEXT;}
};
#endif
@ -555,6 +561,8 @@ struct COMMONSHADER
for (int i = 0; i < 4; i++)
samplers[i].enable_texture();
}
void set_context(uint new_context) { context = new_context * NOCONTEXT;}
};
#endif
@ -607,6 +615,7 @@ struct VERTEXSHADER
bool IsDualContext(ZZshParameter param) { return false;}
void set_context(uint new_context) { context = new_context * NOCONTEXT;}
};
#endif

View File

@ -129,12 +129,13 @@ GSVertexBufferStateOGL *vertex_array;
COMMONSHADER g_cs;
static GLuint s_pipeline = 0;
int g_current_texture_bind[11] = {0};
GLenum g_current_vs = NULL;
GLenum g_current_ps = NULL;
uint g_current_texture_bind[11] = {0};
GLenum g_current_vs = 0;
GLenum g_current_ps = 0;
//FRAGMENTSHADER ppsDebug;
//FRAGMENTSHADER ppsDebug2;
FRAGMENTSHADER ppsDebug;
FRAGMENTSHADER ppsDebug2;
FRAGMENTSHADER ppsDebug3;
//------------------ Code
@ -421,6 +422,13 @@ void init_shader() {
glGenProgramPipelines(1, &s_pipeline);
glBindProgramPipeline(s_pipeline);
// FIXME
// In the future it would be better to use directly the common shader
g_vparamPosXY[0] = g_cs.g_vparamPosXY;
g_vparamPosXY[1] = g_cs.g_vparamPosXY;
g_fparamFogColor = g_cs.g_fparamFogColor;
}
void PutParametersInProgram(VERTEXSHADER* vs, FRAGMENTSHADER* ps) {
@ -472,14 +480,14 @@ std::string BuildGlslMacro(bool writedepth, int texwrap = 3, bool testaem = fals
static __forceinline bool LOAD_VS(const std::string& DefineString, const char* name, VERTEXSHADER& vertex, ZZshProfile context)
{
bool flag = CompileShaderFromFile(vertex.program, DefineString, name, GL_VERTEX_SHADER);
vertex.context = context * NOCONTEXT;
vertex.set_context(context);
return flag;
}
static __forceinline bool LOAD_PS(const std::string& DefineString, const char* name, FRAGMENTSHADER& fragment, ZZshProfile context)
{
bool flag = CompileShaderFromFile(fragment.program, DefineString, name, GL_FRAGMENT_SHADER);
fragment.context = context * NOCONTEXT;
fragment.set_context(context);
return flag;
}
@ -498,6 +506,11 @@ bool ZZshLoadExtraEffects() {
std::string depth_macro = BuildGlslMacro(true);
std::string empty_macro = BuildGlslMacro(false);
// DEBUG
// Put them first so it is easier to get their program index in apitrace. Namely 3,4,5
if (!LOAD_PS(empty_macro, "ZeroDebugPS", ppsDebug, 0)) bLoadSuccess = false;
if (!LOAD_PS(empty_macro, "ZeroDebug2PS", ppsDebug2, 0)) bLoadSuccess = false;
//if (!LOAD_PS(empty_macro, "ZeroDebug3PS", ppsDebug3, 0)) bLoadSuccess = false;
const char* pvsshaders[4] = { "RegularVS", "TextureVS", "RegularFogVS", "TextureFogVS" };
@ -557,10 +570,6 @@ bool ZZshLoadExtraEffects() {
if (!LOAD_PS(empty_macro, "Convert16to32PS", ppsConvert16to32, 0)) bLoadSuccess = false;
if (!LOAD_PS(empty_macro, "Convert32to16PS", ppsConvert32to16, 0)) bLoadSuccess = false;
// DEBUG
// if (!LOAD_PS(empty_macro, "ZeroDebugPS", ppsDebug, 0)) bLoadSuccess = false;
// if (!LOAD_PS(empty_macro, "ZeroDebug2PS", ppsDebug2, 0)) bLoadSuccess = false;
GL_REPORT_ERRORD();
return true;
}
@ -598,7 +607,7 @@ FRAGMENTSHADER* ZZshLoadShadeEffect(int type, int texfilter, int fog, int testae
std::string macro = BuildGlslMacro(s_bWriteDepth, texwrap, testaem, exactcolor);
std::string main_entry = format("Texture%s%d_%sPS", fog?"Fog":"", texfilter, g_pTexTypes[type]);
pf->context = context * NOCONTEXT;
pf->set_context(context);
if (!CompileShaderFromFile(pf->program, macro, main_entry, GL_FRAGMENT_SHADER)) {
ZZLog::Error_Log("Failed to create shader %d,%d,%d,%d.", type, fog, texfilter, 4*clamp.wms+clamp.wmt);
if( pbFailed != NULL ) *pbFailed = false;

View File

@ -24,37 +24,22 @@
#extension ARB_texture_rectangle: require
#extension GL_ARB_shading_language_420pack: require
#extension GL_ARB_separate_shader_objects : require
// Set with version macro
// #define GL_compatibility_profile 1
#define PERSPECTIVE_CORRECT_TEX
// When writting GLSL code we should change variables in code according to denominator
// Not than in and out variables are differ!
// in POSITION set by glVertexPointer goes to gl_Vertex;
// out POSITION goes to gl_position
// in COLOR0 gl_Color
// out COLOR0 gl_FrontColor
// in TEXCOORD0 gl_MultiTexCoord0
// out TEXCOORD0 gl_TexCoord[0]
//in Fragments:
// in TEXCOORD0 gl_TexCoord[0]
// out COLOR0 gl_FragData[0]
//#define TEST_AEM // tests AEM for black pixels
//#define REGION_REPEAT // set if texture wrapping mode is region repeat
//#define WRITE_DEPTH // set if depth is also written in a MRT
//#define ACCURATE_DECOMPRESSION // set for less capable hardware ATI Radeon 9000 series
//#define EXACT_COLOR // make sure the output color is clamped to 1/255 boundaries (for alpha testing)
#define PERSPECTIVE_CORRECT_TEX
#ifdef PERSPECTIVE_CORRECT_TEX
#define TEX_XY tex.xy/tex.z
#define TEX_DECL vec4
#define TEX_DECL vec3
#else
#define TEX_XY tex.xy
#define TEX_DECL vec4
#define TEX_DECL vec2
#endif
// NVidia CG-data types
@ -77,25 +62,6 @@ struct vertex
float fog;
};
// VS input (from VBO)
//
// glColorPointer -> gl_Color (color)
// glSecondaryColorPointerEXT -> gl_SecondaryColor (it seems just a way to have another parameter in shader)
// glTexCoordPointer -> gl_MultiTexCoord0 (tex coord)
// glVertexPointer -> gl_Vertex (position)
//
// VS Output (to PS)
// gl_Position (must be kept)
// vertex
//
// FS input (from VS)
// vertex
//
// FS output
// gl_FragData[0]
// gl_FragData[1]
#ifdef VERTEX_SHADER
out gl_PerVertex {
invariant vec4 gl_Position;
@ -110,10 +76,6 @@ layout(location = 3) in vec3 TexCoord;
layout(location = 0) out vertex VSout;
/////// return ZZ_SH_CRTC;
// otex0 -> tex
// ointerpos -> z
#endif
#ifdef FRAGMENT_SHADER
@ -797,12 +759,16 @@ void ZeroPS() {
}
void ZeroDebugPS() {
FragData0 = vec4(0.0, 1.0, 0.0, 0.5);
//FragData0 = vec4(PSin.position.x, PSin.position.y, 1.0, 0.5);
FragData0 = vec4(PSin.tex.x, PSin.tex.y, PSin.tex.z, 0.5);
}
void ZeroDebug2PS() {
FragData0 = vec4(1.0, 0.0, 0.0, 0.5);
vec2 xy = ps2memcoord(fract(PSin.tex.xy/PSin.tex.z)).xy * vec2(1/4096.0f, 1/48.0f);
FragData0 = vec4(xy.x, xy.y, 0.0, 0.5);
}
void ZeroDebug3PS() {
//FragData0 = vec4(PSin.position.x/2.0f + 0.5f, PSin.position.y/2.0f + 0.5f, 1.0, 0.5);
}
void BaseTexturePS() {
@ -858,7 +824,7 @@ void SetColor() {
void SetTex() {
#ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = TexCoord.xyz;
VSout.tex = TexCoord;
#else
VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif