~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Common/ShaderId.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#pragma once
 
2
 
 
3
#include "base/basictypes.h"
 
4
 
 
5
// TODO: There will be additional bits, indicating that groups of these will be
 
6
// sent to the shader and processed there. This will cut down the number of shaders ("ubershader approach")
 
7
// This is probably only really worth doing for lighting and bones.
 
8
enum {
 
9
        VS_BIT_LMODE = 0,
 
10
        VS_BIT_IS_THROUGH = 1,
 
11
        VS_BIT_ENABLE_FOG = 2,
 
12
        VS_BIT_HAS_COLOR = 3,
 
13
        VS_BIT_DO_TEXTURE = 4,
 
14
        VS_BIT_DO_TEXTURE_PROJ = 6,
 
15
        VS_BIT_USE_HW_TRANSFORM = 8,
 
16
        VS_BIT_HAS_NORMAL = 9,  // conditioned on hw transform
 
17
        VS_BIT_NORM_REVERSE = 10,
 
18
        VS_BIT_HAS_TEXCOORD = 11,  // 5 free after
 
19
        VS_BIT_UVGEN_MODE = 16,
 
20
        VS_BIT_UVPROJ_MODE = 18,  // 2, can overlap with LS0
 
21
        VS_BIT_LS0 = 18,  // 2
 
22
        VS_BIT_LS1 = 20,  // 2
 
23
        VS_BIT_BONES = 22,  // 3 should be enough, not 8
 
24
        VS_BIT_ENABLE_BONES = 30,
 
25
        VS_BIT_LIGHT0_COMP = 32,  // 2 bits
 
26
        VS_BIT_LIGHT0_TYPE = 34,  // 2 bits
 
27
        VS_BIT_LIGHT1_COMP = 36,  // 2 bits
 
28
        VS_BIT_LIGHT1_TYPE = 38,  // 2 bits
 
29
        VS_BIT_LIGHT2_COMP = 40,  // 2 bits
 
30
        VS_BIT_LIGHT2_TYPE = 42,  // 2 bits
 
31
        VS_BIT_LIGHT3_COMP = 44,  // 2 bits
 
32
        VS_BIT_LIGHT3_TYPE = 46,  // 2 bits
 
33
        VS_BIT_MATERIAL_UPDATE = 48,  // 3 bits, 1 free after
 
34
        VS_BIT_LIGHT0_ENABLE = 52,
 
35
        VS_BIT_LIGHT1_ENABLE = 53,
 
36
        VS_BIT_LIGHT2_ENABLE = 54,
 
37
        VS_BIT_LIGHT3_ENABLE = 55,
 
38
        VS_BIT_LIGHTING_ENABLE = 56,
 
39
        VS_BIT_WEIGHT_FMTSCALE = 57,  // only two bits, 1 free after
 
40
        VS_BIT_TEXCOORD_FMTSCALE = 60,
 
41
        VS_BIT_FLATSHADE = 62,  // 1 free after
 
42
};
 
43
 
 
44
 
 
45
// Local
 
46
enum {
 
47
        FS_BIT_CLEARMODE = 0,
 
48
        FS_BIT_DO_TEXTURE = 1,
 
49
        FS_BIT_TEXFUNC = 2,  // 3 bits
 
50
        FS_BIT_TEXALPHA = 5,
 
51
        FS_BIT_SHADER_TEX_CLAMP = 7,
 
52
        FS_BIT_CLAMP_S = 8,
 
53
        FS_BIT_CLAMP_T = 9,
 
54
        FS_BIT_TEXTURE_AT_OFFSET = 10,
 
55
        FS_BIT_LMODE = 11,
 
56
        FS_BIT_ALPHA_TEST = 12,
 
57
        FS_BIT_ALPHA_TEST_FUNC = 13,  // 3 bits
 
58
        FS_BIT_ALPHA_AGAINST_ZERO = 16,
 
59
        FS_BIT_COLOR_TEST = 17,
 
60
        FS_BIT_COLOR_TEST_FUNC = 18,  // 2 bits
 
61
        FS_BIT_COLOR_AGAINST_ZERO = 20,
 
62
        FS_BIT_ENABLE_FOG = 21,
 
63
        FS_BIT_DO_TEXTURE_PROJ = 22,
 
64
        FS_BIT_COLOR_DOUBLE = 23,
 
65
        FS_BIT_STENCIL_TO_ALPHA = 24,  // 2 bits
 
66
        FS_BIT_REPLACE_ALPHA_WITH_STENCIL_TYPE = 26,  // 4 bits
 
67
        FS_BIT_REPLACE_LOGIC_OP_TYPE = 30,  // 2 bits
 
68
        FS_BIT_REPLACE_BLEND = 32,  // 3 bits
 
69
        FS_BIT_BLENDEQ = 35,  // 3 bits
 
70
        FS_BIT_BLENDFUNC_A = 38,  // 4 bits
 
71
        FS_BIT_BLENDFUNC_B = 42,
 
72
        FS_BIT_FLATSHADE = 46,
 
73
        FS_BIT_BGRA_TEXTURE = 47,
 
74
};
 
75
 
 
76
struct ShaderID {
 
77
        ShaderID() {
 
78
                clear();
 
79
        }
 
80
        void clear() {
 
81
                for (size_t i = 0; i < ARRAY_SIZE(d); i++) {
 
82
                        d[i] = 0;
 
83
                }
 
84
        }
 
85
        void set_invalid() {
 
86
                for (size_t i = 0; i < ARRAY_SIZE(d); i++) {
 
87
                        d[i] = 0xFFFFFFFF;
 
88
                }
 
89
        }
 
90
 
 
91
        u32 d[2];
 
92
        bool operator < (const ShaderID &other) const {
 
93
                for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
 
94
                        if (d[i] < other.d[i])
 
95
                                return true;
 
96
                        if (d[i] > other.d[i])
 
97
                                return false;
 
98
                }
 
99
                return false;
 
100
        }
 
101
        bool operator == (const ShaderID &other) const {
 
102
                for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
 
103
                        if (d[i] != other.d[i])
 
104
                                return false;
 
105
                }
 
106
                return true;
 
107
        }
 
108
 
 
109
        bool Bit(int bit) const {
 
110
                return (d[bit >> 5] >> (bit & 31)) & 1;
 
111
        }
 
112
        // Does not handle crossing 32-bit boundaries
 
113
        int Bits(int bit, int count) const {
 
114
                const int mask = (1 << count) - 1;
 
115
                return (d[bit >> 5] >> (bit & 31)) & mask;
 
116
        }
 
117
        void SetBit(int bit, bool value = true) {
 
118
                if (value) {
 
119
                        d[bit >> 5] |= 1 << (bit & 31);
 
120
                }
 
121
        }
 
122
        void SetBits(int bit, int count, int value) {
 
123
                if (value != 0) {
 
124
                        const int mask = (1 << count) - 1;
 
125
                        d[bit >> 5] |= (value & mask) << (bit & 31);
 
126
                }
 
127
        }
 
128
 
 
129
        void ToString(std::string *dest) const {
 
130
                dest->resize(sizeof(d));
 
131
                memcpy(&(*dest)[0], d, sizeof(d));
 
132
        }
 
133
        void FromString(std::string src) {
 
134
                memcpy(d, &(src)[0], sizeof(d));
 
135
        }
 
136
};
 
137
 
 
138
 
 
139
bool CanUseHardwareTransform(int prim);
 
140
void ComputeVertexShaderID(ShaderID *id, u32 vertexType, bool useHWTransform);
 
141
// Generates a compact string that describes the shader. Useful in a list to get an overview
 
142
// of the current flora of shaders.
 
143
std::string VertexShaderDesc(const ShaderID &id);
 
144
 
 
145
void ComputeFragmentShaderID(ShaderID *id);
 
146
std::string FragmentShaderDesc(const ShaderID &id);