GSdx: GPU accelerate 8 bits texture conversion port from OpenGL to Direct3D11.

Commit:
d29e375f72

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

Credits to KrossX for porting the shader.
This commit is contained in:
lightningterror 2018-09-10 22:05:48 +02:00
parent 6b52cc9829
commit f40c1de919
3 changed files with 162 additions and 4 deletions

View File

@ -95,7 +95,7 @@ public: // TODO
{ {
CComPtr<ID3D11InputLayout> il; CComPtr<ID3D11InputLayout> il;
CComPtr<ID3D11VertexShader> vs; CComPtr<ID3D11VertexShader> vs;
CComPtr<ID3D11PixelShader> ps[10]; CComPtr<ID3D11PixelShader> ps[18];
CComPtr<ID3D11SamplerState> ln; CComPtr<ID3D11SamplerState> ln;
CComPtr<ID3D11SamplerState> pt; CComPtr<ID3D11SamplerState> pt;
CComPtr<ID3D11DepthStencilState> dss; CComPtr<ID3D11DepthStencilState> dss;

View File

@ -23,6 +23,7 @@
#include "GSTextureCache.h" #include "GSTextureCache.h"
#include "GSUtil.h" #include "GSUtil.h"
bool s_IS_DIRECT3D11 = false;
bool s_IS_OPENGL = false; bool s_IS_OPENGL = false;
bool GSTextureCache::m_disable_partial_invalidation = false; bool GSTextureCache::m_disable_partial_invalidation = false;
bool GSTextureCache::m_wrap_gs_mem = false; bool GSTextureCache::m_wrap_gs_mem = false;
@ -30,6 +31,7 @@ bool GSTextureCache::m_wrap_gs_mem = false;
GSTextureCache::GSTextureCache(GSRenderer* r) GSTextureCache::GSTextureCache(GSRenderer* r)
: m_renderer(r) : m_renderer(r)
{ {
s_IS_DIRECT3D11 = theApp.GetCurrentRendererType() == GSRendererType::DX1011_HW;
s_IS_OPENGL = theApp.GetCurrentRendererType() == GSRendererType::OGL_HW; s_IS_OPENGL = theApp.GetCurrentRendererType() == GSRendererType::OGL_HW;
if (theApp.GetConfigB("UserHacks")) { if (theApp.GetConfigB("UserHacks")) {
@ -1187,7 +1189,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// TODO: clean up this mess // TODO: clean up this mess
int shader = dst->m_type != RenderTarget ? ShaderConvert_FLOAT32_TO_RGBA8 : ShaderConvert_COPY; 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) { 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");

View File

@ -219,6 +219,162 @@ PS_OUTPUT ps_main9(PS_INPUT input) // triangular
return output; return output;
} }
// DUMMY SHADERS START
PS_OUTPUT ps_main10(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main11(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main12(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main13(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main14(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main15(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
return output;
}
PS_OUTPUT ps_main16(PS_INPUT input)
{
PS_OUTPUT output;
output.c = input.p;
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 #elif SHADER_MODEL <= 0x300
PS_OUTPUT ps_main1(PS_INPUT input) PS_OUTPUT ps_main1(PS_INPUT input)