zzogl: rework dump test, to avoid bad mix between u32/u8

glsl4: Replace some define with function (ogl4 support function pointer). Explain how depth is computed in vertex shader


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5233 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut 2012-05-27 08:13:27 +00:00
parent c6d8af0c7f
commit f8875f12dc
11 changed files with 122 additions and 113 deletions

View File

@ -124,7 +124,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "")
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# Set some default compiler flags # Set some default compiler flags
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing") set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing -Wno-unused-function")
set(DEFAULT_GCC_FLAG "-m32 -msse -msse2 -march=i686 -pthread ${DEFAULT_WARNINGS}") set(DEFAULT_GCC_FLAG "-m32 -msse -msse2 -march=i686 -pthread ${DEFAULT_WARNINGS}")
set(DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof") set(DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof")

View File

@ -168,6 +168,7 @@ bool GSDeviceOGL::Create(GSWnd* wnd)
const GLubyte* s; const GLubyte* s;
s = glGetString(GL_VERSION); s = glGetString(GL_VERSION);
if (s == NULL) return false; if (s == NULL) return false;
fprintf(stderr, "Supported Opengl version: %s\n", s);
GLuint dot = 0; GLuint dot = 0;
while (s[dot] != '\0' && s[dot] != '.') dot++; while (s[dot] != '\0' && s[dot] != '.') dot++;

View File

@ -58,13 +58,14 @@ void GSDump::Close()
} }
} }
void GSDump::Transfer(int index, const u8* mem, size_t size) void GSDump::Transfer(int index, const u32* mem, size_t size, u32 real_size)
{ {
if(m_gs && size > 0) if(m_gs && size > 0)
{ {
fputc(0, m_gs); fputc(0, m_gs);
fputc(index, m_gs); fputc(index, m_gs);
fwrite(&size, 4, 1, m_gs); fwrite(&size, 4, 1, m_gs);
fwrite(&real_size, 4, 1, m_gs);
fwrite(mem, size, 1, m_gs); fwrite(mem, size, 1, m_gs);
} }
} }

View File

@ -56,7 +56,7 @@ public:
void Open(const string& fn, u32 crc, const freezeData& fd, u8* regs); void Open(const string& fn, u32 crc, const freezeData& fd, u8* regs);
void Close(); void Close();
void ReadFIFO(u32 size); void ReadFIFO(u32 size);
void Transfer(int index, const u8* mem, size_t size); void Transfer(int index, const u32* mem, size_t size, u32 real_size);
void VSync(int field, bool last, u8* regs); void VSync(int field, bool last, u8* regs);
operator bool() {return m_gs != NULL;} operator bool() {return m_gs != NULL;}
}; };

View File

@ -399,7 +399,7 @@ static bool get_snapshot_filename(char *filename, char* path, const char* extens
{ {
snapshotnr++; snapshotnr++;
sprintf(filename, "%s/snap%03ld.%s", path, snapshotnr, extension); sprintf(filename, "%s/snap%03d.%s", path, snapshotnr, extension);
bmpfile = fopen(filename, "rb"); bmpfile = fopen(filename, "rb");
@ -627,6 +627,7 @@ struct Packet
{ {
u8 type, param; u8 type, param;
u32 size, addr; u32 size, addr;
u32 real_size;
vector<u32> buff; vector<u32> buff;
}; };
@ -680,18 +681,20 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
p->param = (u8)fgetc(fp); p->param = (u8)fgetc(fp);
fread(&p->size, 4, 1, fp); fread(&p->size, 4, 1, fp);
fread(&p->real_size, 4, 1, fp);
switch(p->param) switch(p->param)
{ {
case 0: case 0:
p->buff.resize(0x4000); p->buff.resize(0x4000/4);
p->addr = 0x4000 - p->size; //p->addr = 0x4000 - p->size;
fread(&p->buff[p->addr], p->size, 1, fp); //fread(&p->buff[p->addr], p->size, 1, fp);
fread(&p->buff[0], p->size, 1, fp);
break; break;
case 1: case 1:
case 2: case 2:
case 3: case 3:
p->buff.resize(p->size); p->buff.resize(p->size/4);
fread(&p->buff[0], p->size, 1, fp); fread(&p->buff[0], p->size, 1, fp);
break; break;
} }
@ -712,7 +715,7 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
case 3: case 3:
p->buff.resize(0x2000); p->buff.resize(0x2000/4);
fread(&p->buff[0], 0x2000, 1, fp); fread(&p->buff[0], 0x2000, 1, fp);
@ -741,12 +744,14 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
{ {
case 0: case 0:
//fprintf(stderr, "TRANSFER %d size %d\n", p->param, p->real_size);
switch(p->param) switch(p->param)
{ {
case 0: GSgifTransfer1(&p->buff[0], p->addr); break; //case 0: GSgifTransfer1((u32*)&p->buff[0], p->addr); break;
case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break; case 0: _GSgifTransfer<0>(&p->buff[0], p->real_size); break;
case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break; case 1: GSgifTransfer2((u32*)&p->buff[0], p->real_size); break;
case 3: GSgifTransfer(&p->buff[0], p->size / 16); break; case 2: GSgifTransfer3((u32*)&p->buff[0], p->real_size); break;
case 3: GSgifTransfer((u32*)&p->buff[0], p->real_size); break;
} }
break; break;
@ -775,8 +780,8 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
} }
} }
unsigned long end = timeGetTime(); unsigned long end = timeGetTime();
fprintf(stderr, "The %d frames of the scene was render on %dms\n", frame_number, end - start); fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start);
fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number); fprintf(stderr, "A means of %fms by frame (limit 16ms/f)\n", (float)(end - start)/(float)frame_number);
sleep(1); sleep(1);
finished--; finished--;

View File

@ -76,6 +76,8 @@ template<int index> void _GSgifTransfer(const u32 *pMem, u32 size)
#ifdef _DEBUG #ifdef _DEBUG
gifTransferLog(index, pMem, size); gifTransferLog(index, pMem, size);
const u32* start = pMem;
u32 size_arg = size;
g_dump.Transfer(index, (const u8*)pMem, size); g_dump.Transfer(index, (const u8*)pMem, size);
#endif #endif
@ -218,6 +220,10 @@ template<int index> void _GSgifTransfer(const u32 *pMem, u32 size)
} }
} }
#ifdef _DEBUG
g_dump.Transfer(index, start, pMem - start, size_arg);
#endif
// This is the case when not all data was readed from one try: VU1 has too much data. // This is the case when not all data was readed from one try: VU1 has too much data.
// So we should redo reading from the start. // So we should redo reading from the start.
if (index == 0) if (index == 0)

View File

@ -58,13 +58,14 @@ void GSDump::Close()
} }
} }
void GSDump::Transfer(int index, const u8* mem, size_t size) void GSDump::Transfer(int index, const u32* mem, size_t size, u32 real_size)
{ {
if(m_gs && size > 0) if(m_gs && size > 0)
{ {
fputc(0, m_gs); fputc(0, m_gs);
fputc(index, m_gs); fputc(index, m_gs);
fwrite(&size, 4, 1, m_gs); fwrite(&size, 4, 1, m_gs);
fwrite(&real_size, 4, 1, m_gs);
fwrite(mem, size, 1, m_gs); fwrite(mem, size, 1, m_gs);
} }
} }

View File

@ -56,7 +56,7 @@ public:
void Open(const string& fn, u32 crc, const freezeData& fd, u8* regs); void Open(const string& fn, u32 crc, const freezeData& fd, u8* regs);
void Close(); void Close();
void ReadFIFO(u32 size); void ReadFIFO(u32 size);
void Transfer(int index, const u8* mem, size_t size); void Transfer(int index, const u32* mem, size_t size, u32 real_size);
void VSync(int field, bool last, u8* regs); void VSync(int field, bool last, u8* regs);
operator bool() {return m_gs != NULL;} operator bool() {return m_gs != NULL;}
}; };

View File

@ -403,7 +403,7 @@ static bool get_snapshot_filename(char *filename, char* path, const char* extens
{ {
snapshotnr++; snapshotnr++;
sprintf(filename, "%s/snap%03ld.%s", path, snapshotnr, extension); sprintf(filename, "%s/snap%03d.%s", path, snapshotnr, extension);
bmpfile = fopen(filename, "rb"); bmpfile = fopen(filename, "rb");
@ -641,6 +641,7 @@ struct Packet
{ {
u8 type, param; u8 type, param;
u32 size, addr; u32 size, addr;
u32 real_size;
vector<u32> buff; vector<u32> buff;
}; };
@ -694,18 +695,20 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
p->param = (u8)fgetc(fp); p->param = (u8)fgetc(fp);
fread(&p->size, 4, 1, fp); fread(&p->size, 4, 1, fp);
fread(&p->real_size, 4, 1, fp);
switch(p->param) switch(p->param)
{ {
case 0: case 0:
p->buff.resize(0x4000); p->buff.resize(0x4000/4);
p->addr = 0x4000 - p->size; //p->addr = 0x4000 - p->size;
fread(&p->buff[p->addr], p->size, 1, fp); //fread(&p->buff[p->addr], p->size, 1, fp);
fread(&p->buff[0], p->size, 1, fp);
break; break;
case 1: case 1:
case 2: case 2:
case 3: case 3:
p->buff.resize(p->size); p->buff.resize(p->size/4);
fread(&p->buff[0], p->size, 1, fp); fread(&p->buff[0], p->size, 1, fp);
break; break;
} }
@ -726,7 +729,7 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
case 3: case 3:
p->buff.resize(0x2000); p->buff.resize(0x2000/4);
fread(&p->buff[0], 0x2000, 1, fp); fread(&p->buff[0], 0x2000, 1, fp);
@ -755,12 +758,14 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
{ {
case 0: case 0:
//fprintf(stderr, "TRANSFER %d size %d\n", p->param, p->real_size);
switch(p->param) switch(p->param)
{ {
case 0: GSgifTransfer1(&p->buff[0], p->addr); break; //case 0: GSgifTransfer1((u32*)&p->buff[0], p->addr); break;
case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break; case 0: _GSgifTransfer<0>(&p->buff[0], p->real_size); break;
case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break; case 1: GSgifTransfer2((u32*)&p->buff[0], p->real_size); break;
case 3: GSgifTransfer(&p->buff[0], p->size / 16); break; case 2: GSgifTransfer3((u32*)&p->buff[0], p->real_size); break;
case 3: GSgifTransfer((u32*)&p->buff[0], p->real_size); break;
} }
break; break;
@ -789,8 +794,8 @@ EXPORT_C_(void) GSReplay(char* lpszCmdLine)
} }
} }
unsigned long end = timeGetTime(); unsigned long end = timeGetTime();
fprintf(stderr, "The %d frames of the scene was render on %dms\n", frame_number, end - start); fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start);
fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number); fprintf(stderr, "A means of %fms by frame (limit 16ms/f)\n", (float)(end - start)/(float)frame_number);
sleep(1); sleep(1);
finished--; finished--;

View File

@ -76,6 +76,8 @@ template<int index> void _GSgifTransfer(const u32 *pMem, u32 size)
#ifdef _DEBUG #ifdef _DEBUG
gifTransferLog(index, pMem, size); gifTransferLog(index, pMem, size);
const u32* start = pMem;
u32 size_arg = size;
g_dump.Transfer(index, (const u8*)pMem, size); g_dump.Transfer(index, (const u8*)pMem, size);
#endif #endif
@ -222,6 +224,10 @@ template<int index> void _GSgifTransfer(const u32 *pMem, u32 size)
} }
} }
#ifdef _DEBUG
g_dump.Transfer(index, start, pMem - start, size_arg);
#endif
// This is the case when not all data was readed from one try: VU1 has too much data. // This is the case when not all data was readed from one try: VU1 has too much data.
// So we should redo reading from the start. // So we should redo reading from the start.
if (index == 0) if (index == 0)

View File

@ -57,12 +57,6 @@
#define TEX_DECL vec4 #define TEX_DECL vec4
#endif #endif
#ifdef WRITE_DEPTH
#define DOZWRITE(x) x
#else
#define DOZWRITE(x)
#endif
// NVidia CG-data types // NVidia CG-data types
#define half2 vec2 #define half2 vec2
#define half3 vec3 #define half3 vec3
@ -602,38 +596,34 @@ half4 ps2FinalColor(half4 col)
half4 ps2FinalColor(half4 col) half4 ps2FinalColor(half4 col)
{ {
return col * g_fOneColor.xxxy + g_fOneColor.zzzw; return col * g_fOneColor.xxxy + g_fOneColor.zzzw;
//return vec4(1.0f,0.0f,1.0f, 0.8f);
} }
#endif #endif
#ifdef FRAGMENT_SHADER // This is code only for FRAGMENTS (pixel shader) #ifdef FRAGMENT_SHADER // This is code only for FRAGMENTS (pixel shader)
#ifdef WRITE_DEPTH
void write_depth_target(vec4 z)
{
FragData1 = z;
}
#else
void write_depth_target(vec4 z) { }
#endif
void RegularPS() { void RegularPS() {
// whenever outputting depth, make sure to mult by 255/256 and 1 // whenever outputting depth, make sure to mult by 255/256 and 1
FragData0 = ps2FinalColor(PSin.color); FragData0 = ps2FinalColor(PSin.color);
DOZWRITE(FragData1 = PSin.z;) write_depth_target(PSin.z);
} }
#ifdef WRITE_DEPTH
#define DECL_TEXPS(num, bit) \ #define DECL_TEXPS(num, bit) \
void Texture##num##bit##PS() \ void Texture##num##bit##PS() \
{ \ { \
FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \ FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
FragData1 = PSin.z; \ write_depth_target(PSin.z); \
} }
#else
#define DECL_TEXPS(num, bit) \
void Texture##num##bit##PS() \
{ \
FragData0 = ps2FinalColor(ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color)); \
}
#endif
#define DECL_TEXPS_(num) \ #define DECL_TEXPS_(num) \
DECL_TEXPS(num, _32) \ DECL_TEXPS(num, _32) \
DECL_TEXPS(num, _tex32) \ DECL_TEXPS(num, _tex32) \
@ -653,32 +643,18 @@ void RegularFogPS() {
c.xyz = mix(g_fFogColor.xyz, PSin.color.xyz, vec3(PSin.fog)); c.xyz = mix(g_fFogColor.xyz, PSin.color.xyz, vec3(PSin.fog));
c.w = PSin.color.w; c.w = PSin.color.w;
FragData0 = ps2FinalColor(c); FragData0 = ps2FinalColor(c);
DOZWRITE(FragData1 = PSin.z;) write_depth_target(PSin.z);
} }
#ifdef WRITE_DEPTH
#define DECL_TEXFOGPS(num, bit) \ #define DECL_TEXFOGPS(num, bit) \
void TextureFog##num##bit##PS() \ void TextureFog##num##bit##PS() \
{ \ { \
half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \ half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \
c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \ c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \
FragData0 = ps2FinalColor(c); \ FragData0 = ps2FinalColor(c); \
FragData1 = PSin.z; \ write_depth_target(PSin.z); \
} }
#else
#define DECL_TEXFOGPS(num, bit) \
void TextureFog##num##bit##PS() \
{ \
half4 c = ps2CalcShade(ps2shade##num##bit(PSin.tex), PSin.color); \
c.xyz = mix(g_fFogColor.xyz, c.xyz, vec3(PSin.fog)); \
FragData0 = ps2FinalColor(c); \
}
#endif
#define DECL_TEXFOGPS_(num) \ #define DECL_TEXFOGPS_(num) \
DECL_TEXFOGPS(num, _32) \ DECL_TEXFOGPS(num, _32) \
DECL_TEXFOGPS(num, _tex32) \ DECL_TEXFOGPS(num, _tex32) \
@ -876,70 +852,78 @@ void Convert32to16PS() {
#ifdef VERTEX_SHADER #ifdef VERTEX_SHADER
float4 OutPosition() { void SetColor() {
VSout.color = Color;
}
void SetTex() {
#ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = TexCoord.xyz;
#else
VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif
}
void SetZ() {
#ifdef WRITE_DEPTH
VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;
VSout.z.w = g_fc0.y;
#endif
}
float SetPosition() {
float4 position; float4 position;
position.xy = vec2(Vert.xy) * g_fPosXY.xy + g_fPosXY.zw; position.xy = vec2(Vert.xy) * g_fPosXY.xy + g_fPosXY.zw;
// FIXME: the factor in normal mode seem bogus. They don't have same order than in log mode. Or I failed to understand the logic
//// normal mode.
// -> dot(g_fZ, SecondaryColor.zyxw)) => reconstruct a float from normalized char. The float range from 0 to 1
// position.z = dot(g_fZ, SecondaryColor.zyxw);
//// logz mode
// -> dot(g_fZ, SecondaryColor.zyxw)) => reconstruct a float from normalized char. The float range from 0 to 2**32
// position.z = log(g_fc0.y + dot(g_fZ, SecondaryColor.zyxw)) * g_fZNorm.x
// position.z = log(1 + Z_INT) * 0.999f / (32 * log(2.0)) = log2(1 + Z_INT) * 0.999f / 32
// log2(...) will range from 0 to 32
position.z = (log(g_fc0.y + dot(g_fZ, SecondaryColor.zyxw)) * g_fZNorm.x + g_fZNorm.y) * g_fZMin.y + dot(g_fZ, SecondaryColor.zyxw) * g_fZMin.x ; position.z = (log(g_fc0.y + dot(g_fZ, SecondaryColor.zyxw)) * g_fZNorm.x + g_fZNorm.y) * g_fZMin.y + dot(g_fZ, SecondaryColor.zyxw) * g_fZMin.x ;
position.w = g_fc0.y; position.w = g_fc0.y;
return position;
gl_Position = position;
// For fog
return position.z;
}
void SetFog(float z) {
VSout.fog = z * g_fBilinear.w;
} }
// just smooth shadering // just smooth shadering
void RegularVS() { void RegularVS() {
float4 position = OutPosition(); float z = SetPosition();
gl_Position = position; SetColor();
SetZ();
VSout.color = Color;
DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;)
} }
// diffuse texture mapping // diffuse texture mapping
void TextureVS() { void TextureVS() {
float4 position = OutPosition(); float z = SetPosition();
gl_Position = position; SetColor();
SetTex();
VSout.color = Color; SetZ();
#ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = TexCoord.xyz;
#else
VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif
DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void RegularFogVS() { void RegularFogVS() {
float4 position = OutPosition(); float z = SetPosition();
gl_Position = position; SetColor();
SetZ();
VSout.color = Color; SetFog(z);
VSout.fog = position.z * g_fBilinear.w;
DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void TextureFogVS() { void TextureFogVS() {
float4 position = OutPosition(); float z = SetPosition();
gl_Position = position; SetColor();
SetTex();
VSout.color = Color; SetZ();
SetFog(z);
#ifdef PERSPECTIVE_CORRECT_TEX
VSout.tex.xyz = TexCoord.xyz;
#else
VSout.tex.xy = TexCoord.xy/TexCoord.z;
#endif
VSout.fog = position.z * g_fBilinear.w;
DOZWRITE(VSout.z = SecondaryColor * g_fZBias.x + g_fZBias.y;)
DOZWRITE(VSout.z.w = g_fc0.y;)
} }
void BitBltVS() { void BitBltVS() {