blob: 0f25cd5fedd7523304b39817548bb5c1ed02b17a [file] [log] [blame]
Ben Skeggs857a3292008-07-11 20:44:39 +10001/*
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01002 * Copyright 2010 Christoph Bumiller
Ben Skeggs857a3292008-07-11 20:44:39 +10003 *
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
Kenneth Graunke3d8d5b22013-04-21 13:46:48 -070017 * 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.
Ben Skeggs857a3292008-07-11 20:44:39 +100021 */
22
Emil Velikov2b5f3952014-08-14 21:05:35 +010023#include <errno.h>
24#include <xf86drm.h>
25#include <nouveau_drm.h>
Marcin Slusarzb5dfc382011-04-16 22:15:52 +020026#include "util/u_format.h"
Xavier Chantry6ddd6402010-05-05 14:39:59 +020027#include "util/u_format_s3tc.h"
Ben Skeggs84cc07d2008-02-29 15:03:57 +110028#include "pipe/p_screen.h"
Ben Skeggs84cc07d2008-02-29 15:03:57 +110029
Johannes Obermayr5eb7ff12013-08-20 20:14:00 +020030#include "nv50/nv50_context.h"
31#include "nv50/nv50_screen.h"
Ben Skeggs84cc07d2008-02-29 15:03:57 +110032
Johannes Obermayr5eb7ff12013-08-20 20:14:00 +020033#include "nouveau_vp3_video.h"
Ilia Mirkina2061ee2013-08-10 20:19:24 -040034
Johannes Obermayr5eb7ff12013-08-20 20:14:00 +020035#include "nv_object.xml.h"
Christoph Bumiller4de293b2010-08-15 21:37:50 +020036
Marcin Slusarz1906d2b2012-06-27 14:45:17 +020037/* affected by LOCAL_WARPS_LOG_ALLOC / LOCAL_WARPS_NO_CLAMP */
38#define LOCAL_WARPS_ALLOC 32
39/* affected by STACK_WARPS_LOG_ALLOC / STACK_WARPS_NO_CLAMP */
40#define STACK_WARPS_ALLOC 32
41
42#define THREADS_IN_WARP 32
43
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010044static boolean
45nv50_screen_is_format_supported(struct pipe_screen *pscreen,
46 enum pipe_format format,
47 enum pipe_texture_target target,
48 unsigned sample_count,
Marek Olšáke9689752011-03-08 00:01:58 +010049 unsigned bindings)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010050{
Christoph Bumiller7d2d4502013-01-19 20:53:22 +010051 if (sample_count > 8)
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +020052 return false;
Christoph Bumiller9f499862011-08-27 17:31:04 +020053 if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +020054 return false;
Christoph Bumillerb2dcf882011-07-11 18:02:27 +020055 if (sample_count == 8 && util_format_get_blocksizebits(format) >= 128)
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +020056 return false;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010057
Marek Olšák75fa5c92011-04-11 06:23:00 +020058 if (!util_format_is_supported(format, bindings))
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +020059 return false;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010060
61 switch (format) {
62 case PIPE_FORMAT_Z16_UNORM:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +020063 if (nv50_screen(pscreen)->tesla->oclass < NVA0_3D_CLASS)
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +020064 return false;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010065 break;
66 default:
67 break;
68 }
69
Ilia Mirkindf03be12016-03-31 21:52:13 -040070 if (bindings & PIPE_BIND_LINEAR)
71 if (util_format_is_depth_or_stencil(format) ||
72 (target != PIPE_TEXTURE_1D &&
73 target != PIPE_TEXTURE_2D &&
74 target != PIPE_TEXTURE_RECT) ||
75 sample_count > 1)
76 return false;
77
Marek Olšák5981ab52016-09-07 21:24:08 +020078 /* shared is always supported */
79 bindings &= ~(PIPE_BIND_LINEAR |
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010080 PIPE_BIND_SHARED);
81
Ben Skeggs346d7a22016-02-15 15:37:29 +100082 return (( nv50_format_table[format].usage |
83 nv50_vertex_format[format].usage) & bindings) == bindings;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010084}
85
86static int
87nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
88{
Christoph Bumiller02fac292012-05-03 12:50:08 +020089 const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
Emil Velikov2b5f3952014-08-14 21:05:35 +010090 struct nouveau_device *dev = nouveau_screen(pscreen)->device;
Christoph Bumiller02fac292012-05-03 12:50:08 +020091
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010092 switch (param) {
Ilia Mirkin22e95512014-06-16 03:25:44 -040093 /* non-boolean caps */
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010094 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
Adel Gadllahfc8196f2011-10-24 19:41:03 +020095 return 14;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010096 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
Adel Gadllahfc8196f2011-10-24 19:41:03 +020097 return 12;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +010098 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
Adel Gadllahfc8196f2011-10-24 19:41:03 +020099 return 14;
Christoph Bumiller8a44ecd2012-04-24 23:21:41 +0200100 case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
101 return 512;
Ilia Mirkinc2f9ad52014-04-09 14:58:53 -0400102 case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
Christoph Bumillerd53c49b2011-09-05 15:31:28 +0200103 case PIPE_CAP_MIN_TEXEL_OFFSET:
Christoph Bumiller0bbf1652012-04-14 21:42:52 +0200104 return -8;
Ilia Mirkinc2f9ad52014-04-09 14:58:53 -0400105 case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
Christoph Bumillerd53c49b2011-09-05 15:31:28 +0200106 case PIPE_CAP_MAX_TEXEL_OFFSET:
Christoph Bumiller0bbf1652012-04-14 21:42:52 +0200107 return 7;
Marek Olšák52cb3952013-05-02 03:24:33 +0200108 case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
Ilia Mirkin7a275fc2015-09-15 19:39:25 -0400109 return 128 * 1024 * 1024;
Christoph Bumiller672ad902012-01-29 13:24:11 +0100110 case PIPE_CAP_GLSL_FEATURE_LEVEL:
Ilia Mirkin839bd3c2014-01-15 05:48:51 -0500111 return 330;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100112 case PIPE_CAP_MAX_RENDER_TARGETS:
113 return 8;
Christoph Bumiller802d02c2012-04-14 02:39:16 +0200114 case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
115 return 1;
Marek Olšák861a0292011-12-15 18:42:21 +0100116 case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
Christoph Bumiller02fac292012-05-03 12:50:08 +0200117 return 4;
Christoph Bumillerf37c3a32012-01-07 00:39:54 +0100118 case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
Christoph Bumillerf37c3a32012-01-07 00:39:54 +0100119 case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
Christoph Bumiller02fac292012-05-03 12:50:08 +0200120 return 64;
Grigori Goronzyd34d5fd2014-02-09 22:56:20 +0100121 case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
122 case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
123 return 1024;
Ilia Mirkin746e5262014-06-26 20:01:50 -0400124 case PIPE_CAP_MAX_VERTEX_STREAMS:
125 return 1;
Timothy Arceri89e68062014-08-19 21:09:58 -1000126 case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
127 return 2048;
Ilia Mirkin22e95512014-06-16 03:25:44 -0400128 case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
129 return 256;
130 case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
Ilia Mirkinaa3b85f2016-02-27 15:30:34 -0500131 return 16; /* 256 for binding as RT, but that's not possible in GL */
Ilia Mirkin22e95512014-06-16 03:25:44 -0400132 case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
133 return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
134 case PIPE_CAP_MAX_VIEWPORTS:
135 return NV50_MAX_VIEWPORTS;
136 case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
137 return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50;
138 case PIPE_CAP_ENDIANNESS:
139 return PIPE_ENDIAN_LITTLE;
140 case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
141 return (class_3d >= NVA3_3D_CLASS) ? 4 : 0;
Ilia Mirkin194bcb42016-06-12 16:05:31 -0400142 case PIPE_CAP_MAX_WINDOW_RECTANGLES:
143 return NV50_MAX_WINDOW_RECTANGLES;
Ilia Mirkin22e95512014-06-16 03:25:44 -0400144
145 /* supported caps */
146 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
147 case PIPE_CAP_TEXTURE_SWIZZLE:
148 case PIPE_CAP_TEXTURE_SHADOW_MAP:
149 case PIPE_CAP_NPOT_TEXTURES:
150 case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
Ilia Mirkin9515d652016-08-20 22:40:33 -0400151 case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
Ilia Mirkin22e95512014-06-16 03:25:44 -0400152 case PIPE_CAP_ANISOTROPIC_FILTER:
153 case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
154 case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
155 case PIPE_CAP_TWO_SIDED_STENCIL:
156 case PIPE_CAP_DEPTH_CLIP_DISABLE:
157 case PIPE_CAP_POINT_SPRITE:
158 case PIPE_CAP_SM3:
159 case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
160 case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
161 case PIPE_CAP_VERTEX_COLOR_CLAMPED:
162 case PIPE_CAP_QUERY_TIMESTAMP:
163 case PIPE_CAP_QUERY_TIME_ELAPSED:
164 case PIPE_CAP_OCCLUSION_QUERY:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100165 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
166 case PIPE_CAP_INDEP_BLEND_ENABLE:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100167 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
168 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100169 case PIPE_CAP_PRIMITIVE_RESTART:
Marek Olšák95c78812011-03-05 16:06:10 +0100170 case PIPE_CAP_TGSI_INSTANCEID:
171 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
Marek Olšák4a7f0132011-03-29 18:18:05 +0200172 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
Marek Olšák3d13b082011-09-27 23:08:04 +0200173 case PIPE_CAP_CONDITIONAL_RENDER:
Marek Olšákba890862011-09-27 23:18:17 +0200174 case PIPE_CAP_TEXTURE_BARRIER:
Christoph Bumiller8b4f7b02012-02-06 16:29:03 +0100175 case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
Fredrik Höglundaf372122012-06-18 22:50:02 +0200176 case PIPE_CAP_START_INSTANCE:
Marek Olšák437ab1d2012-04-24 15:19:31 +0200177 case PIPE_CAP_USER_CONSTANT_BUFFERS:
Christoph Bumillere6caafd2012-05-16 21:08:37 +0200178 case PIPE_CAP_USER_VERTEX_BUFFERS:
Ilia Mirkin22e95512014-06-16 03:25:44 -0400179 case PIPE_CAP_TEXTURE_MULTISAMPLE:
180 case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
Ilia Mirkinf08d7b82014-08-14 00:17:17 -0400181 case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
Ilia Mirkin95058bd2014-08-20 20:19:38 -0400182 case PIPE_CAP_SAMPLER_VIEW_TARGET:
Tobias Klausmann1a170982014-09-22 04:40:58 +0200183 case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
Ilia Mirkin3bc42a02014-10-23 00:43:45 -0400184 case PIPE_CAP_CLIP_HALFZ:
Ilia Mirkin7c211a12015-02-01 09:01:50 -0500185 case PIPE_CAP_POLYGON_OFFSET_CLAMP:
Ilia Mirkin5000a5f2015-02-18 03:35:23 -0500186 case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
Marek Olšák44dc1d32015-08-10 19:37:01 +0200187 case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
188 case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
Ilia Mirkina6bf20d2015-08-11 11:59:56 -0400189 case PIPE_CAP_DEPTH_BOUNDS_TEST:
Ilia Mirkin4294db92015-09-10 22:07:27 -0400190 case PIPE_CAP_TGSI_TXQS:
Ilia Mirkind0693d72015-10-28 20:52:50 -0400191 case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
Ilia Mirkin06fa2e82015-10-29 23:25:08 -0400192 case PIPE_CAP_SHAREABLE_SHADERS:
Ilia Mirkinc4182bb2015-11-09 12:39:05 -0500193 case PIPE_CAP_CLEAR_TEXTURE:
Samuel Pitoisetff724402015-10-14 21:42:41 +0200194 case PIPE_CAP_COMPUTE:
Ilia Mirkine3706a72016-01-08 17:32:56 -0500195 case PIPE_CAP_TGSI_FS_FACE_IS_INTEGER_SYSVAL:
Ilia Mirkinf9480d72016-04-03 15:11:39 -0400196 case PIPE_CAP_INVALIDATE_BUFFER:
Ilia Mirkin59ca9212016-04-03 16:02:59 -0400197 case PIPE_CAP_STRING_MARKER:
Tobias Klausmann8c029392016-05-08 22:44:11 +0200198 case PIPE_CAP_CULL_DISTANCE:
Ilia Mirkinafb6dc52016-10-13 21:39:42 -0400199 case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
Ilia Mirkinb755f2f2017-01-14 18:55:25 -0500200 case PIPE_CAP_TGSI_MUL_ZERO_WINS:
Ilia Mirkin0e9232d2017-03-15 23:29:47 -0400201 case PIPE_CAP_TGSI_TEX_TXF_LZ:
Boyan Dingb1b189a2017-04-04 22:44:47 +0800202 case PIPE_CAP_TGSI_CLOCK:
Marek Olšák70dcb732017-04-30 01:18:43 +0200203 case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
Marek Olšák50189372017-05-15 16:30:30 +0200204 case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
Marek Olšák978c1aa12012-04-11 15:40:00 +0200205 return 1;
Ilia Mirkin22e95512014-06-16 03:25:44 -0400206 case PIPE_CAP_SEAMLESS_CUBE_MAP:
207 return 1; /* class_3d >= NVA0_3D_CLASS; */
208 /* supported on nva0+ */
209 case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
210 return class_3d >= NVA0_3D_CLASS;
211 /* supported on nva3+ */
212 case PIPE_CAP_CUBE_MAP_ARRAY:
213 case PIPE_CAP_INDEP_BLEND_FUNC:
214 case PIPE_CAP_TEXTURE_QUERY_LOD:
215 case PIPE_CAP_SAMPLE_SHADING:
Ilia Mirkinf768eaa2015-10-29 22:18:25 -0400216 case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
Ilia Mirkin22e95512014-06-16 03:25:44 -0400217 return class_3d >= NVA3_3D_CLASS;
218
219 /* unsupported caps */
220 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
221 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
222 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
223 case PIPE_CAP_SHADER_STENCIL_EXPORT:
224 case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
Christoph Bumiller587c2212012-04-24 13:34:36 +0200225 case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
226 case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
227 case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
Christoph Bumiller8acaf862013-03-15 22:11:31 +0100228 case PIPE_CAP_TGSI_TEXCOORD:
Ilia Mirkin32b71242014-07-03 11:15:18 -0400229 case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
Dave Airlie2fcbec42013-09-21 18:45:43 +1000230 case PIPE_CAP_TEXTURE_GATHER_SM5:
Dave Airlie76ba50a2013-11-27 19:47:51 +1000231 case PIPE_CAP_FAKE_SW_MSAA:
Ilia Mirkind95df4f2014-04-26 23:44:57 -0400232 case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
Christoph Bumiller4b586a22014-05-17 01:20:19 +0200233 case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
Christoph Bumillerbc198f82013-04-05 14:29:36 +0200234 case PIPE_CAP_DRAW_INDIRECT:
Ilia Mirkind67b9ba2015-12-31 13:30:13 -0500235 case PIPE_CAP_MULTI_DRAW_INDIRECT:
236 case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
Roland Scheideggerade8b262014-12-12 04:13:43 +0100237 case PIPE_CAP_VERTEXID_NOBASE:
Axel Davyeb1c12d2015-01-17 14:30:17 +0100238 case PIPE_CAP_MULTISAMPLE_Z_RESOLVE: /* potentially supported on some hw */
Marek Olšák8b587ee2015-02-10 14:00:57 +0100239 case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
Marek Olšák79ffc08a2015-04-29 15:44:55 +0200240 case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
Marek Olšák26222932015-06-12 14:24:17 +0200241 case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
Ilia Mirkin87b4e4e2015-12-29 16:49:32 -0500242 case PIPE_CAP_DRAW_PARAMETERS:
Ilia Mirkine9f43d62016-01-02 18:55:48 -0500243 case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
Marek Olšák34738a92016-01-02 20:45:00 +0100244 case PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL:
Ilia Mirkinebfb5442016-01-02 21:56:45 -0500245 case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
Charmaine Lee3038e892016-01-14 10:22:17 -0700246 case PIPE_CAP_GENERATE_MIPMAP:
Nicolai Hähnle3abb5482016-01-26 10:26:30 -0500247 case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
Nicolai Hähnle6af6d7b2016-01-26 10:27:58 -0500248 case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
Ilia Mirkinf9e6f462016-01-09 23:30:16 -0500249 case PIPE_CAP_QUERY_BUFFER_OBJECT:
Marek Olšákd2e4c9e2016-02-01 21:56:50 +0100250 case PIPE_CAP_QUERY_MEMORY_INFO:
Marek Olšákdcb2b772016-02-29 20:22:37 +0100251 case PIPE_CAP_PCI_GROUP:
252 case PIPE_CAP_PCI_BUS:
253 case PIPE_CAP_PCI_DEVICE:
254 case PIPE_CAP_PCI_FUNCTION:
Edward O'Callaghan4bc91302016-02-17 20:59:52 +1100255 case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
Bas Nieuwenhuizen70dcd842016-04-12 15:00:31 +0200256 case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
Kenneth Graunke70048eb2016-05-20 21:05:34 -0700257 case PIPE_CAP_PRIMITIVE_RESTART_FOR_PATCHES:
Ilia Mirkinedfa7a42016-05-29 11:39:52 -0400258 case PIPE_CAP_TGSI_VOTE:
Axel Davy59a69292016-06-13 22:28:32 +0200259 case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
Józef Kucia3cd28fe2016-07-19 13:07:24 +0200260 case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
Ilia Mirkin3fdeb7c2016-10-14 00:03:12 -0400261 case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
Nicolai Hähnle611166b2016-11-18 20:49:54 +0100262 case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
Rob Clark026a7222016-04-01 16:10:42 -0400263 case PIPE_CAP_NATIVE_FENCE_FD:
Marek Olšáke51baeb2016-12-31 13:34:11 +0100264 case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
Ilia Mirkinee3ebe62017-01-01 23:10:00 -0500265 case PIPE_CAP_TGSI_FS_FBFETCH:
Nicolai Hähnlea020cb32017-01-27 10:35:13 +0100266 case PIPE_CAP_DOUBLES:
Dave Airlief8045062016-06-09 10:13:03 +1000267 case PIPE_CAP_INT64:
Ilia Mirkinb0900332017-02-04 22:31:29 -0500268 case PIPE_CAP_INT64_DIVMOD:
Lyudeffe2bd62017-03-16 18:00:05 -0400269 case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
Nicolai Hähnled6e6fa02017-02-02 21:10:44 +0100270 case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
Nicolai Hähnled3e6f6d2017-03-30 11:16:09 +0200271 case PIPE_CAP_TGSI_BALLOT:
Nicolai Hähnle17f24a92017-04-13 21:54:54 +0200272 case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
Lyude467af442017-05-24 15:42:39 -0400273 case PIPE_CAP_POST_DEPTH_COVERAGE:
Samuel Pitoiset973822b2017-02-16 13:43:16 +0100274 case PIPE_CAP_BINDLESS_TEXTURE:
Nicolai Hähnle01f15982017-06-25 18:31:11 +0200275 case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
Nicolai Hähnlea6777992017-07-26 19:16:14 +0200276 case PIPE_CAP_QUERY_SO_OVERFLOW:
Timothy Arceri4e4042d2017-08-03 13:54:45 +1000277 case PIPE_CAP_MEMOBJ:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100278 return 0;
Emil Velikov2b5f3952014-08-14 21:05:35 +0100279
280 case PIPE_CAP_VENDOR_ID:
281 return 0x10de;
282 case PIPE_CAP_DEVICE_ID: {
283 uint64_t device_id;
284 if (nouveau_getparam(dev, NOUVEAU_GETPARAM_PCI_DEVICE, &device_id)) {
285 NOUVEAU_ERR("NOUVEAU_GETPARAM_PCI_DEVICE failed.\n");
286 return -1;
287 }
288 return device_id;
289 }
290 case PIPE_CAP_ACCELERATED:
291 return 1;
292 case PIPE_CAP_VIDEO_MEMORY:
293 return dev->vram_size >> 20;
294 case PIPE_CAP_UMA:
295 return 0;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100296 }
Ilia Mirkin22e95512014-06-16 03:25:44 -0400297
298 NOUVEAU_ERR("unknown PIPE_CAP %d\n", param);
299 return 0;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100300}
301
302static int
Brian Paul637e5712017-03-05 12:13:02 -0700303nv50_screen_get_shader_param(struct pipe_screen *pscreen,
304 enum pipe_shader_type shader,
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100305 enum pipe_shader_cap param)
306{
307 switch (shader) {
308 case PIPE_SHADER_VERTEX:
309 case PIPE_SHADER_GEOMETRY:
310 case PIPE_SHADER_FRAGMENT:
311 break;
Samuel Pitoiset89d25a82016-02-19 20:25:10 +0100312 case PIPE_SHADER_COMPUTE:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100313 default:
314 return 0;
315 }
Johannes Obermayr5eb7ff12013-08-20 20:14:00 +0200316
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100317 switch (param) {
318 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
319 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
320 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
321 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
322 return 16384;
323 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
324 return 4;
325 case PIPE_SHADER_CAP_MAX_INPUTS:
326 if (shader == PIPE_SHADER_VERTEX)
327 return 32;
Ilia Mirkinbad88712013-12-01 03:44:42 -0500328 return 15;
Marek Olšák5f5b83c2014-10-01 20:28:17 +0200329 case PIPE_SHADER_CAP_MAX_OUTPUTS:
330 return 16;
Marek Olšák04f2c882014-07-24 20:32:08 +0200331 case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE:
332 return 65536;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100333 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
Christoph Bumillerfcb28682012-05-16 20:52:41 +0200334 return NV50_MAX_PIPE_CONSTBUFS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100335 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
336 return shader != PIPE_SHADER_FRAGMENT;
Ilia Mirkinf4784552016-06-11 11:50:15 -0400337 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100338 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
339 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
340 return 1;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100341 case PIPE_SHADER_CAP_MAX_TEMPS:
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200342 return nv50_screen(pscreen)->max_tls_space / ONE_TEMP_SIZE;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100343 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
344 return 1;
Brian Paul13f3ae52013-02-01 11:16:54 -0700345 case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
Ilia Mirkinc1e4a6b2016-03-12 21:26:21 -0500346 return 1;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100347 case PIPE_SHADER_CAP_SUBROUTINES:
348 return 0; /* please inline, or provide function declarations */
Bryan Cain17b695e2011-05-05 21:10:28 -0500349 case PIPE_SHADER_CAP_INTEGERS:
Christoph Bumiller0bbf1652012-04-14 21:42:52 +0200350 return 1;
Samuel Pitoiset00b50442017-04-25 00:31:49 +0200351 case PIPE_SHADER_CAP_TGSI_SKIP_MERGE_REGISTERS:
352 return 1;
Marek Olšákf5bfe542011-09-27 22:22:06 +0200353 case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
Roland Scheidegger2983c032013-11-26 02:30:41 +0100354 /* The chip could handle more sampler views than samplers */
355 case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
Samuel Pitoiset19a62142015-07-13 13:34:31 +0200356 return MIN2(16, PIPE_MAX_SAMPLERS);
Ilia Mirkinf57a8442016-05-22 14:05:36 -0400357 case PIPE_SHADER_CAP_PREFERRED_IR:
358 return PIPE_SHADER_IR_TGSI;
359 case PIPE_SHADER_CAP_MAX_UNROLL_ITERATIONS_HINT:
360 return 32;
Ilia Mirkinc85a6862015-02-19 23:30:36 -0500361 case PIPE_SHADER_CAP_TGSI_DROUND_SUPPORTED:
362 case PIPE_SHADER_CAP_TGSI_DFRACEXP_DLDEXP_SUPPORTED:
Marek Olšák216543e2015-02-28 00:26:31 +0100363 case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED:
Marek Olšákb6ebe7e2015-05-25 19:30:44 +0200364 case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
Ilia Mirkin266d0012015-09-26 20:27:42 -0400365 case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
Samuel Pitoisetcbf24a02016-02-14 22:51:34 +0100366 case PIPE_SHADER_CAP_SUPPORTED_IRS:
Ilia Mirkin9fbfa1a2016-01-08 22:56:23 -0500367 case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
Marek Olšák72217d42016-10-28 22:34:20 +0200368 case PIPE_SHADER_CAP_LOWER_IF_THRESHOLD:
Ilia Mirkinc85a6862015-02-19 23:30:36 -0500369 return 0;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100370 default:
371 NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
372 return 0;
373 }
374}
375
376static float
Marek Olšákbb71f922011-11-19 22:38:22 +0100377nv50_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100378{
379 switch (param) {
Marek Olšákbb71f922011-11-19 22:38:22 +0100380 case PIPE_CAPF_MAX_LINE_WIDTH:
381 case PIPE_CAPF_MAX_LINE_WIDTH_AA:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100382 return 10.0f;
Marek Olšákbb71f922011-11-19 22:38:22 +0100383 case PIPE_CAPF_MAX_POINT_WIDTH:
384 case PIPE_CAPF_MAX_POINT_WIDTH_AA:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100385 return 64.0f;
Marek Olšákbb71f922011-11-19 22:38:22 +0100386 case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100387 return 16.0f;
Marek Olšákbb71f922011-11-19 22:38:22 +0100388 case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100389 return 4.0f;
Christoph Bumillerb9142c22013-05-25 02:04:25 +0200390 case PIPE_CAPF_GUARD_BAND_LEFT:
391 case PIPE_CAPF_GUARD_BAND_TOP:
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100392 return 0.0f;
Christoph Bumillerb9142c22013-05-25 02:04:25 +0200393 case PIPE_CAPF_GUARD_BAND_RIGHT:
394 case PIPE_CAPF_GUARD_BAND_BOTTOM:
395 return 0.0f; /* that or infinity */
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100396 }
Christoph Bumillerb9142c22013-05-25 02:04:25 +0200397
398 NOUVEAU_ERR("unknown PIPE_CAPF %d\n", param);
399 return 0.0f;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100400}
401
Samuel Pitoisetff724402015-10-14 21:42:41 +0200402static int
403nv50_screen_get_compute_param(struct pipe_screen *pscreen,
Bas Nieuwenhuizen1a5c8c22016-03-25 02:06:50 +0100404 enum pipe_shader_ir ir_type,
Samuel Pitoisetff724402015-10-14 21:42:41 +0200405 enum pipe_compute_cap param, void *data)
406{
407 struct nv50_screen *screen = nv50_screen(pscreen);
408
409#define RET(x) do { \
410 if (data) \
411 memcpy(data, x, sizeof(x)); \
412 return sizeof(x); \
413} while (0)
414
415 switch (param) {
416 case PIPE_COMPUTE_CAP_GRID_DIMENSION:
417 RET((uint64_t []) { 2 });
418 case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
419 RET(((uint64_t []) { 65535, 65535 }));
420 case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
421 RET(((uint64_t []) { 512, 512, 64 }));
422 case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
423 RET((uint64_t []) { 512 });
424 case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: /* g0-15[] */
425 RET((uint64_t []) { 1ULL << 32 });
426 case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: /* s[] */
427 RET((uint64_t []) { 16 << 10 });
428 case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: /* l[] */
429 RET((uint64_t []) { 16 << 10 });
430 case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: /* c[], arbitrary limit */
431 RET((uint64_t []) { 4096 });
432 case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
433 RET((uint32_t []) { 32 });
434 case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
435 RET((uint64_t []) { 1ULL << 40 });
436 case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
437 RET((uint32_t []) { 0 });
438 case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
439 RET((uint32_t []) { screen->mp_count });
440 case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
441 RET((uint32_t []) { 512 }); /* FIXME: arbitrary limit */
Jan Veselyc7af8492016-08-28 04:06:28 -0400442 case PIPE_COMPUTE_CAP_ADDRESS_BITS:
443 RET((uint32_t []) { 32 });
Samuel Pitoiset07bb4512016-09-10 16:31:27 +0200444 case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
445 RET((uint64_t []) { 0 });
Samuel Pitoisetff724402015-10-14 21:42:41 +0200446 default:
447 return 0;
448 }
449
450#undef RET
451}
452
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100453static void
454nv50_screen_destroy(struct pipe_screen *pscreen)
455{
456 struct nv50_screen *screen = nv50_screen(pscreen);
457
Maarten Lankhorstfee06862014-02-12 14:56:53 +0100458 if (!nouveau_drm_screen_unref(&screen->base))
459 return;
460
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000461 if (screen->base.fence.current) {
Ilia Mirkin507f0232014-03-05 22:25:55 -0500462 struct nouveau_fence *current = NULL;
463
464 /* nouveau_fence_wait will create a new current fence, so wait on the
465 * _current_ one, and remove both.
466 */
467 nouveau_fence_ref(screen->base.fence.current, &current);
Ilia Mirkinba093a02015-10-30 20:44:57 -0400468 nouveau_fence_wait(current, NULL);
Ilia Mirkin507f0232014-03-05 22:25:55 -0500469 nouveau_fence_ref(NULL, &current);
470 nouveau_fence_ref(NULL, &screen->base.fence.current);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100471 }
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200472 if (screen->base.pushbuf)
473 screen->base.pushbuf->user_priv = NULL;
474
Christoph Bumiller36ea7442012-09-26 23:06:40 +0200475 if (screen->blitter)
476 nv50_blitter_destroy(screen);
Samuel Pitoiset695ae812015-12-16 22:54:30 +0100477 if (screen->pm.prog) {
478 screen->pm.prog->code = NULL; /* hardcoded, don't FREE */
479 nv50_program_destroy(NULL, screen->pm.prog);
480 FREE(screen->pm.prog);
481 }
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100482
483 nouveau_bo_ref(NULL, &screen->code);
484 nouveau_bo_ref(NULL, &screen->tls_bo);
485 nouveau_bo_ref(NULL, &screen->stack_bo);
486 nouveau_bo_ref(NULL, &screen->txc);
487 nouveau_bo_ref(NULL, &screen->uniforms);
488 nouveau_bo_ref(NULL, &screen->fence.bo);
489
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200490 nouveau_heap_destroy(&screen->vp_code_heap);
491 nouveau_heap_destroy(&screen->gp_code_heap);
492 nouveau_heap_destroy(&screen->fp_code_heap);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100493
Matt Turnerb6109de2012-09-04 23:33:28 -0700494 FREE(screen->tic.entries);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100495
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200496 nouveau_object_del(&screen->tesla);
497 nouveau_object_del(&screen->eng2d);
498 nouveau_object_del(&screen->m2mf);
Samuel Pitoisetff724402015-10-14 21:42:41 +0200499 nouveau_object_del(&screen->compute);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200500 nouveau_object_del(&screen->sync);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100501
502 nouveau_screen_fini(&screen->base);
503
504 FREE(screen);
505}
506
507static void
Marcin Slusarz9849f362011-10-08 23:05:25 +0200508nv50_screen_fence_emit(struct pipe_screen *pscreen, u32 *sequence)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100509{
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000510 struct nv50_screen *screen = nv50_screen(pscreen);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200511 struct nouveau_pushbuf *push = screen->base.pushbuf;
Marcin Slusarz9849f362011-10-08 23:05:25 +0200512
513 /* we need to do it after possible flush in MARK_RING */
514 *sequence = ++screen->base.fence.sequence;
515
Ilia Mirkinbb73fc42015-11-04 22:42:41 -0500516 assert(PUSH_AVAIL(push) + push->rsvd_kick >= 5);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200517 PUSH_DATA (push, NV50_FIFO_PKHDR(NV50_3D(QUERY_ADDRESS_HIGH), 4));
518 PUSH_DATAh(push, screen->fence.bo->offset);
519 PUSH_DATA (push, screen->fence.bo->offset);
520 PUSH_DATA (push, *sequence);
521 PUSH_DATA (push, NV50_3D_QUERY_GET_MODE_WRITE_UNK0 |
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000522 NV50_3D_QUERY_GET_UNK4 |
523 NV50_3D_QUERY_GET_UNIT_CROP |
524 NV50_3D_QUERY_GET_TYPE_QUERY |
525 NV50_3D_QUERY_GET_QUERY_SELECT_ZERO |
526 NV50_3D_QUERY_GET_SHORT);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100527}
528
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000529static u32
530nv50_screen_fence_update(struct pipe_screen *pscreen)
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100531{
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200532 return nv50_screen(pscreen)->fence.map[0];
533}
534
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200535static void
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200536nv50_screen_init_hwctx(struct nv50_screen *screen)
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200537{
538 struct nouveau_pushbuf *push = screen->base.pushbuf;
539 struct nv04_fifo *fifo;
540 unsigned i;
541
542 fifo = (struct nv04_fifo *)screen->base.channel->data;
543
544 BEGIN_NV04(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1);
545 PUSH_DATA (push, screen->m2mf->handle);
546 BEGIN_NV04(push, SUBC_M2MF(NV03_M2MF_DMA_NOTIFY), 3);
547 PUSH_DATA (push, screen->sync->handle);
548 PUSH_DATA (push, fifo->vram);
549 PUSH_DATA (push, fifo->vram);
550
551 BEGIN_NV04(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1);
552 PUSH_DATA (push, screen->eng2d->handle);
553 BEGIN_NV04(push, NV50_2D(DMA_NOTIFY), 4);
554 PUSH_DATA (push, screen->sync->handle);
555 PUSH_DATA (push, fifo->vram);
556 PUSH_DATA (push, fifo->vram);
557 PUSH_DATA (push, fifo->vram);
558 BEGIN_NV04(push, NV50_2D(OPERATION), 1);
559 PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY);
560 BEGIN_NV04(push, NV50_2D(CLIP_ENABLE), 1);
561 PUSH_DATA (push, 0);
562 BEGIN_NV04(push, NV50_2D(COLOR_KEY_ENABLE), 1);
563 PUSH_DATA (push, 0);
564 BEGIN_NV04(push, SUBC_2D(0x0888), 1);
565 PUSH_DATA (push, 1);
Ilia Mirkin4467c0c2014-05-03 03:00:07 -0400566 BEGIN_NV04(push, NV50_2D(COND_MODE), 1);
567 PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200568
569 BEGIN_NV04(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1);
570 PUSH_DATA (push, screen->tesla->handle);
571
572 BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
573 PUSH_DATA (push, NV50_3D_COND_MODE_ALWAYS);
574
575 BEGIN_NV04(push, NV50_3D(DMA_NOTIFY), 1);
576 PUSH_DATA (push, screen->sync->handle);
577 BEGIN_NV04(push, NV50_3D(DMA_ZETA), 11);
578 for (i = 0; i < 11; ++i)
579 PUSH_DATA(push, fifo->vram);
580 BEGIN_NV04(push, NV50_3D(DMA_COLOR(0)), NV50_3D_DMA_COLOR__LEN);
581 for (i = 0; i < NV50_3D_DMA_COLOR__LEN; ++i)
582 PUSH_DATA(push, fifo->vram);
583
584 BEGIN_NV04(push, NV50_3D(REG_MODE), 1);
585 PUSH_DATA (push, NV50_3D_REG_MODE_STRIPED);
586 BEGIN_NV04(push, NV50_3D(UNK1400_LANES), 1);
587 PUSH_DATA (push, 0xf);
588
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +0200589 if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", true)) {
Christoph Bumiller2170fed2012-04-23 20:08:54 +0200590 BEGIN_NV04(push, NV50_3D(WATCHDOG_TIMER), 1);
591 PUSH_DATA (push, 0x18);
592 }
593
Tobias Klausmann1f8c0be2015-01-03 01:00:08 +0100594 BEGIN_NV04(push, NV50_3D(ZETA_COMP_ENABLE), 1);
Ben Skeggs1a9ec8e2015-11-26 09:57:30 +1000595 PUSH_DATA(push, screen->base.drm->version >= 0x01000101);
Tobias Klausmann1f8c0be2015-01-03 01:00:08 +0100596
597 BEGIN_NV04(push, NV50_3D(RT_COMP_ENABLE(0)), 8);
598 for (i = 0; i < 8; ++i)
Ben Skeggs1a9ec8e2015-11-26 09:57:30 +1000599 PUSH_DATA(push, screen->base.drm->version >= 0x01000101);
Tobias Klausmann1f8c0be2015-01-03 01:00:08 +0100600
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200601 BEGIN_NV04(push, NV50_3D(RT_CONTROL), 1);
602 PUSH_DATA (push, 1);
603
604 BEGIN_NV04(push, NV50_3D(CSAA_ENABLE), 1);
605 PUSH_DATA (push, 0);
606 BEGIN_NV04(push, NV50_3D(MULTISAMPLE_ENABLE), 1);
607 PUSH_DATA (push, 0);
608 BEGIN_NV04(push, NV50_3D(MULTISAMPLE_MODE), 1);
609 PUSH_DATA (push, NV50_3D_MULTISAMPLE_MODE_MS1);
610 BEGIN_NV04(push, NV50_3D(MULTISAMPLE_CTRL), 1);
611 PUSH_DATA (push, 0);
Christoph Bumillera284a0a2013-04-04 15:28:13 +0200612 BEGIN_NV04(push, NV50_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1);
613 PUSH_DATA (push, 1);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200614 BEGIN_NV04(push, NV50_3D(BLEND_SEPARATE_ALPHA), 1);
615 PUSH_DATA (push, 1);
616
617 if (screen->tesla->oclass >= NVA0_3D_CLASS) {
618 BEGIN_NV04(push, SUBC_3D(NVA0_3D_TEX_MISC), 1);
Ilia Mirkin1d1ddfe2016-02-13 22:14:02 -0500619 PUSH_DATA (push, 0);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200620 }
621
622 BEGIN_NV04(push, NV50_3D(SCREEN_Y_CONTROL), 1);
623 PUSH_DATA (push, 0);
624 BEGIN_NV04(push, NV50_3D(WINDOW_OFFSET_X), 2);
625 PUSH_DATA (push, 0);
626 PUSH_DATA (push, 0);
627 BEGIN_NV04(push, NV50_3D(ZCULL_REGION), 1);
628 PUSH_DATA (push, 0x3f);
629
630 BEGIN_NV04(push, NV50_3D(VP_ADDRESS_HIGH), 2);
631 PUSH_DATAh(push, screen->code->offset + (0 << NV50_CODE_BO_SIZE_LOG2));
632 PUSH_DATA (push, screen->code->offset + (0 << NV50_CODE_BO_SIZE_LOG2));
633
634 BEGIN_NV04(push, NV50_3D(FP_ADDRESS_HIGH), 2);
635 PUSH_DATAh(push, screen->code->offset + (1 << NV50_CODE_BO_SIZE_LOG2));
636 PUSH_DATA (push, screen->code->offset + (1 << NV50_CODE_BO_SIZE_LOG2));
637
638 BEGIN_NV04(push, NV50_3D(GP_ADDRESS_HIGH), 2);
639 PUSH_DATAh(push, screen->code->offset + (2 << NV50_CODE_BO_SIZE_LOG2));
640 PUSH_DATA (push, screen->code->offset + (2 << NV50_CODE_BO_SIZE_LOG2));
641
642 BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3);
643 PUSH_DATAh(push, screen->tls_bo->offset);
644 PUSH_DATA (push, screen->tls_bo->offset);
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200645 PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8));
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200646
647 BEGIN_NV04(push, NV50_3D(STACK_ADDRESS_HIGH), 3);
648 PUSH_DATAh(push, screen->stack_bo->offset);
649 PUSH_DATA (push, screen->stack_bo->offset);
650 PUSH_DATA (push, 4);
651
652 BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
653 PUSH_DATAh(push, screen->uniforms->offset + (0 << 16));
654 PUSH_DATA (push, screen->uniforms->offset + (0 << 16));
655 PUSH_DATA (push, (NV50_CB_PVP << 16) | 0x0000);
656
657 BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
658 PUSH_DATAh(push, screen->uniforms->offset + (1 << 16));
659 PUSH_DATA (push, screen->uniforms->offset + (1 << 16));
660 PUSH_DATA (push, (NV50_CB_PGP << 16) | 0x0000);
661
662 BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
663 PUSH_DATAh(push, screen->uniforms->offset + (2 << 16));
664 PUSH_DATA (push, screen->uniforms->offset + (2 << 16));
665 PUSH_DATA (push, (NV50_CB_PFP << 16) | 0x0000);
666
667 BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
668 PUSH_DATAh(push, screen->uniforms->offset + (3 << 16));
669 PUSH_DATA (push, screen->uniforms->offset + (3 << 16));
Ilia Mirkinb87f5ab2014-01-12 23:23:44 -0500670 PUSH_DATA (push, (NV50_CB_AUX << 16) | (NV50_CB_AUX_SIZE & 0xffff));
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200671
Christoph Bumillerfcb28682012-05-16 20:52:41 +0200672 BEGIN_NI04(push, NV50_3D(SET_PROGRAM_CB), 3);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200673 PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf01);
674 PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf21);
675 PUSH_DATA (push, (NV50_CB_AUX << 12) | 0xf31);
676
Ben Skeggs63c3a792012-10-08 10:25:39 +1000677 /* return { 0.0, 0.0, 0.0, 0.0 } on out-of-bounds vtxbuf access */
678 BEGIN_NV04(push, NV50_3D(CB_ADDR), 1);
Ilia Mirkin3bd40072014-01-12 03:32:30 -0500679 PUSH_DATA (push, (NV50_CB_AUX_RUNOUT_OFFSET << (8 - 2)) | NV50_CB_AUX);
Ben Skeggs63c3a792012-10-08 10:25:39 +1000680 BEGIN_NI04(push, NV50_3D(CB_DATA(0)), 4);
681 PUSH_DATAf(push, 0.0f);
682 PUSH_DATAf(push, 0.0f);
683 PUSH_DATAf(push, 0.0f);
684 PUSH_DATAf(push, 0.0f);
685 BEGIN_NV04(push, NV50_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2);
Ilia Mirkinb87f5ab2014-01-12 23:23:44 -0500686 PUSH_DATAh(push, screen->uniforms->offset + (3 << 16) + NV50_CB_AUX_RUNOUT_OFFSET);
687 PUSH_DATA (push, screen->uniforms->offset + (3 << 16) + NV50_CB_AUX_RUNOUT_OFFSET);
Ben Skeggs63c3a792012-10-08 10:25:39 +1000688
Ilia Mirkin3bd40072014-01-12 03:32:30 -0500689 nv50_upload_ms_info(push);
690
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200691 /* max TIC (bits 4:8) & TSC bindings, per program type */
692 for (i = 0; i < 3; ++i) {
693 BEGIN_NV04(push, NV50_3D(TEX_LIMITS(i)), 1);
694 PUSH_DATA (push, 0x54);
695 }
696
697 BEGIN_NV04(push, NV50_3D(TIC_ADDRESS_HIGH), 3);
698 PUSH_DATAh(push, screen->txc->offset);
699 PUSH_DATA (push, screen->txc->offset);
700 PUSH_DATA (push, NV50_TIC_MAX_ENTRIES - 1);
701
702 BEGIN_NV04(push, NV50_3D(TSC_ADDRESS_HIGH), 3);
703 PUSH_DATAh(push, screen->txc->offset + 65536);
704 PUSH_DATA (push, screen->txc->offset + 65536);
705 PUSH_DATA (push, NV50_TSC_MAX_ENTRIES - 1);
706
707 BEGIN_NV04(push, NV50_3D(LINKED_TSC), 1);
708 PUSH_DATA (push, 0);
709
710 BEGIN_NV04(push, NV50_3D(CLIP_RECTS_EN), 1);
711 PUSH_DATA (push, 0);
712 BEGIN_NV04(push, NV50_3D(CLIP_RECTS_MODE), 1);
713 PUSH_DATA (push, NV50_3D_CLIP_RECTS_MODE_INSIDE_ANY);
714 BEGIN_NV04(push, NV50_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
715 for (i = 0; i < 8 * 2; ++i)
716 PUSH_DATA(push, 0);
717 BEGIN_NV04(push, NV50_3D(CLIPID_ENABLE), 1);
718 PUSH_DATA (push, 0);
719
720 BEGIN_NV04(push, NV50_3D(VIEWPORT_TRANSFORM_EN), 1);
721 PUSH_DATA (push, 1);
Ilia Mirkin246ca4b2014-01-21 02:56:01 -0500722 for (i = 0; i < NV50_MAX_VIEWPORTS; i++) {
723 BEGIN_NV04(push, NV50_3D(DEPTH_RANGE_NEAR(i)), 2);
724 PUSH_DATAf(push, 0.0f);
725 PUSH_DATAf(push, 1.0f);
726 BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(i)), 2);
727 PUSH_DATA (push, 8192 << 16);
728 PUSH_DATA (push, 8192 << 16);
729 }
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200730
731 BEGIN_NV04(push, NV50_3D(VIEW_VOLUME_CLIP_CTRL), 1);
732#ifdef NV50_SCISSORS_CLIPPING
733 PUSH_DATA (push, 0x0000);
734#else
735 PUSH_DATA (push, 0x1080);
736#endif
737
738 BEGIN_NV04(push, NV50_3D(CLEAR_FLAGS), 1);
739 PUSH_DATA (push, NV50_3D_CLEAR_FLAGS_CLEAR_RECT_VIEWPORT);
740
741 /* We use scissors instead of exact view volume clipping,
742 * so they're always enabled.
743 */
Ilia Mirkin246ca4b2014-01-21 02:56:01 -0500744 for (i = 0; i < NV50_MAX_VIEWPORTS; i++) {
745 BEGIN_NV04(push, NV50_3D(SCISSOR_ENABLE(i)), 3);
746 PUSH_DATA (push, 1);
747 PUSH_DATA (push, 8192 << 16);
748 PUSH_DATA (push, 8192 << 16);
749 }
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200750
751 BEGIN_NV04(push, NV50_3D(RASTERIZE_ENABLE), 1);
752 PUSH_DATA (push, 1);
753 BEGIN_NV04(push, NV50_3D(POINT_RASTER_RULES), 1);
754 PUSH_DATA (push, NV50_3D_POINT_RASTER_RULES_OGL);
755 BEGIN_NV04(push, NV50_3D(FRAG_COLOR_CLAMP_EN), 1);
756 PUSH_DATA (push, 0x11111111);
757 BEGIN_NV04(push, NV50_3D(EDGEFLAG), 1);
758 PUSH_DATA (push, 1);
759
Ilia Mirkinbe0311c2014-12-30 23:19:47 -0500760 BEGIN_NV04(push, NV50_3D(VB_ELEMENT_BASE), 1);
761 PUSH_DATA (push, 0);
762 if (screen->base.class_3d >= NV84_3D_CLASS) {
Samuel Pitoiset9e40a622015-11-19 09:51:02 +0100763 BEGIN_NV04(push, NV84_3D(VERTEX_ID_BASE), 1);
Ilia Mirkinbe0311c2014-12-30 23:19:47 -0500764 PUSH_DATA (push, 0);
765 }
766
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200767 PUSH_KICK (push);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100768}
769
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200770static int nv50_tls_alloc(struct nv50_screen *screen, unsigned tls_space,
771 uint64_t *tls_size)
772{
773 struct nouveau_device *dev = screen->base.device;
774 int ret;
775
776 screen->cur_tls_space = util_next_power_of_two(tls_space / ONE_TEMP_SIZE) *
777 ONE_TEMP_SIZE;
778 if (nouveau_mesa_debug)
779 debug_printf("allocating space for %u temps\n",
780 util_next_power_of_two(tls_space / ONE_TEMP_SIZE));
781 *tls_size = screen->cur_tls_space * util_next_power_of_two(screen->TPs) *
782 screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP;
783
784 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16,
785 *tls_size, NULL, &screen->tls_bo);
786 if (ret) {
787 NOUVEAU_ERR("Failed to allocate local bo: %d\n", ret);
788 return ret;
789 }
790
791 return 0;
792}
793
794int nv50_tls_realloc(struct nv50_screen *screen, unsigned tls_space)
795{
796 struct nouveau_pushbuf *push = screen->base.pushbuf;
797 int ret;
798 uint64_t tls_size;
799
800 if (tls_space < screen->cur_tls_space)
801 return 0;
802 if (tls_space > screen->max_tls_space) {
803 /* fixable by limiting number of warps (LOCAL_WARPS_LOG_ALLOC /
804 * LOCAL_WARPS_NO_CLAMP) */
805 NOUVEAU_ERR("Unsupported number of temporaries (%u > %u). Fixable if someone cares.\n",
806 (unsigned)(tls_space / ONE_TEMP_SIZE),
807 (unsigned)(screen->max_tls_space / ONE_TEMP_SIZE));
808 return -ENOMEM;
809 }
810
811 nouveau_bo_ref(NULL, &screen->tls_bo);
812 ret = nv50_tls_alloc(screen, tls_space, &tls_size);
813 if (ret)
814 return ret;
815
816 BEGIN_NV04(push, NV50_3D(LOCAL_ADDRESS_HIGH), 3);
817 PUSH_DATAh(push, screen->tls_bo->offset);
818 PUSH_DATA (push, screen->tls_bo->offset);
819 PUSH_DATA (push, util_logbase2(screen->cur_tls_space / 8));
820
821 return 1;
822}
823
Ben Skeggs6c1bfff2015-11-26 14:24:42 +1000824struct nouveau_screen *
Marcin Slusarz10e93122011-12-02 22:02:51 +0100825nv50_screen_create(struct nouveau_device *dev)
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100826{
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100827 struct nv50_screen *screen;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100828 struct pipe_screen *pscreen;
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200829 struct nouveau_object *chan;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100830 uint64_t value;
831 uint32_t tesla_class;
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200832 unsigned stack_size;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100833 int ret;
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100834
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100835 screen = CALLOC_STRUCT(nv50_screen);
836 if (!screen)
837 return NULL;
838 pscreen = &screen->base.base;
Ben Skeggs323d4da2015-11-26 14:34:43 +1000839 pscreen->destroy = nv50_screen_destroy;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000840
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100841 ret = nouveau_screen_init(&screen->base, dev);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200842 if (ret) {
843 NOUVEAU_ERR("nouveau_screen_init failed: %d\n", ret);
844 goto fail;
845 }
Ben Skeggs84cc07d2008-02-29 15:03:57 +1100846
Christoph Bumiller1befacc2012-05-17 14:43:47 +0200847 /* TODO: Prevent FIFO prefetch before transfer of index buffers and
848 * admit them to VRAM.
849 */
850 screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER |
851 PIPE_BIND_VERTEX_BUFFER;
852 screen->base.sysmem_bindings |=
853 PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER;
854
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200855 screen->base.pushbuf->user_priv = screen;
856 screen->base.pushbuf->rsvd_kick = 5;
857
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100858 chan = screen->base.channel;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000859
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100860 pscreen->context_create = nv50_create;
861 pscreen->is_format_supported = nv50_screen_is_format_supported;
862 pscreen->get_param = nv50_screen_get_param;
863 pscreen->get_shader_param = nv50_screen_get_shader_param;
864 pscreen->get_paramf = nv50_screen_get_paramf;
Samuel Pitoisetff724402015-10-14 21:42:41 +0200865 pscreen->get_compute_param = nv50_screen_get_compute_param;
Samuel Pitoiset6a9c1512015-11-10 01:27:15 +0100866 pscreen->get_driver_query_info = nv50_screen_get_driver_query_info;
Samuel Pitoisetaede8ca2015-11-10 01:40:00 +0100867 pscreen->get_driver_query_group_info = nv50_screen_get_driver_query_group_info;
Ben Skeggsbc466be2009-06-04 10:19:04 +1000868
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100869 nv50_screen_init_resource_functions(pscreen);
Ben Skeggs63a3a372009-02-20 09:32:47 +1000870
Ilia Mirkin940f7ce2013-07-29 19:28:45 -0400871 if (screen->base.device->chipset < 0x84 ||
Samuel Pitoisetcd0dec02015-07-20 21:32:43 +0200872 debug_get_bool_option("NOUVEAU_PMPEG", false)) {
Ilia Mirkinfbdae1c2013-07-16 17:50:43 -0400873 /* PMPEG */
874 nouveau_screen_init_vdec(&screen->base);
875 } else if (screen->base.device->chipset < 0x98 ||
876 screen->base.device->chipset == 0xa0) {
877 /* VP2 */
878 screen->base.base.get_video_param = nv84_screen_get_video_param;
879 screen->base.base.is_video_format_supported = nv84_screen_video_supported;
880 } else {
Ilia Mirkina2061ee2013-08-10 20:19:24 -0400881 /* VP3/4 */
882 screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param;
883 screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported;
Ilia Mirkinfbdae1c2013-07-16 17:50:43 -0400884 }
Christoph Bumillerea316c52011-07-21 10:39:41 +0200885
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100886 ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, 4096,
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200887 NULL, &screen->fence.bo);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200888 if (ret) {
889 NOUVEAU_ERR("Failed to allocate fence bo: %d\n", ret);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100890 goto fail;
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200891 }
892
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200893 nouveau_bo_map(screen->fence.bo, 0, NULL);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100894 screen->fence.map = screen->fence.bo->map;
Ben Skeggs7a8ee052011-03-01 10:17:28 +1000895 screen->base.fence.emit = nv50_screen_fence_emit;
896 screen->base.fence.update = nv50_screen_fence_update;
Ben Skeggs1cec61e2008-03-13 18:08:22 +1100897
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200898 ret = nouveau_object_new(chan, 0xbeef0301, NOUVEAU_NOTIFIER_CLASS,
899 &(struct nv04_notify){ .length = 32 },
900 sizeof(struct nv04_notify), &screen->sync);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200901 if (ret) {
902 NOUVEAU_ERR("Failed to allocate notifier: %d\n", ret);
903 goto fail;
904 }
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200905
906 ret = nouveau_object_new(chan, 0xbeef5039, NV50_M2MF_CLASS,
907 NULL, 0, &screen->m2mf);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200908 if (ret) {
909 NOUVEAU_ERR("Failed to allocate PGRAPH context for M2MF: %d\n", ret);
910 goto fail;
911 }
Ben Skeggsb2e48f82008-03-12 02:39:13 +1100912
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200913 ret = nouveau_object_new(chan, 0xbeef502d, NV50_2D_CLASS,
914 NULL, 0, &screen->eng2d);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200915 if (ret) {
916 NOUVEAU_ERR("Failed to allocate PGRAPH context for 2D: %d\n", ret);
917 goto fail;
918 }
Ben Skeggs63a3a372009-02-20 09:32:47 +1000919
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100920 switch (dev->chipset & 0xf0) {
921 case 0x50:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200922 tesla_class = NV50_3D_CLASS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100923 break;
924 case 0x80:
925 case 0x90:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200926 tesla_class = NV84_3D_CLASS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100927 break;
928 case 0xa0:
929 switch (dev->chipset) {
930 case 0xa0:
931 case 0xaa:
932 case 0xac:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200933 tesla_class = NVA0_3D_CLASS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100934 break;
935 case 0xaf:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200936 tesla_class = NVAF_3D_CLASS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100937 break;
938 default:
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200939 tesla_class = NVA3_3D_CLASS;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100940 break;
941 }
942 break;
943 default:
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200944 NOUVEAU_ERR("Not a known NV50 chipset: NV%02x\n", dev->chipset);
945 goto fail;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100946 }
Christoph Bumillere44089b2012-04-14 23:56:56 +0200947 screen->base.class_3d = tesla_class;
Christoph Bumiller272bbbf2010-03-21 13:17:02 +0100948
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200949 ret = nouveau_object_new(chan, 0xbeef5097, tesla_class,
950 NULL, 0, &screen->tesla);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200951 if (ret) {
952 NOUVEAU_ERR("Failed to allocate PGRAPH context for 3D: %d\n", ret);
953 goto fail;
954 }
Ben Skeggsf722fd92008-06-01 22:41:40 +1000955
Ilia Mirkinf76c7ad2014-02-04 02:30:18 -0500956 /* This over-allocates by a page. The GP, which would execute at the end of
957 * the last page, would trigger faults. The going theory is that it
958 * prefetches up to a certain amount.
Ilia Mirkind98b85b2014-01-13 13:36:28 -0500959 */
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100960 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16,
Ilia Mirkinf76c7ad2014-02-04 02:30:18 -0500961 (3 << NV50_CODE_BO_SIZE_LOG2) + 0x1000,
962 NULL, &screen->code);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200963 if (ret) {
964 NOUVEAU_ERR("Failed to allocate code bo: %d\n", ret);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100965 goto fail;
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200966 }
Ben Skeggs716c1cd2008-06-01 23:10:31 +1000967
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200968 nouveau_heap_init(&screen->vp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
969 nouveau_heap_init(&screen->gp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
970 nouveau_heap_init(&screen->fp_code_heap, 0, 1 << NV50_CODE_BO_SIZE_LOG2);
Christoph Bumiller7048ad62011-03-03 12:25:12 +0100971
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200972 nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
Christoph Bumiller4de293b2010-08-15 21:37:50 +0200973
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200974 screen->TPs = util_bitcount(value & 0xffff);
975 screen->MPsInTP = util_bitcount((value >> 24) & 0xf);
Christoph Bumiller4de293b2010-08-15 21:37:50 +0200976
Samuel Pitoisetff724402015-10-14 21:42:41 +0200977 screen->mp_count = screen->TPs * screen->MPsInTP;
978
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200979 stack_size = util_next_power_of_two(screen->TPs) * screen->MPsInTP *
980 STACK_WARPS_ALLOC * 64 * 8;
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200981
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +0200982 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, stack_size, NULL,
Christoph Bumillerf80c03e2011-02-28 12:41:09 +0100983 &screen->stack_bo);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +0200984 if (ret) {
985 NOUVEAU_ERR("Failed to allocate stack bo: %d\n", ret);
986 goto fail;
987 }
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200988
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200989 uint64_t size_of_one_temp = util_next_power_of_two(screen->TPs) *
990 screen->MPsInTP * LOCAL_WARPS_ALLOC * THREADS_IN_WARP *
991 ONE_TEMP_SIZE;
992 screen->max_tls_space = dev->vram_size / size_of_one_temp * ONE_TEMP_SIZE;
993 screen->max_tls_space /= 2; /* half of vram */
Christoph Bumillerf30810c2010-09-09 19:12:54 +0200994
Marcin Slusarz1906d2b2012-06-27 14:45:17 +0200995 /* hw can address max 64 KiB */
996 screen->max_tls_space = MIN2(screen->max_tls_space, 64 << 10);
997
998 uint64_t tls_size;
999 unsigned tls_space = 4/*temps*/ * ONE_TEMP_SIZE;
1000 ret = nv50_tls_alloc(screen, tls_space, &tls_size);
1001 if (ret)
1002 goto fail;
Ben Skeggs3250bac2008-03-12 02:56:10 +11001003
Marcin Slusarz90dcd6c2011-10-08 23:58:32 +02001004 if (nouveau_mesa_debug)
Marcin Slusarz1906d2b2012-06-27 14:45:17 +02001005 debug_printf("TPs = %u, MPsInTP = %u, VRAM = %"PRIu64" MiB, tls_size = %"PRIu64" KiB\n",
1006 screen->TPs, screen->MPsInTP, dev->vram_size >> 20, tls_size >> 10);
Ben Skeggs431504b2008-06-16 18:56:39 +10001007
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +02001008 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 4 << 16, NULL,
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001009 &screen->uniforms);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +02001010 if (ret) {
1011 NOUVEAU_ERR("Failed to allocate uniforms bo: %d\n", ret);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001012 goto fail;
Marcin Slusarz0fceaee2012-06-26 16:22:43 +02001013 }
Christoph Bumillerd29f5552009-12-24 12:39:42 +01001014
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +02001015 ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 16, 3 << 16, NULL,
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001016 &screen->txc);
Marcin Slusarz0fceaee2012-06-26 16:22:43 +02001017 if (ret) {
1018 NOUVEAU_ERR("Failed to allocate TIC/TSC bo: %d\n", ret);
1019 goto fail;
1020 }
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001021
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001022 screen->tic.entries = CALLOC(4096, sizeof(void *));
1023 screen->tsc.entries = screen->tic.entries + 2048;
1024
Christoph Bumiller36ea7442012-09-26 23:06:40 +02001025 if (!nv50_blitter_create(screen))
Christoph Bumillere9d84da2011-07-28 15:54:53 +02001026 goto fail;
1027
Marcin Slusarz1906d2b2012-06-27 14:45:17 +02001028 nv50_screen_init_hwctx(screen);
Christoph Bumiller6d1cdec2012-04-06 15:41:55 +02001029
Samuel Pitoisetff724402015-10-14 21:42:41 +02001030 ret = nv50_screen_compute_setup(screen, screen->base.pushbuf);
1031 if (ret) {
1032 NOUVEAU_ERR("Failed to init compute context: %d\n", ret);
1033 goto fail;
1034 }
1035
Emil Velikov9c500392017-01-16 16:25:19 +00001036 nouveau_fence_new(&screen->base, &screen->base.fence.current);
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001037
Ben Skeggs6c1bfff2015-11-26 14:24:42 +10001038 return &screen->base;
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001039
1040fail:
Ben Skeggs323d4da2015-11-26 14:34:43 +10001041 screen->base.base.context_create = NULL;
1042 return &screen->base;
Ben Skeggs84cc07d2008-02-29 15:03:57 +11001043}
1044
Christoph Bumillerf80c03e2011-02-28 12:41:09 +01001045int
1046nv50_screen_tic_alloc(struct nv50_screen *screen, void *entry)
1047{
1048 int i = screen->tic.next;
1049
1050 while (screen->tic.lock[i / 32] & (1 << (i % 32)))
1051 i = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
1052
1053 screen->tic.next = (i + 1) & (NV50_TIC_MAX_ENTRIES - 1);
1054
1055 if (screen->tic.entries[i])
1056 nv50_tic_entry(screen->tic.entries[i])->id = -1;
1057
1058 screen->tic.entries[i] = entry;
1059 return i;
1060}
1061
1062int
1063nv50_screen_tsc_alloc(struct nv50_screen *screen, void *entry)
1064{
1065 int i = screen->tsc.next;
1066
1067 while (screen->tsc.lock[i / 32] & (1 << (i % 32)))
1068 i = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
1069
1070 screen->tsc.next = (i + 1) & (NV50_TSC_MAX_ENTRIES - 1);
1071
1072 if (screen->tsc.entries[i])
1073 nv50_tsc_entry(screen->tsc.entries[i])->id = -1;
1074
1075 screen->tsc.entries[i] = entry;
1076 return i;
1077}