Skip to content

Commit

Permalink
Merge pull request #17922 from hrydgard/ubershader-developer-options
Browse files Browse the repository at this point in the history
Add checkboxes in developer tools to allow disabling ubershaders
  • Loading branch information
hrydgard authored Aug 17, 2023
2 parents 8fb5b06 + 89ff606 commit 2c46571
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 37 deletions.
3 changes: 3 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ static const ConfigSetting graphicsSettings[] = {

ConfigSetting("ShaderCache", &g_Config.bShaderCache, true, CfgFlag::DONT_SAVE), // Doesn't save. Ini-only.
ConfigSetting("GpuLogProfiler", &g_Config.bGpuLogProfiler, false, CfgFlag::DEFAULT),

ConfigSetting("UberShaderVertex", &g_Config.bUberShaderVertex, true, CfgFlag::DEFAULT),
ConfigSetting("UberShaderFragment", &g_Config.bUberShaderFragment, true, CfgFlag::DEFAULT),
};

static const ConfigSetting soundSettings[] = {
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ struct Config {
int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
bool bHardwareTessellation;
bool bShaderCache; // Hidden ini-only setting, useful for debugging shader compile times.
bool bUberShaderVertex;
bool bUberShaderFragment;

std::vector<std::string> vPostShaderNames; // Off for chain end (only Off for no shader)
std::map<std::string, float> mPostShaderSetting;
Expand Down
3 changes: 2 additions & 1 deletion GPU/Common/ShaderUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
int format = gstate_c.depalFramebufferFormat;
uint32_t val = BytesToUint32(indexMask, indexShift, indexOffset, format);
// Poke in a bilinear filter flag in the top bit.
val |= gstate.isMagnifyFilteringEnabled() << 31;
if (gstate.isMagnifyFilteringEnabled())
val |= 0x80000000;
ub->depal_mask_shift_off_fmt = val;
}
}
Expand Down
2 changes: 0 additions & 2 deletions GPU/D3D11/GPU_D3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ u32 GPU_D3D11::CheckGPUFeatures() const {
features |= GPU_USE_16BIT_FORMATS;
}

features |= GPU_USE_FRAGMENT_UBERSHADER;

return CheckGPUFeaturesLate(features);
}

Expand Down
3 changes: 0 additions & 3 deletions GPU/Directx9/GPU_DX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ u32 GPU_DX9::CheckGPUFeatures() const {
// So we cannot incorrectly use the viewport transform as the depth range on Direct3D.
features |= GPU_USE_ACCURATE_DEPTH;

// DX9 GPUs probably benefit more than they lose from this. Though, might be a vendor check.
features |= GPU_USE_FRAGMENT_UBERSHADER;

return CheckGPUFeaturesLate(features);
}

Expand Down
10 changes: 5 additions & 5 deletions GPU/GLES/GPU_GLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ u32 GPU_GLES::CheckGPUFeatures() const {
features |= GPU_USE_SINGLE_PASS_STEREO;
}

if (!gl_extensions.GLES3) {
// Heuristic.
features &= ~GPU_USE_FRAGMENT_UBERSHADER;
}

features = CheckGPUFeaturesLate(features);

if (draw_->GetBugs().Has(Draw::Bugs::ADRENO_RESOURCE_DEADLOCK) && g_Config.bVendorBugChecksEnabled) {
Expand All @@ -193,11 +198,6 @@ u32 GPU_GLES::CheckGPUFeatures() const {
features |= GPU_ROUND_DEPTH_TO_16BIT;
}
}

if (gl_extensions.GLES3) {
features |= GPU_USE_FRAGMENT_UBERSHADER;
}

return features;
}

Expand Down
7 changes: 6 additions & 1 deletion GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ u32 GPUCommonHW::CheckGPUFeatures() const {
features |= GPU_USE_FRAMEBUFFER_FETCH;
}

if (draw_->GetShaderLanguageDesc().bitwiseOps) {
if (draw_->GetShaderLanguageDesc().bitwiseOps && g_Config.bUberShaderVertex) {
features |= GPU_USE_LIGHT_UBERSHADER;
}

Expand All @@ -624,6 +624,11 @@ u32 GPUCommonHW::CheckGPUFeatures() const {
features |= GPU_USE_ACCURATE_DEPTH;
}

// Some backends will turn this off again in the calling function.
if (g_Config.bUberShaderFragment) {
features |= GPU_USE_FRAGMENT_UBERSHADER;
}

return features;
}

Expand Down
4 changes: 0 additions & 4 deletions GPU/Vulkan/GPU_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ u32 GPU_Vulkan::CheckGPUFeatures() const {
}
}

// Only a few low-power GPUs should probably avoid this.
// Let's figure that out later.
features |= GPU_USE_FRAGMENT_UBERSHADER;

// Attempt to workaround #17386
if (draw_->GetBugs().Has(Draw::Bugs::UNIFORM_INDEXING_BROKEN)) {
features &= ~GPU_USE_LIGHT_UBERSHADER;
Expand Down
53 changes: 34 additions & 19 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,26 @@ void DeveloperToolsScreen::CreateViews() {

LinearLayout *list = settingsScroll->Add(new LinearLayoutList(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)));
list->SetSpacing(0);

list->Add(new ItemHeader(dev->T("Texture Replacement")));
list->Add(new CheckBox(&g_Config.bSaveNewTextures, dev->T("Save new textures")));
list->Add(new CheckBox(&g_Config.bReplaceTextures, dev->T("Replace textures")));

Choice *createTextureIni = list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")));
createTextureIni->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
createTextureIni->SetEnabledFunc([&] {
if (!PSP_IsInited())
return false;

// Disable the choice to Open/Create if the textures.ini file already exists, and we can't open it due to platform support limitations.
if (!System_GetPropertyBool(SYSPROP_SUPPORTS_OPEN_FILE_IN_EDITOR)) {
if (hasTexturesIni_ == HasIni::MAYBE)
hasTexturesIni_ = TextureReplacer::IniExists(g_paramSFO.GetDiscID()) ? HasIni::YES : HasIni::NO;
return hasTexturesIni_ != HasIni::YES;
}
return true;
});

list->Add(new ItemHeader(sy->T("General")));

bool canUseJit = true;
Expand Down Expand Up @@ -1697,35 +1717,30 @@ void DeveloperToolsScreen::CreateViews() {
if (GetGPUBackend() == GPUBackend::VULKAN) {
list->Add(new CheckBox(&g_Config.bGpuLogProfiler, dev->T("GPU log profiler")));
}
list->Add(new ItemHeader(dev->T("Texture Replacement")));
list->Add(new CheckBox(&g_Config.bSaveNewTextures, dev->T("Save new textures")));
list->Add(new CheckBox(&g_Config.bReplaceTextures, dev->T("Replace textures")));

Choice *createTextureIni = list->Add(new Choice(dev->T("Create/Open textures.ini file for current game")));
createTextureIni->OnClick.Handle(this, &DeveloperToolsScreen::OnOpenTexturesIniFile);
createTextureIni->SetEnabledFunc([&] {
if (!PSP_IsInited())
return false;

// Disable the choice to Open/Create if the textures.ini file already exists, and we can't open it due to platform support limitations.
if (!System_GetPropertyBool(SYSPROP_SUPPORTS_OPEN_FILE_IN_EDITOR)) {
if (hasTexturesIni_ == HasIni::MAYBE)
hasTexturesIni_ = TextureReplacer::IniExists(g_paramSFO.GetDiscID()) ? HasIni::YES : HasIni::NO;
return hasTexturesIni_ != HasIni::YES;
}
return true;
});

Draw::DrawContext *draw = screenManager()->getDrawContext();

list->Add(new ItemHeader(dev->T("Ubershaders")));
if (draw->GetShaderLanguageDesc().bitwiseOps && !draw->GetBugs().Has(Draw::Bugs::UNIFORM_INDEXING_BROKEN)) {
// If the above if fails, the checkbox is redundant since it'll be force disabled anyway.
list->Add(new CheckBox(&g_Config.bUberShaderVertex, dev->T("Vertex")));
}
#if !PPSSPP_PLATFORM(UWP)
if (g_Config.iGPUBackend != (int)GPUBackend::OPENGL || gl_extensions.GLES3) {
#else
{
#endif
list->Add(new CheckBox(&g_Config.bUberShaderFragment, dev->T("Fragment")));
}

// Experimental, will move to main graphics settings later.
bool multiViewSupported = draw->GetDeviceCaps().multiViewSupported;

auto enableStereo = [=]() -> bool {
return g_Config.bStereoRendering && multiViewSupported;
};

if (draw->GetDeviceCaps().multiViewSupported) {
if (multiViewSupported) {
list->Add(new ItemHeader(gr->T("Stereo rendering")));
list->Add(new CheckBox(&g_Config.bStereoRendering, gr->T("Stereo rendering")));
std::vector<std::string> stereoShaderNames;
Expand Down
7 changes: 5 additions & 2 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ xBRZ = &xBRZ
[Developer]
Allocator Viewer = Allocator viewer (Vulkan)
Allow remote debugger = Allow remote debugger
Audio Debug = Audio Debug
Backspace = Backspace
Block address = Block address
By Address = By address
Control Debug = Control Debug
Copy savestates to memstick root = Copy save states to Memory Stick root
Create/Open textures.ini file for current game = Create/Open textures.ini file for current game
Current = Current
Expand All @@ -311,6 +313,7 @@ Dump next frame to log = Dump next frame to log
Enable driver bug workarounds = Enable driver bug workarounds
Enable Logging = Enable debug logging
Enter address = Enter address
Fragment = Fragment
FPU = FPU
Framedump tests = Framedump tests
Frame Profiler = Frame profiler
Expand Down Expand Up @@ -344,10 +347,10 @@ Stats = Stats
System Information = System information
Texture ini file created = Texture ini file created
Texture Replacement = Texture replacement
Audio Debug = Audio Debug
Control Debug = Control Debug
Toggle Freeze = Toggle freeze
Touchscreen Test = Touchscreen test
Ubershaders = Ubershaders
Vertex = Vertex
VFPU = VFPU
[Dialog]
Expand Down

0 comments on commit 2c46571

Please sign in to comment.