2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-06-03 05:08:54 +00:00
|
|
|
#include <string>
|
|
|
|
|
2016-01-02 20:01:12 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/LinearDiskCache.h"
|
2014-06-03 05:08:54 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DShader.h"
|
|
|
|
#include "VideoBackends/D3D/PixelShaderCache.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/Debugger.h"
|
|
|
|
#include "VideoCommon/PixelShaderGen.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/Statistics.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
namespace DX11
|
|
|
|
{
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
|
|
|
|
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry;
|
2013-03-26 22:35:14 +00:00
|
|
|
PixelShaderUid PixelShaderCache::last_uid;
|
2015-10-29 13:43:05 +00:00
|
|
|
UidChecker<PixelShaderUid, ShaderCode> PixelShaderCache::pixel_uid_checker;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2013-03-26 22:35:14 +00:00
|
|
|
LinearDiskCache<PixelShaderUid, u8> g_ps_disk_cache;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
ID3D11PixelShader* s_ColorMatrixProgram[2] = {nullptr};
|
|
|
|
ID3D11PixelShader* s_ColorCopyProgram[2] = {nullptr};
|
|
|
|
ID3D11PixelShader* s_DepthMatrixProgram[2] = {nullptr};
|
|
|
|
ID3D11PixelShader* s_ClearProgram = nullptr;
|
2014-11-29 20:55:14 +00:00
|
|
|
ID3D11PixelShader* s_AnaglyphProgram = nullptr;
|
2015-11-28 11:33:47 +00:00
|
|
|
ID3D11PixelShader* s_DepthResolveProgram = nullptr;
|
2014-03-09 20:14:26 +00:00
|
|
|
ID3D11PixelShader* s_rgba6_to_rgb8[2] = {nullptr};
|
|
|
|
ID3D11PixelShader* s_rgb8_to_rgba6[2] = {nullptr};
|
|
|
|
ID3D11Buffer* pscbuf = nullptr;
|
2011-01-25 15:08:30 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
const char clear_program_code[] = {
|
|
|
|
"void main(\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"in float4 incol0 : COLOR0){\n"
|
|
|
|
"ocol0 = incol0;\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2011-04-30 14:08:58 +00:00
|
|
|
// TODO: Find some way to avoid having separate shaders for non-MSAA and MSAA...
|
2010-06-13 19:50:06 +00:00
|
|
|
const char color_copy_program_code[] = {
|
2010-06-14 14:36:01 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-11-03 12:10:41 +00:00
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"void main(\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
2014-11-03 12:10:41 +00:00
|
|
|
"in float3 uv0 : TEXCOORD0){\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"ocol0 = Tex0.Sample(samp0,uv0);\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2015-01-02 02:02:33 +00:00
|
|
|
// Anaglyph Red-Cyan shader based on Dubois algorithm
|
|
|
|
// Constants taken from the paper:
|
|
|
|
// "Conversion of a Stereo Pair to Anaglyph with
|
|
|
|
// the Least-Squares Projection Method"
|
|
|
|
// Eric Dubois, March 2009
|
2014-11-29 20:55:14 +00:00
|
|
|
const char anaglyph_program_code[] = {
|
|
|
|
"sampler samp0 : register(s0);\n"
|
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
|
|
|
"void main(\n"
|
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
|
|
|
"in float3 uv0 : TEXCOORD0){\n"
|
2015-01-02 12:35:53 +00:00
|
|
|
"float4 c0 = Tex0.Sample(samp0, float3(uv0.xy, 0.0));\n"
|
|
|
|
"float4 c1 = Tex0.Sample(samp0, float3(uv0.xy, 1.0));\n"
|
|
|
|
"float3x3 l = float3x3( 0.437, 0.449, 0.164,\n"
|
|
|
|
" -0.062,-0.062,-0.024,\n"
|
|
|
|
" -0.048,-0.050,-0.017);\n"
|
|
|
|
"float3x3 r = float3x3(-0.011,-0.032,-0.007,\n"
|
|
|
|
" 0.377, 0.761, 0.009,\n"
|
|
|
|
" -0.026,-0.093, 1.234);\n"
|
|
|
|
"ocol0 = float4(mul(l, c0.rgb) + mul(r, c1.rgb), c0.a);\n"
|
2014-11-29 20:55:14 +00:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
// TODO: Improve sampling algorithm!
|
|
|
|
const char color_copy_program_code_msaa[] = {
|
2014-12-27 13:37:43 +00:00
|
|
|
"#define SAMPLES %d\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"void main(\n"
|
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
2014-12-03 13:20:46 +00:00
|
|
|
"in float3 uv0 : TEXCOORD0){\n"
|
|
|
|
"int width, height, slices, samples;\n"
|
|
|
|
"Tex0.GetDimensions(width, height, slices, samples);\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"ocol0 = 0;\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"for(int i = 0; i < SAMPLES; ++i)\n"
|
2014-11-03 12:10:41 +00:00
|
|
|
" ocol0 += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"ocol0 /= SAMPLES;\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
const char color_matrix_program_code[] = {
|
2010-06-14 14:36:01 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"uniform float4 cColMatrix[7] : register(c0);\n"
|
2013-10-29 05:23:17 +00:00
|
|
|
"void main(\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
"in float3 uv0 : TEXCOORD0){\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"float4 texcol = Tex0.Sample(samp0,uv0);\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"texcol = round(texcol * cColMatrix[5])*cColMatrix[6];\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
const char color_matrix_program_code_msaa[] = {
|
2014-12-27 13:37:43 +00:00
|
|
|
"#define SAMPLES %d\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"uniform float4 cColMatrix[7] : register(c0);\n"
|
2013-10-29 05:23:17 +00:00
|
|
|
"void main(\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
"in float4 pos : SV_Position,\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
"in float3 uv0 : TEXCOORD0){\n"
|
2014-12-03 13:20:46 +00:00
|
|
|
"int width, height, slices, samples;\n"
|
|
|
|
"Tex0.GetDimensions(width, height, slices, samples);\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"float4 texcol = 0;\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"for(int i = 0; i < SAMPLES; ++i)\n"
|
2014-12-03 13:20:46 +00:00
|
|
|
" texcol += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"texcol /= SAMPLES;\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"texcol = round(texcol * cColMatrix[5])*cColMatrix[6];\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
const char depth_matrix_program[] = {
|
2010-06-14 14:36:01 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"uniform float4 cColMatrix[7] : register(c0);\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"void main(\n"
|
2010-06-14 14:36:01 +00:00
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0){\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
" float4 texcol = Tex0.Sample(samp0,uv0);\n"
|
2015-08-15 11:46:34 +00:00
|
|
|
" int depth = int((1.0 - texcol.x) * 16777216.0);\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Convert to Z24 format
|
|
|
|
" int4 workspace;\n"
|
|
|
|
" workspace.r = (depth >> 16) & 255;\n"
|
|
|
|
" workspace.g = (depth >> 8) & 255;\n"
|
|
|
|
" workspace.b = depth & 255;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Convert to Z4 format
|
|
|
|
" workspace.a = (depth >> 16) & 0xF0;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Normalize components to [0.0..1.0]
|
|
|
|
" texcol = float4(workspace) / 255.0;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Apply color matrix
|
2014-08-17 07:14:29 +00:00
|
|
|
" ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
|
2010-06-13 19:50:06 +00:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
const char depth_matrix_program_msaa[] = {
|
2014-12-27 13:37:43 +00:00
|
|
|
"#define SAMPLES %d\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
2011-01-07 19:23:57 +00:00
|
|
|
"uniform float4 cColMatrix[7] : register(c0);\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"void main(\n"
|
|
|
|
"out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-11-22 18:52:59 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0){\n"
|
2014-12-03 13:20:46 +00:00
|
|
|
" int width, height, slices, samples;\n"
|
|
|
|
" Tex0.GetDimensions(width, height, slices, samples);\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
" float4 texcol = 0;\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" for(int i = 0; i < SAMPLES; ++i)\n"
|
2014-12-03 13:20:46 +00:00
|
|
|
" texcol += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" texcol /= SAMPLES;\n"
|
2015-08-15 11:46:34 +00:00
|
|
|
" int depth = int((1.0 - texcol.x) * 16777216.0);\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Convert to Z24 format
|
|
|
|
" int4 workspace;\n"
|
|
|
|
" workspace.r = (depth >> 16) & 255;\n"
|
|
|
|
" workspace.g = (depth >> 8) & 255;\n"
|
|
|
|
" workspace.b = depth & 255;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Convert to Z4 format
|
|
|
|
" workspace.a = (depth >> 16) & 0xF0;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Normalize components to [0.0..1.0]
|
|
|
|
" texcol = float4(workspace) / 255.0;\n"
|
2014-08-17 07:14:29 +00:00
|
|
|
|
2015-05-04 21:28:30 +00:00
|
|
|
// Apply color matrix
|
2014-08-17 07:14:29 +00:00
|
|
|
" ocol0 = float4(dot(texcol,cColMatrix[0]),dot(texcol,cColMatrix[1]),dot(texcol,cColMatrix[2]),dot(texcol,cColMatrix[3])) + cColMatrix[4];\n"
|
2010-11-27 11:11:05 +00:00
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2015-11-28 11:33:47 +00:00
|
|
|
const char depth_resolve_program[] = {
|
|
|
|
"#define SAMPLES %d\n"
|
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
|
|
|
"void main(\n"
|
|
|
|
" out float depth : SV_Depth,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
|
|
|
" in float3 uv0 : TEXCOORD0)\n"
|
|
|
|
"{\n"
|
|
|
|
" int width, height, slices, samples;\n"
|
|
|
|
" Tex0.GetDimensions(width, height, slices, samples);\n"
|
|
|
|
" depth = Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), 0).x;\n"
|
|
|
|
" for(int i = 1; i < SAMPLES; ++i)\n"
|
|
|
|
" depth = min(depth, Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i).x);\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
2011-04-30 14:08:58 +00:00
|
|
|
const char reint_rgba6_to_rgb8[] = {
|
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"void main(\n"
|
|
|
|
" out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0)\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"{\n"
|
|
|
|
" int4 src6 = round(Tex0.Sample(samp0,uv0) * 63.f);\n"
|
|
|
|
" int4 dst8;\n"
|
|
|
|
" dst8.r = (src6.r << 2) | (src6.g >> 4);\n"
|
|
|
|
" dst8.g = ((src6.g & 0xF) << 4) | (src6.b >> 2);\n"
|
|
|
|
" dst8.b = ((src6.b & 0x3) << 6) | src6.a;\n"
|
|
|
|
" dst8.a = 255;\n"
|
|
|
|
" ocol0 = (float4)dst8 / 255.f;\n"
|
|
|
|
"}"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char reint_rgba6_to_rgb8_msaa[] = {
|
2014-12-27 13:37:43 +00:00
|
|
|
"#define SAMPLES %d\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"void main(\n"
|
|
|
|
" out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0)\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"{\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" int width, height, slices, samples;\n"
|
|
|
|
" Tex0.GetDimensions(width, height, slices, samples);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
" float4 texcol = 0;\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" for (int i = 0; i < SAMPLES; ++i)\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" texcol += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" texcol /= SAMPLES;\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
" int4 src6 = round(texcol * 63.f);\n"
|
|
|
|
" int4 dst8;\n"
|
|
|
|
" dst8.r = (src6.r << 2) | (src6.g >> 4);\n"
|
|
|
|
" dst8.g = ((src6.g & 0xF) << 4) | (src6.b >> 2);\n"
|
|
|
|
" dst8.b = ((src6.b & 0x3) << 6) | src6.a;\n"
|
|
|
|
" dst8.a = 255;\n"
|
|
|
|
" ocol0 = (float4)dst8 / 255.f;\n"
|
|
|
|
"}"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char reint_rgb8_to_rgba6[] = {
|
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
"Texture2DArray Tex0 : register(t0);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"void main(\n"
|
|
|
|
" out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0)\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"{\n"
|
|
|
|
" int4 src8 = round(Tex0.Sample(samp0,uv0) * 255.f);\n"
|
|
|
|
" int4 dst6;\n"
|
|
|
|
" dst6.r = src8.r >> 2;\n"
|
|
|
|
" dst6.g = ((src8.r & 0x3) << 4) | (src8.g >> 4);\n"
|
|
|
|
" dst6.b = ((src8.g & 0xF) << 2) | (src8.b >> 6);\n"
|
|
|
|
" dst6.a = src8.b & 0x3F;\n"
|
|
|
|
" ocol0 = (float4)dst6 / 63.f;\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char reint_rgb8_to_rgba6_msaa[] = {
|
2014-12-27 13:37:43 +00:00
|
|
|
"#define SAMPLES %d\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"sampler samp0 : register(s0);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"void main(\n"
|
|
|
|
" out float4 ocol0 : SV_Target,\n"
|
|
|
|
" in float4 pos : SV_Position,\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" in float3 uv0 : TEXCOORD0)\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
"{\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" int width, height, slices, samples;\n"
|
|
|
|
" Tex0.GetDimensions(width, height, slices, samples);\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
" float4 texcol = 0;\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" for (int i = 0; i < SAMPLES; ++i)\n"
|
2014-12-21 14:37:05 +00:00
|
|
|
" texcol += Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i);\n"
|
2014-12-27 13:37:43 +00:00
|
|
|
" texcol /= SAMPLES;\n"
|
2011-04-30 14:08:58 +00:00
|
|
|
" int4 src8 = round(texcol * 255.f);\n"
|
|
|
|
" int4 dst6;\n"
|
|
|
|
" dst6.r = src8.r >> 2;\n"
|
|
|
|
" dst6.g = ((src8.r & 0x3) << 4) | (src8.g >> 4);\n"
|
|
|
|
" dst6.b = ((src8.g & 0xF) << 2) | (src8.b >> 6);\n"
|
|
|
|
" dst6.a = src8.b & 0x3F;\n"
|
|
|
|
" ocol0 = (float4)dst6 / 63.f;\n"
|
|
|
|
"}\n"
|
|
|
|
};
|
|
|
|
|
|
|
|
ID3D11PixelShader* PixelShaderCache::ReinterpRGBA6ToRGB8(bool multisampled)
|
2011-02-04 17:00:34 +00:00
|
|
|
{
|
2015-12-12 12:00:08 +00:00
|
|
|
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
|
2011-03-30 07:17:23 +00:00
|
|
|
{
|
2011-04-30 14:08:58 +00:00
|
|
|
if (!s_rgba6_to_rgb8[0])
|
|
|
|
{
|
2014-07-07 23:28:12 +00:00
|
|
|
s_rgba6_to_rgb8[0] = D3D::CompileAndCreatePixelShader(reint_rgba6_to_rgb8);
|
2011-04-30 14:08:58 +00:00
|
|
|
CHECK(s_rgba6_to_rgb8[0], "Create RGBA6 to RGB8 pixel shader");
|
|
|
|
D3D::SetDebugObjectName(s_rgba6_to_rgb8[0], "RGBA6 to RGB8 pixel shader");
|
|
|
|
}
|
|
|
|
return s_rgba6_to_rgb8[0];
|
2011-03-30 07:17:23 +00:00
|
|
|
}
|
2011-04-30 14:08:58 +00:00
|
|
|
else if (!s_rgba6_to_rgb8[1])
|
|
|
|
{
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-12 12:00:08 +00:00
|
|
|
std::string buf = StringFromFormat(reint_rgba6_to_rgb8_msaa, g_ActiveConfig.iMultisamples);
|
2014-07-07 23:28:12 +00:00
|
|
|
s_rgba6_to_rgb8[1] = D3D::CompileAndCreatePixelShader(buf);
|
2011-04-30 14:08:58 +00:00
|
|
|
|
|
|
|
CHECK(s_rgba6_to_rgb8[1], "Create RGBA6 to RGB8 MSAA pixel shader");
|
|
|
|
D3D::SetDebugObjectName(s_rgba6_to_rgb8[1], "RGBA6 to RGB8 MSAA pixel shader");
|
|
|
|
}
|
|
|
|
return s_rgba6_to_rgb8[1];
|
2011-02-04 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2011-04-30 14:08:58 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::ReinterpRGB8ToRGBA6(bool multisampled)
|
2011-02-04 17:00:34 +00:00
|
|
|
{
|
2015-12-12 12:00:08 +00:00
|
|
|
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
|
2011-03-30 07:17:23 +00:00
|
|
|
{
|
2011-04-30 14:08:58 +00:00
|
|
|
if (!s_rgb8_to_rgba6[0])
|
|
|
|
{
|
2014-07-07 23:28:12 +00:00
|
|
|
s_rgb8_to_rgba6[0] = D3D::CompileAndCreatePixelShader(reint_rgb8_to_rgba6);
|
2011-04-30 14:08:58 +00:00
|
|
|
CHECK(s_rgb8_to_rgba6[0], "Create RGB8 to RGBA6 pixel shader");
|
|
|
|
D3D::SetDebugObjectName(s_rgb8_to_rgba6[0], "RGB8 to RGBA6 pixel shader");
|
|
|
|
}
|
|
|
|
return s_rgb8_to_rgba6[0];
|
2011-03-30 07:17:23 +00:00
|
|
|
}
|
2011-04-30 14:08:58 +00:00
|
|
|
else if (!s_rgb8_to_rgba6[1])
|
|
|
|
{
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-12 12:00:08 +00:00
|
|
|
std::string buf = StringFromFormat(reint_rgb8_to_rgba6_msaa, g_ActiveConfig.iMultisamples);
|
2014-07-07 23:28:12 +00:00
|
|
|
s_rgb8_to_rgba6[1] = D3D::CompileAndCreatePixelShader(buf);
|
2011-04-30 14:08:58 +00:00
|
|
|
|
|
|
|
CHECK(s_rgb8_to_rgba6[1], "Create RGB8 to RGBA6 MSAA pixel shader");
|
|
|
|
D3D::SetDebugObjectName(s_rgb8_to_rgba6[1], "RGB8 to RGBA6 MSAA pixel shader");
|
|
|
|
}
|
|
|
|
return s_rgb8_to_rgba6[1];
|
2011-02-04 17:00:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::GetColorCopyProgram(bool multisampled)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2015-12-12 12:00:08 +00:00
|
|
|
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
|
2014-07-07 23:28:12 +00:00
|
|
|
{
|
|
|
|
return s_ColorCopyProgram[0];
|
|
|
|
}
|
|
|
|
else if (s_ColorCopyProgram[1])
|
|
|
|
{
|
|
|
|
return s_ColorCopyProgram[1];
|
|
|
|
}
|
2011-06-11 19:37:21 +00:00
|
|
|
else
|
2010-11-27 11:11:05 +00:00
|
|
|
{
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-12 12:00:08 +00:00
|
|
|
std::string buf = StringFromFormat(color_copy_program_code_msaa, g_ActiveConfig.iMultisamples);
|
2014-07-07 23:28:12 +00:00
|
|
|
s_ColorCopyProgram[1] = D3D::CompileAndCreatePixelShader(buf);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_ColorCopyProgram[1]!=nullptr, "Create color copy MSAA pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorCopyProgram[1], "color copy MSAA pixel shader");
|
|
|
|
return s_ColorCopyProgram[1];
|
2010-11-27 11:11:05 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::GetColorMatrixProgram(bool multisampled)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2015-12-12 12:00:08 +00:00
|
|
|
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
|
2014-07-07 23:28:12 +00:00
|
|
|
{
|
|
|
|
return s_ColorMatrixProgram[0];
|
|
|
|
}
|
|
|
|
else if (s_ColorMatrixProgram[1])
|
|
|
|
{
|
|
|
|
return s_ColorMatrixProgram[1];
|
|
|
|
}
|
2011-06-11 19:37:21 +00:00
|
|
|
else
|
2010-11-27 11:11:05 +00:00
|
|
|
{
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-12 12:00:08 +00:00
|
|
|
std::string buf = StringFromFormat(color_matrix_program_code_msaa, g_ActiveConfig.iMultisamples);
|
2014-07-07 23:28:12 +00:00
|
|
|
s_ColorMatrixProgram[1] = D3D::CompileAndCreatePixelShader(buf);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_ColorMatrixProgram[1]!=nullptr, "Create color matrix MSAA pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorMatrixProgram[1], "color matrix MSAA pixel shader");
|
|
|
|
return s_ColorMatrixProgram[1];
|
2010-11-27 11:11:05 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::GetDepthMatrixProgram(bool multisampled)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2015-12-12 12:00:08 +00:00
|
|
|
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
|
2014-07-07 23:28:12 +00:00
|
|
|
{
|
|
|
|
return s_DepthMatrixProgram[0];
|
|
|
|
}
|
|
|
|
else if (s_DepthMatrixProgram[1])
|
|
|
|
{
|
|
|
|
return s_DepthMatrixProgram[1];
|
|
|
|
}
|
2011-06-11 19:37:21 +00:00
|
|
|
else
|
2010-11-27 11:11:05 +00:00
|
|
|
{
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-12 12:00:08 +00:00
|
|
|
std::string buf = StringFromFormat(depth_matrix_program_msaa, g_ActiveConfig.iMultisamples);
|
2014-07-07 23:28:12 +00:00
|
|
|
s_DepthMatrixProgram[1] = D3D::CompileAndCreatePixelShader(buf);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_DepthMatrixProgram[1]!=nullptr, "Create depth matrix MSAA pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_DepthMatrixProgram[1], "depth matrix MSAA pixel shader");
|
|
|
|
return s_DepthMatrixProgram[1];
|
2010-11-27 11:11:05 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ID3D11PixelShader* PixelShaderCache::GetClearProgram()
|
|
|
|
{
|
|
|
|
return s_ClearProgram;
|
|
|
|
}
|
|
|
|
|
2014-11-29 20:55:14 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::GetAnaglyphProgram()
|
|
|
|
{
|
|
|
|
return s_AnaglyphProgram;
|
|
|
|
}
|
|
|
|
|
2015-11-28 11:33:47 +00:00
|
|
|
ID3D11PixelShader* PixelShaderCache::GetDepthResolveProgram()
|
|
|
|
{
|
|
|
|
if (s_DepthResolveProgram != nullptr)
|
|
|
|
return s_DepthResolveProgram;
|
|
|
|
|
|
|
|
// create MSAA shader for current AA mode
|
2015-12-28 05:50:01 +00:00
|
|
|
std::string buf = StringFromFormat(depth_resolve_program, g_ActiveConfig.iMultisamples);
|
2015-11-28 11:33:47 +00:00
|
|
|
s_DepthResolveProgram = D3D::CompileAndCreatePixelShader(buf);
|
|
|
|
CHECK(s_DepthResolveProgram != nullptr, "Create depth matrix MSAA pixel shader");
|
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_DepthResolveProgram, "depth resolve pixel shader");
|
|
|
|
return s_DepthResolveProgram;
|
|
|
|
}
|
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
ID3D11Buffer* &PixelShaderCache::GetConstantBuffer()
|
2011-01-25 15:08:30 +00:00
|
|
|
{
|
|
|
|
// TODO: divide the global variables of the generated shaders into about 5 constant buffers to speed this up
|
2013-10-07 15:52:22 +00:00
|
|
|
if (PixelShaderManager::dirty)
|
2011-01-25 15:08:30 +00:00
|
|
|
{
|
|
|
|
D3D11_MAPPED_SUBRESOURCE map;
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::context->Map(pscbuf, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
2013-10-07 15:52:22 +00:00
|
|
|
memcpy(map.pData, &PixelShaderManager::constants, sizeof(PixelShaderConstants));
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::context->Unmap(pscbuf, 0);
|
2013-10-07 15:52:22 +00:00
|
|
|
PixelShaderManager::dirty = false;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-10-07 15:52:22 +00:00
|
|
|
ADDSTAT(stats.thisFrame.bytesUniformStreamed, sizeof(PixelShaderConstants));
|
2011-01-25 15:08:30 +00:00
|
|
|
}
|
|
|
|
return pscbuf;
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this class will load the precompiled shaders into our cache
|
2013-03-26 22:35:14 +00:00
|
|
|
class PixelShaderCacheInserter : public LinearDiskCacheReader<PixelShaderUid, u8>
|
2010-11-15 05:22:03 +00:00
|
|
|
{
|
2010-06-13 19:50:06 +00:00
|
|
|
public:
|
2014-12-12 16:25:16 +00:00
|
|
|
void Read(const PixelShaderUid &key, const u8* value, u32 value_size)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
PixelShaderCache::InsertByteCode(key, value, value_size);
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void PixelShaderCache::Init()
|
|
|
|
{
|
2014-12-17 08:37:29 +00:00
|
|
|
unsigned int cbsize = ROUND_UP(sizeof(PixelShaderConstants), 16); // must be a multiple of 16
|
2011-01-25 15:08:30 +00:00
|
|
|
D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
2014-03-09 20:14:26 +00:00
|
|
|
D3D::device->CreateBuffer(&cbdesc, nullptr, &pscbuf);
|
|
|
|
CHECK(pscbuf!=nullptr, "Create pixel shader constant buffer");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)pscbuf, "pixel shader constant buffer used to emulate the GX pipeline");
|
2011-01-25 15:08:30 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
// used when drawing clear quads
|
2014-07-07 23:28:12 +00:00
|
|
|
s_ClearProgram = D3D::CompileAndCreatePixelShader(clear_program_code);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_ClearProgram!=nullptr, "Create clear pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ClearProgram, "clear pixel shader");
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-11-29 20:55:14 +00:00
|
|
|
// used for anaglyph stereoscopy
|
|
|
|
s_AnaglyphProgram = D3D::CompileAndCreatePixelShader(anaglyph_program_code);
|
|
|
|
CHECK(s_AnaglyphProgram != nullptr, "Create anaglyph pixel shader");
|
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_AnaglyphProgram, "anaglyph pixel shader");
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
// used when copying/resolving the color buffer
|
2014-07-07 23:28:12 +00:00
|
|
|
s_ColorCopyProgram[0] = D3D::CompileAndCreatePixelShader(color_copy_program_code);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_ColorCopyProgram[0]!=nullptr, "Create color copy pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorCopyProgram[0], "color copy pixel shader");
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
// used for color conversion
|
2014-07-07 23:28:12 +00:00
|
|
|
s_ColorMatrixProgram[0] = D3D::CompileAndCreatePixelShader(color_matrix_program_code);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_ColorMatrixProgram[0]!=nullptr, "Create color matrix pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorMatrixProgram[0], "color matrix pixel shader");
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
// used for depth copy
|
2014-07-07 23:28:12 +00:00
|
|
|
s_DepthMatrixProgram[0] = D3D::CompileAndCreatePixelShader(depth_matrix_program);
|
2014-03-09 20:14:26 +00:00
|
|
|
CHECK(s_DepthMatrixProgram[0]!=nullptr, "Create depth matrix pixel shader");
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_DepthMatrixProgram[0], "depth matrix pixel shader");
|
2010-06-13 19:50:06 +00:00
|
|
|
|
|
|
|
Clear();
|
|
|
|
|
2011-03-01 03:06:14 +00:00
|
|
|
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
2014-03-12 19:33:41 +00:00
|
|
|
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
SETSTAT(stats.numPixelShadersCreated, 0);
|
|
|
|
SETSTAT(stats.numPixelShadersAlive, 0);
|
|
|
|
|
2014-06-03 05:08:54 +00:00
|
|
|
std::string cache_filename = StringFromFormat("%sdx11-%s-ps.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
2015-06-12 11:56:53 +00:00
|
|
|
SConfig::GetInstance().m_strUniqueID.c_str());
|
2011-06-11 19:37:21 +00:00
|
|
|
PixelShaderCacheInserter inserter;
|
|
|
|
g_ps_disk_cache.OpenAndRead(cache_filename, inserter);
|
2011-09-10 01:10:28 +00:00
|
|
|
|
2011-09-29 21:32:05 +00:00
|
|
|
if (g_Config.bEnableShaderDebugging)
|
2011-09-10 01:10:28 +00:00
|
|
|
Clear();
|
2011-09-29 20:54:52 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
last_entry = nullptr;
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ONLY to be used during shutdown.
|
|
|
|
void PixelShaderCache::Clear()
|
|
|
|
{
|
2014-02-12 15:00:34 +00:00
|
|
|
for (auto& iter : PixelShaders)
|
|
|
|
iter.second.Destroy();
|
2013-04-29 19:00:39 +00:00
|
|
|
PixelShaders.clear();
|
|
|
|
pixel_uid_checker.Invalidate();
|
2011-09-29 20:54:52 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
last_entry = nullptr;
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 11:11:05 +00:00
|
|
|
// Used in Swap() when AA mode has changed
|
|
|
|
void PixelShaderCache::InvalidateMSAAShaders()
|
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
SAFE_RELEASE(s_ColorCopyProgram[1]);
|
|
|
|
SAFE_RELEASE(s_ColorMatrixProgram[1]);
|
|
|
|
SAFE_RELEASE(s_DepthMatrixProgram[1]);
|
|
|
|
SAFE_RELEASE(s_rgb8_to_rgba6[1]);
|
|
|
|
SAFE_RELEASE(s_rgba6_to_rgb8[1]);
|
2015-11-28 11:33:47 +00:00
|
|
|
SAFE_RELEASE(s_DepthResolveProgram);
|
2010-11-27 11:11:05 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
void PixelShaderCache::Shutdown()
|
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
SAFE_RELEASE(pscbuf);
|
2011-01-25 15:08:30 +00:00
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
SAFE_RELEASE(s_ClearProgram);
|
2014-11-29 20:55:14 +00:00
|
|
|
SAFE_RELEASE(s_AnaglyphProgram);
|
2015-11-28 11:33:47 +00:00
|
|
|
SAFE_RELEASE(s_DepthResolveProgram);
|
2010-11-27 11:11:05 +00:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
SAFE_RELEASE(s_ColorCopyProgram[i]);
|
|
|
|
SAFE_RELEASE(s_ColorMatrixProgram[i]);
|
|
|
|
SAFE_RELEASE(s_DepthMatrixProgram[i]);
|
|
|
|
SAFE_RELEASE(s_rgba6_to_rgb8[i]);
|
|
|
|
SAFE_RELEASE(s_rgb8_to_rgba6[i]);
|
2010-11-27 11:11:05 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
Clear();
|
|
|
|
g_ps_disk_cache.Sync();
|
|
|
|
g_ps_disk_cache.Close();
|
|
|
|
}
|
|
|
|
|
2015-11-01 21:39:31 +00:00
|
|
|
bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2015-11-03 02:47:05 +00:00
|
|
|
PixelShaderUid uid = GetPixelShaderUid(dstAlphaMode, API_D3D);
|
2013-04-29 19:00:39 +00:00
|
|
|
if (g_ActiveConfig.bEnableShaderDebugging)
|
|
|
|
{
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode code = GeneratePixelShaderCode(dstAlphaMode, API_D3D);
|
2013-04-29 19:00:39 +00:00
|
|
|
pixel_uid_checker.AddToIndexAndCheck(code, uid, "Pixel", "p");
|
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Check if the shader is already set
|
2011-09-29 20:54:52 +00:00
|
|
|
if (last_entry)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-09-29 20:54:52 +00:00
|
|
|
if (uid == last_uid)
|
|
|
|
{
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
2014-03-09 20:14:26 +00:00
|
|
|
return (last_entry->shader != nullptr);
|
2011-09-29 20:54:52 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 20:54:52 +00:00
|
|
|
last_uid = uid;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Check if the shader is already in the cache
|
2010-06-13 19:50:06 +00:00
|
|
|
PSCache::iterator iter;
|
|
|
|
iter = PixelShaders.find(uid);
|
|
|
|
if (iter != PixelShaders.end())
|
|
|
|
{
|
|
|
|
const PSCacheEntry &entry = iter->second;
|
|
|
|
last_entry = &entry;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
|
2014-03-09 20:14:26 +00:00
|
|
|
return (entry.shader != nullptr);
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Need to compile a new shader
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode code = GeneratePixelShaderCode(dstAlphaMode, API_D3D);
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-06-11 19:37:21 +00:00
|
|
|
D3DBlob* pbytecode;
|
2014-07-07 23:28:12 +00:00
|
|
|
if (!D3D::CompilePixelShader(code.GetBuffer(), &pbytecode))
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
2010-06-13 19:50:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Insert the bytecode into the caches
|
2011-06-11 19:37:21 +00:00
|
|
|
g_ps_disk_cache.Append(uid, pbytecode->Data(), pbytecode->Size());
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-09-08 22:32:04 +00:00
|
|
|
bool success = InsertByteCode(uid, pbytecode->Data(), pbytecode->Size());
|
2011-06-11 19:37:21 +00:00
|
|
|
pbytecode->Release();
|
2011-09-08 22:32:04 +00:00
|
|
|
|
2011-09-09 19:34:46 +00:00
|
|
|
if (g_ActiveConfig.bEnableShaderDebugging && success)
|
2011-09-08 22:32:04 +00:00
|
|
|
{
|
2013-03-26 22:35:14 +00:00
|
|
|
PixelShaders[uid].code = code.GetBuffer();
|
2011-09-08 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-05 14:15:36 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
2011-09-08 22:32:04 +00:00
|
|
|
return success;
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2013-03-26 22:35:14 +00:00
|
|
|
bool PixelShaderCache::InsertByteCode(const PixelShaderUid &uid, const void* bytecode, unsigned int bytecodelen)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
ID3D11PixelShader* shader = D3D::CreatePixelShaderFromByteCode(bytecode, bytecodelen);
|
2014-03-09 20:14:26 +00:00
|
|
|
if (shader == nullptr)
|
2010-06-13 19:50:06 +00:00
|
|
|
return false;
|
2011-09-08 20:59:34 +00:00
|
|
|
|
2010-06-17 10:42:57 +00:00
|
|
|
// TODO: Somehow make the debug name a bit more specific
|
2011-06-11 19:37:21 +00:00
|
|
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)shader, "a pixel shader of PixelShaderCache");
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Make an entry in the table
|
2010-06-13 19:50:06 +00:00
|
|
|
PSCacheEntry newentry;
|
|
|
|
newentry.shader = shader;
|
|
|
|
PixelShaders[uid] = newentry;
|
|
|
|
last_entry = &PixelShaders[uid];
|
|
|
|
|
2014-08-30 20:54:18 +00:00
|
|
|
if (!shader)
|
|
|
|
{
|
2011-06-11 19:37:21 +00:00
|
|
|
// INCSTAT(stats.numPixelShadersFailed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
INCSTAT(stats.numPixelShadersCreated);
|
|
|
|
SETSTAT(stats.numPixelShadersAlive, PixelShaders.size());
|
|
|
|
return true;
|
2011-01-29 20:16:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
} // DX11
|