VideoConfig: Add config options for ubershaders

This commit is contained in:
Stenzek 2017-06-13 20:07:09 +10:00
parent 745d541527
commit 901bf9c257
12 changed files with 207 additions and 0 deletions

View File

@ -274,6 +274,10 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
{
putXfbSetting(which);
}
else if (scSetting.getKey().equals(SettingsFile.KEY_UBERSHADER_MODE))
{
putUberShaderModeSetting(which);
}
else if (scSetting.getKey().equals(SettingsFile.KEY_WIIMOTE_EXTENSION))
{
putExtensionSetting(which, Character.getNumericValue(scSetting.getSection().charAt(scSetting.getSection().length() - 1)));
@ -437,6 +441,33 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
mView.putSetting(xfbReal);
}
public void putUberShaderModeSetting(int which)
{
BooleanSetting disableSpecializedShaders = null;
BooleanSetting backgroundShaderCompilation = null;
switch (which)
{
case 0:
disableSpecializedShaders = new BooleanSetting(SettingsFile.KEY_DISABLE_SPECIALIZED_SHADERS, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, false);
backgroundShaderCompilation = new BooleanSetting(SettingsFile.KEY_BACKGROUND_SHADER_COMPILING, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, false);
break;
case 1:
disableSpecializedShaders = new BooleanSetting(SettingsFile.KEY_DISABLE_SPECIALIZED_SHADERS, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, true);
backgroundShaderCompilation = new BooleanSetting(SettingsFile.KEY_BACKGROUND_SHADER_COMPILING, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, false);
break;
case 2:
disableSpecializedShaders = new BooleanSetting(SettingsFile.KEY_DISABLE_SPECIALIZED_SHADERS, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, true);
backgroundShaderCompilation = new BooleanSetting(SettingsFile.KEY_BACKGROUND_SHADER_COMPILING, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, true);
break;
}
mView.putSetting(disableSpecializedShaders);
mView.putSetting(backgroundShaderCompilation);
}
public void putExtensionSetting(int which, int wiimoteNumber)
{
StringSetting extension = new StringSetting(SettingsFile.KEY_WIIMOTE_EXTENSION, SettingsFile.SECTION_WIIMOTE + wiimoteNumber,

View File

@ -276,6 +276,8 @@ public final class SettingsFragmentPresenter
private void addEnhanceSettings(ArrayList<SettingsItem> sl)
{
int uberShaderModeValue = getUberShaderModeValue();
Setting resolution = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_INTERNAL_RES);
Setting fsaa = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_FSAA);
Setting anisotropic = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_ENHANCEMENTS).getSetting(SettingsFile.KEY_ANISOTROPY);
@ -283,6 +285,7 @@ public final class SettingsFragmentPresenter
Setting perPixel = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_PER_PIXEL);
Setting forceFilter = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_ENHANCEMENTS).getSetting(SettingsFile.KEY_FORCE_FILTERING);
Setting disableFog = mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_DISABLE_FOG);
IntSetting uberShaderMode = new IntSetting(SettingsFile.KEY_UBERSHADER_MODE, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, uberShaderModeValue);
sl.add(new SingleChoiceSetting(SettingsFile.KEY_INTERNAL_RES, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, R.string.internal_resolution, R.string.internal_resolution_descrip, R.array.internalResolutionEntries, R.array.internalResolutionValues, 0, resolution));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_FSAA, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, R.string.FSAA, R.string.FSAA_descrip, R.array.FSAAEntries, R.array.FSAAValues, 0, fsaa));
@ -296,6 +299,7 @@ public final class SettingsFragmentPresenter
sl.add(new CheckBoxSetting(SettingsFile.KEY_PER_PIXEL, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, R.string.per_pixel_lighting, R.string.per_pixel_lighting_descrip, false, perPixel));
sl.add(new CheckBoxSetting(SettingsFile.KEY_FORCE_FILTERING, SettingsFile.SECTION_GFX_ENHANCEMENTS, SettingsFile.SETTINGS_GFX, R.string.force_texture_filtering, R.string.force_texture_filtering_descrip, false, forceFilter));
sl.add(new CheckBoxSetting(SettingsFile.KEY_DISABLE_FOG, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, R.string.disable_fog, R.string.disable_fog_descrip, false, disableFog));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_UBERSHADER_MODE, SettingsFile.SECTION_GFX_SETTINGS, SettingsFile.SETTINGS_GFX, R.string.ubershader_mode, R.string.ubershader_mode_descrip, R.array.uberShaderModeEntries, R.array.uberShaderModeValues, 0, uberShaderMode));
/*
Check if we support stereo
@ -903,6 +907,29 @@ public final class SettingsFragmentPresenter
return xfbValue;
}
private int getUberShaderModeValue()
{
int uberShaderModeValue = 0;
try
{
boolean backgroundShaderCompiling = ((BooleanSetting) mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_BACKGROUND_SHADER_COMPILING)).getValue();
boolean disableSpecializedShaders = ((BooleanSetting) mSettings.get(SettingsFile.SETTINGS_GFX).get(SettingsFile.SECTION_GFX_SETTINGS).getSetting(SettingsFile.KEY_DISABLE_SPECIALIZED_SHADERS)).getValue();
if (disableSpecializedShaders)
uberShaderModeValue = 2; // Exclusive
else if (backgroundShaderCompiling)
uberShaderModeValue = 1; // Hybrid
else
uberShaderModeValue = 0; // Disabled
}
catch (NullPointerException ex)
{
}
return uberShaderModeValue;
}
private int getExtensionValue(int wiimoteNumber)
{
int extensionValue;

View File

@ -79,6 +79,9 @@ public final class SettingsFile
public static final String KEY_XFB_REAL = "UseRealXFB";
public static final String KEY_FAST_DEPTH = "FastDepthCalc";
public static final String KEY_ASPECT_RATIO = "AspectRatio";
public static final String KEY_UBERSHADER_MODE = "UberShaderMode";
public static final String KEY_DISABLE_SPECIALIZED_SHADERS = "DisableSpecializedShaders";
public static final String KEY_BACKGROUND_SHADER_COMPILING = "BackgroundShaderCompiling";
public static final String KEY_GCPAD_TYPE = "SIDevice";

View File

@ -89,6 +89,18 @@
<item>2</item>
</integer-array>
<!-- Ubershader Mode Preference -->
<string-array name="uberShaderModeEntries" translatable="false">
<item>Disabled</item>
<item>Hybrid</item>
<item>Exclusive</item>
</string-array>
<integer-array name="uberShaderModeValues" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</integer-array>
<!-- Internal Resolution Preference -->
<string-array name="internalResolutionEntries" translatable="false">
<item>1x Native (640x528)</item>

View File

@ -179,6 +179,8 @@
<string name="fast_depth_calculation_descrip">Uses a less accurate algorithm to calculate depth values.</string>
<string name="aspect_ratio">Aspect Ratio</string>
<string name="aspect_ratio_descrip">Select what aspect ratio to use when rendering</string>
<string name="ubershader_mode">Ubershader Mode</string>
<string name="ubershader_mode_descrip">Specifies when to use Ubershaders. Disabled - Never, Hybrid - Use ubershaders while compiling specialized shaders. Exclusive - Use only ubershaders, largest performance impact.</string>
<!-- Miscellaneous -->
<string name="yes">Yes</string>

View File

@ -77,6 +77,18 @@ const ConfigInfo<bool> GFX_BACKEND_MULTITHREADING{
const ConfigInfo<int> GFX_COMMAND_BUFFER_EXECUTE_INTERVAL{
{System::GFX, "Settings", "CommandBufferExecuteInterval"}, 100};
const ConfigInfo<bool> GFX_SHADER_CACHE{{System::GFX, "Settings", "ShaderCache"}, true};
const ConfigInfo<bool> GFX_BACKGROUND_SHADER_COMPILING{
{System::GFX, "Settings", "BackgroundShaderCompiling"}, false};
const ConfigInfo<bool> GFX_DISABLE_SPECIALIZED_SHADERS{
{System::GFX, "Settings", "DisableSpecializedShaders"}, false};
const ConfigInfo<bool> GFX_PRECOMPILE_UBER_SHADERS{
{System::GFX, "Settings", "PrecompileUberShaders"}, true};
const ConfigInfo<int> GFX_SHADER_COMPILER_THREADS{
{System::GFX, "Settings", "ShaderCompilerThreads"}, 1};
const ConfigInfo<bool> GFX_FORCE_VERTEX_UBER_SHADERS{
{System::GFX, "Settings", "ForceVertexUberShaders"}, false};
const ConfigInfo<bool> GFX_FORCE_PIXEL_UBER_SHADERS{
{System::GFX, "Settings", "ForcePixelUberShaders"}, false};
const ConfigInfo<bool> GFX_SW_ZCOMPLOC{{System::GFX, "Settings", "SWZComploc"}, true};
const ConfigInfo<bool> GFX_SW_ZFREEZE{{System::GFX, "Settings", "SWZFreeze"}, true};

View File

@ -59,6 +59,12 @@ extern const ConfigInfo<bool> GFX_ENABLE_VALIDATION_LAYER;
extern const ConfigInfo<bool> GFX_BACKEND_MULTITHREADING;
extern const ConfigInfo<int> GFX_COMMAND_BUFFER_EXECUTE_INTERVAL;
extern const ConfigInfo<bool> GFX_SHADER_CACHE;
extern const ConfigInfo<bool> GFX_BACKGROUND_SHADER_COMPILING;
extern const ConfigInfo<bool> GFX_DISABLE_SPECIALIZED_SHADERS;
extern const ConfigInfo<bool> GFX_PRECOMPILE_UBER_SHADERS;
extern const ConfigInfo<int> GFX_SHADER_COMPILER_THREADS;
extern const ConfigInfo<bool> GFX_FORCE_VERTEX_UBER_SHADERS;
extern const ConfigInfo<bool> GFX_FORCE_PIXEL_UBER_SHADERS;
extern const ConfigInfo<bool> GFX_SW_ZCOMPLOC;
extern const ConfigInfo<bool> GFX_SW_ZFREEZE;

View File

@ -43,6 +43,10 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location)
Config::GFX_DISABLE_FOG.location, Config::GFX_BORDERLESS_FULLSCREEN.location,
Config::GFX_ENABLE_VALIDATION_LAYER.location, Config::GFX_BACKEND_MULTITHREADING.location,
Config::GFX_COMMAND_BUFFER_EXECUTE_INTERVAL.location, Config::GFX_SHADER_CACHE.location,
Config::GFX_BACKGROUND_SHADER_COMPILING.location,
Config::GFX_DISABLE_SPECIALIZED_SHADERS.location,
Config::GFX_PRECOMPILE_UBER_SHADERS.location, Config::GFX_SHADER_COMPILER_THREADS.location,
Config::GFX_FORCE_VERTEX_UBER_SHADERS.location, Config::GFX_FORCE_PIXEL_UBER_SHADERS.location,
Config::GFX_SW_ZCOMPLOC.location, Config::GFX_SW_ZFREEZE.location,
Config::GFX_SW_DUMP_OBJECTS.location, Config::GFX_SW_DUMP_TEV_STAGES.location,

View File

@ -308,6 +308,14 @@ static wxString gpu_texture_decoding_desc =
wxTRANSLATE("Enables texture decoding using the GPU instead of the CPU. This may result in "
"performance gains in some scenarios, or on systems where the CPU is the "
"bottleneck.\n\nIf unsure, leave this unchecked.");
static wxString ubershader_desc =
wxTRANSLATE("Disabled: Ubershaders are never used. Stuttering will occur during shader "
"compilation, but GPU demands are low. Recommended for low-end hardware.\n\n"
"Hybrid: Ubershaders will be used to prevent stuttering during shader "
"compilation, but traditional shaders will be used when they will not cause "
"stuttering. Balances performance and smoothness.\n\n"
"Exclusive: Ubershaders will always be used. Only recommended for high-end "
"systems.");
VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title)
: wxDialog(parent, wxID_ANY, wxString::Format(_("Dolphin %s Graphics Configuration"),
@ -561,6 +569,29 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title)
row += 1;
}
// ubershaders
{
const std::array<wxString, 3> mode_choices = {{_("Disabled"), _("Hybrid"), _("Exclusive")}};
wxChoice* const choice_mode =
new wxChoice(page_enh, wxID_ANY, wxDefaultPosition, wxDefaultSize,
static_cast<int>(mode_choices.size()), mode_choices.data());
RegisterControl(choice_mode, wxGetTranslation(ubershader_desc));
szr_enh->Add(new wxStaticText(page_enh, wxID_ANY, _("Ubershaders:")), wxGBPosition(row, 0),
wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
szr_enh->Add(choice_mode, wxGBPosition(row, 1), span2, wxALIGN_CENTER_VERTICAL);
row += 1;
// Determine ubershader mode
choice_mode->Bind(wxEVT_CHOICE, &VideoConfigDiag::OnUberShaderModeChanged, this);
if (Config::GetBase(Config::GFX_DISABLE_SPECIALIZED_SHADERS))
choice_mode->SetSelection(2);
else if (Config::GetBase(Config::GFX_BACKGROUND_SHADER_COMPILING))
choice_mode->SetSelection(1);
else
choice_mode->SetSelection(0);
}
// postproc shader
if (vconfig.backend_info.bSupportsPostProcessing)
{
@ -1326,3 +1357,13 @@ void VideoConfigDiag::OnAAChanged(wxCommandEvent& ev)
Config::SetBaseOrCurrent(Config::GFX_MSAA, vconfig.backend_info.AAModes[mode]);
}
void VideoConfigDiag::OnUberShaderModeChanged(wxCommandEvent& ev)
{
// 0: No ubershaders
// 1: Hybrid ubershaders
// 2: Only ubershaders
int mode = ev.GetInt();
Config::SetBaseOrCurrent(Config::GFX_BACKGROUND_SHADER_COMPILING, mode == 1);
Config::SetBaseOrCurrent(Config::GFX_DISABLE_SPECIALIZED_SHADERS, mode == 2);
}

View File

@ -140,6 +140,7 @@ protected:
void PopulatePostProcessingShaders();
void PopulateAAList();
void OnAAChanged(wxCommandEvent& ev);
void OnUberShaderModeChanged(wxCommandEvent& ev);
wxChoice* choice_backend;
wxChoice* choice_adapter;

View File

@ -4,6 +4,7 @@
#include <algorithm>
#include "Common/CPUDetect.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Core/Config/GraphicsSettings.h"
@ -93,6 +94,12 @@ void VideoConfig::Refresh()
bBackendMultithreading = Config::Get(Config::GFX_BACKEND_MULTITHREADING);
iCommandBufferExecuteInterval = Config::Get(Config::GFX_COMMAND_BUFFER_EXECUTE_INTERVAL);
bShaderCache = Config::Get(Config::GFX_SHADER_CACHE);
bBackgroundShaderCompiling = Config::Get(Config::GFX_BACKGROUND_SHADER_COMPILING);
bDisableSpecializedShaders = Config::Get(Config::GFX_DISABLE_SPECIALIZED_SHADERS);
bPrecompileUberShaders = Config::Get(Config::GFX_PRECOMPILE_UBER_SHADERS);
iShaderCompilerThreads = Config::Get(Config::GFX_SHADER_COMPILER_THREADS);
bForceVertexUberShaders = Config::Get(Config::GFX_FORCE_VERTEX_UBER_SHADERS);
bForcePixelUberShaders = Config::Get(Config::GFX_FORCE_PIXEL_UBER_SHADERS);
bZComploc = Config::Get(Config::GFX_SW_ZCOMPLOC);
bZFreeze = Config::Get(Config::GFX_SW_ZFREEZE);
@ -188,3 +195,31 @@ bool VideoConfig::IsVSync()
{
return bVSync && !Core::GetIsThrottlerTempDisabled();
}
u32 VideoConfig::GetShaderCompilerThreads() const
{
if (iShaderCompilerThreads >= 0)
return static_cast<u32>(iShaderCompilerThreads);
// Automatic number. We use clamp(cpus - 3, 1, 4).
return static_cast<u32>(std::min(std::max(cpu_info.num_cores - 3, 1), 4));
}
bool VideoConfig::CanUseUberShaders() const
{
// Ubershaders are currently incompatible with per-pixel lighting.
return !bEnablePixelLighting;
}
bool VideoConfig::CanPrecompileUberShaders() const
{
// We don't want to precompile ubershaders if they're never going to be used.
return bPrecompileUberShaders && (bBackgroundShaderCompiling || bDisableSpecializedShaders) &&
CanUseUberShaders();
}
bool VideoConfig::CanBackgroundCompileShaders() const
{
// We require precompiled ubershaders to background compile shaders.
return bBackgroundShaderCompiling && bPrecompileUberShaders && CanUseUberShaders();
}

View File

@ -168,6 +168,35 @@ struct VideoConfig final
// Currently only supported with Vulkan.
int iCommandBufferExecuteInterval;
// The following options determine the ubershader mode:
// No ubershaders:
// - bBackgroundShaderCompiling = false
// - bDisableSpecializedShaders = false
// Hybrid/background compiling:
// - bBackgroundShaderCompiling = true
// - bDisableSpecializedShaders = false
// Ubershaders only:
// - bBackgroundShaderCompiling = false
// - bDisableSpecializedShaders = true
// Enable background shader compiling, use ubershaders while waiting.
bool bBackgroundShaderCompiling;
// Use ubershaders only, don't compile specialized shaders.
bool bDisableSpecializedShaders;
// Precompile ubershader variants at boot/config reload time.
bool bPrecompileUberShaders;
// Number of shader compiler threads.
// 0 disables background compilation.
// -1 uses an automatic number based on the CPU threads.
int iShaderCompilerThreads;
// Temporary toggling of ubershaders, for debugging
bool bForceVertexUberShaders;
bool bForcePixelUberShaders;
// Static config per API
// TODO: Move this out of VideoConfig
struct
@ -226,6 +255,10 @@ struct VideoConfig final
return backend_info.bSupportsGPUTextureDecoding && bEnableGPUTextureDecoding;
}
bool UseVertexRounding() const { return bVertexRounding && iEFBScale != SCALE_1X; }
u32 GetShaderCompilerThreads() const;
bool CanUseUberShaders() const;
bool CanPrecompileUberShaders() const;
bool CanBackgroundCompileShaders() const;
};
extern VideoConfig g_Config;