1
// Copyright (c) 2016- PPSSPP Project.
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.
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.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
23
#include "Common/Vulkan/VulkanContext.h"
24
#include "Common/Vulkan/VulkanLoader.h"
25
#include "Common/Vulkan/VulkanImage.h"
27
// Vulkan doesn't really have the concept of an FBO that owns the images,
28
// but it does have the concept of a framebuffer as a set of attachments.
29
// VulkanFBO is an approximation of the FBO concept the other backends use
30
// to make things as similar as possible without being suboptimal.
32
// An FBO can be rendered to and used as a texture multiple times in a frame.
33
// Even at multiple sizes, while keeping the same contents.
34
// With GL or D3D we'd just rely on the driver managing duplicates for us, but in
35
// Vulkan we will want to be able to batch up the whole frame and reorder passes
36
// so that all textures are ready before the main scene, instead of switching back and
37
// forth. This comes at a memory cost but will be worth it.
39
// When we render to a scene, then render to a texture, then go back to the scene and
40
// use that texture, we will register that as a dependency. Then we will walk the DAG
41
// to find the final order of command buffers, and execute it.
43
// Each FBO will get its own command buffer for each pass.
46
struct VulkanFBOPass {
55
// Depth-format is chosen automatically depending on hardware support.
56
// Color format will be 32-bit RGBA.
57
void Create(VulkanContext *vulkan, VkRenderPass rp_compatible, int width, int height, VkFormat colorFormat);
59
VulkanTexture *GetColor() { return color_; }
60
VulkanTexture *GetDepthStencil() { return depthStencil_; }
62
VkFramebuffer GetFramebuffer() { return framebuffer_; }
65
VulkanTexture *color_;
66
VulkanTexture *depthStencil_;
68
// This point specifically to color and depth.
69
VkFramebuffer framebuffer_;
72
// Similar to a subset of Thin3D, but separate.
73
// This is used for things like postprocessing shaders, depal, etc.
74
// No UBO data is used, only PushConstants.
75
// No transform matrices, only post-proj coordinates.
76
// Two textures can be sampled.
79
Vulkan2D(VulkanContext *vulkan);
82
VkPipeline GetPipeline(VkPipelineCache cache, VkRenderPass rp, VkShaderModule vs, VkShaderModule fs);
87
VkDescriptorSet GetDescriptorSet(VkImageView tex1, VkSampler sampler1, VkImageView tex2, VkSampler sampler2);
90
void BindDescriptorSet(VkCommandBuffer cmd, VkImageView tex1, VkSampler sampler1);
98
VulkanContext *vulkan_;
99
VkDescriptorSetLayout descriptorSetLayout_;
100
VkPipelineLayout pipelineLayout_;
102
// Yes, another one...
103
struct DescriptorSetKey {
104
VkImageView imageView[2];
105
VkSampler sampler[2];
107
bool operator < (const DescriptorSetKey &other) const {
108
return std::tie(imageView[0], imageView[1], sampler[0], sampler[1]) <
109
std::tie(other.imageView[0], other.imageView[1], other.sampler[0], other.sampler[1]);
117
bool operator < (const PipelineKey &other) const {
118
return std::tie(vs, fs, rp) < std::tie(other.vs, other.fs, other.rp);
123
VkDescriptorPool descPool;
124
std::map<DescriptorSetKey, VkDescriptorSet> descSets;
127
FrameData frameData_[2];
130
std::map<PipelineKey, VkPipeline> pipelines_;
134
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error);
b'\\ No newline at end of file'