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_texture.h"
30 #include "nouveau_util.h"
31 #include "nouveau_gldefs.h"
32 #include "nouveau_class.h"
33 #include "nv04_driver.h"
36 get_tex_format(struct gl_texture_image
*ti
)
38 switch (ti
->TexFormat
) {
42 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_Y8
;
43 case MESA_FORMAT_ARGB1555
:
44 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A1R5G5B5
;
45 case MESA_FORMAT_ARGB4444
:
46 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A4R4G4B4
;
47 case MESA_FORMAT_RGB565
:
48 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_R5G6B5
;
49 case MESA_FORMAT_ARGB8888
:
50 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
51 case MESA_FORMAT_XRGB8888
:
52 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_X8R8G8B8
;
59 nv04_emit_tex_obj(struct gl_context
*ctx
, int emit
)
61 const int i
= emit
- NOUVEAU_STATE_TEX_OBJ0
;
62 struct nouveau_channel
*chan
= context_chan(ctx
);
63 struct nouveau_grobj
*fahrenheit
= nv04_context_engine(ctx
);
64 struct nouveau_bo_context
*bctx
= context_bctx_i(ctx
, TEXTURE
, i
);
65 const int bo_flags
= NOUVEAU_BO_RD
| NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
;
66 struct nouveau_surface
*s
;
67 uint32_t format
= 0xa0, filter
= 0x1010;
69 if (i
&& !nv04_mtex_engine(fahrenheit
))
72 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
73 struct gl_texture_object
*t
= ctx
->Texture
.Unit
[i
]._Current
;
74 struct gl_texture_image
*ti
= t
->Image
[0][t
->BaseLevel
];
75 int lod_max
= 1, lod_bias
= 0;
77 if (!nouveau_texture_validate(ctx
, t
))
80 s
= &to_nouveau_texture(t
)->surfaces
[t
->BaseLevel
];
82 if (t
->MinFilter
!= GL_NEAREST
&&
83 t
->MinFilter
!= GL_LINEAR
) {
84 lod_max
= CLAMP(MIN2(t
->MaxLod
, t
->_MaxLambda
),
87 lod_bias
= CLAMP(ctx
->Texture
.Unit
[i
].LodBias
+
88 t
->LodBias
, -16, 15) * 8;
91 format
|= nvgl_wrap_mode(t
->WrapT
) << 28 |
92 nvgl_wrap_mode(t
->WrapS
) << 24 |
93 ti
->HeightLog2
<< 20 |
98 filter
|= log2i(t
->MaxAnisotropy
) << 31 |
99 nvgl_filter_mode(t
->MagFilter
) << 28 |
100 log2i(t
->MaxAnisotropy
) << 27 |
101 nvgl_filter_mode(t
->MinFilter
) << 24 |
102 (lod_bias
& 0xff) << 16;
105 s
= &to_nv04_context(ctx
)->dummy_texture
;
107 format
|= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT
|
108 NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT
|
110 NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
112 filter
|= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST
|
113 NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST
;
116 if (nv04_mtex_engine(fahrenheit
)) {
117 nouveau_bo_markl(bctx
, fahrenheit
,
118 NV04_MULTITEX_TRIANGLE_OFFSET(i
),
119 s
->bo
, s
->offset
, bo_flags
);
121 nouveau_bo_mark(bctx
, fahrenheit
,
122 NV04_MULTITEX_TRIANGLE_FORMAT(i
),
124 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A
,
125 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B
,
126 bo_flags
| NOUVEAU_BO_OR
);
128 BEGIN_RING(chan
, fahrenheit
, NV04_MULTITEX_TRIANGLE_FILTER(i
), 1);
129 OUT_RING(chan
, filter
);
132 nouveau_bo_markl(bctx
, fahrenheit
,
133 NV04_TEXTURED_TRIANGLE_OFFSET
,
134 s
->bo
, s
->offset
, bo_flags
);
136 nouveau_bo_mark(bctx
, fahrenheit
,
137 NV04_TEXTURED_TRIANGLE_FORMAT
,
139 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A
,
140 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B
,
141 bo_flags
| NOUVEAU_BO_OR
);
143 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_COLORKEY
, 1);
146 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_FILTER
, 1);
147 OUT_RING(chan
, filter
);