2015-10-10 16:41:19 +02: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/.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-03-19 10:55:06 +01:00
|
|
|
#include <cstring>
|
2022-06-11 16:24:19 +02:00
|
|
|
|
2020-10-05 20:58:33 +02:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2022-06-11 16:24:19 +02:00
|
|
|
#include "Common/Thread/Promise.h"
|
2016-01-03 18:31:03 +01:00
|
|
|
|
2015-10-10 16:41:19 +02:00
|
|
|
#include "GPU/Common/VertexDecoderCommon.h"
|
|
|
|
|
#include "GPU/Common/ShaderId.h"
|
2020-10-23 00:44:35 +02:00
|
|
|
#include "GPU/Common/ShaderCommon.h"
|
2015-10-10 16:41:19 +02:00
|
|
|
#include "GPU/Vulkan/VulkanUtil.h"
|
2016-01-09 01:23:32 +01:00
|
|
|
#include "GPU/Vulkan/StateMappingVulkan.h"
|
2020-10-11 11:47:24 +02:00
|
|
|
#include "GPU/Vulkan/VulkanQueueRunner.h"
|
2022-09-07 16:11:15 +02:00
|
|
|
#include "GPU/Vulkan/VulkanRenderManager.h"
|
2020-10-11 11:47:24 +02:00
|
|
|
|
2019-06-16 20:29:38 +02:00
|
|
|
struct VKRGraphicsPipeline;
|
|
|
|
|
class VulkanRenderManager;
|
2023-01-08 23:37:38 +01:00
|
|
|
class VulkanContext;
|
|
|
|
|
class VulkanVertexShader;
|
|
|
|
|
class VulkanFragmentShader;
|
|
|
|
|
class VulkanGeometryShader;
|
|
|
|
|
class ShaderManagerVulkan;
|
|
|
|
|
class DrawEngineCommon;
|
2019-06-16 20:29:38 +02:00
|
|
|
|
2015-10-10 16:41:19 +02:00
|
|
|
struct VulkanPipelineKey {
|
2016-01-09 11:07:14 +01:00
|
|
|
VulkanPipelineRasterStateKey raster; // prim is included here
|
2022-09-06 13:30:18 +02:00
|
|
|
VKRRenderPass *renderPass;
|
2022-06-11 16:24:19 +02:00
|
|
|
Promise<VkShaderModule> *vShader;
|
|
|
|
|
Promise<VkShaderModule> *fShader;
|
2022-10-01 20:01:23 -07:00
|
|
|
Promise<VkShaderModule> *gShader;
|
2018-03-13 23:22:21 +01:00
|
|
|
uint32_t vtxFmtId;
|
2017-11-13 15:18:27 +01:00
|
|
|
bool useHWTransform;
|
2016-01-03 18:31:03 +01:00
|
|
|
|
2016-01-09 21:19:18 +01:00
|
|
|
void ToString(std::string *str) const {
|
|
|
|
|
str->resize(sizeof(*this));
|
|
|
|
|
memcpy(&(*str)[0], this, sizeof(*this));
|
|
|
|
|
}
|
|
|
|
|
void FromString(const std::string &str) {
|
|
|
|
|
memcpy(this, &str[0], sizeof(*this));
|
|
|
|
|
}
|
2023-01-08 23:37:38 +01:00
|
|
|
std::string GetDescription(DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::string GetRasterStateDesc(bool lineBreaks) const;
|
2015-10-10 16:41:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Simply wraps a Vulkan pipeline, providing some metadata.
|
|
|
|
|
struct VulkanPipeline {
|
2022-12-03 14:52:06 -08:00
|
|
|
~VulkanPipeline() {
|
|
|
|
|
desc->Release();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 20:29:38 +02:00
|
|
|
VKRGraphicsPipeline *pipeline;
|
2022-12-03 14:52:06 -08:00
|
|
|
VKRGraphicsPipelineDesc *desc;
|
2022-02-19 20:40:27 +01:00
|
|
|
PipelineFlags pipelineFlags; // PipelineFlags enum above.
|
2018-03-16 17:38:02 +01:00
|
|
|
|
2022-02-19 20:40:27 +01:00
|
|
|
bool UsesBlendConstant() const { return (pipelineFlags & PipelineFlags::USES_BLEND_CONSTANT) != 0; }
|
|
|
|
|
bool UsesDepthStencil() const { return (pipelineFlags & PipelineFlags::USES_DEPTH_STENCIL) != 0; }
|
2022-10-01 12:12:46 -07:00
|
|
|
bool UsesGeometryShader() const { return (pipelineFlags & PipelineFlags::USES_GEOMETRY_SHADER) != 0; }
|
2022-11-28 22:59:42 +01:00
|
|
|
bool UsesDiscard() const { return (pipelineFlags & PipelineFlags::USES_DISCARD) != 0; }
|
2022-09-07 15:19:20 +02:00
|
|
|
|
|
|
|
|
u32 GetVariantsBitmask() const;
|
2015-10-10 16:41:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PipelineManagerVulkan {
|
|
|
|
|
public:
|
2016-01-03 18:31:03 +01:00
|
|
|
PipelineManagerVulkan(VulkanContext *ctx);
|
|
|
|
|
~PipelineManagerVulkan();
|
2015-10-10 16:41:19 +02:00
|
|
|
|
2022-09-07 15:19:20 +02:00
|
|
|
// variantMask is only used when loading pipelines from cache.
|
2023-01-13 10:14:29 +01:00
|
|
|
VulkanPipeline *GetOrCreatePipeline(VulkanRenderManager *renderManager, VkPipelineLayout layout, const VulkanPipelineRasterStateKey &rasterKey, const DecVtxFormat *decFmt, VulkanVertexShader *vs, VulkanFragmentShader *fs, VulkanGeometryShader *gs, bool useHwTransform, u32 variantMask, int multiSampleLevel, bool cacheLoad);
|
2016-01-10 14:24:10 +01:00
|
|
|
int GetNumPipelines() const { return (int)pipelines_.size(); }
|
|
|
|
|
|
|
|
|
|
void Clear();
|
2016-01-05 21:18:43 +01:00
|
|
|
|
2016-10-09 11:17:03 -07:00
|
|
|
void DeviceLost();
|
|
|
|
|
void DeviceRestore(VulkanContext *vulkan);
|
|
|
|
|
|
2022-12-01 23:41:31 +01:00
|
|
|
void InvalidateMSAAPipelines();
|
|
|
|
|
|
2023-01-08 23:37:38 +01:00
|
|
|
std::string DebugGetObjectString(std::string id, DebugShaderType type, DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager);
|
2022-12-14 14:29:18 +01:00
|
|
|
std::vector<std::string> DebugGetObjectIDs(DebugShaderType type) const;
|
2016-01-09 21:19:18 +01:00
|
|
|
|
2018-03-13 23:22:21 +01:00
|
|
|
// Saves data for faster creation next time.
|
2022-12-13 19:18:20 +01:00
|
|
|
void SavePipelineCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext);
|
2022-12-14 14:29:18 +01:00
|
|
|
bool LoadPipelineCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VkPipelineLayout layout, int multiSampleLevel);
|
2018-10-30 20:32:12 -07:00
|
|
|
void CancelCache();
|
2018-03-13 23:22:21 +01:00
|
|
|
|
2016-01-03 18:31:03 +01:00
|
|
|
private:
|
2023-09-11 12:02:56 +02:00
|
|
|
DenseHashMap<VulkanPipelineKey, VulkanPipeline *> pipelines_;
|
2018-03-13 23:22:21 +01:00
|
|
|
VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;
|
2016-01-03 18:31:03 +01:00
|
|
|
VulkanContext *vulkan_;
|
2018-10-30 20:32:12 -07:00
|
|
|
bool cancelCache_ = false;
|
2015-10-10 16:41:19 +02:00
|
|
|
};
|