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/DrawPixel.h
Views: 1401
// Copyright (c) 2021- 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 <string>22#include <vector>23#include <unordered_map>24#include <unordered_set>25#include "Common/Data/Collections/Hashmaps.h"26#include "GPU/Math3D.h"27#include "GPU/Software/FuncId.h"28#include "GPU/Software/RasterizerRegCache.h"2930class BinManager;3132namespace Rasterizer {3334// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.35// We'll still have and want it for the actual function call, to keep the args in vector registers.36#if defined(__clang__) || defined(__GNUC__)37#pragma GCC diagnostic push38#pragma GCC diagnostic ignored "-Wignored-attributes"39#endif4041typedef void (SOFTRAST_CALL *SingleFunc)(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID);42SingleFunc GetSingleFunc(const PixelFuncID &id, BinManager *binner);4344void Init();45void FlushJit();46void Shutdown();4748bool CheckDepthTestPassed(GEComparison func, int x, int y, int stride, u16 z);4950bool DescribeCodePtr(const u8 *ptr, std::string &name);5152struct PixelBlendState {53bool usesFactors = false;54bool usesDstAlpha = false;55bool dstFactorIsInverse = false;56bool srcColorAsFactor = false;57bool dstColorAsFactor = false;58bool readsDstPixel = true;59};60void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id);6162class PixelJitCache : public Rasterizer::CodeBlock {63public:64PixelJitCache();6566// Returns a pointer to the code to run.67SingleFunc GetSingle(const PixelFuncID &id, BinManager *binner);68static SingleFunc GenericSingle(const PixelFuncID &id);69void Clear() override;70void Flush();7172std::string DescribeCodePtr(const u8 *ptr) override;7374private:75void Compile(const PixelFuncID &id);76SingleFunc CompileSingle(const PixelFuncID &id);7778RegCache::Reg GetPixelID();79void UnlockPixelID(RegCache::Reg &r);80// Note: these may require a temporary reg.81RegCache::Reg GetColorOff(const PixelFuncID &id);82RegCache::Reg GetDepthOff(const PixelFuncID &id);83RegCache::Reg GetDestStencil(const PixelFuncID &id);8485void WriteConstantPool(const PixelFuncID &id);8687bool Jit_ApplyDepthRange(const PixelFuncID &id);88bool Jit_AlphaTest(const PixelFuncID &id);89bool Jit_ApplyFog(const PixelFuncID &id);90bool Jit_ColorTest(const PixelFuncID &id);91bool Jit_StencilAndDepthTest(const PixelFuncID &id);92bool Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencilReg, RegCache::Reg maskedReg);93bool Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg stencilReg);94bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, RegCache::Reg stencilReg);95bool Jit_WriteStencilOnly(const PixelFuncID &id, RegCache::Reg stencilReg);96bool Jit_DepthTest(const PixelFuncID &id);97bool Jit_WriteDepth(const PixelFuncID &id);98bool Jit_AlphaBlend(const PixelFuncID &id);99bool Jit_BlendFactor(const PixelFuncID &id, RegCache::Reg factorReg, RegCache::Reg dstReg, PixelBlendFactor factor);100bool Jit_DstBlendFactor(const PixelFuncID &id, RegCache::Reg srcFactorReg, RegCache::Reg dstFactorReg, RegCache::Reg dstReg);101bool Jit_Dither(const PixelFuncID &id);102bool Jit_WriteColor(const PixelFuncID &id);103bool Jit_ApplyLogicOp(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg maskReg);104bool Jit_ConvertTo565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);105bool Jit_ConvertTo5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);106bool Jit_ConvertTo4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);107bool Jit_ConvertFrom565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);108bool Jit_ConvertFrom5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);109bool Jit_ConvertFrom4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);110111struct LastCache {112size_t key;113SingleFunc func;114int gen = -1;115116bool Match(size_t k, int g) const {117return key == k && gen == g;118}119120void Set(size_t k, SingleFunc f, int g) {121key = k;122func = f;123gen = g;124}125};126127DenseHashMap<size_t, SingleFunc> cache_;128std::unordered_map<PixelFuncID, const u8 *> addresses_;129std::unordered_set<PixelFuncID> compileQueue_;130static int clearGen_;131static thread_local LastCache lastSingle_;132133const u8 *constBlendHalf_11_4s_ = nullptr;134const u8 *constBlendInvert_11_4s_ = nullptr;135136#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)137void Discard();138void Discard(Gen::CCFlags cc);139140// Used for any test failure.141std::vector<Gen::FixupBranch> discards_;142// Used in Jit_ApplyLogicOp() to skip the standard MOV/OR write.143std::vector<Gen::FixupBranch> skipStandardWrites_;144int stackIDOffset_ = 0;145bool colorIs16Bit_ = false;146#endif147};148149#if defined(__clang__) || defined(__GNUC__)150#pragma GCC diagnostic pop151#endif152153};154155156