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/D3D11/ShaderManagerD3D11.h
Views: 1401
// Copyright (c) 2017- 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>2021#include <d3d11.h>2223#include "Common/CommonTypes.h"24#include "GPU/Common/ShaderCommon.h"25#include "GPU/Common/ShaderId.h"26#include "GPU/Common/ShaderUniforms.h"27#include "GPU/Common/FragmentShaderGenerator.h"2829class D3D11Context;30class D3D11PushBuffer;3132class D3D11FragmentShader {33public:34D3D11FragmentShader(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel, FShaderID id, const char *code, bool useHWTransform);35~D3D11FragmentShader();3637const std::string &source() const { return source_; }3839bool Failed() const { return failed_; }40bool UseHWTransform() const { return useHWTransform_; }4142std::string GetShaderString(DebugShaderStringType type) const;43ID3D11PixelShader *GetShader() const { return module_; }4445protected:46ID3D11PixelShader *module_ = nullptr;4748ID3D11Device *device_;49std::string source_;50bool failed_ = false;51bool useHWTransform_;52FShaderID id_;53};5455class D3D11VertexShader {56public:57D3D11VertexShader(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel, VShaderID id, const char *code, bool useHWTransform);58~D3D11VertexShader();5960const std::string &source() const { return source_; }61const std::vector<uint8_t> &bytecode() const { return bytecode_; }62bool Failed() const { return failed_; }63bool UseHWTransform() const { return useHWTransform_; }6465std::string GetShaderString(DebugShaderStringType type) const;66ID3D11VertexShader *GetShader() const { return module_; }6768protected:69ID3D11VertexShader *module_ = nullptr;7071ID3D11Device *device_;72std::string source_;73std::vector<uint8_t> bytecode_;7475bool failed_ = false;76bool useHWTransform_;77VShaderID id_;78};7980class D3D11PushBuffer;8182class ShaderManagerD3D11 : public ShaderManagerCommon {83public:84ShaderManagerD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context, D3D_FEATURE_LEVEL featureLevel);85~ShaderManagerD3D11();8687void GetShaders(int prim, VertexDecoder *decoder, D3D11VertexShader **vshader, D3D11FragmentShader **fshader, const ComputedPipelineState &pipelineState, bool useHWTransform, bool useHWTessellation, bool weightsAsFloat, bool useSkinInDecode);88void ClearShaders() override;89void DirtyLastShader() override;9091void DeviceLost() override { draw_ = nullptr; }92void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; }93int GetNumVertexShaders() const { return (int)vsCache_.size(); }94int GetNumFragmentShaders() const { return (int)fsCache_.size(); }9596std::vector<std::string> DebugGetShaderIDs(DebugShaderType type) override;97std::string DebugGetShaderString(std::string id, DebugShaderType type, DebugShaderStringType stringType) override;9899uint64_t UpdateUniforms(bool useBufferedRendering);100void BindUniforms();101102// TODO: Avoid copying these buffers if same as last draw, can still point to it assuming we're still in the same pushbuffer.103// Applies dirty changes and copies the buffer.104bool IsBaseDirty() { return true; }105bool IsLightDirty() { return true; }106bool IsBoneDirty() { return true; }107108private:109void Clear();110111ID3D11Device *device_;112ID3D11DeviceContext *context_;113D3D_FEATURE_LEVEL featureLevel_;114115typedef std::map<FShaderID, D3D11FragmentShader *> FSCache;116FSCache fsCache_;117118typedef std::map<VShaderID, D3D11VertexShader *> VSCache;119VSCache vsCache_;120121char *codeBuffer_;122123// Uniform block scratchpad. These (the relevant ones) are copied to the current pushbuffer at draw time.124UB_VS_FS_Base ub_base;125UB_VS_Lights ub_lights;126UB_VS_Bones ub_bones;127128// Not actual pushbuffers, requires D3D11.1, let's try to live without that first.129ID3D11Buffer *push_base;130ID3D11Buffer *push_lights;131ID3D11Buffer *push_bones;132133D3D11FragmentShader *lastFShader_ = nullptr;134D3D11VertexShader *lastVShader_ = nullptr;135136FShaderID lastFSID_;137VShaderID lastVSID_;138};139140141