2013-08-17 09:23:51 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include <map>
|
2017-01-23 16:32:18 +00:00
|
|
|
#include <cstdint>
|
2015-10-24 21:24:06 +00:00
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
2013-09-15 10:46:14 +00:00
|
|
|
#include "GPU/Directx9/VertexShaderGeneratorDX9.h"
|
|
|
|
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
|
2015-10-24 22:34:23 +00:00
|
|
|
#include "GPU/Common/ShaderCommon.h"
|
2015-10-24 21:24:06 +00:00
|
|
|
#include "GPU/Common/ShaderId.h"
|
2014-08-22 23:52:46 +00:00
|
|
|
#include "thin3d/d3dx9_loader.h"
|
|
|
|
#include "math/lin/matrix4x4.h"
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2013-09-15 15:53:21 +00:00
|
|
|
namespace DX9 {
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
class PSShader;
|
|
|
|
class VSShader;
|
2014-09-10 12:07:30 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// Real public interface
|
|
|
|
|
|
|
|
class PSShader {
|
|
|
|
public:
|
2017-12-02 17:07:27 +00:00
|
|
|
PSShader(LPDIRECT3DDEVICE9 device, FShaderID id, const char *code);
|
2013-08-17 09:23:51 +00:00
|
|
|
~PSShader();
|
|
|
|
|
|
|
|
const std::string &source() const { return source_; }
|
|
|
|
|
|
|
|
bool Failed() const { return failed_; }
|
2015-10-24 22:34:23 +00:00
|
|
|
|
|
|
|
std::string GetShaderString(DebugShaderStringType type) const;
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
LPDIRECT3DPIXELSHADER9 shader;
|
2014-09-10 10:59:33 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
protected:
|
|
|
|
std::string source_;
|
|
|
|
bool failed_;
|
2017-12-02 17:07:27 +00:00
|
|
|
FShaderID id_;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class VSShader {
|
|
|
|
public:
|
2017-12-02 17:07:27 +00:00
|
|
|
VSShader(LPDIRECT3DDEVICE9 device, VShaderID id, const char *code, bool useHWTransform);
|
2013-08-17 09:23:51 +00:00
|
|
|
~VSShader();
|
|
|
|
|
|
|
|
const std::string &source() const { return source_; }
|
|
|
|
|
|
|
|
bool Failed() const { return failed_; }
|
|
|
|
bool UseHWTransform() const { return useHWTransform_; }
|
2015-10-24 22:34:23 +00:00
|
|
|
|
|
|
|
std::string GetShaderString(DebugShaderStringType type) const;
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
LPDIRECT3DVERTEXSHADER9 shader;
|
2014-09-10 11:57:19 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
protected:
|
|
|
|
std::string source_;
|
|
|
|
bool failed_;
|
|
|
|
bool useHWTransform_;
|
2017-12-02 17:07:27 +00:00
|
|
|
VShaderID id_;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
2017-01-23 19:48:23 +00:00
|
|
|
class ShaderManagerDX9 : public ShaderManagerCommon {
|
2013-08-17 09:23:51 +00:00
|
|
|
public:
|
2018-12-23 20:06:29 +00:00
|
|
|
ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device);
|
2013-09-15 10:46:14 +00:00
|
|
|
~ShaderManagerDX9();
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
void ClearCache(bool deleteThem); // TODO: deleteThem currently not respected
|
2020-04-04 18:14:32 +00:00
|
|
|
VSShader *ApplyShader(bool useHWTransform, u32 vertType);
|
2013-08-17 09:23:51 +00:00
|
|
|
void DirtyShader();
|
2017-02-15 17:32:44 +00:00
|
|
|
void DirtyLastShader() override;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-02-08 17:07:34 +00:00
|
|
|
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
|
|
|
|
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2015-10-24 22:34:23 +00:00
|
|
|
std::vector<std::string> DebugGetShaderIDs(DebugShaderType type);
|
|
|
|
std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType);
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
private:
|
2017-01-23 16:32:18 +00:00
|
|
|
void PSUpdateUniforms(u64 dirtyUniforms);
|
|
|
|
void VSUpdateUniforms(u64 dirtyUniforms);
|
2017-08-20 11:53:39 +00:00
|
|
|
inline void PSSetColorUniform3Alpha255(int creg, u32 color, u8 alpha);
|
|
|
|
inline void PSSetColorUniform3(int creg, u32 color);
|
|
|
|
inline void PSSetFloat(int creg, float value);
|
|
|
|
inline void PSSetFloatArray(int creg, const float *value, int count);
|
2014-09-10 11:57:19 +00:00
|
|
|
|
|
|
|
void VSSetMatrix4x3(int creg, const float *m4x3);
|
2014-09-18 21:08:46 +00:00
|
|
|
void VSSetMatrix4x3_3(int creg, const float *m4x3);
|
2017-08-20 11:53:39 +00:00
|
|
|
inline void VSSetColorUniform3(int creg, u32 color);
|
|
|
|
inline void VSSetColorUniform3ExtraFloat(int creg, u32 color, float extra);
|
|
|
|
inline void VSSetColorUniform3Alpha(int creg, u32 color, u8 alpha);
|
2014-09-10 11:57:19 +00:00
|
|
|
void VSSetMatrix(int creg, const float* pMatrix);
|
|
|
|
void VSSetFloat(int creg, float value);
|
|
|
|
void VSSetFloatArray(int creg, const float *value, int count);
|
|
|
|
void VSSetFloat24Uniform3(int creg, const u32 data[3]);
|
2015-08-26 15:45:21 +00:00
|
|
|
void VSSetFloatUniform4(int creg, float data[4]);
|
2014-09-10 11:57:19 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
void Clear();
|
|
|
|
|
2017-02-05 19:36:00 +00:00
|
|
|
LPDIRECT3DDEVICE9 device_;
|
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
FShaderID lastFSID_;
|
|
|
|
VShaderID lastVSID_;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
char *codeBuffer_;
|
|
|
|
|
2014-09-10 12:07:30 +00:00
|
|
|
VSShader *lastVShader_;
|
|
|
|
PSShader *lastPShader_;
|
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
typedef std::map<FShaderID, PSShader *> FSCache;
|
2013-08-23 15:11:01 +00:00
|
|
|
FSCache fsCache_;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-12-02 17:07:27 +00:00
|
|
|
typedef std::map<VShaderID, VSShader *> VSCache;
|
2013-08-23 15:11:01 +00:00
|
|
|
VSCache vsCache_;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
2013-09-15 15:53:21 +00:00
|
|
|
|
|
|
|
};
|