xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/nine/nine_ff.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2011 Joakim Sindholt <[email protected]>
3  * Copyright Axel Davy <[email protected]>
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef _NINE_FF_H_
8 #define _NINE_FF_H_
9 
10 #include "device9.h"
11 #include "vertexdeclaration9.h"
12 
13 bool nine_ff_init(struct NineDevice9 *);
14 void nine_ff_fini(struct NineDevice9 *);
15 
16 void nine_ff_update(struct NineDevice9 *);
17 
18 void
19 nine_d3d_matrix_matrix_mul(D3DMATRIX *, const D3DMATRIX *, const D3DMATRIX *);
20 
21 void
22 nine_d3d_vector4_matrix_mul(D3DVECTOR *, const D3DVECTOR *, const D3DMATRIX *);
23 void
24 nine_d3d_vector3_matrix_mul(D3DVECTOR *, const D3DVECTOR *, const D3DMATRIX *);
25 
26 float
27 nine_d3d_matrix_det(const D3DMATRIX *);
28 
29 void
30 nine_d3d_matrix_inverse(D3DMATRIX *, const D3DMATRIX *);
31 
32 void
33 nine_d3d_matrix_transpose(D3DMATRIX *, const D3DMATRIX *);
34 
35 #define NINED3DTSS_TCI_DISABLE                       0
36 #define NINED3DTSS_TCI_PASSTHRU                      1
37 #define NINED3DTSS_TCI_CAMERASPACENORMAL             2
38 #define NINED3DTSS_TCI_CAMERASPACEPOSITION           3
39 #define NINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR   4
40 #define NINED3DTSS_TCI_SPHEREMAP                     5
41 
42 static inline unsigned
nine_decltype_get_dim(BYTE type)43 nine_decltype_get_dim(BYTE type)
44 {
45     switch (type) {
46     case D3DDECLTYPE_FLOAT1: return 1;
47     case D3DDECLTYPE_FLOAT2: return 2;
48     case D3DDECLTYPE_FLOAT3: return 3;
49     case D3DDECLTYPE_FLOAT4: return 4;
50     case D3DDECLTYPE_D3DCOLOR: return 1;
51     case D3DDECLTYPE_UBYTE4: return 4;
52     case D3DDECLTYPE_SHORT2: return 2;
53     case D3DDECLTYPE_SHORT4: return 4;
54     case D3DDECLTYPE_UBYTE4N: return 4;
55     case D3DDECLTYPE_SHORT2N: return 2;
56     case D3DDECLTYPE_SHORT4N: return 4;
57     case D3DDECLTYPE_USHORT2N: return 2;
58     case D3DDECLTYPE_USHORT4N: return 4;
59     case D3DDECLTYPE_UDEC3: return 3;
60     case D3DDECLTYPE_DEC3N: return 3;
61     case D3DDECLTYPE_FLOAT16_2: return 2;
62     case D3DDECLTYPE_FLOAT16_4: return 4;
63     default:
64         assert(!"Implementation error !");
65     }
66     return 0;
67 }
68 
69 static inline uint16_t
nine_ff_get_projected_key(struct nine_context * context,unsigned num_stages)70 nine_ff_get_projected_key(struct nine_context *context, unsigned num_stages)
71 {
72     unsigned s, i;
73     uint16_t projected = 0;
74     int8_t input_texture_coord[num_stages];
75     memset(&input_texture_coord, 0, sizeof(input_texture_coord));
76 
77     if (context->vdecl) {
78         for (i = 0; i < context->vdecl->nelems; i++) {
79             uint16_t usage = context->vdecl->usage_map[i];
80             if (usage % NINE_DECLUSAGE_COUNT == NINE_DECLUSAGE_TEXCOORD) {
81                 s = usage / NINE_DECLUSAGE_COUNT;
82                 if (s < num_stages)
83                     input_texture_coord[s] = nine_decltype_get_dim(context->vdecl->decls[i].Type);
84             }
85         }
86     }
87 
88     for (s = 0; s < num_stages; ++s) {
89         unsigned gen = (context->ff.tex_stage[s][D3DTSS_TEXCOORDINDEX] >> 16) + 1;
90         unsigned dim = context->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & 0x7;
91         unsigned idx = context->ff.tex_stage[s][D3DTSS_TEXCOORDINDEX] & 7;
92         unsigned proj = !!(context->ff.tex_stage[s][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);
93 
94         if (!context->programmable_vs) {
95             if (dim > 4)
96                 dim = input_texture_coord[idx];
97 
98             if (!dim && gen == NINED3DTSS_TCI_PASSTHRU)
99                 dim = input_texture_coord[idx];
100             else if (!dim)
101                 dim = 4;
102 
103             if (dim == 1) /* NV behaviour */
104                 proj = 0;
105             if (dim > input_texture_coord[idx] && gen == NINED3DTSS_TCI_PASSTHRU)
106                 proj = 0;
107         } else {
108             dim = 4;
109         }
110         if (proj)
111             projected |= (dim-1) << (2 * s);
112     }
113     return projected;
114 }
115 
116 static inline uint16_t
nine_ff_get_projected_key_ff(struct nine_context * context)117 nine_ff_get_projected_key_ff(struct nine_context *context)
118 {
119     /* 8 stages */
120     return nine_ff_get_projected_key(context, 8);
121 }
122 
123 static inline uint8_t
nine_ff_get_projected_key_programmable(struct nine_context * context)124 nine_ff_get_projected_key_programmable(struct nine_context *context)
125 {
126     /* We only look at the 4 stages because this function
127      * is used only for ps 1.1-3, where only the first four
128      * slots are available */
129     return (uint8_t)nine_ff_get_projected_key(context, 4);
130 }
131 
132 #endif /* _NINE_FF_H_ */
133