Debian Codegraph @

src/gallium/drivers/nouveau/nv30/nv30_screen.c

raw
1 /*
2 * Copyright 2012 Red Hat Inc.
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 * Authors: Ben Skeggs
23 *
24 */
25
26 #include <xf86drm.h>
27 #include "drm-uapi/nouveau_drm.h"
28 #include "util/format/u_format.h"
29 #include "util/format/u_format_s3tc.h"
30 #include "util/u_screen.h"
31
32 #include "nv_object.xml.h"
33 #include "nv_m2mf.xml.h"
34 #include "nv30/nv30-40_3d.xml.h"
35 #include "nv30/nv01_2d.xml.h"
36
37 #include "nouveau_fence.h"
38 #include "nv30/nv30_screen.h"
39 #include "nv30/nv30_context.h"
40 #include "nv30/nv30_resource.h"
41 #include "nv30/nv30_format.h"
42 #include "nv30/nv30_winsys.h"
43
44 #define RANKINE_0397_CHIPSET 0x00000003
45 #define RANKINE_0497_CHIPSET 0x000001e0
46 #define RANKINE_0697_CHIPSET 0x00000010
47 #define CURIE_4097_CHIPSET 0x00000baf
48 #define CURIE_4497_CHIPSET 0x00005450
49 #define CURIE_4497_CHIPSET6X 0x00000088
50
51 static void
52 nv30_init_shader_caps(struct nv30_screen *screen)
53 {
54 struct nouveau_object *eng3d = screen->eng3d;
55
56 struct pipe_shader_caps *caps =
57 (struct pipe_shader_caps *)&screen->base.base.shader_caps[MESA_SHADER_VERTEX];
58
59 caps->max_instructions =
60 caps->max_alu_instructions = (eng3d->oclass >= NV40_3D_CLASS) ? 512 : 256;
61 caps->max_tex_instructions =
62 caps->max_tex_indirections = (eng3d->oclass >= NV40_3D_CLASS) ? 512 : 0;
63 caps->max_inputs =
64 caps->max_outputs = 16;
65 caps->max_const_buffer0_size =
66 ((eng3d->oclass >= NV40_3D_CLASS) ? (468 - 6): (256 - 6)) * sizeof(float[4]);
67 caps->max_const_buffers = 1;
68 caps->max_temps = (eng3d->oclass >= NV40_3D_CLASS) ? 32 : 13;
69 caps->supported_irs = (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_TGSI);
70
71 caps = (struct pipe_shader_caps *)&screen->base.base.shader_caps[MESA_SHADER_FRAGMENT];
72
73 caps->max_instructions =
74 caps->max_alu_instructions =
75 caps->max_tex_instructions =
76 caps->max_tex_indirections = 4096;
77 caps->max_inputs = 8; /* should be possible to do 10 with nv4x */
78 caps->max_outputs = 4;
79 caps->max_const_buffer0_size =
80 ((eng3d->oclass >= NV40_3D_CLASS) ? 224 : 32) * sizeof(float[4]);
81 caps->max_const_buffers = 1;
82 caps->max_temps = 32;
83 caps->max_texture_samplers =
84 caps->max_sampler_views = 16;
85 caps->supported_irs = (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_TGSI);
86 }
87
88 static void
89 nv30_init_screen_caps(struct nv30_screen *screen)
90 {
91 struct pipe_caps *caps = (struct pipe_caps *)&screen->base.base.caps;
92
93 u_init_pipe_screen_caps(&screen->base.base, 1);
94
95 struct nouveau_object *eng3d = screen->eng3d;
96 struct nouveau_device *dev = screen->base.device;
97
98 /* non-boolean capabilities */
99 caps->max_render_targets = (eng3d->oclass >= NV40_3D_CLASS) ? 4 : 1;
100 caps->max_texture_2d_size = 4096;
101 caps->max_texture_3d_levels = 10;
102 caps->max_texture_cube_levels = 13;
103 caps->glsl_feature_level =
104 caps->glsl_feature_level_compatibility = 120;
105 caps->endianness = PIPE_ENDIAN_LITTLE;
106 caps->constant_buffer_offset_alignment = 16;
107 caps->min_map_buffer_alignment = NOUVEAU_MIN_BUFFER_MAP_ALIGN;
108 caps->max_viewports = 1;
109 caps->max_vertex_attrib_stride = 2048;
110 caps->max_texture_upload_memory_budget = 8 * 1024 * 1024;
111 caps->max_varyings = 8;
112
113 /* supported capabilities */
114 caps->anisotropic_filter = true;
115 caps->occlusion_query = true;
116 caps->query_time_elapsed = true;
117 caps->query_timestamp = true;
118 caps->texture_swizzle = true;
119 caps->depth_clip_disable = true;
120 caps->fs_coord_origin_upper_left = true;
121 caps->fs_coord_origin_lower_left = true;
122 caps->fs_coord_pixel_center_half_integer = true;
123 caps->fs_coord_pixel_center_integer = true;
124 caps->tgsi_texcoord = true;
125 caps->buffer_map_persistent_coherent = true;
126 caps->clear_scissored = true;
127 caps->allow_mapped_buffers_during_execution = true;
128 caps->query_memory_info = true;
129 caps->vertex_input_alignment = PIPE_VERTEX_INPUT_ALIGNMENT_4BYTE;
130 caps->texture_transfer_modes = PIPE_TEXTURE_TRANSFER_BLIT;
131 /* nv35 capabilities */
132 caps->depth_bounds_test =
133 eng3d->oclass == NV35_3D_CLASS || eng3d->oclass >= NV40_3D_CLASS;
134 caps->supported_prim_modes_with_restart =
135 caps->supported_prim_modes = BITFIELD_MASK(MESA_PRIM_COUNT);
136 /* nv4x capabilities */
137 caps->blend_equation_separate =
138 caps->npot_textures =
139 caps->conditional_render =
140 caps->texture_mirror_clamp =
141 caps->texture_mirror_clamp_to_edge =
142 caps->primitive_restart =
143 caps->primitive_restart_fixed_index = eng3d->oclass >= NV40_3D_CLASS;
144 /* unsupported */
145 caps->emulate_nonfixed_primitive_restart = false;
146 caps->depth_clip_disable_separate = false;
147 caps->max_dual_source_render_targets = 0;
148 caps->fragment_shader_texture_lod = false;
149 caps->fragment_shader_derivatives = false;
150 caps->indep_blend_enable = false;
151 caps->indep_blend_func = false;
152 caps->max_texture_array_layers = 0;
153 caps->shader_stencil_export = false;
154 caps->vs_instanceid = false;
155 caps->vertex_element_instance_divisor = false; /* xxx = yes? */
156 caps->max_stream_output_buffers = 0;
157 caps->stream_output_pause_resume = false;
158 caps->stream_output_interleave_buffers = false;
159 caps->min_texel_offset = 0;
160 caps->max_texel_offset = 0;
161 caps->min_texture_gather_offset = 0;
162 caps->max_texture_gather_offset = 0;
163 caps->max_stream_output_separate_components = 0;
164 caps->max_stream_output_interleaved_components = 0;
165 caps->max_geometry_output_vertices = 0;
166 caps->max_geometry_total_output_components = 0;
167 caps->max_vertex_streams = 0;
168 caps->tgsi_can_compact_constants = false;
169 caps->texture_barrier = false;
170 caps->seamless_cube_map = false;
171 caps->seamless_cube_map_per_texture = false;
172 caps->cube_map_array = false;
173 caps->vertex_color_unclamped = false;
174 caps->fragment_color_clamped = false;
175 caps->vertex_color_clamped = false;
176 caps->quads_follow_provoking_vertex_convention = false;
177 caps->mixed_colorbuffer_formats = false;
178 caps->start_instance = false;
179 caps->texture_multisample = false;
180 caps->texture_buffer_objects = false;
181 caps->texture_buffer_offset_alignment = 0;
182 caps->query_pipeline_statistics = false;
183 caps->texture_border_color_quirk = false;
184 caps->max_texel_buffer_elements = 0;
185 caps->mixed_framebuffer_sizes = false;
186 caps->vs_layer_viewport = false;
187 caps->max_texture_gather_components = 0;
188 caps->texture_gather_sm5 = false;
189 caps->fake_sw_msaa = false;
190 caps->texture_query_lod = false;
191 caps->sample_shading = false;
192 caps->texture_gather_offsets = false;
193 caps->vs_window_space_position = false;
194 caps->user_vertex_buffers = false;
195 caps->compute = false;
196 caps->draw_indirect = false;
197 caps->multi_draw_indirect = false;
198 caps->multi_draw_indirect_params = false;
199 caps->fs_fine_derivative = false;
200 caps->conditional_render_inverted = false;
201 caps->sampler_view_target = false;
202 caps->clip_halfz = false;
203 caps->polygon_offset_clamp = false;
204 caps->multisample_z_resolve = false;
205 caps->resource_from_user_memory = false;
206 caps->device_reset_status_query = false;
207 caps->max_shader_patch_varyings = 0;
208 caps->texture_float_linear = false;
209 caps->texture_half_float_linear = false;
210 caps->texture_query_samples = false;
211 caps->force_persample_interp = false;
212 caps->copy_between_compressed_and_plain_formats = false;
213 caps->shareable_shaders = false;
214 caps->draw_parameters = false;
215 caps->shader_pack_half_float = false;
216 caps->fs_position_is_sysval = false;
217 caps->fs_face_is_integer_sysval = false;
218 caps->shader_buffer_offset_alignment = 0;
219 caps->invalidate_buffer = false;
220 caps->generate_mipmap = false;
221 caps->string_marker = false;
222 caps->buffer_sampler_view_rgba_only = false;
223 caps->surface_reinterpret_blocks = false;
224 caps->compressed_surface_reinterpret_blocks_layered = false;
225 caps->query_buffer_object = false;
226 caps->framebuffer_no_attachment = false;
227 caps->robust_buffer_access_behavior = false;
228 caps->cull_distance = false;
229 caps->shader_group_vote = false;
230 caps->max_window_rectangles = 0;
231 caps->viewport_subpixel_bits = 0;
232 caps->mixed_color_depth_bits = 0;
233 caps->shader_array_components = false;
234 caps->native_fence_fd = false;
235 caps->fbfetch = 0;
236 caps->legacy_math_rules = false;
237 caps->doubles = false;
238 caps->int64 = false;
239 caps->tgsi_tex_txf_lz = false;
240 caps->shader_clock = false;
241 caps->polygon_mode_fill_rectangle = false;
242 caps->sparse_buffer_page_size = 0;
243 caps->shader_ballot = false;
244 caps->tes_layer_viewport = false;
245 caps->can_bind_const_buffer_as_vertex = false;
246 caps->post_depth_coverage = false;
247 caps->bindless_texture = false;
248 caps->nir_samplers_as_deref = false;
249 caps->query_so_overflow = false;
250 caps->memobj = false;
251 caps->load_constbuf = false;
252 caps->tile_raster_order = false;
253 caps->max_combined_shader_output_resources = 0;
254 caps->framebuffer_msaa_constraints = false;
255 caps->signed_vertex_buffer_offset = false;
256 caps->context_priority_mask = 0;
257 caps->fence_signal = false;
258 caps->constbuf0_flags = 0;
259 caps->packed_uniforms = false;
260 caps->conservative_raster_post_snap_triangles = false;
261 caps->conservative_raster_post_snap_points_lines = false;
262 caps->conservative_raster_pre_snap_triangles = false;
263 caps->conservative_raster_pre_snap_points_lines = false;
264 caps->conservative_raster_post_depth_coverage = false;
265 caps->max_conservative_raster_subpixel_precision_bias = false;
266 caps->programmable_sample_locations = false;
267 caps->image_load_formatted = false;
268 caps->image_atomic_inc_wrap = false;
269 caps->image_store_formatted = false;
270
271 caps->pci_group = dev->info.pci.domain;
272 caps->pci_bus = dev->info.pci.bus;
273 caps->pci_device = dev->info.pci.dev;
274 caps->pci_function = dev->info.pci.func;
275
276 caps->max_gs_invocations = 32;
277 caps->max_shader_buffer_size = 1 << 27;
278 caps->vendor_id = 0x10de;
279 caps->device_id = dev->info.device_id;
280 caps->video_memory = dev->vram_size >> 20;
281 caps->uma = false;
282
283 caps->min_line_width =
284 caps->min_line_width_aa =
285 caps->min_point_size =
286 caps->min_point_size_aa = 1;
287
288 caps->point_size_granularity =
289 caps->line_width_granularity = 0.1;
290
291 caps->max_line_width =
292 caps->max_line_width_aa = 10.0;
293
294 caps->max_point_size =
295 caps->max_point_size_aa = 64.0;
296
297 caps->max_texture_anisotropy = (eng3d->oclass >= NV40_3D_CLASS) ? 16.0 : 8.0;
298 caps->max_texture_lod_bias = 15.0;
299 }
300
301 static bool
302 nv30_screen_is_format_supported(struct pipe_screen *pscreen,
303 enum pipe_format format,
304 enum pipe_texture_target target,
305 unsigned sample_count,
306 unsigned storage_sample_count,
307 unsigned bindings)
308 {
309 if (sample_count > nv30_screen(pscreen)->max_sample_count)
310 return false;
311
312 if (!(0x00000017 & (1 << sample_count)))
313 return false;
314
315 if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
316 return false;
317
318 /* No way to render to a swizzled 3d texture. We don't necessarily know if
319 * it's swizzled or not here, but we have to assume anyways.
320 */
321 if (target == PIPE_TEXTURE_3D && (bindings & PIPE_BIND_RENDER_TARGET))
322 return false;
323
324 /* shared is always supported */
325 bindings &= ~PIPE_BIND_SHARED;
326
327 if (bindings & PIPE_BIND_INDEX_BUFFER) {
328 if (format != PIPE_FORMAT_R8_UINT &&
329 format != PIPE_FORMAT_R16_UINT &&
330 format != PIPE_FORMAT_R32_UINT)
331 return false;
332 bindings &= ~PIPE_BIND_INDEX_BUFFER;
333 }
334
335 return (nv30_format_info(pscreen, format)->bindings & bindings) == bindings;
336 }
337
338 static const nir_shader_compiler_options nv30_base_compiler_options = {
339 .fuse_ffma32 = true,
340 .fuse_ffma64 = true,
341 .lower_bitops = true,
342 .lower_extract_byte = true,
343 .lower_extract_word = true,
344 .lower_fdiv = true,
345 .lower_fsat = true,
346 .lower_insert_byte = true,
347 .lower_insert_word = true,
348 .lower_fdph = true,
349 .lower_flrp32 = true,
350 .lower_flrp64 = true,
351 .lower_fmod = true,
352 .lower_fpow = true, /* In hardware as of nv40 FS */
353 .lower_uniforms_to_ubo = true,
354 .force_indirect_unrolling = nir_var_all,
355 .force_indirect_unrolling_sampler = true,
356 .max_unroll_iterations = 32,
357 .no_integers = true,
358 };
359
360 static void
361 nv30_screen_fence_emit(struct pipe_context *pcontext, uint32_t *sequence,
362 struct nouveau_bo *wait)
363 {
364 struct nv30_context *nv30 = nv30_context(pcontext);
365 struct nv30_screen *screen = nv30->screen;
366 struct nouveau_pushbuf *push = nv30->base.pushbuf;
367 struct nouveau_pushbuf_refn ref = { wait, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR };
368
369 *sequence = ++screen->base.fence.sequence;
370
371 assert(PUSH_AVAIL(push) + push->rsvd_kick >= 3);
372 PUSH_DATA (push, NV30_3D_FENCE_OFFSET |
373 (2 /* size */ << 18) | (7 /* subchan */ << 13));
374 PUSH_DATA (push, 0);
375 PUSH_DATA (push, *sequence);
376
377 nouveau_pushbuf_refn(push, &ref, 1);
378 }
379
380 static uint32_t
381 nv30_screen_fence_update(struct pipe_screen *pscreen)
382 {
383 struct nv30_screen *screen = nv30_screen(pscreen);
384 struct nv04_notify *fence = screen->fence->data;
385 return *(uint32_t *)((char *)screen->notify->map + fence->offset);
386 }
387
388 static void
389 nv30_screen_destroy(struct pipe_screen *pscreen)
390 {
391 struct nv30_screen *screen = nv30_screen(pscreen);
392
393 if (!screen->base.initialized)
394 return;
395
396 nouveau_bo_ref(NULL, &screen->notify);
397
398 nouveau_heap_destroy(&screen->query_heap);
399 nouveau_heap_destroy(&screen->vp_exec_heap);
400 nouveau_heap_destroy(&screen->vp_data_heap);
401
402 nouveau_object_del(&screen->query);
403 nouveau_object_del(&screen->fence);
404 nouveau_object_del(&screen->ntfy);
405
406 nouveau_object_del(&screen->sifm);
407 nouveau_object_del(&screen->swzsurf);
408 nouveau_object_del(&screen->surf2d);
409 nouveau_object_del(&screen->m2mf);
410 nouveau_object_del(&screen->eng3d);
411 nouveau_object_del(&screen->null);
412
413 nouveau_screen_fini(&screen->base);
414 FREE(screen);
415 }
416
417 #define FAIL_SCREEN_INIT(str, err) \
418 do { \
419 NOUVEAU_ERR(str, err); \
420 screen->base.base.context_create = NULL; \
421 return &screen->base; \
422 } while(0)
423
424 struct nouveau_screen *
425 nv30_screen_create(struct nouveau_device *dev)
426 {
427 struct nv30_screen *screen;
428 struct pipe_screen *pscreen;
429 struct nouveau_pushbuf *push;
430 struct nv04_fifo *fifo;
431 unsigned oclass = 0;
432 int ret, i;
433
434 switch (dev->chipset & 0xf0) {
435 case 0x30:
436 if (RANKINE_0397_CHIPSET & (1 << (dev->chipset & 0x0f)))
437 oclass = NV30_3D_CLASS;
438 else
439 if (RANKINE_0697_CHIPSET & (1 << (dev->chipset & 0x0f)))
440 oclass = NV34_3D_CLASS;
441 else
442 if (RANKINE_0497_CHIPSET & (1 << (dev->chipset & 0x0f)))
443 oclass = NV35_3D_CLASS;
444 break;
445 case 0x40:
446 if (CURIE_4097_CHIPSET & (1 << (dev->chipset & 0x0f)))
447 oclass = NV40_3D_CLASS;
448 else
449 if (CURIE_4497_CHIPSET & (1 << (dev->chipset & 0x0f)))
450 oclass = NV44_3D_CLASS;
451 break;
452 case 0x60:
453 if (CURIE_4497_CHIPSET6X & (1 << (dev->chipset & 0x0f)))
454 oclass = NV44_3D_CLASS;
455 break;
456 default:
457 break;
458 }
459
460 if (!oclass) {
461 NOUVEAU_ERR("unknown 3d class for 0x%02x\n", dev->chipset);
462 return NULL;
463 }
464
465 screen = CALLOC_STRUCT(nv30_screen);
466 if (!screen)
467 return NULL;
468
469 pscreen = &screen->base.base;
470 pscreen->destroy = nv30_screen_destroy;
471
472 /*
473 * Some modern apps try to use msaa without keeping in mind the
474 * restrictions on videomem of older cards. Resulting in dmesg saying:
475 * [ 1197.850642] nouveau E[soffice.bin[3785]] fail ttm_validate
476 * [ 1197.850648] nouveau E[soffice.bin[3785]] validating bo list
477 * [ 1197.850654] nouveau E[soffice.bin[3785]] validate: -12
478 *
479 * Because we are running out of video memory, after which the program
480 * using the msaa visual freezes, and eventually the entire system freezes.
481 *
482 * To work around this we do not allow msaa visauls by default and allow
483 * the user to override this via NV30_MAX_MSAA.
484 */
485 screen->max_sample_count = debug_get_num_option("NV30_MAX_MSAA", 0);
486 if (screen->max_sample_count > 4)
487 screen->max_sample_count = 4;
488
489 pscreen->context_create = nv30_context_create;
490 pscreen->is_format_supported = nv30_screen_is_format_supported;
491
492 pscreen->nir_options[MESA_SHADER_VERTEX] = &nv30_base_compiler_options;
493 pscreen->nir_options[MESA_SHADER_FRAGMENT] = &screen->fs_compiler_options;
494
495 nv30_resource_screen_init(pscreen);
496 nouveau_screen_init_vdec(&screen->base);
497
498 screen->base.fence.emit = nv30_screen_fence_emit;
499 screen->base.fence.update = nv30_screen_fence_update;
500
501 ret = nouveau_screen_init(&screen->base, dev);
502 if (ret)
503 FAIL_SCREEN_INIT("nv30_screen_init failed: %d\n", ret);
504
505 screen->base.vidmem_bindings |= PIPE_BIND_VERTEX_BUFFER;
506 screen->base.sysmem_bindings |= PIPE_BIND_VERTEX_BUFFER;
507 if (oclass == NV40_3D_CLASS) {
508 screen->base.vidmem_bindings |= PIPE_BIND_INDEX_BUFFER;
509 screen->base.sysmem_bindings |= PIPE_BIND_INDEX_BUFFER;
510 }
511
512 screen->fs_compiler_options = nv30_base_compiler_options;
513 screen->fs_compiler_options.lower_fsat = false;
514 if (oclass >= NV40_3D_CLASS)
515 screen->fs_compiler_options.lower_fpow = false;
516
517 fifo = screen->base.channel->data;
518 push = screen->base.pushbuf;
519 push->rsvd_kick = 16;
520
521 ret = nouveau_object_new(screen->base.channel, 0x00000000, NV01_NULL_CLASS,
522 NULL, 0, &screen->null);
523 if (ret)
524 FAIL_SCREEN_INIT("error allocating null object: %d\n", ret);
525
526 /* DMA_FENCE refuses to accept DMA objects with "adjust" filled in,
527 * this means that the address pointed at by the DMA object must
528 * be 4KiB aligned, which means this object needs to be the first
529 * one allocated on the channel.
530 */
531 ret = nouveau_object_new(screen->base.channel, 0xbeef1e00,
532 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
533 .length = 32 }, sizeof(struct nv04_notify),
534 &screen->fence);
535 if (ret)
536 FAIL_SCREEN_INIT("error allocating fence notifier: %d\n", ret);
537
538 /* DMA_NOTIFY object, we don't actually use this but M2MF fails without */
539 ret = nouveau_object_new(screen->base.channel, 0xbeef0301,
540 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
541 .length = 32 }, sizeof(struct nv04_notify),
542 &screen->ntfy);
543 if (ret)
544 FAIL_SCREEN_INIT("error allocating sync notifier: %d\n", ret);
545
546 /* DMA_QUERY, used to implement occlusion queries, we attempt to allocate
547 * the remainder of the "notifier block" assigned by the kernel for
548 * use as query objects
549 */
550 ret = nouveau_object_new(screen->base.channel, 0xbeef0351,
551 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
552 .length = 4096 - 128 }, sizeof(struct nv04_notify),
553 &screen->query);
554 if (ret)
555 FAIL_SCREEN_INIT("error allocating query notifier: %d\n", ret);
556
557 ret = nouveau_heap_init(&screen->query_heap, 0, 4096 - 128);
558 if (ret)
559 FAIL_SCREEN_INIT("error creating query heap: %d\n", ret);
560
561 list_inithead(&screen->queries);
562
563 /* Vertex program resources (code/data), currently 6 of the constant
564 * slots are reserved to implement user clipping planes
565 */
566 if (oclass < NV40_3D_CLASS) {
567 nouveau_heap_init(&screen->vp_exec_heap, 0, 256);
568 nouveau_heap_init(&screen->vp_data_heap, 6, 256 - 6);
569 } else {
570 nouveau_heap_init(&screen->vp_exec_heap, 0, 512);
571 nouveau_heap_init(&screen->vp_data_heap, 6, 468 - 6);
572 }
573
574 ret = nouveau_bo_wrap(screen->base.device, fifo->base.notify, &screen->notify);
575 if (ret == 0)
576 ret = BO_MAP(&screen->base, screen->notify, 0, screen->base.client);
577 if (ret)
578 FAIL_SCREEN_INIT("error mapping notifier memory: %d\n", ret);
579
580 ret = nouveau_object_new(screen->base.channel, 0xbeef3097, oclass,
581 NULL, 0, &screen->eng3d);
582 if (ret)
583 FAIL_SCREEN_INIT("error allocating 3d object: %d\n", ret);
584
585 nv30_init_shader_caps(screen);
586 nv30_init_screen_caps(screen);
587
588 BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
589 PUSH_DATA (push, screen->eng3d->handle);
590 BEGIN_NV04(push, NV30_3D(DMA_NOTIFY), 13);
591 PUSH_DATA (push, screen->ntfy->handle);
592 PUSH_DATA (push, fifo->vram); /* TEXTURE0 */
593 PUSH_DATA (push, fifo->gart); /* TEXTURE1 */
594 PUSH_DATA (push, fifo->vram); /* COLOR1 */
595 PUSH_DATA (push, screen->null->handle); /* UNK190 */
596 PUSH_DATA (push, fifo->vram); /* COLOR0 */
597 PUSH_DATA (push, fifo->vram); /* ZETA */
598 PUSH_DATA (push, fifo->vram); /* VTXBUF0 */
599 PUSH_DATA (push, fifo->gart); /* VTXBUF1 */
600 PUSH_DATA (push, screen->fence->handle); /* FENCE */
601 PUSH_DATA (push, screen->query->handle); /* QUERY - intr 0x80 if nullobj */
602 PUSH_DATA (push, screen->null->handle); /* UNK1AC */
603 PUSH_DATA (push, screen->null->handle); /* UNK1B0 */
604 if (screen->eng3d->oclass < NV40_3D_CLASS) {
605 BEGIN_NV04(push, SUBC_3D(0x03b0), 1);
606 PUSH_DATA (push, 0x00100000);
607 BEGIN_NV04(push, SUBC_3D(0x1d80), 1);
608 PUSH_DATA (push, 3);
609
610 BEGIN_NV04(push, SUBC_3D(0x1e98), 1);
611 PUSH_DATA (push, 0);
612 BEGIN_NV04(push, SUBC_3D(0x17e0), 3);
613 PUSH_DATA (push, fui(0.0));
614 PUSH_DATA (push, fui(0.0));
615 PUSH_DATA (push, fui(1.0));
616 BEGIN_NV04(push, SUBC_3D(0x1f80), 16);
617 for (i = 0; i < 16; i++)
618 PUSH_DATA (push, (i == 8) ? 0x0000ffff : 0);
619
620 BEGIN_NV04(push, NV30_3D(RC_ENABLE), 1);
621 PUSH_DATA (push, 0);
622 } else {
623 BEGIN_NV04(push, NV40_3D(DMA_COLOR2), 2);
624 PUSH_DATA (push, fifo->vram);
625 PUSH_DATA (push, fifo->vram); /* COLOR3 */
626
627 BEGIN_NV04(push, SUBC_3D(0x1450), 1);
628 PUSH_DATA (push, 0x00000004);
629
630 BEGIN_NV04(push, SUBC_3D(0x1ea4), 3); /* ZCULL */
631 PUSH_DATA (push, 0x00000010);
632 PUSH_DATA (push, 0x01000100);
633 PUSH_DATA (push, 0xff800006);
634
635 /* vtxprog output routing */
636 BEGIN_NV04(push, SUBC_3D(0x1fc4), 1);
637 PUSH_DATA (push, 0x06144321);
638 BEGIN_NV04(push, SUBC_3D(0x1fc8), 2);
639 PUSH_DATA (push, 0xedcba987);
640 PUSH_DATA (push, 0x0000006f);
641 BEGIN_NV04(push, SUBC_3D(0x1fd0), 1);
642 PUSH_DATA (push, 0x00171615);
643 BEGIN_NV04(push, SUBC_3D(0x1fd4), 1);
644 PUSH_DATA (push, 0x001b1a19);
645
646 BEGIN_NV04(push, SUBC_3D(0x1ef8), 1);
647 PUSH_DATA (push, 0x0020ffff);
648 BEGIN_NV04(push, SUBC_3D(0x1d64), 1);
649 PUSH_DATA (push, 0x01d300d4);
650
651 BEGIN_NV04(push, NV40_3D(MIPMAP_ROUNDING), 1);
652 PUSH_DATA (push, NV40_3D_MIPMAP_ROUNDING_MODE_DOWN);
653 }
654
655 ret = nouveau_object_new(screen->base.channel, 0xbeef3901, NV03_M2MF_CLASS,
656 NULL, 0, &screen->m2mf);
657 if (ret)
658 FAIL_SCREEN_INIT("error allocating m2mf object: %d\n", ret);
659
660 BEGIN_NV04(push, NV01_SUBC(M2MF, OBJECT), 1);
661 PUSH_DATA (push, screen->m2mf->handle);
662 BEGIN_NV04(push, NV03_M2MF(DMA_NOTIFY), 1);
663 PUSH_DATA (push, screen->ntfy->handle);
664
665 ret = nouveau_object_new(screen->base.channel, 0xbeef6201,
666 NV10_SURFACE_2D_CLASS, NULL, 0, &screen->surf2d);
667 if (ret)
668 FAIL_SCREEN_INIT("error allocating surf2d object: %d\n", ret);
669
670 BEGIN_NV04(push, NV01_SUBC(SF2D, OBJECT), 1);
671 PUSH_DATA (push, screen->surf2d->handle);
672 BEGIN_NV04(push, NV04_SF2D(DMA_NOTIFY), 1);
673 PUSH_DATA (push, screen->ntfy->handle);
674
675 if (dev->chipset < 0x40)
676 oclass = NV30_SURFACE_SWZ_CLASS;
677 else
678 oclass = NV40_SURFACE_SWZ_CLASS;
679
680 ret = nouveau_object_new(screen->base.channel, 0xbeef5201, oclass,
681 NULL, 0, &screen->swzsurf);
682 if (ret)
683 FAIL_SCREEN_INIT("error allocating swizzled surface object: %d\n", ret);
684
685 BEGIN_NV04(push, NV01_SUBC(SSWZ, OBJECT), 1);
686 PUSH_DATA (push, screen->swzsurf->handle);
687 BEGIN_NV04(push, NV04_SSWZ(DMA_NOTIFY), 1);
688 PUSH_DATA (push, screen->ntfy->handle);
689
690 if (dev->chipset < 0x40)
691 oclass = NV30_SIFM_CLASS;
692 else
693 oclass = NV40_SIFM_CLASS;
694
695 ret = nouveau_object_new(screen->base.channel, 0xbeef7701, oclass,
696 NULL, 0, &screen->sifm);
697 if (ret)
698 FAIL_SCREEN_INIT("error allocating scaled image object: %d\n", ret);
699
700 BEGIN_NV04(push, NV01_SUBC(SIFM, OBJECT), 1);
701 PUSH_DATA (push, screen->sifm->handle);
702 BEGIN_NV04(push, NV03_SIFM(DMA_NOTIFY), 1);
703 PUSH_DATA (push, screen->ntfy->handle);
704 BEGIN_NV04(push, NV05_SIFM(COLOR_CONVERSION), 1);
705 PUSH_DATA (push, NV05_SIFM_COLOR_CONVERSION_TRUNCATE);
706 PUSH_KICK (push);
707
708 return &screen->base;
709 }