1 // Copyright (c) 2015- 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 "Common/GPU/Vulkan/VulkanLoader.h"
21 #include "GPU/GPUInterface.h"
22 #include "GPU/Common/FramebufferManagerCommon.h"
23 #include "GPU/Common/GPUDebugInterface.h"
24 #include "GPU/Common/PresentationCommon.h"
25 #include "GPU/Vulkan/VulkanUtil.h"
26 #include "GPU/Vulkan/DepalettizeShaderVulkan.h"
27 
28 class TextureCacheVulkan;
29 class DrawEngineVulkan;
30 class VulkanContext;
31 class ShaderManagerVulkan;
32 class VulkanTexture;
33 class VulkanPushBuffer;
34 
35 class FramebufferManagerVulkan : public FramebufferManagerCommon {
36 public:
37 	FramebufferManagerVulkan(Draw::DrawContext *draw, VulkanContext *vulkan);
38 	~FramebufferManagerVulkan();
39 
40 	void SetTextureCache(TextureCacheVulkan *tc);
41 	void SetShaderManager(ShaderManagerVulkan *sm);
42 	void SetDrawEngine(DrawEngineVulkan *td);
SetVulkan2D(Vulkan2D * vk2d)43 	void SetVulkan2D(Vulkan2D *vk2d) { vulkan2D_ = vk2d; }
SetPushBuffer(VulkanPushBuffer * push)44 	void SetPushBuffer(VulkanPushBuffer *push) { push_ = push; }
45 
46 	// x,y,w,h are relative to destW, destH which fill out the target completely.
47 	void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) override;
48 
49 	void BeginFrameVulkan();  // there's a BeginFrame in the base class, which this calls
50 	void EndFrame();
51 
52 	void DeviceLost() override;
53 	void DeviceRestore(Draw::DrawContext *draw) override;
54 
55 	bool NotifyStencilUpload(u32 addr, int size, StencilUpload flags = StencilUpload::NEEDS_CLEAR) override;
56 
57 	// If within a render pass, this will just issue a regular clear. If beginning a new render pass,
58 	// do that.
59 	void NotifyClear(bool clearColor, bool clearAlpha, bool clearDepth, uint32_t color, float depth);
60 
61 protected:
62 	void Bind2DShader() override;
63 
64 	// Used by ReadFramebufferToMemory and later framebuffer block copies
65 	void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp, const char *tag) override;
66 
67 private:
68 	void InitDeviceObjects();
69 	void DestroyDeviceObjects();
70 
71 	VulkanContext *vulkan_;
72 
73 	// Used to keep track of command buffers here but have moved all that into Thin3D.
74 
75 	TextureCacheVulkan *textureCacheVulkan_ = nullptr;
76 	ShaderManagerVulkan *shaderManagerVulkan_ = nullptr;
77 	DrawEngineVulkan *drawEngineVulkan_ = nullptr;
78 	VulkanPushBuffer *push_;
79 
80 	enum {
81 		MAX_COMMAND_BUFFERS = 32,
82 	};
83 
84 	VkPipelineCache pipelineCache2D_;
85 
86 	// Basic shaders
87 	VkShaderModule fsBasicTex_ = VK_NULL_HANDLE;
88 	VkShaderModule vsBasicTex_ = VK_NULL_HANDLE;
89 
90 	VkShaderModule stencilVs_ = VK_NULL_HANDLE;
91 	VkShaderModule stencilFs_ = VK_NULL_HANDLE;
92 
93 	VkPipeline cur2DPipeline_ = VK_NULL_HANDLE;
94 
95 	VkSampler linearSampler_;
96 	VkSampler nearestSampler_;
97 
98 	// Simple 2D drawing engine.
99 	Vulkan2D *vulkan2D_;
100 };
101