mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
D3D: Add SBS/TAB output support.
This commit is contained in:
parent
9253bb7d96
commit
e53705784b
@ -422,20 +422,20 @@ int CD3DFont::DrawTextScaled(float x, float y, float size, float spacing, u32 dw
|
||||
ID3D11SamplerState* linear_copy_sampler = nullptr;
|
||||
ID3D11SamplerState* point_copy_sampler = nullptr;
|
||||
|
||||
struct STQVertex { float x, y, z, u, v, w; };
|
||||
struct STSQVertex { float x, y, z, u, v, w; };
|
||||
struct STQVertex { float x, y, z, u, v, w, g; };
|
||||
struct STSQVertex { float x, y, z, u, v, w, g; };
|
||||
struct ClearVertex { float x, y, z; u32 col; };
|
||||
struct ColVertex { float x, y, z; u32 col; };
|
||||
|
||||
struct
|
||||
{
|
||||
float u1, v1, u2, v2, G;
|
||||
float u1, v1, u2, v2, S, G;
|
||||
} tex_quad_data;
|
||||
|
||||
struct
|
||||
{
|
||||
MathUtil::Rectangle<float> rdest;
|
||||
float u1, v1, u2, v2, G;
|
||||
float u1, v1, u2, v2, S, G;
|
||||
} tex_sub_quad_data;
|
||||
|
||||
struct
|
||||
@ -512,7 +512,8 @@ void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
|
||||
ID3D11PixelShader* PShader,
|
||||
ID3D11VertexShader* Vshader,
|
||||
ID3D11InputLayout* layout,
|
||||
float Gamma)
|
||||
float Gamma,
|
||||
u32 slice)
|
||||
{
|
||||
float sw = 1.0f /(float) SourceWidth;
|
||||
float sh = 1.0f /(float) SourceHeight;
|
||||
@ -520,19 +521,21 @@ void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
|
||||
float u2 = ((float)rSource->right) * sw;
|
||||
float v1 = ((float)rSource->top) * sh;
|
||||
float v2 = ((float)rSource->bottom) * sh;
|
||||
float S = (float)slice;
|
||||
float G = 1.0f / Gamma;
|
||||
|
||||
STQVertex coords[4] = {
|
||||
{-1.0f, 1.0f, 0.0f, u1, v1, G},
|
||||
{ 1.0f, 1.0f, 0.0f, u2, v1, G},
|
||||
{-1.0f,-1.0f, 0.0f, u1, v2, G},
|
||||
{ 1.0f,-1.0f, 0.0f, u2, v2, G},
|
||||
{-1.0f, 1.0f, 0.0f, u1, v1, S, G},
|
||||
{ 1.0f, 1.0f, 0.0f, u2, v1, S, G},
|
||||
{-1.0f,-1.0f, 0.0f, u1, v2, S, G},
|
||||
{ 1.0f,-1.0f, 0.0f, u2, v2, S, G},
|
||||
};
|
||||
|
||||
// only upload the data to VRAM if it changed
|
||||
if (stq_observer ||
|
||||
tex_quad_data.u1 != u1 || tex_quad_data.v1 != v1 ||
|
||||
tex_quad_data.u2 != u2 || tex_quad_data.v2 != v2 || tex_quad_data.G != G)
|
||||
tex_quad_data.u2 != u2 || tex_quad_data.v2 != v2 ||
|
||||
tex_quad_data.S != S || tex_quad_data.G != G)
|
||||
{
|
||||
stq_offset = util_vbuf->AppendData(coords, sizeof(coords), sizeof(STQVertex));
|
||||
stq_observer = false;
|
||||
@ -541,7 +544,8 @@ void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
|
||||
tex_quad_data.v1 = v1;
|
||||
tex_quad_data.u2 = u2;
|
||||
tex_quad_data.v2 = v2;
|
||||
tex_quad_data.G = G;
|
||||
tex_quad_data.S = S;
|
||||
tex_quad_data.G = G;
|
||||
}
|
||||
UINT stride = sizeof(STQVertex);
|
||||
UINT offset = 0;
|
||||
@ -568,7 +572,8 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
|
||||
ID3D11PixelShader* PShader,
|
||||
ID3D11VertexShader* Vshader,
|
||||
ID3D11InputLayout* layout,
|
||||
float Gamma)
|
||||
float Gamma,
|
||||
u32 slice)
|
||||
{
|
||||
float sw = 1.0f /(float) SourceWidth;
|
||||
float sh = 1.0f /(float) SourceHeight;
|
||||
@ -576,20 +581,22 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
|
||||
float u2 = (rSource->right ) * sw;
|
||||
float v1 = (rSource->top ) * sh;
|
||||
float v2 = (rSource->bottom) * sh;
|
||||
float S = (float)slice;
|
||||
float G = 1.0f / Gamma;
|
||||
|
||||
STSQVertex coords[4] = {
|
||||
{ rDest->left , rDest->bottom, 0.0f, u1, v2, G},
|
||||
{ rDest->right, rDest->bottom, 0.0f, u2, v2, G},
|
||||
{ rDest->left , rDest->top , 0.0f, u1, v1, G},
|
||||
{ rDest->right, rDest->top , 0.0f, u2, v1, G},
|
||||
{ rDest->left , rDest->bottom, 0.0f, u1, v2, S, G},
|
||||
{ rDest->right, rDest->bottom, 0.0f, u2, v2, S, G},
|
||||
{ rDest->left , rDest->top , 0.0f, u1, v1, S, G},
|
||||
{ rDest->right, rDest->top , 0.0f, u2, v1, S, G},
|
||||
};
|
||||
|
||||
// only upload the data to VRAM if it changed
|
||||
if (stsq_observer ||
|
||||
memcmp(rDest, &tex_sub_quad_data.rdest, sizeof(*rDest)) != 0 ||
|
||||
tex_sub_quad_data.u1 != u1 || tex_sub_quad_data.v1 != v1 ||
|
||||
tex_sub_quad_data.u2 != u2 || tex_sub_quad_data.v2 != v2 || tex_sub_quad_data.G != G)
|
||||
tex_sub_quad_data.u2 != u2 || tex_sub_quad_data.v2 != v2 ||
|
||||
tex_sub_quad_data.S != S || tex_sub_quad_data.G != G)
|
||||
{
|
||||
stsq_offset = util_vbuf->AppendData(coords, sizeof(coords), sizeof(STSQVertex));
|
||||
stsq_observer = false;
|
||||
@ -598,6 +605,7 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
|
||||
tex_sub_quad_data.v1 = v1;
|
||||
tex_sub_quad_data.u2 = u2;
|
||||
tex_sub_quad_data.v2 = v2;
|
||||
tex_sub_quad_data.S = S;
|
||||
tex_sub_quad_data.G = G;
|
||||
memcpy(&tex_sub_quad_data.rdest, &rDest, sizeof(rDest));
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ namespace D3D
|
||||
ID3D11PixelShader* PShader,
|
||||
ID3D11VertexShader* VShader,
|
||||
ID3D11InputLayout* layout,
|
||||
float Gamma = 1.0f);
|
||||
float Gamma = 1.0f,
|
||||
u32 slice = 0);
|
||||
void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
|
||||
const MathUtil::Rectangle<int>* rSource,
|
||||
int SourceWidth,
|
||||
@ -71,7 +72,8 @@ namespace D3D
|
||||
ID3D11PixelShader* PShader,
|
||||
ID3D11VertexShader* Vshader,
|
||||
ID3D11InputLayout* layout,
|
||||
float Gamma = 1.0f);
|
||||
float Gamma = 1.0f,
|
||||
u32 slice = 0);
|
||||
void drawClearQuad(u32 Color, float z, ID3D11PixelShader* PShader, ID3D11VertexShader* Vshader, ID3D11InputLayout* layout);
|
||||
void drawColorQuad(u32 Color, float x1, float y1, float x2, float y2);
|
||||
}
|
||||
|
@ -51,11 +51,11 @@ const char clear_program_code[] = {
|
||||
// TODO: Find some way to avoid having separate shaders for non-MSAA and MSAA...
|
||||
const char color_copy_program_code[] = {
|
||||
"sampler samp0 : register(s0);\n"
|
||||
"Texture2D Tex0 : register(t0);\n"
|
||||
"Texture2DArray Tex0 : register(t0);\n"
|
||||
"void main(\n"
|
||||
"out float4 ocol0 : SV_Target,\n"
|
||||
"in float4 pos : SV_Position,\n"
|
||||
"in float2 uv0 : TEXCOORD0){\n"
|
||||
"in float3 uv0 : TEXCOORD0){\n"
|
||||
"ocol0 = Tex0.Sample(samp0,uv0);\n"
|
||||
"}\n"
|
||||
};
|
||||
@ -63,16 +63,16 @@ const char color_copy_program_code[] = {
|
||||
// TODO: Improve sampling algorithm!
|
||||
const char color_copy_program_code_msaa[] = {
|
||||
"sampler samp0 : register(s0);\n"
|
||||
"Texture2DMS<float4, %d> Tex0 : register(t0);\n"
|
||||
"Texture2DMSArray<float4, %d> Tex0 : register(t0);\n"
|
||||
"void main(\n"
|
||||
"out float4 ocol0 : SV_Target,\n"
|
||||
"in float4 pos : SV_Position,\n"
|
||||
"in float2 uv0 : TEXCOORD0){\n"
|
||||
"in float3 uv0 : TEXCOORD0,\n"
|
||||
"int width, height, samples;\n"
|
||||
"Tex0.GetDimensions(width, height, samples);\n"
|
||||
"ocol0 = 0;\n"
|
||||
"for(int i = 0; i < samples; ++i)\n"
|
||||
" ocol0 += Tex0.Load(int2(uv0.x*(width), uv0.y*(height)), i);\n"
|
||||
" ocol0 += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
||||
"ocol0 /= samples;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
@ -761,7 +761,25 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
|
||||
|
||||
// TODO: Improve sampling algorithm for the pixel shader so that we can use the multisampled EFB texture as source
|
||||
D3DTexture2D* read_texture = FramebufferManager::GetResolvedEFBColorTexture();
|
||||
D3D::drawShadedTexQuad(read_texture->GetSRV(), targetRc.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(false),VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), Gamma);
|
||||
|
||||
if (g_ActiveConfig.iStereoMode == STEREO_SBS || g_ActiveConfig.iStereoMode == STEREO_TAB)
|
||||
{
|
||||
TargetRectangle leftRc, rightRc;
|
||||
ConvertStereoRectangle(GetTargetRectangle(), leftRc, rightRc);
|
||||
|
||||
D3D11_VIEWPORT leftVp = CD3D11_VIEWPORT((float)leftRc.left, (float)leftRc.top, (float)leftRc.GetWidth(), (float)leftRc.GetHeight());
|
||||
D3D11_VIEWPORT rightVp = CD3D11_VIEWPORT((float)rightRc.left, (float)rightRc.top, (float)rightRc.GetWidth(), (float)rightRc.GetHeight());
|
||||
|
||||
D3D::context->RSSetViewports(1, &leftVp);
|
||||
D3D::drawShadedTexQuad(read_texture->GetSRV(), targetRc.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(false), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), Gamma, 0);
|
||||
|
||||
D3D::context->RSSetViewports(1, &rightVp);
|
||||
D3D::drawShadedTexQuad(read_texture->GetSRV(), targetRc.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(false), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), Gamma, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D::drawShadedTexQuad(read_texture->GetSRV(), targetRc.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(false), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), Gamma);
|
||||
}
|
||||
}
|
||||
|
||||
// done with drawing the game stuff, good moment to save a screenshot
|
||||
|
@ -73,15 +73,15 @@ const char simple_shader_code[] = {
|
||||
"struct VSOUTPUT\n"
|
||||
"{\n"
|
||||
"float4 vPosition : POSITION;\n"
|
||||
"float2 vTexCoord : TEXCOORD0;\n"
|
||||
"float3 vTexCoord : TEXCOORD0;\n"
|
||||
"float vTexCoord1 : TEXCOORD1;\n"
|
||||
"};\n"
|
||||
"VSOUTPUT main(float4 inPosition : POSITION,float3 inTEX0 : TEXCOORD0)\n"
|
||||
"VSOUTPUT main(float4 inPosition : POSITION,float4 inTEX0 : TEXCOORD0)\n"
|
||||
"{\n"
|
||||
"VSOUTPUT OUT;\n"
|
||||
"OUT.vPosition = inPosition;\n"
|
||||
"OUT.vTexCoord = inTEX0.xy;\n"
|
||||
"OUT.vTexCoord1 = inTEX0.z;\n"
|
||||
"OUT.vTexCoord = inTEX0.xyz;\n"
|
||||
"OUT.vTexCoord1 = inTEX0.w;\n"
|
||||
"return OUT;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user