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/FuncId.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 <algorithm>20#include <cstdint>21#include <functional>2223#include "GPU/ge_constants.h"2425// 0-10 match GEBlendSrcFactor/GEBlendDstFactor.26enum class PixelBlendFactor {27OTHERCOLOR,28INVOTHERCOLOR,29SRCALPHA,30INVSRCALPHA,31DSTALPHA,32INVDSTALPHA,33DOUBLESRCALPHA,34DOUBLEINVSRCALPHA,35DOUBLEDSTALPHA,36DOUBLEINVDSTALPHA,37FIX,38// These are invented, but common FIX values.39ZERO,40ONE,41};4243#pragma pack(push, 1)4445struct PixelFuncID {46PixelFuncID() {47}4849struct {50// Warning: these are not hashed or compared for equal. Just cached values.51uint32_t colorWriteMask{};52int8_t ditherMatrix[16]{};53uint32_t fogColor;54int minz;55int maxz;56uint16_t framebufStride;57uint16_t depthbufStride;58GELogicOp logicOp;59uint8_t stencilRef;60uint8_t stencilTestMask;61uint8_t alphaTestMask;62GEComparison colorTestFunc;63uint32_t colorTestMask;64uint32_t colorTestRef;65uint32_t alphaBlendSrc;66uint32_t alphaBlendDst;67} cached;6869union {70uint64_t fullKey{};71struct {72bool clearMode : 1;73// Reused as ColorClear.74bool colorTest : 1;75// Reused as StencilClear.76bool stencilTest : 1;77// Reused as DepthClear.78bool depthWrite : 1;79bool applyDepthRange : 1;80// If alpha testing is disabled, set to GE_COMP_ALWAYS.81uint8_t alphaTestFunc : 3;82// If depth testing is disabled, set to GE_COMP_ALWAYS.83uint8_t depthTestFunc : 3;84uint8_t stencilTestFunc : 3;85uint8_t fbFormat : 2;86// 16 bits before alphaTestRef.87uint8_t alphaTestRef : 8;88uint8_t stencilTestRef : 8;89// 32 bits before alphaBlend.90bool alphaBlend : 1;91uint8_t alphaBlendEq : 3;92uint8_t alphaBlendSrc : 4;93uint8_t alphaBlendDst : 4;94// Meaning: alphaTestMask != 0xFF95bool hasAlphaTestMask : 1;96// Meaning: stencilTestMask != 0xFF97bool hasStencilTestMask : 1;98bool dithering : 1;99bool applyLogicOp : 1;100// 48 bits before applyFog.101bool applyFog : 1;102// Meaning: fb_stride == 512 && z_stride == 512103bool useStandardStride : 1;104// Meaning: maskRGB != 0 || maskA != 0105bool applyColorWriteMask : 1;106uint8_t sFail : 3;107uint8_t zFail : 3;108uint8_t zPass : 3;109bool earlyZChecks : 1;110// 61 bits, 3 free.111};112};113114bool ColorClear() const {115return colorTest;116}117bool StencilClear() const {118return stencilTest;119}120bool DepthClear() const {121return depthWrite;122}123124GEComparison AlphaTestFunc() const {125return GEComparison(alphaTestFunc);126}127GEComparison DepthTestFunc() const {128return GEComparison(depthTestFunc);129}130GEComparison StencilTestFunc() const {131return GEComparison(stencilTestFunc);132}133134GEBufferFormat FBFormat() const {135return GEBufferFormat(fbFormat);136}137138GEBlendMode AlphaBlendEq() const {139return GEBlendMode(alphaBlendEq);140}141PixelBlendFactor AlphaBlendSrc() const {142return PixelBlendFactor(alphaBlendSrc);143}144PixelBlendFactor AlphaBlendDst() const {145return PixelBlendFactor(alphaBlendDst);146}147148GEStencilOp SFail() const {149return GEStencilOp(sFail);150}151GEStencilOp ZFail() const {152return GEStencilOp(zFail);153}154GEStencilOp ZPass() const {155return GEStencilOp(zPass);156}157158bool operator == (const PixelFuncID &other) const {159return fullKey == other.fullKey;160}161};162163#pragma pack(pop)164165struct SamplerID {166SamplerID() : fullKey(0) {167}168169struct {170struct {171uint16_t w;172uint16_t h;173} sizes[8];174uint32_t texBlendColor;175uint32_t clutFormat;176union {177const uint8_t *clut;178const uint16_t *clut16;179const uint32_t *clut32;180};181} cached;182183uint32_t pad;184185union {186uint32_t fullKey;187struct {188uint8_t texfmt : 4;189uint8_t clutfmt : 2;190bool clampS : 1;191bool clampT : 1;192bool swizzle : 1;193bool useSharedClut : 1;194bool hasClutMask : 1;195bool hasClutShift : 1;196bool hasClutOffset : 1;197bool hasInvalidPtr : 1;198bool overReadSafe : 1;199bool useStandardBufw : 1;200uint8_t width0Shift : 4;201uint8_t height0Shift : 4;202uint8_t texFunc : 3;203bool useTextureAlpha : 1;204bool useColorDoubling : 1;205bool hasAnyMips : 1;206bool linear : 1;207bool fetch : 1;208};209};210211GETextureFormat TexFmt() const {212return GETextureFormat(texfmt);213}214215GEPaletteFormat ClutFmt() const {216return GEPaletteFormat(clutfmt);217}218219GETexFunc TexFunc() const {220return GETexFunc(texFunc);221}222223bool operator == (const SamplerID &other) const {224return fullKey == other.fullKey;225}226};227228namespace std {229230template <>231struct hash<PixelFuncID> {232std::size_t operator()(const PixelFuncID &k) const {233return hash<uint64_t>()(k.fullKey);234}235};236237template <>238struct hash<SamplerID> {239std::size_t operator()(const SamplerID &k) const {240return hash<uint32_t>()(k.fullKey);241}242};243244};245246void ComputePixelFuncID(PixelFuncID *id);247std::string DescribePixelFuncID(const PixelFuncID &id);248249void ComputeSamplerID(SamplerID *id);250std::string DescribeSamplerID(const SamplerID &id);251252253