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/DrawEngineD3D11.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 <d3d11.h>20#include <d3d11_1.h>2122#include "Common/Data/Collections/Hashmaps.h"23#include "GPU/GPUState.h"24#include "GPU/Common/GPUDebugInterface.h"25#include "GPU/Common/IndexGenerator.h"26#include "GPU/Common/VertexDecoderCommon.h"27#include "GPU/Common/DrawEngineCommon.h"28#include "GPU/Common/GPUStateUtils.h"29#include "GPU/D3D11/StateMappingD3D11.h"30#include "GPU/D3D11/D3D11Util.h"3132struct DecVtxFormat;33struct UVScale;3435class D3D11VertexShader;36class ShaderManagerD3D11;37class TextureCacheD3D11;38class FramebufferManagerD3D11;3940class TessellationDataTransferD3D11 : public TessellationDataTransfer {41private:42ID3D11DeviceContext *context_;43ID3D11Device *device_;44ID3D11Buffer *buf[3]{};45ID3D11ShaderResourceView *view[3]{};46D3D11_BUFFER_DESC desc{};47int prevSize = 0;48int prevSizeWU = 0, prevSizeWV = 0;49public:50TessellationDataTransferD3D11(ID3D11DeviceContext *context, ID3D11Device *device);51~TessellationDataTransferD3D11();52// Send spline/bezier's control points and weights to vertex shader through structured shader buffer.53void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;54};5556// Handles transform, lighting and drawing.57class DrawEngineD3D11 : public DrawEngineCommon {58public:59DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context);60~DrawEngineD3D11();6162void DeviceLost() override { draw_ = nullptr; }63void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; }6465void SetShaderManager(ShaderManagerD3D11 *shaderManager) {66shaderManager_ = shaderManager;67}68void SetTextureCache(TextureCacheD3D11 *textureCache) {69textureCache_ = textureCache;70}71void SetFramebufferManager(FramebufferManagerD3D11 *fbManager) {72framebufferManager_ = fbManager;73}74void InitDeviceObjects();75void DestroyDeviceObjects();7677void BeginFrame();7879// So that this can be inlined80void Flush() {81if (!numDrawVerts_)82return;83DoFlush();84}8586void FinishDeferred() {87if (!numDrawVerts_)88return;89DecodeVerts(decoded_);90}9192void DispatchFlush() override {93if (!numDrawVerts_)94return;95Flush();96}9798void NotifyConfigChanged() override;99100void ClearInputLayoutMap();101102private:103void Invalidate(InvalidationCallbackFlags flags);104105void DoFlush();106107void ApplyDrawState(int prim);108void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef);109110ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);111112Draw::DrawContext *draw_; // Used for framebuffer related things exclusively.113ID3D11Device *device_;114ID3D11Device1 *device1_;115ID3D11DeviceContext *context_;116ID3D11DeviceContext1 *context1_;117118struct InputLayoutKey {119D3D11VertexShader *vshader;120u32 decFmtId;121bool operator <(const InputLayoutKey &other) const {122if (decFmtId < other.decFmtId)123return true;124if (decFmtId > other.decFmtId)125return false;126return vshader < other.vshader;127}128};129130DenseHashMap<InputLayoutKey, ID3D11InputLayout *> inputLayoutMap_;131132// Other133ShaderManagerD3D11 *shaderManager_ = nullptr;134TextureCacheD3D11 *textureCache_ = nullptr;135FramebufferManagerD3D11 *framebufferManager_ = nullptr;136137// Pushbuffers138PushBufferD3D11 *pushVerts_;139PushBufferD3D11 *pushInds_;140141// D3D11 state object caches.142DenseHashMap<uint64_t, ID3D11BlendState *> blendCache_;143DenseHashMap<uint64_t, ID3D11BlendState1 *> blendCache1_;144DenseHashMap<uint64_t, ID3D11DepthStencilState *> depthStencilCache_;145DenseHashMap<uint32_t, ID3D11RasterizerState *> rasterCache_;146147// Keep the depth state between ApplyDrawState and ApplyDrawStateLate148ID3D11RasterizerState *rasterState_ = nullptr;149ID3D11BlendState *blendState_ = nullptr;150ID3D11BlendState1 *blendState1_ = nullptr;151ID3D11DepthStencilState *depthStencilState_ = nullptr;152153// State keys154D3D11StateKeys keys_{};155D3D11DynamicState dynState_{};156157// Hardware tessellation158TessellationDataTransferD3D11 *tessDataTransferD3D11;159160int lastRenderStepId_ = -1;161};162163164