blob: 7e436fd47d8b0deb90f12e72feec2e9a82fd1bc3 [file] [log] [blame]
Ben Skeggs857a3292008-07-11 20:44:39 +10001/*
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01002 * Copyright 2010 Christoph Bumiller
Ben Skeggs857a3292008-07-11 20:44:39 +10003 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
Marcin Slusarzb5dfc382011-04-16 22:15:52 +020023#include "util/u_format.h"
Xavier Chantry6ddd6402010-05-05 14:39:59 +020024#include "util/u_format_s3tc.h"
Ben Skeggs84cc07d2008-02-29 15:03:57 +110025#include "pipe/p_screen.h"
Ben Skeggs84cc07d2008-02-29 15:03:57 +110026
27#include "nv50_context.h"
28#include "nv50_screen.h"
29
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010030#include "nouveau/nv_object.xml.h"
Christoph Bumiller272bbbf2010-03-21 13:17:02 +010031
Christoph Bumiller4de293b2010-08-15 21:37:50 +020032#ifndef NOUVEAU_GETPARAM_GRAPH_UNITS
33# define NOUVEAU_GETPARAM_GRAPH_UNITS 13
34#endif
35
36extern int nouveau_device_get_param(struct nouveau_device *dev,
37 uint64_t param, uint64_t *value);
38
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010039static boolean
40nv50_screen_is_format_supported(struct pipe_screen *pscreen,
41 enum pipe_format format,
42 enum pipe_texture_target target,
43 unsigned sample_count,
Marek Olšáke9689752011-03-08 00:01:58 +010044 unsigned bindings)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010045{
46 if (sample_count > 1)
47 return FALSE;
48
Marek Olšák75fa5c92011-04-11 06:23:00 +020049 if (!util_format_is_supported(format, bindings))
50 return FALSE;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010051
52 switch (format) {
53 case PIPE_FORMAT_Z16_UNORM:
Christoph Bumiller3bf92a22011-03-03 12:31:35 +010054 if (nv50_screen(pscreen)->tesla->grclass < NVA0_3D)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010055 return FALSE;
56 break;
57 default:
58 break;
59 }
60
61 /* transfers & shared are always supported */
62 bindings &= ~(PIPE_BIND_TRANSFER_READ |
63 PIPE_BIND_TRANSFER_WRITE |
64 PIPE_BIND_SHARED);
65
66 return (nv50_format_table[format].usage & bindings) == bindings;
67}
68
69static int
70nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
71{
72 switch (param) {
73 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
74 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
75 return 32;
76 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
77 return 64;
78 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
79 return 13;
80 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
81 return 10;
82 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
83 return 13;
84 case PIPE_CAP_ARRAY_TEXTURES: /* shader support missing */
85 return 0;
86 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
87 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
88 case PIPE_CAP_TEXTURE_SWIZZLE:
89 case PIPE_CAP_TEXTURE_SHADOW_MAP:
90 case PIPE_CAP_NPOT_TEXTURES:
91 case PIPE_CAP_ANISOTROPIC_FILTER:
Maxim Levitskyd6b24862011-05-10 10:16:54 +020092 return 1;
Christoph Bumiller531b12a2011-05-06 21:11:03 +020093 case PIPE_CAP_SEAMLESS_CUBE_MAP:
94 return nv50_screen(pscreen)->tesla->grclass >= NVA0_3D;
95 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
96 return 0;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010097 case PIPE_CAP_TWO_SIDED_STENCIL:
98 case PIPE_CAP_DEPTH_CLAMP:
99 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
100 case PIPE_CAP_POINT_SPRITE:
101 return 1;
102 case PIPE_CAP_GLSL:
103 case PIPE_CAP_SM3:
104 return 1;
105 case PIPE_CAP_MAX_RENDER_TARGETS:
106 return 8;
Christoph Bumiller8f060df2011-03-29 23:09:02 +0200107 case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
108 return 1;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100109 case PIPE_CAP_TIMER_QUERY:
110 case PIPE_CAP_OCCLUSION_QUERY:
111 return 1;
112 case PIPE_CAP_STREAM_OUTPUT:
113 return 0;
114 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
115 case PIPE_CAP_INDEP_BLEND_ENABLE:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100116 return 1;
Christoph Bumillerddcb9022011-03-02 19:41:08 +0100117 case PIPE_CAP_INDEP_BLEND_FUNC:
Christoph Bumiller3bf92a22011-03-03 12:31:35 +0100118 return nv50_screen(pscreen)->tesla->grclass >= NVA3_3D;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100119 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
120 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
121 return 1;
122 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
123 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
124 return 0;
125 case PIPE_CAP_SHADER_STENCIL_EXPORT:
126 return 0;
127 case PIPE_CAP_PRIMITIVE_RESTART:
Marek Olšák95c78812011-03-05 16:06:10 +0100128 case PIPE_CAP_TGSI_INSTANCEID:
129 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
Marek Olšák4a7f0132011-03-29 18:18:05 +0200130 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100131 return 1;
132 default:
133 NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
134 return 0;
135 }
136}
137
138static int
139nv50_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
140 enum pipe_shader_cap param)
141{
142 switch (shader) {
143 case PIPE_SHADER_VERTEX:
144 case PIPE_SHADER_GEOMETRY:
145 case PIPE_SHADER_FRAGMENT:
146 break;
147 default:
148 return 0;
149 }
150
151 switch (param) {
152 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
153 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
154 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
155 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
156 return 16384;
157 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
158 return 4;
159 case PIPE_SHADER_CAP_MAX_INPUTS:
160 if (shader == PIPE_SHADER_VERTEX)
161 return 32;
162 return 0x300 / 16;
163 case PIPE_SHADER_CAP_MAX_CONSTS:
164 return 65536 / 16;
165 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
166 return 14;
167 case PIPE_SHADER_CAP_MAX_ADDRS:
168 return 1;
169 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
170 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
171 return shader != PIPE_SHADER_FRAGMENT;
172 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
173 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
174 return 1;
175 case PIPE_SHADER_CAP_MAX_PREDS:
176 return 0;
177 case PIPE_SHADER_CAP_MAX_TEMPS:
178 return NV50_CAP_MAX_PROGRAM_TEMPS;
179 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
180 return 1;
181 case PIPE_SHADER_CAP_SUBROUTINES:
182 return 0; /* please inline, or provide function declarations */
Bryan Cain17b695e2011-05-05 21:10:28 -0500183 case PIPE_SHADER_CAP_INTEGERS:
184 return 0;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100185 default:
186 NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
187 return 0;
188 }
189}
190
191static float
192nv50_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_cap param)
193{
194 switch (param) {
195 case PIPE_CAP_MAX_LINE_WIDTH:
196 case PIPE_CAP_MAX_LINE_WIDTH_AA:
197 return 10.0f;
198 case PIPE_CAP_MAX_POINT_WIDTH:
199 case PIPE_CAP_MAX_POINT_WIDTH_AA:
200 return 64.0f;
201 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
202 return 16.0f;
203 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
204 return 4.0f;
205 default:
206 NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
207 return 0.0f;
208 }
209}
210
211static void
212nv50_screen_destroy(struct pipe_screen *pscreen)
213{
214 struct nv50_screen *screen = nv50_screen(pscreen);
215
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000216 if (screen->base.fence.current) {
217 nouveau_fence_wait(screen->base.fence.current);
218 nouveau_fence_ref (NULL, &screen->base.fence.current);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100219 }
220
221 nouveau_bo_ref(NULL, &screen->code);
222 nouveau_bo_ref(NULL, &screen->tls_bo);
223 nouveau_bo_ref(NULL, &screen->stack_bo);
224 nouveau_bo_ref(NULL, &screen->txc);
225 nouveau_bo_ref(NULL, &screen->uniforms);
226 nouveau_bo_ref(NULL, &screen->fence.bo);
227
228 nouveau_resource_destroy(&screen->vp_code_heap);
229 nouveau_resource_destroy(&screen->gp_code_heap);
230 nouveau_resource_destroy(&screen->fp_code_heap);
231
232 if (screen->tic.entries)
233 FREE(screen->tic.entries);
234
Ben Skeggs2f30a5b2011-03-01 10:27:45 +1000235 nouveau_mm_destroy(screen->mm_VRAM_fe0);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100236
237 nouveau_grobj_free(&screen->tesla);
238 nouveau_grobj_free(&screen->eng2d);
239 nouveau_grobj_free(&screen->m2mf);
240
241 nouveau_notifier_free(&screen->sync);
242
243 nouveau_screen_fini(&screen->base);
244
245 FREE(screen);
246}
247
248static void
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000249nv50_screen_fence_emit(struct pipe_screen *pscreen, u32 sequence)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100250{
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000251 struct nv50_screen *screen = nv50_screen(pscreen);
252 struct nouveau_channel *chan = screen->base.channel;
253
254 MARK_RING (chan, 5, 2);
255 BEGIN_RING(chan, RING_3D(QUERY_ADDRESS_HIGH), 4);
256 OUT_RELOCh(chan, screen->fence.bo, 0, NOUVEAU_BO_WR);
257 OUT_RELOCl(chan, screen->fence.bo, 0, NOUVEAU_BO_WR);
258 OUT_RING (chan, sequence);
259 OUT_RING (chan, NV50_3D_QUERY_GET_MODE_WRITE_UNK0 |
260 NV50_3D_QUERY_GET_UNK4 |
261 NV50_3D_QUERY_GET_UNIT_CROP |
262 NV50_3D_QUERY_GET_TYPE_QUERY |
263 NV50_3D_QUERY_GET_QUERY_SELECT_ZERO |
264 NV50_3D_QUERY_GET_SHORT);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100265}
266
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000267static u32
268nv50_screen_fence_update(struct pipe_screen *pscreen)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100269{
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000270 struct nv50_screen *screen = nv50_screen(pscreen);
271 return screen->fence.map[0];
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100272}
273
274#define FAIL_SCREEN_INIT(str, err) \
275 do { \
276 NOUVEAU_ERR(str, err); \
277 nv50_screen_destroy(pscreen); \
278 return NULL; \
279 } while(0)
280
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100281struct pipe_screen *
Ben Skeggs80e9e1e2009-06-05 10:28:13 +1000282nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100283{
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100284 struct nv50_screen *screen;
285 struct nouveau_channel *chan;
286 struct pipe_screen *pscreen;
287 uint64_t value;
288 uint32_t tesla_class;
289 unsigned stack_size, max_warps, tls_space;
290 int ret;
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100291 unsigned i, base;
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100292
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100293 screen = CALLOC_STRUCT(nv50_screen);
294 if (!screen)
295 return NULL;
296 pscreen = &screen->base.base;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000297
Ben Skeggs6b4e3e82011-03-03 15:56:20 +1000298 screen->base.sysmem_bindings = PIPE_BIND_CONSTANT_BUFFER;
299
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100300 ret = nouveau_screen_init(&screen->base, dev);
301 if (ret)
302 FAIL_SCREEN_INIT("nouveau_screen_init failed: %d\n", ret);
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100303
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100304 chan = screen->base.channel;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000305
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100306 pscreen->winsys = ws;
307 pscreen->destroy = nv50_screen_destroy;
308 pscreen->context_create = nv50_create;
309 pscreen->is_format_supported = nv50_screen_is_format_supported;
310 pscreen->get_param = nv50_screen_get_param;
311 pscreen->get_shader_param = nv50_screen_get_shader_param;
312 pscreen->get_paramf = nv50_screen_get_paramf;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000313
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100314 nv50_screen_init_resource_functions(pscreen);
Ben Skeggs63a3a372009-02-20 09:32:47 +1000315
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100316 ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, 4096,
317 &screen->fence.bo);
318 if (ret)
319 goto fail;
320 nouveau_bo_map(screen->fence.bo, NOUVEAU_BO_RDWR);
321 screen->fence.map = screen->fence.bo->map;
322 nouveau_bo_unmap(screen->fence.bo);
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000323 screen->base.fence.emit = nv50_screen_fence_emit;
324 screen->base.fence.update = nv50_screen_fence_update;
Ben Skeggs1cec61e2008-03-13 18:08:22 +1100325
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100326 ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync);
327 if (ret)
328 FAIL_SCREEN_INIT("Error allocating notifier: %d\n", ret);
Ben Skeggsb2e48f82008-03-12 02:39:13 +1100329
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100330 ret = nouveau_grobj_alloc(chan, 0xbeef5039, NV50_M2MF, &screen->m2mf);
331 if (ret)
332 FAIL_SCREEN_INIT("Error allocating PGRAPH context for M2MF: %d\n", ret);
Luca Barbierie0af5c92010-02-23 11:06:31 +0100333
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100334 BIND_RING (chan, screen->m2mf, NV50_SUBCH_MF);
335 BEGIN_RING(chan, RING_MF_(NV04_M2MF_DMA_NOTIFY), 3);
336 OUT_RING (chan, screen->sync->handle);
337 OUT_RING (chan, chan->vram->handle);
338 OUT_RING (chan, chan->vram->handle);
Ben Skeggsb2e48f82008-03-12 02:39:13 +1100339
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100340 ret = nouveau_grobj_alloc(chan, 0xbeef502d, NV50_2D, &screen->eng2d);
341 if (ret)
342 FAIL_SCREEN_INIT("Error allocating PGRAPH context for 2D: %d\n", ret);
Ben Skeggs63a3a372009-02-20 09:32:47 +1000343
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100344 BIND_RING (chan, screen->eng2d, NV50_SUBCH_2D);
345 BEGIN_RING(chan, RING_2D(DMA_NOTIFY), 4);
346 OUT_RING (chan, screen->sync->handle);
347 OUT_RING (chan, chan->vram->handle);
348 OUT_RING (chan, chan->vram->handle);
349 OUT_RING (chan, chan->vram->handle);
350 BEGIN_RING(chan, RING_2D(OPERATION), 1);
351 OUT_RING (chan, NV50_2D_OPERATION_SRCCOPY);
352 BEGIN_RING(chan, RING_2D(CLIP_ENABLE), 1);
353 OUT_RING (chan, 0);
354 BEGIN_RING(chan, RING_2D(COLOR_KEY_ENABLE), 1);
355 OUT_RING (chan, 0);
356 BEGIN_RING(chan, RING_2D_(0x0888), 1);
357 OUT_RING (chan, 1);
Ben Skeggs13393732009-02-05 14:04:45 +1000358
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100359 switch (dev->chipset & 0xf0) {
360 case 0x50:
361 tesla_class = NV50_3D;
362 break;
363 case 0x80:
364 case 0x90:
365 tesla_class = NV84_3D;
366 break;
367 case 0xa0:
368 switch (dev->chipset) {
369 case 0xa0:
370 case 0xaa:
371 case 0xac:
372 tesla_class = NVA0_3D;
373 break;
374 case 0xaf:
375 tesla_class = NVAF_3D;
376 break;
377 default:
378 tesla_class = NVA3_3D;
379 break;
380 }
381 break;
382 default:
383 FAIL_SCREEN_INIT("Not a known NV50 chipset: NV%02x\n", dev->chipset);
384 break;
385 }
Christoph Bumiller272bbbf2010-03-21 13:17:02 +0100386
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100387 ret = nouveau_grobj_alloc(chan, 0xbeef5097, tesla_class, &screen->tesla);
388 if (ret)
389 FAIL_SCREEN_INIT("Error allocating PGRAPH context for 3D: %d\n", ret);
Ben Skeggsf722fd92008-06-01 22:41:40 +1000390
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100391 BIND_RING (chan, screen->tesla, NV50_SUBCH_3D);
Christoph Bumiller7d967b92009-10-28 00:30:45 +0100392
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100393 BEGIN_RING(chan, RING_3D(COND_MODE), 1);
394 OUT_RING (chan, NV50_3D_COND_MODE_ALWAYS);
Christoph Bumiller4c223aa2010-01-16 13:25:55 +0100395
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100396 BEGIN_RING(chan, RING_3D(DMA_NOTIFY), 1);
397 OUT_RING (chan, screen->sync->handle);
398 BEGIN_RING(chan, RING_3D(DMA_ZETA), 11);
399 for (i = 0; i < 11; ++i)
400 OUT_RING(chan, chan->vram->handle);
401 BEGIN_RING(chan, RING_3D(DMA_COLOR(0)), NV50_3D_DMA_COLOR__LEN);
402 for (i = 0; i < NV50_3D_DMA_COLOR__LEN; ++i)
403 OUT_RING(chan, chan->vram->handle);
Ben Skeggsf722fd92008-06-01 22:41:40 +1000404
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100405 BEGIN_RING(chan, RING_3D(REG_MODE), 1);
406 OUT_RING (chan, NV50_3D_REG_MODE_STRIPED);
407 BEGIN_RING(chan, RING_3D(UNK1400_LANES), 1);
408 OUT_RING (chan, 0xf);
Christoph Bumiller2ef1d752010-09-24 22:46:51 +0200409
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100410 BEGIN_RING(chan, RING_3D(RT_CONTROL), 1);
411 OUT_RING (chan, 1);
Christoph Bumiller94ba1652009-05-23 16:13:24 +0200412
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100413 BEGIN_RING(chan, RING_3D(CSAA_ENABLE), 1);
414 OUT_RING (chan, 0);
415 BEGIN_RING(chan, RING_3D(MULTISAMPLE_ENABLE), 1);
416 OUT_RING (chan, 0);
417 BEGIN_RING(chan, RING_3D(MULTISAMPLE_MODE), 1);
418 OUT_RING (chan, NV50_3D_MULTISAMPLE_MODE_MS1);
419 BEGIN_RING(chan, RING_3D(MULTISAMPLE_CTRL), 1);
420 OUT_RING (chan, 0);
Christoph Bumiller843d5392011-03-31 19:04:17 +0200421 BEGIN_RING(chan, RING_3D(LINE_LAST_PIXEL), 1);
422 OUT_RING (chan, 0);
Christoph Bumiller7b4e4782011-04-09 18:25:29 +0200423 BEGIN_RING(chan, RING_3D(BLEND_SEPARATE_ALPHA), 1);
424 OUT_RING (chan, 1);
Christoph Bumiller94ba1652009-05-23 16:13:24 +0200425
Christoph Bumiller531b12a2011-05-06 21:11:03 +0200426 if (tesla_class >= NVA0_3D) {
427 BEGIN_RING(chan, RING_3D_(NVA0_3D_TEX_MISC), 1);
428 OUT_RING (chan, NVA0_3D_TEX_MISC_SEAMLESS_CUBE_MAP);
429 }
430
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100431 BEGIN_RING(chan, RING_3D(SCREEN_Y_CONTROL), 1);
432 OUT_RING (chan, 0);
433 BEGIN_RING(chan, RING_3D(WINDOW_OFFSET_X), 2);
434 OUT_RING (chan, 0);
435 OUT_RING (chan, 0);
436 BEGIN_RING(chan, RING_3D(ZCULL_REGION), 1); /* deactivate ZCULL */
437 OUT_RING (chan, 0x3f);
Ben Skeggsf722fd92008-06-01 22:41:40 +1000438
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100439 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16,
440 3 << NV50_CODE_BO_SIZE_LOG2, &screen->code);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100441 if (ret)
442 goto fail;
Ben Skeggs716c1cd2008-06-01 23:10:31 +1000443
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100444 nouveau_resource_init(&screen->vp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
445 nouveau_resource_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
446 nouveau_resource_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
447
448 base = 1 << NV50_CODE_BO_SIZE_LOG2;
Ben Skeggs072fdc12009-06-04 16:13:56 +1000449
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100450 BEGIN_RING(chan, RING_3D(VP_ADDRESS_HIGH), 2);
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100451 OUT_RELOCh(chan, screen->code, base * 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
452 OUT_RELOCl(chan, screen->code, base * 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
Ben Skeggs716c1cd2008-06-01 23:10:31 +1000453
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100454 BEGIN_RING(chan, RING_3D(FP_ADDRESS_HIGH), 2);
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100455 OUT_RELOCh(chan, screen->code, base * 1, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
456 OUT_RELOCl(chan, screen->code, base * 1, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
Christoph Bumiller4de293b2010-08-15 21:37:50 +0200457
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100458 BEGIN_RING(chan, RING_3D(GP_ADDRESS_HIGH), 2);
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100459 OUT_RELOCh(chan, screen->code, base * 2, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
460 OUT_RELOCl(chan, screen->code, base * 2, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200461
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100462 nouveau_device_get_param(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
Christoph Bumiller4de293b2010-08-15 21:37:50 +0200463
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100464 max_warps = util_bitcount(value & 0xffff);
465 max_warps *= util_bitcount((value >> 24) & 0xf) * 32;
Christoph Bumiller4de293b2010-08-15 21:37:50 +0200466
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100467 stack_size = max_warps * 64 * 8;
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200468
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100469 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, stack_size,
470 &screen->stack_bo);
471 if (ret)
472 FAIL_SCREEN_INIT("Failed to allocate stack bo: %d\n", ret);
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200473
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100474 BEGIN_RING(chan, RING_3D(STACK_ADDRESS_HIGH), 3);
475 OUT_RELOCh(chan, screen->stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
476 OUT_RELOCl(chan, screen->stack_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
477 OUT_RING (chan, 4);
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200478
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100479 tls_space = NV50_CAP_MAX_PROGRAM_TEMPS * 16;
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200480
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100481 screen->tls_size = tls_space * max_warps * 32;
Ben Skeggs3250bac2008-03-12 02:56:10 +1100482
Marek Olšák7e5953f2011-04-27 13:08:25 +0200483 debug_printf("max_warps = %i, tls_size = %llu KiB\n",
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100484 max_warps, screen->tls_size >> 10);
Ben Skeggs101305f2008-06-13 10:58:27 +1000485
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100486 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, screen->tls_size,
487 &screen->tls_bo);
488 if (ret)
489 FAIL_SCREEN_INIT("Failed to allocate stack bo: %d\n", ret);
Christoph Bumiller0811b092010-07-23 12:03:33 +0200490
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100491 BEGIN_RING(chan, RING_3D(LOCAL_ADDRESS_HIGH), 3);
492 OUT_RELOCh(chan, screen->tls_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
493 OUT_RELOCl(chan, screen->tls_bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
Matt Turnerc5ac8a82011-05-09 00:17:01 -0400494 OUT_RING (chan, util_logbase2(tls_space / 8));
Ben Skeggs431504b2008-06-16 18:56:39 +1000495
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100496 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 4 << 16,
497 &screen->uniforms);
498 if (ret)
499 goto fail;
Christoph Bumillerd29f5552009-12-24 12:39:42 +0100500
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100501 BEGIN_RING(chan, RING_3D(CB_DEF_ADDRESS_HIGH), 3);
502 OUT_RELOCh(chan, screen->uniforms, 0 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
503 OUT_RELOCl(chan, screen->uniforms, 0 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
504 OUT_RING (chan, (NV50_CB_PVP << 16) | 0x0000);
Ben Skeggsb2e48f82008-03-12 02:39:13 +1100505
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100506 BEGIN_RING(chan, RING_3D(CB_DEF_ADDRESS_HIGH), 3);
507 OUT_RELOCh(chan, screen->uniforms, 1 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
508 OUT_RELOCl(chan, screen->uniforms, 1 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
509 OUT_RING (chan, (NV50_CB_PGP << 16) | 0x0000);
510
511 BEGIN_RING(chan, RING_3D(CB_DEF_ADDRESS_HIGH), 3);
512 OUT_RELOCh(chan, screen->uniforms, 2 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
513 OUT_RELOCl(chan, screen->uniforms, 2 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
514 OUT_RING (chan, (NV50_CB_PFP << 16) | 0x0000);
515
516 BEGIN_RING(chan, RING_3D(CB_DEF_ADDRESS_HIGH), 3);
517 OUT_RELOCh(chan, screen->uniforms, 3 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
518 OUT_RELOCl(chan, screen->uniforms, 3 << 16, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
519 OUT_RING (chan, (NV50_CB_AUX << 16) | 0x0200);
520
521 BEGIN_RING_NI(chan, RING_3D(SET_PROGRAM_CB), 6);
522 OUT_RING (chan, (NV50_CB_PVP << 12) | 0x001);
523 OUT_RING (chan, (NV50_CB_PGP << 12) | 0x021);
524 OUT_RING (chan, (NV50_CB_PFP << 12) | 0x031);
525 OUT_RING (chan, (NV50_CB_AUX << 12) | 0xf01);
526 OUT_RING (chan, (NV50_CB_AUX << 12) | 0xf21);
527 OUT_RING (chan, (NV50_CB_AUX << 12) | 0xf31);
528
529 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 3 << 16,
530 &screen->txc);
531 if (ret)
532 FAIL_SCREEN_INIT("Could not allocate TIC/TSC bo: %d\n", ret);
533
534 /* max TIC (bits 4:8) & TSC bindings, per program type */
535 for (i = 0; i < 3; ++i) {
536 BEGIN_RING(chan, RING_3D(TEX_LIMITS(i)), 1);
537 OUT_RING (chan, 0x54);
538 }
539
540 BEGIN_RING(chan, RING_3D(TIC_ADDRESS_HIGH), 3);
541 OUT_RELOCh(chan, screen->txc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
542 OUT_RELOCl(chan, screen->txc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
543 OUT_RING (chan, NV50_TIC_MAX_ENTRIES - 1);
544
545 BEGIN_RING(chan, RING_3D(TSC_ADDRESS_HIGH), 3);
546 OUT_RELOCh(chan, screen->txc, 65536, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
547 OUT_RELOCl(chan, screen->txc, 65536, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD);
548 OUT_RING (chan, NV50_TSC_MAX_ENTRIES - 1);
549
550 BEGIN_RING(chan, RING_3D(LINKED_TSC), 1);
551 OUT_RING (chan, 0);
552
553 BEGIN_RING(chan, RING_3D(CLIP_RECTS_EN), 1);
554 OUT_RING (chan, 0);
555 BEGIN_RING(chan, RING_3D(CLIP_RECTS_MODE), 1);
556 OUT_RING (chan, NV50_3D_CLIP_RECTS_MODE_INSIDE_ANY);
557 BEGIN_RING(chan, RING_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
558 for (i = 0; i < 8 * 2; ++i)
559 OUT_RING(chan, 0);
560 BEGIN_RING(chan, RING_3D(CLIPID_ENABLE), 1);
561 OUT_RING (chan, 0);
562
563 BEGIN_RING(chan, RING_3D(VIEWPORT_TRANSFORM_EN), 1);
564 OUT_RING (chan, 1);
565 BEGIN_RING(chan, RING_3D(DEPTH_RANGE_NEAR(0)), 2);
566 OUT_RINGf (chan, 0.0f);
567 OUT_RINGf (chan, 1.0f);
568
569 BEGIN_RING(chan, RING_3D(VIEW_VOLUME_CLIP_CTRL), 1);
570#ifdef NV50_SCISSORS_CLIPPING
571 OUT_RING (chan, 0x0000);
572#else
573 OUT_RING (chan, 0x1080);
574#endif
575
576 BEGIN_RING(chan, RING_3D(CLEAR_FLAGS), 1);
577 OUT_RING (chan, NV50_3D_CLEAR_FLAGS_CLEAR_RECT_VIEWPORT);
578
579 /* We use scissors instead of exact view volume clipping,
580 * so they're always enabled.
581 */
582 BEGIN_RING(chan, RING_3D(SCISSOR_ENABLE(0)), 3);
583 OUT_RING (chan, 1);
584 OUT_RING (chan, 8192 << 16);
585 OUT_RING (chan, 8192 << 16);
586
587 BEGIN_RING(chan, RING_3D(RASTERIZE_ENABLE), 1);
588 OUT_RING (chan, 1);
589 BEGIN_RING(chan, RING_3D(POINT_RASTER_RULES), 1);
590 OUT_RING (chan, NV50_3D_POINT_RASTER_RULES_OGL);
591 BEGIN_RING(chan, RING_3D(FRAG_COLOR_CLAMP_EN), 1);
592 OUT_RING (chan, 0x11111111);
593 BEGIN_RING(chan, RING_3D(EDGEFLAG_ENABLE), 1);
594 OUT_RING (chan, 1);
595
596 FIRE_RING (chan);
597
598 screen->tic.entries = CALLOC(4096, sizeof(void *));
599 screen->tsc.entries = screen->tic.entries + 2048;
600
Ben Skeggs2f30a5b2011-03-01 10:27:45 +1000601 screen->mm_VRAM_fe0 = nouveau_mm_create(dev, NOUVEAU_BO_VRAM, 0xfe0);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100602
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000603 nouveau_fence_new(&screen->base, &screen->base.fence.current, FALSE);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100604
605 return pscreen;
606
607fail:
608 nv50_screen_destroy(pscreen);
609 return NULL;
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100610}
611
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100612void
613nv50_screen_make_buffers_resident(struct nv50_screen *screen)
614{
615 struct nouveau_channel *chan = screen->base.channel;
616
617 const unsigned flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD;
618
619 MARK_RING(chan, 5, 5);
620 nouveau_bo_validate(chan, screen->code, flags);
621 nouveau_bo_validate(chan, screen->uniforms, flags);
622 nouveau_bo_validate(chan, screen->txc, flags);
623 nouveau_bo_validate(chan, screen->tls_bo, flags);
624 nouveau_bo_validate(chan, screen->stack_bo, flags);
625}
626
627int
628nv50_screen_tic_alloc(struct nv50_screen *screen, void *entry)
629{
630 int i = screen->tic.next;
631
632 while (screen->tic.lock[i / 32] & (1 << (i % 32)))
633 i = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
634
635 screen->tic.next = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
636
637 if (screen->tic.entries[i])
638 nv50_tic_entry(screen->tic.entries[i])->id = -1;
639
640 screen->tic.entries[i] = entry;
641 return i;
642}
643
644int
645nv50_screen_tsc_alloc(struct nv50_screen *screen, void *entry)
646{
647 int i = screen->tsc.next;
648
649 while (screen->tsc.lock[i / 32] & (1 << (i % 32)))
650 i = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
651
652 screen->tsc.next = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
653
654 if (screen->tsc.entries[i])
655 nv50_tsc_entry(screen->tsc.entries[i])->id = -1;
656
657 screen->tsc.entries[i] = entry;
658 return i;
659}