| 1 |
/* |
| 2 |
* Copyright 2010 Christoph Bumiller |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included in |
| 12 |
* all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <xf86drm.h> |
| 24 |
#include "drm-uapi/nouveau_drm.h" |
| 25 |
#include <nvif/class.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 "nouveau_vp3_video.h" |
| 32 |
|
| 33 |
#include "nv50_ir_driver.h" |
| 34 |
|
| 35 |
#include "nvc0/nvc0_context.h" |
| 36 |
#include "nvc0/nvc0_screen.h" |
| 37 |
|
| 38 |
#include "nvc0/mme/com9097.mme.h" |
| 39 |
#include "nvc0/mme/com90c0.mme.h" |
| 40 |
#include "nvc0/mme/comc597.mme.h" |
| 41 |
|
| 42 |
#include "nv50/g80_texture.xml.h" |
| 43 |
|
| 44 |
static bool |
| 45 |
nvc0_screen_is_format_supported(struct pipe_screen *pscreen, |
| 46 |
enum pipe_format format, |
| 47 |
enum pipe_texture_target target, |
| 48 |
unsigned sample_count, |
| 49 |
unsigned storage_sample_count, |
| 50 |
unsigned bindings) |
| 51 |
{ |
| 52 |
const struct util_format_description *desc = util_format_description(format); |
| 53 |
|
| 54 |
if (sample_count > 8) |
| 55 |
return false; |
| 56 |
if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */ |
| 57 |
return false; |
| 58 |
|
| 59 |
if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) |
| 60 |
return false; |
| 61 |
|
| 62 |
/* Short-circuit the rest of the logic -- this is used by the gallium frontend |
| 63 |
* to determine valid MS levels in a no-attachments scenario. |
| 64 |
*/ |
| 65 |
if (format == PIPE_FORMAT_NONE && bindings & PIPE_BIND_RENDER_TARGET) |
| 66 |
return true; |
| 67 |
|
| 68 |
if ((bindings & PIPE_BIND_SAMPLER_VIEW) && (target != PIPE_BUFFER)) |
| 69 |
if (util_format_get_blocksizebits(format) == 3 * 32) |
| 70 |
return false; |
| 71 |
|
| 72 |
if (bindings & PIPE_BIND_LINEAR) |
| 73 |
if (util_format_is_depth_or_stencil(format) || |
| 74 |
(target != PIPE_TEXTURE_1D && |
| 75 |
target != PIPE_TEXTURE_2D && |
| 76 |
target != PIPE_TEXTURE_RECT) || |
| 77 |
sample_count > 1) |
| 78 |
return false; |
| 79 |
|
| 80 |
/* Restrict ETC2 and ASTC formats here. These are only supported on GK20A |
| 81 |
* and GM20B. |
| 82 |
*/ |
| 83 |
if ((desc->layout == UTIL_FORMAT_LAYOUT_ETC || |
| 84 |
desc->layout == UTIL_FORMAT_LAYOUT_ASTC) && |
| 85 |
nouveau_screen(pscreen)->device->chipset != 0x12b && |
| 86 |
nouveau_screen(pscreen)->class_3d != NVEA_3D_CLASS) |
| 87 |
return false; |
| 88 |
|
| 89 |
/* shared is always supported */ |
| 90 |
bindings &= ~(PIPE_BIND_LINEAR | |
| 91 |
PIPE_BIND_SHARED); |
| 92 |
|
| 93 |
if (bindings & PIPE_BIND_SHADER_IMAGE) { |
| 94 |
if (format == PIPE_FORMAT_B8G8R8A8_UNORM && |
| 95 |
nouveau_screen(pscreen)->class_3d < NVE4_3D_CLASS) { |
| 96 |
/* This should work on Fermi, but for currently unknown reasons it |
| 97 |
* does not and results in breaking reads from pbos. */ |
| 98 |
return false; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
if (bindings & PIPE_BIND_INDEX_BUFFER) { |
| 103 |
if (format != PIPE_FORMAT_R8_UINT && |
| 104 |
format != PIPE_FORMAT_R16_UINT && |
| 105 |
format != PIPE_FORMAT_R32_UINT) |
| 106 |
return false; |
| 107 |
bindings &= ~PIPE_BIND_INDEX_BUFFER; |
| 108 |
} |
| 109 |
|
| 110 |
return (( nvc0_format_table[format].usage | |
| 111 |
nvc0_vertex_format[format].usage) & bindings) == bindings; |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
nvc0_init_shader_caps(struct nvc0_screen *screen) |
| 116 |
{ |
| 117 |
const uint16_t class_3d = screen->base.class_3d; |
| 118 |
|
| 119 |
for (unsigned i = 0; i <= MESA_SHADER_COMPUTE; i++) { |
| 120 |
struct pipe_shader_caps *caps = |
| 121 |
(struct pipe_shader_caps *)&screen->base.base.shader_caps[i]; |
| 122 |
|
| 123 |
caps->supported_irs = 1 << PIPE_SHADER_IR_NIR; |
| 124 |
caps->max_instructions = |
| 125 |
caps->max_alu_instructions = |
| 126 |
caps->max_tex_instructions = |
| 127 |
caps->max_tex_indirections = 16384; |
| 128 |
caps->max_control_flow_depth = 16; |
| 129 |
caps->max_inputs = 0x200 / 16; |
| 130 |
caps->max_outputs = 32; |
| 131 |
caps->max_const_buffer0_size = NVC0_MAX_CONSTBUF_SIZE; |
| 132 |
caps->max_const_buffers = NVC0_MAX_PIPE_CONSTBUFS; |
| 133 |
caps->indirect_temp_addr = true; |
| 134 |
caps->indirect_const_addr = true; |
| 135 |
caps->max_temps = NVC0_CAP_MAX_PROGRAM_TEMPS; |
| 136 |
caps->cont_supported = true; |
| 137 |
caps->tgsi_sqrt_supported = true; |
| 138 |
caps->subroutines = true; |
| 139 |
caps->integers = true; |
| 140 |
caps->max_shader_buffers = NVC0_MAX_BUFFERS; |
| 141 |
caps->max_texture_samplers = (class_3d >= NVE4_3D_CLASS) ? 32 : 16; |
| 142 |
caps->max_sampler_views = (class_3d >= NVE4_3D_CLASS) ? 32 : 16; |
| 143 |
caps->max_shader_images = |
| 144 |
class_3d >= NVE4_3D_CLASS || |
| 145 |
i == MESA_SHADER_FRAGMENT || |
| 146 |
i == MESA_SHADER_COMPUTE ? NVC0_MAX_IMAGES : 0; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
static void |
| 151 |
nvc0_init_compute_caps(struct nvc0_screen *screen) |
| 152 |
{ |
| 153 |
struct nouveau_device *dev = screen->base.device; |
| 154 |
const uint16_t obj_class = screen->compute->oclass; |
| 155 |
|
| 156 |
struct pipe_compute_caps *caps = |
| 157 |
(struct pipe_compute_caps *)&screen->base.base.compute_caps; |
| 158 |
|
| 159 |
caps->grid_dimension = 3; |
| 160 |
|
| 161 |
caps->max_grid_size[0] = obj_class >= NVE4_COMPUTE_CLASS ? 0x7fffffff : 65535; |
| 162 |
caps->max_grid_size[1] = 65535; |
| 163 |
caps->max_grid_size[2] = 65535; |
| 164 |
|
| 165 |
caps->max_block_size[0] = 1024; |
| 166 |
caps->max_block_size[1] = 1024; |
| 167 |
caps->max_block_size[2] = 64; |
| 168 |
|
| 169 |
caps->max_threads_per_block = 1024; |
| 170 |
|
| 171 |
caps->max_variable_threads_per_block = obj_class >= NVE4_COMPUTE_CLASS ? 1024 : 512; |
| 172 |
caps->max_mem_alloc_size = |
| 173 |
caps->max_global_size = nouveau_device_get_global_mem_size(dev); /* g[] */ |
| 174 |
|
| 175 |
caps->max_local_size = /* s[] */ |
| 176 |
obj_class == GM200_COMPUTE_CLASS ? 96 << 10 : |
| 177 |
(obj_class == GM107_COMPUTE_CLASS ? 64 << 10 : 48 << 10); |
| 178 |
|
| 179 |
caps->subgroup_sizes = 32; |
| 180 |
caps->max_compute_units = screen->mp_count_compute; |
| 181 |
caps->max_clock_frequency = 512; /* FIXME: arbitrary limit */ |
| 182 |
caps->address_bits = 64; |
| 183 |
} |
| 184 |
|
| 185 |
static void |
| 186 |
nvc0_init_screen_caps(struct nvc0_screen *screen) |
| 187 |
{ |
| 188 |
struct pipe_caps *caps = (struct pipe_caps *)&screen->base.base.caps; |
| 189 |
|
| 190 |
u_init_pipe_screen_caps(&screen->base.base, 1); |
| 191 |
|
| 192 |
const uint16_t class_3d = screen->base.class_3d; |
| 193 |
struct nouveau_device *dev = screen->base.device; |
| 194 |
|
| 195 |
/* non-boolean caps */ |
| 196 |
caps->max_texture_2d_size = 16384; |
| 197 |
caps->max_texture_cube_levels = 15; |
| 198 |
caps->max_texture_3d_levels = 12; |
| 199 |
caps->max_texture_array_layers = 2048; |
| 200 |
caps->min_texel_offset = -8; |
| 201 |
caps->max_texel_offset = 7; |
| 202 |
caps->min_texture_gather_offset = -32; |
| 203 |
caps->max_texture_gather_offset = 31; |
| 204 |
caps->max_texel_buffer_elements = 128 * 1024 * 1024; |
| 205 |
caps->glsl_feature_level = 430; |
| 206 |
caps->glsl_feature_level_compatibility = 430; |
| 207 |
caps->max_render_targets = 8; |
| 208 |
caps->max_dual_source_render_targets = 1; |
| 209 |
caps->viewport_subpixel_bits = |
| 210 |
caps->rasterizer_subpixel_bits = 8; |
| 211 |
caps->max_stream_output_buffers = 4; |
| 212 |
caps->max_stream_output_separate_components = |
| 213 |
caps->max_stream_output_interleaved_components = 128; |
| 214 |
caps->max_geometry_output_vertices = |
| 215 |
caps->max_geometry_total_output_components = 1024; |
| 216 |
caps->max_vertex_streams = 4; |
| 217 |
caps->max_gs_invocations = 32; |
| 218 |
caps->max_shader_buffer_size = 1 << 27; |
| 219 |
caps->max_vertex_attrib_stride = 2048; |
| 220 |
caps->max_vertex_element_src_offset = 2047; |
| 221 |
caps->constant_buffer_offset_alignment = 256; |
| 222 |
caps->texture_buffer_offset_alignment = class_3d < GM107_3D_CLASS ? |
| 223 |
256 /* IMAGE bindings require alignment to 256 */ : 16; |
| 224 |
caps->shader_buffer_offset_alignment = 16; |
| 225 |
caps->min_map_buffer_alignment = NOUVEAU_MIN_BUFFER_MAP_ALIGN; |
| 226 |
caps->max_viewports = NVC0_MAX_VIEWPORTS; |
| 227 |
caps->max_texture_gather_components = 4; |
| 228 |
caps->texture_border_color_quirk = PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50; |
| 229 |
caps->endianness = PIPE_ENDIAN_LITTLE; |
| 230 |
caps->max_shader_patch_varyings = 30; |
| 231 |
caps->max_window_rectangles = NVC0_MAX_WINDOW_RECTANGLES; |
| 232 |
caps->max_conservative_raster_subpixel_precision_bias = class_3d >= GM200_3D_CLASS ? 8 : 0; |
| 233 |
caps->max_texture_upload_memory_budget = 64 * 1024 * 1024; |
| 234 |
/* NOTE: These only count our slots for GENERIC varyings. |
| 235 |
* The address space may be larger, but the actual hard limit seems to be |
| 236 |
* less than what the address space layout permits, so don't add TEXCOORD, |
| 237 |
* COLOR, etc. here. |
| 238 |
*/ |
| 239 |
caps->max_varyings = 0x1f0 / 16; |
| 240 |
caps->max_vertex_buffers = 16; |
| 241 |
caps->gl_begin_end_buffer_size = 512 * 1024; /* TODO: Investigate tuning this */ |
| 242 |
|
| 243 |
caps->timer_resolution = 1000; |
| 244 |
|
| 245 |
caps->supported_prim_modes_with_restart = |
| 246 |
caps->supported_prim_modes = BITFIELD_MASK(MESA_PRIM_COUNT); |
| 247 |
|
| 248 |
/* supported caps */ |
| 249 |
caps->texture_mirror_clamp = true; |
| 250 |
caps->texture_mirror_clamp_to_edge = true; |
| 251 |
caps->texture_swizzle = true; |
| 252 |
caps->npot_textures = true; |
| 253 |
caps->mixed_framebuffer_sizes = true; |
| 254 |
caps->mixed_color_depth_bits = true; |
| 255 |
caps->anisotropic_filter = true; |
| 256 |
caps->seamless_cube_map = true; |
| 257 |
caps->cube_map_array = true; |
| 258 |
caps->texture_buffer_objects = true; |
| 259 |
caps->texture_multisample = true; |
| 260 |
caps->depth_clip_disable = true; |
| 261 |
caps->tgsi_texcoord = true; |
| 262 |
caps->fragment_shader_texture_lod = true; |
| 263 |
caps->fragment_shader_derivatives = true; |
| 264 |
caps->fragment_color_clamped = true; |
| 265 |
caps->vertex_color_unclamped = true; |
| 266 |
caps->vertex_color_clamped = true; |
| 267 |
caps->query_timestamp = true; |
| 268 |
caps->query_time_elapsed = true; |
| 269 |
caps->occlusion_query = true; |
| 270 |
caps->stream_output_pause_resume = true; |
| 271 |
caps->stream_output_interleave_buffers = true; |
| 272 |
caps->query_pipeline_statistics = true; |
| 273 |
caps->blend_equation_separate = true; |
| 274 |
caps->indep_blend_enable = true; |
| 275 |
caps->indep_blend_func = true; |
| 276 |
caps->fs_coord_origin_upper_left = true; |
| 277 |
caps->fs_coord_pixel_center_half_integer = true; |
| 278 |
caps->primitive_restart = true; |
| 279 |
caps->primitive_restart_fixed_index = true; |
| 280 |
caps->vs_instanceid = true; |
| 281 |
caps->vertex_element_instance_divisor = true; |
| 282 |
caps->conditional_render = true; |
| 283 |
caps->texture_barrier = true; |
| 284 |
caps->quads_follow_provoking_vertex_convention = true; |
| 285 |
caps->start_instance = true; |
| 286 |
caps->draw_indirect = true; |
| 287 |
caps->user_vertex_buffers = true; |
| 288 |
caps->texture_query_lod = true; |
| 289 |
caps->sample_shading = true; |
| 290 |
caps->texture_gather_offsets = true; |
| 291 |
caps->texture_gather_sm5 = true; |
| 292 |
caps->fs_fine_derivative = true; |
| 293 |
caps->conditional_render_inverted = true; |
| 294 |
caps->sampler_view_target = true; |
| 295 |
caps->clip_halfz = true; |
| 296 |
caps->polygon_offset_clamp = true; |
| 297 |
caps->multisample_z_resolve = true; |
| 298 |
caps->texture_float_linear = true; |
| 299 |
caps->texture_half_float_linear = true; |
| 300 |
caps->depth_bounds_test = true; |
| 301 |
caps->texture_query_samples = true; |
| 302 |
caps->copy_between_compressed_and_plain_formats = true; |
| 303 |
caps->force_persample_interp = true; |
| 304 |
caps->draw_parameters = true; |
| 305 |
caps->shader_pack_half_float = true; |
| 306 |
caps->multi_draw_indirect = true; |
| 307 |
caps->memobj = true; |
| 308 |
caps->multi_draw_indirect_params = true; |
| 309 |
caps->fs_face_is_integer_sysval = true; |
| 310 |
caps->query_buffer_object = true; |
| 311 |
caps->invalidate_buffer = true; |
| 312 |
caps->string_marker = true; |
| 313 |
caps->framebuffer_no_attachment = true; |
| 314 |
caps->cull_distance = true; |
| 315 |
caps->robust_buffer_access_behavior = true; |
| 316 |
caps->shader_group_vote = true; |
| 317 |
caps->shader_array_components = true; |
| 318 |
caps->legacy_math_rules = true; |
| 319 |
caps->doubles = true; |
| 320 |
caps->int64 = true; |
| 321 |
caps->tgsi_tex_txf_lz = false; |
| 322 |
caps->shader_clock = true; |
| 323 |
caps->compute = true; |
| 324 |
caps->can_bind_const_buffer_as_vertex = true; |
| 325 |
caps->query_so_overflow = true; |
| 326 |
caps->image_atomic_inc_wrap = true; |
| 327 |
caps->demote_to_helper_invocation = true; |
| 328 |
caps->device_reset_status_query = true; |
| 329 |
caps->texture_shadow_lod = true; |
| 330 |
caps->clear_scissored = true; |
| 331 |
caps->image_store_formatted = true; |
| 332 |
caps->query_memory_info = true; |
| 333 |
caps->texture_transfer_modes = |
| 334 |
screen->base.vram_domain & NOUVEAU_BO_VRAM ? PIPE_TEXTURE_TRANSFER_BLIT : 0; |
| 335 |
caps->fbfetch = class_3d >= NVE4_3D_CLASS ? 1 : 0; /* needs testing on fermi */ |
| 336 |
caps->seamless_cube_map_per_texture = |
| 337 |
caps->shader_ballot = class_3d >= NVE4_3D_CLASS; |
| 338 |
caps->bindless_texture = class_3d >= NVE4_3D_CLASS; |
| 339 |
caps->image_atomic_float_add = class_3d < GM107_3D_CLASS; /* needs additional lowering */ |
| 340 |
caps->polygon_mode_fill_rectangle = |
| 341 |
caps->vs_layer_viewport = |
| 342 |
caps->tes_layer_viewport = |
| 343 |
caps->post_depth_coverage = |
| 344 |
caps->conservative_raster_post_snap_triangles = |
| 345 |
caps->conservative_raster_post_snap_points_lines = |
| 346 |
caps->conservative_raster_post_depth_coverage = |
| 347 |
caps->programmable_sample_locations = |
| 348 |
caps->viewport_swizzle = |
| 349 |
caps->viewport_mask = |
| 350 |
caps->sampler_reduction_minmax = class_3d >= GM200_3D_CLASS; |
| 351 |
caps->conservative_raster_pre_snap_triangles = class_3d >= GP100_3D_CLASS; |
| 352 |
caps->resource_from_user_memory_compute_only = |
| 353 |
caps->system_svm = screen->base.has_svm; |
| 354 |
|
| 355 |
caps->gl_spirv = true; |
| 356 |
caps->gl_spirv_variable_pointers = true; |
| 357 |
|
| 358 |
/* nir related caps */ |
| 359 |
caps->nir_images_as_deref = false; |
| 360 |
|
| 361 |
caps->pci_group = dev->info.pci.domain; |
| 362 |
caps->pci_bus = dev->info.pci.bus; |
| 363 |
caps->pci_device = dev->info.pci.dev; |
| 364 |
caps->pci_function = dev->info.pci.func; |
| 365 |
|
| 366 |
caps->opencl_integer_functions = false; /* could be done */ |
| 367 |
caps->integer_multiply_32x16 = false; /* could be done */ |
| 368 |
caps->map_unsynchronized_thread_safe = false; /* when we fix MT stuff */ |
| 369 |
caps->alpha_to_coverage_dither_control = false; /* TODO */ |
| 370 |
caps->shader_atomic_int64 = false; /* TODO */ |
| 371 |
caps->hardware_gl_select = false; |
| 372 |
|
| 373 |
caps->vendor_id = 0x10de; |
| 374 |
caps->device_id = dev->info.device_id; |
| 375 |
caps->video_memory = dev->vram_size >> 20; |
| 376 |
caps->uma = screen->base.is_uma; |
| 377 |
|
| 378 |
caps->min_line_width = |
| 379 |
caps->min_line_width_aa = |
| 380 |
caps->min_point_size = |
| 381 |
caps->min_point_size_aa = 1; |
| 382 |
caps->point_size_granularity = |
| 383 |
caps->line_width_granularity = 0.1; |
| 384 |
caps->max_line_width = |
| 385 |
caps->max_line_width_aa = 10.0f; |
| 386 |
caps->max_point_size = 63.0f; |
| 387 |
caps->max_point_size_aa = 63.375f; |
| 388 |
caps->max_texture_anisotropy = 16.0f; |
| 389 |
caps->max_texture_lod_bias = 15.0f; |
| 390 |
caps->min_conservative_raster_dilate = 0.0f; |
| 391 |
caps->max_conservative_raster_dilate = class_3d >= GM200_3D_CLASS ? 0.75f : 0.0f; |
| 392 |
caps->conservative_raster_dilate_granularity = class_3d >= GM200_3D_CLASS ? 0.25f : 0.0f; |
| 393 |
} |
| 394 |
|
| 395 |
static void |
| 396 |
nvc0_screen_get_sample_pixel_grid(struct pipe_screen *pscreen, |
| 397 |
unsigned sample_count, |
| 398 |
unsigned *width, unsigned *height) |
| 399 |
{ |
| 400 |
switch (sample_count) { |
| 401 |
case 0: |
| 402 |
case 1: |
| 403 |
/* this could be 4x4, but the GL state tracker makes it difficult to |
| 404 |
* create a 1x MSAA texture and smaller grids save CB space */ |
| 405 |
*width = 2; |
| 406 |
*height = 4; |
| 407 |
break; |
| 408 |
case 2: |
| 409 |
*width = 2; |
| 410 |
*height = 4; |
| 411 |
break; |
| 412 |
case 4: |
| 413 |
*width = 2; |
| 414 |
*height = 2; |
| 415 |
break; |
| 416 |
case 8: |
| 417 |
*width = 1; |
| 418 |
*height = 2; |
| 419 |
break; |
| 420 |
default: |
| 421 |
assert(0); |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
static void |
| 426 |
nvc0_screen_destroy(struct pipe_screen *pscreen) |
| 427 |
{ |
| 428 |
struct nvc0_screen *screen = nvc0_screen(pscreen); |
| 429 |
|
| 430 |
if (!screen->base.initialized) |
| 431 |
return; |
| 432 |
|
| 433 |
if (screen->blitter) |
| 434 |
nvc0_blitter_destroy(screen); |
| 435 |
if (screen->pm.prog) { |
| 436 |
screen->pm.prog->code = NULL; /* hardcoded, don't FREE */ |
| 437 |
nvc0_program_destroy(NULL, screen->pm.prog); |
| 438 |
FREE(screen->pm.prog); |
| 439 |
} |
| 440 |
|
| 441 |
nouveau_bo_ref(NULL, &screen->text); |
| 442 |
nouveau_bo_ref(NULL, &screen->uniform_bo); |
| 443 |
nouveau_bo_ref(NULL, &screen->tls); |
| 444 |
nouveau_bo_ref(NULL, &screen->txc); |
| 445 |
nouveau_bo_ref(NULL, &screen->fence.bo); |
| 446 |
nouveau_bo_ref(NULL, &screen->poly_cache); |
| 447 |
|
| 448 |
nouveau_heap_free(&screen->lib_code); |
| 449 |
nouveau_heap_destroy(&screen->text_heap); |
| 450 |
|
| 451 |
FREE(screen->tic.entries); |
| 452 |
|
| 453 |
nouveau_object_del(&screen->eng3d); |
| 454 |
nouveau_object_del(&screen->eng2d); |
| 455 |
nouveau_object_del(&screen->m2mf); |
| 456 |
nouveau_object_del(&screen->copy); |
| 457 |
nouveau_object_del(&screen->compute); |
| 458 |
nouveau_object_del(&screen->nvsw); |
| 459 |
|
| 460 |
nouveau_screen_fini(&screen->base); |
| 461 |
simple_mtx_destroy(&screen->state_lock); |
| 462 |
|
| 463 |
FREE(screen); |
| 464 |
} |
| 465 |
|
| 466 |
static int |
| 467 |
nvc0_graph_set_macro(struct nvc0_screen *screen, uint32_t m, unsigned pos, |
| 468 |
unsigned size, const uint32_t *data) |
| 469 |
{ |
| 470 |
struct nouveau_pushbuf *push = screen->base.pushbuf; |
| 471 |
|
| 472 |
size /= 4; |
| 473 |
|
| 474 |
assert((pos + size) <= 0x800); |
| 475 |
|
| 476 |
BEGIN_NVC0(push, SUBC_3D(NVC0_GRAPH_MACRO_ID), 2); |
| 477 |
PUSH_DATA (push, (m - 0x3800) / 8); |
| 478 |
PUSH_DATA (push, pos); |
| 479 |
BEGIN_1IC0(push, SUBC_3D(NVC0_GRAPH_MACRO_UPLOAD_POS), size + 1); |
| 480 |
PUSH_DATA (push, pos); |
| 481 |
PUSH_DATAp(push, data, size); |
| 482 |
|
| 483 |
return pos + size; |
| 484 |
} |
| 485 |
|
| 486 |
static int |
| 487 |
tu102_graph_set_macro(struct nvc0_screen *screen, uint32_t m, unsigned pos, |
| 488 |
unsigned size, const uint32_t *data) |
| 489 |
{ |
| 490 |
struct nouveau_pushbuf *push = screen->base.pushbuf; |
| 491 |
|
| 492 |
size /= 4; |
| 493 |
|
| 494 |
assert((pos + size) <= 0x800); |
| 495 |
|
| 496 |
BEGIN_NVC0(push, SUBC_3D(NVC0_GRAPH_MACRO_ID), 2); |
| 497 |
PUSH_DATA (push, (m - 0x3800) / 8); |
| 498 |
PUSH_DATA (push, pos); |
| 499 |
BEGIN_1IC0(push, SUBC_3D(NVC0_GRAPH_MACRO_UPLOAD_POS), size + 1); |
| 500 |
PUSH_DATA (push, pos); |
| 501 |
PUSH_DATAp(push, data, size); |
| 502 |
|
| 503 |
return pos + (size / 3); |
| 504 |
} |
| 505 |
|
| 506 |
static void |
| 507 |
nvc0_magic_3d_init(struct nouveau_pushbuf *push, uint16_t obj_class) |
| 508 |
{ |
| 509 |
BEGIN_NVC0(push, SUBC_3D(0x10cc), 1); |
| 510 |
PUSH_DATA (push, 0xff); |
| 511 |
BEGIN_NVC0(push, SUBC_3D(0x10e0), 2); |
| 512 |
PUSH_DATA (push, 0xff); |
| 513 |
PUSH_DATA (push, 0xff); |
| 514 |
BEGIN_NVC0(push, SUBC_3D(0x10ec), 2); |
| 515 |
PUSH_DATA (push, 0xff); |
| 516 |
PUSH_DATA (push, 0xff); |
| 517 |
if (obj_class < GV100_3D_CLASS) { |
| 518 |
BEGIN_NVC0(push, SUBC_3D(0x074c), 1); |
| 519 |
PUSH_DATA (push, 0x3f); |
| 520 |
} |
| 521 |
|
| 522 |
BEGIN_NVC0(push, SUBC_3D(0x16a8), 1); |
| 523 |
PUSH_DATA (push, (3 << 16) | 3); |
| 524 |
BEGIN_NVC0(push, SUBC_3D(0x1794), 1); |
| 525 |
PUSH_DATA (push, (2 << 16) | 2); |
| 526 |
|
| 527 |
if (obj_class < GM107_3D_CLASS) { |
| 528 |
BEGIN_NVC0(push, SUBC_3D(0x12ac), 1); |
| 529 |
PUSH_DATA (push, 0); |
| 530 |
} |
| 531 |
BEGIN_NVC0(push, SUBC_3D(0x0218), 1); |
| 532 |
PUSH_DATA (push, 0x10); |
| 533 |
BEGIN_NVC0(push, SUBC_3D(0x10fc), 1); |
| 534 |
PUSH_DATA (push, 0x10); |
| 535 |
BEGIN_NVC0(push, SUBC_3D(0x1290), 1); |
| 536 |
PUSH_DATA (push, 0x10); |
| 537 |
BEGIN_NVC0(push, SUBC_3D(0x12d8), 2); |
| 538 |
PUSH_DATA (push, 0x10); |
| 539 |
PUSH_DATA (push, 0x10); |
| 540 |
BEGIN_NVC0(push, SUBC_3D(0x1140), 1); |
| 541 |
PUSH_DATA (push, 0x10); |
| 542 |
BEGIN_NVC0(push, SUBC_3D(0x1610), 1); |
| 543 |
PUSH_DATA (push, 0xe); |
| 544 |
|
| 545 |
BEGIN_NVC0(push, NVC0_3D(VERTEX_ID_GEN_MODE), 1); |
| 546 |
PUSH_DATA (push, NVC0_3D_VERTEX_ID_GEN_MODE_DRAW_ARRAYS_ADD_START); |
| 547 |
BEGIN_NVC0(push, SUBC_3D(0x030c), 1); |
| 548 |
PUSH_DATA (push, 0); |
| 549 |
BEGIN_NVC0(push, SUBC_3D(0x0300), 1); |
| 550 |
PUSH_DATA (push, 3); |
| 551 |
|
| 552 |
if (obj_class < GV100_3D_CLASS) { |
| 553 |
BEGIN_NVC0(push, SUBC_3D(0x02d0), 1); |
| 554 |
PUSH_DATA (push, 0x3fffff); |
| 555 |
} |
| 556 |
BEGIN_NVC0(push, SUBC_3D(0x0fdc), 1); |
| 557 |
PUSH_DATA (push, 1); |
| 558 |
BEGIN_NVC0(push, SUBC_3D(0x19c0), 1); |
| 559 |
PUSH_DATA (push, 1); |
| 560 |
|
| 561 |
if (obj_class < GM107_3D_CLASS) { |
| 562 |
BEGIN_NVC0(push, SUBC_3D(0x075c), 1); |
| 563 |
PUSH_DATA (push, 3); |
| 564 |
|
| 565 |
if (obj_class >= NVE4_3D_CLASS) { |
| 566 |
BEGIN_NVC0(push, SUBC_3D(0x07fc), 1); |
| 567 |
PUSH_DATA (push, 1); |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
/* TODO: find out what software methods 0x1528, 0x1280 and (on nve4) 0x02dc |
| 572 |
* are supposed to do */ |
| 573 |
} |
| 574 |
|
| 575 |
static void |
| 576 |
nvc0_screen_fence_emit(struct pipe_context *pcontext, u32 *sequence, |
| 577 |
struct nouveau_bo *wait) |
| 578 |
{ |
| 579 |
struct nvc0_context *nvc0 = nvc0_context(pcontext); |
| 580 |
struct nvc0_screen *screen = nvc0->screen; |
| 581 |
struct nouveau_pushbuf *push = nvc0->base.pushbuf; |
| 582 |
struct nouveau_pushbuf_refn ref = { wait, NOUVEAU_BO_GART | NOUVEAU_BO_RDWR }; |
| 583 |
|
| 584 |
/* we need to do it after possible flush in MARK_RING */ |
| 585 |
*sequence = ++screen->base.fence.sequence; |
| 586 |
|
| 587 |
assert(PUSH_AVAIL(push) + push->rsvd_kick >= 5); |
| 588 |
PUSH_DATA (push, NVC0_FIFO_PKHDR_SQ(NVC0_3D(QUERY_ADDRESS_HIGH), 4)); |
| 589 |
PUSH_DATAh(push, screen->fence.bo->offset); |
| 590 |
PUSH_DATA (push, screen->fence.bo->offset); |
| 591 |
PUSH_DATA (push, *sequence); |
| 592 |
PUSH_DATA (push, NVC0_3D_QUERY_GET_FENCE | NVC0_3D_QUERY_GET_SHORT | |
| 593 |
(0xf << NVC0_3D_QUERY_GET_UNIT__SHIFT)); |
| 594 |
|
| 595 |
nouveau_pushbuf_refn(push, &ref, 1); |
| 596 |
} |
| 597 |
|
| 598 |
static u32 |
| 599 |
nvc0_screen_fence_update(struct pipe_screen *pscreen) |
| 600 |
{ |
| 601 |
struct nvc0_screen *screen = nvc0_screen(pscreen); |
| 602 |
return screen->fence.map[0]; |
| 603 |
} |
| 604 |
|
| 605 |
static int |
| 606 |
nvc0_screen_init_compute(struct nvc0_screen *screen) |
| 607 |
{ |
| 608 |
const struct nouveau_mclass computes[] = { |
| 609 |
{ AD102_COMPUTE_CLASS, -1 }, |
| 610 |
{ GA102_COMPUTE_CLASS, -1 }, |
| 611 |
{ TU102_COMPUTE_CLASS, -1 }, |
| 612 |
{ GV100_COMPUTE_CLASS, -1 }, |
| 613 |
{ GP104_COMPUTE_CLASS, -1 }, |
| 614 |
{ GP100_COMPUTE_CLASS, -1 }, |
| 615 |
{ GM200_COMPUTE_CLASS, -1 }, |
| 616 |
{ GM107_COMPUTE_CLASS, -1 }, |
| 617 |
{ NVF0_COMPUTE_CLASS, -1 }, |
| 618 |
{ NVE4_COMPUTE_CLASS, -1 }, |
| 619 |
/* In theory, GF110+ should also support NVC8_COMPUTE_CLASS but, |
| 620 |
* in practice, a ILLEGAL_CLASS dmesg fail appears when using it. */ |
| 621 |
// { NVC8_COMPUTE_CLASS, -1 }, |
| 622 |
{ NVC0_COMPUTE_CLASS, -1 }, |
| 623 |
{} |
| 624 |
}; |
| 625 |
struct nouveau_object *chan = screen->base.channel; |
| 626 |
int ret; |
| 627 |
|
| 628 |
ret = nouveau_object_mclass(chan, computes); |
| 629 |
if (ret < 0) { |
| 630 |
NOUVEAU_ERR("No supported compute class: %d\n", ret); |
| 631 |
return ret; |
| 632 |
} |
| 633 |
|
| 634 |
ret = nouveau_object_new(chan, 0xbeef00c0, computes[ret].oclass, NULL, 0, &screen->compute); |
| 635 |
if (ret) { |
| 636 |
NOUVEAU_ERR("Failed to allocate compute class: %d\n", ret); |
| 637 |
return ret; |
| 638 |
} |
| 639 |
|
| 640 |
if (screen->compute->oclass < NVE4_COMPUTE_CLASS) |
| 641 |
return nvc0_screen_compute_setup(screen, screen->base.pushbuf); |
| 642 |
|
| 643 |
return nve4_screen_compute_setup(screen, screen->base.pushbuf); |
| 644 |
} |
| 645 |
|
| 646 |
static int |
| 647 |
nvc0_screen_resize_tls_area(struct nvc0_screen *screen, |
| 648 |
uint32_t lpos, uint32_t lneg, uint32_t cstack) |
| 649 |
{ |
| 650 |
struct nouveau_bo *bo = NULL; |
| 651 |
int ret; |
| 652 |
uint64_t size = (lpos + lneg) * 32 + cstack; |
| 653 |
|
| 654 |
if (size >= (1 << 20)) { |
| 655 |
NOUVEAU_ERR("requested TLS size too large: 0x%"PRIx64"\n", size); |
| 656 |
return -1; |
| 657 |
} |
| 658 |
|
| 659 |
size *= (screen->base.device->chipset >= 0xe0) ? 64 : 48; /* max warps */ |
| 660 |
size = align(size, 0x8000); |
| 661 |
size *= screen->mp_count; |
| 662 |
|
| 663 |
size = align(size, 1 << 17); |
| 664 |
|
| 665 |
ret = nouveau_bo_new(screen->base.device, NV_VRAM_DOMAIN(&screen->base), 1 << 17, size, |
| 666 |
NULL, &bo); |
| 667 |
if (ret) |
| 668 |
return ret; |
| 669 |
|
| 670 |
/* Make sure that the pushbuf has acquired a reference to the old tls |
| 671 |
* segment, as it may have commands that will reference it. |
| 672 |
*/ |
| 673 |
if (screen->tls) |
| 674 |
PUSH_REF1(screen->base.pushbuf, screen->tls, |
| 675 |
NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RDWR); |
| 676 |
nouveau_bo_ref(NULL, &screen->tls); |
| 677 |
screen->tls = bo; |
| 678 |
return 0; |
| 679 |
} |
| 680 |
|
| 681 |
int |
| 682 |
nvc0_screen_resize_text_area(struct nvc0_screen *screen, struct nouveau_pushbuf *push, |
| 683 |
uint64_t size) |
| 684 |
{ |
| 685 |
struct nouveau_bo *bo; |
| 686 |
int ret; |
| 687 |
|
| 688 |
ret = nouveau_bo_new(screen->base.device, NV_VRAM_DOMAIN(&screen->base), |
| 689 |
1 << 17, size, NULL, &bo); |
| 690 |
if (ret) |
| 691 |
return ret; |
| 692 |
|
| 693 |
/* Make sure that the pushbuf has acquired a reference to the old text |
| 694 |
* segment, as it may have commands that will reference it. |
| 695 |
*/ |
| 696 |
if (screen->text) |
| 697 |
PUSH_REF1(screen->base.pushbuf, screen->text, |
| 698 |
NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD); |
| 699 |
nouveau_bo_ref(NULL, &screen->text); |
| 700 |
screen->text = bo; |
| 701 |
|
| 702 |
nouveau_heap_free(&screen->lib_code); |
| 703 |
nouveau_heap_destroy(&screen->text_heap); |
| 704 |
|
| 705 |
/* |
| 706 |
* Shader storage needs a 2K (from NVIDIA) overallocations at the end |
| 707 |
* to avoid prefetch bugs. |
| 708 |
*/ |
| 709 |
nouveau_heap_init(&screen->text_heap, 0, size - 0x800); |
| 710 |
|
| 711 |
/* update the code segment setup */ |
| 712 |
if (screen->eng3d->oclass < GV100_3D_CLASS) { |
| 713 |
BEGIN_NVC0(push, NVC0_3D(CODE_ADDRESS_HIGH), 2); |
| 714 |
PUSH_DATAh(push, screen->text->offset); |
| 715 |
PUSH_DATA (push, screen->text->offset); |
| 716 |
if (screen->compute) { |
| 717 |
BEGIN_NVC0(push, NVC0_CP(CODE_ADDRESS_HIGH), 2); |
| 718 |
PUSH_DATAh(push, screen->text->offset); |
| 719 |
PUSH_DATA (push, screen->text->offset); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
return 0; |
| 724 |
} |
| 725 |
|
| 726 |
void |
| 727 |
nvc0_screen_bind_cb_3d(struct nvc0_screen *screen, struct nouveau_pushbuf *push, |
| 728 |
bool *can_serialize, int stage, int index, int size, uint64_t addr) |
| 729 |
{ |
| 730 |
assert(stage != 5); |
| 731 |
|
| 732 |
if (screen->base.class_3d >= GM107_3D_CLASS) { |
| 733 |
struct nvc0_cb_binding *binding = &screen->cb_bindings[stage][index]; |
| 734 |
|
| 735 |
// TODO: Better figure out the conditions in which this is needed |
| 736 |
bool serialize = binding->addr == addr && binding->size != size; |
| 737 |
if (can_serialize) |
| 738 |
serialize = serialize && *can_serialize; |
| 739 |
if (serialize) { |
| 740 |
IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0); |
| 741 |
if (can_serialize) |
| 742 |
*can_serialize = false; |
| 743 |
} |
| 744 |
|
| 745 |
binding->addr = addr; |
| 746 |
binding->size = size; |
| 747 |
} |
| 748 |
|
| 749 |
if (size >= 0) { |
| 750 |
BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3); |
| 751 |
PUSH_DATA (push, size); |
| 752 |
PUSH_DATAh(push, addr); |
| 753 |
PUSH_DATA (push, addr); |
| 754 |
} |
| 755 |
IMMED_NVC0(push, NVC0_3D(CB_BIND(stage)), (index << 4) | (size >= 0)); |
| 756 |
} |
| 757 |
|
| 758 |
#define FAIL_SCREEN_INIT(str, err) \ |
| 759 |
do { \ |
| 760 |
NOUVEAU_ERR(str, err); \ |
| 761 |
goto fail; \ |
| 762 |
} while(0) |
| 763 |
|
| 764 |
struct nouveau_screen * |
| 765 |
nvc0_screen_create(struct nouveau_device *dev) |
| 766 |
{ |
| 767 |
struct nvc0_screen *screen; |
| 768 |
struct pipe_screen *pscreen; |
| 769 |
struct nouveau_object *chan; |
| 770 |
|
| 771 |
struct nouveau_pushbuf *push; |
| 772 |
uint64_t value; |
| 773 |
uint32_t flags; |
| 774 |
int ret; |
| 775 |
unsigned i; |
| 776 |
|
| 777 |
switch (dev->chipset & ~0xf) { |
| 778 |
case 0xc0: |
| 779 |
case 0xd0: |
| 780 |
case 0xe0: |
| 781 |
case 0xf0: |
| 782 |
case 0x100: |
| 783 |
case 0x110: |
| 784 |
case 0x120: |
| 785 |
case 0x130: |
| 786 |
case 0x140: |
| 787 |
case 0x160: |
| 788 |
case 0x170: |
| 789 |
case 0x190: |
| 790 |
break; |
| 791 |
default: |
| 792 |
return NULL; |
| 793 |
} |
| 794 |
|
| 795 |
screen = CALLOC_STRUCT(nvc0_screen); |
| 796 |
if (!screen) |
| 797 |
return NULL; |
| 798 |
pscreen = &screen->base.base; |
| 799 |
pscreen->destroy = nvc0_screen_destroy; |
| 800 |
|
| 801 |
simple_mtx_init(&screen->state_lock, mtx_plain); |
| 802 |
|
| 803 |
ret = nouveau_screen_init(&screen->base, dev); |
| 804 |
if (ret) |
| 805 |
FAIL_SCREEN_INIT("Base screen init failed: %d\n", ret); |
| 806 |
chan = screen->base.channel; |
| 807 |
push = screen->base.pushbuf; |
| 808 |
push->rsvd_kick = 5; |
| 809 |
|
| 810 |
/* TODO: could this be higher on Kepler+? how does reclocking vs no |
| 811 |
* reclocking affect performance? |
| 812 |
* TODO: could this be higher on Fermi? |
| 813 |
*/ |
| 814 |
if (dev->chipset >= 0xe0) |
| 815 |
screen->base.transfer_pushbuf_threshold = 1024; |
| 816 |
|
| 817 |
screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER | |
| 818 |
PIPE_BIND_SHADER_BUFFER | |
| 819 |
PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER | |
| 820 |
PIPE_BIND_COMMAND_ARGS_BUFFER | PIPE_BIND_QUERY_BUFFER; |
| 821 |
screen->base.sysmem_bindings |= |
| 822 |
PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER; |
| 823 |
|
| 824 |
if (screen->base.vram_domain & NOUVEAU_BO_GART) { |
| 825 |
screen->base.sysmem_bindings |= screen->base.vidmem_bindings; |
| 826 |
screen->base.vidmem_bindings = 0; |
| 827 |
} |
| 828 |
|
| 829 |
for (unsigned i = 0; i <= MESA_SHADER_COMPUTE; i++) |
| 830 |
pscreen->nir_options[i] = nv50_ir_nir_shader_compiler_options(screen->base.device->chipset, i); |
| 831 |
|
| 832 |
pscreen->context_create = nvc0_create; |
| 833 |
pscreen->is_format_supported = nvc0_screen_is_format_supported; |
| 834 |
pscreen->get_sample_pixel_grid = nvc0_screen_get_sample_pixel_grid; |
| 835 |
pscreen->get_driver_query_info = nvc0_screen_get_driver_query_info; |
| 836 |
pscreen->get_driver_query_group_info = nvc0_screen_get_driver_query_group_info; |
| 837 |
|
| 838 |
nvc0_screen_init_resource_functions(pscreen); |
| 839 |
|
| 840 |
screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param; |
| 841 |
screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported; |
| 842 |
|
| 843 |
flags = NOUVEAU_BO_GART | NOUVEAU_BO_MAP; |
| 844 |
if (screen->base.drm->version >= 0x01000202) |
| 845 |
flags |= NOUVEAU_BO_COHERENT; |
| 846 |
|
| 847 |
ret = nouveau_bo_new(dev, flags, 0, 4096, NULL, &screen->fence.bo); |
| 848 |
if (ret) |
| 849 |
FAIL_SCREEN_INIT("Error allocating fence BO: %d\n", ret); |
| 850 |
BO_MAP(&screen->base, screen->fence.bo, 0, NULL); |
| 851 |
screen->fence.map = screen->fence.bo->map; |
| 852 |
screen->base.fence.emit = nvc0_screen_fence_emit; |
| 853 |
screen->base.fence.update = nvc0_screen_fence_update; |
| 854 |
|
| 855 |
if (dev->chipset < 0x140) { |
| 856 |
ret = nouveau_object_new(chan, (dev->chipset < 0xe0) ? 0x1f906e : 0x906e, |
| 857 |
NVIF_CLASS_SW_GF100, NULL, 0, &screen->nvsw); |
| 858 |
if (ret) |
| 859 |
FAIL_SCREEN_INIT("Error creating SW object: %d\n", ret); |
| 860 |
|
| 861 |
BEGIN_NVC0(push, SUBC_SW(NV01_SUBCHAN_OBJECT), 1); |
| 862 |
PUSH_DATA (push, screen->nvsw->handle); |
| 863 |
} |
| 864 |
|
| 865 |
const struct nouveau_mclass m2mfs[] = { |
| 866 |
{ NVF0_P2MF_CLASS, -1 }, |
| 867 |
{ NVE4_P2MF_CLASS, -1 }, |
| 868 |
{ NVC0_M2MF_CLASS, -1 }, |
| 869 |
{} |
| 870 |
}; |
| 871 |
|
| 872 |
ret = nouveau_object_mclass(chan, m2mfs); |
| 873 |
if (ret < 0) |
| 874 |
FAIL_SCREEN_INIT("No supported m2mf class: %d\n", ret); |
| 875 |
|
| 876 |
ret = nouveau_object_new(chan, 0xbeef323f, m2mfs[ret].oclass, NULL, 0, |
| 877 |
&screen->m2mf); |
| 878 |
if (ret) |
| 879 |
FAIL_SCREEN_INIT("Error allocating PGRAPH context for M2MF: %d\n", ret); |
| 880 |
|
| 881 |
BEGIN_NVC0(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1); |
| 882 |
PUSH_DATA (push, screen->m2mf->oclass); |
| 883 |
|
| 884 |
if (screen->m2mf->oclass >= NVE4_P2MF_CLASS) { |
| 885 |
const struct nouveau_mclass copys[] = { |
| 886 |
{ AMPERE_DMA_COPY_B, -1 }, |
| 887 |
{ AMPERE_DMA_COPY_A, -1 }, |
| 888 |
{ TURING_DMA_COPY_A, -1 }, |
| 889 |
{ VOLTA_DMA_COPY_A, -1 }, |
| 890 |
{ PASCAL_DMA_COPY_B, -1 }, |
| 891 |
{ PASCAL_DMA_COPY_A, -1 }, |
| 892 |
{ MAXWELL_DMA_COPY_A, -1 }, |
| 893 |
{ KEPLER_DMA_COPY_A, -1 }, |
| 894 |
{} |
| 895 |
}; |
| 896 |
|
| 897 |
ret = nouveau_object_mclass(chan, copys); |
| 898 |
if (ret < 0) |
| 899 |
FAIL_SCREEN_INIT("No supported copy engine class: %d\n", ret); |
| 900 |
|
| 901 |
ret = nouveau_object_new(chan, 0, copys[ret].oclass, NULL, 0, &screen->copy); |
| 902 |
if (ret) |
| 903 |
FAIL_SCREEN_INIT("Error allocating copy engine class: %d\n", ret); |
| 904 |
|
| 905 |
BEGIN_NVC0(push, SUBC_COPY(NV01_SUBCHAN_OBJECT), 1); |
| 906 |
PUSH_DATA (push, screen->copy->oclass); |
| 907 |
} |
| 908 |
|
| 909 |
ret = nouveau_object_new(chan, 0xbeef902d, NVC0_2D_CLASS, NULL, 0, |
| 910 |
&screen->eng2d); |
| 911 |
if (ret) |
| 912 |
FAIL_SCREEN_INIT("Error allocating PGRAPH context for 2D: %d\n", ret); |
| 913 |
|
| 914 |
BEGIN_NVC0(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1); |
| 915 |
PUSH_DATA (push, screen->eng2d->oclass); |
| 916 |
BEGIN_NVC0(push, SUBC_2D(NVC0_2D_SINGLE_GPC), 1); |
| 917 |
PUSH_DATA (push, 0); |
| 918 |
BEGIN_NVC0(push, NVC0_2D(OPERATION), 1); |
| 919 |
PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY); |
| 920 |
BEGIN_NVC0(push, NVC0_2D(CLIP_ENABLE), 1); |
| 921 |
PUSH_DATA (push, 0); |
| 922 |
BEGIN_NVC0(push, NVC0_2D(COLOR_KEY_ENABLE), 1); |
| 923 |
PUSH_DATA (push, 0); |
| 924 |
BEGIN_NVC0(push, NVC0_2D(SET_PIXELS_FROM_MEMORY_CORRAL_SIZE), 1); |
| 925 |
PUSH_DATA (push, 0x3f); |
| 926 |
BEGIN_NVC0(push, NVC0_2D(SET_PIXELS_FROM_MEMORY_SAFE_OVERLAP), 1); |
| 927 |
PUSH_DATA (push, 1); |
| 928 |
BEGIN_NVC0(push, NVC0_2D(COND_MODE), 1); |
| 929 |
PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS); |
| 930 |
|
| 931 |
BEGIN_NVC0(push, SUBC_2D(NVC0_GRAPH_NOTIFY_ADDRESS_HIGH), 2); |
| 932 |
PUSH_DATAh(push, screen->fence.bo->offset + 16); |
| 933 |
PUSH_DATA (push, screen->fence.bo->offset + 16); |
| 934 |
|
| 935 |
const struct nouveau_mclass threeds[] = { |
| 936 |
{ AD102_3D_CLASS, -1 }, |
| 937 |
{ GA102_3D_CLASS, -1 }, |
| 938 |
{ TU102_3D_CLASS, -1 }, |
| 939 |
{ GV100_3D_CLASS, -1 }, |
| 940 |
{ GP102_3D_CLASS, -1 }, |
| 941 |
{ GP100_3D_CLASS, -1 }, |
| 942 |
{ GM200_3D_CLASS, -1 }, |
| 943 |
{ GM107_3D_CLASS, -1 }, |
| 944 |
{ NVF0_3D_CLASS, -1 }, |
| 945 |
{ NVEA_3D_CLASS, -1 }, |
| 946 |
{ NVE4_3D_CLASS, -1 }, |
| 947 |
{ NVC8_3D_CLASS, -1 }, |
| 948 |
{ NVC1_3D_CLASS, -1 }, |
| 949 |
{ NVC0_3D_CLASS, -1 }, |
| 950 |
{} |
| 951 |
}; |
| 952 |
|
| 953 |
ret = nouveau_object_mclass(chan, threeds); |
| 954 |
if (ret < 0) |
| 955 |
FAIL_SCREEN_INIT("No supported 3d class: %d\n", ret); |
| 956 |
|
| 957 |
ret = nouveau_object_new(chan, 0xbeef003d, threeds[ret].oclass, NULL, 0, |
| 958 |
&screen->eng3d); |
| 959 |
if (ret) |
| 960 |
FAIL_SCREEN_INIT("Error allocating PGRAPH context for 3D: %d\n", ret); |
| 961 |
screen->base.class_3d = screen->eng3d->oclass; |
| 962 |
|
| 963 |
BEGIN_NVC0(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1); |
| 964 |
PUSH_DATA (push, screen->eng3d->oclass); |
| 965 |
|
| 966 |
BEGIN_NVC0(push, NVC0_3D(COND_MODE), 1); |
| 967 |
PUSH_DATA (push, NVC0_3D_COND_MODE_ALWAYS); |
| 968 |
|
| 969 |
if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", true)) { |
| 970 |
/* kill shaders after about 1 second (at 100 MHz) */ |
| 971 |
BEGIN_NVC0(push, NVC0_3D(WATCHDOG_TIMER), 1); |
| 972 |
PUSH_DATA (push, 0x17); |
| 973 |
} |
| 974 |
|
| 975 |
IMMED_NVC0(push, NVC0_3D(ZETA_COMP_ENABLE), |
| 976 |
screen->base.drm->version >= 0x01000101); |
| 977 |
BEGIN_NVC0(push, NVC0_3D(RT_COMP_ENABLE(0)), 8); |
| 978 |
for (i = 0; i < 8; ++i) |
| 979 |
PUSH_DATA(push, screen->base.drm->version >= 0x01000101); |
| 980 |
|
| 981 |
BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1); |
| 982 |
PUSH_DATA (push, 1); |
| 983 |
|
| 984 |
BEGIN_NVC0(push, NVC0_3D(CSAA_ENABLE), 1); |
| 985 |
PUSH_DATA (push, 0); |
| 986 |
BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_ENABLE), 1); |
| 987 |
PUSH_DATA (push, 0); |
| 988 |
BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 1); |
| 989 |
PUSH_DATA (push, NVC0_3D_MULTISAMPLE_MODE_MS1); |
| 990 |
BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_CTRL), 1); |
| 991 |
PUSH_DATA (push, 0); |
| 992 |
BEGIN_NVC0(push, NVC0_3D(LINE_WIDTH_SEPARATE), 1); |
| 993 |
PUSH_DATA (push, 1); |
| 994 |
BEGIN_NVC0(push, NVC0_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1); |
| 995 |
PUSH_DATA (push, 1); |
| 996 |
BEGIN_NVC0(push, NVC0_3D(BLEND_SEPARATE_ALPHA), 1); |
| 997 |
PUSH_DATA (push, 1); |
| 998 |
BEGIN_NVC0(push, NVC0_3D(BLEND_ENABLE_COMMON), 1); |
| 999 |
PUSH_DATA (push, 0); |
| 1000 |
BEGIN_NVC0(push, NVC0_3D(SHADE_MODEL), 1); |
| 1001 |
PUSH_DATA (push, NVC0_3D_SHADE_MODEL_SMOOTH); |
| 1002 |
if (screen->eng3d->oclass < NVE4_3D_CLASS) { |
| 1003 |
IMMED_NVC0(push, NVC0_3D(TEX_MISC), 0); |
| 1004 |
} else if (screen->eng3d->oclass < GA102_3D_CLASS) { |
| 1005 |
BEGIN_NVC0(push, NVE4_3D(TEX_CB_INDEX), 1); |
| 1006 |
PUSH_DATA (push, 15); |
| 1007 |
} |
| 1008 |
BEGIN_NVC0(push, NVC0_3D(CALL_LIMIT_LOG), 1); |
| 1009 |
PUSH_DATA (push, 8); /* 128 */ |
| 1010 |
BEGIN_NVC0(push, NVC0_3D(ZCULL_STATCTRS_ENABLE), 1); |
| 1011 |
PUSH_DATA (push, 1); |
| 1012 |
if (screen->eng3d->oclass >= NVC1_3D_CLASS) { |
| 1013 |
BEGIN_NVC0(push, NVC0_3D(CACHE_SPLIT), 1); |
| 1014 |
PUSH_DATA (push, NVC0_3D_CACHE_SPLIT_48K_SHARED_16K_L1); |
| 1015 |
} |
| 1016 |
|
| 1017 |
nvc0_magic_3d_init(push, screen->eng3d->oclass); |
| 1018 |
|
| 1019 |
ret = nvc0_screen_resize_text_area(screen, push, 1 << 19); |
| 1020 |
if (ret) |
| 1021 |
FAIL_SCREEN_INIT("Error allocating TEXT area: %d\n", ret); |
| 1022 |
|
| 1023 |
/* 6 user uniform areas, 6 driver areas, and 1 for the runout */ |
| 1024 |
ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 12, 13 << 16, NULL, |
| 1025 |
&screen->uniform_bo); |
| 1026 |
if (ret) |
| 1027 |
FAIL_SCREEN_INIT("Error allocating uniform BO: %d\n", ret); |
| 1028 |
|
| 1029 |
PUSH_REF1 (push, screen->uniform_bo, NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_WR); |
| 1030 |
|
| 1031 |
/* return { 0.0, 0.0, 0.0, 0.0 } for out-of-bounds vtxbuf access */ |
| 1032 |
BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3); |
| 1033 |
PUSH_DATA (push, 256); |
| 1034 |
PUSH_DATAh(push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO); |
| 1035 |
PUSH_DATA (push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO); |
| 1036 |
BEGIN_1IC0(push, NVC0_3D(CB_POS), 5); |
| 1037 |
PUSH_DATA (push, 0); |
| 1038 |
PUSH_DATAf(push, 0.0f); |
| 1039 |
PUSH_DATAf(push, 0.0f); |
| 1040 |
PUSH_DATAf(push, 0.0f); |
| 1041 |
PUSH_DATAf(push, 0.0f); |
| 1042 |
BEGIN_NVC0(push, NVC0_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2); |
| 1043 |
PUSH_DATAh(push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO); |
| 1044 |
PUSH_DATA (push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO); |
| 1045 |
|
| 1046 |
if (screen->base.drm->version >= 0x01000101) { |
| 1047 |
ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value); |
| 1048 |
if (ret) |
| 1049 |
FAIL_SCREEN_INIT("NOUVEAU_GETPARAM_GRAPH_UNITS failed: %d\n", ret); |
| 1050 |
} else { |
| 1051 |
if (dev->chipset >= 0xe0 && dev->chipset < 0xf0) |
| 1052 |
value = (8 << 8) | 4; |
| 1053 |
else |
| 1054 |
value = (16 << 8) | 4; |
| 1055 |
} |
| 1056 |
screen->gpc_count = value & 0x000000ff; |
| 1057 |
screen->mp_count = value >> 8; |
| 1058 |
screen->mp_count_compute = screen->mp_count; |
| 1059 |
|
| 1060 |
ret = nvc0_screen_resize_tls_area(screen, 128 * 16, 0, 0x200); |
| 1061 |
if (ret) |
| 1062 |
FAIL_SCREEN_INIT("Error allocating TLS area: %d\n", ret); |
| 1063 |
|
| 1064 |
BEGIN_NVC0(push, NVC0_3D(TEMP_ADDRESS_HIGH), 4); |
| 1065 |
PUSH_DATAh(push, screen->tls->offset); |
| 1066 |
PUSH_DATA (push, screen->tls->offset); |
| 1067 |
PUSH_DATA (push, screen->tls->size >> 32); |
| 1068 |
PUSH_DATA (push, screen->tls->size); |
| 1069 |
BEGIN_NVC0(push, NVC0_3D(WARP_TEMP_ALLOC), 1); |
| 1070 |
PUSH_DATA (push, 0); |
| 1071 |
/* Reduce likelihood of collision with real buffers by placing the hole at |
| 1072 |
* the top of the 4G area. This will have to be dealt with for real |
| 1073 |
* eventually by blocking off that area from the VM. |
| 1074 |
*/ |
| 1075 |
BEGIN_NVC0(push, NVC0_3D(LOCAL_BASE), 1); |
| 1076 |
PUSH_DATA (push, 0xff << 24); |
| 1077 |
|
| 1078 |
if (screen->eng3d->oclass < GM107_3D_CLASS) { |
| 1079 |
ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 17, 1 << 20, NULL, |
| 1080 |
&screen->poly_cache); |
| 1081 |
if (ret) |
| 1082 |
FAIL_SCREEN_INIT("Error allocating poly cache BO: %d\n", ret); |
| 1083 |
|
| 1084 |
BEGIN_NVC0(push, NVC0_3D(VERTEX_QUARANTINE_ADDRESS_HIGH), 3); |
| 1085 |
PUSH_DATAh(push, screen->poly_cache->offset); |
| 1086 |
PUSH_DATA (push, screen->poly_cache->offset); |
| 1087 |
PUSH_DATA (push, 3); |
| 1088 |
} |
| 1089 |
|
| 1090 |
ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 17, 1 << 17, NULL, |
| 1091 |
&screen->txc); |
| 1092 |
if (ret) |
| 1093 |
FAIL_SCREEN_INIT("Error allocating txc BO: %d\n", ret); |
| 1094 |
|
| 1095 |
BEGIN_NVC0(push, NVC0_3D(TIC_ADDRESS_HIGH), 3); |
| 1096 |
PUSH_DATAh(push, screen->txc->offset); |
| 1097 |
PUSH_DATA (push, screen->txc->offset); |
| 1098 |
PUSH_DATA (push, NVC0_TIC_MAX_ENTRIES - 1); |
| 1099 |
if (screen->eng3d->oclass >= GM107_3D_CLASS) { |
| 1100 |
screen->tic.maxwell = true; |
| 1101 |
if (screen->eng3d->oclass == GM107_3D_CLASS) { |
| 1102 |
screen->tic.maxwell = |
| 1103 |
debug_get_bool_option("NOUVEAU_MAXWELL_TIC", true); |
| 1104 |
IMMED_NVC0(push, SUBC_3D(0x0f10), screen->tic.maxwell); |
| 1105 |
} |
| 1106 |
} |
| 1107 |
|
| 1108 |
BEGIN_NVC0(push, NVC0_3D(TSC_ADDRESS_HIGH), 3); |
| 1109 |
PUSH_DATAh(push, screen->txc->offset + 65536); |
| 1110 |
PUSH_DATA (push, screen->txc->offset + 65536); |
| 1111 |
PUSH_DATA (push, NVC0_TSC_MAX_ENTRIES - 1); |
| 1112 |
|
| 1113 |
BEGIN_NVC0(push, NVC0_3D(SCREEN_Y_CONTROL), 1); |
| 1114 |
PUSH_DATA (push, 0); |
| 1115 |
BEGIN_NVC0(push, NVC0_3D(WINDOW_OFFSET_X), 2); |
| 1116 |
PUSH_DATA (push, 0); |
| 1117 |
PUSH_DATA (push, 0); |
| 1118 |
BEGIN_NVC0(push, NVC0_3D(ZCULL_REGION), 1); /* deactivate ZCULL */ |
| 1119 |
PUSH_DATA (push, 0x3f); |
| 1120 |
|
| 1121 |
BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_MODE), 1); |
| 1122 |
PUSH_DATA (push, NVC0_3D_CLIP_RECTS_MODE_INSIDE_ANY); |
| 1123 |
BEGIN_NVC0(push, NVC0_3D(CLIP_RECT_HORIZ(0)), 8 * 2); |
| 1124 |
for (i = 0; i < 8 * 2; ++i) |
| 1125 |
PUSH_DATA(push, 0); |
| 1126 |
BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_EN), 1); |
| 1127 |
PUSH_DATA (push, 0); |
| 1128 |
BEGIN_NVC0(push, NVC0_3D(CLIPID_ENABLE), 1); |
| 1129 |
PUSH_DATA (push, 0); |
| 1130 |
|
| 1131 |
/* neither scissors, viewport nor stencil mask should affect clears */ |
| 1132 |
BEGIN_NVC0(push, NVC0_3D(CLEAR_FLAGS), 1); |
| 1133 |
PUSH_DATA (push, 0); |
| 1134 |
|
| 1135 |
BEGIN_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1); |
| 1136 |
PUSH_DATA (push, 1); |
| 1137 |
for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { |
| 1138 |
BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(i)), 2); |
| 1139 |
PUSH_DATAf(push, 0.0f); |
| 1140 |
PUSH_DATAf(push, 1.0f); |
| 1141 |
} |
| 1142 |
BEGIN_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 1); |
| 1143 |
PUSH_DATA (push, NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1); |
| 1144 |
|
| 1145 |
/* We use scissors instead of exact view volume clipping, |
| 1146 |
* so they're always enabled. |
| 1147 |
*/ |
| 1148 |
for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { |
| 1149 |
BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(i)), 3); |
| 1150 |
PUSH_DATA (push, 1); |
| 1151 |
PUSH_DATA (push, 16384 << 16); |
| 1152 |
PUSH_DATA (push, 16384 << 16); |
| 1153 |
} |
| 1154 |
|
| 1155 |
if (screen->eng3d->oclass < TU102_3D_CLASS) { |
| 1156 |
#define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n); |
| 1157 |
|
| 1158 |
i = 0; |
| 1159 |
MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_PER_INSTANCE, mme9097_per_instance_bf); |
| 1160 |
MK_MACRO(NVC0_3D_MACRO_BLEND_ENABLES, mme9097_blend_enables); |
| 1161 |
MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_SELECT, mme9097_vertex_array_select); |
| 1162 |
MK_MACRO(NVC0_3D_MACRO_TEP_SELECT, mme9097_tep_select); |
| 1163 |
MK_MACRO(NVC0_3D_MACRO_GP_SELECT, mme9097_gp_select); |
| 1164 |
MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_FRONT, mme9097_poly_mode_front); |
| 1165 |
MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_BACK, mme9097_poly_mode_back); |
| 1166 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT, mme9097_draw_arrays_indirect); |
| 1167 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT, mme9097_draw_elts_indirect); |
| 1168 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT_COUNT, mme9097_draw_arrays_indirect_count); |
| 1169 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT_COUNT, mme9097_draw_elts_indirect_count); |
| 1170 |
MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE, mme9097_query_buffer_write); |
| 1171 |
MK_MACRO(NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE, mme9097_conservative_raster_state); |
| 1172 |
MK_MACRO(NVC0_3D_MACRO_SET_PRIV_REG, mme9097_set_priv_reg); |
| 1173 |
MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER, mme9097_compute_counter); |
| 1174 |
MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER_TO_QUERY, mme9097_compute_counter_to_query); |
| 1175 |
MK_MACRO(NVC0_CP_MACRO_LAUNCH_GRID_INDIRECT, mme90c0_launch_grid_indirect); |
| 1176 |
} else { |
| 1177 |
#undef MK_MACRO |
| 1178 |
#define MK_MACRO(m, n) i = tu102_graph_set_macro(screen, m, i, sizeof(n), n); |
| 1179 |
|
| 1180 |
i = 0; |
| 1181 |
MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_PER_INSTANCE, mmec597_per_instance_bf); |
| 1182 |
MK_MACRO(NVC0_3D_MACRO_BLEND_ENABLES, mmec597_blend_enables); |
| 1183 |
MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_SELECT, mmec597_vertex_array_select); |
| 1184 |
MK_MACRO(NVC0_3D_MACRO_TEP_SELECT, mmec597_tep_select); |
| 1185 |
MK_MACRO(NVC0_3D_MACRO_GP_SELECT, mmec597_gp_select); |
| 1186 |
MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_FRONT, mmec597_poly_mode_front); |
| 1187 |
MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_BACK, mmec597_poly_mode_back); |
| 1188 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT, mmec597_draw_arrays_indirect); |
| 1189 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT, mmec597_draw_elts_indirect); |
| 1190 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT_COUNT, mmec597_draw_arrays_indirect_count); |
| 1191 |
MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT_COUNT, mmec597_draw_elts_indirect_count); |
| 1192 |
MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE, mmec597_query_buffer_write); |
| 1193 |
MK_MACRO(NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE, mmec597_conservative_raster_state); |
| 1194 |
MK_MACRO(NVC0_3D_MACRO_SET_PRIV_REG, mmec597_set_priv_reg); |
| 1195 |
MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER, mmec597_compute_counter); |
| 1196 |
MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER_TO_QUERY, mmec597_compute_counter_to_query); |
| 1197 |
} |
| 1198 |
|
| 1199 |
BEGIN_NVC0(push, NVC0_3D(RASTERIZE_ENABLE), 1); |
| 1200 |
PUSH_DATA (push, 1); |
| 1201 |
BEGIN_NVC0(push, NVC0_3D(RT_SEPARATE_FRAG_DATA), 1); |
| 1202 |
PUSH_DATA (push, 1); |
| 1203 |
BEGIN_NVC0(push, NVC0_3D(MACRO_GP_SELECT), 1); |
| 1204 |
PUSH_DATA (push, 0x40); |
| 1205 |
BEGIN_NVC0(push, NVC0_3D(LAYER), 1); |
| 1206 |
PUSH_DATA (push, 0); |
| 1207 |
BEGIN_NVC0(push, NVC0_3D(MACRO_TEP_SELECT), 1); |
| 1208 |
PUSH_DATA (push, 0x30); |
| 1209 |
BEGIN_NVC0(push, NVC0_3D(PATCH_VERTICES), 1); |
| 1210 |
PUSH_DATA (push, 3); |
| 1211 |
BEGIN_NVC0(push, NVC0_3D(SP_SELECT(2)), 1); |
| 1212 |
PUSH_DATA (push, 0x20); |
| 1213 |
BEGIN_NVC0(push, NVC0_3D(SP_SELECT(0)), 1); |
| 1214 |
PUSH_DATA (push, 0x00); |
| 1215 |
screen->save_state.patch_vertices = 3; |
| 1216 |
|
| 1217 |
BEGIN_NVC0(push, NVC0_3D(POINT_COORD_REPLACE), 1); |
| 1218 |
PUSH_DATA (push, 0); |
| 1219 |
BEGIN_NVC0(push, NVC0_3D(POINT_RASTER_RULES), 1); |
| 1220 |
PUSH_DATA (push, NVC0_3D_POINT_RASTER_RULES_OGL); |
| 1221 |
|
| 1222 |
IMMED_NVC0(push, NVC0_3D(EDGEFLAG), 1); |
| 1223 |
|
| 1224 |
if (nvc0_screen_init_compute(screen)) |
| 1225 |
goto fail; |
| 1226 |
|
| 1227 |
/* XXX: Compute and 3D are somehow aliased on Fermi. */ |
| 1228 |
for (i = 0; i < 5; ++i) { |
| 1229 |
unsigned j = 0; |
| 1230 |
for (j = 0; j < 16; j++) |
| 1231 |
screen->cb_bindings[i][j].size = -1; |
| 1232 |
|
| 1233 |
/* TIC and TSC entries for each unit (nve4+ only) */ |
| 1234 |
/* auxiliary constants (6 user clip planes, base instance id) */ |
| 1235 |
nvc0_screen_bind_cb_3d(screen, push, NULL, i, 15, NVC0_CB_AUX_SIZE, |
| 1236 |
screen->uniform_bo->offset + NVC0_CB_AUX_INFO(i)); |
| 1237 |
if (screen->eng3d->oclass >= NVE4_3D_CLASS) { |
| 1238 |
unsigned j; |
| 1239 |
BEGIN_1IC0(push, NVC0_3D(CB_POS), 9); |
| 1240 |
PUSH_DATA (push, NVC0_CB_AUX_UNK_INFO); |
| 1241 |
for (j = 0; j < 8; ++j) |
| 1242 |
PUSH_DATA(push, j); |
| 1243 |
} else { |
| 1244 |
BEGIN_NVC0(push, NVC0_3D(TEX_LIMITS(i)), 1); |
| 1245 |
PUSH_DATA (push, 0x54); |
| 1246 |
} |
| 1247 |
|
| 1248 |
/* MS sample coordinate offsets: these do not work with _ALT modes ! */ |
| 1249 |
BEGIN_1IC0(push, NVC0_3D(CB_POS), 1 + 2 * 8); |
| 1250 |
PUSH_DATA (push, NVC0_CB_AUX_MS_INFO); |
| 1251 |
PUSH_DATA (push, 0); /* 0 */ |
| 1252 |
PUSH_DATA (push, 0); |
| 1253 |
PUSH_DATA (push, 1); /* 1 */ |
| 1254 |
PUSH_DATA (push, 0); |
| 1255 |
PUSH_DATA (push, 0); /* 2 */ |
| 1256 |
PUSH_DATA (push, 1); |
| 1257 |
PUSH_DATA (push, 1); /* 3 */ |
| 1258 |
PUSH_DATA (push, 1); |
| 1259 |
PUSH_DATA (push, 2); /* 4 */ |
| 1260 |
PUSH_DATA (push, 0); |
| 1261 |
PUSH_DATA (push, 3); /* 5 */ |
| 1262 |
PUSH_DATA (push, 0); |
| 1263 |
PUSH_DATA (push, 2); /* 6 */ |
| 1264 |
PUSH_DATA (push, 1); |
| 1265 |
PUSH_DATA (push, 3); /* 7 */ |
| 1266 |
PUSH_DATA (push, 1); |
| 1267 |
} |
| 1268 |
BEGIN_NVC0(push, NVC0_3D(LINKED_TSC), 1); |
| 1269 |
PUSH_DATA (push, 0); |
| 1270 |
|
| 1271 |
/* requires Nvidia provided firmware */ |
| 1272 |
if (screen->eng3d->oclass >= GM200_3D_CLASS) { |
| 1273 |
unsigned reg = screen->eng3d->oclass >= GV100_3D_CLASS ? 0x419ba4 : 0x419f78; |
| 1274 |
BEGIN_1IC0(push, NVC0_3D(MACRO_SET_PRIV_REG), 3); |
| 1275 |
PUSH_DATA (push, reg); |
| 1276 |
PUSH_DATA (push, 0x00000000); |
| 1277 |
PUSH_DATA (push, 0x00000008); |
| 1278 |
} |
| 1279 |
|
| 1280 |
PUSH_KICK (push); |
| 1281 |
|
| 1282 |
screen->tic.entries = CALLOC( |
| 1283 |
NVC0_TIC_MAX_ENTRIES + NVC0_TSC_MAX_ENTRIES + NVE4_IMG_MAX_HANDLES, |
| 1284 |
sizeof(void *)); |
| 1285 |
screen->tsc.entries = screen->tic.entries + NVC0_TIC_MAX_ENTRIES; |
| 1286 |
screen->img.entries = (void *)(screen->tsc.entries + NVC0_TSC_MAX_ENTRIES); |
| 1287 |
|
| 1288 |
if (!nvc0_blitter_create(screen)) |
| 1289 |
goto fail; |
| 1290 |
|
| 1291 |
nouveau_device_set_classes_for_debug(dev, |
| 1292 |
screen->eng3d->oclass, |
| 1293 |
screen->compute->oclass, |
| 1294 |
screen->m2mf->oclass, |
| 1295 |
screen->copy ? screen->copy->oclass : 0); |
| 1296 |
|
| 1297 |
nvc0_init_shader_caps(screen); |
| 1298 |
nvc0_init_compute_caps(screen); |
| 1299 |
nvc0_init_screen_caps(screen); |
| 1300 |
|
| 1301 |
return &screen->base; |
| 1302 |
|
| 1303 |
fail: |
| 1304 |
screen->base.base.context_create = NULL; |
| 1305 |
return &screen->base; |
| 1306 |
} |
| 1307 |
|
| 1308 |
int |
| 1309 |
nvc0_screen_tic_alloc(struct nvc0_screen *screen, void *entry) |
| 1310 |
{ |
| 1311 |
int i = screen->tic.next; |
| 1312 |
|
| 1313 |
while (screen->tic.lock[i / 32] & (1 << (i % 32))) |
| 1314 |
i = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1); |
| 1315 |
|
| 1316 |
screen->tic.next = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1); |
| 1317 |
|
| 1318 |
if (screen->tic.entries[i]) |
| 1319 |
nv50_tic_entry(screen->tic.entries[i])->id = -1; |
| 1320 |
|
| 1321 |
screen->tic.entries[i] = entry; |
| 1322 |
return i; |
| 1323 |
} |
| 1324 |
|
| 1325 |
int |
| 1326 |
nvc0_screen_tsc_alloc(struct nvc0_screen *screen, void *entry) |
| 1327 |
{ |
| 1328 |
int i = screen->tsc.next; |
| 1329 |
|
| 1330 |
while (screen->tsc.lock[i / 32] & (1 << (i % 32))) |
| 1331 |
i = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1); |
| 1332 |
|
| 1333 |
screen->tsc.next = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1); |
| 1334 |
|
| 1335 |
if (screen->tsc.entries[i]) |
| 1336 |
nv50_tsc_entry(screen->tsc.entries[i])->id = -1; |
| 1337 |
|
| 1338 |
screen->tsc.entries[i] = entry; |
| 1339 |
return i; |
| 1340 |
} |