2017-02-19 21:02:30 +00:00
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
// Copyright (c) 2015- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2018-03-17 14:42:07 +00:00
|
|
|
#include <thread>
|
2019-09-04 19:42:47 +00:00
|
|
|
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2020-08-15 10:25:39 +00:00
|
|
|
#include "Common/Log.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "Common/GraphicsContext.h"
|
2020-08-15 18:53:08 +00:00
|
|
|
#include "Common/Serialize/Serializer.h"
|
|
|
|
#include "Common/TimeUtil.h"
|
2023-09-23 23:07:08 +00:00
|
|
|
#include "Common/Thread/ThreadUtil.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/Debugger/Breakpoints.h"
|
|
|
|
#include "Core/MemMapHelpers.h"
|
|
|
|
#include "Core/Reporting.h"
|
|
|
|
#include "Core/System.h"
|
2018-03-13 22:22:21 +00:00
|
|
|
#include "Core/ELF/ParamSFO.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
|
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "GPU/GeDisasm.h"
|
2020-08-03 21:17:22 +00:00
|
|
|
#include "GPU/Common/FramebufferManagerCommon.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "GPU/Vulkan/ShaderManagerVulkan.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/Vulkan/GPU_Vulkan.h"
|
2020-08-03 21:22:11 +00:00
|
|
|
#include "GPU/Vulkan/FramebufferManagerVulkan.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
#include "GPU/Vulkan/DrawEngineVulkan.h"
|
|
|
|
#include "GPU/Vulkan/TextureCacheVulkan.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/Vulkan/VulkanRenderManager.h"
|
|
|
|
#include "Common/GPU/Vulkan/VulkanQueueRunner.h"
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2017-01-30 15:50:35 +00:00
|
|
|
GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
|
2023-02-25 13:24:59 +00:00
|
|
|
: GPUCommonHW(gfxCtx, draw), drawEngine_(draw) {
|
2022-12-13 15:53:53 +00:00
|
|
|
gstate_c.SetUseFlags(CheckGPUFeatures());
|
2022-10-02 03:01:23 +00:00
|
|
|
drawEngine_.InitDeviceObjects();
|
2016-01-05 20:18:43 +00:00
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)gfxCtx->GetAPIContext();
|
2021-12-19 21:49:42 +00:00
|
|
|
|
|
|
|
vulkan->SetProfilerEnabledPtr(&g_Config.bGpuLogProfiler);
|
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
shaderManagerVulkan_ = new ShaderManagerVulkan(draw);
|
|
|
|
pipelineManager_ = new PipelineManagerVulkan(vulkan);
|
|
|
|
framebufferManagerVulkan_ = new FramebufferManagerVulkan(draw);
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManager_ = framebufferManagerVulkan_;
|
2022-08-23 09:11:04 +00:00
|
|
|
textureCacheVulkan_ = new TextureCacheVulkan(draw, framebufferManager_->GetDraw2D(), vulkan);
|
2016-12-21 17:07:17 +00:00
|
|
|
textureCache_ = textureCacheVulkan_;
|
2017-01-21 19:42:40 +00:00
|
|
|
drawEngineCommon_ = &drawEngine_;
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManager_ = shaderManagerVulkan_;
|
2016-12-21 17:07:17 +00:00
|
|
|
|
|
|
|
drawEngine_.SetTextureCache(textureCacheVulkan_);
|
|
|
|
drawEngine_.SetFramebufferManager(framebufferManagerVulkan_);
|
2017-01-23 19:48:23 +00:00
|
|
|
drawEngine_.SetShaderManager(shaderManagerVulkan_);
|
2016-01-09 00:23:32 +00:00
|
|
|
drawEngine_.SetPipelineManager(pipelineManager_);
|
2021-05-08 16:10:23 +00:00
|
|
|
drawEngine_.Init();
|
2016-12-21 17:07:17 +00:00
|
|
|
framebufferManagerVulkan_->SetTextureCache(textureCacheVulkan_);
|
|
|
|
framebufferManagerVulkan_->SetDrawEngine(&drawEngine_);
|
2017-02-19 21:02:30 +00:00
|
|
|
framebufferManagerVulkan_->SetShaderManager(shaderManagerVulkan_);
|
2022-12-14 14:15:31 +00:00
|
|
|
framebufferManagerVulkan_->Init(msaaLevel_);
|
2017-10-30 11:05:08 +00:00
|
|
|
textureCacheVulkan_->SetFramebufferManager(framebufferManagerVulkan_);
|
2017-01-23 19:48:23 +00:00
|
|
|
textureCacheVulkan_->SetShaderManager(shaderManagerVulkan_);
|
2017-02-04 10:47:19 +00:00
|
|
|
textureCacheVulkan_->SetDrawEngine(&drawEngine_);
|
2017-10-30 11:05:08 +00:00
|
|
|
|
|
|
|
InitDeviceObjects();
|
2016-01-05 20:18:43 +00:00
|
|
|
|
|
|
|
// Sanity check gstate
|
|
|
|
if ((int *)&gstate.transferstart - (int *)&gstate != 0xEA) {
|
2024-07-14 12:42:59 +00:00
|
|
|
ERROR_LOG(Log::G3D, "gstate has drifted out of sync!");
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BuildReportingInfo();
|
2016-03-26 18:44:22 +00:00
|
|
|
|
2022-09-08 06:41:00 +00:00
|
|
|
textureCache_->NotifyConfigChanged();
|
2018-03-13 22:22:21 +00:00
|
|
|
|
|
|
|
// Load shader cache.
|
|
|
|
std::string discID = g_paramSFO.GetDiscID();
|
2018-12-15 09:44:05 +00:00
|
|
|
if (discID.size()) {
|
2018-03-13 22:22:21 +00:00
|
|
|
File::CreateFullPath(GetSysDirectory(DIRECTORY_APP_CACHE));
|
2021-05-05 23:31:38 +00:00
|
|
|
shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) / (discID + ".vkshadercache");
|
2023-09-24 08:45:43 +00:00
|
|
|
LoadCache(shaderCachePath_);
|
2018-03-13 22:22:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
void GPU_Vulkan::LoadCache(const Path &filename) {
|
2021-11-21 20:23:15 +00:00
|
|
|
if (!g_Config.bShaderCache) {
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "Shader cache disabled. Not loading.");
|
2021-11-21 20:23:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
PSP_SetLoading("Loading shader cache...");
|
|
|
|
// Actually precompiled by IsReady() since we're single-threaded.
|
|
|
|
FILE *f = File::OpenCFile(filename, "rb");
|
|
|
|
if (!f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// First compile shaders to SPIR-V, then load the pipeline cache and recreate the pipelines.
|
|
|
|
// It's when recreating the pipelines that the pipeline cache is useful - in the ideal case,
|
|
|
|
// it can just memcpy the finished shader binaries out of the pipeline cache file.
|
2022-12-14 05:32:11 +00:00
|
|
|
bool result = shaderManagerVulkan_->LoadCacheFlags(f, &drawEngine_);
|
2022-12-13 15:35:02 +00:00
|
|
|
if (!result) {
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "ShaderManagerVulkan failed to load cache header.");
|
2022-12-14 05:32:11 +00:00
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
// Reload use flags in case LoadCacheFlags() changed them.
|
2022-12-14 06:00:51 +00:00
|
|
|
if (drawEngineCommon_->EverUsedExactEqualDepth()) {
|
|
|
|
sawExactEqualDepth_ = true;
|
|
|
|
}
|
2022-12-14 05:32:11 +00:00
|
|
|
gstate_c.SetUseFlags(CheckGPUFeatures());
|
|
|
|
result = shaderManagerVulkan_->LoadCache(f);
|
|
|
|
if (!result) {
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "ShaderManagerVulkan failed to load cache.");
|
2022-12-14 05:32:11 +00:00
|
|
|
}
|
2022-12-13 15:35:02 +00:00
|
|
|
}
|
2018-03-13 22:22:21 +00:00
|
|
|
if (result) {
|
2022-12-13 18:18:20 +00:00
|
|
|
// WARNING: See comment in LoadPipelineCache if you are tempted to flip the second parameter to true.
|
2022-12-14 14:15:31 +00:00
|
|
|
result = pipelineManager_->LoadPipelineCache(f, false, shaderManagerVulkan_, draw_, drawEngine_.GetPipelineLayout(), msaaLevel_);
|
2018-03-13 22:22:21 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
2022-12-14 14:15:31 +00:00
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
if (!result) {
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "Incompatible Vulkan pipeline cache - rebuilding.");
|
2018-03-13 22:22:21 +00:00
|
|
|
// Bad cache file for this GPU/Driver/etc. Delete it.
|
|
|
|
File::Delete(filename);
|
|
|
|
} else {
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "Loaded Vulkan pipeline cache.");
|
2018-03-13 22:22:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
void GPU_Vulkan::SaveCache(const Path &filename) {
|
2021-11-21 20:23:15 +00:00
|
|
|
if (!g_Config.bShaderCache) {
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "Shader cache disabled. Not saving.");
|
2021-11-21 20:23:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:26:29 +00:00
|
|
|
if (!draw_) {
|
|
|
|
// Already got the lost message, we're in shutdown.
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "Not saving shaders - shutting down from in-game.");
|
2018-04-05 18:26:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
FILE *f = File::OpenCFile(filename, "wb");
|
|
|
|
if (!f)
|
|
|
|
return;
|
2022-12-14 05:32:11 +00:00
|
|
|
shaderManagerVulkan_->SaveCache(f, &drawEngine_);
|
2019-07-23 15:45:52 +00:00
|
|
|
// WARNING: See comment in LoadCache if you are tempted to flip the second parameter to true.
|
2022-12-13 18:18:20 +00:00
|
|
|
pipelineManager_->SavePipelineCache(f, false, shaderManagerVulkan_, draw_);
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "Saved Vulkan pipeline cache");
|
2018-03-13 22:22:21 +00:00
|
|
|
fclose(f);
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GPU_Vulkan::~GPU_Vulkan() {
|
2023-05-03 20:33:34 +00:00
|
|
|
if (draw_) {
|
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2023-10-11 07:04:28 +00:00
|
|
|
// This now also does a hard sync with the render thread, so that we can safely delete our pipeline layout below.
|
2024-01-22 10:06:50 +00:00
|
|
|
rm->StopThreads();
|
2024-01-24 10:36:25 +00:00
|
|
|
rm->CheckNothingPending();
|
2023-05-03 20:33:34 +00:00
|
|
|
}
|
2023-05-02 20:04:14 +00:00
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
SaveCache(shaderCachePath_);
|
2023-09-20 16:43:33 +00:00
|
|
|
|
2024-01-23 23:50:32 +00:00
|
|
|
// StopThreads should have ensured that no pipelines are queued to compile at this point. So we can tear it down.
|
2023-09-20 16:43:33 +00:00
|
|
|
delete pipelineManager_;
|
|
|
|
pipelineManager_ = nullptr;
|
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
// Note: We save the cache in DeviceLost
|
2017-10-30 11:05:08 +00:00
|
|
|
DestroyDeviceObjects();
|
2017-12-03 10:02:49 +00:00
|
|
|
drawEngine_.DeviceLost();
|
2023-02-25 15:12:24 +00:00
|
|
|
shaderManager_->ClearShaders();
|
|
|
|
|
|
|
|
// other managers are deleted in ~GPUCommonHW.
|
2023-09-18 14:42:22 +00:00
|
|
|
if (draw_) {
|
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2024-01-22 10:06:50 +00:00
|
|
|
rm->StartThreads();
|
2023-09-18 14:42:22 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 08:02:15 +00:00
|
|
|
u32 GPU_Vulkan::CheckGPUFeatures() const {
|
2023-02-25 15:12:24 +00:00
|
|
|
uint32_t features = GPUCommonHW::CheckGPUFeatures();
|
2017-11-21 10:56:42 +00:00
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
2023-05-03 09:53:32 +00:00
|
|
|
|
2023-04-03 20:36:13 +00:00
|
|
|
// Could simplify this, but it's good as documentation.
|
2021-11-14 23:25:28 +00:00
|
|
|
switch (vulkan->GetPhysicalDeviceProperties().properties.vendorID) {
|
2017-12-10 18:20:11 +00:00
|
|
|
case VULKAN_VENDOR_AMD:
|
|
|
|
// Accurate depth is required on AMD (due to reverse-Z driver bug) so we ignore the compat flag to disable it on those. See #9545
|
2022-10-17 06:30:27 +00:00
|
|
|
features |= GPU_USE_ACCURATE_DEPTH;
|
2017-12-10 18:20:11 +00:00
|
|
|
break;
|
2019-02-26 14:21:21 +00:00
|
|
|
case VULKAN_VENDOR_QUALCOMM:
|
|
|
|
// Accurate depth is required on Adreno too (seems to also have a reverse-Z driver bug).
|
2022-10-17 06:30:27 +00:00
|
|
|
features |= GPU_USE_ACCURATE_DEPTH;
|
2019-02-26 14:21:21 +00:00
|
|
|
break;
|
2017-12-10 18:20:11 +00:00
|
|
|
case VULKAN_VENDOR_ARM:
|
2019-09-04 19:42:47 +00:00
|
|
|
{
|
|
|
|
// This check is probably not exactly accurate. But old drivers had problems with reverse-Z, just like AMD and Qualcomm.
|
2022-04-17 21:02:17 +00:00
|
|
|
|
|
|
|
// NOTE: Galaxy S8 has version 16 but still seems to have some problems with accurate depth.
|
|
|
|
|
2023-05-03 09:53:32 +00:00
|
|
|
// TODO: Move this check to thin3d_vulkan.
|
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
bool driverTooOld = IsHashMaliDriverVersion(vulkan->GetPhysicalDeviceProperties().properties)
|
|
|
|
|| VK_VERSION_MAJOR(vulkan->GetPhysicalDeviceProperties().properties.driverVersion) < 14;
|
2022-04-17 21:02:17 +00:00
|
|
|
|
2019-09-04 19:42:47 +00:00
|
|
|
if (!PSP_CoreParameter().compat.flags().DisableAccurateDepth || driverTooOld) {
|
2022-10-17 06:30:27 +00:00
|
|
|
features |= GPU_USE_ACCURATE_DEPTH;
|
2022-11-13 16:04:47 +00:00
|
|
|
} else {
|
|
|
|
features &= ~GPU_USE_ACCURATE_DEPTH;
|
2017-12-10 18:20:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-09-04 19:42:47 +00:00
|
|
|
}
|
2023-04-03 20:36:13 +00:00
|
|
|
case VULKAN_VENDOR_IMGTEC:
|
|
|
|
// We ignore the disable flag on IMGTec. Another reverse-Z bug (plus, not really any reason to bother). See #17044
|
|
|
|
features |= GPU_USE_ACCURATE_DEPTH;
|
|
|
|
break;
|
2017-12-10 18:20:11 +00:00
|
|
|
default:
|
2023-04-03 20:36:13 +00:00
|
|
|
// On other GPUs we'll just assume we don't need inaccurate depth, leaving ARM Mali as the odd one out.
|
|
|
|
features |= GPU_USE_ACCURATE_DEPTH;
|
2017-12-10 18:20:11 +00:00
|
|
|
break;
|
2017-11-21 10:56:42 +00:00
|
|
|
}
|
2017-11-21 12:58:42 +00:00
|
|
|
|
2018-12-10 23:22:16 +00:00
|
|
|
// Might enable this later - in the first round we are mostly looking at depth/stencil/discard.
|
2021-02-01 08:22:58 +00:00
|
|
|
// if (!g_Config.bEnableVendorBugChecks)
|
2022-10-17 06:30:27 +00:00
|
|
|
// features |= GPU_USE_ACCURATE_DEPTH;
|
2018-12-10 23:22:16 +00:00
|
|
|
|
2017-11-21 12:58:42 +00:00
|
|
|
// Mandatory features on Vulkan, which may be checked in "centralized" code
|
2022-10-17 06:30:27 +00:00
|
|
|
features |= GPU_USE_TEXTURE_LOD_CONTROL;
|
|
|
|
features |= GPU_USE_INSTANCE_RENDERING;
|
|
|
|
features |= GPU_USE_VERTEX_TEXTURE_FETCH;
|
|
|
|
features |= GPU_USE_TEXTURE_FLOAT;
|
2022-02-19 19:40:27 +00:00
|
|
|
|
2022-10-02 03:39:22 +00:00
|
|
|
// Fall back to geometry shader culling if we can't do vertex range culling.
|
2022-11-27 07:27:59 +00:00
|
|
|
// Checking accurate depth here because the old depth path is uncommon and not well tested for this.
|
|
|
|
if (draw_->GetDeviceCaps().geometryShaderSupported && (features & GPU_USE_ACCURATE_DEPTH) != 0) {
|
2022-10-09 07:57:10 +00:00
|
|
|
const bool useGeometry = g_Config.bUseGeometryShader && !draw_->GetBugs().Has(Draw::Bugs::GEOMETRY_SHADERS_SLOW_OR_BROKEN);
|
2022-10-02 03:39:22 +00:00
|
|
|
const bool vertexSupported = draw_->GetDeviceCaps().clipDistanceSupported && draw_->GetDeviceCaps().cullDistanceSupported;
|
2022-10-17 06:30:27 +00:00
|
|
|
if (useGeometry && (!vertexSupported || (features & GPU_USE_VS_RANGE_CULLING) == 0)) {
|
2022-10-02 03:39:22 +00:00
|
|
|
// Switch to culling via the geometry shader if not fully supported in vertex.
|
2022-10-17 06:30:27 +00:00
|
|
|
features |= GPU_USE_GS_CULLING;
|
|
|
|
features &= ~GPU_USE_VS_RANGE_CULLING;
|
2021-10-26 07:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-29 14:48:27 +00:00
|
|
|
if (!draw_->GetBugs().Has(Draw::Bugs::PVR_BAD_16BIT_TEXFORMATS)) {
|
|
|
|
// These are VULKAN_4444_FORMAT and friends.
|
|
|
|
// Note that we are now using the correct set of formats - the only cases where some may be missing
|
|
|
|
// are non-conformant implementations like MoltenVK.
|
|
|
|
uint32_t fmt4444 = draw_->GetDataFormatSupport(Draw::DataFormat::B4G4R4A4_UNORM_PACK16);
|
|
|
|
uint32_t fmt1555 = draw_->GetDataFormatSupport(Draw::DataFormat::A1R5G5B5_UNORM_PACK16);
|
|
|
|
uint32_t fmt565 = draw_->GetDataFormatSupport(Draw::DataFormat::R5G6B5_UNORM_PACK16);
|
|
|
|
if ((fmt4444 & Draw::FMT_TEXTURE) && (fmt565 & Draw::FMT_TEXTURE) && (fmt1555 & Draw::FMT_TEXTURE)) {
|
|
|
|
features |= GPU_USE_16BIT_FORMATS;
|
|
|
|
} else {
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "Deficient texture format support: 4444: %d 1555: %d 565: %d", fmt4444, fmt1555, fmt565);
|
2024-01-29 14:48:27 +00:00
|
|
|
}
|
2020-03-01 13:07:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 14:02:18 +00:00
|
|
|
if (g_Config.bStereoRendering && draw_->GetDeviceCaps().multiViewSupported) {
|
2022-10-17 22:26:10 +00:00
|
|
|
features |= GPU_USE_SINGLE_PASS_STEREO;
|
2022-10-26 14:02:18 +00:00
|
|
|
features |= GPU_USE_SIMPLE_STEREO_PERSPECTIVE;
|
|
|
|
|
2022-10-23 19:50:00 +00:00
|
|
|
if (features & GPU_USE_GS_CULLING) {
|
|
|
|
// Many devices that support stereo and GS don't support GS during stereo.
|
|
|
|
features &= ~GPU_USE_GS_CULLING;
|
|
|
|
features |= GPU_USE_VS_RANGE_CULLING;
|
|
|
|
}
|
2022-10-17 22:26:10 +00:00
|
|
|
}
|
|
|
|
|
2023-05-03 09:53:32 +00:00
|
|
|
// Attempt to workaround #17386
|
|
|
|
if (draw_->GetBugs().Has(Draw::Bugs::UNIFORM_INDEXING_BROKEN)) {
|
|
|
|
features &= ~GPU_USE_LIGHT_UBERSHADER;
|
|
|
|
}
|
|
|
|
|
2023-09-18 14:25:00 +00:00
|
|
|
features |= GPU_USE_FRAMEBUFFER_ARRAYS;
|
2022-11-13 16:04:47 +00:00
|
|
|
return CheckGPUFeaturesLate(features);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
void GPU_Vulkan::BeginHostFrame() {
|
2023-02-25 15:12:24 +00:00
|
|
|
GPUCommonHW::BeginHostFrame();
|
2016-01-08 00:05:52 +00:00
|
|
|
|
2022-11-21 16:55:30 +00:00
|
|
|
drawEngine_.BeginFrame();
|
2023-02-25 14:59:35 +00:00
|
|
|
textureCache_->StartFrame();
|
2017-10-30 11:05:08 +00:00
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
|
|
|
int curFrame = vulkan->GetCurFrame();
|
2016-01-08 00:05:52 +00:00
|
|
|
|
2023-02-25 14:59:35 +00:00
|
|
|
framebufferManager_->BeginFrame();
|
2017-10-30 11:05:08 +00:00
|
|
|
|
2023-09-24 09:50:24 +00:00
|
|
|
shaderManagerVulkan_->DirtyLastShader();
|
2017-01-24 08:41:38 +00:00
|
|
|
gstate_c.Dirty(DIRTY_ALL);
|
2016-03-21 23:12:41 +00:00
|
|
|
|
2022-12-14 06:00:51 +00:00
|
|
|
if (gstate_c.useFlagsChanged) {
|
|
|
|
// TODO: It'd be better to recompile them in the background, probably?
|
|
|
|
// This most likely means that saw equal depth changed.
|
2024-07-14 12:42:59 +00:00
|
|
|
WARN_LOG(Log::G3D, "Shader use flags changed, clearing all shaders and depth buffers");
|
2023-02-09 23:42:46 +00:00
|
|
|
// TODO: Not all shaders need to be recompiled. In fact, quite few? Of course, depends on
|
|
|
|
// the use flag change.. This is a major frame rate hitch in the start of a race in Outrun.
|
2023-02-25 14:59:35 +00:00
|
|
|
shaderManager_->ClearShaders();
|
2023-01-09 08:48:41 +00:00
|
|
|
pipelineManager_->Clear();
|
2023-02-09 23:42:46 +00:00
|
|
|
framebufferManager_->ClearAllDepthBuffers();
|
2022-12-14 06:00:51 +00:00
|
|
|
gstate_c.useFlagsChanged = false;
|
|
|
|
}
|
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
if (dumpNextFrame_) {
|
2024-07-14 12:42:59 +00:00
|
|
|
NOTICE_LOG(Log::G3D, "DUMPING THIS FRAME");
|
2016-01-08 00:05:52 +00:00
|
|
|
dumpThisFrame_ = true;
|
|
|
|
dumpNextFrame_ = false;
|
|
|
|
} else if (dumpThisFrame_) {
|
|
|
|
dumpThisFrame_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::EndHostFrame() {
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
2017-10-30 11:05:08 +00:00
|
|
|
|
2016-01-08 00:05:52 +00:00
|
|
|
drawEngine_.EndFrame();
|
2020-08-22 08:50:39 +00:00
|
|
|
|
2023-02-25 15:12:24 +00:00
|
|
|
GPUCommonHW::EndHostFrame();
|
2016-01-08 00:05:52 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
// Needs to be called on GPU thread, not reporting thread.
|
|
|
|
void GPU_Vulkan::BuildReportingInfo() {
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
|
|
|
const auto &props = vulkan->GetPhysicalDeviceProperties().properties;
|
2022-10-23 20:05:33 +00:00
|
|
|
const auto &available = vulkan->GetDeviceFeatures().available;
|
2016-03-27 15:52:55 +00:00
|
|
|
|
2022-10-23 20:05:33 +00:00
|
|
|
#define CHECK_BOOL_FEATURE(n) do { if (available.standard.n) { featureNames += ", " #n; } } while (false)
|
2022-10-26 16:39:43 +00:00
|
|
|
#define CHECK_BOOL_FEATURE_MULTIVIEW(n) do { if (available.multiview.n) { featureNames += ", " #n; } } while (false)
|
2016-03-27 15:52:55 +00:00
|
|
|
|
|
|
|
std::string featureNames = "";
|
|
|
|
CHECK_BOOL_FEATURE(fullDrawIndexUint32);
|
|
|
|
CHECK_BOOL_FEATURE(geometryShader);
|
|
|
|
CHECK_BOOL_FEATURE(sampleRateShading);
|
|
|
|
CHECK_BOOL_FEATURE(dualSrcBlend);
|
|
|
|
CHECK_BOOL_FEATURE(logicOp);
|
|
|
|
CHECK_BOOL_FEATURE(multiDrawIndirect);
|
|
|
|
CHECK_BOOL_FEATURE(drawIndirectFirstInstance);
|
|
|
|
CHECK_BOOL_FEATURE(depthClamp);
|
|
|
|
CHECK_BOOL_FEATURE(depthBiasClamp);
|
|
|
|
CHECK_BOOL_FEATURE(depthBounds);
|
|
|
|
CHECK_BOOL_FEATURE(samplerAnisotropy);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionETC2);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionASTC_LDR);
|
|
|
|
CHECK_BOOL_FEATURE(textureCompressionBC);
|
|
|
|
CHECK_BOOL_FEATURE(occlusionQueryPrecise);
|
|
|
|
CHECK_BOOL_FEATURE(pipelineStatisticsQuery);
|
|
|
|
CHECK_BOOL_FEATURE(fragmentStoresAndAtomics);
|
|
|
|
CHECK_BOOL_FEATURE(shaderTessellationAndGeometryPointSize);
|
|
|
|
CHECK_BOOL_FEATURE(shaderStorageImageMultisample);
|
|
|
|
CHECK_BOOL_FEATURE(shaderSampledImageArrayDynamicIndexing);
|
|
|
|
CHECK_BOOL_FEATURE(shaderClipDistance);
|
|
|
|
CHECK_BOOL_FEATURE(shaderCullDistance);
|
|
|
|
CHECK_BOOL_FEATURE(shaderInt64);
|
|
|
|
CHECK_BOOL_FEATURE(shaderInt16);
|
2022-10-26 16:39:43 +00:00
|
|
|
CHECK_BOOL_FEATURE_MULTIVIEW(multiview);
|
|
|
|
CHECK_BOOL_FEATURE_MULTIVIEW(multiviewGeometryShader);
|
2016-03-27 15:52:55 +00:00
|
|
|
|
2016-03-27 16:26:34 +00:00
|
|
|
#undef CHECK_BOOL_FEATURE
|
|
|
|
|
2016-03-27 15:52:55 +00:00
|
|
|
if (!featureNames.empty()) {
|
|
|
|
featureNames = featureNames.substr(2);
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
char temp[16384];
|
2016-03-27 15:52:55 +00:00
|
|
|
snprintf(temp, sizeof(temp), "v%08x driver v%08x (%s), vendorID=%d, deviceID=%d (features: %s)", props.apiVersion, props.driverVersion, props.deviceName, props.vendorID, props.deviceID, featureNames.c_str());
|
|
|
|
reportingPrimaryInfo_ = props.deviceName;
|
2016-01-05 20:18:43 +00:00
|
|
|
reportingFullInfo_ = temp;
|
|
|
|
|
|
|
|
Reporting::UpdateConfig();
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::FinishDeferred() {
|
2017-11-16 15:27:24 +00:00
|
|
|
drawEngine_.FinishDeferred();
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 11:05:08 +00:00
|
|
|
void GPU_Vulkan::InitDeviceObjects() {
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "GPU_Vulkan::InitDeviceObjects");
|
2018-04-13 15:32:36 +00:00
|
|
|
|
|
|
|
uint32_t hacks = 0;
|
2018-04-13 16:05:04 +00:00
|
|
|
if (PSP_CoreParameter().compat.flags().MGS2AcidHack)
|
2018-04-13 15:32:36 +00:00
|
|
|
hacks |= QUEUE_HACK_MGS2_ACID;
|
2018-04-13 16:05:04 +00:00
|
|
|
if (PSP_CoreParameter().compat.flags().SonicRivalsHack)
|
|
|
|
hacks |= QUEUE_HACK_SONIC;
|
2019-11-03 17:22:48 +00:00
|
|
|
|
|
|
|
// Always on.
|
|
|
|
hacks |= QUEUE_HACK_RENDERPASS_MERGE;
|
2019-08-13 21:07:58 +00:00
|
|
|
|
2018-04-13 15:32:36 +00:00
|
|
|
if (hacks) {
|
2023-03-14 22:38:52 +00:00
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2018-04-13 15:32:36 +00:00
|
|
|
rm->GetQueueRunner()->EnableHacks(hacks);
|
|
|
|
}
|
2017-10-30 11:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_Vulkan::DestroyDeviceObjects() {
|
2024-07-14 12:42:59 +00:00
|
|
|
INFO_LOG(Log::G3D, "GPU_Vulkan::DestroyDeviceObjects");
|
2018-04-13 15:32:36 +00:00
|
|
|
// Need to turn off hacks when shutting down the GPU. Don't want them running in the menu.
|
2018-04-14 20:14:05 +00:00
|
|
|
if (draw_) {
|
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
|
|
|
if (rm)
|
|
|
|
rm->GetQueueRunner()->EnableHacks(0);
|
|
|
|
}
|
2017-10-30 11:05:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:41:31 +00:00
|
|
|
void GPU_Vulkan::CheckRenderResized() {
|
|
|
|
if (renderResized_) {
|
2023-02-26 18:54:30 +00:00
|
|
|
GPUCommonHW::CheckRenderResized();
|
2022-12-01 22:41:31 +00:00
|
|
|
pipelineManager_->InvalidateMSAAPipelines();
|
|
|
|
framebufferManager_->ReleasePipelines();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
void GPU_Vulkan::DeviceLost() {
|
2023-09-25 23:15:40 +00:00
|
|
|
// draw_ is normally actually still valid here in Vulkan. But we null it out in GPUCommonHW::DeviceLost so we don't try to use it again.
|
2023-10-11 07:04:28 +00:00
|
|
|
// So, we have to save it here to be able to call ReleaseCompileQueue().
|
2023-09-25 23:15:40 +00:00
|
|
|
Draw::DrawContext *draw = draw_;
|
|
|
|
if (draw) {
|
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2024-01-22 10:06:50 +00:00
|
|
|
rm->StopThreads();
|
2023-09-25 23:15:40 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
if (shaderCachePath_.Valid()) {
|
2018-03-13 22:22:21 +00:00
|
|
|
SaveCache(shaderCachePath_);
|
|
|
|
}
|
2017-10-30 11:05:08 +00:00
|
|
|
DestroyDeviceObjects();
|
2016-10-09 18:27:16 +00:00
|
|
|
pipelineManager_->DeviceLost();
|
2020-11-06 23:56:48 +00:00
|
|
|
|
2023-02-25 14:59:35 +00:00
|
|
|
GPUCommonHW::DeviceLost();
|
2023-09-25 23:15:40 +00:00
|
|
|
|
|
|
|
if (draw) {
|
|
|
|
VulkanRenderManager *rm = (VulkanRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2024-01-22 10:06:50 +00:00
|
|
|
rm->StartThreads();
|
2023-09-25 23:15:40 +00:00
|
|
|
}
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 22:04:27 +00:00
|
|
|
void GPU_Vulkan::DeviceRestore(Draw::DrawContext *draw) {
|
|
|
|
GPUCommonHW::DeviceRestore(draw);
|
2016-10-09 18:27:16 +00:00
|
|
|
|
2021-11-14 23:25:28 +00:00
|
|
|
VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT);
|
|
|
|
pipelineManager_->DeviceRestore(vulkan);
|
2023-02-26 10:05:52 +00:00
|
|
|
|
|
|
|
InitDeviceObjects();
|
2016-09-11 03:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 08:17:02 +00:00
|
|
|
void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) {
|
2020-09-20 19:33:06 +00:00
|
|
|
size_t offset = FormatGPUStatsCommon(buffer, bufsize);
|
|
|
|
buffer += offset;
|
|
|
|
bufsize -= offset;
|
|
|
|
if ((int)bufsize < 0)
|
|
|
|
return;
|
2016-03-31 08:23:40 +00:00
|
|
|
const DrawEngineVulkanStats &drawStats = drawEngine_.GetStats();
|
2017-12-03 09:29:41 +00:00
|
|
|
char texStats[256];
|
|
|
|
textureCacheVulkan_->GetStats(texStats, sizeof(texStats));
|
2020-09-20 19:33:06 +00:00
|
|
|
snprintf(buffer, bufsize,
|
2016-03-31 08:23:40 +00:00
|
|
|
"Vertex, Fragment, Pipelines loaded: %i, %i, %i\n"
|
2023-03-15 09:19:00 +00:00
|
|
|
"Pushbuffer space used: Vtx %d, Idx %d\n"
|
2017-12-03 09:29:41 +00:00
|
|
|
"%s\n",
|
2017-01-23 19:48:23 +00:00
|
|
|
shaderManagerVulkan_->GetNumVertexShaders(),
|
|
|
|
shaderManagerVulkan_->GetNumFragmentShaders(),
|
2016-03-31 08:23:40 +00:00
|
|
|
pipelineManager_->GetNumPipelines(),
|
|
|
|
drawStats.pushVertexSpaceUsed,
|
2017-12-03 09:29:41 +00:00
|
|
|
drawStats.pushIndexSpaceUsed,
|
|
|
|
texStats
|
2016-03-31 08:17:02 +00:00
|
|
|
);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> GPU_Vulkan::DebugGetShaderIDs(DebugShaderType type) {
|
2023-02-25 15:40:52 +00:00
|
|
|
switch (type) {
|
|
|
|
case SHADER_TYPE_PIPELINE:
|
2016-01-09 20:19:18 +00:00
|
|
|
return pipelineManager_->DebugGetObjectIDs(type);
|
2023-02-25 15:40:52 +00:00
|
|
|
case SHADER_TYPE_SAMPLER:
|
2017-12-06 15:01:56 +00:00
|
|
|
return textureCacheVulkan_->DebugGetSamplerIDs();
|
2023-02-25 15:40:52 +00:00
|
|
|
default:
|
|
|
|
return GPUCommonHW::DebugGetShaderIDs(type);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
std::string GPU_Vulkan::DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) {
|
2023-02-25 15:40:52 +00:00
|
|
|
switch (type) {
|
|
|
|
case SHADER_TYPE_PIPELINE:
|
2023-01-08 22:37:38 +00:00
|
|
|
return pipelineManager_->DebugGetObjectString(id, type, stringType, shaderManagerVulkan_);
|
2023-02-25 15:40:52 +00:00
|
|
|
case SHADER_TYPE_SAMPLER:
|
2017-12-06 15:01:56 +00:00
|
|
|
return textureCacheVulkan_->DebugGetSamplerString(id, stringType);
|
2023-02-25 15:40:52 +00:00
|
|
|
default:
|
|
|
|
return GPUCommonHW::DebugGetShaderString(id, type, stringType);
|
2016-01-05 20:18:43 +00:00
|
|
|
}
|
2015-10-10 14:41:19 +00:00
|
|
|
}
|