CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/PipelineManagerVulkan.h
Views: 1401
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
struct VKRGraphicsPipeline;
34
class VulkanRenderManager;
35
class VulkanContext;
36
class VulkanVertexShader;
37
class VulkanFragmentShader;
38
class VulkanGeometryShader;
39
class ShaderManagerVulkan;
40
class DrawEngineCommon;
41
42
struct VulkanPipelineKey {
43
VulkanPipelineRasterStateKey raster; // prim is included here
44
VKRRenderPass *renderPass;
45
Promise<VkShaderModule> *vShader;
46
Promise<VkShaderModule> *fShader;
47
Promise<VkShaderModule> *gShader;
48
uint32_t vtxFmtId;
49
bool useHWTransform;
50
51
void ToString(std::string *str) const {
52
str->resize(sizeof(*this));
53
memcpy(&(*str)[0], this, sizeof(*this));
54
}
55
void FromString(const std::string &str) {
56
memcpy(this, &str[0], sizeof(*this));
57
}
58
std::string GetDescription(DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager) const;
59
60
private:
61
std::string GetRasterStateDesc(bool lineBreaks) const;
62
};
63
64
// Simply wraps a Vulkan pipeline, providing some metadata.
65
struct VulkanPipeline {
66
~VulkanPipeline() {
67
desc->Release();
68
}
69
70
VKRGraphicsPipeline *pipeline;
71
VKRGraphicsPipelineDesc *desc;
72
PipelineFlags pipelineFlags; // PipelineFlags enum above.
73
74
bool UsesBlendConstant() const { return (pipelineFlags & PipelineFlags::USES_BLEND_CONSTANT) != 0; }
75
bool UsesDepthStencil() const { return (pipelineFlags & PipelineFlags::USES_DEPTH_STENCIL) != 0; }
76
bool UsesGeometryShader() const { return (pipelineFlags & PipelineFlags::USES_GEOMETRY_SHADER) != 0; }
77
bool UsesDiscard() const { return (pipelineFlags & PipelineFlags::USES_DISCARD) != 0; }
78
bool UsesFlatShading() const { return (pipelineFlags & PipelineFlags::USES_FLAT_SHADING) != 0; }
79
80
u32 GetVariantsBitmask() const;
81
};
82
83
class PipelineManagerVulkan {
84
public:
85
PipelineManagerVulkan(VulkanContext *ctx);
86
~PipelineManagerVulkan();
87
88
// variantMask is only used when loading pipelines from cache.
89
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);
90
int GetNumPipelines() const { return (int)pipelines_.size(); }
91
92
void Clear();
93
94
void DeviceLost();
95
void DeviceRestore(VulkanContext *vulkan);
96
97
void InvalidateMSAAPipelines();
98
99
std::string DebugGetObjectString(const std::string &id, DebugShaderType type, DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager);
100
std::vector<std::string> DebugGetObjectIDs(DebugShaderType type) const;
101
102
// Saves data for faster creation next time.
103
void SavePipelineCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext);
104
bool LoadPipelineCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VKRPipelineLayout *layout, int multiSampleLevel);
105
106
private:
107
DenseHashMap<VulkanPipelineKey, VulkanPipeline *> pipelines_;
108
VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;
109
VulkanContext *vulkan_;
110
};
111
112