1 #include "pipe/p_state.h"
2 #include "pipe/p_defines.h"
3 #include "util/u_inlines.h"
5 #include "tgsi/tgsi_parse.h"
7 #include "nv30_context.h"
8 #include "nvfx_state.h"
10 static INLINE
unsigned
11 wrap_mode(unsigned wrap
) {
15 case PIPE_TEX_WRAP_REPEAT
:
16 ret
= NV34TCL_TX_WRAP_S_REPEAT
;
18 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
19 ret
= NV34TCL_TX_WRAP_S_MIRRORED_REPEAT
;
21 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
22 ret
= NV34TCL_TX_WRAP_S_CLAMP_TO_EDGE
;
24 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
25 ret
= NV34TCL_TX_WRAP_S_CLAMP_TO_BORDER
;
27 case PIPE_TEX_WRAP_CLAMP
:
28 ret
= NV34TCL_TX_WRAP_S_CLAMP
;
30 /* case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
31 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP_TO_EDGE;
33 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
34 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP_TO_BORDER;
36 case PIPE_TEX_WRAP_MIRROR_CLAMP:
37 ret = NV34TCL_TX_WRAP_S_MIRROR_CLAMP;
40 NOUVEAU_ERR("unknown wrap mode: %d\n", wrap
);
41 ret
= NV34TCL_TX_WRAP_S_REPEAT
;
45 return ret
>> NV34TCL_TX_WRAP_S_SHIFT
;
49 nv30_sampler_state_create(struct pipe_context
*pipe
,
50 const struct pipe_sampler_state
*cso
)
52 struct nvfx_sampler_state
*ps
;
55 ps
= MALLOC(sizeof(struct nvfx_sampler_state
));
58 /* TODO: Not all RECTs formats have this bit set, bits 15-8 of format
59 are the tx format to use. We should store normalized coord flag
60 in sampler state structure, and set appropriate format in
63 /*NV34TCL_TX_FORMAT_RECT*/
64 /*if (!cso->normalized_coords) {
68 ps
->wrap
= ((wrap_mode(cso
->wrap_s
) << NV34TCL_TX_WRAP_S_SHIFT
) |
69 (wrap_mode(cso
->wrap_t
) << NV34TCL_TX_WRAP_T_SHIFT
) |
70 (wrap_mode(cso
->wrap_r
) << NV34TCL_TX_WRAP_R_SHIFT
));
74 if (cso
->max_anisotropy
>= 8) {
75 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_8X
;
77 if (cso
->max_anisotropy
>= 4) {
78 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_4X
;
80 if (cso
->max_anisotropy
>= 2) {
81 ps
->en
|= NV34TCL_TX_ENABLE_ANISO_2X
;
84 switch (cso
->mag_img_filter
) {
85 case PIPE_TEX_FILTER_LINEAR
:
86 filter
|= NV34TCL_TX_FILTER_MAGNIFY_LINEAR
;
88 case PIPE_TEX_FILTER_NEAREST
:
90 filter
|= NV34TCL_TX_FILTER_MAGNIFY_NEAREST
;
94 switch (cso
->min_img_filter
) {
95 case PIPE_TEX_FILTER_LINEAR
:
96 switch (cso
->min_mip_filter
) {
97 case PIPE_TEX_MIPFILTER_NEAREST
:
98 filter
|= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_NEAREST
;
100 case PIPE_TEX_MIPFILTER_LINEAR
:
101 filter
|= NV34TCL_TX_FILTER_MINIFY_LINEAR_MIPMAP_LINEAR
;
103 case PIPE_TEX_MIPFILTER_NONE
:
105 filter
|= NV34TCL_TX_FILTER_MINIFY_LINEAR
;
109 case PIPE_TEX_FILTER_NEAREST
:
111 switch (cso
->min_mip_filter
) {
112 case PIPE_TEX_MIPFILTER_NEAREST
:
113 filter
|= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_NEAREST
;
115 case PIPE_TEX_MIPFILTER_LINEAR
:
116 filter
|= NV34TCL_TX_FILTER_MINIFY_NEAREST_MIPMAP_LINEAR
;
118 case PIPE_TEX_MIPFILTER_NONE
:
120 filter
|= NV34TCL_TX_FILTER_MINIFY_NEAREST
;
131 limit
= CLAMP(cso
->lod_bias
, -16.0, 15.0);
132 ps
->filt
|= (int)(cso
->lod_bias
* 256.0) & 0x1fff;
134 limit
= CLAMP(cso
->max_lod
, 0.0, 15.0);
135 ps
->en
|= (int)(limit
) << 14 /*NV34TCL_TX_ENABLE_MIPMAP_MAX_LOD_SHIFT*/;
137 limit
= CLAMP(cso
->min_lod
, 0.0, 15.0);
138 ps
->en
|= (int)(limit
) << 26 /*NV34TCL_TX_ENABLE_MIPMAP_MIN_LOD_SHIFT*/;
141 if (cso
->compare_mode
== PIPE_TEX_COMPARE_R_TO_TEXTURE
) {
142 switch (cso
->compare_func
) {
143 case PIPE_FUNC_NEVER
:
144 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_NEVER
;
146 case PIPE_FUNC_GREATER
:
147 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_GREATER
;
149 case PIPE_FUNC_EQUAL
:
150 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_EQUAL
;
152 case PIPE_FUNC_GEQUAL
:
153 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_GEQUAL
;
156 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_LESS
;
158 case PIPE_FUNC_NOTEQUAL
:
159 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_NOTEQUAL
;
161 case PIPE_FUNC_LEQUAL
:
162 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_LEQUAL
;
164 case PIPE_FUNC_ALWAYS
:
165 ps
->wrap
|= NV34TCL_TX_WRAP_RCOMP_ALWAYS
;
172 ps
->bcol
= ((float_to_ubyte(cso
->border_color
[3]) << 24) |
173 (float_to_ubyte(cso
->border_color
[0]) << 16) |
174 (float_to_ubyte(cso
->border_color
[1]) << 8) |
175 (float_to_ubyte(cso
->border_color
[2]) << 0));