CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/GPU/Software/Sampler.h
Views: 1401
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 "ppsspp_config.h"
21
22
#include <unordered_map>
23
#include <unordered_set>
24
#include "Common/Data/Collections/Hashmaps.h"
25
#include "GPU/Math3D.h"
26
#include "GPU/Software/FuncId.h"
27
#include "GPU/Software/RasterizerRegCache.h"
28
29
class BinManager;
30
31
namespace Sampler {
32
33
// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.
34
// We'll still have and want it for the actual function call, to keep the args in vector registers.
35
#if defined(__clang__) || defined(__GNUC__)
36
#pragma GCC diagnostic push
37
#pragma GCC diagnostic ignored "-Wignored-attributes"
38
#endif
39
40
typedef Rasterizer::Vec4IntResult(SOFTRAST_CALL *FetchFunc)(int u, int v, const u8 *tptr, int bufw, int level, const SamplerID &samplerID);
41
FetchFunc GetFetchFunc(SamplerID id, BinManager *binner);
42
43
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *NearestFunc)(float s, float t, Rasterizer::Vec4IntArg prim_color, const u8 *const *tptr, const uint16_t *bufw, int level, int levelFrac, const SamplerID &samplerID);
44
NearestFunc GetNearestFunc(SamplerID id, BinManager *binner);
45
46
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *LinearFunc)(float s, float t, Rasterizer::Vec4IntArg prim_color, const u8 *const *tptr, const uint16_t *bufw, int level, int levelFrac, const SamplerID &samplerID);
47
LinearFunc GetLinearFunc(SamplerID id, BinManager *binner);
48
49
void Init();
50
void FlushJit();
51
void Shutdown();
52
53
bool DescribeCodePtr(const u8 *ptr, std::string &name);
54
55
class SamplerJitCache : public Rasterizer::CodeBlock {
56
public:
57
SamplerJitCache();
58
59
// Returns a pointer to the code to run.
60
NearestFunc GetNearest(const SamplerID &id, BinManager *binner);
61
LinearFunc GetLinear(const SamplerID &id, BinManager *binner);
62
FetchFunc GetFetch(const SamplerID &id, BinManager *binner);
63
void Clear() override;
64
void Flush();
65
66
std::string DescribeCodePtr(const u8 *ptr) override;
67
68
private:
69
void Compile(const SamplerID &id);
70
NearestFunc GetByID(const SamplerID &id, size_t key, BinManager *binner);
71
FetchFunc CompileFetch(const SamplerID &id);
72
NearestFunc CompileNearest(const SamplerID &id);
73
LinearFunc CompileLinear(const SamplerID &id);
74
75
Rasterizer::RegCache::Reg GetSamplerID();
76
void UnlockSamplerID(Rasterizer::RegCache::Reg &r);
77
78
void WriteConstantPool(const SamplerID &id);
79
80
bool Jit_ReadTextureFormat(const SamplerID &id);
81
bool Jit_GetTexData(const SamplerID &id, int bitsPerTexel);
82
bool Jit_GetTexDataSwizzled(const SamplerID &id, int bitsPerTexel);
83
bool Jit_GetTexDataSwizzled4(const SamplerID &id);
84
bool Jit_Decode5650(const SamplerID &id);
85
bool Jit_Decode5551(const SamplerID &id);
86
bool Jit_Decode4444(const SamplerID &id);
87
bool Jit_TransformClutIndex(const SamplerID &id, int bitsPerIndex);
88
bool Jit_ReadClutColor(const SamplerID &id);
89
bool Jit_GetDXT1Color(const SamplerID &id, int blockSize, int alpha);
90
bool Jit_ApplyDXTAlpha(const SamplerID &id);
91
bool Jit_GetTexelCoords(const SamplerID &id);
92
93
bool Jit_GetTexelCoordsQuad(const SamplerID &id);
94
bool Jit_PrepareDataOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1);
95
bool Jit_PrepareDataDirectOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);
96
bool Jit_PrepareDataSwizzledOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);
97
bool Jit_PrepareDataDXTOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int blockSize);
98
bool Jit_FetchQuad(const SamplerID &id, bool level1);
99
bool Jit_GetDataQuad(const SamplerID &id, bool level1, int bitsPerTexel);
100
bool Jit_TransformClutIndexQuad(const SamplerID &id, int bitsPerIndex);
101
bool Jit_ReadClutQuad(const SamplerID &id, bool level1);
102
bool Jit_BlendQuad(const SamplerID &id, bool level1);
103
bool Jit_DecodeQuad(const SamplerID &id, bool level1);
104
bool Jit_Decode5650Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
105
bool Jit_Decode5551Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
106
bool Jit_Decode4444Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
107
108
bool Jit_ApplyTextureFunc(const SamplerID &id);
109
110
#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86)
111
int stackArgPos_ = 0;
112
int stackIDOffset_ = -1;
113
int stackLevelOffset_ = -1;
114
int stackUV1Offset_ = 0;
115
#endif
116
117
const u8 *constWidthHeight256f_ = nullptr;
118
const u8 *constWidthMinus1i_ = nullptr;
119
const u8 *constHeightMinus1i_ = nullptr;
120
const u8 *constUNext_ = nullptr;
121
const u8 *constVNext_ = nullptr;
122
const u8 *constOnes32_ = nullptr;
123
const u8 *constOnes16_ = nullptr;
124
const u8 *constMaxTexel32_ = nullptr;
125
const u8 *const10All16_ = nullptr;
126
const u8 *const10Low_ = nullptr;
127
const u8 *const10All8_ = nullptr;
128
const u8 *const5551Swizzle_ = nullptr;
129
const u8 *const5650Swizzle_ = nullptr;
130
131
struct LastCache {
132
size_t key;
133
NearestFunc func;
134
int gen = -1;
135
136
bool Match(size_t k, int g) const {
137
return key == k && gen == g;
138
}
139
140
void Set(size_t k, NearestFunc f, int g) {
141
key = k;
142
func = f;
143
gen = g;
144
}
145
};
146
147
DenseHashMap<size_t, NearestFunc> cache_;
148
std::unordered_map<SamplerID, const u8 *> addresses_;
149
std::unordered_set<SamplerID> compileQueue_;
150
static int clearGen_;
151
static thread_local LastCache lastFetch_;
152
static thread_local LastCache lastNearest_;
153
static thread_local LastCache lastLinear_;
154
};
155
156
#if defined(__clang__) || defined(__GNUC__)
157
#pragma GCC diagnostic pop
158
#endif
159
160
};
161
162