Merge pull request #3332 from degasus/master

MSAA: Store samples in ini files.
This commit is contained in:
Scott Mansell 2015-12-19 01:37:10 +13:00
commit ebe3c49c5f
12 changed files with 68 additions and 91 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include <map>
#include <string>
#include <utility>
@ -774,11 +775,11 @@ void VideoConfigDiag::PopulateAAList()
}
}
int selected_mode_index = vconfig.iMultisampleMode;
int selected_mode_index = 0;
// Don't go out of range
if (selected_mode_index >= aa_modes.size())
return;
auto index = std::find(aa_modes.begin(), aa_modes.end(), vconfig.iMultisamples);
if (index != aa_modes.end())
selected_mode_index = index - aa_modes.begin();
// Select one of the SSAA modes at the end of the list if SSAA is enabled
if (supports_ssaa && vconfig.bSSAA && aa_modes[selected_mode_index] != 1)
@ -789,11 +790,14 @@ void VideoConfigDiag::PopulateAAList()
void VideoConfigDiag::OnAAChanged(wxCommandEvent& ev)
{
int mode = ev.GetInt();
size_t mode = ev.GetInt();
ev.Skip();
vconfig.bSSAA = mode > m_msaa_modes;
mode -= vconfig.bSSAA * m_msaa_modes;
vconfig.iMultisampleMode = mode;
if (mode >= vconfig.backend_info.AAModes.size())
return;
vconfig.iMultisamples = vconfig.backend_info.AAModes[mode];
}

View File

@ -285,5 +285,5 @@ protected:
VideoConfig &vconfig;
std::string ininame;
int m_msaa_modes;
size_t m_msaa_modes;
};

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)

View File

@ -66,14 +66,6 @@ static int OSDInternalW, OSDInternalH;
namespace OGL
{
enum MultisampleMode
{
MULTISAMPLE_OFF,
MULTISAMPLE_2X,
MULTISAMPLE_4X,
MULTISAMPLE_8X,
};
VideoConfig g_ogl_config;
// Declarations and definitions
@ -82,7 +74,7 @@ static RasterFont* s_pfont = nullptr;
// 1 for no MSAA. Use s_MSAASamples > 1 to check for MSAA.
static int s_MSAASamples = 1;
static int s_last_multisample_mode = 0;
static int s_last_multisamples = 1;
static bool s_last_stereo_mode = false;
static bool s_last_xfb_mode = false;
@ -98,38 +90,6 @@ static bool s_efbCacheValid[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT];
static bool s_efbCacheIsCleared = false;
static std::vector<u32> s_efbCache[2][EFB_CACHE_WIDTH * EFB_CACHE_HEIGHT]; // 2 for PEEK_Z and PEEK_COLOR
static int GetNumMSAASamples(int MSAAMode)
{
int samples;
switch (MSAAMode)
{
case MULTISAMPLE_OFF:
samples = 1;
break;
case MULTISAMPLE_2X:
samples = 2;
break;
case MULTISAMPLE_4X:
samples = 4;
break;
case MULTISAMPLE_8X:
samples = 8;
break;
default:
samples = 1;
}
if (samples <= g_ogl_config.max_samples)
return samples;
// TODO: move this to InitBackendInfo
OSD::AddMessage(StringFromFormat("%d Anti Aliasing samples selected, but only %d supported by your GPU.", samples, g_ogl_config.max_samples), 10000);
return g_ogl_config.max_samples;
}
static void GLAPIENTRY ErrorCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char* message, const void* userParam)
{
const char *s_source;
@ -492,11 +452,11 @@ Renderer::Renderer()
g_Config.backend_info.bSupportsBBox = true;
g_ogl_config.bSupportsMSAA = true;
g_ogl_config.bSupports2DTextureStorage = true;
if (g_ActiveConfig.iStereoMode > 0 && g_ActiveConfig.iMultisampleMode > 1 && !g_ogl_config.bSupports3DTextureStorage)
if (g_ActiveConfig.iStereoMode > 0 && g_ActiveConfig.iMultisamples > 1 && !g_ogl_config.bSupports3DTextureStorage)
{
// GLES 3.1 can't support stereo rendering and MSAA
OSD::AddMessage("MSAA Stereo rendering isn't supported by your GPU.", 10000);
g_ActiveConfig.iMultisampleMode = 1;
g_ActiveConfig.iMultisamples = 1;
}
}
else
@ -628,8 +588,8 @@ Renderer::Renderer()
g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData "
);
s_last_multisample_mode = g_ActiveConfig.iMultisampleMode;
s_MSAASamples = GetNumMSAASamples(s_last_multisample_mode);
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_MSAASamples = s_last_multisamples;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
@ -1536,18 +1496,24 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, co
TargetSizeChanged = true;
}
if (TargetSizeChanged || xfbchanged || WindowResized ||
(s_last_multisample_mode != g_ActiveConfig.iMultisampleMode) || (s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)))
(s_last_multisamples != g_ActiveConfig.iMultisamples) || (s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)))
{
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
if (TargetSizeChanged ||
s_last_multisample_mode != g_ActiveConfig.iMultisampleMode || s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
s_last_multisamples != g_ActiveConfig.iMultisamples || s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
{
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_multisample_mode = g_ActiveConfig.iMultisampleMode;
s_MSAASamples = GetNumMSAASamples(s_last_multisample_mode);
s_last_multisamples = g_ActiveConfig.iMultisamples;
s_MSAASamples = s_last_multisamples;
if (s_MSAASamples > 1 && s_MSAASamples > g_ogl_config.max_samples)
{
s_MSAASamples = g_ogl_config.max_samples;
OSD::AddMessage(StringFromFormat("%d Anti Aliasing samples selected, but only %d supported by your GPU.", s_last_multisamples, g_ogl_config.max_samples), 10000);
}
delete g_framebuffer_manager;
g_framebuffer_manager = new FramebufferManager(s_target_width, s_target_height,

View File

@ -347,8 +347,8 @@ static inline T GeneratePixelShader(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
warn_once = false;
}
uid_data->msaa = g_ActiveConfig.iMultisampleMode > 0;
uid_data->ssaa = g_ActiveConfig.iMultisampleMode > 0 && g_ActiveConfig.bSSAA;
uid_data->msaa = g_ActiveConfig.iMultisamples > 1;
uid_data->ssaa = g_ActiveConfig.iMultisamples > 1 && g_ActiveConfig.bSSAA;
if (ApiType == API_OPENGL)
{
out.Write("out vec4 ocol0;\n");

View File

@ -295,7 +295,7 @@ static inline void AssignVSOutputMembers(T& object, const char* a, const char* b
// Without MSAA, this flag is defined to have no effect.
static inline const char* GetInterpolationQualifier(API_TYPE api_type, bool in = true, bool in_out = false)
{
if (!g_ActiveConfig.iMultisampleMode)
if (g_ActiveConfig.iMultisamples <= 1)
return "";
if (!g_ActiveConfig.bSSAA)

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include <cmath>
#include "Common/CommonTypes.h"
@ -76,7 +77,7 @@ void VideoConfig::Load(const std::string& ini_file)
settings->Get("UseFFV1", &bUseFFV1, 0);
settings->Get("EnablePixelLighting", &bEnablePixelLighting, 0);
settings->Get("FastDepthCalc", &bFastDepthCalc, true);
settings->Get("MSAA", &iMultisampleMode, 0);
settings->Get("MSAA", &iMultisamples, 1);
settings->Get("SSAA", &bSSAA, false);
settings->Get("EFBScale", &iEFBScale, (int)SCALE_1X); // native
settings->Get("TexFmtOverlayEnable", &bTexFmtOverlayEnable, 0);
@ -169,7 +170,7 @@ void VideoConfig::GameIniLoad()
CHECK_SETTING("Video_Settings", "CacheHiresTextures", bCacheHiresTextures);
CHECK_SETTING("Video_Settings", "EnablePixelLighting", bEnablePixelLighting);
CHECK_SETTING("Video_Settings", "FastDepthCalc", bFastDepthCalc);
CHECK_SETTING("Video_Settings", "MSAA", iMultisampleMode);
CHECK_SETTING("Video_Settings", "MSAA", iMultisamples);
CHECK_SETTING("Video_Settings", "SSAA", bSSAA);
int tmp = -9000;
@ -244,8 +245,11 @@ void VideoConfig::GameIniLoad()
void VideoConfig::VerifyValidity()
{
// TODO: Check iMaxAnisotropy value
if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1)) iAdapter = 0;
if (iMultisampleMode < 0 || iMultisampleMode >= (int)backend_info.AAModes.size()) iMultisampleMode = 0;
if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1))
iAdapter = 0;
if (std::find(backend_info.AAModes.begin(), backend_info.AAModes.end(), iMultisamples) == backend_info.AAModes.end())
iMultisamples = 1;
if (iStereoMode > 0)
{
@ -292,7 +296,7 @@ void VideoConfig::Save(const std::string& ini_file)
settings->Set("UseFFV1", bUseFFV1);
settings->Set("EnablePixelLighting", bEnablePixelLighting);
settings->Set("FastDepthCalc", bFastDepthCalc);
settings->Set("MSAA", iMultisampleMode);
settings->Set("MSAA", iMultisamples);
settings->Set("SSAA", bSSAA);
settings->Set("EFBScale", iEFBScale);
settings->Set("TexFmtOverlayEnable", bTexFmtOverlayEnable);

View File

@ -82,7 +82,7 @@ struct VideoConfig final
bool bUseRealXFB;
// Enhancements
int iMultisampleMode;
int iMultisamples;
bool bSSAA;
int iEFBScale;
bool bForceFiltering;