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/VulkanUtil.h
Views: 1401
// Copyright (c) 2016- 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 <tuple>20#include <map>2122#include "Common/Data/Collections/Hashmaps.h"23#include "Common/GPU/Vulkan/VulkanContext.h"24#include "Common/GPU/Vulkan/VulkanImage.h"25#include "Common/GPU/Vulkan/VulkanLoader.h"26#include "Common/GPU/Vulkan/VulkanDescSet.h"27#include "Common/GPU/thin3d.h"2829extern const VkComponentMapping VULKAN_4444_SWIZZLE;30extern const VkComponentMapping VULKAN_1555_SWIZZLE;31extern const VkComponentMapping VULKAN_565_SWIZZLE;32extern const VkComponentMapping VULKAN_8888_SWIZZLE;3334#define VULKAN_4444_FORMAT VK_FORMAT_B4G4R4A4_UNORM_PACK1635#define VULKAN_1555_FORMAT VK_FORMAT_A1R5G5B5_UNORM_PACK1636#define VULKAN_565_FORMAT VK_FORMAT_R5G6B5_UNORM_PACK1637#define VULKAN_8888_FORMAT VK_FORMAT_R8G8B8A8_UNORM38#define VULKAN_CLUT8_FORMAT VK_FORMAT_R8_UNORM3940// Manager for compute shaders that upload things (and those have two bindings: a storage buffer to read from and an image to write to).41class VulkanComputeShaderManager {42public:43VulkanComputeShaderManager(VulkanContext *vulkan);44~VulkanComputeShaderManager();4546void DeviceLost() {47DestroyDeviceObjects();48}49void DeviceRestore(Draw::DrawContext *draw) {50vulkan_ = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);51InitDeviceObjects(draw);52}5354// Note: This doesn't cache. The descriptor is for immediate use only.55VkDescriptorSet GetDescriptorSet(VkImageView image, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, VkBuffer buffer2 = VK_NULL_HANDLE, VkDeviceSize offset2 = 0, VkDeviceSize range2 = 0);5657// This of course caches though.58VkPipeline GetPipeline(VkShaderModule cs);59VkPipelineLayout GetPipelineLayout() const { return pipelineLayout_; }6061void BeginFrame();6263private:64void InitDeviceObjects(Draw::DrawContext *draw);65void DestroyDeviceObjects();6667VulkanContext *vulkan_ = nullptr;68VkDescriptorSetLayout descriptorSetLayout_ = VK_NULL_HANDLE;69VkPipelineLayout pipelineLayout_ = VK_NULL_HANDLE;70VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;7172struct FrameData {73FrameData() : descPool("VulkanComputeShaderManager", true) {}7475VulkanDescSetPool descPool;76bool descPoolUsed = false;77};78FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];7980struct PipelineKey {81VkShaderModule module;82};8384DenseHashMap<PipelineKey, VkPipeline> pipelines_;85};868788VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error);899091