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/Directx9/ShaderManagerDX9.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 <map>20#include <cstdint>21#include <d3d9.h>22#include <wrl/client.h>2324#include "Common/CommonTypes.h"25#include "GPU/Common/VertexShaderGenerator.h"26#include "GPU/Common/FragmentShaderGenerator.h"27#include "GPU/Common/ShaderCommon.h"28#include "GPU/Common/ShaderId.h"29#include "Common/Math/lin/matrix4x4.h"3031class PSShader;32class VSShader;3334// Real public interface3536class PSShader {37public:38PSShader(LPDIRECT3DDEVICE9 device, FShaderID id, const char *code);39~PSShader();4041const std::string &source() const { return source_; }4243bool Failed() const { return failed_; }4445std::string GetShaderString(DebugShaderStringType type) const;4647Microsoft::WRL::ComPtr<IDirect3DPixelShader9> shader;4849protected:50std::string source_;51bool failed_ = false;52FShaderID id_;53};5455class VSShader {56public:57VSShader(LPDIRECT3DDEVICE9 device, VShaderID id, const char *code, bool useHWTransform);58~VSShader();5960const std::string &source() const { return source_; }6162bool Failed() const { return failed_; }63bool UseHWTransform() const { return useHWTransform_; }6465std::string GetShaderString(DebugShaderStringType type) const;6667Microsoft::WRL::ComPtr<IDirect3DVertexShader9> shader;6869protected:70std::string source_;71bool failed_ = false;72bool useHWTransform_;73VShaderID id_;74};7576class ShaderManagerDX9 : public ShaderManagerCommon {77public:78ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device);79~ShaderManagerDX9();8081void ClearShaders() override;82VSShader *ApplyShader(bool useHWTransform, bool useHWTessellation, VertexDecoder *decoder, bool weightsAsFloat, bool useSkinInDecode, const ComputedPipelineState &pipelineState);83void DirtyLastShader() override;8485int GetNumVertexShaders() const { return (int)vsCache_.size(); }86int GetNumFragmentShaders() const { return (int)fsCache_.size(); }8788void DeviceLost() override { draw_ = nullptr; }89void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; }9091std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) override;92std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) override;9394private:95void PSUpdateUniforms(u64 dirtyUniforms);96void VSUpdateUniforms(u64 dirtyUniforms);97inline void PSSetColorUniform3Alpha255(int creg, u32 color, u8 alpha);98inline void PSSetColorUniform3(int creg, u32 color);99inline void PSSetFloat(int creg, float value);100inline void PSSetFloatArray(int creg, const float *value, int count);101102void VSSetMatrix4x3_3(int creg, const float *m4x3);103inline void VSSetColorUniform3(int creg, u32 color);104inline void VSSetColorUniform3ExtraFloat(int creg, u32 color, float extra);105inline void VSSetColorUniform3Alpha(int creg, u32 color, u8 alpha);106void VSSetMatrix(int creg, const float* pMatrix);107void VSSetFloat(int creg, float value);108void VSSetFloatArray(int creg, const float *value, int count);109void VSSetFloat24Uniform3(int creg, const u32 data[3]);110void VSSetFloat24Uniform3Normalized(int creg, const u32 data[3]);111void VSSetFloatUniform4(int creg, const float data[4]);112113void Clear();114115LPDIRECT3DDEVICE9 device_;116117FShaderID lastFSID_;118VShaderID lastVSID_;119120char *codeBuffer_;121122VSShader *lastVShader_ = nullptr;123PSShader *lastPShader_ = nullptr;124125typedef std::map<FShaderID, PSShader *> FSCache;126FSCache fsCache_;127128typedef std::map<VShaderID, VSShader *> VSCache;129VSCache vsCache_;130};131132133