2017-05-09 19:48:05 -07:00
|
|
|
// Copyright (c) 2017- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2022-11-20 12:04:02 -08:00
|
|
|
#include <unordered_set>
|
2022-12-02 20:59:13 -08:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2017-05-09 19:48:05 -07:00
|
|
|
#include "GPU/Math3D.h"
|
2021-11-20 13:11:52 -08:00
|
|
|
#include "GPU/Software/FuncId.h"
|
2021-11-27 17:12:48 -08:00
|
|
|
#include "GPU/Software/RasterizerRegCache.h"
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2022-12-06 19:07:43 -08:00
|
|
|
class BinManager;
|
|
|
|
|
2017-05-09 19:48:05 -07:00
|
|
|
namespace Sampler {
|
|
|
|
|
2021-12-11 10:03:50 -08:00
|
|
|
// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.
|
|
|
|
// We'll still have and want it for the actual function call, to keep the args in vector registers.
|
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wignored-attributes"
|
|
|
|
#endif
|
|
|
|
|
2022-01-15 15:20:21 -08:00
|
|
|
typedef Rasterizer::Vec4IntResult(SOFTRAST_CALL *FetchFunc)(int u, int v, const u8 *tptr, int bufw, int level, const SamplerID &samplerID);
|
2022-12-06 19:07:43 -08:00
|
|
|
FetchFunc GetFetchFunc(SamplerID id, BinManager *binner);
|
2021-12-31 10:35:26 -08:00
|
|
|
|
2022-10-23 01:15:43 -07:00
|
|
|
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);
|
2022-12-06 19:07:43 -08:00
|
|
|
NearestFunc GetNearestFunc(SamplerID id, BinManager *binner);
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2022-10-23 01:15:43 -07:00
|
|
|
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);
|
2022-12-06 19:07:43 -08:00
|
|
|
LinearFunc GetLinearFunc(SamplerID id, BinManager *binner);
|
2017-05-21 16:16:03 -07:00
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
void Init();
|
2022-11-20 12:04:02 -08:00
|
|
|
void FlushJit();
|
2017-05-10 17:31:34 -07:00
|
|
|
void Shutdown();
|
|
|
|
|
2017-05-10 20:36:09 -07:00
|
|
|
bool DescribeCodePtr(const u8 *ptr, std::string &name);
|
|
|
|
|
2021-11-27 17:12:48 -08:00
|
|
|
class SamplerJitCache : public Rasterizer::CodeBlock {
|
2017-05-10 17:31:34 -07:00
|
|
|
public:
|
|
|
|
SamplerJitCache();
|
|
|
|
|
|
|
|
// Returns a pointer to the code to run.
|
2022-12-06 19:07:43 -08:00
|
|
|
NearestFunc GetNearest(const SamplerID &id, BinManager *binner);
|
|
|
|
LinearFunc GetLinear(const SamplerID &id, BinManager *binner);
|
|
|
|
FetchFunc GetFetch(const SamplerID &id, BinManager *binner);
|
2022-01-18 11:19:03 -08:00
|
|
|
void Clear() override;
|
2022-11-20 12:04:02 -08:00
|
|
|
void Flush();
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2022-01-18 11:19:03 -08:00
|
|
|
std::string DescribeCodePtr(const u8 *ptr) override;
|
2017-05-10 20:36:09 -07:00
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
private:
|
2022-01-29 20:28:20 -08:00
|
|
|
void Compile(const SamplerID &id);
|
2022-12-06 19:16:19 -08:00
|
|
|
NearestFunc GetByID(const SamplerID &id, size_t key, BinManager *binner);
|
2021-12-31 10:35:26 -08:00
|
|
|
FetchFunc CompileFetch(const SamplerID &id);
|
|
|
|
NearestFunc CompileNearest(const SamplerID &id);
|
2017-05-21 16:16:03 -07:00
|
|
|
LinearFunc CompileLinear(const SamplerID &id);
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2022-01-15 17:22:43 -08:00
|
|
|
Rasterizer::RegCache::Reg GetSamplerID();
|
|
|
|
void UnlockSamplerID(Rasterizer::RegCache::Reg &r);
|
2021-12-28 15:37:25 -08:00
|
|
|
|
2021-12-31 11:42:37 -08:00
|
|
|
void WriteConstantPool(const SamplerID &id);
|
|
|
|
|
2017-05-10 17:38:38 -07:00
|
|
|
bool Jit_ReadTextureFormat(const SamplerID &id);
|
2017-05-10 17:35:16 -07:00
|
|
|
bool Jit_GetTexData(const SamplerID &id, int bitsPerTexel);
|
2017-05-10 18:04:22 -07:00
|
|
|
bool Jit_GetTexDataSwizzled(const SamplerID &id, int bitsPerTexel);
|
2021-12-12 18:42:42 -08:00
|
|
|
bool Jit_GetTexDataSwizzled4(const SamplerID &id);
|
2022-01-09 11:10:12 -08:00
|
|
|
bool Jit_Decode5650(const SamplerID &id);
|
|
|
|
bool Jit_Decode5551(const SamplerID &id);
|
|
|
|
bool Jit_Decode4444(const SamplerID &id);
|
2017-05-10 19:22:39 -07:00
|
|
|
bool Jit_TransformClutIndex(const SamplerID &id, int bitsPerIndex);
|
2017-05-10 17:35:16 -07:00
|
|
|
bool Jit_ReadClutColor(const SamplerID &id);
|
2021-09-12 13:57:28 -07:00
|
|
|
bool Jit_GetDXT1Color(const SamplerID &id, int blockSize, int alpha);
|
2021-09-12 14:53:55 -07:00
|
|
|
bool Jit_ApplyDXTAlpha(const SamplerID &id);
|
2021-12-31 17:26:22 -08:00
|
|
|
bool Jit_GetTexelCoords(const SamplerID &id);
|
2017-05-10 17:35:16 -07:00
|
|
|
|
2021-12-28 09:56:51 -08:00
|
|
|
bool Jit_GetTexelCoordsQuad(const SamplerID &id);
|
2021-12-31 13:02:58 -08:00
|
|
|
bool Jit_PrepareDataOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1);
|
|
|
|
bool Jit_PrepareDataDirectOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);
|
|
|
|
bool Jit_PrepareDataSwizzledOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);
|
2022-02-05 13:04:17 -08:00
|
|
|
bool Jit_PrepareDataDXTOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int blockSize);
|
2022-01-02 17:17:40 -08:00
|
|
|
bool Jit_FetchQuad(const SamplerID &id, bool level1);
|
2022-01-02 16:38:18 -08:00
|
|
|
bool Jit_GetDataQuad(const SamplerID &id, bool level1, int bitsPerTexel);
|
2022-01-02 13:52:48 -08:00
|
|
|
bool Jit_TransformClutIndexQuad(const SamplerID &id, int bitsPerIndex);
|
2022-01-02 10:45:03 -08:00
|
|
|
bool Jit_ReadClutQuad(const SamplerID &id, bool level1);
|
2021-12-28 16:22:54 -08:00
|
|
|
bool Jit_BlendQuad(const SamplerID &id, bool level1);
|
2022-01-01 14:17:08 -08:00
|
|
|
bool Jit_DecodeQuad(const SamplerID &id, bool level1);
|
|
|
|
bool Jit_Decode5650Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
|
|
|
|
bool Jit_Decode5551Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
|
|
|
|
bool Jit_Decode4444Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);
|
2021-12-12 18:42:42 -08:00
|
|
|
|
2021-12-28 17:52:17 -08:00
|
|
|
bool Jit_ApplyTextureFunc(const SamplerID &id);
|
|
|
|
|
2022-01-18 11:19:03 -08:00
|
|
|
#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86)
|
2021-12-28 09:56:51 -08:00
|
|
|
int stackArgPos_ = 0;
|
2022-01-15 17:22:43 -08:00
|
|
|
int stackIDOffset_ = -1;
|
2022-01-29 22:20:46 -08:00
|
|
|
int stackLevelOffset_ = -1;
|
2022-01-28 23:50:54 -08:00
|
|
|
int stackUV1Offset_ = 0;
|
2017-05-10 17:31:34 -07:00
|
|
|
#endif
|
|
|
|
|
2022-01-24 20:14:00 -08:00
|
|
|
const u8 *constWidthHeight256f_ = nullptr;
|
2021-12-28 09:56:51 -08:00
|
|
|
const u8 *constWidthMinus1i_ = nullptr;
|
|
|
|
const u8 *constHeightMinus1i_ = nullptr;
|
|
|
|
const u8 *constUNext_ = nullptr;
|
|
|
|
const u8 *constVNext_ = nullptr;
|
2021-12-28 17:52:17 -08:00
|
|
|
const u8 *constOnes32_ = nullptr;
|
|
|
|
const u8 *constOnes16_ = nullptr;
|
2022-09-10 19:33:02 -07:00
|
|
|
const u8 *constMaxTexel32_ = nullptr;
|
2021-12-30 15:23:48 -08:00
|
|
|
const u8 *const10All16_ = nullptr;
|
2021-12-28 15:37:25 -08:00
|
|
|
const u8 *const10Low_ = nullptr;
|
2021-12-30 15:23:48 -08:00
|
|
|
const u8 *const10All8_ = nullptr;
|
2022-01-01 14:17:08 -08:00
|
|
|
const u8 *const5551Swizzle_ = nullptr;
|
|
|
|
const u8 *const5650Swizzle_ = nullptr;
|
2021-12-28 09:56:51 -08:00
|
|
|
|
2022-12-06 20:26:24 -08:00
|
|
|
struct LastCache {
|
2022-12-06 19:16:19 -08:00
|
|
|
size_t key;
|
|
|
|
NearestFunc func;
|
2022-12-06 20:55:52 -08:00
|
|
|
int gen = -1;
|
2022-12-06 20:26:24 -08:00
|
|
|
|
2022-12-06 20:55:52 -08:00
|
|
|
bool Match(size_t k, int g) const {
|
|
|
|
return key == k && gen == g;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(size_t k, NearestFunc f, int g) {
|
2022-12-06 20:26:24 -08:00
|
|
|
key = k;
|
|
|
|
func = f;
|
2022-12-06 20:55:52 -08:00
|
|
|
gen = g;
|
2022-12-06 20:26:24 -08:00
|
|
|
}
|
2022-12-06 19:16:19 -08:00
|
|
|
};
|
|
|
|
|
2023-09-11 12:02:56 +02:00
|
|
|
DenseHashMap<size_t, NearestFunc> cache_;
|
2017-05-21 16:16:03 -07:00
|
|
|
std::unordered_map<SamplerID, const u8 *> addresses_;
|
2022-11-20 12:04:02 -08:00
|
|
|
std::unordered_set<SamplerID> compileQueue_;
|
2023-02-22 21:15:03 -08:00
|
|
|
static int clearGen_;
|
2022-12-06 20:26:24 -08:00
|
|
|
static thread_local LastCache lastFetch_;
|
|
|
|
static thread_local LastCache lastNearest_;
|
|
|
|
static thread_local LastCache lastLinear_;
|
2017-05-10 17:31:34 -07:00
|
|
|
};
|
2017-05-09 19:48:05 -07:00
|
|
|
|
2021-12-11 10:03:50 -08:00
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2017-05-09 19:48:05 -07:00
|
|
|
};
|