Skip to content

Commit

Permalink
GSdx: GPU accelerate 8 bits texture conversion port from OpenGL to Di…
Browse files Browse the repository at this point in the history
…rect3D11.

Commit:
d29e375

Only native res is supported currently, but it's still great progress.
Someone needs to port the ScalingFactor to
D3D from commit: 6121677

Credits to KrossX for porting the shader.
  • Loading branch information
lightningterror committed Sep 13, 2018
1 parent ad143d9 commit 8e0eedc
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/GSdx/GSDevice11.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class GSDevice11 : public GSDeviceDX
{
CComPtr<ID3D11InputLayout> il;
CComPtr<ID3D11VertexShader> vs;
CComPtr<ID3D11PixelShader> ps[10];
CComPtr<ID3D11PixelShader> ps[18];
CComPtr<ID3D11SamplerState> ln;
CComPtr<ID3D11SamplerState> pt;
CComPtr<ID3D11DepthStencilState> dss;
Expand Down
4 changes: 3 additions & 1 deletion plugins/GSdx/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#include "GSTextureCache.h"
#include "GSUtil.h"

bool s_IS_DIRECT3D11 = false;
bool s_IS_OPENGL = false;
bool GSTextureCache::m_disable_partial_invalidation = false;
bool GSTextureCache::m_wrap_gs_mem = false;

GSTextureCache::GSTextureCache(GSRenderer* r)
: m_renderer(r)
{
s_IS_DIRECT3D11 = theApp.GetCurrentRendererType() == GSRendererType::DX1011_HW;
s_IS_OPENGL = theApp.GetCurrentRendererType() == GSRendererType::OGL_HW;

if (theApp.GetConfigB("UserHacks")) {
Expand Down Expand Up @@ -1187,7 +1189,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// TODO: clean up this mess

int shader = dst->m_type != RenderTarget ? ShaderConvert_FLOAT32_TO_RGBA8 : ShaderConvert_COPY;
bool is_8bits = TEX0.PSM == PSM_PSMT8 && s_IS_OPENGL;
bool is_8bits = TEX0.PSM == PSM_PSMT8 && (s_IS_DIRECT3D11 || s_IS_OPENGL);

if (is_8bits) {
GL_INS("Reading RT as a packed-indexed 8 bits format");
Expand Down
156 changes: 156 additions & 0 deletions plugins/GSdx/res/convert.fx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,162 @@ PS_OUTPUT ps_main9(PS_INPUT input) // triangular
return output;
}

// DUMMY SHADERS START
PS_OUTPUT ps_main10(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main11(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main12(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main13(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main14(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main15(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}

PS_OUTPUT ps_main16(PS_INPUT input)
{
PS_OUTPUT output;

output.c = 0;

return output;
}
// DUMMY SHADERS END

PS_OUTPUT ps_main17(PS_INPUT input)
{
PS_OUTPUT output;

// Potential speed optimization. There is a high probability that
// game only want to extract a single channel (blue). It will allow
// to remove most of the conditional operation and yield a +2/3 fps
// boost on MGS3
//
// Hypothesis wrong in Prince of Persia ... Seriously WTF !
//#define ONLY_BLUE;

// Convert a RGBA texture into a 8 bits packed texture
// Input column: 8x2 RGBA pixels
// 0: 8 RGBA
// 1: 8 RGBA
// Output column: 16x4 Index pixels
// 0: 8 R | 8 B
// 1: 8 R | 8 B
// 2: 8 G | 8 A
// 3: 8 G | 8 A
float c;

uint2 sel = uint2(input.p.xy) % uint2(16u, 16u);
int2 tb = ((int2(input.p.xy) & ~int2(15, 3)) >> 1);

int ty = tb.y | (int(input.p.y) & 1);
int txN = tb.x | (int(input.p.x) & 7);
int txH = tb.x | ((int(input.p.x) + 4) & 7);

//txN *= ScalingFactor.x;
//txH *= ScalingFactor.x;
//ty *= ScalingFactor.y;

// TODO investigate texture gather
float4 cN = Texture.Load(int3(txN, ty, 0));
float4 cH = Texture.Load(int3(txH, ty, 0));


if ((sel.y & 4u) == 0u)
{
#ifdef ONLY_BLUE
c = cN.b;
#else
// Column 0 and 2
if ((sel.y & 3u) < 2u)
{
// First 2 lines of the col
if (sel.x < 8u)
c = cN.r;
else
c = cN.b;
}
else
{
if (sel.x < 8u)
c = cH.g;
else
c = cH.a;
}
#endif
}
else
{
#ifdef ONLY_BLUE
c = cH.b;
#else
// Column 1 and 3
if ((sel.y & 3u) < 2u)
{
// First 2 lines of the col
if (sel.x < 8u)
c = cH.r;
else
c = cH.b;
}
else
{
if (sel.x < 8u)
c = cN.g;
else
c = cN.a;
}
#endif
}

output.c = (float4)(c); // Divide by something here?

return output;
}

#elif SHADER_MODEL <= 0x300

PS_OUTPUT ps_main1(PS_INPUT input)
Expand Down

0 comments on commit 8e0eedc

Please sign in to comment.