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