nvc0: regenerate rnndb headers
[mesa.git] / src / gallium / drivers / nouveau / nvc0 / nvc0_screen.c
1 /*
2 * Copyright 2010 Christoph Bumiller
3 *
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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #include <xf86drm.h>
24 #include <nouveau_drm.h>
25 #include "util/u_format.h"
26 #include "util/u_format_s3tc.h"
27 #include "pipe/p_screen.h"
28
29 #include "vl/vl_decoder.h"
30 #include "vl/vl_video_buffer.h"
31
32 #include "nouveau_vp3_video.h"
33
34 #include "nvc0/nvc0_context.h"
35 #include "nvc0/nvc0_screen.h"
36
37 #include "nvc0/mme/com9097.mme.h"
38
39 static boolean
40 nvc0_screen_is_format_supported(struct pipe_screen *pscreen,
41 enum pipe_format format,
42 enum pipe_texture_target target,
43 unsigned sample_count,
44 unsigned bindings)
45 {
46 if (sample_count > 8)
47 return FALSE;
48 if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */
49 return FALSE;
50
51 if (!util_format_is_supported(format, bindings))
52 return FALSE;
53
54 if ((bindings & PIPE_BIND_SAMPLER_VIEW) && (target != PIPE_BUFFER))
55 if (util_format_get_blocksizebits(format) == 3 * 32)
56 return FALSE;
57
58 /* transfers & shared are always supported */
59 bindings &= ~(PIPE_BIND_TRANSFER_READ |
60 PIPE_BIND_TRANSFER_WRITE |
61 PIPE_BIND_SHARED);
62
63 return (nvc0_format_table[format].usage & bindings) == bindings;
64 }
65
66 static int
67 nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
68 {
69 const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
70 struct nouveau_device *dev = nouveau_screen(pscreen)->device;
71
72 switch (param) {
73 /* non-boolean caps */
74 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
75 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
76 return 15;
77 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
78 return (class_3d >= NVE4_3D_CLASS) ? 13 : 12;
79 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
80 return 2048;
81 case PIPE_CAP_MIN_TEXEL_OFFSET:
82 return -8;
83 case PIPE_CAP_MAX_TEXEL_OFFSET:
84 return 7;
85 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
86 return -32;
87 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
88 return 31;
89 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
90 return 65536;
91 case PIPE_CAP_GLSL_FEATURE_LEVEL:
92 return 400;
93 case PIPE_CAP_MAX_RENDER_TARGETS:
94 return 8;
95 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
96 return 1;
97 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
98 return 4;
99 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
100 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
101 return 128;
102 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
103 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
104 return 1024;
105 case PIPE_CAP_MAX_VERTEX_STREAMS:
106 return 4;
107 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
108 return 2048;
109 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
110 return 256;
111 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
112 return 1; /* 256 for binding as RT, but that's not possible in GL */
113 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
114 return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
115 case PIPE_CAP_MAX_VIEWPORTS:
116 return NVC0_MAX_VIEWPORTS;
117 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
118 return 4;
119 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
120 return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50;
121 case PIPE_CAP_ENDIANNESS:
122 return PIPE_ENDIAN_LITTLE;
123
124 /* supported caps */
125 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
126 case PIPE_CAP_TEXTURE_SWIZZLE:
127 case PIPE_CAP_TEXTURE_SHADOW_MAP:
128 case PIPE_CAP_NPOT_TEXTURES:
129 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
130 case PIPE_CAP_ANISOTROPIC_FILTER:
131 case PIPE_CAP_SEAMLESS_CUBE_MAP:
132 case PIPE_CAP_CUBE_MAP_ARRAY:
133 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
134 case PIPE_CAP_TEXTURE_MULTISAMPLE:
135 case PIPE_CAP_TWO_SIDED_STENCIL:
136 case PIPE_CAP_DEPTH_CLIP_DISABLE:
137 case PIPE_CAP_POINT_SPRITE:
138 case PIPE_CAP_TGSI_TEXCOORD:
139 case PIPE_CAP_SM3:
140 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
141 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
142 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
143 case PIPE_CAP_QUERY_TIMESTAMP:
144 case PIPE_CAP_QUERY_TIME_ELAPSED:
145 case PIPE_CAP_OCCLUSION_QUERY:
146 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
147 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
148 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
149 case PIPE_CAP_INDEP_BLEND_ENABLE:
150 case PIPE_CAP_INDEP_BLEND_FUNC:
151 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
152 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
153 case PIPE_CAP_PRIMITIVE_RESTART:
154 case PIPE_CAP_TGSI_INSTANCEID:
155 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
156 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
157 case PIPE_CAP_CONDITIONAL_RENDER:
158 case PIPE_CAP_TEXTURE_BARRIER:
159 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
160 case PIPE_CAP_START_INSTANCE:
161 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
162 case PIPE_CAP_DRAW_INDIRECT:
163 case PIPE_CAP_USER_CONSTANT_BUFFERS:
164 case PIPE_CAP_USER_INDEX_BUFFERS:
165 case PIPE_CAP_USER_VERTEX_BUFFERS:
166 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
167 case PIPE_CAP_TEXTURE_QUERY_LOD:
168 case PIPE_CAP_SAMPLE_SHADING:
169 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
170 case PIPE_CAP_TEXTURE_GATHER_SM5:
171 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
172 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
173 case PIPE_CAP_SAMPLER_VIEW_TARGET:
174 case PIPE_CAP_CLIP_HALFZ:
175 return 1;
176 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
177 return (class_3d >= NVE4_3D_CLASS) ? 1 : 0;
178 case PIPE_CAP_COMPUTE:
179 return (class_3d == NVE4_3D_CLASS) ? 1 : 0;
180
181 /* unsupported caps */
182 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
183 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
184 case PIPE_CAP_SHADER_STENCIL_EXPORT:
185 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
186 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
187 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
188 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
189 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
190 case PIPE_CAP_FAKE_SW_MSAA:
191 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
192 case PIPE_CAP_VERTEXID_NOBASE:
193 return 0;
194
195 case PIPE_CAP_VENDOR_ID:
196 return 0x10de;
197 case PIPE_CAP_DEVICE_ID: {
198 uint64_t device_id;
199 if (nouveau_getparam(dev, NOUVEAU_GETPARAM_PCI_DEVICE, &device_id)) {
200 NOUVEAU_ERR("NOUVEAU_GETPARAM_PCI_DEVICE failed.\n");
201 return -1;
202 }
203 return device_id;
204 }
205 case PIPE_CAP_ACCELERATED:
206 return 1;
207 case PIPE_CAP_VIDEO_MEMORY:
208 return dev->vram_size >> 20;
209 case PIPE_CAP_UMA:
210 return 0;
211 }
212
213 NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
214 return 0;
215 }
216
217 static int
218 nvc0_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader,
219 enum pipe_shader_cap param)
220 {
221 const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
222
223 switch (shader) {
224 case PIPE_SHADER_VERTEX:
225 /*
226 case PIPE_SHADER_TESSELLATION_CONTROL:
227 case PIPE_SHADER_TESSELLATION_EVALUATION:
228 */
229 case PIPE_SHADER_GEOMETRY:
230 case PIPE_SHADER_FRAGMENT:
231 break;
232 case PIPE_SHADER_COMPUTE:
233 if (class_3d != NVE4_3D_CLASS)
234 return 0;
235 break;
236 default:
237 return 0;
238 }
239
240 switch (param) {
241 case PIPE_SHADER_CAP_PREFERRED_IR:
242 return PIPE_SHADER_IR_TGSI;
243 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
244 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
245 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
246 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
247 return 16384;
248 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
249 return 16;
250 case PIPE_SHADER_CAP_MAX_INPUTS:
251 if (shader == PIPE_SHADER_VERTEX)
252 return 32;
253 /* NOTE: These only count our slots for GENERIC varyings.
254 * The address space may be larger, but the actual hard limit seems to be
255 * less than what the address space layout permits, so don't add TEXCOORD,
256 * COLOR, etc. here.
257 */
258 if (shader == PIPE_SHADER_FRAGMENT)
259 return 0x1f0 / 16;
260 /* Actually this counts CLIPVERTEX, which occupies the last generic slot,
261 * and excludes 0x60 per-patch inputs.
262 */
263 return 0x200 / 16;
264 case PIPE_SHADER_CAP_MAX_OUTPUTS:
265 return 32;
266 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
267 return 65536;
268 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
269 if (shader == PIPE_SHADER_COMPUTE && class_3d >= NVE4_3D_CLASS)
270 return NVE4_MAX_PIPE_CONSTBUFS_COMPUTE;
271 return NVC0_MAX_PIPE_CONSTBUFS;
272 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
273 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
274 return shader != PIPE_SHADER_FRAGMENT;
275 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
276 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
277 return 1;
278 case PIPE_SHADER_CAP_MAX_PREDS:
279 return 0;
280 case PIPE_SHADER_CAP_MAX_TEMPS:
281 return NVC0_CAP_MAX_PROGRAM_TEMPS;
282 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
283 return 1;
284 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
285 return 0;
286 case PIPE_SHADER_CAP_SUBROUTINES:
287 return 1;
288 case PIPE_SHADER_CAP_INTEGERS:
289 return 1;
290 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
291 return 16; /* would be 32 in linked (OpenGL-style) mode */
292 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
293 return 16; /* XXX not sure if more are really safe */
294 default:
295 NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
296 return 0;
297 }
298 }
299
300 static float
301 nvc0_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
302 {
303 switch (param) {
304 case PIPE_CAPF_MAX_LINE_WIDTH:
305 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
306 return 10.0f;
307 case PIPE_CAPF_MAX_POINT_WIDTH:
308 return 63.0f;
309 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
310 return 63.375f;
311 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
312 return 16.0f;
313 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
314 return 15.0f;
315 case PIPE_CAPF_GUARD_BAND_LEFT:
316 case PIPE_CAPF_GUARD_BAND_TOP:
317 return 0.0f;
318 case PIPE_CAPF_GUARD_BAND_RIGHT:
319 case PIPE_CAPF_GUARD_BAND_BOTTOM:
320 return 0.0f; /* that or infinity */
321 }
322
323 NOUVEAU_ERR("unknown PIPE_CAPF %d\n", param);
324 return 0.0f;
325 }
326
327 static int
328 nvc0_screen_get_compute_param(struct pipe_screen *pscreen,
329 enum pipe_compute_cap param, void *data)
330 {
331 uint64_t *data64 = (uint64_t *)data;
332 const uint16_t obj_class = nvc0_screen(pscreen)->compute->oclass;
333
334 switch (param) {
335 case PIPE_COMPUTE_CAP_GRID_DIMENSION:
336 data64[0] = 3;
337 return 8;
338 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
339 data64[0] = (obj_class >= NVE4_COMPUTE_CLASS) ? 0x7fffffff : 65535;
340 data64[1] = 65535;
341 data64[2] = 65535;
342 return 24;
343 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
344 data64[0] = 1024;
345 data64[1] = 1024;
346 data64[2] = 64;
347 return 24;
348 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
349 data64[0] = 1024;
350 return 8;
351 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: /* g[] */
352 data64[0] = (uint64_t)1 << 40;
353 return 8;
354 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: /* s[] */
355 data64[0] = 48 << 10;
356 return 8;
357 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: /* l[] */
358 data64[0] = 512 << 10;
359 return 8;
360 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: /* c[], arbitrary limit */
361 data64[0] = 4096;
362 return 8;
363 default:
364 return 0;
365 }
366 }
367
368 static void
369 nvc0_screen_destroy(struct pipe_screen *pscreen)
370 {
371 struct nvc0_screen *screen = nvc0_screen(pscreen);
372
373 if (!nouveau_drm_screen_unref(&screen->base))
374 return;
375
376 if (screen->base.fence.current) {
377 struct nouveau_fence *current = NULL;
378
379 /* nouveau_fence_wait will create a new current fence, so wait on the
380 * _current_ one, and remove both.
381 */
382 nouveau_fence_ref(screen->base.fence.current, &current);
383 nouveau_fence_wait(current);
384 nouveau_fence_ref(NULL, &current);
385 nouveau_fence_ref(NULL, &screen->base.fence.current);
386 }
387 if (screen->base.pushbuf)
388 screen->base.pushbuf->user_priv = NULL;
389
390 if (screen->blitter)
391 nvc0_blitter_destroy(screen);
392 if (screen->pm.prog) {
393 screen->pm.prog->code = NULL; /* hardcoded, don't FREE */
394 nvc0_program_destroy(NULL, screen->pm.prog);
395 }
396
397 nouveau_bo_ref(NULL, &screen->text);
398 nouveau_bo_ref(NULL, &screen->uniform_bo);
399 nouveau_bo_ref(NULL, &screen->tls);
400 nouveau_bo_ref(NULL, &screen->txc);
401 nouveau_bo_ref(NULL, &screen->fence.bo);
402 nouveau_bo_ref(NULL, &screen->poly_cache);
403 nouveau_bo_ref(NULL, &screen->parm);
404
405 nouveau_heap_destroy(&screen->lib_code);
406 nouveau_heap_destroy(&screen->text_heap);
407
408 FREE(screen->tic.entries);
409
410 nouveau_object_del(&screen->eng3d);
411 nouveau_object_del(&screen->eng2d);
412 nouveau_object_del(&screen->m2mf);
413 nouveau_object_del(&screen->compute);
414 nouveau_object_del(&screen->nvsw);
415
416 nouveau_screen_fini(&screen->base);
417
418 FREE(screen);
419 }
420
421 static int
422 nvc0_graph_set_macro(struct nvc0_screen *screen, uint32_t m, unsigned pos,
423 unsigned size, const uint32_t *data)
424 {
425 struct nouveau_pushbuf *push = screen->base.pushbuf;
426
427 size /= 4;
428
429 assert((pos + size) <= 0x800);
430
431 BEGIN_NVC0(push, SUBC_3D(NVC0_GRAPH_MACRO_ID), 2);
432 PUSH_DATA (push, (m - 0x3800) / 8);
433 PUSH_DATA (push, pos);
434 BEGIN_1IC0(push, SUBC_3D(NVC0_GRAPH_MACRO_UPLOAD_POS), size + 1);
435 PUSH_DATA (push, pos);
436 PUSH_DATAp(push, data, size);
437
438 return pos + size;
439 }
440
441 static void
442 nvc0_magic_3d_init(struct nouveau_pushbuf *push, uint16_t obj_class)
443 {
444 BEGIN_NVC0(push, SUBC_3D(0x10cc), 1);
445 PUSH_DATA (push, 0xff);
446 BEGIN_NVC0(push, SUBC_3D(0x10e0), 2);
447 PUSH_DATA (push, 0xff);
448 PUSH_DATA (push, 0xff);
449 BEGIN_NVC0(push, SUBC_3D(0x10ec), 2);
450 PUSH_DATA (push, 0xff);
451 PUSH_DATA (push, 0xff);
452 BEGIN_NVC0(push, SUBC_3D(0x074c), 1);
453 PUSH_DATA (push, 0x3f);
454
455 BEGIN_NVC0(push, SUBC_3D(0x16a8), 1);
456 PUSH_DATA (push, (3 << 16) | 3);
457 BEGIN_NVC0(push, SUBC_3D(0x1794), 1);
458 PUSH_DATA (push, (2 << 16) | 2);
459
460 if (obj_class < GM107_3D_CLASS) {
461 BEGIN_NVC0(push, SUBC_3D(0x12ac), 1);
462 PUSH_DATA (push, 0);
463 }
464 BEGIN_NVC0(push, SUBC_3D(0x0218), 1);
465 PUSH_DATA (push, 0x10);
466 BEGIN_NVC0(push, SUBC_3D(0x10fc), 1);
467 PUSH_DATA (push, 0x10);
468 BEGIN_NVC0(push, SUBC_3D(0x1290), 1);
469 PUSH_DATA (push, 0x10);
470 BEGIN_NVC0(push, SUBC_3D(0x12d8), 2);
471 PUSH_DATA (push, 0x10);
472 PUSH_DATA (push, 0x10);
473 BEGIN_NVC0(push, SUBC_3D(0x1140), 1);
474 PUSH_DATA (push, 0x10);
475 BEGIN_NVC0(push, SUBC_3D(0x1610), 1);
476 PUSH_DATA (push, 0xe);
477
478 BEGIN_NVC0(push, SUBC_3D(0x164c), 1);
479 PUSH_DATA (push, 1 << 12);
480 BEGIN_NVC0(push, SUBC_3D(0x030c), 1);
481 PUSH_DATA (push, 0);
482 BEGIN_NVC0(push, SUBC_3D(0x0300), 1);
483 PUSH_DATA (push, 3);
484
485 BEGIN_NVC0(push, SUBC_3D(0x02d0), 1);
486 PUSH_DATA (push, 0x3fffff);
487 BEGIN_NVC0(push, SUBC_3D(0x0fdc), 1);
488 PUSH_DATA (push, 1);
489 BEGIN_NVC0(push, SUBC_3D(0x19c0), 1);
490 PUSH_DATA (push, 1);
491
492 if (obj_class < GM107_3D_CLASS) {
493 BEGIN_NVC0(push, SUBC_3D(0x075c), 1);
494 PUSH_DATA (push, 3);
495
496 if (obj_class >= NVE4_3D_CLASS) {
497 BEGIN_NVC0(push, SUBC_3D(0x07fc), 1);
498 PUSH_DATA (push, 1);
499 }
500 }
501
502 /* TODO: find out what software methods 0x1528, 0x1280 and (on nve4) 0x02dc
503 * are supposed to do */
504 }
505
506 static void
507 nvc0_screen_fence_emit(struct pipe_screen *pscreen, u32 *sequence)
508 {
509 struct nvc0_screen *screen = nvc0_screen(pscreen);
510 struct nouveau_pushbuf *push = screen->base.pushbuf;
511
512 /* we need to do it after possible flush in MARK_RING */
513 *sequence = ++screen->base.fence.sequence;
514
515 BEGIN_NVC0(push, NVC0_3D(QUERY_ADDRESS_HIGH), 4);
516 PUSH_DATAh(push, screen->fence.bo->offset);
517 PUSH_DATA (push, screen->fence.bo->offset);
518 PUSH_DATA (push, *sequence);
519 PUSH_DATA (push, NVC0_3D_QUERY_GET_FENCE | NVC0_3D_QUERY_GET_SHORT |
520 (0xf << NVC0_3D_QUERY_GET_UNIT__SHIFT));
521 }
522
523 static u32
524 nvc0_screen_fence_update(struct pipe_screen *pscreen)
525 {
526 struct nvc0_screen *screen = nvc0_screen(pscreen);
527 return screen->fence.map[0];
528 }
529
530 static int
531 nvc0_screen_init_compute(struct nvc0_screen *screen)
532 {
533 screen->base.base.get_compute_param = nvc0_screen_get_compute_param;
534
535 switch (screen->base.device->chipset & ~0xf) {
536 case 0xc0:
537 case 0xd0:
538 /* Using COMPUTE has weird effects on 3D state, we need to
539 * investigate this further before enabling it by default.
540 */
541 if (debug_get_bool_option("NVC0_COMPUTE", FALSE))
542 return nvc0_screen_compute_setup(screen, screen->base.pushbuf);
543 return 0;
544 case 0xe0:
545 return nve4_screen_compute_setup(screen, screen->base.pushbuf);
546 case 0xf0:
547 case 0x100:
548 case 0x110:
549 return 0;
550 default:
551 return -1;
552 }
553 }
554
555 boolean
556 nvc0_screen_resize_tls_area(struct nvc0_screen *screen,
557 uint32_t lpos, uint32_t lneg, uint32_t cstack)
558 {
559 struct nouveau_bo *bo = NULL;
560 int ret;
561 uint64_t size = (lpos + lneg) * 32 + cstack;
562
563 if (size >= (1 << 20)) {
564 NOUVEAU_ERR("requested TLS size too large: 0x%"PRIx64"\n", size);
565 return FALSE;
566 }
567
568 size *= (screen->base.device->chipset >= 0xe0) ? 64 : 48; /* max warps */
569 size = align(size, 0x8000);
570 size *= screen->mp_count;
571
572 size = align(size, 1 << 17);
573
574 ret = nouveau_bo_new(screen->base.device, NOUVEAU_BO_VRAM, 1 << 17, size,
575 NULL, &bo);
576 if (ret) {
577 NOUVEAU_ERR("failed to allocate TLS area, size: 0x%"PRIx64"\n", size);
578 return FALSE;
579 }
580 nouveau_bo_ref(NULL, &screen->tls);
581 screen->tls = bo;
582 return TRUE;
583 }
584
585 #define FAIL_SCREEN_INIT(str, err) \
586 do { \
587 NOUVEAU_ERR(str, err); \
588 nvc0_screen_destroy(pscreen); \
589 return NULL; \
590 } while(0)
591
592 struct pipe_screen *
593 nvc0_screen_create(struct nouveau_device *dev)
594 {
595 struct nvc0_screen *screen;
596 struct pipe_screen *pscreen;
597 struct nouveau_object *chan;
598 struct nouveau_pushbuf *push;
599 uint64_t value;
600 uint32_t obj_class;
601 int ret;
602 unsigned i;
603
604 switch (dev->chipset & ~0xf) {
605 case 0xc0:
606 case 0xd0:
607 case 0xe0:
608 case 0xf0:
609 case 0x100:
610 case 0x110:
611 break;
612 default:
613 return NULL;
614 }
615
616 screen = CALLOC_STRUCT(nvc0_screen);
617 if (!screen)
618 return NULL;
619 pscreen = &screen->base.base;
620
621 ret = nouveau_screen_init(&screen->base, dev);
622 if (ret) {
623 nvc0_screen_destroy(pscreen);
624 return NULL;
625 }
626 chan = screen->base.channel;
627 push = screen->base.pushbuf;
628 push->user_priv = screen;
629 push->rsvd_kick = 5;
630
631 screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER |
632 PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
633 PIPE_BIND_COMMAND_ARGS_BUFFER;
634 screen->base.sysmem_bindings |=
635 PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER;
636
637 pscreen->destroy = nvc0_screen_destroy;
638 pscreen->context_create = nvc0_create;
639 pscreen->is_format_supported = nvc0_screen_is_format_supported;
640 pscreen->get_param = nvc0_screen_get_param;
641 pscreen->get_shader_param = nvc0_screen_get_shader_param;
642 pscreen->get_paramf = nvc0_screen_get_paramf;
643 pscreen->get_driver_query_info = nvc0_screen_get_driver_query_info;
644
645 nvc0_screen_init_resource_functions(pscreen);
646
647 screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param;
648 screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported;
649
650 ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, 4096, NULL,
651 &screen->fence.bo);
652 if (ret)
653 goto fail;
654 nouveau_bo_map(screen->fence.bo, 0, NULL);
655 screen->fence.map = screen->fence.bo->map;
656 screen->base.fence.emit = nvc0_screen_fence_emit;
657 screen->base.fence.update = nvc0_screen_fence_update;
658
659
660 ret = nouveau_object_new(chan,
661 (dev->chipset < 0xe0) ? 0x1f906e : 0x906e, 0x906e,
662 NULL, 0, &screen->nvsw);
663 if (ret)
664 FAIL_SCREEN_INIT("Error creating SW object: %d\n", ret);
665
666
667 switch (dev->chipset & ~0xf) {
668 case 0x110:
669 case 0x100:
670 case 0xf0:
671 obj_class = NVF0_P2MF_CLASS;
672 break;
673 case 0xe0:
674 obj_class = NVE4_P2MF_CLASS;
675 break;
676 default:
677 obj_class = NVC0_M2MF_CLASS;
678 break;
679 }
680 ret = nouveau_object_new(chan, 0xbeef323f, obj_class, NULL, 0,
681 &screen->m2mf);
682 if (ret)
683 FAIL_SCREEN_INIT("Error allocating PGRAPH context for M2MF: %d\n", ret);
684
685 BEGIN_NVC0(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1);
686 PUSH_DATA (push, screen->m2mf->oclass);
687 if (screen->m2mf->oclass == NVE4_P2MF_CLASS) {
688 BEGIN_NVC0(push, SUBC_COPY(NV01_SUBCHAN_OBJECT), 1);
689 PUSH_DATA (push, 0xa0b5);
690 }
691
692 ret = nouveau_object_new(chan, 0xbeef902d, NVC0_2D_CLASS, NULL, 0,
693 &screen->eng2d);
694 if (ret)
695 FAIL_SCREEN_INIT("Error allocating PGRAPH context for 2D: %d\n", ret);
696
697 BEGIN_NVC0(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1);
698 PUSH_DATA (push, screen->eng2d->oclass);
699 BEGIN_NVC0(push, SUBC_2D(NVC0_2D_SINGLE_GPC), 1);
700 PUSH_DATA (push, 0);
701 BEGIN_NVC0(push, NVC0_2D(OPERATION), 1);
702 PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY);
703 BEGIN_NVC0(push, NVC0_2D(CLIP_ENABLE), 1);
704 PUSH_DATA (push, 0);
705 BEGIN_NVC0(push, NVC0_2D(COLOR_KEY_ENABLE), 1);
706 PUSH_DATA (push, 0);
707 BEGIN_NVC0(push, SUBC_2D(0x0884), 1);
708 PUSH_DATA (push, 0x3f);
709 BEGIN_NVC0(push, SUBC_2D(0x0888), 1);
710 PUSH_DATA (push, 1);
711 BEGIN_NVC0(push, NVC0_2D(COND_MODE), 1);
712 PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS);
713
714 BEGIN_NVC0(push, SUBC_2D(NVC0_GRAPH_NOTIFY_ADDRESS_HIGH), 2);
715 PUSH_DATAh(push, screen->fence.bo->offset + 16);
716 PUSH_DATA (push, screen->fence.bo->offset + 16);
717
718 switch (dev->chipset & ~0xf) {
719 case 0x110:
720 obj_class = GM107_3D_CLASS;
721 break;
722 case 0x100:
723 case 0xf0:
724 obj_class = NVF0_3D_CLASS;
725 break;
726 case 0xe0:
727 switch (dev->chipset) {
728 case 0xea:
729 obj_class = NVEA_3D_CLASS;
730 break;
731 default:
732 obj_class = NVE4_3D_CLASS;
733 break;
734 }
735 break;
736 case 0xd0:
737 obj_class = NVC8_3D_CLASS;
738 break;
739 case 0xc0:
740 default:
741 switch (dev->chipset) {
742 case 0xc8:
743 obj_class = NVC8_3D_CLASS;
744 break;
745 case 0xc1:
746 obj_class = NVC1_3D_CLASS;
747 break;
748 default:
749 obj_class = NVC0_3D_CLASS;
750 break;
751 }
752 break;
753 }
754 ret = nouveau_object_new(chan, 0xbeef003d, obj_class, NULL, 0,
755 &screen->eng3d);
756 if (ret)
757 FAIL_SCREEN_INIT("Error allocating PGRAPH context for 3D: %d\n", ret);
758 screen->base.class_3d = obj_class;
759
760 BEGIN_NVC0(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1);
761 PUSH_DATA (push, screen->eng3d->oclass);
762
763 BEGIN_NVC0(push, NVC0_3D(COND_MODE), 1);
764 PUSH_DATA (push, NVC0_3D_COND_MODE_ALWAYS);
765
766 if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", TRUE)) {
767 /* kill shaders after about 1 second (at 100 MHz) */
768 BEGIN_NVC0(push, NVC0_3D(WATCHDOG_TIMER), 1);
769 PUSH_DATA (push, 0x17);
770 }
771
772 IMMED_NVC0(push, NVC0_3D(ZETA_COMP_ENABLE), dev->drm_version >= 0x01000101);
773 BEGIN_NVC0(push, NVC0_3D(RT_COMP_ENABLE(0)), 8);
774 for (i = 0; i < 8; ++i)
775 PUSH_DATA(push, dev->drm_version >= 0x01000101);
776
777 BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1);
778 PUSH_DATA (push, 1);
779
780 BEGIN_NVC0(push, NVC0_3D(CSAA_ENABLE), 1);
781 PUSH_DATA (push, 0);
782 BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_ENABLE), 1);
783 PUSH_DATA (push, 0);
784 BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 1);
785 PUSH_DATA (push, NVC0_3D_MULTISAMPLE_MODE_MS1);
786 BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_CTRL), 1);
787 PUSH_DATA (push, 0);
788 BEGIN_NVC0(push, NVC0_3D(LINE_WIDTH_SEPARATE), 1);
789 PUSH_DATA (push, 1);
790 BEGIN_NVC0(push, NVC0_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1);
791 PUSH_DATA (push, 1);
792 BEGIN_NVC0(push, NVC0_3D(BLEND_SEPARATE_ALPHA), 1);
793 PUSH_DATA (push, 1);
794 BEGIN_NVC0(push, NVC0_3D(BLEND_ENABLE_COMMON), 1);
795 PUSH_DATA (push, 0);
796 if (screen->eng3d->oclass < NVE4_3D_CLASS) {
797 BEGIN_NVC0(push, NVC0_3D(TEX_MISC), 1);
798 PUSH_DATA (push, NVC0_3D_TEX_MISC_SEAMLESS_CUBE_MAP);
799 } else {
800 BEGIN_NVC0(push, NVE4_3D(TEX_CB_INDEX), 1);
801 PUSH_DATA (push, 15);
802 }
803 BEGIN_NVC0(push, NVC0_3D(CALL_LIMIT_LOG), 1);
804 PUSH_DATA (push, 8); /* 128 */
805 BEGIN_NVC0(push, NVC0_3D(ZCULL_STATCTRS_ENABLE), 1);
806 PUSH_DATA (push, 1);
807 if (screen->eng3d->oclass >= NVC1_3D_CLASS) {
808 BEGIN_NVC0(push, NVC0_3D(CACHE_SPLIT), 1);
809 PUSH_DATA (push, NVC0_3D_CACHE_SPLIT_48K_SHARED_16K_L1);
810 }
811
812 nvc0_magic_3d_init(push, screen->eng3d->oclass);
813
814 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 17, 1 << 20, NULL,
815 &screen->text);
816 if (ret)
817 goto fail;
818
819 /* XXX: getting a page fault at the end of the code buffer every few
820 * launches, don't use the last 256 bytes to work around them - prefetch ?
821 */
822 nouveau_heap_init(&screen->text_heap, 0, (1 << 20) - 0x100);
823
824 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 12, 6 << 16, NULL,
825 &screen->uniform_bo);
826 if (ret)
827 goto fail;
828
829 PUSH_REFN (push, screen->uniform_bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
830
831 for (i = 0; i < 5; ++i) {
832 /* TIC and TSC entries for each unit (nve4+ only) */
833 /* auxiliary constants (6 user clip planes, base instance id) */
834 BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3);
835 PUSH_DATA (push, 512);
836 PUSH_DATAh(push, screen->uniform_bo->offset + (5 << 16) + (i << 9));
837 PUSH_DATA (push, screen->uniform_bo->offset + (5 << 16) + (i << 9));
838 BEGIN_NVC0(push, NVC0_3D(CB_BIND(i)), 1);
839 PUSH_DATA (push, (15 << 4) | 1);
840 if (screen->eng3d->oclass >= NVE4_3D_CLASS) {
841 unsigned j;
842 BEGIN_1IC0(push, NVC0_3D(CB_POS), 9);
843 PUSH_DATA (push, 0);
844 for (j = 0; j < 8; ++j)
845 PUSH_DATA(push, j);
846 } else {
847 BEGIN_NVC0(push, NVC0_3D(TEX_LIMITS(i)), 1);
848 PUSH_DATA (push, 0x54);
849 }
850 }
851 BEGIN_NVC0(push, NVC0_3D(LINKED_TSC), 1);
852 PUSH_DATA (push, 0);
853
854 /* return { 0.0, 0.0, 0.0, 0.0 } for out-of-bounds vtxbuf access */
855 BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3);
856 PUSH_DATA (push, 256);
857 PUSH_DATAh(push, screen->uniform_bo->offset + (5 << 16) + (6 << 9));
858 PUSH_DATA (push, screen->uniform_bo->offset + (5 << 16) + (6 << 9));
859 BEGIN_1IC0(push, NVC0_3D(CB_POS), 5);
860 PUSH_DATA (push, 0);
861 PUSH_DATAf(push, 0.0f);
862 PUSH_DATAf(push, 0.0f);
863 PUSH_DATAf(push, 0.0f);
864 PUSH_DATAf(push, 0.0f);
865 BEGIN_NVC0(push, NVC0_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2);
866 PUSH_DATAh(push, screen->uniform_bo->offset + (5 << 16) + (6 << 9));
867 PUSH_DATA (push, screen->uniform_bo->offset + (5 << 16) + (6 << 9));
868
869 if (dev->drm_version >= 0x01000101) {
870 ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
871 if (ret) {
872 NOUVEAU_ERR("NOUVEAU_GETPARAM_GRAPH_UNITS failed.\n");
873 goto fail;
874 }
875 } else {
876 if (dev->chipset >= 0xe0 && dev->chipset < 0xf0)
877 value = (8 << 8) | 4;
878 else
879 value = (16 << 8) | 4;
880 }
881 screen->mp_count = value >> 8;
882 screen->mp_count_compute = screen->mp_count;
883
884 nvc0_screen_resize_tls_area(screen, 128 * 16, 0, 0x200);
885
886 BEGIN_NVC0(push, NVC0_3D(CODE_ADDRESS_HIGH), 2);
887 PUSH_DATAh(push, screen->text->offset);
888 PUSH_DATA (push, screen->text->offset);
889 BEGIN_NVC0(push, NVC0_3D(TEMP_ADDRESS_HIGH), 4);
890 PUSH_DATAh(push, screen->tls->offset);
891 PUSH_DATA (push, screen->tls->offset);
892 PUSH_DATA (push, screen->tls->size >> 32);
893 PUSH_DATA (push, screen->tls->size);
894 BEGIN_NVC0(push, NVC0_3D(WARP_TEMP_ALLOC), 1);
895 PUSH_DATA (push, 0);
896 BEGIN_NVC0(push, NVC0_3D(LOCAL_BASE), 1);
897 PUSH_DATA (push, 0);
898
899 if (screen->eng3d->oclass < GM107_3D_CLASS) {
900 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 17, 1 << 20, NULL,
901 &screen->poly_cache);
902 if (ret)
903 goto fail;
904
905 BEGIN_NVC0(push, NVC0_3D(VERTEX_QUARANTINE_ADDRESS_HIGH), 3);
906 PUSH_DATAh(push, screen->poly_cache->offset);
907 PUSH_DATA (push, screen->poly_cache->offset);
908 PUSH_DATA (push, 3);
909 }
910
911 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 17, 1 << 17, NULL,
912 &screen->txc);
913 if (ret)
914 goto fail;
915
916 BEGIN_NVC0(push, NVC0_3D(TIC_ADDRESS_HIGH), 3);
917 PUSH_DATAh(push, screen->txc->offset);
918 PUSH_DATA (push, screen->txc->offset);
919 PUSH_DATA (push, NVC0_TIC_MAX_ENTRIES - 1);
920
921 BEGIN_NVC0(push, NVC0_3D(TSC_ADDRESS_HIGH), 3);
922 PUSH_DATAh(push, screen->txc->offset + 65536);
923 PUSH_DATA (push, screen->txc->offset + 65536);
924 PUSH_DATA (push, NVC0_TSC_MAX_ENTRIES - 1);
925
926 BEGIN_NVC0(push, NVC0_3D(SCREEN_Y_CONTROL), 1);
927 PUSH_DATA (push, 0);
928 BEGIN_NVC0(push, NVC0_3D(WINDOW_OFFSET_X), 2);
929 PUSH_DATA (push, 0);
930 PUSH_DATA (push, 0);
931 BEGIN_NVC0(push, NVC0_3D(ZCULL_REGION), 1); /* deactivate ZCULL */
932 PUSH_DATA (push, 0x3f);
933
934 BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_MODE), 1);
935 PUSH_DATA (push, NVC0_3D_CLIP_RECTS_MODE_INSIDE_ANY);
936 BEGIN_NVC0(push, NVC0_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
937 for (i = 0; i < 8 * 2; ++i)
938 PUSH_DATA(push, 0);
939 BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_EN), 1);
940 PUSH_DATA (push, 0);
941 BEGIN_NVC0(push, NVC0_3D(CLIPID_ENABLE), 1);
942 PUSH_DATA (push, 0);
943
944 /* neither scissors, viewport nor stencil mask should affect clears */
945 BEGIN_NVC0(push, NVC0_3D(CLEAR_FLAGS), 1);
946 PUSH_DATA (push, 0);
947
948 BEGIN_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1);
949 PUSH_DATA (push, 1);
950 for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) {
951 BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(i)), 2);
952 PUSH_DATAf(push, 0.0f);
953 PUSH_DATAf(push, 1.0f);
954 }
955 BEGIN_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 1);
956 PUSH_DATA (push, NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1);
957
958 /* We use scissors instead of exact view volume clipping,
959 * so they're always enabled.
960 */
961 for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) {
962 BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(i)), 3);
963 PUSH_DATA (push, 1);
964 PUSH_DATA (push, 8192 << 16);
965 PUSH_DATA (push, 8192 << 16);
966 }
967
968 #define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n);
969
970 i = 0;
971 MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_PER_INSTANCE, mme9097_per_instance_bf);
972 MK_MACRO(NVC0_3D_MACRO_BLEND_ENABLES, mme9097_blend_enables);
973 MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_SELECT, mme9097_vertex_array_select);
974 MK_MACRO(NVC0_3D_MACRO_TEP_SELECT, mme9097_tep_select);
975 MK_MACRO(NVC0_3D_MACRO_GP_SELECT, mme9097_gp_select);
976 MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_FRONT, mme9097_poly_mode_front);
977 MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_BACK, mme9097_poly_mode_back);
978 MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT, mme9097_draw_arrays_indirect);
979 MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT, mme9097_draw_elts_indirect);
980
981 BEGIN_NVC0(push, NVC0_3D(RASTERIZE_ENABLE), 1);
982 PUSH_DATA (push, 1);
983 BEGIN_NVC0(push, NVC0_3D(RT_SEPARATE_FRAG_DATA), 1);
984 PUSH_DATA (push, 1);
985 BEGIN_NVC0(push, NVC0_3D(MACRO_GP_SELECT), 1);
986 PUSH_DATA (push, 0x40);
987 BEGIN_NVC0(push, NVC0_3D(LAYER), 1);
988 PUSH_DATA (push, 0);
989 BEGIN_NVC0(push, NVC0_3D(MACRO_TEP_SELECT), 1);
990 PUSH_DATA (push, 0x30);
991 BEGIN_NVC0(push, NVC0_3D(PATCH_VERTICES), 1);
992 PUSH_DATA (push, 3);
993 BEGIN_NVC0(push, NVC0_3D(SP_SELECT(2)), 1);
994 PUSH_DATA (push, 0x20);
995 BEGIN_NVC0(push, NVC0_3D(SP_SELECT(0)), 1);
996 PUSH_DATA (push, 0x00);
997
998 BEGIN_NVC0(push, NVC0_3D(POINT_COORD_REPLACE), 1);
999 PUSH_DATA (push, 0);
1000 BEGIN_NVC0(push, NVC0_3D(POINT_RASTER_RULES), 1);
1001 PUSH_DATA (push, NVC0_3D_POINT_RASTER_RULES_OGL);
1002
1003 IMMED_NVC0(push, NVC0_3D(EDGEFLAG), 1);
1004
1005 if (nvc0_screen_init_compute(screen))
1006 goto fail;
1007
1008 PUSH_KICK (push);
1009
1010 screen->tic.entries = CALLOC(4096, sizeof(void *));
1011 screen->tsc.entries = screen->tic.entries + 2048;
1012
1013 if (!nvc0_blitter_create(screen))
1014 goto fail;
1015
1016 nouveau_fence_new(&screen->base, &screen->base.fence.current, FALSE);
1017
1018 return pscreen;
1019
1020 fail:
1021 nvc0_screen_destroy(pscreen);
1022 return NULL;
1023 }
1024
1025 int
1026 nvc0_screen_tic_alloc(struct nvc0_screen *screen, void *entry)
1027 {
1028 int i = screen->tic.next;
1029
1030 while (screen->tic.lock[i / 32] & (1 << (i % 32)))
1031 i = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1);
1032
1033 screen->tic.next = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1);
1034
1035 if (screen->tic.entries[i])
1036 nv50_tic_entry(screen->tic.entries[i])->id = -1;
1037
1038 screen->tic.entries[i] = entry;
1039 return i;
1040 }
1041
1042 int
1043 nvc0_screen_tsc_alloc(struct nvc0_screen *screen, void *entry)
1044 {
1045 int i = screen->tsc.next;
1046
1047 while (screen->tsc.lock[i / 32] & (1 << (i % 32)))
1048 i = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1);
1049
1050 screen->tsc.next = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1);
1051
1052 if (screen->tsc.entries[i])
1053 nv50_tsc_entry(screen->tsc.entries[i])->id = -1;
1054
1055 screen->tsc.entries[i] = entry;
1056 return i;
1057 }