CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Vulkan/PipelineManagerVulkan.h
Views: 1401
// Copyright (c) 2015- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <cstring>2021#include "Common/Data/Collections/Hashmaps.h"22#include "Common/Thread/Promise.h"2324#include "GPU/Common/VertexDecoderCommon.h"25#include "GPU/Common/ShaderId.h"26#include "GPU/Common/ShaderCommon.h"27#include "GPU/Vulkan/VulkanUtil.h"28#include "GPU/Vulkan/StateMappingVulkan.h"29#include "GPU/Vulkan/VulkanQueueRunner.h"30#include "GPU/Vulkan/VulkanRenderManager.h"3132struct VKRGraphicsPipeline;33class VulkanRenderManager;34class VulkanContext;35class VulkanVertexShader;36class VulkanFragmentShader;37class VulkanGeometryShader;38class ShaderManagerVulkan;39class DrawEngineCommon;4041struct VulkanPipelineKey {42VulkanPipelineRasterStateKey raster; // prim is included here43VKRRenderPass *renderPass;44Promise<VkShaderModule> *vShader;45Promise<VkShaderModule> *fShader;46Promise<VkShaderModule> *gShader;47uint32_t vtxFmtId;48bool useHWTransform;4950void ToString(std::string *str) const {51str->resize(sizeof(*this));52memcpy(&(*str)[0], this, sizeof(*this));53}54void FromString(const std::string &str) {55memcpy(this, &str[0], sizeof(*this));56}57std::string GetDescription(DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager) const;5859private:60std::string GetRasterStateDesc(bool lineBreaks) const;61};6263// Simply wraps a Vulkan pipeline, providing some metadata.64struct VulkanPipeline {65~VulkanPipeline() {66desc->Release();67}6869VKRGraphicsPipeline *pipeline;70VKRGraphicsPipelineDesc *desc;71PipelineFlags pipelineFlags; // PipelineFlags enum above.7273bool UsesBlendConstant() const { return (pipelineFlags & PipelineFlags::USES_BLEND_CONSTANT) != 0; }74bool UsesDepthStencil() const { return (pipelineFlags & PipelineFlags::USES_DEPTH_STENCIL) != 0; }75bool UsesGeometryShader() const { return (pipelineFlags & PipelineFlags::USES_GEOMETRY_SHADER) != 0; }76bool UsesDiscard() const { return (pipelineFlags & PipelineFlags::USES_DISCARD) != 0; }77bool UsesFlatShading() const { return (pipelineFlags & PipelineFlags::USES_FLAT_SHADING) != 0; }7879u32 GetVariantsBitmask() const;80};8182class PipelineManagerVulkan {83public:84PipelineManagerVulkan(VulkanContext *ctx);85~PipelineManagerVulkan();8687// variantMask is only used when loading pipelines from cache.88VulkanPipeline *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);89int GetNumPipelines() const { return (int)pipelines_.size(); }9091void Clear();9293void DeviceLost();94void DeviceRestore(VulkanContext *vulkan);9596void InvalidateMSAAPipelines();9798std::string DebugGetObjectString(const std::string &id, DebugShaderType type, DebugShaderStringType stringType, ShaderManagerVulkan *shaderManager);99std::vector<std::string> DebugGetObjectIDs(DebugShaderType type) const;100101// Saves data for faster creation next time.102void SavePipelineCache(FILE *file, bool saveRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext);103bool LoadPipelineCache(FILE *file, bool loadRawPipelineCache, ShaderManagerVulkan *shaderManager, Draw::DrawContext *drawContext, VKRPipelineLayout *layout, int multiSampleLevel);104105private:106DenseHashMap<VulkanPipelineKey, VulkanPipeline *> pipelines_;107VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;108VulkanContext *vulkan_;109};110111112