Merge pull request #782 from PCSX2/gsdx-texture-format-v2split

Improve GSdx texturing
This commit is contained in:
Gregory Hainaut 2015-08-21 00:42:56 +02:00
commit d2e4dac9ab
4 changed files with 73 additions and 61 deletions

View File

@ -826,6 +826,7 @@ void GSDeviceOGL::SelfShaderTest()
sel.atst = 1;
sel.tfx = 1;
sel.tcc = 1;
sel.fst = 1;
sel.ltf = ltf;
sel.aem = aem;

View File

@ -760,7 +760,13 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
{
ps_sel.fog = 1;
ps_cb.FogColor_AREF = GSVector4::rgba32(m_env.FOGCOL.u32[0]);
GSVector4 fc = GSVector4::rgba32(m_env.FOGCOL.u32[0]);
#if _M_SSE >= 0x401
// Blend AREF to avoid to load a random value for alpha (dirty cache)
ps_cb.FogColor_AREF = fc.blend32<8>(ps_cb.FogColor_AREF);
#else
ps_cb.FogColor_AREF = fc;
#endif
}
if (m_context->TEST.ATE)
@ -781,7 +787,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM];
const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[m_context->TEX0.CPSM] : psm;
bool bilinear = m_filter == 2 ? m_vt.IsLinear() : m_filter != 0;
bool simple_sample = !tex->m_palette && cpsm.fmt == 0 && m_context->CLAMP.WMS < 3 && m_context->CLAMP.WMT < 3;
bool simple_sample = !tex->m_palette && cpsm.fmt == 0 && m_context->CLAMP.WMS < 2 && m_context->CLAMP.WMT < 2;
// Don't force extra filtering on sprite (it creates various upscaling issue)
bilinear &= !((m_vt.m_primclass == GS_SPRITE_CLASS) && m_userhacks_round_sprite_offset && !m_vt.IsLinear());
@ -831,13 +837,17 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
if (PRIM->FST)
{
// FIXME move it in the ps_cb
vs_cb.TextureScale = GSVector4(1.0f / 16) / WH.xyxy();
ps_sel.fst = 1;
}
ps_cb.WH = WH;
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
ps_cb.MskFix = GSVector4i(m_context->CLAMP.MINU, m_context->CLAMP.MINV, m_context->CLAMP.MAXU, m_context->CLAMP.MAXV);
if ((m_context->CLAMP.WMS | m_context->CLAMP.WMT) > 1) {
ps_cb.MskFix = GSVector4i(m_context->CLAMP.MINU, m_context->CLAMP.MINV, m_context->CLAMP.MAXU, m_context->CLAMP.MAXV);
ps_cb.MinMax = GSVector4(ps_cb.MskFix) / WH.xyxy();
}
// TC Offset Hack
ps_sel.tcoffsethack = !!UserHacks_TCOffset;
@ -849,8 +859,9 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
ps_cb.MinMax = clamp / WH.xyxy();
ps_cb.MinF_TA = (clamp + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
ps_ssel.tau = (m_context->CLAMP.WMS + 3) >> 1;
ps_ssel.tav = (m_context->CLAMP.WMT + 3) >> 1;
// Only enable clamping in CLAMP mode. REGION_CLAMP will be done manually in the shader
ps_ssel.tau = (m_context->CLAMP.WMS != CLAMP_CLAMP);
ps_ssel.tav = (m_context->CLAMP.WMT != CLAMP_CLAMP);
ps_ssel.ltf = bilinear && simple_sample;
// Setup Texture ressources

View File

@ -63,16 +63,25 @@ layout(std140, binding = 21) uniform cb21
{
vec3 FogColor;
float AREF;
vec4 WH;
vec2 MinF;
vec2 TA;
uvec4 MskFix;
uvec4 FbMask;
vec3 _not_yet_used;
vec3 _pad1;
float Af;
vec4 HalfTexel;
vec4 MinMax;
vec2 TC_OffsetHack;
vec2 _pad2;
};
vec4 sample_c(vec2 uv)
@ -80,12 +89,12 @@ vec4 sample_c(vec2 uv)
return texture(TextureSampler, uv);
}
vec4 sample_p(uint idx)
vec4 sample_p(float idx)
{
return texelFetch(PaletteSampler, ivec2(idx, 0u), 0);
return texture(PaletteSampler, vec2(idx, 0.0f));
}
vec4 wrapuv(vec4 uv)
vec4 clamp_wrap_uv(vec4 uv)
{
vec4 uv_out = uv;
@ -120,21 +129,6 @@ vec4 wrapuv(vec4 uv)
return uv_out;
}
vec2 clampuv(vec2 uv)
{
vec2 uv_out = uv;
#if (PS_WMS == 2) && (PS_WMT == 2)
uv_out = clamp(uv, MinF, MinMax.zw);
#elif PS_WMS == 2
uv_out.x = clamp(uv.x, MinF.x, MinMax.z);
#elif PS_WMT == 2
uv_out.y = clamp(uv.y, MinF.y, MinMax.w);
#endif
return uv_out;
}
mat4 sample_4c(vec4 uv)
{
mat4 c;
@ -149,7 +143,7 @@ mat4 sample_4c(vec4 uv)
return c;
}
uvec4 sample_4_index(vec4 uv)
vec4 sample_4_index(vec4 uv)
{
vec4 c;
@ -169,18 +163,22 @@ uvec4 sample_4_index(vec4 uv)
#if PS_IFMT == 1
// 4HH
return i >> 4u;
return vec4(i >> 4u) / 255.0f;
#elif PS_IFMT == 2
// 4HL
return i & 0xFu;
return vec4(i & 0xFu) / 255.0f;
#else
// Most of texture will hit this code so keep normalized float value
// 8 bits
return i;
return c;
#endif
}
mat4 sample_4p(uvec4 u)
mat4 sample_4p(vec4 u)
{
mat4 c;
@ -207,10 +205,12 @@ vec4 sample_color(vec2 st, float q)
mat4 c;
vec2 dd;
#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)
c[0] = sample_c(clampuv(st));
// FIXME I'm not sure this condition is useful (I think code will be optimized)
#if (PS_LTF == 0 && PS_FMT == FMT_32 && PS_WMS < 2 && PS_WMT < 2)
// No software LTF and pure 32 bits RGBA texure without special texture wrapping
c[0] = sample_c(st);
#ifdef TEX_COORD_DEBUG
c[0].rg = clampuv(st).xy;
c[0].rg = st.xy;
#endif
#else
@ -226,7 +226,7 @@ vec4 sample_color(vec2 st, float q)
uv = st.xyxy;
}
uv = wrapuv(uv);
uv = clamp_wrap_uv(uv);
if((PS_FMT & FMT_PAL) != 0)
{

View File

@ -922,16 +922,25 @@ static const char* tfx_fs_all_glsl =
"{\n"
" vec3 FogColor;\n"
" float AREF;\n"
"\n"
" vec4 WH;\n"
"\n"
" vec2 MinF;\n"
" vec2 TA;\n"
"\n"
" uvec4 MskFix;\n"
"\n"
" uvec4 FbMask;\n"
" vec3 _not_yet_used;\n"
"\n"
" vec3 _pad1;\n"
" float Af;\n"
"\n"
" vec4 HalfTexel;\n"
"\n"
" vec4 MinMax;\n"
"\n"
" vec2 TC_OffsetHack;\n"
" vec2 _pad2;\n"
"};\n"
"\n"
"vec4 sample_c(vec2 uv)\n"
@ -939,12 +948,12 @@ static const char* tfx_fs_all_glsl =
" return texture(TextureSampler, uv);\n"
"}\n"
"\n"
"vec4 sample_p(uint idx)\n"
"vec4 sample_p(float idx)\n"
"{\n"
" return texelFetch(PaletteSampler, ivec2(idx, 0u), 0);\n"
" return texture(PaletteSampler, vec2(idx, 0.0f));\n"
"}\n"
"\n"
"vec4 wrapuv(vec4 uv)\n"
"vec4 clamp_wrap_uv(vec4 uv)\n"
"{\n"
" vec4 uv_out = uv;\n"
"\n"
@ -979,21 +988,6 @@ static const char* tfx_fs_all_glsl =
" return uv_out;\n"
"}\n"
"\n"
"vec2 clampuv(vec2 uv)\n"
"{\n"
" vec2 uv_out = uv;\n"
"\n"
"#if (PS_WMS == 2) && (PS_WMT == 2)\n"
" uv_out = clamp(uv, MinF, MinMax.zw);\n"
"#elif PS_WMS == 2\n"
" uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n"
"#elif PS_WMT == 2\n"
" uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n"
"#endif\n"
"\n"
" return uv_out;\n"
"}\n"
"\n"
"mat4 sample_4c(vec4 uv)\n"
"{\n"
" mat4 c;\n"
@ -1008,7 +1002,7 @@ static const char* tfx_fs_all_glsl =
" return c;\n"
"}\n"
"\n"
"uvec4 sample_4_index(vec4 uv)\n"
"vec4 sample_4_index(vec4 uv)\n"
"{\n"
" vec4 c;\n"
"\n"
@ -1028,18 +1022,22 @@ static const char* tfx_fs_all_glsl =
"\n"
"#if PS_IFMT == 1\n"
" // 4HH\n"
" return i >> 4u;\n"
" return vec4(i >> 4u) / 255.0f;\n"
"\n"
"#elif PS_IFMT == 2\n"
" // 4HL\n"
" return i & 0xFu;\n"
" return vec4(i & 0xFu) / 255.0f;\n"
"\n"
"#else\n"
" // Most of texture will hit this code so keep normalized float value\n"
"\n"
" // 8 bits\n"
" return i;\n"
" return c;\n"
"#endif\n"
"\n"
"}\n"
"\n"
"mat4 sample_4p(uvec4 u)\n"
"mat4 sample_4p(vec4 u)\n"
"{\n"
" mat4 c;\n"
"\n"
@ -1066,10 +1064,12 @@ static const char* tfx_fs_all_glsl =
" mat4 c;\n"
" vec2 dd;\n"
"\n"
"#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)\n"
" c[0] = sample_c(clampuv(st));\n"
" // FIXME I'm not sure this condition is useful (I think code will be optimized)\n"
"#if (PS_LTF == 0 && PS_FMT == FMT_32 && PS_WMS < 2 && PS_WMT < 2)\n"
" // No software LTF and pure 32 bits RGBA texure without special texture wrapping\n"
" c[0] = sample_c(st);\n"
"#ifdef TEX_COORD_DEBUG\n"
" c[0].rg = clampuv(st).xy;\n"
" c[0].rg = st.xy;\n"
"#endif\n"
"\n"
"#else\n"
@ -1085,7 +1085,7 @@ static const char* tfx_fs_all_glsl =
" uv = st.xyxy;\n"
" }\n"
"\n"
" uv = wrapuv(uv);\n"
" uv = clamp_wrap_uv(uv);\n"
"\n"
" if((PS_FMT & FMT_PAL) != 0)\n"
" {\n"