| 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 <errno.h> |
| 24 |
#include <xf86drm.h> |
| 25 |
#include "drm-uapi/nouveau_drm.h" |
| 26 |
#include "util/format/u_format.h" |
| 27 |
#include "util/format/u_format_s3tc.h" |
| 28 |
#include "util/u_screen.h" |
| 29 |
#include "pipe/p_screen.h" |
| 30 |
|
| 31 |
#include "nv50_ir_driver.h" |
| 32 |
|
| 33 |
#include "nv50/nv50_context.h" |
| 34 |
#include "nv50/nv50_screen.h" |
| 35 |
|
| 36 |
#include "nouveau_vp3_video.h" |
| 37 |
|
| 38 |
#include "nv_object.xml.h" |
| 39 |
|
| 40 |
/* affected by LOCAL_WARPS_LOG_ALLOC / LOCAL_WARPS_NO_CLAMP */ |
| 41 |
#define LOCAL_WARPS_ALLOC 32 |
| 42 |
/* affected by STACK_WARPS_LOG_ALLOC / STACK_WARPS_NO_CLAMP */ |
| 43 |
#define STACK_WARPS_ALLOC 32 |
| 44 |
|
| 45 |
#define THREADS_IN_WARP 32 |
| 46 |
|
| 47 |
static bool |
| 48 |
nv50_screen_is_format_supported(struct pipe_screen *pscreen, |
| 49 |
enum pipe_format format, |
| 50 |
enum pipe_texture_target target, |
| 51 |
unsigned sample_count, |
| 52 |
unsigned storage_sample_count, |
| 53 |
unsigned bindings) |
| 54 |
{ |
| 55 |
if (sample_count > 8) |
| 56 |
return false; |
| 57 |
if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */ |
| 58 |
return false; |
| 59 |
if (sample_count == 8 && util_format_get_blocksizebits(format) >= 128) |
| 60 |
return false; |
| 61 |
|
| 62 |
if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) |
| 63 |
return false; |
| 64 |
|
| 65 |
/* Short-circuit the rest of the logic -- this is used by the gallium frontend |
| 66 |
* to determine valid MS levels in a no-attachments scenario. |
| 67 |
*/ |
| 68 |
if (format == PIPE_FORMAT_NONE && bindings & PIPE_BIND_RENDER_TARGET) |
| 69 |
return true; |
| 70 |
|
| 71 |
switch (format) { |
| 72 |
case PIPE_FORMAT_Z16_UNORM: |
| 73 |
if (nv50_screen(pscreen)->tesla->oclass < NVA0_3D_CLASS) |
| 74 |
return false; |
| 75 |
break; |
| 76 |
default: |
| 77 |
break; |
| 78 |
} |
| 79 |
|
| 80 |
if (bindings & PIPE_BIND_LINEAR) |
| 81 |
if (util_format_is_depth_or_stencil(format) || |
| 82 |
(target != PIPE_TEXTURE_1D && |
| 83 |
target != PIPE_TEXTURE_2D && |
| 84 |
target != PIPE_TEXTURE_RECT) || |
| 85 |
sample_count > 1) |
| 86 |
return false; |
| 87 |
|
| 88 |
/* shared is always supported */ |
| 89 |
bindings &= ~(PIPE_BIND_LINEAR | |
| 90 |
PIPE_BIND_SHARED); |
| 91 |
|
| 92 |
if (bindings & PIPE_BIND_INDEX_BUFFER) { |
| 93 |
if (format != PIPE_FORMAT_R8_UINT && |
| 94 |
format != PIPE_FORMAT_R16_UINT && |
| 95 |
format != PIPE_FORMAT_R32_UINT) |
| 96 |
return false; |
| 97 |
bindings &= ~PIPE_BIND_INDEX_BUFFER; |
| 98 |
} |
| 99 |
|
| 100 |
return (( nv50_format_table[format].usage | |
| 101 |
nv50_vertex_format[format].usage) & bindings) == bindings; |
| 102 |
} |
| 103 |
|
| 104 |
static void |
| 105 |
nv50_init_shader_caps(struct nv50_screen *screen) |
| 106 |
{ |
| 107 |
for (unsigned i = 0; i <= MESA_SHADER_COMPUTE; i++) { |
| 108 |
struct pipe_shader_caps *caps = |
| 109 |
(struct pipe_shader_caps *)&screen->base.base.shader_caps[i]; |
| 110 |
|
| 111 |
if (i == MESA_SHADER_TESS_CTRL || i == MESA_SHADER_TESS_EVAL) |
| 112 |
continue; |
| 113 |
|
| 114 |
caps->max_instructions = |
| 115 |
caps->max_alu_instructions = |
| 116 |
caps->max_tex_instructions = |
| 117 |
caps->max_tex_indirections = 16384; |
| 118 |
caps->max_control_flow_depth = 4; |
| 119 |
caps->max_inputs = i == MESA_SHADER_VERTEX ? 32 : 15; |
| 120 |
caps->max_outputs = 16; |
| 121 |
caps->max_const_buffer0_size = 65536; |
| 122 |
caps->max_const_buffers = NV50_MAX_PIPE_CONSTBUFS; |
| 123 |
caps->indirect_temp_addr = true; |
| 124 |
caps->indirect_const_addr = true; |
| 125 |
caps->max_temps = screen->max_tls_space / ONE_TEMP_SIZE; |
| 126 |
caps->cont_supported = true; |
| 127 |
caps->tgsi_sqrt_supported = true; |
| 128 |
caps->integers = true; |
| 129 |
caps->max_texture_samplers = |
| 130 |
/* The chip could handle more sampler views than samplers */ |
| 131 |
caps->max_sampler_views = MIN2(16, PIPE_MAX_SAMPLERS); |
| 132 |
caps->max_shader_buffers = |
| 133 |
caps->max_shader_images = i == MESA_SHADER_COMPUTE ? NV50_MAX_GLOBALS - 1 : 0; |
| 134 |
caps->supported_irs = 1 << PIPE_SHADER_IR_NIR; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
nv50_init_compute_caps(struct nv50_screen *screen) |
| 140 |
{ |
| 141 |
struct nouveau_device *dev = screen->base.device; |
| 142 |
|
| 143 |
struct pipe_compute_caps *caps = |
| 144 |
(struct pipe_compute_caps *)&screen->base.base.compute_caps; |
| 145 |
|
| 146 |
caps->grid_dimension = 3; |
| 147 |
|
| 148 |
caps->max_grid_size[0] = |
| 149 |
caps->max_grid_size[1] = |
| 150 |
caps->max_grid_size[2] = 65535; |
| 151 |
|
| 152 |
caps->max_block_size[0] = 512; |
| 153 |
caps->max_block_size[1] = 512; |
| 154 |
caps->max_block_size[2] = 64; |
| 155 |
|
| 156 |
caps->max_threads_per_block = 512; |
| 157 |
|
| 158 |
caps->max_mem_alloc_size = |
| 159 |
caps->max_global_size = nouveau_device_get_global_mem_size(dev); /* g0-15[] */ |
| 160 |
caps->max_local_size = 16 << 10; /* s[] */ |
| 161 |
caps->subgroup_sizes = 32; |
| 162 |
caps->max_compute_units = screen->mp_count; |
| 163 |
caps->max_clock_frequency = 512; /* FIXME: arbitrary limit */ |
| 164 |
caps->address_bits = 32; |
| 165 |
} |
| 166 |
|
| 167 |
static void |
| 168 |
nv50_init_screen_caps(struct nv50_screen *screen) |
| 169 |
{ |
| 170 |
struct pipe_caps *caps = (struct pipe_caps *)&screen->base.base.caps; |
| 171 |
|
| 172 |
u_init_pipe_screen_caps(&screen->base.base, 1); |
| 173 |
|
| 174 |
const uint16_t class_3d = screen->base.class_3d; |
| 175 |
struct nouveau_device *dev = screen->base.device; |
| 176 |
|
| 177 |
/* Non-boolean caps */ |
| 178 |
caps->max_texture_2d_size = 8192; |
| 179 |
caps->max_texture_3d_levels = 12; |
| 180 |
caps->max_texture_cube_levels = 14; |
| 181 |
caps->max_texture_array_layers = 512; |
| 182 |
caps->min_texture_gather_offset = |
| 183 |
caps->min_texel_offset = -8; |
| 184 |
caps->max_texture_gather_offset = |
| 185 |
caps->max_texel_offset = 7; |
| 186 |
caps->max_texel_buffer_elements = 128 * 1024 * 1024; |
| 187 |
caps->glsl_feature_level = 330; |
| 188 |
caps->glsl_feature_level_compatibility = 330; |
| 189 |
caps->essl_feature_level = class_3d >= NVA3_3D_CLASS ? 310 : 300; |
| 190 |
caps->max_render_targets = 8; |
| 191 |
caps->max_dual_source_render_targets = 1; |
| 192 |
caps->max_combined_shader_output_resources = NV50_MAX_GLOBALS - 1; |
| 193 |
caps->viewport_subpixel_bits = |
| 194 |
caps->rasterizer_subpixel_bits = 8; |
| 195 |
caps->max_stream_output_buffers = 4; |
| 196 |
caps->max_stream_output_interleaved_components = 64; |
| 197 |
caps->max_stream_output_separate_components = 4; |
| 198 |
caps->max_geometry_output_vertices = |
| 199 |
caps->max_geometry_total_output_components = 1024; |
| 200 |
caps->max_vertex_streams = 1; |
| 201 |
caps->max_gs_invocations = 0; |
| 202 |
caps->max_shader_buffer_size = 1 << 27; |
| 203 |
caps->max_vertex_attrib_stride = 2048; |
| 204 |
caps->max_vertex_element_src_offset = 2047; |
| 205 |
caps->constant_buffer_offset_alignment = 256; |
| 206 |
caps->texture_buffer_offset_alignment = 16; /* 256 for binding as RT, but that's not possible in GL */ |
| 207 |
caps->shader_buffer_offset_alignment = 256; /* the access limit is aligned to 256 */ |
| 208 |
caps->min_map_buffer_alignment = NOUVEAU_MIN_BUFFER_MAP_ALIGN; |
| 209 |
caps->max_viewports = NV50_MAX_VIEWPORTS; |
| 210 |
caps->texture_border_color_quirk = PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50; |
| 211 |
caps->endianness = PIPE_ENDIAN_LITTLE; |
| 212 |
caps->max_texture_gather_components = (class_3d >= NVA3_3D_CLASS) ? 4 : 0; |
| 213 |
caps->max_window_rectangles = NV50_MAX_WINDOW_RECTANGLES; |
| 214 |
caps->max_texture_upload_memory_budget = 16 * 1024 * 1024; |
| 215 |
caps->max_varyings = 15; |
| 216 |
caps->max_vertex_buffers = 16; |
| 217 |
caps->gl_begin_end_buffer_size = 512 * 1024; /* TODO: Investigate tuning this */ |
| 218 |
|
| 219 |
caps->supported_prim_modes_with_restart = |
| 220 |
caps->supported_prim_modes = BITFIELD_MASK(MESA_PRIM_COUNT); |
| 221 |
|
| 222 |
/* supported caps */ |
| 223 |
caps->texture_mirror_clamp = true; |
| 224 |
caps->texture_mirror_clamp_to_edge = true; |
| 225 |
caps->texture_swizzle = true; |
| 226 |
caps->npot_textures = true; |
| 227 |
caps->mixed_framebuffer_sizes = true; |
| 228 |
caps->mixed_color_depth_bits = true; |
| 229 |
caps->anisotropic_filter = true; |
| 230 |
caps->texture_buffer_objects = true; |
| 231 |
caps->depth_clip_disable = true; |
| 232 |
caps->fragment_shader_texture_lod = true; |
| 233 |
caps->fragment_shader_derivatives = true; |
| 234 |
caps->fragment_color_clamped = true; |
| 235 |
caps->vertex_color_unclamped = true; |
| 236 |
caps->vertex_color_clamped = true; |
| 237 |
caps->query_timestamp = true; |
| 238 |
caps->query_time_elapsed = true; |
| 239 |
caps->occlusion_query = true; |
| 240 |
caps->blend_equation_separate = true; |
| 241 |
caps->indep_blend_enable = true; |
| 242 |
caps->fs_coord_origin_upper_left = true; |
| 243 |
caps->fs_coord_pixel_center_half_integer = true; |
| 244 |
caps->primitive_restart = true; |
| 245 |
caps->primitive_restart_fixed_index = true; |
| 246 |
caps->vs_instanceid = true; |
| 247 |
caps->vertex_element_instance_divisor = true; |
| 248 |
caps->conditional_render = true; |
| 249 |
caps->texture_barrier = true; |
| 250 |
caps->quads_follow_provoking_vertex_convention = true; |
| 251 |
caps->start_instance = true; |
| 252 |
caps->user_vertex_buffers = true; |
| 253 |
caps->texture_multisample = true; |
| 254 |
caps->fs_fine_derivative = true; |
| 255 |
caps->sampler_view_target = true; |
| 256 |
caps->conditional_render_inverted = true; |
| 257 |
caps->clip_halfz = true; |
| 258 |
caps->memobj = true; |
| 259 |
caps->polygon_offset_clamp = true; |
| 260 |
caps->query_pipeline_statistics = true; |
| 261 |
caps->texture_float_linear = true; |
| 262 |
caps->texture_half_float_linear = true; |
| 263 |
caps->depth_bounds_test = true; |
| 264 |
caps->texture_query_samples = true; |
| 265 |
caps->copy_between_compressed_and_plain_formats = true; |
| 266 |
caps->fs_face_is_integer_sysval = true; |
| 267 |
caps->invalidate_buffer = true; |
| 268 |
caps->string_marker = true; |
| 269 |
caps->cull_distance = true; |
| 270 |
caps->shader_array_components = true; |
| 271 |
caps->legacy_math_rules = true; |
| 272 |
caps->tgsi_tex_txf_lz = false; |
| 273 |
caps->shader_clock = true; |
| 274 |
caps->can_bind_const_buffer_as_vertex = true; |
| 275 |
caps->clear_scissored = true; |
| 276 |
caps->framebuffer_no_attachment = true; |
| 277 |
caps->compute = true; |
| 278 |
caps->query_memory_info = true; |
| 279 |
|
| 280 |
/* nvc0 has fixed function alpha test support, but nv50 doesn't. If we |
| 281 |
* don't have it, then the frontend will lower it for us. |
| 282 |
*/ |
| 283 |
caps->alpha_test = class_3d >= NVC0_3D_CLASS; |
| 284 |
|
| 285 |
caps->texture_transfer_modes = PIPE_TEXTURE_TRANSFER_BLIT; |
| 286 |
caps->seamless_cube_map = true; /* class_3d >= NVA0_3D_CLASS; */ |
| 287 |
/* supported on nva0+ */ |
| 288 |
caps->stream_output_pause_resume = class_3d >= NVA0_3D_CLASS; |
| 289 |
/* supported on nva3+ */ |
| 290 |
caps->cube_map_array = |
| 291 |
caps->indep_blend_func = |
| 292 |
caps->texture_query_lod = |
| 293 |
caps->sample_shading = |
| 294 |
caps->force_persample_interp = class_3d >= NVA3_3D_CLASS; |
| 295 |
|
| 296 |
caps->pci_group = dev->info.pci.domain; |
| 297 |
caps->pci_bus = dev->info.pci.bus; |
| 298 |
caps->pci_device = dev->info.pci.dev; |
| 299 |
caps->pci_function = dev->info.pci.func; |
| 300 |
|
| 301 |
caps->multisample_z_resolve = false; /* potentially supported on some hw */ |
| 302 |
caps->integer_multiply_32x16 = false; /* could be done */ |
| 303 |
caps->map_unsynchronized_thread_safe = false; /* when we fix MT stuff */ |
| 304 |
caps->nir_images_as_deref = false; |
| 305 |
caps->hardware_gl_select = false; |
| 306 |
|
| 307 |
caps->vendor_id = 0x10de; |
| 308 |
caps->device_id = dev->info.device_id; |
| 309 |
caps->video_memory = dev->vram_size >> 20; |
| 310 |
caps->uma = screen->base.is_uma; |
| 311 |
|
| 312 |
caps->min_line_width = |
| 313 |
caps->min_line_width_aa = |
| 314 |
caps->min_point_size = |
| 315 |
caps->min_point_size_aa = 1; |
| 316 |
caps->point_size_granularity = |
| 317 |
caps->line_width_granularity = 0.1; |
| 318 |
caps->max_line_width = |
| 319 |
caps->max_line_width_aa = 10.0f; |
| 320 |
caps->max_point_size = |
| 321 |
caps->max_point_size_aa = 64.0f; |
| 322 |
caps->max_texture_anisotropy = 16.0f; |
| 323 |
caps->max_texture_lod_bias = 15.0f; |
| 324 |
} |
| 325 |
|
| 326 |
static void |
| 327 |
nv50_screen_destroy(struct pipe_screen *pscreen) |
| 328 |
{ |
| 329 |
struct nv50_screen *screen = nv50_screen(pscreen); |
| 330 |
|
| 331 |
if (!screen->base.initialized) |
| 332 |
return; |
| 333 |
|
| 334 |
if (screen->blitter) |
| 335 |
nv50_blitter_destroy(screen); |
| 336 |
if (screen->pm.prog) { |
| 337 |
screen->pm.prog->code = NULL; /* hardcoded, don't FREE */ |
| 338 |
nv50_program_destroy(NULL, screen->pm.prog); |
| 339 |
FREE(screen->pm.prog); |
| 340 |
} |
| 341 |
|
| 342 |
nouveau_bo_ref(NULL, &screen->code); |
| 343 |
nouveau_bo_ref(NULL, &screen->tls_bo); |
| 344 |
nouveau_bo_ref(NULL, &screen->stack_bo); |
| 345 |
nouveau_bo_ref(NULL, &screen->txc); |
| 346 |
nouveau_bo_ref(NULL, &screen->uniforms); |
| 347 |
nouveau_bo_ref(NULL, &screen->fence.bo); |
| 348 |
|
| 349 |
nouveau_heap_destroy(&screen->vp_code_heap); |
| 350 |
nouveau_heap_destroy(&screen->gp_code_heap); |
| 351 |
nouveau_heap_destroy(&screen->fp_code_heap); |
| 352 |
|
| 353 |
FREE(screen->tic.entries); |
| 354 |
|
| 355 |
nouveau_object_del(&screen->tesla); |
| 356 |
nouveau_object_del(&screen->eng2d); |
| 357 |
nouveau_object_del(&screen->m2mf); |
| 358 |
nouveau_object_del(&screen->compute); |
| 359 |
nouveau_object_del(&screen->sync); |
| 360 |
|
| 361 |
nouveau_screen_fini(&screen->base); |
| 362 |
simple_mtx_destroy(&screen->state_lock); |
| 363 |
|
| 364 |
FREE(screen); |
| 365 |
} |
| 366 |
|
| 367 |
static void |
| 368 |
nv50_screen_fence_emit(struct pipe_context *pcontext, u32 *sequence, |
| 369 |
struct nouveau_bo *wait) |
| 370 |
{ |
| 371 |
struct nv50_context *nv50 = nv50_context(pcontext); |
| 372 |
struct nv50_screen *screen = nv50->screen; |
| 373 |
struct nouveau_pushbuf *push = nv50->base.pushbuf; |
| 374 |
struct nouveau_pushbuf_refn ref = { wait, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR }; |
| 375 |
|
| 376 |
/* we need to do it after possible flush in MARK_RING */ |
| 377 |
*sequence = ++screen->base.fence.sequence; |
| 378 |
|
| 379 |
assert(PUSH_AVAIL(push) + push->rsvd_kick >= 5); |
| 380 |
PUSH_DATA (push, NV50_FIFO_PKHDR(NV50_3D(QUERY_ADDRESS_HIGH), 4)); |
| 381 |
PUSH_DATAh(push, screen->fence.bo->offset); |
| 382 |
PUSH_DATA (push, screen->fence.bo->offset); |
| 383 |
PUSH_DATA (push, *sequence); |
| 384 |
PUSH_DATA (push, NV50_3D_QUERY_GET_MODE_WRITE_UNK0 | |
| 385 |
NV50_3D_QUERY_GET_UNK4 | |
| 386 |
NV50_3D_QUERY_GET_UNIT_CROP | |
| 387 |
NV50_3D_QUERY_GET_TYPE_QUERY | |
| 388 |
NV50_3D_QUERY_GET_QUERY_SELECT_ZERO | |
| 389 |
NV50_3D_QUERY_GET_SHORT); |
| 390 |
|
| 391 |
nouveau_pushbuf_refn(push, &ref, 1); |
| 392 |
} |
| 393 |
|
| 394 |
static u32 |
| 395 |
nv50_screen_fence_update(struct pipe_screen *pscreen) |
| 396 |
{ |
| 397 |
return nv50_screen(pscreen)->fence.map[0]; |
| 398 |
} |
| 399 |
|
| 400 |
static void |
| 401 |
nv50_screen_init_hwctx(struct nv50_screen *screen) |
| 402 |
{ |
| 403 |
struct nouveau_pushbuf *push = screen->base.pushbuf; |
| 404 |
struct nv04_fifo *fifo; |
| 405 |
unsigned i; |
| 406 |
|
| 407 |
fifo = (struct nv04_fifo *)screen->base.channel->data; |
| 408 |
|
| 409 |
BEGIN_NV04(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1); |
| 410 |
PUSH_DATA (push, screen->m2mf->handle); |
| 411 |
BEGIN_NV04(push, SUBC_M2MF(NV03_M2MF_DMA_NOTIFY), 3); |
| 412 |
PUSH_DATA (push, screen->sync->handle); |
| 413 |
PUSH_DATA (push, fifo->vram); |
| 414 |
PUSH_DATA (push, fifo->vram); |
| 415 |
|
| 416 |
BEGIN_NV04(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1); |
| 417 |
PUSH_DATA (push, screen->eng2d->handle); |
| 418 |
BEGIN_NV04(push, NV50_2D(DMA_NOTIFY), 4); |
| 419 |
PUSH_DATA (push, screen->sync->handle); |
| 420 |
PUSH_DATA (push, fifo->vram); |
| 421 |
PUSH_DATA (push, fifo->vram); |
| 422 |
PUSH_DATA (push, fifo->vram); |
| 423 |
BEGIN_NV04(push, NV50_2D(OPERATION), 1); |
| 424 |
PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY); |
| 425 |
BEGIN_NV04(push, NV50_2D(CLIP_ENABLE), 1); |
| 426 |
PUSH_DATA (push, 0); |
| 427 |
BEGIN_NV04(push, NV50_2D(COLOR_KEY_ENABLE), 1); |
| 428 |
PUSH_DATA (push, 0); |
| 429 |
BEGIN_NV04(push, NV50_2D(SET_PIXELS_FROM_MEMORY_SAFE_OVERLAP), 1); |
| 430 |
PUSH_DATA (push, 1); |
| 431 |
BEGIN_NV04(push, NV50_2D(COND_MODE), 1); |
| 432 |
PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS); |
| 433 |
|
| 434 |
BEGIN_NV04(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1); |
| 435 |
PUSH_DATA (push, screen->tesla->handle); |
| 436 |
|
| 437 |
BEGIN_NV04(push, NV50_3D(COND_MODE), 1); |
| 438 |
PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS); |
| 439 |
|
| 440 |
BEGIN_NV04(push, NV50_3D(DMA_NOTIFY), 1); |
| 441 |
PUSH_DATA (push, screen->sync->handle); |
| 442 |
BEGIN_NV04(push, NV50_3D(DMA_ZETA), 11); |
| 443 |
for (i = 0; i < 11; ++i) |
| 444 |
PUSH_DATA(push, fifo->vram); |
| 445 |
BEGIN_NV04(push, NV50_3D(DMA_COLOR(0)), NV50_3D_DMA_COLOR__LEN); |
| 446 |
for (i = 0; i < NV50_3D_DMA_COLOR__LEN; ++i) |
| 447 |
PUSH_DATA(push, fifo->vram); |
| 448 |
|
| 449 |
BEGIN_NV04(push, NV50_3D(REG_MODE), 1); |
| 450 |
PUSH_DATA (push, NV50_3D_REG_MODE_STRIPED); |
| 451 |
BEGIN_NV04(push, NV50_3D(UNK1400_LANES), 1); |
| 452 |
PUSH_DATA (push, 0xf); |
| 453 |
|
| 454 |
if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", true)) { |
| 455 |
BEGIN_NV04(push, NV50_3D(WATCHDOG_TIMER), 1); |
| 456 |
PUSH_DATA (push, 0x18); |
| 457 |
} |
| 458 |
|
| 459 |
BEGIN_NV04(push, NV50_3D(ZETA_COMP_ENABLE), 1); |
| 460 |
PUSH_DATA(push, screen->base.drm->version >= 0x01000101); |
| 461 |
|
| 462 |
BEGIN_NV04(push, NV50_3D(RT_COMP_ENABLE(0)), 8); |
| 463 |
for (i = 0; i < 8; ++i) |
| 464 |
PUSH_DATA(push, screen->base.drm->version >= 0x01000101); |
| 465 |
|
| 466 |
BEGIN_NV04(push, NV50_3D(RT_CONTROL), 1); |
| 467 |
PUSH_DATA (push, 1); |
| 468 |
|
| 469 |
BEGIN_NV04(push, NV50_3D(CSAA_ENABLE), 1); |
| 470 |
PUSH_DATA (push, 0); |
| 471 |
BEGIN_NV04(push, NV50_3D(MULTISAMPLE_ENABLE), 1); |
| 472 |
PUSH_DATA (push, 0); |
| 473 |
BEGIN_NV04(push, NV50_3D(MULTISAMPLE_MODE), 1); |
| 474 |
PUSH_DATA (push, NV50_3D_MULTISAMPLE_MODE_MS1); |
| 475 |
BEGIN_NV04(push, NV50_3D(MULTISAMPLE_CTRL), 1); |
| 476 |
PUSH_DATA (push, 0); |
| 477 |
BEGIN_NV04(push, NV50_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1); |
| 478 |
PUSH_DATA (push, 1); |
| 479 |
BEGIN_NV04(push, NV50_3D(BLEND_SEPARATE_ALPHA), 1); |
| 480 |
PUSH_DATA (push, 1); |
| 481 |
|
| 482 |
if (screen->tesla->oclass >= NVA0_3D_CLASS) { |
| 483 |
BEGIN_NV04(push, SUBC_3D(NVA0_3D_TEX_MISC), 1); |
| 484 |
PUSH_DATA (push, 0); |
| 485 |
} |
| 486 |
|
| 487 |
BEGIN_NV04(push, NV50_3D(SCREEN_Y_CONTROL), 1); |
| 488 |
PUSH_DATA (push, 0); |
| 489 |
BEGIN_NV04(push, NV50_3D(WINDOW_OFFSET_X), 2); |
| 490 |
PUSH_DATA (push, 0); |
| 491 |
PUSH_DATA (push, 0); |
| 492 |
BEGIN_NV04(push, NV50_3D(ZCULL_REGION), 1); |
| 493 |
PUSH_DATA (push, 0x3f); |
| 494 |
|
| 495 |
BEGIN_NV04(push, NV50_3D(VP_ADDRESS_HIGH), 2); |
| 496 |
PUSH_DATAh(push, screen->code->offset + (NV50_SHADER_STAGE_VERTEX << NV50_CODE_BO_SIZE_LOG2)); |
| 497 |
PUSH_DATA (push, screen->code->offset + (NV50_SHADER_STAGE_VERTEX << NV50_CODE_BO_SIZE_LOG2)); |
| 498 |
|
| 499 |
BEGIN_NV04(push, NV50_3D(FP_ADDRESS_HIGH), 2); |
| 500 |
PUSH_DATAh(push, screen->code->offset + (NV50_SHADER_STAGE_FRAGMENT << NV50_CODE_BO_SIZE_LOG2)); |
| 501 |
PUSH_DATA (push, screen->code->offset + (NV50_SHADER_STAGE_FRAGMENT << NV50_CODE_BO_SIZE_LOG2)); |
| 502 |
|
| 503 |
BEGIN_NV04(push, NV50_3D(GP_ADDRESS_HIGH), 2); |
| 504 |
PUSH_DATAh(push, screen->code->offset + (NV50_SHADER_STAGE_GEOMETRY << NV50_CODE_BO_SIZE_LOG2)); |
| 505 |
PUSH_DATA (push, screen->code->offset + (NV50_SHADER_STAGE_GEOMETRY << NV50_CODE_BO_SIZE_LOG2)); |
| 506 |
|
| 507 |
BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3); |
| 508 |
PUSH_DATAh(push, screen->tls_bo->offset); |
| 509 |
PUSH_DATA (push, screen->tls_bo->offset); |
| 510 |
PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8)); |
| 511 |
|
| 512 |
BEGIN_NV04(push, NV50_3D(STACK_ADDRESS_HIGH), 3); |
| 513 |
PUSH_DATAh(push, screen->stack_bo->offset); |
| 514 |
PUSH_DATA (push, screen->stack_bo->offset); |
| 515 |
PUSH_DATA (push, 4); |
| 516 |
|
| 517 |
BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3); |
| 518 |
PUSH_DATAh(push, screen->uniforms->offset + (0 << 16)); |
| 519 |
PUSH_DATA (push, screen->uniforms->offset + (0 << 16)); |
| 520 |
PUSH_DATA (push, (NV50_CB_PVP << 16) | 0x0000); |
| 521 |
|
| 522 |
BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3); |
| 523 |
PUSH_DATAh(push, screen->uniforms->offset + (1 << 16)); |
| 524 |
PUSH_DATA (push, screen->uniforms->offset + (1 << 16)); |
| 525 |
PUSH_DATA (push, (NV50_CB_PGP << 16) | 0x0000); |
| 526 |
|
| 527 |
BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3); |
| 528 |
PUSH_DATAh(push, screen->uniforms->offset + (2 << 16)); |
| 529 |
PUSH_DATA (push, screen->uniforms->offset + (2 << 16)); |
| 530 |
PUSH_DATA (push, (NV50_CB_PFP << 16) | 0x0000); |
| 531 |
|
| 532 |
BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3); |
| 533 |
PUSH_DATAh(push, screen->uniforms->offset + (4 << 16)); |
| 534 |
PUSH_DATA (push, screen->uniforms->offset + (4 << 16)); |
| 535 |
PUSH_DATA (push, (NV50_CB_AUX << 16) | (NV50_CB_AUX_SIZE & 0xffff)); |
| 536 |
|
| 537 |
BEGIN_NI04(push, NV50_3D(SET_PROGRAM_CB), 3); |
| 538 |
PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf01); |
| 539 |
PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf21); |
| 540 |
PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf31); |
| 541 |
|
| 542 |
/* return { 0.0, 0.0, 0.0, 0.0 } on out-of-bounds vtxbuf access */ |
| 543 |
BEGIN_NV04(push, NV50_3D(CB_ADDR), 1); |
| 544 |
PUSH_DATA (push, (NV50_CB_AUX_RUNOUT_OFFSET << (8 - 2)) | NV50_CB_AUX); |
| 545 |
BEGIN_NI04(push, NV50_3D(CB_DATA(0)), 4); |
| 546 |
PUSH_DATAf(push, 0.0f); |
| 547 |
PUSH_DATAf(push, 0.0f); |
| 548 |
PUSH_DATAf(push, 0.0f); |
| 549 |
PUSH_DATAf(push, 0.0f); |
| 550 |
BEGIN_NV04(push, NV50_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2); |
| 551 |
PUSH_DATAh(push, screen->uniforms->offset + (4 << 16) + NV50_CB_AUX_RUNOUT_OFFSET); |
| 552 |
PUSH_DATA (push, screen->uniforms->offset + (4 << 16) + NV50_CB_AUX_RUNOUT_OFFSET); |
| 553 |
|
| 554 |
/* set the membar offset */ |
| 555 |
BEGIN_NV04(push, NV50_3D(CB_ADDR), 1); |
| 556 |
PUSH_DATA (push, (NV50_CB_AUX_MEMBAR_OFFSET << (8 - 2)) | NV50_CB_AUX); |
| 557 |
BEGIN_NI04(push, NV50_3D(CB_DATA(0)), 1); |
| 558 |
PUSH_DATA (push, screen->uniforms->offset + (4 << 16) + NV50_CB_AUX_MEMBAR_OFFSET); |
| 559 |
|
| 560 |
nv50_upload_ms_info(push); |
| 561 |
|
| 562 |
/* max TIC (bits 4:8) & TSC bindings, per program type */ |
| 563 |
for (i = 0; i < NV50_MAX_3D_SHADER_STAGES; ++i) { |
| 564 |
BEGIN_NV04(push, NV50_3D(TEX_LIMITS(i)), 1); |
| 565 |
PUSH_DATA (push, 0x54); |
| 566 |
} |
| 567 |
|
| 568 |
BEGIN_NV04(push, NV50_3D(TIC_ADDRESS_HIGH), 3); |
| 569 |
PUSH_DATAh(push, screen->txc->offset); |
| 570 |
PUSH_DATA (push, screen->txc->offset); |
| 571 |
PUSH_DATA (push, NV50_TIC_MAX_ENTRIES - 1); |
| 572 |
|
| 573 |
BEGIN_NV04(push, NV50_3D(TSC_ADDRESS_HIGH), 3); |
| 574 |
PUSH_DATAh(push, screen->txc->offset + 65536); |
| 575 |
PUSH_DATA (push, screen->txc->offset + 65536); |
| 576 |
PUSH_DATA (push, NV50_TSC_MAX_ENTRIES - 1); |
| 577 |
|
| 578 |
BEGIN_NV04(push, NV50_3D(LINKED_TSC), 1); |
| 579 |
PUSH_DATA (push, 0); |
| 580 |
|
| 581 |
BEGIN_NV04(push, NV50_3D(CLIP_RECTS_EN), 1); |
| 582 |
PUSH_DATA (push, 0); |
| 583 |
BEGIN_NV04(push, NV50_3D(CLIP_RECTS_MODE), 1); |
| 584 |
PUSH_DATA (push, NV50_3D_CLIP_RECTS_MODE_INSIDE_ANY); |
| 585 |
BEGIN_NV04(push, NV50_3D(CLIP_RECT_HORIZ(0)), 8 * 2); |
| 586 |
for (i = 0; i < 8 * 2; ++i) |
| 587 |
PUSH_DATA(push, 0); |
| 588 |
BEGIN_NV04(push, NV50_3D(CLIPID_ENABLE), 1); |
| 589 |
PUSH_DATA (push, 0); |
| 590 |
|
| 591 |
BEGIN_NV04(push, NV50_3D(VIEWPORT_TRANSFORM_EN), 1); |
| 592 |
PUSH_DATA (push, 1); |
| 593 |
for (i = 0; i < NV50_MAX_VIEWPORTS; i++) { |
| 594 |
BEGIN_NV04(push, NV50_3D(DEPTH_RANGE_NEAR(i)), 2); |
| 595 |
PUSH_DATAf(push, 0.0f); |
| 596 |
PUSH_DATAf(push, 1.0f); |
| 597 |
BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(i)), 2); |
| 598 |
PUSH_DATA (push, 8192 << 16); |
| 599 |
PUSH_DATA (push, 8192 << 16); |
| 600 |
} |
| 601 |
|
| 602 |
BEGIN_NV04(push, NV50_3D(VIEW_VOLUME_CLIP_CTRL), 1); |
| 603 |
#ifdef NV50_SCISSORS_CLIPPING |
| 604 |
PUSH_DATA (push, 0x0000); |
| 605 |
#else |
| 606 |
PUSH_DATA (push, 0x1080); |
| 607 |
#endif |
| 608 |
|
| 609 |
BEGIN_NV04(push, NV50_3D(CLEAR_FLAGS), 1); |
| 610 |
PUSH_DATA (push, NV50_3D_CLEAR_FLAGS_CLEAR_RECT_VIEWPORT); |
| 611 |
|
| 612 |
/* We use scissors instead of exact view volume clipping, |
| 613 |
* so they're always enabled. |
| 614 |
*/ |
| 615 |
for (i = 0; i < NV50_MAX_VIEWPORTS; i++) { |
| 616 |
BEGIN_NV04(push, NV50_3D(SCISSOR_ENABLE(i)), 3); |
| 617 |
PUSH_DATA (push, 1); |
| 618 |
PUSH_DATA (push, 8192 << 16); |
| 619 |
PUSH_DATA (push, 8192 << 16); |
| 620 |
} |
| 621 |
|
| 622 |
BEGIN_NV04(push, NV50_3D(RASTERIZE_ENABLE), 1); |
| 623 |
PUSH_DATA (push, 1); |
| 624 |
BEGIN_NV04(push, NV50_3D(POINT_RASTER_RULES), 1); |
| 625 |
PUSH_DATA (push, NV50_3D_POINT_RASTER_RULES_OGL); |
| 626 |
BEGIN_NV04(push, NV50_3D(FRAG_COLOR_CLAMP_EN), 1); |
| 627 |
PUSH_DATA (push, 0x11111111); |
| 628 |
BEGIN_NV04(push, NV50_3D(EDGEFLAG), 1); |
| 629 |
PUSH_DATA (push, 1); |
| 630 |
|
| 631 |
BEGIN_NV04(push, NV50_3D(VB_ELEMENT_BASE), 1); |
| 632 |
PUSH_DATA (push, 0); |
| 633 |
if (screen->base.class_3d >= NV84_3D_CLASS) { |
| 634 |
BEGIN_NV04(push, NV84_3D(VERTEX_ID_BASE), 1); |
| 635 |
PUSH_DATA (push, 0); |
| 636 |
} |
| 637 |
|
| 638 |
BEGIN_NV04(push, NV50_3D(UNK0FDC), 1); |
| 639 |
PUSH_DATA (push, 1); |
| 640 |
BEGIN_NV04(push, NV50_3D(UNK19C0), 1); |
| 641 |
PUSH_DATA (push, 1); |
| 642 |
} |
| 643 |
|
| 644 |
static int nv50_tls_alloc(struct nv50_screen *screen, unsigned tls_space, |
| 645 |
uint64_t *tls_size) |
| 646 |
{ |
| 647 |
struct nouveau_device *dev = screen->base.device; |
| 648 |
int ret; |
| 649 |
|
| 650 |
assert(tls_space % ONE_TEMP_SIZE == 0); |
| 651 |
screen->cur_tls_space = util_next_power_of_two(tls_space / ONE_TEMP_SIZE) * |
| 652 |
ONE_TEMP_SIZE; |
| 653 |
if (nouveau_mesa_debug) |
| 654 |
debug_printf("allocating space for %u temps\n", |
| 655 |
util_next_power_of_two(tls_space / ONE_TEMP_SIZE)); |
| 656 |
*tls_size = screen->cur_tls_space * util_next_power_of_two(screen->TPs) * |
| 657 |
screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP; |
| 658 |
|
| 659 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, |
| 660 |
*tls_size, NULL, &screen->tls_bo); |
| 661 |
if (ret) { |
| 662 |
NOUVEAU_ERR("Failed to allocate local bo: %d\n", ret); |
| 663 |
return ret; |
| 664 |
} |
| 665 |
|
| 666 |
return 0; |
| 667 |
} |
| 668 |
|
| 669 |
int nv50_tls_realloc(struct nv50_screen *screen, unsigned tls_space) |
| 670 |
{ |
| 671 |
struct nouveau_pushbuf *push = screen->base.pushbuf; |
| 672 |
int ret; |
| 673 |
uint64_t tls_size; |
| 674 |
|
| 675 |
if (tls_space < screen->cur_tls_space) |
| 676 |
return 0; |
| 677 |
if (tls_space > screen->max_tls_space) { |
| 678 |
/* fixable by limiting number of warps (LOCAL_WARPS_LOG_ALLOC / |
| 679 |
* LOCAL_WARPS_NO_CLAMP) */ |
| 680 |
NOUVEAU_ERR("Unsupported number of temporaries (%u > %u). Fixable if someone cares.\n", |
| 681 |
(unsigned)(tls_space / ONE_TEMP_SIZE), |
| 682 |
(unsigned)(screen->max_tls_space / ONE_TEMP_SIZE)); |
| 683 |
return -ENOMEM; |
| 684 |
} |
| 685 |
|
| 686 |
nouveau_bo_ref(NULL, &screen->tls_bo); |
| 687 |
ret = nv50_tls_alloc(screen, tls_space, &tls_size); |
| 688 |
if (ret) |
| 689 |
return ret; |
| 690 |
|
| 691 |
BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3); |
| 692 |
PUSH_DATAh(push, screen->tls_bo->offset); |
| 693 |
PUSH_DATA (push, screen->tls_bo->offset); |
| 694 |
PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8)); |
| 695 |
|
| 696 |
return 1; |
| 697 |
} |
| 698 |
|
| 699 |
struct nouveau_screen * |
| 700 |
nv50_screen_create(struct nouveau_device *dev) |
| 701 |
{ |
| 702 |
struct nv50_screen *screen; |
| 703 |
struct pipe_screen *pscreen; |
| 704 |
struct nouveau_object *chan; |
| 705 |
uint64_t value; |
| 706 |
uint32_t tesla_class; |
| 707 |
unsigned stack_size; |
| 708 |
int ret; |
| 709 |
|
| 710 |
screen = CALLOC_STRUCT(nv50_screen); |
| 711 |
if (!screen) |
| 712 |
return NULL; |
| 713 |
pscreen = &screen->base.base; |
| 714 |
pscreen->destroy = nv50_screen_destroy; |
| 715 |
|
| 716 |
simple_mtx_init(&screen->state_lock, mtx_plain); |
| 717 |
ret = nouveau_screen_init(&screen->base, dev); |
| 718 |
if (ret) { |
| 719 |
NOUVEAU_ERR("nouveau_screen_init failed: %d\n", ret); |
| 720 |
goto fail; |
| 721 |
} |
| 722 |
|
| 723 |
/* TODO: Prevent FIFO prefetch before transfer of index buffers and |
| 724 |
* admit them to VRAM. |
| 725 |
*/ |
| 726 |
screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER | |
| 727 |
PIPE_BIND_VERTEX_BUFFER; |
| 728 |
screen->base.sysmem_bindings |= |
| 729 |
PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER; |
| 730 |
|
| 731 |
screen->base.pushbuf->rsvd_kick = 5; |
| 732 |
|
| 733 |
chan = screen->base.channel; |
| 734 |
|
| 735 |
pscreen->context_create = nv50_create; |
| 736 |
pscreen->is_format_supported = nv50_screen_is_format_supported; |
| 737 |
pscreen->get_driver_query_info = nv50_screen_get_driver_query_info; |
| 738 |
pscreen->get_driver_query_group_info = nv50_screen_get_driver_query_group_info; |
| 739 |
|
| 740 |
for (unsigned i = 0; i <= MESA_SHADER_COMPUTE; i++) |
| 741 |
pscreen->nir_options[i] = nv50_ir_nir_shader_compiler_options(NVISA_G80_CHIPSET, i); |
| 742 |
|
| 743 |
nv50_screen_init_resource_functions(pscreen); |
| 744 |
|
| 745 |
if (screen->base.device->chipset < 0x84 || |
| 746 |
debug_get_bool_option("NOUVEAU_PMPEG", false)) { |
| 747 |
/* PMPEG */ |
| 748 |
nouveau_screen_init_vdec(&screen->base); |
| 749 |
} else if (screen->base.device->chipset < 0x98 || |
| 750 |
screen->base.device->chipset == 0xa0) { |
| 751 |
/* VP2 */ |
| 752 |
screen->base.base.get_video_param = nv84_screen_get_video_param; |
| 753 |
screen->base.base.is_video_format_supported = nv84_screen_video_supported; |
| 754 |
} else { |
| 755 |
/* VP3/4 */ |
| 756 |
screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param; |
| 757 |
screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported; |
| 758 |
} |
| 759 |
|
| 760 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, 4096, |
| 761 |
NULL, &screen->fence.bo); |
| 762 |
if (ret) { |
| 763 |
NOUVEAU_ERR("Failed to allocate fence bo: %d\n", ret); |
| 764 |
goto fail; |
| 765 |
} |
| 766 |
|
| 767 |
BO_MAP(&screen->base, screen->fence.bo, 0, NULL); |
| 768 |
screen->fence.map = screen->fence.bo->map; |
| 769 |
screen->base.fence.emit = nv50_screen_fence_emit; |
| 770 |
screen->base.fence.update = nv50_screen_fence_update; |
| 771 |
|
| 772 |
ret = nouveau_object_new(chan, 0xbeef0301, NOUVEAU_NOTIFIER_CLASS, |
| 773 |
&(struct nv04_notify){ .length = 32 }, |
| 774 |
sizeof(struct nv04_notify), &screen->sync); |
| 775 |
if (ret) { |
| 776 |
NOUVEAU_ERR("Failed to allocate notifier: %d\n", ret); |
| 777 |
goto fail; |
| 778 |
} |
| 779 |
|
| 780 |
ret = nouveau_object_new(chan, 0xbeef5039, NV50_M2MF_CLASS, |
| 781 |
NULL, 0, &screen->m2mf); |
| 782 |
if (ret) { |
| 783 |
NOUVEAU_ERR("Failed to allocate PGRAPH context for M2MF: %d\n", ret); |
| 784 |
goto fail; |
| 785 |
} |
| 786 |
|
| 787 |
ret = nouveau_object_new(chan, 0xbeef502d, NV50_2D_CLASS, |
| 788 |
NULL, 0, &screen->eng2d); |
| 789 |
if (ret) { |
| 790 |
NOUVEAU_ERR("Failed to allocate PGRAPH context for 2D: %d\n", ret); |
| 791 |
goto fail; |
| 792 |
} |
| 793 |
|
| 794 |
switch (dev->chipset & 0xf0) { |
| 795 |
case 0x50: |
| 796 |
tesla_class = NV50_3D_CLASS; |
| 797 |
break; |
| 798 |
case 0x80: |
| 799 |
case 0x90: |
| 800 |
tesla_class = NV84_3D_CLASS; |
| 801 |
break; |
| 802 |
case 0xa0: |
| 803 |
switch (dev->chipset) { |
| 804 |
case 0xa0: |
| 805 |
case 0xaa: |
| 806 |
case 0xac: |
| 807 |
tesla_class = NVA0_3D_CLASS; |
| 808 |
break; |
| 809 |
case 0xaf: |
| 810 |
tesla_class = NVAF_3D_CLASS; |
| 811 |
break; |
| 812 |
default: |
| 813 |
tesla_class = NVA3_3D_CLASS; |
| 814 |
break; |
| 815 |
} |
| 816 |
break; |
| 817 |
default: |
| 818 |
NOUVEAU_ERR("Not a known NV50 chipset: NV%02x\n", dev->chipset); |
| 819 |
goto fail; |
| 820 |
} |
| 821 |
screen->base.class_3d = tesla_class; |
| 822 |
|
| 823 |
ret = nouveau_object_new(chan, 0xbeef5097, tesla_class, |
| 824 |
NULL, 0, &screen->tesla); |
| 825 |
if (ret) { |
| 826 |
NOUVEAU_ERR("Failed to allocate PGRAPH context for 3D: %d\n", ret); |
| 827 |
goto fail; |
| 828 |
} |
| 829 |
|
| 830 |
/* This over-allocates by a page. The GP, which would execute at the end of |
| 831 |
* the last page, would trigger faults. The going theory is that it |
| 832 |
* prefetches up to a certain amount. |
| 833 |
*/ |
| 834 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, |
| 835 |
(3 << NV50_CODE_BO_SIZE_LOG2) + 0x1000, |
| 836 |
NULL, &screen->code); |
| 837 |
if (ret) { |
| 838 |
NOUVEAU_ERR("Failed to allocate code bo: %d\n", ret); |
| 839 |
goto fail; |
| 840 |
} |
| 841 |
|
| 842 |
nouveau_heap_init(&screen->vp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2); |
| 843 |
nouveau_heap_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2); |
| 844 |
nouveau_heap_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2); |
| 845 |
|
| 846 |
nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value); |
| 847 |
|
| 848 |
screen->TPs = util_bitcount(value & 0xffff); |
| 849 |
screen->MPsInTP = util_bitcount(value & 0x0f000000); |
| 850 |
|
| 851 |
screen->mp_count = screen->TPs * screen->MPsInTP; |
| 852 |
|
| 853 |
stack_size = util_next_power_of_two(screen->TPs) * screen->MPsInTP * |
| 854 |
STACK_WARPS_ALLOC * 64 * 8; |
| 855 |
|
| 856 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, stack_size, NULL, |
| 857 |
&screen->stack_bo); |
| 858 |
if (ret) { |
| 859 |
NOUVEAU_ERR("Failed to allocate stack bo: %d\n", ret); |
| 860 |
goto fail; |
| 861 |
} |
| 862 |
|
| 863 |
uint64_t size_of_one_temp = util_next_power_of_two(screen->TPs) * |
| 864 |
screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP * |
| 865 |
ONE_TEMP_SIZE; |
| 866 |
screen->max_tls_space = dev->vram_size / size_of_one_temp * ONE_TEMP_SIZE; |
| 867 |
screen->max_tls_space /= 2; /* half of vram */ |
| 868 |
|
| 869 |
/* hw can address max 64 KiB */ |
| 870 |
screen->max_tls_space = MIN2(screen->max_tls_space, 64 << 10); |
| 871 |
|
| 872 |
uint64_t tls_size; |
| 873 |
unsigned tls_space = 4/*temps*/ * ONE_TEMP_SIZE; |
| 874 |
ret = nv50_tls_alloc(screen, tls_space, &tls_size); |
| 875 |
if (ret) |
| 876 |
goto fail; |
| 877 |
|
| 878 |
if (nouveau_mesa_debug) |
| 879 |
debug_printf("TPs = %u, MPsInTP = %u, VRAM = %"PRIu64" MiB, tls_size = %"PRIu64" KiB\n", |
| 880 |
screen->TPs, screen->MPsInTP, dev->vram_size >> 20, tls_size >> 10); |
| 881 |
|
| 882 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 5 << 16, NULL, |
| 883 |
&screen->uniforms); |
| 884 |
if (ret) { |
| 885 |
NOUVEAU_ERR("Failed to allocate uniforms bo: %d\n", ret); |
| 886 |
goto fail; |
| 887 |
} |
| 888 |
|
| 889 |
ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 3 << 16, NULL, |
| 890 |
&screen->txc); |
| 891 |
if (ret) { |
| 892 |
NOUVEAU_ERR("Failed to allocate TIC/TSC bo: %d\n", ret); |
| 893 |
goto fail; |
| 894 |
} |
| 895 |
|
| 896 |
screen->tic.entries = CALLOC(4096, sizeof(void *)); |
| 897 |
screen->tsc.entries = screen->tic.entries + 2048; |
| 898 |
|
| 899 |
if (!nv50_blitter_create(screen)) |
| 900 |
goto fail; |
| 901 |
|
| 902 |
nv50_screen_init_hwctx(screen); |
| 903 |
|
| 904 |
ret = nv50_screen_compute_setup(screen, screen->base.pushbuf); |
| 905 |
if (ret) { |
| 906 |
NOUVEAU_ERR("Failed to init compute context: %d\n", ret); |
| 907 |
goto fail; |
| 908 |
} |
| 909 |
|
| 910 |
// submit all initial state |
| 911 |
PUSH_KICK(screen->base.pushbuf); |
| 912 |
|
| 913 |
nv50_init_shader_caps(screen); |
| 914 |
nv50_init_compute_caps(screen); |
| 915 |
nv50_init_screen_caps(screen); |
| 916 |
|
| 917 |
return &screen->base; |
| 918 |
|
| 919 |
fail: |
| 920 |
screen->base.base.context_create = NULL; |
| 921 |
return &screen->base; |
| 922 |
} |
| 923 |
|
| 924 |
int |
| 925 |
nv50_screen_tic_alloc(struct nv50_screen *screen, void *entry) |
| 926 |
{ |
| 927 |
int i = screen->tic.next; |
| 928 |
|
| 929 |
while (screen->tic.lock[i / 32] & (1 << (i % 32))) |
| 930 |
i = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1); |
| 931 |
|
| 932 |
screen->tic.next = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1); |
| 933 |
|
| 934 |
if (screen->tic.entries[i]) |
| 935 |
nv50_tic_entry(screen->tic.entries[i])->id = -1; |
| 936 |
|
| 937 |
screen->tic.entries[i] = entry; |
| 938 |
return i; |
| 939 |
} |
| 940 |
|
| 941 |
int |
| 942 |
nv50_screen_tsc_alloc(struct nv50_screen *screen, void *entry) |
| 943 |
{ |
| 944 |
int i = screen->tsc.next; |
| 945 |
|
| 946 |
while (screen->tsc.lock[i / 32] & (1 << (i % 32))) |
| 947 |
i = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1); |
| 948 |
|
| 949 |
screen->tsc.next = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1); |
| 950 |
|
| 951 |
if (screen->tsc.entries[i]) |
| 952 |
nv50_tsc_entry(screen->tsc.entries[i])->id = -1; |
| 953 |
|
| 954 |
screen->tsc.entries[i] = entry; |
| 955 |
return i; |
| 956 |
} |