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/DrawPixel.h
Views: 1401
1
// Copyright (c) 2021- 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 <string>
23
#include <vector>
24
#include <unordered_map>
25
#include <unordered_set>
26
#include "Common/Data/Collections/Hashmaps.h"
27
#include "GPU/Math3D.h"
28
#include "GPU/Software/FuncId.h"
29
#include "GPU/Software/RasterizerRegCache.h"
30
31
class BinManager;
32
33
namespace Rasterizer {
34
35
// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.
36
// We'll still have and want it for the actual function call, to keep the args in vector registers.
37
#if defined(__clang__) || defined(__GNUC__)
38
#pragma GCC diagnostic push
39
#pragma GCC diagnostic ignored "-Wignored-attributes"
40
#endif
41
42
typedef void (SOFTRAST_CALL *SingleFunc)(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID);
43
SingleFunc GetSingleFunc(const PixelFuncID &id, BinManager *binner);
44
45
void Init();
46
void FlushJit();
47
void Shutdown();
48
49
bool CheckDepthTestPassed(GEComparison func, int x, int y, int stride, u16 z);
50
51
bool DescribeCodePtr(const u8 *ptr, std::string &name);
52
53
struct PixelBlendState {
54
bool usesFactors = false;
55
bool usesDstAlpha = false;
56
bool dstFactorIsInverse = false;
57
bool srcColorAsFactor = false;
58
bool dstColorAsFactor = false;
59
bool readsDstPixel = true;
60
};
61
void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id);
62
63
class PixelJitCache : public Rasterizer::CodeBlock {
64
public:
65
PixelJitCache();
66
67
// Returns a pointer to the code to run.
68
SingleFunc GetSingle(const PixelFuncID &id, BinManager *binner);
69
static SingleFunc GenericSingle(const PixelFuncID &id);
70
void Clear() override;
71
void Flush();
72
73
std::string DescribeCodePtr(const u8 *ptr) override;
74
75
private:
76
void Compile(const PixelFuncID &id);
77
SingleFunc CompileSingle(const PixelFuncID &id);
78
79
RegCache::Reg GetPixelID();
80
void UnlockPixelID(RegCache::Reg &r);
81
// Note: these may require a temporary reg.
82
RegCache::Reg GetColorOff(const PixelFuncID &id);
83
RegCache::Reg GetDepthOff(const PixelFuncID &id);
84
RegCache::Reg GetDestStencil(const PixelFuncID &id);
85
86
void WriteConstantPool(const PixelFuncID &id);
87
88
bool Jit_ApplyDepthRange(const PixelFuncID &id);
89
bool Jit_AlphaTest(const PixelFuncID &id);
90
bool Jit_ApplyFog(const PixelFuncID &id);
91
bool Jit_ColorTest(const PixelFuncID &id);
92
bool Jit_StencilAndDepthTest(const PixelFuncID &id);
93
bool Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencilReg, RegCache::Reg maskedReg);
94
bool Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg stencilReg);
95
bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, RegCache::Reg stencilReg);
96
bool Jit_WriteStencilOnly(const PixelFuncID &id, RegCache::Reg stencilReg);
97
bool Jit_DepthTest(const PixelFuncID &id);
98
bool Jit_WriteDepth(const PixelFuncID &id);
99
bool Jit_AlphaBlend(const PixelFuncID &id);
100
bool Jit_BlendFactor(const PixelFuncID &id, RegCache::Reg factorReg, RegCache::Reg dstReg, PixelBlendFactor factor);
101
bool Jit_DstBlendFactor(const PixelFuncID &id, RegCache::Reg srcFactorReg, RegCache::Reg dstFactorReg, RegCache::Reg dstReg);
102
bool Jit_Dither(const PixelFuncID &id);
103
bool Jit_WriteColor(const PixelFuncID &id);
104
bool Jit_ApplyLogicOp(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg maskReg);
105
bool Jit_ConvertTo565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
106
bool Jit_ConvertTo5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
107
bool Jit_ConvertTo4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
108
bool Jit_ConvertFrom565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
109
bool Jit_ConvertFrom5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
110
bool Jit_ConvertFrom4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
111
112
struct LastCache {
113
size_t key;
114
SingleFunc func;
115
int gen = -1;
116
117
bool Match(size_t k, int g) const {
118
return key == k && gen == g;
119
}
120
121
void Set(size_t k, SingleFunc f, int g) {
122
key = k;
123
func = f;
124
gen = g;
125
}
126
};
127
128
DenseHashMap<size_t, SingleFunc> cache_;
129
std::unordered_map<PixelFuncID, const u8 *> addresses_;
130
std::unordered_set<PixelFuncID> compileQueue_;
131
static int clearGen_;
132
static thread_local LastCache lastSingle_;
133
134
const u8 *constBlendHalf_11_4s_ = nullptr;
135
const u8 *constBlendInvert_11_4s_ = nullptr;
136
137
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
138
void Discard();
139
void Discard(Gen::CCFlags cc);
140
141
// Used for any test failure.
142
std::vector<Gen::FixupBranch> discards_;
143
// Used in Jit_ApplyLogicOp() to skip the standard MOV/OR write.
144
std::vector<Gen::FixupBranch> skipStandardWrites_;
145
int stackIDOffset_ = 0;
146
bool colorIs16Bit_ = false;
147
#endif
148
};
149
150
#if defined(__clang__) || defined(__GNUC__)
151
#pragma GCC diagnostic pop
152
#endif
153
154
};
155
156