2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
29 #include "nouveau_gldefs.h"
30 #include "nouveau_texture.h"
31 #include "nouveau_class.h"
32 #include "nouveau_util.h"
33 #include "nv20_driver.h"
36 get_tex_format(struct gl_texture_image
*ti
)
38 switch (ti
->TexFormat
) {
39 case MESA_FORMAT_ARGB8888
:
40 return NV20TCL_TX_FORMAT_FORMAT_A8R8G8B8
;
42 case MESA_FORMAT_ARGB1555
:
43 return NV20TCL_TX_FORMAT_FORMAT_A1R5G5B5
;
45 case MESA_FORMAT_ARGB4444
:
46 return NV20TCL_TX_FORMAT_FORMAT_A4R4G4B4
;
48 case MESA_FORMAT_RGB565
:
49 return NV20TCL_TX_FORMAT_FORMAT_R5G6B5
;
52 return NV20TCL_TX_FORMAT_FORMAT_A8
;
55 return NV20TCL_TX_FORMAT_FORMAT_L8
;
58 return NV20TCL_TX_FORMAT_FORMAT_INDEX8
;
66 nv20_emit_tex_obj(GLcontext
*ctx
, int emit
)
68 const int i
= emit
- NOUVEAU_STATE_TEX_OBJ0
;
69 struct nouveau_channel
*chan
= context_chan(ctx
);
70 struct nouveau_grobj
*kelvin
= context_eng3d(ctx
);
71 struct nouveau_bo_context
*bctx
= context_bctx_i(ctx
, TEXTURE
, i
);
72 const int bo_flags
= NOUVEAU_BO_RD
| NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
;
73 struct gl_texture_object
*t
;
74 struct nouveau_surface
*s
;
75 struct gl_texture_image
*ti
;
76 uint32_t tx_format
, tx_filter
, tx_wrap
, tx_enable
;
78 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
79 BEGIN_RING(chan
, kelvin
, NV20TCL_TX_ENABLE(i
), 1);
82 context_dirty(ctx
, TEX_SHADER
);
86 t
= ctx
->Texture
.Unit
[i
]._Current
;
87 s
= &to_nouveau_texture(t
)->surfaces
[t
->BaseLevel
];
88 ti
= t
->Image
[0][t
->BaseLevel
];
90 if (!nouveau_texture_validate(ctx
, t
))
93 /* Recompute the texturing registers. */
94 tx_format
= ti
->DepthLog2
<< 28
95 | ti
->HeightLog2
<< 24
98 | NV20TCL_TX_FORMAT_DIMS_2D
99 | NV20TCL_TX_FORMAT_NO_BORDER
102 tx_wrap
= nvgl_wrap_mode(t
->WrapR
) << 16
103 | nvgl_wrap_mode(t
->WrapT
) << 8
104 | nvgl_wrap_mode(t
->WrapS
) << 0;
106 tx_filter
= nvgl_filter_mode(t
->MagFilter
) << 24
107 | nvgl_filter_mode(t
->MinFilter
) << 16;
109 tx_enable
= NV20TCL_TX_ENABLE_ENABLE
110 | log2i(t
->MaxAnisotropy
) << 4;
112 if (t
->MinFilter
!= GL_NEAREST
&&
113 t
->MinFilter
!= GL_LINEAR
) {
114 int lod_min
= t
->MinLod
;
115 int lod_max
= MIN2(t
->MaxLod
, t
->_MaxLambda
);
116 int lod_bias
= t
->LodBias
117 + ctx
->Texture
.Unit
[i
].LodBias
;
119 lod_max
= CLAMP(lod_max
, 0, 15);
120 lod_min
= CLAMP(lod_min
, 0, 15);
121 lod_bias
= CLAMP(lod_bias
, 0, 15);
123 tx_format
|= NV20TCL_TX_FORMAT_MIPMAP
;
124 tx_filter
|= lod_bias
<< 8;
125 tx_enable
|= lod_min
<< 26
129 /* Write it to the hardware. */
130 nouveau_bo_mark(bctx
, kelvin
, NV20TCL_TX_FORMAT(i
),
132 NV20TCL_TX_FORMAT_DMA0
,
133 NV20TCL_TX_FORMAT_DMA1
,
134 bo_flags
| NOUVEAU_BO_OR
);
136 nouveau_bo_markl(bctx
, kelvin
, NV20TCL_TX_OFFSET(i
),
139 BEGIN_RING(chan
, kelvin
, NV20TCL_TX_WRAP(i
), 1);
140 OUT_RING(chan
, tx_wrap
);
142 BEGIN_RING(chan
, kelvin
, NV20TCL_TX_FILTER(i
), 1);
143 OUT_RING(chan
, tx_filter
);
145 BEGIN_RING(chan
, kelvin
, NV20TCL_TX_ENABLE(i
), 1);
146 OUT_RING(chan
, tx_enable
);
148 context_dirty(ctx
, TEX_SHADER
);
152 nv20_emit_tex_shader(GLcontext
*ctx
, int emit
)
154 struct nouveau_channel
*chan
= context_chan(ctx
);
155 struct nouveau_grobj
*kelvin
= context_eng3d(ctx
);
156 uint32_t tx_shader_op
= 0;
159 for (i
= 0; i
< NV20_TEXTURE_UNITS
; i
++) {
160 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
)
163 tx_shader_op
|= NV20TCL_TX_SHADER_OP_TX0_TEXTURE_2D
<< 5 * i
;
166 BEGIN_RING(chan
, kelvin
, NV20TCL_TX_SHADER_OP
, 1);
167 OUT_RING(chan
, tx_shader_op
);