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/VulkanUtil.h
Views: 1401
1
// Copyright (c) 2016- 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 <tuple>
21
#include <map>
22
23
#include "Common/Data/Collections/Hashmaps.h"
24
#include "Common/GPU/Vulkan/VulkanContext.h"
25
#include "Common/GPU/Vulkan/VulkanImage.h"
26
#include "Common/GPU/Vulkan/VulkanLoader.h"
27
#include "Common/GPU/Vulkan/VulkanDescSet.h"
28
#include "Common/GPU/thin3d.h"
29
30
extern const VkComponentMapping VULKAN_4444_SWIZZLE;
31
extern const VkComponentMapping VULKAN_1555_SWIZZLE;
32
extern const VkComponentMapping VULKAN_565_SWIZZLE;
33
extern const VkComponentMapping VULKAN_8888_SWIZZLE;
34
35
#define VULKAN_4444_FORMAT VK_FORMAT_B4G4R4A4_UNORM_PACK16
36
#define VULKAN_1555_FORMAT VK_FORMAT_A1R5G5B5_UNORM_PACK16
37
#define VULKAN_565_FORMAT VK_FORMAT_R5G6B5_UNORM_PACK16
38
#define VULKAN_8888_FORMAT VK_FORMAT_R8G8B8A8_UNORM
39
#define VULKAN_CLUT8_FORMAT VK_FORMAT_R8_UNORM
40
41
// Manager for compute shaders that upload things (and those have two bindings: a storage buffer to read from and an image to write to).
42
class VulkanComputeShaderManager {
43
public:
44
VulkanComputeShaderManager(VulkanContext *vulkan);
45
~VulkanComputeShaderManager();
46
47
void DeviceLost() {
48
DestroyDeviceObjects();
49
}
50
void DeviceRestore(Draw::DrawContext *draw) {
51
vulkan_ = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
52
InitDeviceObjects(draw);
53
}
54
55
// Note: This doesn't cache. The descriptor is for immediate use only.
56
VkDescriptorSet GetDescriptorSet(VkImageView image, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, VkBuffer buffer2 = VK_NULL_HANDLE, VkDeviceSize offset2 = 0, VkDeviceSize range2 = 0);
57
58
// This of course caches though.
59
VkPipeline GetPipeline(VkShaderModule cs);
60
VkPipelineLayout GetPipelineLayout() const { return pipelineLayout_; }
61
62
void BeginFrame();
63
64
private:
65
void InitDeviceObjects(Draw::DrawContext *draw);
66
void DestroyDeviceObjects();
67
68
VulkanContext *vulkan_ = nullptr;
69
VkDescriptorSetLayout descriptorSetLayout_ = VK_NULL_HANDLE;
70
VkPipelineLayout pipelineLayout_ = VK_NULL_HANDLE;
71
VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;
72
73
struct FrameData {
74
FrameData() : descPool("VulkanComputeShaderManager", true) {}
75
76
VulkanDescSetPool descPool;
77
bool descPoolUsed = false;
78
};
79
FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];
80
81
struct PipelineKey {
82
VkShaderModule module;
83
};
84
85
DenseHashMap<PipelineKey, VkPipeline> pipelines_;
86
};
87
88
89
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error);
90
91