1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2010 Christoph Bumiller
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
12bf215546Sopenharmony_ci * all copies or substantial portions of the Software.
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci#include <xf86drm.h>
24bf215546Sopenharmony_ci#include <nouveau_drm.h>
25bf215546Sopenharmony_ci#include <nvif/class.h>
26bf215546Sopenharmony_ci#include "util/format/u_format.h"
27bf215546Sopenharmony_ci#include "util/format/u_format_s3tc.h"
28bf215546Sopenharmony_ci#include "util/u_screen.h"
29bf215546Sopenharmony_ci#include "pipe/p_screen.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "nouveau_vp3_video.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "nv50_ir_driver.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "nvc0/nvc0_context.h"
36bf215546Sopenharmony_ci#include "nvc0/nvc0_screen.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#include "nvc0/mme/com9097.mme.h"
39bf215546Sopenharmony_ci#include "nvc0/mme/com90c0.mme.h"
40bf215546Sopenharmony_ci#include "nvc0/mme/comc597.mme.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#include "nv50/g80_texture.xml.h"
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_cistatic bool
45bf215546Sopenharmony_cinvc0_screen_is_format_supported(struct pipe_screen *pscreen,
46bf215546Sopenharmony_ci                                enum pipe_format format,
47bf215546Sopenharmony_ci                                enum pipe_texture_target target,
48bf215546Sopenharmony_ci                                unsigned sample_count,
49bf215546Sopenharmony_ci                                unsigned storage_sample_count,
50bf215546Sopenharmony_ci                                unsigned bindings)
51bf215546Sopenharmony_ci{
52bf215546Sopenharmony_ci   const struct util_format_description *desc = util_format_description(format);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci   if (sample_count > 8)
55bf215546Sopenharmony_ci      return false;
56bf215546Sopenharmony_ci   if (!(0x117 & (1 << sample_count))) /* 0, 1, 2, 4 or 8 */
57bf215546Sopenharmony_ci      return false;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
60bf215546Sopenharmony_ci      return false;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   /* Short-circuit the rest of the logic -- this is used by the gallium frontend
63bf215546Sopenharmony_ci    * to determine valid MS levels in a no-attachments scenario.
64bf215546Sopenharmony_ci    */
65bf215546Sopenharmony_ci   if (format == PIPE_FORMAT_NONE && bindings & PIPE_BIND_RENDER_TARGET)
66bf215546Sopenharmony_ci      return true;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   if ((bindings & PIPE_BIND_SAMPLER_VIEW) && (target != PIPE_BUFFER))
69bf215546Sopenharmony_ci      if (util_format_get_blocksizebits(format) == 3 * 32)
70bf215546Sopenharmony_ci         return false;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   if (bindings & PIPE_BIND_LINEAR)
73bf215546Sopenharmony_ci      if (util_format_is_depth_or_stencil(format) ||
74bf215546Sopenharmony_ci          (target != PIPE_TEXTURE_1D &&
75bf215546Sopenharmony_ci           target != PIPE_TEXTURE_2D &&
76bf215546Sopenharmony_ci           target != PIPE_TEXTURE_RECT) ||
77bf215546Sopenharmony_ci          sample_count > 1)
78bf215546Sopenharmony_ci         return false;
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci   /* Restrict ETC2 and ASTC formats here. These are only supported on GK20A
81bf215546Sopenharmony_ci    * and GM20B.
82bf215546Sopenharmony_ci    */
83bf215546Sopenharmony_ci   if ((desc->layout == UTIL_FORMAT_LAYOUT_ETC ||
84bf215546Sopenharmony_ci        desc->layout == UTIL_FORMAT_LAYOUT_ASTC) &&
85bf215546Sopenharmony_ci       nouveau_screen(pscreen)->device->chipset != 0x12b &&
86bf215546Sopenharmony_ci       nouveau_screen(pscreen)->class_3d != NVEA_3D_CLASS)
87bf215546Sopenharmony_ci      return false;
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci   /* shared is always supported */
90bf215546Sopenharmony_ci   bindings &= ~(PIPE_BIND_LINEAR |
91bf215546Sopenharmony_ci                 PIPE_BIND_SHARED);
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   if (bindings & PIPE_BIND_SHADER_IMAGE) {
94bf215546Sopenharmony_ci      if (format == PIPE_FORMAT_B8G8R8A8_UNORM &&
95bf215546Sopenharmony_ci          nouveau_screen(pscreen)->class_3d < NVE4_3D_CLASS) {
96bf215546Sopenharmony_ci         /* This should work on Fermi, but for currently unknown reasons it
97bf215546Sopenharmony_ci          * does not and results in breaking reads from pbos. */
98bf215546Sopenharmony_ci         return false;
99bf215546Sopenharmony_ci      }
100bf215546Sopenharmony_ci   }
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   if (bindings & PIPE_BIND_INDEX_BUFFER) {
103bf215546Sopenharmony_ci      if (format != PIPE_FORMAT_R8_UINT &&
104bf215546Sopenharmony_ci          format != PIPE_FORMAT_R16_UINT &&
105bf215546Sopenharmony_ci          format != PIPE_FORMAT_R32_UINT)
106bf215546Sopenharmony_ci         return false;
107bf215546Sopenharmony_ci      bindings &= ~PIPE_BIND_INDEX_BUFFER;
108bf215546Sopenharmony_ci   }
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   return (( nvc0_format_table[format].usage |
111bf215546Sopenharmony_ci            nvc0_vertex_format[format].usage) & bindings) == bindings;
112bf215546Sopenharmony_ci}
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_cistatic int
115bf215546Sopenharmony_cinvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
116bf215546Sopenharmony_ci{
117bf215546Sopenharmony_ci   const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
118bf215546Sopenharmony_ci   const struct nouveau_screen *screen = nouveau_screen(pscreen);
119bf215546Sopenharmony_ci   struct nouveau_device *dev = screen->device;
120bf215546Sopenharmony_ci   static bool debug_cap_printed[PIPE_CAP_LAST] = {};
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci   switch (param) {
123bf215546Sopenharmony_ci   /* non-boolean caps */
124bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
125bf215546Sopenharmony_ci      return 16384;
126bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
127bf215546Sopenharmony_ci      return 15;
128bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
129bf215546Sopenharmony_ci      return 12;
130bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
131bf215546Sopenharmony_ci      return 2048;
132bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXEL_OFFSET:
133bf215546Sopenharmony_ci      return -8;
134bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_OFFSET:
135bf215546Sopenharmony_ci      return 7;
136bf215546Sopenharmony_ci   case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
137bf215546Sopenharmony_ci      return -32;
138bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
139bf215546Sopenharmony_ci      return 31;
140bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXEL_BUFFER_ELEMENTS_UINT:
141bf215546Sopenharmony_ci      return 128 * 1024 * 1024;
142bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL:
143bf215546Sopenharmony_ci      return 430;
144bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
145bf215546Sopenharmony_ci      return 430;
146bf215546Sopenharmony_ci   case PIPE_CAP_MAX_RENDER_TARGETS:
147bf215546Sopenharmony_ci      return 8;
148bf215546Sopenharmony_ci   case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
149bf215546Sopenharmony_ci      return 1;
150bf215546Sopenharmony_ci   case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
151bf215546Sopenharmony_ci   case PIPE_CAP_RASTERIZER_SUBPIXEL_BITS:
152bf215546Sopenharmony_ci      return 8;
153bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS:
154bf215546Sopenharmony_ci      return 4;
155bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS:
156bf215546Sopenharmony_ci   case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS:
157bf215546Sopenharmony_ci      return 128;
158bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_OUTPUT_VERTICES:
159bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
160bf215546Sopenharmony_ci      return 1024;
161bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_STREAMS:
162bf215546Sopenharmony_ci      return 4;
163bf215546Sopenharmony_ci   case PIPE_CAP_MAX_GS_INVOCATIONS:
164bf215546Sopenharmony_ci      return 32;
165bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT:
166bf215546Sopenharmony_ci      return 1 << 27;
167bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE:
168bf215546Sopenharmony_ci      return 2048;
169bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_ELEMENT_SRC_OFFSET:
170bf215546Sopenharmony_ci      return 2047;
171bf215546Sopenharmony_ci   case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
172bf215546Sopenharmony_ci      return 256;
173bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
174bf215546Sopenharmony_ci      if (class_3d < GM107_3D_CLASS)
175bf215546Sopenharmony_ci         return 256; /* IMAGE bindings require alignment to 256 */
176bf215546Sopenharmony_ci      return 16;
177bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
178bf215546Sopenharmony_ci      return 16;
179bf215546Sopenharmony_ci   case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
180bf215546Sopenharmony_ci      return NOUVEAU_MIN_BUFFER_MAP_ALIGN;
181bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VIEWPORTS:
182bf215546Sopenharmony_ci      return NVC0_MAX_VIEWPORTS;
183bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
184bf215546Sopenharmony_ci      return 4;
185bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
186bf215546Sopenharmony_ci      return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50;
187bf215546Sopenharmony_ci   case PIPE_CAP_ENDIANNESS:
188bf215546Sopenharmony_ci      return PIPE_ENDIAN_LITTLE;
189bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
190bf215546Sopenharmony_ci      return 30;
191bf215546Sopenharmony_ci   case PIPE_CAP_MAX_WINDOW_RECTANGLES:
192bf215546Sopenharmony_ci      return NVC0_MAX_WINDOW_RECTANGLES;
193bf215546Sopenharmony_ci   case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
194bf215546Sopenharmony_ci      return class_3d >= GM200_3D_CLASS ? 8 : 0;
195bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
196bf215546Sopenharmony_ci      return 64 * 1024 * 1024;
197bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VARYINGS:
198bf215546Sopenharmony_ci      /* NOTE: These only count our slots for GENERIC varyings.
199bf215546Sopenharmony_ci       * The address space may be larger, but the actual hard limit seems to be
200bf215546Sopenharmony_ci       * less than what the address space layout permits, so don't add TEXCOORD,
201bf215546Sopenharmony_ci       * COLOR, etc. here.
202bf215546Sopenharmony_ci       */
203bf215546Sopenharmony_ci      return 0x1f0 / 16;
204bf215546Sopenharmony_ci   case PIPE_CAP_MAX_VERTEX_BUFFERS:
205bf215546Sopenharmony_ci      return 16;
206bf215546Sopenharmony_ci   case PIPE_CAP_GL_BEGIN_END_BUFFER_SIZE:
207bf215546Sopenharmony_ci      return 512 * 1024; /* TODO: Investigate tuning this */
208bf215546Sopenharmony_ci   case PIPE_CAP_MAX_TEXTURE_MB:
209bf215546Sopenharmony_ci      return 0; /* TODO: use 1/2 of VRAM for this? */
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci   case PIPE_CAP_SUPPORTED_PRIM_MODES_WITH_RESTART:
212bf215546Sopenharmony_ci   case PIPE_CAP_SUPPORTED_PRIM_MODES:
213bf215546Sopenharmony_ci      return BITFIELD_MASK(PIPE_PRIM_MAX);
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   /* supported caps */
216bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
217bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
218bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SWIZZLE:
219bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SHADOW_MAP:
220bf215546Sopenharmony_ci   case PIPE_CAP_NPOT_TEXTURES:
221bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
222bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
223bf215546Sopenharmony_ci   case PIPE_CAP_ANISOTROPIC_FILTER:
224bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP:
225bf215546Sopenharmony_ci   case PIPE_CAP_CUBE_MAP_ARRAY:
226bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
227bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_MULTISAMPLE:
228bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE:
229bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SPRITE:
230bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEXCOORD:
231bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
232bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
233bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
234bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_UNCLAMPED:
235bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_COLOR_CLAMPED:
236bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIMESTAMP:
237bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_TIME_ELAPSED:
238bf215546Sopenharmony_ci   case PIPE_CAP_OCCLUSION_QUERY:
239bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
240bf215546Sopenharmony_ci   case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
241bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
242bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_SEPARATE:
243bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_ENABLE:
244bf215546Sopenharmony_ci   case PIPE_CAP_INDEP_BLEND_FUNC:
245bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT:
246bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
247bf215546Sopenharmony_ci   case PIPE_CAP_POINT_COORD_ORIGIN_UPPER_LEFT:
248bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART:
249bf215546Sopenharmony_ci   case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX:
250bf215546Sopenharmony_ci   case PIPE_CAP_VS_INSTANCEID:
251bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
252bf215546Sopenharmony_ci   case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
253bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER:
254bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BARRIER:
255bf215546Sopenharmony_ci   case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
256bf215546Sopenharmony_ci   case PIPE_CAP_START_INSTANCE:
257bf215546Sopenharmony_ci   case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
258bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_INDIRECT:
259bf215546Sopenharmony_ci   case PIPE_CAP_USER_VERTEX_BUFFERS:
260bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_LOD:
261bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLE_SHADING:
262bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
263bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_GATHER_SM5:
264bf215546Sopenharmony_ci   case PIPE_CAP_FS_FINE_DERIVATIVE:
265bf215546Sopenharmony_ci   case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
266bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_VIEW_TARGET:
267bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_HALFZ:
268bf215546Sopenharmony_ci   case PIPE_CAP_POLYGON_OFFSET_CLAMP:
269bf215546Sopenharmony_ci   case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
270bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
271bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
272bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_BOUNDS_TEST:
273bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_QUERY_SAMPLES:
274bf215546Sopenharmony_ci   case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
275bf215546Sopenharmony_ci   case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
276bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_TEXTURE:
277bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_PARAMETERS:
278bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_PACK_HALF_FLOAT:
279bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT:
280bf215546Sopenharmony_ci   case PIPE_CAP_MULTI_DRAW_INDIRECT_PARAMS:
281bf215546Sopenharmony_ci   case PIPE_CAP_FS_FACE_IS_INTEGER_SYSVAL:
282bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_BUFFER_OBJECT:
283bf215546Sopenharmony_ci   case PIPE_CAP_INVALIDATE_BUFFER:
284bf215546Sopenharmony_ci   case PIPE_CAP_STRING_MARKER:
285bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_NO_ATTACHMENT:
286bf215546Sopenharmony_ci   case PIPE_CAP_CULL_DISTANCE:
287bf215546Sopenharmony_ci   case PIPE_CAP_ROBUST_BUFFER_ACCESS_BEHAVIOR:
288bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_GROUP_VOTE:
289bf215546Sopenharmony_ci   case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
290bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_ARRAY_COMPONENTS:
291bf215546Sopenharmony_ci   case PIPE_CAP_LEGACY_MATH_RULES:
292bf215546Sopenharmony_ci   case PIPE_CAP_DOUBLES:
293bf215546Sopenharmony_ci   case PIPE_CAP_INT64:
294bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TEX_TXF_LZ:
295bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_CLOCK:
296bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE:
297bf215546Sopenharmony_ci   case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
298bf215546Sopenharmony_ci   case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
299bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_SO_OVERFLOW:
300bf215546Sopenharmony_ci   case PIPE_CAP_DEST_SURFACE_SRGB_CONTROL:
301bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_DIV:
302bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_ATOMIC_INC_WRAP:
303bf215546Sopenharmony_ci   case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION:
304bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
305bf215546Sopenharmony_ci   case PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF:
306bf215546Sopenharmony_ci   case PIPE_CAP_FLATSHADE:
307bf215546Sopenharmony_ci   case PIPE_CAP_ALPHA_TEST:
308bf215546Sopenharmony_ci   case PIPE_CAP_POINT_SIZE_FIXED:
309bf215546Sopenharmony_ci   case PIPE_CAP_TWO_SIDED_COLOR:
310bf215546Sopenharmony_ci   case PIPE_CAP_CLIP_PLANES:
311bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_SHADOW_LOD:
312bf215546Sopenharmony_ci   case PIPE_CAP_PACKED_STREAM_OUTPUT:
313bf215546Sopenharmony_ci   case PIPE_CAP_CLEAR_SCISSORED:
314bf215546Sopenharmony_ci   case PIPE_CAP_GL_CLAMP:
315bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_STORE_FORMATTED:
316bf215546Sopenharmony_ci   case PIPE_CAP_TEXRECT:
317bf215546Sopenharmony_ci   case PIPE_CAP_ALLOW_DYNAMIC_VAO_FASTPATH:
318bf215546Sopenharmony_ci   case PIPE_CAP_SHAREABLE_SHADERS:
319bf215546Sopenharmony_ci   case PIPE_CAP_PREFER_BACK_BUFFER_REUSE:
320bf215546Sopenharmony_ci      return 1;
321bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_TRANSFER_MODES:
322bf215546Sopenharmony_ci      return nouveau_screen(pscreen)->vram_domain & NOUVEAU_BO_VRAM ? PIPE_TEXTURE_TRANSFER_BLIT : 0;
323bf215546Sopenharmony_ci   case PIPE_CAP_FBFETCH:
324bf215546Sopenharmony_ci      return class_3d >= NVE4_3D_CLASS ? 1 : 0; /* needs testing on fermi */
325bf215546Sopenharmony_ci   case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
326bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_BALLOT:
327bf215546Sopenharmony_ci      return class_3d >= NVE4_3D_CLASS;
328bf215546Sopenharmony_ci   case PIPE_CAP_BINDLESS_TEXTURE:
329bf215546Sopenharmony_ci      return class_3d >= NVE4_3D_CLASS;
330bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_ATOMIC_FLOAT_ADD:
331bf215546Sopenharmony_ci      return class_3d < GM107_3D_CLASS; /* needs additional lowering */
332bf215546Sopenharmony_ci   case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
333bf215546Sopenharmony_ci   case PIPE_CAP_VS_LAYER_VIEWPORT:
334bf215546Sopenharmony_ci   case PIPE_CAP_TES_LAYER_VIEWPORT:
335bf215546Sopenharmony_ci   case PIPE_CAP_POST_DEPTH_COVERAGE:
336bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
337bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
338bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
339bf215546Sopenharmony_ci   case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
340bf215546Sopenharmony_ci   case PIPE_CAP_VIEWPORT_SWIZZLE:
341bf215546Sopenharmony_ci   case PIPE_CAP_VIEWPORT_MASK:
342bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_REDUCTION_MINMAX:
343bf215546Sopenharmony_ci      return class_3d >= GM200_3D_CLASS;
344bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
345bf215546Sopenharmony_ci      return class_3d >= GP100_3D_CLASS;
346bf215546Sopenharmony_ci   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY_COMPUTE_ONLY:
347bf215546Sopenharmony_ci   case PIPE_CAP_SYSTEM_SVM:
348bf215546Sopenharmony_ci      return screen->has_svm ? 1 : 0;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci   /* caps has to be turned on with nir */
351bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV:
352bf215546Sopenharmony_ci   case PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS:
353bf215546Sopenharmony_ci   case PIPE_CAP_INT64_DIVMOD:
354bf215546Sopenharmony_ci      return screen->prefer_nir ? 1 : 0;
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   /* nir related caps */
357bf215546Sopenharmony_ci   case PIPE_CAP_NIR_IMAGES_AS_DEREF:
358bf215546Sopenharmony_ci      return 0;
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci   /* unsupported caps */
361bf215546Sopenharmony_ci   case PIPE_CAP_EMULATE_NONFIXED_PRIMITIVE_RESTART:
362bf215546Sopenharmony_ci   case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
363bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_ORIGIN_LOWER_LEFT:
364bf215546Sopenharmony_ci   case PIPE_CAP_FS_COORD_PIXEL_CENTER_INTEGER:
365bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_STENCIL_EXPORT:
366bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
367bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
368bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
369bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
370bf215546Sopenharmony_ci   case PIPE_CAP_VERTEX_ATTRIB_ELEMENT_ALIGNED_ONLY:
371bf215546Sopenharmony_ci   case PIPE_CAP_FAKE_SW_MSAA:
372bf215546Sopenharmony_ci   case PIPE_CAP_VS_WINDOW_SPACE_POSITION:
373bf215546Sopenharmony_ci   case PIPE_CAP_VERTEXID_NOBASE:
374bf215546Sopenharmony_ci   case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
375bf215546Sopenharmony_ci   case PIPE_CAP_FS_POSITION_IS_SYSVAL:
376bf215546Sopenharmony_ci   case PIPE_CAP_FS_POINT_IS_SYSVAL:
377bf215546Sopenharmony_ci   case PIPE_CAP_GENERATE_MIPMAP:
378bf215546Sopenharmony_ci   case PIPE_CAP_BUFFER_SAMPLER_VIEW_RGBA_ONLY:
379bf215546Sopenharmony_ci   case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
380bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_MEMORY_INFO:
381bf215546Sopenharmony_ci   case PIPE_CAP_PCI_GROUP:
382bf215546Sopenharmony_ci   case PIPE_CAP_PCI_BUS:
383bf215546Sopenharmony_ci   case PIPE_CAP_PCI_DEVICE:
384bf215546Sopenharmony_ci   case PIPE_CAP_PCI_FUNCTION:
385bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_CAN_READ_OUTPUTS:
386bf215546Sopenharmony_ci   case PIPE_CAP_NATIVE_FENCE_FD:
387bf215546Sopenharmony_ci   case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
388bf215546Sopenharmony_ci   case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
389bf215546Sopenharmony_ci   case PIPE_CAP_MEMOBJ:
390bf215546Sopenharmony_ci   case PIPE_CAP_LOAD_CONSTBUF:
391bf215546Sopenharmony_ci   case PIPE_CAP_TILE_RASTER_ORDER:
392bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
393bf215546Sopenharmony_ci   case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
394bf215546Sopenharmony_ci   case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
395bf215546Sopenharmony_ci   case PIPE_CAP_CONTEXT_PRIORITY_MASK:
396bf215546Sopenharmony_ci   case PIPE_CAP_FENCE_SIGNAL:
397bf215546Sopenharmony_ci   case PIPE_CAP_CONSTBUF0_FLAGS:
398bf215546Sopenharmony_ci   case PIPE_CAP_PACKED_UNIFORMS:
399bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
400bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_SHADER_BUFFERS:
401bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTERS:
402bf215546Sopenharmony_ci   case PIPE_CAP_MAX_COMBINED_HW_ATOMIC_COUNTER_BUFFERS:
403bf215546Sopenharmony_ci   case PIPE_CAP_SURFACE_SAMPLE_COUNT:
404bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE:
405bf215546Sopenharmony_ci   case PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND:
406bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS:
407bf215546Sopenharmony_ci   case PIPE_CAP_NIR_COMPACT_ARRAYS:
408bf215546Sopenharmony_ci   case PIPE_CAP_IMAGE_LOAD_FORMATTED:
409bf215546Sopenharmony_ci   case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES:
410bf215546Sopenharmony_ci   case PIPE_CAP_ATOMIC_FLOAT_MINMAX:
411bf215546Sopenharmony_ci   case PIPE_CAP_CONSERVATIVE_RASTER_INNER_COVERAGE:
412bf215546Sopenharmony_ci   case PIPE_CAP_FRAGMENT_SHADER_INTERLOCK:
413bf215546Sopenharmony_ci   case PIPE_CAP_CS_DERIVED_SYSTEM_VALUES_SUPPORTED:
414bf215546Sopenharmony_ci   case PIPE_CAP_FBFETCH_COHERENT:
415bf215546Sopenharmony_ci   case PIPE_CAP_TGSI_TG4_COMPONENT_IN_SWIZZLE:
416bf215546Sopenharmony_ci   case PIPE_CAP_OPENCL_INTEGER_FUNCTIONS: /* could be done */
417bf215546Sopenharmony_ci   case PIPE_CAP_INTEGER_MULTIPLY_32X16: /* could be done */
418bf215546Sopenharmony_ci   case PIPE_CAP_FRONTEND_NOOP:
419bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_SAMPLES_IDENTICAL:
420bf215546Sopenharmony_ci   case PIPE_CAP_VIEWPORT_TRANSFORM_LOWERED:
421bf215546Sopenharmony_ci   case PIPE_CAP_PSIZ_CLAMPED:
422bf215546Sopenharmony_ci   case PIPE_CAP_TEXTURE_BUFFER_SAMPLER:
423bf215546Sopenharmony_ci   case PIPE_CAP_PREFER_REAL_BUFFER_IN_CONSTBUF0:
424bf215546Sopenharmony_ci   case PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE: /* when we fix MT stuff */
425bf215546Sopenharmony_ci   case PIPE_CAP_ALPHA_TO_COVERAGE_DITHER_CONTROL: /* TODO */
426bf215546Sopenharmony_ci   case PIPE_CAP_SHADER_ATOMIC_INT64: /* TODO */
427bf215546Sopenharmony_ci   case PIPE_CAP_GLSL_ZERO_INIT:
428bf215546Sopenharmony_ci   case PIPE_CAP_BLEND_EQUATION_ADVANCED:
429bf215546Sopenharmony_ci   case PIPE_CAP_NO_CLIP_ON_COPY_TEX:
430bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_PROTECTED_CONTENT:
431bf215546Sopenharmony_ci   case PIPE_CAP_SAMPLER_REDUCTION_MINMAX_ARB:
432bf215546Sopenharmony_ci   case PIPE_CAP_DRAW_VERTEX_STATE:
433bf215546Sopenharmony_ci   case PIPE_CAP_PREFER_POT_ALIGNED_VARYINGS:
434bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SPARSE_TEXTURE_SIZE:
435bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SPARSE_3D_TEXTURE_SIZE:
436bf215546Sopenharmony_ci   case PIPE_CAP_MAX_SPARSE_ARRAY_TEXTURE_LAYERS:
437bf215546Sopenharmony_ci   case PIPE_CAP_SPARSE_TEXTURE_FULL_ARRAY_CUBE_MIPMAPS:
438bf215546Sopenharmony_ci   case PIPE_CAP_QUERY_SPARSE_TEXTURE_RESIDENCY:
439bf215546Sopenharmony_ci   case PIPE_CAP_CLAMP_SPARSE_TEXTURE_LOD:
440bf215546Sopenharmony_ci   case PIPE_CAP_HARDWARE_GL_SELECT:
441bf215546Sopenharmony_ci      return 0;
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_ci   case PIPE_CAP_VENDOR_ID:
444bf215546Sopenharmony_ci      return 0x10de;
445bf215546Sopenharmony_ci   case PIPE_CAP_DEVICE_ID: {
446bf215546Sopenharmony_ci      uint64_t device_id;
447bf215546Sopenharmony_ci      if (nouveau_getparam(dev, NOUVEAU_GETPARAM_PCI_DEVICE, &device_id)) {
448bf215546Sopenharmony_ci         NOUVEAU_ERR("NOUVEAU_GETPARAM_PCI_DEVICE failed.\n");
449bf215546Sopenharmony_ci         return -1;
450bf215546Sopenharmony_ci      }
451bf215546Sopenharmony_ci      return device_id;
452bf215546Sopenharmony_ci   }
453bf215546Sopenharmony_ci   case PIPE_CAP_ACCELERATED:
454bf215546Sopenharmony_ci      return 1;
455bf215546Sopenharmony_ci   case PIPE_CAP_VIDEO_MEMORY:
456bf215546Sopenharmony_ci      return dev->vram_size >> 20;
457bf215546Sopenharmony_ci   case PIPE_CAP_UMA:
458bf215546Sopenharmony_ci      return 0;
459bf215546Sopenharmony_ci
460bf215546Sopenharmony_ci   default:
461bf215546Sopenharmony_ci      if (!debug_cap_printed[param]) {
462bf215546Sopenharmony_ci         debug_printf("%s: unhandled cap %d\n", __func__, param);
463bf215546Sopenharmony_ci         debug_cap_printed[param] = true;
464bf215546Sopenharmony_ci      }
465bf215546Sopenharmony_ci      FALLTHROUGH;
466bf215546Sopenharmony_ci   /* caps where we want the default value */
467bf215546Sopenharmony_ci   case PIPE_CAP_DMABUF:
468bf215546Sopenharmony_ci   case PIPE_CAP_ESSL_FEATURE_LEVEL:
469bf215546Sopenharmony_ci   case PIPE_CAP_THROTTLE:
470bf215546Sopenharmony_ci      return u_pipe_screen_get_param_defaults(pscreen, param);
471bf215546Sopenharmony_ci   }
472bf215546Sopenharmony_ci}
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_cistatic int
475bf215546Sopenharmony_cinvc0_screen_get_shader_param(struct pipe_screen *pscreen,
476bf215546Sopenharmony_ci                             enum pipe_shader_type shader,
477bf215546Sopenharmony_ci                             enum pipe_shader_cap param)
478bf215546Sopenharmony_ci{
479bf215546Sopenharmony_ci   const struct nouveau_screen *screen = nouveau_screen(pscreen);
480bf215546Sopenharmony_ci   const uint16_t class_3d = screen->class_3d;
481bf215546Sopenharmony_ci
482bf215546Sopenharmony_ci   switch (shader) {
483bf215546Sopenharmony_ci   case PIPE_SHADER_VERTEX:
484bf215546Sopenharmony_ci   case PIPE_SHADER_GEOMETRY:
485bf215546Sopenharmony_ci   case PIPE_SHADER_FRAGMENT:
486bf215546Sopenharmony_ci   case PIPE_SHADER_COMPUTE:
487bf215546Sopenharmony_ci   case PIPE_SHADER_TESS_CTRL:
488bf215546Sopenharmony_ci   case PIPE_SHADER_TESS_EVAL:
489bf215546Sopenharmony_ci      break;
490bf215546Sopenharmony_ci   default:
491bf215546Sopenharmony_ci      return 0;
492bf215546Sopenharmony_ci   }
493bf215546Sopenharmony_ci
494bf215546Sopenharmony_ci   switch (param) {
495bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_PREFERRED_IR:
496bf215546Sopenharmony_ci      return screen->prefer_nir ? PIPE_SHADER_IR_NIR : PIPE_SHADER_IR_TGSI;
497bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUPPORTED_IRS: {
498bf215546Sopenharmony_ci      uint32_t irs = 1 << PIPE_SHADER_IR_NIR |
499bf215546Sopenharmony_ci         ((class_3d >= GV100_3D_CLASS) ? 0 : 1 << PIPE_SHADER_IR_TGSI);
500bf215546Sopenharmony_ci      if (screen->force_enable_cl)
501bf215546Sopenharmony_ci         irs |= 1 << PIPE_SHADER_IR_NIR_SERIALIZED;
502bf215546Sopenharmony_ci      return irs;
503bf215546Sopenharmony_ci   }
504bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
505bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
506bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
507bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
508bf215546Sopenharmony_ci      return 16384;
509bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
510bf215546Sopenharmony_ci      return 16;
511bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_INPUTS:
512bf215546Sopenharmony_ci      return 0x200 / 16;
513bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_OUTPUTS:
514bf215546Sopenharmony_ci      return 32;
515bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE:
516bf215546Sopenharmony_ci      return NVC0_MAX_CONSTBUF_SIZE;
517bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
518bf215546Sopenharmony_ci      return NVC0_MAX_PIPE_CONSTBUFS;
519bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
520bf215546Sopenharmony_ci      return shader != PIPE_SHADER_FRAGMENT;
521bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
522bf215546Sopenharmony_ci      /* HW doesn't support indirect addressing of fragment program inputs
523bf215546Sopenharmony_ci       * on Volta.  The binary driver generates a function to handle every
524bf215546Sopenharmony_ci       * possible indirection, and indirectly calls the function to handle
525bf215546Sopenharmony_ci       * this instead.
526bf215546Sopenharmony_ci       */
527bf215546Sopenharmony_ci      if (class_3d >= GV100_3D_CLASS)
528bf215546Sopenharmony_ci         return shader != PIPE_SHADER_FRAGMENT;
529bf215546Sopenharmony_ci      return 1;
530bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
531bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
532bf215546Sopenharmony_ci      return 1;
533bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEMPS:
534bf215546Sopenharmony_ci      return NVC0_CAP_MAX_PROGRAM_TEMPS;
535bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_CONT_SUPPORTED:
536bf215546Sopenharmony_ci      return 1;
537bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED:
538bf215546Sopenharmony_ci      return 1;
539bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_SUBROUTINES:
540bf215546Sopenharmony_ci      return 1;
541bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INTEGERS:
542bf215546Sopenharmony_ci      return 1;
543bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DROUND_SUPPORTED:
544bf215546Sopenharmony_ci      return 1;
545bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED:
546bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_LDEXP_SUPPORTED:
547bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE:
548bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT64_ATOMICS:
549bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16:
550bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_DERIVATIVES:
551bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_FP16_CONST_BUFFERS:
552bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_INT16:
553bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS:
554bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS:
555bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS:
556bf215546Sopenharmony_ci      return 0;
557bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS:
558bf215546Sopenharmony_ci      return NVC0_MAX_BUFFERS;
559bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS:
560bf215546Sopenharmony_ci      return (class_3d >= NVE4_3D_CLASS) ? 32 : 16;
561bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS:
562bf215546Sopenharmony_ci      return (class_3d >= NVE4_3D_CLASS) ? 32 : 16;
563bf215546Sopenharmony_ci   case PIPE_SHADER_CAP_MAX_SHADER_IMAGES:
564bf215546Sopenharmony_ci      if (class_3d >= NVE4_3D_CLASS)
565bf215546Sopenharmony_ci         return NVC0_MAX_IMAGES;
566bf215546Sopenharmony_ci      if (shader == PIPE_SHADER_FRAGMENT || shader == PIPE_SHADER_COMPUTE)
567bf215546Sopenharmony_ci         return NVC0_MAX_IMAGES;
568bf215546Sopenharmony_ci      return 0;
569bf215546Sopenharmony_ci   default:
570bf215546Sopenharmony_ci      NOUVEAU_ERR("unknown PIPE_SHADER_CAP %d\n", param);
571bf215546Sopenharmony_ci      return 0;
572bf215546Sopenharmony_ci   }
573bf215546Sopenharmony_ci}
574bf215546Sopenharmony_ci
575bf215546Sopenharmony_cistatic float
576bf215546Sopenharmony_cinvc0_screen_get_paramf(struct pipe_screen *pscreen, enum pipe_capf param)
577bf215546Sopenharmony_ci{
578bf215546Sopenharmony_ci   const uint16_t class_3d = nouveau_screen(pscreen)->class_3d;
579bf215546Sopenharmony_ci
580bf215546Sopenharmony_ci   switch (param) {
581bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH:
582bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_LINE_WIDTH_AA:
583bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE:
584bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_POINT_SIZE_AA:
585bf215546Sopenharmony_ci      return 1;
586bf215546Sopenharmony_ci   case PIPE_CAPF_POINT_SIZE_GRANULARITY:
587bf215546Sopenharmony_ci   case PIPE_CAPF_LINE_WIDTH_GRANULARITY:
588bf215546Sopenharmony_ci      return 0.1;
589bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH:
590bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_LINE_WIDTH_AA:
591bf215546Sopenharmony_ci      return 10.0f;
592bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE:
593bf215546Sopenharmony_ci      return 63.0f;
594bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_POINT_SIZE_AA:
595bf215546Sopenharmony_ci      return 63.375f;
596bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:
597bf215546Sopenharmony_ci      return 16.0f;
598bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
599bf215546Sopenharmony_ci      return 15.0f;
600bf215546Sopenharmony_ci   case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
601bf215546Sopenharmony_ci      return 0.0f;
602bf215546Sopenharmony_ci   case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
603bf215546Sopenharmony_ci      return class_3d >= GM200_3D_CLASS ? 0.75f : 0.0f;
604bf215546Sopenharmony_ci   case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
605bf215546Sopenharmony_ci      return class_3d >= GM200_3D_CLASS ? 0.25f : 0.0f;
606bf215546Sopenharmony_ci   }
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_ci   NOUVEAU_ERR("unknown PIPE_CAPF %d\n", param);
609bf215546Sopenharmony_ci   return 0.0f;
610bf215546Sopenharmony_ci}
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_cistatic int
613bf215546Sopenharmony_cinvc0_screen_get_compute_param(struct pipe_screen *pscreen,
614bf215546Sopenharmony_ci                              enum pipe_shader_ir ir_type,
615bf215546Sopenharmony_ci                              enum pipe_compute_cap param, void *data)
616bf215546Sopenharmony_ci{
617bf215546Sopenharmony_ci   struct nvc0_screen *screen = nvc0_screen(pscreen);
618bf215546Sopenharmony_ci   const uint16_t obj_class = screen->compute->oclass;
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci#define RET(x) do {                  \
621bf215546Sopenharmony_ci   if (data)                         \
622bf215546Sopenharmony_ci      memcpy(data, x, sizeof(x));    \
623bf215546Sopenharmony_ci   return sizeof(x);                 \
624bf215546Sopenharmony_ci} while (0)
625bf215546Sopenharmony_ci
626bf215546Sopenharmony_ci   switch (param) {
627bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_GRID_DIMENSION:
628bf215546Sopenharmony_ci      RET((uint64_t []) { 3 });
629bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
630bf215546Sopenharmony_ci      if (obj_class >= NVE4_COMPUTE_CLASS) {
631bf215546Sopenharmony_ci         RET(((uint64_t []) { 0x7fffffff, 65535, 65535 }));
632bf215546Sopenharmony_ci      } else {
633bf215546Sopenharmony_ci         RET(((uint64_t []) { 65535, 65535, 65535 }));
634bf215546Sopenharmony_ci      }
635bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
636bf215546Sopenharmony_ci      RET(((uint64_t []) { 1024, 1024, 64 }));
637bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
638bf215546Sopenharmony_ci      RET((uint64_t []) { 1024 });
639bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:
640bf215546Sopenharmony_ci      if (obj_class >= NVE4_COMPUTE_CLASS) {
641bf215546Sopenharmony_ci         RET((uint64_t []) { 1024 });
642bf215546Sopenharmony_ci      } else {
643bf215546Sopenharmony_ci         RET((uint64_t []) { 512 });
644bf215546Sopenharmony_ci      }
645bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: /* g[] */
646bf215546Sopenharmony_ci      RET((uint64_t []) { 1ULL << 40 });
647bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: /* s[] */
648bf215546Sopenharmony_ci      switch (obj_class) {
649bf215546Sopenharmony_ci      case GM200_COMPUTE_CLASS:
650bf215546Sopenharmony_ci         RET((uint64_t []) { 96 << 10 });
651bf215546Sopenharmony_ci      case GM107_COMPUTE_CLASS:
652bf215546Sopenharmony_ci         RET((uint64_t []) { 64 << 10 });
653bf215546Sopenharmony_ci      default:
654bf215546Sopenharmony_ci         RET((uint64_t []) { 48 << 10 });
655bf215546Sopenharmony_ci      }
656bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: /* l[] */
657bf215546Sopenharmony_ci      RET((uint64_t []) { 512 << 10 });
658bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: /* c[], arbitrary limit */
659bf215546Sopenharmony_ci      RET((uint64_t []) { 4096 });
660bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
661bf215546Sopenharmony_ci      RET((uint32_t []) { 32 });
662bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:
663bf215546Sopenharmony_ci      RET((uint64_t []) { 1ULL << 40 });
664bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:
665bf215546Sopenharmony_ci      RET((uint32_t []) { NVC0_MAX_IMAGES });
666bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:
667bf215546Sopenharmony_ci      RET((uint32_t []) { screen->mp_count_compute });
668bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:
669bf215546Sopenharmony_ci      RET((uint32_t []) { 512 }); /* FIXME: arbitrary limit */
670bf215546Sopenharmony_ci   case PIPE_COMPUTE_CAP_ADDRESS_BITS:
671bf215546Sopenharmony_ci      RET((uint32_t []) { 64 });
672bf215546Sopenharmony_ci   default:
673bf215546Sopenharmony_ci      return 0;
674bf215546Sopenharmony_ci   }
675bf215546Sopenharmony_ci
676bf215546Sopenharmony_ci#undef RET
677bf215546Sopenharmony_ci}
678bf215546Sopenharmony_ci
679bf215546Sopenharmony_cistatic void
680bf215546Sopenharmony_cinvc0_screen_get_sample_pixel_grid(struct pipe_screen *pscreen,
681bf215546Sopenharmony_ci                                  unsigned sample_count,
682bf215546Sopenharmony_ci                                  unsigned *width, unsigned *height)
683bf215546Sopenharmony_ci{
684bf215546Sopenharmony_ci   switch (sample_count) {
685bf215546Sopenharmony_ci   case 0:
686bf215546Sopenharmony_ci   case 1:
687bf215546Sopenharmony_ci      /* this could be 4x4, but the GL state tracker makes it difficult to
688bf215546Sopenharmony_ci       * create a 1x MSAA texture and smaller grids save CB space */
689bf215546Sopenharmony_ci      *width = 2;
690bf215546Sopenharmony_ci      *height = 4;
691bf215546Sopenharmony_ci      break;
692bf215546Sopenharmony_ci   case 2:
693bf215546Sopenharmony_ci      *width = 2;
694bf215546Sopenharmony_ci      *height = 4;
695bf215546Sopenharmony_ci      break;
696bf215546Sopenharmony_ci   case 4:
697bf215546Sopenharmony_ci      *width = 2;
698bf215546Sopenharmony_ci      *height = 2;
699bf215546Sopenharmony_ci      break;
700bf215546Sopenharmony_ci   case 8:
701bf215546Sopenharmony_ci      *width = 1;
702bf215546Sopenharmony_ci      *height = 2;
703bf215546Sopenharmony_ci      break;
704bf215546Sopenharmony_ci   default:
705bf215546Sopenharmony_ci      assert(0);
706bf215546Sopenharmony_ci   }
707bf215546Sopenharmony_ci}
708bf215546Sopenharmony_ci
709bf215546Sopenharmony_cistatic void
710bf215546Sopenharmony_cinvc0_screen_destroy(struct pipe_screen *pscreen)
711bf215546Sopenharmony_ci{
712bf215546Sopenharmony_ci   struct nvc0_screen *screen = nvc0_screen(pscreen);
713bf215546Sopenharmony_ci
714bf215546Sopenharmony_ci   if (!nouveau_drm_screen_unref(&screen->base))
715bf215546Sopenharmony_ci      return;
716bf215546Sopenharmony_ci
717bf215546Sopenharmony_ci   nouveau_fence_cleanup(&screen->base);
718bf215546Sopenharmony_ci
719bf215546Sopenharmony_ci   if (screen->base.pushbuf)
720bf215546Sopenharmony_ci      screen->base.pushbuf->user_priv = NULL;
721bf215546Sopenharmony_ci
722bf215546Sopenharmony_ci   if (screen->blitter)
723bf215546Sopenharmony_ci      nvc0_blitter_destroy(screen);
724bf215546Sopenharmony_ci   if (screen->pm.prog) {
725bf215546Sopenharmony_ci      screen->pm.prog->code = NULL; /* hardcoded, don't FREE */
726bf215546Sopenharmony_ci      nvc0_program_destroy(NULL, screen->pm.prog);
727bf215546Sopenharmony_ci      FREE(screen->pm.prog);
728bf215546Sopenharmony_ci   }
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->text);
731bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->uniform_bo);
732bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->tls);
733bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->txc);
734bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->fence.bo);
735bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->poly_cache);
736bf215546Sopenharmony_ci
737bf215546Sopenharmony_ci   nouveau_heap_destroy(&screen->lib_code);
738bf215546Sopenharmony_ci   nouveau_heap_destroy(&screen->text_heap);
739bf215546Sopenharmony_ci
740bf215546Sopenharmony_ci   FREE(screen->tic.entries);
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_ci   nouveau_object_del(&screen->eng3d);
743bf215546Sopenharmony_ci   nouveau_object_del(&screen->eng2d);
744bf215546Sopenharmony_ci   nouveau_object_del(&screen->m2mf);
745bf215546Sopenharmony_ci   nouveau_object_del(&screen->compute);
746bf215546Sopenharmony_ci   nouveau_object_del(&screen->nvsw);
747bf215546Sopenharmony_ci
748bf215546Sopenharmony_ci   nouveau_screen_fini(&screen->base);
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci   FREE(screen);
751bf215546Sopenharmony_ci}
752bf215546Sopenharmony_ci
753bf215546Sopenharmony_cistatic int
754bf215546Sopenharmony_cinvc0_graph_set_macro(struct nvc0_screen *screen, uint32_t m, unsigned pos,
755bf215546Sopenharmony_ci                     unsigned size, const uint32_t *data)
756bf215546Sopenharmony_ci{
757bf215546Sopenharmony_ci   struct nouveau_pushbuf *push = screen->base.pushbuf;
758bf215546Sopenharmony_ci
759bf215546Sopenharmony_ci   size /= 4;
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_ci   assert((pos + size) <= 0x800);
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(NVC0_GRAPH_MACRO_ID), 2);
764bf215546Sopenharmony_ci   PUSH_DATA (push, (m - 0x3800) / 8);
765bf215546Sopenharmony_ci   PUSH_DATA (push, pos);
766bf215546Sopenharmony_ci   BEGIN_1IC0(push, SUBC_3D(NVC0_GRAPH_MACRO_UPLOAD_POS), size + 1);
767bf215546Sopenharmony_ci   PUSH_DATA (push, pos);
768bf215546Sopenharmony_ci   PUSH_DATAp(push, data, size);
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_ci   return pos + size;
771bf215546Sopenharmony_ci}
772bf215546Sopenharmony_ci
773bf215546Sopenharmony_cistatic int
774bf215546Sopenharmony_citu102_graph_set_macro(struct nvc0_screen *screen, uint32_t m, unsigned pos,
775bf215546Sopenharmony_ci                     unsigned size, const uint32_t *data)
776bf215546Sopenharmony_ci{
777bf215546Sopenharmony_ci   struct nouveau_pushbuf *push = screen->base.pushbuf;
778bf215546Sopenharmony_ci
779bf215546Sopenharmony_ci   size /= 4;
780bf215546Sopenharmony_ci
781bf215546Sopenharmony_ci   assert((pos + size) <= 0x800);
782bf215546Sopenharmony_ci
783bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(NVC0_GRAPH_MACRO_ID), 2);
784bf215546Sopenharmony_ci   PUSH_DATA (push, (m - 0x3800) / 8);
785bf215546Sopenharmony_ci   PUSH_DATA (push, pos);
786bf215546Sopenharmony_ci   BEGIN_1IC0(push, SUBC_3D(NVC0_GRAPH_MACRO_UPLOAD_POS), size + 1);
787bf215546Sopenharmony_ci   PUSH_DATA (push, pos);
788bf215546Sopenharmony_ci   PUSH_DATAp(push, data, size);
789bf215546Sopenharmony_ci
790bf215546Sopenharmony_ci   return pos + (size / 3);
791bf215546Sopenharmony_ci}
792bf215546Sopenharmony_ci
793bf215546Sopenharmony_cistatic void
794bf215546Sopenharmony_cinvc0_magic_3d_init(struct nouveau_pushbuf *push, uint16_t obj_class)
795bf215546Sopenharmony_ci{
796bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x10cc), 1);
797bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff);
798bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x10e0), 2);
799bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff);
800bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff);
801bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x10ec), 2);
802bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff);
803bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff);
804bf215546Sopenharmony_ci   if (obj_class < GV100_3D_CLASS) {
805bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_3D(0x074c), 1);
806bf215546Sopenharmony_ci      PUSH_DATA (push, 0x3f);
807bf215546Sopenharmony_ci   }
808bf215546Sopenharmony_ci
809bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x16a8), 1);
810bf215546Sopenharmony_ci   PUSH_DATA (push, (3 << 16) | 3);
811bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x1794), 1);
812bf215546Sopenharmony_ci   PUSH_DATA (push, (2 << 16) | 2);
813bf215546Sopenharmony_ci
814bf215546Sopenharmony_ci   if (obj_class < GM107_3D_CLASS) {
815bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_3D(0x12ac), 1);
816bf215546Sopenharmony_ci      PUSH_DATA (push, 0);
817bf215546Sopenharmony_ci   }
818bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x0218), 1);
819bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
820bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x10fc), 1);
821bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
822bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x1290), 1);
823bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
824bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x12d8), 2);
825bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
826bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
827bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x1140), 1);
828bf215546Sopenharmony_ci   PUSH_DATA (push, 0x10);
829bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x1610), 1);
830bf215546Sopenharmony_ci   PUSH_DATA (push, 0xe);
831bf215546Sopenharmony_ci
832bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(VERTEX_ID_GEN_MODE), 1);
833bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_VERTEX_ID_GEN_MODE_DRAW_ARRAYS_ADD_START);
834bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x030c), 1);
835bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
836bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x0300), 1);
837bf215546Sopenharmony_ci   PUSH_DATA (push, 3);
838bf215546Sopenharmony_ci
839bf215546Sopenharmony_ci   if (obj_class < GV100_3D_CLASS) {
840bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_3D(0x02d0), 1);
841bf215546Sopenharmony_ci      PUSH_DATA (push, 0x3fffff);
842bf215546Sopenharmony_ci   }
843bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x0fdc), 1);
844bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
845bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(0x19c0), 1);
846bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
847bf215546Sopenharmony_ci
848bf215546Sopenharmony_ci   if (obj_class < GM107_3D_CLASS) {
849bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_3D(0x075c), 1);
850bf215546Sopenharmony_ci      PUSH_DATA (push, 3);
851bf215546Sopenharmony_ci
852bf215546Sopenharmony_ci      if (obj_class >= NVE4_3D_CLASS) {
853bf215546Sopenharmony_ci         BEGIN_NVC0(push, SUBC_3D(0x07fc), 1);
854bf215546Sopenharmony_ci         PUSH_DATA (push, 1);
855bf215546Sopenharmony_ci      }
856bf215546Sopenharmony_ci   }
857bf215546Sopenharmony_ci
858bf215546Sopenharmony_ci   /* TODO: find out what software methods 0x1528, 0x1280 and (on nve4) 0x02dc
859bf215546Sopenharmony_ci    * are supposed to do */
860bf215546Sopenharmony_ci}
861bf215546Sopenharmony_ci
862bf215546Sopenharmony_cistatic void
863bf215546Sopenharmony_cinvc0_screen_fence_emit(struct pipe_screen *pscreen, u32 *sequence)
864bf215546Sopenharmony_ci{
865bf215546Sopenharmony_ci   struct nvc0_screen *screen = nvc0_screen(pscreen);
866bf215546Sopenharmony_ci   struct nouveau_pushbuf *push = screen->base.pushbuf;
867bf215546Sopenharmony_ci
868bf215546Sopenharmony_ci   /* we need to do it after possible flush in MARK_RING */
869bf215546Sopenharmony_ci   *sequence = ++screen->base.fence.sequence;
870bf215546Sopenharmony_ci
871bf215546Sopenharmony_ci   assert(PUSH_AVAIL(push) + push->rsvd_kick >= 5);
872bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_FIFO_PKHDR_SQ(NVC0_3D(QUERY_ADDRESS_HIGH), 4));
873bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->fence.bo->offset);
874bf215546Sopenharmony_ci   PUSH_DATA (push, screen->fence.bo->offset);
875bf215546Sopenharmony_ci   PUSH_DATA (push, *sequence);
876bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_QUERY_GET_FENCE | NVC0_3D_QUERY_GET_SHORT |
877bf215546Sopenharmony_ci              (0xf << NVC0_3D_QUERY_GET_UNIT__SHIFT));
878bf215546Sopenharmony_ci}
879bf215546Sopenharmony_ci
880bf215546Sopenharmony_cistatic u32
881bf215546Sopenharmony_cinvc0_screen_fence_update(struct pipe_screen *pscreen)
882bf215546Sopenharmony_ci{
883bf215546Sopenharmony_ci   struct nvc0_screen *screen = nvc0_screen(pscreen);
884bf215546Sopenharmony_ci   return screen->fence.map[0];
885bf215546Sopenharmony_ci}
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_cistatic int
888bf215546Sopenharmony_cinvc0_screen_init_compute(struct nvc0_screen *screen)
889bf215546Sopenharmony_ci{
890bf215546Sopenharmony_ci   screen->base.base.get_compute_param = nvc0_screen_get_compute_param;
891bf215546Sopenharmony_ci
892bf215546Sopenharmony_ci   switch (screen->base.device->chipset & ~0xf) {
893bf215546Sopenharmony_ci   case 0xc0:
894bf215546Sopenharmony_ci   case 0xd0:
895bf215546Sopenharmony_ci      return nvc0_screen_compute_setup(screen, screen->base.pushbuf);
896bf215546Sopenharmony_ci   case 0xe0:
897bf215546Sopenharmony_ci   case 0xf0:
898bf215546Sopenharmony_ci   case 0x100:
899bf215546Sopenharmony_ci   case 0x110:
900bf215546Sopenharmony_ci   case 0x120:
901bf215546Sopenharmony_ci   case 0x130:
902bf215546Sopenharmony_ci   case 0x140:
903bf215546Sopenharmony_ci   case 0x160:
904bf215546Sopenharmony_ci      return nve4_screen_compute_setup(screen, screen->base.pushbuf);
905bf215546Sopenharmony_ci   default:
906bf215546Sopenharmony_ci      return -1;
907bf215546Sopenharmony_ci   }
908bf215546Sopenharmony_ci}
909bf215546Sopenharmony_ci
910bf215546Sopenharmony_cistatic int
911bf215546Sopenharmony_cinvc0_screen_resize_tls_area(struct nvc0_screen *screen,
912bf215546Sopenharmony_ci                            uint32_t lpos, uint32_t lneg, uint32_t cstack)
913bf215546Sopenharmony_ci{
914bf215546Sopenharmony_ci   struct nouveau_bo *bo = NULL;
915bf215546Sopenharmony_ci   int ret;
916bf215546Sopenharmony_ci   uint64_t size = (lpos + lneg) * 32 + cstack;
917bf215546Sopenharmony_ci
918bf215546Sopenharmony_ci   if (size >= (1 << 20)) {
919bf215546Sopenharmony_ci      NOUVEAU_ERR("requested TLS size too large: 0x%"PRIx64"\n", size);
920bf215546Sopenharmony_ci      return -1;
921bf215546Sopenharmony_ci   }
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci   size *= (screen->base.device->chipset >= 0xe0) ? 64 : 48; /* max warps */
924bf215546Sopenharmony_ci   size  = align(size, 0x8000);
925bf215546Sopenharmony_ci   size *= screen->mp_count;
926bf215546Sopenharmony_ci
927bf215546Sopenharmony_ci   size = align(size, 1 << 17);
928bf215546Sopenharmony_ci
929bf215546Sopenharmony_ci   ret = nouveau_bo_new(screen->base.device, NV_VRAM_DOMAIN(&screen->base), 1 << 17, size,
930bf215546Sopenharmony_ci                        NULL, &bo);
931bf215546Sopenharmony_ci   if (ret)
932bf215546Sopenharmony_ci      return ret;
933bf215546Sopenharmony_ci
934bf215546Sopenharmony_ci   /* Make sure that the pushbuf has acquired a reference to the old tls
935bf215546Sopenharmony_ci    * segment, as it may have commands that will reference it.
936bf215546Sopenharmony_ci    */
937bf215546Sopenharmony_ci   if (screen->tls)
938bf215546Sopenharmony_ci      PUSH_REFN(screen->base.pushbuf, screen->tls,
939bf215546Sopenharmony_ci                NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RDWR);
940bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->tls);
941bf215546Sopenharmony_ci   screen->tls = bo;
942bf215546Sopenharmony_ci   return 0;
943bf215546Sopenharmony_ci}
944bf215546Sopenharmony_ci
945bf215546Sopenharmony_ciint
946bf215546Sopenharmony_cinvc0_screen_resize_text_area(struct nvc0_screen *screen, uint64_t size)
947bf215546Sopenharmony_ci{
948bf215546Sopenharmony_ci   struct nouveau_pushbuf *push = screen->base.pushbuf;
949bf215546Sopenharmony_ci   struct nouveau_bo *bo;
950bf215546Sopenharmony_ci   int ret;
951bf215546Sopenharmony_ci
952bf215546Sopenharmony_ci   ret = nouveau_bo_new(screen->base.device, NV_VRAM_DOMAIN(&screen->base),
953bf215546Sopenharmony_ci                        1 << 17, size, NULL, &bo);
954bf215546Sopenharmony_ci   if (ret)
955bf215546Sopenharmony_ci      return ret;
956bf215546Sopenharmony_ci
957bf215546Sopenharmony_ci   /* Make sure that the pushbuf has acquired a reference to the old text
958bf215546Sopenharmony_ci    * segment, as it may have commands that will reference it.
959bf215546Sopenharmony_ci    */
960bf215546Sopenharmony_ci   if (screen->text)
961bf215546Sopenharmony_ci      PUSH_REFN(push, screen->text,
962bf215546Sopenharmony_ci                NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD);
963bf215546Sopenharmony_ci   nouveau_bo_ref(NULL, &screen->text);
964bf215546Sopenharmony_ci   screen->text = bo;
965bf215546Sopenharmony_ci
966bf215546Sopenharmony_ci   nouveau_heap_destroy(&screen->lib_code);
967bf215546Sopenharmony_ci   nouveau_heap_destroy(&screen->text_heap);
968bf215546Sopenharmony_ci
969bf215546Sopenharmony_ci   /* XXX: getting a page fault at the end of the code buffer every few
970bf215546Sopenharmony_ci    *  launches, don't use the last 256 bytes to work around them - prefetch ?
971bf215546Sopenharmony_ci    */
972bf215546Sopenharmony_ci   nouveau_heap_init(&screen->text_heap, 0, size - 0x100);
973bf215546Sopenharmony_ci
974bf215546Sopenharmony_ci   /* update the code segment setup */
975bf215546Sopenharmony_ci   if (screen->eng3d->oclass < GV100_3D_CLASS) {
976bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(CODE_ADDRESS_HIGH), 2);
977bf215546Sopenharmony_ci      PUSH_DATAh(push, screen->text->offset);
978bf215546Sopenharmony_ci      PUSH_DATA (push, screen->text->offset);
979bf215546Sopenharmony_ci      if (screen->compute) {
980bf215546Sopenharmony_ci         BEGIN_NVC0(push, NVC0_CP(CODE_ADDRESS_HIGH), 2);
981bf215546Sopenharmony_ci         PUSH_DATAh(push, screen->text->offset);
982bf215546Sopenharmony_ci         PUSH_DATA (push, screen->text->offset);
983bf215546Sopenharmony_ci      }
984bf215546Sopenharmony_ci   }
985bf215546Sopenharmony_ci
986bf215546Sopenharmony_ci   return 0;
987bf215546Sopenharmony_ci}
988bf215546Sopenharmony_ci
989bf215546Sopenharmony_civoid
990bf215546Sopenharmony_cinvc0_screen_bind_cb_3d(struct nvc0_screen *screen, bool *can_serialize,
991bf215546Sopenharmony_ci                       int stage, int index, int size, uint64_t addr)
992bf215546Sopenharmony_ci{
993bf215546Sopenharmony_ci   assert(stage != 5);
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_ci   struct nouveau_pushbuf *push = screen->base.pushbuf;
996bf215546Sopenharmony_ci
997bf215546Sopenharmony_ci   if (screen->base.class_3d >= GM107_3D_CLASS) {
998bf215546Sopenharmony_ci      struct nvc0_cb_binding *binding = &screen->cb_bindings[stage][index];
999bf215546Sopenharmony_ci
1000bf215546Sopenharmony_ci      // TODO: Better figure out the conditions in which this is needed
1001bf215546Sopenharmony_ci      bool serialize = binding->addr == addr && binding->size != size;
1002bf215546Sopenharmony_ci      if (can_serialize)
1003bf215546Sopenharmony_ci         serialize = serialize && *can_serialize;
1004bf215546Sopenharmony_ci      if (serialize) {
1005bf215546Sopenharmony_ci         IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
1006bf215546Sopenharmony_ci         if (can_serialize)
1007bf215546Sopenharmony_ci            *can_serialize = false;
1008bf215546Sopenharmony_ci      }
1009bf215546Sopenharmony_ci
1010bf215546Sopenharmony_ci      binding->addr = addr;
1011bf215546Sopenharmony_ci      binding->size = size;
1012bf215546Sopenharmony_ci   }
1013bf215546Sopenharmony_ci
1014bf215546Sopenharmony_ci   if (size >= 0) {
1015bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3);
1016bf215546Sopenharmony_ci      PUSH_DATA (push, size);
1017bf215546Sopenharmony_ci      PUSH_DATAh(push, addr);
1018bf215546Sopenharmony_ci      PUSH_DATA (push, addr);
1019bf215546Sopenharmony_ci   }
1020bf215546Sopenharmony_ci   IMMED_NVC0(push, NVC0_3D(CB_BIND(stage)), (index << 4) | (size >= 0));
1021bf215546Sopenharmony_ci}
1022bf215546Sopenharmony_ci
1023bf215546Sopenharmony_cistatic const void *
1024bf215546Sopenharmony_cinvc0_screen_get_compiler_options(struct pipe_screen *pscreen,
1025bf215546Sopenharmony_ci                                 enum pipe_shader_ir ir,
1026bf215546Sopenharmony_ci                                 enum pipe_shader_type shader)
1027bf215546Sopenharmony_ci{
1028bf215546Sopenharmony_ci   struct nvc0_screen *screen = nvc0_screen(pscreen);
1029bf215546Sopenharmony_ci   if (ir == PIPE_SHADER_IR_NIR)
1030bf215546Sopenharmony_ci      return nv50_ir_nir_shader_compiler_options(screen->base.device->chipset,
1031bf215546Sopenharmony_ci                                                 shader);
1032bf215546Sopenharmony_ci   return NULL;
1033bf215546Sopenharmony_ci}
1034bf215546Sopenharmony_ci
1035bf215546Sopenharmony_ci#define FAIL_SCREEN_INIT(str, err)                    \
1036bf215546Sopenharmony_ci   do {                                               \
1037bf215546Sopenharmony_ci      NOUVEAU_ERR(str, err);                          \
1038bf215546Sopenharmony_ci      goto fail;                                      \
1039bf215546Sopenharmony_ci   } while(0)
1040bf215546Sopenharmony_ci
1041bf215546Sopenharmony_cistruct nouveau_screen *
1042bf215546Sopenharmony_cinvc0_screen_create(struct nouveau_device *dev)
1043bf215546Sopenharmony_ci{
1044bf215546Sopenharmony_ci   struct nvc0_screen *screen;
1045bf215546Sopenharmony_ci   struct pipe_screen *pscreen;
1046bf215546Sopenharmony_ci   struct nouveau_object *chan;
1047bf215546Sopenharmony_ci   struct nouveau_pushbuf *push;
1048bf215546Sopenharmony_ci   uint64_t value;
1049bf215546Sopenharmony_ci   uint32_t obj_class;
1050bf215546Sopenharmony_ci   uint32_t flags;
1051bf215546Sopenharmony_ci   int ret;
1052bf215546Sopenharmony_ci   unsigned i;
1053bf215546Sopenharmony_ci
1054bf215546Sopenharmony_ci   switch (dev->chipset & ~0xf) {
1055bf215546Sopenharmony_ci   case 0xc0:
1056bf215546Sopenharmony_ci   case 0xd0:
1057bf215546Sopenharmony_ci   case 0xe0:
1058bf215546Sopenharmony_ci   case 0xf0:
1059bf215546Sopenharmony_ci   case 0x100:
1060bf215546Sopenharmony_ci   case 0x110:
1061bf215546Sopenharmony_ci   case 0x120:
1062bf215546Sopenharmony_ci   case 0x130:
1063bf215546Sopenharmony_ci   case 0x140:
1064bf215546Sopenharmony_ci   case 0x160:
1065bf215546Sopenharmony_ci      break;
1066bf215546Sopenharmony_ci   default:
1067bf215546Sopenharmony_ci      return NULL;
1068bf215546Sopenharmony_ci   }
1069bf215546Sopenharmony_ci
1070bf215546Sopenharmony_ci   screen = CALLOC_STRUCT(nvc0_screen);
1071bf215546Sopenharmony_ci   if (!screen)
1072bf215546Sopenharmony_ci      return NULL;
1073bf215546Sopenharmony_ci   pscreen = &screen->base.base;
1074bf215546Sopenharmony_ci   pscreen->destroy = nvc0_screen_destroy;
1075bf215546Sopenharmony_ci
1076bf215546Sopenharmony_ci   ret = nouveau_screen_init(&screen->base, dev);
1077bf215546Sopenharmony_ci   if (ret)
1078bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Base screen init failed: %d\n", ret);
1079bf215546Sopenharmony_ci   chan = screen->base.channel;
1080bf215546Sopenharmony_ci   push = screen->base.pushbuf;
1081bf215546Sopenharmony_ci   push->user_priv = screen;
1082bf215546Sopenharmony_ci   push->rsvd_kick = 5;
1083bf215546Sopenharmony_ci
1084bf215546Sopenharmony_ci   /* TODO: could this be higher on Kepler+? how does reclocking vs no
1085bf215546Sopenharmony_ci    * reclocking affect performance?
1086bf215546Sopenharmony_ci    * TODO: could this be higher on Fermi?
1087bf215546Sopenharmony_ci    */
1088bf215546Sopenharmony_ci   if (dev->chipset >= 0xe0)
1089bf215546Sopenharmony_ci      screen->base.transfer_pushbuf_threshold = 1024;
1090bf215546Sopenharmony_ci
1091bf215546Sopenharmony_ci   screen->base.vidmem_bindings |= PIPE_BIND_CONSTANT_BUFFER |
1092bf215546Sopenharmony_ci      PIPE_BIND_SHADER_BUFFER |
1093bf215546Sopenharmony_ci      PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER |
1094bf215546Sopenharmony_ci      PIPE_BIND_COMMAND_ARGS_BUFFER | PIPE_BIND_QUERY_BUFFER;
1095bf215546Sopenharmony_ci   screen->base.sysmem_bindings |=
1096bf215546Sopenharmony_ci      PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER;
1097bf215546Sopenharmony_ci
1098bf215546Sopenharmony_ci   if (screen->base.vram_domain & NOUVEAU_BO_GART) {
1099bf215546Sopenharmony_ci      screen->base.sysmem_bindings |= screen->base.vidmem_bindings;
1100bf215546Sopenharmony_ci      screen->base.vidmem_bindings = 0;
1101bf215546Sopenharmony_ci   }
1102bf215546Sopenharmony_ci
1103bf215546Sopenharmony_ci   pscreen->context_create = nvc0_create;
1104bf215546Sopenharmony_ci   pscreen->is_format_supported = nvc0_screen_is_format_supported;
1105bf215546Sopenharmony_ci   pscreen->get_param = nvc0_screen_get_param;
1106bf215546Sopenharmony_ci   pscreen->get_shader_param = nvc0_screen_get_shader_param;
1107bf215546Sopenharmony_ci   pscreen->get_paramf = nvc0_screen_get_paramf;
1108bf215546Sopenharmony_ci   pscreen->get_sample_pixel_grid = nvc0_screen_get_sample_pixel_grid;
1109bf215546Sopenharmony_ci   pscreen->get_driver_query_info = nvc0_screen_get_driver_query_info;
1110bf215546Sopenharmony_ci   pscreen->get_driver_query_group_info = nvc0_screen_get_driver_query_group_info;
1111bf215546Sopenharmony_ci   /* nir stuff */
1112bf215546Sopenharmony_ci   pscreen->get_compiler_options = nvc0_screen_get_compiler_options;
1113bf215546Sopenharmony_ci
1114bf215546Sopenharmony_ci   nvc0_screen_init_resource_functions(pscreen);
1115bf215546Sopenharmony_ci
1116bf215546Sopenharmony_ci   screen->base.base.get_video_param = nouveau_vp3_screen_get_video_param;
1117bf215546Sopenharmony_ci   screen->base.base.is_video_format_supported = nouveau_vp3_screen_video_supported;
1118bf215546Sopenharmony_ci
1119bf215546Sopenharmony_ci   flags = NOUVEAU_BO_GART | NOUVEAU_BO_MAP;
1120bf215546Sopenharmony_ci   if (screen->base.drm->version >= 0x01000202)
1121bf215546Sopenharmony_ci      flags |= NOUVEAU_BO_COHERENT;
1122bf215546Sopenharmony_ci
1123bf215546Sopenharmony_ci   ret = nouveau_bo_new(dev, flags, 0, 4096, NULL, &screen->fence.bo);
1124bf215546Sopenharmony_ci   if (ret)
1125bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating fence BO: %d\n", ret);
1126bf215546Sopenharmony_ci   nouveau_bo_map(screen->fence.bo, 0, NULL);
1127bf215546Sopenharmony_ci   screen->fence.map = screen->fence.bo->map;
1128bf215546Sopenharmony_ci   screen->base.fence.emit = nvc0_screen_fence_emit;
1129bf215546Sopenharmony_ci   screen->base.fence.update = nvc0_screen_fence_update;
1130bf215546Sopenharmony_ci
1131bf215546Sopenharmony_ci   if (dev->chipset < 0x140) {
1132bf215546Sopenharmony_ci      ret = nouveau_object_new(chan, (dev->chipset < 0xe0) ? 0x1f906e : 0x906e,
1133bf215546Sopenharmony_ci                               NVIF_CLASS_SW_GF100, NULL, 0, &screen->nvsw);
1134bf215546Sopenharmony_ci      if (ret)
1135bf215546Sopenharmony_ci         FAIL_SCREEN_INIT("Error creating SW object: %d\n", ret);
1136bf215546Sopenharmony_ci
1137bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_SW(NV01_SUBCHAN_OBJECT), 1);
1138bf215546Sopenharmony_ci      PUSH_DATA (push, screen->nvsw->handle);
1139bf215546Sopenharmony_ci   }
1140bf215546Sopenharmony_ci
1141bf215546Sopenharmony_ci   switch (dev->chipset & ~0xf) {
1142bf215546Sopenharmony_ci   case 0x160:
1143bf215546Sopenharmony_ci   case 0x140:
1144bf215546Sopenharmony_ci   case 0x130:
1145bf215546Sopenharmony_ci   case 0x120:
1146bf215546Sopenharmony_ci   case 0x110:
1147bf215546Sopenharmony_ci   case 0x100:
1148bf215546Sopenharmony_ci   case 0xf0:
1149bf215546Sopenharmony_ci      obj_class = NVF0_P2MF_CLASS;
1150bf215546Sopenharmony_ci      break;
1151bf215546Sopenharmony_ci   case 0xe0:
1152bf215546Sopenharmony_ci      obj_class = NVE4_P2MF_CLASS;
1153bf215546Sopenharmony_ci      break;
1154bf215546Sopenharmony_ci   default:
1155bf215546Sopenharmony_ci      obj_class = NVC0_M2MF_CLASS;
1156bf215546Sopenharmony_ci      break;
1157bf215546Sopenharmony_ci   }
1158bf215546Sopenharmony_ci   ret = nouveau_object_new(chan, 0xbeef323f, obj_class, NULL, 0,
1159bf215546Sopenharmony_ci                            &screen->m2mf);
1160bf215546Sopenharmony_ci   if (ret)
1161bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating PGRAPH context for M2MF: %d\n", ret);
1162bf215546Sopenharmony_ci
1163bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_M2MF(NV01_SUBCHAN_OBJECT), 1);
1164bf215546Sopenharmony_ci   PUSH_DATA (push, screen->m2mf->oclass);
1165bf215546Sopenharmony_ci   if (screen->m2mf->oclass == NVE4_P2MF_CLASS) {
1166bf215546Sopenharmony_ci      BEGIN_NVC0(push, SUBC_COPY(NV01_SUBCHAN_OBJECT), 1);
1167bf215546Sopenharmony_ci      PUSH_DATA (push, NVE4_COPY_CLASS);
1168bf215546Sopenharmony_ci   }
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_ci   ret = nouveau_object_new(chan, 0xbeef902d, NVC0_2D_CLASS, NULL, 0,
1171bf215546Sopenharmony_ci                            &screen->eng2d);
1172bf215546Sopenharmony_ci   if (ret)
1173bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating PGRAPH context for 2D: %d\n", ret);
1174bf215546Sopenharmony_ci
1175bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_2D(NV01_SUBCHAN_OBJECT), 1);
1176bf215546Sopenharmony_ci   PUSH_DATA (push, screen->eng2d->oclass);
1177bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_2D(NVC0_2D_SINGLE_GPC), 1);
1178bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1179bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(OPERATION), 1);
1180bf215546Sopenharmony_ci   PUSH_DATA (push, NV50_2D_OPERATION_SRCCOPY);
1181bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(CLIP_ENABLE), 1);
1182bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1183bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(COLOR_KEY_ENABLE), 1);
1184bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1185bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(SET_PIXELS_FROM_MEMORY_CORRAL_SIZE), 1);
1186bf215546Sopenharmony_ci   PUSH_DATA (push, 0x3f);
1187bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(SET_PIXELS_FROM_MEMORY_SAFE_OVERLAP), 1);
1188bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1189bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_2D(COND_MODE), 1);
1190bf215546Sopenharmony_ci   PUSH_DATA (push, NV50_2D_COND_MODE_ALWAYS);
1191bf215546Sopenharmony_ci
1192bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_2D(NVC0_GRAPH_NOTIFY_ADDRESS_HIGH), 2);
1193bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->fence.bo->offset + 16);
1194bf215546Sopenharmony_ci   PUSH_DATA (push, screen->fence.bo->offset + 16);
1195bf215546Sopenharmony_ci
1196bf215546Sopenharmony_ci   switch (dev->chipset & ~0xf) {
1197bf215546Sopenharmony_ci   case 0x160:
1198bf215546Sopenharmony_ci      obj_class = TU102_3D_CLASS;
1199bf215546Sopenharmony_ci      break;
1200bf215546Sopenharmony_ci   case 0x140:
1201bf215546Sopenharmony_ci      obj_class = GV100_3D_CLASS;
1202bf215546Sopenharmony_ci      break;
1203bf215546Sopenharmony_ci   case 0x130:
1204bf215546Sopenharmony_ci      switch (dev->chipset) {
1205bf215546Sopenharmony_ci      case 0x130:
1206bf215546Sopenharmony_ci      case 0x13b:
1207bf215546Sopenharmony_ci         obj_class = GP100_3D_CLASS;
1208bf215546Sopenharmony_ci         break;
1209bf215546Sopenharmony_ci      default:
1210bf215546Sopenharmony_ci         obj_class = GP102_3D_CLASS;
1211bf215546Sopenharmony_ci         break;
1212bf215546Sopenharmony_ci      }
1213bf215546Sopenharmony_ci      break;
1214bf215546Sopenharmony_ci   case 0x120:
1215bf215546Sopenharmony_ci      obj_class = GM200_3D_CLASS;
1216bf215546Sopenharmony_ci      break;
1217bf215546Sopenharmony_ci   case 0x110:
1218bf215546Sopenharmony_ci      obj_class = GM107_3D_CLASS;
1219bf215546Sopenharmony_ci      break;
1220bf215546Sopenharmony_ci   case 0x100:
1221bf215546Sopenharmony_ci   case 0xf0:
1222bf215546Sopenharmony_ci      obj_class = NVF0_3D_CLASS;
1223bf215546Sopenharmony_ci      break;
1224bf215546Sopenharmony_ci   case 0xe0:
1225bf215546Sopenharmony_ci      switch (dev->chipset) {
1226bf215546Sopenharmony_ci      case 0xea:
1227bf215546Sopenharmony_ci         obj_class = NVEA_3D_CLASS;
1228bf215546Sopenharmony_ci         break;
1229bf215546Sopenharmony_ci      default:
1230bf215546Sopenharmony_ci         obj_class = NVE4_3D_CLASS;
1231bf215546Sopenharmony_ci         break;
1232bf215546Sopenharmony_ci      }
1233bf215546Sopenharmony_ci      break;
1234bf215546Sopenharmony_ci   case 0xd0:
1235bf215546Sopenharmony_ci      obj_class = NVC8_3D_CLASS;
1236bf215546Sopenharmony_ci      break;
1237bf215546Sopenharmony_ci   case 0xc0:
1238bf215546Sopenharmony_ci   default:
1239bf215546Sopenharmony_ci      switch (dev->chipset) {
1240bf215546Sopenharmony_ci      case 0xc8:
1241bf215546Sopenharmony_ci         obj_class = NVC8_3D_CLASS;
1242bf215546Sopenharmony_ci         break;
1243bf215546Sopenharmony_ci      case 0xc1:
1244bf215546Sopenharmony_ci         obj_class = NVC1_3D_CLASS;
1245bf215546Sopenharmony_ci         break;
1246bf215546Sopenharmony_ci      default:
1247bf215546Sopenharmony_ci         obj_class = NVC0_3D_CLASS;
1248bf215546Sopenharmony_ci         break;
1249bf215546Sopenharmony_ci      }
1250bf215546Sopenharmony_ci      break;
1251bf215546Sopenharmony_ci   }
1252bf215546Sopenharmony_ci   ret = nouveau_object_new(chan, 0xbeef003d, obj_class, NULL, 0,
1253bf215546Sopenharmony_ci                            &screen->eng3d);
1254bf215546Sopenharmony_ci   if (ret)
1255bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating PGRAPH context for 3D: %d\n", ret);
1256bf215546Sopenharmony_ci   screen->base.class_3d = obj_class;
1257bf215546Sopenharmony_ci
1258bf215546Sopenharmony_ci   BEGIN_NVC0(push, SUBC_3D(NV01_SUBCHAN_OBJECT), 1);
1259bf215546Sopenharmony_ci   PUSH_DATA (push, screen->eng3d->oclass);
1260bf215546Sopenharmony_ci
1261bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(COND_MODE), 1);
1262bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_COND_MODE_ALWAYS);
1263bf215546Sopenharmony_ci
1264bf215546Sopenharmony_ci   if (debug_get_bool_option("NOUVEAU_SHADER_WATCHDOG", true)) {
1265bf215546Sopenharmony_ci      /* kill shaders after about 1 second (at 100 MHz) */
1266bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(WATCHDOG_TIMER), 1);
1267bf215546Sopenharmony_ci      PUSH_DATA (push, 0x17);
1268bf215546Sopenharmony_ci   }
1269bf215546Sopenharmony_ci
1270bf215546Sopenharmony_ci   IMMED_NVC0(push, NVC0_3D(ZETA_COMP_ENABLE),
1271bf215546Sopenharmony_ci                    screen->base.drm->version >= 0x01000101);
1272bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(RT_COMP_ENABLE(0)), 8);
1273bf215546Sopenharmony_ci   for (i = 0; i < 8; ++i)
1274bf215546Sopenharmony_ci      PUSH_DATA(push, screen->base.drm->version >= 0x01000101);
1275bf215546Sopenharmony_ci
1276bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1);
1277bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1278bf215546Sopenharmony_ci
1279bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CSAA_ENABLE), 1);
1280bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1281bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_ENABLE), 1);
1282bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1283bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 1);
1284bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_MULTISAMPLE_MODE_MS1);
1285bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(MULTISAMPLE_CTRL), 1);
1286bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1287bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(LINE_WIDTH_SEPARATE), 1);
1288bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1289bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(PRIM_RESTART_WITH_DRAW_ARRAYS), 1);
1290bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1291bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(BLEND_SEPARATE_ALPHA), 1);
1292bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1293bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(BLEND_ENABLE_COMMON), 1);
1294bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1295bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(SHADE_MODEL), 1);
1296bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_SHADE_MODEL_SMOOTH);
1297bf215546Sopenharmony_ci   if (screen->eng3d->oclass < NVE4_3D_CLASS) {
1298bf215546Sopenharmony_ci      IMMED_NVC0(push, NVC0_3D(TEX_MISC), 0);
1299bf215546Sopenharmony_ci   } else {
1300bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVE4_3D(TEX_CB_INDEX), 1);
1301bf215546Sopenharmony_ci      PUSH_DATA (push, 15);
1302bf215546Sopenharmony_ci   }
1303bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CALL_LIMIT_LOG), 1);
1304bf215546Sopenharmony_ci   PUSH_DATA (push, 8); /* 128 */
1305bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(ZCULL_STATCTRS_ENABLE), 1);
1306bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1307bf215546Sopenharmony_ci   if (screen->eng3d->oclass >= NVC1_3D_CLASS) {
1308bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(CACHE_SPLIT), 1);
1309bf215546Sopenharmony_ci      PUSH_DATA (push, NVC0_3D_CACHE_SPLIT_48K_SHARED_16K_L1);
1310bf215546Sopenharmony_ci   }
1311bf215546Sopenharmony_ci
1312bf215546Sopenharmony_ci   nvc0_magic_3d_init(push, screen->eng3d->oclass);
1313bf215546Sopenharmony_ci
1314bf215546Sopenharmony_ci   ret = nvc0_screen_resize_text_area(screen, 1 << 19);
1315bf215546Sopenharmony_ci   if (ret)
1316bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating TEXT area: %d\n", ret);
1317bf215546Sopenharmony_ci
1318bf215546Sopenharmony_ci   /* 6 user uniform areas, 6 driver areas, and 1 for the runout */
1319bf215546Sopenharmony_ci   ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 12, 13 << 16, NULL,
1320bf215546Sopenharmony_ci                        &screen->uniform_bo);
1321bf215546Sopenharmony_ci   if (ret)
1322bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating uniform BO: %d\n", ret);
1323bf215546Sopenharmony_ci
1324bf215546Sopenharmony_ci   PUSH_REFN (push, screen->uniform_bo, NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_WR);
1325bf215546Sopenharmony_ci
1326bf215546Sopenharmony_ci   /* return { 0.0, 0.0, 0.0, 0.0 } for out-of-bounds vtxbuf access */
1327bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CB_SIZE), 3);
1328bf215546Sopenharmony_ci   PUSH_DATA (push, 256);
1329bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO);
1330bf215546Sopenharmony_ci   PUSH_DATA (push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO);
1331bf215546Sopenharmony_ci   BEGIN_1IC0(push, NVC0_3D(CB_POS), 5);
1332bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1333bf215546Sopenharmony_ci   PUSH_DATAf(push, 0.0f);
1334bf215546Sopenharmony_ci   PUSH_DATAf(push, 0.0f);
1335bf215546Sopenharmony_ci   PUSH_DATAf(push, 0.0f);
1336bf215546Sopenharmony_ci   PUSH_DATAf(push, 0.0f);
1337bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(VERTEX_RUNOUT_ADDRESS_HIGH), 2);
1338bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO);
1339bf215546Sopenharmony_ci   PUSH_DATA (push, screen->uniform_bo->offset + NVC0_CB_AUX_RUNOUT_INFO);
1340bf215546Sopenharmony_ci
1341bf215546Sopenharmony_ci   if (screen->base.drm->version >= 0x01000101) {
1342bf215546Sopenharmony_ci      ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_GRAPH_UNITS, &value);
1343bf215546Sopenharmony_ci      if (ret)
1344bf215546Sopenharmony_ci         FAIL_SCREEN_INIT("NOUVEAU_GETPARAM_GRAPH_UNITS failed: %d\n", ret);
1345bf215546Sopenharmony_ci   } else {
1346bf215546Sopenharmony_ci      if (dev->chipset >= 0xe0 && dev->chipset < 0xf0)
1347bf215546Sopenharmony_ci         value = (8 << 8) | 4;
1348bf215546Sopenharmony_ci      else
1349bf215546Sopenharmony_ci         value = (16 << 8) | 4;
1350bf215546Sopenharmony_ci   }
1351bf215546Sopenharmony_ci   screen->gpc_count = value & 0x000000ff;
1352bf215546Sopenharmony_ci   screen->mp_count = value >> 8;
1353bf215546Sopenharmony_ci   screen->mp_count_compute = screen->mp_count;
1354bf215546Sopenharmony_ci
1355bf215546Sopenharmony_ci   ret = nvc0_screen_resize_tls_area(screen, 128 * 16, 0, 0x200);
1356bf215546Sopenharmony_ci   if (ret)
1357bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating TLS area: %d\n", ret);
1358bf215546Sopenharmony_ci
1359bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(TEMP_ADDRESS_HIGH), 4);
1360bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->tls->offset);
1361bf215546Sopenharmony_ci   PUSH_DATA (push, screen->tls->offset);
1362bf215546Sopenharmony_ci   PUSH_DATA (push, screen->tls->size >> 32);
1363bf215546Sopenharmony_ci   PUSH_DATA (push, screen->tls->size);
1364bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(WARP_TEMP_ALLOC), 1);
1365bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1366bf215546Sopenharmony_ci   /* Reduce likelihood of collision with real buffers by placing the hole at
1367bf215546Sopenharmony_ci    * the top of the 4G area. This will have to be dealt with for real
1368bf215546Sopenharmony_ci    * eventually by blocking off that area from the VM.
1369bf215546Sopenharmony_ci    */
1370bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(LOCAL_BASE), 1);
1371bf215546Sopenharmony_ci   PUSH_DATA (push, 0xff << 24);
1372bf215546Sopenharmony_ci
1373bf215546Sopenharmony_ci   if (screen->eng3d->oclass < GM107_3D_CLASS) {
1374bf215546Sopenharmony_ci      ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 17, 1 << 20, NULL,
1375bf215546Sopenharmony_ci                           &screen->poly_cache);
1376bf215546Sopenharmony_ci      if (ret)
1377bf215546Sopenharmony_ci         FAIL_SCREEN_INIT("Error allocating poly cache BO: %d\n", ret);
1378bf215546Sopenharmony_ci
1379bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(VERTEX_QUARANTINE_ADDRESS_HIGH), 3);
1380bf215546Sopenharmony_ci      PUSH_DATAh(push, screen->poly_cache->offset);
1381bf215546Sopenharmony_ci      PUSH_DATA (push, screen->poly_cache->offset);
1382bf215546Sopenharmony_ci      PUSH_DATA (push, 3);
1383bf215546Sopenharmony_ci   }
1384bf215546Sopenharmony_ci
1385bf215546Sopenharmony_ci   ret = nouveau_bo_new(dev, NV_VRAM_DOMAIN(&screen->base), 1 << 17, 1 << 17, NULL,
1386bf215546Sopenharmony_ci                        &screen->txc);
1387bf215546Sopenharmony_ci   if (ret)
1388bf215546Sopenharmony_ci      FAIL_SCREEN_INIT("Error allocating txc BO: %d\n", ret);
1389bf215546Sopenharmony_ci
1390bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(TIC_ADDRESS_HIGH), 3);
1391bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->txc->offset);
1392bf215546Sopenharmony_ci   PUSH_DATA (push, screen->txc->offset);
1393bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_TIC_MAX_ENTRIES - 1);
1394bf215546Sopenharmony_ci   if (screen->eng3d->oclass >= GM107_3D_CLASS) {
1395bf215546Sopenharmony_ci      screen->tic.maxwell = true;
1396bf215546Sopenharmony_ci      if (screen->eng3d->oclass == GM107_3D_CLASS) {
1397bf215546Sopenharmony_ci         screen->tic.maxwell =
1398bf215546Sopenharmony_ci            debug_get_bool_option("NOUVEAU_MAXWELL_TIC", true);
1399bf215546Sopenharmony_ci         IMMED_NVC0(push, SUBC_3D(0x0f10), screen->tic.maxwell);
1400bf215546Sopenharmony_ci      }
1401bf215546Sopenharmony_ci   }
1402bf215546Sopenharmony_ci
1403bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(TSC_ADDRESS_HIGH), 3);
1404bf215546Sopenharmony_ci   PUSH_DATAh(push, screen->txc->offset + 65536);
1405bf215546Sopenharmony_ci   PUSH_DATA (push, screen->txc->offset + 65536);
1406bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_TSC_MAX_ENTRIES - 1);
1407bf215546Sopenharmony_ci
1408bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(SCREEN_Y_CONTROL), 1);
1409bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1410bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(WINDOW_OFFSET_X), 2);
1411bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1412bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1413bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(ZCULL_REGION), 1); /* deactivate ZCULL */
1414bf215546Sopenharmony_ci   PUSH_DATA (push, 0x3f);
1415bf215546Sopenharmony_ci
1416bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_MODE), 1);
1417bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_CLIP_RECTS_MODE_INSIDE_ANY);
1418bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CLIP_RECT_HORIZ(0)), 8 * 2);
1419bf215546Sopenharmony_ci   for (i = 0; i < 8 * 2; ++i)
1420bf215546Sopenharmony_ci      PUSH_DATA(push, 0);
1421bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CLIP_RECTS_EN), 1);
1422bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1423bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CLIPID_ENABLE), 1);
1424bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1425bf215546Sopenharmony_ci
1426bf215546Sopenharmony_ci   /* neither scissors, viewport nor stencil mask should affect clears */
1427bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(CLEAR_FLAGS), 1);
1428bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1429bf215546Sopenharmony_ci
1430bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1);
1431bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1432bf215546Sopenharmony_ci   for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) {
1433bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(i)), 2);
1434bf215546Sopenharmony_ci      PUSH_DATAf(push, 0.0f);
1435bf215546Sopenharmony_ci      PUSH_DATAf(push, 1.0f);
1436bf215546Sopenharmony_ci   }
1437bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 1);
1438bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1);
1439bf215546Sopenharmony_ci
1440bf215546Sopenharmony_ci   /* We use scissors instead of exact view volume clipping,
1441bf215546Sopenharmony_ci    * so they're always enabled.
1442bf215546Sopenharmony_ci    */
1443bf215546Sopenharmony_ci   for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) {
1444bf215546Sopenharmony_ci      BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(i)), 3);
1445bf215546Sopenharmony_ci      PUSH_DATA (push, 1);
1446bf215546Sopenharmony_ci      PUSH_DATA (push, 16384 << 16);
1447bf215546Sopenharmony_ci      PUSH_DATA (push, 16384 << 16);
1448bf215546Sopenharmony_ci   }
1449bf215546Sopenharmony_ci
1450bf215546Sopenharmony_ci   if (screen->eng3d->oclass < TU102_3D_CLASS) {
1451bf215546Sopenharmony_ci#define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n);
1452bf215546Sopenharmony_ci
1453bf215546Sopenharmony_ci      i = 0;
1454bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_PER_INSTANCE, mme9097_per_instance_bf);
1455bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_BLEND_ENABLES, mme9097_blend_enables);
1456bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_SELECT, mme9097_vertex_array_select);
1457bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_TEP_SELECT, mme9097_tep_select);
1458bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_GP_SELECT, mme9097_gp_select);
1459bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_FRONT, mme9097_poly_mode_front);
1460bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_BACK, mme9097_poly_mode_back);
1461bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT, mme9097_draw_arrays_indirect);
1462bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT, mme9097_draw_elts_indirect);
1463bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT_COUNT, mme9097_draw_arrays_indirect_count);
1464bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT_COUNT, mme9097_draw_elts_indirect_count);
1465bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE, mme9097_query_buffer_write);
1466bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE, mme9097_conservative_raster_state);
1467bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER, mme9097_compute_counter);
1468bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER_TO_QUERY, mme9097_compute_counter_to_query);
1469bf215546Sopenharmony_ci      MK_MACRO(NVC0_CP_MACRO_LAUNCH_GRID_INDIRECT, mme90c0_launch_grid_indirect);
1470bf215546Sopenharmony_ci   } else {
1471bf215546Sopenharmony_ci#undef MK_MACRO
1472bf215546Sopenharmony_ci#define MK_MACRO(m, n) i = tu102_graph_set_macro(screen, m, i, sizeof(n), n);
1473bf215546Sopenharmony_ci
1474bf215546Sopenharmony_ci      i = 0;
1475bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_PER_INSTANCE, mmec597_per_instance_bf);
1476bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_BLEND_ENABLES, mmec597_blend_enables);
1477bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_VERTEX_ARRAY_SELECT, mmec597_vertex_array_select);
1478bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_TEP_SELECT, mmec597_tep_select);
1479bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_GP_SELECT, mmec597_gp_select);
1480bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_FRONT, mmec597_poly_mode_front);
1481bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_POLYGON_MODE_BACK, mmec597_poly_mode_back);
1482bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT, mmec597_draw_arrays_indirect);
1483bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT, mmec597_draw_elts_indirect);
1484bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ARRAYS_INDIRECT_COUNT, mmec597_draw_arrays_indirect_count);
1485bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_DRAW_ELEMENTS_INDIRECT_COUNT, mmec597_draw_elts_indirect_count);
1486bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_QUERY_BUFFER_WRITE, mmec597_query_buffer_write);
1487bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_CONSERVATIVE_RASTER_STATE, mmec597_conservative_raster_state);
1488bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER, mmec597_compute_counter);
1489bf215546Sopenharmony_ci      MK_MACRO(NVC0_3D_MACRO_COMPUTE_COUNTER_TO_QUERY, mmec597_compute_counter_to_query);
1490bf215546Sopenharmony_ci   }
1491bf215546Sopenharmony_ci
1492bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(RASTERIZE_ENABLE), 1);
1493bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1494bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(RT_SEPARATE_FRAG_DATA), 1);
1495bf215546Sopenharmony_ci   PUSH_DATA (push, 1);
1496bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(MACRO_GP_SELECT), 1);
1497bf215546Sopenharmony_ci   PUSH_DATA (push, 0x40);
1498bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(LAYER), 1);
1499bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1500bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(MACRO_TEP_SELECT), 1);
1501bf215546Sopenharmony_ci   PUSH_DATA (push, 0x30);
1502bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(PATCH_VERTICES), 1);
1503bf215546Sopenharmony_ci   PUSH_DATA (push, 3);
1504bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(SP_SELECT(2)), 1);
1505bf215546Sopenharmony_ci   PUSH_DATA (push, 0x20);
1506bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(SP_SELECT(0)), 1);
1507bf215546Sopenharmony_ci   PUSH_DATA (push, 0x00);
1508bf215546Sopenharmony_ci   screen->save_state.patch_vertices = 3;
1509bf215546Sopenharmony_ci
1510bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(POINT_COORD_REPLACE), 1);
1511bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1512bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(POINT_RASTER_RULES), 1);
1513bf215546Sopenharmony_ci   PUSH_DATA (push, NVC0_3D_POINT_RASTER_RULES_OGL);
1514bf215546Sopenharmony_ci
1515bf215546Sopenharmony_ci   IMMED_NVC0(push, NVC0_3D(EDGEFLAG), 1);
1516bf215546Sopenharmony_ci
1517bf215546Sopenharmony_ci   if (nvc0_screen_init_compute(screen))
1518bf215546Sopenharmony_ci      goto fail;
1519bf215546Sopenharmony_ci
1520bf215546Sopenharmony_ci   /* XXX: Compute and 3D are somehow aliased on Fermi. */
1521bf215546Sopenharmony_ci   for (i = 0; i < 5; ++i) {
1522bf215546Sopenharmony_ci      unsigned j = 0;
1523bf215546Sopenharmony_ci      for (j = 0; j < 16; j++)
1524bf215546Sopenharmony_ci         screen->cb_bindings[i][j].size = -1;
1525bf215546Sopenharmony_ci
1526bf215546Sopenharmony_ci      /* TIC and TSC entries for each unit (nve4+ only) */
1527bf215546Sopenharmony_ci      /* auxiliary constants (6 user clip planes, base instance id) */
1528bf215546Sopenharmony_ci      nvc0_screen_bind_cb_3d(screen, NULL, i, 15, NVC0_CB_AUX_SIZE,
1529bf215546Sopenharmony_ci                             screen->uniform_bo->offset + NVC0_CB_AUX_INFO(i));
1530bf215546Sopenharmony_ci      if (screen->eng3d->oclass >= NVE4_3D_CLASS) {
1531bf215546Sopenharmony_ci         unsigned j;
1532bf215546Sopenharmony_ci         BEGIN_1IC0(push, NVC0_3D(CB_POS), 9);
1533bf215546Sopenharmony_ci         PUSH_DATA (push, NVC0_CB_AUX_UNK_INFO);
1534bf215546Sopenharmony_ci         for (j = 0; j < 8; ++j)
1535bf215546Sopenharmony_ci            PUSH_DATA(push, j);
1536bf215546Sopenharmony_ci      } else {
1537bf215546Sopenharmony_ci         BEGIN_NVC0(push, NVC0_3D(TEX_LIMITS(i)), 1);
1538bf215546Sopenharmony_ci         PUSH_DATA (push, 0x54);
1539bf215546Sopenharmony_ci      }
1540bf215546Sopenharmony_ci
1541bf215546Sopenharmony_ci      /* MS sample coordinate offsets: these do not work with _ALT modes ! */
1542bf215546Sopenharmony_ci      BEGIN_1IC0(push, NVC0_3D(CB_POS), 1 + 2 * 8);
1543bf215546Sopenharmony_ci      PUSH_DATA (push, NVC0_CB_AUX_MS_INFO);
1544bf215546Sopenharmony_ci      PUSH_DATA (push, 0); /* 0 */
1545bf215546Sopenharmony_ci      PUSH_DATA (push, 0);
1546bf215546Sopenharmony_ci      PUSH_DATA (push, 1); /* 1 */
1547bf215546Sopenharmony_ci      PUSH_DATA (push, 0);
1548bf215546Sopenharmony_ci      PUSH_DATA (push, 0); /* 2 */
1549bf215546Sopenharmony_ci      PUSH_DATA (push, 1);
1550bf215546Sopenharmony_ci      PUSH_DATA (push, 1); /* 3 */
1551bf215546Sopenharmony_ci      PUSH_DATA (push, 1);
1552bf215546Sopenharmony_ci      PUSH_DATA (push, 2); /* 4 */
1553bf215546Sopenharmony_ci      PUSH_DATA (push, 0);
1554bf215546Sopenharmony_ci      PUSH_DATA (push, 3); /* 5 */
1555bf215546Sopenharmony_ci      PUSH_DATA (push, 0);
1556bf215546Sopenharmony_ci      PUSH_DATA (push, 2); /* 6 */
1557bf215546Sopenharmony_ci      PUSH_DATA (push, 1);
1558bf215546Sopenharmony_ci      PUSH_DATA (push, 3); /* 7 */
1559bf215546Sopenharmony_ci      PUSH_DATA (push, 1);
1560bf215546Sopenharmony_ci   }
1561bf215546Sopenharmony_ci   BEGIN_NVC0(push, NVC0_3D(LINKED_TSC), 1);
1562bf215546Sopenharmony_ci   PUSH_DATA (push, 0);
1563bf215546Sopenharmony_ci
1564bf215546Sopenharmony_ci   PUSH_KICK (push);
1565bf215546Sopenharmony_ci
1566bf215546Sopenharmony_ci   screen->tic.entries = CALLOC(
1567bf215546Sopenharmony_ci         NVC0_TIC_MAX_ENTRIES + NVC0_TSC_MAX_ENTRIES + NVE4_IMG_MAX_HANDLES,
1568bf215546Sopenharmony_ci         sizeof(void *));
1569bf215546Sopenharmony_ci   screen->tsc.entries = screen->tic.entries + NVC0_TIC_MAX_ENTRIES;
1570bf215546Sopenharmony_ci   screen->img.entries = (void *)(screen->tsc.entries + NVC0_TSC_MAX_ENTRIES);
1571bf215546Sopenharmony_ci
1572bf215546Sopenharmony_ci   if (!nvc0_blitter_create(screen))
1573bf215546Sopenharmony_ci      goto fail;
1574bf215546Sopenharmony_ci
1575bf215546Sopenharmony_ci   nouveau_fence_new(&screen->base, &screen->base.fence.current);
1576bf215546Sopenharmony_ci
1577bf215546Sopenharmony_ci   return &screen->base;
1578bf215546Sopenharmony_ci
1579bf215546Sopenharmony_cifail:
1580bf215546Sopenharmony_ci   screen->base.base.context_create = NULL;
1581bf215546Sopenharmony_ci   return &screen->base;
1582bf215546Sopenharmony_ci}
1583bf215546Sopenharmony_ci
1584bf215546Sopenharmony_ciint
1585bf215546Sopenharmony_cinvc0_screen_tic_alloc(struct nvc0_screen *screen, void *entry)
1586bf215546Sopenharmony_ci{
1587bf215546Sopenharmony_ci   int i = screen->tic.next;
1588bf215546Sopenharmony_ci
1589bf215546Sopenharmony_ci   while (screen->tic.lock[i / 32] & (1 << (i % 32)))
1590bf215546Sopenharmony_ci      i = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1);
1591bf215546Sopenharmony_ci
1592bf215546Sopenharmony_ci   screen->tic.next = (i + 1) & (NVC0_TIC_MAX_ENTRIES - 1);
1593bf215546Sopenharmony_ci
1594bf215546Sopenharmony_ci   if (screen->tic.entries[i])
1595bf215546Sopenharmony_ci      nv50_tic_entry(screen->tic.entries[i])->id = -1;
1596bf215546Sopenharmony_ci
1597bf215546Sopenharmony_ci   screen->tic.entries[i] = entry;
1598bf215546Sopenharmony_ci   return i;
1599bf215546Sopenharmony_ci}
1600bf215546Sopenharmony_ci
1601bf215546Sopenharmony_ciint
1602bf215546Sopenharmony_cinvc0_screen_tsc_alloc(struct nvc0_screen *screen, void *entry)
1603bf215546Sopenharmony_ci{
1604bf215546Sopenharmony_ci   int i = screen->tsc.next;
1605bf215546Sopenharmony_ci
1606bf215546Sopenharmony_ci   while (screen->tsc.lock[i / 32] & (1 << (i % 32)))
1607bf215546Sopenharmony_ci      i = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1);
1608bf215546Sopenharmony_ci
1609bf215546Sopenharmony_ci   screen->tsc.next = (i + 1) & (NVC0_TSC_MAX_ENTRIES - 1);
1610bf215546Sopenharmony_ci
1611bf215546Sopenharmony_ci   if (screen->tsc.entries[i])
1612bf215546Sopenharmony_ci      nv50_tsc_entry(screen->tsc.entries[i])->id = -1;
1613bf215546Sopenharmony_ci
1614bf215546Sopenharmony_ci   screen->tsc.entries[i] = entry;
1615bf215546Sopenharmony_ci   return i;
1616bf215546Sopenharmony_ci}
1617