2016-03-17 10:56:43 +00:00
|
|
|
// Copyright (c) 2016- PPSSPP Project.
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
#include <cstdio>
|
2020-09-29 10:44:47 +00:00
|
|
|
#include <cstdint>
|
2018-03-13 22:22:21 +00:00
|
|
|
|
2020-10-05 18:58:33 +00:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2020-10-04 21:24:14 +00:00
|
|
|
#include "Common/GPU/Vulkan/VulkanMemory.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/Common/ShaderCommon.h"
|
|
|
|
#include "GPU/Common/ShaderId.h"
|
2020-11-01 12:02:53 +00:00
|
|
|
#include "GPU/Common/VertexShaderGenerator.h"
|
2020-10-31 17:56:44 +00:00
|
|
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "GPU/Vulkan/VulkanUtil.h"
|
2020-10-03 22:25:21 +00:00
|
|
|
#include "Common/Math/lin/matrix4x4.h"
|
2017-02-08 16:35:41 +00:00
|
|
|
#include "GPU/Common/ShaderUniforms.h"
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-09 20:19:18 +00:00
|
|
|
class VulkanContext;
|
|
|
|
class VulkanPushBuffer;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
class VulkanFragmentShader {
|
|
|
|
public:
|
2018-03-13 22:22:21 +00:00
|
|
|
VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, const char *code);
|
2015-10-10 14:41:19 +00:00
|
|
|
~VulkanFragmentShader();
|
|
|
|
|
|
|
|
const std::string &source() const { return source_; }
|
|
|
|
|
|
|
|
bool Failed() const { return failed_; }
|
|
|
|
|
|
|
|
std::string GetShaderString(DebugShaderStringType type) const;
|
2016-01-09 00:23:32 +00:00
|
|
|
VkShaderModule GetModule() const { return module_; }
|
2018-03-13 22:22:21 +00:00
|
|
|
const FShaderID &GetID() { return id_; }
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VkShaderModule module_;
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
VulkanContext *vulkan_;
|
2015-10-10 14:41:19 +00:00
|
|
|
std::string source_;
|
|
|
|
bool failed_;
|
2017-12-02 17:07:27 +00:00
|
|
|
FShaderID id_;
|
2015-10-10 14:41:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class VulkanVertexShader {
|
|
|
|
public:
|
2018-03-17 09:33:50 +00:00
|
|
|
VulkanVertexShader(VulkanContext *vulkan, VShaderID id, const char *code, bool useHWTransform);
|
2015-10-10 14:41:19 +00:00
|
|
|
~VulkanVertexShader();
|
|
|
|
|
|
|
|
const std::string &source() const { return source_; }
|
|
|
|
|
|
|
|
bool Failed() const { return failed_; }
|
|
|
|
bool UseHWTransform() const { return useHWTransform_; }
|
|
|
|
|
|
|
|
std::string GetShaderString(DebugShaderStringType type) const;
|
2016-01-09 00:23:32 +00:00
|
|
|
VkShaderModule GetModule() const { return module_; }
|
2018-03-13 22:22:21 +00:00
|
|
|
const VShaderID &GetID() { return id_; }
|
2015-10-10 14:41:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
VkShaderModule module_;
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
VulkanContext *vulkan_;
|
2015-10-10 14:41:19 +00:00
|
|
|
std::string source_;
|
|
|
|
bool failed_;
|
|
|
|
bool useHWTransform_;
|
2017-12-02 17:07:27 +00:00
|
|
|
VShaderID id_;
|
2015-10-10 14:41:19 +00:00
|
|
|
};
|
|
|
|
|
2016-01-09 20:19:18 +00:00
|
|
|
class VulkanPushBuffer;
|
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
class ShaderManagerVulkan : public ShaderManagerCommon {
|
2015-10-10 14:41:19 +00:00
|
|
|
public:
|
2018-12-23 20:06:29 +00:00
|
|
|
ShaderManagerVulkan(Draw::DrawContext *draw, VulkanContext *vulkan);
|
2015-10-10 14:41:19 +00:00
|
|
|
~ShaderManagerVulkan();
|
|
|
|
|
2018-12-23 20:06:29 +00:00
|
|
|
void DeviceRestore(VulkanContext *vulkan, Draw::DrawContext *draw);
|
2016-10-09 18:17:03 +00:00
|
|
|
|
2020-04-04 18:52:32 +00:00
|
|
|
void GetShaders(int prim, u32 vertType, VulkanVertexShader **vshader, VulkanFragmentShader **fshader, bool useHWTransform, bool useHWTessellation);
|
2016-01-10 13:24:10 +00:00
|
|
|
void ClearShaders();
|
2015-10-10 14:41:19 +00:00
|
|
|
void DirtyShader();
|
2017-02-15 17:32:44 +00:00
|
|
|
void DirtyLastShader() override;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
|
|
|
|
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
// Used for saving/loading the cache. Don't need to be particularly fast.
|
|
|
|
VulkanVertexShader *GetVertexShaderFromID(VShaderID id) { return vsCache_.Get(id); }
|
|
|
|
VulkanFragmentShader *GetFragmentShaderFromID(FShaderID id) { return fsCache_.Get(id); }
|
|
|
|
VulkanVertexShader *GetVertexShaderFromModule(VkShaderModule module);
|
|
|
|
VulkanFragmentShader *GetFragmentShaderFromModule(VkShaderModule module);
|
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
|
|
|
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
|
|
|
|
|
2020-04-04 18:03:07 +00:00
|
|
|
uint64_t UpdateUniforms(bool useBufferedRendering);
|
2016-01-09 11:17:02 +00:00
|
|
|
|
2016-01-09 00:23:32 +00:00
|
|
|
// TODO: Avoid copying these buffers if same as last draw, can still point to it assuming we're still in the same pushbuffer.
|
|
|
|
// Applies dirty changes and copies the buffer.
|
|
|
|
bool IsBaseDirty() { return true; }
|
|
|
|
bool IsLightDirty() { return true; }
|
2018-04-10 10:22:02 +00:00
|
|
|
bool IsBoneDirty() { return true; }
|
2016-01-09 00:23:32 +00:00
|
|
|
|
2017-08-18 11:39:42 +00:00
|
|
|
uint32_t PushBaseBuffer(VulkanPushBuffer *dest, VkBuffer *buf) {
|
|
|
|
return dest->PushAligned(&ub_base, sizeof(ub_base), uboAlignment_, buf);
|
|
|
|
}
|
|
|
|
uint32_t PushLightBuffer(VulkanPushBuffer *dest, VkBuffer *buf) {
|
|
|
|
return dest->PushAligned(&ub_lights, sizeof(ub_lights), uboAlignment_, buf);
|
|
|
|
}
|
2018-04-10 10:22:02 +00:00
|
|
|
// TODO: Only push half the bone buffer if we only have four bones.
|
|
|
|
uint32_t PushBoneBuffer(VulkanPushBuffer *dest, VkBuffer *buf) {
|
|
|
|
return dest->PushAligned(&ub_bones, sizeof(ub_bones), uboAlignment_, buf);
|
|
|
|
}
|
2016-01-09 00:23:32 +00:00
|
|
|
|
2018-03-13 22:22:21 +00:00
|
|
|
bool LoadCache(FILE *f);
|
|
|
|
void SaveCache(FILE *f);
|
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
private:
|
|
|
|
void Clear();
|
|
|
|
|
2016-01-05 20:18:43 +00:00
|
|
|
VulkanContext *vulkan_;
|
2020-10-31 17:56:44 +00:00
|
|
|
ShaderLanguageDesc compat_;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
typedef DenseHashMap<FShaderID, VulkanFragmentShader *, nullptr> FSCache;
|
2016-01-09 11:17:02 +00:00
|
|
|
FSCache fsCache_;
|
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
typedef DenseHashMap<VShaderID, VulkanVertexShader *, nullptr> VSCache;
|
2016-01-09 11:17:02 +00:00
|
|
|
VSCache vsCache_;
|
|
|
|
|
2015-10-10 14:41:19 +00:00
|
|
|
char *codeBuffer_;
|
|
|
|
|
2017-01-23 16:32:18 +00:00
|
|
|
uint64_t uboAlignment_;
|
2015-10-10 14:41:19 +00:00
|
|
|
// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.
|
2016-01-09 10:07:14 +00:00
|
|
|
UB_VS_FS_Base ub_base;
|
2015-10-10 14:41:19 +00:00
|
|
|
UB_VS_Lights ub_lights;
|
2018-04-10 10:22:02 +00:00
|
|
|
UB_VS_Bones ub_bones;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2020-10-30 22:29:18 +00:00
|
|
|
VulkanFragmentShader *lastFShader_ = nullptr;
|
|
|
|
VulkanVertexShader *lastVShader_ = nullptr;
|
2015-10-10 14:41:19 +00:00
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
FShaderID lastFSID_;
|
|
|
|
VShaderID lastVSID_;
|
2015-10-10 14:41:19 +00:00
|
|
|
};
|