Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/PipelineManagerVulkan.h
5671 views
1
// Copyright (c) 2015- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <cstring>
21
22
#include "Common/Data/Collections/Hashmaps.h"
23
#include "Common/Thread/Promise.h"
24
25
#include "GPU/Common/VertexDecoderCommon.h"
26
#include "GPU/Common/ShaderId.h"
27
#include "GPU/Common/ShaderCommon.h"
28
#include "GPU/Vulkan/VulkanUtil.h"
29
#include "GPU/Vulkan/StateMappingVulkan.h"
30
#include "GPU/Vulkan/VulkanQueueRunner.h"
31
#include "GPU/Vulkan/VulkanRenderManager.h"
32
33
#include "Common/File/FileUtil.h"
34
35
struct VKRGraphicsPipeline;
36
class VulkanRenderManager;
37
class VulkanContext;
38
class VulkanVertexShader;
39
class VulkanFragmentShader;
40
class VulkanGeometryShader;
41
class ShaderManagerVulkan;
42
class DrawEngineCommon;
43
44
struct VulkanPipelineKey {
45
VulkanPipelineRasterStateKey raster; // prim is included here
46
VKRRenderPass *renderPass;
47
Promise<VkShaderModule> *vShader;
48
Promise<VkShaderModule> *fShader;
49
Promise<VkShaderModule> *gShader;
50
uint32_t vtxFmtId;
51
bool useHWTransform;
52
53
void ToString(std::string *str) const {
54
str->resize(sizeof(*this));
55
memcpy(&(*str)[0], this, sizeof(*this));
56
}
57
void FromString(const std::string &str) {
58
memcpy(this, &str[0], sizeof(*this));
59
}
60
std::string GetDescription(DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager) const;
61
62
private:
63
std::string GetRasterStateDesc(bool lineBreaks) const;
64
};
65
66
// Simply wraps a Vulkan pipeline, providing some metadata.
67
struct VulkanPipeline {
68
~VulkanPipeline() {
69
desc->Release();
70
}
71
72
VKRGraphicsPipeline *pipeline;
73
VKRGraphicsPipelineDesc *desc;
74
PipelineFlags pipelineFlags; // PipelineFlags enum above.
75
76
bool UsesBlendConstant() const { return (pipelineFlags & PipelineFlags::USES_BLEND_CONSTANT) != 0; }
77
bool UsesDepthStencil() const { return (pipelineFlags & PipelineFlags::USES_DEPTH_STENCIL) != 0; }
78
bool UsesGeometryShader() const { return (pipelineFlags & PipelineFlags::USES_GEOMETRY_SHADER) != 0; }
79
bool UsesDiscard() const { return (pipelineFlags & PipelineFlags::USES_DISCARD) != 0; }
80
bool UsesFlatShading() const { return (pipelineFlags & PipelineFlags::USES_FLAT_SHADING) != 0; }
81
82
u32 GetVariantsBitmask() const;
83
};
84
85
class PipelineManagerVulkan {
86
public:
87
PipelineManagerVulkan(VulkanContext *ctx);
88
~PipelineManagerVulkan();
89
90
// variantMask is only used when loading pipelines from cache.
91
VulkanPipeline *GetOrCreatePipeline(VulkanRenderManager *renderManager, VKRPipelineLayout *layout, const VulkanPipelineRasterStateKey &rasterKey, const DecVtxFormat *decFmt, VulkanVertexShader *vs, VulkanFragmentShader *fs, VulkanGeometryShader *gs, bool useHwTransform, u32 variantMask, int multiSampleLevel, bool cacheLoad);
92
int GetNumPipelines() const { return (int)pipelines_.size(); }
93
94
void Clear();
95
96
void DeviceLost();
97
void DeviceRestore(VulkanContext *vulkan);
98
99
void InvalidateMSAAPipelines();
100
void BlockUntilReady();
101
102
std::string DebugGetObjectString(const std::string &id, DebugShaderType type, DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager);
103
std::vector<std::string> DebugGetObjectIDs(DebugShaderType type) const;
104
105
// Saves data for faster creation next time.
106
void SavePipelineCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext);
107
bool LoadPipelineCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VKRPipelineLayout *layout, int multiSampleLevel);
108
109
private:
110
DenseHashMap<VulkanPipelineKey, VulkanPipeline *> pipelines_;
111
VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;
112
VulkanContext *vulkan_;
113
};
114
115