Merge branch '7.8'
[mesa.git] / src / gallium / drivers / nvfx / nvfx_tex.h
1 #ifndef NVFX_TEX_H_
2 #define NVFX_TEX_H_
3
4 static inline unsigned
5 nvfx_tex_wrap_mode(unsigned wrap) {
6 unsigned ret;
7
8 switch (wrap) {
9 case PIPE_TEX_WRAP_REPEAT:
10 ret = NV34TCL_TX_WRAP_S_REPEAT;
11 break;
12 case PIPE_TEX_WRAP_MIRROR_REPEAT:
13 ret = NV34TCL_TX_WRAP_S_MIRRORED_REPEAT;
14 break;
15 case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
16 ret = NV34TCL_TX_WRAP_S_CLAMP_TO_EDGE;
17 break;
18 case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
19 ret = NV34TCL_TX_WRAP_S_CLAMP_TO_BORDER;
20 break;
21 case PIPE_TEX_WRAP_CLAMP:
22 ret = NV34TCL_TX_WRAP_S_CLAMP;
23 break;
24 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
25 ret = NV40TCL_TEX_WRAP_S_MIRROR_CLAMP_TO_EDGE;
26 break;
27 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
28 ret = NV40TCL_TEX_WRAP_S_MIRROR_CLAMP_TO_BORDER;
29 break;
30 case PIPE_TEX_WRAP_MIRROR_CLAMP:
31 ret = NV40TCL_TEX_WRAP_S_MIRROR_CLAMP;
32 break;
33 default:
34 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap);
35 ret = NV34TCL_TX_WRAP_S_REPEAT;
36 break;
37 }
38
39 return ret >> NV34TCL_TX_WRAP_S_SHIFT;
40 }
41
42 static inline unsigned
43 nvfx_tex_wrap_compare_mode(const struct pipe_sampler_state* cso)
44 {
45 if (cso->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
46 switch (cso->compare_func) {
47 case PIPE_FUNC_NEVER:
48 return NV34TCL_TX_WRAP_RCOMP_NEVER;
49 case PIPE_FUNC_GREATER:
50 return NV34TCL_TX_WRAP_RCOMP_GREATER;
51 case PIPE_FUNC_EQUAL:
52 return NV34TCL_TX_WRAP_RCOMP_EQUAL;
53 case PIPE_FUNC_GEQUAL:
54 return NV34TCL_TX_WRAP_RCOMP_GEQUAL;
55 case PIPE_FUNC_LESS:
56 return NV34TCL_TX_WRAP_RCOMP_LESS;
57 case PIPE_FUNC_NOTEQUAL:
58 return NV34TCL_TX_WRAP_RCOMP_NOTEQUAL;
59 case PIPE_FUNC_LEQUAL:
60 return NV34TCL_TX_WRAP_RCOMP_LEQUAL;
61 case PIPE_FUNC_ALWAYS:
62 return NV34TCL_TX_WRAP_RCOMP_ALWAYS;
63 default:
64 break;
65 }
66 }
67 return 0;
68 }
69
70 static inline unsigned nvfx_tex_filter(const struct pipe_sampler_state* cso)
71 {
72 unsigned filter = 0;
73 switch (cso->mag_img_filter) {
74 case PIPE_TEX_FILTER_LINEAR:
75 filter |= NV34TCL_TX_FILTER_MAGNIFY_LINEAR;
76 break;
77 case PIPE_TEX_FILTER_NEAREST:
78 default:
79 filter |= NV34TCL_TX_FILTER_MAGNIFY_NEAREST;
80 break;
81 }
82
83 switch (cso->min_img_filter) {
84 case PIPE_TEX_FILTER_LINEAR:
85 switch (cso->min_mip_filter) {
86 case PIPE_TEX_MIPFILTER_NEAREST:
87 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST;
88 break;
89 case PIPE_TEX_MIPFILTER_LINEAR:
90 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR;
91 break;
92 case PIPE_TEX_MIPFILTER_NONE:
93 default:
94 filter |= NV34TCL_TX_FILTER_MINIFY_LINEAR;
95 break;
96 }
97 break;
98 case PIPE_TEX_FILTER_NEAREST:
99 default:
100 switch (cso->min_mip_filter) {
101 case PIPE_TEX_MIPFILTER_NEAREST:
102 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST;
103 break;
104 case PIPE_TEX_MIPFILTER_LINEAR:
105 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR;
106 break;
107 case PIPE_TEX_MIPFILTER_NONE:
108 default:
109 filter |= NV34TCL_TX_FILTER_MINIFY_NEAREST;
110 break;
111 }
112 break;
113 }
114 return filter;
115 }
116
117 static inline unsigned nvfx_tex_border_color(const float* border_color)
118 {
119 return ((float_to_ubyte(border_color[3]) << 24) |
120 (float_to_ubyte(border_color[0]) << 16) |
121 (float_to_ubyte(border_color[1]) << 8) |
122 (float_to_ubyte(border_color[2]) << 0));
123 }
124
125 struct nvfx_sampler_state {
126 uint32_t fmt;
127 uint32_t wrap;
128 uint32_t en;
129 uint32_t filt;
130 uint32_t bcol;
131 };
132
133 #endif /* NVFX_TEX_H_ */