gsdx-ogl: depth support: better support of 16 bits z buffer

Fix issue in socom2
This commit is contained in:
Gregory Hainaut 2015-07-31 23:23:17 +02:00
parent eb0fa8c7dc
commit 4a3c145c72
5 changed files with 37 additions and 10 deletions

View File

@ -940,7 +940,7 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture
return; return;
} }
bool draw_in_depth = (ps == m_convert.ps[12] || ps == m_convert.ps[13]); bool draw_in_depth = (ps == m_convert.ps[12] || ps == m_convert.ps[13] || ps == m_convert.ps[14]);
// Performance optimization. It might be faster to use a framebuffer blit for standard case // Performance optimization. It might be faster to use a framebuffer blit for standard case
// instead to emulate it with shader // instead to emulate it with shader

View File

@ -500,7 +500,7 @@ class GSDeviceOGL : public GSDevice
struct { struct {
GLuint vs; // program object GLuint vs; // program object
GLuint ps[15]; // program object GLuint ps[16]; // program object
GLuint ln; // sampler object GLuint ln; // sampler object
GLuint pt; // sampler object GLuint pt; // sampler object
GSDepthStencilOGL* dss; GSDepthStencilOGL* dss;

View File

@ -283,7 +283,8 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int
if (type == DepthStencil) { if (type == DepthStencil) {
GL_CACHE("TC: Lookup Target(Depth) %dx%d, hit Color (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); GL_CACHE("TC: Lookup Target(Depth) %dx%d, hit Color (0x%x, F:0x%x)", w, h, bp, TEX0.PSM);
int shader = (TEX0.PSM & 1) ? 13 : 12; int shader = 12 + GSLocalMemory::m_psm[TEX0.PSM].fmt;
ASSERT(shader <= 14);
m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, shader, false); m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, shader, false);
} else { } else {
GL_CACHE("TC: Lookup Target(Color) %dx%d, hit Depth (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); GL_CACHE("TC: Lookup Target(Color) %dx%d, hit Depth (0x%x, F:0x%x)", w, h, bp, TEX0.PSM);
@ -861,7 +862,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
if (is_8bits) { if (is_8bits) {
GL_INS("Reading RT as a packed-indexed 8 bits format"); GL_INS("Reading RT as a packed-indexed 8 bits format");
shader = 14; // ask a conversion to 8 bits format shader = 15; // ask a conversion to 8 bits format
} }
#ifdef ENABLE_OGL_DEBUG #ifdef ENABLE_OGL_DEBUG

View File

@ -194,17 +194,30 @@ void ps_main12()
//out float gl_FragDepth; //out float gl_FragDepth;
void ps_main13() void ps_main13()
{ {
// Same as above but without the alpha channel // Same as above but without the alpha channel (24 bits Z)
// Convert a RRGBA texture into a float depth texture // Convert a RRGBA texture into a float depth texture
// FIXME: I'm afraid of the accuracy // FIXME: I'm afraid of the accuracy
const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 0.0) * vec4(255.0/256.0); const vec3 bitSh = vec3(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0) * vec3(255.0/256.0);
gl_FragDepth = dot(sample_c(), bitSh); gl_FragDepth = dot(sample_c().rgb, bitSh);
} }
#endif #endif
#ifdef ps_main14 #ifdef ps_main14
//out float gl_FragDepth;
void ps_main14() void ps_main14()
{
// Same as above but without the A/B channels (16 bits Z)
// Convert a RRGBA texture into a float depth texture
// FIXME: I'm afraid of the accuracy
const vec2 bitSh = vec2(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0)) * vec2(255.0/256.0);
gl_FragDepth = dot(sample_c().rg, bitSh);
}
#endif
#ifdef ps_main15
void ps_main15()
{ {
// Potential speed optimization. There is a high probability that // Potential speed optimization. There is a high probability that

View File

@ -219,18 +219,31 @@ static const char* convert_glsl =
"//out float gl_FragDepth;\n" "//out float gl_FragDepth;\n"
"void ps_main13()\n" "void ps_main13()\n"
"{\n" "{\n"
" // Same as above but without the alpha channel\n" " // Same as above but without the alpha channel (24 bits Z)\n"
"\n" "\n"
" // Convert a RRGBA texture into a float depth texture\n" " // Convert a RRGBA texture into a float depth texture\n"
" // FIXME: I'm afraid of the accuracy\n" " // FIXME: I'm afraid of the accuracy\n"
" const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 0.0) * vec4(255.0/256.0);\n" " const vec3 bitSh = vec3(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0) * vec3(255.0/256.0);\n"
" gl_FragDepth = dot(sample_c(), bitSh);\n" " gl_FragDepth = dot(sample_c().rgb, bitSh);\n"
"}\n" "}\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#ifdef ps_main14\n" "#ifdef ps_main14\n"
"//out float gl_FragDepth;\n"
"void ps_main14()\n" "void ps_main14()\n"
"{\n" "{\n"
" // Same as above but without the A/B channels (16 bits Z)\n"
"\n"
" // Convert a RRGBA texture into a float depth texture\n"
" // FIXME: I'm afraid of the accuracy\n"
" const vec2 bitSh = vec2(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0)) * vec2(255.0/256.0);\n"
" gl_FragDepth = dot(sample_c().rg, bitSh);\n"
"}\n"
"#endif\n"
"\n"
"#ifdef ps_main15\n"
"void ps_main15()\n"
"{\n"
"\n" "\n"
" // Potential speed optimization. There is a high probability that\n" " // Potential speed optimization. There is a high probability that\n"
" // game only want to extract a single channel (blue). It will allow\n" " // game only want to extract a single channel (blue). It will allow\n"