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 .lower_vector_cmp = true,
355 .force_indirect_unrolling = nir_var_all,
356 .force_indirect_unrolling_sampler = true,
357 .max_unroll_iterations = 32,
358 .no_integers = true,
359 };
360
361 static void
362 nv30_screen_fence_emit(struct pipe_context *pcontext, uint32_t *sequence,
363 struct nouveau_bo *wait)
364 {
365 struct nv30_context *nv30 = nv30_context(pcontext);
366 struct nv30_screen *screen = nv30->screen;
367 struct nouveau_pushbuf *push = nv30->base.pushbuf;
368 struct nouveau_pushbuf_refn ref = { wait, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR };
369
370 *sequence = ++screen->base.fence.sequence;
371
372 assert(PUSH_AVAIL(push) + push->rsvd_kick >= 3);
373 PUSH_DATA (push, NV30_3D_FENCE_OFFSET |
374 (2 /* size */ << 18) | (7 /* subchan */ << 13));
375 PUSH_DATA (push, 0);
376 PUSH_DATA (push, *sequence);
377
378 nouveau_pushbuf_refn(push, &ref, 1);
379 }
380
381 static uint32_t
382 nv30_screen_fence_update(struct pipe_screen *pscreen)
383 {
384 struct nv30_screen *screen = nv30_screen(pscreen);
385 struct nv04_notify *fence = screen->fence->data;
386 return *(uint32_t *)((char *)screen->notify->map + fence->offset);
387 }
388
389 static void
390 nv30_screen_destroy(struct pipe_screen *pscreen)
391 {
392 struct nv30_screen *screen = nv30_screen(pscreen);
393
394 if (!screen->base.initialized)
395 return;
396
397 nouveau_bo_ref(NULL, &screen->notify);
398
399 nouveau_heap_destroy(&screen->query_heap);
400 nouveau_heap_destroy(&screen->vp_exec_heap);
401 nouveau_heap_destroy(&screen->vp_data_heap);
402
403 nouveau_object_del(&screen->query);
404 nouveau_object_del(&screen->fence);
405 nouveau_object_del(&screen->ntfy);
406
407 nouveau_object_del(&screen->sifm);
408 nouveau_object_del(&screen->swzsurf);
409 nouveau_object_del(&screen->surf2d);
410 nouveau_object_del(&screen->m2mf);
411 nouveau_object_del(&screen->eng3d);
412 nouveau_object_del(&screen->null);
413
414 nouveau_screen_fini(&screen->base);
415 FREE(screen);
416 }
417
418 #define FAIL_SCREEN_INIT(str, err) \
419 do { \
420 NOUVEAU_ERR(str, err); \
421 screen->base.base.context_create = NULL; \
422 return &screen->base; \
423 } while(0)
424
425 struct nouveau_screen *
426 nv30_screen_create(struct nouveau_device *dev)
427 {
428 struct nv30_screen *screen;
429 struct pipe_screen *pscreen;
430 struct nouveau_pushbuf *push;
431 struct nv04_fifo *fifo;
432 unsigned oclass = 0;
433 int ret, i;
434
435 switch (dev->chipset & 0xf0) {
436 case 0x30:
437 if (RANKINE_0397_CHIPSET & (1 << (dev->chipset & 0x0f)))
438 oclass = NV30_3D_CLASS;
439 else
440 if (RANKINE_0697_CHIPSET & (1 << (dev->chipset & 0x0f)))
441 oclass = NV34_3D_CLASS;
442 else
443 if (RANKINE_0497_CHIPSET & (1 << (dev->chipset & 0x0f)))
444 oclass = NV35_3D_CLASS;
445 break;
446 case 0x40:
447 if (CURIE_4097_CHIPSET & (1 << (dev->chipset & 0x0f)))
448 oclass = NV40_3D_CLASS;
449 else
450 if (CURIE_4497_CHIPSET & (1 << (dev->chipset & 0x0f)))
451 oclass = NV44_3D_CLASS;
452 break;
453 case 0x60:
454 if (CURIE_4497_CHIPSET6X & (1 << (dev->chipset & 0x0f)))
455 oclass = NV44_3D_CLASS;
456 break;
457 default:
458 break;
459 }
460
461 if (!oclass) {
462 NOUVEAU_ERR("unknown 3d class for 0x%02x\n", dev->chipset);
463 return NULL;
464 }
465
466 screen = CALLOC_STRUCT(nv30_screen);
467 if (!screen)
468 return NULL;
469
470 pscreen = &screen->base.base;
471 pscreen->destroy = nv30_screen_destroy;
472
473 /*
474 * Some modern apps try to use msaa without keeping in mind the
475 * restrictions on videomem of older cards. Resulting in dmesg saying:
476 * [ 1197.850642] nouveau E[soffice.bin[3785]] fail ttm_validate
477 * [ 1197.850648] nouveau E[soffice.bin[3785]] validating bo list
478 * [ 1197.850654] nouveau E[soffice.bin[3785]] validate: -12
479 *
480 * Because we are running out of video memory, after which the program
481 * using the msaa visual freezes, and eventually the entire system freezes.
482 *
483 * To work around this we do not allow msaa visauls by default and allow
484 * the user to override this via NV30_MAX_MSAA.
485 */
486 screen->max_sample_count = debug_get_num_option("NV30_MAX_MSAA", 0);
487 if (screen->max_sample_count > 4)
488 screen->max_sample_count = 4;
489
490 pscreen->context_create = nv30_context_create;
491 pscreen->is_format_supported = nv30_screen_is_format_supported;
492
493 pscreen->nir_options[MESA_SHADER_VERTEX] = &nv30_base_compiler_options;
494 pscreen->nir_options[MESA_SHADER_FRAGMENT] = &screen->fs_compiler_options;
495
496 nv30_resource_screen_init(pscreen);
497 nouveau_screen_init_vdec(&screen->base);
498
499 screen->base.fence.emit = nv30_screen_fence_emit;
500 screen->base.fence.update = nv30_screen_fence_update;
501
502 ret = nouveau_screen_init(&screen->base, dev);
503 if (ret)
504 FAIL_SCREEN_INIT("nv30_screen_init failed: %d\n", ret);
505
506 screen->base.vidmem_bindings |= PIPE_BIND_VERTEX_BUFFER;
507 screen->base.sysmem_bindings |= PIPE_BIND_VERTEX_BUFFER;
508 if (oclass == NV40_3D_CLASS) {
509 screen->base.vidmem_bindings |= PIPE_BIND_INDEX_BUFFER;
510 screen->base.sysmem_bindings |= PIPE_BIND_INDEX_BUFFER;
511 }
512
513 screen->fs_compiler_options = nv30_base_compiler_options;
514 screen->fs_compiler_options.lower_fsat = false;
515 if (oclass >= NV40_3D_CLASS)
516 screen->fs_compiler_options.lower_fpow = false;
517
518 fifo = screen->base.channel->data;
519 push = screen->base.pushbuf;
520 push->rsvd_kick = 16;
521
522 ret = nouveau_object_new(screen->base.channel, 0x00000000, NV01_NULL_CLASS,
523 NULL, 0, &screen->null);
524 if (ret)
525 FAIL_SCREEN_INIT("error allocating null object: %d\n", ret);
526
527 /* DMA_FENCE refuses to accept DMA objects with "adjust" filled in,
528 * this means that the address pointed at by the DMA object must
529 * be 4KiB aligned, which means this object needs to be the first
530 * one allocated on the channel.
531 */
532 ret = nouveau_object_new(screen->base.channel, 0xbeef1e00,
533 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
534 .length = 32 }, sizeof(struct nv04_notify),
535 &screen->fence);
536 if (ret)
537 FAIL_SCREEN_INIT("error allocating fence notifier: %d\n", ret);
538
539 /* DMA_NOTIFY object, we don't actually use this but M2MF fails without */
540 ret = nouveau_object_new(screen->base.channel, 0xbeef0301,
541 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
542 .length = 32 }, sizeof(struct nv04_notify),
543 &screen->ntfy);
544 if (ret)
545 FAIL_SCREEN_INIT("error allocating sync notifier: %d\n", ret);
546
547 /* DMA_QUERY, used to implement occlusion queries, we attempt to allocate
548 * the remainder of the "notifier block" assigned by the kernel for
549 * use as query objects
550 */
551 ret = nouveau_object_new(screen->base.channel, 0xbeef0351,
552 NOUVEAU_NOTIFIER_CLASS, &(struct nv04_notify) {
553 .length = 4096 - 128 }, sizeof(struct nv04_notify),
554 &screen->query);
555 if (ret)
556 FAIL_SCREEN_INIT("error allocating query notifier: %d\n", ret);
557
558 ret = nouveau_heap_init(&screen->query_heap, 0, 4096 - 128);
559 if (ret)
560 FAIL_SCREEN_INIT("error creating query heap: %d\n", ret);
561
562 list_inithead(&screen->queries);
563
564 /* Vertex program resources (code/data), currently 6 of the constant
565 * slots are reserved to implement user clipping planes
566 */
567 if (oclass < NV40_3D_CLASS) {
568 nouveau_heap_init(&screen->vp_exec_heap, 0, 256);
569 nouveau_heap_init(&screen->vp_data_heap, 6, 256 - 6);
570 } else {
571 nouveau_heap_init(&screen->vp_exec_heap, 0, 512);
572 nouveau_heap_init(&screen->vp_data_heap, 6, 468 - 6);
573 }
574
575 ret = nouveau_bo_wrap(screen->base.device, fifo->base.notify, &screen->notify);
576 if (ret == 0)
577 ret = BO_MAP(&screen->base, screen->notify, 0, screen->base.client);
578 if (ret)
579 FAIL_SCREEN_INIT("error mapping notifier memory: %d\n", ret);
580
581 ret = nouveau_object_new(screen->base.channel, 0xbeef3097, oclass,
582 NULL, 0, &screen->eng3d);
583 if (ret)
584 FAIL_SCREEN_INIT("error allocating 3d object: %d\n", ret);
585
586 nv30_init_shader_caps(screen);
587 nv30_init_screen_caps(screen);
588
589 BEGIN_NV04(push, NV01_SUBC(3D, OBJECT), 1);
590 PUSH_DATA (push, screen->eng3d->handle);
591 BEGIN_NV04(push, NV30_3D(DMA_NOTIFY), 13);
592 PUSH_DATA (push, screen->ntfy->handle);
593 PUSH_DATA (push, fifo->vram); /* TEXTURE0 */
594 PUSH_DATA (push, fifo->gart); /* TEXTURE1 */
595 PUSH_DATA (push, fifo->vram); /* COLOR1 */
596 PUSH_DATA (push, screen->null->handle); /* UNK190 */
597 PUSH_DATA (push, fifo->vram); /* COLOR0 */
598 PUSH_DATA (push, fifo->vram); /* ZETA */
599 PUSH_DATA (push, fifo->vram); /* VTXBUF0 */
600 PUSH_DATA (push, fifo->gart); /* VTXBUF1 */
601 PUSH_DATA (push, screen->fence->handle); /* FENCE */
602 PUSH_DATA (push, screen->query->handle); /* QUERY - intr 0x80 if nullobj */
603 PUSH_DATA (push, screen->null->handle); /* UNK1AC */
604 PUSH_DATA (push, screen->null->handle); /* UNK1B0 */
605 if (screen->eng3d->oclass < NV40_3D_CLASS) {
606 BEGIN_NV04(push, SUBC_3D(0x03b0), 1);
607 PUSH_DATA (push, 0x00100000);
608 BEGIN_NV04(push, SUBC_3D(0x1d80), 1);
609 PUSH_DATA (push, 3);
610
611 BEGIN_NV04(push, SUBC_3D(0x1e98), 1);
612 PUSH_DATA (push, 0);
613 BEGIN_NV04(push, SUBC_3D(0x17e0), 3);
614 PUSH_DATA (push, fui(0.0));
615 PUSH_DATA (push, fui(0.0));
616 PUSH_DATA (push, fui(1.0));
617 BEGIN_NV04(push, SUBC_3D(0x1f80), 16);
618 for (i = 0; i < 16; i++)
619 PUSH_DATA (push, (i == 8) ? 0x0000ffff : 0);
620
621 BEGIN_NV04(push, NV30_3D(RC_ENABLE), 1);
622 PUSH_DATA (push, 0);
623 } else {
624 BEGIN_NV04(push, NV40_3D(DMA_COLOR2), 2);
625 PUSH_DATA (push, fifo->vram);
626 PUSH_DATA (push, fifo->vram); /* COLOR3 */
627
628 BEGIN_NV04(push, SUBC_3D(0x1450), 1);
629 PUSH_DATA (push, 0x00000004);
630
631 BEGIN_NV04(push, SUBC_3D(0x1ea4), 3); /* ZCULL */
632 PUSH_DATA (push, 0x00000010);
633 PUSH_DATA (push, 0x01000100);
634 PUSH_DATA (push, 0xff800006);
635
636 /* vtxprog output routing */
637 BEGIN_NV04(push, SUBC_3D(0x1fc4), 1);
638 PUSH_DATA (push, 0x06144321);
639 BEGIN_NV04(push, SUBC_3D(0x1fc8), 2);
640 PUSH_DATA (push, 0xedcba987);
641 PUSH_DATA (push, 0x0000006f);
642 BEGIN_NV04(push, SUBC_3D(0x1fd0), 1);
643 PUSH_DATA (push, 0x00171615);
644 BEGIN_NV04(push, SUBC_3D(0x1fd4), 1);
645 PUSH_DATA (push, 0x001b1a19);
646
647 BEGIN_NV04(push, SUBC_3D(0x1ef8), 1);
648 PUSH_DATA (push, 0x0020ffff);
649 BEGIN_NV04(push, SUBC_3D(0x1d64), 1);
650 PUSH_DATA (push, 0x01d300d4);
651
652 BEGIN_NV04(push, NV40_3D(MIPMAP_ROUNDING), 1);
653 PUSH_DATA (push, NV40_3D_MIPMAP_ROUNDING_MODE_DOWN);
654 }
655
656 ret = nouveau_object_new(screen->base.channel, 0xbeef3901, NV03_M2MF_CLASS,
657 NULL, 0, &screen->m2mf);
658 if (ret)
659 FAIL_SCREEN_INIT("error allocating m2mf object: %d\n", ret);
660
661 BEGIN_NV04(push, NV01_SUBC(M2MF, OBJECT), 1);
662 PUSH_DATA (push, screen->m2mf->handle);
663 BEGIN_NV04(push, NV03_M2MF(DMA_NOTIFY), 1);
664 PUSH_DATA (push, screen->ntfy->handle);
665
666 ret = nouveau_object_new(screen->base.channel, 0xbeef6201,
667 NV10_SURFACE_2D_CLASS, NULL, 0, &screen->surf2d);
668 if (ret)
669 FAIL_SCREEN_INIT("error allocating surf2d object: %d\n", ret);
670
671 BEGIN_NV04(push, NV01_SUBC(SF2D, OBJECT), 1);
672 PUSH_DATA (push, screen->surf2d->handle);
673 BEGIN_NV04(push, NV04_SF2D(DMA_NOTIFY), 1);
674 PUSH_DATA (push, screen->ntfy->handle);
675
676 if (dev->chipset < 0x40)
677 oclass = NV30_SURFACE_SWZ_CLASS;
678 else
679 oclass = NV40_SURFACE_SWZ_CLASS;
680
681 ret = nouveau_object_new(screen->base.channel, 0xbeef5201, oclass,
682 NULL, 0, &screen->swzsurf);
683 if (ret)
684 FAIL_SCREEN_INIT("error allocating swizzled surface object: %d\n", ret);
685
686 BEGIN_NV04(push, NV01_SUBC(SSWZ, OBJECT), 1);
687 PUSH_DATA (push, screen->swzsurf->handle);
688 BEGIN_NV04(push, NV04_SSWZ(DMA_NOTIFY), 1);
689 PUSH_DATA (push, screen->ntfy->handle);
690
691 if (dev->chipset < 0x40)
692 oclass = NV30_SIFM_CLASS;
693 else
694 oclass = NV40_SIFM_CLASS;
695
696 ret = nouveau_object_new(screen->base.channel, 0xbeef7701, oclass,
697 NULL, 0, &screen->sifm);
698 if (ret)
699 FAIL_SCREEN_INIT("error allocating scaled image object: %d\n", ret);
700
701 BEGIN_NV04(push, NV01_SUBC(SIFM, OBJECT), 1);
702 PUSH_DATA (push, screen->sifm->handle);
703 BEGIN_NV04(push, NV03_SIFM(DMA_NOTIFY), 1);
704 PUSH_DATA (push, screen->ntfy->handle);
705 BEGIN_NV04(push, NV05_SIFM(COLOR_CONVERSION), 1);
706 PUSH_DATA (push, NV05_SIFM_COLOR_CONVERSION_TRUNCATE);
707 PUSH_KICK (push);
708
709 return &screen->base;
710 }