gallium/util: add fast path for buffers in u_default_transfer_inline_write
[mesa.git] / src / gallium / drivers / nvfx / nvfx_screen.c
1 #include "pipe/p_screen.h"
2 #include "pipe/p_state.h"
3 #include "util/u_format.h"
4 #include "util/u_format_s3tc.h"
5 #include "vl/vl_decoder.h"
6 #include "vl/vl_video_buffer.h"
7
8 #include "nouveau/nouveau_screen.h"
9 #include "nouveau/nv_object.xml.h"
10 #include "nvfx_context.h"
11 #include "nvfx_screen.h"
12 #include "nvfx_resource.h"
13 #include "nvfx_tex.h"
14
15 #define NV30_3D_CHIPSET_3X_MASK 0x00000003
16 #define NV34_3D_CHIPSET_3X_MASK 0x00000010
17 #define NV35_3D_CHIPSET_3X_MASK 0x000001e0
18
19 #define NV4X_GRCLASS4097_CHIPSETS 0x00000baf
20 #define NV4X_GRCLASS4497_CHIPSETS 0x00005450
21 #define NV6X_GRCLASS4497_CHIPSETS 0x00000088
22
23 static int
24 nvfx_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
25 {
26 struct nvfx_screen *screen = nvfx_screen(pscreen);
27
28 switch (param) {
29 case PIPE_CAP_NPOT_TEXTURES:
30 return screen->advertise_npot;
31 case PIPE_CAP_TWO_SIDED_STENCIL:
32 return 1;
33 case PIPE_CAP_SM3:
34 /* TODO: >= nv4x support Shader Model 3.0 */
35 return 0;
36 case PIPE_CAP_GLSL_FEATURE_LEVEL:
37 return 120;
38 case PIPE_CAP_ANISOTROPIC_FILTER:
39 return 1;
40 case PIPE_CAP_POINT_SPRITE:
41 return 1;
42 case PIPE_CAP_MAX_RENDER_TARGETS:
43 return screen->use_nv4x ? 4 : 1;
44 case PIPE_CAP_OCCLUSION_QUERY:
45 return 1;
46 case PIPE_CAP_TIMER_QUERY:
47 return 0;
48 case PIPE_CAP_TEXTURE_SHADOW_MAP:
49 return 1;
50 case PIPE_CAP_TEXTURE_SWIZZLE:
51 return 1;
52 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
53 return 13;
54 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
55 return 10;
56 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
57 return 13;
58 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
59 return !!screen->use_nv4x;
60 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
61 return screen->advertise_blend_equation_separate;
62 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
63 return 16;
64 case PIPE_CAP_INDEP_BLEND_ENABLE:
65 /* TODO: on nv40 we have separate color masks */
66 /* TODO: nv40 mrt blending is probably broken */
67 return 0;
68 case PIPE_CAP_INDEP_BLEND_FUNC:
69 return 0;
70 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
71 return 0;
72 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
73 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
74 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
75 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
76 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
77 return 1;
78 case PIPE_CAP_DEPTH_CLIP_DISABLE:
79 return 0; // TODO: implement depth clamp
80 case PIPE_CAP_PRIMITIVE_RESTART:
81 return 0; // TODO: implement primitive restart
82 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
83 case PIPE_CAP_TGSI_INSTANCEID:
84 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
85 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
86 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
87 case PIPE_CAP_SEAMLESS_CUBE_MAP:
88 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
89 case PIPE_CAP_SHADER_STENCIL_EXPORT:
90 case PIPE_CAP_MIN_TEXEL_OFFSET:
91 case PIPE_CAP_MAX_TEXEL_OFFSET:
92 case PIPE_CAP_CONDITIONAL_RENDER:
93 case PIPE_CAP_TEXTURE_BARRIER:
94 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
95 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
96 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
97 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
98 case PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS:
99 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
100 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
101 return 0;
102 default:
103 NOUVEAU_ERR("Warning: unknown PIPE_CAP %d\n", param);
104 return 0;
105 }
106 }
107
108 static int
109 nvfx_screen_get_shader_param(struct pipe_screen *pscreen, unsigned shader, enum pipe_shader_cap param)
110 {
111 struct nvfx_screen *screen = nvfx_screen(pscreen);
112
113 switch(shader) {
114 case PIPE_SHADER_FRAGMENT:
115 switch(param) {
116 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
117 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
118 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
119 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
120 return 4096;
121 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
122 /* FIXME: is it the dynamic (nv30:0/nv40:24) or the static
123 value (nv30:0/nv40:4) ? */
124 return screen->use_nv4x ? 4 : 0;
125 case PIPE_SHADER_CAP_MAX_INPUTS:
126 return screen->use_nv4x ? 12 : 10;
127 case PIPE_SHADER_CAP_MAX_CONSTS:
128 return screen->use_nv4x ? 224 : 32;
129 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
130 return 1;
131 case PIPE_SHADER_CAP_MAX_TEMPS:
132 return 32;
133 case PIPE_SHADER_CAP_MAX_ADDRS:
134 return screen->use_nv4x ? 1 : 0;
135 case PIPE_SHADER_CAP_MAX_PREDS:
136 return 0; /* we could expose these, but nothing uses them */
137 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
138 return 0;
139 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
140 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
141 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
142 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
143 return 0;
144 case PIPE_SHADER_CAP_SUBROUTINES:
145 return screen->use_nv4x ? 1 : 0;
146 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
147 return 16;
148 default:
149 break;
150 }
151 break;
152 case PIPE_SHADER_VERTEX:
153 switch(param) {
154 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
155 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
156 return screen->use_nv4x ? 512 : 256;
157 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
158 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
159 return screen->use_nv4x ? 512 : 0;
160 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
161 /* FIXME: is it the dynamic (nv30:24/nv40:24) or the static
162 value (nv30:1/nv40:4) ? */
163 return screen->use_nv4x ? 4 : 1;
164 case PIPE_SHADER_CAP_MAX_INPUTS:
165 return 16;
166 case PIPE_SHADER_CAP_MAX_CONSTS:
167 /* - 6 is for clip planes; Gallium should be fixed to put
168 * them in the vertex shader itself, so we don't need to reserve these */
169 return (screen->use_nv4x ? 468 : 256) - 6;
170 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
171 return 1;
172 case PIPE_SHADER_CAP_MAX_TEMPS:
173 return screen->use_nv4x ? 32 : 13;
174 case PIPE_SHADER_CAP_MAX_ADDRS:
175 return 2;
176 case PIPE_SHADER_CAP_MAX_PREDS:
177 return 0; /* we could expose these, but nothing uses them */
178 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
179 return 1;
180 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
181 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
182 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
183 return 0;
184 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
185 return 1;
186 case PIPE_SHADER_CAP_SUBROUTINES:
187 return 1;
188 case PIPE_SHADER_CAP_INTEGERS:
189 return 0;
190 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
191 return 0; /* We have 4 on nv40 - but unsupported currently */
192 default:
193 break;
194 }
195 break;
196 default:
197 break;
198 }
199 return 0;
200 }
201
202 static float
203 nvfx_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
204 {
205 struct nvfx_screen *screen = nvfx_screen(pscreen);
206
207 switch (param) {
208 case PIPE_CAPF_MAX_LINE_WIDTH:
209 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
210 return 10.0;
211 case PIPE_CAPF_MAX_POINT_WIDTH:
212 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
213 return 64.0;
214 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
215 return screen->use_nv4x ? 16.0 : 8.0;
216 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
217 return 15.0;
218 default:
219 NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
220 return 0.0;
221 }
222 }
223
224 static int
225 nvfx_screen_get_video_param(struct pipe_screen *screen,
226 enum pipe_video_profile profile,
227 enum pipe_video_cap param)
228 {
229 switch (param) {
230 case PIPE_VIDEO_CAP_SUPPORTED:
231 return vl_profile_supported(screen, profile);
232 case PIPE_VIDEO_CAP_NPOT_TEXTURES:
233 return 0;
234 case PIPE_VIDEO_CAP_MAX_WIDTH:
235 case PIPE_VIDEO_CAP_MAX_HEIGHT:
236 return vl_video_buffer_max_size(screen);
237 case PIPE_VIDEO_CAP_PREFERED_FORMAT:
238 return PIPE_FORMAT_NV12;
239 case PIPE_VIDEO_CAP_PREFERS_INTERLACED:
240 return false;
241 case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:
242 return false;
243 case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:
244 return true;
245 default:
246 return 0;
247 }
248 }
249
250 static boolean
251 nvfx_screen_is_format_supported(struct pipe_screen *pscreen,
252 enum pipe_format format,
253 enum pipe_texture_target target,
254 unsigned sample_count,
255 unsigned bind)
256 {
257 struct nvfx_screen *screen = nvfx_screen(pscreen);
258
259 if (!util_format_is_supported(format, bind))
260 return FALSE;
261
262 if (sample_count > 1)
263 return FALSE;
264
265 if (bind & PIPE_BIND_RENDER_TARGET) {
266 switch (format) {
267 case PIPE_FORMAT_B8G8R8A8_UNORM:
268 case PIPE_FORMAT_B8G8R8X8_UNORM:
269 case PIPE_FORMAT_R8G8B8A8_UNORM:
270 case PIPE_FORMAT_R8G8B8X8_UNORM:
271 case PIPE_FORMAT_B5G6R5_UNORM:
272 break;
273 case PIPE_FORMAT_R16G16B16A16_FLOAT:
274 if(!screen->advertise_fp16)
275 return FALSE;
276 break;
277 case PIPE_FORMAT_R32G32B32A32_FLOAT:
278 if(!screen->advertise_fp32)
279 return FALSE;
280 break;
281 default:
282 return FALSE;
283 }
284 }
285
286 if (bind & PIPE_BIND_DEPTH_STENCIL) {
287 switch (format) {
288 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
289 case PIPE_FORMAT_X8Z24_UNORM:
290 case PIPE_FORMAT_Z16_UNORM:
291 break;
292 default:
293 return FALSE;
294 }
295 }
296
297 if (bind & PIPE_BIND_SAMPLER_VIEW) {
298 struct nvfx_texture_format* tf = &nvfx_texture_formats[format];
299 if(util_format_is_s3tc(format) && !util_format_s3tc_enabled)
300 return FALSE;
301 if(format == PIPE_FORMAT_R16G16B16A16_FLOAT && !screen->advertise_fp16)
302 return FALSE;
303 if(format == PIPE_FORMAT_R32G32B32A32_FLOAT && !screen->advertise_fp32)
304 return FALSE;
305 if(screen->use_nv4x)
306 {
307 if(tf->fmt[4] < 0)
308 return FALSE;
309 }
310 else
311 {
312 if(tf->fmt[0] < 0)
313 return FALSE;
314 }
315 }
316
317 // note that we do actually support everything through translate
318 if (bind & PIPE_BIND_VERTEX_BUFFER) {
319 unsigned type = nvfx_vertex_formats[format];
320 if(!type)
321 return FALSE;
322 }
323
324 if (bind & PIPE_BIND_INDEX_BUFFER) {
325 // 8-bit indices supported, but not in hardware index buffer
326 if(format != PIPE_FORMAT_R16_USCALED && format != PIPE_FORMAT_R32_USCALED)
327 return FALSE;
328 }
329
330 if(bind & PIPE_BIND_STREAM_OUTPUT)
331 return FALSE;
332
333 return TRUE;
334 }
335
336 static void
337 nvfx_screen_destroy(struct pipe_screen *pscreen)
338 {
339 struct nvfx_screen *screen = nvfx_screen(pscreen);
340
341 nouveau_resource_destroy(&screen->vp_exec_heap);
342 nouveau_resource_destroy(&screen->vp_data_heap);
343 nouveau_resource_destroy(&screen->query_heap);
344 nouveau_notifier_free(&screen->query);
345 nouveau_notifier_free(&screen->sync);
346 nouveau_grobj_free(&screen->eng3d);
347 nvfx_screen_surface_takedown(pscreen);
348 nouveau_bo_ref(NULL, &screen->fence);
349
350 nouveau_screen_fini(&screen->base);
351
352 FREE(pscreen);
353 }
354
355 static void nv30_screen_init(struct nvfx_screen *screen)
356 {
357 struct nouveau_channel *chan = screen->base.channel;
358 struct nouveau_grobj *eng3d = screen->eng3d;
359 int i;
360
361 /* TODO: perhaps we should do some of this on nv40 too? */
362 for (i=1; i<8; i++) {
363 BEGIN_RING(chan, eng3d, NV30_3D_VIEWPORT_CLIP_HORIZ(i), 1);
364 OUT_RING(chan, 0);
365 BEGIN_RING(chan, eng3d, NV30_3D_VIEWPORT_CLIP_VERT(i), 1);
366 OUT_RING(chan, 0);
367 }
368
369 BEGIN_RING(chan, eng3d, 0x220, 1);
370 OUT_RING(chan, 1);
371
372 BEGIN_RING(chan, eng3d, 0x03b0, 1);
373 OUT_RING(chan, 0x00100000);
374 BEGIN_RING(chan, eng3d, 0x1454, 1);
375 OUT_RING(chan, 0);
376 BEGIN_RING(chan, eng3d, 0x1d80, 1);
377 OUT_RING(chan, 3);
378 BEGIN_RING(chan, eng3d, 0x1450, 1);
379 OUT_RING(chan, 0x00030004);
380
381 /* NEW */
382 BEGIN_RING(chan, eng3d, 0x1e98, 1);
383 OUT_RING(chan, 0);
384 BEGIN_RING(chan, eng3d, 0x17e0, 3);
385 OUT_RING(chan, fui(0.0));
386 OUT_RING(chan, fui(0.0));
387 OUT_RING(chan, fui(1.0));
388 BEGIN_RING(chan, eng3d, 0x1f80, 16);
389 for (i=0; i<16; i++) {
390 OUT_RING(chan, (i==8) ? 0x0000ffff : 0);
391 }
392
393 BEGIN_RING(chan, eng3d, 0x120, 3);
394 OUT_RING(chan, 0);
395 OUT_RING(chan, 1);
396 OUT_RING(chan, 2);
397
398 BEGIN_RING(chan, eng3d, 0x1d88, 1);
399 OUT_RING(chan, 0x00001200);
400
401 BEGIN_RING(chan, eng3d, NV30_3D_RC_ENABLE, 1);
402 OUT_RING(chan, 0);
403
404 BEGIN_RING(chan, eng3d, NV30_3D_DEPTH_RANGE_NEAR, 2);
405 OUT_RING(chan, fui(0.0));
406 OUT_RING(chan, fui(1.0));
407
408 BEGIN_RING(chan, eng3d, NV30_3D_MULTISAMPLE_CONTROL, 1);
409 OUT_RING(chan, 0xffff0000);
410
411 /* enables use of vp rather than fixed-function somehow */
412 BEGIN_RING(chan, eng3d, 0x1e94, 1);
413 OUT_RING(chan, 0x13);
414 }
415
416 static void nv40_screen_init(struct nvfx_screen *screen)
417 {
418 struct nouveau_channel *chan = screen->base.channel;
419 struct nouveau_grobj *eng3d = screen->eng3d;
420
421 BEGIN_RING(chan, eng3d, NV40_3D_DMA_COLOR2, 2);
422 OUT_RING(chan, screen->base.channel->vram->handle);
423 OUT_RING(chan, screen->base.channel->vram->handle);
424
425 BEGIN_RING(chan, eng3d, 0x1450, 1);
426 OUT_RING(chan, 0x00000004);
427
428 BEGIN_RING(chan, eng3d, 0x1ea4, 3);
429 OUT_RING(chan, 0x00000010);
430 OUT_RING(chan, 0x01000100);
431 OUT_RING(chan, 0xff800006);
432
433 /* vtxprog output routing */
434 BEGIN_RING(chan, eng3d, 0x1fc4, 1);
435 OUT_RING(chan, 0x06144321);
436 BEGIN_RING(chan, eng3d, 0x1fc8, 2);
437 OUT_RING(chan, 0xedcba987);
438 OUT_RING(chan, 0x0000006f);
439 BEGIN_RING(chan, eng3d, 0x1fd0, 1);
440 OUT_RING(chan, 0x00171615);
441 BEGIN_RING(chan, eng3d, 0x1fd4, 1);
442 OUT_RING(chan, 0x001b1a19);
443
444 BEGIN_RING(chan, eng3d, 0x1ef8, 1);
445 OUT_RING(chan, 0x0020ffff);
446 BEGIN_RING(chan, eng3d, 0x1d64, 1);
447 OUT_RING(chan, 0x01d300d4);
448 BEGIN_RING(chan, eng3d, 0x1e94, 1);
449 OUT_RING(chan, 0x00000001);
450
451 BEGIN_RING(chan, eng3d, NV40_3D_MIPMAP_ROUNDING, 1);
452 OUT_RING(chan, NV40_3D_MIPMAP_ROUNDING_MODE_DOWN);
453 }
454
455 static unsigned
456 nvfx_screen_get_vertex_buffer_flags(struct nvfx_screen* screen)
457 {
458 int vram_hack_default = 0;
459 int vram_hack;
460 // TODO: this is a bit of a guess; also add other cards that may need this hack.
461 // It may also depend on the specific card or the AGP/PCIe chipset.
462 if(screen->base.device->chipset == 0x47 /* G70 */
463 || screen->base.device->chipset == 0x49 /* G71 */
464 || screen->base.device->chipset == 0x46 /* G72 */
465 )
466 vram_hack_default = 1;
467 vram_hack = debug_get_bool_option("NOUVEAU_VTXIDX_IN_VRAM", vram_hack_default);
468
469 return vram_hack ? NOUVEAU_BO_VRAM : NOUVEAU_BO_GART;
470 }
471
472 static void nvfx_channel_flush_notify(struct nouveau_channel* chan)
473 {
474 struct nvfx_screen* screen = chan->user_private;
475 struct nvfx_context* nvfx = screen->cur_ctx;
476 if(nvfx)
477 nvfx->relocs_needed = NVFX_RELOCATE_ALL;
478 }
479
480 struct pipe_screen *
481 nvfx_screen_create(struct nouveau_device *dev)
482 {
483 static const unsigned query_sizes[] = {(4096 - 4 * 32) / 32, 3 * 1024 / 32, 2 * 1024 / 32, 1024 / 32};
484 struct nvfx_screen *screen = CALLOC_STRUCT(nvfx_screen);
485 struct nouveau_channel *chan;
486 struct pipe_screen *pscreen;
487 unsigned eng3d_class = 0;
488 int ret, i;
489
490 if (!screen)
491 return NULL;
492
493 pscreen = &screen->base.base;
494
495 ret = nouveau_screen_init(&screen->base, dev);
496 if (ret) {
497 nvfx_screen_destroy(pscreen);
498 return NULL;
499 }
500 chan = screen->base.channel;
501 screen->cur_ctx = NULL;
502 chan->user_private = screen;
503 chan->flush_notify = nvfx_channel_flush_notify;
504
505 pscreen->destroy = nvfx_screen_destroy;
506 pscreen->get_param = nvfx_screen_get_param;
507 pscreen->get_shader_param = nvfx_screen_get_shader_param;
508 pscreen->get_paramf = nvfx_screen_get_paramf;
509 pscreen->get_video_param = nvfx_screen_get_video_param;
510 pscreen->is_format_supported = nvfx_screen_is_format_supported;
511 pscreen->is_video_format_supported = vl_video_buffer_is_format_supported;
512 pscreen->context_create = nvfx_create;
513
514 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 4096, &screen->fence);
515 if (ret) {
516 nvfx_screen_destroy(pscreen);
517 return NULL;
518 }
519
520 switch (dev->chipset & 0xf0) {
521 case 0x30:
522 if (NV30_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f)))
523 eng3d_class = NV30_3D;
524 else if (NV34_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f)))
525 eng3d_class = NV34_3D;
526 else if (NV35_3D_CHIPSET_3X_MASK & (1 << (dev->chipset & 0x0f)))
527 eng3d_class = NV35_3D;
528 break;
529 case 0x40:
530 if (NV4X_GRCLASS4097_CHIPSETS & (1 << (dev->chipset & 0x0f)))
531 eng3d_class = NV40_3D;
532 else if (NV4X_GRCLASS4497_CHIPSETS & (1 << (dev->chipset & 0x0f)))
533 eng3d_class = NV44_3D;
534 screen->is_nv4x = ~0;
535 break;
536 case 0x60:
537 if (NV6X_GRCLASS4497_CHIPSETS & (1 << (dev->chipset & 0x0f)))
538 eng3d_class = NV44_3D;
539 screen->is_nv4x = ~0;
540 break;
541 }
542
543 if (!eng3d_class) {
544 NOUVEAU_ERR("Unknown nv3x/nv4x chipset: nv%02x\n", dev->chipset);
545 return NULL;
546 }
547
548 screen->advertise_npot = !!screen->is_nv4x;
549 screen->advertise_blend_equation_separate = !!screen->is_nv4x;
550 screen->use_nv4x = screen->is_nv4x;
551
552 if(screen->is_nv4x) {
553 if(debug_get_bool_option("NVFX_SIMULATE_NV30", FALSE))
554 screen->use_nv4x = 0;
555 if(!debug_get_bool_option("NVFX_NPOT", TRUE))
556 screen->advertise_npot = 0;
557 if(!debug_get_bool_option("NVFX_BLEND_EQ_SEP", TRUE))
558 screen->advertise_blend_equation_separate = 0;
559 }
560
561 screen->force_swtnl = debug_get_bool_option("NVFX_SWTNL", FALSE);
562 screen->trace_draw = debug_get_bool_option("NVFX_TRACE_DRAW", FALSE);
563
564 screen->buffer_allocation_cost = debug_get_num_option("NVFX_BUFFER_ALLOCATION_COST", 16384);
565 screen->inline_cost_per_hardware_cost = atof(debug_get_option("NVFX_INLINE_COST_PER_HARDWARE_COST", "1.0"));
566 screen->static_reuse_threshold = atof(debug_get_option("NVFX_STATIC_REUSE_THRESHOLD", "2.0"));
567
568 /* We don't advertise these by default because filtering and blending doesn't work as
569 * it should, due to several restrictions.
570 * The only exception is fp16 on nv40.
571 */
572 screen->advertise_fp16 = debug_get_bool_option("NVFX_FP16", !!screen->use_nv4x);
573 screen->advertise_fp32 = debug_get_bool_option("NVFX_FP32", 0);
574
575 screen->vertex_buffer_reloc_flags = nvfx_screen_get_vertex_buffer_flags(screen);
576
577 /* surely both nv3x and nv44 support index buffers too: find out how and test that */
578 if(eng3d_class == NV40_3D)
579 screen->index_buffer_reloc_flags = screen->vertex_buffer_reloc_flags;
580
581 if(!screen->force_swtnl && screen->vertex_buffer_reloc_flags == screen->index_buffer_reloc_flags)
582 screen->base.vertex_buffer_flags = screen->base.index_buffer_flags = screen->vertex_buffer_reloc_flags;
583
584 nvfx_screen_init_resource_functions(pscreen);
585
586 ret = nouveau_grobj_alloc(chan, 0xbeef3097, eng3d_class, &screen->eng3d);
587 if (ret) {
588 NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
589 return FALSE;
590 }
591
592 /* 2D engine setup */
593 nvfx_screen_surface_init(pscreen);
594
595 /* Notifier for sync purposes */
596 ret = nouveau_notifier_alloc(chan, 0xbeef0301, 1, &screen->sync);
597 if (ret) {
598 NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
599 nvfx_screen_destroy(pscreen);
600 return NULL;
601 }
602
603 /* Query objects */
604 for(i = 0; i < sizeof(query_sizes) / sizeof(query_sizes[0]); ++i)
605 {
606 ret = nouveau_notifier_alloc(chan, 0xbeef0302, query_sizes[i], &screen->query);
607 if(!ret)
608 break;
609 }
610
611 if (ret) {
612 NOUVEAU_ERR("Error initialising query objects: %d\n", ret);
613 nvfx_screen_destroy(pscreen);
614 return NULL;
615 }
616
617 ret = nouveau_resource_init(&screen->query_heap, 0, query_sizes[i]);
618 if (ret) {
619 NOUVEAU_ERR("Error initialising query object heap: %d\n", ret);
620 nvfx_screen_destroy(pscreen);
621 return NULL;
622 }
623
624 LIST_INITHEAD(&screen->query_list);
625
626 /* Vtxprog resources */
627 if (nouveau_resource_init(&screen->vp_exec_heap, 0, screen->use_nv4x ? 512 : 256) ||
628 nouveau_resource_init(&screen->vp_data_heap, 0, screen->use_nv4x ? 468 : 256)) {
629 nvfx_screen_destroy(pscreen);
630 return NULL;
631 }
632
633 BIND_RING(chan, screen->eng3d, 7);
634
635 /* Static eng3d initialisation */
636 /* note that we just started using the channel, so we must have space in the pushbuffer */
637 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_NOTIFY, 1);
638 OUT_RING(chan, screen->sync->handle);
639 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_TEXTURE0, 2);
640 OUT_RING(chan, chan->vram->handle);
641 OUT_RING(chan, chan->gart->handle);
642 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_COLOR1, 1);
643 OUT_RING(chan, chan->vram->handle);
644 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_COLOR0, 2);
645 OUT_RING(chan, chan->vram->handle);
646 OUT_RING(chan, chan->vram->handle);
647 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_VTXBUF0, 2);
648 OUT_RING(chan, chan->vram->handle);
649 OUT_RING(chan, chan->gart->handle);
650
651 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_FENCE, 2);
652 OUT_RING(chan, 0);
653 OUT_RING(chan, screen->query->handle);
654
655 BEGIN_RING(chan, screen->eng3d, NV30_3D_DMA_UNK1AC, 2);
656 OUT_RING(chan, chan->vram->handle);
657 OUT_RING(chan, chan->vram->handle);
658
659 if(!screen->is_nv4x)
660 nv30_screen_init(screen);
661 else
662 nv40_screen_init(screen);
663
664 return pscreen;
665 }