Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Vulkan/VulkanUtil.h
5733 views
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
#include "Core/ConfigValues.h"
30
31
extern const VkComponentMapping VULKAN_4444_SWIZZLE;
32
extern const VkComponentMapping VULKAN_1555_SWIZZLE;
33
extern const VkComponentMapping VULKAN_565_SWIZZLE;
34
extern const VkComponentMapping VULKAN_8888_SWIZZLE;
35
36
#define VULKAN_4444_FORMAT VK_FORMAT_B4G4R4A4_UNORM_PACK16
37
#define VULKAN_1555_FORMAT VK_FORMAT_A1R5G5B5_UNORM_PACK16
38
#define VULKAN_565_FORMAT VK_FORMAT_R5G6B5_UNORM_PACK16
39
#define VULKAN_8888_FORMAT VK_FORMAT_R8G8B8A8_UNORM
40
#define VULKAN_CLUT8_FORMAT VK_FORMAT_R8_UNORM
41
42
// Manager for compute shaders that upload things (and those have two bindings: a storage buffer to read from and an image to write to).
43
class VulkanComputeShaderManager {
44
public:
45
VulkanComputeShaderManager(VulkanContext *vulkan);
46
~VulkanComputeShaderManager();
47
48
void DeviceLost() {
49
DestroyDeviceObjects();
50
}
51
void DeviceRestore(Draw::DrawContext *draw) {
52
vulkan_ = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
53
InitDeviceObjects(draw);
54
}
55
56
// Note: This doesn't cache. The descriptor is for immediate use only.
57
VkDescriptorSet GetDescriptorSet(VkImageView image, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, VkBuffer buffer2 = VK_NULL_HANDLE, VkDeviceSize offset2 = 0, VkDeviceSize range2 = 0);
58
59
// This of course caches though.
60
VkPipeline GetPipeline(VkShaderModule cs);
61
VkPipelineLayout GetPipelineLayout() const { return pipelineLayout_; }
62
63
void BeginFrame();
64
65
private:
66
void InitDeviceObjects(Draw::DrawContext *draw);
67
void DestroyDeviceObjects();
68
69
VulkanContext *vulkan_ = nullptr;
70
VkDescriptorSetLayout descriptorSetLayout_ = VK_NULL_HANDLE;
71
VkPipelineLayout pipelineLayout_ = VK_NULL_HANDLE;
72
VkPipelineCache pipelineCache_ = VK_NULL_HANDLE;
73
74
struct FrameData {
75
FrameData() : descPool("VulkanComputeShaderManager", true) {}
76
77
VulkanDescSetPool descPool;
78
bool descPoolUsed = false;
79
};
80
FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];
81
82
struct PipelineKey {
83
VkShaderModule module;
84
};
85
86
DenseHashMap<PipelineKey, VkPipeline> pipelines_;
87
};
88
89
90
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error);
91
92
VkPresentModeKHR ConfigPresentModeToVulkan(Draw::DrawContext *draw);
93
void InitVulkanCreateInfoFromConfig(VulkanContext::CreateInfo *info);
94
95