Skip to content

Commit

Permalink
Merge pull request #3332 from degasus/master
Browse files Browse the repository at this point in the history
MSAA: Store samples in ini files.
  • Loading branch information
phire committed Dec 18, 2015
2 parents 7a78df2 + e26d9f7 commit ebe3c49
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 91 deletions.
16 changes: 10 additions & 6 deletions Source/Core/DolphinWX/VideoConfigDiag.cpp
Expand Up @@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <algorithm>
#include <map>
#include <string>
#include <utility>
Expand Down Expand Up @@ -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)
Expand All @@ -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];
}
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/VideoConfigDiag.h
Expand Up @@ -285,5 +285,5 @@ class VideoConfigDiag : public wxDialog
VideoConfig &vconfig;
std::string ininame;

int m_msaa_modes;
size_t m_msaa_modes;
};
16 changes: 9 additions & 7 deletions Source/Core/VideoBackends/D3D/D3DBase.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 0 additions & 1 deletion Source/Core/VideoBackends/D3D/D3DBase.h
Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/VideoBackends/D3D/FramebufferManager.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/VideoBackends/D3D/PixelShaderCache.cpp
Expand Up @@ -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])
{
Expand All @@ -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");
Expand All @@ -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])
{
Expand All @@ -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");
Expand All @@ -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];
}
Expand All @@ -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");
Expand All @@ -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];
}
Expand All @@ -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");
Expand All @@ -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];
}
Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/VideoBackends/D3D/Render.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
64 changes: 15 additions & 49 deletions Source/Core/VideoBackends/OGL/Render.cpp
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/PixelShaderGen.cpp
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/ShaderGenCommon.h
Expand Up @@ -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)
Expand Down

0 comments on commit ebe3c49

Please sign in to comment.