1 // Copyright (c) 2017- PPSSPP Project. 2 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, version 2.0 or later versions. 6 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License 2.0 for more details. 11 12 // A copy of the GPL 2.0 should have been included with the program. 13 // If not, see http://www.gnu.org/licenses/ 14 15 // Official git repository and contact information can be found at 16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. 17 18 #pragma once 19 20 #include "Common/CommonWindows.h" 21 22 #include <d3d11.h> 23 24 #include "GPU/GPU.h" 25 #include "GPU/GPUInterface.h" 26 #include "GPU/D3D11/TextureScalerD3D11.h" 27 #include "GPU/Common/TextureCacheCommon.h" 28 29 struct VirtualFramebuffer; 30 31 class FramebufferManagerD3D11; 32 class DepalShaderCacheD3D11; 33 class ShaderManagerD3D11; 34 35 class SamplerCacheD3D11 { 36 public: SamplerCacheD3D11()37 SamplerCacheD3D11() {} 38 ~SamplerCacheD3D11(); 39 ID3D11SamplerState *GetOrCreateSampler(ID3D11Device *device, const SamplerCacheKey &key); 40 41 private: 42 std::map<SamplerCacheKey, ID3D11SamplerState *> cache_; 43 }; 44 45 class TextureCacheD3D11 : public TextureCacheCommon { 46 public: 47 TextureCacheD3D11(Draw::DrawContext *draw); 48 ~TextureCacheD3D11(); 49 50 void StartFrame(); 51 52 void SetFramebufferManager(FramebufferManagerD3D11 *fbManager); SetDepalShaderCache(DepalShaderCacheD3D11 * dpCache)53 void SetDepalShaderCache(DepalShaderCacheD3D11 *dpCache) { 54 depalShaderCache_ = dpCache; 55 } SetShaderManager(ShaderManagerD3D11 * sm)56 void SetShaderManager(ShaderManagerD3D11 *sm) { 57 shaderManager_ = sm; 58 } 59 60 void ForgetLastTexture() override; 61 void InvalidateLastTexture() override; 62 63 bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; 64 65 protected: 66 void BindTexture(TexCacheEntry *entry) override; 67 void Unbind() override; 68 void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override; 69 70 private: 71 void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int maxLevel, int scaleFactor, DXGI_FORMAT dstFmt); 72 DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; 73 static TexCacheEntry::TexStatus CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h); 74 void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; 75 76 void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; 77 void BuildTexture(TexCacheEntry *const entry) override; 78 79 ID3D11Device *device_; 80 ID3D11DeviceContext *context_; 81 DxTex(TexCacheEntry * entry)82 ID3D11Texture2D *&DxTex(TexCacheEntry *entry) { 83 return (ID3D11Texture2D *&)entry->texturePtr; 84 } DxView(TexCacheEntry * entry)85 ID3D11ShaderResourceView *DxView(TexCacheEntry *entry) { 86 return (ID3D11ShaderResourceView *)entry->textureView; 87 } 88 89 TextureScalerD3D11 scaler; 90 91 SamplerCacheD3D11 samplerCache_; 92 93 ID3D11ShaderResourceView *lastBoundTexture; 94 ID3D11Buffer *depalConstants_; 95 96 FramebufferManagerD3D11 *framebufferManagerD3D11_; 97 DepalShaderCacheD3D11 *depalShaderCache_; 98 ShaderManagerD3D11 *shaderManager_; 99 100 }; 101 102 DXGI_FORMAT GetClutDestFormatD3D11(GEPaletteFormat format); 103