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 "nv_object.xml.h"
33 #include "nv04_3d.xml.h"
34 #include "nv04_driver.h"
37 get_tex_format(struct gl_texture_image
*ti
)
39 switch (ti
->TexFormat
) {
43 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_Y8
;
44 case MESA_FORMAT_ARGB1555
:
45 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A1R5G5B5
;
46 case MESA_FORMAT_ARGB4444
:
47 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A4R4G4B4
;
48 case MESA_FORMAT_RGB565
:
49 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_R5G6B5
;
50 case MESA_FORMAT_ARGB8888
:
51 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
52 case MESA_FORMAT_XRGB8888
:
53 return NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_X8R8G8B8
;
60 nv04_emit_tex_obj(struct gl_context
*ctx
, int emit
)
62 const int i
= emit
- NOUVEAU_STATE_TEX_OBJ0
;
63 struct nouveau_channel
*chan
= context_chan(ctx
);
64 struct nouveau_grobj
*fahrenheit
= nv04_context_engine(ctx
);
65 struct nouveau_bo_context
*bctx
= context_bctx_i(ctx
, TEXTURE
, i
);
66 const int bo_flags
= NOUVEAU_BO_RD
| NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
;
67 struct nouveau_surface
*s
;
68 uint32_t format
= 0xa0, filter
= 0x1010;
70 if (i
&& !nv04_mtex_engine(fahrenheit
))
73 if (ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
74 struct gl_texture_object
*t
= ctx
->Texture
.Unit
[i
]._Current
;
75 struct gl_texture_image
*ti
= t
->Image
[0][t
->BaseLevel
];
76 int lod_max
= 1, lod_bias
= 0;
78 if (!nouveau_texture_validate(ctx
, t
))
81 s
= &to_nouveau_texture(t
)->surfaces
[t
->BaseLevel
];
83 if (t
->MinFilter
!= GL_NEAREST
&&
84 t
->MinFilter
!= GL_LINEAR
) {
85 lod_max
= CLAMP(MIN2(t
->MaxLod
, t
->_MaxLambda
),
88 lod_bias
= CLAMP(ctx
->Texture
.Unit
[i
].LodBias
+
89 t
->LodBias
, -16, 15) * 8;
92 format
|= nvgl_wrap_mode(t
->WrapT
) << 28 |
93 nvgl_wrap_mode(t
->WrapS
) << 24 |
94 ti
->HeightLog2
<< 20 |
99 filter
|= log2i(t
->MaxAnisotropy
) << 31 |
100 nvgl_filter_mode(t
->MagFilter
) << 28 |
101 log2i(t
->MaxAnisotropy
) << 27 |
102 nvgl_filter_mode(t
->MinFilter
) << 24 |
103 (lod_bias
& 0xff) << 16;
106 s
= &to_nv04_context(ctx
)->dummy_texture
;
108 format
|= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT
|
109 NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT
|
111 NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8
;
113 filter
|= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST
|
114 NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST
;
117 if (nv04_mtex_engine(fahrenheit
)) {
118 nouveau_bo_markl(bctx
, fahrenheit
,
119 NV04_MULTITEX_TRIANGLE_OFFSET(i
),
120 s
->bo
, s
->offset
, bo_flags
);
122 nouveau_bo_mark(bctx
, fahrenheit
,
123 NV04_MULTITEX_TRIANGLE_FORMAT(i
),
125 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_A
,
126 NV04_MULTITEX_TRIANGLE_FORMAT_DMA_B
,
127 bo_flags
| NOUVEAU_BO_OR
);
129 BEGIN_RING(chan
, fahrenheit
, NV04_MULTITEX_TRIANGLE_FILTER(i
), 1);
130 OUT_RING(chan
, filter
);
133 nouveau_bo_markl(bctx
, fahrenheit
,
134 NV04_TEXTURED_TRIANGLE_OFFSET
,
135 s
->bo
, s
->offset
, bo_flags
);
137 nouveau_bo_mark(bctx
, fahrenheit
,
138 NV04_TEXTURED_TRIANGLE_FORMAT
,
140 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_A
,
141 NV04_TEXTURED_TRIANGLE_FORMAT_DMA_B
,
142 bo_flags
| NOUVEAU_BO_OR
);
144 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_COLORKEY
, 1);
147 BEGIN_RING(chan
, fahrenheit
, NV04_TEXTURED_TRIANGLE_FILTER
, 1);
148 OUT_RING(chan
, filter
);