ppsspp/GPU/Directx9/ShaderManagerDX9.h

133 lines
3.8 KiB
C
Raw Normal View History

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>
#include <cstdint>
#include "Common/Common.h"
#include "GPU/Directx9/VertexShaderGeneratorDX9.h"
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
#include "GPU/Common/ShaderCommon.h"
#include "GPU/Common/ShaderId.h"
#include "thin3d/d3dx9_loader.h"
#include "math/lin/matrix4x4.h"
2013-08-17 09:23:51 +00:00
namespace DX9 {
2013-08-17 09:23:51 +00:00
class PSShader;
class VSShader;
2013-08-17 09:23:51 +00:00
// Real public interface
class PSShader {
public:
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_; }
std::string GetShaderString(DebugShaderStringType type) const;
2013-08-17 09:23:51 +00:00
LPDIRECT3DPIXELSHADER9 shader;
2013-08-17 09:23:51 +00:00
protected:
std::string source_;
bool failed_;
FShaderID id_;
2013-08-17 09:23:51 +00:00
};
class VSShader {
public:
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_; }
std::string GetShaderString(DebugShaderStringType type) const;
2013-08-17 09:23:51 +00:00
LPDIRECT3DVERTEXSHADER9 shader;
2013-08-17 09:23:51 +00:00
protected:
std::string source_;
bool failed_;
bool useHWTransform_;
VShaderID id_;
2013-08-17 09:23:51 +00:00
};
class ShaderManagerDX9 : public ShaderManagerCommon {
2013-08-17 09:23:51 +00:00
public:
ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device);
~ShaderManagerDX9();
2013-08-17 09:23:51 +00:00
void ClearCache(bool deleteThem); // TODO: deleteThem currently not respected
VSShader *ApplyShader(bool useHWTransform, bool useHWTessellation, 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
int GetNumVertexShaders() const { return (int)vsCache_.size(); }
int GetNumFragmentShaders() const { return (int)fsCache_.size(); }
2013-08-17 09:23:51 +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:
void PSUpdateUniforms(u64 dirtyUniforms);
void VSUpdateUniforms(u64 dirtyUniforms);
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);
void VSSetMatrix4x3(int creg, const float *m4x3);
void VSSetMatrix4x3_3(int creg, const float *m4x3);
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);
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]);
2013-08-17 09:23:51 +00:00
void Clear();
LPDIRECT3DDEVICE9 device_;
FShaderID lastFSID_;
VShaderID lastVSID_;
2013-08-17 09:23:51 +00:00
char *codeBuffer_;
VSShader *lastVShader_;
PSShader *lastPShader_;
typedef std::map<FShaderID, PSShader *> FSCache;
2013-08-23 15:11:01 +00:00
FSCache fsCache_;
2013-08-17 09:23:51 +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
};
};