Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/D3D11/TextureCacheD3D11.h
3187 views
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
#include <wrl/client.h>
24
25
#include "GPU/GPU.h"
26
#include "GPU/GPUCommon.h"
27
#include "GPU/Common/TextureCacheCommon.h"
28
29
struct VirtualFramebuffer;
30
31
class FramebufferManagerD3D11;
32
class TextureShaderCache;
33
class ShaderManagerD3D11;
34
35
class SamplerCacheD3D11 {
36
public:
37
SamplerCacheD3D11() {}
38
~SamplerCacheD3D11();
39
HRESULT GetOrCreateSampler(ID3D11Device *device, const SamplerCacheKey &key, ID3D11SamplerState **);
40
void Destroy() {
41
cache_.clear();
42
}
43
44
private:
45
std::map<SamplerCacheKey, Microsoft::WRL::ComPtr<ID3D11SamplerState>> cache_;
46
};
47
48
#define D3D11_INVALID_TEX (ID3D11ShaderResourceView *)(-1LL)
49
50
class TextureCacheD3D11 : public TextureCacheCommon {
51
public:
52
TextureCacheD3D11(Draw::DrawContext *draw, Draw2D *draw2D);
53
~TextureCacheD3D11();
54
55
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager);
56
57
void ForgetLastTexture() override;
58
59
bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override;
60
61
void DeviceLost() override;
62
void DeviceRestore(Draw::DrawContext *draw) override;
63
64
void InitDeviceObjects();
65
void DestroyDeviceObjects();
66
67
protected:
68
void BindTexture(TexCacheEntry *entry) override;
69
void Unbind() override;
70
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
71
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
72
void ApplySamplingParams(const SamplerCacheKey &key) override;
73
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
74
75
private:
76
DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
77
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
78
79
void BuildTexture(TexCacheEntry *const entry) override;
80
81
ID3D11Device *device_;
82
ID3D11DeviceContext *context_;
83
84
ID3D11Resource *&DxTex(const TexCacheEntry *entry) const {
85
return (ID3D11Resource *&)entry->texturePtr;
86
}
87
ID3D11ShaderResourceView *DxView(const TexCacheEntry *entry) const {
88
return (ID3D11ShaderResourceView *)entry->textureView;
89
}
90
91
SamplerCacheD3D11 samplerCache_;
92
93
ID3D11ShaderResourceView *lastBoundTexture_ = D3D11_INVALID_TEX;
94
Microsoft::WRL::ComPtr<ID3D11Buffer> depalConstants_;
95
Microsoft::WRL::ComPtr<ID3D11SamplerState> samplerPoint2DClamp_;
96
Microsoft::WRL::ComPtr<ID3D11SamplerState> samplerLinear2DClamp_;
97
};
98
99
DXGI_FORMAT GetClutDestFormatD3D11(GEPaletteFormat format);
100
101