~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Vulkan/VulkanUtil.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/Vulkan/VulkanContext.h"
 
24
#include "Common/Vulkan/VulkanLoader.h"
 
25
#include "Common/Vulkan/VulkanImage.h"
 
26
 
 
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.
 
31
//
 
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.
 
38
//
 
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.
 
42
//
 
43
// Each FBO will get its own command buffer for each pass. 
 
44
 
 
45
// 
 
46
struct VulkanFBOPass {
 
47
        VkCommandBuffer cmd;
 
48
};
 
49
 
 
50
class VulkanFBO {
 
51
public:
 
52
        VulkanFBO();
 
53
        ~VulkanFBO();
 
54
 
 
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);
 
58
 
 
59
        VulkanTexture *GetColor() { return color_; }
 
60
        VulkanTexture *GetDepthStencil() { return depthStencil_; }
 
61
 
 
62
        VkFramebuffer GetFramebuffer() { return framebuffer_; }
 
63
 
 
64
private:
 
65
        VulkanTexture *color_;
 
66
        VulkanTexture *depthStencil_;
 
67
 
 
68
        // This point specifically to color and depth.
 
69
        VkFramebuffer framebuffer_;
 
70
};
 
71
 
 
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.
 
77
class Vulkan2D {
 
78
public:
 
79
        Vulkan2D(VulkanContext *vulkan);
 
80
        ~Vulkan2D();
 
81
 
 
82
        VkPipeline GetPipeline(VkPipelineCache cache, VkRenderPass rp, VkShaderModule vs, VkShaderModule fs);
 
83
 
 
84
        void BeginFrame();
 
85
        void EndFrame();
 
86
 
 
87
        VkDescriptorSet GetDescriptorSet(VkImageView tex1, VkSampler sampler1, VkImageView tex2, VkSampler sampler2);
 
88
 
 
89
        // Simple way
 
90
        void BindDescriptorSet(VkCommandBuffer cmd, VkImageView tex1, VkSampler sampler1);
 
91
 
 
92
        struct Vertex {
 
93
                float x, y, z;
 
94
                float u, v;
 
95
        };
 
96
 
 
97
private:
 
98
        VulkanContext *vulkan_;
 
99
        VkDescriptorSetLayout descriptorSetLayout_;
 
100
        VkPipelineLayout pipelineLayout_;
 
101
 
 
102
        // Yes, another one...
 
103
        struct DescriptorSetKey {
 
104
                VkImageView imageView[2];
 
105
                VkSampler sampler[2];
 
106
 
 
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]);
 
110
                }
 
111
        };
 
112
 
 
113
        struct PipelineKey {
 
114
                VkShaderModule vs;
 
115
                VkShaderModule fs;
 
116
                VkRenderPass rp;
 
117
                bool operator < (const PipelineKey &other) const {
 
118
                        return std::tie(vs, fs, rp) < std::tie(other.vs, other.fs, other.rp);
 
119
                }
 
120
        };
 
121
 
 
122
        struct FrameData {
 
123
                VkDescriptorPool descPool;
 
124
                std::map<DescriptorSetKey, VkDescriptorSet> descSets;
 
125
        };
 
126
 
 
127
        FrameData frameData_[2];
 
128
        int curFrame_;
 
129
 
 
130
        std::map<PipelineKey, VkPipeline> pipelines_;
 
131
};
 
132
 
 
133
 
 
134
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error);
 
 
b'\\ No newline at end of file'