2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-12-03 21:17:56 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2016-11-27 10:56:22 +00:00
|
|
|
#include "Common/Align.h"
|
2014-12-03 21:17:56 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DShader.h"
|
2017-07-20 05:25:31 +00:00
|
|
|
#include "VideoBackends/D3D/D3DState.h"
|
2014-12-21 14:37:05 +00:00
|
|
|
#include "VideoBackends/D3D/FramebufferManager.h"
|
2014-12-03 21:17:56 +00:00
|
|
|
#include "VideoBackends/D3D/GeometryShaderCache.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/Debugger.h"
|
|
|
|
#include "VideoCommon/GeometryShaderGen.h"
|
2014-12-14 20:23:13 +00:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
|
|
|
#include "VideoCommon/Statistics.h"
|
2014-12-03 21:17:56 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
|
|
|
namespace DX11
|
|
|
|
{
|
2014-11-23 01:13:25 +00:00
|
|
|
ID3D11GeometryShader* ClearGeometryShader = nullptr;
|
2014-11-29 20:31:30 +00:00
|
|
|
ID3D11GeometryShader* CopyGeometryShader = nullptr;
|
2014-11-23 01:13:25 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ID3D11GeometryShader* GeometryShaderCache::GetClearGeometryShader()
|
|
|
|
{
|
2017-11-11 03:55:00 +00:00
|
|
|
return (g_ActiveConfig.stereo_mode != StereoMode::Off) ? ClearGeometryShader : nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
ID3D11GeometryShader* GeometryShaderCache::GetCopyGeometryShader()
|
|
|
|
{
|
2017-11-11 03:55:00 +00:00
|
|
|
return (g_ActiveConfig.stereo_mode != StereoMode::Off) ? CopyGeometryShader : nullptr;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2014-11-23 01:13:25 +00:00
|
|
|
|
2014-12-03 21:17:56 +00:00
|
|
|
ID3D11Buffer* gscbuf = nullptr;
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
ID3D11Buffer*& GeometryShaderCache::GetConstantBuffer()
|
2014-12-14 20:23:13 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to
|
|
|
|
// speed this up
|
|
|
|
if (GeometryShaderManager::dirty)
|
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE map;
|
|
|
|
D3D::context->Map(gscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
|
|
|
memcpy(map.pData, &GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
|
|
|
|
D3D::context->Unmap(gscbuf, 0);
|
|
|
|
GeometryShaderManager::dirty = false;
|
|
|
|
|
|
|
|
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(GeometryShaderConstants));
|
|
|
|
}
|
|
|
|
return gscbuf;
|
2014-12-14 20:23:13 +00:00
|
|
|
}
|
|
|
|
|
2014-11-23 01:13:25 +00:00
|
|
|
const char clear_shader_code[] = {
|
2016-06-24 08:43:46 +00:00
|
|
|
"struct VSOUTPUT\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 vPosition : POSITION;\n"
|
|
|
|
" float4 vColor0 : COLOR0;\n"
|
|
|
|
"};\n"
|
|
|
|
"struct GSOUTPUT\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 vPosition : POSITION;\n"
|
|
|
|
" float4 vColor0 : COLOR0;\n"
|
|
|
|
" uint slice : SV_RenderTargetArrayIndex;\n"
|
|
|
|
"};\n"
|
|
|
|
"[maxvertexcount(6)]\n"
|
|
|
|
"void main(triangle VSOUTPUT o[3], inout TriangleStream<GSOUTPUT> Output)\n"
|
|
|
|
"{\n"
|
|
|
|
"for(int slice = 0; slice < 2; slice++)\n"
|
|
|
|
"{\n"
|
|
|
|
" for(int i = 0; i < 3; i++)\n"
|
|
|
|
" {\n"
|
|
|
|
" GSOUTPUT OUT;\n"
|
|
|
|
" OUT.vPosition = o[i].vPosition;\n"
|
|
|
|
" OUT.vColor0 = o[i].vColor0;\n"
|
|
|
|
" OUT.slice = slice;\n"
|
|
|
|
" Output.Append(OUT);\n"
|
|
|
|
" }\n"
|
|
|
|
" Output.RestartStrip();\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"};
|
2014-11-23 01:13:25 +00:00
|
|
|
|
2014-11-29 20:31:30 +00:00
|
|
|
const char copy_shader_code[] = {
|
2016-06-24 08:43:46 +00:00
|
|
|
"struct VSOUTPUT\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 vPosition : POSITION;\n"
|
|
|
|
" float3 vTexCoord : TEXCOORD0;\n"
|
|
|
|
"};\n"
|
|
|
|
"struct GSOUTPUT\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 vPosition : POSITION;\n"
|
|
|
|
" float3 vTexCoord : TEXCOORD0;\n"
|
|
|
|
" uint slice : SV_RenderTargetArrayIndex;\n"
|
|
|
|
"};\n"
|
|
|
|
"[maxvertexcount(6)]\n"
|
|
|
|
"void main(triangle VSOUTPUT o[3], inout TriangleStream<GSOUTPUT> Output)\n"
|
|
|
|
"{\n"
|
|
|
|
"for(int slice = 0; slice < 2; slice++)\n"
|
|
|
|
"{\n"
|
|
|
|
" for(int i = 0; i < 3; i++)\n"
|
|
|
|
" {\n"
|
|
|
|
" GSOUTPUT OUT;\n"
|
|
|
|
" OUT.vPosition = o[i].vPosition;\n"
|
|
|
|
" OUT.vTexCoord = o[i].vTexCoord;\n"
|
2018-05-02 11:58:56 +00:00
|
|
|
" OUT.vTexCoord.z = float(slice);\n"
|
2016-06-24 08:43:46 +00:00
|
|
|
" OUT.slice = slice;\n"
|
|
|
|
" Output.Append(OUT);\n"
|
|
|
|
" }\n"
|
|
|
|
" Output.RestartStrip();\n"
|
|
|
|
"}\n"
|
|
|
|
"}\n"};
|
2014-11-29 20:31:30 +00:00
|
|
|
|
2014-12-03 21:17:56 +00:00
|
|
|
void GeometryShaderCache::Init()
|
|
|
|
{
|
2016-11-27 10:56:22 +00:00
|
|
|
unsigned int gbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(GeometryShaderConstants)),
|
|
|
|
16); // must be a multiple of 16
|
2016-06-24 08:43:46 +00:00
|
|
|
D3D11_BUFFER_DESC gbdesc = CD3D11_BUFFER_DESC(gbsize, D3D11_BIND_CONSTANT_BUFFER,
|
|
|
|
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
|
|
|
HRESULT hr = D3D::device->CreateBuffer(&gbdesc, nullptr, &gscbuf);
|
|
|
|
CHECK(hr == S_OK, "Create geometry shader constant buffer (size=%u)", gbsize);
|
2017-09-02 18:22:18 +00:00
|
|
|
D3D::SetDebugObjectName(gscbuf,
|
2016-06-24 08:43:46 +00:00
|
|
|
"geometry shader constant buffer used to emulate the GX pipeline");
|
|
|
|
|
|
|
|
// used when drawing clear quads
|
|
|
|
ClearGeometryShader = D3D::CompileAndCreateGeometryShader(clear_shader_code);
|
|
|
|
CHECK(ClearGeometryShader != nullptr, "Create clear geometry shader");
|
2017-09-02 18:22:18 +00:00
|
|
|
D3D::SetDebugObjectName(ClearGeometryShader, "clear geometry shader");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// used for buffer copy
|
|
|
|
CopyGeometryShader = D3D::CompileAndCreateGeometryShader(copy_shader_code);
|
|
|
|
CHECK(CopyGeometryShader != nullptr, "Create copy geometry shader");
|
2017-09-02 18:22:18 +00:00
|
|
|
D3D::SetDebugObjectName(CopyGeometryShader, "copy geometry shader");
|
2014-12-03 21:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GeometryShaderCache::Shutdown()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
SAFE_RELEASE(gscbuf);
|
2014-12-14 20:23:13 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
SAFE_RELEASE(ClearGeometryShader);
|
|
|
|
SAFE_RELEASE(CopyGeometryShader);
|
2014-12-03 21:17:56 +00:00
|
|
|
}
|
|
|
|
} // DX11
|