CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Software/Sampler.h
Views: 1401
// Copyright (c) 2017- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "ppsspp_config.h"2021#include <unordered_map>22#include <unordered_set>23#include "Common/Data/Collections/Hashmaps.h"24#include "GPU/Math3D.h"25#include "GPU/Software/FuncId.h"26#include "GPU/Software/RasterizerRegCache.h"2728class BinManager;2930namespace Sampler {3132// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.33// We'll still have and want it for the actual function call, to keep the args in vector registers.34#if defined(__clang__) || defined(__GNUC__)35#pragma GCC diagnostic push36#pragma GCC diagnostic ignored "-Wignored-attributes"37#endif3839typedef Rasterizer::Vec4IntResult(SOFTRAST_CALL *FetchFunc)(int u, int v, const u8 *tptr, int bufw, int level, const SamplerID &samplerID);40FetchFunc GetFetchFunc(SamplerID id, BinManager *binner);4142typedef 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);43NearestFunc GetNearestFunc(SamplerID id, BinManager *binner);4445typedef 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);46LinearFunc GetLinearFunc(SamplerID id, BinManager *binner);4748void Init();49void FlushJit();50void Shutdown();5152bool DescribeCodePtr(const u8 *ptr, std::string &name);5354class SamplerJitCache : public Rasterizer::CodeBlock {55public:56SamplerJitCache();5758// Returns a pointer to the code to run.59NearestFunc GetNearest(const SamplerID &id, BinManager *binner);60LinearFunc GetLinear(const SamplerID &id, BinManager *binner);61FetchFunc GetFetch(const SamplerID &id, BinManager *binner);62void Clear() override;63void Flush();6465std::string DescribeCodePtr(const u8 *ptr) override;6667private:68void Compile(const SamplerID &id);69NearestFunc GetByID(const SamplerID &id, size_t key, BinManager *binner);70FetchFunc CompileFetch(const SamplerID &id);71NearestFunc CompileNearest(const SamplerID &id);72LinearFunc CompileLinear(const SamplerID &id);7374Rasterizer::RegCache::Reg GetSamplerID();75void UnlockSamplerID(Rasterizer::RegCache::Reg &r);7677void WriteConstantPool(const SamplerID &id);7879bool Jit_ReadTextureFormat(const SamplerID &id);80bool Jit_GetTexData(const SamplerID &id, int bitsPerTexel);81bool Jit_GetTexDataSwizzled(const SamplerID &id, int bitsPerTexel);82bool Jit_GetTexDataSwizzled4(const SamplerID &id);83bool Jit_Decode5650(const SamplerID &id);84bool Jit_Decode5551(const SamplerID &id);85bool Jit_Decode4444(const SamplerID &id);86bool Jit_TransformClutIndex(const SamplerID &id, int bitsPerIndex);87bool Jit_ReadClutColor(const SamplerID &id);88bool Jit_GetDXT1Color(const SamplerID &id, int blockSize, int alpha);89bool Jit_ApplyDXTAlpha(const SamplerID &id);90bool Jit_GetTexelCoords(const SamplerID &id);9192bool Jit_GetTexelCoordsQuad(const SamplerID &id);93bool Jit_PrepareDataOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1);94bool Jit_PrepareDataDirectOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);95bool Jit_PrepareDataSwizzledOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int bitsPerTexel);96bool Jit_PrepareDataDXTOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, bool level1, int blockSize);97bool Jit_FetchQuad(const SamplerID &id, bool level1);98bool Jit_GetDataQuad(const SamplerID &id, bool level1, int bitsPerTexel);99bool Jit_TransformClutIndexQuad(const SamplerID &id, int bitsPerIndex);100bool Jit_ReadClutQuad(const SamplerID &id, bool level1);101bool Jit_BlendQuad(const SamplerID &id, bool level1);102bool Jit_DecodeQuad(const SamplerID &id, bool level1);103bool Jit_Decode5650Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);104bool Jit_Decode5551Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);105bool Jit_Decode4444Quad(const SamplerID &id, Rasterizer::RegCache::Reg quadReg);106107bool Jit_ApplyTextureFunc(const SamplerID &id);108109#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86)110int stackArgPos_ = 0;111int stackIDOffset_ = -1;112int stackLevelOffset_ = -1;113int stackUV1Offset_ = 0;114#endif115116const u8 *constWidthHeight256f_ = nullptr;117const u8 *constWidthMinus1i_ = nullptr;118const u8 *constHeightMinus1i_ = nullptr;119const u8 *constUNext_ = nullptr;120const u8 *constVNext_ = nullptr;121const u8 *constOnes32_ = nullptr;122const u8 *constOnes16_ = nullptr;123const u8 *constMaxTexel32_ = nullptr;124const u8 *const10All16_ = nullptr;125const u8 *const10Low_ = nullptr;126const u8 *const10All8_ = nullptr;127const u8 *const5551Swizzle_ = nullptr;128const u8 *const5650Swizzle_ = nullptr;129130struct LastCache {131size_t key;132NearestFunc func;133int gen = -1;134135bool Match(size_t k, int g) const {136return key == k && gen == g;137}138139void Set(size_t k, NearestFunc f, int g) {140key = k;141func = f;142gen = g;143}144};145146DenseHashMap<size_t, NearestFunc> cache_;147std::unordered_map<SamplerID, const u8 *> addresses_;148std::unordered_set<SamplerID> compileQueue_;149static int clearGen_;150static thread_local LastCache lastFetch_;151static thread_local LastCache lastNearest_;152static thread_local LastCache lastLinear_;153};154155#if defined(__clang__) || defined(__GNUC__)156#pragma GCC diagnostic pop157#endif158159};160161162