CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/GLES/ShaderManagerGLES.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <vector>2021#include "Common/Data/Collections/Hashmaps.h"22#include "Common/GPU/OpenGL/GLRenderManager.h"23#include "Common/File/Path.h"24#include "GPU/Common/ShaderCommon.h"25#include "GPU/Common/ShaderId.h"26#include "GPU/Common/VertexShaderGenerator.h"27#include "GPU/Common/FragmentShaderGenerator.h"2829class DrawEngineGLES;30class Shader;31struct ShaderLanguageDesc;3233namespace File {34class IOFile;35}3637class LinkedShader {38public:39LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs, FShaderID FSID, Shader *fs, bool useHWTransform, bool preloading = false);40~LinkedShader();4142void use(const ShaderID &VSID) const;43void UpdateUniforms(const ShaderID &VSID, bool useBufferedRendering, const ShaderLanguageDesc &shaderLanguage);44void Delete();4546GLRenderManager *render_;47Shader *vs_;48// Set to false if the VS failed, happens on Mali-400 a lot for complex shaders.49bool useHWTransform_;5051GLRProgram *program;52uint64_t availableUniforms;53uint64_t dirtyUniforms = 0;5455// Present attributes in the shader.56int attrMask; // 1 << ATTR_ ... or-ed together.5758int u_stencilReplaceValue;59int u_tex;60int u_proj;61int u_proj_lens;62int u_proj_through;63int u_texenv;64int u_view;65int u_texmtx;66int u_world;67int u_depthRange; // x,y = viewport xscale/xcenter. z,w=clipping minz/maxz (?)68int u_cullRangeMin;69int u_cullRangeMax;70int u_rotation;71int u_mipBias;72int u_scaleX;73int u_scaleY;7475#ifdef USE_BONE_ARRAY76int u_bone; // array, size is numBones77#else78int u_bone[8];79#endif80int numBones;8182// Shader blending.83int u_fbotex;84int u_blendFixA;85int u_blendFixB;86int u_fbotexSize;8788// Shader depal89int u_pal; // the texture90int u_depal_mask_shift_off_fmt; // the params9192// Fragment processing inputs93int u_alphacolorref;94int u_alphacolormask;95int u_colorWriteMask;96int u_testtex;97int u_fogcolor;98int u_fogcoef;99100// Texturing101int u_uvscaleoffset;102int u_texclamp;103int u_texclampoff;104int u_texNoAlphaMul;105106// Lighting107int u_lightControl;108int u_ambient;109int u_matambientalpha;110int u_matdiffuse;111int u_matspecular;112int u_matemissive;113int u_lightpos[4];114int u_lightdir[4];115int u_lightatt[4]; // attenuation116int u_lightangle_spotCoef[4]; // spotlight cone angle (cosine) (x), spotlight dropoff (y)117int u_lightdiffuse[4]; // each light consist of vec4[3]118int u_lightspecular[4]; // attenuation119int u_lightambient[4]; // attenuation120121// Spline Tessellation122int u_tess_points; // Control Points123int u_tess_weights_u;124int u_tess_weights_v;125int u_spline_counts;126};127128// Real public interface129130struct ShaderDescGLES {131uint32_t glShaderType;132uint32_t attrMask;133uint64_t uniformMask;134bool useHWTransform;135};136137class Shader {138public:139Shader(GLRenderManager *render, const char *code, const std::string &desc, const ShaderDescGLES ¶ms);140~Shader();141GLRShader *shader;142143bool UseHWTransform() const { return useHWTransform_; } // only relevant for vtx shaders144145std::string GetShaderString(DebugShaderStringType type, ShaderID id) const;146147uint32_t GetAttrMask() const { return attrMask_; }148uint64_t GetUniformMask() const { return uniformMask_; }149150private:151GLRenderManager *render_;152std::string source_;153bool useHWTransform_;154bool isFragment_;155uint32_t attrMask_; // only used in vertex shaders156uint64_t uniformMask_;157};158159class ShaderManagerGLES : public ShaderManagerCommon {160public:161ShaderManagerGLES(Draw::DrawContext *draw);162~ShaderManagerGLES();163164void ClearShaders() override;165166// This is the old ApplyShader split into two parts, because of annoying information dependencies.167// If you call ApplyVertexShader, you MUST call ApplyFragmentShader soon afterwards.168Shader *ApplyVertexShader(bool useHWTransform, bool useHWTessellation, VertexDecoder *vertexDecoder, bool weightsAsFloat, bool useSkinInDecode, VShaderID *VSID);169LinkedShader *ApplyFragmentShader(VShaderID VSID, Shader *vs, const ComputedPipelineState &pipelineState, bool useBufferedRendering);170171void DeviceLost() override;172void DeviceRestore(Draw::DrawContext *draw) override;173174void DirtyLastShader() override;175176int GetNumVertexShaders() const { return (int)vsCache_.size(); }177int GetNumFragmentShaders() const { return (int)fsCache_.size(); }178int GetNumPrograms() const { return (int)linkedShaderCache_.size(); }179180std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) override;181std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) override;182183static bool LoadCacheFlags(File::IOFile &f, DrawEngineGLES *drawEngine);184bool LoadCache(File::IOFile &f);185void SaveCache(const Path &filename, DrawEngineGLES *drawEngine);186187private:188void Clear();189Shader *CompileFragmentShader(FShaderID id);190Shader *CompileVertexShader(VShaderID id);191192struct LinkedShaderCacheEntry {193LinkedShaderCacheEntry(Shader *vs_, Shader *fs_, LinkedShader *ls_)194: vs(vs_), fs(fs_), ls(ls_) { }195196Shader *vs;197Shader *fs;198LinkedShader *ls;199};200typedef std::vector<LinkedShaderCacheEntry> LinkedShaderCache;201202GLRenderManager *render_;203LinkedShaderCache linkedShaderCache_;204205bool lastVShaderSame_ = false;206207FShaderID lastFSID_;208VShaderID lastVSID_;209210LinkedShader *lastShader_ = nullptr;211u64 shaderSwitchDirtyUniforms_ = 0;212char *codeBuffer_;213214typedef DenseHashMap<FShaderID, Shader *> FSCache;215FSCache fsCache_;216217typedef DenseHashMap<VShaderID, Shader *> VSCache;218VSCache vsCache_;219};220221222