MSAA: Store samples in ini files.

This commit is contained in:
degasus
2015-12-12 13:00:08 +01:00
parent cc3dc05438
commit e26d9f7c35
12 changed files with 68 additions and 91 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include "Common/StringUtil.h"
#include "VideoBackends/D3D/D3DBase.h"
#include "VideoBackends/D3D/D3DState.h"
@ -199,11 +201,6 @@ D3D_FEATURE_LEVEL GetFeatureLevel(IDXGIAdapter* adapter)
return feat_level;
}
DXGI_SAMPLE_DESC GetAAMode(int index)
{
return aa_modes[index];
}
HRESULT Create(HWND wnd)
{
hWnd = wnd;
@ -258,9 +255,14 @@ HRESULT Create(HWND wnd)
// get supported AA modes
aa_modes = EnumAAModes(adapter);
if (g_Config.iMultisampleMode >= (int)aa_modes.size())
if (std::find_if(
aa_modes.begin(),
aa_modes.end(),
[](const DXGI_SAMPLE_DESC& desc) {return desc.Count == g_Config.iMultisamples;}
) == aa_modes.end())
{
g_Config.iMultisampleMode = 0;
g_Config.iMultisamples = 1;
UpdateActiveConfig();
}

View File

@ -33,7 +33,6 @@ void UnloadD3DCompiler();
D3D_FEATURE_LEVEL GetFeatureLevel(IDXGIAdapter* adapter);
std::vector<DXGI_SAMPLE_DESC> EnumAAModes(IDXGIAdapter* adapter);
DXGI_SAMPLE_DESC GetAAMode(int index);
HRESULT Create(HWND wnd);
void Close();

View File

@ -30,7 +30,7 @@ ID3D11Texture2D* &FramebufferManager::GetEFBDepthStagingBuffer() { return m_efb.
D3DTexture2D* &FramebufferManager::GetResolvedEFBColorTexture()
{
if (g_ActiveConfig.iMultisampleMode)
if (g_ActiveConfig.iMultisamples > 1)
{
for (int i = 0; i < m_efb.slices; i++)
D3D::context->ResolveSubresource(m_efb.resolved_color_tex->GetTex(), D3D11CalcSubresource(0, i, 1), m_efb.color_tex->GetTex(), D3D11CalcSubresource(0, i, 1), DXGI_FORMAT_R8G8B8A8_UNORM);
@ -42,7 +42,7 @@ D3DTexture2D* &FramebufferManager::GetResolvedEFBColorTexture()
D3DTexture2D* &FramebufferManager::GetResolvedEFBDepthTexture()
{
if (g_ActiveConfig.iMultisampleMode)
if (g_ActiveConfig.iMultisamples > 1)
{
for (int i = 0; i < m_efb.slices; i++)
D3D::context->ResolveSubresource(m_efb.resolved_depth_tex->GetTex(), D3D11CalcSubresource(0, i, 1), m_efb.depth_tex->GetTex(), D3D11CalcSubresource(0, i, 1), DXGI_FORMAT_R24_UNORM_X8_TYPELESS);
@ -64,7 +64,9 @@ FramebufferManager::FramebufferManager()
{
m_target_width = 1;
}
DXGI_SAMPLE_DESC sample_desc = D3D::GetAAMode(g_ActiveConfig.iMultisampleMode);
DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples;
sample_desc.Quality = 0;
ID3D11Texture2D* buf;
D3D11_TEXTURE2D_DESC texdesc;
@ -125,7 +127,7 @@ FramebufferManager::FramebufferManager()
CHECK(hr==S_OK, "create EFB depth staging buffer (hr=%#x)", hr);
D3D::SetDebugObjectName((ID3D11DeviceChild*)m_efb.depth_staging_buf, "EFB depth staging texture (used for Renderer::AccessEFB)");
if (g_ActiveConfig.iMultisampleMode)
if (g_ActiveConfig.iMultisamples > 1)
{
// Framebuffer resolve textures (color+depth)
texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM, m_target_width, m_target_height, m_efb.slices, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, 0, 1);

View File

@ -287,7 +287,7 @@ const char reint_rgb8_to_rgba6_msaa[] = {
ID3D11PixelShader* PixelShaderCache::ReinterpRGBA6ToRGB8(bool multisampled)
{
if (!multisampled || D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count == 1)
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
{
if (!s_rgba6_to_rgb8[0])
{
@ -300,7 +300,7 @@ ID3D11PixelShader* PixelShaderCache::ReinterpRGBA6ToRGB8(bool multisampled)
else if (!s_rgba6_to_rgb8[1])
{
// create MSAA shader for current AA mode
std::string buf = StringFromFormat(reint_rgba6_to_rgb8_msaa, D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count);
std::string buf = StringFromFormat(reint_rgba6_to_rgb8_msaa, g_ActiveConfig.iMultisamples);
s_rgba6_to_rgb8[1] = D3D::CompileAndCreatePixelShader(buf);
CHECK(s_rgba6_to_rgb8[1], "Create RGBA6 to RGB8 MSAA pixel shader");
@ -311,7 +311,7 @@ ID3D11PixelShader* PixelShaderCache::ReinterpRGBA6ToRGB8(bool multisampled)
ID3D11PixelShader* PixelShaderCache::ReinterpRGB8ToRGBA6(bool multisampled)
{
if (!multisampled || D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count == 1)
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
{
if (!s_rgb8_to_rgba6[0])
{
@ -324,7 +324,7 @@ ID3D11PixelShader* PixelShaderCache::ReinterpRGB8ToRGBA6(bool multisampled)
else if (!s_rgb8_to_rgba6[1])
{
// create MSAA shader for current AA mode
std::string buf = StringFromFormat(reint_rgb8_to_rgba6_msaa, D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count);
std::string buf = StringFromFormat(reint_rgb8_to_rgba6_msaa, g_ActiveConfig.iMultisamples);
s_rgb8_to_rgba6[1] = D3D::CompileAndCreatePixelShader(buf);
CHECK(s_rgb8_to_rgba6[1], "Create RGB8 to RGBA6 MSAA pixel shader");
@ -335,7 +335,7 @@ ID3D11PixelShader* PixelShaderCache::ReinterpRGB8ToRGBA6(bool multisampled)
ID3D11PixelShader* PixelShaderCache::GetColorCopyProgram(bool multisampled)
{
if (!multisampled || D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count == 1)
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
{
return s_ColorCopyProgram[0];
}
@ -346,7 +346,7 @@ ID3D11PixelShader* PixelShaderCache::GetColorCopyProgram(bool multisampled)
else
{
// create MSAA shader for current AA mode
std::string buf = StringFromFormat(color_copy_program_code_msaa, D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count);
std::string buf = StringFromFormat(color_copy_program_code_msaa, g_ActiveConfig.iMultisamples);
s_ColorCopyProgram[1] = D3D::CompileAndCreatePixelShader(buf);
CHECK(s_ColorCopyProgram[1]!=nullptr, "Create color copy MSAA pixel shader");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorCopyProgram[1], "color copy MSAA pixel shader");
@ -356,7 +356,7 @@ ID3D11PixelShader* PixelShaderCache::GetColorCopyProgram(bool multisampled)
ID3D11PixelShader* PixelShaderCache::GetColorMatrixProgram(bool multisampled)
{
if (!multisampled || D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count == 1)
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
{
return s_ColorMatrixProgram[0];
}
@ -367,7 +367,7 @@ ID3D11PixelShader* PixelShaderCache::GetColorMatrixProgram(bool multisampled)
else
{
// create MSAA shader for current AA mode
std::string buf = StringFromFormat(color_matrix_program_code_msaa, D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count);
std::string buf = StringFromFormat(color_matrix_program_code_msaa, g_ActiveConfig.iMultisamples);
s_ColorMatrixProgram[1] = D3D::CompileAndCreatePixelShader(buf);
CHECK(s_ColorMatrixProgram[1]!=nullptr, "Create color matrix MSAA pixel shader");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_ColorMatrixProgram[1], "color matrix MSAA pixel shader");
@ -377,7 +377,7 @@ ID3D11PixelShader* PixelShaderCache::GetColorMatrixProgram(bool multisampled)
ID3D11PixelShader* PixelShaderCache::GetDepthMatrixProgram(bool multisampled)
{
if (!multisampled || D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count == 1)
if (!multisampled || g_ActiveConfig.iMultisamples <= 1)
{
return s_DepthMatrixProgram[0];
}
@ -388,7 +388,7 @@ ID3D11PixelShader* PixelShaderCache::GetDepthMatrixProgram(bool multisampled)
else
{
// create MSAA shader for current AA mode
std::string buf = StringFromFormat(depth_matrix_program_msaa, D3D::GetAAMode(g_ActiveConfig.iMultisampleMode).Count);
std::string buf = StringFromFormat(depth_matrix_program_msaa, g_ActiveConfig.iMultisamples);
s_DepthMatrixProgram[1] = D3D::CompileAndCreatePixelShader(buf);
CHECK(s_DepthMatrixProgram[1]!=nullptr, "Create depth matrix MSAA pixel shader");
D3D::SetDebugObjectName((ID3D11DeviceChild*)s_DepthMatrixProgram[1], "depth matrix MSAA pixel shader");

View File

@ -42,7 +42,7 @@
namespace DX11
{
static u32 s_last_multisample_mode = 0;
static u32 s_last_multisamples = 1;
static bool s_last_stereo_mode = false;
static bool s_last_xfb_mode = false;
@ -246,7 +246,7 @@ Renderer::Renderer(void *&window_handle)
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
s_last_multisample_mode = g_ActiveConfig.iMultisampleMode;
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
@ -958,11 +958,11 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
windowResized ||
fullscreen_changed ||
s_last_efb_scale != g_ActiveConfig.iEFBScale ||
s_last_multisample_mode != g_ActiveConfig.iMultisampleMode ||
s_last_multisamples != g_ActiveConfig.iMultisamples ||
s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
{
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
s_last_multisample_mode = g_ActiveConfig.iMultisampleMode;
s_last_multisamples = g_ActiveConfig.iMultisamples;
PixelShaderCache::InvalidateMSAAShaders();
if (windowResized || fullscreen_changed)